diff options
author | Simon Glass <sjg@chromium.org> | 2012-02-14 19:59:25 +0000 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2012-03-06 21:09:41 +0100 |
commit | 9d12d5d41d5653ba2f943886f45b8c2eb0f63450 (patch) | |
tree | 03ea18e10cb7c8f06bf82525c8aacad91938ad93 /include | |
parent | 7344f9128dfa797a9b9d51b38832f77a1eaeac2d (diff) | |
download | u-boot-imx-9d12d5d41d5653ba2f943886f45b8c2eb0f63450.zip u-boot-imx-9d12d5d41d5653ba2f943886f45b8c2eb0f63450.tar.gz u-boot-imx-9d12d5d41d5653ba2f943886f45b8c2eb0f63450.tar.bz2 |
Add cmd_process() to process commands in one place
We currently have the same code in hush.c and main.c. This brings the
code into one place.
As an added feature, if the command function returns CMD_RET_USAGE then
cmd_process() will print a usage message for the command before
returning the standard failure code of 1.
ARM code size increases about 32 bytes with this clean-up.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/command.h | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/include/command.h b/include/command.h index 6dc694f..6e1bdc2 100644 --- a/include/command.h +++ b/include/command.h @@ -112,7 +112,34 @@ static inline int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd) #endif extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); -int cmd_call(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); +/* + * Error codes that commands return to cmd_process(). We use the standard 0 + * and 1 for success and failure, but add one more case - failure with a + * request to call cmd_usage(). But the cmd_process() function handles + * CMD_RET_USAGE itself and after calling cmd_usage() it will return 1. + * This is just a convenience for commands to avoid them having to call + * cmd_usage() all over the place. + */ +enum command_ret_t { + CMD_RET_SUCCESS, /* 0 = Success */ + CMD_RET_FAILURE, /* 1 = Failure */ + CMD_RET_USAGE = -1, /* Failure, please report 'usage' error */ +}; + +/** + * Process a command with arguments. We look up the command and execute it + * if valid. Otherwise we print a usage message. + * + * @param flag Some flags normally 0 (see CMD_FLAG_.. above) + * @param argc Number of arguments (arg 0 must be the command text) + * @param argv Arguments + * @param repeatable This function sets this to 0 if the command is not + * repeatable. If the command is repeatable, the value + * is left unchanged. + * @return 0 if the command succeeded, 1 if it failed + */ +int cmd_process(int flag, int argc, char * const argv[], + int *repeatable); #endif /* __ASSEMBLY__ */ |