2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
20 static void conf(struct menu
*menu
);
21 static void check_conf(struct menu
*menu
);
22 static void xfgets(char *str
, int size
, FILE *in
);
37 } input_mode
= oldaskconfig
;
39 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
)) {
112 xfgets(line
, 128, stdin
);
133 static int conf_string(struct menu
*menu
)
135 struct symbol
*sym
= menu
->sym
;
139 printf("%*s%s ", indent
- 1, "", _(menu
->prompt
->text
));
140 printf("(%s) ", sym
->name
);
141 def
= sym_get_string_value(sym
);
142 if (sym_get_string_value(sym
))
143 printf("[%s] ", def
);
144 if (!conf_askvalue(sym
, def
))
151 if (line
[1] == '\n') {
158 line
[strlen(line
)-1] = 0;
161 if (def
&& sym_set_string_value(sym
, def
))
166 static int conf_sym(struct menu
*menu
)
168 struct symbol
*sym
= menu
->sym
;
169 tristate oldval
, newval
;
172 printf("%*s%s ", indent
- 1, "", _(menu
->prompt
->text
));
174 printf("(%s) ", sym
->name
);
176 oldval
= sym_get_tristate_value(sym
);
188 if (oldval
!= no
&& sym_tristate_within_range(sym
, no
))
190 if (oldval
!= mod
&& sym_tristate_within_range(sym
, mod
))
192 if (oldval
!= yes
&& sym_tristate_within_range(sym
, yes
))
194 if (menu_has_help(menu
))
197 if (!conf_askvalue(sym
, sym_get_string_value(sym
)))
205 if (!line
[1] || !strcmp(&line
[1], "o"))
217 if (!line
[1] || !strcmp(&line
[1], "es"))
228 if (sym_set_tristate_value(sym
, newval
))
235 static int conf_choice(struct menu
*menu
)
237 struct symbol
*sym
, *def_sym
;
242 is_new
= !sym_has_value(sym
);
243 if (sym_is_changable(sym
)) {
246 switch (sym_get_tristate_value(sym
)) {
255 switch (sym_get_tristate_value(sym
)) {
259 printf("%*s%s\n", indent
- 1, "", _(menu_get_prompt(menu
)));
269 printf("%*s%s\n", indent
- 1, "", _(menu_get_prompt(menu
)));
270 def_sym
= sym_get_choice_value(sym
);
273 for (child
= menu
->list
; child
; child
= child
->next
) {
274 if (!menu_is_visible(child
))
277 printf("%*c %s\n", indent
, '*', _(menu_get_prompt(child
)));
281 if (child
->sym
== def_sym
) {
283 printf("%*c", indent
, '>');
285 printf("%*c", indent
, ' ');
286 printf(" %d. %s", cnt
, _(menu_get_prompt(child
)));
287 if (child
->sym
->name
)
288 printf(" (%s)", child
->sym
->name
);
289 if (!sym_has_value(child
->sym
))
293 printf(_("%*schoice"), indent
- 1, "");
298 printf("[1-%d", cnt
);
299 if (menu_has_help(menu
))
302 switch (input_mode
) {
304 case silentoldconfig
:
314 xfgets(line
, 128, stdin
);
316 if (line
[0] == '?') {
322 else if (isdigit(line
[0]))
332 for (child
= menu
->list
; child
; child
= child
->next
) {
333 if (!child
->sym
|| !menu_is_visible(child
))
340 if (line
[0] && line
[strlen(line
) - 1] == '?') {
344 sym_set_choice_value(sym
, child
->sym
);
345 for (child
= child
->list
; child
; child
= child
->next
) {
354 static void conf(struct menu
*menu
)
357 struct property
*prop
;
360 if (!menu_is_visible(menu
))
368 switch (prop
->type
) {
370 if ((input_mode
== silentoldconfig
||
371 input_mode
== listnewconfig
||
372 input_mode
== olddefconfig
) &&
379 prompt
= menu_get_prompt(menu
);
381 printf("%*c\n%*c %s\n%*c\n",
383 indent
, '*', _(prompt
),
393 if (sym_is_choice(sym
)) {
395 if (sym
->curr
.tri
!= mod
)
414 for (child
= menu
->list
; child
; child
= child
->next
)
420 static void check_conf(struct menu
*menu
)
425 if (!menu_is_visible(menu
))
429 if (sym
&& !sym_has_value(sym
)) {
430 if (sym_is_changable(sym
) ||
431 (sym_is_choice(sym
) && sym_get_tristate_value(sym
) == yes
)) {
432 if (input_mode
== listnewconfig
) {
433 if (sym
->name
&& !sym_is_choice_value(sym
)) {
434 printf("%s%s\n", CONFIG_
, sym
->name
);
436 } else if (input_mode
!= olddefconfig
) {
438 printf(_("*\n* Restart config...\n*\n"));
439 rootEntry
= menu_get_parent_menu(menu
);
445 for (child
= menu
->list
; child
; child
= child
->next
)
449 static struct option long_opts
[] = {
450 {"oldaskconfig", no_argument
, NULL
, oldaskconfig
},
451 {"oldconfig", no_argument
, NULL
, oldconfig
},
452 {"silentoldconfig", no_argument
, NULL
, silentoldconfig
},
453 {"defconfig", optional_argument
, NULL
, defconfig
},
454 {"savedefconfig", required_argument
, NULL
, savedefconfig
},
455 {"allnoconfig", no_argument
, NULL
, allnoconfig
},
456 {"allyesconfig", no_argument
, NULL
, allyesconfig
},
457 {"allmodconfig", no_argument
, NULL
, allmodconfig
},
458 {"alldefconfig", no_argument
, NULL
, alldefconfig
},
459 {"randconfig", no_argument
, NULL
, randconfig
},
460 {"listnewconfig", no_argument
, NULL
, listnewconfig
},
461 {"olddefconfig", no_argument
, NULL
, olddefconfig
},
463 * oldnoconfig is an alias of olddefconfig, because people already
464 * are dependent on its behavior(sets new symbols to their default
465 * value but not 'n') with the counter-intuitive name.
467 {"oldnoconfig", no_argument
, NULL
, olddefconfig
},
471 static void conf_usage(const char *progname
)
474 printf("Usage: %s [-s] [option] <kconfig-file>\n", progname
);
475 printf("[option] is _one_ of the following:\n");
476 printf(" --listnewconfig List new options\n");
477 printf(" --oldaskconfig Start a new configuration using a line-oriented program\n");
478 printf(" --oldconfig Update a configuration using a provided .config as base\n");
479 printf(" --silentoldconfig Same as oldconfig, but quietly, additionally update deps\n");
480 printf(" --olddefconfig Same as silentoldconfig but sets new symbols to their default value\n");
481 printf(" --oldnoconfig An alias of olddefconfig\n");
482 printf(" --defconfig <file> New config with default defined in <file>\n");
483 printf(" --savedefconfig <file> Save the minimal current configuration to <file>\n");
484 printf(" --allnoconfig New config where all options are answered with no\n");
485 printf(" --allyesconfig New config where all options are answered with yes\n");
486 printf(" --allmodconfig New config where all options are answered with mod\n");
487 printf(" --alldefconfig New config with all symbols set to default\n");
488 printf(" --randconfig New config with random answer to all options\n");
491 int main(int ac
, char **av
)
493 const char *progname
= av
[0];
495 const char *name
, *defconfig_file
= NULL
/* gcc uninit */;
498 setlocale(LC_ALL
, "");
499 bindtextdomain(PACKAGE
, LOCALEDIR
);
502 tty_stdio
= isatty(0) && isatty(1) && isatty(2);
504 while ((opt
= getopt_long(ac
, av
, "s", long_opts
, NULL
)) != -1) {
506 conf_set_message_callback(NULL
);
509 input_mode
= (enum input_mode
)opt
;
511 case silentoldconfig
:
516 defconfig_file
= optarg
;
525 * Use microseconds derived seed,
526 * compensate for systems where it may be zero
528 gettimeofday(&now
, NULL
);
529 seed
= (unsigned int)((now
.tv_sec
+ 1) * (now
.tv_usec
+ 1));
531 seed_env
= getenv("KCONFIG_SEED");
532 if( seed_env
&& *seed_env
) {
534 int tmp
= (int)strtol(seed_env
, &endp
, 0);
539 fprintf( stderr
, "KCONFIG_SEED=0x%X\n", seed
);
553 conf_usage(progname
);
559 printf(_("%s: Kconfig file missing\n"), av
[0]);
560 conf_usage(progname
);
567 name
= conf_get_configname();
568 if (stat(name
, &tmpstat
)) {
569 fprintf(stderr
, _("***\n"
570 "*** Configuration file \"%s\" not found!\n"
572 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
573 "*** \"make menuconfig\" or \"make xconfig\").\n"
579 switch (input_mode
) {
582 defconfig_file
= conf_get_default_confname();
583 if (conf_read(defconfig_file
)) {
585 "*** Can't find default configuration \"%s\"!\n"
586 "***\n"), defconfig_file
);
591 case silentoldconfig
:
603 name
= getenv("KCONFIG_ALLCONFIG");
606 if ((strcmp(name
, "") != 0) && (strcmp(name
, "1") != 0)) {
607 if (conf_read_simple(name
, S_DEF_USER
)) {
609 _("*** Can't read seed configuration \"%s\"!\n"),
615 switch (input_mode
) {
616 case allnoconfig
: name
= "allno.config"; break;
617 case allyesconfig
: name
= "allyes.config"; break;
618 case allmodconfig
: name
= "allmod.config"; break;
619 case alldefconfig
: name
= "alldef.config"; break;
620 case randconfig
: name
= "allrandom.config"; break;
623 if (conf_read_simple(name
, S_DEF_USER
) &&
624 conf_read_simple("all.config", S_DEF_USER
)) {
626 _("*** KCONFIG_ALLCONFIG set, but no \"%s\" or \"all.config\" file found\n"),
636 if (conf_get_changed()) {
637 name
= getenv("KCONFIG_NOSILENTUPDATE");
640 _("\n*** The configuration requires explicit update.\n\n"));
644 valid_stdin
= tty_stdio
;
647 switch (input_mode
) {
649 conf_set_all_new_symbols(def_no
);
652 conf_set_all_new_symbols(def_yes
);
655 conf_set_all_new_symbols(def_mod
);
658 conf_set_all_new_symbols(def_default
);
661 /* Really nothing to do in this loop */
662 while (conf_set_all_new_symbols(def_random
)) ;
665 conf_set_all_new_symbols(def_default
);
670 rootEntry
= &rootmenu
;
672 input_mode
= silentoldconfig
;
677 case silentoldconfig
:
678 /* Update until a loop caused no more changes */
681 check_conf(&rootmenu
);
683 (input_mode
!= listnewconfig
&&
684 input_mode
!= olddefconfig
));
689 /* silentoldconfig is used during the build so we shall update autoconf.
690 * All other commands are only used to generate a config.
692 if (conf_get_changed() && conf_write(NULL
)) {
693 fprintf(stderr
, _("\n*** Error during writing of the configuration.\n\n"));
696 if (conf_write_autoconf()) {
697 fprintf(stderr
, _("\n*** Error during update of the configuration.\n\n"));
700 } else if (input_mode
== savedefconfig
) {
701 if (conf_write_defconfig(defconfig_file
)) {
702 fprintf(stderr
, _("n*** Error while saving defconfig to: %s\n\n"),
706 } else if (input_mode
!= listnewconfig
) {
707 if (conf_write(NULL
)) {
708 fprintf(stderr
, _("\n*** Error during writing of the configuration.\n\n"));
716 * Helper function to facilitate fgets() by Jean Sacren.
718 void xfgets(char *str
, int size
, FILE *in
)
720 if (fgets(str
, size
, in
) == NULL
)
721 fprintf(stderr
, "\nError in reading or end of file.\n");