]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - include/command.h
Find subcommands without prefix
[z180-stamp.git] / include / command.h
index 2fd20a0b4855382fb5d08911a123237d5c19e379..fb7f9b8bee117b3cdcd5049c8847a6e949f86226 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * (C) Copyright 2014-2016 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * (C) Copyright 2000-2009
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * SPDX-License-Identifier:    GPL-2.0
+ */
 
 /*
  *  Definitions for Command Processor
@@ -7,6 +15,7 @@
 
 #include "common.h"
 #include "config.h"
+#include <setjmp.h>
 
 #ifndef NULL
 #define NULL   0
@@ -26,8 +35,8 @@
  * cmd_usage() all over the place.
  */
 typedef enum {
-       CMD_RET_SUCCESS,        /* 0 = Success */
-       CMD_RET_FAILURE,        /* 1 = Failure */
+       CMD_RET_SUCCESS = 0,    /* Success */
+       CMD_RET_FAILURE = 1,    /* Failure */
        CMD_RET_USAGE = -1,     /* Failure, please report 'usage' error */
 } command_ret_t;
 
@@ -35,26 +44,25 @@ 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                 */
-       int             maxargs;        /* maximum number of arguments  */
-       int             repeatable;     /* autorepeat allowed?          */
-                                       /* Implementation function      */
-       command_ret_t   (*cmd)(const FLASH struct cmd_tbl_s *, int, int, char * const []);
-       const FLASH char *usage;                /* Usage message        (short) */
+       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 []);
+       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[]);
 #endif
 };
 
-typedef const FLASH struct cmd_tbl_s cmd_tbl_t;
-
-extern command_ret_t do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
-
 /**
  * Process a command with arguments. We look up the command and execute it
  * if valid. Otherwise we print a usage message.
@@ -68,16 +76,13 @@ extern command_ret_t do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const a
  * @return 0 if the command succeeded, 1 if it failed
  */
 command_ret_t
-cmd_process(int flag, int argc, char * const argv[], uint_fast8_t *repeatable);
+cmd_process(uint_fast8_t flag, int argc, char * const argv[], uint_fast8_t *repeatable);
 
 
 /* command.c */
-command_ret_t _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
-             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 *cmdtp, uint_fast8_t flag, int argc, char * const argv[]);
 
-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
@@ -99,21 +104,19 @@ int cmd_process_error(cmd_tbl_t *cmdtp, int err);
  *
  * All commands use a common argument format:
  *
- * void function (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+ * void function (cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]);
  */
 
 
 #ifdef CONFIG_CMD_BOOTD
-extern command_ret_t do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+extern command_ret_t do_bootd(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]);
 #endif
 #ifdef CONFIG_CMD_BOOTM
-extern command_ret_t do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+extern command_ret_t do_bootm(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]);
 extern int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd);
 #else
-static inline int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
+static inline int bootm_maybe_autostart(cmd_tbl_t *cmdtp UNUSED, const char *cmd UNUSED)
 {
-       (void) cmdtp; (void) cmd;
-
        return 0;
 }
 #endif
@@ -121,13 +124,18 @@ static inline int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
 extern int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
                           char *const argv[]);
 
-extern command_ret_t do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
-
 /*
  * Command Flags:
  */
-#define CMD_FLAG_REPEAT                0x0001  /* repeat last command          */
-#define CMD_FLAG_BOOTD         0x0002  /* command is from bootd        */
+#define CMD_FLAG_REPEAT                0x01    /* repeat last command          */
+#define CMD_FLAG_BOOTD         0x02    /* command is from bootd        */
+
+/*
+ * Flags for command table:
+ */
+#define CTBL_REPEAT                    0x01    /* command is repeatable        */
+#define CTBL_SUBCMD                    0x02    /* command has subcommands      */
+#define CTBL_SUBCMDAUTO                0x04    /* execute subcommands whithout prefix*/
 
 #ifdef CONFIG_AUTO_COMPLETE
 # define _CMD_COMPLETE(x) x,
@@ -141,18 +149,31 @@ extern command_ret_t do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const
 #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(_name, _maxargs, _rep, _cmd, _usage, _help)       \
-       CMD_TBL_ITEM_COMPLETE(_name, _maxargs, _rep, _cmd,              \
-                                       _usage, _help, NULL)
+#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) }
 
-typedef command_ret_t (*do_cmd_t)(cmd_tbl_t *, int, int, char * const []);
+#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_TOP(_name, _maxargs, _rep, _cmd, _usage, _help, _subtbl)  \
+       CMD_TBL_ITEM_FULL(_name, _maxargs, _rep, _cmd,                             \
+                                       _usage, _help, _subtbl, NULL)
+
+#define CMD_TBL_END(_table_start)      { .subcmd = _table_start }
+
+typedef command_ret_t (*do_cmd_t)(cmd_tbl_t *, uint_fast8_t, int, char * const []);
 
 extern  cmd_tbl_t cmd_tbl[];
 
+extern jmp_buf cmd_jbuf;
+
 
 #endif /* __COMMAND_H */