diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2012-05-14 12:54:56 -0700 |
---|---|---|
committer | Vadim Bendebury <vbendeb@chromium.org> | 2012-05-14 13:35:03 -0700 |
commit | 6a324c1de569529b26ebc694ceca3a66c38c989d (patch) | |
tree | 3886d4be6989ff6aa1ea2c8ec649761d9f56d7b3 /common/console.c | |
parent | 55898c8b4b14521bf6c188a7d7e034a9b1ae7b35 (diff) | |
download | chrome-ec-6a324c1de569529b26ebc694ceca3a66c38c989d.tar.gz |
Allow console commands abbreviation
The EC console input handling code is being enhanced to accept
abbreviated command names.
If the abbreviation is unique, the appropriate command is used, if the
abbreviation is ambiguous, the command is handled as nonexistent. The
error message is being modified to mention that the command either
does not exist or is ambiguous.
This change also makes it impossible to have command names matching
the beginning of other command names. Two such cases are being fixed
(`ch' renamed to `chan' and `thermal' renamed to 'thermalconf').
BUG=none
TEST=manual
. program the new EC image. Try entering at the console:
> h
Command 'h' either not found or ambiguous.
Command returned error 1
> he
Known commands:
adc autofan battery ch charger
...
> help
Known commands:
adc autofan battery ch charger
...
Change-Id: Iaa3e91e1504e42daefb02d561e00c39003548197
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'common/console.c')
-rw-r--r-- | common/console.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/common/console.c b/common/console.c index 50ca6da2d4..cdb5daf5e6 100644 --- a/common/console.c +++ b/common/console.c @@ -128,14 +128,18 @@ static int split_words(char *input, int max_argc, int *argc, char **argv) * no match found. */ static const struct console_command *find_command(char *name) { - const struct console_command *cmd; + const struct console_command *cmd, *match = NULL; + int match_length = strlen(name); for (cmd = __cmds; cmd < __cmds_end; cmd++) { - if (!strcasecmp(name, cmd->name)) - return cmd; + if (!strncasecmp(name, cmd->name, match_length)) { + if (match) + return NULL; + match = cmd; + } } - return NULL; + return match; } @@ -159,7 +163,7 @@ static int handle_command(char *input) if (cmd) return cmd->handler(argc, argv); - ccprintf("Command '%s' not found.\n", argv[0]); + ccprintf("Command '%s' either not found or ambiguous.\n", argv[0]); return EC_ERROR_UNKNOWN; } @@ -293,7 +297,7 @@ static int command_ch(int argc, char **argv) } /* Otherwise, print help */ - ccputs("Usage: ch [newmask]\n"); + ccputs("Usage: chan [newmask]\n"); return EC_ERROR_INVAL; }; -DECLARE_CONSOLE_COMMAND(ch, command_ch); +DECLARE_CONSOLE_COMMAND(chan, command_ch); |