diff options
Diffstat (limited to 'gdb/cli/cli-utils.c')
-rw-r--r-- | gdb/cli/cli-utils.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c index 30ee445..7331599 100644 --- a/gdb/cli/cli-utils.c +++ b/gdb/cli/cli-utils.c @@ -23,6 +23,8 @@ #include <ctype.h> +static std::string extract_arg_maybe_quoted (const char **arg); + /* See documentation in cli-utils.h. */ int @@ -128,6 +130,70 @@ get_number (char **pp) /* See documentation in cli-utils.h. */ +bool +extract_info_print_args (const char **args, + bool *quiet, + std::string *regexp, + std::string *t_regexp) +{ + /* Check for NAMEREGEXP or -- NAMEREGEXP. */ + if (**args != '-' || check_for_argument (args, "--", 2)) + { + *args = skip_spaces (*args); + *regexp = *args; + *args = NULL; + return true; + } + + if (check_for_argument (args, "-t", 2)) + { + *t_regexp = extract_arg_maybe_quoted (args); + *args = skip_spaces (*args); + return true; + } + + if (check_for_argument (args, "-q", 2)) + { + *quiet = true; + *args = skip_spaces (*args); + return true; + } + + return false; +} + +/* See documentation in cli-utils.h. */ + +void +report_unrecognized_option_error (const char *command, const char *args) +{ + std::string option = extract_arg (&args); + + error (_("Unrecognized option '%s' to %s command. " + "Try \"help %s\"."), option.c_str (), + command, command); +} + +/* See documentation in cli-utils.h. */ + +const char * +info_print_args_help (const char *prefix, + const char *entity_kind) +{ + return xstrprintf (_("\ +%sIf NAMEREGEXP is provided, only prints the %s whose name\n\ +matches NAMEREGEXP.\n\ +If -t TYPEREGEXP is provided, only prints the %s whose type\n\ +matches TYPEREGEXP. Note that the matching is done with the type\n\ +printed by the 'whatis' command.\n\ +By default, the command might produce headers and/or messages indicating\n\ +why no %s can be printed.\n\ +The flag -q disables the production of these headers and messages."), + prefix, entity_kind, entity_kind, entity_kind); +} + +/* See documentation in cli-utils.h. */ + number_or_range_parser::number_or_range_parser (const char *string) { init (string); @@ -283,6 +349,69 @@ remove_trailing_whitespace (const char *start, const char *s) return s; } +/* A helper function to extract an argument from *ARG. An argument is + delimited by whitespace, but it can also be optionally quoted. + The quoting and special characters are handled similarly to + the parsing done by gdb_argv. + The return value is empty if no argument was found. */ + +static std::string +extract_arg_maybe_quoted (const char **arg) +{ + bool squote = false; + bool dquote = false; + bool bsquote = false; + std::string result; + const char *p = *arg; + + /* Find the start of the argument. */ + p = skip_spaces (p); + + /* Parse p similarly to gdb_argv buildargv function. */ + while (*p != '\0') + { + if (isspace (*p) && !squote && !dquote && !bsquote) + break; + else + { + if (bsquote) + { + bsquote = false; + result += *p; + } + else if (*p == '\\') + bsquote = true; + else if (squote) + { + if (*p == '\'') + squote = false; + else + result += *p; + } + else if (dquote) + { + if (*p == '"') + dquote = false; + else + result += *p; + } + else + { + if (*p == '\'') + squote = true; + else if (*p == '"') + dquote = true; + else + result += *p; + } + p++; + } + } + + *arg = p; + return result; +} + /* See documentation in cli-utils.h. */ std::string |