2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
20 static void conf_warning(const char *fmt
, ...)
21 __attribute__ ((format (printf
, 1, 2)));
23 static void conf_message(const char *fmt
, ...)
24 __attribute__ ((format (printf
, 1, 2)));
26 static const char *conf_filename
;
27 static int conf_lineno
, conf_warnings
, conf_unsaved
;
29 const char conf_defname
[] = ".defconfig";
31 static void conf_warning(const char *fmt
, ...)
35 fprintf(stderr
, "%s:%d:warning: ", conf_filename
, conf_lineno
);
36 vfprintf(stderr
, fmt
, ap
);
37 fprintf(stderr
, "\n");
42 static void conf_default_message_callback(const char *fmt
, va_list ap
)
49 static void (*conf_message_callback
) (const char *fmt
, va_list ap
) =
50 conf_default_message_callback
;
51 void conf_set_message_callback(void (*fn
) (const char *fmt
, va_list ap
))
53 conf_message_callback
= fn
;
56 static void conf_message(const char *fmt
, ...)
61 if (conf_message_callback
)
62 conf_message_callback(fmt
, ap
);
65 const char *conf_get_configname(void)
67 char *name
= getenv("BR2_CONFIG");
69 return name
? name
: ".config";
72 const char *conf_get_autoconfig_name(void)
74 return getenv("KCONFIG_AUTOCONFIG");
77 static char *conf_expand_value(const char *in
)
81 static char res_value
[SYMBOL_MAXLENGTH
];
82 char *dst
, name
[SYMBOL_MAXLENGTH
];
86 while ((src
= strchr(in
, '$'))) {
87 strncat(res_value
, in
, src
- in
);
90 while (isalnum(*src
) || *src
== '_')
93 sym
= sym_lookup(name
, 0);
95 strcat(res_value
, sym_get_string_value(sym
));
98 strcat(res_value
, in
);
103 char *conf_get_default_confname(void)
106 static char fullname
[PATH_MAX
+1];
109 name
= conf_expand_value(conf_defname
);
110 env
= getenv(SRCTREE
);
112 sprintf(fullname
, "%s/%s", env
, name
);
113 if (!stat(fullname
, &buf
))
119 static int conf_set_sym_val(struct symbol
*sym
, int def
, int def_flags
, char *p
)
126 sym
->def
[def
].tri
= mod
;
127 sym
->flags
|= def_flags
;
133 sym
->def
[def
].tri
= yes
;
134 sym
->flags
|= def_flags
;
138 sym
->def
[def
].tri
= no
;
139 sym
->flags
|= def_flags
;
142 if (def
!= S_DEF_AUTO
)
143 conf_warning("symbol value '%s' invalid for %s",
148 for (p2
= p
; *p2
&& !isspace(*p2
); p2
++)
150 sym
->type
= S_STRING
;
157 for (p2
= p
; (p2
= strpbrk(p2
, "\"\\")); p2
++) {
162 memmove(p2
, p2
+ 1, strlen(p2
));
165 if (def
!= S_DEF_AUTO
)
166 conf_warning("invalid string found");
173 if (sym_string_valid(sym
, p
)) {
174 sym
->def
[def
].val
= strdup(p
);
175 sym
->flags
|= def_flags
;
177 if (def
!= S_DEF_AUTO
)
178 conf_warning("symbol value '%s' invalid for %s",
189 #define LINE_GROWTH 16
190 static int add_byte(int c
, char **lineptr
, size_t slen
, size_t *n
)
193 size_t new_size
= slen
+ 1;
195 new_size
+= LINE_GROWTH
- 1;
197 nline
= realloc(*lineptr
, new_size
);
205 (*lineptr
)[slen
] = c
;
210 static ssize_t
compat_getline(char **lineptr
, size_t *n
, FILE *stream
)
212 char *line
= *lineptr
;
216 int c
= getc(stream
);
220 if (add_byte(c
, &line
, slen
, n
) < 0)
225 if (add_byte('\0', &line
, slen
, n
) < 0)
232 if (add_byte(c
, &line
, slen
, n
) < 0)
244 int conf_read_simple(const char *name
, int def
)
248 size_t line_asize
= 0;
254 in
= zconf_fopen(name
);
256 struct property
*prop
;
258 name
= conf_get_configname();
259 in
= zconf_fopen(name
);
262 sym_add_change_count(1);
263 if (!sym_defconfig_list
) {
265 sym_calc_value(modules_sym
);
269 for_all_defaults(sym_defconfig_list
, prop
) {
270 if (expr_calc_value(prop
->visible
.expr
) == no
||
271 prop
->expr
->type
!= E_SYMBOL
)
273 name
= conf_expand_value(prop
->expr
->left
.sym
->name
);
274 in
= zconf_fopen(name
);
276 conf_message(_("using defaults found in %s"),
286 conf_filename
= name
;
291 def_flags
= SYMBOL_DEF
<< def
;
292 for_all_symbols(i
, sym
) {
293 sym
->flags
|= SYMBOL_CHANGED
;
294 sym
->flags
&= ~(def_flags
|SYMBOL_VALID
);
295 if (sym_is_choice(sym
))
296 sym
->flags
|= def_flags
;
301 if (sym
->def
[def
].val
)
302 free(sym
->def
[def
].val
);
305 sym
->def
[def
].val
= NULL
;
306 sym
->def
[def
].tri
= no
;
310 while (compat_getline(&line
, &line_asize
, in
) != -1) {
313 if (line
[0] == '#') {
314 if (memcmp(line
+ 2, CONFIG_
, strlen(CONFIG_
)))
316 p
= strchr(line
+ 2 + strlen(CONFIG_
), ' ');
320 if (strncmp(p
, "is not set", 10))
322 if (def
== S_DEF_USER
) {
323 sym
= sym_find(line
+ 2 + strlen(CONFIG_
));
325 sym_add_change_count(1);
329 sym
= sym_lookup(line
+ 2 + strlen(CONFIG_
), 0);
330 if (sym
->type
== S_UNKNOWN
)
331 sym
->type
= S_BOOLEAN
;
333 if (sym
->flags
& def_flags
) {
334 conf_warning("override: reassigning to symbol %s", sym
->name
);
339 sym
->def
[def
].tri
= no
;
340 sym
->flags
|= def_flags
;
345 } else if (memcmp(line
, CONFIG_
, strlen(CONFIG_
)) == 0) {
346 p
= strchr(line
+ strlen(CONFIG_
), '=');
350 p2
= strchr(p
, '\n');
356 if (def
== S_DEF_USER
) {
357 sym
= sym_find(line
+ strlen(CONFIG_
));
359 sym_add_change_count(1);
363 sym
= sym_lookup(line
+ strlen(CONFIG_
), 0);
364 if (sym
->type
== S_UNKNOWN
)
367 if (sym
->flags
& def_flags
) {
368 conf_warning("override: reassigning to symbol %s", sym
->name
);
370 if (conf_set_sym_val(sym
, def
, def_flags
, p
))
373 if (line
[0] != '\r' && line
[0] != '\n')
374 conf_warning("unexpected data");
378 if (sym
&& sym_is_choice_value(sym
)) {
379 struct symbol
*cs
= prop_get_symbol(sym_get_choice_prop(sym
));
380 switch (sym
->def
[def
].tri
) {
384 if (cs
->def
[def
].tri
== yes
) {
385 conf_warning("%s creates inconsistent choice state", sym
->name
);
386 cs
->flags
&= ~def_flags
;
390 if (cs
->def
[def
].tri
!= no
)
391 conf_warning("override: %s changes choice state", sym
->name
);
392 cs
->def
[def
].val
= sym
;
395 cs
->def
[def
].tri
= EXPR_OR(cs
->def
[def
].tri
, sym
->def
[def
].tri
);
402 sym_calc_value(modules_sym
);
406 int conf_read(const char *name
)
411 sym_set_change_count(0);
413 if (conf_read_simple(name
, S_DEF_USER
))
416 for_all_symbols(i
, sym
) {
418 if (sym_is_choice(sym
) || (sym
->flags
& SYMBOL_AUTO
))
420 if (sym_has_value(sym
) && (sym
->flags
& SYMBOL_WRITE
)) {
421 /* check that calculated value agrees with saved value */
425 if (sym
->def
[S_DEF_USER
].tri
!= sym_get_tristate_value(sym
))
427 if (!sym_is_choice(sym
))
431 if (!strcmp(sym
->curr
.val
, sym
->def
[S_DEF_USER
].val
))
435 } else if (!sym_has_value(sym
) && !(sym
->flags
& SYMBOL_WRITE
))
436 /* no previous value and not saved */
439 /* maybe print value in verbose mode... */
442 for_all_symbols(i
, sym
) {
443 if (sym_has_value(sym
) && !sym_is_choice_value(sym
)) {
444 /* Reset values of generates values, so they'll appear
445 * as new, if they should become visible, but that
446 * doesn't quite work if the Kconfig and the saved
447 * configuration disagree.
449 if (sym
->visible
== no
&& !conf_unsaved
)
450 sym
->flags
&= ~SYMBOL_DEF_USER
;
455 /* Reset a string value if it's out of range */
456 if (sym_string_within_range(sym
, sym
->def
[S_DEF_USER
].val
))
458 sym
->flags
&= ~(SYMBOL_VALID
|SYMBOL_DEF_USER
);
467 sym_add_change_count(conf_warnings
|| conf_unsaved
);
473 * Kconfig configuration printer
475 * This printer is used when generating the resulting configuration after
476 * kconfig invocation and `defconfig' files. Unset symbol might be omitted by
477 * passing a non-NULL argument to the printer.
481 kconfig_print_symbol(FILE *fp
, struct symbol
*sym
, const char *value
, void *arg
)
488 bool skip_unset
= (arg
!= NULL
);
491 fprintf(fp
, "# %s%s is not set\n",
500 fprintf(fp
, "%s%s=%s\n", CONFIG_
, sym
->name
, value
);
504 kconfig_print_comment(FILE *fp
, const char *value
, void *arg
)
506 const char *p
= value
;
510 l
= strcspn(p
, "\n");
514 xfwrite(p
, l
, 1, fp
);
523 static struct conf_printer kconfig_printer_cb
=
525 .print_symbol
= kconfig_print_symbol
,
526 .print_comment
= kconfig_print_comment
,
532 * This printer is used when generating the `include/generated/autoconf.h' file.
535 header_print_symbol(FILE *fp
, struct symbol
*sym
, const char *value
, void *arg
)
541 const char *suffix
= "";
550 fprintf(fp
, "#define %s%s%s 1\n",
551 CONFIG_
, sym
->name
, suffix
);
556 const char *prefix
= "";
558 if (value
[0] != '0' || (value
[1] != 'x' && value
[1] != 'X'))
560 fprintf(fp
, "#define %s%s %s%s\n",
561 CONFIG_
, sym
->name
, prefix
, value
);
566 fprintf(fp
, "#define %s%s %s\n",
567 CONFIG_
, sym
->name
, value
);
576 header_print_comment(FILE *fp
, const char *value
, void *arg
)
578 const char *p
= value
;
583 l
= strcspn(p
, "\n");
587 xfwrite(p
, l
, 1, fp
);
594 fprintf(fp
, " */\n");
597 static struct conf_printer header_printer_cb
=
599 .print_symbol
= header_print_symbol
,
600 .print_comment
= header_print_comment
,
606 * This printer is used when generating the `include/config/tristate.conf' file.
609 tristate_print_symbol(FILE *fp
, struct symbol
*sym
, const char *value
, void *arg
)
612 if (sym
->type
== S_TRISTATE
&& *value
!= 'n')
613 fprintf(fp
, "%s%s=%c\n", CONFIG_
, sym
->name
, (char)toupper(*value
));
616 static struct conf_printer tristate_printer_cb
=
618 .print_symbol
= tristate_print_symbol
,
619 .print_comment
= kconfig_print_comment
,
622 static void conf_write_symbol(FILE *fp
, struct symbol
*sym
,
623 struct conf_printer
*printer
, void *printer_arg
)
632 str
= sym_get_string_value(sym
);
633 str
= sym_escape_string_value(str
);
634 printer
->print_symbol(fp
, sym
, str
, printer_arg
);
638 str
= sym_get_string_value(sym
);
639 printer
->print_symbol(fp
, sym
, str
, printer_arg
);
644 conf_write_heading(FILE *fp
, struct conf_printer
*printer
, void *printer_arg
)
648 snprintf(buf
, sizeof(buf
),
650 "Automatically generated file; DO NOT EDIT.\n"
652 rootmenu
.prompt
->text
);
654 printer
->print_comment(fp
, buf
, printer_arg
);
658 * Write out a minimal config.
659 * All values that has default values are skipped as this is redundant.
661 int conf_write_defconfig(const char *filename
)
667 out
= fopen(filename
, "w");
671 sym_clear_all_valid();
673 /* Traverse all menus to find all relevant symbols */
674 menu
= rootmenu
.list
;
680 if (!menu_is_visible(menu
))
682 } else if (!sym_is_choice(sym
)) {
684 if (!(sym
->flags
& SYMBOL_WRITE
))
686 sym
->flags
&= ~SYMBOL_WRITE
;
687 /* If we cannot change the symbol - skip */
688 if (!sym_is_changable(sym
))
690 /* If symbol equals to default value - skip */
691 if (strcmp(sym_get_string_value(sym
), sym_get_string_default(sym
)) == 0)
695 * If symbol is a choice value and equals to the
696 * default for a choice - skip.
697 * But only if value is bool and equal to "y" and
698 * choice is not "optional".
699 * (If choice is "optional" then all values can be "n")
701 if (sym_is_choice_value(sym
)) {
705 cs
= prop_get_symbol(sym_get_choice_prop(sym
));
706 ds
= sym_choice_default(cs
);
707 if (!sym_is_optional(cs
) && sym
== ds
) {
708 if ((sym
->type
== S_BOOLEAN
) &&
709 sym_get_tristate_value(sym
) == yes
)
713 conf_write_symbol(out
, sym
, &kconfig_printer_cb
, NULL
);
716 if (menu
->list
!= NULL
) {
719 else if (menu
->next
!= NULL
) {
722 while ((menu
= menu
->parent
)) {
723 if (menu
->next
!= NULL
) {
734 int conf_write(const char *name
)
739 const char *basename
;
741 char dirname
[PATH_MAX
+1], tmpname
[PATH_MAX
+1], newname
[PATH_MAX
+1];
745 name
= conf_get_configname();
748 if (name
&& name
[0]) {
752 if (!stat(name
, &st
) && S_ISDIR(st
.st_mode
)) {
753 strcpy(dirname
, name
);
754 strcat(dirname
, "/");
755 basename
= conf_get_configname();
756 } else if ((slash
= strrchr(name
, '/'))) {
757 int size
= slash
- name
+ 1;
758 memcpy(dirname
, name
, size
);
761 basename
= slash
+ 1;
763 basename
= conf_get_configname();
767 basename
= conf_get_configname();
769 sprintf(newname
, "%s%s", dirname
, basename
);
770 env
= getenv("KCONFIG_OVERWRITECONFIG");
772 sprintf(tmpname
, "%s.tmpconfig.%d", dirname
, (int)getpid());
773 out
= fopen(tmpname
, "w");
776 out
= fopen(newname
, "w");
781 conf_write_heading(out
, &kconfig_printer_cb
, NULL
);
783 if (!conf_get_changed())
784 sym_clear_all_valid();
786 menu
= rootmenu
.list
;
790 if (!menu_is_visible(menu
))
792 str
= menu_get_prompt(menu
);
797 } else if (!(sym
->flags
& SYMBOL_CHOICE
)) {
799 if (!(sym
->flags
& SYMBOL_WRITE
))
801 sym
->flags
&= ~SYMBOL_WRITE
;
803 conf_write_symbol(out
, sym
, &kconfig_printer_cb
, NULL
);
813 else while ((menu
= menu
->parent
)) {
823 strcat(dirname
, basename
);
824 strcat(dirname
, ".old");
825 rename(newname
, dirname
);
826 if (rename(tmpname
, newname
))
830 conf_message(_("configuration written to %s"), newname
);
832 sym_set_change_count(0);
837 static int conf_split_config(void)
840 char path
[PATH_MAX
+1];
841 char *opwd
, *dir
, *_name
;
847 name
= conf_get_autoconfig_name();
848 conf_read_simple(name
, S_DEF_AUTO
);
851 _name
= strdup(name
);
852 if (opwd
== NULL
|| _name
== NULL
)
854 opwd
= getcwd(opwd
, 256);
855 dir
= dirname(_name
);
866 for_all_symbols(i
, sym
) {
868 if ((sym
->flags
& SYMBOL_AUTO
) || !sym
->name
)
870 if (sym
->flags
& SYMBOL_WRITE
) {
871 if (sym
->flags
& SYMBOL_DEF_AUTO
) {
873 * symbol has old and new value,
879 if (sym_get_tristate_value(sym
) ==
880 sym
->def
[S_DEF_AUTO
].tri
)
886 if (!strcmp(sym_get_string_value(sym
),
887 sym
->def
[S_DEF_AUTO
].val
))
895 * If there is no old value, only 'no' (unset)
896 * is allowed as new value.
901 if (sym_get_tristate_value(sym
) == no
)
908 } else if (!(sym
->flags
& SYMBOL_DEF_AUTO
))
909 /* There is neither an old nor a new value. */
912 * There is an old value, but no new value ('no' (unset)
913 * isn't saved in auto.conf, so the old value is always
914 * different from 'no').
917 /* Replace all '_' and append ".h" */
922 *d
++ = (c
== '_') ? '/' : c
;
926 /* Assume directory path already exists. */
927 fd
= open(path
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0644);
929 if (errno
!= ENOENT
) {
934 * Create directory components,
935 * unless they exist already.
938 while ((d
= strchr(d
, '/'))) {
940 if (stat(path
, &sb
) && mkdir(path
, 0755)) {
947 fd
= open(path
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0644);
964 int conf_write_autoconf(void)
968 FILE *out
, *tristate
, *out_h
;
970 char dir
[PATH_MAX
+1], buf
[PATH_MAX
+1];
973 strcpy(dir
, conf_get_configname());
974 s
= strrchr(dir
, '/');
980 sym_clear_all_valid();
982 sprintf(buf
, "%s.config.cmd", dir
);
985 if (conf_split_config())
988 sprintf(buf
, "%s.tmpconfig", dir
);
989 out
= fopen(buf
, "w");
993 sprintf(buf
, "%s.tmpconfig_tristate", dir
);
994 tristate
= fopen(buf
, "w");
1000 sprintf(buf
, "%s.tmpconfig.h", dir
);
1001 out_h
= fopen(buf
, "w");
1008 conf_write_heading(out
, &kconfig_printer_cb
, NULL
);
1010 conf_write_heading(tristate
, &tristate_printer_cb
, NULL
);
1012 conf_write_heading(out_h
, &header_printer_cb
, NULL
);
1014 for_all_symbols(i
, sym
) {
1015 sym_calc_value(sym
);
1016 if (!(sym
->flags
& SYMBOL_WRITE
) || !sym
->name
)
1019 /* write symbol to auto.conf, tristate and header files */
1020 conf_write_symbol(out
, sym
, &kconfig_printer_cb
, (void *)1);
1022 conf_write_symbol(tristate
, sym
, &tristate_printer_cb
, (void *)1);
1024 conf_write_symbol(out_h
, sym
, &header_printer_cb
, NULL
);
1030 name
= getenv("KCONFIG_AUTOHEADER");
1032 name
= "include/generated/autoconf.h";
1033 sprintf(buf
, "%s.tmpconfig.h", dir
);
1034 if (rename(buf
, name
))
1036 name
= getenv("KCONFIG_TRISTATE");
1038 name
= "include/config/tristate.conf";
1039 sprintf(buf
, "%s.tmpconfig_tristate", dir
);
1040 if (rename(buf
, name
))
1042 name
= conf_get_autoconfig_name();
1044 * This must be the last step, kbuild has a dependency on auto.conf
1045 * and this marks the successful completion of the previous steps.
1047 sprintf(buf
, "%s.tmpconfig", dir
);
1048 if (rename(buf
, name
))
1054 static int sym_change_count
;
1055 static void (*conf_changed_callback
)(void);
1057 void sym_set_change_count(int count
)
1059 int _sym_change_count
= sym_change_count
;
1060 sym_change_count
= count
;
1061 if (conf_changed_callback
&&
1062 (bool)_sym_change_count
!= (bool)count
)
1063 conf_changed_callback();
1066 void sym_add_change_count(int count
)
1068 sym_set_change_count(count
+ sym_change_count
);
1071 bool conf_get_changed(void)
1073 return sym_change_count
;
1076 void conf_set_changed_callback(void (*fn
)(void))
1078 conf_changed_callback
= fn
;
1081 static bool randomize_choice_values(struct symbol
*csym
)
1083 struct property
*prop
;
1089 * If choice is mod then we may have more items selected
1090 * and if no then no-one.
1091 * In both cases stop.
1093 if (csym
->curr
.tri
!= yes
)
1096 prop
= sym_get_choice_prop(csym
);
1098 /* count entries in choice block */
1100 expr_list_for_each_sym(prop
->expr
, e
, sym
)
1104 * find a random value and set it to yes,
1105 * set the rest to no so we have only one set
1107 def
= (rand() % cnt
);
1110 expr_list_for_each_sym(prop
->expr
, e
, sym
) {
1112 sym
->def
[S_DEF_USER
].tri
= yes
;
1113 csym
->def
[S_DEF_USER
].val
= sym
;
1116 sym
->def
[S_DEF_USER
].tri
= no
;
1118 sym
->flags
|= SYMBOL_DEF_USER
;
1119 /* clear VALID to get value calculated */
1120 sym
->flags
&= ~SYMBOL_VALID
;
1122 csym
->flags
|= SYMBOL_DEF_USER
;
1123 /* clear VALID to get value calculated */
1124 csym
->flags
&= ~(SYMBOL_VALID
);
1129 void set_all_choice_values(struct symbol
*csym
)
1131 struct property
*prop
;
1135 prop
= sym_get_choice_prop(csym
);
1138 * Set all non-assinged choice values to no
1140 expr_list_for_each_sym(prop
->expr
, e
, sym
) {
1141 if (!sym_has_value(sym
))
1142 sym
->def
[S_DEF_USER
].tri
= no
;
1144 csym
->flags
|= SYMBOL_DEF_USER
;
1145 /* clear VALID to get value calculated */
1146 csym
->flags
&= ~(SYMBOL_VALID
| SYMBOL_NEED_SET_CHOICE_VALUES
);
1149 bool conf_set_all_new_symbols(enum conf_def_mode mode
)
1151 struct symbol
*sym
, *csym
;
1152 int i
, cnt
, pby
, pty
, ptm
; /* pby: probability of boolean = y
1153 * pty: probability of tristate = y
1154 * ptm: probability of tristate = m
1157 pby
= 50; pty
= ptm
= 33; /* can't go as the default in switch-case
1158 * below, otherwise gcc whines about
1159 * -Wmaybe-uninitialized */
1160 if (mode
== def_random
) {
1162 char *env
= getenv("KCONFIG_PROBABILITY");
1164 while( env
&& *env
) {
1166 int tmp
= strtol( env
, &endp
, 10 );
1167 if( tmp
>= 0 && tmp
<= 100 ) {
1171 perror( "KCONFIG_PROBABILITY" );
1174 env
= (*endp
== ':') ? endp
+1 : endp
;
1181 pby
= p
[0]; ptm
= pby
/2; pty
= pby
-ptm
;
1184 pty
= p
[0]; ptm
= p
[1]; pby
= pty
+ ptm
;
1187 pby
= p
[0]; pty
= p
[1]; ptm
= p
[2];
1191 if( pty
+ptm
> 100 ) {
1193 perror( "KCONFIG_PROBABILITY" );
1197 bool has_changed
= false;
1199 for_all_symbols(i
, sym
) {
1200 if (sym_has_value(sym
) || (sym
->flags
& SYMBOL_VALID
))
1202 switch (sym_get_type(sym
)) {
1208 sym
->def
[S_DEF_USER
].tri
= yes
;
1211 sym
->def
[S_DEF_USER
].tri
= mod
;
1214 sym
->def
[S_DEF_USER
].tri
= no
;
1217 sym
->def
[S_DEF_USER
].tri
= no
;
1219 if (sym
->type
== S_TRISTATE
) {
1221 sym
->def
[S_DEF_USER
].tri
= yes
;
1222 else if (cnt
< (pty
+ptm
))
1223 sym
->def
[S_DEF_USER
].tri
= mod
;
1224 } else if (cnt
< pby
)
1225 sym
->def
[S_DEF_USER
].tri
= yes
;
1230 if (!(sym_is_choice(sym
) && mode
== def_random
))
1231 sym
->flags
|= SYMBOL_DEF_USER
;
1239 sym_clear_all_valid();
1242 * We have different type of choice blocks.
1243 * If curr.tri equals to mod then we can select several
1244 * choice symbols in one block.
1245 * In this case we do nothing.
1246 * If curr.tri equals yes then only one symbol can be
1247 * selected in a choice block and we set it to yes,
1248 * and the rest to no.
1250 if (mode
!= def_random
) {
1251 for_all_symbols(i
, csym
) {
1252 if ((sym_is_choice(csym
) && !sym_has_value(csym
)) ||
1253 sym_is_choice_value(csym
))
1254 csym
->flags
|= SYMBOL_NEED_SET_CHOICE_VALUES
;
1258 for_all_symbols(i
, csym
) {
1259 if (sym_has_value(csym
) || !sym_is_choice(csym
))
1262 sym_calc_value(csym
);
1263 if (mode
== def_random
)
1264 has_changed
= randomize_choice_values(csym
);
1266 set_all_choice_values(csym
);