]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
Fix help, env subcommands
authorLeo C <erbl259-lmu@yahoo.de>
Sat, 28 Jul 2018 10:47:35 +0000 (12:47 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Sat, 28 Jul 2018 10:47:35 +0000 (12:47 +0200)
avr/command.c
avr/command_tbl.c
avr/env.c
include/env.h

index c9137eabc83e3f4cf23636f88124d49087afc928..b4a972c1b0a07f783c235aa3dad25099c7bad8df 100644 (file)
 #include "env.h"
 #include "debug.h"
 
+#define DEBUG_CMD      1       /* set to 1 to debug */
+
+#define debug_cmd(fmt, args...)                                                              \
+       debug_cond(DEBUG_CMD, fmt, ##args)
+
 
 jmp_buf cmd_jbuf;
 
@@ -64,7 +69,7 @@ int cmd_tbl_item_count(cmd_tbl_t *p)
        int count = 0;
 
        while (p->name != NULL) {
-               if (p->subcmd && p->flags & CTBL_SUBCMDAUTO) {
+               if (p->subcmd) {
                        cmd_tbl_t *sub = p->subcmd;
                        while (sub->name != NULL) {
                                if (sub->flags & CTBL_SUBCMDAUTO)
@@ -72,7 +77,9 @@ int cmd_tbl_item_count(cmd_tbl_t *p)
                                sub++;
                        }
                }
-               p++; count++;
+               if ((p->flags & CTBL_SUBCMDAUTO) == 0)
+                       count++;
+               p++;
        }
        return count;
 }
@@ -110,7 +117,7 @@ cmd_tbl_t *_find_cmd (const char *cmd, cmd_tbl_t *table, find_cmd_para_t *para)
 
                        cmdtp_ret = cmdtp;      /* abbreviated command ? */
                        n_found++;
-               } else if (cmdtp->subcmd && cmdtp->flags & CTBL_SUBCMDAUTO) {
+               } else if (cmdtp->subcmd) {
                        cmd_tbl_t *sub = _find_cmd(cmd, cmdtp->subcmd, para);
                        if (sub && sub->flags & CTBL_SUBCMDAUTO) {
                                cmdtp_ret = sub;
@@ -179,12 +186,11 @@ command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag UNUSED, int argc, char
                cmd_tbl_t *tp = tbl_start;
                int i = 0;
                while (tp->name != NULL) {
-                       uint_fast8_t len;
-                       if (tp->subcmd && tp->flags & CTBL_SUBCMDAUTO) {
+                       if (tp->subcmd) {
                                cmd_tbl_t *sub = tp->subcmd;
                                while (sub->name != NULL) {
                                        if (sub->flags & CTBL_SUBCMDAUTO) {
-                                               len = strlen_P(sub->name);
+                                               uint_fast8_t len = strlen_P(sub->name);
                                                if (len > maxlen_cmd)
                                                        maxlen_cmd = len;
                                                cmd_list[i++] = sub;
@@ -192,10 +198,13 @@ command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag UNUSED, int argc, char
                                        sub++;
                                }
                        }
-                       len = strlen_P(tp->name);
-                       if (len > maxlen_cmd)
-                               maxlen_cmd = len;
-                       cmd_list[i++] = tp++;
+                       if ((tp->flags & CTBL_SUBCMDAUTO) == 0) {
+                               uint_fast8_t len = strlen_P(tp->name);
+                               if (len > maxlen_cmd)
+                                       maxlen_cmd = len;
+                                       cmd_list[i++] = tp;
+                       }
+                       tp++;
                }
                /* Sort command list */
                qsort(cmd_list, cmd_items, sizeof (cmd_tbl_t *), cmpstring_PP);
index 7a6b776b4cd7f52927a505d7414c6485ea541c18..ea41fc7b504a2d036432db7c439c54b610bada12 100644 (file)
@@ -107,33 +107,12 @@ CMD_TBL_ITEM_COMPLETE(
        "    - run the commands in the script file 'filename'",
        var_complete
 ),
-CMD_TBL_ITEM_COMPLETE(
-       printenv, CONFIG_SYS_MAXARGS,   1,      do_env_print,
-       "print environment variables",
-       "[-s] [name ...]\n"
-       "    Print value of environment variable(s) 'name'\n"
-       "    If no names are given, print values of all environment variables\n"
-       "    -s Print in setenv form",
-       var_complete
-),
-CMD_TBL_ITEM_COMPLETE(
-       setenv, CONFIG_SYS_MAXARGS,     0,      do_env_set,
-       "set environment variables",
-       "name value ...\n"
-       "    - set environment variable 'name' to 'value ...'\n"
-       "setenv name\n"
-       "    - delete environment variable 'name'",
-       var_complete
-),
-CMD_TBL_ITEM(
-       saveenv,        1,      0,      do_env_save,
-       "save environment variables to persistent storage",
-       ""
-),
-CMD_TBL_ITEM(
-       defaultenv,     1,      0,      do_env_default,
-       "set all environment variables to their default values",
-       ""
+
+CMD_TBL_ITEM_TOP(
+       env, CONFIG_SYS_MAXARGS, 0, do_env,
+       "environment handling commands",
+       "",
+       cmd_tbl_env
 ),
 
 CMD_TBL_ITEM(
@@ -332,7 +311,7 @@ CMD_TBL_ITEM_TOP(
        cmd_tbl_sd
 ),
 CMD_TBL_ITEM_TOP(
-       fat,   CONFIG_SYS_MAXARGS, CTBL_SUBCMDAUTO, do_fat,
+       fat,   CONFIG_SYS_MAXARGS, 0, do_fat,
        "fat filesystem commands",
        "<subcommand> args ...\n"
        "fat help\n"
index 44c5742afe3043a6054218eede24a7660436e62b..add281c26e36c64d922329930e4b1d7ca8526cc1 100644 (file)
--- a/avr/env.c
+++ b/avr/env.c
@@ -795,3 +795,91 @@ int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf)
        return found;
 }
 #endif
+
+cmd_tbl_t cmd_tbl_env[] = {
+CMD_TBL_ITEM_COMPLETE(
+       printenv, CONFIG_SYS_MAXARGS,   1|CTBL_SUBCMDAUTO,      do_env_print,
+       "print environment variables",
+       "[-s] [name ...]\n"
+       "    Print value of environment variable(s) 'name'\n"
+       "    If no names are given, print values of all environment variables\n"
+       "    -s Print in setenv form",
+       var_complete
+),
+CMD_TBL_ITEM_COMPLETE(
+       setenv, CONFIG_SYS_MAXARGS,     CTBL_SUBCMDAUTO,        do_env_set,
+       "set environment variables",
+       "name value ...\n"
+       "    - set environment variable 'name' to 'value ...'\n"
+       "setenv name\n"
+       "    - delete environment variable 'name'",
+       var_complete
+),
+CMD_TBL_ITEM(
+       saveenv,        1,      CTBL_SUBCMDAUTO,        do_env_save,
+       "save environment variables to persistent storage",
+       ""
+),
+CMD_TBL_ITEM(
+       defaultenv,     1,      CTBL_SUBCMDAUTO,        do_env_default,
+       "set all environment variables to their default values",
+       ""
+),
+
+CMD_TBL_ITEM_COMPLETE(
+       print, CONFIG_SYS_MAXARGS,      1,      do_env_print,
+       "print environment variables",
+       "[-s] [name ...]\n"
+       "    Print value of environment variable(s) 'name'\n"
+       "    If no names are given, print values of all environment variables\n"
+       "    -s Print in setenv form",
+       var_complete
+),
+CMD_TBL_ITEM_COMPLETE(
+       set, CONFIG_SYS_MAXARGS,        0,      do_env_set,
+       "set environment variables",
+       "name value ...\n"
+       "    - set environment variable 'name' to 'value ...'\n"
+       "setenv name\n"
+       "    - delete environment variable 'name'",
+       var_complete
+),
+CMD_TBL_ITEM(
+       save,   1,      0,      do_env_save,
+       "save environment variables to persistent storage",
+       ""
+),
+CMD_TBL_ITEM(
+       default,        1,      0,      do_env_default,
+       "set all environment variables to their default values",
+       ""
+),
+
+CMD_TBL_ITEM(
+       help,   CONFIG_SYS_MAXARGS,     CTBL_RPT,       do_help,
+       "Print sub command description/usage",
+       "\n"
+       "       - print brief description of all sub commands\n"
+       "env help command ...\n"
+       "       - print detailed usage of sub cmd 'command'"
+),
+
+/* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */
+       {FSTR("?"),   CONFIG_SYS_MAXARGS, 1, do_help,
+        NULL,
+#ifdef  CONFIG_SYS_LONGHELP
+       FSTR(""),
+#endif /* CONFIG_SYS_LONGHELP */
+       NULL,
+#ifdef CONFIG_AUTO_COMPLETE
+       NULL,
+#endif
+},
+/* Mark end of table */
+CMD_TBL_END(cmd_tbl_env)
+};
+
+command_ret_t do_env(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED)
+{
+       return CMD_RET_USAGE;
+}
index 1dbe30f413cf33e02c99882c5bcf2d932afed62f..4666688e1525ebf9ad2cab7593ebdca1a831ec1c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014, 2018 Leo C. <erbl259-lmu@yahoo.de>
  *
  * SPDX-License-Identifier:    GPL-2.0
  */
@@ -9,11 +9,9 @@
 
 #include "command.h"
 
-command_ret_t do_env_print(cmd_tbl_t *, uint_fast8_t, int, char * const []);
-command_ret_t do_env_default(cmd_tbl_t *, uint_fast8_t, int, char * const []);
-command_ret_t do_env_set(cmd_tbl_t *, uint_fast8_t, int, char * const []);
-command_ret_t do_env_save(cmd_tbl_t *, uint_fast8_t, int, char * const []);
+extern cmd_tbl_t cmd_tbl_env[];
 
+command_ret_t do_env(cmd_tbl_t *, uint_fast8_t, int, char * const []);
 int env_init(void);
 char *getenv_str(const MEMX char *name);
 unsigned long getenv_ulong(const MEMX char *name, int base, unsigned long default_val);