aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli/cli-decode.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2012-06-13 15:47:16 +0000
committerTom Tromey <tromey@redhat.com>2012-06-13 15:47:16 +0000
commit49c4e619f81a66545e2332dc218d9bf31bbb51ad (patch)
tree7eb2c5e41613a35d7030005bbc19bb23414065ed /gdb/cli/cli-decode.c
parent625e8578d7514d65901421467d2b6f0f5d87f634 (diff)
downloadgdb-49c4e619f81a66545e2332dc218d9bf31bbb51ad.zip
gdb-49c4e619f81a66545e2332dc218d9bf31bbb51ad.tar.gz
gdb-49c4e619f81a66545e2332dc218d9bf31bbb51ad.tar.bz2
* ada-lang.c (ada_make_symbol_completion_list): Return a VEC.
* breakpoint.c (catch_syscall_completer): Return a VEC. * cli/cli-cmds.c (complete_command): Update. * cli/cli-decode.c (complete_on_cmdlist): Return a VEC. (complete_on_enum): Likewise. * command.h: Include gdb_vecs.h. (completer_ftype): Change return type. (complete_on_cmdlist, complete_on_enum): Likewise. * completer.c (noop_completer, filename_completer) (location_completer): Return a VEC. (add_struct_fields): Remove 'nextp' argument. Change 'output' to a VEC. (expression_completer, complete_line_internal, complete_line) (command_completer): Return a VEC. (gdb_completion_word_break_characters, line_completion_function): Update. * completer.h: Include gdb_vecs.h. (complete_line, noop_completer, filename_completer) (expression_completer, location_completer, command_completer): Update. * f-lang.c (f_word_break_characters): Return a VEC. * interps.c (interpreter_completer): Return a VEC. * language.h (struct language_defn) <la_make_symbol_completion_list>: Return a VEC. * python/py-cmd.c (cmdpy_completer): Return a VEC. * symtab.c (free_completion_list): Take a VEC. (return_val_size, return_val_index): Remove. (return_val): Now a VEC. (completion_list_add_name): Update. (default_make_symbol_completion_list_break_on) (default_make_symbol_completion_list, make_symbol_completion_list) (make_symbol_completion_list_fn, make_file_symbol_completion_list): Return a VEC. (add_filename_to_list): Update. (struct add_partial_filename_data) <list_used, list_alloced>: Remove. <list>: Now a VEC. (maybe_add_partial_symtab_filename): Update. (make_source_files_completion_list): Return a VEC. * symtab.h (default_make_symbol_completion_list_break_on) (default_make_symbol_completion_list, make_symbol_completion_list) (make_symbol_completion_list_fn, make_file_symbol_completion_list) (make_source_files_completion_list): Update.
Diffstat (limited to 'gdb/cli/cli-decode.c')
-rw-r--r--gdb/cli/cli-decode.c94
1 files changed, 22 insertions, 72 deletions
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 2974d11..c337b43 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -1637,26 +1637,20 @@ lookup_cmd_composition (char *text,
"foo" and we want to complete to "foobar". If WORD is "oo", return
"oobar"; if WORD is "baz/foo", return "baz/foobar". */
-char **
+VEC (char_ptr) *
complete_on_cmdlist (struct cmd_list_element *list, char *text, char *word)
{
struct cmd_list_element *ptr;
- char **matchlist;
- int sizeof_matchlist;
- int matches;
+ VEC (char_ptr) *matchlist = NULL;
int textlen = strlen (text);
int pass;
int saw_deprecated_match = 0;
- sizeof_matchlist = 10;
- matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));
- matches = 0;
-
/* We do one or two passes. In the first pass, we skip deprecated
commands. If we see no matching commands in the first pass, and
if we did happen to see a matching deprecated command, we do
another loop to collect those. */
- for (pass = 0; matches == 0 && pass < 2; ++pass)
+ for (pass = 0; matchlist == 0 && pass < 2; ++pass)
{
for (ptr = list; ptr; ptr = ptr->next)
if (!strncmp (ptr->name, text, textlen)
@@ -1664,6 +1658,8 @@ complete_on_cmdlist (struct cmd_list_element *list, char *text, char *word)
&& (ptr->func
|| ptr->prefixlist))
{
+ char *match;
+
if (pass == 0)
{
if ((ptr->flags & CMD_DEPRECATED) != 0)
@@ -1673,31 +1669,22 @@ complete_on_cmdlist (struct cmd_list_element *list, char *text, char *word)
}
}
- if (matches == sizeof_matchlist)
- {
- sizeof_matchlist *= 2;
- matchlist = (char **) xrealloc ((char *) matchlist,
- (sizeof_matchlist
- * sizeof (char *)));
- }
-
- matchlist[matches] = (char *)
- xmalloc (strlen (word) + strlen (ptr->name) + 1);
+ match = (char *) xmalloc (strlen (word) + strlen (ptr->name) + 1);
if (word == text)
- strcpy (matchlist[matches], ptr->name);
+ strcpy (match, ptr->name);
else if (word > text)
{
/* Return some portion of ptr->name. */
- strcpy (matchlist[matches], ptr->name + (word - text));
+ strcpy (match, ptr->name + (word - text));
}
else
{
/* Return some of text plus ptr->name. */
- strncpy (matchlist[matches], word, text - word);
- matchlist[matches][text - word] = '\0';
- strcat (matchlist[matches], ptr->name);
+ strncpy (match, word, text - word);
+ match[text - word] = '\0';
+ strcat (match, ptr->name);
}
- ++matches;
+ VEC_safe_push (char_ptr, matchlist, match);
}
/* If we saw no matching deprecated commands in the first pass,
just bail out. */
@@ -1705,18 +1692,6 @@ complete_on_cmdlist (struct cmd_list_element *list, char *text, char *word)
break;
}
- if (matches == 0)
- {
- xfree (matchlist);
- matchlist = 0;
- }
- else
- {
- matchlist = (char **) xrealloc ((char *) matchlist, ((matches + 1)
- * sizeof (char *)));
- matchlist[matches] = (char *) 0;
- }
-
return matchlist;
}
@@ -1730,64 +1705,39 @@ complete_on_cmdlist (struct cmd_list_element *list, char *text, char *word)
and we want to complete to "foobar". If WORD is "oo", return
"oobar"; if WORD is "baz/foo", return "baz/foobar". */
-char **
+VEC (char_ptr) *
complete_on_enum (const char *const *enumlist,
char *text,
char *word)
{
- char **matchlist;
- int sizeof_matchlist;
- int matches;
+ VEC (char_ptr) *matchlist = NULL;
int textlen = strlen (text);
int i;
const char *name;
- sizeof_matchlist = 10;
- matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));
- matches = 0;
-
for (i = 0; (name = enumlist[i]) != NULL; i++)
if (strncmp (name, text, textlen) == 0)
{
- if (matches == sizeof_matchlist)
- {
- sizeof_matchlist *= 2;
- matchlist = (char **) xrealloc ((char *) matchlist,
- (sizeof_matchlist
- * sizeof (char *)));
- }
+ char *match;
- matchlist[matches] = (char *)
- xmalloc (strlen (word) + strlen (name) + 1);
+ match = (char *) xmalloc (strlen (word) + strlen (name) + 1);
if (word == text)
- strcpy (matchlist[matches], name);
+ strcpy (match, name);
else if (word > text)
{
/* Return some portion of name. */
- strcpy (matchlist[matches], name + (word - text));
+ strcpy (match, name + (word - text));
}
else
{
/* Return some of text plus name. */
- strncpy (matchlist[matches], word, text - word);
- matchlist[matches][text - word] = '\0';
- strcat (matchlist[matches], name);
+ strncpy (match, word, text - word);
+ match[text - word] = '\0';
+ strcat (match, name);
}
- ++matches;
+ VEC_safe_push (char_ptr, matchlist, match);
}
- if (matches == 0)
- {
- xfree (matchlist);
- matchlist = 0;
- }
- else
- {
- matchlist = (char **) xrealloc ((char *) matchlist, ((matches + 1)
- * sizeof (char *)));
- matchlist[matches] = (char *) 0;
- }
-
return matchlist;
}