]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
cli: hush_modern: Enable loops
authorFrancis Laniel <francis.laniel@amarulasolutions.com>
Fri, 22 Dec 2023 21:02:40 +0000 (22:02 +0100)
committerTom Rini <trini@konsulko.com>
Thu, 28 Dec 2023 17:02:56 +0000 (12:02 -0500)
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@amarulasolutions.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
common/cli_hush_modern.c
common/cli_hush_upstream.c

index 6360747f2104f9e487b578bd4dad21245d3e5c7f..fb578c38535926659e75b55aad629353eedec502 100644 (file)
@@ -34,6 +34,7 @@
 #define ENABLE_HUSH_INTERACTIVE        1
 #define ENABLE_FEATURE_EDITING 1
 #define ENABLE_HUSH_IF         1
+#define ENABLE_HUSH_LOOPS      1
 /* No MMU in U-Boot */
 #define BB_MMU                 0
 #define USE_FOR_NOMMU(...)     __VA_ARGS__
index 06af538a4887a662052707ea13a4f851155943ed..748edc9d2fd48ab606e55103c259bd0ad073813e 100644 (file)
@@ -10348,7 +10348,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;
@@ -10450,7 +10450,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_modern(full_var, /*flag:*/ 0);
+#endif /* __U_BOOT__ */
                        continue;
                }
                if (rword == RES_IN) {