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 A3676C7619A for ; Thu, 30 Mar 2023 20:00:12 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EDAE3861C9; Thu, 30 Mar 2023 21:56:21 +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="c6juCXTn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 19A048609B; Thu, 30 Mar 2023 21:54:57 +0200 (CEST) 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 932F38615C for ; Thu, 30 Mar 2023 21:50:25 +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-x32d.google.com with SMTP id j18-20020a05600c1c1200b003ee5157346cso14057382wms.1 for ; Thu, 30 Mar 2023 12:50:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1680205823; 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=c6juCXTnCIsUfYWCu/ItpC4dI3jHoQTxv+/1wnew8cR6D4H/5n1SNWuGmjFPMIgquI DzU1ULWo6++EItsa42l5RXFqC03s2CdPgpcccxj/6UnQyJLYtkwMIPYW9V2/qDfgufAI V/yU33K1mNmtr/P/pSvxGtbHtC9W0bGBPSwN4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680205823; 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=RfaLE4mgK4TltpHc7q6KRayI5kNR7/QmSpZDpnOPMnN0z9Sa3kEOxjPLxjlgwb0H3V Q5bqfDQOL32ESadPUuFfbSScfeb8uHhXKGdzm+94qIQKWXTgngmnTbZW/U9JwN2BHHKa y0L787oE+AEiEBJOnUc3FeSuPEl3tpy7XQ/45fuXv7KMkCRYLGBpzN4kvBU/8GXB+TNn BcBIv0oC619EES8Oq35ocr+h8ncnliXwyN5tvgmt8CQUPsbGafyaZSUma7r5PXJmcFKK xpYHVd+/I1997W5bnLyYiNienwHGuZTWzUjE5fRHlkNfQuvwh9r4P2EIzW7sKZ3rAKs4 Jq5Q== X-Gm-Message-State: AO0yUKWu0NgZPcrpsb52AEtYqT4z1hIOuvC/9GbaqY/7lfEvRn3XDbkZ h3zgkQNUIy8wO6PRVjbtJrUeAvy+boS1aGg3kcfRTw== X-Google-Smtp-Source: AK7set9IRhR7ibAI9gIVfLHMU52nxlcg1RT1hyuvBE7XYj+7ol6g/RjBU1mtOehbeCLl5K5xA15CnA== X-Received: by 2002:a7b:c04a:0:b0:3ee:7f0b:388f with SMTP id u10-20020a7bc04a000000b003ee7f0b388fmr19647005wmc.40.1680205823408; Thu, 30 Mar 2023 12:50:23 -0700 (PDT) Received: from pwmachine.numericable.fr ([78.30.11.60]) by smtp.gmail.com with ESMTPSA id l24-20020a1c7918000000b003e203681b26sm203762wme.29.2023.03.30.12.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 12:50:23 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Michael Nazzareno Trimarchi , Tom Rini , Simon Glass , Harald Seiler , Francis Laniel , "Albert ARIBAUD (3ADEV)" , Tony Dinh , Sergei Antonov , Ilias Apalodimas , Heinrich Schuchardt , Masahisa Kojima , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Stefan Roese , John Keeping , Roger Knecht , Neil Armstrong , Alexey Romanov , Marek Vasut , Patrice Chotard , Fabrice Gasnier , Hector Palacios , Rasmus Villemoes , AKASHI Takahiro , Linus Walleij , Rui Miguel Silva , Andrew Scull Subject: [RFC PATCH v7 20/23] cli: hush_2021: Enable loops Date: Thu, 30 Mar 2023 20:47:08 +0100 Message-Id: <20230330194716.23623-21-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230330194716.23623-1-francis.laniel@amarulasolutions.com> References: <20230330194716.23623-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.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) { -- 2.34.1