From patchwork Thu Jun 8 18:34:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francis Laniel X-Patchwork-Id: 1792481 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=85.214.62.61; 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=SftHJ3Jb; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4QcY2536tgz20Wn for ; Fri, 9 Jun 2023 04:41:01 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D446586100; Thu, 8 Jun 2023 20:36:34 +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="SftHJ3Jb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6C69A861A4; Thu, 8 Jun 2023 20:36:19 +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=unavailable autolearn_force=no version=3.4.2 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 0682385828 for ; Thu, 8 Jun 2023 20:35:57 +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 5b1f17b1804b1-3f61530506aso9260315e9.1 for ; Thu, 08 Jun 2023 11:35:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1686249351; x=1688841351; 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=M6m96BWRNrUs7wLN2G3qt/SSwCbl/84LCFDpBmC79iE=; b=SftHJ3JbB9iKvKDf2BT1nVFC4xw42R/IrUnkV2suWwDZlw7pm/ShYjkloKoHO6QiOB TWaWLsm7ZEqYT5A5lcbgpLu2NNGZHdtm/4lFPeoaMPN0mTvzWScmxrWBIJ50+6eutZ4S BkcNTwq0AfdrcSDN8cQU8vbEZYwdV6XINKu8s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686249351; x=1688841351; 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=M6m96BWRNrUs7wLN2G3qt/SSwCbl/84LCFDpBmC79iE=; b=IZXqnU/EzYCJmMemI88UPQbR5ZH+ViZ6o7P2FP4TO09oC/Ph8D+eHB+1JDKAgLDR/C V0SrdotwVHu4IX5gNtvKtwm4I2k6LBuqhggwHlzK6+5gN1sbcEldOpm2cCY2It2mEADy 88GFGRcRWZLuB6uKDxKBzCvbwZHfLdeqMrHl/1z+JcbuNUFjRCf5g/dJOpodz53yn60i 2vRXrAIaWN3C8qUS3DAdMSMHUAAYESi9+YiX+uQkYzbaCGHrV9UkIqP8UvogzawWpHHc jDeOxsZ85VpcvllY9ws3Gab4nwY5WWRfUK8jZkqLm5cHAtHJsgYoB2D9/S7wnl+7tIT3 m/3g== X-Gm-Message-State: AC+VfDzi43Jk0gRo7IW/JFTsBC0deI/5deSsbGiQTUiDn1f6lysjKvCv wH7laaQvZRHoUyFzFmhlh48U85ON3j7JOCc7pavoNA== X-Google-Smtp-Source: ACHHUZ7qEdXQW8fW6oFVwEIByQmSkwTZYw3A/Frtkx3Ma5qbzVXJE5lRy05wF6LLadvycUcxNhanng== X-Received: by 2002:a7b:cc01:0:b0:3f7:e800:abd2 with SMTP id f1-20020a7bcc01000000b003f7e800abd2mr2354307wmh.35.1686249350960; Thu, 08 Jun 2023 11:35:50 -0700 (PDT) Received: from pwmachine.home (120.124.191.92.dynamic.jazztel.es. [92.191.124.120]) by smtp.gmail.com with ESMTPSA id t10-20020a1c770a000000b003f8009be6c0sm408783wmi.3.2023.06.08.11.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 11:35:50 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Michael Nazzareno Trimarchi , Tom Rini , Simon Glass , Harald Seiler , Francis Laniel , Tony Dinh Subject: [RFC PATCH v9 19/23] cli: hush_2021: Enable if keyword Date: Thu, 8 Jun 2023 19:34:34 +0100 Message-Id: <20230608183438.16748-20-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230608183438.16748-1-francis.laniel@amarulasolutions.com> References: <20230608183438.16748-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 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 7dd30ea0ef..aba5dcbbcd 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 68a9a4bb72..9b65dcbde1 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) { @@ -3962,7 +3960,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 @@ -3992,7 +3989,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[] = { "{}", "()", @@ -4010,10 +4006,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; @@ -9833,6 +9827,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: @@ -9841,10 +9836,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; @@ -10363,12 +10359,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