2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
13 #define LKC_DIRECT_LINK
16 static void conf(struct menu
*menu
);
17 static void check_conf(struct menu
*menu
);
28 } input_mode
= ask_all
;
31 static int indent
= 1;
32 static int valid_stdin
= 1;
34 static char line
[128];
35 static struct menu
*rootEntry
;
37 static char nohelp_text
[] = N_("Sorry, no help available for this option yet.\n");
39 static void strip(char *str
)
48 memmove(str
, p
, l
+ 1);
56 static void check_stdin(void)
58 if (!valid_stdin
&& input_mode
== ask_silent
) {
59 printf(_("aborted!\n\n"));
60 printf(_("Console input/output is redirected. "));
61 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
66 static char *fgets_check_stream(char *s
, int size
, FILE *stream
)
68 char *ret
= fgets(s
, size
, stream
);
70 if (ret
== NULL
&& feof(stream
)) {
71 printf(_("aborted!\n\n"));
72 printf(_("Console input is closed. "));
73 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
80 static void conf_askvalue(struct symbol
*sym
, const char *def
)
82 enum symbol_type type
= sym_get_type(sym
);
85 if (!sym_has_value(sym
))
91 if (!sym_is_changable(sym
)) {
103 if (sym_has_value(sym
)) {
110 if (sym_has_value(sym
)) {
117 fgets_check_stream(line
, 128, stdin
);
135 switch (input_mode
) {
137 if (sym_tristate_within_range(sym
, yes
)) {
144 if (type
== S_TRISTATE
) {
145 if (sym_tristate_within_range(sym
, mod
)) {
152 if (sym_tristate_within_range(sym
, yes
)) {
160 if (sym_tristate_within_range(sym
, no
)) {
168 val
= (tristate
)(random() % 3);
169 } while (!sym_tristate_within_range(sym
, val
));
171 case no
: line
[0] = 'n'; break;
172 case mod
: line
[0] = 'm'; break;
173 case yes
: line
[0] = 'y'; break;
184 int conf_string(struct menu
*menu
)
186 struct symbol
*sym
= menu
->sym
;
187 const char *def
, *help
;
190 printf("%*s%s ", indent
- 1, "", menu
->prompt
->text
);
191 printf("(%s) ", sym
->name
);
192 def
= sym_get_string_value(sym
);
193 if (sym_get_string_value(sym
))
194 printf("[%s] ", def
);
195 conf_askvalue(sym
, def
);
201 if (line
[1] == '\n') {
204 help
= menu
->sym
->help
;
205 printf("\n%s\n", menu
->sym
->help
);
210 line
[strlen(line
)-1] = 0;
213 if (def
&& sym_set_string_value(sym
, def
))
218 static int conf_sym(struct menu
*menu
)
220 struct symbol
*sym
= menu
->sym
;
222 tristate oldval
, newval
;
226 printf("%*s%s ", indent
- 1, "", menu
->prompt
->text
);
228 printf("(%s) ", sym
->name
);
229 type
= sym_get_type(sym
);
231 oldval
= sym_get_tristate_value(sym
);
243 if (oldval
!= no
&& sym_tristate_within_range(sym
, no
))
245 if (oldval
!= mod
&& sym_tristate_within_range(sym
, mod
))
247 if (oldval
!= yes
&& sym_tristate_within_range(sym
, yes
))
252 conf_askvalue(sym
, sym_get_string_value(sym
));
259 if (!line
[1] || !strcmp(&line
[1], "o"))
271 if (!line
[1] || !strcmp(&line
[1], "es"))
282 if (sym_set_tristate_value(sym
, newval
))
288 printf("\n%s\n", help
);
292 static int conf_choice(struct menu
*menu
)
294 struct symbol
*sym
, *def_sym
;
300 type
= sym_get_type(sym
);
301 is_new
= !sym_has_value(sym
);
302 if (sym_is_changable(sym
)) {
305 switch (sym_get_tristate_value(sym
)) {
314 switch (sym_get_tristate_value(sym
)) {
318 printf("%*s%s\n", indent
- 1, "", menu_get_prompt(menu
));
328 printf("%*s%s\n", indent
- 1, "", menu_get_prompt(menu
));
329 def_sym
= sym_get_choice_value(sym
);
333 for (child
= menu
->list
; child
; child
= child
->next
) {
334 if (!menu_is_visible(child
))
337 printf("%*c %s\n", indent
, '*', menu_get_prompt(child
));
341 if (child
->sym
== def_sym
) {
343 printf("%*c", indent
, '>');
345 printf("%*c", indent
, ' ');
346 printf(" %d. %s", cnt
, menu_get_prompt(child
));
347 if (child
->sym
->name
)
348 printf(" (%s)", child
->sym
->name
);
349 if (!sym_has_value(child
->sym
))
353 printf("%*schoice", indent
- 1, "");
358 printf("[1-%d", cnt
);
362 switch (input_mode
) {
373 fgets_check_stream(line
, 128, stdin
);
375 if (line
[0] == '?') {
376 printf("\n%s\n", menu
->sym
->help
?
377 menu
->sym
->help
: nohelp_text
);
382 else if (isdigit(line
[0]))
388 def
= (random() % cnt
) + 1;
399 for (child
= menu
->list
; child
; child
= child
->next
) {
400 if (!child
->sym
|| !menu_is_visible(child
))
407 if (line
[strlen(line
) - 1] == '?') {
408 printf("\n%s\n", child
->sym
->help
?
409 child
->sym
->help
: nohelp_text
);
412 sym_set_choice_value(sym
, child
->sym
);
422 static void conf(struct menu
*menu
)
425 struct property
*prop
;
428 if (!menu_is_visible(menu
))
436 switch (prop
->type
) {
438 if (input_mode
== ask_silent
&& rootEntry
!= menu
) {
443 prompt
= menu_get_prompt(menu
);
445 printf("%*c\n%*c %s\n%*c\n",
457 if (sym_is_choice(sym
)) {
459 if (sym
->curr
.tri
!= mod
)
478 for (child
= menu
->list
; child
; child
= child
->next
)
484 static void check_conf(struct menu
*menu
)
489 if (!menu_is_visible(menu
))
493 if (sym
&& !sym_has_value(sym
)) {
494 if (sym_is_changable(sym
) ||
495 (sym_is_choice(sym
) && sym_get_tristate_value(sym
) == yes
)) {
497 printf(_("*\n* Restart config...\n*\n"));
498 rootEntry
= menu_get_parent_menu(menu
);
503 for (child
= menu
->list
; child
; child
= child
->next
)
507 int main(int ac
, char **av
)
513 if (ac
> i
&& av
[i
][0] == '-') {
514 switch (av
[i
++][1]) {
516 input_mode
= ask_new
;
519 input_mode
= ask_silent
;
520 valid_stdin
= isatty(0) && isatty(1) && isatty(2);
523 input_mode
= set_default
;
526 input_mode
= set_default
;
527 defconfig_file
= av
[i
++];
528 if (!defconfig_file
) {
529 printf(_("%s: No default config file specified\n"),
538 input_mode
= set_mod
;
541 input_mode
= set_yes
;
544 input_mode
= set_random
;
549 printf("%s [-o|-s] config\n", av
[0]);
555 printf(_("%s: Kconfig file missing\n"), av
[0]);
559 switch (input_mode
) {
562 defconfig_file
= conf_get_default_confname();
563 if (conf_read(defconfig_file
)) {
565 "*** Can't find default configuration \"%s\"!\n"
566 "***\n", defconfig_file
);
571 if (stat(".config", &tmpstat
)) {
573 "*** You have not yet configured your build!\n"
575 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
576 "*** \"make menuconfig\" or \"make xconfig\").\n"
592 if (input_mode
!= ask_silent
) {
593 rootEntry
= &rootmenu
;
595 if (input_mode
== ask_all
) {
596 input_mode
= ask_silent
;
602 check_conf(&rootmenu
);
604 if (conf_write(NULL
)) {
605 fprintf(stderr
, _("\n*** Error during writing of the build configuration.\n\n"));
This page took 0.084469 seconds and 5 git commands to generate.