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))
80 if (!sym_is_changable(sym)) {
92 if (sym_has_value(sym)) {
99 if (sym_has_value(sym)) {
106 fgets(line, 128, stdin);
124 switch (input_mode) {
126 if (sym_tristate_within_range(sym, yes)) {
133 if (type == S_TRISTATE) {
134 if (sym_tristate_within_range(sym, mod)) {
141 if (sym_tristate_within_range(sym, yes)) {
149 if (sym_tristate_within_range(sym, no)) {
157 val = (tristate)(random() % 3);
158 } while (!sym_tristate_within_range(sym, val));
160 case no: line[0] = 'n'; break;
161 case mod: line[0] = 'm'; break;
162 case yes: line[0] = 'y'; break;
173 int conf_string(struct menu *menu)
175 struct symbol *sym = menu->sym;
179 printf("%*s%s ", indent - 1, "", menu->prompt->text);
180 printf("(%s) ", sym->name);
181 def = sym_get_string_value(sym);
182 if (sym_get_string_value(sym))
183 printf("[%s] ", def);
184 conf_askvalue(sym, def);
190 if (line[1] == '\n') {
191 printf("\n%s\n", menu->sym->help ? menu->sym->help : nohelp_text);
196 line[strlen(line)-1] = 0;
199 if (def && sym_set_string_value(sym, def))
204 static int conf_sym(struct menu *menu)
206 struct symbol *sym = menu->sym;
207 tristate oldval, newval;
211 printf("%*s%s ", indent - 1, "", menu->prompt->text);
213 printf("(%s) ", sym->name);
215 oldval = sym_get_tristate_value(sym);
227 if (oldval != no && sym_tristate_within_range(sym, no))
229 if (oldval != mod && sym_tristate_within_range(sym, mod))
231 if (oldval != yes && sym_tristate_within_range(sym, yes))
236 conf_askvalue(sym, sym_get_string_value(sym));
243 if (!line[1] || !strcmp(&line[1], "o"))
255 if (!line[1] || !strcmp(&line[1], "es"))
266 if (sym_set_tristate_value(sym, newval))
272 printf("\n%s\n", help);
276 static int conf_choice(struct menu *menu)
278 struct symbol *sym, *def_sym;
283 is_new = !sym_has_value(sym);
284 if (sym_is_changable(sym)) {
287 switch (sym_get_tristate_value(sym)) {
296 switch (sym_get_tristate_value(sym)) {
300 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
310 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
311 def_sym = sym_get_choice_value(sym);
314 for (child = menu->list; child; child = child->next) {
315 if (!menu_is_visible(child))
318 printf("%*c %s\n", indent, '*', menu_get_prompt(child));
322 if (child->sym == def_sym) {
324 printf("%*c", indent, '>');
326 printf("%*c", indent, ' ');
327 printf(" %d. %s", cnt, menu_get_prompt(child));
328 if (child->sym->name)
329 printf(" (%s)", child->sym->name);
330 if (!sym_has_value(child->sym))
334 printf("%*schoice", indent - 1, "");
339 printf("[1-%d", cnt);
343 switch (input_mode) {
354 fgets(line, 128, stdin);
356 if (line[0] == '?') {
357 printf("\n%s\n", menu->sym->help ?
358 menu->sym->help : nohelp_text);
363 else if (isdigit(line[0]))
369 def = (random() % cnt) + 1;
380 for (child = menu->list; child; child = child->next) {
381 if (!child->sym || !menu_is_visible(child))
388 if (strlen(line) > 0 && line[strlen(line) - 1] == '?') {
389 printf("\n%s\n", child->sym->help ?
390 child->sym->help : nohelp_text);
393 sym_set_choice_value(sym, child->sym);
403 static void conf(struct menu *menu)
406 struct property *prop;
409 if (!menu_is_visible(menu))
417 switch (prop->type) {
419 if (input_mode == ask_silent && rootEntry != menu) {
424 prompt = menu_get_prompt(menu);
426 printf("%*c\n%*c %s\n%*c\n",
438 if (sym_is_choice(sym)) {
440 if (sym->curr.tri != mod)
459 for (child = menu->list; child; child = child->next)
465 static void check_conf(struct menu *menu)
470 if (!menu_is_visible(menu))
474 if (sym && !sym_has_value(sym)) {
475 if (sym_is_changable(sym) ||
476 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
478 printf(_("*\n* Restart config...\n*\n"));
479 rootEntry = menu_get_parent_menu(menu);
484 for (child = menu->list; child; child = child->next)
488 int main(int ac, char **av)
494 if (ac > i && av[i][0] == '-') {
495 switch (av[i++][1]) {
497 input_mode = ask_new;
500 input_mode = ask_silent;
501 valid_stdin = isatty(0); //bbox: && isatty(1) && isatty(2);
504 input_mode = set_default;
507 input_mode = set_default;
508 defconfig_file = av[i++];
509 if (!defconfig_file) {
510 printf(_("%s: No default config file specified\n"),
519 input_mode = set_mod;
522 input_mode = set_yes;
525 input_mode = set_random;
530 fprintf(stderr, "See README for usage info\n");
536 printf(_("%s: Kconfig file missing\n"), av[0]);
540 switch (input_mode) {
543 defconfig_file = conf_get_default_confname();
544 if (conf_read(defconfig_file)) {
546 "*** Can't find default configuration \"%s\"!\n"
547 "***\n", defconfig_file);
552 if (stat(".config", &tmpstat)) {
554 "*** You have not yet configured busybox!\n"
556 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
557 "*** \"make menuconfig\" or \"make defconfig\").\n"
569 name = getenv("KCONFIG_ALLCONFIG");
570 if (name && !stat(name, &tmpstat)) {
571 conf_read_simple(name);
574 switch (input_mode) {
575 case set_no: name = "allno.config"; break;
576 case set_mod: name = "allmod.config"; break;
577 case set_yes: name = "allyes.config"; break;
578 case set_random: name = "allrandom.config"; break;
581 if (!stat(name, &tmpstat))
582 conf_read_simple(name);
583 else if (!stat("all.config", &tmpstat))
584 conf_read_simple("all.config");
590 if (input_mode != ask_silent) {
591 rootEntry = &rootmenu;
593 if (input_mode == ask_all) {
594 input_mode = ask_silent;
600 check_conf(&rootmenu);
602 if (conf_write(NULL)) {
603 fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));