diff options
author | Marco Barisione <mbarisione@undo.io> | 2021-05-07 15:43:30 +0100 |
---|---|---|
committer | Marco Barisione <mbarisione@undo.io> | 2021-05-07 15:43:30 +0100 |
commit | a9b49cbcd5935a713da5715799ea3b24e0a52851 (patch) | |
tree | efd3e48a50d31f4622598915d43f304b38420155 /gdb/cli/cli-script.c | |
parent | 97834047e13bb9f30430331c27b11412a5ed6950 (diff) | |
download | binutils-a9b49cbcd5935a713da5715799ea3b24e0a52851.zip binutils-a9b49cbcd5935a713da5715799ea3b24e0a52851.tar.gz binutils-a9b49cbcd5935a713da5715799ea3b24e0a52851.tar.bz2 |
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.
Diffstat (limited to 'gdb/cli/cli-script.c')
-rw-r--r-- | gdb/cli/cli-script.c | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 9d0dd77..0544f3e 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -1391,7 +1391,7 @@ do_define_command (const char *comname, int from_tty, CMD_POST_HOOK }; struct cmd_list_element *c, *newc, *hookc = 0, **list; - const char *tem, *comfull; + const char *comfull; int hook_type = CMD_NO_HOOK; int hook_name_size = 0; @@ -1403,11 +1403,7 @@ do_define_command (const char *comname, int from_tty, comfull = comname; list = validate_comname (&comname); - /* Look it up, and verify that we got an exact match. */ - tem = comname; - c = lookup_cmd (&tem, *list, "", NULL, -1, 1); - if (c && strcmp (comname, c->name) != 0) - c = 0; + c = lookup_cmd_exact (comname, *list); if (c && commands == nullptr) { @@ -1448,11 +1444,9 @@ do_define_command (const char *comname, int from_tty, if (hook_type != CMD_NO_HOOK) { - /* Look up cmd it hooks, and verify that we got an exact match. */ - tem = comname + hook_name_size; - hookc = lookup_cmd (&tem, *list, "", NULL, -1, 0); - if (hookc && strcmp (comname + hook_name_size, hookc->name) != 0) - hookc = 0; + /* Look up cmd it hooks. */ + hookc = lookup_cmd_exact (comname + hook_name_size, *list, + /* ignore_help_classes = */ false); if (!hookc && commands == nullptr) { warning (_("Your new `%s' command does not " @@ -1593,17 +1587,12 @@ static void define_prefix_command (const char *comname, int from_tty) { struct cmd_list_element *c, **list; - const char *tem; const char *comfull; comfull = comname; list = validate_comname (&comname); - /* Look it up, and verify that we got an exact match. */ - tem = comname; - c = lookup_cmd (&tem, *list, "", NULL, -1, 1); - if (c != nullptr && strcmp (comname, c->name) != 0) - c = nullptr; + c = lookup_cmd_exact (comname, *list); if (c != nullptr && c->theclass != class_user) error (_("Command \"%s\" is built-in."), comfull); |