diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-06 13:51:04 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-06 13:51:04 +0000 |
commit | 4fa499a17b52b299abc3a6ddd289bb6ca74bb84b (patch) | |
tree | 17df4dd427d85319857d9b7882585b3db9ad6994 /scripts/config/conf.c | |
parent | c12f53090bd41dbb87279083bc442769cb0610f0 (diff) | |
download | busybox-w32-4fa499a17b52b299abc3a6ddd289bb6ca74bb84b.tar.gz busybox-w32-4fa499a17b52b299abc3a6ddd289bb6ca74bb84b.tar.bz2 busybox-w32-4fa499a17b52b299abc3a6ddd289bb6ca74bb84b.zip |
build system: remove loeftover (two empty dirs)
Diffstat (limited to 'scripts/config/conf.c')
-rw-r--r-- | scripts/config/conf.c | 584 |
1 files changed, 0 insertions, 584 deletions
diff --git a/scripts/config/conf.c b/scripts/config/conf.c deleted file mode 100644 index 2da5ff7a7..000000000 --- a/scripts/config/conf.c +++ /dev/null | |||
@@ -1,584 +0,0 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> | ||
4 | * Released under the terms of the GNU GPL v2.0. | ||
5 | */ | ||
6 | |||
7 | #include <ctype.h> | ||
8 | #include <stdlib.h> | ||
9 | #include <string.h> | ||
10 | #include <unistd.h> | ||
11 | #include <time.h> | ||
12 | #include <sys/stat.h> | ||
13 | |||
14 | #define LKC_DIRECT_LINK | ||
15 | #include "lkc.h" | ||
16 | |||
17 | static void conf(struct menu *menu); | ||
18 | static void check_conf(struct menu *menu); | ||
19 | |||
20 | enum { | ||
21 | ask_all, | ||
22 | ask_new, | ||
23 | ask_silent, | ||
24 | set_default, | ||
25 | set_yes, | ||
26 | set_mod, | ||
27 | set_no, | ||
28 | set_random | ||
29 | } input_mode = ask_all; | ||
30 | char *defconfig_file; | ||
31 | |||
32 | static int indent = 1; | ||
33 | static int valid_stdin = 1; | ||
34 | static int conf_cnt; | ||
35 | static char line[128]; | ||
36 | static struct menu *rootEntry; | ||
37 | |||
38 | static char nohelp_text[] = "Sorry, no help available for this option yet.\n"; | ||
39 | |||
40 | static void strip(char *str) | ||
41 | { | ||
42 | char *p = str; | ||
43 | int l; | ||
44 | |||
45 | while ((isspace(*p))) | ||
46 | p++; | ||
47 | l = strlen(p); | ||
48 | if (p != str) | ||
49 | memmove(str, p, l + 1); | ||
50 | if (!l) | ||
51 | return; | ||
52 | p = str + l - 1; | ||
53 | while ((isspace(*p))) | ||
54 | *p-- = 0; | ||
55 | } | ||
56 | |||
57 | static void check_stdin(void) | ||
58 | { | ||
59 | if (!valid_stdin && input_mode == ask_silent) { | ||
60 | printf("aborted!\n\n"); | ||
61 | printf("Console input/output is redirected. "); | ||
62 | printf("Run 'make oldconfig' to update configuration.\n\n"); | ||
63 | exit(1); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | static void conf_askvalue(struct symbol *sym, const char *def) | ||
68 | { | ||
69 | enum symbol_type type = sym_get_type(sym); | ||
70 | tristate val; | ||
71 | |||
72 | if (!sym_has_value(sym)) | ||
73 | printf("(NEW) "); | ||
74 | |||
75 | line[0] = '\n'; | ||
76 | line[1] = 0; | ||
77 | |||
78 | if (!sym_is_changable(sym)) { | ||
79 | printf("%s\n", def); | ||
80 | line[0] = '\n'; | ||
81 | line[1] = 0; | ||
82 | return; | ||
83 | } | ||
84 | |||
85 | switch (input_mode) { | ||
86 | case ask_new: | ||
87 | case ask_silent: | ||
88 | if (sym_has_value(sym)) { | ||
89 | printf("%s\n", def); | ||
90 | return; | ||
91 | } | ||
92 | check_stdin(); | ||
93 | case ask_all: | ||
94 | fflush(stdout); | ||
95 | fgets(line, 128, stdin); | ||
96 | return; | ||
97 | case set_default: | ||
98 | printf("%s\n", def); | ||
99 | return; | ||
100 | default: | ||
101 | break; | ||
102 | } | ||
103 | |||
104 | switch (type) { | ||
105 | case S_INT: | ||
106 | case S_HEX: | ||
107 | case S_STRING: | ||
108 | printf("%s\n", def); | ||
109 | return; | ||
110 | default: | ||
111 | ; | ||
112 | } | ||
113 | switch (input_mode) { | ||
114 | case set_yes: | ||
115 | if (sym_tristate_within_range(sym, yes)) { | ||
116 | line[0] = 'y'; | ||
117 | line[1] = '\n'; | ||
118 | line[2] = 0; | ||
119 | break; | ||
120 | } | ||
121 | case set_mod: | ||
122 | if (type == S_TRISTATE) { | ||
123 | if (sym_tristate_within_range(sym, mod)) { | ||
124 | line[0] = 'm'; | ||
125 | line[1] = '\n'; | ||
126 | line[2] = 0; | ||
127 | break; | ||
128 | } | ||
129 | } else { | ||
130 | if (sym_tristate_within_range(sym, yes)) { | ||
131 | line[0] = 'y'; | ||
132 | line[1] = '\n'; | ||
133 | line[2] = 0; | ||
134 | break; | ||
135 | } | ||
136 | } | ||
137 | case set_no: | ||
138 | if (sym_tristate_within_range(sym, no)) { | ||
139 | line[0] = 'n'; | ||
140 | line[1] = '\n'; | ||
141 | line[2] = 0; | ||
142 | break; | ||
143 | } | ||
144 | case set_random: | ||
145 | do { | ||
146 | val = (tristate)(random() % 3); | ||
147 | } while (!sym_tristate_within_range(sym, val)); | ||
148 | switch (val) { | ||
149 | case no: line[0] = 'n'; break; | ||
150 | case mod: line[0] = 'm'; break; | ||
151 | case yes: line[0] = 'y'; break; | ||
152 | } | ||
153 | line[1] = '\n'; | ||
154 | line[2] = 0; | ||
155 | break; | ||
156 | default: | ||
157 | break; | ||
158 | } | ||
159 | printf("%s", line); | ||
160 | } | ||
161 | |||
162 | int conf_string(struct menu *menu) | ||
163 | { | ||
164 | struct symbol *sym = menu->sym; | ||
165 | const char *def, *help; | ||
166 | |||
167 | while (1) { | ||
168 | printf("%*s%s ", indent - 1, "", menu->prompt->text); | ||
169 | printf("(%s) ", sym->name); | ||
170 | def = sym_get_string_value(sym); | ||
171 | if (sym_get_string_value(sym)) | ||
172 | printf("[%s] ", def); | ||
173 | conf_askvalue(sym, def); | ||
174 | switch (line[0]) { | ||
175 | case '\n': | ||
176 | break; | ||
177 | case '?': | ||
178 | /* print help */ | ||
179 | if (line[1] == '\n') { | ||
180 | help = nohelp_text; | ||
181 | if (menu->sym->help) | ||
182 | help = menu->sym->help; | ||
183 | printf("\n%s\n", menu->sym->help); | ||
184 | def = NULL; | ||
185 | break; | ||
186 | } | ||
187 | default: | ||
188 | line[strlen(line)-1] = 0; | ||
189 | def = line; | ||
190 | } | ||
191 | if (def && sym_set_string_value(sym, def)) | ||
192 | return 0; | ||
193 | } | ||
194 | } | ||
195 | |||
196 | static int conf_sym(struct menu *menu) | ||
197 | { | ||
198 | struct symbol *sym = menu->sym; | ||
199 | int type; | ||
200 | tristate oldval, newval; | ||
201 | const char *help; | ||
202 | |||
203 | while (1) { | ||
204 | printf("%*s%s ", indent - 1, "", menu->prompt->text); | ||
205 | if (sym->name) | ||
206 | printf("(%s) ", sym->name); | ||
207 | type = sym_get_type(sym); | ||
208 | putchar('['); | ||
209 | oldval = sym_get_tristate_value(sym); | ||
210 | switch (oldval) { | ||
211 | case no: | ||
212 | putchar('N'); | ||
213 | break; | ||
214 | case mod: | ||
215 | putchar('M'); | ||
216 | break; | ||
217 | case yes: | ||
218 | putchar('Y'); | ||
219 | break; | ||
220 | } | ||
221 | if (oldval != no && sym_tristate_within_range(sym, no)) | ||
222 | printf("/n"); | ||
223 | if (oldval != mod && sym_tristate_within_range(sym, mod)) | ||
224 | printf("/m"); | ||
225 | if (oldval != yes && sym_tristate_within_range(sym, yes)) | ||
226 | printf("/y"); | ||
227 | if (sym->help) | ||
228 | printf("/?"); | ||
229 | printf("] "); | ||
230 | conf_askvalue(sym, sym_get_string_value(sym)); | ||
231 | strip(line); | ||
232 | |||
233 | switch (line[0]) { | ||
234 | case 'n': | ||
235 | case 'N': | ||
236 | newval = no; | ||
237 | if (!line[1] || !strcmp(&line[1], "o")) | ||
238 | break; | ||
239 | continue; | ||
240 | case 'm': | ||
241 | case 'M': | ||
242 | newval = mod; | ||
243 | if (!line[1]) | ||
244 | break; | ||
245 | continue; | ||
246 | case 'y': | ||
247 | case 'Y': | ||
248 | newval = yes; | ||
249 | if (!line[1] || !strcmp(&line[1], "es")) | ||
250 | break; | ||
251 | continue; | ||
252 | case 0: | ||
253 | newval = oldval; | ||
254 | break; | ||
255 | case '?': | ||
256 | goto help; | ||
257 | default: | ||
258 | continue; | ||
259 | } | ||
260 | if (sym_set_tristate_value(sym, newval)) | ||
261 | return 0; | ||
262 | help: | ||
263 | help = nohelp_text; | ||
264 | if (sym->help) | ||
265 | help = sym->help; | ||
266 | printf("\n%s\n", help); | ||
267 | } | ||
268 | } | ||
269 | |||
270 | static int conf_choice(struct menu *menu) | ||
271 | { | ||
272 | struct symbol *sym, *def_sym; | ||
273 | struct menu *child; | ||
274 | int type; | ||
275 | bool is_new; | ||
276 | |||
277 | sym = menu->sym; | ||
278 | type = sym_get_type(sym); | ||
279 | is_new = !sym_has_value(sym); | ||
280 | if (sym_is_changable(sym)) { | ||
281 | conf_sym(menu); | ||
282 | sym_calc_value(sym); | ||
283 | switch (sym_get_tristate_value(sym)) { | ||
284 | case no: | ||
285 | return 1; | ||
286 | case mod: | ||
287 | return 0; | ||
288 | case yes: | ||
289 | break; | ||
290 | } | ||
291 | } else { | ||
292 | switch (sym_get_tristate_value(sym)) { | ||
293 | case no: | ||
294 | return 1; | ||
295 | case mod: | ||
296 | printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu)); | ||
297 | return 0; | ||
298 | case yes: | ||
299 | break; | ||
300 | } | ||
301 | } | ||
302 | |||
303 | while (1) { | ||
304 | int cnt, def; | ||
305 | |||
306 | printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu)); | ||
307 | def_sym = sym_get_choice_value(sym); | ||
308 | cnt = def = 0; | ||
309 | line[0] = '0'; | ||
310 | line[1] = 0; | ||
311 | for (child = menu->list; child; child = child->next) { | ||
312 | if (!menu_is_visible(child)) | ||
313 | continue; | ||
314 | if (!child->sym) { | ||
315 | printf("%*c %s\n", indent, '*', menu_get_prompt(child)); | ||
316 | continue; | ||
317 | } | ||
318 | cnt++; | ||
319 | if (child->sym == def_sym) { | ||
320 | def = cnt; | ||
321 | printf("%*c", indent, '>'); | ||
322 | } else | ||
323 | printf("%*c", indent, ' '); | ||
324 | printf(" %d. %s", cnt, menu_get_prompt(child)); | ||
325 | if (child->sym->name) | ||
326 | printf(" (%s)", child->sym->name); | ||
327 | if (!sym_has_value(child->sym)) | ||
328 | printf(" (NEW)"); | ||
329 | printf("\n"); | ||
330 | } | ||
331 | printf("%*schoice", indent - 1, ""); | ||
332 | if (cnt == 1) { | ||
333 | printf("[1]: 1\n"); | ||
334 | goto conf_childs; | ||
335 | } | ||
336 | printf("[1-%d", cnt); | ||
337 | if (sym->help) | ||
338 | printf("?"); | ||
339 | printf("]: "); | ||
340 | switch (input_mode) { | ||
341 | case ask_new: | ||
342 | case ask_silent: | ||
343 | if (!is_new) { | ||
344 | cnt = def; | ||
345 | printf("%d\n", cnt); | ||
346 | break; | ||
347 | } | ||
348 | check_stdin(); | ||
349 | case ask_all: | ||
350 | fflush(stdout); | ||
351 | fgets(line, 128, stdin); | ||
352 | strip(line); | ||
353 | if (line[0] == '?') { | ||
354 | printf("\n%s\n", menu->sym->help ? | ||
355 | menu->sym->help : nohelp_text); | ||
356 | continue; | ||
357 | } | ||
358 | if (!line[0]) | ||
359 | cnt = def; | ||
360 | else if (isdigit(line[0])) | ||
361 | cnt = atoi(line); | ||
362 | else | ||
363 | continue; | ||
364 | break; | ||
365 | case set_random: | ||
366 | def = (random() % cnt) + 1; | ||
367 | case set_default: | ||
368 | case set_yes: | ||
369 | case set_mod: | ||
370 | case set_no: | ||
371 | cnt = def; | ||
372 | printf("%d\n", cnt); | ||
373 | break; | ||
374 | } | ||
375 | |||
376 | conf_childs: | ||
377 | for (child = menu->list; child; child = child->next) { | ||
378 | if (!child->sym || !menu_is_visible(child)) | ||
379 | continue; | ||
380 | if (!--cnt) | ||
381 | break; | ||
382 | } | ||
383 | if (!child) | ||
384 | continue; | ||
385 | if (line[strlen(line) - 1] == '?') { | ||
386 | printf("\n%s\n", child->sym->help ? | ||
387 | child->sym->help : nohelp_text); | ||
388 | continue; | ||
389 | } | ||
390 | sym_set_choice_value(sym, child->sym); | ||
391 | if (child->list) { | ||
392 | indent += 2; | ||
393 | conf(child->list); | ||
394 | indent -= 2; | ||
395 | } | ||
396 | return 1; | ||
397 | } | ||
398 | } | ||
399 | |||
400 | static void conf(struct menu *menu) | ||
401 | { | ||
402 | struct symbol *sym; | ||
403 | struct property *prop; | ||
404 | struct menu *child; | ||
405 | |||
406 | if (!menu_is_visible(menu)) | ||
407 | return; | ||
408 | |||
409 | sym = menu->sym; | ||
410 | prop = menu->prompt; | ||
411 | if (prop) { | ||
412 | const char *prompt; | ||
413 | |||
414 | switch (prop->type) { | ||
415 | case P_MENU: | ||
416 | if (input_mode == ask_silent && rootEntry != menu) { | ||
417 | check_conf(menu); | ||
418 | return; | ||
419 | } | ||
420 | case P_COMMENT: | ||
421 | prompt = menu_get_prompt(menu); | ||
422 | if (prompt) | ||
423 | printf("%*c\n%*c %s\n%*c\n", | ||
424 | indent, '*', | ||
425 | indent, '*', prompt, | ||
426 | indent, '*'); | ||
427 | default: | ||
428 | ; | ||
429 | } | ||
430 | } | ||
431 | |||
432 | if (!sym) | ||
433 | goto conf_childs; | ||
434 | |||
435 | if (sym_is_choice(sym)) { | ||
436 | conf_choice(menu); | ||
437 | if (sym->curr.tri != mod) | ||
438 | return; | ||
439 | goto conf_childs; | ||
440 | } | ||
441 | |||
442 | switch (sym->type) { | ||
443 | case S_INT: | ||
444 | case S_HEX: | ||
445 | case S_STRING: | ||
446 | conf_string(menu); | ||
447 | break; | ||
448 | default: | ||
449 | conf_sym(menu); | ||
450 | break; | ||
451 | } | ||
452 | |||
453 | conf_childs: | ||
454 | if (sym) | ||
455 | indent += 2; | ||
456 | for (child = menu->list; child; child = child->next) | ||
457 | conf(child); | ||
458 | if (sym) | ||
459 | indent -= 2; | ||
460 | } | ||
461 | |||
462 | static void check_conf(struct menu *menu) | ||
463 | { | ||
464 | struct symbol *sym; | ||
465 | struct menu *child; | ||
466 | |||
467 | if (!menu_is_visible(menu)) | ||
468 | return; | ||
469 | |||
470 | sym = menu->sym; | ||
471 | if (sym) { | ||
472 | if (sym_is_changable(sym) && !sym_has_value(sym)) { | ||
473 | if (!conf_cnt++) | ||
474 | printf("*\n* Restart config...\n*\n"); | ||
475 | rootEntry = menu_get_parent_menu(menu); | ||
476 | conf(rootEntry); | ||
477 | } | ||
478 | if (sym_is_choice(sym) && sym_get_tristate_value(sym) != mod) | ||
479 | return; | ||
480 | } | ||
481 | |||
482 | for (child = menu->list; child; child = child->next) | ||
483 | check_conf(child); | ||
484 | } | ||
485 | |||
486 | int main(int ac, char **av) | ||
487 | { | ||
488 | int i = 1; | ||
489 | const char *name; | ||
490 | struct stat tmpstat; | ||
491 | |||
492 | if (ac > i && av[i][0] == '-') { | ||
493 | switch (av[i++][1]) { | ||
494 | case 'o': | ||
495 | input_mode = ask_new; | ||
496 | break; | ||
497 | case 's': | ||
498 | input_mode = ask_silent; | ||
499 | valid_stdin = isatty(0) && isatty(1) && isatty(2); | ||
500 | break; | ||
501 | case 'd': | ||
502 | input_mode = set_default; | ||
503 | break; | ||
504 | case 'D': | ||
505 | input_mode = set_default; | ||
506 | defconfig_file = av[i++]; | ||
507 | if (!defconfig_file) { | ||
508 | printf("%s: No default config file specified\n", | ||
509 | av[0]); | ||
510 | exit(1); | ||
511 | } | ||
512 | break; | ||
513 | case 'n': | ||
514 | input_mode = set_no; | ||
515 | break; | ||
516 | case 'm': | ||
517 | input_mode = set_mod; | ||
518 | break; | ||
519 | case 'y': | ||
520 | input_mode = set_yes; | ||
521 | break; | ||
522 | case 'r': | ||
523 | input_mode = set_random; | ||
524 | srandom(time(NULL)); | ||
525 | break; | ||
526 | case 'h': | ||
527 | case '?': | ||
528 | printf("%s [-o|-s] config\n", av[0]); | ||
529 | exit(0); | ||
530 | } | ||
531 | } | ||
532 | name = av[i]; | ||
533 | if (!name) { | ||
534 | printf("%s: configuration file missing\n", av[0]); | ||
535 | } | ||
536 | conf_parse(name); | ||
537 | //zconfdump(stdout); | ||
538 | switch (input_mode) { | ||
539 | case set_default: | ||
540 | if (!defconfig_file) | ||
541 | defconfig_file = conf_get_default_confname(); | ||
542 | if (conf_read(defconfig_file)) { | ||
543 | printf("***\n" | ||
544 | "*** Can't find default configuration \"%s\"!\n" | ||
545 | "***\n", defconfig_file); | ||
546 | exit(1); | ||
547 | } | ||
548 | break; | ||
549 | case ask_silent: | ||
550 | if (stat(".config", &tmpstat)) { | ||
551 | printf("***\n" | ||
552 | "*** You have not yet configured BusyBox!\n" | ||
553 | "***\n" | ||
554 | "*** Please run some configurator (e.g. \"make oldconfig\" or\n" | ||
555 | "*** \"make menuconfig\" or \"make config\").\n" | ||
556 | "***\n"); | ||
557 | exit(1); | ||
558 | } | ||
559 | case ask_all: | ||
560 | case ask_new: | ||
561 | conf_read(NULL); | ||
562 | break; | ||
563 | default: | ||
564 | break; | ||
565 | } | ||
566 | |||
567 | if (input_mode != ask_silent) { | ||
568 | rootEntry = &rootmenu; | ||
569 | conf(&rootmenu); | ||
570 | if (input_mode == ask_all) { | ||
571 | input_mode = ask_silent; | ||
572 | valid_stdin = 1; | ||
573 | } | ||
574 | } | ||
575 | do { | ||
576 | conf_cnt = 0; | ||
577 | check_conf(&rootmenu); | ||
578 | } while (conf_cnt); | ||
579 | if (conf_write(NULL)) { | ||
580 | fprintf(stderr, "\n*** Error during writing of the BusyBox configuration.\n\n"); | ||
581 | return 1; | ||
582 | } | ||
583 | return 0; | ||
584 | } | ||