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 void print_help(struct menu
*menu
)
43 struct gstr help
= str_new();
45 menu_get_ext_help(menu
, &help
);
47 printf("\n%s\n", str_get(&help
));
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 static 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') {
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
))
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] == '?') {
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] == '?') {
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 name
= conf_get_configname();
502 if (stat(name
, &tmpstat
)) {
503 fprintf(stderr
, _("***\n"
504 "*** You have not yet configured your kernel!\n"
505 "*** (missing kernel config file \"%s\")\n"
507 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
508 "*** \"make menuconfig\" or \"make xconfig\").\n"
514 switch (input_mode
) {
517 defconfig_file
= conf_get_default_confname();
518 if (conf_read(defconfig_file
)) {
520 "*** Can't find default configuration \"%s\"!\n"
521 "***\n"), defconfig_file
);
534 name
= getenv("KCONFIG_ALLCONFIG");
535 if (name
&& !stat(name
, &tmpstat
)) {
536 conf_read_simple(name
, S_DEF_USER
);
539 switch (input_mode
) {
540 case set_no
: name
= "allno.config"; break;
541 case set_mod
: name
= "allmod.config"; break;
542 case set_yes
: name
= "allyes.config"; break;
543 case set_random
: name
= "allrandom.config"; break;
546 if (!stat(name
, &tmpstat
))
547 conf_read_simple(name
, S_DEF_USER
);
548 else if (!stat("all.config", &tmpstat
))
549 conf_read_simple("all.config", S_DEF_USER
);
556 if (conf_get_changed()) {
557 name
= getenv("KCONFIG_NOSILENTUPDATE");
560 _("\n*** Kernel configuration requires explicit update.\n\n"));
564 valid_stdin
= isatty(0) && isatty(1) && isatty(2);
567 switch (input_mode
) {
569 conf_set_all_new_symbols(def_no
);
572 conf_set_all_new_symbols(def_yes
);
575 conf_set_all_new_symbols(def_mod
);
578 conf_set_all_new_symbols(def_random
);
581 conf_set_all_new_symbols(def_default
);
585 rootEntry
= &rootmenu
;
587 input_mode
= ask_silent
;
590 /* Update until a loop caused no more changes */
593 check_conf(&rootmenu
);
599 /* silentoldconfig is used during the build so we shall update autoconf.
600 * All other commands are only used to generate a config.
602 if (conf_get_changed() && conf_write(NULL
)) {
603 fprintf(stderr
, _("\n*** Error during writing of the kernel configuration.\n\n"));
606 if (conf_write_autoconf()) {
607 fprintf(stderr
, _("\n*** Error during update of the kernel configuration.\n\n"));
611 if (conf_write(NULL
)) {
612 fprintf(stderr
, _("\n*** Error during writing of the kernel configuration.\n\n"));