1 /* Some commonly-used VEC types.
3 Copyright (C) 2012-2016 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "common-defs.h"
22 #include "host-defs.h"
24 /* Call xfree for each element of CHAR_PTR_VEC and final VEC_free for
27 You must not modify CHAR_PTR_VEC after it got registered with this function
28 by make_cleanup as the CHAR_PTR_VEC base address may change on its updates.
29 Contrary to VEC_free this function does not (cannot) clear the pointer. */
32 free_char_ptr_vec (VEC (char_ptr
) *char_ptr_vec
)
37 for (ix
= 0; VEC_iterate (char_ptr
, char_ptr_vec
, ix
, name
); ++ix
)
39 VEC_free (char_ptr
, char_ptr_vec
);
42 /* Worker function to split character delimiter separated string of fields
43 STR into a CHAR_PTR_VEC. */
46 delim_string_to_char_ptr_vec_append (VEC (char_ptr
) **vecp
,
47 const char *str
, char delimiter
)
52 const char *next_field
;
55 next_field
= strchr (str
, delimiter
);
56 if (next_field
== NULL
)
57 this_len
= strlen (str
);
60 this_len
= next_field
- str
;
64 this_field
= (char *) xmalloc (this_len
+ 1);
65 memcpy (this_field
, str
, this_len
);
66 this_field
[this_len
] = '\0';
67 VEC_safe_push (char_ptr
, *vecp
, this_field
);
74 /* Split STR, a list of DELIMITER-separated fields, into a CHAR_PTR_VEC.
76 You may modify the returned strings.
77 Read free_char_ptr_vec for its cleanup. */
80 delim_string_to_char_ptr_vec (const char *str
, char delimiter
)
82 VEC (char_ptr
) *retval
= NULL
;
84 delim_string_to_char_ptr_vec_append (&retval
, str
, delimiter
);
89 /* Extended version of dirnames_to_char_ptr_vec - additionally if *VECP is
90 non-NULL the new list elements from DIRNAMES are appended to the existing
91 *VECP list of entries. *VECP address will be updated by this call. */
94 dirnames_to_char_ptr_vec_append (VEC (char_ptr
) **vecp
, const char *dirnames
)
96 delim_string_to_char_ptr_vec_append (vecp
, dirnames
, DIRNAME_SEPARATOR
);
99 /* Split DIRNAMES by DIRNAME_SEPARATOR delimiter and return a list of all the
100 elements in their original order. For empty string ("") DIRNAMES return
101 list of one empty string ("") element.
103 You may modify the returned strings.
104 Read free_char_ptr_vec for its cleanup. */
107 dirnames_to_char_ptr_vec (const char *dirnames
)
109 VEC (char_ptr
) *retval
= NULL
;
111 dirnames_to_char_ptr_vec_append (&retval
, dirnames
);
This page took 0.032398 seconds and 4 git commands to generate.