2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
16 #define LKC_DIRECT_LINK
19 static void conf(struct menu
*menu
);
20 static void check_conf(struct menu
*menu
);
31 } input_mode
= ask_all
;
34 static int indent
= 1;
35 static int valid_stdin
= 1;
36 static int sync_kconfig
;
38 static char line
[128];
39 static struct menu
*rootEntry
;
41 static char nohelp_text
[] = N_("Sorry, no help available for this option yet.\n");
43 static const char *get_help(struct menu
*menu
)
45 if (menu_has_help(menu
))
46 return _(menu_get_help(menu
));
51 static void strip(char *str
)
60 memmove(str
, p
, l
+ 1);
68 static void check_stdin(void)
71 printf(_("aborted!\n\n"));
72 printf(_("Console input/output is redirected. "));
73 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
78 static int conf_askvalue(struct symbol
*sym
, const char *def
)
80 enum symbol_type type
= sym_get_type(sym
);
82 if (!sym_has_value(sym
))
88 if (!sym_is_changable(sym
)) {
98 if (sym_has_value(sym
)) {
105 fgets(line
, 128, stdin
);
124 int conf_string(struct menu
*menu
)
126 struct symbol
*sym
= menu
->sym
;
130 printf("%*s%s ", indent
- 1, "", _(menu
->prompt
->text
));
131 printf("(%s) ", sym
->name
);
132 def
= sym_get_string_value(sym
);
133 if (sym_get_string_value(sym
))
134 printf("[%s] ", def
);
135 if (!conf_askvalue(sym
, def
))
142 if (line
[1] == '\n') {
143 printf("\n%s\n", get_help(menu
));
148 line
[strlen(line
)-1] = 0;
151 if (def
&& sym_set_string_value(sym
, def
))
156 static int conf_sym(struct menu
*menu
)
158 struct symbol
*sym
= menu
->sym
;
160 tristate oldval
, newval
;
163 printf("%*s%s ", indent
- 1, "", _(menu
->prompt
->text
));
165 printf("(%s) ", sym
->name
);
166 type
= sym_get_type(sym
);
168 oldval
= sym_get_tristate_value(sym
);
180 if (oldval
!= no
&& sym_tristate_within_range(sym
, no
))
182 if (oldval
!= mod
&& sym_tristate_within_range(sym
, mod
))
184 if (oldval
!= yes
&& sym_tristate_within_range(sym
, yes
))
186 if (menu_has_help(menu
))
189 if (!conf_askvalue(sym
, sym_get_string_value(sym
)))
197 if (!line
[1] || !strcmp(&line
[1], "o"))
209 if (!line
[1] || !strcmp(&line
[1], "es"))
220 if (sym_set_tristate_value(sym
, newval
))
223 printf("\n%s\n", get_help(menu
));
227 static int conf_choice(struct menu
*menu
)
229 struct symbol
*sym
, *def_sym
;
235 type
= sym_get_type(sym
);
236 is_new
= !sym_has_value(sym
);
237 if (sym_is_changable(sym
)) {
240 switch (sym_get_tristate_value(sym
)) {
249 switch (sym_get_tristate_value(sym
)) {
253 printf("%*s%s\n", indent
- 1, "", _(menu_get_prompt(menu
)));
263 printf("%*s%s\n", indent
- 1, "", _(menu_get_prompt(menu
)));
264 def_sym
= sym_get_choice_value(sym
);
267 for (child
= menu
->list
; child
; child
= child
->next
) {
268 if (!menu_is_visible(child
))
271 printf("%*c %s\n", indent
, '*', _(menu_get_prompt(child
)));
275 if (child
->sym
== def_sym
) {
277 printf("%*c", indent
, '>');
279 printf("%*c", indent
, ' ');
280 printf(" %d. %s", cnt
, _(menu_get_prompt(child
)));
281 if (child
->sym
->name
)
282 printf(" (%s)", child
->sym
->name
);
283 if (!sym_has_value(child
->sym
))
287 printf(_("%*schoice"), indent
- 1, "");
292 printf("[1-%d", cnt
);
293 if (menu_has_help(menu
))
296 switch (input_mode
) {
307 fgets(line
, 128, stdin
);
309 if (line
[0] == '?') {
310 printf("\n%s\n", get_help(menu
));
315 else if (isdigit(line
[0]))
325 for (child
= menu
->list
; child
; child
= child
->next
) {
326 if (!child
->sym
|| !menu_is_visible(child
))
333 if (line
[strlen(line
) - 1] == '?') {
334 printf("\n%s\n", get_help(child
));
337 sym_set_choice_value(sym
, child
->sym
);
338 for (child
= child
->list
; child
; child
= child
->next
) {
347 static void conf(struct menu
*menu
)
350 struct property
*prop
;
353 if (!menu_is_visible(menu
))
361 switch (prop
->type
) {
363 if (input_mode
== ask_silent
&& rootEntry
!= menu
) {
368 prompt
= menu_get_prompt(menu
);
370 printf("%*c\n%*c %s\n%*c\n",
372 indent
, '*', _(prompt
),
382 if (sym_is_choice(sym
)) {
384 if (sym
->curr
.tri
!= mod
)
403 for (child
= menu
->list
; child
; child
= child
->next
)
409 static void check_conf(struct menu
*menu
)
414 if (!menu_is_visible(menu
))
418 if (sym
&& !sym_has_value(sym
)) {
419 if (sym_is_changable(sym
) ||
420 (sym_is_choice(sym
) && sym_get_tristate_value(sym
) == yes
)) {
422 printf(_("*\n* Restart config...\n*\n"));
423 rootEntry
= menu_get_parent_menu(menu
);
428 for (child
= menu
->list
; child
; child
= child
->next
)
432 int main(int ac
, char **av
)
438 #ifndef KBUILD_NO_NLS
439 setlocale(LC_ALL
, "");
440 bindtextdomain(PACKAGE
, LOCALEDIR
);
444 while ((opt
= getopt(ac
, av
, "osdD:nmyrh")) != -1) {
447 input_mode
= ask_silent
;
450 input_mode
= ask_silent
;
454 input_mode
= set_default
;
457 input_mode
= set_default
;
458 defconfig_file
= optarg
;
464 input_mode
= set_mod
;
467 input_mode
= set_yes
;
475 * Use microseconds derived seed,
476 * compensate for systems where it may be zero
478 gettimeofday(&now
, NULL
);
480 seed
= (unsigned int)((now
.tv_sec
+ 1) * (now
.tv_usec
+ 1));
483 input_mode
= set_random
;
487 printf(_("See README for usage info\n"));
491 fprintf(stderr
, _("See README for usage info\n"));
496 printf(_("%s: Kconfig file missing\n"), av
[0]);
503 name
= conf_get_configname();
504 if (stat(name
, &tmpstat
)) {
505 fprintf(stderr
, _("***\n"
506 "*** You have not yet configured your kernel!\n"
507 "*** (missing kernel config file \"%s\")\n"
509 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
510 "*** \"make menuconfig\" or \"make xconfig\").\n"
516 switch (input_mode
) {
519 defconfig_file
= conf_get_default_confname();
520 if (conf_read(defconfig_file
)) {
522 "*** Can't find default configuration \"%s\"!\n"
523 "***\n"), defconfig_file
);
536 name
= getenv("KCONFIG_ALLCONFIG");
537 if (name
&& !stat(name
, &tmpstat
)) {
538 conf_read_simple(name
, S_DEF_USER
);
541 switch (input_mode
) {
542 case set_no
: name
= "allno.config"; break;
543 case set_mod
: name
= "allmod.config"; break;
544 case set_yes
: name
= "allyes.config"; break;
545 case set_random
: name
= "allrandom.config"; break;
548 if (!stat(name
, &tmpstat
))
549 conf_read_simple(name
, S_DEF_USER
);
550 else if (!stat("all.config", &tmpstat
))
551 conf_read_simple("all.config", S_DEF_USER
);
558 if (conf_get_changed()) {
559 name
= getenv("KCONFIG_NOSILENTUPDATE");
562 _("\n*** Kernel configuration requires explicit update.\n\n"));
566 valid_stdin
= isatty(0) && isatty(1) && isatty(2);
569 switch (input_mode
) {
571 conf_set_all_new_symbols(def_no
);
574 conf_set_all_new_symbols(def_yes
);
577 conf_set_all_new_symbols(def_mod
);
580 conf_set_all_new_symbols(def_random
);
583 conf_set_all_new_symbols(def_default
);
587 rootEntry
= &rootmenu
;
589 input_mode
= ask_silent
;
592 /* Update until a loop caused no more changes */
595 check_conf(&rootmenu
);
601 /* silentoldconfig is used during the build so we shall update autoconf.
602 * All other commands are only used to generate a config.
604 if (conf_get_changed() && conf_write(NULL
)) {
605 fprintf(stderr
, _("\n*** Error during writing of the kernel configuration.\n\n"));
608 if (conf_write_autoconf()) {
609 fprintf(stderr
, _("\n*** Error during update of the kernel configuration.\n\n"));
613 if (conf_write(NULL
)) {
614 fprintf(stderr
, _("\n*** Error during writing of the kernel configuration.\n\n"));