2012-07-19 07:37:58 +08:00
|
|
|
/* Some commonly-used VEC types.
|
|
|
|
|
2021-01-01 16:03:39 +08:00
|
|
|
Copyright (C) 2012-2021 Free Software Foundation, Inc.
|
2012-07-19 07:37:58 +08:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
2014-09-12 17:11:42 +08:00
|
|
|
#include "common-defs.h"
|
2012-07-19 07:37:58 +08:00
|
|
|
#include "gdb_vecs.h"
|
|
|
|
#include "host-defs.h"
|
|
|
|
|
2014-01-18 02:23:29 +08:00
|
|
|
/* Worker function to split character delimiter separated string of fields
|
2018-03-03 12:22:06 +08:00
|
|
|
STR into a char pointer vector. */
|
2012-07-19 07:37:58 +08:00
|
|
|
|
2014-01-18 02:23:29 +08:00
|
|
|
static void
|
2018-03-03 12:22:06 +08:00
|
|
|
delim_string_to_char_ptr_vec_append
|
|
|
|
(std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *str,
|
|
|
|
char delimiter)
|
2012-07-19 07:37:58 +08:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
size_t this_len;
|
2015-10-14 02:40:50 +08:00
|
|
|
const char *next_field;
|
|
|
|
char *this_field;
|
2012-07-19 07:37:58 +08:00
|
|
|
|
2014-01-18 02:23:29 +08:00
|
|
|
next_field = strchr (str, delimiter);
|
|
|
|
if (next_field == NULL)
|
|
|
|
this_len = strlen (str);
|
2012-07-19 07:37:58 +08:00
|
|
|
else
|
|
|
|
{
|
2014-01-18 02:23:29 +08:00
|
|
|
this_len = next_field - str;
|
|
|
|
next_field++;
|
2012-07-19 07:37:58 +08:00
|
|
|
}
|
|
|
|
|
2015-09-26 02:08:06 +08:00
|
|
|
this_field = (char *) xmalloc (this_len + 1);
|
2014-01-18 02:23:29 +08:00
|
|
|
memcpy (this_field, str, this_len);
|
|
|
|
this_field[this_len] = '\0';
|
2018-03-03 12:22:06 +08:00
|
|
|
vecp->emplace_back (this_field);
|
2012-07-19 07:37:58 +08:00
|
|
|
|
2014-01-18 02:23:29 +08:00
|
|
|
str = next_field;
|
2012-07-19 07:37:58 +08:00
|
|
|
}
|
2014-01-18 02:23:29 +08:00
|
|
|
while (str != NULL);
|
|
|
|
}
|
|
|
|
|
2018-03-03 12:22:06 +08:00
|
|
|
/* See gdb_vecs.h. */
|
2014-01-18 02:23:29 +08:00
|
|
|
|
2018-03-03 12:22:06 +08:00
|
|
|
std::vector<gdb::unique_xmalloc_ptr<char>>
|
2014-01-18 02:23:29 +08:00
|
|
|
delim_string_to_char_ptr_vec (const char *str, char delimiter)
|
|
|
|
{
|
2018-03-03 12:22:06 +08:00
|
|
|
std::vector<gdb::unique_xmalloc_ptr<char>> retval;
|
2014-01-18 02:23:29 +08:00
|
|
|
|
|
|
|
delim_string_to_char_ptr_vec_append (&retval, str, delimiter);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2018-03-03 12:22:06 +08:00
|
|
|
/* See gdb_vecs.h. */
|
2014-01-18 02:23:29 +08:00
|
|
|
|
|
|
|
void
|
2018-03-03 12:22:06 +08:00
|
|
|
dirnames_to_char_ptr_vec_append
|
|
|
|
(std::vector<gdb::unique_xmalloc_ptr<char>> *vecp, const char *dirnames)
|
2014-01-18 02:23:29 +08:00
|
|
|
{
|
|
|
|
delim_string_to_char_ptr_vec_append (vecp, dirnames, DIRNAME_SEPARATOR);
|
2012-07-19 07:37:58 +08:00
|
|
|
}
|
|
|
|
|
2018-03-03 12:22:06 +08:00
|
|
|
/* See gdb_vecs.h. */
|
2012-07-19 07:37:58 +08:00
|
|
|
|
2018-03-03 12:22:06 +08:00
|
|
|
std::vector<gdb::unique_xmalloc_ptr<char>>
|
2012-07-19 07:37:58 +08:00
|
|
|
dirnames_to_char_ptr_vec (const char *dirnames)
|
|
|
|
{
|
2018-03-03 12:22:06 +08:00
|
|
|
std::vector<gdb::unique_xmalloc_ptr<char>> retval;
|
2012-07-19 07:37:58 +08:00
|
|
|
|
|
|
|
dirnames_to_char_ptr_vec_append (&retval, dirnames);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|