Add delim_string_to_char_ptr_vec.
* common/gdb_vecs.c (delim_string_to_char_ptr_vec_append): New function, contents of dirnames_to_char_ptr_vec_append moved here. (delim_string_to_char_ptr_vec): New function. (dirnames_to_char_ptr_vec_append): Rewrite. * common/gdb_vecs.h (delim_string_to_char_ptr_vec): Declare.
This commit is contained in:
parent
df049a5831
commit
749234e540
|
@ -1,3 +1,11 @@
|
||||||
|
2014-01-17 Doug Evans <dje@google.com>
|
||||||
|
|
||||||
|
* common/gdb_vecs.c (delim_string_to_char_ptr_vec_append): New
|
||||||
|
function, contents of dirnames_to_char_ptr_vec_append moved here.
|
||||||
|
(delim_string_to_char_ptr_vec): New function.
|
||||||
|
(dirnames_to_char_ptr_vec_append): Rewrite.
|
||||||
|
* common/gdb_vecs.h (delim_string_to_char_ptr_vec): Declare.
|
||||||
|
|
||||||
2014-01-17 Doug Evans <dje@google.com>
|
2014-01-17 Doug Evans <dje@google.com>
|
||||||
|
|
||||||
* common/common-utils.h (FUNCTION_NAME): Renamed from ASSERT_FUNCTION,
|
* common/common-utils.h (FUNCTION_NAME): Renamed from ASSERT_FUNCTION,
|
||||||
|
|
|
@ -44,6 +44,52 @@ free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec)
|
||||||
VEC_free (char_ptr, char_ptr_vec);
|
VEC_free (char_ptr, char_ptr_vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Worker function to split character delimiter separated string of fields
|
||||||
|
STR into a CHAR_PTR_VEC. */
|
||||||
|
|
||||||
|
static void
|
||||||
|
delim_string_to_char_ptr_vec_append (VEC (char_ptr) **vecp,
|
||||||
|
const char *str, char delimiter)
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
size_t this_len;
|
||||||
|
char *next_field, *this_field;
|
||||||
|
|
||||||
|
next_field = strchr (str, delimiter);
|
||||||
|
if (next_field == NULL)
|
||||||
|
this_len = strlen (str);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this_len = next_field - str;
|
||||||
|
next_field++;
|
||||||
|
}
|
||||||
|
|
||||||
|
this_field = xmalloc (this_len + 1);
|
||||||
|
memcpy (this_field, str, this_len);
|
||||||
|
this_field[this_len] = '\0';
|
||||||
|
VEC_safe_push (char_ptr, *vecp, this_field);
|
||||||
|
|
||||||
|
str = next_field;
|
||||||
|
}
|
||||||
|
while (str != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Split STR, a list of DELIMITER-separated fields, into a CHAR_PTR_VEC.
|
||||||
|
|
||||||
|
You may modify the returned strings.
|
||||||
|
Read free_char_ptr_vec for its cleanup. */
|
||||||
|
|
||||||
|
VEC (char_ptr) *
|
||||||
|
delim_string_to_char_ptr_vec (const char *str, char delimiter)
|
||||||
|
{
|
||||||
|
VEC (char_ptr) *retval = NULL;
|
||||||
|
|
||||||
|
delim_string_to_char_ptr_vec_append (&retval, str, delimiter);
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
/* Extended version of dirnames_to_char_ptr_vec - additionally if *VECP is
|
/* Extended version of dirnames_to_char_ptr_vec - additionally if *VECP is
|
||||||
non-NULL the new list elements from DIRNAMES are appended to the existing
|
non-NULL the new list elements from DIRNAMES are appended to the existing
|
||||||
*VECP list of entries. *VECP address will be updated by this call. */
|
*VECP list of entries. *VECP address will be updated by this call. */
|
||||||
|
@ -51,28 +97,7 @@ free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec)
|
||||||
void
|
void
|
||||||
dirnames_to_char_ptr_vec_append (VEC (char_ptr) **vecp, const char *dirnames)
|
dirnames_to_char_ptr_vec_append (VEC (char_ptr) **vecp, const char *dirnames)
|
||||||
{
|
{
|
||||||
do
|
delim_string_to_char_ptr_vec_append (vecp, dirnames, DIRNAME_SEPARATOR);
|
||||||
{
|
|
||||||
size_t this_len;
|
|
||||||
char *next_dir, *this_dir;
|
|
||||||
|
|
||||||
next_dir = strchr (dirnames, DIRNAME_SEPARATOR);
|
|
||||||
if (next_dir == NULL)
|
|
||||||
this_len = strlen (dirnames);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this_len = next_dir - dirnames;
|
|
||||||
next_dir++;
|
|
||||||
}
|
|
||||||
|
|
||||||
this_dir = xmalloc (this_len + 1);
|
|
||||||
memcpy (this_dir, dirnames, this_len);
|
|
||||||
this_dir[this_len] = '\0';
|
|
||||||
VEC_safe_push (char_ptr, *vecp, this_dir);
|
|
||||||
|
|
||||||
dirnames = next_dir;
|
|
||||||
}
|
|
||||||
while (dirnames != NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Split DIRNAMES by DIRNAME_SEPARATOR delimiter and return a list of all the
|
/* Split DIRNAMES by DIRNAME_SEPARATOR delimiter and return a list of all the
|
||||||
|
|
|
@ -36,6 +36,9 @@ extern void free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec);
|
||||||
extern struct cleanup *
|
extern struct cleanup *
|
||||||
make_cleanup_free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec);
|
make_cleanup_free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec);
|
||||||
|
|
||||||
|
extern VEC (char_ptr) *delim_string_to_char_ptr_vec (const char *str,
|
||||||
|
char delimiter);
|
||||||
|
|
||||||
extern void dirnames_to_char_ptr_vec_append (VEC (char_ptr) **vecp,
|
extern void dirnames_to_char_ptr_vec_append (VEC (char_ptr) **vecp,
|
||||||
const char *dirnames);
|
const char *dirnames);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue