summaryrefslogtreecommitdiff
path: root/avr/command.c
diff options
context:
space:
mode:
Diffstat (limited to 'avr/command.c')
-rw-r--r--avr/command.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/avr/command.c b/avr/command.c
index c8a73f0..c9137ea 100644
--- a/avr/command.c
+++ b/avr/command.c
@@ -1,5 +1,5 @@
/*
- * (C) Copyright 2014, 2016 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014, 2016, 2018 Leo C. <erbl259-lmu@yahoo.de>
*
* (C) Copyright 2000-2009
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
@@ -13,8 +13,6 @@
#include "command.h"
#include "common.h"
-#include <stdlib.h>
-#include <string.h>
#include <ctype.h>
#include <setjmp.h>
@@ -66,6 +64,14 @@ int cmd_tbl_item_count(cmd_tbl_t *p)
int count = 0;
while (p->name != NULL) {
+ if (p->subcmd && p->flags & CTBL_SUBCMDAUTO) {
+ cmd_tbl_t *sub = p->subcmd;
+ while (sub->name != NULL) {
+ if (sub->flags & CTBL_SUBCMDAUTO)
+ count++;
+ sub++;
+ }
+ }
p++; count++;
}
return count;
@@ -106,7 +112,7 @@ cmd_tbl_t *_find_cmd (const char *cmd, cmd_tbl_t *table, find_cmd_para_t *para)
n_found++;
} else if (cmdtp->subcmd && cmdtp->flags & CTBL_SUBCMDAUTO) {
cmd_tbl_t *sub = _find_cmd(cmd, cmdtp->subcmd, para);
- if (sub) {
+ if (sub && sub->flags & CTBL_SUBCMDAUTO) {
cmdtp_ret = sub;
++n_found;
}
@@ -171,11 +177,25 @@ command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag UNUSED, int argc, char
/* Make array of commands */
cmd_tbl_t *tp = tbl_start;
- for (int i = 0; i < cmd_items; i++) {
- uint_fast8_t l = strlen_P(tp->name);
- if (l > maxlen_cmd)
- maxlen_cmd = l;
- cmd_list[i] = tp++;
+ int i = 0;
+ while (tp->name != NULL) {
+ uint_fast8_t len;
+ if (tp->subcmd && tp->flags & CTBL_SUBCMDAUTO) {
+ cmd_tbl_t *sub = tp->subcmd;
+ while (sub->name != NULL) {
+ if (sub->flags & CTBL_SUBCMDAUTO) {
+ len = strlen_P(sub->name);
+ if (len > maxlen_cmd)
+ maxlen_cmd = len;
+ cmd_list[i++] = sub;
+ }
+ sub++;
+ }
+ }
+ len = strlen_P(tp->name);
+ if (len > maxlen_cmd)
+ maxlen_cmd = len;
+ cmd_list[i++] = tp++;
}
/* Sort command list */
qsort(cmd_list, cmd_items, sizeof (cmd_tbl_t *), cmpstring_PP);
@@ -209,7 +229,7 @@ command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag UNUSED, int argc, char
*/
for (uint8_t i = 1; i < argc; ++i) {
if ((cmdtp = find_cmd(argv[i], tbl_start, NULL)) != NULL &&
- (opt_debug || cmdtp->name[0] != '!')) {
+ (opt_debug || !(cmdtp->flags & CTBL_DBG))) {
cmd_usage(cmdtp);
} else {
printf_P(PSTR("Unknown command '%s' - try 'help'"
@@ -223,7 +243,7 @@ command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag UNUSED, int argc, char
}
-command_ret_t cmd_usage(const FLASH cmd_tbl_t *cmdtp)
+command_ret_t cmd_usage(cmd_tbl_t *cmdtp)
{
// printf("%s - %s\n\n", cmdtp->name, cmdtp->usage);
print_usage_line(cmdtp->name, 0, cmdtp->usage);