From patchwork Fri May 12 20:03:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francis Laniel X-Patchwork-Id: 1780770 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.a=rsa-sha256 header.s=google header.b=T04Y5qDg; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QJ0FF2KLdz1yfq for ; Sat, 13 May 2023 06:08:17 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5DD7D86317; Fri, 12 May 2023 22:07:24 +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="T04Y5qDg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5342C86366; Fri, 12 May 2023 22:07:20 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (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 D06F486354 for ; Fri, 12 May 2023 22:07:14 +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-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3090408e09bso506679f8f.2 for ; Fri, 12 May 2023 13:07:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1683922034; x=1686514034; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=11Ziq5j8tH6//n8W109RGgZi+yynEIbpG8hLQmj18Xg=; b=T04Y5qDgRJul45KaP7LdZXIp75wbP1yu7XatGEA5abo1kde6Yo1QQk35v2CbZ4AEym Ouv4LmRupQ943+eW2tIDTOH9QEVBd67kCa0bWbWCGTytHmXT5TuJbOFSStdDb/4XZ58O xVkJYdOTKo/CsqwUSv4ohUCrBHOu2erb9lDDM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683922034; x=1686514034; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=11Ziq5j8tH6//n8W109RGgZi+yynEIbpG8hLQmj18Xg=; b=ARq6o8Y189aVloKi1oQJmhjsKHEOJRZlgZyUqnOujlXvq6DK8mrUAJIJONC06euNFK cAlFYtk6BCUk2fSoSgll7MBe3qPTUWR8CR8LvFGMjDY7y/TottLngLbOwBIvZqTIt47h xDQT1zHVqRLd6zpHhMIlpSErL03lSdBv+Nk+fi4gh/Zy81E9Ap5OX+/r57/IZCVhNy1Y wpHIGE2aLhYZH56Du8v/Gju1OBaQ2uJXLHUikzspwO8xBbRV691dcysdbnuXFJCBe31r yPg+xhudyAKQfVQ7nb9p9JjVMn6NzgzZdUR4aYQ/3uAAkHnshvgujngLWN6o0WgwgyAD 4SOA== X-Gm-Message-State: AC+VfDwU0l5lgRrssBqiylnIY79wSTUSgV6FGBRamrOA7zpVEB4c+60r ybm65SWPcBeajzrsX1r3Fd5a+as7N1401xPNqTw= X-Google-Smtp-Source: ACHHUZ5crHw+G6iK1mL2TEwnwsgwg1e0llhGzm+w5/gsUXpz1/9ZA+QHIoa2oHLc/wyLHowWWDtPTQ== X-Received: by 2002:adf:fd4c:0:b0:306:2c47:9736 with SMTP id h12-20020adffd4c000000b003062c479736mr17740143wrs.15.1683922034578; Fri, 12 May 2023 13:07:14 -0700 (PDT) Received: from pwmachine.numericable.fr ([213.94.16.214]) by smtp.gmail.com with ESMTPSA id n6-20020a7bcbc6000000b003f33f8f0a05sm29565859wmi.9.2023.05.12.13.07.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 13:07:13 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Michael Nazzareno Trimarchi , Tom Rini , Simon Glass , Harald Seiler , Francis Laniel Subject: [RFC PATCH v8 20/23] cli: hush_2021: Enable loops Date: Fri, 12 May 2023 21:03:28 +0100 Message-Id: <20230512200331.51457-21-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230512200331.51457-1-francis.laniel@amarulasolutions.com> References: <20230512200331.51457-1-francis.laniel@amarulasolutions.com> MIME-Version: 1.0 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.8 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_2021.c | 1 + common/cli_hush_upstream.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/common/cli_hush_2021.c b/common/cli_hush_2021.c index aba5dcbbcd..0a207d147b 100644 --- a/common/cli_hush_2021.c +++ b/common/cli_hush_2021.c @@ -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__ diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c index 9b65dcbde1..23392939e1 100644 --- a/common/cli_hush_upstream.c +++ b/common/cli_hush_upstream.c @@ -10349,7 +10349,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; @@ -10451,7 +10451,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) {