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);
122 int conf_string(struct menu *menu)
124 struct symbol *sym = menu->sym;
128 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
129 printf("(%s) ", sym->name);
130 def = sym_get_string_value(sym);
131 if (sym_get_string_value(sym))
132 printf("[%s] ", def);
133 if (!conf_askvalue(sym, def))
140 if (line[1] == '\n') {
141 printf("\n%s\n", get_help(menu));
146 line[strlen(line)-1] = 0;
149 if (def && sym_set_string_value(sym, def))
154 static int conf_sym(struct menu *menu)
156 struct symbol *sym = menu->sym;
158 tristate oldval, newval;
161 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
163 printf("(%s) ", sym->name);
164 type = sym_get_type(sym);
166 oldval = sym_get_tristate_value(sym);
178 if (oldval != no && sym_tristate_within_range(sym, no))
180 if (oldval != mod && sym_tristate_within_range(sym, mod))
182 if (oldval != yes && sym_tristate_within_range(sym, yes))
184 if (menu_has_help(menu))
187 if (!conf_askvalue(sym, sym_get_string_value(sym)))
195 if (!line[1] || !strcmp(&line[1], "o"))
207 if (!line[1] || !strcmp(&line[1], "es"))
218 if (sym_set_tristate_value(sym, newval))
221 printf("\n%s\n", get_help(menu));
225 static int conf_choice(struct menu *menu)
227 struct symbol *sym, *def_sym;
233 type = sym_get_type(sym);
234 is_new = !sym_has_value(sym);
235 if (sym_is_changable(sym)) {
238 switch (sym_get_tristate_value(sym)) {
247 switch (sym_get_tristate_value(sym)) {
251 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
261 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
262 def_sym = sym_get_choice_value(sym);
265 for (child = menu->list; child; child = child->next) {
266 if (!menu_is_visible(child))
269 printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
273 if (child->sym == def_sym) {
275 printf("%*c", indent, '>');
277 printf("%*c", indent, ' ');
278 printf(" %d. %s", cnt, _(menu_get_prompt(child)));
279 if (child->sym->name)
280 printf(" (%s)", child->sym->name);
281 if (!sym_has_value(child->sym))
285 printf(_("%*schoice"), indent - 1, "");
290 printf("[1-%d", cnt);
291 if (menu_has_help(menu))
294 switch (input_mode) {
305 fgets(line, 128, stdin);
307 if (line[0] == '?') {
308 printf("\n%s\n", get_help(menu));
313 else if (isdigit(line[0]))
323 for (child = menu->list; child; child = child->next) {
324 if (!child->sym || !menu_is_visible(child))
331 if (line[strlen(line) - 1] == '?') {
332 printf("\n%s\n", get_help(child));
335 sym_set_choice_value(sym, child->sym);
336 for (child = child->list; child; child = child->next) {
345 static void conf(struct menu *menu)
348 struct property *prop;
351 if (!menu_is_visible(menu))
359 switch (prop->type) {
361 if (input_mode == ask_silent && rootEntry != menu) {
366 prompt = menu_get_prompt(menu);
368 printf("%*c\n%*c %s\n%*c\n",
370 indent, '*', _(prompt),
380 if (sym_is_choice(sym)) {
382 if (sym->curr.tri != mod)
401 for (child = menu->list; child; child = child->next)
407 static void check_conf(struct menu *menu)
412 if (!menu_is_visible(menu))
416 if (sym && !sym_has_value(sym)) {
417 if (sym_is_changable(sym) ||
418 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
420 printf(_("*\n* Restart config...\n*\n"));
421 rootEntry = menu_get_parent_menu(menu);
426 for (child = menu->list; child; child = child->next)
430 static void conf_do_update(void)
432 /* Update until a loop caused no more changes */
435 check_conf(&rootmenu);
439 static int conf_silent_update(void)
443 if (conf_get_changed()) {
444 name = getenv("KCONFIG_NOSILENTUPDATE");
447 _("\n*** Kernel configuration requires explicit update.\n\n"));
455 static int conf_update(void)
457 rootEntry = &rootmenu;
459 if (input_mode == ask_all) {
460 input_mode = ask_silent;
467 int main(int ac, char **av)
473 setlocale(LC_ALL, "");
474 bindtextdomain(PACKAGE, LOCALEDIR);
477 while ((opt = getopt(ac, av, "osdD:nmyrh")) != -1) {
480 input_mode = ask_new;
483 input_mode = ask_silent;
484 valid_stdin = isatty(0) && isatty(1) && isatty(2);
487 input_mode = set_default;
490 input_mode = set_default;
491 defconfig_file = optarg;
497 input_mode = set_mod;
500 input_mode = set_yes;
503 input_mode = set_random;
507 printf(_("See README for usage info\n"));
511 fprintf(stderr, _("See README for usage info\n"));
516 printf(_("%s: Kconfig file missing\n"), av[0]);
522 switch (input_mode) {
525 defconfig_file = conf_get_default_confname();
526 if (conf_read(defconfig_file)) {
528 "*** Can't find default configuration \"%s\"!\n"
529 "***\n"), defconfig_file);
534 if (stat(".config", &tmpstat)) {
536 "*** You have not yet configured your kernel!\n"
537 "*** (missing kernel .config file)\n"
539 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
540 "*** \"make menuconfig\" or \"make xconfig\").\n"
552 name = getenv("KCONFIG_ALLCONFIG");
553 if (name && !stat(name, &tmpstat)) {
554 conf_read_simple(name, S_DEF_USER);
557 switch (input_mode) {
558 case set_no: name = "allno.config"; break;
559 case set_mod: name = "allmod.config"; break;
560 case set_yes: name = "allyes.config"; break;
561 case set_random: name = "allrandom.config"; break;
564 if (!stat(name, &tmpstat))
565 conf_read_simple(name, S_DEF_USER);
566 else if (!stat("all.config", &tmpstat))
567 conf_read_simple("all.config", S_DEF_USER);
572 switch (input_mode) {
574 conf_set_all_new_symbols(def_no);
577 conf_set_all_new_symbols(def_yes);
580 conf_set_all_new_symbols(def_mod);
583 conf_set_all_new_symbols(def_random);
586 conf_set_all_new_symbols(def_default);
590 if (conf_silent_update())
599 if (conf_write(NULL)) {
600 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
603 /* ask_silent is used during the build so we shall update autoconf.
604 * All other commands are only used to generate a config.
606 if (input_mode == ask_silent && conf_write_autoconf()) {
607 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));