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 setlocale(LC_ALL
, "");
439 bindtextdomain(PACKAGE
, LOCALEDIR
);
442 while ((opt
= getopt(ac
, av
, "osdD:nmyrh")) != -1) {
445 input_mode
= ask_silent
;
448 input_mode
= ask_silent
;
452 input_mode
= set_default
;
455 input_mode
= set_default
;
456 defconfig_file
= optarg
;
462 input_mode
= set_mod
;
465 input_mode
= set_yes
;
473 * Use microseconds derived seed,
474 * compensate for systems where it may be zero
476 gettimeofday(&now
, NULL
);
478 seed
= (unsigned int)((now
.tv_sec
+ 1) * (now
.tv_usec
+ 1));
481 input_mode
= set_random
;
485 printf(_("See README for usage info\n"));
489 fprintf(stderr
, _("See README for usage info\n"));
494 printf(_("%s: Kconfig file missing\n"), av
[0]);
501 if (stat(".config", &tmpstat
)) {
502 fprintf(stderr
, _("***\n"
503 "*** You have not yet configured your kernel!\n"
504 "*** (missing kernel .config file)\n"
506 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
507 "*** \"make menuconfig\" or \"make xconfig\").\n"
513 switch (input_mode
) {
516 defconfig_file
= conf_get_default_confname();
517 if (conf_read(defconfig_file
)) {
519 "*** Can't find default configuration \"%s\"!\n"
520 "***\n"), defconfig_file
);
533 name
= getenv("KCONFIG_ALLCONFIG");
534 if (name
&& !stat(name
, &tmpstat
)) {
535 conf_read_simple(name
, S_DEF_USER
);
538 switch (input_mode
) {
539 case set_no
: name
= "allno.config"; break;
540 case set_mod
: name
= "allmod.config"; break;
541 case set_yes
: name
= "allyes.config"; break;
542 case set_random
: name
= "allrandom.config"; break;
545 if (!stat(name
, &tmpstat
))
546 conf_read_simple(name
, S_DEF_USER
);
547 else if (!stat("all.config", &tmpstat
))
548 conf_read_simple("all.config", S_DEF_USER
);
555 if (conf_get_changed()) {
556 name
= getenv("KCONFIG_NOSILENTUPDATE");
559 _("\n*** Kernel configuration requires explicit update.\n\n"));
563 valid_stdin
= isatty(0) && isatty(1) && isatty(2);
566 switch (input_mode
) {
568 conf_set_all_new_symbols(def_no
);
571 conf_set_all_new_symbols(def_yes
);
574 conf_set_all_new_symbols(def_mod
);
577 conf_set_all_new_symbols(def_random
);
580 conf_set_all_new_symbols(def_default
);
584 rootEntry
= &rootmenu
;
586 input_mode
= ask_silent
;
589 /* Update until a loop caused no more changes */
592 check_conf(&rootmenu
);
598 /* silentoldconfig is used during the build so we shall update autoconf.
599 * All other commands are only used to generate a config.
601 if (conf_get_changed() && conf_write(NULL
)) {
602 fprintf(stderr
, _("\n*** Error during writing of the kernel configuration.\n\n"));
605 if (conf_write_autoconf()) {
606 fprintf(stderr
, _("\n*** Error during update of the kernel configuration.\n\n"));
610 if (conf_write(NULL
)) {
611 fprintf(stderr
, _("\n*** Error during writing of the kernel configuration.\n\n"));