mirror of
https://github.com/Stichting-MINIX-Research-Foundation/u-boot.git
synced 2025-09-13 14:06:07 -04:00
hush: Add default value substitution support
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 <joe.hershberger@ni.com>
This commit is contained in:
parent
923c46f97a
commit
641b0d374e
@ -2743,14 +2743,51 @@ static int parse_group(o_string *dest, struct p_context *ctx,
|
|||||||
static char *lookup_param(char *src)
|
static char *lookup_param(char *src)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
char *sep;
|
||||||
|
char *default_val = NULL;
|
||||||
|
int assign = 0;
|
||||||
|
int expand_empty = 0;
|
||||||
|
|
||||||
if (!src)
|
if (!src)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
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);
|
p = getenv(src);
|
||||||
if (!p)
|
if (!p)
|
||||||
p = get_local_var(src);
|
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;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user