boolean/auto-boolean commands, make "o" ambiguous
[deliverable/binutils-gdb.git] / gdb / cli / cli-decode.c
index 87ebed5f6e2769ee4fae3ffa1181bf60f6403534..30f79b5259df5d15569eeb1d971970551d15ec0f 100644 (file)
@@ -1,6 +1,6 @@
 /* Handle lists of commands, their decoding and documentation, for GDB.
 
-   Copyright (C) 1986-2017 Free Software Foundation, Inc.
+   Copyright (C) 1986-2019 Free Software Foundation, Inc.
 
    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
@@ -23,6 +23,7 @@
 #include "ui-out.h"
 #include "cli/cli-cmds.h"
 #include "cli/cli-decode.h"
+#include "cli/cli-style.h"
 #include "common/gdb_optional.h"
 
 /* Prototypes for local functions.  */
@@ -101,28 +102,12 @@ print_help_for_command (struct cmd_list_element *c, const char *prefix,
    bounce function (unless cfunc / sfunc is NULL that is).  */
 
 static void
-do_cfunc (struct cmd_list_element *c, char *args, int from_tty)
-{
-  c->function.cfunc (args, from_tty);
-}
-
-void
-set_cmd_cfunc (struct cmd_list_element *cmd, cmd_cfunc_ftype *cfunc)
-{
-  if (cfunc == NULL)
-    cmd->func = NULL;
-  else
-    cmd->func = do_cfunc;
-  cmd->function.cfunc = cfunc;
-}
-
-static void
-do_const_cfunc (struct cmd_list_element *c, char *args, int from_tty)
+do_const_cfunc (struct cmd_list_element *c, const char *args, int from_tty)
 {
   c->function.const_cfunc (args, from_tty);
 }
 
-void
+static void
 set_cmd_cfunc (struct cmd_list_element *cmd, cmd_const_cfunc_ftype *cfunc)
 {
   if (cfunc == NULL)
@@ -133,13 +118,13 @@ set_cmd_cfunc (struct cmd_list_element *cmd, cmd_const_cfunc_ftype *cfunc)
 }
 
 static void
-do_sfunc (struct cmd_list_element *c, char *args, int from_tty)
+do_sfunc (struct cmd_list_element *c, const char *args, int from_tty)
 {
   c->function.sfunc (args, from_tty, c);
 }
 
 void
-set_cmd_sfunc (struct cmd_list_element *cmd, cmd_sfunc_ftype *sfunc)
+set_cmd_sfunc (struct cmd_list_element *cmd, cmd_const_sfunc_ftype *sfunc)
 {
   if (sfunc == NULL)
     cmd->func = NULL;
@@ -148,12 +133,6 @@ set_cmd_sfunc (struct cmd_list_element *cmd, cmd_sfunc_ftype *sfunc)
   cmd->function.sfunc = sfunc;
 }
 
-int
-cmd_cfunc_eq (struct cmd_list_element *cmd, cmd_cfunc_ftype *cfunc)
-{
-  return cmd->func == do_cfunc && cmd->function.cfunc == cfunc;
-}
-
 int
 cmd_cfunc_eq (struct cmd_list_element *cmd, cmd_const_cfunc_ftype *cfunc)
 {
@@ -215,7 +194,8 @@ static struct cmd_list_element *
 do_add_cmd (const char *name, enum command_class theclass,
            const char *doc, struct cmd_list_element **list)
 {
-  struct cmd_list_element *c = XNEW (struct cmd_list_element);
+  struct cmd_list_element *c = new struct cmd_list_element (name, theclass,
+                                                           doc);
   struct cmd_list_element *p, *iter;
 
   /* Turn each alias of the old command into an alias of the new
@@ -249,53 +229,16 @@ do_add_cmd (const char *name, enum command_class theclass,
       p->next = c;
     }
 
-  c->name = name;
-  c->theclass = theclass;
-  set_cmd_context (c, NULL);
-  c->doc = doc;
-  c->cmd_deprecated = 0;
-  c->deprecated_warn_user = 0;
-  c->malloced_replacement = 0;
-  c->doc_allocated = 0;
-  c->replacement = NULL;
-  c->pre_show_hook = NULL;
-  c->hook_in = 0;
-  c->prefixlist = NULL;
-  c->prefixname = NULL;
-  c->allow_unknown = 0;
-  c->prefix = NULL;
-  c->abbrev_flag = 0;
-  set_cmd_completer (c, symbol_completer);
-  c->completer_handle_brkchars = NULL;
-  c->destroyer = NULL;
-  c->type = not_set_cmd;
-  c->var = NULL;
-  c->var_type = var_boolean;
-  c->enums = NULL;
-  c->user_commands = NULL;
-  c->cmd_pointer = NULL;
-  c->alias_chain = NULL;
-  c->suppress_notification = NULL;
-
   return c;
 }
 
-struct cmd_list_element *
-add_cmd (const char *name, enum command_class theclass, cmd_cfunc_ftype *fun,
-        const char *doc, struct cmd_list_element **list)
-{
-  cmd_list_element *result = do_add_cmd (name, theclass, doc, list);
-  set_cmd_cfunc (result, fun);
-  return result;
-}
-
 struct cmd_list_element *
 add_cmd (const char *name, enum command_class theclass,
         const char *doc, struct cmd_list_element **list)
 {
   cmd_list_element *result = do_add_cmd (name, theclass, doc, list);
   result->func = NULL;
-  result->function.cfunc = NULL; /* Ok.  */
+  result->function.const_cfunc = NULL;
   return result;
 }
 
@@ -309,6 +252,23 @@ add_cmd (const char *name, enum command_class theclass,
   return result;
 }
 
+/* Add an element with a suppress notification to the LIST of commands.  */
+
+struct cmd_list_element *
+add_cmd_suppress_notification (const char *name, enum command_class theclass,
+                              cmd_const_cfunc_ftype *fun, const char *doc,
+                              struct cmd_list_element **list,
+                              int *suppress_notification)
+{
+  struct cmd_list_element *element;
+
+  element = add_cmd (name, theclass, fun, doc, list);
+  element->suppress_notification = suppress_notification;
+
+  return element;
+}
+
+
 /* Deprecates a command CMD.
    REPLACEMENT is the name of the command which should be used in
    place of this command, or NULL if no such command exists.
@@ -420,11 +380,30 @@ add_prefix_cmd (const char *name, enum command_class theclass,
   return c;
 }
 
+/* Like ADD_PREFIX_CMD but sets the suppress_notification pointer on the
+   new command list element.  */
+
+struct cmd_list_element *
+add_prefix_cmd_suppress_notification
+               (const char *name, enum command_class theclass,
+               cmd_const_cfunc_ftype *fun,
+               const char *doc, struct cmd_list_element **prefixlist,
+               const char *prefixname, int allow_unknown,
+               struct cmd_list_element **list,
+               int *suppress_notification)
+{
+  struct cmd_list_element *element
+    = add_prefix_cmd (name, theclass, fun, doc, prefixlist,
+                     prefixname, allow_unknown, list);
+  element->suppress_notification = suppress_notification;
+  return element;
+}
+
 /* Like add_prefix_cmd but sets the abbrev_flag on the new command.  */
 
 struct cmd_list_element *
 add_abbrev_prefix_cmd (const char *name, enum command_class theclass,
-                      cmd_cfunc_ftype *fun, const char *doc,
+                      cmd_const_cfunc_ftype *fun, const char *doc,
                       struct cmd_list_element **prefixlist,
                       const char *prefixname,
                       int allow_unknown, struct cmd_list_element **list)
@@ -445,10 +424,9 @@ not_just_help_class_command (const char *args, int from_tty)
 }
 
 /* This is an empty "sfunc".  */
-static void empty_sfunc (char *, int, struct cmd_list_element *);
 
 static void
-empty_sfunc (char *args, int from_tty, struct cmd_list_element *c)
+empty_sfunc (const char *args, int from_tty, struct cmd_list_element *c)
 {
 }
 
@@ -496,7 +474,7 @@ add_setshow_cmd_full (const char *name,
                      var_types var_type, void *var,
                      const char *set_doc, const char *show_doc,
                      const char *help_doc,
-                     cmd_sfunc_ftype *set_func,
+                     cmd_const_sfunc_ftype *set_func,
                      show_value_ftype *show_func,
                      struct cmd_list_element **set_list,
                      struct cmd_list_element **show_list,
@@ -531,6 +509,9 @@ add_setshow_cmd_full (const char *name,
                              full_show_doc, show_list);
   show->doc_allocated = 1;
   show->show_value_func = show_func;
+  /* Disable the default symbol completer.  Doesn't make much sense
+     for the "show" command to complete on anything.  */
+  set_cmd_completer (show, nullptr);
 
   if (set_result != NULL)
     *set_result = set;
@@ -551,19 +532,23 @@ add_setshow_enum_cmd (const char *name,
                      const char *set_doc,
                      const char *show_doc,
                      const char *help_doc,
-                     cmd_sfunc_ftype *set_func,
+                     cmd_const_sfunc_ftype *set_func,
                      show_value_ftype *show_func,
                      struct cmd_list_element **set_list,
-                     struct cmd_list_element **show_list)
+                     struct cmd_list_element **show_list,
+                     void *context)
 {
-  struct cmd_list_element *c;
+  struct cmd_list_element *c, *show;
 
   add_setshow_cmd_full (name, theclass, var_enum, var,
                        set_doc, show_doc, help_doc,
                        set_func, show_func,
                        set_list, show_list,
-                       &c, NULL);
+                       &c, &show);
   c->enums = enumlist;
+
+  set_cmd_context (c, context);
+  set_cmd_context (show, context);
 }
 
 const char * const auto_boolean_enums[] = { "on", "off", "auto", NULL };
@@ -578,7 +563,7 @@ add_setshow_auto_boolean_cmd (const char *name,
                              enum auto_boolean *var,
                              const char *set_doc, const char *show_doc,
                              const char *help_doc,
-                             cmd_sfunc_ftype *set_func,
+                             cmd_const_sfunc_ftype *set_func,
                              show_value_ftype *show_func,
                              struct cmd_list_element **set_list,
                              struct cmd_list_element **show_list)
@@ -601,7 +586,7 @@ void
 add_setshow_boolean_cmd (const char *name, enum command_class theclass, int *var,
                         const char *set_doc, const char *show_doc,
                         const char *help_doc,
-                        cmd_sfunc_ftype *set_func,
+                        cmd_const_sfunc_ftype *set_func,
                         show_value_ftype *show_func,
                         struct cmd_list_element **set_list,
                         struct cmd_list_element **show_list)
@@ -624,7 +609,7 @@ add_setshow_filename_cmd (const char *name, enum command_class theclass,
                          char **var,
                          const char *set_doc, const char *show_doc,
                          const char *help_doc,
-                         cmd_sfunc_ftype *set_func,
+                         cmd_const_sfunc_ftype *set_func,
                          show_value_ftype *show_func,
                          struct cmd_list_element **set_list,
                          struct cmd_list_element **show_list)
@@ -646,16 +631,21 @@ add_setshow_string_cmd (const char *name, enum command_class theclass,
                        char **var,
                        const char *set_doc, const char *show_doc,
                        const char *help_doc,
-                       cmd_sfunc_ftype *set_func,
+                       cmd_const_sfunc_ftype *set_func,
                        show_value_ftype *show_func,
                        struct cmd_list_element **set_list,
                        struct cmd_list_element **show_list)
 {
+  cmd_list_element *set_cmd;
+
   add_setshow_cmd_full (name, theclass, var_string, var,
                        set_doc, show_doc, help_doc,
                        set_func, show_func,
                        set_list, show_list,
-                       NULL, NULL);
+                       &set_cmd, NULL);
+
+  /* Disable the default symbol completer.  */
+  set_cmd_completer (set_cmd, nullptr);
 }
 
 /* Add element named NAME to both the set and show command LISTs (the
@@ -665,7 +655,7 @@ add_setshow_string_noescape_cmd (const char *name, enum command_class theclass,
                                 char **var,
                                 const char *set_doc, const char *show_doc,
                                 const char *help_doc,
-                                cmd_sfunc_ftype *set_func,
+                                cmd_const_sfunc_ftype *set_func,
                                 show_value_ftype *show_func,
                                 struct cmd_list_element **set_list,
                                 struct cmd_list_element **show_list)
@@ -677,6 +667,10 @@ add_setshow_string_noescape_cmd (const char *name, enum command_class theclass,
                        set_func, show_func,
                        set_list, show_list,
                        &set_cmd, NULL);
+
+  /* Disable the default symbol completer.  */
+  set_cmd_completer (set_cmd, nullptr);
+
   return set_cmd;
 }
 
@@ -687,7 +681,7 @@ add_setshow_optional_filename_cmd (const char *name, enum command_class theclass
                                   char **var,
                                   const char *set_doc, const char *show_doc,
                                   const char *help_doc,
-                                  cmd_sfunc_ftype *set_func,
+                                  cmd_const_sfunc_ftype *set_func,
                                   show_value_ftype *show_func,
                                   struct cmd_list_element **set_list,
                                   struct cmd_list_element **show_list)
@@ -731,7 +725,7 @@ add_setshow_integer_cmd (const char *name, enum command_class theclass,
                         int *var,
                         const char *set_doc, const char *show_doc,
                         const char *help_doc,
-                        cmd_sfunc_ftype *set_func,
+                        cmd_const_sfunc_ftype *set_func,
                         show_value_ftype *show_func,
                         struct cmd_list_element **set_list,
                         struct cmd_list_element **show_list)
@@ -756,7 +750,7 @@ add_setshow_uinteger_cmd (const char *name, enum command_class theclass,
                          unsigned int *var,
                          const char *set_doc, const char *show_doc,
                          const char *help_doc,
-                         cmd_sfunc_ftype *set_func,
+                         cmd_const_sfunc_ftype *set_func,
                          show_value_ftype *show_func,
                          struct cmd_list_element **set_list,
                          struct cmd_list_element **show_list)
@@ -781,7 +775,7 @@ add_setshow_zinteger_cmd (const char *name, enum command_class theclass,
                          int *var,
                          const char *set_doc, const char *show_doc,
                          const char *help_doc,
-                         cmd_sfunc_ftype *set_func,
+                         cmd_const_sfunc_ftype *set_func,
                          show_value_ftype *show_func,
                          struct cmd_list_element **set_list,
                          struct cmd_list_element **show_list)
@@ -800,7 +794,7 @@ add_setshow_zuinteger_unlimited_cmd (const char *name,
                                     const char *set_doc,
                                     const char *show_doc,
                                     const char *help_doc,
-                                    cmd_sfunc_ftype *set_func,
+                                    cmd_const_sfunc_ftype *set_func,
                                     show_value_ftype *show_func,
                                     struct cmd_list_element **set_list,
                                     struct cmd_list_element **show_list)
@@ -825,7 +819,7 @@ add_setshow_zuinteger_cmd (const char *name, enum command_class theclass,
                           unsigned int *var,
                           const char *set_doc, const char *show_doc,
                           const char *help_doc,
-                          cmd_sfunc_ftype *set_func,
+                          cmd_const_sfunc_ftype *set_func,
                           show_value_ftype *show_func,
                           struct cmd_list_element **set_list,
                           struct cmd_list_element **show_list)
@@ -873,8 +867,6 @@ delete_cmd (const char *name, struct cmd_list_element **list,
          *prehookee = iter->hookee_pre;
          if (iter->hookee_post)
            iter->hookee_post->hook_post = 0;
-         if (iter->doc && iter->doc_allocated)
-           xfree ((char *) iter->doc);
          *posthook = iter->hook_post;
          *posthookee = iter->hookee_post;
 
@@ -898,7 +890,7 @@ delete_cmd (const char *name, struct cmd_list_element **list,
              *prevp = iter->alias_chain;
            }
 
-         xfree (iter);
+         delete iter;
 
          /* We won't see another command with the same name.  */
          break;
@@ -915,7 +907,7 @@ delete_cmd (const char *name, struct cmd_list_element **list,
 /* Add an element to the list of info subcommands.  */
 
 struct cmd_list_element *
-add_info (const char *name, cmd_cfunc_ftype *fun, const char *doc)
+add_info (const char *name, cmd_const_cfunc_ftype *fun, const char *doc)
 {
   return add_cmd (name, class_info, fun, doc, &infolist);
 }
@@ -931,7 +923,8 @@ add_info_alias (const char *name, const char *oldname, int abbrev_flag)
 /* Add an element to the list of commands.  */
 
 struct cmd_list_element *
-add_com (const char *name, enum command_class theclass, cmd_cfunc_ftype *fun,
+add_com (const char *name, enum command_class theclass,
+        cmd_const_cfunc_ftype *fun,
         const char *doc)
 {
   return add_cmd (name, theclass, fun, doc, &cmdlist);
@@ -950,25 +943,49 @@ add_com_alias (const char *name, const char *oldname, enum command_class theclas
 
 struct cmd_list_element *
 add_com_suppress_notification (const char *name, enum command_class theclass,
-                              cmd_cfunc_ftype *fun, const char *doc,
+                              cmd_const_cfunc_ftype *fun, const char *doc,
                               int *suppress_notification)
 {
-  struct cmd_list_element *element;
+  return add_cmd_suppress_notification (name, theclass, fun, doc,
+                                       &cmdlist, suppress_notification);
+}
 
-  element = add_cmd (name, theclass, fun, doc, &cmdlist);
-  element->suppress_notification = suppress_notification;
+/* If VERBOSE, print the full help for command C and highlight the
+   documentation parts matching HIGHLIGHT,
+   otherwise print only one-line help for command C.  */
 
-  return element;
+static void
+print_doc_of_command (struct cmd_list_element *c, const char *prefix,
+                     bool verbose, compiled_regex &highlight,
+                     struct ui_file *stream)
+{
+  /* When printing the full documentation, add a line to separate
+     this documentation from the previous command help, in the likely
+     case that apropos finds several commands.  */
+  if (verbose)
+    fputs_filtered ("\n", stream);
+
+  fprintf_styled (stream, title_style.style (),
+                 "%s%s", prefix, c->name);
+  fputs_filtered (" -- ", stream);
+  if (verbose)
+    fputs_highlighted (c->doc, highlight, stream);
+  else
+    print_doc_line (stream, c->doc);
+  fputs_filtered ("\n", stream);
 }
 
 /* Recursively walk the commandlist structures, and print out the
    documentation of commands that match our regex in either their
    name, or their documentation.
+   If VERBOSE, prints the complete documentation and highlight the
+   documentation parts matching REGEX, otherwise prints only
+   the first line.
 */
-void 
-apropos_cmd (struct ui_file *stream, 
+void
+apropos_cmd (struct ui_file *stream,
             struct cmd_list_element *commandlist,
-            compiled_regex &regex, const char *prefix)
+            bool verbose, compiled_regex &regex, const char *prefix)
 {
   struct cmd_list_element *c;
   int returnvalue;
@@ -984,10 +1001,7 @@ apropos_cmd (struct ui_file *stream,
          /* Try to match against the name.  */
          returnvalue = regex.search (c->name, name_len, 0, name_len, NULL);
          if (returnvalue >= 0)
-           {
-             print_help_for_command (c, prefix, 
-                                     0 /* don't recurse */, stream);
-           }
+           print_doc_of_command (c, prefix, verbose, regex, stream);
        }
       if (c->doc != NULL && returnvalue < 0)
        {
@@ -995,10 +1009,7 @@ apropos_cmd (struct ui_file *stream,
 
          /* Try to match against documentation.  */
          if (regex.search (c->doc, doc_len, 0, doc_len, NULL) >= 0)
-           {
-             print_help_for_command (c, prefix, 
-                                     0 /* don't recurse */, stream);
-           }
+           print_doc_of_command (c, prefix, verbose, regex, stream);
        }
       /* Check if this command has subcommands and is not an
         abbreviation.  We skip listing subcommands of abbreviations
@@ -1007,7 +1018,7 @@ apropos_cmd (struct ui_file *stream,
        {
          /* Recursively call ourselves on the subcommand list,
             passing the right prefix in.  */
-         apropos_cmd (stream,*c->prefixlist,regex,c->prefixname);
+         apropos_cmd (stream, *c->prefixlist, verbose, regex, c->prefixname);
        }
     }
 }
@@ -1115,9 +1126,9 @@ help_list (struct cmd_list_element *list, const char *cmdtype,
   if (len)
     {
       cmdtype1[0] = ' ';
-      strncpy (cmdtype1 + 1, cmdtype, len - 1);
+      memcpy (cmdtype1 + 1, cmdtype, len - 1);
       cmdtype1[len] = 0;
-      strncpy (cmdtype2, cmdtype, len - 1);
+      memcpy (cmdtype2, cmdtype, len - 1);
       strcpy (cmdtype2 + len - 1, " sub");
     }
 
@@ -1150,6 +1161,9 @@ Type \"help all\" for the list of all commands.");
   fputs_filtered ("documentation.\n", stream);
   fputs_filtered ("Type \"apropos word\" to search "
                  "for commands related to \"word\".\n", stream);
+  fputs_filtered ("Type \"apropos -v word\" for full documentation", stream);
+  wrap_here ("");
+  fputs_filtered (" of commands related to \"word\".\n", stream);
   fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
                  stream);
 }
@@ -1236,10 +1250,12 @@ static void
 print_help_for_command (struct cmd_list_element *c, const char *prefix,
                        int recurse, struct ui_file *stream)
 {
-  fprintf_filtered (stream, "%s%s -- ", prefix, c->name);
+  fprintf_styled (stream, title_style.style (),
+                 "%s%s", prefix, c->name);
+  fputs_filtered (" -- ", stream);
   print_doc_line (stream, c->doc);
   fputs_filtered ("\n", stream);
-  
+
   if (recurse
       && c->prefixlist != 0
       && c->abbrev_flag == 0)
@@ -1335,9 +1351,9 @@ find_command_name_length (const char *text)
      Note that this is larger than the character set allowed when
      creating user-defined commands.  */
 
-  /* Recognize '!' as a single character command so that, e.g., "!ls"
+  /* Recognize the single character commands so that, e.g., "!ls"
      works as expected.  */
-  if (*p == '!')
+  if (*p == '!' || *p == '|')
     return 1;
 
   while (isalnum (*p) || *p == '-' || *p == '_'
@@ -1352,13 +1368,13 @@ find_command_name_length (const char *text)
    This is a stricter subset of all gdb commands,
    see find_command_name_length.  */
 
-int
+bool
 valid_user_defined_cmd_name_p (const char *name)
 {
   const char *p;
 
   if (*name == '\0')
-    return FALSE;
+    return false;
 
   /* Alas "42" is a legitimate user-defined command.
      In the interests of not breaking anything we preserve that.  */
@@ -1370,10 +1386,10 @@ valid_user_defined_cmd_name_p (const char *name)
          || *p == '_')
        ; /* Ok.  */
       else
-       return FALSE;
+       return false;
     }
 
-  return TRUE;
+  return true;
 }
 
 /* This routine takes a line of TEXT and a CLIST in which to start the
@@ -1417,7 +1433,7 @@ lookup_cmd_1 (const char **text, struct cmd_list_element *clist,
              struct cmd_list_element **result_list, int ignore_help_classes)
 {
   char *command;
-  int len, tmp, nfound;
+  int len, nfound;
   struct cmd_list_element *found, *c;
   const char *line = *text;
 
@@ -1621,7 +1637,6 @@ lookup_cmd (const char **line, struct cmd_list_element *list,
              }
          error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype,
                 *line, ambbuf);
-         return 0;             /* lint */
        }
     }
   else
@@ -1746,7 +1761,7 @@ lookup_cmd_composition (const char *text,
                       struct cmd_list_element **cmd)
 {
   char *command;
-  int len, tmp, nfound;
+  int len, nfound;
   struct cmd_list_element *cur_list;
   struct cmd_list_element *prev_cmd;
 
@@ -1847,8 +1862,6 @@ complete_on_cmdlist (struct cmd_list_element *list,
            && (!ignore_help_classes || ptr->func
                || ptr->prefixlist))
          {
-           char *match;
-
            if (pass == 0)
              {
                if (ptr->cmd_deprecated)
@@ -1858,22 +1871,8 @@ complete_on_cmdlist (struct cmd_list_element *list,
                  }
              }
 
-           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);
-             }
-           tracker.add_completion (gdb::unique_xmalloc_ptr<char> (match));
+           tracker.add_completion
+             (make_completion_match_str (ptr->name, text, word));
            got_matches = true;
          }
 
@@ -1907,26 +1906,7 @@ complete_on_enum (completion_tracker &tracker,
 
   for (i = 0; (name = enumlist[i]) != NULL; i++)
     if (strncmp (name, text, textlen) == 0)
-      {
-       char *match;
-
-       match = (char *) xmalloc (strlen (word) + strlen (name) + 1);
-       if (word == text)
-         strcpy (match, name);
-       else if (word > text)
-         {
-           /* Return some portion of name.  */
-           strcpy (match, name + (word - text));
-         }
-       else
-         {
-           /* Return some of text plus name.  */
-           strncpy (match, word, text - word);
-           match[text - word] = '\0';
-           strcat (match, name);
-         }
-       tracker.add_completion (gdb::unique_xmalloc_ptr<char> (match));
-      }
+      tracker.add_completion (make_completion_match_str (name, text, word));
 }
 
 
@@ -1940,7 +1920,7 @@ cmd_func_p (struct cmd_list_element *cmd)
 
 /* Call the command function.  */
 void
-cmd_func (struct cmd_list_element *cmd, char *args, int from_tty)
+cmd_func (struct cmd_list_element *cmd, const char *args, int from_tty)
 {
   if (cmd_func_p (cmd))
     {
@@ -1959,6 +1939,5 @@ int
 cli_user_command_p (struct cmd_list_element *cmd)
 {
   return (cmd->theclass == class_user
-         && (cmd->func == do_cfunc || cmd->func == do_sfunc
-             || cmd->func == do_const_cfunc));
+         && (cmd->func == do_const_cfunc || cmd->func == do_sfunc));
 }
This page took 0.032859 seconds and 4 git commands to generate.