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
;
30 static int indent
= 1;
31 static int valid_stdin
= 1;
33 static char line
[128];
34 static struct menu
*rootEntry
;
36 static char nohelp_text
[] = "Sorry, no help available for this option yet.\n";
39 static void printo(const char *o
)
58 static void strip(char *str
)
63 while ((isspace((int)*p
)))
67 memmove(str
, p
, l
+ 1);
71 while ((isspace((int)*p
)))
75 static void conf_askvalue(struct symbol
*sym
, const char *def
)
77 enum symbol_type type
= sym_get_type(sym
);
80 if (!sym_has_value(sym
))
89 if (sym_has_value(sym
)) {
93 if (!valid_stdin
&& input_mode
== ask_silent
) {
94 printf("aborted!\n\n");
95 printf("Console input/output is redirected. ");
96 printf("Run 'make oldconfig' to update configuration.\n\n");
101 fgets(line
, 128, stdin
);
119 switch (input_mode
) {
121 if (sym_tristate_within_range(sym
, yes
)) {
128 if (type
== S_TRISTATE
) {
129 if (sym_tristate_within_range(sym
, mod
)) {
136 if (sym_tristate_within_range(sym
, yes
)) {
144 if (sym_tristate_within_range(sym
, no
)) {
152 val
= (tristate
)(random() % 3);
153 } while (!sym_tristate_within_range(sym
, val
));
155 case no
: line
[0] = 'n'; break;
156 case mod
: line
[0] = 'm'; break;
157 case yes
: line
[0] = 'y'; break;
168 int conf_string(struct menu
*menu
)
170 struct symbol
*sym
= menu
->sym
;
171 const char *def
, *help
;
174 printf("%*s%s ", indent
- 1, "", menu
->prompt
->text
);
175 printf("(%s) ", sym
->name
);
176 def
= sym_get_string_value(sym
);
177 if (sym_get_string_value(sym
))
178 printf("[%s] ", def
);
179 conf_askvalue(sym
, def
);
188 help
= menu
->sym
->help
;
189 printf("\n%s\n", menu
->sym
->help
);
194 line
[strlen(line
)-1] = 0;
197 if (def
&& sym_set_string_value(sym
, def
))
202 static int conf_sym(struct menu
*menu
)
204 struct symbol
*sym
= menu
->sym
;
206 tristate oldval
, newval
;
210 printf("%*s%s ", indent
- 1, "", menu
->prompt
->text
);
212 printf("(%s) ", sym
->name
);
213 type
= sym_get_type(sym
);
215 oldval
= sym_get_tristate_value(sym
);
227 if (oldval
!= no
&& sym_tristate_within_range(sym
, no
))
229 if (oldval
!= mod
&& sym_tristate_within_range(sym
, mod
))
231 if (oldval
!= yes
&& sym_tristate_within_range(sym
, yes
))
236 conf_askvalue(sym
, sym_get_string_value(sym
));
243 if (!line
[1] || !strcmp(&line
[1], "o"))
255 if (!line
[1] || !strcmp(&line
[1], "es"))
266 if (sym_set_tristate_value(sym
, newval
))
272 printf("\n%s\n", help
);
276 static int conf_choice(struct menu
*menu
)
278 struct symbol
*sym
, *def_sym
;
279 struct menu
*cmenu
, *def_menu
;
285 type
= sym_get_type(sym
);
286 is_new
= !sym_has_value(sym
);
287 if (sym_is_changable(sym
)) {
290 switch (sym_get_tristate_value(sym
)) {
299 sym
->def
= sym
->curr
;
300 if (S_TRI(sym
->curr
) == mod
) {
301 printf("%*s%s\n", indent
- 1, "", menu_get_prompt(menu
));
307 printf("%*s%s ", indent
- 1, "", menu_get_prompt(menu
));
308 def_sym
= sym_get_choice_value(sym
);
310 for (cmenu
= menu
->list
; cmenu
; cmenu
= cmenu
->next
) {
311 if (!menu_is_visible(cmenu
))
313 printo(menu_get_prompt(cmenu
));
314 if (cmenu
->sym
== def_sym
)
319 printf("[%s] ", menu_get_prompt(def_menu
));
324 switch (input_mode
) {
328 conf_askvalue(sym
, menu_get_prompt(def_menu
));
335 if (line
[0] == '?' && !line
[1]) {
338 help
= menu
->sym
->help
;
339 printf("\n%s\n", help
);
347 for (cmenu
= menu
->list
; cmenu
; cmenu
= cmenu
->next
) {
348 if (!cmenu
->sym
|| !menu_is_visible(cmenu
))
350 if (!strncasecmp(line
, menu_get_prompt(cmenu
), len
)) {
357 sym_set_choice_value(sym
, def_menu
->sym
);
358 if (def_menu
->list
) {
360 conf(def_menu
->list
);
368 static void conf(struct menu
*menu
)
371 struct property
*prop
;
374 if (!menu_is_visible(menu
))
382 switch (prop
->type
) {
384 if (input_mode
== ask_silent
&& rootEntry
!= menu
) {
389 prompt
= menu_get_prompt(menu
);
391 printf("%*c\n%*c %s\n%*c\n",
403 if (sym_is_choice(sym
)) {
405 if (S_TRI(sym
->curr
) != mod
)
424 for (child
= menu
->list
; child
; child
= child
->next
)
430 static void check_conf(struct menu
*menu
)
435 if (!menu_is_visible(menu
))
442 if (sym_is_choice(sym
)) {
443 if (!sym_has_value(sym
)) {
445 printf("*\n* Restart config...\n*\n");
446 rootEntry
= menu_get_parent_menu(menu
);
449 if (sym_get_tristate_value(sym
) != mod
)
454 if (!sym_has_value(sym
)) {
456 printf("*\n* Restart config...\n*\n");
457 rootEntry
= menu_get_parent_menu(menu
);
462 for (child
= menu
->list
; child
; child
= child
->next
)
466 int main(int ac
, char **av
)
471 if (ac
> 1 && av
[1][0] == '-') {
474 input_mode
= ask_new
;
477 input_mode
= ask_silent
;
478 valid_stdin
= isatty(0) && isatty(1) && isatty(2);
481 input_mode
= set_default
;
487 input_mode
= set_mod
;
490 input_mode
= set_yes
;
493 input_mode
= set_random
;
498 printf("%s [-o|-s] config\n", av
[0]);
506 switch (input_mode
) {
508 name
= conf_get_default_confname();
509 if (conf_read(name
)) {
511 "*** Can't find default configuration \"%s\"!\n"
517 if (stat(".config", &tmpstat
)) {
519 "*** You have not yet configured!\n"
521 "*** Please run some configurator (e.g. \"make oldconfig\"\n"
522 "*** or \"make menuconfig\").\n"
534 if (input_mode
!= ask_silent
) {
535 rootEntry
= &rootmenu
;
537 if (input_mode
== ask_all
) {
538 input_mode
= ask_silent
;
544 check_conf(&rootmenu
);