aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scripts/kconfig/lkc_proto.h1
-rw-r--r--scripts/kconfig/symbol.c49
2 files changed, 50 insertions, 0 deletions
diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h
index 9a948c9ce44e..4531badb3fe1 100644
--- a/scripts/kconfig/lkc_proto.h
+++ b/scripts/kconfig/lkc_proto.h
@@ -28,6 +28,7 @@ P(symbol_hash,struct symbol *,[SYMBOL_HASHSIZE]);
28 28
29P(sym_lookup,struct symbol *,(const char *name, int flags)); 29P(sym_lookup,struct symbol *,(const char *name, int flags));
30P(sym_find,struct symbol *,(const char *name)); 30P(sym_find,struct symbol *,(const char *name));
31P(sym_expand_string_value,const char *,(const char *in));
31P(sym_re_search,struct symbol **,(const char *pattern)); 32P(sym_re_search,struct symbol **,(const char *pattern));
32P(sym_type_name,const char *,(enum symbol_type type)); 33P(sym_type_name,const char *,(enum symbol_type type));
33P(sym_calc_value,void,(struct symbol *sym)); 34P(sym_calc_value,void,(struct symbol *sym));
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 */
848const 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
843struct symbol **sym_re_search(const char *pattern) 892struct symbol **sym_re_search(const char *pattern)
844{ 893{
845 struct symbol *sym, **sym_arr = NULL; 894 struct symbol *sym, **sym_arr = NULL;