Re: [U-Boot] [PATCH 1/3] hush: Add default value substitution support

2012-09-02 Thread Wolfgang Denk
Dear Joe,

In message <201208171931.35608.vap...@gentoo.org> Mike Frysinger wrote:
>
> > ${VAR:-default}
...
> > ${VAR:=default}
...
> > ${VAR:+default}
...
> how about ${VAR-default} and ${VAR=default} and ${VAR+default} ?

Maybe we (= you?) can add these, too?

> > +   if (assign) {
> > +   char *var = malloc(strlen(src)+strlen(default_val)+2);
> 
> please put spaces around the "+"

Ah, I missed that.

> > +   if (var) {
> > +   sprintf(var, "%s=%s", src, default_val);
> > +   set_local_var(var, 0);
> > +   }
> 
> isn't there a helper func for this ?

Eventually we can lean this up in another patch, please?

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
The ideal situation is to have massive computing power right at home.
Something that dims the streetlights and shrinks the picture  on  the
neighbours' TVs when you boot it up.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 1/3] hush: Add default value substitution support

2012-09-02 Thread Wolfgang Denk
Dear Joe Hershberger,

In message <1345235191-13757-1-git-send-email-joe.hershber...@ni.com> you wrote:
> Use standard sh syntax:
> ${VAR:-default}
>   Use default value: if VAR is set and non-null, expands to $VAR.
>   Otherwise, expands to default.
> ${VAR:=default}
>   Set default value: if VAR is set and non-null, expands to $VAR.
>   Otherwise, sets hush VAR to default and expands to default.
> ${VAR:+default}
>   If VAR is set and non-null, expands to the empty string.
>   Otherwise, expands to default.
> 
> Signed-off-by: Joe Hershberger 
> ---
>  common/hush.c | 43 ---
>  1 file changed, 40 insertions(+), 3 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
It is the quality rather than the quantity that matters.
- Lucius Annaeus Seneca (4 B.C. - A.D. 65)
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 1/3] hush: Add default value substitution support

2012-08-17 Thread Mike Frysinger
On Friday 17 August 2012 16:26:29 Joe Hershberger wrote:
> Use standard sh syntax:
> ${VAR:-default}
>   Use default value: if VAR is set and non-null, expands to $VAR.
>   Otherwise, expands to default.
> ${VAR:=default}
>   Set default value: if VAR is set and non-null, expands to $VAR.
>   Otherwise, sets hush VAR to default and expands to default.
> ${VAR:+default}
>   If VAR is set and non-null, expands to the empty string.
>   Otherwise, expands to default.

how about ${VAR-default} and ${VAR=default} and ${VAR+default} ?

> --- a/common/hush.c
> +++ b/common/hush.c
>
> + if (sep) {
> + *sep = '\0';
> + if (*(sep + 1) == '-')

switch (sep[1]) {
case '-':
...

> + default_val = sep+2;

sep + 2

> + if (!p || strlen(p) == 0) {

if (!p || !p[0])

> + if (assign) {
> + char *var = malloc(strlen(src)+strlen(default_val)+2);

please put spaces around the "+"

> + if (var) {
> + sprintf(var, "%s=%s", src, default_val);
> + set_local_var(var, 0);
> + }

isn't there a helper func for this ?
-mike


signature.asc
Description: This is a digitally signed message part.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 1/3] hush: Add default value substitution support

2012-08-17 Thread Joe Hershberger
Use standard sh syntax:
${VAR:-default}
Use default value: if VAR is set and non-null, expands to $VAR.
Otherwise, expands to default.
${VAR:=default}
Set default value: if VAR is set and non-null, expands to $VAR.
Otherwise, sets hush VAR to default and expands to default.
${VAR:+default}
If VAR is set and non-null, expands to the empty string.
Otherwise, expands to default.

Signed-off-by: Joe Hershberger 
---
 common/hush.c | 43 ---
 1 file changed, 40 insertions(+), 3 deletions(-)

diff --git a/common/hush.c b/common/hush.c
index 1eff182..39cf203 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -2743,13 +2743,50 @@ static int parse_group(o_string *dest, struct p_context 
*ctx,
 static char *lookup_param(char *src)
 {
char *p;
+   char *sep;
+   char *default_val = NULL;
+   int assign = 0;
+   int expand_empty = 0;
 
if (!src)
return NULL;
 
-   p = getenv(src);
-   if (!p)
-   p = get_local_var(src);
+   sep = strchr(src, ':');
+
+   if (sep) {
+   *sep = '\0';
+   if (*(sep + 1) == '-')
+   default_val = sep+2;
+   if (*(sep + 1) == '=') {
+   default_val = sep+2;
+   assign = 1;
+   }
+   if (*(sep + 1) == '+') {
+   default_val = sep+2;
+   expand_empty = 1;
+   }
+   }
+
+   p = getenv(src);
+   if (!p)
+   p = get_local_var(src);
+
+   if (!p || strlen(p) == 0) {
+   p = default_val;
+   if (assign) {
+   char *var = malloc(strlen(src)+strlen(default_val)+2);
+   if (var) {
+   sprintf(var, "%s=%s", src, default_val);
+   set_local_var(var, 0);
+   }
+   free(var);
+   }
+   } else if (expand_empty) {
+   p += strlen(p);
+   }
+
+   if (sep)
+   *sep = ':';
 
return p;
 }
-- 
1.7.11.5

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot