/* Search through names of commands and documentations for a certain
regular expression. */
-static void
-apropos_command (const char *searchstr, int from_tty)
+static void
+apropos_command (const char *arg, int from_tty)
{
- if (searchstr == NULL)
+ bool verbose = arg && check_for_argument (&arg, "-v", 2);
+
+ if (verbose)
+ arg = skip_spaces (arg);
+
+ if (arg == NULL || *arg == '\0')
error (_("REGEXP string is empty"));
- compiled_regex pattern (searchstr, REG_ICASE,
+ compiled_regex pattern (arg, REG_ICASE,
_("Error in regular expression"));
- apropos_cmd (gdb_stdout, cmdlist, pattern, "");
+ apropos_cmd (gdb_stdout, cmdlist, verbose, pattern, "");
}
/* Subroutine of alias_command to simplify it.
Show definitions of non-python/scheme user defined commands.\n\
Argument is the name of the user defined command.\n\
With no argument, show definitions of all user defined commands."), &showlist);
- add_com ("apropos", class_support, apropos_command,
- _("Search for commands matching a REGEXP"));
+ add_com ("apropos", class_support, apropos_command, _("\
+Search for commands matching a REGEXP\n\
+Usage: apropos [-v] REGEXP\n\
+Flag -v indicates to produce a verbose output, showing full documentation\n\
+of the matching commands."));
add_setshow_uinteger_cmd ("max-user-call-depth", no_class,
&max_user_call_depth, _("\
#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. */
&cmdlist, 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. */
+
+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 ®ex, const char *prefix)
+ bool verbose, compiled_regex ®ex, const char *prefix)
{
struct cmd_list_element *c;
int returnvalue;
/* 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)
{
/* 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
{
/* 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);
}
}
}
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);
}
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)