diff options
Diffstat (limited to 'extra/config/confdata.c')
-rw-r--r-- | extra/config/confdata.c | 70 |
1 files changed, 49 insertions, 21 deletions
diff --git a/extra/config/confdata.c b/extra/config/confdata.c index 9da48ebdc..281dd0024 100644 --- a/extra/config/confdata.c +++ b/extra/config/confdata.c @@ -11,6 +11,7 @@ #include <string.h> #include <time.h> #include <unistd.h> +#include <libgen.h> #define LKC_DIRECT_LINK #include "lkc.h" @@ -553,7 +554,7 @@ int conf_write(const char *name) int conf_split_config(void) { - char *name, path[128]; + char *name, path[128], opwd[512]; char *s, *d, c; struct symbol *sym; struct stat sb; @@ -564,7 +565,9 @@ int conf_split_config(void) name = "include/config/auto.conf"; conf_read_simple(name, S_DEF_AUTO); - if (chdir("include/config")) + if (getcwd(opwd, sizeof(opwd)) == NULL) + return 1; + if (chdir(dirname(strdup(name)))) return 1; res = 0; @@ -658,7 +661,7 @@ int conf_split_config(void) close(fd); } out: - if (chdir("../..")) + if (chdir(opwd)) return 1; return res; @@ -666,6 +669,7 @@ out: int conf_write_autoconf(void) { + char opwd[512]; struct symbol *sym; const char *str; char *name; @@ -673,6 +677,10 @@ int conf_write_autoconf(void) time_t now; int i, l; + if (getcwd(opwd, sizeof(opwd)) == NULL) + return 1; + if (chdir(dirname(strdup(conf_get_configname())))) + return 1; sym_clear_all_valid(); file_write_dep("include/config/auto.conf.cmd"); @@ -780,7 +788,7 @@ int conf_write_autoconf(void) */ if (rename(".tmpconfig", name)) return 1; - + chdir(opwd); return 0; } @@ -841,7 +849,7 @@ void conf_set_all_new_symbols(enum conf_def_mode mode) default: continue; } - if (!sym_is_choice(sym) || mode != def_random) + if (!(sym_is_choice(sym) && mode == def_random)) sym->flags |= SYMBOL_DEF_USER; break; default: @@ -850,33 +858,53 @@ void conf_set_all_new_symbols(enum conf_def_mode mode) } - if (modules_sym) - sym_calc_value(modules_sym); + sym_clear_all_valid(); if (mode != def_random) return; - + /* + * We have different type of choice blocks. + * If curr.tri equal to mod then we can select several + * choice symbols in one block. + * In this case we do nothing. + * If curr.tri equal yes then only one symbol can be + * selected in a choice block and we set it to yes, + * and the rest to no. + */ for_all_symbols(i, csym) { if (sym_has_value(csym) || !sym_is_choice(csym)) continue; sym_calc_value(csym); + + if (csym->curr.tri != yes) + continue; + prop = sym_get_choice_prop(csym); - def = -1; - while (1) { - cnt = 0; - expr_list_for_each_sym(prop->expr, e, sym) { - if (sym->visible == no) - continue; - if (def == cnt++) { - csym->def[S_DEF_USER].val = sym; - break; - } + + /* count entries in choice block */ + cnt = 0; + expr_list_for_each_sym(prop->expr, e, sym) + cnt++; + + /* + * find a random value and set it to yes, + * set the rest to no so we have only one set + */ + def = (rand() % cnt); + + cnt = 0; + expr_list_for_each_sym(prop->expr, e, sym) { + if (def == cnt++) { + sym->def[S_DEF_USER].tri = yes; + csym->def[S_DEF_USER].val = sym; + } + else { + sym->def[S_DEF_USER].tri = no; } - if (def >= 0 || cnt < 2) - break; - def = (rand() % cnt) + 1; } csym->flags |= SYMBOL_DEF_USER; + /* clear VALID to get value calculated */ + csym->flags &= ~(SYMBOL_VALID); } } |