summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo C2018-07-29 14:47:30 +0200
committerLeo C2018-07-29 14:47:30 +0200
commitbc72540aa158b4eba2dcda3e7921caa7f970ff9a (patch)
tree73b812b66e9d9cbc0e001d735680d216aafaa127
parente96dcd6d096cc51414b156ab7aa746da27074c53 (diff)
downloadz180-stamp-bc72540aa158b4eba2dcda3e7921caa7f970ff9a.zip
Print prefix of subcommands
-rw-r--r--avr/command.c87
-rw-r--r--include/command.h1
2 files changed, 53 insertions, 35 deletions
diff --git a/avr/command.c b/avr/command.c
index b11297b..bb179b8 100644
--- a/avr/command.c
+++ b/avr/command.c
@@ -31,18 +31,67 @@
jmp_buf cmd_jbuf;
+static int cmd_tbl_item_count(cmd_tbl_t *p)
+{
+ int count = 0;
+
+ while (p->name != NULL) {
+ if (p->subcmd) {
+ cmd_tbl_t *sub = p->subcmd;
+ while (sub->name != NULL) {
+ if (sub->flags & CTBL_SUBCMDAUTO)
+ count++;
+ sub++;
+ }
+ }
+ if ((p->flags & CTBL_SUBCMDAUTO) == 0)
+ count++;
+ p++;
+ }
+ return count;
+}
+
+static cmd_tbl_t *get_cmd_tbl_base(cmd_tbl_t *cmdtp)
+{
+ cmd_tbl_t *p = cmdtp;
+
+ while (p->name != NULL)
+ ++p;
+
+ return p->subcmd;
+}
+
+static void print_name_prefix(cmd_tbl_t *p)
+{
+ cmd_tbl_t *tbl_start = get_cmd_tbl_base(p);
+ cmd_tbl_t *top;
+
+ if (tbl_start == cmd_tbl)
+ top = NULL;
+ else {
+ top = cmd_tbl;
+ while (top->subcmd != tbl_start)
+ ++top;
+ }
+
+ if (top && (p->flags & CTBL_SUBCMDAUTO) == 0) {
+ printf_P(PSTR("%S "), top->name);
+ }
+}
+
static void print_usage_line(cmd_tbl_t *p, int width)
{
width -= strlen_P(p->name);
if (width < 0)
width = 0;
+ print_name_prefix(p);
my_puts_P(p->name);
print_blanks(width);
my_puts_P(PSTR(" - "));
puts_P(p->usage);
}
-int strcmp_PP(const FLASH char *s1, const FLASH char *s2)
+static int strcmp_PP(const FLASH char *s1, const FLASH char *s2)
{
unsigned char c1, c2;
@@ -54,7 +103,7 @@ int strcmp_PP(const FLASH char *s1, const FLASH char *s2)
return c1 - c2;
}
-int cmpstring_PP(const void *p1, const void *p2)
+static int cmpstring_PP(const void *p1, const void *p2)
{
return strcmp_PP((*(const FLASH cmd_tbl_t **) p1)->name,
(*(const FLASH cmd_tbl_t **) p2)->name);
@@ -62,42 +111,11 @@ int cmpstring_PP(const void *p1, const void *p2)
/****************************************************************************/
-int cmd_tbl_item_count(cmd_tbl_t *p)
-{
- int count = 0;
-
- while (p->name != NULL) {
- if (p->subcmd) {
- cmd_tbl_t *sub = p->subcmd;
- while (sub->name != NULL) {
- if (sub->flags & CTBL_SUBCMDAUTO)
- count++;
- sub++;
- }
- }
- if ((p->flags & CTBL_SUBCMDAUTO) == 0)
- count++;
- p++;
- }
- return count;
-}
-
-
-cmd_tbl_t *get_cmd_tbl_base(cmd_tbl_t *cmdtp)
-{
- cmd_tbl_t *p = cmdtp;
-
- while (p->name != NULL)
- ++p;
-
- return p->subcmd;
-}
-
/*
* find command table entry for a command
*/
-cmd_tbl_t *find_cmd (const char *cmd, cmd_tbl_t *table)
+static cmd_tbl_t *find_cmd (const char *cmd, cmd_tbl_t *table)
{
if (!cmd)
return NULL;
@@ -225,6 +243,7 @@ command_ret_t cmd_usage(cmd_tbl_t *cmdtp)
print_usage_line(cmdtp, 0);
#ifdef CONFIG_SYS_LONGHELP
my_puts_P(PSTR("Usage:\n"));
+ print_name_prefix(cmdtp);
my_puts_P(cmdtp->name);
my_puts_P(PSTR(" "));
diff --git a/include/command.h b/include/command.h
index 614d527..93c9a2d 100644
--- a/include/command.h
+++ b/include/command.h
@@ -81,7 +81,6 @@ cmd_process(uint_fast8_t flag, int argc, char * const argv[], uint_fast8_t *repe
/* command.c */
command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]);
-int cmd_tbl_item_count(cmd_tbl_t *p);
command_ret_t cmd_usage(cmd_tbl_t *cmdtp);
#ifdef CONFIG_AUTO_COMPLETE