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);
29 } input_mode = ask_all;
32 static int indent = 1;
33 static int valid_stdin = 1;
35 static char line[128];
36 static struct menu *rootEntry;
38 static char nohelp_text[] = N_("Sorry, no help available for this option yet.\n");
40 static const char *get_help(struct menu *menu)
42 if (menu_has_help(menu))
43 return menu_get_help(menu);
48 static void strip(char *str)
57 memmove(str, p, l + 1);
65 static void check_stdin(void)
67 if (!valid_stdin && input_mode == ask_silent) {
68 printf(_("aborted!\n\n"));
69 printf(_("Console input/output is redirected. "));
70 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
75 static int conf_askvalue(struct symbol *sym, const char *def)
77 enum symbol_type type = sym_get_type(sym);
80 if (!sym_has_value(sym))
86 if (!sym_is_changable(sym)) {
98 if (sym_has_value(sym)) {
105 if (sym_has_value(sym)) {
112 fgets(line, 128, stdin);
130 switch (input_mode) {
132 if (sym_tristate_within_range(sym, yes)) {
139 if (type == S_TRISTATE) {
140 if (sym_tristate_within_range(sym, mod)) {
147 if (sym_tristate_within_range(sym, yes)) {
155 if (sym_tristate_within_range(sym, no)) {
163 val = (tristate)(random() % 3);
164 } while (!sym_tristate_within_range(sym, val));
166 case no: line[0] = 'n'; break;
167 case mod: line[0] = 'm'; break;
168 case yes: line[0] = 'y'; break;
180 int conf_string(struct menu *menu)
182 struct symbol *sym = menu->sym;
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 if (!conf_askvalue(sym, def))
198 if (line[1] == '\n') {
199 printf("\n%s\n", get_help(menu));
204 line[strlen(line)-1] = 0;
207 if (def && sym_set_string_value(sym, def))
212 static int conf_sym(struct menu *menu)
214 struct symbol *sym = menu->sym;
216 tristate oldval, newval;
219 printf("%*s%s ", indent - 1, "", menu->prompt->text);
221 printf("(%s) ", sym->name);
222 type = sym_get_type(sym);
224 oldval = sym_get_tristate_value(sym);
236 if (oldval != no && sym_tristate_within_range(sym, no))
238 if (oldval != mod && sym_tristate_within_range(sym, mod))
240 if (oldval != yes && sym_tristate_within_range(sym, yes))
242 if (menu_has_help(menu))
245 if (!conf_askvalue(sym, sym_get_string_value(sym)))
253 if (!line[1] || !strcmp(&line[1], "o"))
265 if (!line[1] || !strcmp(&line[1], "es"))
276 if (sym_set_tristate_value(sym, newval))
279 printf("\n%s\n", get_help(menu));
283 static int conf_choice(struct menu *menu)
285 struct symbol *sym, *def_sym;
291 type = sym_get_type(sym);
292 is_new = !sym_has_value(sym);
293 if (sym_is_changable(sym)) {
296 switch (sym_get_tristate_value(sym)) {
305 switch (sym_get_tristate_value(sym)) {
309 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
319 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
320 def_sym = sym_get_choice_value(sym);
323 for (child = menu->list; child; child = child->next) {
324 if (!menu_is_visible(child))
327 printf("%*c %s\n", indent, '*', menu_get_prompt(child));
331 if (child->sym == def_sym) {
333 printf("%*c", indent, '>');
335 printf("%*c", indent, ' ');
336 printf(" %d. %s", cnt, menu_get_prompt(child));
337 if (child->sym->name)
338 printf(" (%s)", child->sym->name);
339 if (!sym_has_value(child->sym))
343 printf("%*schoice", indent - 1, "");
348 printf("[1-%d", cnt);
349 if (menu_has_help(menu))
352 switch (input_mode) {
363 fgets(line, 128, stdin);
365 if (line[0] == '?') {
366 printf("\n%s\n", get_help(menu));
371 else if (isdigit(line[0]))
377 def = (random() % cnt) + 1;
388 for (child = menu->list; child; child = child->next) {
389 if (!child->sym || !menu_is_visible(child))
396 if (line[strlen(line) - 1] == '?') {
397 printf("\n%s\n", get_help(child));
400 sym_set_choice_value(sym, child->sym);
410 static void conf(struct menu *menu)
413 struct property *prop;
416 if (!menu_is_visible(menu))
424 switch (prop->type) {
426 if (input_mode == ask_silent && rootEntry != menu) {
431 prompt = menu_get_prompt(menu);
433 printf("%*c\n%*c %s\n%*c\n",
445 if (sym_is_choice(sym)) {
447 if (sym->curr.tri != mod)
466 for (child = menu->list; child; child = child->next)
472 static void check_conf(struct menu *menu)
477 if (!menu_is_visible(menu))
481 if (sym && !sym_has_value(sym)) {
482 if (sym_is_changable(sym) ||
483 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
485 printf(_("*\n* Restart config...\n*\n"));
486 rootEntry = menu_get_parent_menu(menu);
491 for (child = menu->list; child; child = child->next)
495 int main(int ac, char **av)
501 if (ac > i && av[i][0] == '-') {
502 switch (av[i++][1]) {
504 input_mode = ask_new;
507 input_mode = ask_silent;
508 valid_stdin = isatty(0) && isatty(1) && isatty(2);
511 input_mode = set_default;
514 input_mode = set_default;
515 defconfig_file = av[i++];
516 if (!defconfig_file) {
517 printf(_("%s: No default config file specified\n"),
526 input_mode = set_mod;
529 input_mode = set_yes;
532 input_mode = set_random;
537 fprintf(stderr, "See README for usage info\n");
543 printf(_("%s: Kconfig file missing\n"), av[0]);
548 switch (input_mode) {
551 defconfig_file = conf_get_default_confname();
552 if (conf_read(defconfig_file)) {
554 "*** Can't find default configuration \"%s\"!\n"
555 "***\n", defconfig_file);
560 if (stat(".config", &tmpstat)) {
562 "*** You have not yet configured your kernel!\n"
563 "*** (missing kernel .config file)\n"
565 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
566 "*** \"make menuconfig\" or \"make xconfig\").\n"
578 name = getenv("KCONFIG_ALLCONFIG");
579 if (name && !stat(name, &tmpstat)) {
580 conf_read_simple(name, S_DEF_USER);
583 switch (input_mode) {
584 case set_no: name = "allno.config"; break;
585 case set_mod: name = "allmod.config"; break;
586 case set_yes: name = "allyes.config"; break;
587 case set_random: name = "allrandom.config"; break;
590 if (!stat(name, &tmpstat))
591 conf_read_simple(name, S_DEF_USER);
592 else if (!stat("all.config", &tmpstat))
593 conf_read_simple("all.config", S_DEF_USER);
599 if (input_mode != ask_silent) {
600 rootEntry = &rootmenu;
602 if (input_mode == ask_all) {
603 input_mode = ask_silent;
606 } else if (conf_get_changed()) {
607 name = getenv("KCONFIG_NOSILENTUPDATE");
609 fprintf(stderr, _("\n*** Kernel configuration requires explicit update.\n\n"));
617 check_conf(&rootmenu);
619 if (conf_write(NULL)) {
620 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
624 if (input_mode == ask_silent && conf_write_autoconf()) {
625 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));