2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
19 /* return true if 'path' exists, false otherwise */
20 static bool is_present(const char *path)
24 return !stat(path, &st);
27 /* return true if 'path' exists and it is a directory, false otherwise */
28 static bool is_dir(const char *path)
35 return S_ISDIR(st.st_mode);
39 * Create the parent directory of the given path.
41 * For example, if 'include/config/auto.conf' is given, create 'include/config'.
43 static int make_parent_dir(const char *path)
45 char tmp[PATH_MAX + 1];
48 strncpy(tmp, path, sizeof(tmp));
49 tmp[sizeof(tmp) - 1] = 0;
51 /* Remove the base name. Just return if nothing is left */
52 p = strrchr(tmp, '/');
57 /* Just in case it is an absolute path */
62 while ((p = strchr(p, '/'))) {
65 /* skip if the directory exists */
66 if (!is_dir(tmp) && mkdir(tmp, 0755))
77 static char depfile_path[PATH_MAX];
78 static size_t depfile_prefix_len;
80 /* touch depfile for symbol 'name' */
81 static int conf_touch_dep(const char *name)
87 /* check overflow: prefix + name + ".h" + '\0' must fit in buffer. */
88 if (depfile_prefix_len + strlen(name) + 3 > sizeof(depfile_path))
91 d = depfile_path + depfile_prefix_len;
95 *d++ = (c == '_') ? '/' : tolower(c);
98 /* Assume directory path already exists. */
99 fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
104 ret = make_parent_dir(depfile_path);
109 fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
118 struct conf_printer {
119 void (*print_symbol)(FILE *, struct symbol *, const char *, void *);
120 void (*print_comment)(FILE *, const char *, void *);
123 static void conf_warning(const char *fmt, ...)
124 __attribute__ ((format (printf, 1, 2)));
126 static void conf_message(const char *fmt, ...)
127 __attribute__ ((format (printf, 1, 2)));
129 static const char *conf_filename;
130 static int conf_lineno, conf_warnings;
132 const char conf_defname[] = "include/generated/defconfig";
134 static void conf_warning(const char *fmt, ...)
138 fprintf(stderr, "%s:%d:warning: ", conf_filename, conf_lineno);
139 vfprintf(stderr, fmt, ap);
140 fprintf(stderr, "\n");
145 static void conf_default_message_callback(const char *s)
152 static void (*conf_message_callback)(const char *s) =
153 conf_default_message_callback;
154 void conf_set_message_callback(void (*fn)(const char *s))
156 conf_message_callback = fn;
159 static void conf_message(const char *fmt, ...)
164 if (!conf_message_callback)
169 vsnprintf(buf, sizeof(buf), fmt, ap);
170 conf_message_callback(buf);
174 const char *conf_get_configname(void)
176 char *name = getenv("KCONFIG_CONFIG");
178 return name ? name : ".config";
181 const char *conf_get_autoconfig_name(void)
183 char *name = getenv("KCONFIG_AUTOCONFIG");
185 return name ? name : "include/generated/auto.conf";
188 char *conf_get_default_confname(void)
190 static char fullname[PATH_MAX+1];
193 name = expand_string(conf_defname);
194 env = getenv(SRCTREE);
196 sprintf(fullname, "%s/%s", env, name);
197 if (is_present(fullname))
203 static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
210 sym->def[def].tri = mod;
211 sym->flags |= def_flags;
217 sym->def[def].tri = yes;
218 sym->flags |= def_flags;
222 sym->def[def].tri = no;
223 sym->flags |= def_flags;
226 if (def != S_DEF_AUTO)
227 conf_warning("symbol value '%s' invalid for %s",
232 for (p2 = p; *p2 && !isspace(*p2); p2++)
234 sym->type = S_STRING;
241 for (p2 = p; (p2 = strpbrk(p2, "\"\\")); p2++) {
246 memmove(p2, p2 + 1, strlen(p2));
249 if (def != S_DEF_AUTO)
250 conf_warning("invalid string found");
257 if (sym_string_valid(sym, p)) {
258 sym->def[def].val = xstrdup(p);
259 sym->flags |= def_flags;
261 if (def != S_DEF_AUTO)
262 conf_warning("symbol value '%s' invalid for %s",
273 #define LINE_GROWTH 16
274 static int add_byte(int c, char **lineptr, size_t slen, size_t *n)
277 size_t new_size = slen + 1;
279 new_size += LINE_GROWTH - 1;
281 nline = xrealloc(*lineptr, new_size);
289 (*lineptr)[slen] = c;
294 static ssize_t compat_getline(char **lineptr, size_t *n, FILE *stream)
296 char *line = *lineptr;
300 int c = getc(stream);
304 if (add_byte(c, &line, slen, n) < 0)
309 if (add_byte('\0', &line, slen, n) < 0)
316 if (add_byte(c, &line, slen, n) < 0)
328 int conf_read_simple(const char *name, int def)
332 size_t line_asize = 0;
338 in = zconf_fopen(name);
340 struct property *prop;
342 name = conf_get_configname();
343 in = zconf_fopen(name);
346 sym_add_change_count(1);
347 if (!sym_defconfig_list)
350 for_all_defaults(sym_defconfig_list, prop) {
351 if (expr_calc_value(prop->visible.expr) == no ||
352 prop->expr->type != E_SYMBOL)
354 sym_calc_value(prop->expr->left.sym);
355 name = sym_get_string_value(prop->expr->left.sym);
356 in = zconf_fopen(name);
358 conf_message("using defaults found in %s",
368 conf_filename = name;
372 def_flags = SYMBOL_DEF << def;
373 for_all_symbols(i, sym) {
374 sym->flags |= SYMBOL_CHANGED;
375 sym->flags &= ~(def_flags|SYMBOL_VALID);
376 if (sym_is_choice(sym))
377 sym->flags |= def_flags;
382 if (sym->def[def].val)
383 free(sym->def[def].val);
386 sym->def[def].val = NULL;
387 sym->def[def].tri = no;
391 while (compat_getline(&line, &line_asize, in) != -1) {
394 if (line[0] == '#') {
395 if (memcmp(line + 2, CONFIG_, strlen(CONFIG_)))
397 p = strchr(line + 2 + strlen(CONFIG_), ' ');
401 if (strncmp(p, "is not set", 10))
403 if (def == S_DEF_USER) {
404 sym = sym_find(line + 2 + strlen(CONFIG_));
406 sym_add_change_count(1);
410 sym = sym_lookup(line + 2 + strlen(CONFIG_), 0);
411 if (sym->type == S_UNKNOWN)
412 sym->type = S_BOOLEAN;
414 if (sym->flags & def_flags) {
415 conf_warning("override: reassigning to symbol %s", sym->name);
420 sym->def[def].tri = no;
421 sym->flags |= def_flags;
426 } else if (memcmp(line, CONFIG_, strlen(CONFIG_)) == 0) {
427 p = strchr(line + strlen(CONFIG_), '=');
431 p2 = strchr(p, '\n');
437 if (def == S_DEF_USER) {
438 sym = sym_find(line + strlen(CONFIG_));
440 sym_add_change_count(1);
444 sym = sym_lookup(line + strlen(CONFIG_), 0);
445 if (sym->type == S_UNKNOWN)
448 if (sym->flags & def_flags) {
449 conf_warning("override: reassigning to symbol %s", sym->name);
451 if (conf_set_sym_val(sym, def, def_flags, p))
454 if (line[0] != '\r' && line[0] != '\n')
455 conf_warning("unexpected data: %.*s",
456 (int)strcspn(line, "\r\n"), line);
461 if (sym && sym_is_choice_value(sym)) {
462 struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));
463 switch (sym->def[def].tri) {
467 if (cs->def[def].tri == yes) {
468 conf_warning("%s creates inconsistent choice state", sym->name);
469 cs->flags &= ~def_flags;
473 if (cs->def[def].tri != no)
474 conf_warning("override: %s changes choice state", sym->name);
475 cs->def[def].val = sym;
478 cs->def[def].tri = EXPR_OR(cs->def[def].tri, sym->def[def].tri);
486 int conf_read(const char *name)
489 int conf_unsaved = 0;
492 sym_set_change_count(0);
494 if (conf_read_simple(name, S_DEF_USER)) {
495 sym_calc_value(modules_sym);
499 sym_calc_value(modules_sym);
501 for_all_symbols(i, sym) {
503 if (sym_is_choice(sym) || (sym->flags & SYMBOL_NO_WRITE))
505 if (sym_has_value(sym) && (sym->flags & SYMBOL_WRITE)) {
506 /* check that calculated value agrees with saved value */
510 if (sym->def[S_DEF_USER].tri != sym_get_tristate_value(sym))
512 if (!sym_is_choice(sym))
516 if (!strcmp(sym->curr.val, sym->def[S_DEF_USER].val))
520 } else if (!sym_has_value(sym) && !(sym->flags & SYMBOL_WRITE))
521 /* no previous value and not saved */
524 /* maybe print value in verbose mode... */
527 for_all_symbols(i, sym) {
528 if (sym_has_value(sym) && !sym_is_choice_value(sym)) {
529 /* Reset values of generates values, so they'll appear
530 * as new, if they should become visible, but that
531 * doesn't quite work if the Kconfig and the saved
532 * configuration disagree.
534 if (sym->visible == no && !conf_unsaved)
535 sym->flags &= ~SYMBOL_DEF_USER;
540 /* Reset a string value if it's out of range */
541 if (sym_string_within_range(sym, sym->def[S_DEF_USER].val))
543 sym->flags &= ~(SYMBOL_VALID|SYMBOL_DEF_USER);
552 sym_add_change_count(conf_warnings || conf_unsaved);
558 * Kconfig configuration printer
560 * This printer is used when generating the resulting configuration after
561 * kconfig invocation and `defconfig' files. Unset symbol might be omitted by
562 * passing a non-NULL argument to the printer.
566 kconfig_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
573 bool skip_unset = (arg != NULL);
576 fprintf(fp, "# %s%s is not set\n",
585 fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, value);
589 kconfig_print_cmake_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
596 bool skip_unset = (arg != NULL);
599 fprintf(fp, "set(%s%s false)\n",
600 CONFIG_, sym->name, value);
602 } else if (*value == 'm') {
605 fprintf(fp, "set(%s%s true)\n", CONFIG_, sym->name, value);
609 const char *prefix = "";
611 if (value[0] != '0' || (value[1] != 'x' && value[1] != 'X'))
613 fprintf(fp, "set(%s%s %s%s)\n",
614 CONFIG_, sym->name, prefix, value);
619 fprintf(fp, "set(%s%s %s)\n",
620 CONFIG_, sym->name, value);
629 kconfig_print_comment(FILE *fp, const char *value, void *arg)
631 const char *p = value;
635 l = strcspn(p, "\n");
639 xfwrite(p, l, 1, fp);
648 static struct conf_printer kconfig_printer_cb =
650 .print_symbol = kconfig_print_symbol,
651 .print_comment = kconfig_print_comment,
654 static struct conf_printer kconfig_printer_cmake_cb =
656 .print_symbol = kconfig_print_cmake_symbol,
657 .print_comment = kconfig_print_comment,
663 * This printer is used when generating the `include/generated/autoconf.h' file.
666 header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
672 const char *suffix = "";
681 fprintf(fp, "#define %s%s%s 1\n",
682 CONFIG_, sym->name, suffix);
687 const char *prefix = "";
689 if (value[0] != '0' || (value[1] != 'x' && value[1] != 'X'))
691 fprintf(fp, "#define %s%s %s%s\n",
692 CONFIG_, sym->name, prefix, value);
697 fprintf(fp, "#define %s%s %s\n",
698 CONFIG_, sym->name, value);
707 header_print_comment(FILE *fp, const char *value, void *arg)
709 const char *p = value;
714 l = strcspn(p, "\n");
718 xfwrite(p, l, 1, fp);
725 fprintf(fp, " */\n");
728 static struct conf_printer header_printer_cb =
730 .print_symbol = header_print_symbol,
731 .print_comment = header_print_comment,
737 * This printer is used when generating the `include/generated/tristate.conf' file.
740 tristate_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
743 if (sym->type == S_TRISTATE && *value != 'n')
744 fprintf(fp, "%s%s=%c\n", CONFIG_, sym->name, (char)toupper(*value));
747 static struct conf_printer tristate_printer_cb =
749 .print_symbol = tristate_print_symbol,
750 .print_comment = kconfig_print_comment,
753 static void conf_write_symbol(FILE *fp, struct symbol *sym,
754 struct conf_printer *printer, void *printer_arg)
763 str = sym_get_string_value(sym);
764 str = sym_escape_string_value(str);
765 printer->print_symbol(fp, sym, str, printer_arg);
769 str = sym_get_string_value(sym);
770 printer->print_symbol(fp, sym, str, printer_arg);
775 conf_write_heading(FILE *fp, struct conf_printer *printer, void *printer_arg)
779 snprintf(buf, sizeof(buf),
781 "Automatically generated file; DO NOT EDIT.\n"
783 rootmenu.prompt->text);
785 printer->print_comment(fp, buf, printer_arg);
789 * Write out a minimal config.
790 * All values that has default values are skipped as this is redundant.
792 int conf_write_defconfig(const char *filename)
798 out = fopen(filename, "w");
802 sym_clear_all_valid();
804 /* Traverse all menus to find all relevant symbols */
805 menu = rootmenu.list;
811 if (!menu_is_visible(menu))
813 } else if (!sym_is_choice(sym)) {
815 if (!(sym->flags & SYMBOL_WRITE))
817 sym->flags &= ~SYMBOL_WRITE;
818 /* If we cannot change the symbol - skip */
819 if (!sym_is_changable(sym))
821 /* If symbol equals to default value - skip */
822 if (strcmp(sym_get_string_value(sym), sym_get_string_default(sym)) == 0)
826 * If symbol is a choice value and equals to the
827 * default for a choice - skip.
828 * But only if value is bool and equal to "y" and
829 * choice is not "optional".
830 * (If choice is "optional" then all values can be "n")
832 if (sym_is_choice_value(sym)) {
836 cs = prop_get_symbol(sym_get_choice_prop(sym));
837 ds = sym_choice_default(cs);
838 if (!sym_is_optional(cs) && sym == ds) {
839 if ((sym->type == S_BOOLEAN) &&
840 sym_get_tristate_value(sym) == yes)
844 conf_write_symbol(out, sym, &kconfig_printer_cb, NULL);
847 if (menu->list != NULL) {
850 else if (menu->next != NULL) {
853 while ((menu = menu->parent)) {
854 if (menu->next != NULL) {
865 int conf_write(const char *name)
870 const char *basename;
872 char dirname[PATH_MAX+1], tmpname[PATH_MAX+22], newname[PATH_MAX+8];
876 if (name && name[0]) {
880 strcpy(dirname, name);
881 strcat(dirname, "/");
882 basename = conf_get_configname();
883 } else if ((slash = strrchr(name, '/'))) {
884 int size = slash - name + 1;
885 memcpy(dirname, name, size);
888 basename = slash + 1;
890 basename = conf_get_configname();
894 basename = conf_get_configname();
896 sprintf(newname, "%s%s", dirname, basename);
897 env = getenv("KCONFIG_OVERWRITECONFIG");
899 sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid());
900 out = fopen(tmpname, "w");
903 out = fopen(newname, "w");
908 conf_write_heading(out, &kconfig_printer_cb, NULL);
910 if (!conf_get_changed())
911 sym_clear_all_valid();
913 menu = rootmenu.list;
917 if (!menu_is_visible(menu))
919 str = menu_get_prompt(menu);
924 } else if (!(sym->flags & SYMBOL_CHOICE)) {
926 if (!(sym->flags & SYMBOL_WRITE))
928 sym->flags &= ~SYMBOL_WRITE;
930 conf_write_symbol(out, sym, &kconfig_printer_cb, NULL);
940 else while ((menu = menu->parent)) {
950 strcat(dirname, basename);
951 strcat(dirname, ".old");
952 rename(newname, dirname);
953 if (rename(tmpname, newname))
957 conf_message("configuration written to %s", newname);
959 sym_set_change_count(0);
964 /* write a dependency file as used by kbuild to track dependencies */
965 static int conf_write_dep(const char *name)
972 out = fopen("..config.tmp", "w");
975 fprintf(out, "deps_config := \\\n");
976 for (file = file_list; file; file = file->next) {
978 fprintf(out, "\t%s \\\n", file->name);
980 fprintf(out, "\t%s\n", file->name);
982 fprintf(out, "\n%s: \\\n"
983 "\t$(deps_config)\n\n", conf_get_autoconfig_name());
985 env_write_dep(out, conf_get_autoconfig_name());
987 fprintf(out, "\n$(deps_config): ;\n");
990 if (make_parent_dir(name))
992 rename("..config.tmp", name);
996 static int conf_touch_deps(void)
1002 strcpy(depfile_path, "include/generated/");
1003 depfile_prefix_len = strlen(depfile_path);
1005 name = conf_get_autoconfig_name();
1006 conf_read_simple(name, S_DEF_AUTO);
1007 sym_calc_value(modules_sym);
1009 for_all_symbols(i, sym) {
1010 sym_calc_value(sym);
1011 if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name)
1013 if (sym->flags & SYMBOL_WRITE) {
1014 if (sym->flags & SYMBOL_DEF_AUTO) {
1016 * symbol has old and new value,
1017 * so compare them...
1019 switch (sym->type) {
1022 if (sym_get_tristate_value(sym) ==
1023 sym->def[S_DEF_AUTO].tri)
1029 if (!strcmp(sym_get_string_value(sym),
1030 sym->def[S_DEF_AUTO].val))
1038 * If there is no old value, only 'no' (unset)
1039 * is allowed as new value.
1041 switch (sym->type) {
1044 if (sym_get_tristate_value(sym) == no)
1051 } else if (!(sym->flags & SYMBOL_DEF_AUTO))
1052 /* There is neither an old nor a new value. */
1055 * There is an old value, but no new value ('no' (unset)
1056 * isn't saved in auto.conf, so the old value is always
1057 * different from 'no').
1060 res = conf_touch_dep(sym->name);
1068 int conf_write_autoconf(void)
1072 FILE *out, *tristate, *out_h, *out_c;
1075 sym_clear_all_valid();
1077 conf_write_dep("include/generated/auto.conf.cmd");
1079 if (conf_touch_deps())
1082 out = fopen(".tmpconfig", "w");
1086 tristate = fopen(".tmpconfig_tristate", "w");
1092 out_h = fopen(".tmpconfig.h", "w");
1099 out_c = fopen(".tmpconfig.cmake", "w");
1106 conf_write_heading(out, &kconfig_printer_cb, NULL);
1108 conf_write_heading(tristate, &tristate_printer_cb, NULL);
1110 conf_write_heading(out_h, &header_printer_cb, NULL);
1112 conf_write_heading(out_c, &kconfig_printer_cmake_cb, NULL);
1114 for_all_symbols(i, sym) {
1115 sym_calc_value(sym);
1116 if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
1119 /* write symbol to auto.conf, tristate and header files */
1120 conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1);
1122 conf_write_symbol(tristate, sym, &tristate_printer_cb, (void *)1);
1124 conf_write_symbol(out_h, sym, &header_printer_cb, NULL);
1126 conf_write_symbol(out_c, sym, &kconfig_printer_cmake_cb, NULL);
1133 name = getenv("KCONFIG_AUTOHEADER");
1135 name = "include/generated/autoconf.h";
1136 if (make_parent_dir(name))
1138 if (rename(".tmpconfig.h", name))
1141 name = getenv("KCONFIG_TRISTATE");
1143 name = "include/generated/tristate.conf";
1144 if (make_parent_dir(name))
1146 if (rename(".tmpconfig_tristate", name))
1149 name = getenv("KCONFIG_CMAKE");
1151 name = "config.cmake";
1152 if (make_parent_dir(name))
1154 if (rename(".tmpconfig.cmake", name))
1157 name = conf_get_autoconfig_name();
1158 if (make_parent_dir(name))
1162 * This must be the last step, kbuild has a dependency on auto.conf
1163 * and this marks the successful completion of the previous steps.
1165 if (rename(".tmpconfig", name))
1171 static int sym_change_count;
1172 static void (*conf_changed_callback)(void);
1174 void sym_set_change_count(int count)
1176 int _sym_change_count = sym_change_count;
1177 sym_change_count = count;
1178 if (conf_changed_callback &&
1179 (bool)_sym_change_count != (bool)count)
1180 conf_changed_callback();
1183 void sym_add_change_count(int count)
1185 sym_set_change_count(count + sym_change_count);
1188 bool conf_get_changed(void)
1190 return sym_change_count;
1193 void conf_set_changed_callback(void (*fn)(void))
1195 conf_changed_callback = fn;
1198 static bool randomize_choice_values(struct symbol *csym)
1200 struct property *prop;
1206 * If choice is mod then we may have more items selected
1207 * and if no then no-one.
1208 * In both cases stop.
1210 if (csym->curr.tri != yes)
1213 prop = sym_get_choice_prop(csym);
1215 /* count entries in choice block */
1217 expr_list_for_each_sym(prop->expr, e, sym)
1221 * find a random value and set it to yes,
1222 * set the rest to no so we have only one set
1224 def = (rand() % cnt);
1227 expr_list_for_each_sym(prop->expr, e, sym) {
1229 sym->def[S_DEF_USER].tri = yes;
1230 csym->def[S_DEF_USER].val = sym;
1233 sym->def[S_DEF_USER].tri = no;
1235 sym->flags |= SYMBOL_DEF_USER;
1236 /* clear VALID to get value calculated */
1237 sym->flags &= ~SYMBOL_VALID;
1239 csym->flags |= SYMBOL_DEF_USER;
1240 /* clear VALID to get value calculated */
1241 csym->flags &= ~(SYMBOL_VALID);
1246 void set_all_choice_values(struct symbol *csym)
1248 struct property *prop;
1252 prop = sym_get_choice_prop(csym);
1255 * Set all non-assinged choice values to no
1257 expr_list_for_each_sym(prop->expr, e, sym) {
1258 if (!sym_has_value(sym))
1259 sym->def[S_DEF_USER].tri = no;
1261 csym->flags |= SYMBOL_DEF_USER;
1262 /* clear VALID to get value calculated */
1263 csym->flags &= ~(SYMBOL_VALID | SYMBOL_NEED_SET_CHOICE_VALUES);
1266 bool conf_set_all_new_symbols(enum conf_def_mode mode)
1268 struct symbol *sym, *csym;
1269 int i, cnt, pby, pty, ptm; /* pby: probability of bool = y
1270 * pty: probability of tristate = y
1271 * ptm: probability of tristate = m
1274 pby = 50; pty = ptm = 33; /* can't go as the default in switch-case
1275 * below, otherwise gcc whines about
1276 * -Wmaybe-uninitialized */
1277 if (mode == def_random) {
1279 char *env = getenv("KCONFIG_PROBABILITY");
1281 while( env && *env ) {
1283 int tmp = strtol( env, &endp, 10 );
1284 if( tmp >= 0 && tmp <= 100 ) {
1288 perror( "KCONFIG_PROBABILITY" );
1291 env = (*endp == ':') ? endp+1 : endp;
1298 pby = p[0]; ptm = pby/2; pty = pby-ptm;
1301 pty = p[0]; ptm = p[1]; pby = pty + ptm;
1304 pby = p[0]; pty = p[1]; ptm = p[2];
1308 if( pty+ptm > 100 ) {
1310 perror( "KCONFIG_PROBABILITY" );
1314 bool has_changed = false;
1316 for_all_symbols(i, sym) {
1317 if (sym_has_value(sym) || (sym->flags & SYMBOL_VALID))
1319 switch (sym_get_type(sym)) {
1325 sym->def[S_DEF_USER].tri = yes;
1328 sym->def[S_DEF_USER].tri = mod;
1331 if (sym->flags & SYMBOL_ALLNOCONFIG_Y)
1332 sym->def[S_DEF_USER].tri = yes;
1334 sym->def[S_DEF_USER].tri = no;
1337 sym->def[S_DEF_USER].tri = no;
1339 if (sym->type == S_TRISTATE) {
1341 sym->def[S_DEF_USER].tri = yes;
1342 else if (cnt < (pty+ptm))
1343 sym->def[S_DEF_USER].tri = mod;
1344 } else if (cnt < pby)
1345 sym->def[S_DEF_USER].tri = yes;
1350 if (!(sym_is_choice(sym) && mode == def_random))
1351 sym->flags |= SYMBOL_DEF_USER;
1359 sym_clear_all_valid();
1362 * We have different type of choice blocks.
1363 * If curr.tri equals to mod then we can select several
1364 * choice symbols in one block.
1365 * In this case we do nothing.
1366 * If curr.tri equals yes then only one symbol can be
1367 * selected in a choice block and we set it to yes,
1368 * and the rest to no.
1370 if (mode != def_random) {
1371 for_all_symbols(i, csym) {
1372 if ((sym_is_choice(csym) && !sym_has_value(csym)) ||
1373 sym_is_choice_value(csym))
1374 csym->flags |= SYMBOL_NEED_SET_CHOICE_VALUES;
1378 for_all_symbols(i, csym) {
1379 if (sym_has_value(csym) || !sym_is_choice(csym))
1382 sym_calc_value(csym);
1383 if (mode == def_random)
1384 has_changed = randomize_choice_values(csym);
1386 set_all_choice_values(csym);