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 5C1EAC77B7C for ; Fri, 12 May 2023 20:08:00 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F006F86334; Fri, 12 May 2023 22:07:22 +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="qyZmBv1x"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C293086366; Fri, 12 May 2023 22:07:19 +0200 (CEST) Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (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 EEC9586312 for ; Fri, 12 May 2023 22:07: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-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3090408e09bso506498f8f.2 for ; Fri, 12 May 2023 13:07:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1683922018; x=1686514018; 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=jnowZuUrE17g+tKuxT2zBkYxjYxVi7CpX1ywM+CZUCk=; b=qyZmBv1xV8AWHdFSaAr/67dyeSuj6fuhEGKrs7KKU1IMZ0CZmnurSIdvGMdSITYxm/ wC1C18NtIdVMrOkAsCzFEnXWuTOPmCrcx1aIDFLtrJFy/UQ1Ua/r1Yp08A+7lUhoXPdY vWIB63lEZK+uc6aPwjVUzJRrC7we2kABCUzd0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683922018; x=1686514018; 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=jnowZuUrE17g+tKuxT2zBkYxjYxVi7CpX1ywM+CZUCk=; b=IUCH7iNiD6Y18BgiHVHgmRCZAbeBsb32M6ZeMasqBDifDv7eMFkaJGc2p/iwRMRgue nW2JXSVIZEPG+JJX0I60Gbpy9miV48/5Xc+9tBevQlcEWAAvZuJ9UpvwOMvh8rtvtPxU 6G0eqfZXaE8H784g3KIA8qB2NZMDhGjwGsuhLeVd3DaTnO0ZzjwVWjhF6Q2+9mGECs0d PmLTgBlnA6BdYfTidZ9ggboCkD2/Rl3BPldxfd+hyOdB/gSRUFaAst6JUGf4OrFOq+iI cLTlmzvcl7fHW9osOROMvzbfBeDxp2QLGXkij4XRfmILlFvf/jkODTEnWecqev/Z0KPU cyMQ== X-Gm-Message-State: AC+VfDx05QwbHSD8HcfGZGpuqbFlj3FyuOHLiYvTJQdqRvWc42VfLaCW InMh6VTPOQ437/A4qY/ipUSpfEBDOerHCO7jl+g= X-Google-Smtp-Source: ACHHUZ6bbUUhoyW3Rd1PtDTW8s181suxbXextew+eC11xF7soOcwrGhhhpN/9ngkJ48vBOJ3ts3yZQ== X-Received: by 2002:a05:6000:10a:b0:2fe:6b1e:3818 with SMTP id o10-20020a056000010a00b002fe6b1e3818mr15724016wrx.51.1683922018747; Fri, 12 May 2023 13:06:58 -0700 (PDT) Received: from pwmachine.numericable.fr ([213.94.16.214]) by smtp.gmail.com with ESMTPSA id n6-20020a7bcbc6000000b003f33f8f0a05sm29565859wmi.9.2023.05.12.13.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 13:06:57 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Michael Nazzareno Trimarchi , Tom Rini , Simon Glass , Harald Seiler , Francis Laniel , Marek Vasut , Hector Palacios , Evgeny Bachinin Subject: [RFC PATCH v8 15/23] cli: add hush 2021 as parser for run_command*() Date: Fri, 12 May 2023 21:03:23 +0100 Message-Id: <20230512200331.51457-16-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230512200331.51457-1-francis.laniel@amarulasolutions.com> References: <20230512200331.51457-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 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. Reviewed-by: Simon Glass 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 e3e2bc7fe1..899007da9d 100644 --- a/common/cli.c +++ b/common/cli.c @@ -43,14 +43,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. */ +#else + 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 } @@ -67,12 +84,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; @@ -111,12 +141,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 b11445c3ac..dbf77ad503 100644 --- a/common/cli_hush_upstream.c +++ b/common/cli_hush_upstream.c @@ -8023,7 +8023,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.34.1