]>
cloudbase.mooo.com Git - z180-stamp.git/blob - include/command.h
2 * (C) Copyright 2014-2016 Leo C. <erbl259-lmu@yahoo.de>
4 * (C) Copyright 2000-2009
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * SPDX-License-Identifier: GPL-2.0
11 * Definitions for Command Processor
24 /* Default to a width of 8 characters for help message command width */
25 #ifndef CONFIG_SYS_HELP_CMD_WIDTH
26 #define CONFIG_SYS_HELP_CMD_WIDTH 8
30 * Error codes that commands return to cmd_process(). We use the standard 0
31 * and 1 for success and failure, but add one more case - failure with a
32 * request to call cmd_usage(). But the cmd_process() function handles
33 * CMD_RET_USAGE itself and after calling cmd_usage() it will return 1.
34 * This is just a convenience for commands to avoid them having to call
35 * cmd_usage() all over the place.
38 CMD_RET_SUCCESS
= 0, /* Success */
39 CMD_RET_FAILURE
= 1, /* Failure */
40 CMD_RET_USAGE
= -1, /* Failure, please report 'usage' error */
44 * Monitor Command Table
48 const FLASH
char *name
; /* Command Name */
49 int maxargs
; /* maximum number of arguments */
50 int repeatable
; /* autorepeat allowed? */
51 /* Implementation function */
52 command_ret_t (*cmd
)(const FLASH
struct cmd_tbl_s
*, int, int, char * const []);
53 const FLASH
char *usage
; /* Usage message (short) */
54 #ifdef CONFIG_SYS_LONGHELP
55 const FLASH
char *help
; /* Help message (long) */
57 #ifdef CONFIG_AUTO_COMPLETE
58 /* do auto completion on the arguments */
59 int (*complete
)(int argc
, char * const argv
[], char last_char
, int maxv
, char *cmdv
[]);
63 typedef const FLASH
struct cmd_tbl_s cmd_tbl_t
;
66 * Process a command with arguments. We look up the command and execute it
67 * if valid. Otherwise we print a usage message.
69 * @param flag Some flags normally 0 (see CMD_FLAG_.. above)
70 * @param argc Number of arguments (arg 0 must be the command text)
71 * @param argv Arguments
72 * @param repeatable This function sets this to 0 if the command is not
73 * repeatable. If the command is repeatable, the value
75 * @return 0 if the command succeeded, 1 if it failed
78 cmd_process(int flag
, int argc
, char * const argv
[], uint_fast8_t *repeatable
);
82 command_ret_t
_do_help (cmd_tbl_t
*cmd_start
, int cmd_items
, cmd_tbl_t
* cmdtp
, int
83 flag
, int argc
, char * const argv
[]);
84 cmd_tbl_t
*find_cmd(const char *cmd
);
85 cmd_tbl_t
*find_cmd_tbl (const char *cmd
, cmd_tbl_t
*table
, int table_len
);
87 int cmd_tbl_item_count(void);
88 command_ret_t
cmd_usage(cmd_tbl_t
*cmdtp
);
90 #ifdef CONFIG_AUTO_COMPLETE
91 extern int var_complete(int argc
, char * const argv
[], char last_char
, int maxv
, char *cmdv
[]);
92 extern int cmd_auto_complete(const FLASH
char *const prompt
, char *buf
, int *np
, int *colp
);
96 * cmd_process_error() - report and process a possible error
98 * @cmdtp: Command which caused the error
99 * @err: Error code (0 if none, -ve for error, like -EIO)
100 * @return 0 if there is not error, 1 (CMD_RET_FAILURE) if an error is found
102 int cmd_process_error(cmd_tbl_t
*cmdtp
, int err
);
107 * All commands use a common argument format:
109 * void function (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
113 #ifdef CONFIG_CMD_BOOTD
114 extern command_ret_t
do_bootd(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[]);
116 #ifdef CONFIG_CMD_BOOTM
117 extern command_ret_t
do_bootm(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[]);
118 extern int bootm_maybe_autostart(cmd_tbl_t
*cmdtp
, const char *cmd
);
120 static inline int bootm_maybe_autostart(cmd_tbl_t
*cmdtp
, const char *cmd
)
122 (void) cmdtp
; (void) cmd
;
128 extern int common_diskboot(cmd_tbl_t
*cmdtp
, const char *intf
, int argc
,
131 extern command_ret_t
do_reset(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[]);
136 #define CMD_FLAG_REPEAT 0x0001 /* repeat last command */
137 #define CMD_FLAG_BOOTD 0x0002 /* command is from bootd */
139 #ifdef CONFIG_AUTO_COMPLETE
140 # define _CMD_COMPLETE(x) x,
142 # define _CMD_COMPLETE(x)
144 #ifdef CONFIG_SYS_LONGHELP
145 # define _CMD_HELP(x) x,
147 # define _CMD_HELP(x)
151 #define CMD_TBL_ITEM_COMPLETE(_name, _maxargs, _rep, _cmd, \
152 _usage, _help, _comp) \
153 { FSTR(#_name), _maxargs, _rep, _cmd, FSTR(_usage), \
154 _CMD_HELP(FSTR(_help)) _CMD_COMPLETE(_comp) }
156 #define CMD_TBL_ITEM(_name, _maxargs, _rep, _cmd, _usage, _help) \
157 CMD_TBL_ITEM_COMPLETE(_name, _maxargs, _rep, _cmd, \
160 typedef command_ret_t (*do_cmd_t
)(cmd_tbl_t
*, int, int, char * const []);
162 extern cmd_tbl_t cmd_tbl
[];
164 extern jmp_buf cmd_jbuf
;
167 #endif /* __COMMAND_H */