2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
19 static void conf(struct menu *menu);
20 static void check_conf(struct menu *menu);
35 } input_mode = oldaskconfig;
39 static int indent = 1;
40 static int valid_stdin = 1;
41 static int sync_kconfig;
43 static char line[128];
44 static struct menu *rootEntry;
46 static void print_help(struct menu *menu)
48 struct gstr help = str_new();
50 menu_get_ext_help(menu, &help);
52 printf("\n%s\n", str_get(&help));
56 static void strip(char *str)
65 memmove(str, p, l + 1);
73 static void check_stdin(void)
76 printf(_("aborted!\n\n"));
77 printf(_("Console input/output is redirected. "));
78 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
83 static int conf_askvalue(struct symbol *sym, const char *def)
85 enum symbol_type type = sym_get_type(sym);
87 if (!sym_has_value(sym))
93 if (!sym_is_changable(sym)) {
100 switch (input_mode) {
102 case silentoldconfig:
103 if (sym_has_value(sym)) {
111 xfgets(line, 128, stdin);
130 static int conf_string(struct menu *menu)
132 struct symbol *sym = menu->sym;
136 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
137 printf("(%s) ", sym->name);
138 def = sym_get_string_value(sym);
139 if (sym_get_string_value(sym))
140 printf("[%s] ", def);
141 if (!conf_askvalue(sym, def))
148 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) {
301 case silentoldconfig:
311 xfgets(line, 128, stdin);
313 if (line[0] == '?') {
319 else if (isdigit(line[0]))
329 for (child = menu->list; child; child = child->next) {
330 if (!child->sym || !menu_is_visible(child))
337 if (line[0] && line[strlen(line) - 1] == '?') {
341 sym_set_choice_value(sym, child->sym);
342 for (child = child->list; child; child = child->next) {
351 static void conf(struct menu *menu)
354 struct property *prop;
357 if (!menu_is_visible(menu))
365 switch (prop->type) {
367 if ((input_mode == silentoldconfig ||
368 input_mode == listnewconfig ||
369 input_mode == oldnoconfig) &&
376 prompt = menu_get_prompt(menu);
378 printf("%*c\n%*c %s\n%*c\n",
380 indent, '*', _(prompt),
390 if (sym_is_choice(sym)) {
392 if (sym->curr.tri != mod)
411 for (child = menu->list; child; child = child->next)
417 static void check_conf(struct menu *menu)
422 if (!menu_is_visible(menu))
426 if (sym && !sym_has_value(sym)) {
427 if (sym_is_changable(sym) ||
428 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
429 if (input_mode == listnewconfig) {
430 if (sym->name && !sym_is_choice_value(sym)) {
431 printf("%s%s\n", CONFIG_, sym->name);
433 } else if (input_mode != oldnoconfig) {
435 printf(_("*\n* Restart config...\n*\n"));
436 rootEntry = menu_get_parent_menu(menu);
442 for (child = menu->list; child; child = child->next)
446 static struct option long_opts[] = {
447 {"oldaskconfig", no_argument, NULL, oldaskconfig},
448 {"oldconfig", no_argument, NULL, oldconfig},
449 {"silentoldconfig", no_argument, NULL, silentoldconfig},
450 {"defconfig", optional_argument, NULL, defconfig},
451 {"savedefconfig", required_argument, NULL, savedefconfig},
452 {"allnoconfig", no_argument, NULL, allnoconfig},
453 {"allyesconfig", no_argument, NULL, allyesconfig},
454 {"allmodconfig", no_argument, NULL, allmodconfig},
455 {"alldefconfig", no_argument, NULL, alldefconfig},
456 {"randconfig", no_argument, NULL, randconfig},
457 {"listnewconfig", no_argument, NULL, listnewconfig},
458 {"oldnoconfig", no_argument, NULL, oldnoconfig},
462 int main(int ac, char **av)
468 setlocale(LC_ALL, "");
469 bindtextdomain(PACKAGE, LOCALEDIR);
472 while ((opt = getopt_long(ac, av, "", long_opts, NULL)) != -1) {
473 input_mode = (enum input_mode)opt;
475 case silentoldconfig:
480 defconfig_file = optarg;
488 * Use microseconds derived seed,
489 * compensate for systems where it may be zero
491 gettimeofday(&now, NULL);
493 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
498 fprintf(stderr, _("See README for usage info\n"));
504 printf(_("%s: Kconfig file missing\n"), av[0]);
511 name = conf_get_configname();
512 if (stat(name, &tmpstat)) {
513 fprintf(stderr, _("***\n"
514 "*** Configuration file \"%s\" not found!\n"
516 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
517 "*** \"make menuconfig\" or \"make xconfig\").\n"
523 switch (input_mode) {
526 defconfig_file = conf_get_default_confname();
527 if (conf_read(defconfig_file)) {
529 "*** Can't find default configuration \"%s\"!\n"
530 "***\n"), defconfig_file);
535 case silentoldconfig:
547 name = getenv("KCONFIG_ALLCONFIG");
548 if (name && !stat(name, &tmpstat)) {
549 conf_read_simple(name, S_DEF_USER);
552 switch (input_mode) {
553 case allnoconfig: name = "allno.config"; break;
554 case allyesconfig: name = "allyes.config"; break;
555 case allmodconfig: name = "allmod.config"; break;
556 case alldefconfig: name = "alldef.config"; break;
557 case randconfig: name = "allrandom.config"; break;
560 if (!stat(name, &tmpstat))
561 conf_read_simple(name, S_DEF_USER);
562 else if (!stat("all.config", &tmpstat))
563 conf_read_simple("all.config", S_DEF_USER);
570 if (conf_get_changed()) {
571 name = getenv("KCONFIG_NOSILENTUPDATE");
574 _("\n*** The configuration requires explicit update.\n\n"));
578 valid_stdin = isatty(0) && isatty(1) && isatty(2);
581 switch (input_mode) {
583 conf_set_all_new_symbols(def_no);
586 conf_set_all_new_symbols(def_yes);
589 conf_set_all_new_symbols(def_mod);
592 conf_set_all_new_symbols(def_default);
595 conf_set_all_new_symbols(def_random);
598 conf_set_all_new_symbols(def_default);
603 rootEntry = &rootmenu;
605 input_mode = silentoldconfig;
610 case silentoldconfig:
611 /* Update until a loop caused no more changes */
614 check_conf(&rootmenu);
616 (input_mode != listnewconfig &&
617 input_mode != oldnoconfig));
622 /* silentoldconfig is used during the build so we shall update autoconf.
623 * All other commands are only used to generate a config.
625 if (conf_get_changed() && conf_write(NULL)) {
626 fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
629 if (conf_write_autoconf()) {
630 fprintf(stderr, _("\n*** Error during update of the configuration.\n\n"));
633 } else if (input_mode == savedefconfig) {
634 if (conf_write_defconfig(defconfig_file)) {
635 fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
639 } else if (input_mode != listnewconfig) {
640 if (conf_write(NULL)) {
641 fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
648 * Helper function to facilitate fgets() by Jean Sacren.
650 void xfgets(str, size, in)
655 if (fgets(str, size, in) == NULL)
656 fprintf(stderr, "\nError in reading or end of file.\n");