mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-10 17:41:54 +00:00
Merge "Arrange help output to sort 'column first'"
This commit is contained in:
@@ -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;
|
||||
const int ncmds = __cmds_end - __cmds;
|
||||
int i, j, cols, rows;
|
||||
unsigned char indices[ncmds];
|
||||
|
||||
ccputs("Known commands:");
|
||||
/* Initialize the index. */
|
||||
for (i = 0; i < ncmds; i++)
|
||||
indices[i] = i;
|
||||
|
||||
/* 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;
|
||||
/* 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 */
|
||||
cflush();
|
||||
|
||||
prev = next;
|
||||
}
|
||||
|
||||
ccputs("\n");
|
||||
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();
|
||||
}
|
||||
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
DECLARE_CONSOLE_COMMAND(help, command_help);
|
||||
|
||||
Reference in New Issue
Block a user