[RFC PATCH v2 20/21] cli: hush_2021: Enable loops
Francis Laniel
francis.laniel at amarulasolutions.com
Sun Feb 6 19:37:16 CET 2022
Enables the use of for, while and until loops for command line as
well as with run_command().
Signed-off-by: Francis Laniel <francis.laniel at amarulasolutions.com>
Reviewed-by: Simon Glass <sjg at chromium.org>
---
common/cli_hush_upstream.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c
index 5c783494d1..498fd8d10b 100644
--- a/common/cli_hush_upstream.c
+++ b/common/cli_hush_upstream.c
@@ -10306,7 +10306,7 @@ static int run_list(struct pipe *pi)
#ifndef __U_BOOT__
for (; pi; pi = IF_HUSH_LOOPS(rword == RES_DONE ? loop_top : ) pi->next) {
#else /* __U_BOOT__ */
- for (; pi; pi = pi->next) {
+ for (; pi; pi = rword == RES_DONE ? loop_top : pi->next) {
#endif /* __U_BOOT__ */
int r;
int sv_errexit_depth;
@@ -10408,7 +10408,20 @@ static int run_list(struct pipe *pi)
}
/* Insert next value from for_lcur */
/* note: *for_lcur already has quotes removed, $var expanded, etc */
+#ifndef __U_BOOT__
set_local_var(xasprintf("%s=%s", pi->cmds[0].argv[0], *for_lcur++), /*flag:*/ 0);
+#else /* __U_BOOT__ */
+ /* We cannot use xasprintf, so we emulate it. */
+ char *full_var;
+ char *var = pi->cmds[0].argv[0];
+ char *val = *for_lcur++;
+
+ /* + 1 to take into account =. */
+ full_var = xmalloc(strlen(var) + strlen(val) + 1);
+ sprintf(full_var, "%s=%s", var, val);
+
+ set_local_var(full_var, /*flag:*/ 0);
+#endif /* __U_BOOT__ */
continue;
}
if (rword == RES_IN) {
--
2.25.1
More information about the U-Boot
mailing list