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
[] = "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 void conf_askvalue(struct symbol
*sym
, const char *def
)
68 enum symbol_type type
= sym_get_type(sym
);
71 if (!sym_has_value(sym
))
77 if (!sym_is_changable(sym
)) {
87 if (sym_has_value(sym
)) {
94 fgets(line
, 128, stdin
);
112 switch (input_mode
) {
114 if (sym_tristate_within_range(sym
, yes
)) {
121 if (type
== S_TRISTATE
) {
122 if (sym_tristate_within_range(sym
, mod
)) {
129 if (sym_tristate_within_range(sym
, yes
)) {
137 if (sym_tristate_within_range(sym
, no
)) {
145 val
= (tristate
)(random() % 3);
146 } while (!sym_tristate_within_range(sym
, val
));
148 case no
: line
[0] = 'n'; break;
149 case mod
: line
[0] = 'm'; break;
150 case yes
: line
[0] = 'y'; break;
161 int conf_string(struct menu
*menu
)
163 struct symbol
*sym
= menu
->sym
;
164 const char *def
, *help
;
167 printf("%*s%s ", indent
- 1, "", menu
->prompt
->text
);
168 printf("(%s) ", sym
->name
);
169 def
= sym_get_string_value(sym
);
170 if (sym_get_string_value(sym
))
171 printf("[%s] ", def
);
172 conf_askvalue(sym
, def
);
178 if (line
[1] == '\n') {
181 help
= menu
->sym
->help
;
182 printf("\n%s\n", menu
->sym
->help
);
187 line
[strlen(line
)-1] = 0;
190 if (def
&& sym_set_string_value(sym
, def
))
195 static int conf_sym(struct menu
*menu
)
197 struct symbol
*sym
= menu
->sym
;
199 tristate oldval
, newval
;
203 printf("%*s%s ", indent
- 1, "", menu
->prompt
->text
);
205 printf("(%s) ", sym
->name
);
206 type
= sym_get_type(sym
);
208 oldval
= sym_get_tristate_value(sym
);
220 if (oldval
!= no
&& sym_tristate_within_range(sym
, no
))
222 if (oldval
!= mod
&& sym_tristate_within_range(sym
, mod
))
224 if (oldval
!= yes
&& sym_tristate_within_range(sym
, yes
))
229 conf_askvalue(sym
, sym_get_string_value(sym
));
236 if (!line
[1] || !strcmp(&line
[1], "o"))
248 if (!line
[1] || !strcmp(&line
[1], "es"))
259 if (sym_set_tristate_value(sym
, newval
))
265 printf("\n%s\n", help
);
269 static int conf_choice(struct menu
*menu
)
271 struct symbol
*sym
, *def_sym
;
277 type
= sym_get_type(sym
);
278 is_new
= !sym_has_value(sym
);
279 if (sym_is_changable(sym
)) {
282 switch (sym_get_tristate_value(sym
)) {
291 switch (sym_get_tristate_value(sym
)) {
295 printf("%*s%s\n", indent
- 1, "", menu_get_prompt(menu
));
305 printf("%*s%s\n", indent
- 1, "", menu_get_prompt(menu
));
306 def_sym
= sym_get_choice_value(sym
);
310 for (child
= menu
->list
; child
; child
= child
->next
) {
311 if (!menu_is_visible(child
))
314 printf("%*c %s\n", indent
, '*', menu_get_prompt(child
));
318 if (child
->sym
== def_sym
) {
320 printf("%*c", indent
, '>');
322 printf("%*c", indent
, ' ');
323 printf(" %d. %s", cnt
, menu_get_prompt(child
));
324 if (child
->sym
->name
)
325 printf(" (%s)", child
->sym
->name
);
326 if (!sym_has_value(child
->sym
))
330 printf("%*schoice", indent
- 1, "");
335 printf("[1-%d", cnt
);
339 switch (input_mode
) {
350 fgets(line
, 128, stdin
);
352 if (line
[0] == '?') {
353 printf("\n%s\n", menu
->sym
->help
?
354 menu
->sym
->help
: nohelp_text
);
359 else if (isdigit(line
[0]))
365 def
= (random() % cnt
) + 1;
376 for (child
= menu
->list
; child
; child
= child
->next
) {
377 if (!child
->sym
|| !menu_is_visible(child
))
384 if (line
[strlen(line
) - 1] == '?') {
385 printf("\n%s\n", child
->sym
->help
?
386 child
->sym
->help
: nohelp_text
);
389 sym_set_choice_value(sym
, child
->sym
);
399 static void conf(struct menu
*menu
)
402 struct property
*prop
;
405 if (!menu_is_visible(menu
))
413 switch (prop
->type
) {
415 if (input_mode
== ask_silent
&& rootEntry
!= menu
) {
420 prompt
= menu_get_prompt(menu
);
422 printf("%*c\n%*c %s\n%*c\n",
434 if (sym_is_choice(sym
)) {
436 if (sym
->curr
.tri
!= mod
)
455 for (child
= menu
->list
; child
; child
= child
->next
)
461 static void check_conf(struct menu
*menu
)
466 if (!menu_is_visible(menu
))
471 if (sym_is_changable(sym
) && !sym_has_value(sym
)) {
473 printf("*\n* Restart config...\n*\n");
474 rootEntry
= menu_get_parent_menu(menu
);
477 if (sym_is_choice(sym
) && sym_get_tristate_value(sym
) != mod
)
481 for (child
= menu
->list
; child
; child
= child
->next
)
485 int main(int ac
, char **av
)
491 if (ac
> i
&& av
[i
][0] == '-') {
492 switch (av
[i
++][1]) {
494 input_mode
= ask_new
;
497 input_mode
= ask_silent
;
498 valid_stdin
= isatty(0) && isatty(1) && isatty(2);
501 input_mode
= set_default
;
504 input_mode
= set_default
;
505 defconfig_file
= av
[i
++];
506 if (!defconfig_file
) {
507 printf("%s: No default config file specified\n",
516 input_mode
= set_mod
;
519 input_mode
= set_yes
;
522 input_mode
= set_random
;
527 printf("%s [-o|-s] config\n", av
[0]);
533 printf("%s: configuration file missing\n", av
[0]);
537 switch (input_mode
) {
540 defconfig_file
= conf_get_default_confname();
541 if (conf_read(defconfig_file
)) {
543 "*** Can't find default configuration \"%s\"!\n"
544 "***\n", defconfig_file
);
549 if (stat(".config", &tmpstat
)) {
551 "*** You have not yet configured Buildroot!\n"
553 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
554 "*** \"make menuconfig\" or \"make config\").\n"
566 if (input_mode
!= ask_silent
) {
567 rootEntry
= &rootmenu
;
569 if (input_mode
== ask_all
) {
570 input_mode
= ask_silent
;
576 check_conf(&rootmenu
);
578 if (conf_write(NULL
)) {
579 fprintf(stderr
, "\n*** Error during writing of the Buildroot configuration.\n\n");
This page took 0.072442 seconds and 5 git commands to generate.