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 35F40C433F5 for ; Fri, 31 Dec 2021 16:17:49 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9090F83063; Fri, 31 Dec 2021 17:15:52 +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="C8jJznyX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C3A42836CB; Fri, 31 Dec 2021 17:15:26 +0100 (CET) Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) (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 8278783040 for ; Fri, 31 Dec 2021 17:14:17 +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-wr1-x42d.google.com with SMTP id d9so56779836wrb.0 for ; Fri, 31 Dec 2021 08:14:17 -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=8DF+9KYczvSN58ihSSqDUe2E/NAizWkIRokrC+vCtG8=; b=C8jJznyX4qWku1+VvxPnyFg5P9yNWbVW5Ql/e4JQX2EIWCGKn/Qk4nFIvqMew40B65 ye7tE8h8jGxel3LscX9QOUn7duJ47E+aYXlev5usR9CtK9lt6665e65qb2ZxCQjFUNt/ eNQMjX6zixoHCChBY7bYsaaGzZRZPy646ruJg= 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=8DF+9KYczvSN58ihSSqDUe2E/NAizWkIRokrC+vCtG8=; b=CnkmR/3yiRX1n9u7ETyEFdbadmCdK5NECbWKbnqNy+C/ESaM+M+/KUk2FmGyiY/j7Y EljIHSXYAZkEShbOLmfD1pGQCSTr74x6qqxPE+h8lPbvHk6e9nGZ1e6w2oZbTuMQcP2k o5lMmZgyr63xbqukOuhmrQFUsAge4LABqHh07YiQ8/vNTa5DM8G7VLE57OdhufVkQ1wr TpDLaLFPHMvV2bem0C8CqzjT/Ui0v+5Ui/a7PIBWyYG41AD8Kie5fI3gQfZ56cmCmuaa xR40jsok2F7nBsRO2t4EhwO4O9s5EDG1byYFkzwJkNv03ubQljz2NtopqRmsvzuZelY+ LorA== X-Gm-Message-State: AOAM532hK1t8sJzDn18eJaP9m22c1KinrvTA8WVOG45q8NUdu4wFDg+D 72MmqcUkX+t1qjMe7xdlq1jr+gxoRFybyQ== X-Google-Smtp-Source: ABdhPJwlfCcRZen24OPsqn1JRJTq+40p4bFA7hXU+UOkK5Sw6yWsIS9AYDSZJYHZoe4M9SUpIaAvKQ== X-Received: by 2002:a5d:64c3:: with SMTP id f3mr29150537wri.155.1640967257190; Fri, 31 Dec 2021 08:14:17 -0800 (PST) Received: from pwmachine.home ([2a01:cb14:983:1f00:eef7:8bf8:8ee0:cb1a]) by smtp.gmail.com with ESMTPSA id f6sm31855522wmq.6.2021.12.31.08.14.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Dec 2021 08:14:16 -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 v1 20/21] cli: hush_2021: Enable loops. Date: Fri, 31 Dec 2021 17:13:26 +0100 Message-Id: <20211231161327.24918-21-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211231161327.24918-1-francis.laniel@amarulasolutions.com> References: <20211231161327.24918-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.38 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.2 at phobos.denx.de X-Virus-Status: Clean This commit enables the use of for, while and until loops for command line as well as with run_command(). Signed-off-by: Francis Laniel --- common/cli_hush_2021_upstream.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/common/cli_hush_2021_upstream.c b/common/cli_hush_2021_upstream.c index 5c783494d1..498fd8d10b 100644 --- a/common/cli_hush_2021_upstream.c +++ b/common/cli_hush_2021_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