2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
17 #define LKC_DIRECT_LINK
20 static void conf(struct menu *menu);
21 static void check_conf(struct menu *menu);
35 } input_mode = oldaskconfig;
39 static int indent = 1;
40 static int valid_stdin = 1;
41 static int sync_kconfig;
43 static char line[128];
44 static struct menu *rootEntry;
46 static void print_help(struct menu *menu)
48 struct gstr help = str_new();
50 menu_get_ext_help(menu, &help);
52 printf("\n%s\n", str_get(&help));
56 static void strip(char *str)
65 memmove(str, p, l + 1);
73 static void check_stdin(void)
76 printf(_("aborted!\n\n"));
77 printf(_("Console input/output is redirected. "));
78 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
83 static int conf_askvalue(struct symbol *sym, const char *def)
85 enum symbol_type type = sym_get_type(sym);
87 if (!sym_has_value(sym))
93 if (!sym_is_changable(sym)) {
100 switch (input_mode) {
102 case silentoldconfig:
103 if (sym_has_value(sym)) {
110 fgets(line, 128, stdin);
129 static int conf_string(struct menu *menu)
131 struct symbol *sym = menu->sym;
135 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
136 printf("(%s) ", sym->name);
137 def = sym_get_string_value(sym);
138 if (sym_get_string_value(sym))
139 printf("[%s] ", def);
140 if (!conf_askvalue(sym, def))
147 if (line[1] == '\n') {
153 line[strlen(line)-1] = 0;
156 if (def && sym_set_string_value(sym, def))
161 static int conf_sym(struct menu *menu)
163 struct symbol *sym = menu->sym;
164 tristate oldval, newval;
167 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
169 printf("(%s) ", sym->name);
171 oldval = sym_get_tristate_value(sym);
183 if (oldval != no && sym_tristate_within_range(sym, no))
185 if (oldval != mod && sym_tristate_within_range(sym, mod))
187 if (oldval != yes && sym_tristate_within_range(sym, yes))
189 if (menu_has_help(menu))
192 if (!conf_askvalue(sym, sym_get_string_value(sym)))
200 if (!line[1] || !strcmp(&line[1], "o"))
212 if (!line[1] || !strcmp(&line[1], "es"))
223 if (sym_set_tristate_value(sym, newval))
230 static int conf_choice(struct menu *menu)
232 struct symbol *sym, *def_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) {
299 case silentoldconfig:
308 fgets(line, 128, stdin);
310 if (line[0] == '?') {
316 else if (isdigit(line[0]))
326 for (child = menu->list; child; child = child->next) {
327 if (!child->sym || !menu_is_visible(child))
334 if (line[strlen(line) - 1] == '?') {
338 sym_set_choice_value(sym, child->sym);
339 for (child = child->list; child; child = child->next) {
348 static void conf(struct menu *menu)
351 struct property *prop;
354 if (!menu_is_visible(menu))
362 switch (prop->type) {
364 if ((input_mode == silentoldconfig ||
365 input_mode == listnewconfig ||
366 input_mode == oldnoconfig) &&
372 prompt = menu_get_prompt(menu);
374 printf("%*c\n%*c %s\n%*c\n",
376 indent, '*', _(prompt),
386 if (sym_is_choice(sym)) {
388 if (sym->curr.tri != mod)
407 for (child = menu->list; child; child = child->next)
413 static void check_conf(struct menu *menu)
418 if (!menu_is_visible(menu))
422 if (sym && !sym_has_value(sym)) {
423 if (sym_is_changable(sym) ||
424 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
425 if (input_mode == listnewconfig) {
426 if (sym->name && !sym_is_choice_value(sym)) {
427 printf("CONFIG_%s\n", sym->name);
431 printf(_("*\n* Restart config...\n*\n"));
432 rootEntry = menu_get_parent_menu(menu);
438 for (child = menu->list; child; child = child->next)
442 static struct option long_opts[] = {
443 {"oldaskconfig", no_argument, NULL, oldaskconfig},
444 {"oldconfig", no_argument, NULL, oldconfig},
445 {"silentoldconfig", no_argument, NULL, silentoldconfig},
446 {"defconfig", optional_argument, NULL, defconfig},
447 {"allnoconfig", no_argument, NULL, allnoconfig},
448 {"allyesconfig", no_argument, NULL, allyesconfig},
449 {"allmodconfig", no_argument, NULL, allmodconfig},
450 {"alldefconfig", no_argument, NULL, alldefconfig},
451 {"randconfig", no_argument, NULL, randconfig},
452 {"listnewconfig", no_argument, NULL, listnewconfig},
453 {"oldnoconfig", no_argument, NULL, oldnoconfig},
457 int main(int ac, char **av)
463 setlocale(LC_ALL, "");
464 bindtextdomain(PACKAGE, LOCALEDIR);
467 while ((opt = getopt_long_only(ac, av, "", long_opts, NULL)) != -1) {
468 input_mode = (enum input_mode)opt;
470 case silentoldconfig:
474 defconfig_file = optarg;
482 * Use microseconds derived seed,
483 * compensate for systems where it may be zero
485 gettimeofday(&now, NULL);
487 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
492 fprintf(stderr, _("See README for usage info\n"));
498 printf(_("%s: Kconfig file missing\n"), av[0]);
505 name = conf_get_configname();
506 if (stat(name, &tmpstat)) {
507 fprintf(stderr, _("***\n"
508 "*** You have not yet configured your kernel!\n"
509 "*** (missing kernel config file \"%s\")\n"
511 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
512 "*** \"make menuconfig\" or \"make xconfig\").\n"
518 switch (input_mode) {
521 defconfig_file = conf_get_default_confname();
522 if (conf_read(defconfig_file)) {
524 "*** Can't find default configuration \"%s\"!\n"
525 "***\n"), defconfig_file);
529 case silentoldconfig:
541 name = getenv("KCONFIG_ALLCONFIG");
542 if (name && !stat(name, &tmpstat)) {
543 conf_read_simple(name, S_DEF_USER);
546 switch (input_mode) {
547 case allnoconfig: name = "allno.config"; break;
548 case allyesconfig: name = "allyes.config"; break;
549 case allmodconfig: name = "allmod.config"; break;
550 case alldefconfig: name = "alldef.config"; break;
551 case randconfig: name = "allrandom.config"; break;
554 if (!stat(name, &tmpstat))
555 conf_read_simple(name, S_DEF_USER);
556 else if (!stat("all.config", &tmpstat))
557 conf_read_simple("all.config", S_DEF_USER);
564 if (conf_get_changed()) {
565 name = getenv("KCONFIG_NOSILENTUPDATE");
568 _("\n*** Kernel configuration requires explicit update.\n\n"));
572 valid_stdin = isatty(0) && isatty(1) && isatty(2);
575 switch (input_mode) {
577 conf_set_all_new_symbols(def_no);
580 conf_set_all_new_symbols(def_yes);
583 conf_set_all_new_symbols(def_mod);
586 conf_set_all_new_symbols(def_default);
589 conf_set_all_new_symbols(def_random);
592 conf_set_all_new_symbols(def_default);
596 rootEntry = &rootmenu;
598 input_mode = silentoldconfig;
602 case silentoldconfig:
603 /* Update until a loop caused no more changes */
606 check_conf(&rootmenu);
608 (input_mode != listnewconfig &&
609 input_mode != oldnoconfig));
614 /* silentoldconfig is used during the build so we shall update autoconf.
615 * All other commands are only used to generate a config.
617 if (conf_get_changed() && conf_write(NULL)) {
618 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
621 if (conf_write_autoconf()) {
622 fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
625 } else if (input_mode != listnewconfig) {
626 if (conf_write(NULL)) {
627 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));