]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
Enable execution of individual sub commands on top level
authorLeo C <erbl259-lmu@yahoo.de>
Fri, 27 Jul 2018 22:49:48 +0000 (00:49 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Fri, 27 Jul 2018 23:22:36 +0000 (01:22 +0200)
avr/cmd_fat.c
avr/cmd_sd.c
avr/command.c
avr/command_tbl.c
include/command.h

index 52ad95f498c524f27f2cb166d2491e8859ae9610..0c1d0e73aebb0109feec7194bdbe43909711f9d5 100644 (file)
@@ -534,17 +534,17 @@ CMD_TBL_ITEM(
        "dev"
 ),
 CMD_TBL_ITEM(
        "dev"
 ),
 CMD_TBL_ITEM(
-       pwd,    2,      CTBL_RPT,       do_pwd,
+       pwd,    2,      CTBL_RPT|CTBL_SUBCMDAUTO,       do_pwd,
        "Print name of current/working directory",
        ""
 ),
 CMD_TBL_ITEM(
        "Print name of current/working directory",
        ""
 ),
 CMD_TBL_ITEM(
-       cd,             2,      0,                      do_cd,
+       cd,             2,      0|CTBL_SUBCMDAUTO,                      do_cd,
        "Change the current/working directory.",
        "path"
 ),
 CMD_TBL_ITEM(
        "Change the current/working directory.",
        "path"
 ),
 CMD_TBL_ITEM(
-       ls,             2,      CTBL_RPT,       do_ls,
+       ls,             2,      CTBL_RPT|CTBL_SUBCMDAUTO,       do_ls,
        "Directory listing",
        "path"
 ),
        "Directory listing",
        "path"
 ),
@@ -578,7 +578,7 @@ CMD_TBL_ITEM(
 
 /* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */
        {FSTR("?"),   CONFIG_SYS_MAXARGS, 1, do_help,
 
 /* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */
        {FSTR("?"),   CONFIG_SYS_MAXARGS, 1, do_help,
-        FSTR("Alias for 'help'"),
+        NULL,
 #ifdef  CONFIG_SYS_LONGHELP
        FSTR(""),
 #endif /* CONFIG_SYS_LONGHELP */
 #ifdef  CONFIG_SYS_LONGHELP
        FSTR(""),
 #endif /* CONFIG_SYS_LONGHELP */
index 06c933852cb1f5df1ce8885bbcaea12a35f89ab6..1612a6fac97f6b5c13c4789a403a0da7aeaf3f2d 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
  */
  *
  * SPDX-License-Identifier:    GPL-2.0
  */
@@ -317,7 +317,7 @@ command_ret_t do_ioctl_sync(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char
 cmd_tbl_t cmd_tbl_sd[] = {
 CMD_TBL_ITEM(
        status, 2,                      CTBL_RPT,       do_status,
 cmd_tbl_t cmd_tbl_sd[] = {
 CMD_TBL_ITEM(
        status, 2,                      CTBL_RPT,       do_status,
-       "Socket staus",
+       "Socket status",
        "drive"
 ),
 CMD_TBL_ITEM(
        "drive"
 ),
 CMD_TBL_ITEM(
@@ -362,7 +362,7 @@ CMD_TBL_ITEM(
 
 /* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */
        {FSTR("?"),   CONFIG_SYS_MAXARGS, 1, do_help,
 
 /* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */
        {FSTR("?"),   CONFIG_SYS_MAXARGS, 1, do_help,
-        FSTR("Alias for 'help'"),
+        NULL,
 #ifdef  CONFIG_SYS_LONGHELP
        FSTR(""),
 #endif /* CONFIG_SYS_LONGHELP */
 #ifdef  CONFIG_SYS_LONGHELP
        FSTR(""),
 #endif /* CONFIG_SYS_LONGHELP */
@@ -376,7 +376,7 @@ CMD_TBL_END(cmd_tbl_sd)
 };
 
 
 };
 
 
-command_ret_t do_sd(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
+command_ret_t do_sd(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED)
 {
        puts_P(PSTR("Huch?"));
        return CMD_RET_USAGE;
 {
        puts_P(PSTR("Huch?"));
        return CMD_RET_USAGE;
index c8a73f0bea37facb1b640451e5dd30d55dedd324..c9137eabc83e3f4cf23636f88124d49087afc928 100644 (file)
@@ -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.
  *
  * (C) Copyright 2000-2009
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
@@ -13,8 +13,6 @@
 
 #include "command.h"
 #include "common.h"
 
 #include "command.h"
 #include "common.h"
-#include <stdlib.h>
-#include <string.h>
 #include <ctype.h>
 #include <setjmp.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) {
        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;
                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);
                        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;
                        }
                                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;
 
                /* 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);
                }
                /* 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 &&
         */
        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'"
                        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);
 {
 //     printf("%s - %s\n\n", cmdtp->name, cmdtp->usage);
        print_usage_line(cmdtp->name, 0, cmdtp->usage);
index 5e2d1d041902a0ee8231f4cecb7b834467950ac8..7a6b776b4cd7f52927a505d7414c6485ea541c18 100644 (file)
@@ -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>
  *
  * SPDX-License-Identifier:    GPL-2.0
  */
  *
  * SPDX-License-Identifier:    GPL-2.0
  */
@@ -271,12 +271,12 @@ CMD_TBL_ITEM(
        "   -l  write value as long (32 bit)"
 ),
 CMD_TBL_ITEM(
        "   -l  write value as long (32 bit)"
 ),
 CMD_TBL_ITEM(
-       cp,     4,      CTBL_RPT,       do_mem_cp,
+       mcp,    4,      CTBL_RPT,       do_mem_cp,
        "memory copy",
        "source target count"
 ),
 CMD_TBL_ITEM(
        "memory copy",
        "source target count"
 ),
 CMD_TBL_ITEM(
-       cmp,    4,      CTBL_RPT,       do_mem_cmp,
+       mcmp,   4,      CTBL_RPT,       do_mem_cmp,
        "memory compare",
        "addr1 addr2 count"
 ),
        "memory compare",
        "addr1 addr2 count"
 ),
@@ -324,7 +324,7 @@ CMD_TBL_ITEM(
 #endif /* CONFIG_MX_CYCLIC */
 
 CMD_TBL_ITEM_TOP(
 #endif /* CONFIG_MX_CYCLIC */
 
 CMD_TBL_ITEM_TOP(
-       sd,   CONFIG_SYS_MAXARGS, CTBL_SUBCMDAUTO, do_sd,
+       sd,   CONFIG_SYS_MAXARGS, 0, do_sd,
        "SD/MMC card handling commands",
        "<subcommand> args ...\n"
        "sd help\n"
        "SD/MMC card handling commands",
        "<subcommand> args ...\n"
        "sd help\n"
@@ -332,7 +332,7 @@ CMD_TBL_ITEM_TOP(
        cmd_tbl_sd
 ),
 CMD_TBL_ITEM_TOP(
        cmd_tbl_sd
 ),
 CMD_TBL_ITEM_TOP(
-       fat,   CONFIG_SYS_MAXARGS, CTBL_SUBCMD|CTBL_SUBCMDAUTO, do_fat,
+       fat,   CONFIG_SYS_MAXARGS, CTBL_SUBCMDAUTO, do_fat,
        "fat filesystem commands",
        "<subcommand> args ...\n"
        "fat help\n"
        "fat filesystem commands",
        "<subcommand> args ...\n"
        "fat help\n"
index d7eccc932da18dbb624ce3186412f0729b627978..614d5273c948f17fc87fe1ade262064fe62638d3 100644 (file)
@@ -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.
  *
  * (C) Copyright 2000-2009
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
@@ -50,13 +50,12 @@ struct cmd_tbl_s {
        uint8_t         maxargs;                        /* maximum number of arguments  */
        uint8_t         flags;                  /* autorepeat allowed?          */
                                                                /* Implementation function      */
        uint8_t         maxargs;                        /* maximum number of arguments  */
        uint8_t         flags;                  /* autorepeat allowed?          */
                                                                /* Implementation function      */
-       command_ret_t   (*cmd)(const FLASH struct cmd_tbl_s *, uint_fast8_t, int, char * const []);
+       command_ret_t   (*cmd)(cmd_tbl_t *, uint_fast8_t, int, char * const []);
        const FLASH char *usage;        /* Usage message        (short) */
 #ifdef CONFIG_SYS_LONGHELP
        const FLASH char *help;         /* Help  message        (long)  */
 #endif
        cmd_tbl_t *subcmd;
        const FLASH char *usage;        /* Usage message        (short) */
 #ifdef CONFIG_SYS_LONGHELP
        const FLASH char *help;         /* Help  message        (long)  */
 #endif
        cmd_tbl_t *subcmd;
-//     const FLASH struct cmd_tbl_s *subcommands;
 #ifdef CONFIG_AUTO_COMPLETE
        /* do auto completion on the arguments */
        int             (*complete)(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]);
 #ifdef CONFIG_AUTO_COMPLETE
        /* do auto completion on the arguments */
        int             (*complete)(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]);