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 const char *get_help(struct menu
*menu
)
42 if (menu_has_help(menu
))
43 return menu_get_help(menu
);
48 static void strip(char *str
)
57 memmove(str
, p
, l
+ 1);
65 static void check_stdin(void)
67 if (!valid_stdin
&& input_mode
== ask_silent
) {
68 printf(_("aborted!\n\n"));
69 printf(_("Console input/output is redirected. "));
70 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
75 static void conf_askvalue(struct symbol
*sym
, const char *def
)
77 enum symbol_type type
= sym_get_type(sym
);
80 if (!sym_has_value(sym
))
86 if (!sym_is_changable(sym
)) {
98 if (sym_has_value(sym
)) {
105 if (sym_has_value(sym
)) {
112 fgets(line
, 128, stdin
);
130 switch (input_mode
) {
132 if (sym_tristate_within_range(sym
, yes
)) {
139 if (type
== S_TRISTATE
) {
140 if (sym_tristate_within_range(sym
, mod
)) {
147 if (sym_tristate_within_range(sym
, yes
)) {
155 if (sym_tristate_within_range(sym
, no
)) {
163 val
= (tristate
)(random() % 3);
164 } while (!sym_tristate_within_range(sym
, val
));
166 case no
: line
[0] = 'n'; break;
167 case mod
: line
[0] = 'm'; break;
168 case yes
: line
[0] = 'y'; break;
179 int conf_string(struct menu
*menu
)
181 struct symbol
*sym
= menu
->sym
;
185 printf("%*s%s ", indent
- 1, "", menu
->prompt
->text
);
186 printf("(%s) ", sym
->name
);
187 def
= sym_get_string_value(sym
);
188 if (sym_get_string_value(sym
))
189 printf("[%s] ", def
);
190 conf_askvalue(sym
, def
);
196 if (line
[1] == '\n') {
197 printf("\n%s\n", get_help(menu
));
202 line
[strlen(line
)-1] = 0;
205 if (def
&& sym_set_string_value(sym
, def
))
210 static int conf_sym(struct menu
*menu
)
212 struct symbol
*sym
= menu
->sym
;
214 tristate oldval
, newval
;
217 printf("%*s%s ", indent
- 1, "", menu
->prompt
->text
);
219 printf("(%s) ", sym
->name
);
220 type
= sym_get_type(sym
);
222 oldval
= sym_get_tristate_value(sym
);
234 if (oldval
!= no
&& sym_tristate_within_range(sym
, no
))
236 if (oldval
!= mod
&& sym_tristate_within_range(sym
, mod
))
238 if (oldval
!= yes
&& sym_tristate_within_range(sym
, yes
))
240 if (menu_has_help(menu
))
243 conf_askvalue(sym
, sym_get_string_value(sym
));
250 if (!line
[1] || !strcmp(&line
[1], "o"))
262 if (!line
[1] || !strcmp(&line
[1], "es"))
273 if (sym_set_tristate_value(sym
, newval
))
276 printf("\n%s\n", get_help(menu
));
280 static int conf_choice(struct menu
*menu
)
282 struct symbol
*sym
, *def_sym
;
288 type
= sym_get_type(sym
);
289 is_new
= !sym_has_value(sym
);
290 if (sym_is_changable(sym
)) {
293 switch (sym_get_tristate_value(sym
)) {
302 switch (sym_get_tristate_value(sym
)) {
306 printf("%*s%s\n", indent
- 1, "", menu_get_prompt(menu
));
316 printf("%*s%s\n", indent
- 1, "", menu_get_prompt(menu
));
317 def_sym
= sym_get_choice_value(sym
);
320 for (child
= menu
->list
; child
; child
= child
->next
) {
321 if (!menu_is_visible(child
))
324 printf("%*c %s\n", indent
, '*', menu_get_prompt(child
));
328 if (child
->sym
== def_sym
) {
330 printf("%*c", indent
, '>');
332 printf("%*c", indent
, ' ');
333 printf(" %d. %s", cnt
, menu_get_prompt(child
));
334 if (child
->sym
->name
)
335 printf(" (%s)", child
->sym
->name
);
336 if (!sym_has_value(child
->sym
))
340 printf("%*schoice", indent
- 1, "");
345 printf("[1-%d", cnt
);
346 if (menu_has_help(menu
))
349 switch (input_mode
) {
360 fgets(line
, 128, stdin
);
362 if (line
[0] == '?') {
363 printf("\n%s\n", get_help(menu
));
368 else if (isdigit(line
[0]))
374 def
= (random() % cnt
) + 1;
385 for (child
= menu
->list
; child
; child
= child
->next
) {
386 if (!child
->sym
|| !menu_is_visible(child
))
393 if (line
[strlen(line
) - 1] == '?') {
394 printf("\n%s\n", get_help(child
));
397 sym_set_choice_value(sym
, child
->sym
);
407 static void conf(struct menu
*menu
)
410 struct property
*prop
;
413 if (!menu_is_visible(menu
))
421 switch (prop
->type
) {
423 if (input_mode
== ask_silent
&& rootEntry
!= menu
) {
428 prompt
= menu_get_prompt(menu
);
430 printf("%*c\n%*c %s\n%*c\n",
442 if (sym_is_choice(sym
)) {
444 if (sym
->curr
.tri
!= mod
)
463 for (child
= menu
->list
; child
; child
= child
->next
)
469 static void check_conf(struct menu
*menu
)
474 if (!menu_is_visible(menu
))
478 if (sym
&& !sym_has_value(sym
)) {
479 if (sym_is_changable(sym
) ||
480 (sym_is_choice(sym
) && sym_get_tristate_value(sym
) == yes
)) {
482 printf(_("*\n* Restart config...\n*\n"));
483 rootEntry
= menu_get_parent_menu(menu
);
488 for (child
= menu
->list
; child
; child
= child
->next
)
492 int main(int ac
, char **av
)
498 if (ac
> i
&& av
[i
][0] == '-') {
499 switch (av
[i
++][1]) {
501 input_mode
= ask_new
;
504 input_mode
= ask_silent
;
505 valid_stdin
= isatty(0) && isatty(1) && isatty(2);
508 input_mode
= set_default
;
511 input_mode
= set_default
;
512 defconfig_file
= av
[i
++];
513 if (!defconfig_file
) {
514 printf(_("%s: No default config file specified\n"),
523 input_mode
= set_mod
;
526 input_mode
= set_yes
;
529 input_mode
= set_random
;
534 fprintf(stderr
, "See README for usage info\n");
540 printf(_("%s: Kconfig file missing\n"), av
[0]);
545 switch (input_mode
) {
548 defconfig_file
= conf_get_default_confname();
549 if (conf_read(defconfig_file
)) {
551 "*** Can't find default configuration \"%s\"!\n"
552 "***\n", defconfig_file
);
557 if (stat(".config", &tmpstat
)) {
559 "*** You have not yet configured your kernel!\n"
560 "*** (missing kernel .config file)\n"
562 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
563 "*** \"make menuconfig\" or \"make xconfig\").\n"
575 name
= getenv("KCONFIG_ALLCONFIG");
576 if (name
&& !stat(name
, &tmpstat
)) {
577 conf_read_simple(name
, S_DEF_USER
);
580 switch (input_mode
) {
581 case set_no
: name
= "allno.config"; break;
582 case set_mod
: name
= "allmod.config"; break;
583 case set_yes
: name
= "allyes.config"; break;
584 case set_random
: name
= "allrandom.config"; break;
587 if (!stat(name
, &tmpstat
))
588 conf_read_simple(name
, S_DEF_USER
);
589 else if (!stat("all.config", &tmpstat
))
590 conf_read_simple("all.config", S_DEF_USER
);
596 if (input_mode
!= ask_silent
) {
597 rootEntry
= &rootmenu
;
599 if (input_mode
== ask_all
) {
600 input_mode
= ask_silent
;
603 } else if (conf_get_changed()) {
604 name
= getenv("KCONFIG_NOSILENTUPDATE");
606 fprintf(stderr
, _("\n*** Kernel configuration requires explicit update.\n\n"));
614 check_conf(&rootmenu
);
616 if (conf_write(NULL
)) {
617 fprintf(stderr
, _("\n*** Error during writing of the kernel configuration.\n\n"));
621 if (input_mode
== ask_silent
&& conf_write_autoconf()) {
622 fprintf(stderr
, _("\n*** Error during writing of the kernel configuration.\n\n"));