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 char *fgets_check_stream(char *s, int size, FILE *stream)
72 char *ret = fgets(s, size, stream);
74 if (ret == NULL && feof(stream)) {
75 printf(_("aborted!\n\n"));
76 printf(_("Console input is closed. "));
77 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
84 static void conf_askvalue(struct symbol *sym, const char *def)
86 enum symbol_type type = sym_get_type(sym);
89 if (!sym_has_value(sym))
95 if (!sym_is_changable(sym)) {
102 switch (input_mode) {
107 if (sym_has_value(sym)) {
114 if (sym_has_value(sym)) {
121 fgets_check_stream(line, 128, stdin);
124 if (!sym_has_value(sym)) {
125 fprintf(stderr,"CONFIG_%s\n",sym->name);
145 switch (input_mode) {
147 if (sym_tristate_within_range(sym, yes)) {
154 if (type == S_TRISTATE) {
155 if (sym_tristate_within_range(sym, mod)) {
162 if (sym_tristate_within_range(sym, yes)) {
170 if (sym_tristate_within_range(sym, no)) {
178 val = (tristate)(random() % 3);
179 } while (!sym_tristate_within_range(sym, val));
181 case no: line[0] = 'n'; break;
182 case mod: line[0] = 'm'; break;
183 case yes: line[0] = 'y'; break;
194 int conf_string(struct menu *menu)
196 struct symbol *sym = menu->sym;
197 const char *def, *help;
200 printf("%*s%s ", indent - 1, "", menu->prompt->text);
201 printf("(%s) ", sym->name);
202 def = sym_get_string_value(sym);
203 if (sym_get_string_value(sym))
204 printf("[%s] ", def);
205 conf_askvalue(sym, def);
211 if (line[1] == '\n') {
214 help = menu->sym->help;
215 printf("\n%s\n", menu->sym->help);
220 line[strlen(line)-1] = 0;
223 if (def && sym_set_string_value(sym, def))
228 static int conf_sym(struct menu *menu)
230 struct symbol *sym = menu->sym;
232 tristate oldval, newval;
236 printf("%*s%s ", indent - 1, "", menu->prompt->text);
238 printf("(%s) ", sym->name);
239 type = sym_get_type(sym);
241 oldval = sym_get_tristate_value(sym);
253 if (oldval != no && sym_tristate_within_range(sym, no))
255 if (oldval != mod && sym_tristate_within_range(sym, mod))
257 if (oldval != yes && sym_tristate_within_range(sym, yes))
262 conf_askvalue(sym, sym_get_string_value(sym));
269 if (!line[1] || !strcmp(&line[1], "o"))
281 if (!line[1] || !strcmp(&line[1], "es"))
292 if (sym_set_tristate_value(sym, newval))
298 printf("\n%s\n", help);
302 static int conf_choice(struct menu *menu)
304 struct symbol *sym, *def_sym;
310 type = sym_get_type(sym);
311 is_new = !sym_has_value(sym);
312 if (sym_is_changable(sym)) {
315 switch (sym_get_tristate_value(sym)) {
324 switch (sym_get_tristate_value(sym)) {
328 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
338 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
339 def_sym = sym_get_choice_value(sym);
343 for (child = menu->list; child; child = child->next) {
344 if (!menu_is_visible(child))
347 printf("%*c %s\n", indent, '*', menu_get_prompt(child));
351 if (child->sym == def_sym) {
353 printf("%*c", indent, '>');
355 printf("%*c", indent, ' ');
356 printf(" %d. %s", cnt, menu_get_prompt(child));
357 if (child->sym->name)
358 printf(" (%s)", child->sym->name);
359 if (!sym_has_value(child->sym))
363 printf("%*schoice", indent - 1, "");
368 printf("[1-%d", cnt);
372 switch (input_mode) {
387 fgets_check_stream(line, 128, stdin);
389 if (line[0] == '?') {
390 printf("\n%s\n", menu->sym->help ?
391 menu->sym->help : nohelp_text);
396 else if (isdigit(line[0]))
402 def = (random() % cnt) + 1;
413 for (child = menu->list; child; child = child->next) {
414 if (!child->sym || !menu_is_visible(child))
421 if (line[strlen(line) - 1] == '?') {
422 printf("\n%s\n", child->sym->help ?
423 child->sym->help : nohelp_text);
426 sym_set_choice_value(sym, child->sym);
436 static void conf(struct menu *menu)
439 struct property *prop;
442 if (!menu_is_visible(menu))
450 switch (prop->type) {
452 if (input_mode == ask_silent && rootEntry != menu) {
457 prompt = menu_get_prompt(menu);
459 printf("%*c\n%*c %s\n%*c\n",
471 if (sym_is_choice(sym)) {
473 if (sym->curr.tri != mod)
492 for (child = menu->list; child; child = child->next)
498 static void check_conf(struct menu *menu)
503 if (!menu_is_visible(menu))
507 if (sym && !sym_has_value(sym)) {
508 if (sym_is_changable(sym) ||
509 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
511 printf(_("*\n* Restart config...\n*\n"));
512 rootEntry = menu_get_parent_menu(menu);
513 if (input_mode == dont_ask)
514 fprintf(stderr,"CONFIG_%s\n",sym->name);
520 for (child = menu->list; child; child = child->next)
524 int main(int ac, char **av)
530 if (ac > i && av[i][0] == '-') {
531 switch (av[i++][1]) {
533 input_mode = ask_new;
536 input_mode = dont_ask;
539 input_mode = ask_silent;
540 valid_stdin = isatty(0) && 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 printf("%s [-o|-s] config\n", av[0]);
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 your kernel!\n"
595 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
596 "*** \"make menuconfig\" or \"make xconfig\").\n"
609 name = getenv("KCONFIG_ALLCONFIG");
610 if (name && !stat(name, &tmpstat)) {
611 conf_read_simple(name);
614 switch (input_mode) {
615 case set_no: name = "allno.config"; break;
616 case set_mod: name = "allmod.config"; break;
617 case set_yes: name = "allyes.config"; break;
618 case set_random: name = "allrandom.config"; break;
621 if (!stat(name, &tmpstat))
622 conf_read_simple(name);
623 else if (!stat("all.config", &tmpstat))
624 conf_read_simple("all.config");
630 if (input_mode != ask_silent) {
631 rootEntry = &rootmenu;
633 if (input_mode == ask_all) {
634 input_mode = ask_silent;
640 check_conf(&rootmenu);
641 } while ((conf_cnt) && (input_mode != dont_ask));
642 if (conf_write(NULL)) {
643 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));