diff options
author | Dean Glazeski <dnglaze@gmail.com> | 2009-12-31 16:01:32 -0600 |
---|---|---|
committer | David Brownell <dbrownell@users.sourceforge.net> | 2010-01-02 02:10:55 -0800 |
commit | 9d167d62f2eadf81e0028e471e05154c9aabbbfb (patch) | |
tree | c2ede3e076dbfa5cc12205465f04fdce4af0aa98 /src/helper | |
parent | be01786186951b42d8aa8b8968ac1615e080a9c7 (diff) | |
download | openocd+libswd-9d167d62f2eadf81e0028e471e05154c9aabbbfb.tar.gz openocd+libswd-9d167d62f2eadf81e0028e471e05154c9aabbbfb.tar.bz2 openocd+libswd-9d167d62f2eadf81e0028e471e05154c9aabbbfb.tar.xz openocd+libswd-9d167d62f2eadf81e0028e471e05154c9aabbbfb.zip |
Fix usage/help search for subcommands.
This makes it so that the usage/help command properly uses the whole command,
including subcommand, in the search for help information. This previously
caused erroneous output from the usage command handler.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Diffstat (limited to 'src/helper')
-rw-r--r-- | src/helper/command.c | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/src/helper/command.c b/src/helper/command.c index e55f9e73..b4e31ea1 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -960,18 +960,45 @@ static COMMAND_HELPER(command_help_show, struct command *c, unsigned n, COMMAND_HANDLER(handle_help_command) { bool full = strcmp(CMD_NAME, "help") == 0; - + int retval; struct command *c = CMD_CTX->commands; + char *match = NULL; - const char *match = ""; if (CMD_ARGC == 0) match = ""; - else if (CMD_ARGC == 1) - match = CMD_ARGV[0]; - else + else if (CMD_ARGC >= 1) { + unsigned i; + + for (i = 0; i < CMD_ARGC; ++i) { + if (NULL != match) { + char *prev = match; + + match = alloc_printf("%s %s", match, + CMD_ARGV[i]); + free(prev); + if (NULL == match) { + LOG_ERROR("unable to build " + "search string"); + return -ENOMEM; + } + } else { + match = alloc_printf("%s", CMD_ARGV[i]); + if (NULL == match) { + LOG_ERROR("unable to build " + "search string"); + return -ENOMEM; + } + } + } + } else return ERROR_COMMAND_SYNTAX_ERROR; - - return CALL_COMMAND_HANDLER(command_help_show_list, c, 0, full, match); + + retval = CALL_COMMAND_HANDLER(command_help_show_list, + c, 0, full, match); + + if (CMD_ARGC >= 1) + free(match); + return retval; } static int command_unknown_find(unsigned argc, Jim_Obj *const *argv, |