2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
20 static void conf(struct menu
*menu
);
21 static void check_conf(struct menu
*menu
);
22 static void xfgets(char *str
, int size
, FILE *in
);
37 } input_mode
= oldaskconfig
;
39 static int indent
= 1;
41 static int valid_stdin
= 1;
42 static int sync_kconfig
;
44 static char line
[PATH_MAX
];
45 static struct menu
*rootEntry
;
47 static void print_help(struct menu
*menu
)
49 struct gstr help
= str_new();
51 menu_get_ext_help(menu
, &help
);
53 printf("\n%s\n", str_get(&help
));
57 static void strip(char *str
)
66 memmove(str
, p
, l
+ 1);
74 static void check_stdin(void)
77 printf(_("aborted!\n\n"));
78 printf(_("Console input/output is redirected. "));
79 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
84 static int conf_askvalue(struct symbol
*sym
, const char *def
)
86 enum symbol_type type
= sym_get_type(sym
);
88 if (!sym_has_value(sym
))
94 if (!sym_is_changable(sym
)) {
101 switch (input_mode
) {
103 case silentoldconfig
:
104 if (sym_has_value(sym
)) {
112 xfgets(line
, sizeof(line
), stdin
);
133 static int conf_string(struct menu
*menu
)
135 struct symbol
*sym
= menu
->sym
;
139 printf("%*s%s ", indent
- 1, "", _(menu
->prompt
->text
));
140 printf("(%s) ", sym
->name
);
141 def
= sym_get_string_value(sym
);
142 if (sym_get_string_value(sym
))
143 printf("[%s] ", def
);
144 if (!conf_askvalue(sym
, def
))
151 if (line
[1] == '\n') {
158 line
[strlen(line
)-1] = 0;
161 if (def
&& sym_set_string_value(sym
, def
))
166 static int conf_sym(struct menu
*menu
)
168 struct symbol
*sym
= menu
->sym
;
169 tristate oldval
, newval
;
172 printf("%*s%s ", indent
- 1, "", _(menu
->prompt
->text
));
174 printf("(%s) ", sym
->name
);
176 oldval
= sym_get_tristate_value(sym
);
188 if (oldval
!= no
&& sym_tristate_within_range(sym
, no
))
190 if (oldval
!= mod
&& sym_tristate_within_range(sym
, mod
))
192 if (oldval
!= yes
&& sym_tristate_within_range(sym
, yes
))
194 if (menu_has_help(menu
))
197 if (!conf_askvalue(sym
, sym_get_string_value(sym
)))
205 if (!line
[1] || !strcmp(&line
[1], "o"))
217 if (!line
[1] || !strcmp(&line
[1], "es"))
228 if (sym_set_tristate_value(sym
, newval
))
235 static int conf_choice(struct menu
*menu
)
237 struct symbol
*sym
, *def_sym
;
242 is_new
= !sym_has_value(sym
);
243 if (sym_is_changable(sym
)) {
246 switch (sym_get_tristate_value(sym
)) {
255 switch (sym_get_tristate_value(sym
)) {
259 printf("%*s%s\n", indent
- 1, "", _(menu_get_prompt(menu
)));
269 printf("%*s%s\n", indent
- 1, "", _(menu_get_prompt(menu
)));
270 def_sym
= sym_get_choice_value(sym
);
273 for (child
= menu
->list
; child
; child
= child
->next
) {
274 if (!menu_is_visible(child
))
277 printf("%*c %s\n", indent
, '*', _(menu_get_prompt(child
)));
281 if (child
->sym
== def_sym
) {
283 printf("%*c", indent
, '>');
285 printf("%*c", indent
, ' ');
286 printf(" %d. %s", cnt
, _(menu_get_prompt(child
)));
287 if (child
->sym
->name
)
288 printf(" (%s)", child
->sym
->name
);
289 if (!sym_has_value(child
->sym
))
293 printf(_("%*schoice"), indent
- 1, "");
298 printf("[1-%d", cnt
);
299 if (menu_has_help(menu
))
302 switch (input_mode
) {
304 case silentoldconfig
:
314 xfgets(line
, sizeof(line
), stdin
);
316 if (line
[0] == '?') {
322 else if (isdigit(line
[0]))
332 for (child
= menu
->list
; child
; child
= child
->next
) {
333 if (!child
->sym
|| !menu_is_visible(child
))
340 if (line
[0] && line
[strlen(line
) - 1] == '?') {
344 sym_set_choice_value(sym
, child
->sym
);
345 for (child
= child
->list
; child
; child
= child
->next
) {
354 static void conf(struct menu
*menu
)
357 struct property
*prop
;
360 if (!menu_is_visible(menu
))
368 switch (prop
->type
) {
370 if ((input_mode
== silentoldconfig
||
371 input_mode
== listnewconfig
||
372 input_mode
== olddefconfig
) &&
379 prompt
= menu_get_prompt(menu
);
381 printf("%*c\n%*c %s\n%*c\n",
383 indent
, '*', _(prompt
),
393 if (sym_is_choice(sym
)) {
395 if (sym
->curr
.tri
!= mod
)
414 for (child
= menu
->list
; child
; child
= child
->next
)
420 static void check_conf(struct menu
*menu
)
425 if (!menu_is_visible(menu
))
429 if (sym
&& !sym_has_value(sym
)) {
430 if (sym_is_changable(sym
) ||
431 (sym_is_choice(sym
) && sym_get_tristate_value(sym
) == yes
)) {
432 if (input_mode
== listnewconfig
) {
433 if (sym
->name
&& !sym_is_choice_value(sym
)) {
434 printf("%s%s\n", CONFIG_
, sym
->name
);
436 } else if (input_mode
!= olddefconfig
) {
438 printf(_("*\n* Restart config...\n*\n"));
439 rootEntry
= menu_get_parent_menu(menu
);
445 for (child
= menu
->list
; child
; child
= child
->next
)
449 #if 00 // || !defined __UCLIBC__ || \
450 defined __UCLIBC_HAS_GETOPT_LONG__
451 static struct option long_opts
[] = {
452 {"oldaskconfig", no_argument
, NULL
, oldaskconfig
},
453 {"oldconfig", no_argument
, NULL
, oldconfig
},
454 {"silentoldconfig", no_argument
, NULL
, silentoldconfig
},
455 {"defconfig", optional_argument
, NULL
, defconfig
},
456 {"savedefconfig", required_argument
, NULL
, savedefconfig
},
457 {"allnoconfig", no_argument
, NULL
, allnoconfig
},
458 {"allyesconfig", no_argument
, NULL
, allyesconfig
},
459 {"allmodconfig", no_argument
, NULL
, allmodconfig
},
460 {"alldefconfig", no_argument
, NULL
, alldefconfig
},
461 {"randconfig", no_argument
, NULL
, randconfig
},
462 {"listnewconfig", no_argument
, NULL
, listnewconfig
},
463 {"olddefconfig", no_argument
, NULL
, olddefconfig
},
465 * oldnoconfig is an alias of olddefconfig, because people already
466 * are dependent on its behavior(sets new symbols to their default
467 * value but not 'n') with the counter-intuitive name.
469 {"oldnoconfig", no_argument
, NULL
, olddefconfig
},
473 static void conf_usage(const char *progname
)
476 printf("Usage: %s [option] <kconfig-file>\n", progname
);
477 printf("[option] is _one_ of the following:\n");
478 printf(" --listnewconfig List new options\n");
479 printf(" --oldaskconfig Start a new configuration using a line-oriented program\n");
480 printf(" --oldconfig Update a configuration using a provided .config as base\n");
481 printf(" --silentoldconfig Same as oldconfig, but quietly, additionally update deps\n");
482 printf(" --olddefconfig Same as silentoldconfig but sets new symbols to their default value\n");
483 printf(" --oldnoconfig An alias of olddefconfig\n");
484 printf(" --defconfig <file> New config with default defined in <file>\n");
485 printf(" --savedefconfig <file> Save the minimal current configuration to <file>\n");
486 printf(" --allnoconfig New config where all options are answered with no\n");
487 printf(" --allyesconfig New config where all options are answered with yes\n");
488 printf(" --allmodconfig New config where all options are answered with mod\n");
489 printf(" --alldefconfig New config with all symbols set to default\n");
490 printf(" --randconfig New config with random answer to all options\n");
493 static void conf_usage(const char *progname
)
496 printf("Usage: %s [option] <kconfig-file>\n", progname
);
497 printf("[option] is _one_ of the following:\n");
498 printf(" -a, --oldaskconfig Start a new configuration using a line-oriented program\n");
499 printf(" -s, --silentoldconfig Same as oldconfig, but quietly, additionally update deps\n");
500 printf(" -o, --oldconfig Update a configuration using a provided .config as base\n");
501 printf(" -n, --allnoconfig New config where all options are answered with no\n");
502 printf(" -y, --allyesconfig New config where all options are answered with yes\n");
503 printf(" -m, --allmodconfig New config where all options are answered with mod\n");
504 printf(" -A, --alldefconfig New config with all symbols set to default\n");
505 printf(" -r, --randconfig New config with random answer to all options\n");
506 printf(" -D, --defconfig <file> New config with default defined in <file>\n");
507 printf(" -S, --savedefconfig <file> Save the minimal current configuration to <file>\n");
508 printf(" -l, --listnewconfig List new options\n");
509 printf(" -d, --olddefconfig Same as silentoldconfig but sets new symbols to their default value\n");
510 printf(" --oldnoconfig An alias of olddefconfig\n");
515 int main(int ac
, char **av
)
517 const char *progname
= av
[0];
519 const char *name
, *defconfig_file
= NULL
/* gcc uninit */;
522 setlocale(LC_ALL
, "");
523 bindtextdomain(PACKAGE
, LOCALEDIR
);
526 tty_stdio
= isatty(0) && isatty(1) && isatty(2);
528 #if 00// !defined __UCLIBC__ || \
529 defined __UCLIBC_HAS_GETOPT_LONG__
530 while ((opt
= getopt_long(ac
, av
, "", long_opts
, NULL
)) != -1)
532 char *gch
= "asonymArDSld";
533 while ((opt
= getopt(ac
, av
, "asonymArD:S:ldh")) != -1)
536 char *x
= memchr(gch
, opt
, strlen(gch
));
541 input_mode
= (enum input_mode
)opt
;
543 case silentoldconfig
:
548 defconfig_file
= optarg
;
557 * Use microseconds derived seed,
558 * compensate for systems where it may be zero
560 gettimeofday(&now
, NULL
);
561 seed
= (unsigned int)((now
.tv_sec
+ 1) * (now
.tv_usec
+ 1));
563 seed_env
= getenv("KCONFIG_SEED");
564 if( seed_env
&& *seed_env
) {
566 int tmp
= (int)strtol(seed_env
, &endp
, 0);
571 fprintf( stderr
, "KCONFIG_SEED=0x%X\n", seed
);
585 conf_usage(progname
);
591 printf(_("%s: Kconfig file missing\n"), av
[0]);
592 conf_usage(progname
);
599 name
= conf_get_configname();
600 if (stat(name
, &tmpstat
)) {
601 fprintf(stderr
, _("***\n"
602 "*** Configuration file \"%s\" not found!\n"
604 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
605 "*** \"make menuconfig\" or \"make xconfig\").\n"
611 switch (input_mode
) {
614 defconfig_file
= conf_get_default_confname();
615 if (conf_read(defconfig_file
)) {
617 "*** Can't find default configuration \"%s\"!\n"
618 "***\n"), defconfig_file
);
623 case silentoldconfig
:
635 name
= getenv("KCONFIG_ALLCONFIG");
638 if ((strcmp(name
, "") != 0) && (strcmp(name
, "1") != 0)) {
639 if (conf_read_simple(name
, S_DEF_USER
)) {
641 _("*** Can't read seed configuration \"%s\"!\n"),
647 switch (input_mode
) {
648 case allnoconfig
: name
= "allno.config"; break;
649 case allyesconfig
: name
= "allyes.config"; break;
650 case allmodconfig
: name
= "allmod.config"; break;
651 case alldefconfig
: name
= "alldef.config"; break;
652 case randconfig
: name
= "allrandom.config"; break;
655 if (conf_read_simple(name
, S_DEF_USER
) &&
656 conf_read_simple("all.config", S_DEF_USER
)) {
658 _("*** KCONFIG_ALLCONFIG set, but no \"%s\" or \"all.config\" file found\n"),
668 if (conf_get_changed()) {
669 name
= getenv("KCONFIG_NOSILENTUPDATE");
672 _("\n*** The configuration requires explicit update.\n\n"));
676 valid_stdin
= tty_stdio
;
679 switch (input_mode
) {
681 conf_set_all_new_symbols(def_no
);
684 conf_set_all_new_symbols(def_yes
);
687 conf_set_all_new_symbols(def_mod
);
690 conf_set_all_new_symbols(def_default
);
693 /* Really nothing to do in this loop */
694 while (conf_set_all_new_symbols(def_random
)) ;
697 conf_set_all_new_symbols(def_default
);
702 rootEntry
= &rootmenu
;
704 input_mode
= silentoldconfig
;
709 case silentoldconfig
:
710 /* Update until a loop caused no more changes */
713 check_conf(&rootmenu
);
715 (input_mode
!= listnewconfig
&&
716 input_mode
!= olddefconfig
));
721 /* silentoldconfig is used during the build so we shall update autoconf.
722 * All other commands are only used to generate a config.
724 if (conf_get_changed() && conf_write(NULL
)) {
725 fprintf(stderr
, _("\n*** Error during writing of the configuration.\n\n"));
728 if (conf_write_autoconf()) {
729 fprintf(stderr
, _("\n*** Error during update of the configuration.\n\n"));
732 } else if (input_mode
== savedefconfig
) {
733 if (conf_write_defconfig(defconfig_file
)) {
734 fprintf(stderr
, _("n*** Error while saving defconfig to: %s\n\n"),
738 } else if (input_mode
!= listnewconfig
) {
739 if (conf_write(NULL
)) {
740 fprintf(stderr
, _("\n*** Error during writing of the configuration.\n\n"));
748 * Helper function to facilitate fgets() by Jean Sacren.
750 void xfgets(char *str
, int size
, FILE *in
)
752 if (fgets(str
, size
, in
) == NULL
)
753 fprintf(stderr
, "\nError in reading or end of file.\n");