aboutsummaryrefslogtreecommitdiff
path: root/gdb/common/gdb_vecs.c
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2014-01-17 10:23:29 -0800
committerDoug Evans <dje@google.com>2014-01-17 10:23:29 -0800
commit749234e5402bddc054d77b4113ecd09eda7a872e (patch)
tree34e289742a937a28e8854e849bdb58c6fc76a2ea /gdb/common/gdb_vecs.c
parentdf049a5831c7c573698b98bfd4bc0ec8dc854c1f (diff)
downloadgdb-749234e5402bddc054d77b4113ecd09eda7a872e.zip
gdb-749234e5402bddc054d77b4113ecd09eda7a872e.tar.gz
gdb-749234e5402bddc054d77b4113ecd09eda7a872e.tar.bz2
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.
Diffstat (limited to 'gdb/common/gdb_vecs.c')
-rw-r--r--gdb/common/gdb_vecs.c59
1 files changed, 42 insertions, 17 deletions
diff --git a/gdb/common/gdb_vecs.c b/gdb/common/gdb_vecs.c
index b256986..4a3330f 100644
--- a/gdb/common/gdb_vecs.c
+++ b/gdb/common/gdb_vecs.c
@@ -44,35 +44,60 @@ free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec)
VEC_free (char_ptr, char_ptr_vec);
}
-/* 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
- *VECP list of entries. *VECP address will be updated by this call. */
+/* Worker function to split character delimiter separated string of fields
+ STR into a CHAR_PTR_VEC. */
-void
-dirnames_to_char_ptr_vec_append (VEC (char_ptr) **vecp, const char *dirnames)
+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_dir, *this_dir;
+ char *next_field, *this_field;
- next_dir = strchr (dirnames, DIRNAME_SEPARATOR);
- if (next_dir == NULL)
- this_len = strlen (dirnames);
+ next_field = strchr (str, delimiter);
+ if (next_field == NULL)
+ this_len = strlen (str);
else
{
- this_len = next_dir - dirnames;
- next_dir++;
+ this_len = next_field - str;
+ next_field++;
}
- 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);
+ 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);
- dirnames = next_dir;
+ str = next_field;
}
- while (dirnames != NULL);
+ 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
+ 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. */
+
+void
+dirnames_to_char_ptr_vec_append (VEC (char_ptr) **vecp, const char *dirnames)
+{
+ delim_string_to_char_ptr_vec_append (vecp, dirnames, DIRNAME_SEPARATOR);
}
/* Split DIRNAMES by DIRNAME_SEPARATOR delimiter and return a list of all the