2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
17 #define LKC_DIRECT_LINK
20 static void conf(struct menu
*menu
);
21 static void check_conf(struct menu
*menu
);
36 } input_mode
= oldaskconfig
;
40 static int indent
= 1;
41 static int valid_stdin
= 1;
42 static int sync_kconfig
;
44 static char line
[128];
45 static struct menu
*rootEntry
;
47 static void print_help(struct menu
*menu
)
49 struct gstr help
= str_new();
51 menu_get_ext_help(menu
, &help
);
53 printf("\n%s\n", str_get(&help
));
57 static void strip(char *str
)
66 memmove(str
, p
, l
+ 1);
74 static void check_stdin(void)
77 printf(_("aborted!\n\n"));
78 printf(_("Console input/output is redirected. "));
79 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
84 static int conf_askvalue(struct symbol
*sym
, const char *def
)
86 enum symbol_type type
= sym_get_type(sym
);
88 if (!sym_has_value(sym
))
94 if (!sym_is_changable(sym
)) {
101 switch (input_mode
) {
103 case silentoldconfig
:
104 if (sym_has_value(sym
)) {
111 xfgets(line
, 128, stdin
);
130 static int conf_string(struct menu
*menu
)
132 struct symbol
*sym
= menu
->sym
;
136 printf("%*s%s ", indent
- 1, "", _(menu
->prompt
->text
));
137 printf("(%s) ", sym
->name
);
138 def
= sym_get_string_value(sym
);
139 if (sym_get_string_value(sym
))
140 printf("[%s] ", def
);
141 if (!conf_askvalue(sym
, def
))
148 if (line
[1] == '\n') {
154 line
[strlen(line
)-1] = 0;
157 if (def
&& sym_set_string_value(sym
, def
))
162 static int conf_sym(struct menu
*menu
)
164 struct symbol
*sym
= menu
->sym
;
165 tristate oldval
, newval
;
168 printf("%*s%s ", indent
- 1, "", _(menu
->prompt
->text
));
170 printf("(%s) ", sym
->name
);
172 oldval
= sym_get_tristate_value(sym
);
184 if (oldval
!= no
&& sym_tristate_within_range(sym
, no
))
186 if (oldval
!= mod
&& sym_tristate_within_range(sym
, mod
))
188 if (oldval
!= yes
&& sym_tristate_within_range(sym
, yes
))
190 if (menu_has_help(menu
))
193 if (!conf_askvalue(sym
, sym_get_string_value(sym
)))
201 if (!line
[1] || !strcmp(&line
[1], "o"))
213 if (!line
[1] || !strcmp(&line
[1], "es"))
224 if (sym_set_tristate_value(sym
, newval
))
231 static int conf_choice(struct menu
*menu
)
233 struct symbol
*sym
, *def_sym
;
238 is_new
= !sym_has_value(sym
);
239 if (sym_is_changable(sym
)) {
242 switch (sym_get_tristate_value(sym
)) {
251 switch (sym_get_tristate_value(sym
)) {
255 printf("%*s%s\n", indent
- 1, "", _(menu_get_prompt(menu
)));
265 printf("%*s%s\n", indent
- 1, "", _(menu_get_prompt(menu
)));
266 def_sym
= sym_get_choice_value(sym
);
269 for (child
= menu
->list
; child
; child
= child
->next
) {
270 if (!menu_is_visible(child
))
273 printf("%*c %s\n", indent
, '*', _(menu_get_prompt(child
)));
277 if (child
->sym
== def_sym
) {
279 printf("%*c", indent
, '>');
281 printf("%*c", indent
, ' ');
282 printf(" %d. %s", cnt
, _(menu_get_prompt(child
)));
283 if (child
->sym
->name
)
284 printf(" (%s)", child
->sym
->name
);
285 if (!sym_has_value(child
->sym
))
289 printf(_("%*schoice"), indent
- 1, "");
294 printf("[1-%d", cnt
);
295 if (menu_has_help(menu
))
298 switch (input_mode
) {
300 case silentoldconfig
:
309 xfgets(line
, 128, stdin
);
311 if (line
[0] == '?') {
317 else if (isdigit(line
[0]))
327 for (child
= menu
->list
; child
; child
= child
->next
) {
328 if (!child
->sym
|| !menu_is_visible(child
))
335 if (line
[strlen(line
) - 1] == '?') {
339 sym_set_choice_value(sym
, child
->sym
);
340 for (child
= child
->list
; child
; child
= child
->next
) {
349 static void conf(struct menu
*menu
)
352 struct property
*prop
;
355 if (!menu_is_visible(menu
))
363 switch (prop
->type
) {
365 if ((input_mode
== silentoldconfig
||
366 input_mode
== listnewconfig
||
367 input_mode
== oldnoconfig
) &&
373 prompt
= menu_get_prompt(menu
);
375 printf("%*c\n%*c %s\n%*c\n",
377 indent
, '*', _(prompt
),
387 if (sym_is_choice(sym
)) {
389 if (sym
->curr
.tri
!= mod
)
408 for (child
= menu
->list
; child
; child
= child
->next
)
414 static void check_conf(struct menu
*menu
)
419 if (!menu_is_visible(menu
))
423 if (sym
&& !sym_has_value(sym
)) {
424 if (sym_is_changable(sym
) ||
425 (sym_is_choice(sym
) && sym_get_tristate_value(sym
) == yes
)) {
426 if (input_mode
== listnewconfig
) {
427 if (sym
->name
&& !sym_is_choice_value(sym
)) {
428 printf("%s%s\n", CONFIG_
, sym
->name
);
430 } else if (input_mode
!= oldnoconfig
) {
432 printf(_("*\n* Restart config...\n*\n"));
433 rootEntry
= menu_get_parent_menu(menu
);
439 for (child
= menu
->list
; child
; child
= child
->next
)
443 static struct option long_opts
[] = {
444 {"oldaskconfig", no_argument
, NULL
, oldaskconfig
},
445 {"oldconfig", no_argument
, NULL
, oldconfig
},
446 {"silentoldconfig", no_argument
, NULL
, silentoldconfig
},
447 {"defconfig", optional_argument
, NULL
, defconfig
},
448 {"savedefconfig", required_argument
, NULL
, savedefconfig
},
449 {"allnoconfig", no_argument
, NULL
, allnoconfig
},
450 {"allyesconfig", no_argument
, NULL
, allyesconfig
},
451 {"allmodconfig", no_argument
, NULL
, allmodconfig
},
452 {"alldefconfig", no_argument
, NULL
, alldefconfig
},
453 {"randconfig", no_argument
, NULL
, randconfig
},
454 {"listnewconfig", no_argument
, NULL
, listnewconfig
},
455 {"oldnoconfig", no_argument
, NULL
, oldnoconfig
},
459 int main(int ac
, char **av
)
465 setlocale(LC_ALL
, "");
466 bindtextdomain(PACKAGE
, LOCALEDIR
);
469 while ((opt
= getopt_long(ac
, av
, "", long_opts
, NULL
)) != -1) {
470 input_mode
= (enum input_mode
)opt
;
472 case silentoldconfig
:
477 defconfig_file
= optarg
;
485 * Use microseconds derived seed,
486 * compensate for systems where it may be zero
488 gettimeofday(&now
, NULL
);
490 seed
= (unsigned int)((now
.tv_sec
+ 1) * (now
.tv_usec
+ 1));
495 fprintf(stderr
, _("See README for usage info\n"));
501 printf(_("%s: Kconfig file missing\n"), av
[0]);
508 name
= conf_get_configname();
509 if (stat(name
, &tmpstat
)) {
510 fprintf(stderr
, _("***\n"
511 "*** Configuration file \"%s\" not found!\n"
513 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
514 "*** \"make menuconfig\" or \"make xconfig\").\n"
520 switch (input_mode
) {
523 defconfig_file
= conf_get_default_confname();
524 if (conf_read(defconfig_file
)) {
526 "*** Can't find default configuration \"%s\"!\n"
527 "***\n"), defconfig_file
);
534 case silentoldconfig
:
546 name
= getenv("KCONFIG_ALLCONFIG");
547 if (name
&& !stat(name
, &tmpstat
)) {
548 conf_read_simple(name
, S_DEF_USER
);
551 switch (input_mode
) {
552 case allnoconfig
: name
= "allno.config"; break;
553 case allyesconfig
: name
= "allyes.config"; break;
554 case allmodconfig
: name
= "allmod.config"; break;
555 case alldefconfig
: name
= "alldef.config"; break;
556 case randconfig
: name
= "allrandom.config"; break;
559 if (!stat(name
, &tmpstat
))
560 conf_read_simple(name
, S_DEF_USER
);
561 else if (!stat("all.config", &tmpstat
))
562 conf_read_simple("all.config", S_DEF_USER
);
569 if (conf_get_changed()) {
570 name
= getenv("KCONFIG_NOSILENTUPDATE");
573 _("\n*** The configuration requires explicit update.\n\n"));
577 valid_stdin
= isatty(0) && isatty(1) && isatty(2);
580 switch (input_mode
) {
582 conf_set_all_new_symbols(def_no
);
585 conf_set_all_new_symbols(def_yes
);
588 conf_set_all_new_symbols(def_mod
);
591 conf_set_all_new_symbols(def_default
);
594 conf_set_all_new_symbols(def_random
);
597 conf_set_all_new_symbols(def_default
);
602 rootEntry
= &rootmenu
;
604 input_mode
= silentoldconfig
;
609 case silentoldconfig
:
610 /* Update until a loop caused no more changes */
613 check_conf(&rootmenu
);
615 (input_mode
!= listnewconfig
&&
616 input_mode
!= oldnoconfig
));
621 /* silentoldconfig is used during the build so we shall update autoconf.
622 * All other commands are only used to generate a config.
624 if (conf_get_changed() && conf_write(NULL
)) {
625 fprintf(stderr
, _("\n*** Error during writing of the configuration.\n\n"));
628 if (conf_write_autoconf()) {
629 fprintf(stderr
, _("\n*** Error during update of the configuration.\n\n"));
632 } else if (input_mode
== savedefconfig
) {
633 if (conf_write_defconfig(defconfig_file
)) {
634 fprintf(stderr
, _("n*** Error while saving defconfig to: %s\n\n"),
638 } else if (input_mode
!= listnewconfig
) {
639 if (conf_write(NULL
)) {
640 fprintf(stderr
, _("\n*** Error during writing of the configuration.\n\n"));
647 * Helper function to facilitate fgets() by Jean Sacren.
649 void xfgets(str
, size
, in
)
654 if (fgets(str
, size
, in
) == NULL
)
655 fprintf(stderr
, "\nError in reading or end of file.\n");