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 479BDC433EF for ; Thu, 16 Jun 2022 22:35:44 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 339458449D; Fri, 17 Jun 2022 00:33:51 +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="ercAIXrU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EBCFB8447E; Fri, 17 Jun 2022 00:33:39 +0200 (CEST) Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) (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 B9AD58440F for ; Fri, 17 Jun 2022 00:33:11 +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-x32f.google.com with SMTP id i81-20020a1c3b54000000b0039c76434147so3504404wma.1 for ; Thu, 16 Jun 2022 15:33:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VzblyUqUyaKvTx/SuDtcTGN0LS+pTW9Dd5BwnSL+quM=; b=ercAIXrUKwvNSZBhVSlnFIlperEurxmtfoDB4h5K7I1AyJqbtudrv+pbWBGLd4/u/A udasv33/mWEd8HSwfIiY8RrnoDd5aN86YshVjtVjplW7MaBbhbrbV6WXEQeBNKg3+qgk +yaCvb9JaWoPGZS0L0g6UHz6p0Y1VGkiQ9YWM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VzblyUqUyaKvTx/SuDtcTGN0LS+pTW9Dd5BwnSL+quM=; b=fDbCNHnU1jh4WcP/Zaq71nh1DmJ5azPXhMW6JFaTYy9roUJmPFzwUaRKoOglk/W03T 4m2ZBOQSoeTLl/4QqmEOLPcy+Ir7cEPKssL2K9yV6IF0OYYxsqUb3VL9lXET3GbSI4uz kn9S3ImQI0NxDRUp0RWw0swDEdpBrxL4cHhAQ4a1UjqIfyeAldfziuj1YUfBcJraJC0/ CS4v2SU4yJ9cLLRJl2P7ItRxRTJQ/5Zbl6iiGTg7kUks+hO3uD9cKdarbkkyaScwlTtV b0QR2W6I7naR8O69Zih0N+iem7DQz0RugKHHaOd7Et68W0dbqXfNb+no9LrtmbSLz8dX AjJA== X-Gm-Message-State: AOAM531xBDe+YdjgS8+ShcpClB0rxYoxM9mqkS5fFN0baUWFvSHh8OF8 dmDV/q4kil7IoialUFZu1LzFgYooUyZsxQ== X-Google-Smtp-Source: ABdhPJyYWqOFyQarDGDDAKcozXCXvHGkF19bMN7Df3N4ETUijFT6ILmoIBAptbZvWgkWXqaLgJwxkA== X-Received: by 2002:a7b:c10d:0:b0:39c:4a17:1e90 with SMTP id w13-20020a7bc10d000000b0039c4a171e90mr17534893wmi.108.1655418791455; Thu, 16 Jun 2022 15:33:11 -0700 (PDT) Received: from pwmachine.home (17.pool80-103-97.dynamic.orange.es. [80.103.97.17]) by smtp.gmail.com with ESMTPSA id n4-20020a05600c4f8400b003971fc23185sm7912044wmq.20.2022.06.16.15.33.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 15:33:10 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Marek Behun , Michael Nazzareno Trimarchi , Simon Glass , Wolfgang Denk , Harald Seiler , Tom Rini , Francis Laniel Subject: [RFC PATCH v4 16/28] cli: add hush 2021 as parser for run_command*(). Date: Fri, 17 Jun 2022 00:31:46 +0200 Message-Id: <20220616223158.9225-17-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220616223158.9225-1-francis.laniel@amarulasolutions.com> References: <20220616223158.9225-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.5 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 | 60 ++++++++++++++++++++++++++++---------- common/cli_hush_upstream.c | 2 +- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/common/cli.c b/common/cli.c index bff4a68640..18912e4680 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; +#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 /* HUSH_2021_PARSER */ - /* Not yet implemented. */ + 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,24 @@ 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 +137,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 d03aff8fae..a768fd6197 100644 --- a/common/cli_hush_upstream.c +++ b/common/cli_hush_upstream.c @@ -8014,7 +8014,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