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 B510CC433FE for ; Tue, 1 Nov 2022 19:29:48 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D85C684F99; Tue, 1 Nov 2022 20:29:46 +0100 (CET) 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="MUpuLTdE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1E02C85100; Tue, 1 Nov 2022 20:21:57 +0100 (CET) Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) (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 AA87584FC0 for ; Tue, 1 Nov 2022 20:21:31 +0100 (CET) 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-x434.google.com with SMTP id a14so21498785wru.5 for ; Tue, 01 Nov 2022 12:21:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; 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=jF3QIlxJuEEpm9LiDHSk//sXMTlN4pCqoTRu4/6ntmM=; b=MUpuLTdExmSRayYoXXvA3tAua5UwuqlbLIEVMKjOEcg1Fcl9GuSGfxw/dZFE1rARuD VVqy4mf/twDxSkCi10krzTZ3LAImG6NcbeP55awXYtFTzdaUO3l42bIp42LCs8M2aOR0 mblsqGyY6Ae0sJDE0eODKO/JRlFan+mhJ2qrQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=jF3QIlxJuEEpm9LiDHSk//sXMTlN4pCqoTRu4/6ntmM=; b=xm0xw+QRGnKaBGwzlAyrM6tcFlVLnIx4bI14Wq3p1jFwKpFybmn39xcQzsE6zKAyIt j1yIrYpRYYHMYciaFWEHZ1wxcQqQwnAv4X+tni1hEcMD1DsjwhxF4hS61d95zJmXtITe Eixf6T4fP3G6zFkWqw2IqkxDTYVNVQPaSdSfP9hKr9k5DSfvUlx7Y5o/PDHRQe3CTJM3 ERipNtRDG+SFRk8fGBkb39rZvhzUYQHGPAfPAif0oX+QxlOuybX227LMyYaEuK1rNNrF Z02ZNg8fPrxL9cjVeCoBZKTIQp6FjPYGCDyAyoDfYoG8/G9m4lMt93hKvdwU0NyPmRN0 voiw== X-Gm-Message-State: ACrzQf0qUEOGfkFLrnoQKDFLmJU2xC74eoYAbrJC3fqjvwWukjaJ82uK H47q7EvgLxxUnaJcMkC1O6wxU0Zlxygc8g== X-Google-Smtp-Source: AMsMyM65kPIoZnfG2cyUB993XIs6YGzyNhCpDDZZnNNpQ2yy5QrdUUahlinr+WBBbmqaJDl1QVs7BQ== X-Received: by 2002:adf:f4c7:0:b0:236:c415:c707 with SMTP id h7-20020adff4c7000000b00236c415c707mr9419662wrp.24.1667330491385; Tue, 01 Nov 2022 12:21:31 -0700 (PDT) Received: from pwmachine.numericable.fr (85-170-25-210.rev.numericable.fr. [85.170.25.210]) by smtp.gmail.com with ESMTPSA id h17-20020a5d6e11000000b002356c051b9csm10755732wrz.66.2022.11.01.12.21.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Nov 2022 12:21:31 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Michael Nazzareno Trimarchi , Tom Rini , Aleksandar Gerasimovski , Holger Brunck , Francis Laniel , Simon Glass , Harald Seiler Subject: [RFC PATCH v5 19/24] cli: hush_2021: Enable if keyword Date: Tue, 1 Nov 2022 20:20:24 +0100 Message-Id: <20221101192029.10231-20-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101192029.10231-1-francis.laniel@amarulasolutions.com> References: <20221101192029.10231-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.6 at phobos.denx.de X-Virus-Status: Clean Adds support for "if then else" construct both for command line interface and through run_command(). Signed-off-by: Francis Laniel Reviewed-by: Simon Glass --- common/cli_hush_2021.c | 11 +++++++++++ common/cli_hush_upstream.c | 12 ++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/common/cli_hush_2021.c b/common/cli_hush_2021.c index e6563a5341..be8851f986 100644 --- a/common/cli_hush_2021.c +++ b/common/cli_hush_2021.c @@ -33,6 +33,7 @@ */ #define ENABLE_HUSH_INTERACTIVE 1 #define ENABLE_FEATURE_EDITING 1 +#define ENABLE_HUSH_IF 1 /* No MMU in U-Boot */ #define BB_MMU 0 #define USE_FOR_NOMMU(...) __VA_ARGS__ @@ -124,6 +125,11 @@ static void bb_error_msg(const char *s, ...) va_end(p); } +static void bb_simple_error_msg(const char *s) +{ + bb_error_msg("%s", s); +} + static void *xmalloc(size_t size) { void *p = NULL; @@ -147,6 +153,11 @@ static void *xrealloc(void *ptr, size_t size) return p; } +static void *xmemdup(const void *s, int n) +{ + return memcpy(xmalloc(n), s, n); +} + #define xstrdup strdup #define xstrndup strndup diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c index 8a08c7e49a..3b8c6a35b0 100644 --- a/common/cli_hush_upstream.c +++ b/common/cli_hush_upstream.c @@ -1488,7 +1488,6 @@ static void msg_and_die_if_script(unsigned lineno, const char *fmt, ...) die_if_script(); } -#ifndef __U_BOOT__ static void syntax_error(unsigned lineno UNUSED_PARAM, const char *msg) { if (msg) @@ -1497,7 +1496,6 @@ static void syntax_error(unsigned lineno UNUSED_PARAM, const char *msg) bb_simple_error_msg("syntax error"); die_if_script(); } -#endif /* !__U_BOOT__ */ static void syntax_error_at(unsigned lineno UNUSED_PARAM, const char *msg) { @@ -3969,7 +3967,6 @@ static void debug_print_tree(struct pipe *pi, int lvl) [PIPE_OR ] = "OR" , [PIPE_BG ] = "BG" , }; -#ifndef __U_BOOT__ static const char *RES[] = { [RES_NONE ] = "NONE" , # if ENABLE_HUSH_IF @@ -3999,7 +3996,6 @@ static void debug_print_tree(struct pipe *pi, int lvl) [RES_XXXX ] = "XXXX" , [RES_SNTX ] = "SNTX" , }; -#endif /* !__U_BOOT__ */ static const char *const CMDTYPE[] = { "{}", "()", @@ -4017,10 +4013,8 @@ static void debug_print_tree(struct pipe *pi, int lvl) lvl*2, "", pin, pi->num_cmds, -#ifdef __U_BOOT__ (IF_HAS_KEYWORDS(pi->pi_inverted ? "! " :) ""), RES[pi->res_word], -#endif /* !__U_BOOT__ */ pi->followup, PIPE[pi->followup] ); prn = 0; @@ -9835,6 +9829,7 @@ static NOINLINE int run_pipe(struct pipe *pi) rcode = 1; /* exitcode if redir failed */ #ifndef __U_BOOT__ if (setup_redirects(command, &squirrel) == 0) { +#endif /* !__U_BOOT__ */ debug_printf_exec(": run_list\n"); //FIXME: we need to pass squirrel down into run_list() //for SH_STANDALONE case, or else this construct: @@ -9843,10 +9838,11 @@ static NOINLINE int run_pipe(struct pipe *pi) //and in SH_STANDALONE mode, "find" is not execed, //therefore CLOEXEC on saved fd does not help. rcode = run_list(command->group) & 0xff; +#ifndef __U_BOOT__ } restore_redirects(squirrel); - IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;) #endif /* !__U_BOOT__ */ + IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;) debug_leave(); debug_printf_exec("run_pipe: return %d\n", rcode); return rcode; @@ -10365,12 +10361,12 @@ static int run_list(struct pipe *pi) break; if (G_flag_return_in_progress == 1) break; +#endif /* !__U_BOOT__ */ IF_HAS_KEYWORDS(rword = pi->res_word;) debug_printf_exec(": rword=%d cond_code=%d last_rword=%d\n", rword, cond_code, last_rword); -#endif /* !__U_BOOT__ */ sv_errexit_depth = G.errexit_depth; if ( #if ENABLE_HUSH_IF -- 2.25.1