gdb: add lookup_cmd_exact to simplify a common pattern
In code dealing with commands, there's a pattern repeated a few times of calling lookup_cmd with some speficic arguments and then using strcmp on the returned command to check for an exact match. As a later patch would add a few more similar lines of code, this patch adds a new lookup_cmd_exact function which simplify this use case. gdb/ChangeLog: * cli/cli-decode.c (lookup_cmd_exact): Add. * cli/cli-script.c (do_define_command): Use lookup_cmd_exact. (define_prefix_command): Ditto. * command.h: Add lookup_cmd_exact.
This commit is contained in:
parent
97834047e1
commit
a9b49cbcd5
3 changed files with 40 additions and 17 deletions
|
@ -1875,6 +1875,21 @@ lookup_cmd (const char **line, struct cmd_list_element *list,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* See command.h. */
|
||||
|
||||
struct cmd_list_element *
|
||||
lookup_cmd_exact (const char *name,
|
||||
struct cmd_list_element *list,
|
||||
bool ignore_help_classes)
|
||||
{
|
||||
const char *tem = name;
|
||||
struct cmd_list_element *cmd = lookup_cmd (&tem, list, "", NULL, -1,
|
||||
ignore_help_classes);
|
||||
if (cmd != nullptr && strcmp (name, cmd->name) != 0)
|
||||
cmd = nullptr;
|
||||
return cmd;
|
||||
}
|
||||
|
||||
/* We are here presumably because an alias or command in TEXT is
|
||||
deprecated and a warning message should be generated. This
|
||||
function decodes TEXT and potentially generates a warning message
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue