diff options
author | Tom Tromey <tromey@redhat.com> | 2012-06-13 15:47:16 +0000 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2012-06-13 15:47:16 +0000 |
commit | 49c4e619f81a66545e2332dc218d9bf31bbb51ad (patch) | |
tree | 7eb2c5e41613a35d7030005bbc19bb23414065ed /gdb/cli | |
parent | 625e8578d7514d65901421467d2b6f0f5d87f634 (diff) | |
download | gdb-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')
-rw-r--r-- | gdb/cli/cli-cmds.c | 32 | ||||
-rw-r--r-- | gdb/cli/cli-decode.c | 94 |
2 files changed, 37 insertions, 89 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index e5fa206..24d55c3 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -254,7 +254,8 @@ static void complete_command (char *arg, int from_tty) { int argpoint; - char **completions, *point, *arg_prefix; + char *point, *arg_prefix; + VEC (char_ptr) *completions; dont_repeat (); @@ -282,33 +283,30 @@ complete_command (char *arg, int from_tty) if (completions) { - int item, size; + int ix, size = VEC_length (char_ptr, completions); + char *item, *prev = NULL; - for (size = 0; completions[size]; ++size) - ; - qsort (completions, size, sizeof (char *), compare_strings); + qsort (VEC_address (char_ptr, completions), size, + sizeof (char *), compare_strings); /* We do extra processing here since we only want to print each unique item once. */ - item = 0; - while (item < size) + for (ix = 0; VEC_iterate (char_ptr, completions, ix, item); ++ix) { int next_item; - printf_unfiltered ("%s%s\n", arg_prefix, completions[item]); - next_item = item + 1; - while (next_item < size - && ! strcmp (completions[item], completions[next_item])) + if (prev == NULL || strcmp (item, prev) != 0) { - xfree (completions[next_item]); - ++next_item; + printf_unfiltered ("%s%s\n", arg_prefix, item); + xfree (prev); + prev = item; } - - xfree (completions[item]); - item = next_item; + else + xfree (item); } - xfree (completions); + xfree (prev); + VEC_free (char_ptr, completions); } } 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; } |