New cli-utils.h/.c function extract_info_print_args

New cli-utils.h/.c function extract_info_print_args factorizes
the extraction of the args '[-q] [-t TYPEREGEXP] [NAMEREGEXP]'.
New cli-utils.h/.c function report_unrecognized_option_error
factorizes reporting an unknown option for a command.

These functions will be used by the commands
  info [args|functions|locals|variables]

As extract_info_print_args will be used for 'info functions|variables' which
already have the NAMEREGEXP arg, it provides a backward compatible
behaviour.

cli-utils.c has a new static function extract_arg_maybe_quoted
that extracts an argument, possibly quoted.  The behaviour of this
function is similar to the parsing done by gdb_argv.

gdb/ChangeLog
2018-10-27  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli-utils.c (extract_arg_maybe_quoted): New function.
	(extract_info_print_args): New function.
	(info_print_args_help): New function.
	(report_unrecognized_option_error): New function.
	* cli-utils.h (extract_arg_maybe_quoted): New function.
	(extract_info_print_args): New function.
	(info_print_args_help): New function.
	(report_unrecognized_option_error): New function.
This commit is contained in:
Philippe Waroquiers 2018-07-01 22:46:41 +02:00
parent 6951e9f3e2
commit 0d4cad90ca
3 changed files with 170 additions and 0 deletions

View file

@ -39,6 +39,36 @@ extern int get_number (const char **);
extern int get_number (char **);
/* Extract from ARGS the arguments [-q] [-t TYPEREGEXP] [--] NAMEREGEXP.
The caller is responsible to initialize *QUIET to false, *REGEXP
and *T_REGEXP to "".
extract_info_print_args can then be called iteratively to search
for valid arguments, as part of a 'main parsing loop' searching for
-q/-t/-- arguments together with other flags and options.
Returns true and updates *ARGS + one of *QUIET, *REGEXP, *T_REGEXP if
it finds a valid argument.
Returns false if no valid argument is found at the beginning of ARGS. */
extern bool extract_info_print_args (const char **args,
bool *quiet,
std::string *regexp,
std::string *t_regexp);
/* Throws an error telling the user that ARGS starts with an option
unrecognized by COMMAND. */
extern void report_unrecognized_option_error (const char *command,
const char *args);
/* Builds the help string for a command documented by PREFIX,
followed by the extract_info_print_args help for ENTITY_KIND. */
const char *info_print_args_help (const char *prefix,
const char *entity_kind);
/* Parse a number or a range.
A number will be of the form handled by get_number.
A range will be of the form <number1> - <number2>, and