summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2012-05-14 15:02:49 -0700
committerVadim Bendebury <vbendeb@chromium.org>2012-05-14 17:44:45 -0700
commit336944e9519ee90a523398b497328d353f8cef4d (patch)
tree101b04ffea01cfbaf8e7b7d1ed320dd1b8e0151f
parentd296c0d2462f799d26d579d8c2e0d0eab35c4a5f (diff)
downloadchrome-ec-336944e9519ee90a523398b497328d353f8cef4d.tar.gz
Arrange help output to sort 'column first'
Sort the command name index, and then print them in file columns (as before), but ordering columns first. This makes it much easier to examine the 'help' command output. BUG=none TEST=manual . program the new image . execute the 'help' command . observe output printed sorted 'columns first' Change-Id: I7b15cef09a61fe20eb4ba5ee274ba1d72063f1c0 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
-rw-r--r--common/console.c56
1 files changed, 31 insertions, 25 deletions
diff --git a/common/console.c b/common/console.c
index cdb5daf5e6..3a57716db3 100644
--- a/common/console.c
+++ b/common/console.c
@@ -226,36 +226,42 @@ void console_task(void)
/* Command handler - prints help. */
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;
-
- ccputs("Known commands:");
-
- /* Sort the commands by name */
- for (i = 0; i < ncmds; i++) {
- const char *next = "zzzz";
-
- if (!(i % 5))
- ccputs("\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;
+ const int ncmds = __cmds_end - __cmds;
+ int i, j, cols, rows;
+ unsigned char indices[ncmds];
+
+ /* Initialize the index. */
+ for (i = 0; i < ncmds; i++)
+ indices[i] = i;
+
+ /* Bubble sort commands by name. */
+ for (i = 0; i < (ncmds - 1); i++) {
+ for (j = i + 1; j < ncmds; j++) {
+ if (strcasecmp(__cmds[indices[i]].name,
+ __cmds[indices[j]].name) > 0) {
+ int tmp = indices[j];
+ indices[j] = indices[i];
+ indices[i] = tmp;
+ }
}
+ }
- ccprintf("%-15s", next);
- /* Generates enough output to overflow the buffer */
+ ccputs("Known commands:\n");
+
+ cols = 5; /* printing in five columns */
+ rows = (ncmds + 1) / cols;
+ for (i = 0; i < rows; i++) {
+ ccputs(" ");
+ for (j = 0; j < cols; j++) {
+ int index = j * rows + i;
+ if (index >= ncmds)
+ break;
+ ccprintf("%-15s", __cmds[indices[index]].name);
+ }
+ ccputs("\n");
cflush();
-
- prev = next;
}
- ccputs("\n");
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(help, command_help);