2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
11 #include <sys/utsname.h>
16 struct symbol symbol_yes
= {
19 .flags
= SYMBOL_CONST
|SYMBOL_VALID
,
23 .flags
= SYMBOL_CONST
|SYMBOL_VALID
,
27 .flags
= SYMBOL_CONST
|SYMBOL_VALID
,
31 .flags
= SYMBOL_VALID
,
34 struct symbol
*sym_defconfig_list
;
35 struct symbol
*modules_sym
;
38 struct expr
*sym_env_list
;
40 static void sym_add_default(struct symbol
*sym
, const char *def
)
42 struct property
*prop
= prop_alloc(P_DEFAULT
, sym
);
44 prop
->expr
= expr_alloc_symbol(sym_lookup(def
, SYMBOL_CONST
));
53 static bool inited
= false;
63 sym
= sym_lookup("UNAME_RELEASE", 0);
65 sym
->flags
|= SYMBOL_AUTO
;
67 sym_add_default(sym
, uts
.release
);
69 sym_add_default(sym
, "mingw-unknown");
73 enum symbol_type
sym_get_type(struct symbol
*sym
)
75 enum symbol_type type
= sym
->type
;
77 if (type
== S_TRISTATE
) {
78 if (sym_is_choice_value(sym
) && sym
->visible
== yes
)
80 else if (modules_val
== no
)
86 const char *sym_type_name(enum symbol_type type
)
107 struct property
*sym_get_choice_prop(struct symbol
*sym
)
109 struct property
*prop
;
111 for_all_choices(sym
, prop
)
116 struct property
*sym_get_env_prop(struct symbol
*sym
)
118 struct property
*prop
;
120 for_all_properties(sym
, prop
, P_ENV
)
125 struct property
*sym_get_default_prop(struct symbol
*sym
)
127 struct property
*prop
;
129 for_all_defaults(sym
, prop
) {
130 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
131 if (prop
->visible
.tri
!= no
)
137 static struct property
*sym_get_range_prop(struct symbol
*sym
)
139 struct property
*prop
;
141 for_all_properties(sym
, prop
, P_RANGE
) {
142 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
143 if (prop
->visible
.tri
!= no
)
149 static long long sym_get_range_val(struct symbol
*sym
, int base
)
162 return strtoll(sym
->curr
.val
, NULL
, base
);
165 static void sym_validate_range(struct symbol
*sym
)
167 struct property
*prop
;
182 prop
= sym_get_range_prop(sym
);
185 val
= strtoll(sym
->curr
.val
, NULL
, base
);
186 val2
= sym_get_range_val(prop
->expr
->left
.sym
, base
);
188 val2
= sym_get_range_val(prop
->expr
->right
.sym
, base
);
192 if (sym
->type
== S_INT
)
193 sprintf(str
, "%lld", val2
);
195 sprintf(str
, "0x%llx", val2
);
196 sym
->curr
.val
= strdup(str
);
199 static void sym_calc_visibility(struct symbol
*sym
)
201 struct property
*prop
;
204 /* any prompt visible? */
206 for_all_prompts(sym
, prop
) {
207 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
208 tri
= EXPR_OR(tri
, prop
->visible
.tri
);
210 if (tri
== mod
&& (sym
->type
!= S_TRISTATE
|| modules_val
== no
))
212 if (sym
->visible
!= tri
) {
214 sym_set_changed(sym
);
216 if (sym_is_choice_value(sym
))
218 /* defaulting to "yes" if no explicit "depends on" are given */
220 if (sym
->dir_dep
.expr
)
221 tri
= expr_calc_value(sym
->dir_dep
.expr
);
224 if (sym
->dir_dep
.tri
!= tri
) {
225 sym
->dir_dep
.tri
= tri
;
226 sym_set_changed(sym
);
229 if (sym
->rev_dep
.expr
)
230 tri
= expr_calc_value(sym
->rev_dep
.expr
);
231 if (tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
233 if (sym
->rev_dep
.tri
!= tri
) {
234 sym
->rev_dep
.tri
= tri
;
235 sym_set_changed(sym
);
240 * Find the default symbol for a choice.
241 * First try the default values for the choice symbol
242 * Next locate the first visible choice value
243 * Return NULL if none was found
245 struct symbol
*sym_choice_default(struct symbol
*sym
)
247 struct symbol
*def_sym
;
248 struct property
*prop
;
251 /* any of the defaults visible? */
252 for_all_defaults(sym
, prop
) {
253 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
254 if (prop
->visible
.tri
== no
)
256 def_sym
= prop_get_symbol(prop
);
257 if (def_sym
->visible
!= no
)
261 /* just get the first visible value */
262 prop
= sym_get_choice_prop(sym
);
263 expr_list_for_each_sym(prop
->expr
, e
, def_sym
)
264 if (def_sym
->visible
!= no
)
267 /* failed to locate any defaults */
271 static struct symbol
*sym_calc_choice(struct symbol
*sym
)
273 struct symbol
*def_sym
;
274 struct property
*prop
;
278 /* first calculate all choice values' visibilities */
280 prop
= sym_get_choice_prop(sym
);
281 expr_list_for_each_sym(prop
->expr
, e
, def_sym
) {
282 sym_calc_visibility(def_sym
);
283 if (def_sym
->visible
!= no
)
284 flags
&= def_sym
->flags
;
287 sym
->flags
&= flags
| ~SYMBOL_DEF_USER
;
289 /* is the user choice visible? */
290 def_sym
= sym
->def
[S_DEF_USER
].val
;
291 if (def_sym
&& def_sym
->visible
!= no
)
294 def_sym
= sym_choice_default(sym
);
297 /* no choice? reset tristate value */
303 void sym_calc_value(struct symbol
*sym
)
305 struct symbol_value newval
, oldval
;
306 struct property
*prop
;
312 if (sym
->flags
& SYMBOL_VALID
)
315 if (sym_is_choice_value(sym
) &&
316 sym
->flags
& SYMBOL_NEED_SET_CHOICE_VALUES
) {
317 sym
->flags
&= ~SYMBOL_NEED_SET_CHOICE_VALUES
;
318 prop
= sym_get_choice_prop(sym
);
319 sym_calc_value(prop_get_symbol(prop
));
322 sym
->flags
|= SYMBOL_VALID
;
330 newval
= symbol_empty
.curr
;
334 newval
= symbol_no
.curr
;
337 sym
->curr
.val
= sym
->name
;
341 if (!sym_is_choice_value(sym
))
342 sym
->flags
&= ~SYMBOL_WRITE
;
344 sym_calc_visibility(sym
);
346 /* set default if recursively called */
349 switch (sym_get_type(sym
)) {
352 if (sym_is_choice_value(sym
) && sym
->visible
== yes
) {
353 prop
= sym_get_choice_prop(sym
);
354 newval
.tri
= (prop_get_symbol(prop
)->curr
.val
== sym
) ? yes
: no
;
356 if (sym
->visible
!= no
) {
357 /* if the symbol is visible use the user value
358 * if available, otherwise try the default value
360 sym
->flags
|= SYMBOL_WRITE
;
361 if (sym_has_value(sym
)) {
362 newval
.tri
= EXPR_AND(sym
->def
[S_DEF_USER
].tri
,
367 if (sym
->rev_dep
.tri
!= no
)
368 sym
->flags
|= SYMBOL_WRITE
;
369 if (!sym_is_choice(sym
)) {
370 prop
= sym_get_default_prop(sym
);
372 sym
->flags
|= SYMBOL_WRITE
;
373 newval
.tri
= EXPR_AND(expr_calc_value(prop
->expr
),
378 if (sym
->dir_dep
.tri
== no
&& sym
->rev_dep
.tri
!= no
) {
380 e
= expr_simplify_unmet_dep(sym
->rev_dep
.expr
,
382 fprintf(stderr
, "warning: (");
383 expr_fprint(e
, stderr
);
384 fprintf(stderr
, ") selects %s which has unmet direct dependencies (",
386 expr_fprint(sym
->dir_dep
.expr
, stderr
);
387 fprintf(stderr
, ")\n");
391 newval
.tri
= EXPR_OR(newval
.tri
, sym
->rev_dep
.tri
);
393 if (newval
.tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
399 if (sym
->visible
!= no
) {
400 sym
->flags
|= SYMBOL_WRITE
;
401 if (sym_has_value(sym
)) {
402 newval
.val
= sym
->def
[S_DEF_USER
].val
;
406 prop
= sym_get_default_prop(sym
);
408 struct symbol
*ds
= prop_get_symbol(prop
);
410 sym
->flags
|= SYMBOL_WRITE
;
412 newval
.val
= ds
->curr
.val
;
421 if (sym_is_choice(sym
) && newval
.tri
== yes
)
422 sym
->curr
.val
= sym_calc_choice(sym
);
423 sym_validate_range(sym
);
425 if (memcmp(&oldval
, &sym
->curr
, sizeof(oldval
))) {
426 sym_set_changed(sym
);
427 if (modules_sym
== sym
) {
428 sym_set_all_changed();
429 modules_val
= modules_sym
->curr
.tri
;
433 if (sym_is_choice(sym
)) {
434 struct symbol
*choice_sym
;
436 prop
= sym_get_choice_prop(sym
);
437 expr_list_for_each_sym(prop
->expr
, e
, choice_sym
) {
438 if ((sym
->flags
& SYMBOL_WRITE
) &&
439 choice_sym
->visible
!= no
)
440 choice_sym
->flags
|= SYMBOL_WRITE
;
441 if (sym
->flags
& SYMBOL_CHANGED
)
442 sym_set_changed(choice_sym
);
446 if (sym
->flags
& SYMBOL_AUTO
)
447 sym
->flags
&= ~SYMBOL_WRITE
;
449 if (sym
->flags
& SYMBOL_NEED_SET_CHOICE_VALUES
)
450 set_all_choice_values(sym
);
453 void sym_clear_all_valid(void)
458 for_all_symbols(i
, sym
)
459 sym
->flags
&= ~SYMBOL_VALID
;
460 sym_add_change_count(1);
462 sym_calc_value(modules_sym
);
465 void sym_set_changed(struct symbol
*sym
)
467 struct property
*prop
;
469 sym
->flags
|= SYMBOL_CHANGED
;
470 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
472 prop
->menu
->flags
|= MENU_CHANGED
;
476 void sym_set_all_changed(void)
481 for_all_symbols(i
, sym
)
482 sym_set_changed(sym
);
485 bool sym_tristate_within_range(struct symbol
*sym
, tristate val
)
487 int type
= sym_get_type(sym
);
489 if (sym
->visible
== no
)
492 if (type
!= S_BOOLEAN
&& type
!= S_TRISTATE
)
495 if (type
== S_BOOLEAN
&& val
== mod
)
497 if (sym
->visible
<= sym
->rev_dep
.tri
)
499 if (sym_is_choice_value(sym
) && sym
->visible
== yes
)
501 return val
>= sym
->rev_dep
.tri
&& val
<= sym
->visible
;
504 bool sym_set_tristate_value(struct symbol
*sym
, tristate val
)
506 tristate oldval
= sym_get_tristate_value(sym
);
508 if (oldval
!= val
&& !sym_tristate_within_range(sym
, val
))
511 if (!(sym
->flags
& SYMBOL_DEF_USER
)) {
512 sym
->flags
|= SYMBOL_DEF_USER
;
513 sym_set_changed(sym
);
516 * setting a choice value also resets the new flag of the choice
517 * symbol and all other choice values.
519 if (sym_is_choice_value(sym
) && val
== yes
) {
520 struct symbol
*cs
= prop_get_symbol(sym_get_choice_prop(sym
));
521 struct property
*prop
;
524 cs
->def
[S_DEF_USER
].val
= sym
;
525 cs
->flags
|= SYMBOL_DEF_USER
;
526 prop
= sym_get_choice_prop(cs
);
527 for (e
= prop
->expr
; e
; e
= e
->left
.expr
) {
528 if (e
->right
.sym
->visible
!= no
)
529 e
->right
.sym
->flags
|= SYMBOL_DEF_USER
;
533 sym
->def
[S_DEF_USER
].tri
= val
;
535 sym_clear_all_valid();
540 tristate
sym_toggle_tristate_value(struct symbol
*sym
)
542 tristate oldval
, newval
;
544 oldval
= newval
= sym_get_tristate_value(sym
);
557 if (sym_set_tristate_value(sym
, newval
))
559 } while (oldval
!= newval
);
563 bool sym_string_valid(struct symbol
*sym
, const char *str
)
576 if (ch
== '0' && *str
!= 0)
578 while ((ch
= *str
++)) {
584 if (str
[0] == '0' && (str
[1] == 'x' || str
[1] == 'X'))
590 } while ((ch
= *str
++));
606 bool sym_string_within_range(struct symbol
*sym
, const char *str
)
608 struct property
*prop
;
613 return sym_string_valid(sym
, str
);
615 if (!sym_string_valid(sym
, str
))
617 prop
= sym_get_range_prop(sym
);
620 val
= strtoll(str
, NULL
, 10);
621 return val
>= sym_get_range_val(prop
->expr
->left
.sym
, 10) &&
622 val
<= sym_get_range_val(prop
->expr
->right
.sym
, 10);
624 if (!sym_string_valid(sym
, str
))
626 prop
= sym_get_range_prop(sym
);
629 val
= strtoll(str
, NULL
, 16);
630 return val
>= sym_get_range_val(prop
->expr
->left
.sym
, 16) &&
631 val
<= sym_get_range_val(prop
->expr
->right
.sym
, 16);
636 return sym_tristate_within_range(sym
, yes
);
638 return sym_tristate_within_range(sym
, mod
);
640 return sym_tristate_within_range(sym
, no
);
648 bool sym_set_string_value(struct symbol
*sym
, const char *newval
)
659 return sym_set_tristate_value(sym
, yes
);
661 return sym_set_tristate_value(sym
, mod
);
663 return sym_set_tristate_value(sym
, no
);
670 if (!sym_string_within_range(sym
, newval
))
673 if (!(sym
->flags
& SYMBOL_DEF_USER
)) {
674 sym
->flags
|= SYMBOL_DEF_USER
;
675 sym_set_changed(sym
);
678 oldval
= sym
->def
[S_DEF_USER
].val
;
679 size
= strlen(newval
) + 1;
680 if (sym
->type
== S_HEX
&& (newval
[0] != '0' || (newval
[1] != 'x' && newval
[1] != 'X'))) {
682 sym
->def
[S_DEF_USER
].val
= val
= xmalloc(size
);
685 } else if (!oldval
|| strcmp(oldval
, newval
))
686 sym
->def
[S_DEF_USER
].val
= val
= xmalloc(size
);
691 free((void *)oldval
);
692 sym_clear_all_valid();
698 * Find the default value associated to a symbol.
699 * For tristate symbol handle the modules=n case
700 * in which case "m" becomes "y".
701 * If the symbol does not have any default then fallback
702 * to the fixed default values.
704 const char *sym_get_string_default(struct symbol
*sym
)
706 struct property
*prop
;
711 sym_calc_visibility(sym
);
712 sym_calc_value(modules_sym
);
713 val
= symbol_no
.curr
.tri
;
714 str
= symbol_empty
.curr
.val
;
716 /* If symbol has a default value look it up */
717 prop
= sym_get_default_prop(sym
);
722 /* The visibility may limit the value from yes => mod */
723 val
= EXPR_AND(expr_calc_value(prop
->expr
), prop
->visible
.tri
);
727 * The following fails to handle the situation
728 * where a default value is further limited by
731 ds
= prop_get_symbol(prop
);
734 str
= (const char *)ds
->curr
.val
;
739 /* Handle select statements */
740 val
= EXPR_OR(val
, sym
->rev_dep
.tri
);
742 /* transpose mod to yes if modules are not enabled */
744 if (!sym_is_choice_value(sym
) && modules_sym
->curr
.tri
== no
)
747 /* transpose mod to yes if type is bool */
748 if (sym
->type
== S_BOOLEAN
&& val
== mod
)
756 case mod
: return "m";
757 case yes
: return "y";
771 const char *sym_get_string_value(struct symbol
*sym
)
778 val
= sym_get_tristate_value(sym
);
783 sym_calc_value(modules_sym
);
784 return (modules_sym
->curr
.tri
== no
) ? "n" : "m";
792 return (const char *)sym
->curr
.val
;
795 bool sym_is_changable(struct symbol
*sym
)
797 return sym
->visible
> sym
->rev_dep
.tri
;
800 static unsigned strhash(const char *s
)
803 unsigned hash
= 2166136261U;
805 hash
= (hash
^ *s
) * 0x01000193;
809 struct symbol
*sym_lookup(const char *name
, int flags
)
811 struct symbol
*symbol
;
816 if (name
[0] && !name
[1]) {
818 case 'y': return &symbol_yes
;
819 case 'm': return &symbol_mod
;
820 case 'n': return &symbol_no
;
823 hash
= strhash(name
) % SYMBOL_HASHSIZE
;
825 for (symbol
= symbol_hash
[hash
]; symbol
; symbol
= symbol
->next
) {
827 !strcmp(symbol
->name
, name
) &&
828 (flags
? symbol
->flags
& flags
829 : !(symbol
->flags
& (SYMBOL_CONST
|SYMBOL_CHOICE
))))
832 new_name
= strdup(name
);
838 symbol
= xmalloc(sizeof(*symbol
));
839 memset(symbol
, 0, sizeof(*symbol
));
840 symbol
->name
= new_name
;
841 symbol
->type
= S_UNKNOWN
;
842 symbol
->flags
|= flags
;
844 symbol
->next
= symbol_hash
[hash
];
845 symbol_hash
[hash
] = symbol
;
850 struct symbol
*sym_find(const char *name
)
852 struct symbol
*symbol
= NULL
;
858 if (name
[0] && !name
[1]) {
860 case 'y': return &symbol_yes
;
861 case 'm': return &symbol_mod
;
862 case 'n': return &symbol_no
;
865 hash
= strhash(name
) % SYMBOL_HASHSIZE
;
867 for (symbol
= symbol_hash
[hash
]; symbol
; symbol
= symbol
->next
) {
869 !strcmp(symbol
->name
, name
) &&
870 !(symbol
->flags
& SYMBOL_CONST
))
878 * Expand symbol's names embedded in the string given in argument. Symbols'
879 * name to be expanded shall be prefixed by a '$'. Unknown symbol expands to
882 const char *sym_expand_string_value(const char *in
)
888 reslen
= strlen(in
) + 1;
889 res
= xmalloc(reslen
);
892 while ((src
= strchr(in
, '$'))) {
893 char *p
, name
[SYMBOL_MAXLENGTH
];
894 const char *symval
= "";
898 strncat(res
, in
, src
- in
);
902 while (isalnum(*src
) || *src
== '_')
906 sym
= sym_find(name
);
909 symval
= sym_get_string_value(sym
);
912 newlen
= strlen(res
) + strlen(symval
) + strlen(src
) + 1;
913 if (newlen
> reslen
) {
915 res
= realloc(res
, reslen
);
926 const char *sym_escape_string_value(const char *in
)
933 reslen
= strlen(in
) + strlen("\"\"") + 1;
937 l
= strcspn(p
, "\"\\");
947 res
= xmalloc(reslen
);
954 l
= strcspn(p
, "\"\\");
962 strncat(res
, p
++, 1);
974 /* Compare matched symbols as thus:
975 * - first, symbols that match exactly
976 * - then, alphabetical sort
978 static int sym_rel_comp(const void *sym1
, const void *sym2
)
980 const struct sym_match
*s1
= sym1
;
981 const struct sym_match
*s2
= sym2
;
985 * - if matched length on symbol s1 is the length of that symbol,
986 * then this symbol should come first;
987 * - if matched length on symbol s2 is the length of that symbol,
988 * then this symbol should come first.
989 * Note: since the search can be a regexp, both symbols may match
990 * exactly; if this is the case, we can't decide which comes first,
991 * and we fallback to sorting alphabetically.
993 exact1
= (s1
->eo
- s1
->so
) == strlen(s1
->sym
->name
);
994 exact2
= (s2
->eo
- s2
->so
) == strlen(s2
->sym
->name
);
995 if (exact1
&& !exact2
)
997 if (!exact1
&& exact2
)
1000 /* As a fallback, sort symbols alphabetically */
1001 return strcmp(s1
->sym
->name
, s2
->sym
->name
);
1004 struct symbol
**sym_re_search(const char *pattern
)
1006 struct symbol
*sym
, **sym_arr
= NULL
;
1007 struct sym_match
*sym_match_arr
= NULL
;
1010 regmatch_t match
[1];
1014 if (strlen(pattern
) == 0)
1016 if (regcomp(&re
, pattern
, REG_EXTENDED
|REG_ICASE
))
1019 for_all_symbols(i
, sym
) {
1020 if (sym
->flags
& SYMBOL_CONST
|| !sym
->name
)
1022 if (regexec(&re
, sym
->name
, 1, match
, 0))
1027 tmp
= realloc(sym_match_arr
, size
* sizeof(struct sym_match
));
1029 goto sym_re_search_free
;
1030 sym_match_arr
= tmp
;
1032 sym_calc_value(sym
);
1033 /* As regexec returned 0, we know we have a match, so
1034 * we can use match[0].rm_[se]o without further checks
1036 sym_match_arr
[cnt
].so
= match
[0].rm_so
;
1037 sym_match_arr
[cnt
].eo
= match
[0].rm_eo
;
1038 sym_match_arr
[cnt
++].sym
= sym
;
1040 if (sym_match_arr
) {
1041 qsort(sym_match_arr
, cnt
, sizeof(struct sym_match
), sym_rel_comp
);
1042 sym_arr
= malloc((cnt
+1) * sizeof(struct symbol
));
1044 goto sym_re_search_free
;
1045 for (i
= 0; i
< cnt
; i
++)
1046 sym_arr
[i
] = sym_match_arr
[i
].sym
;
1047 sym_arr
[cnt
] = NULL
;
1050 /* sym_match_arr can be NULL if no match, but free(NULL) is OK */
1051 free(sym_match_arr
);
1058 * When we check for recursive dependencies we use a stack to save
1059 * current state so we can print out relevant info to user.
1060 * The entries are located on the call stack so no need to free memory.
1061 * Note insert() remove() must always match to properly clear the stack.
1063 static struct dep_stack
{
1064 struct dep_stack
*prev
, *next
;
1066 struct property
*prop
;
1070 static void dep_stack_insert(struct dep_stack
*stack
, struct symbol
*sym
)
1072 memset(stack
, 0, sizeof(*stack
));
1074 check_top
->next
= stack
;
1075 stack
->prev
= check_top
;
1080 static void dep_stack_remove(void)
1082 check_top
= check_top
->prev
;
1084 check_top
->next
= NULL
;
1088 * Called when we have detected a recursive dependency.
1089 * check_top point to the top of the stact so we use
1090 * the ->prev pointer to locate the bottom of the stack.
1092 static void sym_check_print_recursive(struct symbol
*last_sym
)
1094 struct dep_stack
*stack
;
1095 struct symbol
*sym
, *next_sym
;
1096 struct menu
*menu
= NULL
;
1097 struct property
*prop
;
1098 struct dep_stack cv_stack
;
1100 if (sym_is_choice_value(last_sym
)) {
1101 dep_stack_insert(&cv_stack
, last_sym
);
1102 last_sym
= prop_get_symbol(sym_get_choice_prop(last_sym
));
1105 for (stack
= check_top
; stack
!= NULL
; stack
= stack
->prev
)
1106 if (stack
->sym
== last_sym
)
1109 fprintf(stderr
, "unexpected recursive dependency error\n");
1113 for (; stack
; stack
= stack
->next
) {
1115 next_sym
= stack
->next
? stack
->next
->sym
: last_sym
;
1118 prop
= stack
->sym
->prop
;
1120 /* for choice values find the menu entry (used below) */
1121 if (sym_is_choice(sym
) || sym_is_choice_value(sym
)) {
1122 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
1128 if (stack
->sym
== last_sym
)
1129 fprintf(stderr
, "%s:%d:error: recursive dependency detected!\n",
1130 prop
->file
->name
, prop
->lineno
);
1132 fprintf(stderr
, "%s:%d:\tsymbol %s %s value contains %s\n",
1133 prop
->file
->name
, prop
->lineno
,
1134 sym
->name
? sym
->name
: "<choice>",
1135 prop_get_type_name(prop
->type
),
1136 next_sym
->name
? next_sym
->name
: "<choice>");
1137 } else if (stack
->prop
) {
1138 fprintf(stderr
, "%s:%d:\tsymbol %s depends on %s\n",
1139 prop
->file
->name
, prop
->lineno
,
1140 sym
->name
? sym
->name
: "<choice>",
1141 next_sym
->name
? next_sym
->name
: "<choice>");
1142 } else if (sym_is_choice(sym
)) {
1143 fprintf(stderr
, "%s:%d:\tchoice %s contains symbol %s\n",
1144 menu
->file
->name
, menu
->lineno
,
1145 sym
->name
? sym
->name
: "<choice>",
1146 next_sym
->name
? next_sym
->name
: "<choice>");
1147 } else if (sym_is_choice_value(sym
)) {
1148 fprintf(stderr
, "%s:%d:\tsymbol %s is part of choice %s\n",
1149 menu
->file
->name
, menu
->lineno
,
1150 sym
->name
? sym
->name
: "<choice>",
1151 next_sym
->name
? next_sym
->name
: "<choice>");
1153 fprintf(stderr
, "%s:%d:\tsymbol %s is selected by %s\n",
1154 prop
->file
->name
, prop
->lineno
,
1155 sym
->name
? sym
->name
: "<choice>",
1156 next_sym
->name
? next_sym
->name
: "<choice>");
1160 if (check_top
== &cv_stack
)
1164 static struct symbol
*sym_check_expr_deps(struct expr
*e
)
1173 sym
= sym_check_expr_deps(e
->left
.expr
);
1176 return sym_check_expr_deps(e
->right
.expr
);
1178 return sym_check_expr_deps(e
->left
.expr
);
1181 sym
= sym_check_deps(e
->left
.sym
);
1184 return sym_check_deps(e
->right
.sym
);
1186 return sym_check_deps(e
->left
.sym
);
1190 printf("Oops! How to check %d?\n", e
->type
);
1194 /* return NULL when dependencies are OK */
1195 static struct symbol
*sym_check_sym_deps(struct symbol
*sym
)
1197 struct symbol
*sym2
;
1198 struct property
*prop
;
1199 struct dep_stack stack
;
1201 dep_stack_insert(&stack
, sym
);
1203 sym2
= sym_check_expr_deps(sym
->rev_dep
.expr
);
1207 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
1208 if (prop
->type
== P_CHOICE
|| prop
->type
== P_SELECT
)
1211 sym2
= sym_check_expr_deps(prop
->visible
.expr
);
1214 if (prop
->type
!= P_DEFAULT
|| sym_is_choice(sym
))
1216 stack
.expr
= prop
->expr
;
1217 sym2
= sym_check_expr_deps(prop
->expr
);
1229 static struct symbol
*sym_check_choice_deps(struct symbol
*choice
)
1231 struct symbol
*sym
, *sym2
;
1232 struct property
*prop
;
1234 struct dep_stack stack
;
1236 dep_stack_insert(&stack
, choice
);
1238 prop
= sym_get_choice_prop(choice
);
1239 expr_list_for_each_sym(prop
->expr
, e
, sym
)
1240 sym
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1242 choice
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1243 sym2
= sym_check_sym_deps(choice
);
1244 choice
->flags
&= ~SYMBOL_CHECK
;
1248 expr_list_for_each_sym(prop
->expr
, e
, sym
) {
1249 sym2
= sym_check_sym_deps(sym
);
1254 expr_list_for_each_sym(prop
->expr
, e
, sym
)
1255 sym
->flags
&= ~SYMBOL_CHECK
;
1257 if (sym2
&& sym_is_choice_value(sym2
) &&
1258 prop_get_symbol(sym_get_choice_prop(sym2
)) == choice
)
1266 struct symbol
*sym_check_deps(struct symbol
*sym
)
1268 struct symbol
*sym2
;
1269 struct property
*prop
;
1271 if (sym
->flags
& SYMBOL_CHECK
) {
1272 sym_check_print_recursive(sym
);
1275 if (sym
->flags
& SYMBOL_CHECKED
)
1278 if (sym_is_choice_value(sym
)) {
1279 struct dep_stack stack
;
1281 /* for choice groups start the check with main choice symbol */
1282 dep_stack_insert(&stack
, sym
);
1283 prop
= sym_get_choice_prop(sym
);
1284 sym2
= sym_check_deps(prop_get_symbol(prop
));
1286 } else if (sym_is_choice(sym
)) {
1287 sym2
= sym_check_choice_deps(sym
);
1289 sym
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1290 sym2
= sym_check_sym_deps(sym
);
1291 sym
->flags
&= ~SYMBOL_CHECK
;
1294 if (sym2
&& sym2
== sym
)
1300 struct property
*prop_alloc(enum prop_type type
, struct symbol
*sym
)
1302 struct property
*prop
;
1303 struct property
**propp
;
1305 prop
= xmalloc(sizeof(*prop
));
1306 memset(prop
, 0, sizeof(*prop
));
1309 prop
->file
= current_file
;
1310 prop
->lineno
= zconf_lineno();
1312 /* append property to the prop list of symbol */
1314 for (propp
= &sym
->prop
; *propp
; propp
= &(*propp
)->next
)
1322 struct symbol
*prop_get_symbol(struct property
*prop
)
1324 if (prop
->expr
&& (prop
->expr
->type
== E_SYMBOL
||
1325 prop
->expr
->type
== E_LIST
))
1326 return prop
->expr
->left
.sym
;
1330 const char *prop_get_type_name(enum prop_type type
)
1357 static void prop_add_env(const char *env
)
1359 struct symbol
*sym
, *sym2
;
1360 struct property
*prop
;
1363 sym
= current_entry
->sym
;
1364 sym
->flags
|= SYMBOL_AUTO
;
1365 for_all_properties(sym
, prop
, P_ENV
) {
1366 sym2
= prop_get_symbol(prop
);
1367 if (strcmp(sym2
->name
, env
))
1368 menu_warn(current_entry
, "redefining environment symbol from %s",
1373 prop
= prop_alloc(P_ENV
, sym
);
1374 prop
->expr
= expr_alloc_symbol(sym_lookup(env
, SYMBOL_CONST
));
1376 sym_env_list
= expr_alloc_one(E_LIST
, sym_env_list
);
1377 sym_env_list
->right
.sym
= sym
;
1381 sym_add_default(sym
, p
);
1383 menu_warn(current_entry
, "environment variable %s undefined", env
);