]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - include/command.h
Call subcommands from main command processor
[z180-stamp.git] / include / command.h
index 75b5a0d98271d481c12fe04aaa5068f19a0ad261..5e55e471e885dda39822bd07e696a82094169164 100644 (file)
@@ -44,6 +44,7 @@ typedef enum {
  * Monitor Command Table
  */
 
+typedef const FLASH struct cmd_tbl_s cmd_tbl_t;
 struct cmd_tbl_s {
        const FLASH char *name;         /* Command Name                 */
        uint8_t         maxargs;                        /* maximum number of arguments  */
@@ -54,14 +55,14 @@ struct cmd_tbl_s {
 #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[]);
 #endif
 };
 
-typedef const FLASH struct cmd_tbl_s cmd_tbl_t;
-
 /**
  * Process a command with arguments. We look up the command and execute it
  * if valid. Otherwise we print a usage message.
@@ -79,11 +80,10 @@ 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 *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, uint_fast8_t flag, int argc, char * const argv[]);
-cmd_tbl_t *find_cmd(const char *cmd);
-cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len);
+command_ret_t _do_help (cmd_tbl_t *cmd_start, cmd_tbl_t * cmdtp, uint_fast8_t flag, int argc, char * const argv[]);
+cmd_tbl_t *find_cmd (const char *cmd, cmd_tbl_t *table);
 
-int cmd_tbl_item_count(void);
+int cmd_tbl_item_count(cmd_tbl_t *p);
 command_ret_t cmd_usage(cmd_tbl_t *cmdtp);
 
 #ifdef CONFIG_AUTO_COMPLETE
@@ -151,14 +151,23 @@ extern command_ret_t do_reset(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, cha
 #endif
 
 
-#define CMD_TBL_ITEM_COMPLETE(_name, _maxargs, _rep, _cmd,             \
-                               _usage, _help, _comp)                   \
-               { FSTR(#_name), _maxargs, _rep, _cmd, FSTR(_usage),     \
-                       _CMD_HELP(FSTR(_help)) _CMD_COMPLETE(_comp) }
+#define CMD_TBL_ITEM_FULL(_name, _maxargs, _rep, _cmd,                         \
+                               _usage, _help, _subtbl, _comp)                                 \
+               { FSTR(#_name), _maxargs, _rep, _cmd, FSTR(_usage),                        \
+                       _CMD_HELP(FSTR(_help)) _subtbl, _CMD_COMPLETE(_comp) }
+
+#define CMD_TBL_ITEM_COMPLETE(_name, _maxargs, _rep, _cmd,                     \
+                               _usage, _help, _comp)                                          \
+               { FSTR(#_name), _maxargs, _rep, _cmd, FSTR(_usage),                        \
+                       _CMD_HELP(FSTR(_help)) NULL, _CMD_COMPLETE(_comp) }
+
+#define CMD_TBL_ITEM(_name, _maxargs, _rep, _cmd, _usage, _help)               \
+       CMD_TBL_ITEM_FULL(_name, _maxargs, _rep, _cmd,                             \
+                                       _usage, _help, NULL, NULL)
 
-#define CMD_TBL_ITEM(_name, _maxargs, _rep, _cmd, _usage, _help)       \
-       CMD_TBL_ITEM_COMPLETE(_name, _maxargs, _rep, _cmd,              \
-                                       _usage, _help, NULL)
+#define CMD_TBL_ITEM_TOP(_name, _maxargs, _rep, _cmd, _usage, _help, _subtbl)  \
+       CMD_TBL_ITEM_FULL(_name, _maxargs, _rep, _cmd,                             \
+                                       _usage, _help, _subtbl, NULL)
 
 typedef command_ret_t (*do_cmd_t)(cmd_tbl_t *, uint_fast8_t, int, char * const []);