2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
16 #define LKC_DIRECT_LINK
20 #define EUNSETOPT 2 /* if -B and -b are used and unset config
21 * options were found */
23 static void conf(struct menu *menu);
24 static void check_conf(struct menu *menu);
37 } input_mode = ask_all;
40 static int indent = 1;
41 static int valid_stdin = 1;
42 static int sync_kconfig;
44 static char line[128];
45 static struct menu *rootEntry;
46 static int unset_variables;
48 static void print_help(struct menu *menu)
50 struct gstr help = str_new();
52 menu_get_ext_help(menu, &help);
54 printf("\n%s\n", str_get(&help));
58 static void strip(char *str)
67 memmove(str, p, l + 1);
75 static void check_stdin(void)
78 printf(_("aborted!\n\n"));
79 printf(_("Console input/output is redirected. "));
80 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
85 static int conf_askvalue(struct symbol *sym, const char *def)
87 enum symbol_type type = sym_get_type(sym);
89 if (!sym_has_value(sym))
95 if (!sym_is_changable(sym)) {
102 switch (input_mode) {
105 if (sym_has_value(sym)) {
112 fgets(line, 128, stdin);
131 static int conf_string(struct menu *menu)
133 struct symbol *sym = menu->sym;
137 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
138 printf("(%s) ", sym->name);
139 def = sym_get_string_value(sym);
140 if (sym_get_string_value(sym))
141 printf("[%s] ", def);
142 if (!conf_askvalue(sym, def))
149 if (line[1] == '\n') {
155 line[strlen(line)-1] = 0;
158 if (def && sym_set_string_value(sym, def))
163 static int conf_sym(struct menu *menu)
165 struct symbol *sym = menu->sym;
166 tristate oldval, newval;
169 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
171 printf("(%s) ", sym->name);
173 oldval = sym_get_tristate_value(sym);
185 if (oldval != no && sym_tristate_within_range(sym, no))
187 if (oldval != mod && sym_tristate_within_range(sym, mod))
189 if (oldval != yes && sym_tristate_within_range(sym, yes))
191 if (menu_has_help(menu))
194 if (!conf_askvalue(sym, sym_get_string_value(sym)))
202 if (!line[1] || !strcmp(&line[1], "o"))
214 if (!line[1] || !strcmp(&line[1], "es"))
225 if (sym_set_tristate_value(sym, newval))
232 static int conf_choice(struct menu *menu)
234 struct symbol *sym, *def_sym;
239 is_new = !sym_has_value(sym);
240 if (sym_is_changable(sym)) {
243 switch (sym_get_tristate_value(sym)) {
252 switch (sym_get_tristate_value(sym)) {
256 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
266 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
267 def_sym = sym_get_choice_value(sym);
270 for (child = menu->list; child; child = child->next) {
271 if (!menu_is_visible(child))
274 printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
278 if (child->sym == def_sym) {
280 printf("%*c", indent, '>');
282 printf("%*c", indent, ' ');
283 printf(" %d. %s", cnt, _(menu_get_prompt(child)));
284 if (child->sym->name)
285 printf(" (%s)", child->sym->name);
286 if (!sym_has_value(child->sym))
290 printf(_("%*schoice"), indent - 1, "");
295 printf("[1-%d", cnt);
296 if (menu_has_help(menu))
299 switch (input_mode) {
310 fgets(line, 128, stdin);
312 if (line[0] == '?') {
318 else if (isdigit(line[0]))
328 for (child = menu->list; child; child = child->next) {
329 if (!child->sym || !menu_is_visible(child))
336 if (line[strlen(line) - 1] == '?') {
340 sym_set_choice_value(sym, child->sym);
341 for (child = child->list; child; child = child->next) {
350 static void conf(struct menu *menu)
353 struct property *prop;
356 if (!menu_is_visible(menu))
364 switch (prop->type) {
366 if ((input_mode == ask_silent ||
367 input_mode == dont_ask ||
368 input_mode == dont_ask_dont_tell) &&
374 prompt = menu_get_prompt(menu);
376 printf("%*c\n%*c %s\n%*c\n",
378 indent, '*', _(prompt),
388 if (sym_is_choice(sym)) {
390 if (sym->curr.tri != mod)
409 for (child = menu->list; child; child = child->next)
415 static void check_conf(struct menu *menu)
420 if (!menu_is_visible(menu))
424 if (sym && !sym_has_value(sym)) {
425 if (sym_is_changable(sym) ||
426 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
427 if (input_mode == dont_ask ||
428 input_mode == dont_ask_dont_tell) {
429 if (input_mode == dont_ask &&
430 sym->name && !sym_is_choice_value(sym)) {
431 if (!unset_variables)
432 fprintf(stderr, "The following"
433 " variables are not set:\n");
434 fprintf(stderr, "CONFIG_%s\n",
440 printf(_("*\n* Restart config...\n*\n"));
441 rootEntry = menu_get_parent_menu(menu);
447 for (child = menu->list; child; child = child->next)
451 int main(int ac, char **av)
457 setlocale(LC_ALL, "");
458 bindtextdomain(PACKAGE, LOCALEDIR);
461 while ((opt = getopt(ac, av, "osbBdD:nmyrh")) != -1) {
464 input_mode = ask_silent;
467 input_mode = ask_silent;
471 input_mode = dont_ask;
474 input_mode = dont_ask_dont_tell;
477 input_mode = set_default;
480 input_mode = set_default;
481 defconfig_file = optarg;
487 input_mode = set_mod;
490 input_mode = set_yes;
498 * Use microseconds derived seed,
499 * compensate for systems where it may be zero
501 gettimeofday(&now, NULL);
503 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
506 input_mode = set_random;
510 printf(_("See README for usage info\n"));
514 fprintf(stderr, _("See README for usage info\n"));
519 printf(_("%s: Kconfig file missing\n"), av[0]);
526 name = conf_get_configname();
527 if (stat(name, &tmpstat)) {
528 fprintf(stderr, _("***\n"
529 "*** You have not yet configured your kernel!\n"
530 "*** (missing kernel config file \"%s\")\n"
532 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
533 "*** \"make menuconfig\" or \"make xconfig\").\n"
539 switch (input_mode) {
542 defconfig_file = conf_get_default_confname();
543 if (conf_read(defconfig_file)) {
545 "*** Can't find default configuration \"%s\"!\n"
546 "***\n"), defconfig_file);
554 case dont_ask_dont_tell:
561 name = getenv("KCONFIG_ALLCONFIG");
562 if (name && !stat(name, &tmpstat)) {
563 conf_read_simple(name, S_DEF_USER);
566 switch (input_mode) {
567 case set_no: name = "allno.config"; break;
568 case set_mod: name = "allmod.config"; break;
569 case set_yes: name = "allyes.config"; break;
570 case set_random: name = "allrandom.config"; break;
573 if (!stat(name, &tmpstat))
574 conf_read_simple(name, S_DEF_USER);
575 else if (!stat("all.config", &tmpstat))
576 conf_read_simple("all.config", S_DEF_USER);
583 if (conf_get_changed()) {
584 name = getenv("KCONFIG_NOSILENTUPDATE");
587 _("\n*** Kernel configuration requires explicit update.\n\n"));
591 valid_stdin = isatty(0) && isatty(1) && isatty(2);
594 switch (input_mode) {
596 conf_set_all_new_symbols(def_no);
599 conf_set_all_new_symbols(def_yes);
602 conf_set_all_new_symbols(def_mod);
605 conf_set_all_new_symbols(def_random);
608 conf_set_all_new_symbols(def_default);
612 rootEntry = &rootmenu;
614 input_mode = ask_silent;
617 case dont_ask_dont_tell:
619 /* Update until a loop caused no more changes */
622 check_conf(&rootmenu);
624 (input_mode != dont_ask &&
625 input_mode != dont_ask_dont_tell));
630 /* silentoldconfig is used during the build so we shall update autoconf.
631 * All other commands are only used to generate a config.
633 if (conf_get_changed() && conf_write(NULL)) {
634 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
637 if (conf_write_autoconf()) {
638 fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
641 } else if (!unset_variables || input_mode != dont_ask) {
642 if (conf_write(NULL)) {
643 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
647 return unset_variables ? EUNSETOPT : 0;