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",
233 for (p2 = p; (p2 = strpbrk(p2, "\"\\")); p2++) {
238 memmove(p2, p2 + 1, strlen(p2));
241 if (def != S_DEF_AUTO)
242 conf_warning("invalid string found");
248 if (sym_string_valid(sym, p)) {
249 sym->def[def].val = xstrdup(p);
250 sym->flags |= def_flags;
252 if (def != S_DEF_AUTO)
253 conf_warning("symbol value '%s' invalid for %s",
264 #define LINE_GROWTH 16
265 static int add_byte(int c, char **lineptr, size_t slen, size_t *n)
268 size_t new_size = slen + 1;
270 new_size += LINE_GROWTH - 1;
272 nline = xrealloc(*lineptr, new_size);
280 (*lineptr)[slen] = c;
285 static ssize_t compat_getline(char **lineptr, size_t *n, FILE *stream)
287 char *line = *lineptr;
291 int c = getc(stream);
295 if (add_byte(c, &line, slen, n) < 0)
300 if (add_byte('\0', &line, slen, n) < 0)
307 if (add_byte(c, &line, slen, n) < 0)
319 int conf_read_simple(const char *name, int def)
323 size_t line_asize = 0;
329 in = zconf_fopen(name);
331 struct property *prop;
333 name = conf_get_configname();
334 in = zconf_fopen(name);
337 sym_add_change_count(1);
338 if (!sym_defconfig_list)
341 for_all_defaults(sym_defconfig_list, prop) {
342 if (expr_calc_value(prop->visible.expr) == no ||
343 prop->expr->type != E_SYMBOL)
345 sym_calc_value(prop->expr->left.sym);
346 name = sym_get_string_value(prop->expr->left.sym);
347 in = zconf_fopen(name);
349 conf_message("using defaults found in %s",
359 conf_filename = name;
363 def_flags = SYMBOL_DEF << def;
364 for_all_symbols(i, sym) {
365 sym->flags |= SYMBOL_CHANGED;
366 sym->flags &= ~(def_flags|SYMBOL_VALID);
367 if (sym_is_choice(sym))
368 sym->flags |= def_flags;
373 if (sym->def[def].val)
374 free(sym->def[def].val);
377 sym->def[def].val = NULL;
378 sym->def[def].tri = no;
382 while (compat_getline(&line, &line_asize, in) != -1) {
385 if (line[0] == '#') {
386 if (memcmp(line + 2, CONFIG_, strlen(CONFIG_)))
388 p = strchr(line + 2 + strlen(CONFIG_), ' ');
392 if (strncmp(p, "is not set", 10))
394 if (def == S_DEF_USER) {
395 sym = sym_find(line + 2 + strlen(CONFIG_));
397 sym_add_change_count(1);
401 sym = sym_lookup(line + 2 + strlen(CONFIG_), 0);
402 if (sym->type == S_UNKNOWN)
403 sym->type = S_BOOLEAN;
405 if (sym->flags & def_flags) {
406 conf_warning("override: reassigning to symbol %s", sym->name);
411 sym->def[def].tri = no;
412 sym->flags |= def_flags;
417 } else if (memcmp(line, CONFIG_, strlen(CONFIG_)) == 0) {
418 p = strchr(line + strlen(CONFIG_), '=');
422 p2 = strchr(p, '\n');
429 sym = sym_find(line + strlen(CONFIG_));
431 if (def == S_DEF_AUTO)
433 * Reading from include/config/auto.conf
434 * If CONFIG_FOO previously existed in
435 * auto.conf but it is missing now,
436 * include/config/foo.h must be touched.
438 conf_touch_dep(line + strlen(CONFIG_));
440 sym_add_change_count(1);
444 if (sym->flags & def_flags) {
445 conf_warning("override: reassigning to symbol %s", sym->name);
447 if (conf_set_sym_val(sym, def, def_flags, p))
450 if (line[0] != '\r' && line[0] != '\n')
451 conf_warning("unexpected data: %.*s",
452 (int)strcspn(line, "\r\n"), line);
457 if (sym && sym_is_choice_value(sym)) {
458 struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));
459 switch (sym->def[def].tri) {
463 if (cs->def[def].tri == yes) {
464 conf_warning("%s creates inconsistent choice state", sym->name);
465 cs->flags &= ~def_flags;
469 if (cs->def[def].tri != no)
470 conf_warning("override: %s changes choice state", sym->name);
471 cs->def[def].val = sym;
474 cs->def[def].tri = EXPR_OR(cs->def[def].tri, sym->def[def].tri);
482 int conf_read(const char *name)
485 int conf_unsaved = 0;
488 sym_set_change_count(0);
490 if (conf_read_simple(name, S_DEF_USER)) {
491 sym_calc_value(modules_sym);
495 sym_calc_value(modules_sym);
497 for_all_symbols(i, sym) {
499 if (sym_is_choice(sym) || (sym->flags & SYMBOL_NO_WRITE))
501 if (sym_has_value(sym) && (sym->flags & SYMBOL_WRITE)) {
502 /* check that calculated value agrees with saved value */
506 if (sym->def[S_DEF_USER].tri != sym_get_tristate_value(sym))
508 if (!sym_is_choice(sym))
512 if (!strcmp(sym->curr.val, sym->def[S_DEF_USER].val))
516 } else if (!sym_has_value(sym) && !(sym->flags & SYMBOL_WRITE))
517 /* no previous value and not saved */
520 /* maybe print value in verbose mode... */
523 for_all_symbols(i, sym) {
524 if (sym_has_value(sym) && !sym_is_choice_value(sym)) {
525 /* Reset values of generates values, so they'll appear
526 * as new, if they should become visible, but that
527 * doesn't quite work if the Kconfig and the saved
528 * configuration disagree.
530 if (sym->visible == no && !conf_unsaved)
531 sym->flags &= ~SYMBOL_DEF_USER;
536 /* Reset a string value if it's out of range */
537 if (sym_string_within_range(sym, sym->def[S_DEF_USER].val))
539 sym->flags &= ~(SYMBOL_VALID|SYMBOL_DEF_USER);
548 sym_add_change_count(conf_warnings || conf_unsaved);
554 * Kconfig configuration printer
556 * This printer is used when generating the resulting configuration after
557 * kconfig invocation and `defconfig' files. Unset symbol might be omitted by
558 * passing a non-NULL argument to the printer.
562 kconfig_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
569 bool skip_unset = (arg != NULL);
572 fprintf(fp, "# %s%s is not set\n",
581 fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, value);
585 kconfig_print_cmake_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
592 bool skip_unset = (arg != NULL);
595 fprintf(fp, "set(%s%s false)\n",
596 CONFIG_, sym->name, value);
598 } else if (*value == 'm') {
601 fprintf(fp, "set(%s%s true)\n", CONFIG_, sym->name, value);
605 const char *prefix = "";
607 if (value[0] != '0' || (value[1] != 'x' && value[1] != 'X'))
609 fprintf(fp, "set(%s%s %s%s)\n",
610 CONFIG_, sym->name, prefix, value);
615 fprintf(fp, "set(%s%s %s)\n",
616 CONFIG_, sym->name, value);
625 kconfig_print_comment(FILE *fp, const char *value, void *arg)
627 const char *p = value;
631 l = strcspn(p, "\n");
635 xfwrite(p, l, 1, fp);
644 static struct conf_printer kconfig_printer_cb =
646 .print_symbol = kconfig_print_symbol,
647 .print_comment = kconfig_print_comment,
650 static struct conf_printer kconfig_printer_cmake_cb =
652 .print_symbol = kconfig_print_cmake_symbol,
653 .print_comment = kconfig_print_comment,
659 * This printer is used when generating the `include/generated/autoconf.h' file.
662 header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
668 const char *suffix = "";
677 fprintf(fp, "#define %s%s%s 1\n",
678 CONFIG_, sym->name, suffix);
683 const char *prefix = "";
685 if (value[0] != '0' || (value[1] != 'x' && value[1] != 'X'))
687 fprintf(fp, "#define %s%s %s%s\n",
688 CONFIG_, sym->name, prefix, value);
693 fprintf(fp, "#define %s%s %s\n",
694 CONFIG_, sym->name, value);
703 header_print_comment(FILE *fp, const char *value, void *arg)
705 const char *p = value;
710 l = strcspn(p, "\n");
714 xfwrite(p, l, 1, fp);
721 fprintf(fp, " */\n");
724 static struct conf_printer header_printer_cb =
726 .print_symbol = header_print_symbol,
727 .print_comment = header_print_comment,
733 * This printer is used when generating the `include/generated/tristate.conf' file.
736 tristate_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
739 if (sym->type == S_TRISTATE && *value != 'n')
740 fprintf(fp, "%s%s=%c\n", CONFIG_, sym->name, (char)toupper(*value));
743 static struct conf_printer tristate_printer_cb =
745 .print_symbol = tristate_print_symbol,
746 .print_comment = kconfig_print_comment,
749 static void conf_write_symbol(FILE *fp, struct symbol *sym,
750 struct conf_printer *printer, void *printer_arg)
758 str = sym_get_string_value(sym);
759 str = sym_escape_string_value(str);
760 printer->print_symbol(fp, sym, str, printer_arg);
764 str = sym_get_string_value(sym);
765 printer->print_symbol(fp, sym, str, printer_arg);
770 conf_write_heading(FILE *fp, struct conf_printer *printer, void *printer_arg)
774 snprintf(buf, sizeof(buf),
776 "Automatically generated file; DO NOT EDIT.\n"
778 rootmenu.prompt->text);
780 printer->print_comment(fp, buf, printer_arg);
784 * Write out a minimal config.
785 * All values that has default values are skipped as this is redundant.
787 int conf_write_defconfig(const char *filename)
793 out = fopen(filename, "w");
797 sym_clear_all_valid();
799 /* Traverse all menus to find all relevant symbols */
800 menu = rootmenu.list;
806 if (!menu_is_visible(menu))
808 } else if (!sym_is_choice(sym)) {
810 if (!(sym->flags & SYMBOL_WRITE))
812 sym->flags &= ~SYMBOL_WRITE;
813 /* If we cannot change the symbol - skip */
814 if (!sym_is_changable(sym))
816 /* If symbol equals to default value - skip */
817 if (strcmp(sym_get_string_value(sym), sym_get_string_default(sym)) == 0)
821 * If symbol is a choice value and equals to the
822 * default for a choice - skip.
823 * But only if value is bool and equal to "y" and
824 * choice is not "optional".
825 * (If choice is "optional" then all values can be "n")
827 if (sym_is_choice_value(sym)) {
831 cs = prop_get_symbol(sym_get_choice_prop(sym));
832 ds = sym_choice_default(cs);
833 if (!sym_is_optional(cs) && sym == ds) {
834 if ((sym->type == S_BOOLEAN) &&
835 sym_get_tristate_value(sym) == yes)
839 conf_write_symbol(out, sym, &kconfig_printer_cb, NULL);
842 if (menu->list != NULL) {
845 else if (menu->next != NULL) {
848 while ((menu = menu->parent)) {
849 if (menu->next != NULL) {
860 int conf_write(const char *name)
865 const char *basename;
867 char dirname[PATH_MAX+1], tmpname[PATH_MAX+22], newname[PATH_MAX+8];
871 if (name && name[0]) {
875 strcpy(dirname, name);
876 strcat(dirname, "/");
877 basename = conf_get_configname();
878 } else if ((slash = strrchr(name, '/'))) {
879 int size = slash - name + 1;
880 memcpy(dirname, name, size);
883 basename = slash + 1;
885 basename = conf_get_configname();
889 basename = conf_get_configname();
891 sprintf(newname, "%s%s", dirname, basename);
892 env = getenv("KCONFIG_OVERWRITECONFIG");
894 sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid());
895 out = fopen(tmpname, "w");
898 out = fopen(newname, "w");
903 conf_write_heading(out, &kconfig_printer_cb, NULL);
905 if (!conf_get_changed())
906 sym_clear_all_valid();
908 menu = rootmenu.list;
912 if (!menu_is_visible(menu))
914 str = menu_get_prompt(menu);
919 } else if (!(sym->flags & SYMBOL_CHOICE)) {
921 if (!(sym->flags & SYMBOL_WRITE))
923 sym->flags &= ~SYMBOL_WRITE;
925 conf_write_symbol(out, sym, &kconfig_printer_cb, NULL);
935 else while ((menu = menu->parent)) {
945 strcat(dirname, basename);
946 strcat(dirname, ".old");
947 rename(newname, dirname);
948 if (rename(tmpname, newname))
952 conf_message("configuration written to %s", newname);
954 sym_set_change_count(0);
959 /* write a dependency file as used by kbuild to track dependencies */
960 static int conf_write_dep(const char *name)
967 out = fopen("..config.tmp", "w");
970 fprintf(out, "deps_config := \\\n");
971 for (file = file_list; file; file = file->next) {
973 fprintf(out, "\t%s \\\n", file->name);
975 fprintf(out, "\t%s\n", file->name);
977 fprintf(out, "\n%s: \\\n"
978 "\t$(deps_config)\n\n", conf_get_autoconfig_name());
980 env_write_dep(out, conf_get_autoconfig_name());
982 fprintf(out, "\n$(deps_config): ;\n");
985 if (make_parent_dir(name))
987 rename("..config.tmp", name);
991 static int conf_touch_deps(void)
997 strcpy(depfile_path, "include/generated/");
998 depfile_prefix_len = strlen(depfile_path);
1000 name = conf_get_autoconfig_name();
1001 conf_read_simple(name, S_DEF_AUTO);
1002 sym_calc_value(modules_sym);
1004 for_all_symbols(i, sym) {
1005 sym_calc_value(sym);
1006 if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name)
1008 if (sym->flags & SYMBOL_WRITE) {
1009 if (sym->flags & SYMBOL_DEF_AUTO) {
1011 * symbol has old and new value,
1012 * so compare them...
1014 switch (sym->type) {
1017 if (sym_get_tristate_value(sym) ==
1018 sym->def[S_DEF_AUTO].tri)
1024 if (!strcmp(sym_get_string_value(sym),
1025 sym->def[S_DEF_AUTO].val))
1033 * If there is no old value, only 'no' (unset)
1034 * is allowed as new value.
1036 switch (sym->type) {
1039 if (sym_get_tristate_value(sym) == no)
1046 } else if (!(sym->flags & SYMBOL_DEF_AUTO))
1047 /* There is neither an old nor a new value. */
1050 * There is an old value, but no new value ('no' (unset)
1051 * isn't saved in auto.conf, so the old value is always
1052 * different from 'no').
1055 res = conf_touch_dep(sym->name);
1063 int conf_write_autoconf(void)
1067 FILE *out, *tristate, *out_h, *out_c;
1070 sym_clear_all_valid();
1072 conf_write_dep("include/generated/auto.conf.cmd");
1074 if (conf_touch_deps())
1077 out = fopen(".tmpconfig", "w");
1081 tristate = fopen(".tmpconfig_tristate", "w");
1087 out_h = fopen(".tmpconfig.h", "w");
1094 out_c = fopen(".tmpconfig.cmake", "w");
1101 conf_write_heading(out, &kconfig_printer_cb, NULL);
1103 conf_write_heading(tristate, &tristate_printer_cb, NULL);
1105 conf_write_heading(out_h, &header_printer_cb, NULL);
1107 conf_write_heading(out_c, &kconfig_printer_cmake_cb, NULL);
1109 for_all_symbols(i, sym) {
1110 sym_calc_value(sym);
1111 if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
1114 /* write symbol to auto.conf, tristate and header files */
1115 conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1);
1117 conf_write_symbol(tristate, sym, &tristate_printer_cb, (void *)1);
1119 conf_write_symbol(out_h, sym, &header_printer_cb, NULL);
1121 conf_write_symbol(out_c, sym, &kconfig_printer_cmake_cb, NULL);
1128 name = getenv("KCONFIG_AUTOHEADER");
1130 name = "include/generated/autoconf.h";
1131 if (make_parent_dir(name))
1133 if (rename(".tmpconfig.h", name))
1136 name = getenv("KCONFIG_TRISTATE");
1138 name = "include/generated/tristate.conf";
1139 if (make_parent_dir(name))
1141 if (rename(".tmpconfig_tristate", name))
1144 name = getenv("KCONFIG_CMAKE");
1146 name = "config.cmake";
1147 if (make_parent_dir(name))
1149 if (rename(".tmpconfig.cmake", name))
1152 name = conf_get_autoconfig_name();
1153 if (make_parent_dir(name))
1157 * This must be the last step, kbuild has a dependency on auto.conf
1158 * and this marks the successful completion of the previous steps.
1160 if (rename(".tmpconfig", name))
1166 static int sym_change_count;
1167 static void (*conf_changed_callback)(void);
1169 void sym_set_change_count(int count)
1171 int _sym_change_count = sym_change_count;
1172 sym_change_count = count;
1173 if (conf_changed_callback &&
1174 (bool)_sym_change_count != (bool)count)
1175 conf_changed_callback();
1178 void sym_add_change_count(int count)
1180 sym_set_change_count(count + sym_change_count);
1183 bool conf_get_changed(void)
1185 return sym_change_count;
1188 void conf_set_changed_callback(void (*fn)(void))
1190 conf_changed_callback = fn;
1193 static bool randomize_choice_values(struct symbol *csym)
1195 struct property *prop;
1201 * If choice is mod then we may have more items selected
1202 * and if no then no-one.
1203 * In both cases stop.
1205 if (csym->curr.tri != yes)
1208 prop = sym_get_choice_prop(csym);
1210 /* count entries in choice block */
1212 expr_list_for_each_sym(prop->expr, e, sym)
1216 * find a random value and set it to yes,
1217 * set the rest to no so we have only one set
1219 def = (rand() % cnt);
1222 expr_list_for_each_sym(prop->expr, e, sym) {
1224 sym->def[S_DEF_USER].tri = yes;
1225 csym->def[S_DEF_USER].val = sym;
1228 sym->def[S_DEF_USER].tri = no;
1230 sym->flags |= SYMBOL_DEF_USER;
1231 /* clear VALID to get value calculated */
1232 sym->flags &= ~SYMBOL_VALID;
1234 csym->flags |= SYMBOL_DEF_USER;
1235 /* clear VALID to get value calculated */
1236 csym->flags &= ~(SYMBOL_VALID);
1241 void set_all_choice_values(struct symbol *csym)
1243 struct property *prop;
1247 prop = sym_get_choice_prop(csym);
1250 * Set all non-assinged choice values to no
1252 expr_list_for_each_sym(prop->expr, e, sym) {
1253 if (!sym_has_value(sym))
1254 sym->def[S_DEF_USER].tri = no;
1256 csym->flags |= SYMBOL_DEF_USER;
1257 /* clear VALID to get value calculated */
1258 csym->flags &= ~(SYMBOL_VALID | SYMBOL_NEED_SET_CHOICE_VALUES);
1261 bool conf_set_all_new_symbols(enum conf_def_mode mode)
1263 struct symbol *sym, *csym;
1264 int i, cnt, pby, pty, ptm; /* pby: probability of bool = y
1265 * pty: probability of tristate = y
1266 * ptm: probability of tristate = m
1269 pby = 50; pty = ptm = 33; /* can't go as the default in switch-case
1270 * below, otherwise gcc whines about
1271 * -Wmaybe-uninitialized */
1272 if (mode == def_random) {
1274 char *env = getenv("KCONFIG_PROBABILITY");
1276 while( env && *env ) {
1278 int tmp = strtol( env, &endp, 10 );
1279 if( tmp >= 0 && tmp <= 100 ) {
1283 perror( "KCONFIG_PROBABILITY" );
1286 env = (*endp == ':') ? endp+1 : endp;
1293 pby = p[0]; ptm = pby/2; pty = pby-ptm;
1296 pty = p[0]; ptm = p[1]; pby = pty + ptm;
1299 pby = p[0]; pty = p[1]; ptm = p[2];
1303 if( pty+ptm > 100 ) {
1305 perror( "KCONFIG_PROBABILITY" );
1309 bool has_changed = false;
1311 for_all_symbols(i, sym) {
1312 if (sym_has_value(sym) || (sym->flags & SYMBOL_VALID))
1314 switch (sym_get_type(sym)) {
1320 sym->def[S_DEF_USER].tri = yes;
1323 sym->def[S_DEF_USER].tri = mod;
1326 if (sym->flags & SYMBOL_ALLNOCONFIG_Y)
1327 sym->def[S_DEF_USER].tri = yes;
1329 sym->def[S_DEF_USER].tri = no;
1332 sym->def[S_DEF_USER].tri = no;
1334 if (sym->type == S_TRISTATE) {
1336 sym->def[S_DEF_USER].tri = yes;
1337 else if (cnt < (pty+ptm))
1338 sym->def[S_DEF_USER].tri = mod;
1339 } else if (cnt < pby)
1340 sym->def[S_DEF_USER].tri = yes;
1345 if (!(sym_is_choice(sym) && mode == def_random))
1346 sym->flags |= SYMBOL_DEF_USER;
1354 sym_clear_all_valid();
1357 * We have different type of choice blocks.
1358 * If curr.tri equals to mod then we can select several
1359 * choice symbols in one block.
1360 * In this case we do nothing.
1361 * If curr.tri equals yes then only one symbol can be
1362 * selected in a choice block and we set it to yes,
1363 * and the rest to no.
1365 if (mode != def_random) {
1366 for_all_symbols(i, csym) {
1367 if ((sym_is_choice(csym) && !sym_has_value(csym)) ||
1368 sym_is_choice_value(csym))
1369 csym->flags |= SYMBOL_NEED_SET_CHOICE_VALUES;
1373 for_all_symbols(i, csym) {
1374 if (sym_has_value(csym) || !sym_is_choice(csym))
1377 sym_calc_value(csym);
1378 if (mode == def_random)
1379 has_changed = randomize_choice_values(csym);
1381 set_all_choice_values(csym);