6431f5c004d96a62bf442a05d4c12c6adac3ca58
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
);
35 } input_mode
= oldaskconfig
;
37 static int indent
= 1;
38 static int valid_stdin
= 1;
39 static int sync_kconfig
;
41 static char line
[128];
42 static struct menu
*rootEntry
;
44 static void print_help(struct menu
*menu
)
46 struct gstr help
= str_new();
48 menu_get_ext_help(menu
, &help
);
50 printf("\n%s\n", str_get(&help
));
54 static void strip(char *str
)
63 memmove(str
, p
, l
+ 1);
71 static void check_stdin(void)
74 printf(_("aborted!\n\n"));
75 printf(_("Console input/output is redirected. "));
76 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
81 static int conf_askvalue(struct symbol
*sym
, const char *def
)
83 enum symbol_type type
= sym_get_type(sym
);
85 if (!sym_has_value(sym
))
91 if (!sym_is_changable(sym
)) {
100 case silentoldconfig
:
101 if (sym_has_value(sym
)) {
109 xfgets(line
, 128, stdin
);
128 static int conf_string(struct menu
*menu
)
130 struct symbol
*sym
= menu
->sym
;
134 printf("%*s%s ", indent
- 1, "", _(menu
->prompt
->text
));
135 printf("(%s) ", sym
->name
);
136 def
= sym_get_string_value(sym
);
137 if (sym_get_string_value(sym
))
138 printf("[%s] ", def
);
139 if (!conf_askvalue(sym
, def
))
146 if (line
[1] == '\n') {
153 line
[strlen(line
)-1] = 0;
156 if (def
&& sym_set_string_value(sym
, def
))
161 static int conf_sym(struct menu
*menu
)
163 struct symbol
*sym
= menu
->sym
;
164 tristate oldval
, newval
;
167 printf("%*s%s ", indent
- 1, "", _(menu
->prompt
->text
));
169 printf("(%s) ", sym
->name
);
171 oldval
= sym_get_tristate_value(sym
);
183 if (oldval
!= no
&& sym_tristate_within_range(sym
, no
))
185 if (oldval
!= mod
&& sym_tristate_within_range(sym
, mod
))
187 if (oldval
!= yes
&& sym_tristate_within_range(sym
, yes
))
189 if (menu_has_help(menu
))
192 if (!conf_askvalue(sym
, sym_get_string_value(sym
)))
200 if (!line
[1] || !strcmp(&line
[1], "o"))
212 if (!line
[1] || !strcmp(&line
[1], "es"))
223 if (sym_set_tristate_value(sym
, newval
))
230 static int conf_choice(struct menu
*menu
)
232 struct symbol
*sym
, *def_sym
;
237 is_new
= !sym_has_value(sym
);
238 if (sym_is_changable(sym
)) {
241 switch (sym_get_tristate_value(sym
)) {
250 switch (sym_get_tristate_value(sym
)) {
254 printf("%*s%s\n", indent
- 1, "", _(menu_get_prompt(menu
)));
264 printf("%*s%s\n", indent
- 1, "", _(menu_get_prompt(menu
)));
265 def_sym
= sym_get_choice_value(sym
);
268 for (child
= menu
->list
; child
; child
= child
->next
) {
269 if (!menu_is_visible(child
))
272 printf("%*c %s\n", indent
, '*', _(menu_get_prompt(child
)));
276 if (child
->sym
== def_sym
) {
278 printf("%*c", indent
, '>');
280 printf("%*c", indent
, ' ');
281 printf(" %d. %s", cnt
, _(menu_get_prompt(child
)));
282 if (child
->sym
->name
)
283 printf(" (%s)", child
->sym
->name
);
284 if (!sym_has_value(child
->sym
))
288 printf(_("%*schoice"), indent
- 1, "");
293 printf("[1-%d", cnt
);
294 if (menu_has_help(menu
))
297 switch (input_mode
) {
299 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
[0] && 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
) &&
374 prompt
= menu_get_prompt(menu
);
376 printf("%*c\n%*c %s\n%*c\n",
378 indent
, '*', _(prompt
),
388 if (sym_is_choice(sym
)) {
390 if (sym
->curr
.tri
!= mod
)
409 for (child
= menu
->list
; child
; child
= child
->next
)
415 static void check_conf(struct menu
*menu
)
420 if (!menu_is_visible(menu
))
424 if (sym
&& !sym_has_value(sym
)) {
425 if (sym_is_changable(sym
) ||
426 (sym_is_choice(sym
) && sym_get_tristate_value(sym
) == yes
)) {
427 if (input_mode
== listnewconfig
) {
428 if (sym
->name
&& !sym_is_choice_value(sym
)) {
429 printf("%s%s\n", CONFIG_
, sym
->name
);
431 } else if (input_mode
!= oldnoconfig
) {
433 printf(_("*\n* Restart config...\n*\n"));
434 rootEntry
= menu_get_parent_menu(menu
);
440 for (child
= menu
->list
; child
; child
= child
->next
)
444 static struct option long_opts
[] = {
445 {"oldaskconfig", no_argument
, NULL
, oldaskconfig
},
446 {"oldconfig", no_argument
, NULL
, oldconfig
},
447 {"silentoldconfig", no_argument
, NULL
, silentoldconfig
},
448 {"defconfig", optional_argument
, NULL
, defconfig
},
449 {"savedefconfig", required_argument
, NULL
, savedefconfig
},
450 {"allnoconfig", no_argument
, NULL
, allnoconfig
},
451 {"allyesconfig", no_argument
, NULL
, allyesconfig
},
452 {"allmodconfig", no_argument
, NULL
, allmodconfig
},
453 {"alldefconfig", no_argument
, NULL
, alldefconfig
},
454 {"randconfig", no_argument
, NULL
, randconfig
},
455 {"listnewconfig", no_argument
, NULL
, listnewconfig
},
456 {"oldnoconfig", no_argument
, NULL
, oldnoconfig
},
460 int main(int ac
, char **av
)
463 const char *name
, *defconfig_file
= NULL
/* gcc uninit */;
466 setlocale(LC_ALL
, "");
467 bindtextdomain(PACKAGE
, LOCALEDIR
);
470 while ((opt
= getopt_long(ac
, av
, "", long_opts
, NULL
)) != -1) {
471 input_mode
= (enum input_mode
)opt
;
473 case silentoldconfig
:
478 defconfig_file
= optarg
;
486 * Use microseconds derived seed,
487 * compensate for systems where it may be zero
489 gettimeofday(&now
, NULL
);
491 seed
= (unsigned int)((now
.tv_sec
+ 1) * (now
.tv_usec
+ 1));
496 fprintf(stderr
, _("See README for usage info\n"));
502 printf(_("%s: Kconfig file missing\n"), av
[0]);
509 name
= conf_get_configname();
510 if (stat(name
, &tmpstat
)) {
511 fprintf(stderr
, _("***\n"
512 "*** Configuration file \"%s\" not found!\n"
514 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
515 "*** \"make menuconfig\" or \"make xconfig\").\n"
521 switch (input_mode
) {
524 defconfig_file
= conf_get_default_confname();
525 if (conf_read(defconfig_file
)) {
527 "*** Can't find default configuration \"%s\"!\n"
528 "***\n"), defconfig_file
);
533 case silentoldconfig
:
545 name
= getenv("KCONFIG_ALLCONFIG");
546 if (name
&& !stat(name
, &tmpstat
)) {
547 conf_read_simple(name
, S_DEF_USER
);
550 switch (input_mode
) {
551 case allnoconfig
: name
= "allno.config"; break;
552 case allyesconfig
: name
= "allyes.config"; break;
553 case allmodconfig
: name
= "allmod.config"; break;
554 case alldefconfig
: name
= "alldef.config"; break;
555 case randconfig
: name
= "allrandom.config"; break;
558 if (!stat(name
, &tmpstat
))
559 conf_read_simple(name
, S_DEF_USER
);
560 else if (!stat("all.config", &tmpstat
))
561 conf_read_simple("all.config", S_DEF_USER
);
568 if (conf_get_changed()) {
569 name
= getenv("KCONFIG_NOSILENTUPDATE");
572 _("\n*** The configuration requires explicit update.\n\n"));
576 valid_stdin
= isatty(0) && isatty(1) && isatty(2);
579 switch (input_mode
) {
581 conf_set_all_new_symbols(def_no
);
584 conf_set_all_new_symbols(def_yes
);
587 conf_set_all_new_symbols(def_mod
);
590 conf_set_all_new_symbols(def_default
);
593 conf_set_all_new_symbols(def_random
);
596 conf_set_all_new_symbols(def_default
);
601 rootEntry
= &rootmenu
;
603 input_mode
= silentoldconfig
;
608 case silentoldconfig
:
609 /* Update until a loop caused no more changes */
612 check_conf(&rootmenu
);
614 (input_mode
!= listnewconfig
&&
615 input_mode
!= oldnoconfig
));
620 /* silentoldconfig is used during the build so we shall update autoconf.
621 * All other commands are only used to generate a config.
623 if (conf_get_changed() && conf_write(NULL
)) {
624 fprintf(stderr
, _("\n*** Error during writing of the configuration.\n\n"));
627 if (conf_write_autoconf()) {
628 fprintf(stderr
, _("\n*** Error during update of the configuration.\n\n"));
631 } else if (input_mode
== savedefconfig
) {
632 if (conf_write_defconfig(defconfig_file
)) {
633 fprintf(stderr
, _("n*** Error while saving defconfig to: %s\n\n"),
637 } else if (input_mode
!= listnewconfig
) {
638 if (conf_write(NULL
)) {
639 fprintf(stderr
, _("\n*** Error during writing of the configuration.\n\n"));
646 * Helper function to facilitate fgets() by Jean Sacren.
648 void xfgets(str
, size
, in
)
653 if (fgets(str
, size
, in
) == NULL
)
654 fprintf(stderr
, "\nError in reading or end of file.\n");
This page took 0.056001 seconds and 5 git commands to generate.