Fix usage/help search for subcommands.
authorDean Glazeski <dnglaze@gmail.com>
Thu, 31 Dec 2009 22:01:32 +0000 (16:01 -0600)
committerDavid Brownell <dbrownell@users.sourceforge.net>
Sat, 2 Jan 2010 10:10:55 +0000 (02:10 -0800)
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>
src/helper/command.c

index e55f9e73e48682fbb331c7fc5514b846416cae86..b4e31ea1a7e1d2a3a975ad5515999dcd1fd14306 100644 (file)
@@ -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,

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)