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 void strip(char *str)
49 memmove(str, p, l + 1);
57 static void check_stdin(void)
59 if (!valid_stdin && input_mode == ask_silent) {
60 printf(_("aborted!\n\n"));
61 printf(_("Console input/output is redirected. "));
62 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
67 static char *fgets_check_stream(char *s, int size, FILE *stream)
69 char *ret = fgets(s, size, stream);
71 if (ret == NULL && feof(stream)) {
72 printf(_("aborted!\n\n"));
73 printf(_("Console input is closed. "));
74 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
81 static void conf_askvalue(struct symbol *sym, const char *def)
83 enum symbol_type type = sym_get_type(sym);
86 if (!sym_has_value(sym))
92 if (!sym_is_changable(sym)) {
104 if (sym_has_value(sym)) {
111 if (sym_has_value(sym)) {
118 fgets_check_stream(line, 128, stdin);
136 switch (input_mode) {
138 if (sym_tristate_within_range(sym, yes)) {
145 if (type == S_TRISTATE) {
146 if (sym_tristate_within_range(sym, mod)) {
153 if (sym_tristate_within_range(sym, yes)) {
161 if (sym_tristate_within_range(sym, no)) {
169 val = (tristate)(random() % 3);
170 } while (!sym_tristate_within_range(sym, val));
172 case no: line[0] = 'n'; break;
173 case mod: line[0] = 'm'; break;
174 case yes: line[0] = 'y'; break;
185 int conf_string(struct menu *menu)
187 struct symbol *sym = menu->sym;
188 const char *def, *help;
191 printf("%*s%s ", indent - 1, "", menu->prompt->text);
192 printf("(%s) ", sym->name);
193 def = sym_get_string_value(sym);
194 if (sym_get_string_value(sym))
195 printf("[%s] ", def);
196 conf_askvalue(sym, def);
202 if (line[1] == '\n') {
205 help = menu->sym->help;
206 printf("\n%s\n", menu->sym->help);
211 line[strlen(line)-1] = 0;
214 if (def && sym_set_string_value(sym, def))
219 static int conf_sym(struct menu *menu)
221 struct symbol *sym = menu->sym;
223 tristate oldval, newval;
227 printf("%*s%s ", indent - 1, "", menu->prompt->text);
229 printf("(%s) ", sym->name);
230 type = sym_get_type(sym);
232 oldval = sym_get_tristate_value(sym);
244 if (oldval != no && sym_tristate_within_range(sym, no))
246 if (oldval != mod && sym_tristate_within_range(sym, mod))
248 if (oldval != yes && sym_tristate_within_range(sym, yes))
253 conf_askvalue(sym, sym_get_string_value(sym));
260 if (!line[1] || !strcmp(&line[1], "o"))
272 if (!line[1] || !strcmp(&line[1], "es"))
283 if (sym_set_tristate_value(sym, newval))
289 printf("\n%s\n", help);
293 static int conf_choice(struct menu *menu)
295 struct symbol *sym, *def_sym;
301 type = sym_get_type(sym);
302 is_new = !sym_has_value(sym);
303 if (sym_is_changable(sym)) {
306 switch (sym_get_tristate_value(sym)) {
315 switch (sym_get_tristate_value(sym)) {
319 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
329 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
330 def_sym = sym_get_choice_value(sym);
333 for (child = menu->list; child; child = child->next) {
334 if (!menu_is_visible(child))
337 printf("%*c %s\n", indent, '*', menu_get_prompt(child));
341 if (child->sym == def_sym) {
343 printf("%*c", indent, '>');
345 printf("%*c", indent, ' ');
346 printf(" %d. %s", cnt, menu_get_prompt(child));
347 if (child->sym->name)
348 printf(" (%s)", child->sym->name);
349 if (!sym_has_value(child->sym))
353 printf("%*schoice", indent - 1, "");
358 printf("[1-%d", cnt);
362 switch (input_mode) {
373 fgets_check_stream(line, 128, stdin);
375 if (line[0] == '?') {
376 printf("\n%s\n", menu->sym->help ?
377 menu->sym->help : nohelp_text);
382 else if (isdigit(line[0]))
388 def = (random() % cnt) + 1;
399 for (child = menu->list; child; child = child->next) {
400 if (!child->sym || !menu_is_visible(child))
407 if (line[strlen(line) - 1] == '?') {
408 printf("\n%s\n", child->sym->help ?
409 child->sym->help : nohelp_text);
412 sym_set_choice_value(sym, child->sym);
422 static void conf(struct menu *menu)
425 struct property *prop;
428 if (!menu_is_visible(menu))
436 switch (prop->type) {
438 if (input_mode == ask_silent && rootEntry != menu) {
443 prompt = menu_get_prompt(menu);
445 printf("%*c\n%*c %s\n%*c\n",
457 if (sym_is_choice(sym)) {
459 if (sym->curr.tri != mod)
478 for (child = menu->list; child; child = child->next)
484 static void check_conf(struct menu *menu)
489 if (!menu_is_visible(menu))
493 if (sym && !sym_has_value(sym)) {
494 if (sym_is_changable(sym) ||
495 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
497 printf(_("*\n* Restart config...\n*\n"));
498 rootEntry = menu_get_parent_menu(menu);
503 for (child = menu->list; child; child = child->next)
507 int main(int ac, char **av)
513 if (ac > i && av[i][0] == '-') {
514 switch (av[i++][1]) {
516 input_mode = ask_new;
519 input_mode = ask_silent;
520 valid_stdin = isatty(0) && isatty(1) && isatty(2);
523 input_mode = set_default;
526 input_mode = set_default;
527 defconfig_file = av[i++];
528 if (!defconfig_file) {
529 printf(_("%s: No default config file specified\n"),
538 input_mode = set_mod;
541 input_mode = set_yes;
544 input_mode = set_random;
549 fprintf(stderr, "See README for usage info\n");
555 printf(_("%s: Kconfig file missing\n"), av[0]);
559 switch (input_mode) {
562 defconfig_file = conf_get_default_confname();
563 if (conf_read(defconfig_file)) {
565 "*** Can't find default configuration \"%s\"!\n"
566 "***\n", defconfig_file);
571 if (stat(".config", &tmpstat)) {
573 "*** You have not yet configured your kernel!\n"
575 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
576 "*** \"make menuconfig\" or \"make xconfig\").\n"
588 name = getenv("KCONFIG_ALLCONFIG");
589 if (name && !stat(name, &tmpstat)) {
590 conf_read_simple(name);
593 switch (input_mode) {
594 case set_no: name = "allno.config"; break;
595 case set_mod: name = "allmod.config"; break;
596 case set_yes: name = "allyes.config"; break;
597 case set_random: name = "allrandom.config"; break;
600 if (!stat(name, &tmpstat))
601 conf_read_simple(name);
602 else if (!stat("all.config", &tmpstat))
603 conf_read_simple("all.config");
609 if (input_mode != ask_silent) {
610 rootEntry = &rootmenu;
612 if (input_mode == ask_all) {
613 input_mode = ask_silent;
619 check_conf(&rootmenu);
621 if (conf_write(NULL)) {
622 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));