2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
14 #define LKC_DIRECT_LINK
17 static void conf(struct menu
*menu
);
18 static void check_conf(struct menu
*menu
);
29 } input_mode
= ask_all
;
32 static int indent
= 1;
33 static int valid_stdin
= 1;
35 static char line
[128];
36 static struct menu
*rootEntry
;
38 static char nohelp_text
[] = N_("Sorry, no help available for this option yet.\n");
40 static void strip(char *str
)
49 memmove(str
, p
, l
+ 1);
57 static void check_stdin(void)
59 if (!valid_stdin
&& input_mode
== ask_silent
) {
60 printf(_("aborted!\n\n"));
61 printf(_("Console input/output is redirected. "));
62 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
67 static int conf_askvalue(struct symbol
*sym
, const char *def
)
69 enum symbol_type type
= sym_get_type(sym
);
72 if (!sym_has_value(sym
))
78 if (!sym_is_changable(sym
)) {
90 if (sym_has_value(sym
)) {
97 if (sym_has_value(sym
)) {
104 fgets(line
, 128, stdin
);
122 switch (input_mode
) {
124 if (sym_tristate_within_range(sym
, yes
)) {
131 if (type
== S_TRISTATE
) {
132 if (sym_tristate_within_range(sym
, mod
)) {
139 if (sym_tristate_within_range(sym
, yes
)) {
147 if (sym_tristate_within_range(sym
, no
)) {
155 val
= (tristate
)(random() % 3);
156 } while (!sym_tristate_within_range(sym
, val
));
158 case no
: line
[0] = 'n'; break;
159 case mod
: line
[0] = 'm'; break;
160 case yes
: line
[0] = 'y'; break;
172 int conf_string(struct menu
*menu
)
174 struct symbol
*sym
= menu
->sym
;
175 const char *def
, *help
;
178 printf("%*s%s ", indent
- 1, "", menu
->prompt
->text
);
179 printf("(%s) ", sym
->name
);
180 def
= sym_get_string_value(sym
);
181 if (sym_get_string_value(sym
))
182 printf("[%s] ", def
);
183 if (!conf_askvalue(sym
, def
))
190 if (line
[1] == '\n') {
193 help
= menu
->sym
->help
;
194 printf("\n%s\n", menu
->sym
->help
);
199 line
[strlen(line
)-1] = 0;
202 if (def
&& sym_set_string_value(sym
, def
))
207 static int conf_sym(struct menu
*menu
)
209 struct symbol
*sym
= menu
->sym
;
211 tristate oldval
, newval
;
215 printf("%*s%s ", indent
- 1, "", menu
->prompt
->text
);
217 printf("(%s) ", sym
->name
);
218 type
= sym_get_type(sym
);
220 oldval
= sym_get_tristate_value(sym
);
232 if (oldval
!= no
&& sym_tristate_within_range(sym
, no
))
234 if (oldval
!= mod
&& sym_tristate_within_range(sym
, mod
))
236 if (oldval
!= yes
&& sym_tristate_within_range(sym
, yes
))
241 if (!conf_askvalue(sym
, sym_get_string_value(sym
)))
249 if (!line
[1] || !strcmp(&line
[1], "o"))
261 if (!line
[1] || !strcmp(&line
[1], "es"))
272 if (sym_set_tristate_value(sym
, newval
))
278 printf("\n%s\n", help
);
282 static int conf_choice(struct menu
*menu
)
284 struct symbol
*sym
, *def_sym
;
290 type
= sym_get_type(sym
);
291 is_new
= !sym_has_value(sym
);
292 if (sym_is_changable(sym
)) {
295 switch (sym_get_tristate_value(sym
)) {
304 switch (sym_get_tristate_value(sym
)) {
308 printf("%*s%s\n", indent
- 1, "", menu_get_prompt(menu
));
318 printf("%*s%s\n", indent
- 1, "", menu_get_prompt(menu
));
319 def_sym
= sym_get_choice_value(sym
);
322 for (child
= menu
->list
; child
; child
= child
->next
) {
323 if (!menu_is_visible(child
))
326 printf("%*c %s\n", indent
, '*', menu_get_prompt(child
));
330 if (child
->sym
== def_sym
) {
332 printf("%*c", indent
, '>');
334 printf("%*c", indent
, ' ');
335 printf(" %d. %s", cnt
, menu_get_prompt(child
));
336 if (child
->sym
->name
)
337 printf(" (%s)", child
->sym
->name
);
338 if (!sym_has_value(child
->sym
))
342 printf("%*schoice", indent
- 1, "");
347 printf("[1-%d", cnt
);
351 switch (input_mode
) {
362 fgets(line
, 128, stdin
);
364 if (line
[0] == '?') {
365 printf("\n%s\n", menu
->sym
->help
?
366 menu
->sym
->help
: nohelp_text
);
371 else if (isdigit(line
[0]))
377 def
= (random() % cnt
) + 1;
388 for (child
= menu
->list
; child
; child
= child
->next
) {
389 if (!child
->sym
|| !menu_is_visible(child
))
396 if (line
[strlen(line
) - 1] == '?') {
397 printf("\n%s\n", child
->sym
->help
?
398 child
->sym
->help
: nohelp_text
);
401 sym_set_choice_value(sym
, child
->sym
);
411 static void conf(struct menu
*menu
)
414 struct property
*prop
;
417 if (!menu_is_visible(menu
))
425 switch (prop
->type
) {
427 if (input_mode
== ask_silent
&& rootEntry
!= menu
) {
432 prompt
= menu_get_prompt(menu
);
434 printf("%*c\n%*c %s\n%*c\n",
446 if (sym_is_choice(sym
)) {
448 if (sym
->curr
.tri
!= mod
)
467 for (child
= menu
->list
; child
; child
= child
->next
)
473 static void check_conf(struct menu
*menu
)
478 if (!menu_is_visible(menu
))
482 if (sym
&& !sym_has_value(sym
)) {
483 if (sym_is_changable(sym
) ||
484 (sym_is_choice(sym
) && sym_get_tristate_value(sym
) == yes
)) {
486 printf(_("*\n* Restart config...\n*\n"));
487 rootEntry
= menu_get_parent_menu(menu
);
492 for (child
= menu
->list
; child
; child
= child
->next
)
496 int main(int ac
, char **av
)
502 if (ac
> i
&& av
[i
][0] == '-') {
503 switch (av
[i
++][1]) {
505 input_mode
= ask_new
;
508 input_mode
= ask_silent
;
509 valid_stdin
= isatty(0) && isatty(1) && isatty(2);
512 input_mode
= set_default
;
515 input_mode
= set_default
;
516 defconfig_file
= av
[i
++];
517 if (!defconfig_file
) {
518 printf(_("%s: No default config file specified\n"),
527 input_mode
= set_mod
;
530 input_mode
= set_yes
;
533 input_mode
= set_random
;
538 fprintf(stderr
, "See README for usage info\n");
544 printf(_("%s: Kconfig file missing\n"), av
[0]);
549 switch (input_mode
) {
552 defconfig_file
= conf_get_default_confname();
553 if (conf_read(defconfig_file
)) {
555 "*** Can't find default configuration \"%s\"!\n"
556 "***\n", defconfig_file
);
561 if (stat(".config", &tmpstat
)) {
563 "*** You have not yet configured your kernel!\n"
564 "*** (missing kernel .config file)\n"
566 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
567 "*** \"make menuconfig\" or \"make xconfig\").\n"
579 name
= getenv("KCONFIG_ALLCONFIG");
580 if (name
&& !stat(name
, &tmpstat
)) {
581 conf_read_simple(name
, S_DEF_USER
);
584 switch (input_mode
) {
585 case set_no
: name
= "allno.config"; break;
586 case set_mod
: name
= "allmod.config"; break;
587 case set_yes
: name
= "allyes.config"; break;
588 case set_random
: name
= "allrandom.config"; break;
591 if (!stat(name
, &tmpstat
))
592 conf_read_simple(name
, S_DEF_USER
);
593 else if (!stat("all.config", &tmpstat
))
594 conf_read_simple("all.config", S_DEF_USER
);
600 if (input_mode
!= ask_silent
) {
601 rootEntry
= &rootmenu
;
603 if (input_mode
== ask_all
) {
604 input_mode
= ask_silent
;
607 } else if (conf_get_changed()) {
608 name
= getenv("KCONFIG_NOSILENTUPDATE");
610 fprintf(stderr
, _("\n*** Kernel configuration requires explicit update.\n\n"));
618 check_conf(&rootmenu
);
620 if (conf_write(NULL
)) {
621 fprintf(stderr
, _("\n*** Error during writing of the kernel configuration.\n\n"));
625 if (input_mode
== ask_silent
&& conf_write_autoconf()) {
626 fprintf(stderr
, _("\n*** Error during writing of the kernel configuration.\n\n"));