/* Handle lists of commands, their decoding and documentation, for GDB.
- Copyright (C) 1986-2016 Free Software Foundation, Inc.
+ Copyright (C) 1986-2017 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
#include "ui-out.h"
#include "cli/cli-cmds.h"
#include "cli/cli-decode.h"
+#include "common/gdb_optional.h"
/* Prototypes for local functions. */
c->allow_unknown = 0;
c->prefix = NULL;
c->abbrev_flag = 0;
- set_cmd_completer (c, make_symbol_completion_list_fn);
+ set_cmd_completer (c, symbol_completer);
c->completer_handle_brkchars = NULL;
c->destroyer = NULL;
c->type = not_set_cmd;
c->user_commands = NULL;
c->cmd_pointer = NULL;
c->alias_chain = NULL;
+ c->suppress_notification = NULL;
return c;
}
}
struct cmd_list_element *
-add_alias_cmd (const char *name, const char *oldname, enum command_class theclass,
- int abbrev_flag, struct cmd_list_element **list)
+add_alias_cmd (const char *name, cmd_list_element *old,
+ enum command_class theclass, int abbrev_flag,
+ struct cmd_list_element **list)
{
- const char *tmp;
- struct cmd_list_element *old;
- struct cmd_list_element *c;
-
- tmp = oldname;
- old = lookup_cmd (&tmp, *list, "", 1, 1);
-
if (old == 0)
{
struct cmd_list_element *prehook, *prehookee, *posthook, *posthookee;
return 0;
}
- c = add_cmd (name, theclass, NULL, old->doc, list);
+ struct cmd_list_element *c = add_cmd (name, theclass, NULL, old->doc, list);
/* If OLD->DOC can be freed, we should make another copy. */
if (old->doc_allocated)
return c;
}
+struct cmd_list_element *
+add_alias_cmd (const char *name, const char *oldname,
+ enum command_class theclass, int abbrev_flag,
+ struct cmd_list_element **list)
+{
+ const char *tmp;
+ struct cmd_list_element *old;
+
+ tmp = oldname;
+ old = lookup_cmd (&tmp, *list, "", 1, 1);
+
+ return add_alias_cmd (name, old, theclass, abbrev_flag, list);
+}
+
+
/* Like add_cmd but adds an element for a command prefix: a name that
should be followed by a subcommand to be looked up in another
command list. PREFIXLIST should be the address of the variable
{
return add_alias_cmd (name, oldname, theclass, abbrev_flag, &cmdlist);
}
-\f
+
+/* Add an element with a suppress notification to the list of commands. */
+
+struct cmd_list_element *
+add_com_suppress_notification (const char *name, enum command_class theclass,
+ cmd_cfunc_ftype *fun, const char *doc,
+ int *suppress_notification)
+{
+ struct cmd_list_element *element;
+
+ element = add_cmd (name, theclass, fun, doc, &cmdlist);
+ element->suppress_notification = suppress_notification;
+
+ return element;
+}
+
/* Recursively walk the commandlist structures, and print out the
documentation of commands that match our regex in either their
name, or their documentation.
void
apropos_cmd (struct ui_file *stream,
struct cmd_list_element *commandlist,
- struct re_pattern_buffer *regex, const char *prefix)
+ compiled_regex ®ex, const char *prefix)
{
struct cmd_list_element *c;
int returnvalue;
returnvalue = -1; /* Needed to avoid double printing. */
if (c->name != NULL)
{
+ size_t name_len = strlen (c->name);
+
/* Try to match against the name. */
- returnvalue = re_search (regex, c->name, strlen(c->name),
- 0, strlen (c->name), NULL);
+ returnvalue = regex.search (c->name, name_len, 0, name_len, NULL);
if (returnvalue >= 0)
{
print_help_for_command (c, prefix,
}
if (c->doc != NULL && returnvalue < 0)
{
+ size_t doc_len = strlen (c->doc);
+
/* Try to match against documentation. */
- if (re_search(regex,c->doc,strlen(c->doc),0,strlen(c->doc),NULL) >=0)
+ if (regex.search (c->doc, doc_len, 0, doc_len, NULL) >= 0)
{
print_help_for_command (c, prefix,
0 /* don't recurse */, stream);
* all sublists of LIST.
* PREFIX is the prefix to print before each command name.
* STREAM is the stream upon which the output should be written.
- * CLASS should be:
+ * THECLASS should be:
* A non-negative class number to list only commands in that
* class.
* ALL_COMMANDS to list all commands in list.
struct cmd_list_element *c;
for (c = list; c; c = c->next)
- {
+ {
if (c->abbrev_flag == 0
+ && !c->cmd_deprecated
&& (theclass == all_commands
|| (theclass == all_classes && c->func == NULL)
|| (theclass == c->theclass && c->func != NULL)))
{
print_help_for_command (c, prefix, recurse, stream);
}
- else if (c->abbrev_flag == 0 && recurse
+ else if (c->abbrev_flag == 0
+ && recurse
+ && !c->cmd_deprecated
&& theclass == class_user && c->prefixlist != NULL)
/* User-defined commands may be subcommands. */
help_cmd_list (*c->prefixlist, theclass, c->prefixname,
return found;
}
-static int
+/* Return the length of command name in TEXT. */
+
+int
find_command_name_length (const char *text)
{
const char *p = text;
if no prefix command was ever found. For example, in the case of "info a",
"info" matches without ambiguity, but "a" could be "args" or "address", so
*RESULT_LIST is set to the cmd_list_element for "info". So in this case
- RESULT_LIST should not be interpeted as a pointer to the beginning of a
+ RESULT_LIST should not be interpreted as a pointer to the beginning of a
list; it simply points to a specific command. In the case of an ambiguous
return *TEXT is advanced past the last non-ambiguous prefix (e.g.
"info t" can be "info types" or "info target"; upon return *TEXT has been
nfound = 0;
found = find_cmd (command, len, clist, ignore_help_classes, &nfound);
- /* We didn't find the command in the entered case, so lower case it
- and search again. */
- if (!found || nfound == 0)
- {
- for (tmp = 0; tmp < len; tmp++)
- {
- char x = command[tmp];
-
- command[tmp] = isupper (x) ? tolower (x) : x;
- }
- found = find_cmd (command, len, clist, ignore_help_classes, &nfound);
- }
-
/* If nothing matches, we have a simple failure. */
if (nfound == 0)
return 0;
the function field of the struct cmd_list_element is 0). */
struct cmd_list_element *
-lookup_cmd (const char **line, struct cmd_list_element *list, char *cmdtype,
+lookup_cmd (const char **line, struct cmd_list_element *list,
+ const char *cmdtype,
int allow_unknown, int ignore_help_classes)
{
struct cmd_list_element *last_list = 0;
nfound = 0;
*cmd = find_cmd (command, len, cur_list, 1, &nfound);
- /* We didn't find the command in the entered case, so lower case
- it and search again.
- */
- if (!*cmd || nfound == 0)
- {
- for (tmp = 0; tmp < len; tmp++)
- {
- char x = command[tmp];
-
- command[tmp] = isupper (x) ? tolower (x) : x;
- }
- *cmd = find_cmd (command, len, cur_list, 1, &nfound);
- }
-
if (*cmd == CMD_LIST_AMBIGUOUS)
{
return 0; /* ambiguous */
cmd_func (struct cmd_list_element *cmd, char *args, int from_tty)
{
if (cmd_func_p (cmd))
- (*cmd->func) (cmd, args, from_tty);
+ {
+ gdb::optional<scoped_restore_tmpl<int>> restore_suppress;
+
+ if (cmd->suppress_notification != NULL)
+ restore_suppress.emplace (cmd->suppress_notification, 1);
+
+ (*cmd->func) (cmd, args, from_tty);
+ }
else
error (_("Invalid command"));
}