diff options
author | Arnaud Lacombe <lacombar@gmail.com> | 2010-08-18 01:23:50 -0400 |
---|---|---|
committer | Arnaud Lacombe <lacombar@gmail.com> | 2010-09-19 18:19:48 -0400 |
commit | 76a540958af5390a94b7f68c46cb7f2aed34ccf1 (patch) | |
tree | 19c6fd1e22ff5fac8785b5fb2779ace0c7d3d0c1 /scripts/kconfig/symbol.c | |
parent | c0920a1cbd7aecefa5f9768e82136935132ef1cf (diff) |
kconfig: add a symbol string expansion helper
Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
Reviewed-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts/kconfig/symbol.c')
-rw-r--r-- | scripts/kconfig/symbol.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 943712ca6c0a..dc5dcf2189a0 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c | |||
@@ -840,6 +840,55 @@ struct symbol *sym_find(const char *name) | |||
840 | return symbol; | 840 | return symbol; |
841 | } | 841 | } |
842 | 842 | ||
843 | /* | ||
844 | * Expand symbol's names embedded in the string given in argument. Symbols' | ||
845 | * name to be expanded shall be prefixed by a '$'. Unknown symbol expands to | ||
846 | * the empty string. | ||
847 | */ | ||
848 | const char *sym_expand_string_value(const char *in) | ||
849 | { | ||
850 | const char *src; | ||
851 | char *res; | ||
852 | size_t reslen; | ||
853 | |||
854 | reslen = strlen(in) + 1; | ||
855 | res = malloc(reslen); | ||
856 | res[0] = '\0'; | ||
857 | |||
858 | while ((src = strchr(in, '$'))) { | ||
859 | char *p, name[SYMBOL_MAXLENGTH]; | ||
860 | const char *symval = ""; | ||
861 | struct symbol *sym; | ||
862 | size_t newlen; | ||
863 | |||
864 | strncat(res, in, src - in); | ||
865 | src++; | ||
866 | |||
867 | p = name; | ||
868 | while (isalnum(*src) || *src == '_') | ||
869 | *p++ = *src++; | ||
870 | *p = '\0'; | ||
871 | |||
872 | sym = sym_find(name); | ||
873 | if (sym != NULL) { | ||
874 | sym_calc_value(sym); | ||
875 | symval = sym_get_string_value(sym); | ||
876 | } | ||
877 | |||
878 | newlen = strlen(res) + strlen(symval) + strlen(src); | ||
879 | if (newlen > reslen) { | ||
880 | reslen = newlen; | ||
881 | realloc(res, reslen); | ||
882 | } | ||
883 | |||
884 | strcat(res, symval); | ||
885 | in = src; | ||
886 | } | ||
887 | strcat(res, in); | ||
888 | |||
889 | return res; | ||
890 | } | ||
891 | |||
843 | struct symbol **sym_re_search(const char *pattern) | 892 | struct symbol **sym_re_search(const char *pattern) |
844 | { | 893 | { |
845 | struct symbol *sym, **sym_arr = NULL; | 894 | struct symbol *sym, **sym_arr = NULL; |