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 A8DD9C433FE for ; Tue, 1 Nov 2022 19:23:09 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 32D6084E56; Tue, 1 Nov 2022 20:22:32 +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="FIMAQtD/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E996D84F76; Tue, 1 Nov 2022 20:21:59 +0100 (CET) Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) (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 9FDA48508A for ; Tue, 1 Nov 2022 20:21:26 +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-x429.google.com with SMTP id w14so21465308wru.8 for ; Tue, 01 Nov 2022 12:21:26 -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=GHmewBmS+ZaL/6aI5RkPFDawCt5lrRL8YbCgftScN+I=; b=FIMAQtD/pKN51gbRinV5hlJPK1gTDiShtoSC03SCIxD1uYaVbkKHJe9djKKXxQnz70 kSHX+B27mmipATFA1VyxZW9wQHMknmJEF4vQ0wJSQrPA/Xpsbys4cAlQiBJwsupnfA25 e/6WTK1tzCkydeI3ybzakVTFr3peuYOVW9uBk= 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=GHmewBmS+ZaL/6aI5RkPFDawCt5lrRL8YbCgftScN+I=; b=zHCl/vbJIOa1NnYTO0fwX5YuwuFbyaoJuXGQ5Q8qeiIf+ZIs7J8KX30pkJdUmBZcnK EqGFgd2r8/ivyeJ2oyMbIVWap3zkb9UJbIM40ysf7Ch6odI9mOvKltekP9EZoRcIwYTv Xs8Io5ofI8M6Ax6++ccSzrBZWG0YZzCBEdALOAltX/vFCjcxs2eYEVBG7hnhwDpMGK2U GVFk9eYvAgiQlXFCWL5Zi4qf27I8nJU/6aOAt9HjM+9a2bGtfOrL5tukyWvYpUqUfBLK sGIQzq/IdXhosg54CgXJvhw2glmj+IySOTyOwqH1t1PICagccB3Pwj/638MzV2yJ8EuJ Wg8A== X-Gm-Message-State: ACrzQf0Z6s3cSXHhGqhiBs9mOecUT8refftB81+PyXH9BlveXNKjXfNy uhH0IRpq0Ebr5ef3fugWqXQXHA7J7Eo2vA== X-Google-Smtp-Source: AMsMyM6mN1Y3ewtgBQzAv+n7wTSc0pU0pCASbd2j27aHz8jFH/I2ODmKYXY535egvAosAuK6wCBr1Q== X-Received: by 2002:a5d:598c:0:b0:236:751d:1cc8 with SMTP id n12-20020a5d598c000000b00236751d1cc8mr12952257wri.651.1667330486380; Tue, 01 Nov 2022 12:21:26 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Nov 2022 12:21:26 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Michael Nazzareno Trimarchi , Tom Rini , Aleksandar Gerasimovski , Holger Brunck , Francis Laniel , Heinrich Schuchardt , Simon Glass , Harald Seiler Subject: [RFC PATCH v5 15/24] cli: add hush 2021 as parser for run_command*() Date: Tue, 1 Nov 2022 20:20:20 +0100 Message-Id: <20221101192029.10231-16-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 Enables using, in code, hush 2021 as parser for run_command function family. It also enables the command run to be used by CLI user of hush 2021. Signed-off-by: Francis Laniel --- common/cli.c | 63 ++++++++++++++++++++++++++++---------- common/cli_hush_upstream.c | 2 +- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/common/cli.c b/common/cli.c index c2287443d4..740a6919ff 100644 --- a/common/cli.c +++ b/common/cli.c @@ -40,14 +40,31 @@ int run_command(const char *cmd, int flag) return 1; return 0; -#elif CONFIG_IS_ENABLED(HUSH_OLD_PARSER) - int hush_flags = FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP; - - if (flag & CMD_FLAG_ENV) - hush_flags |= FLAG_CONT_ON_NEWLINE; - return parse_string_outer(cmd, hush_flags); -#else /* HUSH_2021_PARSER */ - /* Not yet implemented. */ +#elif CONFIG_IS_ENABLED(HUSH_PARSER) + if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + int hush_flags = FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP; + + if (flag & CMD_FLAG_ENV) + hush_flags |= FLAG_CONT_ON_NEWLINE; + return parse_string_outer(cmd, hush_flags); + } else if (gd->flags & GD_FLG_HUSH_2021_PARSER) { + /* + * Possible values for flags are the following: + * FLAG_EXIT_FROM_LOOP: This flags ensures we exit from loop in + * parse_and_run_stream() after first iteration while normal + * behavior, * i.e. when called from cli_loop(), is to loop + * infinitely. + * FLAG_PARSE_SEMICOLON: Hush 2021 parses ';' and does not stop + * first time it sees one. So, I think we do not need this flag. + * FLAG_REPARSING: For the moment, I do not understand the goal + * of this flag. + * FLAG_CONT_ON_NEWLINE: This flag seems to be used to continue + * parsing even when reading '\n' when coming from + * run_command(). In this case, Hush 2021 reads until it finds + * '\0'. So, I think we do not need this flag. + */ + return parse_string_outer_2021(cmd, FLAG_EXIT_FROM_LOOP); + } return 1; #endif } @@ -64,12 +81,25 @@ int run_command_repeatable(const char *cmd, int flag) #ifndef CONFIG_HUSH_PARSER return cli_simple_run_command(cmd, flag); #else + int ret; + + if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + ret = parse_string_outer(cmd, + FLAG_PARSE_SEMICOLON + | FLAG_EXIT_FROM_LOOP); + } else if (gd->flags & GD_FLG_HUSH_2021_PARSER) { + ret = parse_string_outer_2021(cmd, + FLAG_PARSE_SEMICOLON + | FLAG_EXIT_FROM_LOOP); + } else { + ret = 1; + } + /* * parse_string_outer() returns 1 for failure, so clean up * its result. */ - if (parse_string_outer(cmd, - FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP)) + if (ret) return -1; return 0; @@ -108,12 +138,13 @@ int run_command_list(const char *cmd, int len, int flag) buff[len] = '\0'; } #ifdef CONFIG_HUSH_PARSER -#if CONFIG_IS_ENABLED(HUSH_OLD_PARSER) - rcode = parse_string_outer(buff, FLAG_PARSE_SEMICOLON); -#else /* HUSH_2021_PARSER */ - /* Not yet implemented. */ - rcode = 1; -#endif + if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + rcode = parse_string_outer(buff, FLAG_PARSE_SEMICOLON); + } else if (gd->flags & GD_FLG_HUSH_2021_PARSER) { + rcode = parse_string_outer_2021(buff, FLAG_PARSE_SEMICOLON); + } else { + rcode = 1; + } #else /* * This function will overwrite any \n it sees with a \0, which diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c index 6c023b679a..baa36b16ee 100644 --- a/common/cli_hush_upstream.c +++ b/common/cli_hush_upstream.c @@ -8020,7 +8020,7 @@ static int parse_and_run_string(const char *s) } #ifdef __U_BOOT__ -int parse_string_outer(const char *cmd, int flags) +int parse_string_outer_2021(const char *cmd, int flags) { int ret; int old_flags; -- 2.25.1