Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / scripts / kconfig / symbol.c
blobeff19ec8de98b837faa036dbfd1321d62f7037ac
1 /*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */
6 #include <ctype.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <regex.h>
10 #include <sys/utsname.h>
12 #define LKC_DIRECT_LINK
13 #include "lkc.h"
15 struct symbol symbol_yes = {
16 .name = "y",
17 .curr = { "y", yes },
18 .flags = SYMBOL_CONST|SYMBOL_VALID,
19 }, symbol_mod = {
20 .name = "m",
21 .curr = { "m", mod },
22 .flags = SYMBOL_CONST|SYMBOL_VALID,
23 }, symbol_no = {
24 .name = "n",
25 .curr = { "n", no },
26 .flags = SYMBOL_CONST|SYMBOL_VALID,
27 }, symbol_empty = {
28 .name = "",
29 .curr = { "", no },
30 .flags = SYMBOL_VALID,
33 struct symbol *sym_defconfig_list;
34 struct symbol *modules_sym;
35 tristate modules_val;
37 struct expr *sym_env_list;
39 void sym_add_default(struct symbol *sym, const char *def)
41 struct property *prop = prop_alloc(P_DEFAULT, sym);
43 prop->expr = expr_alloc_symbol(sym_lookup(def, 1));
46 void sym_init(void)
48 struct symbol *sym;
49 struct utsname uts;
50 static bool inited = false;
52 if (inited)
53 return;
54 inited = true;
56 uname(&uts);
58 sym = sym_lookup("UNAME_RELEASE", 0);
59 sym->type = S_STRING;
60 sym->flags |= SYMBOL_AUTO;
61 sym_add_default(sym, uts.release);
64 enum symbol_type sym_get_type(struct symbol *sym)
66 enum symbol_type type = sym->type;
68 if (type == S_TRISTATE) {
69 if (sym_is_choice_value(sym) && sym->visible == yes)
70 type = S_BOOLEAN;
71 else if (modules_val == no)
72 type = S_BOOLEAN;
74 return type;
77 const char *sym_type_name(enum symbol_type type)
79 switch (type) {
80 case S_BOOLEAN:
81 return "boolean";
82 case S_TRISTATE:
83 return "tristate";
84 case S_INT:
85 return "integer";
86 case S_HEX:
87 return "hex";
88 case S_STRING:
89 return "string";
90 case S_UNKNOWN:
91 return "unknown";
92 case S_OTHER:
93 break;
95 return "???";
98 struct property *sym_get_choice_prop(struct symbol *sym)
100 struct property *prop;
102 for_all_choices(sym, prop)
103 return prop;
104 return NULL;
107 struct property *sym_get_env_prop(struct symbol *sym)
109 struct property *prop;
111 for_all_properties(sym, prop, P_ENV)
112 return prop;
113 return NULL;
116 struct property *sym_get_default_prop(struct symbol *sym)
118 struct property *prop;
120 for_all_defaults(sym, prop) {
121 prop->visible.tri = expr_calc_value(prop->visible.expr);
122 if (prop->visible.tri != no)
123 return prop;
125 return NULL;
128 struct property *sym_get_range_prop(struct symbol *sym)
130 struct property *prop;
132 for_all_properties(sym, prop, P_RANGE) {
133 prop->visible.tri = expr_calc_value(prop->visible.expr);
134 if (prop->visible.tri != no)
135 return prop;
137 return NULL;
140 static int sym_get_range_val(struct symbol *sym, int base)
142 sym_calc_value(sym);
143 switch (sym->type) {
144 case S_INT:
145 base = 10;
146 break;
147 case S_HEX:
148 base = 16;
149 break;
150 default:
151 break;
153 return strtol(sym->curr.val, NULL, base);
156 static void sym_validate_range(struct symbol *sym)
158 struct property *prop;
159 int base, val, val2;
160 char str[64];
162 switch (sym->type) {
163 case S_INT:
164 base = 10;
165 break;
166 case S_HEX:
167 base = 16;
168 break;
169 default:
170 return;
172 prop = sym_get_range_prop(sym);
173 if (!prop)
174 return;
175 val = strtol(sym->curr.val, NULL, base);
176 val2 = sym_get_range_val(prop->expr->left.sym, base);
177 if (val >= val2) {
178 val2 = sym_get_range_val(prop->expr->right.sym, base);
179 if (val <= val2)
180 return;
182 if (sym->type == S_INT)
183 sprintf(str, "%d", val2);
184 else
185 sprintf(str, "0x%x", val2);
186 sym->curr.val = strdup(str);
189 static void sym_calc_visibility(struct symbol *sym)
191 struct property *prop;
192 tristate tri;
194 /* any prompt visible? */
195 tri = no;
196 for_all_prompts(sym, prop) {
197 prop->visible.tri = expr_calc_value(prop->visible.expr);
198 tri = EXPR_OR(tri, prop->visible.tri);
200 if (tri == mod && (sym->type != S_TRISTATE || modules_val == no))
201 tri = yes;
202 if (sym->visible != tri) {
203 sym->visible = tri;
204 sym_set_changed(sym);
206 if (sym_is_choice_value(sym))
207 return;
208 tri = no;
209 if (sym->rev_dep.expr)
210 tri = expr_calc_value(sym->rev_dep.expr);
211 if (tri == mod && sym_get_type(sym) == S_BOOLEAN)
212 tri = yes;
213 if (sym->rev_dep.tri != tri) {
214 sym->rev_dep.tri = tri;
215 sym_set_changed(sym);
219 static struct symbol *sym_calc_choice(struct symbol *sym)
221 struct symbol *def_sym;
222 struct property *prop;
223 struct expr *e;
225 /* is the user choice visible? */
226 def_sym = sym->def[S_DEF_USER].val;
227 if (def_sym) {
228 sym_calc_visibility(def_sym);
229 if (def_sym->visible != no)
230 return def_sym;
233 /* any of the defaults visible? */
234 for_all_defaults(sym, prop) {
235 prop->visible.tri = expr_calc_value(prop->visible.expr);
236 if (prop->visible.tri == no)
237 continue;
238 def_sym = prop_get_symbol(prop);
239 sym_calc_visibility(def_sym);
240 if (def_sym->visible != no)
241 return def_sym;
244 /* just get the first visible value */
245 prop = sym_get_choice_prop(sym);
246 expr_list_for_each_sym(prop->expr, e, def_sym) {
247 sym_calc_visibility(def_sym);
248 if (def_sym->visible != no)
249 return def_sym;
252 /* no choice? reset tristate value */
253 sym->curr.tri = no;
254 return NULL;
257 void sym_calc_value(struct symbol *sym)
259 struct symbol_value newval, oldval;
260 struct property *prop;
261 struct expr *e;
263 if (!sym)
264 return;
266 if (sym->flags & SYMBOL_VALID)
267 return;
268 sym->flags |= SYMBOL_VALID;
270 oldval = sym->curr;
272 switch (sym->type) {
273 case S_INT:
274 case S_HEX:
275 case S_STRING:
276 newval = symbol_empty.curr;
277 break;
278 case S_BOOLEAN:
279 case S_TRISTATE:
280 newval = symbol_no.curr;
281 break;
282 default:
283 sym->curr.val = sym->name;
284 sym->curr.tri = no;
285 return;
287 if (!sym_is_choice_value(sym))
288 sym->flags &= ~SYMBOL_WRITE;
290 sym_calc_visibility(sym);
292 /* set default if recursively called */
293 sym->curr = newval;
295 switch (sym_get_type(sym)) {
296 case S_BOOLEAN:
297 case S_TRISTATE:
298 if (sym_is_choice_value(sym) && sym->visible == yes) {
299 prop = sym_get_choice_prop(sym);
300 newval.tri = (prop_get_symbol(prop)->curr.val == sym) ? yes : no;
301 <<<<<<< HEAD:scripts/kconfig/symbol.c
302 } else if (EXPR_OR(sym->visible, sym->rev_dep.tri) != no) {
303 sym->flags |= SYMBOL_WRITE;
304 if (sym_has_value(sym))
305 newval.tri = sym->def[S_DEF_USER].tri;
306 else if (!sym_is_choice(sym)) {
307 prop = sym_get_default_prop(sym);
308 if (prop)
309 newval.tri = expr_calc_value(prop->expr);
310 =======
311 } else {
312 if (sym->visible != no) {
313 /* if the symbol is visible use the user value
314 * if available, otherwise try the default value
316 sym->flags |= SYMBOL_WRITE;
317 if (sym_has_value(sym)) {
318 newval.tri = EXPR_AND(sym->def[S_DEF_USER].tri,
319 sym->visible);
320 goto calc_newval;
322 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:scripts/kconfig/symbol.c
324 <<<<<<< HEAD:scripts/kconfig/symbol.c
325 newval.tri = EXPR_OR(EXPR_AND(newval.tri, sym->visible), sym->rev_dep.tri);
326 } else if (!sym_is_choice(sym)) {
327 prop = sym_get_default_prop(sym);
328 if (prop) {
329 =======
330 if (sym->rev_dep.tri != no)
331 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:scripts/kconfig/symbol.c
332 sym->flags |= SYMBOL_WRITE;
333 <<<<<<< HEAD:scripts/kconfig/symbol.c
334 newval.tri = expr_calc_value(prop->expr);
335 =======
336 if (!sym_is_choice(sym)) {
337 prop = sym_get_default_prop(sym);
338 if (prop) {
339 sym->flags |= SYMBOL_WRITE;
340 newval.tri = EXPR_AND(expr_calc_value(prop->expr),
341 prop->visible.tri);
343 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:scripts/kconfig/symbol.c
345 <<<<<<< HEAD:scripts/kconfig/symbol.c
346 =======
347 calc_newval:
348 newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri);
349 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:scripts/kconfig/symbol.c
351 if (newval.tri == mod && sym_get_type(sym) == S_BOOLEAN)
352 newval.tri = yes;
353 break;
354 case S_STRING:
355 case S_HEX:
356 case S_INT:
357 if (sym->visible != no) {
358 sym->flags |= SYMBOL_WRITE;
359 if (sym_has_value(sym)) {
360 newval.val = sym->def[S_DEF_USER].val;
361 break;
364 prop = sym_get_default_prop(sym);
365 if (prop) {
366 struct symbol *ds = prop_get_symbol(prop);
367 if (ds) {
368 sym->flags |= SYMBOL_WRITE;
369 sym_calc_value(ds);
370 newval.val = ds->curr.val;
373 break;
374 default:
378 if (sym->flags & SYMBOL_AUTO)
379 sym->flags &= ~SYMBOL_WRITE;
381 sym->curr = newval;
382 if (sym_is_choice(sym) && newval.tri == yes)
383 sym->curr.val = sym_calc_choice(sym);
384 sym_validate_range(sym);
386 if (memcmp(&oldval, &sym->curr, sizeof(oldval))) {
387 sym_set_changed(sym);
388 if (modules_sym == sym) {
389 sym_set_all_changed();
390 modules_val = modules_sym->curr.tri;
394 if (sym_is_choice(sym)) {
395 struct symbol *choice_sym;
396 int flags = sym->flags & (SYMBOL_CHANGED | SYMBOL_WRITE);
398 prop = sym_get_choice_prop(sym);
399 expr_list_for_each_sym(prop->expr, e, choice_sym) {
400 choice_sym->flags |= flags;
401 if (flags & SYMBOL_CHANGED)
402 sym_set_changed(choice_sym);
407 void sym_clear_all_valid(void)
409 struct symbol *sym;
410 int i;
412 for_all_symbols(i, sym)
413 sym->flags &= ~SYMBOL_VALID;
414 sym_add_change_count(1);
415 if (modules_sym)
416 sym_calc_value(modules_sym);
419 void sym_set_changed(struct symbol *sym)
421 struct property *prop;
423 sym->flags |= SYMBOL_CHANGED;
424 for (prop = sym->prop; prop; prop = prop->next) {
425 if (prop->menu)
426 prop->menu->flags |= MENU_CHANGED;
430 void sym_set_all_changed(void)
432 struct symbol *sym;
433 int i;
435 for_all_symbols(i, sym)
436 sym_set_changed(sym);
439 bool sym_tristate_within_range(struct symbol *sym, tristate val)
441 int type = sym_get_type(sym);
443 if (sym->visible == no)
444 return false;
446 if (type != S_BOOLEAN && type != S_TRISTATE)
447 return false;
449 if (type == S_BOOLEAN && val == mod)
450 return false;
451 if (sym->visible <= sym->rev_dep.tri)
452 return false;
453 if (sym_is_choice_value(sym) && sym->visible == yes)
454 return val == yes;
455 return val >= sym->rev_dep.tri && val <= sym->visible;
458 bool sym_set_tristate_value(struct symbol *sym, tristate val)
460 tristate oldval = sym_get_tristate_value(sym);
462 if (oldval != val && !sym_tristate_within_range(sym, val))
463 return false;
465 if (!(sym->flags & SYMBOL_DEF_USER)) {
466 sym->flags |= SYMBOL_DEF_USER;
467 sym_set_changed(sym);
470 * setting a choice value also resets the new flag of the choice
471 * symbol and all other choice values.
473 if (sym_is_choice_value(sym) && val == yes) {
474 struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));
475 struct property *prop;
476 struct expr *e;
478 cs->def[S_DEF_USER].val = sym;
479 cs->flags |= SYMBOL_DEF_USER;
480 prop = sym_get_choice_prop(cs);
481 for (e = prop->expr; e; e = e->left.expr) {
482 if (e->right.sym->visible != no)
483 e->right.sym->flags |= SYMBOL_DEF_USER;
487 sym->def[S_DEF_USER].tri = val;
488 if (oldval != val)
489 sym_clear_all_valid();
491 return true;
494 tristate sym_toggle_tristate_value(struct symbol *sym)
496 tristate oldval, newval;
498 oldval = newval = sym_get_tristate_value(sym);
499 do {
500 switch (newval) {
501 case no:
502 newval = mod;
503 break;
504 case mod:
505 newval = yes;
506 break;
507 case yes:
508 newval = no;
509 break;
511 if (sym_set_tristate_value(sym, newval))
512 break;
513 } while (oldval != newval);
514 return newval;
517 bool sym_string_valid(struct symbol *sym, const char *str)
519 signed char ch;
521 switch (sym->type) {
522 case S_STRING:
523 return true;
524 case S_INT:
525 ch = *str++;
526 if (ch == '-')
527 ch = *str++;
528 if (!isdigit(ch))
529 return false;
530 if (ch == '0' && *str != 0)
531 return false;
532 while ((ch = *str++)) {
533 if (!isdigit(ch))
534 return false;
536 return true;
537 case S_HEX:
538 if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
539 str += 2;
540 ch = *str++;
541 do {
542 if (!isxdigit(ch))
543 return false;
544 } while ((ch = *str++));
545 return true;
546 case S_BOOLEAN:
547 case S_TRISTATE:
548 switch (str[0]) {
549 case 'y': case 'Y':
550 case 'm': case 'M':
551 case 'n': case 'N':
552 return true;
554 return false;
555 default:
556 return false;
560 bool sym_string_within_range(struct symbol *sym, const char *str)
562 struct property *prop;
563 int val;
565 switch (sym->type) {
566 case S_STRING:
567 return sym_string_valid(sym, str);
568 case S_INT:
569 if (!sym_string_valid(sym, str))
570 return false;
571 prop = sym_get_range_prop(sym);
572 if (!prop)
573 return true;
574 val = strtol(str, NULL, 10);
575 return val >= sym_get_range_val(prop->expr->left.sym, 10) &&
576 val <= sym_get_range_val(prop->expr->right.sym, 10);
577 case S_HEX:
578 if (!sym_string_valid(sym, str))
579 return false;
580 prop = sym_get_range_prop(sym);
581 if (!prop)
582 return true;
583 val = strtol(str, NULL, 16);
584 return val >= sym_get_range_val(prop->expr->left.sym, 16) &&
585 val <= sym_get_range_val(prop->expr->right.sym, 16);
586 case S_BOOLEAN:
587 case S_TRISTATE:
588 switch (str[0]) {
589 case 'y': case 'Y':
590 return sym_tristate_within_range(sym, yes);
591 case 'm': case 'M':
592 return sym_tristate_within_range(sym, mod);
593 case 'n': case 'N':
594 return sym_tristate_within_range(sym, no);
596 return false;
597 default:
598 return false;
602 bool sym_set_string_value(struct symbol *sym, const char *newval)
604 const char *oldval;
605 char *val;
606 int size;
608 switch (sym->type) {
609 case S_BOOLEAN:
610 case S_TRISTATE:
611 switch (newval[0]) {
612 case 'y': case 'Y':
613 return sym_set_tristate_value(sym, yes);
614 case 'm': case 'M':
615 return sym_set_tristate_value(sym, mod);
616 case 'n': case 'N':
617 return sym_set_tristate_value(sym, no);
619 return false;
620 default:
624 if (!sym_string_within_range(sym, newval))
625 return false;
627 if (!(sym->flags & SYMBOL_DEF_USER)) {
628 sym->flags |= SYMBOL_DEF_USER;
629 sym_set_changed(sym);
632 oldval = sym->def[S_DEF_USER].val;
633 size = strlen(newval) + 1;
634 if (sym->type == S_HEX && (newval[0] != '0' || (newval[1] != 'x' && newval[1] != 'X'))) {
635 size += 2;
636 sym->def[S_DEF_USER].val = val = malloc(size);
637 *val++ = '0';
638 *val++ = 'x';
639 } else if (!oldval || strcmp(oldval, newval))
640 sym->def[S_DEF_USER].val = val = malloc(size);
641 else
642 return true;
644 strcpy(val, newval);
645 free((void *)oldval);
646 sym_clear_all_valid();
648 return true;
651 const char *sym_get_string_value(struct symbol *sym)
653 tristate val;
655 switch (sym->type) {
656 case S_BOOLEAN:
657 case S_TRISTATE:
658 val = sym_get_tristate_value(sym);
659 switch (val) {
660 case no:
661 return "n";
662 case mod:
663 return "m";
664 case yes:
665 return "y";
667 break;
668 default:
671 return (const char *)sym->curr.val;
674 bool sym_is_changable(struct symbol *sym)
676 return sym->visible > sym->rev_dep.tri;
679 struct symbol *sym_lookup(const char *name, int isconst)
681 struct symbol *symbol;
682 const char *ptr;
683 char *new_name;
684 int hash = 0;
686 if (name) {
687 if (name[0] && !name[1]) {
688 switch (name[0]) {
689 case 'y': return &symbol_yes;
690 case 'm': return &symbol_mod;
691 case 'n': return &symbol_no;
694 for (ptr = name; *ptr; ptr++)
695 hash += *ptr;
696 hash &= 0xff;
698 for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) {
699 if (!strcmp(symbol->name, name)) {
700 if ((isconst && symbol->flags & SYMBOL_CONST) ||
701 (!isconst && !(symbol->flags & SYMBOL_CONST)))
702 return symbol;
705 new_name = strdup(name);
706 } else {
707 new_name = NULL;
708 hash = 256;
711 symbol = malloc(sizeof(*symbol));
712 memset(symbol, 0, sizeof(*symbol));
713 symbol->name = new_name;
714 symbol->type = S_UNKNOWN;
715 if (isconst)
716 symbol->flags |= SYMBOL_CONST;
718 symbol->next = symbol_hash[hash];
719 symbol_hash[hash] = symbol;
721 return symbol;
724 struct symbol *sym_find(const char *name)
726 struct symbol *symbol = NULL;
727 const char *ptr;
728 int hash = 0;
730 if (!name)
731 return NULL;
733 if (name[0] && !name[1]) {
734 switch (name[0]) {
735 case 'y': return &symbol_yes;
736 case 'm': return &symbol_mod;
737 case 'n': return &symbol_no;
740 for (ptr = name; *ptr; ptr++)
741 hash += *ptr;
742 hash &= 0xff;
744 for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) {
745 if (!strcmp(symbol->name, name) &&
746 !(symbol->flags & SYMBOL_CONST))
747 break;
750 return symbol;
753 struct symbol **sym_re_search(const char *pattern)
755 struct symbol *sym, **sym_arr = NULL;
756 int i, cnt, size;
757 regex_t re;
759 cnt = size = 0;
760 /* Skip if empty */
761 if (strlen(pattern) == 0)
762 return NULL;
763 if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB|REG_ICASE))
764 return NULL;
766 for_all_symbols(i, sym) {
767 if (sym->flags & SYMBOL_CONST || !sym->name)
768 continue;
769 if (regexec(&re, sym->name, 0, NULL, 0))
770 continue;
771 if (cnt + 1 >= size) {
772 void *tmp = sym_arr;
773 size += 16;
774 sym_arr = realloc(sym_arr, size * sizeof(struct symbol *));
775 if (!sym_arr) {
776 free(tmp);
777 return NULL;
780 sym_arr[cnt++] = sym;
782 if (sym_arr)
783 sym_arr[cnt] = NULL;
784 regfree(&re);
786 return sym_arr;
790 struct symbol *sym_check_deps(struct symbol *sym);
792 static struct symbol *sym_check_expr_deps(struct expr *e)
794 struct symbol *sym;
796 if (!e)
797 return NULL;
798 switch (e->type) {
799 case E_OR:
800 case E_AND:
801 sym = sym_check_expr_deps(e->left.expr);
802 if (sym)
803 return sym;
804 return sym_check_expr_deps(e->right.expr);
805 case E_NOT:
806 return sym_check_expr_deps(e->left.expr);
807 case E_EQUAL:
808 case E_UNEQUAL:
809 sym = sym_check_deps(e->left.sym);
810 if (sym)
811 return sym;
812 return sym_check_deps(e->right.sym);
813 case E_SYMBOL:
814 return sym_check_deps(e->left.sym);
815 default:
816 break;
818 printf("Oops! How to check %d?\n", e->type);
819 return NULL;
822 /* return NULL when dependencies are OK */
823 struct symbol *sym_check_deps(struct symbol *sym)
825 struct symbol *sym2;
826 struct property *prop;
828 if (sym->flags & SYMBOL_CHECK) {
829 fprintf(stderr, "%s:%d:error: found recursive dependency: %s",
830 sym->prop->file->name, sym->prop->lineno, sym->name);
831 return sym;
833 if (sym->flags & SYMBOL_CHECKED)
834 return NULL;
836 sym->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED);
837 sym2 = sym_check_expr_deps(sym->rev_dep.expr);
838 if (sym2)
839 goto out;
841 for (prop = sym->prop; prop; prop = prop->next) {
842 if (prop->type == P_CHOICE || prop->type == P_SELECT)
843 continue;
844 sym2 = sym_check_expr_deps(prop->visible.expr);
845 if (sym2)
846 goto out;
847 if (prop->type != P_DEFAULT || sym_is_choice(sym))
848 continue;
849 sym2 = sym_check_expr_deps(prop->expr);
850 if (sym2)
851 goto out;
853 out:
854 if (sym2)
855 fprintf(stderr, " -> %s%s", sym->name, sym2 == sym? "\n": "");
856 sym->flags &= ~SYMBOL_CHECK;
857 return sym2;
860 struct property *prop_alloc(enum prop_type type, struct symbol *sym)
862 struct property *prop;
863 struct property **propp;
865 prop = malloc(sizeof(*prop));
866 memset(prop, 0, sizeof(*prop));
867 prop->type = type;
868 prop->sym = sym;
869 prop->file = current_file;
870 prop->lineno = zconf_lineno();
872 /* append property to the prop list of symbol */
873 if (sym) {
874 for (propp = &sym->prop; *propp; propp = &(*propp)->next)
876 *propp = prop;
879 return prop;
882 struct symbol *prop_get_symbol(struct property *prop)
884 if (prop->expr && (prop->expr->type == E_SYMBOL ||
885 prop->expr->type == E_LIST))
886 return prop->expr->left.sym;
887 return NULL;
890 const char *prop_get_type_name(enum prop_type type)
892 switch (type) {
893 case P_PROMPT:
894 return "prompt";
895 case P_ENV:
896 return "env";
897 case P_COMMENT:
898 return "comment";
899 case P_MENU:
900 return "menu";
901 case P_DEFAULT:
902 return "default";
903 case P_CHOICE:
904 return "choice";
905 case P_SELECT:
906 return "select";
907 case P_RANGE:
908 return "range";
909 case P_UNKNOWN:
910 break;
912 return "unknown";
915 void prop_add_env(const char *env)
917 struct symbol *sym, *sym2;
918 struct property *prop;
919 char *p;
921 sym = current_entry->sym;
922 sym->flags |= SYMBOL_AUTO;
923 for_all_properties(sym, prop, P_ENV) {
924 sym2 = prop_get_symbol(prop);
925 if (strcmp(sym2->name, env))
926 menu_warn(current_entry, "redefining environment symbol from %s",
927 sym2->name);
928 return;
931 prop = prop_alloc(P_ENV, sym);
932 prop->expr = expr_alloc_symbol(sym_lookup(env, 1));
934 sym_env_list = expr_alloc_one(E_LIST, sym_env_list);
935 sym_env_list->right.sym = sym;
937 p = getenv(env);
938 if (p)
939 sym_add_default(sym, p);
940 else
941 menu_warn(current_entry, "environment variable %s undefined", env);