10 #include <sys/utsname.h>
38 static void sym_add_default(
struct symbol *sym,
const char *def)
49 static bool inited =
false;
60 sym_add_default(sym, uts.release);
68 if (sym_is_choice_value(sym) && sym->
visible ==
yes)
139 static int sym_get_range_val(
struct symbol *sym,
int base)
152 return strtol(sym->
curr.val,
NULL, base);
155 static void sym_validate_range(
struct symbol *sym)
171 prop = sym_get_range_prop(sym);
174 val = strtol(sym->
curr.val,
NULL, base);
175 val2 = sym_get_range_val(prop->
expr->left.sym, base);
177 val2 = sym_get_range_val(prop->
expr->right.sym, base);
185 sym->
curr.val = strdup(str);
188 static void sym_calc_visibility(
struct symbol *sym)
205 if (sym_is_choice_value(sym))
260 static struct symbol *sym_calc_choice(
struct symbol *sym)
271 sym_calc_visibility(def_sym);
273 flags &= def_sym->
flags;
322 if (!sym_is_choice_value(sym))
325 sym_calc_visibility(sym);
333 if (sym_is_choice_value(sym) && sym->
visible ==
yes) {
342 if (sym_has_value(sym)) {
350 if (!sym_is_choice(sym)) {
365 fprintf(stderr,
") selects %s which has unmet direct dependencies (",
381 if (sym_has_value(sym)) {
401 if (sym_is_choice(sym) && newval.
tri ==
yes)
402 sym->
curr.val = sym_calc_choice(sym);
403 sym_validate_range(sym);
405 if (
memcmp(&oldval, &sym->
curr,
sizeof(oldval))) {
407 if (modules_sym == sym) {
413 if (sym_is_choice(sym)) {
414 struct symbol *choice_sym;
447 for (prop = sym->
prop; prop; prop = prop->
next) {
476 if (sym_is_choice_value(sym) && sym->
visible ==
yes)
483 tristate oldval = sym_get_tristate_value(sym);
496 if (sym_is_choice_value(sym) && val ==
yes) {
504 for (e = prop->
expr; e; e = e->left.expr) {
521 oldval = newval = sym_get_tristate_value(sym);
536 }
while (oldval != newval);
553 if (ch ==
'0' && *str != 0)
555 while ((ch = *str++)) {
561 if (str[0] ==
'0' && (str[1] ==
'x' || str[1] ==
'X'))
567 }
while ((ch = *str++));
594 prop = sym_get_range_prop(sym);
597 val = strtol(str,
NULL, 10);
598 return val >= sym_get_range_val(prop->
expr->left.sym, 10) &&
599 val <= sym_get_range_val(prop->
expr->right.sym, 10);
603 prop = sym_get_range_prop(sym);
606 val = strtol(str,
NULL, 16);
607 return val >= sym_get_range_val(prop->
expr->left.sym, 16) &&
608 val <= sym_get_range_val(prop->
expr->right.sym, 16);
656 size =
strlen(newval) + 1;
657 if (sym->
type ==
S_HEX && (newval[0] !=
'0' || (newval[1] !=
'x' && newval[1] !=
'X'))) {
662 }
else if (!oldval ||
strcmp(oldval, newval))
668 free((
void *)oldval);
688 sym_calc_visibility(sym);
711 str = (
const char *)ds->
curr.val;
721 if (!sym_is_choice_value(sym) && modules_sym->
curr.tri ==
no)
733 case mod:
return "m";
734 case yes:
return "y";
755 val = sym_get_tristate_value(sym);
761 return (modules_sym->
curr.tri ==
no) ?
"n" :
"m";
769 return (
const char *)sym->
curr.val;
777 static unsigned strhash(
const char *
s)
780 unsigned hash = 2166136261
U;
782 hash = (hash ^ *s) * 0x01000193;
793 if (name[0] && !name[1]) {
802 for (symbol = symbol_hash[hash]; symbol; symbol = symbol->
next) {
805 (flags ? symbol->
flags & flags
809 new_name = strdup(name);
815 symbol =
malloc(
sizeof(*symbol));
816 memset(symbol, 0,
sizeof(*symbol));
817 symbol->
name = new_name;
822 symbol_hash[
hash] = symbol;
835 if (name[0] && !name[1]) {
844 for (symbol = symbol_hash[hash]; symbol; symbol = symbol->
next) {
869 while ((src =
strchr(in,
'$'))) {
871 const char *symval =
"";
879 while (
isalnum(*src) || *src ==
'_')
890 if (newlen > reslen) {
892 res = realloc(res, reslen);
956 if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB|REG_ICASE))
962 if (regexec(&re, sym->
name, 0,
NULL, 0))
964 if (cnt + 1 >= size) {
967 sym_arr = realloc(sym_arr, size *
sizeof(
struct symbol *));
974 sym_arr[cnt++] = sym;
989 static struct dep_stack {
996 static void dep_stack_insert(
struct dep_stack *
stack,
struct symbol *sym)
998 memset(stack, 0,
sizeof(*stack));
1000 check_top->next =
stack;
1001 stack->prev = check_top;
1006 static void dep_stack_remove(
void)
1008 check_top = check_top->prev;
1010 check_top->next =
NULL;
1018 static void sym_check_print_recursive(
struct symbol *last_sym)
1020 struct dep_stack *
stack;
1021 struct symbol *sym, *next_sym;
1024 struct dep_stack cv_stack;
1026 if (sym_is_choice_value(last_sym)) {
1027 dep_stack_insert(&cv_stack, last_sym);
1031 for (stack = check_top; stack !=
NULL; stack = stack->prev)
1032 if (stack->sym == last_sym)
1035 fprintf(stderr,
"unexpected recursive dependency error\n");
1039 for (;
stack; stack = stack->next) {
1041 next_sym = stack->next ? stack->next->sym : last_sym;
1044 prop = stack->sym->prop;
1047 if (sym_is_choice(sym) || sym_is_choice_value(sym)) {
1048 for (prop = sym->
prop; prop; prop = prop->
next) {
1054 if (stack->sym == last_sym)
1055 fprintf(stderr,
"%s:%d:error: recursive dependency detected!\n",
1058 fprintf(stderr,
"%s:%d:\tsymbol %s %s value contains %s\n",
1060 sym->
name ? sym->
name :
"<choice>",
1062 next_sym->
name ? next_sym->
name :
"<choice>");
1063 }
else if (stack->prop) {
1064 fprintf(stderr,
"%s:%d:\tsymbol %s depends on %s\n",
1066 sym->
name ? sym->
name :
"<choice>",
1067 next_sym->
name ? next_sym->
name :
"<choice>");
1068 }
else if (sym_is_choice(sym)) {
1069 fprintf(stderr,
"%s:%d:\tchoice %s contains symbol %s\n",
1071 sym->
name ? sym->
name :
"<choice>",
1072 next_sym->
name ? next_sym->
name :
"<choice>");
1073 }
else if (sym_is_choice_value(sym)) {
1074 fprintf(stderr,
"%s:%d:\tsymbol %s is part of choice %s\n",
1076 sym->
name ? sym->
name :
"<choice>",
1077 next_sym->
name ? next_sym->
name :
"<choice>");
1079 fprintf(stderr,
"%s:%d:\tsymbol %s is selected by %s\n",
1081 sym->
name ? sym->
name :
"<choice>",
1082 next_sym->
name ? next_sym->
name :
"<choice>");
1086 if (check_top == &cv_stack)
1090 static struct symbol *sym_check_expr_deps(
struct expr *e)
1099 sym = sym_check_expr_deps(e->left.expr);
1102 return sym_check_expr_deps(e->
right.
expr);
1104 return sym_check_expr_deps(e->left.expr);
1121 static struct symbol *sym_check_sym_deps(
struct symbol *sym)
1125 struct dep_stack stack;
1127 dep_stack_insert(&stack, sym);
1129 sym2 = sym_check_expr_deps(sym->
rev_dep.expr);
1133 for (prop = sym->
prop; prop; prop = prop->
next) {
1137 sym2 = sym_check_expr_deps(prop->
visible.expr);
1142 stack.expr = prop->
expr;
1143 sym2 = sym_check_expr_deps(prop->
expr);
1155 static struct symbol *sym_check_choice_deps(
struct symbol *choice)
1157 struct symbol *sym, *sym2;
1160 struct dep_stack stack;
1162 dep_stack_insert(&stack, choice);
1169 sym2 = sym_check_sym_deps(choice);
1175 sym2 = sym_check_sym_deps(sym);
1181 sym->flags &= ~SYMBOL_CHECK;
1183 if (sym2 && sym_is_choice_value(sym2) &&
1197 if (sym->flags & SYMBOL_CHECK) {
1198 sym_check_print_recursive(sym);
1201 if (sym->flags & SYMBOL_CHECKED)
1204 if (sym_is_choice_value(sym)) {
1205 struct dep_stack stack;
1208 dep_stack_insert(&stack, sym);
1212 }
else if (sym_is_choice(sym)) {
1213 sym2 = sym_check_choice_deps(sym);
1216 sym2 = sym_check_sym_deps(sym);
1217 sym->flags &= ~SYMBOL_CHECK;
1220 if (sym2 && sym2 == sym)
1231 prop =
malloc(
sizeof(*prop));
1232 memset(prop, 0,
sizeof(*prop));
1240 for (propp = &sym->
prop; *propp; propp = &(*propp)->
next)
1252 return prop->
expr->left.sym;
1283 static void prop_add_env(
const char *
env)
1285 struct symbol *sym, *sym2;
1289 sym = current_entry->sym;
1294 menu_warn(current_entry,
"redefining environment symbol from %s",
1307 sym_add_default(sym, p);
1309 menu_warn(current_entry,
"environment variable %s undefined", env);