2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
6 #define _XOPEN_SOURCE 700
16 #define LKC_DIRECT_LINK
19 static void conf(struct menu *menu);
20 static void check_conf(struct menu *menu);
31 } input_mode = ask_all;
34 static int indent = 1;
35 static int valid_stdin = 1;
37 static char line[128];
38 static struct menu *rootEntry;
40 static char nohelp_text[] = N_("Sorry, no help available for this option yet.\n");
42 static void strip(char *str)
51 memmove(str, p, l + 1);
59 static void check_stdin(void)
61 if (!valid_stdin && input_mode == ask_silent) {
62 printf(_("aborted!\n\n"));
63 printf(_("Console input/output is redirected. "));
64 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
69 static void conf_askvalue(struct symbol *sym, const char *def)
71 enum symbol_type type = sym_get_type(sym);
74 if (!sym_has_value(sym))
81 if (!sym_is_changable(sym)) {
86 // If autoconf run (allnoconfig and such), reset bool and tristates:
87 // "select ITEM" sets ITEM=y and then parent item might have been
88 // reset to "n" later. Try to set ITEM to "n" on the second run.
89 if (type == S_BOOLEAN || type == S_TRISTATE) {
92 if (sym_tristate_within_range(sym, yes)) {
99 if (type == S_TRISTATE) {
100 if (sym_tristate_within_range(sym, mod)) {
107 if (sym_tristate_within_range(sym, yes)) {
115 if (sym_tristate_within_range(sym, no)) {
121 default: // placate compiler
126 switch (input_mode) {
131 if (sym_has_value(sym)) {
138 if (sym_has_value(sym)) {
145 fgets(line, 128, stdin);
163 switch (input_mode) {
165 if (sym_tristate_within_range(sym, yes)) {
172 if (type == S_TRISTATE) {
173 if (sym_tristate_within_range(sym, mod)) {
180 if (sym_tristate_within_range(sym, yes)) {
188 if (sym_tristate_within_range(sym, no)) {
196 val = (tristate)(random() % 3);
197 } while (!sym_tristate_within_range(sym, val));
199 case no: line[0] = 'n'; break;
200 case mod: line[0] = 'm'; break;
201 case yes: line[0] = 'y'; break;
212 int conf_string(struct menu *menu)
214 struct symbol *sym = menu->sym;
218 printf("%*s%s ", indent - 1, "", menu->prompt->text);
219 printf("(%s) ", sym->name);
220 def = sym_get_string_value(sym);
221 if (sym_get_string_value(sym))
222 printf("[%s] ", def);
223 conf_askvalue(sym, def);
229 if (line[1] == '\n') {
230 printf("\n%s\n", menu->sym->help ? menu->sym->help : nohelp_text);
235 line[strlen(line)-1] = 0;
238 if (def && sym_set_string_value(sym, def))
243 static int conf_sym(struct menu *menu)
245 struct symbol *sym = menu->sym;
246 tristate oldval, newval;
250 printf("%*s%s ", indent - 1, "", menu->prompt->text);
252 printf("(%s) ", sym->name);
254 oldval = sym_get_tristate_value(sym);
266 if (oldval != no && sym_tristate_within_range(sym, no))
268 if (oldval != mod && sym_tristate_within_range(sym, mod))
270 if (oldval != yes && sym_tristate_within_range(sym, yes))
275 conf_askvalue(sym, sym_get_string_value(sym));
282 if (!line[1] || !strcmp(&line[1], "o"))
294 if (!line[1] || !strcmp(&line[1], "es"))
305 if (sym_set_tristate_value(sym, newval))
311 printf("\n%s\n", help);
315 static int conf_choice(struct menu *menu)
317 struct symbol *sym, *def_sym;
322 is_new = !sym_has_value(sym);
323 if (sym_is_changable(sym)) {
326 switch (sym_get_tristate_value(sym)) {
335 switch (sym_get_tristate_value(sym)) {
339 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
349 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
350 def_sym = sym_get_choice_value(sym);
353 for (child = menu->list; child; child = child->next) {
354 if (!menu_is_visible(child))
357 printf("%*c %s\n", indent, '*', menu_get_prompt(child));
361 if (child->sym == def_sym) {
363 printf("%*c", indent, '>');
365 printf("%*c", indent, ' ');
366 printf(" %d. %s", cnt, menu_get_prompt(child));
367 if (child->sym->name)
368 printf(" (%s)", child->sym->name);
369 if (!sym_has_value(child->sym))
373 printf("%*schoice", indent - 1, "");
378 printf("[1-%d", cnt);
382 switch (input_mode) {
393 fgets(line, 128, stdin);
395 if (line[0] == '?') {
396 printf("\n%s\n", menu->sym->help ?
397 menu->sym->help : nohelp_text);
402 else if (isdigit(line[0]))
408 def = (random() % cnt) + 1;
419 for (child = menu->list; child; child = child->next) {
420 if (!child->sym || !menu_is_visible(child))
427 if (strlen(line) > 0 && line[strlen(line) - 1] == '?') {
428 printf("\n%s\n", child->sym->help ?
429 child->sym->help : nohelp_text);
432 sym_set_choice_value(sym, child->sym);
442 static void conf(struct menu *menu)
445 struct property *prop;
448 if (!menu_is_visible(menu))
456 switch (prop->type) {
458 if (input_mode == ask_silent && rootEntry != menu) {
463 prompt = menu_get_prompt(menu);
465 printf("%*c\n%*c %s\n%*c\n",
477 if (sym_is_choice(sym)) {
479 if (sym->curr.tri != mod)
498 for (child = menu->list; child; child = child->next)
504 static void check_conf(struct menu *menu)
509 if (!menu_is_visible(menu))
513 if (sym && !sym_has_value(sym)) {
514 if (sym_is_changable(sym) ||
515 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
517 printf(_("*\n* Restart config...\n*\n"));
518 rootEntry = menu_get_parent_menu(menu);
523 for (child = menu->list; child; child = child->next)
527 int main(int ac, char **av)
533 if (ac > i && av[i][0] == '-') {
534 switch (av[i++][1]) {
536 input_mode = ask_new;
539 input_mode = ask_silent;
540 valid_stdin = isatty(0); //bbox: && isatty(1) && isatty(2);
543 input_mode = set_default;
546 input_mode = set_default;
547 defconfig_file = av[i++];
548 if (!defconfig_file) {
549 printf(_("%s: No default config file specified\n"),
558 input_mode = set_mod;
561 input_mode = set_yes;
564 input_mode = set_random;
569 fprintf(stderr, "See README for usage info\n");
575 printf(_("%s: Kconfig file missing\n"), av[0]);
579 switch (input_mode) {
582 defconfig_file = conf_get_default_confname();
583 if (conf_read(defconfig_file)) {
585 "*** Can't find default configuration \"%s\"!\n"
586 "***\n", defconfig_file);
591 if (stat(".config", &tmpstat)) {
593 "*** You have not yet configured busybox!\n"
595 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
596 "*** \"make menuconfig\" or \"make defconfig\").\n"
608 name = getenv("KCONFIG_ALLCONFIG");
609 if (name && !stat(name, &tmpstat)) {
610 conf_read_simple(name);
613 switch (input_mode) {
614 case set_no: name = "allno.config"; break;
615 case set_mod: name = "allmod.config"; break;
616 case set_yes: name = "allyes.config"; break;
617 case set_random: name = "allrandom.config"; break;
620 if (!stat(name, &tmpstat))
621 conf_read_simple(name);
622 else if (!stat("all.config", &tmpstat))
623 conf_read_simple("all.config");
629 if (input_mode != ask_silent) {
630 rootEntry = &rootmenu;
632 // If autoconf run (allnoconfig and such), run it twice:
633 // "select ITEM" sets ITEM=y and then parent item
634 // is reset to "n" later. Second run sets ITEM to "n".
635 // Example: ADDUSER selects LONG_OPTS.
636 // allnoconfig must set _both_ to "n".
637 // Before, LONG_OPTS remained "y".
638 if (input_mode == set_no
639 || input_mode == set_mod
640 || input_mode == set_yes
642 rootEntry = &rootmenu;
645 if (input_mode == ask_all) {
646 input_mode = ask_silent;
652 check_conf(&rootmenu);
654 if (conf_write(NULL)) {
655 fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));