From mboxrd@z Thu Jan 1 00:00:00 1970 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 3D23FC433EF for ; Thu, 16 Jun 2022 22:36:36 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9A382844E4; Fri, 17 Jun 2022 00:34:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (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="IQ7wxw3v"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 48628844BC; Fri, 17 Jun 2022 00:33:58 +0200 (CEST) Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) (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 7C965843EB for ; Fri, 17 Jun 2022 00:33:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (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-x32a.google.com with SMTP id j5-20020a05600c1c0500b0039c5dbbfa48so3488599wms.5 for ; Thu, 16 Jun 2022 15:33:20 -0700 (PDT) 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=UA6rDZx/4v9YwUCMoxmGYynVqdMDsFApMDE7BOMQQYw=; b=IQ7wxw3vBB2G/Qq3TtKJkdjr+2ti847jCqWzX+wts0qsgRAeTG1Syqidrou0eauo99 vAIozJqN/jxAJx6z9BsohMgJd8mW39S6MywCKu/ZBm+bQbs6SJhUgDFTWBsWdSvmrQsT nMWtltG5cTtbZoV+sEks/EbaVvbDDHNRx50NY= 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=UA6rDZx/4v9YwUCMoxmGYynVqdMDsFApMDE7BOMQQYw=; b=X3f4HFKis3mzlvnuplXrkTN5np56tH9qfN+xfrBHLSosmxcPGiXQj1nfspy3qQtGB/ 5vpTVJDcFLIKlBy1RLfi/c/9fR4g/SmPQKUiV2ghECsDSqzbdCp31xQW52gUTpqlsSOG G4D/wNT3zjcluTHn58/IrKCWWzV30C+lmAeG1NEqrflDP9Jq6dR5Ox9cum/dUqaV/7qJ CnYjzBpF9UmnIEobwAzbp4E6HvwInPbMkF2FaANmUbwAfb4IVx+7OqtCyafOpI+HS97r IRRFN0eysm17Rvy/B7IO/GFSnwqXoC3rlRf1wu5gBrcU5BfrNk+pU3eTt9uihy+3kDcS 2G9w== X-Gm-Message-State: AOAM532BUcVDs54PZHF7ngWcPUMsB3obLiPf/ieynEbOLBn9QUEysa32 zljHvOx9lLT/Cm5WLmwYAjE8Q/NQMBP6oA== X-Google-Smtp-Source: ABdhPJyDLtwnu15iQ61PjBCPer3eBMghct5Mt7KfTam2D1KEjg7FWIcrBohVgQkXQt8tdQt25ea5Mg== X-Received: by 2002:a05:600c:3229:b0:39c:65b2:8935 with SMTP id r41-20020a05600c322900b0039c65b28935mr17790119wmp.155.1655418800297; Thu, 16 Jun 2022 15:33:20 -0700 (PDT) Received: from pwmachine.home (17.pool80-103-97.dynamic.orange.es. [80.103.97.17]) by smtp.gmail.com with ESMTPSA id n4-20020a05600c4f8400b003971fc23185sm7912044wmq.20.2022.06.16.15.33.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 15:33:19 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Marek Behun , Michael Nazzareno Trimarchi , Simon Glass , Wolfgang Denk , Harald Seiler , Tom Rini , Francis Laniel Subject: [RFC PATCH v4 22/28] cli: hush_2021: Enable loops Date: Fri, 17 Jun 2022 00:31:52 +0200 Message-Id: <20220616223158.9225-23-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220616223158.9225-1-francis.laniel@amarulasolutions.com> References: <20220616223158.9225-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 baf4f9aada..7b8712c981 100644 --- a/common/cli_hush_upstream.c +++ b/common/cli_hush_upstream.c @@ -10347,7 +10347,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; @@ -10449,7 +10449,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_2021(full_var, /*flag:*/ 0); +#endif /* __U_BOOT__ */ continue; } if (rword == RES_IN) { -- 2.25.1