2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
14 #define LKC_DIRECT_LINK
17 static void conf(struct menu *menu);
18 static void check_conf(struct menu *menu);
30 } input_mode = ask_all;
33 static int indent = 1;
34 static int valid_stdin = 1;
36 static char line[128];
37 static struct menu *rootEntry;
39 static char nohelp_text[] = N_("Sorry, no help available for this option yet.\n");
41 static int return_value = 0;
43 static void strip(char *str)
52 memmove(str, p, l + 1);
60 static void check_stdin(void)
62 if (!valid_stdin && input_mode == ask_silent) {
63 printf(_("aborted!\n\n"));
64 printf(_("Console input/output is redirected. "));
65 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
70 static void conf_askvalue(struct symbol *sym, const char *def)
72 enum symbol_type type = sym_get_type(sym);
75 if (!sym_has_value(sym))
81 if (!sym_is_changable(sym)) {
93 if (sym_has_value(sym)) {
100 if (sym_has_value(sym)) {
107 fgets(line, 128, stdin);
110 if (!sym_has_value(sym)) {
111 fprintf(stderr,"CONFIG_%s\n",sym->name);
131 switch (input_mode) {
133 if (sym_tristate_within_range(sym, yes)) {
140 if (type == S_TRISTATE) {
141 if (sym_tristate_within_range(sym, mod)) {
148 if (sym_tristate_within_range(sym, yes)) {
156 if (sym_tristate_within_range(sym, no)) {
164 val = (tristate)(random() % 3);
165 } while (!sym_tristate_within_range(sym, val));
167 case no: line[0] = 'n'; break;
168 case mod: line[0] = 'm'; break;
169 case yes: line[0] = 'y'; break;
180 int conf_string(struct menu *menu)
182 struct symbol *sym = menu->sym;
183 const char *def, *help;
186 printf("%*s%s ", indent - 1, "", menu->prompt->text);
187 printf("(%s) ", sym->name);
188 def = sym_get_string_value(sym);
189 if (sym_get_string_value(sym))
190 printf("[%s] ", def);
191 conf_askvalue(sym, def);
197 if (line[1] == '\n') {
200 help = menu->sym->help;
201 printf("\n%s\n", menu->sym->help);
206 line[strlen(line)-1] = 0;
209 if (def && sym_set_string_value(sym, def))
214 static int conf_sym(struct menu *menu)
216 struct symbol *sym = menu->sym;
218 tristate oldval, newval;
222 printf("%*s%s ", indent - 1, "", menu->prompt->text);
224 printf("(%s) ", sym->name);
225 type = sym_get_type(sym);
227 oldval = sym_get_tristate_value(sym);
239 if (oldval != no && sym_tristate_within_range(sym, no))
241 if (oldval != mod && sym_tristate_within_range(sym, mod))
243 if (oldval != yes && sym_tristate_within_range(sym, yes))
248 conf_askvalue(sym, sym_get_string_value(sym));
255 if (!line[1] || !strcmp(&line[1], "o"))
267 if (!line[1] || !strcmp(&line[1], "es"))
278 if (sym_set_tristate_value(sym, newval))
284 printf("\n%s\n", help);
288 static int conf_choice(struct menu *menu)
290 struct symbol *sym, *def_sym;
296 type = sym_get_type(sym);
297 is_new = !sym_has_value(sym);
298 if (sym_is_changable(sym)) {
301 switch (sym_get_tristate_value(sym)) {
310 switch (sym_get_tristate_value(sym)) {
314 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
324 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
325 def_sym = sym_get_choice_value(sym);
328 for (child = menu->list; child; child = child->next) {
329 if (!menu_is_visible(child))
332 printf("%*c %s\n", indent, '*', menu_get_prompt(child));
336 if (child->sym == def_sym) {
338 printf("%*c", indent, '>');
340 printf("%*c", indent, ' ');
341 printf(" %d. %s", cnt, menu_get_prompt(child));
342 if (child->sym->name)
343 printf(" (%s)", child->sym->name);
344 if (!sym_has_value(child->sym))
348 printf("%*schoice", indent - 1, "");
353 printf("[1-%d", cnt);
357 switch (input_mode) {
372 fgets(line, 128, stdin);
374 if (line[0] == '?') {
375 printf("\n%s\n", menu->sym->help ?
376 menu->sym->help : nohelp_text);
381 else if (isdigit(line[0]))
387 def = (random() % cnt) + 1;
398 for (child = menu->list; child; child = child->next) {
399 if (!child->sym || !menu_is_visible(child))
406 if (line[strlen(line) - 1] == '?') {
407 printf("\n%s\n", child->sym->help ?
408 child->sym->help : nohelp_text);
411 sym_set_choice_value(sym, child->sym);
421 static void conf(struct menu *menu)
424 struct property *prop;
427 if (!menu_is_visible(menu))
435 switch (prop->type) {
437 if (input_mode == ask_silent && rootEntry != menu) {
442 prompt = menu_get_prompt(menu);
444 printf("%*c\n%*c %s\n%*c\n",
456 if (sym_is_choice(sym)) {
458 if (sym->curr.tri != mod)
477 for (child = menu->list; child; child = child->next)
483 static void check_conf(struct menu *menu)
488 if (!menu_is_visible(menu))
492 if (sym && !sym_has_value(sym)) {
493 if (sym_is_changable(sym) ||
494 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
496 printf(_("*\n* Restart config...\n*\n"));
497 rootEntry = menu_get_parent_menu(menu);
498 if (input_mode == dont_ask)
499 fprintf(stderr,"CONFIG_%s\n",sym->name);
505 for (child = menu->list; child; child = child->next)
509 int main(int ac, char **av)
515 if (ac > i && av[i][0] == '-') {
516 switch (av[i++][1]) {
518 input_mode = ask_new;
521 input_mode = dont_ask;
524 input_mode = ask_silent;
525 valid_stdin = isatty(0) && isatty(1) && isatty(2);
528 input_mode = set_default;
531 input_mode = set_default;
532 defconfig_file = av[i++];
533 if (!defconfig_file) {
534 printf(_("%s: No default config file specified\n"),
543 input_mode = set_mod;
546 input_mode = set_yes;
549 input_mode = set_random;
554 fprintf(stderr, "See README for usage info\n");
560 printf(_("%s: Kconfig file missing\n"), av[0]);
565 switch (input_mode) {
568 defconfig_file = conf_get_default_confname();
569 if (conf_read(defconfig_file)) {
571 "*** Can't find default configuration \"%s\"!\n"
572 "***\n", defconfig_file);
577 if (stat(".config", &tmpstat)) {
579 "*** You have not yet configured your kernel!\n"
581 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
582 "*** \"make menuconfig\" or \"make xconfig\").\n"
595 name = getenv("KCONFIG_ALLCONFIG");
596 if (name && !stat(name, &tmpstat)) {
597 conf_read_simple(name, S_DEF_USER);
600 switch (input_mode) {
601 case set_no: name = "allno.config"; break;
602 case set_mod: name = "allmod.config"; break;
603 case set_yes: name = "allyes.config"; break;
604 case set_random: name = "allrandom.config"; break;
607 if (!stat(name, &tmpstat))
608 conf_read_simple(name, S_DEF_USER);
609 else if (!stat("all.config", &tmpstat))
610 conf_read_simple("all.config", S_DEF_USER);
616 if (input_mode != ask_silent) {
617 rootEntry = &rootmenu;
619 if (input_mode == ask_all) {
620 input_mode = ask_silent;
623 } else if (conf_get_changed()) {
624 name = getenv("KCONFIG_NOSILENTUPDATE");
626 fprintf(stderr, _("\n*** Kernel configuration requires explicit update.\n\n"));
634 check_conf(&rootmenu);
635 } while ((conf_cnt) && (input_mode != dont_ask));
636 if (conf_write(NULL)) {
637 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
641 if (input_mode == ask_silent && conf_write_autoconf()) {
642 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));