aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/symbol.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/kconfig/symbol.c')
-rw-r--r--scripts/kconfig/symbol.c49
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 */
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;