[PATCH v3 03/19] Implement completion-limiting for complete_on_cmdlist.

Keith Seitz
2015-08-06T22:36:23Z

Differences in this revision:

1. Remove partial copy code from complete_on_cmdlist.

---

This is the first of a series of smaller patches to switch over
all completion functions to using add_completion to add
completions to the completion list to be presented to the user.

Note that in order to verify that this patch works as intended,
one must override the backup completion counting in complete_line.
[This backup code will be permanently removed in a later patch.]
During testing, I have verified all patches with this planned code
removal to verify that it works.

First up is complete_on_cmdlist. Completion-limiting is already tested
in gdb.base/completion.exp, so there are no new tests.

gdb/ChangeLog

* cli/cli-decode.c (complete_on_cmdlist): Use add_completion
to determine whether to continue looking for completions.
---
gdb/cli/cli-decode.c | 21 +++------------------
1 file changed, 3 insertions(+), 18 deletions(-)

diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 3415b77..3cecc90 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -1789,8 +1789,6 @@ complete_on_cmdlist (struct completer_data *cdata,
&& (!ignore_help_classes || ptr->func
|| ptr->prefixlist))
{
- char *match;
-
if (pass == 0)
{
if (ptr->cmd_deprecated)
@@ -1800,22 +1798,9 @@ complete_on_cmdlist (struct completer_data *cdata,
}
}

- match = (char *) xmalloc (strlen (word) + strlen (ptr->name) + 1);
- if (word == text)
- strcpy (match, ptr->name);
- else if (word > text)
- {
- /* Return some portion of ptr->name. */
- strcpy (match, ptr->name + (word - text));
- }
- else
- {
- /* Return some of text plus ptr->name. */
- strncpy (match, word, text - word);
- match[text - word] = '\0';
- strcat (match, ptr->name);
- }
- VEC_safe_push (char_ptr, matchlist, match);
+ if (add_completion (cdata, &matchlist, ptr->name, text, word)
+ == ADD_COMPLETION_MAX_REACHED)
+ return matchlist;
}
/* If we saw no matching deprecated commands in the first pass,
just bail out. */