2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
21 void (*print_symbol
)(FILE *, struct symbol
*, const char *, void *);
22 void (*print_comment
)(FILE *, const char *, void *);
25 static void conf_warning(const char *fmt
, ...)
26 __attribute__ ((format (printf
, 1, 2)));
28 static void conf_message(const char *fmt
, ...)
29 __attribute__ ((format (printf
, 1, 2)));
31 static const char *conf_filename
;
32 static int conf_lineno
, conf_warnings
;
34 const char conf_defname
[] = ".defconfig";
36 static void conf_warning(const char *fmt
, ...)
40 fprintf(stderr
, "%s:%d:warning: ", conf_filename
, conf_lineno
);
41 vfprintf(stderr
, fmt
, ap
);
42 fprintf(stderr
, "\n");
47 static void conf_default_message_callback(const char *fmt
, va_list ap
)
54 static void (*conf_message_callback
) (const char *fmt
, va_list ap
) =
55 conf_default_message_callback
;
56 void conf_set_message_callback(void (*fn
) (const char *fmt
, va_list ap
))
58 conf_message_callback
= fn
;
61 static void conf_message(const char *fmt
, ...)
66 if (conf_message_callback
)
67 conf_message_callback(fmt
, ap
);
71 const char *conf_get_configname(void)
73 char *name
= getenv("BR2_CONFIG");
75 return name
? name
: ".config";
78 const char *conf_get_autoconfig_name(void)
80 return getenv("KCONFIG_AUTOCONFIG");
83 static char *conf_expand_value(const char *in
)
87 static char res_value
[SYMBOL_MAXLENGTH
];
88 char *dst
, name
[SYMBOL_MAXLENGTH
];
92 while ((src
= strchr(in
, '$'))) {
93 strncat(res_value
, in
, src
- in
);
96 while (isalnum(*src
) || *src
== '_')
99 sym
= sym_lookup(name
, 0);
101 strcat(res_value
, sym_get_string_value(sym
));
104 strcat(res_value
, in
);
109 char *conf_get_default_confname(void)
112 static char fullname
[PATH_MAX
+1];
115 name
= conf_expand_value(conf_defname
);
116 env
= getenv(SRCTREE
);
118 sprintf(fullname
, "%s/%s", env
, name
);
119 if (!stat(fullname
, &buf
))
125 static int conf_set_sym_val(struct symbol
*sym
, int def
, int def_flags
, char *p
)
132 sym
->def
[def
].tri
= mod
;
133 sym
->flags
|= def_flags
;
139 sym
->def
[def
].tri
= yes
;
140 sym
->flags
|= def_flags
;
144 sym
->def
[def
].tri
= no
;
145 sym
->flags
|= def_flags
;
148 if (def
!= S_DEF_AUTO
)
149 conf_warning("symbol value '%s' invalid for %s",
154 for (p2
= p
; *p2
&& !isspace(*p2
); p2
++)
156 sym
->type
= S_STRING
;
163 for (p2
= p
; (p2
= strpbrk(p2
, "\"\\")); p2
++) {
168 memmove(p2
, p2
+ 1, strlen(p2
));
171 if (def
!= S_DEF_AUTO
)
172 conf_warning("invalid string found");
179 if (sym_string_valid(sym
, p
)) {
180 sym
->def
[def
].val
= xstrdup(p
);
181 sym
->flags
|= def_flags
;
183 if (def
!= S_DEF_AUTO
)
184 conf_warning("symbol value '%s' invalid for %s",
195 #define LINE_GROWTH 16
196 static int add_byte(int c
, char **lineptr
, size_t slen
, size_t *n
)
199 size_t new_size
= slen
+ 1;
201 new_size
+= LINE_GROWTH
- 1;
203 nline
= xrealloc(*lineptr
, new_size
);
211 (*lineptr
)[slen
] = c
;
216 static ssize_t
compat_getline(char **lineptr
, size_t *n
, FILE *stream
)
218 char *line
= *lineptr
;
222 int c
= getc(stream
);
226 if (add_byte(c
, &line
, slen
, n
) < 0)
231 if (add_byte('\0', &line
, slen
, n
) < 0)
238 if (add_byte(c
, &line
, slen
, n
) < 0)
250 int conf_read_simple(const char *name
, int def
)
254 size_t line_asize
= 0;
260 in
= zconf_fopen(name
);
262 struct property
*prop
;
264 name
= conf_get_configname();
265 in
= zconf_fopen(name
);
268 sym_add_change_count(1);
269 if (!sym_defconfig_list
)
272 for_all_defaults(sym_defconfig_list
, prop
) {
273 if (expr_calc_value(prop
->visible
.expr
) == no
||
274 prop
->expr
->type
!= E_SYMBOL
)
276 name
= conf_expand_value(prop
->expr
->left
.sym
->name
);
277 in
= zconf_fopen(name
);
279 conf_message(_("using defaults found in %s"),
289 conf_filename
= name
;
293 def_flags
= SYMBOL_DEF
<< def
;
294 for_all_symbols(i
, sym
) {
295 sym
->flags
|= SYMBOL_CHANGED
;
296 sym
->flags
&= ~(def_flags
|SYMBOL_VALID
);
297 if (sym_is_choice(sym
))
298 sym
->flags
|= def_flags
;
303 if (sym
->def
[def
].val
)
304 free(sym
->def
[def
].val
);
307 sym
->def
[def
].val
= NULL
;
308 sym
->def
[def
].tri
= no
;
312 while (compat_getline(&line
, &line_asize
, in
) != -1) {
315 if (line
[0] == '#') {
316 if (memcmp(line
+ 2, CONFIG_
, strlen(CONFIG_
)))
318 p
= strchr(line
+ 2 + strlen(CONFIG_
), ' ');
322 if (strncmp(p
, "is not set", 10))
324 if (def
== S_DEF_USER
) {
325 sym
= sym_find(line
+ 2 + strlen(CONFIG_
));
327 sym_add_change_count(1);
331 sym
= sym_lookup(line
+ 2 + strlen(CONFIG_
), 0);
332 if (sym
->type
== S_UNKNOWN
)
333 sym
->type
= S_BOOLEAN
;
335 if (sym
->flags
& def_flags
) {
336 conf_warning("override: reassigning to symbol %s", sym
->name
);
341 sym
->def
[def
].tri
= no
;
342 sym
->flags
|= def_flags
;
347 } else if (memcmp(line
, CONFIG_
, strlen(CONFIG_
)) == 0) {
348 p
= strchr(line
+ strlen(CONFIG_
), '=');
352 p2
= strchr(p
, '\n');
358 if (def
== S_DEF_USER
) {
359 sym
= sym_find(line
+ strlen(CONFIG_
));
361 sym_add_change_count(1);
365 sym
= sym_lookup(line
+ strlen(CONFIG_
), 0);
366 if (sym
->type
== S_UNKNOWN
)
369 if (sym
->flags
& def_flags
) {
370 conf_warning("override: reassigning to symbol %s", sym
->name
);
372 if (conf_set_sym_val(sym
, def
, def_flags
, p
))
375 if (line
[0] != '\r' && line
[0] != '\n')
376 conf_warning("unexpected data: %.*s",
377 (int)strcspn(line
, "\r\n"), line
);
382 if (sym
&& sym_is_choice_value(sym
)) {
383 struct symbol
*cs
= prop_get_symbol(sym_get_choice_prop(sym
));
384 switch (sym
->def
[def
].tri
) {
388 if (cs
->def
[def
].tri
== yes
) {
389 conf_warning("%s creates inconsistent choice state", sym
->name
);
390 cs
->flags
&= ~def_flags
;
394 if (cs
->def
[def
].tri
!= no
)
395 conf_warning("override: %s changes choice state", sym
->name
);
396 cs
->def
[def
].val
= sym
;
399 cs
->def
[def
].tri
= EXPR_OR(cs
->def
[def
].tri
, sym
->def
[def
].tri
);
407 int conf_read(const char *name
)
410 int conf_unsaved
= 0;
413 sym_set_change_count(0);
415 if (conf_read_simple(name
, S_DEF_USER
)) {
416 sym_calc_value(modules_sym
);
420 sym_calc_value(modules_sym
);
422 for_all_symbols(i
, sym
) {
424 if (sym_is_choice(sym
) || (sym
->flags
& SYMBOL_AUTO
))
426 if (sym_has_value(sym
) && (sym
->flags
& SYMBOL_WRITE
)) {
427 /* check that calculated value agrees with saved value */
431 if (sym
->def
[S_DEF_USER
].tri
!= sym_get_tristate_value(sym
))
433 if (!sym_is_choice(sym
))
437 if (!strcmp(sym
->curr
.val
, sym
->def
[S_DEF_USER
].val
))
441 } else if (!sym_has_value(sym
) && !(sym
->flags
& SYMBOL_WRITE
))
442 /* no previous value and not saved */
445 /* maybe print value in verbose mode... */
448 for_all_symbols(i
, sym
) {
449 if (sym_has_value(sym
) && !sym_is_choice_value(sym
)) {
450 /* Reset values of generates values, so they'll appear
451 * as new, if they should become visible, but that
452 * doesn't quite work if the Kconfig and the saved
453 * configuration disagree.
455 if (sym
->visible
== no
&& !conf_unsaved
)
456 sym
->flags
&= ~SYMBOL_DEF_USER
;
461 /* Reset a string value if it's out of range */
462 if (sym_string_within_range(sym
, sym
->def
[S_DEF_USER
].val
))
464 sym
->flags
&= ~(SYMBOL_VALID
|SYMBOL_DEF_USER
);
473 sym_add_change_count(conf_warnings
|| conf_unsaved
);
479 * Kconfig configuration printer
481 * This printer is used when generating the resulting configuration after
482 * kconfig invocation and `defconfig' files. Unset symbol might be omitted by
483 * passing a non-NULL argument to the printer.
487 kconfig_print_symbol(FILE *fp
, struct symbol
*sym
, const char *value
, void *arg
)
494 bool skip_unset
= (arg
!= NULL
);
497 fprintf(fp
, "# %s%s is not set\n",
506 fprintf(fp
, "%s%s=%s\n", CONFIG_
, sym
->name
, value
);
510 kconfig_print_comment(FILE *fp
, const char *value
, void *arg
)
512 const char *p
= value
;
516 l
= strcspn(p
, "\n");
520 xfwrite(p
, l
, 1, fp
);
529 static struct conf_printer kconfig_printer_cb
=
531 .print_symbol
= kconfig_print_symbol
,
532 .print_comment
= kconfig_print_comment
,
538 * This printer is used when generating the `include/generated/autoconf.h' file.
541 header_print_symbol(FILE *fp
, struct symbol
*sym
, const char *value
, void *arg
)
547 const char *suffix
= "";
556 fprintf(fp
, "#define %s%s%s 1\n",
557 CONFIG_
, sym
->name
, suffix
);
562 const char *prefix
= "";
564 if (value
[0] != '0' || (value
[1] != 'x' && value
[1] != 'X'))
566 fprintf(fp
, "#define %s%s %s%s\n",
567 CONFIG_
, sym
->name
, prefix
, value
);
572 fprintf(fp
, "#define %s%s %s\n",
573 CONFIG_
, sym
->name
, value
);
582 header_print_comment(FILE *fp
, const char *value
, void *arg
)
584 const char *p
= value
;
589 l
= strcspn(p
, "\n");
593 xfwrite(p
, l
, 1, fp
);
600 fprintf(fp
, " */\n");
603 static struct conf_printer header_printer_cb
=
605 .print_symbol
= header_print_symbol
,
606 .print_comment
= header_print_comment
,
612 * This printer is used when generating the `include/config/tristate.conf' file.
615 tristate_print_symbol(FILE *fp
, struct symbol
*sym
, const char *value
, void *arg
)
618 if (sym
->type
== S_TRISTATE
&& *value
!= 'n')
619 fprintf(fp
, "%s%s=%c\n", CONFIG_
, sym
->name
, (char)toupper(*value
));
622 static struct conf_printer tristate_printer_cb
=
624 .print_symbol
= tristate_print_symbol
,
625 .print_comment
= kconfig_print_comment
,
628 static void conf_write_symbol(FILE *fp
, struct symbol
*sym
,
629 struct conf_printer
*printer
, void *printer_arg
)
638 str
= sym_get_string_value(sym
);
639 str
= sym_escape_string_value(str
);
640 printer
->print_symbol(fp
, sym
, str
, printer_arg
);
644 str
= sym_get_string_value(sym
);
645 printer
->print_symbol(fp
, sym
, str
, printer_arg
);
650 conf_write_heading(FILE *fp
, struct conf_printer
*printer
, void *printer_arg
)
654 snprintf(buf
, sizeof(buf
),
656 "Automatically generated file; DO NOT EDIT.\n"
658 rootmenu
.prompt
->text
);
660 printer
->print_comment(fp
, buf
, printer_arg
);
664 * Write out a minimal config.
665 * All values that has default values are skipped as this is redundant.
667 int conf_write_defconfig(const char *filename
)
673 out
= fopen(filename
, "w");
677 sym_clear_all_valid();
679 /* Traverse all menus to find all relevant symbols */
680 menu
= rootmenu
.list
;
686 if (!menu_is_visible(menu
))
688 } else if (!sym_is_choice(sym
)) {
690 if (!(sym
->flags
& SYMBOL_WRITE
))
692 sym
->flags
&= ~SYMBOL_WRITE
;
693 /* If we cannot change the symbol - skip */
694 if (!sym_is_changable(sym
))
696 /* If symbol equals to default value - skip */
697 if (strcmp(sym_get_string_value(sym
), sym_get_string_default(sym
)) == 0)
701 * If symbol is a choice value and equals to the
702 * default for a choice - skip.
703 * But only if value is bool and equal to "y" and
704 * choice is not "optional".
705 * (If choice is "optional" then all values can be "n")
707 if (sym_is_choice_value(sym
)) {
711 cs
= prop_get_symbol(sym_get_choice_prop(sym
));
712 ds
= sym_choice_default(cs
);
713 if (!sym_is_optional(cs
) && sym
== ds
) {
714 if ((sym
->type
== S_BOOLEAN
) &&
715 sym_get_tristate_value(sym
) == yes
)
719 conf_write_symbol(out
, sym
, &kconfig_printer_cb
, NULL
);
722 if (menu
->list
!= NULL
) {
725 else if (menu
->next
!= NULL
) {
728 while ((menu
= menu
->parent
)) {
729 if (menu
->next
!= NULL
) {
740 int conf_write(const char *name
)
745 const char *basename
;
747 char dirname
[PATH_MAX
+1], tmpname
[PATH_MAX
+1], newname
[PATH_MAX
+1];
751 name
= conf_get_configname();
754 if (name
&& name
[0]) {
758 if (!stat(name
, &st
) && S_ISDIR(st
.st_mode
)) {
759 strcpy(dirname
, name
);
760 strcat(dirname
, "/");
761 basename
= conf_get_configname();
762 } else if ((slash
= strrchr(name
, '/'))) {
763 int size
= slash
- name
+ 1;
764 memcpy(dirname
, name
, size
);
767 basename
= slash
+ 1;
769 basename
= conf_get_configname();
773 basename
= conf_get_configname();
775 sprintf(newname
, "%s%s", dirname
, basename
);
776 env
= getenv("KCONFIG_OVERWRITECONFIG");
778 sprintf(tmpname
, "%s.tmpconfig.%d", dirname
, (int)getpid());
779 out
= fopen(tmpname
, "w");
782 out
= fopen(newname
, "w");
787 conf_write_heading(out
, &kconfig_printer_cb
, NULL
);
789 if (!conf_get_changed())
790 sym_clear_all_valid();
792 menu
= rootmenu
.list
;
796 if (!menu_is_visible(menu
))
798 str
= menu_get_prompt(menu
);
803 } else if (!(sym
->flags
& SYMBOL_CHOICE
)) {
805 if (!(sym
->flags
& SYMBOL_WRITE
))
807 sym
->flags
&= ~SYMBOL_WRITE
;
809 conf_write_symbol(out
, sym
, &kconfig_printer_cb
, NULL
);
819 else while ((menu
= menu
->parent
)) {
829 strcat(dirname
, basename
);
830 strcat(dirname
, ".old");
831 rename(newname
, dirname
);
832 if (rename(tmpname
, newname
))
836 conf_message(_("configuration written to %s"), newname
);
838 sym_set_change_count(0);
843 static int conf_split_config(void)
846 char path
[PATH_MAX
+1];
847 char *opwd
, *dir
, *_name
;
853 name
= conf_get_autoconfig_name();
854 conf_read_simple(name
, S_DEF_AUTO
);
855 sym_calc_value(modules_sym
);
858 _name
= strdup(name
);
859 if (opwd
== NULL
|| _name
== NULL
)
861 opwd
= getcwd(opwd
, 256);
862 dir
= dirname(_name
);
873 for_all_symbols(i
, sym
) {
875 if ((sym
->flags
& SYMBOL_AUTO
) || !sym
->name
)
877 if (sym
->flags
& SYMBOL_WRITE
) {
878 if (sym
->flags
& SYMBOL_DEF_AUTO
) {
880 * symbol has old and new value,
886 if (sym_get_tristate_value(sym
) ==
887 sym
->def
[S_DEF_AUTO
].tri
)
893 if (!strcmp(sym_get_string_value(sym
),
894 sym
->def
[S_DEF_AUTO
].val
))
902 * If there is no old value, only 'no' (unset)
903 * is allowed as new value.
908 if (sym_get_tristate_value(sym
) == no
)
915 } else if (!(sym
->flags
& SYMBOL_DEF_AUTO
))
916 /* There is neither an old nor a new value. */
919 * There is an old value, but no new value ('no' (unset)
920 * isn't saved in auto.conf, so the old value is always
921 * different from 'no').
924 /* Replace all '_' and append ".h" */
929 *d
++ = (c
== '_') ? '/' : c
;
933 /* Assume directory path already exists. */
934 fd
= open(path
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0644);
936 if (errno
!= ENOENT
) {
941 * Create directory components,
942 * unless they exist already.
945 while ((d
= strchr(d
, '/'))) {
947 if (stat(path
, &sb
) && mkdir(path
, 0755)) {
954 fd
= open(path
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0644);
971 int conf_write_autoconf(void)
975 FILE *out
, *tristate
, *out_h
;
977 char dir
[PATH_MAX
+1], buf
[PATH_MAX
+1];
980 strcpy(dir
, conf_get_configname());
981 s
= strrchr(dir
, '/');
987 sym_clear_all_valid();
989 sprintf(buf
, "%s.config.cmd", dir
);
992 if (conf_split_config())
995 sprintf(buf
, "%s.tmpconfig", dir
);
996 out
= fopen(buf
, "w");
1000 sprintf(buf
, "%s.tmpconfig_tristate", dir
);
1001 tristate
= fopen(buf
, "w");
1007 sprintf(buf
, "%s.tmpconfig.h", dir
);
1008 out_h
= fopen(buf
, "w");
1015 conf_write_heading(out
, &kconfig_printer_cb
, NULL
);
1017 conf_write_heading(tristate
, &tristate_printer_cb
, NULL
);
1019 conf_write_heading(out_h
, &header_printer_cb
, NULL
);
1021 for_all_symbols(i
, sym
) {
1022 sym_calc_value(sym
);
1023 if (!(sym
->flags
& SYMBOL_WRITE
) || !sym
->name
)
1026 /* write symbol to auto.conf, tristate and header files */
1027 conf_write_symbol(out
, sym
, &kconfig_printer_cb
, (void *)1);
1029 conf_write_symbol(tristate
, sym
, &tristate_printer_cb
, (void *)1);
1031 conf_write_symbol(out_h
, sym
, &header_printer_cb
, NULL
);
1037 name
= getenv("KCONFIG_AUTOHEADER");
1039 name
= "include/generated/autoconf.h";
1040 sprintf(buf
, "%s.tmpconfig.h", dir
);
1041 if (rename(buf
, name
))
1043 name
= getenv("KCONFIG_TRISTATE");
1045 name
= "include/config/tristate.conf";
1046 sprintf(buf
, "%s.tmpconfig_tristate", dir
);
1047 if (rename(buf
, name
))
1049 name
= conf_get_autoconfig_name();
1051 * This must be the last step, kbuild has a dependency on auto.conf
1052 * and this marks the successful completion of the previous steps.
1054 sprintf(buf
, "%s.tmpconfig", dir
);
1055 if (rename(buf
, name
))
1061 static int sym_change_count
;
1062 static void (*conf_changed_callback
)(void);
1064 void sym_set_change_count(int count
)
1066 int _sym_change_count
= sym_change_count
;
1067 sym_change_count
= count
;
1068 if (conf_changed_callback
&&
1069 (bool)_sym_change_count
!= (bool)count
)
1070 conf_changed_callback();
1073 void sym_add_change_count(int count
)
1075 sym_set_change_count(count
+ sym_change_count
);
1078 bool conf_get_changed(void)
1080 return sym_change_count
;
1083 void conf_set_changed_callback(void (*fn
)(void))
1085 conf_changed_callback
= fn
;
1088 static bool randomize_choice_values(struct symbol
*csym
)
1090 struct property
*prop
;
1096 * If choice is mod then we may have more items selected
1097 * and if no then no-one.
1098 * In both cases stop.
1100 if (csym
->curr
.tri
!= yes
)
1103 prop
= sym_get_choice_prop(csym
);
1105 /* count entries in choice block */
1107 expr_list_for_each_sym(prop
->expr
, e
, sym
)
1111 * find a random value and set it to yes,
1112 * set the rest to no so we have only one set
1114 def
= (rand() % cnt
);
1117 expr_list_for_each_sym(prop
->expr
, e
, sym
) {
1119 sym
->def
[S_DEF_USER
].tri
= yes
;
1120 csym
->def
[S_DEF_USER
].val
= sym
;
1123 sym
->def
[S_DEF_USER
].tri
= no
;
1125 sym
->flags
|= SYMBOL_DEF_USER
;
1126 /* clear VALID to get value calculated */
1127 sym
->flags
&= ~SYMBOL_VALID
;
1129 csym
->flags
|= SYMBOL_DEF_USER
;
1130 /* clear VALID to get value calculated */
1131 csym
->flags
&= ~(SYMBOL_VALID
);
1136 void set_all_choice_values(struct symbol
*csym
)
1138 struct property
*prop
;
1142 prop
= sym_get_choice_prop(csym
);
1145 * Set all non-assinged choice values to no
1147 expr_list_for_each_sym(prop
->expr
, e
, sym
) {
1148 if (!sym_has_value(sym
))
1149 sym
->def
[S_DEF_USER
].tri
= no
;
1151 csym
->flags
|= SYMBOL_DEF_USER
;
1152 /* clear VALID to get value calculated */
1153 csym
->flags
&= ~(SYMBOL_VALID
| SYMBOL_NEED_SET_CHOICE_VALUES
);
1156 bool conf_set_all_new_symbols(enum conf_def_mode mode
)
1158 struct symbol
*sym
, *csym
;
1159 int i
, cnt
, pby
, pty
, ptm
; /* pby: probability of bool = y
1160 * pty: probability of tristate = y
1161 * ptm: probability of tristate = m
1164 pby
= 50; pty
= ptm
= 33; /* can't go as the default in switch-case
1165 * below, otherwise gcc whines about
1166 * -Wmaybe-uninitialized */
1167 if (mode
== def_random
) {
1169 char *env
= getenv("KCONFIG_PROBABILITY");
1171 while( env
&& *env
) {
1173 int tmp
= strtol( env
, &endp
, 10 );
1174 if( tmp
>= 0 && tmp
<= 100 ) {
1178 perror( "KCONFIG_PROBABILITY" );
1181 env
= (*endp
== ':') ? endp
+1 : endp
;
1188 pby
= p
[0]; ptm
= pby
/2; pty
= pby
-ptm
;
1191 pty
= p
[0]; ptm
= p
[1]; pby
= pty
+ ptm
;
1194 pby
= p
[0]; pty
= p
[1]; ptm
= p
[2];
1198 if( pty
+ptm
> 100 ) {
1200 perror( "KCONFIG_PROBABILITY" );
1204 bool has_changed
= false;
1206 for_all_symbols(i
, sym
) {
1207 if (sym_has_value(sym
) || (sym
->flags
& SYMBOL_VALID
))
1209 switch (sym_get_type(sym
)) {
1215 sym
->def
[S_DEF_USER
].tri
= yes
;
1218 sym
->def
[S_DEF_USER
].tri
= mod
;
1221 if (sym
->flags
& SYMBOL_ALLNOCONFIG_Y
)
1222 sym
->def
[S_DEF_USER
].tri
= yes
;
1224 sym
->def
[S_DEF_USER
].tri
= no
;
1227 sym
->def
[S_DEF_USER
].tri
= no
;
1229 if (sym
->type
== S_TRISTATE
) {
1231 sym
->def
[S_DEF_USER
].tri
= yes
;
1232 else if (cnt
< (pty
+ptm
))
1233 sym
->def
[S_DEF_USER
].tri
= mod
;
1234 } else if (cnt
< pby
)
1235 sym
->def
[S_DEF_USER
].tri
= yes
;
1240 if (!(sym_is_choice(sym
) && mode
== def_random
))
1241 sym
->flags
|= SYMBOL_DEF_USER
;
1249 sym_clear_all_valid();
1252 * We have different type of choice blocks.
1253 * If curr.tri equals to mod then we can select several
1254 * choice symbols in one block.
1255 * In this case we do nothing.
1256 * If curr.tri equals yes then only one symbol can be
1257 * selected in a choice block and we set it to yes,
1258 * and the rest to no.
1260 if (mode
!= def_random
) {
1261 for_all_symbols(i
, csym
) {
1262 if ((sym_is_choice(csym
) && !sym_has_value(csym
)) ||
1263 sym_is_choice_value(csym
))
1264 csym
->flags
|= SYMBOL_NEED_SET_CHOICE_VALUES
;
1268 for_all_symbols(i
, csym
) {
1269 if (sym_has_value(csym
) || !sym_is_choice(csym
))
1272 sym_calc_value(csym
);
1273 if (mode
== def_random
)
1274 has_changed
= randomize_choice_values(csym
);
1276 set_all_choice_values(csym
);