]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - scripts/kconfig/conf.c
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
19 static void conf(struct menu
*menu
);
20 static void check_conf(struct menu
*menu
);
21 static void xfgets(char *str
, int size
, FILE *in
);
36 } input_mode
= oldaskconfig
;
38 static int indent
= 1;
40 static int valid_stdin
= 1;
41 static int sync_kconfig
;
43 static char line
[128];
44 static struct menu
*rootEntry
;
46 static void print_help(struct menu
*menu
)
48 struct gstr help
= str_new();
50 menu_get_ext_help(menu
, &help
);
52 printf("\n%s\n", str_get(&help
));
56 static void strip(char *str
)
65 memmove(str
, p
, l
+ 1);
73 static void check_stdin(void)
76 printf(_("aborted!\n\n"));
77 printf(_("Console input/output is redirected. "));
78 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
83 static int conf_askvalue(struct symbol
*sym
, const char *def
)
85 enum symbol_type type
= sym_get_type(sym
);
87 if (!sym_has_value(sym
))
93 if (!sym_is_changable(sym
)) {
100 switch (input_mode
) {
102 case silentoldconfig
:
103 if (sym_has_value(sym
)) {
111 xfgets(line
, 128, stdin
);
132 static int conf_string(struct menu
*menu
)
134 struct symbol
*sym
= menu
->sym
;
138 printf("%*s%s ", indent
- 1, "", _(menu
->prompt
->text
));
139 printf("(%s) ", sym
->name
);
140 def
= sym_get_string_value(sym
);
141 if (sym_get_string_value(sym
))
142 printf("[%s] ", def
);
143 if (!conf_askvalue(sym
, def
))
150 if (line
[1] == '\n') {
157 line
[strlen(line
)-1] = 0;
160 if (def
&& sym_set_string_value(sym
, def
))
165 static int conf_sym(struct menu
*menu
)
167 struct symbol
*sym
= menu
->sym
;
168 tristate oldval
, newval
;
171 printf("%*s%s ", indent
- 1, "", _(menu
->prompt
->text
));
173 printf("(%s) ", sym
->name
);
175 oldval
= sym_get_tristate_value(sym
);
187 if (oldval
!= no
&& sym_tristate_within_range(sym
, no
))
189 if (oldval
!= mod
&& sym_tristate_within_range(sym
, mod
))
191 if (oldval
!= yes
&& sym_tristate_within_range(sym
, yes
))
193 if (menu_has_help(menu
))
196 if (!conf_askvalue(sym
, sym_get_string_value(sym
)))
204 if (!line
[1] || !strcmp(&line
[1], "o"))
216 if (!line
[1] || !strcmp(&line
[1], "es"))
227 if (sym_set_tristate_value(sym
, newval
))
234 static int conf_choice(struct menu
*menu
)
236 struct symbol
*sym
, *def_sym
;
241 is_new
= !sym_has_value(sym
);
242 if (sym_is_changable(sym
)) {
245 switch (sym_get_tristate_value(sym
)) {
254 switch (sym_get_tristate_value(sym
)) {
258 printf("%*s%s\n", indent
- 1, "", _(menu_get_prompt(menu
)));
268 printf("%*s%s\n", indent
- 1, "", _(menu_get_prompt(menu
)));
269 def_sym
= sym_get_choice_value(sym
);
272 for (child
= menu
->list
; child
; child
= child
->next
) {
273 if (!menu_is_visible(child
))
276 printf("%*c %s\n", indent
, '*', _(menu_get_prompt(child
)));
280 if (child
->sym
== def_sym
) {
282 printf("%*c", indent
, '>');
284 printf("%*c", indent
, ' ');
285 printf(" %d. %s", cnt
, _(menu_get_prompt(child
)));
286 if (child
->sym
->name
)
287 printf(" (%s)", child
->sym
->name
);
288 if (!sym_has_value(child
->sym
))
292 printf(_("%*schoice"), indent
- 1, "");
297 printf("[1-%d", cnt
);
298 if (menu_has_help(menu
))
301 switch (input_mode
) {
303 case silentoldconfig
:
313 xfgets(line
, 128, stdin
);
315 if (line
[0] == '?') {
321 else if (isdigit(line
[0]))
331 for (child
= menu
->list
; child
; child
= child
->next
) {
332 if (!child
->sym
|| !menu_is_visible(child
))
339 if (line
[0] && line
[strlen(line
) - 1] == '?') {
343 sym_set_choice_value(sym
, child
->sym
);
344 for (child
= child
->list
; child
; child
= child
->next
) {
353 static void conf(struct menu
*menu
)
356 struct property
*prop
;
359 if (!menu_is_visible(menu
))
367 switch (prop
->type
) {
369 if ((input_mode
== silentoldconfig
||
370 input_mode
== listnewconfig
||
371 input_mode
== olddefconfig
) &&
378 prompt
= menu_get_prompt(menu
);
380 printf("%*c\n%*c %s\n%*c\n",
382 indent
, '*', _(prompt
),
392 if (sym_is_choice(sym
)) {
394 if (sym
->curr
.tri
!= mod
)
413 for (child
= menu
->list
; child
; child
= child
->next
)
419 static void check_conf(struct menu
*menu
)
424 if (!menu_is_visible(menu
))
428 if (sym
&& !sym_has_value(sym
)) {
429 if (sym_is_changable(sym
) ||
430 (sym_is_choice(sym
) && sym_get_tristate_value(sym
) == yes
)) {
431 if (input_mode
== listnewconfig
) {
432 if (sym
->name
&& !sym_is_choice_value(sym
)) {
433 printf("%s%s\n", CONFIG_
, sym
->name
);
435 } else if (input_mode
!= olddefconfig
) {
437 printf(_("*\n* Restart config...\n*\n"));
438 rootEntry
= menu_get_parent_menu(menu
);
444 for (child
= menu
->list
; child
; child
= child
->next
)
448 static struct option long_opts
[] = {
449 {"oldaskconfig", no_argument
, NULL
, oldaskconfig
},
450 {"oldconfig", no_argument
, NULL
, oldconfig
},
451 {"silentoldconfig", no_argument
, NULL
, silentoldconfig
},
452 {"defconfig", optional_argument
, NULL
, defconfig
},
453 {"savedefconfig", required_argument
, NULL
, savedefconfig
},
454 {"allnoconfig", no_argument
, NULL
, allnoconfig
},
455 {"allyesconfig", no_argument
, NULL
, allyesconfig
},
456 {"allmodconfig", no_argument
, NULL
, allmodconfig
},
457 {"alldefconfig", no_argument
, NULL
, alldefconfig
},
458 {"randconfig", no_argument
, NULL
, randconfig
},
459 {"listnewconfig", no_argument
, NULL
, listnewconfig
},
460 {"olddefconfig", no_argument
, NULL
, olddefconfig
},
462 * oldnoconfig is an alias of olddefconfig, because people already
463 * are dependent on its behavior(sets new symbols to their default
464 * value but not 'n') with the counter-intuitive name.
466 {"oldnoconfig", no_argument
, NULL
, olddefconfig
},
470 static void conf_usage(const char *progname
)
473 printf("Usage: %s [option] <kconfig-file>\n", progname
);
474 printf("[option] is _one_ of the following:\n");
475 printf(" --listnewconfig List new options\n");
476 printf(" --oldaskconfig Start a new configuration using a line-oriented program\n");
477 printf(" --oldconfig Update a configuration using a provided .config as base\n");
478 printf(" --silentoldconfig Same as oldconfig, but quietly, additionally update deps\n");
479 printf(" --olddefconfig Same as silentoldconfig but sets new symbols to their default value\n");
480 printf(" --oldnoconfig An alias of olddefconfig\n");
481 printf(" --defconfig <file> New config with default defined in <file>\n");
482 printf(" --savedefconfig <file> Save the minimal current configuration to <file>\n");
483 printf(" --allnoconfig New config where all options are answered with no\n");
484 printf(" --allyesconfig New config where all options are answered with yes\n");
485 printf(" --allmodconfig New config where all options are answered with mod\n");
486 printf(" --alldefconfig New config with all symbols set to default\n");
487 printf(" --randconfig New config with random answer to all options\n");
490 int main(int ac
, char **av
)
492 const char *progname
= av
[0];
494 const char *name
, *defconfig_file
= NULL
/* gcc uninit */;
497 setlocale(LC_ALL
, "");
498 bindtextdomain(PACKAGE
, LOCALEDIR
);
501 tty_stdio
= isatty(0) && isatty(1) && isatty(2);
503 while ((opt
= getopt_long(ac
, av
, "", long_opts
, NULL
)) != -1) {
504 input_mode
= (enum input_mode
)opt
;
506 case silentoldconfig
:
511 defconfig_file
= optarg
;
519 * Use microseconds derived seed,
520 * compensate for systems where it may be zero
522 gettimeofday(&now
, NULL
);
524 seed
= (unsigned int)((now
.tv_sec
+ 1) * (now
.tv_usec
+ 1));
538 conf_usage(progname
);
544 printf(_("%s: Kconfig file missing\n"), av
[0]);
545 conf_usage(progname
);
552 name
= conf_get_configname();
553 if (stat(name
, &tmpstat
)) {
554 fprintf(stderr
, _("***\n"
555 "*** Configuration file \"%s\" not found!\n"
557 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
558 "*** \"make menuconfig\" or \"make xconfig\").\n"
564 switch (input_mode
) {
567 defconfig_file
= conf_get_default_confname();
568 if (conf_read(defconfig_file
)) {
570 "*** Can't find default configuration \"%s\"!\n"
571 "***\n"), defconfig_file
);
576 case silentoldconfig
:
588 name
= getenv("KCONFIG_ALLCONFIG");
591 if ((strcmp(name
, "") != 0) && (strcmp(name
, "1") != 0)) {
592 if (conf_read_simple(name
, S_DEF_USER
)) {
594 _("*** Can't read seed configuration \"%s\"!\n"),
600 switch (input_mode
) {
601 case allnoconfig
: name
= "allno.config"; break;
602 case allyesconfig
: name
= "allyes.config"; break;
603 case allmodconfig
: name
= "allmod.config"; break;
604 case alldefconfig
: name
= "alldef.config"; break;
605 case randconfig
: name
= "allrandom.config"; break;
608 if (conf_read_simple(name
, S_DEF_USER
) &&
609 conf_read_simple("all.config", S_DEF_USER
)) {
611 _("*** KCONFIG_ALLCONFIG set, but no \"%s\" or \"all.config\" file found\n"),
621 if (conf_get_changed()) {
622 name
= getenv("KCONFIG_NOSILENTUPDATE");
625 _("\n*** The configuration requires explicit update.\n\n"));
629 valid_stdin
= tty_stdio
;
632 switch (input_mode
) {
634 conf_set_all_new_symbols(def_no
);
637 conf_set_all_new_symbols(def_yes
);
640 conf_set_all_new_symbols(def_mod
);
643 conf_set_all_new_symbols(def_default
);
646 conf_set_all_new_symbols(def_random
);
649 conf_set_all_new_symbols(def_default
);
654 rootEntry
= &rootmenu
;
656 input_mode
= silentoldconfig
;
661 case silentoldconfig
:
662 /* Update until a loop caused no more changes */
665 check_conf(&rootmenu
);
667 (input_mode
!= listnewconfig
&&
668 input_mode
!= olddefconfig
));
673 /* silentoldconfig is used during the build so we shall update autoconf.
674 * All other commands are only used to generate a config.
676 if (conf_get_changed() && conf_write(NULL
)) {
677 fprintf(stderr
, _("\n*** Error during writing of the configuration.\n\n"));
680 if (conf_write_autoconf()) {
681 fprintf(stderr
, _("\n*** Error during update of the configuration.\n\n"));
684 } else if (input_mode
== savedefconfig
) {
685 if (conf_write_defconfig(defconfig_file
)) {
686 fprintf(stderr
, _("n*** Error while saving defconfig to: %s\n\n"),
690 } else if (input_mode
!= listnewconfig
) {
691 if (conf_write(NULL
)) {
692 fprintf(stderr
, _("\n*** Error during writing of the configuration.\n\n"));
700 * Helper function to facilitate fgets() by Jean Sacren.
702 void xfgets(char *str
, int size
, FILE *in
)
704 if (fgets(str
, size
, in
) == NULL
)
705 fprintf(stderr
, "\nError in reading or end of file.\n");