2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
17 #define LKC_DIRECT_LINK
20 static void conf(struct menu *menu);
21 static void check_conf(struct menu *menu);
36 } input_mode = oldaskconfig;
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;
47 static void print_help(struct menu *menu)
49 struct gstr help = str_new();
51 menu_get_ext_help(menu, &help);
53 printf("\n%s\n", str_get(&help));
57 static void strip(char *str)
66 memmove(str, p, l + 1);
74 static void check_stdin(void)
77 printf(_("aborted!\n\n"));
78 printf(_("Console input/output is redirected. "));
79 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
84 static int conf_askvalue(struct symbol *sym, const char *def)
86 enum symbol_type type = sym_get_type(sym);
88 if (!sym_has_value(sym))
94 if (!sym_is_changable(sym)) {
101 switch (input_mode) {
103 case silentoldconfig:
104 if (sym_has_value(sym)) {
112 xfgets(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') {
156 line[strlen(line)-1] = 0;
159 if (def && sym_set_string_value(sym, def))
164 static int conf_sym(struct menu *menu)
166 struct symbol *sym = menu->sym;
167 tristate oldval, newval;
170 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
172 printf("(%s) ", sym->name);
174 oldval = sym_get_tristate_value(sym);
186 if (oldval != no && sym_tristate_within_range(sym, no))
188 if (oldval != mod && sym_tristate_within_range(sym, mod))
190 if (oldval != yes && sym_tristate_within_range(sym, yes))
192 if (menu_has_help(menu))
195 if (!conf_askvalue(sym, sym_get_string_value(sym)))
203 if (!line[1] || !strcmp(&line[1], "o"))
215 if (!line[1] || !strcmp(&line[1], "es"))
226 if (sym_set_tristate_value(sym, newval))
233 static int conf_choice(struct menu *menu)
235 struct symbol *sym, *def_sym;
240 is_new = !sym_has_value(sym);
241 if (sym_is_changable(sym)) {
244 switch (sym_get_tristate_value(sym)) {
253 switch (sym_get_tristate_value(sym)) {
257 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
267 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
268 def_sym = sym_get_choice_value(sym);
271 for (child = menu->list; child; child = child->next) {
272 if (!menu_is_visible(child))
275 printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
279 if (child->sym == def_sym) {
281 printf("%*c", indent, '>');
283 printf("%*c", indent, ' ');
284 printf(" %d. %s", cnt, _(menu_get_prompt(child)));
285 if (child->sym->name)
286 printf(" (%s)", child->sym->name);
287 if (!sym_has_value(child->sym))
291 printf(_("%*schoice"), indent - 1, "");
296 printf("[1-%d", cnt);
297 if (menu_has_help(menu))
300 switch (input_mode) {
302 case silentoldconfig:
312 xfgets(line, 128, stdin);
314 if (line[0] == '?') {
320 else if (isdigit(line[0]))
330 for (child = menu->list; child; child = child->next) {
331 if (!child->sym || !menu_is_visible(child))
338 if (line[0] && line[strlen(line) - 1] == '?') {
342 sym_set_choice_value(sym, child->sym);
343 for (child = child->list; child; child = child->next) {
352 static void conf(struct menu *menu)
355 struct property *prop;
358 if (!menu_is_visible(menu))
366 switch (prop->type) {
368 if ((input_mode == silentoldconfig ||
369 input_mode == listnewconfig ||
370 input_mode == oldnoconfig) &&
377 prompt = menu_get_prompt(menu);
379 printf("%*c\n%*c %s\n%*c\n",
381 indent, '*', _(prompt),
391 if (sym_is_choice(sym)) {
393 if (sym->curr.tri != mod)
412 for (child = menu->list; child; child = child->next)
418 static void check_conf(struct menu *menu)
423 if (!menu_is_visible(menu))
427 if (sym && !sym_has_value(sym)) {
428 if (sym_is_changable(sym) ||
429 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
430 if (input_mode == listnewconfig) {
431 if (sym->name && !sym_is_choice_value(sym)) {
432 printf("%s%s\n", CONFIG_, sym->name);
434 } else if (input_mode != oldnoconfig) {
436 printf(_("*\n* Restart config...\n*\n"));
437 rootEntry = menu_get_parent_menu(menu);
443 for (child = menu->list; child; child = child->next)
447 static struct option long_opts[] = {
448 {"oldaskconfig", no_argument, NULL, oldaskconfig},
449 {"oldconfig", no_argument, NULL, oldconfig},
450 {"silentoldconfig", no_argument, NULL, silentoldconfig},
451 {"defconfig", optional_argument, NULL, defconfig},
452 {"savedefconfig", required_argument, NULL, savedefconfig},
453 {"allnoconfig", no_argument, NULL, allnoconfig},
454 {"allyesconfig", no_argument, NULL, allyesconfig},
455 {"allmodconfig", no_argument, NULL, allmodconfig},
456 {"alldefconfig", no_argument, NULL, alldefconfig},
457 {"randconfig", no_argument, NULL, randconfig},
458 {"listnewconfig", no_argument, NULL, listnewconfig},
459 {"oldnoconfig", no_argument, NULL, oldnoconfig},
463 int main(int ac, char **av)
469 setlocale(LC_ALL, "");
470 bindtextdomain(PACKAGE, LOCALEDIR);
473 while ((opt = getopt_long(ac, av, "", long_opts, NULL)) != -1) {
474 input_mode = (enum input_mode)opt;
476 case silentoldconfig:
481 defconfig_file = optarg;
489 * Use microseconds derived seed,
490 * compensate for systems where it may be zero
492 gettimeofday(&now, NULL);
494 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
499 fprintf(stderr, _("See README for usage info\n"));
505 printf(_("%s: Kconfig file missing\n"), av[0]);
512 name = conf_get_configname();
513 if (stat(name, &tmpstat)) {
514 fprintf(stderr, _("***\n"
515 "*** Configuration file \"%s\" not found!\n"
517 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
518 "*** \"make menuconfig\" or \"make xconfig\").\n"
524 switch (input_mode) {
527 defconfig_file = conf_get_default_confname();
528 if (conf_read(defconfig_file)) {
530 "*** Can't find default configuration \"%s\"!\n"
531 "***\n"), defconfig_file);
536 case silentoldconfig:
548 name = getenv("KCONFIG_ALLCONFIG");
549 if (name && !stat(name, &tmpstat)) {
550 conf_read_simple(name, S_DEF_USER);
553 switch (input_mode) {
554 case allnoconfig: name = "allno.config"; break;
555 case allyesconfig: name = "allyes.config"; break;
556 case allmodconfig: name = "allmod.config"; break;
557 case alldefconfig: name = "alldef.config"; break;
558 case randconfig: name = "allrandom.config"; break;
561 if (!stat(name, &tmpstat))
562 conf_read_simple(name, S_DEF_USER);
563 else if (!stat("all.config", &tmpstat))
564 conf_read_simple("all.config", S_DEF_USER);
571 if (conf_get_changed()) {
572 name = getenv("KCONFIG_NOSILENTUPDATE");
575 _("\n*** The configuration requires explicit update.\n\n"));
579 valid_stdin = isatty(0) && isatty(1) && isatty(2);
582 switch (input_mode) {
584 conf_set_all_new_symbols(def_no);
587 conf_set_all_new_symbols(def_yes);
590 conf_set_all_new_symbols(def_mod);
593 conf_set_all_new_symbols(def_default);
596 conf_set_all_new_symbols(def_random);
599 conf_set_all_new_symbols(def_default);
604 rootEntry = &rootmenu;
606 input_mode = silentoldconfig;
611 case silentoldconfig:
612 /* Update until a loop caused no more changes */
615 check_conf(&rootmenu);
617 (input_mode != listnewconfig &&
618 input_mode != oldnoconfig));
623 /* silentoldconfig is used during the build so we shall update autoconf.
624 * All other commands are only used to generate a config.
626 if (conf_get_changed() && conf_write(NULL)) {
627 fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
630 if (conf_write_autoconf()) {
631 fprintf(stderr, _("\n*** Error during update of the configuration.\n\n"));
634 } else if (input_mode == savedefconfig) {
635 if (conf_write_defconfig(defconfig_file)) {
636 fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
640 } else if (input_mode != listnewconfig) {
641 if (conf_write(NULL)) {
642 fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
649 * Helper function to facilitate fgets() by Jean Sacren.
651 void xfgets(str, size, in)
656 if (fgets(str, size, in) == NULL)
657 fprintf(stderr, "\nError in reading or end of file.\n");