X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/13e88ed59974b6940815b6a392266ad34a9ee410..0dd441e803f3563839541e7526f8294032aa7743:/avr/cli.c diff --git a/avr/cli.c b/avr/cli.c index 891a26a..b96ca1b 100644 --- a/avr/cli.c +++ b/avr/cli.c @@ -12,16 +12,10 @@ */ #include "cli.h" -#include "common.h" - -#include +#include "command.h" #include -#include -#include #include "config.h" -#include "command.h" -#include "xmalloc.h" #include "debug.h" #include "env.h" #include "cli_readline.h" @@ -156,7 +150,12 @@ char *process_macros(char *input, char *output) outp = output; } else { int outputlen = outp - output; - outp = xrealloc(output, outputlen); + outp = realloc(output, outputlen); + if (outp == NULL) { + free(output); + output = outp; + break; + } output = outp; } @@ -237,7 +236,7 @@ char *process_macros(char *input, char *output) * @returns * */ -static int cli_run_command(const char *cmd, int flag) +static int cli_run_command(const char *cmd, uint_fast8_t flag) { char *cmdbuf; /* working copy of cmd */ char *token; /* start of token in cmdbuf */ @@ -315,6 +314,10 @@ static int cli_run_command(const char *cmd, int flag) /* find macros in this token and replace them */ finaltoken = process_macros(token, finaltoken); + if (finaltoken == NULL) { + rc = -1; /* no command at all */ + break; + } /* Extract arguments */ argc = cli_parse_line(finaltoken, argv); @@ -362,7 +365,7 @@ static int cli_run_command_list(const char *cmd) * @param flag Execution flags (CMD_FLAG_...) * @return 0 on success, or != 0 on error. */ -int run_command(const char *cmd, int flag) +int run_command(const char *cmd, uint_fast8_t flag) { /* * cli_run_command can return 0 or 1 for success, so clean up @@ -381,7 +384,7 @@ int run_command(const char *cmd, int flag) * @param flag Execution flags (CMD_FLAG_...) * @return 0 (not repeatable) or 1 (repeatable) on success, -1 on error. */ -static int run_command_repeatable(const char *cmd, int flag) +static int run_command_repeatable(const char *cmd, uint_fast8_t flag) { return cli_run_command(cmd, flag); } @@ -400,11 +403,11 @@ void cli_loop(void) { char *lastcommand = NULL; int len; - int flag; + uint_fast8_t flag; int rc = 1; for (;;) { - len = cli_readline(PSTR(CONFIG_SYS_PROMPT), 1); + len = cli_readline(lastcommand ? PSTR(CONFIG_SYS_PROMPT_REPEAT) : PSTR(CONFIG_SYS_PROMPT), 1); flag = 0; /* assume no special flags for now */ if (len > 0) {