X-Git-Url: https://jxself.org/git/?p=carl9170fw.git;a=blobdiff_plain;f=config%2Fpreprocess.c;h=56aa1f0bad0422eab2d1f1f2eb1f8d79f99b769c;hp=46487fe6b36cd99e9ea04cc0bc2cbe7708b98121;hb=c9645e9489aac917a4883ddecc857b1c6fcc2c38;hpb=b68427cdb960942fede090e843b046749a0789f3 diff --git a/config/preprocess.c b/config/preprocess.c index 46487fe..56aa1f0 100644 --- a/config/preprocess.c +++ b/config/preprocess.c @@ -185,6 +185,7 @@ static LIST_HEAD(variable_list); struct variable { char *name; char *value; + enum variable_flavor flavor; struct list_head node; }; @@ -203,28 +204,62 @@ static struct variable *variable_lookup(const char *name) static char *variable_expand(const char *name, int argc, char *argv[]) { struct variable *v; + char *res; v = variable_lookup(name); if (!v) return NULL; - return expand_string_with_args(v->value, argc, argv); + if (v->flavor == VAR_RECURSIVE) + res = expand_string_with_args(v->value, argc, argv); + else + res = xstrdup(v->value); + + return res; } -void variable_add(const char *name, const char *value) +void variable_add(const char *name, const char *value, + enum variable_flavor flavor) { struct variable *v; + char *new_value; + bool append = false; v = variable_lookup(name); if (v) { - free(v->value); + /* For defined variables, += inherits the existing flavor */ + if (flavor == VAR_APPEND) { + flavor = v->flavor; + append = true; + } else { + free(v->value); + } } else { + /* For undefined variables, += assumes the recursive flavor */ + if (flavor == VAR_APPEND) + flavor = VAR_RECURSIVE; + v = xmalloc(sizeof(*v)); v->name = xstrdup(name); list_add_tail(&v->node, &variable_list); } - v->value = xstrdup(value); + v->flavor = flavor; + + if (flavor == VAR_SIMPLE) + new_value = expand_string(value); + else + new_value = xstrdup(value); + + if (append) { + v->value = xrealloc(v->value, + strlen(v->value) + strlen(new_value) + 2); + strcat(v->value, " "); + strcat(v->value, new_value); + free(new_value); + } else { + v->value = new_value; + } } static void variable_del(struct variable *v)