X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fcli_hush.c;h=00861e2d9e4b56c114a4dcae71fdbb0f89a996aa;hb=267c5b79899dcbdfa190b8c6633a2bf517a73123;hp=296542f4c2d62b7094694a40c79c7d2fe9fdf545;hpb=21008ad6384170767041f1608975473c5ffa7fc7;p=u-boot diff --git a/common/cli_hush.c b/common/cli_hush.c index 296542f4c2..00861e2d9e 100644 --- a/common/cli_hush.c +++ b/common/cli_hush.c @@ -79,6 +79,7 @@ #include /* malloc, free, realloc*/ #include /* isalpha, isdigit */ #include /* readline */ +#include #include #include #include @@ -973,6 +974,30 @@ static inline void setup_prompt_string(int promptmode, char **prompt_str) } #endif +#ifdef __U_BOOT__ +static int uboot_cli_readline(struct in_str *i) +{ + char *prompt; + char __maybe_unused *ps_prompt = NULL; + + if (i->promptmode == 1) + prompt = CONFIG_SYS_PROMPT; + else + prompt = CONFIG_SYS_PROMPT_HUSH_PS2; + +#ifdef CONFIG_CMDLINE_PS_SUPPORT + if (i->promptmode == 1) + ps_prompt = getenv("PS1"); + else + ps_prompt = getenv("PS2"); + if (ps_prompt) + prompt = ps_prompt; +#endif + + return cli_readline(prompt); +} +#endif + static void get_user_input(struct in_str *i) { #ifndef __U_BOOT__ @@ -1002,11 +1027,8 @@ static void get_user_input(struct in_str *i) bootretry_reset_cmd_timeout(); i->__promptme = 1; - if (i->promptmode == 1) { - n = cli_readline(CONFIG_SYS_PROMPT); - } else { - n = cli_readline(CONFIG_SYS_PROMPT_HUSH_PS2); - } + n = uboot_cli_readline(i); + #ifdef CONFIG_BOOT_RETRY_TIME if (n == -2) { puts("\nTimeout waiting for command\n"); @@ -2161,7 +2183,7 @@ int set_local_var(const char *s, int flg_export) * NAME=VALUE format. So the first order of business is to * split 's' on the '=' into 'name' and 'value' */ value = strchr(name, '='); - if (value == NULL && ++value == NULL) { + if (value == NULL || *(value + 1) == 0) { free(name); return -1; } @@ -2470,11 +2492,16 @@ static int done_word(o_string *dest, struct p_context *ctx) } argc = ++child->argc; child->argv = realloc(child->argv, (argc+1)*sizeof(*child->argv)); - if (child->argv == NULL) return 1; + if (child->argv == NULL) { + free(str); + return 1; + } child->argv_nonnull = realloc(child->argv_nonnull, (argc+1)*sizeof(*child->argv_nonnull)); - if (child->argv_nonnull == NULL) + if (child->argv_nonnull == NULL) { + free(str); return 1; + } child->argv[argc-1]=str; child->argv_nonnull[argc-1] = dest->nonnull; child->argv[argc]=NULL; @@ -3502,9 +3529,9 @@ static char *insert_var_value_sub(char *inp, int tag_subst) char *p, *p1, *res_str = NULL; while ((p = strchr(inp, SPECIAL_VAR_SYMBOL))) { - /* check the beginning of the string for normal charachters */ + /* check the beginning of the string for normal characters */ if (p != inp) { - /* copy any charachters to the result string */ + /* copy any characters to the result string */ len = p - inp; res_str = xrealloc(res_str, (res_str_len + len)); strncpy((res_str + res_str_len), inp, len);