diff options
author | Randall Spangler <rspangler@chromium.org> | 2012-01-24 10:31:20 -0800 |
---|---|---|
committer | Randall Spangler <rspangler@chromium.org> | 2012-01-24 10:32:29 -0800 |
commit | 8c56cc4fa71f8c793bc1240fb2e40b92ae27abf5 (patch) | |
tree | 923c8716c4fdafcdfce7cc4f333af47f422693a7 /common/console.c | |
parent | 431622d0b902af511c67914572d269db999b511a (diff) | |
download | chrome-ec-8c56cc4fa71f8c793bc1240fb2e40b92ae27abf5.tar.gz |
Help command prints a sorted multi-column list of commands
Signed-off-by: Randall Spangler <rspangler@chromium.org>
BUG=none
TEST=type 'help' from console
Change-Id: If88610f35337243ca2550de2851bd1924083344d
Diffstat (limited to 'common/console.c')
-rw-r--r-- | common/console.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/common/console.c b/common/console.c index 12db5016dc..a5a3d6c103 100644 --- a/common/console.c +++ b/common/console.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -15,11 +15,10 @@ #define PROMPT "> " -/* Xonsole commands are described in a special section */ +/* Console commands are described in a special section */ extern const struct console_command __cmds[]; extern const struct console_command __cmds_end[]; - void console_has_input(void) { /* Wake up the console task */ @@ -151,17 +150,35 @@ void console_task(void) static int command_help(int argc, char **argv) { const struct console_command *cmd; + const int ncmds = ((uint32_t)__cmds_end - (uint32_t)__cmds) / + sizeof(struct console_command); + const char *prev = " "; + int i; - uart_puts("Known commands:\n"); + uart_puts("Known commands:"); - for (cmd = __cmds; cmd < __cmds_end; cmd++) { - uart_printf(" %s\n", cmd->name); + /* Sort the commands by name */ + for (i = 0; i < ncmds; i++) { + const char *next = "zzzz"; + + if (!(i % 5)) + uart_puts("\n "); + + /* Find the next command */ + for (cmd = __cmds; cmd < __cmds_end; cmd++) { + if (strcasecmp(prev, cmd->name) < 0 && + strcasecmp(cmd->name, next) < 0) + next = cmd->name; + } + + uart_printf("%-15s", next); /* Generates enough output to overflow the buffer */ uart_flush_output(); - } - uart_puts("'.' repeats the last command.\n"); + prev = next; + } + uart_puts("\n'.' repeats the last command.\n"); return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(help, command_help); |