2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
15 #define LKC_DIRECT_LINK
18 static void conf(struct menu *menu);
19 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 const char *get_help(struct menu *menu)
43 if (menu_has_help(menu))
44 return _(menu_get_help(menu));
49 static void strip(char *str)
58 memmove(str, p, l + 1);
66 static void check_stdin(void)
68 if (!valid_stdin && input_mode == ask_silent) {
69 printf(_("aborted!\n\n"));
70 printf(_("Console input/output is redirected. "));
71 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
76 static int conf_askvalue(struct symbol *sym, const char *def)
78 enum symbol_type type = sym_get_type(sym);
80 if (!sym_has_value(sym))
86 if (!sym_is_changable(sym)) {
96 if (sym_has_value(sym)) {
103 fgets(line, 128, stdin);
125 int conf_string(struct menu *menu)
127 struct symbol *sym = menu->sym;
131 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
132 printf("(%s) ", sym->name);
133 def = sym_get_string_value(sym);
134 if (sym_get_string_value(sym))
135 printf("[%s] ", def);
136 if (!conf_askvalue(sym, def))
143 if (line[1] == '\n') {
144 printf("\n%s\n", get_help(menu));
149 line[strlen(line)-1] = 0;
152 if (def && sym_set_string_value(sym, def))
157 static int conf_sym(struct menu *menu)
159 struct symbol *sym = menu->sym;
161 tristate oldval, newval;
164 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
166 printf("(%s) ", sym->name);
167 type = sym_get_type(sym);
169 oldval = sym_get_tristate_value(sym);
181 if (oldval != no && sym_tristate_within_range(sym, no))
183 if (oldval != mod && sym_tristate_within_range(sym, mod))
185 if (oldval != yes && sym_tristate_within_range(sym, yes))
187 if (menu_has_help(menu))
190 if (!conf_askvalue(sym, sym_get_string_value(sym)))
198 if (!line[1] || !strcmp(&line[1], "o"))
210 if (!line[1] || !strcmp(&line[1], "es"))
221 if (sym_set_tristate_value(sym, newval))
224 printf("\n%s\n", get_help(menu));
228 static int conf_choice(struct menu *menu)
230 struct symbol *sym, *def_sym;
236 type = sym_get_type(sym);
237 is_new = !sym_has_value(sym);
238 if (sym_is_changable(sym)) {
241 switch (sym_get_tristate_value(sym)) {
250 switch (sym_get_tristate_value(sym)) {
254 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
264 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
265 def_sym = sym_get_choice_value(sym);
268 for (child = menu->list; child; child = child->next) {
269 if (!menu_is_visible(child))
272 printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
276 if (child->sym == def_sym) {
278 printf("%*c", indent, '>');
280 printf("%*c", indent, ' ');
281 printf(" %d. %s", cnt, _(menu_get_prompt(child)));
282 if (child->sym->name)
283 printf(" (%s)", child->sym->name);
284 if (!sym_has_value(child->sym))
288 printf(_("%*schoice"), indent - 1, "");
293 printf("[1-%d", cnt);
294 if (menu_has_help(menu))
297 switch (input_mode) {
308 fgets(line, 128, stdin);
310 if (line[0] == '?') {
311 printf("\n%s\n", get_help(menu));
316 else if (isdigit(line[0]))
330 for (child = menu->list; child; child = child->next) {
331 if (!child->sym || !menu_is_visible(child))
338 if (line[strlen(line) - 1] == '?') {
339 printf("\n%s\n", get_help(child));
342 sym_set_choice_value(sym, child->sym);
343 for (child = child->list; child; child = child->next) {
352 static void conf(struct menu *menu)
355 struct property *prop;
358 if (!menu_is_visible(menu))
366 switch (prop->type) {
368 if (input_mode == ask_silent && rootEntry != menu) {
373 prompt = menu_get_prompt(menu);
375 printf("%*c\n%*c %s\n%*c\n",
377 indent, '*', _(prompt),
387 if (sym_is_choice(sym)) {
389 if (sym->curr.tri != mod)
408 for (child = menu->list; child; child = child->next)
414 static void check_conf(struct menu *menu)
419 if (!menu_is_visible(menu))
423 if (sym && !sym_has_value(sym)) {
424 if (sym_is_changable(sym) ||
425 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
427 printf(_("*\n* Restart config...\n*\n"));
428 rootEntry = menu_get_parent_menu(menu);
433 for (child = menu->list; child; child = child->next)
437 static void conf_do_update(void)
439 /* Update until a loop caused no more changes */
442 check_conf(&rootmenu);
446 static int conf_silent_update(void)
450 if (conf_get_changed()) {
451 name = getenv("KCONFIG_NOSILENTUPDATE");
454 _("\n*** Kernel configuration requires explicit update.\n\n"));
462 static int conf_update(void)
464 rootEntry = &rootmenu;
466 if (input_mode == ask_all) {
467 input_mode = ask_silent;
474 int main(int ac, char **av)
480 setlocale(LC_ALL, "");
481 bindtextdomain(PACKAGE, LOCALEDIR);
484 while ((opt = getopt(ac, av, "osdD:nmyrh")) != -1) {
487 input_mode = ask_new;
490 input_mode = ask_silent;
491 valid_stdin = isatty(0) && isatty(1) && isatty(2);
494 input_mode = set_default;
497 input_mode = set_default;
498 defconfig_file = optarg;
504 input_mode = set_mod;
507 input_mode = set_yes;
510 input_mode = set_random;
514 printf(_("See README for usage info\n"));
518 fprintf(stderr, _("See README for usage info\n"));
523 printf(_("%s: Kconfig file missing\n"), av[0]);
529 switch (input_mode) {
532 defconfig_file = conf_get_default_confname();
533 if (conf_read(defconfig_file)) {
535 "*** Can't find default configuration \"%s\"!\n"
536 "***\n"), defconfig_file);
541 if (stat(".config", &tmpstat)) {
543 "*** You have not yet configured your kernel!\n"
544 "*** (missing kernel .config file)\n"
546 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
547 "*** \"make menuconfig\" or \"make xconfig\").\n"
559 name = getenv("KCONFIG_ALLCONFIG");
560 if (name && !stat(name, &tmpstat)) {
561 conf_read_simple(name, S_DEF_USER);
564 switch (input_mode) {
565 case set_no: name = "allno.config"; break;
566 case set_mod: name = "allmod.config"; break;
567 case set_yes: name = "allyes.config"; break;
568 case set_random: name = "allrandom.config"; break;
571 if (!stat(name, &tmpstat))
572 conf_read_simple(name, S_DEF_USER);
573 else if (!stat("all.config", &tmpstat))
574 conf_read_simple("all.config", S_DEF_USER);
579 switch (input_mode) {
581 conf_set_all_new_symbols(def_no);
584 conf_set_all_new_symbols(def_yes);
587 conf_set_all_new_symbols(def_mod);
590 conf_set_all_new_symbols(def_random);
593 if (conf_silent_update())
604 if (conf_get_changed() && conf_write(NULL)) {
605 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
608 /* ask_silent is used during the build so we shall update autoconf.
609 * All other commands are only used to generate a config.
611 if (input_mode == ask_silent && conf_write_autoconf()) {
612 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));