2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
15 #define LKC_DIRECT_LINK
18 static void conf(struct menu
*menu
);
19 static void check_conf(struct menu
*menu
);
30 } input_mode
= ask_all
;
33 static int indent
= 1;
34 static int valid_stdin
= 1;
36 static char line
[128];
37 static struct menu
*rootEntry
;
39 static char nohelp_text
[] = N_("Sorry, no help available for this option yet.\n");
41 static const char *get_help(struct menu
*menu
)
43 if (menu_has_help(menu
))
44 return _(menu_get_help(menu
));
49 static void strip(char *str
)
58 memmove(str
, p
, l
+ 1);
66 static void check_stdin(void)
68 if (!valid_stdin
&& input_mode
== ask_silent
) {
69 printf(_("aborted!\n\n"));
70 printf(_("Console input/output is redirected. "));
71 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
76 static int conf_askvalue(struct symbol
*sym
, const char *def
)
78 enum symbol_type type
= sym_get_type(sym
);
81 if (!sym_has_value(sym
))
87 if (!sym_is_changable(sym
)) {
99 if (sym_has_value(sym
)) {
106 if (sym_has_value(sym
)) {
113 fgets(line
, 128, stdin
);
131 switch (input_mode
) {
133 if (sym_tristate_within_range(sym
, yes
)) {
140 if (type
== S_TRISTATE
) {
141 if (sym_tristate_within_range(sym
, mod
)) {
148 if (sym_tristate_within_range(sym
, yes
)) {
156 if (sym_tristate_within_range(sym
, no
)) {
164 val
= (tristate
)(rand() % 3);
165 } while (!sym_tristate_within_range(sym
, val
));
167 case no
: line
[0] = 'n'; break;
168 case mod
: line
[0] = 'm'; break;
169 case yes
: line
[0] = 'y'; break;
181 int conf_string(struct menu
*menu
)
183 struct symbol
*sym
= menu
->sym
;
187 printf("%*s%s ", indent
- 1, "", _(menu
->prompt
->text
));
188 printf("(%s) ", sym
->name
);
189 def
= sym_get_string_value(sym
);
190 if (sym_get_string_value(sym
))
191 printf("[%s] ", def
);
192 if (!conf_askvalue(sym
, def
))
199 if (line
[1] == '\n') {
200 printf("\n%s\n", get_help(menu
));
205 line
[strlen(line
)-1] = 0;
208 if (def
&& sym_set_string_value(sym
, def
))
213 static int conf_sym(struct menu
*menu
)
215 struct symbol
*sym
= menu
->sym
;
217 tristate oldval
, newval
;
220 printf("%*s%s ", indent
- 1, "", _(menu
->prompt
->text
));
222 printf("(%s) ", sym
->name
);
223 type
= sym_get_type(sym
);
225 oldval
= sym_get_tristate_value(sym
);
237 if (oldval
!= no
&& sym_tristate_within_range(sym
, no
))
239 if (oldval
!= mod
&& sym_tristate_within_range(sym
, mod
))
241 if (oldval
!= yes
&& sym_tristate_within_range(sym
, yes
))
243 if (menu_has_help(menu
))
246 if (!conf_askvalue(sym
, sym_get_string_value(sym
)))
254 if (!line
[1] || !strcmp(&line
[1], "o"))
266 if (!line
[1] || !strcmp(&line
[1], "es"))
277 if (sym_set_tristate_value(sym
, newval
))
280 printf("\n%s\n", get_help(menu
));
284 static int conf_choice(struct menu
*menu
)
286 struct symbol
*sym
, *def_sym
;
292 type
= sym_get_type(sym
);
293 is_new
= !sym_has_value(sym
);
294 if (sym_is_changable(sym
)) {
297 switch (sym_get_tristate_value(sym
)) {
306 switch (sym_get_tristate_value(sym
)) {
310 printf("%*s%s\n", indent
- 1, "", _(menu_get_prompt(menu
)));
320 printf("%*s%s\n", indent
- 1, "", _(menu_get_prompt(menu
)));
321 def_sym
= sym_get_choice_value(sym
);
324 for (child
= menu
->list
; child
; child
= child
->next
) {
325 if (!menu_is_visible(child
))
328 printf("%*c %s\n", indent
, '*', _(menu_get_prompt(child
)));
332 if (child
->sym
== def_sym
) {
334 printf("%*c", indent
, '>');
336 printf("%*c", indent
, ' ');
337 printf(" %d. %s", cnt
, _(menu_get_prompt(child
)));
338 if (child
->sym
->name
)
339 printf(" (%s)", child
->sym
->name
);
340 if (!sym_has_value(child
->sym
))
344 printf(_("%*schoice"), indent
- 1, "");
349 printf("[1-%d", cnt
);
350 if (menu_has_help(menu
))
353 switch (input_mode
) {
364 fgets(line
, 128, stdin
);
366 if (line
[0] == '?') {
367 printf("\n%s\n", get_help(menu
));
372 else if (isdigit(line
[0]))
379 def
= (rand() % cnt
) + 1;
390 for (child
= menu
->list
; child
; child
= child
->next
) {
391 if (!child
->sym
|| !menu_is_visible(child
))
398 if (line
[strlen(line
) - 1] == '?') {
399 printf("\n%s\n", get_help(child
));
402 sym_set_choice_value(sym
, child
->sym
);
403 for (child
= child
->list
; child
; child
= child
->next
) {
412 static void conf(struct menu
*menu
)
415 struct property
*prop
;
418 if (!menu_is_visible(menu
))
426 switch (prop
->type
) {
428 if (input_mode
== ask_silent
&& rootEntry
!= menu
) {
433 prompt
= menu_get_prompt(menu
);
435 printf("%*c\n%*c %s\n%*c\n",
437 indent
, '*', _(prompt
),
447 if (sym_is_choice(sym
)) {
449 if (sym
->curr
.tri
!= mod
)
468 for (child
= menu
->list
; child
; child
= child
->next
)
474 static void check_conf(struct menu
*menu
)
479 if (!menu_is_visible(menu
))
483 if (sym
&& !sym_has_value(sym
)) {
484 if (sym_is_changable(sym
) ||
485 (sym_is_choice(sym
) && sym_get_tristate_value(sym
) == yes
)) {
487 printf(_("*\n* Restart config...\n*\n"));
488 rootEntry
= menu_get_parent_menu(menu
);
493 for (child
= menu
->list
; child
; child
= child
->next
)
497 int main(int ac
, char **av
)
503 setlocale(LC_ALL
, "");
504 bindtextdomain(PACKAGE
, LOCALEDIR
);
507 while ((opt
= getopt(ac
, av
, "osdD:nmyrh")) != -1) {
510 input_mode
= ask_new
;
513 input_mode
= ask_silent
;
514 valid_stdin
= isatty(0) && isatty(1) && isatty(2);
517 input_mode
= set_default
;
520 input_mode
= set_default
;
521 defconfig_file
= optarg
;
527 input_mode
= set_mod
;
530 input_mode
= set_yes
;
533 input_mode
= set_random
;
537 printf(_("See README for usage info\n"));
541 fprintf(stderr
, _("See README for usage info\n"));
546 printf(_("%s: Kconfig file missing\n"), av
[0]);
552 switch (input_mode
) {
555 defconfig_file
= conf_get_default_confname();
556 if (conf_read(defconfig_file
)) {
558 "*** Can't find default configuration \"%s\"!\n"
559 "***\n"), defconfig_file
);
564 if (stat(".config", &tmpstat
)) {
566 "*** You have not yet configured your kernel!\n"
567 "*** (missing kernel .config file)\n"
569 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
570 "*** \"make menuconfig\" or \"make xconfig\").\n"
582 name
= getenv("KCONFIG_ALLCONFIG");
583 if (name
&& !stat(name
, &tmpstat
)) {
584 conf_read_simple(name
, S_DEF_USER
);
587 switch (input_mode
) {
588 case set_no
: name
= "allno.config"; break;
589 case set_mod
: name
= "allmod.config"; break;
590 case set_yes
: name
= "allyes.config"; break;
591 case set_random
: name
= "allrandom.config"; break;
594 if (!stat(name
, &tmpstat
))
595 conf_read_simple(name
, S_DEF_USER
);
596 else if (!stat("all.config", &tmpstat
))
597 conf_read_simple("all.config", S_DEF_USER
);
603 if (input_mode
!= ask_silent
) {
604 rootEntry
= &rootmenu
;
606 if (input_mode
== ask_all
) {
607 input_mode
= ask_silent
;
610 } else if (conf_get_changed()) {
611 name
= getenv("KCONFIG_NOSILENTUPDATE");
613 fprintf(stderr
, _("\n*** Kernel configuration requires explicit update.\n\n"));
621 check_conf(&rootmenu
);
623 if (conf_write(NULL
)) {
624 fprintf(stderr
, _("\n*** Error during writing of the kernel configuration.\n\n"));
628 if (input_mode
== ask_silent
&& conf_write_autoconf()) {
629 fprintf(stderr
, _("\n*** Error during writing of the kernel configuration.\n\n"));