diff options
author | Peter Korsgaard <jacmet@sunsite.dk> | 2011-02-02 11:48:58 +0100 |
---|---|---|
committer | Peter Korsgaard <jacmet@sunsite.dk> | 2011-02-02 15:54:50 +0100 |
commit | 72daa122b6a4a9562109299d0b747c71aac1e483 (patch) | |
tree | cc1dff80e1e89158b0cac778433fcea5c08ae5f9 /package/config/symbol.c | |
parent | 359a922659c6b33c44ab7c4f94de7d801a8bea63 (diff) |
package/config: rebase against 2.6.37-rc1
Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
Diffstat (limited to 'package/config/symbol.c')
-rw-r--r-- | package/config/symbol.c | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/package/config/symbol.c b/package/config/symbol.c index 1f8b30544..c0efe102d 100644 --- a/package/config/symbol.c +++ b/package/config/symbol.c @@ -350,7 +350,6 @@ void sym_calc_value(struct symbol *sym) } } calc_newval: -#if 0 if (sym->dir_dep.tri == no && sym->rev_dep.tri != no) { fprintf(stderr, "warning: ("); expr_fprint(sym->rev_dep.expr, stderr); @@ -359,7 +358,6 @@ void sym_calc_value(struct symbol *sym) expr_fprint(sym->dir_dep.expr, stderr); fprintf(stderr, ")\n"); } -#endif newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri); } if (newval.tri == mod && sym_get_type(sym) == S_BOOLEAN) @@ -842,6 +840,55 @@ struct symbol *sym_find(const char *name) return symbol; } +/* + * Expand symbol's names embedded in the string given in argument. Symbols' + * name to be expanded shall be prefixed by a '$'. Unknown symbol expands to + * the empty string. + */ +const char *sym_expand_string_value(const char *in) +{ + const char *src; + char *res; + size_t reslen; + + reslen = strlen(in) + 1; + res = malloc(reslen); + res[0] = '\0'; + + while ((src = strchr(in, '$'))) { + char *p, name[SYMBOL_MAXLENGTH]; + const char *symval = ""; + struct symbol *sym; + size_t newlen; + + strncat(res, in, src - in); + src++; + + p = name; + while (isalnum(*src) || *src == '_') + *p++ = *src++; + *p = '\0'; + + sym = sym_find(name); + if (sym != NULL) { + sym_calc_value(sym); + symval = sym_get_string_value(sym); + } + + newlen = strlen(res) + strlen(symval) + strlen(src); + if (newlen > reslen) { + reslen = newlen; + res = realloc(res, reslen); + } + + strcat(res, symval); + in = src; + } + strcat(res, in); + + return res; +} + struct symbol **sym_re_search(const char *pattern) { struct symbol *sym, **sym_arr = NULL; |