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 printc(int ch)
57 static void printo(const char *o)
76 static void strip(char *str)
81 while ((isspace((int)*p)))
85 memmove(str, p, l + 1);
89 while ((isspace((int)*p)))
93 static void conf_askvalue(struct symbol *sym, const char *def)
95 enum symbol_type type = sym_get_type(sym);
98 if (!sym_has_value(sym))
104 switch (input_mode) {
107 if (sym_has_value(sym)) {
111 if (!valid_stdin && input_mode == ask_silent) {
112 printf("aborted!\n\n");
113 printf("Console input/output is redirected. ");
114 printf("Run 'make oldconfig' to update configuration.\n\n");
119 fgets(line, 128, stdin);
137 switch (input_mode) {
139 if (sym_tristate_within_range(sym, yes)) {
146 if (type == S_TRISTATE) {
147 if (sym_tristate_within_range(sym, mod)) {
154 if (sym_tristate_within_range(sym, yes)) {
162 if (sym_tristate_within_range(sym, no)) {
170 val = (tristate)(random() % 3);
171 } while (!sym_tristate_within_range(sym, val));
173 case no: line[0] = 'n'; break;
174 case mod: line[0] = 'm'; break;
175 case yes: line[0] = 'y'; break;
186 int conf_string(struct menu *menu)
188 struct symbol *sym = menu->sym;
189 const char *def, *help;
192 printf("%*s%s ", indent - 1, "", menu->prompt->text);
193 printf("(%s) ", sym->name);
194 def = sym_get_string_value(sym);
195 if (sym_get_string_value(sym))
196 printf("[%s] ", def);
197 conf_askvalue(sym, def);
206 help = menu->sym->help;
207 printf("\n%s\n", menu->sym->help);
212 line[strlen(line)-1] = 0;
215 if (def && sym_set_string_value(sym, def))
220 static int conf_sym(struct menu *menu)
222 struct symbol *sym = menu->sym;
224 tristate oldval, newval;
228 printf("%*s%s ", indent - 1, "", menu->prompt->text);
230 printf("(%s) ", sym->name);
231 type = sym_get_type(sym);
233 oldval = sym_get_tristate_value(sym);
245 if (oldval != no && sym_tristate_within_range(sym, no))
247 if (oldval != mod && sym_tristate_within_range(sym, mod))
249 if (oldval != yes && sym_tristate_within_range(sym, yes))
254 conf_askvalue(sym, sym_get_string_value(sym));
261 if (!line[1] || !strcmp(&line[1], "o"))
273 if (!line[1] || !strcmp(&line[1], "es"))
284 if (sym_set_tristate_value(sym, newval))
290 printf("\n%s\n", help);
294 static int conf_choice(struct menu *menu)
296 struct symbol *sym, *def_sym;
297 struct menu *cmenu, *def_menu;
303 type = sym_get_type(sym);
304 is_new = !sym_has_value(sym);
305 if (sym_is_changable(sym)) {
308 switch (sym_get_tristate_value(sym)) {
317 sym->def = sym->curr;
318 if (S_TRI(sym->curr) == mod) {
319 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
325 printf("%*s%s ", indent - 1, "", menu_get_prompt(menu));
326 def_sym = sym_get_choice_value(sym);
328 for (cmenu = menu->list; cmenu; cmenu = cmenu->next) {
329 if (!menu_is_visible(cmenu))
331 printo(menu_get_prompt(cmenu));
332 if (cmenu->sym == def_sym)
337 printf("[%s] ", menu_get_prompt(def_menu));
342 switch (input_mode) {
346 conf_askvalue(sym, menu_get_prompt(def_menu));
353 if (line[0] == '?' && !line[1]) {
356 help = menu->sym->help;
357 printf("\n%s\n", help);
365 for (cmenu = menu->list; cmenu; cmenu = cmenu->next) {
366 if (!cmenu->sym || !menu_is_visible(cmenu))
368 if (!strncasecmp(line, menu_get_prompt(cmenu), len)) {
375 sym_set_choice_value(sym, def_menu->sym);
376 if (def_menu->list) {
378 conf(def_menu->list);
386 static void conf(struct menu *menu)
389 struct property *prop;
392 if (!menu_is_visible(menu))
400 switch (prop->type) {
402 if (input_mode == ask_silent && rootEntry != menu) {
407 prompt = menu_get_prompt(menu);
409 printf("%*c\n%*c %s\n%*c\n",
421 if (sym_is_choice(sym)) {
423 if (S_TRI(sym->curr) != mod)
442 for (child = menu->list; child; child = child->next)
448 static void check_conf(struct menu *menu)
453 if (!menu_is_visible(menu))
460 if (sym_is_choice(sym)) {
461 if (!sym_has_value(sym)) {
463 printf("*\n* Restart config...\n*\n");
464 rootEntry = menu_get_parent_menu(menu);
467 if (sym_get_tristate_value(sym) != mod)
472 if (!sym_has_value(sym)) {
474 printf("*\n* Restart config...\n*\n");
475 rootEntry = menu_get_parent_menu(menu);
480 for (child = menu->list; child; child = child->next)
484 int main(int ac, char **av)
489 if (ac > 1 && av[1][0] == '-') {
492 input_mode = ask_new;
495 input_mode = ask_silent;
496 valid_stdin = isatty(0) && isatty(1) && isatty(2);
499 input_mode = set_default;
505 input_mode = set_mod;
508 input_mode = set_yes;
511 input_mode = set_random;
516 printf("%s [-o|-s] config\n", av[0]);
524 switch (input_mode) {
526 name = conf_get_default_confname();
527 if (conf_read(name)) {
529 "*** Can't find default configuration \"%s\"!\n"
535 if (stat(".config", &tmpstat)) {
537 "*** You have not yet configured uClibc!\n"
539 "*** Please run some configurator (e.g. \"make oldconfig\"\n"
540 "*** or \"make menuconfig\").\n"
552 if (input_mode != ask_silent) {
553 rootEntry = &rootmenu;
555 if (input_mode == ask_all) {
556 input_mode = ask_silent;
562 check_conf(&rootmenu);