mirror of
https://github.com/smaeul/u-boot.git
synced 2025-10-18 06:38:15 +01:00
cli: hush_modern: Enable if keyword
Adds support for "if then else" construct both for command line interface and through run_command(). Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
d8b256308d
commit
374b77ed9e
@ -33,6 +33,7 @@
|
|||||||
*/
|
*/
|
||||||
#define ENABLE_HUSH_INTERACTIVE 1
|
#define ENABLE_HUSH_INTERACTIVE 1
|
||||||
#define ENABLE_FEATURE_EDITING 1
|
#define ENABLE_FEATURE_EDITING 1
|
||||||
|
#define ENABLE_HUSH_IF 1
|
||||||
/* No MMU in U-Boot */
|
/* No MMU in U-Boot */
|
||||||
#define BB_MMU 0
|
#define BB_MMU 0
|
||||||
#define USE_FOR_NOMMU(...) __VA_ARGS__
|
#define USE_FOR_NOMMU(...) __VA_ARGS__
|
||||||
@ -124,6 +125,11 @@ static void bb_error_msg(const char *s, ...)
|
|||||||
va_end(p);
|
va_end(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void bb_simple_error_msg(const char *s)
|
||||||
|
{
|
||||||
|
bb_error_msg("%s", s);
|
||||||
|
}
|
||||||
|
|
||||||
static void *xmalloc(size_t size)
|
static void *xmalloc(size_t size)
|
||||||
{
|
{
|
||||||
void *p = NULL;
|
void *p = NULL;
|
||||||
@ -147,6 +153,11 @@ static void *xrealloc(void *ptr, size_t size)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *xmemdup(const void *s, int n)
|
||||||
|
{
|
||||||
|
return memcpy(xmalloc(n), s, n);
|
||||||
|
}
|
||||||
|
|
||||||
#define xstrdup strdup
|
#define xstrdup strdup
|
||||||
#define xstrndup strndup
|
#define xstrndup strndup
|
||||||
|
|
||||||
|
@ -1487,7 +1487,6 @@ static void msg_and_die_if_script(unsigned lineno, const char *fmt, ...)
|
|||||||
die_if_script();
|
die_if_script();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __U_BOOT__
|
|
||||||
static void syntax_error(unsigned lineno UNUSED_PARAM, const char *msg)
|
static void syntax_error(unsigned lineno UNUSED_PARAM, const char *msg)
|
||||||
{
|
{
|
||||||
if (msg)
|
if (msg)
|
||||||
@ -1496,7 +1495,6 @@ static void syntax_error(unsigned lineno UNUSED_PARAM, const char *msg)
|
|||||||
bb_simple_error_msg("syntax error");
|
bb_simple_error_msg("syntax error");
|
||||||
die_if_script();
|
die_if_script();
|
||||||
}
|
}
|
||||||
#endif /* !__U_BOOT__ */
|
|
||||||
|
|
||||||
static void syntax_error_at(unsigned lineno UNUSED_PARAM, const char *msg)
|
static void syntax_error_at(unsigned lineno UNUSED_PARAM, const char *msg)
|
||||||
{
|
{
|
||||||
@ -3961,7 +3959,6 @@ static void debug_print_tree(struct pipe *pi, int lvl)
|
|||||||
[PIPE_OR ] = "OR" ,
|
[PIPE_OR ] = "OR" ,
|
||||||
[PIPE_BG ] = "BG" ,
|
[PIPE_BG ] = "BG" ,
|
||||||
};
|
};
|
||||||
#ifndef __U_BOOT__
|
|
||||||
static const char *RES[] = {
|
static const char *RES[] = {
|
||||||
[RES_NONE ] = "NONE" ,
|
[RES_NONE ] = "NONE" ,
|
||||||
# if ENABLE_HUSH_IF
|
# if ENABLE_HUSH_IF
|
||||||
@ -3991,7 +3988,6 @@ static void debug_print_tree(struct pipe *pi, int lvl)
|
|||||||
[RES_XXXX ] = "XXXX" ,
|
[RES_XXXX ] = "XXXX" ,
|
||||||
[RES_SNTX ] = "SNTX" ,
|
[RES_SNTX ] = "SNTX" ,
|
||||||
};
|
};
|
||||||
#endif /* !__U_BOOT__ */
|
|
||||||
static const char *const CMDTYPE[] = {
|
static const char *const CMDTYPE[] = {
|
||||||
"{}",
|
"{}",
|
||||||
"()",
|
"()",
|
||||||
@ -4009,10 +4005,8 @@ static void debug_print_tree(struct pipe *pi, int lvl)
|
|||||||
lvl*2, "",
|
lvl*2, "",
|
||||||
pin,
|
pin,
|
||||||
pi->num_cmds,
|
pi->num_cmds,
|
||||||
#ifdef __U_BOOT__
|
|
||||||
(IF_HAS_KEYWORDS(pi->pi_inverted ? "! " :) ""),
|
(IF_HAS_KEYWORDS(pi->pi_inverted ? "! " :) ""),
|
||||||
RES[pi->res_word],
|
RES[pi->res_word],
|
||||||
#endif /* !__U_BOOT__ */
|
|
||||||
pi->followup, PIPE[pi->followup]
|
pi->followup, PIPE[pi->followup]
|
||||||
);
|
);
|
||||||
prn = 0;
|
prn = 0;
|
||||||
@ -9832,6 +9826,7 @@ static NOINLINE int run_pipe(struct pipe *pi)
|
|||||||
rcode = 1; /* exitcode if redir failed */
|
rcode = 1; /* exitcode if redir failed */
|
||||||
#ifndef __U_BOOT__
|
#ifndef __U_BOOT__
|
||||||
if (setup_redirects(command, &squirrel) == 0) {
|
if (setup_redirects(command, &squirrel) == 0) {
|
||||||
|
#endif /* !__U_BOOT__ */
|
||||||
debug_printf_exec(": run_list\n");
|
debug_printf_exec(": run_list\n");
|
||||||
//FIXME: we need to pass squirrel down into run_list()
|
//FIXME: we need to pass squirrel down into run_list()
|
||||||
//for SH_STANDALONE case, or else this construct:
|
//for SH_STANDALONE case, or else this construct:
|
||||||
@ -9840,10 +9835,11 @@ static NOINLINE int run_pipe(struct pipe *pi)
|
|||||||
//and in SH_STANDALONE mode, "find" is not execed,
|
//and in SH_STANDALONE mode, "find" is not execed,
|
||||||
//therefore CLOEXEC on saved fd does not help.
|
//therefore CLOEXEC on saved fd does not help.
|
||||||
rcode = run_list(command->group) & 0xff;
|
rcode = run_list(command->group) & 0xff;
|
||||||
|
#ifndef __U_BOOT__
|
||||||
}
|
}
|
||||||
restore_redirects(squirrel);
|
restore_redirects(squirrel);
|
||||||
IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;)
|
|
||||||
#endif /* !__U_BOOT__ */
|
#endif /* !__U_BOOT__ */
|
||||||
|
IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;)
|
||||||
debug_leave();
|
debug_leave();
|
||||||
debug_printf_exec("run_pipe: return %d\n", rcode);
|
debug_printf_exec("run_pipe: return %d\n", rcode);
|
||||||
return rcode;
|
return rcode;
|
||||||
@ -10362,12 +10358,12 @@ static int run_list(struct pipe *pi)
|
|||||||
break;
|
break;
|
||||||
if (G_flag_return_in_progress == 1)
|
if (G_flag_return_in_progress == 1)
|
||||||
break;
|
break;
|
||||||
|
#endif /* !__U_BOOT__ */
|
||||||
|
|
||||||
IF_HAS_KEYWORDS(rword = pi->res_word;)
|
IF_HAS_KEYWORDS(rword = pi->res_word;)
|
||||||
debug_printf_exec(": rword=%d cond_code=%d last_rword=%d\n",
|
debug_printf_exec(": rword=%d cond_code=%d last_rword=%d\n",
|
||||||
rword, cond_code, last_rword);
|
rword, cond_code, last_rword);
|
||||||
|
|
||||||
#endif /* !__U_BOOT__ */
|
|
||||||
sv_errexit_depth = G.errexit_depth;
|
sv_errexit_depth = G.errexit_depth;
|
||||||
if (
|
if (
|
||||||
#if ENABLE_HUSH_IF
|
#if ENABLE_HUSH_IF
|
||||||
|
Loading…
x
Reference in New Issue
Block a user