Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA3B8C433F5 for ; Sun, 6 Feb 2022 18:41:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 33C9D83C28; Sun, 6 Feb 2022 19:38:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="F1nzKPVK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8281D83BD7; Sun, 6 Feb 2022 19:38:49 +0100 (CET) Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6572283C27 for ; Sun, 6 Feb 2022 19:37:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=francis.laniel@amarulasolutions.com Received: by mail-wm1-x32d.google.com with SMTP id k127-20020a1ca185000000b0037bc4be8713so769035wme.3 for ; Sun, 06 Feb 2022 10:37:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ED2V7mLLmceWSpTZ2HRbRSuu92TU1UX2D0biNt7UyNM=; b=F1nzKPVK+so4wYaK+zUYViYhKLdUk6T+SHDqXbbq6356ra3pEzLVYcq43HH2EScZmN uiNAQLs5t8hVhbf7sz3yt+ML/88mZ+GsBDL2VDQGIOqLXuD4Xg3AQZJrQl/EyPJwgcUF srlzAbG1yH0lGjREhAHB+/9bMDbsQNRRJPb3A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ED2V7mLLmceWSpTZ2HRbRSuu92TU1UX2D0biNt7UyNM=; b=NgNiT9LuDJyrCEheARncrorrz/GIBdQUTrVrG6dC8+rF3T6fUM77aHcJBRA9y0apbN ylFK8I1T8Foc/B5AXPuXtOFkEr5iprQ5zrrjQIOspj5SMGa/E8lahnejmcv619wr0MAB FZFQXEdcf6lbAdzkmLZ1ewUsnYvUmMomH5Pj1mli+dKRtSWjHN+mNkHefzt8J0cpIlGf 7+ZbXcJxQ3STm7xg3C5t6pnRWkDPJgSeDYr7Qw2gCOpWs3m33H/vaba0/zmCOV8+xRPL HAYAQCOX0To9TYQ3Op6U6TzBJjPsLN2+N+kWzywX/uSOhc03nKch7mzHYK8pxN0fuuQj NSbA== X-Gm-Message-State: AOAM531IAtXZU2SMUBf31hDvcB7wBgnX5KXehwzyYLgV5JuXwewEODJt WI0nzQsZwFMPtxMd5+KMgQabYVWD/mEwwg== X-Google-Smtp-Source: ABdhPJwrz8CoK2MT7/JYKqT+Hzt3dW7ZTZM2C+BgZxojRqttIhuFbThPs1ifZ6ocgP1XswdgCeG42A== X-Received: by 2002:a1c:4604:: with SMTP id t4mr7936410wma.191.1644172676025; Sun, 06 Feb 2022 10:37:56 -0800 (PST) Received: from pwmachine.home ([2a01:cb14:983:1f00:e5b3:218b:cb92:2549]) by smtp.gmail.com with ESMTPSA id ay29sm7095011wmb.38.2022.02.06.10.37.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 10:37:55 -0800 (PST) From: Francis Laniel To: u-boot@lists.denx.de Cc: Marek Behun , Michael Nazzareno Trimarchi , Simon Glass , Wolfgang Denk , Harald Seiler , Francis Laniel Subject: [RFC PATCH v2 20/21] cli: hush_2021: Enable loops Date: Sun, 6 Feb 2022 19:37:16 +0100 Message-Id: <20220206183717.57446-21-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220206183717.57446-1-francis.laniel@amarulasolutions.com> References: <20220206183717.57446-1-francis.laniel@amarulasolutions.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Enables the use of for, while and until loops for command line as well as with run_command(). Signed-off-by: Francis Laniel Reviewed-by: Simon Glass --- 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