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";
38 static void strip(char *str)
47 memmove(str, p, l + 1);
55 static void check_stdin(void)
57 if (!valid_stdin && input_mode == ask_silent) {
58 printf("aborted!\n\n");
59 printf("Console input/output is redirected. ");
60 printf("Run 'make oldconfig' to update configuration.\n\n");
65 static void conf_askvalue(struct symbol *sym, const char *def)
67 enum symbol_type type = sym_get_type(sym);
70 if (!sym_has_value(sym))
76 if (!sym_is_changable(sym)) {
86 if (sym_has_value(sym)) {
93 fgets(line, 128, stdin);
111 switch (input_mode) {
113 if (sym_tristate_within_range(sym, yes)) {
120 if (type == S_TRISTATE) {
121 if (sym_tristate_within_range(sym, mod)) {
128 if (sym_tristate_within_range(sym, yes)) {
136 if (sym_tristate_within_range(sym, no)) {
144 val = (tristate)(random() % 3);
145 } while (!sym_tristate_within_range(sym, val));
147 case no: line[0] = 'n'; break;
148 case mod: line[0] = 'm'; break;
149 case yes: line[0] = 'y'; break;
160 int conf_string(struct menu *menu)
162 struct symbol *sym = menu->sym;
163 const char *def, *help;
166 printf("%*s%s ", indent - 1, "", menu->prompt->text);
167 printf("(%s) ", sym->name);
168 def = sym_get_string_value(sym);
169 if (sym_get_string_value(sym))
170 printf("[%s] ", def);
171 conf_askvalue(sym, def);
180 help = menu->sym->help;
181 printf("\n%s\n", menu->sym->help);
186 line[strlen(line)-1] = 0;
189 if (def && sym_set_string_value(sym, def))
194 static int conf_sym(struct menu *menu)
196 struct symbol *sym = menu->sym;
198 tristate oldval, newval;
202 printf("%*s%s ", indent - 1, "", menu->prompt->text);
204 printf("(%s) ", sym->name);
205 type = sym_get_type(sym);
207 oldval = sym_get_tristate_value(sym);
219 if (oldval != no && sym_tristate_within_range(sym, no))
221 if (oldval != mod && sym_tristate_within_range(sym, mod))
223 if (oldval != yes && sym_tristate_within_range(sym, yes))
228 conf_askvalue(sym, sym_get_string_value(sym));
235 if (!line[1] || !strcmp(&line[1], "o"))
247 if (!line[1] || !strcmp(&line[1], "es"))
258 if (sym_set_tristate_value(sym, newval))
264 printf("\n%s\n", help);
268 static int conf_choice(struct menu *menu)
270 struct symbol *sym, *def_sym;
276 type = sym_get_type(sym);
277 is_new = !sym_has_value(sym);
278 if (sym_is_changable(sym)) {
281 switch (sym_get_tristate_value(sym)) {
290 switch (sym_get_tristate_value(sym)) {
294 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
304 printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
305 def_sym = sym_get_choice_value(sym);
309 for (child = menu->list; child; child = child->next) {
310 if (!menu_is_visible(child))
313 printf("%*c %s\n", indent, '*', menu_get_prompt(child));
317 if (child->sym == def_sym) {
319 printf("%*c", indent, '>');
321 printf("%*c", indent, ' ');
322 printf(" %d. %s", cnt, menu_get_prompt(child));
323 if (child->sym->name)
324 printf(" (%s)", child->sym->name);
325 if (!sym_has_value(child->sym))
329 printf("%*schoice", indent - 1, "");
334 printf("[1-%d", cnt);
338 switch (input_mode) {
349 fgets(line, 128, stdin);
351 if (line[0] == '?') {
352 printf("\n%s\n", menu->sym->help ?
353 menu->sym->help : nohelp_text);
358 else if (isdigit(line[0]))
364 def = (random() % cnt) + 1;
375 for (child = menu->list; child; child = child->next) {
376 if (!child->sym || !menu_is_visible(child))
383 if (line[strlen(line) - 1] == '?') {
384 printf("\n%s\n", child->sym->help ?
385 child->sym->help : nohelp_text);
388 sym_set_choice_value(sym, child->sym);
398 static void conf(struct menu *menu)
401 struct property *prop;
404 if (!menu_is_visible(menu))
412 switch (prop->type) {
414 if (input_mode == ask_silent && rootEntry != menu) {
419 prompt = menu_get_prompt(menu);
421 printf("%*c\n%*c %s\n%*c\n",
433 if (sym_is_choice(sym)) {
435 if (sym->curr.tri != mod)
454 for (child = menu->list; child; child = child->next)
460 static void check_conf(struct menu *menu)
465 if (!menu_is_visible(menu))
470 if (sym_is_changable(sym) && !sym_has_value(sym)) {
472 printf("*\n* Restart config...\n*\n");
473 rootEntry = menu_get_parent_menu(menu);
476 if (sym_is_choice(sym) && sym_get_tristate_value(sym) != mod)
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 BusyBox!\n"
539 "*** Please run some configurator (e.g. \"make config\" or\n"
540 "*** \"make oldconfig\" 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);