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 F2949C77B62 for ; Thu, 30 Mar 2023 20:11:42 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 176B585DD9; Thu, 30 Mar 2023 22:11:41 +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="Si0CAXrD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B5319861A6; Thu, 30 Mar 2023 21:53:25 +0200 (CEST) Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (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 E32D68610B for ; Thu, 30 Mar 2023 21:49:44 +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-x32d.google.com with SMTP id bg16-20020a05600c3c9000b003eb34e21bdfso14078256wmb.0 for ; Thu, 30 Mar 2023 12:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1680205784; 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=mLzNBNtL6H0lN3gsUDRN1dyppfRSFPKcMIL5ZyW4Ex0=; b=Si0CAXrDrfWWpblSQxS0Ic4bp7/jxGwaiBWo8WUljAht61t6j2ncF7HK9iDL42scyF zVRA+oYbrlnCov/iST2aR0U5m1ZJp3z1aG6gFKEHAm/f443dCSnh5rLRRRe3AaWFUv02 dkYj52+ak04M/7YVJwt9d67eXOm6JX6Z1vYzo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680205784; 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=mLzNBNtL6H0lN3gsUDRN1dyppfRSFPKcMIL5ZyW4Ex0=; b=XFjs3vzcM0/PV0btT9XByWiXRC0H5Ta7hqPR5TSCo0XtMtsj3MdiK1qlM0tGs8w4nY ZkUhbzsAbBaeseplfx2EDjH0584WFbuTOyoZfHfGe17VogQwNANii2EnhgjmL/XK3YA6 Co0gVBfXkNAZUkDQC6lOQo4oA1gsm2QhZ5WolPu9PK4ysqZBGDU3FPLwSgQEfan700vk w8gCEaZla6856uVIG7Z5LCJEel3qKdeV11Qk3s/ELRbge+wh2Nep7VUGXES7h/FKwxbe 9LnHbQmQMpUJWYEfTZ5fpxl58FARY3y5fT+ZYpoFkcA0NQ02xYOrbE18vArOI2alNG0+ JCqg== X-Gm-Message-State: AO0yUKXl/xufC2lZ//CfQiehfyVOkcjHcTuTeMnZjdIrE2vuavPMO2Yi d839Rx43dDF9dFEXyGnrdvk3q7IKKRnD4o616YWxwg== X-Google-Smtp-Source: AK7set/XvlqYDitcIHGHLF0CBFUNrJlbjAeD2tgT1stlx5PbiOA4rniIAdy85u7MSb3zadVzEst5/g== X-Received: by 2002:a1c:f217:0:b0:3ee:5c4c:bdb0 with SMTP id s23-20020a1cf217000000b003ee5c4cbdb0mr18573792wmc.39.1680205784367; Thu, 30 Mar 2023 12:49:44 -0700 (PDT) Received: from pwmachine.numericable.fr ([78.30.11.60]) by smtp.gmail.com with ESMTPSA id l24-20020a1c7918000000b003e203681b26sm203762wme.29.2023.03.30.12.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 12:49:44 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Michael Nazzareno Trimarchi , Tom Rini , Simon Glass , Harald Seiler , Francis Laniel , "Albert ARIBAUD (3ADEV)" , Tony Dinh , Sergei Antonov , Ilias Apalodimas , Heinrich Schuchardt , Masahisa Kojima , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Stefan Roese , John Keeping , Neil Armstrong , Roger Knecht , Linus Walleij , Alexey Romanov , Marek Vasut , Hector Palacios , Rasmus Villemoes , AKASHI Takahiro , Rui Miguel Silva , Andrew Scull Subject: [RFC PATCH v7 15/23] cli: add hush 2021 as parser for run_command*() Date: Thu, 30 Mar 2023 20:47:03 +0100 Message-Id: <20230330194716.23623-16-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230330194716.23623-1-francis.laniel@amarulasolutions.com> References: <20230330194716.23623-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. 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 e75a3ccc50..4575d4c898 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. */ +#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 } @@ -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 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