Introduce class completion_tracker & rewrite completion<->readline interaction
[deliverable/binutils-gdb.git] / gdb / cli / cli-decode.c
index 064b481f9fda003a8e077d0d052ff9c4a8e0dc36..1bbbe46c3c1a60b1bf3f1c1b83ecdf03e76e38a3 100644 (file)
@@ -657,8 +657,9 @@ add_setshow_optional_filename_cmd (const char *name, enum command_class theclass
 /* Completes on literal "unlimited".  Used by integer commands that
    support a special "unlimited" value.  */
 
-static VEC (char_ptr) *
+static void
 integer_unlimited_completer (struct cmd_list_element *ignore,
+                            completion_tracker &tracker,
                             const char *text, const char *word)
 {
   static const char * const keywords[] =
@@ -667,7 +668,7 @@ integer_unlimited_completer (struct cmd_list_element *ignore,
       NULL,
     };
 
-  return complete_on_enum (keywords, text, word);
+  complete_on_enum (tracker, keywords, text, word);
 }
 
 /* Add element named NAME to both the set and show command LISTs (the
@@ -1771,13 +1772,13 @@ lookup_cmd_composition (const char *text,
    "foo" and we want to complete to "foobar".  If WORD is "oo", return
    "oobar"; if WORD is "baz/foo", return "baz/foobar".  */
 
-VEC (char_ptr) *
+void
 complete_on_cmdlist (struct cmd_list_element *list,
+                    completion_tracker &tracker,
                     const char *text, const char *word,
                     int ignore_help_classes)
 {
   struct cmd_list_element *ptr;
-  VEC (char_ptr) *matchlist = NULL;
   int textlen = strlen (text);
   int pass;
   int saw_deprecated_match = 0;
@@ -1786,8 +1787,10 @@ complete_on_cmdlist (struct cmd_list_element *list,
      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; matchlist == 0 && pass < 2; ++pass)
+  for (pass = 0; pass < 2; ++pass)
     {
+      bool got_matches = false;
+
       for (ptr = list; ptr; ptr = ptr->next)
        if (!strncmp (ptr->name, text, textlen)
            && !ptr->abbrev_flag
@@ -1820,32 +1823,34 @@ complete_on_cmdlist (struct cmd_list_element *list,
                match[text - word] = '\0';
                strcat (match, ptr->name);
              }
-           VEC_safe_push (char_ptr, matchlist, match);
+           tracker.add_completion (gdb::unique_xmalloc_ptr<char> (match));
+           got_matches = true;
          }
+
+      if (got_matches)
+       break;
+
       /* If we saw no matching deprecated commands in the first pass,
         just bail out.  */
       if (!saw_deprecated_match)
        break;
     }
-
-  return matchlist;
 }
 
 /* Helper function for SYMBOL_COMPLETION_FUNCTION.  */
 
-/* Return a vector of char pointers which point to the different
-   possible completions in CMD of TEXT.
+/* Add the different possible completions in ENUMLIST of TEXT.
 
    WORD points in the same buffer as TEXT, and completions should be
    returned relative to this position.  For example, suppose TEXT is "foo"
    and we want to complete to "foobar".  If WORD is "oo", return
    "oobar"; if WORD is "baz/foo", return "baz/foobar".  */
 
-VEC (char_ptr) *
-complete_on_enum (const char *const *enumlist,
+void
+complete_on_enum (completion_tracker &tracker,
+                 const char *const *enumlist,
                  const char *text, const char *word)
 {
-  VEC (char_ptr) *matchlist = NULL;
   int textlen = strlen (text);
   int i;
   const char *name;
@@ -1870,10 +1875,8 @@ complete_on_enum (const char *const *enumlist,
            match[text - word] = '\0';
            strcat (match, name);
          }
-       VEC_safe_push (char_ptr, matchlist, match);
+       tracker.add_completion (gdb::unique_xmalloc_ptr<char> (match));
       }
-
-  return matchlist;
 }
 
 
This page took 0.026018 seconds and 4 git commands to generate.