diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2013-07-12 06:34:42 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2013-07-12 06:34:42 -0400 |
commit | f2006e27396f55276f24434f56e208d86e7f9908 (patch) | |
tree | 71896db916d33888b4286f80117d3cac0da40e6d /scripts/kconfig/symbol.c | |
parent | e399eb56a6110e13f97e644658648602e2b08de7 (diff) | |
parent | 9903883f1dd6e86f286b7bfa6e4b423f98c1cd9e (diff) |
Merge branch 'linus' into timers/urgent
Get upstream changes so we can apply fixes against them
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'scripts/kconfig/symbol.c')
-rw-r--r-- | scripts/kconfig/symbol.c | 99 |
1 files changed, 85 insertions, 14 deletions
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index ecc5aa5f865d..d550300ec00c 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c | |||
@@ -136,7 +136,7 @@ static struct property *sym_get_range_prop(struct symbol *sym) | |||
136 | return NULL; | 136 | return NULL; |
137 | } | 137 | } |
138 | 138 | ||
139 | static int sym_get_range_val(struct symbol *sym, int base) | 139 | static long sym_get_range_val(struct symbol *sym, int base) |
140 | { | 140 | { |
141 | sym_calc_value(sym); | 141 | sym_calc_value(sym); |
142 | switch (sym->type) { | 142 | switch (sym->type) { |
@@ -155,7 +155,7 @@ static int sym_get_range_val(struct symbol *sym, int base) | |||
155 | static void sym_validate_range(struct symbol *sym) | 155 | static void sym_validate_range(struct symbol *sym) |
156 | { | 156 | { |
157 | struct property *prop; | 157 | struct property *prop; |
158 | int base, val, val2; | 158 | long base, val, val2; |
159 | char str[64]; | 159 | char str[64]; |
160 | 160 | ||
161 | switch (sym->type) { | 161 | switch (sym->type) { |
@@ -179,9 +179,9 @@ static void sym_validate_range(struct symbol *sym) | |||
179 | return; | 179 | return; |
180 | } | 180 | } |
181 | if (sym->type == S_INT) | 181 | if (sym->type == S_INT) |
182 | sprintf(str, "%d", val2); | 182 | sprintf(str, "%ld", val2); |
183 | else | 183 | else |
184 | sprintf(str, "0x%x", val2); | 184 | sprintf(str, "0x%lx", val2); |
185 | sym->curr.val = strdup(str); | 185 | sym->curr.val = strdup(str); |
186 | } | 186 | } |
187 | 187 | ||
@@ -300,6 +300,14 @@ void sym_calc_value(struct symbol *sym) | |||
300 | 300 | ||
301 | if (sym->flags & SYMBOL_VALID) | 301 | if (sym->flags & SYMBOL_VALID) |
302 | return; | 302 | return; |
303 | |||
304 | if (sym_is_choice_value(sym) && | ||
305 | sym->flags & SYMBOL_NEED_SET_CHOICE_VALUES) { | ||
306 | sym->flags &= ~SYMBOL_NEED_SET_CHOICE_VALUES; | ||
307 | prop = sym_get_choice_prop(sym); | ||
308 | sym_calc_value(prop_get_symbol(prop)); | ||
309 | } | ||
310 | |||
303 | sym->flags |= SYMBOL_VALID; | 311 | sym->flags |= SYMBOL_VALID; |
304 | 312 | ||
305 | oldval = sym->curr; | 313 | oldval = sym->curr; |
@@ -425,6 +433,9 @@ void sym_calc_value(struct symbol *sym) | |||
425 | 433 | ||
426 | if (sym->flags & SYMBOL_AUTO) | 434 | if (sym->flags & SYMBOL_AUTO) |
427 | sym->flags &= ~SYMBOL_WRITE; | 435 | sym->flags &= ~SYMBOL_WRITE; |
436 | |||
437 | if (sym->flags & SYMBOL_NEED_SET_CHOICE_VALUES) | ||
438 | set_all_choice_values(sym); | ||
428 | } | 439 | } |
429 | 440 | ||
430 | void sym_clear_all_valid(void) | 441 | void sym_clear_all_valid(void) |
@@ -583,7 +594,7 @@ bool sym_string_valid(struct symbol *sym, const char *str) | |||
583 | bool sym_string_within_range(struct symbol *sym, const char *str) | 594 | bool sym_string_within_range(struct symbol *sym, const char *str) |
584 | { | 595 | { |
585 | struct property *prop; | 596 | struct property *prop; |
586 | int val; | 597 | long val; |
587 | 598 | ||
588 | switch (sym->type) { | 599 | switch (sym->type) { |
589 | case S_STRING: | 600 | case S_STRING: |
@@ -943,38 +954,98 @@ const char *sym_escape_string_value(const char *in) | |||
943 | return res; | 954 | return res; |
944 | } | 955 | } |
945 | 956 | ||
957 | struct sym_match { | ||
958 | struct symbol *sym; | ||
959 | off_t so, eo; | ||
960 | }; | ||
961 | |||
962 | /* Compare matched symbols as thus: | ||
963 | * - first, symbols that match exactly | ||
964 | * - then, alphabetical sort | ||
965 | */ | ||
966 | static int sym_rel_comp( const void *sym1, const void *sym2 ) | ||
967 | { | ||
968 | struct sym_match *s1 = *(struct sym_match **)sym1; | ||
969 | struct sym_match *s2 = *(struct sym_match **)sym2; | ||
970 | int l1, l2; | ||
971 | |||
972 | /* Exact match: | ||
973 | * - if matched length on symbol s1 is the length of that symbol, | ||
974 | * then this symbol should come first; | ||
975 | * - if matched length on symbol s2 is the length of that symbol, | ||
976 | * then this symbol should come first. | ||
977 | * Note: since the search can be a regexp, both symbols may match | ||
978 | * exactly; if this is the case, we can't decide which comes first, | ||
979 | * and we fallback to sorting alphabetically. | ||
980 | */ | ||
981 | l1 = s1->eo - s1->so; | ||
982 | l2 = s2->eo - s2->so; | ||
983 | if (l1 == strlen(s1->sym->name) && l2 != strlen(s2->sym->name)) | ||
984 | return -1; | ||
985 | if (l1 != strlen(s1->sym->name) && l2 == strlen(s2->sym->name)) | ||
986 | return 1; | ||
987 | |||
988 | /* As a fallback, sort symbols alphabetically */ | ||
989 | return strcmp(s1->sym->name, s2->sym->name); | ||
990 | } | ||
991 | |||
946 | struct symbol **sym_re_search(const char *pattern) | 992 | struct symbol **sym_re_search(const char *pattern) |
947 | { | 993 | { |
948 | struct symbol *sym, **sym_arr = NULL; | 994 | struct symbol *sym, **sym_arr = NULL; |
995 | struct sym_match **sym_match_arr = NULL; | ||
949 | int i, cnt, size; | 996 | int i, cnt, size; |
950 | regex_t re; | 997 | regex_t re; |
998 | regmatch_t match[1]; | ||
951 | 999 | ||
952 | cnt = size = 0; | 1000 | cnt = size = 0; |
953 | /* Skip if empty */ | 1001 | /* Skip if empty */ |
954 | if (strlen(pattern) == 0) | 1002 | if (strlen(pattern) == 0) |
955 | return NULL; | 1003 | return NULL; |
956 | if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB|REG_ICASE)) | 1004 | if (regcomp(&re, pattern, REG_EXTENDED|REG_ICASE)) |
957 | return NULL; | 1005 | return NULL; |
958 | 1006 | ||
959 | for_all_symbols(i, sym) { | 1007 | for_all_symbols(i, sym) { |
1008 | struct sym_match *tmp_sym_match; | ||
960 | if (sym->flags & SYMBOL_CONST || !sym->name) | 1009 | if (sym->flags & SYMBOL_CONST || !sym->name) |
961 | continue; | 1010 | continue; |
962 | if (regexec(&re, sym->name, 0, NULL, 0)) | 1011 | if (regexec(&re, sym->name, 1, match, 0)) |
963 | continue; | 1012 | continue; |
964 | if (cnt + 1 >= size) { | 1013 | if (cnt + 1 >= size) { |
965 | void *tmp = sym_arr; | 1014 | void *tmp; |
966 | size += 16; | 1015 | size += 16; |
967 | sym_arr = realloc(sym_arr, size * sizeof(struct symbol *)); | 1016 | tmp = realloc(sym_match_arr, size * sizeof(struct sym_match *)); |
968 | if (!sym_arr) { | 1017 | if (!tmp) { |
969 | free(tmp); | 1018 | goto sym_re_search_free; |
970 | return NULL; | ||
971 | } | 1019 | } |
1020 | sym_match_arr = tmp; | ||
972 | } | 1021 | } |
973 | sym_calc_value(sym); | 1022 | sym_calc_value(sym); |
974 | sym_arr[cnt++] = sym; | 1023 | tmp_sym_match = (struct sym_match*)malloc(sizeof(struct sym_match)); |
1024 | if (!tmp_sym_match) | ||
1025 | goto sym_re_search_free; | ||
1026 | tmp_sym_match->sym = sym; | ||
1027 | /* As regexec return 0, we know we have a match, so | ||
1028 | * we can use match[0].rm_[se]o without further checks | ||
1029 | */ | ||
1030 | tmp_sym_match->so = match[0].rm_so; | ||
1031 | tmp_sym_match->eo = match[0].rm_eo; | ||
1032 | sym_match_arr[cnt++] = tmp_sym_match; | ||
975 | } | 1033 | } |
976 | if (sym_arr) | 1034 | if (sym_match_arr) { |
1035 | qsort(sym_match_arr, cnt, sizeof(struct sym_match*), sym_rel_comp); | ||
1036 | sym_arr = malloc((cnt+1) * sizeof(struct symbol)); | ||
1037 | if (!sym_arr) | ||
1038 | goto sym_re_search_free; | ||
1039 | for (i = 0; i < cnt; i++) | ||
1040 | sym_arr[i] = sym_match_arr[i]->sym; | ||
977 | sym_arr[cnt] = NULL; | 1041 | sym_arr[cnt] = NULL; |
1042 | } | ||
1043 | sym_re_search_free: | ||
1044 | if (sym_match_arr) { | ||
1045 | for (i = 0; i < cnt; i++) | ||
1046 | free(sym_match_arr[i]); | ||
1047 | free(sym_match_arr); | ||
1048 | } | ||
978 | regfree(&re); | 1049 | regfree(&re); |
979 | 1050 | ||
980 | return sym_arr; | 1051 | return sym_arr; |