2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
13 #define LKC_DIRECT_LINK
16 static void conf(struct menu *menu);
17 static void check_conf(struct menu *menu);
28 } input_mode = ask_all;
31 static int indent = 1;
32 static int valid_stdin = 1;
34 static char line[128];
35 static struct menu *rootEntry;
37 static char nohelp_text[] = N_("Sorry, no help available for this option yet.\n");
39 static void strip(char *str)
48 memmove(str, p, l + 1);
56 static void check_stdin(void)
58 if (!valid_stdin && input_mode == ask_silent) {
59 printf(_("aborted!\n\n"));
60 printf(_("Console input/output is redirected. "));
61 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
66 static void conf_askvalue(struct symbol *sym, const char *def)
68 enum symbol_type type = sym_get_type(sym);
71 if (!sym_has_value(sym))
77 if (!sym_is_changable(sym)) {
89 if (sym_has_value(sym)) {
96 if (sym_has_value(sym)) {
103 fgets(line, 128, stdin);
121 switch (input_mode) {
123 if (sym_tristate_within_range(sym, yes)) {
130 if (type == S_TRISTATE) {
131 if (sym_tristate_within_range(sym, mod)) {
138 if (sym_tristate_within_range(sym, yes)) {
146 if (sym_tristate_within_range(sym, no)) {
154 val = (tristate)(random() % 3);
155 } while (!sym_tristate_within_range(sym, val));
157 case no: line[0] = 'n'; break;
158 case mod: line[0] = 'm'; break;
159 case yes: line[0] = 'y'; break;
170 int conf_string(struct menu *menu)
172 struct symbol *sym = menu->sym;
173 const char *def, *help;
176 printf("%*s%s ", indent - 1, "", menu->prompt->text);
177 printf("(%s) ", sym->name);
178 def = sym_get_string_value(sym);
179 if (sym_get_string_value(sym))
180 printf("[%s] ", def);
181 conf_askvalue(sym, def);
187 if (line[1] == '\n') {
190 help = menu->sym->help;
191 printf("\n%s\n", menu->sym->help);
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;
208 tristate oldval, newval;
212 printf("%*s%s ", indent - 1, "", menu->prompt->text);
214 printf("(%s) ", sym->name);
215 type = sym_get_type(sym);
217 oldval = sym_get_tristate_value(sym);
229 if (oldval != no && sym_tristate_within_range(sym, no))
231 if (oldval != mod && sym_tristate_within_range(sym, mod))
233 if (oldval != yes && sym_tristate_within_range(sym, yes))
238 conf_askvalue(sym, sym_get_string_value(sym));
245 if (!line[1] || !strcmp(&line[1], "o"))
257 if (!line[1] || !strcmp(&line[1], "es"))
268 if (sym_set_tristate_value(sym, newval))
274 printf("\n%s\n", help);
278 static int conf_choice(struct menu *menu)
280 struct symbol *sym, *def_sym;
286 type = sym_get_type(sym);
287 is_new = !sym_has_value(sym);
288 if (sym_is_changable(sym)) {
291 switch (sym_get_tristate_value(sym)) {
300 switch (sym_get_tristate_value(sym)) {
304 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
314 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
315 def_sym = sym_get_choice_value(sym);
318 for (child = menu->list; child; child = child->next) {
319 if (!menu_is_visible(child))
322 printf("%*c %s\n", indent, '*', menu_get_prompt(child));
326 if (child->sym == def_sym) {
328 printf("%*c", indent, '>');
330 printf("%*c", indent, ' ');
331 printf(" %d. %s", cnt, menu_get_prompt(child));
332 if (child->sym->name)
333 printf(" (%s)", child->sym->name);
334 if (!sym_has_value(child->sym))
338 printf("%*schoice", indent - 1, "");
343 printf("[1-%d", cnt);
347 switch (input_mode) {
358 fgets(line, 128, stdin);
360 if (line[0] == '?') {
361 printf("\n%s\n", menu->sym->help ?
362 menu->sym->help : nohelp_text);
367 else if (isdigit(line[0]))
373 def = (random() % cnt) + 1;
384 for (child = menu->list; child; child = child->next) {
385 if (!child->sym || !menu_is_visible(child))
392 if (line[strlen(line) - 1] == '?') {
393 printf("\n%s\n", child->sym->help ?
394 child->sym->help : nohelp_text);
397 sym_set_choice_value(sym, child->sym);
407 static void conf(struct menu *menu)
410 struct property *prop;
413 if (!menu_is_visible(menu))
421 switch (prop->type) {
423 if (input_mode == ask_silent && rootEntry != menu) {
428 prompt = menu_get_prompt(menu);
430 printf("%*c\n%*c %s\n%*c\n",
442 if (sym_is_choice(sym)) {
444 if (sym->curr.tri != mod)
463 for (child = menu->list; child; child = child->next)
469 static void check_conf(struct menu *menu)
474 if (!menu_is_visible(menu))
478 if (sym && !sym_has_value(sym)) {
479 if (sym_is_changable(sym) ||
480 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
482 printf(_("*\n* Restart config...\n*\n"));
483 rootEntry = menu_get_parent_menu(menu);
488 for (child = menu->list; child; child = child->next)
492 int main(int ac, char **av)
498 if (ac > i && av[i][0] == '-') {
499 switch (av[i++][1]) {
501 input_mode = ask_new;
504 input_mode = ask_silent;
505 valid_stdin = isatty(0) && isatty(1) && isatty(2);
508 input_mode = set_default;
511 input_mode = set_default;
512 defconfig_file = av[i++];
513 if (!defconfig_file) {
514 printf(_("%s: No default config file specified\n"),
523 input_mode = set_mod;
526 input_mode = set_yes;
529 input_mode = set_random;
534 printf("%s [-o|-s] config\n", av[0]);
540 printf(_("%s: Kconfig file missing\n"), av[0]);
544 switch (input_mode) {
547 defconfig_file = conf_get_default_confname();
548 if (conf_read(defconfig_file)) {
550 "*** Can't find default configuration \"%s\"!\n"
551 "***\n", defconfig_file);
556 if (stat(".config", &tmpstat)) {
558 "*** You have not yet configured your kernel!\n"
560 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
561 "*** \"make menuconfig\" or \"make xconfig\").\n"
573 name = getenv("KCONFIG_ALLCONFIG");
574 if (name && !stat(name, &tmpstat)) {
575 conf_read_simple(name);
578 switch (input_mode) {
579 case set_no: name = "allno.config"; break;
580 case set_mod: name = "allmod.config"; break;
581 case set_yes: name = "allyes.config"; break;
582 case set_random: name = "allrandom.config"; break;
585 if (!stat(name, &tmpstat))
586 conf_read_simple(name);
587 else if (!stat("all.config", &tmpstat))
588 conf_read_simple("all.config");
594 if (input_mode != ask_silent) {
595 rootEntry = &rootmenu;
597 if (input_mode == ask_all) {
598 input_mode = ask_silent;
604 check_conf(&rootmenu);
606 if (conf_write(NULL)) {
607 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));