forked from Imagelibrary/binutils-gdb
Convert substitute_path_component to C++
Simplify the code of utils.c:substiute_path_component by converting it to C++. gdb/ChangeLog: * utils.c (substitute_path_component): Convert to C++. * utils.h (substitute_path_componetn): Adjust declatation. * auto-load.c (auto_load_expand_dir_vars): Adjust.
This commit is contained in:
committed by
Andreas Arnez
parent
3d044c0c78
commit
c48c4ca231
@@ -40,6 +40,7 @@
|
|||||||
#include "filestuff.h"
|
#include "filestuff.h"
|
||||||
#include "extension.h"
|
#include "extension.h"
|
||||||
#include "gdb/section-scripts.h"
|
#include "gdb/section-scripts.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
/* The section to look in for auto-loaded scripts (in file formats that
|
/* The section to look in for auto-loaded scripts (in file formats that
|
||||||
support sections).
|
support sections).
|
||||||
@@ -175,21 +176,20 @@ static VEC (char_ptr) *auto_load_safe_path_vec;
|
|||||||
this vector must be freed by free_char_ptr_vec by the caller. */
|
this vector must be freed by free_char_ptr_vec by the caller. */
|
||||||
|
|
||||||
static VEC (char_ptr) *
|
static VEC (char_ptr) *
|
||||||
auto_load_expand_dir_vars (const char *string)
|
auto_load_expand_dir_vars (std::string orig)
|
||||||
{
|
{
|
||||||
VEC (char_ptr) *dir_vec;
|
VEC (char_ptr) *dir_vec;
|
||||||
char *s;
|
std::string str = orig;
|
||||||
|
|
||||||
s = xstrdup (string);
|
substitute_path_component (str, "$datadir", gdb_datadir);
|
||||||
substitute_path_component (&s, "$datadir", gdb_datadir);
|
substitute_path_component (str, "$debugdir", debug_file_directory);
|
||||||
substitute_path_component (&s, "$debugdir", debug_file_directory);
|
|
||||||
|
|
||||||
if (debug_auto_load && strcmp (s, string) != 0)
|
if (debug_auto_load && str.compare (orig) != 0)
|
||||||
fprintf_unfiltered (gdb_stdlog,
|
fprintf_unfiltered (gdb_stdlog,
|
||||||
_("auto-load: Expanded $-variables to \"%s\".\n"), s);
|
_("auto-load: Expanded $-variables to \"%s\".\n"),
|
||||||
|
str.c_str ());
|
||||||
|
|
||||||
dir_vec = dirnames_to_char_ptr_vec (s);
|
dir_vec = dirnames_to_char_ptr_vec (str.c_str ());
|
||||||
xfree(s);
|
|
||||||
|
|
||||||
return dir_vec;
|
return dir_vec;
|
||||||
}
|
}
|
||||||
|
|||||||
50
gdb/utils.c
50
gdb/utils.c
@@ -66,6 +66,8 @@
|
|||||||
#include "interps.h"
|
#include "interps.h"
|
||||||
#include "gdb_regex.h"
|
#include "gdb_regex.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#if !HAVE_DECL_MALLOC
|
#if !HAVE_DECL_MALLOC
|
||||||
extern PTR malloc (); /* ARI: PTR */
|
extern PTR malloc (); /* ARI: PTR */
|
||||||
#endif
|
#endif
|
||||||
@@ -3156,49 +3158,25 @@ make_cleanup_free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec)
|
|||||||
return make_cleanup (do_free_char_ptr_vec, char_ptr_vec);
|
return make_cleanup (do_free_char_ptr_vec, char_ptr_vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Substitute all occurences of string FROM by string TO in *STRINGP. *STRINGP
|
/* See utils.h. */
|
||||||
must come from xrealloc-compatible allocator and it may be updated. FROM
|
|
||||||
needs to be delimited by IS_DIR_SEPARATOR or DIRNAME_SEPARATOR (or be
|
|
||||||
located at the start or end of *STRINGP. */
|
|
||||||
|
|
||||||
void
|
void
|
||||||
substitute_path_component (char **stringp, const char *from, const char *to)
|
substitute_path_component (std::string &str, const std::string &from,
|
||||||
|
const std::string &to)
|
||||||
{
|
{
|
||||||
char *string = *stringp, *s;
|
for (size_t pos = str.find (from); pos != std::string::npos;
|
||||||
const size_t from_len = strlen (from);
|
pos = str.find (from, pos + 1))
|
||||||
const size_t to_len = strlen (to);
|
|
||||||
|
|
||||||
for (s = string;;)
|
|
||||||
{
|
{
|
||||||
s = strstr (s, from);
|
char start, end;
|
||||||
if (s == NULL)
|
start = str[pos - 1];
|
||||||
break;
|
end = str[pos + from.length ()];
|
||||||
|
if ((pos == 0 || IS_DIR_SEPARATOR (start) || start == DIRNAME_SEPARATOR)
|
||||||
if ((s == string || IS_DIR_SEPARATOR (s[-1])
|
&& (end == '\0' || IS_DIR_SEPARATOR (end)
|
||||||
|| s[-1] == DIRNAME_SEPARATOR)
|
|| end == DIRNAME_SEPARATOR))
|
||||||
&& (s[from_len] == '\0' || IS_DIR_SEPARATOR (s[from_len])
|
|
||||||
|| s[from_len] == DIRNAME_SEPARATOR))
|
|
||||||
{
|
{
|
||||||
char *string_new;
|
str.replace (pos, from.length (), to);
|
||||||
|
|
||||||
string_new
|
|
||||||
= (char *) xrealloc (string, (strlen (string) + to_len + 1));
|
|
||||||
|
|
||||||
/* Relocate the current S pointer. */
|
|
||||||
s = s - string + string_new;
|
|
||||||
string = string_new;
|
|
||||||
|
|
||||||
/* Replace from by to. */
|
|
||||||
memmove (&s[to_len], &s[from_len], strlen (&s[from_len]) + 1);
|
|
||||||
memcpy (s, to, to_len);
|
|
||||||
|
|
||||||
s += to_len;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
s++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*stringp = string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_WAITPID
|
#ifdef HAVE_WAITPID
|
||||||
|
|||||||
@@ -132,8 +132,13 @@ extern char *gdb_abspath (const char *);
|
|||||||
extern int gdb_filename_fnmatch (const char *pattern, const char *string,
|
extern int gdb_filename_fnmatch (const char *pattern, const char *string,
|
||||||
int flags);
|
int flags);
|
||||||
|
|
||||||
extern void substitute_path_component (char **stringp, const char *from,
|
/* Substitute all occurences of string FROM by string TO in STR. FROM
|
||||||
const char *to);
|
needs to be delimited by IS_DIR_SEPARATOR or DIRNAME_SEPARATOR (or be
|
||||||
|
located at the start or end of STR). */
|
||||||
|
|
||||||
|
extern void substitute_path_component (std::string &str,
|
||||||
|
const std::string &from,
|
||||||
|
const std::string &to);
|
||||||
|
|
||||||
char *ldirname (const char *filename);
|
char *ldirname (const char *filename);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user