From patchwork Fri Dec 4 19:02:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nishanth Menon X-Patchwork-Id: 57722 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp738628lbb; Fri, 4 Dec 2015 11:02:39 -0800 (PST) X-Received: by 10.194.89.34 with SMTP id bl2mr19406969wjb.9.1449255758964; Fri, 04 Dec 2015 11:02:38 -0800 (PST) Return-Path: Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id t7si20357243wjf.187.2015.12.04.11.02.38; Fri, 04 Dec 2015 11:02:38 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 575604B67B; Fri, 4 Dec 2015 20:02:38 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id b7TRJs4GfneZ; Fri, 4 Dec 2015 20:02:38 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BE3A04B668; Fri, 4 Dec 2015 20:02:37 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DE86C4B667 for ; Fri, 4 Dec 2015 20:02:33 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xBriYNQ-gWmA for ; Fri, 4 Dec 2015 20:02:33 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from comal.ext.ti.com (comal.ext.ti.com [198.47.26.152]) by theia.denx.de (Postfix) with ESMTPS id 6D77F4B668 for ; Fri, 4 Dec 2015 20:02:29 +0100 (CET) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id tB4J2Rfl007298; Fri, 4 Dec 2015 13:02:27 -0600 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id tB4J2R9c013296; Fri, 4 Dec 2015 13:02:27 -0600 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.224.2; Fri, 4 Dec 2015 13:02:27 -0600 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id tB4J2QOX030087; Fri, 4 Dec 2015 13:02:26 -0600 From: Nishanth Menon To: Simon Glass , Rabin Vincent Date: Fri, 4 Dec 2015 13:02:24 -0600 Message-ID: <1449255744-25787-1-git-send-email-nm@ti.com> X-Mailer: git-send-email 2.6.2.402.g2635c2b MIME-Version: 1.0 Cc: Tom Rini , u-boot@lists.denx.de Subject: [U-Boot] [PATCH] common: cli_hush: Do a simple recursive variables parsing X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 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" When we use the following in bootargs: v1=abc v2=123-${v1} echo ${v2} we get 123-${v1} when we should have got 123-abc This is because we do not recursively check to see if v2 by itself has a hidden variable. Fix the same with recursive call. NOTE: this is a limited implementation as the next level variable default assignment etc would not function. Signed-off-by: Nishanth Menon --- For next level recursion of variables to work, this patch depends on https://patchwork.ozlabs.org/patch/552823/ Tested on Sandbox. common/cli_hush.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) -- 2.6.2.402.g2635c2b _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot diff --git a/common/cli_hush.c b/common/cli_hush.c index 5a26af80c758..d56d6cfb131e 100644 --- a/common/cli_hush.c +++ b/common/cli_hush.c @@ -471,7 +471,7 @@ static int redirect_opt_num(o_string *o); static int process_command_subs(o_string *dest, struct p_context *ctx, struct in_str *input, int subst_end); static int parse_group(o_string *dest, struct p_context *ctx, struct in_str *input, int ch); #endif -static char *lookup_param(char *src); +static char *lookup_param(char *src, bool *b); static char *make_string(char **inp, int *nonnull); static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *input); #ifndef __U_BOOT__ @@ -2740,7 +2740,7 @@ static int parse_group(o_string *dest, struct p_context *ctx, /* basically useful version until someone wants to get fancier, * see the bash man page under "Parameter Expansion" */ -static char *lookup_param(char *src) +static char *lookup_param(char *src, bool *b) { char *p; char *sep; @@ -2748,9 +2748,10 @@ static char *lookup_param(char *src) int assign = 0; int expand_empty = 0; - if (!src) + if (!src || !b) return NULL; + *b = false; sep = strchr(src, ':'); if (sep) { @@ -2783,6 +2784,16 @@ static char *lookup_param(char *src) } } else if (expand_empty) { p += strlen(p); + } else { + char f[CONFIG_SYS_CBSIZE]; + + if (strlen(p) < CONFIG_SYS_CBSIZE) { + cli_simple_process_macros(p, f); + if (strncmp(p, f, CONFIG_SYS_CBSIZE)) { + p = strdup(f); + *b = true; + } + } } if (sep) @@ -3501,6 +3512,7 @@ static char *insert_var_value_sub(char *inp, int tag_subst) int len; int done = 0; char *p, *p1, *res_str = NULL; + bool b; while ((p = strchr(inp, SPECIAL_VAR_SYMBOL))) { /* check the beginning of the string for normal characters */ @@ -3516,7 +3528,8 @@ static char *insert_var_value_sub(char *inp, int tag_subst) p = strchr(inp, SPECIAL_VAR_SYMBOL); *p = '\0'; /* look up the value to substitute */ - if ((p1 = lookup_param(inp))) { + p1 = lookup_param(inp, &b); + if (p1) { if (tag_subst) len = res_str_len + strlen(p1) + 2; else @@ -3544,6 +3557,9 @@ static char *insert_var_value_sub(char *inp, int tag_subst) strcpy((res_str + res_str_len), p1); res_str_len = len; + + if (b) + free(p1); } *p = SPECIAL_VAR_SYMBOL; inp = ++p;