X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/022330eb94f180b0b626988d294ce43c2191ad61..c82e9b3342cb1971d2d6e66d4537f2ae3ba6c72c:/avr/command.c diff --git a/avr/command.c b/avr/command.c index b0d9c90..8a4ca02 100644 --- a/avr/command.c +++ b/avr/command.c @@ -13,7 +13,6 @@ #include "command.h" #include "common.h" -#include #include #include "config.h" @@ -22,6 +21,7 @@ #include "env.h" #include "debug.h" #include "getopt-min.h" +#include "strerror.h" #define DEBUG_CMD 0 /* set to 1 to debug */ @@ -261,9 +261,6 @@ command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag UNUSED, int argc, char #define OPT_USAGE 0x08 #define OPT_LONG 0x10 - /* reset getopt() */ - optind = 0; - int opt; while ((opt = getopt(argc, argv, PSTR("afk"))) != -1) { switch (opt) { @@ -707,7 +704,7 @@ static cmd_tbl_t *cmd_invocation_ptr; * @param argv Arguments * @return 0 if command succeeded, else non-zero (CMD_RET_...) */ -command_ret_t cmd_call(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]) +static command_ret_t cmd_call(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]) { command_ret_t result; @@ -769,6 +766,7 @@ command_ret_t cmd_process(uint_fast8_t flag, int argc, char * const argv[], /* If OK so far, then do the command */ if (!rc) { + optind = 0; /* reset getopt() */ cmd_invocation_ptr = cmdtp; rc = cmd_call(cmdtp, flag, argc, argv); *repeatable &= (cmdtp->flags & CTBL_RPT) != 0; @@ -791,16 +789,24 @@ int cmd_process_error(cmd_tbl_t *cmdtp, int err) return 0; } - -void cmd_error(const char *fmt, ...) +void cmd_error(int status, int errnum, const char *fmt, ...) { va_list ap; va_start(ap, fmt); print_prefixed_name(cmd_invocation_ptr); - my_puts_P(PSTR(": ")); - vfprintf_P(stdout, fmt, ap); + if (fmt != NULL) { + my_puts_P(PSTR(": ")); + vfprintf_P(stdout, fmt, ap); + } va_end(ap); + + if (errnum != 0) + printf_P(PSTR(": %S"), my_strerror_P(errnum)); + putchar('\n'); _delay_ms(20); - //command_ret = CMD_RET_FAILURE; + + if (status != 0) { + longjmp(cmd_jbuf, 1); + } }