blob: c4217731145d99dc31dff0a022b32e5a306bbd4b [file] [log] [blame]
Patrick Georgi0588d192009-08-12 15:00:51 +00001/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */
5
6#include <locale.h>
7#include <ctype.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <time.h>
12#include <unistd.h>
Patrick Georgid5208402014-04-11 20:24:06 +020013#include <getopt.h>
Patrick Georgi0588d192009-08-12 15:00:51 +000014#include <sys/stat.h>
Patrick Georgid5208402014-04-11 20:24:06 +020015#include <sys/time.h>
16#include <errno.h>
Patrick Georgi0588d192009-08-12 15:00:51 +000017
Patrick Georgi0588d192009-08-12 15:00:51 +000018#include "lkc.h"
19
Stefan Reinauer57a31312015-08-20 11:19:34 -070020int kconfig_warnings = 0;
21
Patrick Georgi0588d192009-08-12 15:00:51 +000022static void conf(struct menu *menu);
23static void check_conf(struct menu *menu);
Patrick Georgid5208402014-04-11 20:24:06 +020024static void xfgets(char *str, int size, FILE *in);
Patrick Georgi0588d192009-08-12 15:00:51 +000025
Patrick Georgid5208402014-04-11 20:24:06 +020026enum input_mode {
27 oldaskconfig,
28 silentoldconfig,
29 oldconfig,
30 allnoconfig,
31 allyesconfig,
32 allmodconfig,
33 alldefconfig,
34 randconfig,
35 defconfig,
36 savedefconfig,
37 listnewconfig,
38 olddefconfig,
39} input_mode = oldaskconfig;
Patrick Georgi0588d192009-08-12 15:00:51 +000040
41static int indent = 1;
Patrick Georgid5208402014-04-11 20:24:06 +020042static int tty_stdio;
Patrick Georgi0588d192009-08-12 15:00:51 +000043static int valid_stdin = 1;
Patrick Georgid5208402014-04-11 20:24:06 +020044static int sync_kconfig;
Patrick Georgi0588d192009-08-12 15:00:51 +000045static int conf_cnt;
46static char line[128];
47static struct menu *rootEntry;
48
Patrick Georgid5208402014-04-11 20:24:06 +020049static void print_help(struct menu *menu)
Patrick Georgi0588d192009-08-12 15:00:51 +000050{
Patrick Georgid5208402014-04-11 20:24:06 +020051 struct gstr help = str_new();
52
53 menu_get_ext_help(menu, &help);
54
55 printf("\n%s\n", str_get(&help));
56 str_free(&help);
Patrick Georgi0588d192009-08-12 15:00:51 +000057}
58
59static void strip(char *str)
60{
61 char *p = str;
62 int l;
63
64 while ((isspace(*p)))
65 p++;
66 l = strlen(p);
67 if (p != str)
68 memmove(str, p, l + 1);
69 if (!l)
70 return;
71 p = str + l - 1;
72 while ((isspace(*p)))
73 *p-- = 0;
74}
75
76static void check_stdin(void)
77{
Patrick Georgid5208402014-04-11 20:24:06 +020078 if (!valid_stdin) {
Patrick Georgi0588d192009-08-12 15:00:51 +000079 printf(_("aborted!\n\n"));
80 printf(_("Console input/output is redirected. "));
81 printf(_("Run 'make oldconfig' to update configuration.\n\n"));
82 exit(1);
83 }
84}
85
86static int conf_askvalue(struct symbol *sym, const char *def)
87{
88 enum symbol_type type = sym_get_type(sym);
Patrick Georgi0588d192009-08-12 15:00:51 +000089
90 if (!sym_has_value(sym))
91 printf(_("(NEW) "));
92
93 line[0] = '\n';
94 line[1] = 0;
95
96 if (!sym_is_changable(sym)) {
97 printf("%s\n", def);
98 line[0] = '\n';
99 line[1] = 0;
100 return 0;
101 }
102
103 switch (input_mode) {
Patrick Georgid5208402014-04-11 20:24:06 +0200104 case oldconfig:
105 case silentoldconfig:
Patrick Georgi0588d192009-08-12 15:00:51 +0000106 if (sym_has_value(sym)) {
107 printf("%s\n", def);
108 return 0;
109 }
110 check_stdin();
Patrick Georgid5208402014-04-11 20:24:06 +0200111 /* fall through */
112 case oldaskconfig:
Patrick Georgi0588d192009-08-12 15:00:51 +0000113 fflush(stdout);
Patrick Georgid5208402014-04-11 20:24:06 +0200114 xfgets(line, 128, stdin);
115 if (!tty_stdio)
116 printf("\n");
Patrick Georgi0588d192009-08-12 15:00:51 +0000117 return 1;
118 default:
119 break;
120 }
121
122 switch (type) {
123 case S_INT:
124 case S_HEX:
125 case S_STRING:
126 printf("%s\n", def);
127 return 1;
128 default:
129 ;
130 }
Patrick Georgi0588d192009-08-12 15:00:51 +0000131 printf("%s", line);
132 return 1;
133}
134
Patrick Georgid5208402014-04-11 20:24:06 +0200135static int conf_string(struct menu *menu)
Patrick Georgi0588d192009-08-12 15:00:51 +0000136{
137 struct symbol *sym = menu->sym;
138 const char *def;
139
140 while (1) {
141 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
142 printf("(%s) ", sym->name);
143 def = sym_get_string_value(sym);
144 if (sym_get_string_value(sym))
145 printf("[%s] ", def);
146 if (!conf_askvalue(sym, def))
147 return 0;
148 switch (line[0]) {
149 case '\n':
150 break;
151 case '?':
152 /* print help */
153 if (line[1] == '\n') {
Patrick Georgid5208402014-04-11 20:24:06 +0200154 print_help(menu);
Patrick Georgi0588d192009-08-12 15:00:51 +0000155 def = NULL;
156 break;
157 }
Patrick Georgid5208402014-04-11 20:24:06 +0200158 /* fall through */
Patrick Georgi0588d192009-08-12 15:00:51 +0000159 default:
160 line[strlen(line)-1] = 0;
161 def = line;
162 }
163 if (def && sym_set_string_value(sym, def))
164 return 0;
165 }
166}
167
168static int conf_sym(struct menu *menu)
169{
170 struct symbol *sym = menu->sym;
Patrick Georgi0588d192009-08-12 15:00:51 +0000171 tristate oldval, newval;
172
173 while (1) {
174 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
175 if (sym->name)
176 printf("(%s) ", sym->name);
Patrick Georgi0588d192009-08-12 15:00:51 +0000177 putchar('[');
178 oldval = sym_get_tristate_value(sym);
179 switch (oldval) {
180 case no:
181 putchar('N');
182 break;
183 case mod:
184 putchar('M');
185 break;
186 case yes:
187 putchar('Y');
188 break;
189 }
190 if (oldval != no && sym_tristate_within_range(sym, no))
191 printf("/n");
192 if (oldval != mod && sym_tristate_within_range(sym, mod))
193 printf("/m");
194 if (oldval != yes && sym_tristate_within_range(sym, yes))
195 printf("/y");
196 if (menu_has_help(menu))
197 printf("/?");
198 printf("] ");
199 if (!conf_askvalue(sym, sym_get_string_value(sym)))
200 return 0;
201 strip(line);
202
203 switch (line[0]) {
204 case 'n':
205 case 'N':
206 newval = no;
207 if (!line[1] || !strcmp(&line[1], "o"))
208 break;
209 continue;
210 case 'm':
211 case 'M':
212 newval = mod;
213 if (!line[1])
214 break;
215 continue;
216 case 'y':
217 case 'Y':
218 newval = yes;
219 if (!line[1] || !strcmp(&line[1], "es"))
220 break;
221 continue;
222 case 0:
223 newval = oldval;
224 break;
225 case '?':
226 goto help;
227 default:
228 continue;
229 }
230 if (sym_set_tristate_value(sym, newval))
231 return 0;
232help:
Patrick Georgid5208402014-04-11 20:24:06 +0200233 print_help(menu);
Patrick Georgi0588d192009-08-12 15:00:51 +0000234 }
235}
236
237static int conf_choice(struct menu *menu)
238{
239 struct symbol *sym, *def_sym;
240 struct menu *child;
Patrick Georgi0588d192009-08-12 15:00:51 +0000241 bool is_new;
242
243 sym = menu->sym;
Patrick Georgi0588d192009-08-12 15:00:51 +0000244 is_new = !sym_has_value(sym);
245 if (sym_is_changable(sym)) {
246 conf_sym(menu);
247 sym_calc_value(sym);
248 switch (sym_get_tristate_value(sym)) {
249 case no:
250 return 1;
251 case mod:
252 return 0;
253 case yes:
254 break;
255 }
256 } else {
257 switch (sym_get_tristate_value(sym)) {
258 case no:
259 return 1;
260 case mod:
261 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
262 return 0;
263 case yes:
264 break;
265 }
266 }
267
268 while (1) {
269 int cnt, def;
270
271 printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
272 def_sym = sym_get_choice_value(sym);
273 cnt = def = 0;
274 line[0] = 0;
275 for (child = menu->list; child; child = child->next) {
276 if (!menu_is_visible(child))
277 continue;
278 if (!child->sym) {
279 printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
280 continue;
281 }
282 cnt++;
283 if (child->sym == def_sym) {
284 def = cnt;
285 printf("%*c", indent, '>');
286 } else
287 printf("%*c", indent, ' ');
288 printf(" %d. %s", cnt, _(menu_get_prompt(child)));
289 if (child->sym->name)
290 printf(" (%s)", child->sym->name);
291 if (!sym_has_value(child->sym))
292 printf(_(" (NEW)"));
293 printf("\n");
294 }
295 printf(_("%*schoice"), indent - 1, "");
296 if (cnt == 1) {
297 printf("[1]: 1\n");
298 goto conf_childs;
299 }
300 printf("[1-%d", cnt);
301 if (menu_has_help(menu))
302 printf("?");
303 printf("]: ");
304 switch (input_mode) {
Patrick Georgid5208402014-04-11 20:24:06 +0200305 case oldconfig:
306 case silentoldconfig:
Patrick Georgi0588d192009-08-12 15:00:51 +0000307 if (!is_new) {
308 cnt = def;
309 printf("%d\n", cnt);
310 break;
311 }
312 check_stdin();
Patrick Georgid5208402014-04-11 20:24:06 +0200313 /* fall through */
314 case oldaskconfig:
Patrick Georgi0588d192009-08-12 15:00:51 +0000315 fflush(stdout);
Patrick Georgid5208402014-04-11 20:24:06 +0200316 xfgets(line, 128, stdin);
Patrick Georgi0588d192009-08-12 15:00:51 +0000317 strip(line);
318 if (line[0] == '?') {
Patrick Georgid5208402014-04-11 20:24:06 +0200319 print_help(menu);
Patrick Georgi0588d192009-08-12 15:00:51 +0000320 continue;
321 }
322 if (!line[0])
323 cnt = def;
324 else if (isdigit(line[0]))
325 cnt = atoi(line);
326 else
327 continue;
328 break;
Patrick Georgid5208402014-04-11 20:24:06 +0200329 default:
Patrick Georgi0588d192009-08-12 15:00:51 +0000330 break;
331 }
332
333 conf_childs:
334 for (child = menu->list; child; child = child->next) {
335 if (!child->sym || !menu_is_visible(child))
336 continue;
337 if (!--cnt)
338 break;
339 }
340 if (!child)
341 continue;
Patrick Georgid5208402014-04-11 20:24:06 +0200342 if (line[0] && line[strlen(line) - 1] == '?') {
343 print_help(child);
Patrick Georgi0588d192009-08-12 15:00:51 +0000344 continue;
345 }
346 sym_set_choice_value(sym, child->sym);
347 for (child = child->list; child; child = child->next) {
348 indent += 2;
349 conf(child);
350 indent -= 2;
351 }
352 return 1;
353 }
354}
355
356static void conf(struct menu *menu)
357{
358 struct symbol *sym;
359 struct property *prop;
360 struct menu *child;
361
362 if (!menu_is_visible(menu))
363 return;
364
365 sym = menu->sym;
366 prop = menu->prompt;
367 if (prop) {
368 const char *prompt;
369
370 switch (prop->type) {
371 case P_MENU:
Patrick Georgid5208402014-04-11 20:24:06 +0200372 if ((input_mode == silentoldconfig ||
373 input_mode == listnewconfig ||
374 input_mode == olddefconfig) &&
375 rootEntry != menu) {
Patrick Georgi0588d192009-08-12 15:00:51 +0000376 check_conf(menu);
377 return;
378 }
Patrick Georgid5208402014-04-11 20:24:06 +0200379 /* fall through */
Patrick Georgi0588d192009-08-12 15:00:51 +0000380 case P_COMMENT:
381 prompt = menu_get_prompt(menu);
382 if (prompt)
383 printf("%*c\n%*c %s\n%*c\n",
384 indent, '*',
385 indent, '*', _(prompt),
386 indent, '*');
387 default:
388 ;
389 }
390 }
391
392 if (!sym)
393 goto conf_childs;
394
395 if (sym_is_choice(sym)) {
396 conf_choice(menu);
397 if (sym->curr.tri != mod)
398 return;
399 goto conf_childs;
400 }
401
402 switch (sym->type) {
403 case S_INT:
404 case S_HEX:
405 case S_STRING:
406 conf_string(menu);
407 break;
408 default:
409 conf_sym(menu);
410 break;
411 }
412
413conf_childs:
414 if (sym)
415 indent += 2;
416 for (child = menu->list; child; child = child->next)
417 conf(child);
418 if (sym)
419 indent -= 2;
420}
421
422static void check_conf(struct menu *menu)
423{
424 struct symbol *sym;
425 struct menu *child;
426
427 if (!menu_is_visible(menu))
428 return;
429
430 sym = menu->sym;
431 if (sym && !sym_has_value(sym)) {
432 if (sym_is_changable(sym) ||
433 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
Patrick Georgid5208402014-04-11 20:24:06 +0200434 if (input_mode == listnewconfig) {
435 if (sym->name && !sym_is_choice_value(sym)) {
436 printf("%s%s\n", CONFIG_, sym->name);
437 }
438 } else if (input_mode != olddefconfig) {
439 if (!conf_cnt++)
440 printf(_("*\n* Restart config...\n*\n"));
441 rootEntry = menu_get_parent_menu(menu);
442 conf(rootEntry);
443 }
Patrick Georgi0588d192009-08-12 15:00:51 +0000444 }
445 }
446
447 for (child = menu->list; child; child = child->next)
448 check_conf(child);
449}
450
Patrick Georgid5208402014-04-11 20:24:06 +0200451static struct option long_opts[] = {
452 {"oldaskconfig", no_argument, NULL, oldaskconfig},
453 {"oldconfig", no_argument, NULL, oldconfig},
454 {"silentoldconfig", no_argument, NULL, silentoldconfig},
455 {"defconfig", optional_argument, NULL, defconfig},
456 {"savedefconfig", required_argument, NULL, savedefconfig},
457 {"allnoconfig", no_argument, NULL, allnoconfig},
458 {"allyesconfig", no_argument, NULL, allyesconfig},
459 {"allmodconfig", no_argument, NULL, allmodconfig},
460 {"alldefconfig", no_argument, NULL, alldefconfig},
461 {"randconfig", no_argument, NULL, randconfig},
462 {"listnewconfig", no_argument, NULL, listnewconfig},
463 {"olddefconfig", no_argument, NULL, olddefconfig},
464 /*
465 * oldnoconfig is an alias of olddefconfig, because people already
466 * are dependent on its behavior(sets new symbols to their default
467 * value but not 'n') with the counter-intuitive name.
468 */
469 {"oldnoconfig", no_argument, NULL, olddefconfig},
470 {NULL, 0, NULL, 0}
471};
472
473static void conf_usage(const char *progname)
474{
475
476 printf("Usage: %s [option] <kconfig-file>\n", progname);
477 printf("[option] is _one_ of the following:\n");
478 printf(" --listnewconfig List new options\n");
479 printf(" --oldaskconfig Start a new configuration using a line-oriented program\n");
480 printf(" --oldconfig Update a configuration using a provided .config as base\n");
481 printf(" --silentoldconfig Same as oldconfig, but quietly, additionally update deps\n");
482 printf(" --olddefconfig Same as silentoldconfig but sets new symbols to their default value\n");
483 printf(" --oldnoconfig An alias of olddefconfig\n");
484 printf(" --defconfig <file> New config with default defined in <file>\n");
485 printf(" --savedefconfig <file> Save the minimal current configuration to <file>\n");
486 printf(" --allnoconfig New config where all options are answered with no\n");
487 printf(" --allyesconfig New config where all options are answered with yes\n");
488 printf(" --allmodconfig New config where all options are answered with mod\n");
489 printf(" --alldefconfig New config with all symbols set to default\n");
490 printf(" --randconfig New config with random answer to all options\n");
491}
492
Patrick Georgi0588d192009-08-12 15:00:51 +0000493int main(int ac, char **av)
494{
Patrick Georgid5208402014-04-11 20:24:06 +0200495 const char *progname = av[0];
Patrick Georgi0588d192009-08-12 15:00:51 +0000496 int opt;
Patrick Georgid5208402014-04-11 20:24:06 +0200497 const char *name, *defconfig_file = NULL /* gcc uninit */;
Stefan Reinauer57a31312015-08-20 11:19:34 -0700498 char *env;
Patrick Georgi0588d192009-08-12 15:00:51 +0000499 struct stat tmpstat;
500
501 setlocale(LC_ALL, "");
502 bindtextdomain(PACKAGE, LOCALEDIR);
503 textdomain(PACKAGE);
504
Patrick Georgid5208402014-04-11 20:24:06 +0200505 tty_stdio = isatty(0) && isatty(1) && isatty(2);
506
507 while ((opt = getopt_long(ac, av, "", long_opts, NULL)) != -1) {
508 input_mode = (enum input_mode)opt;
Patrick Georgi0588d192009-08-12 15:00:51 +0000509 switch (opt) {
Patrick Georgid5208402014-04-11 20:24:06 +0200510 case silentoldconfig:
511 sync_kconfig = 1;
Patrick Georgi0588d192009-08-12 15:00:51 +0000512 break;
Patrick Georgid5208402014-04-11 20:24:06 +0200513 case defconfig:
514 case savedefconfig:
Patrick Georgi0588d192009-08-12 15:00:51 +0000515 defconfig_file = optarg;
516 break;
Patrick Georgid5208402014-04-11 20:24:06 +0200517 case randconfig:
518 {
519 struct timeval now;
520 unsigned int seed;
521 char *seed_env;
522
523 /*
524 * Use microseconds derived seed,
525 * compensate for systems where it may be zero
526 */
527 gettimeofday(&now, NULL);
528 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
529
530 seed_env = getenv("KCONFIG_SEED");
531 if( seed_env && *seed_env ) {
532 char *endp;
533 int tmp = (int)strtol(seed_env, &endp, 0);
534 if (*endp == '\0') {
535 seed = tmp;
536 }
537 }
538 fprintf( stderr, "KCONFIG_SEED=0x%X\n", seed );
539 srand(seed);
Patrick Georgi0588d192009-08-12 15:00:51 +0000540 break;
Patrick Georgid5208402014-04-11 20:24:06 +0200541 }
542 case oldaskconfig:
543 case oldconfig:
544 case allnoconfig:
545 case allyesconfig:
546 case allmodconfig:
547 case alldefconfig:
548 case listnewconfig:
549 case olddefconfig:
Patrick Georgi0588d192009-08-12 15:00:51 +0000550 break;
Patrick Georgid5208402014-04-11 20:24:06 +0200551 case '?':
552 conf_usage(progname);
Patrick Georgi0588d192009-08-12 15:00:51 +0000553 exit(1);
Patrick Georgid5208402014-04-11 20:24:06 +0200554 break;
Patrick Georgi0588d192009-08-12 15:00:51 +0000555 }
556 }
557 if (ac == optind) {
558 printf(_("%s: Kconfig file missing\n"), av[0]);
Patrick Georgid5208402014-04-11 20:24:06 +0200559 conf_usage(progname);
Patrick Georgi0588d192009-08-12 15:00:51 +0000560 exit(1);
561 }
562 name = av[optind];
563 conf_parse(name);
564 //zconfdump(stdout);
Patrick Georgid5208402014-04-11 20:24:06 +0200565 if (sync_kconfig) {
566 name = conf_get_configname();
567 if (stat(name, &tmpstat)) {
568 fprintf(stderr, _("***\n"
569 "*** Configuration file \"%s\" not found!\n"
570 "***\n"
571 "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
572 "*** \"make menuconfig\" or \"make xconfig\").\n"
573 "***\n"), name);
574 exit(1);
575 }
576 }
577
Patrick Georgi0588d192009-08-12 15:00:51 +0000578 switch (input_mode) {
Patrick Georgid5208402014-04-11 20:24:06 +0200579 case defconfig:
Patrick Georgi0588d192009-08-12 15:00:51 +0000580 if (!defconfig_file)
581 defconfig_file = conf_get_default_confname();
582 if (conf_read(defconfig_file)) {
583 printf(_("***\n"
584 "*** Can't find default configuration \"%s\"!\n"
585 "***\n"), defconfig_file);
586 exit(1);
587 }
588 break;
Patrick Georgid5208402014-04-11 20:24:06 +0200589 case savedefconfig:
590 case silentoldconfig:
591 case oldaskconfig:
592 case oldconfig:
593 case listnewconfig:
594 case olddefconfig:
Patrick Georgi0588d192009-08-12 15:00:51 +0000595 conf_read(NULL);
596 break;
Patrick Georgid5208402014-04-11 20:24:06 +0200597 case allnoconfig:
598 case allyesconfig:
599 case allmodconfig:
600 case alldefconfig:
601 case randconfig:
Patrick Georgi0588d192009-08-12 15:00:51 +0000602 name = getenv("KCONFIG_ALLCONFIG");
Patrick Georgid5208402014-04-11 20:24:06 +0200603 if (!name)
604 break;
605 if ((strcmp(name, "") != 0) && (strcmp(name, "1") != 0)) {
606 if (conf_read_simple(name, S_DEF_USER)) {
607 fprintf(stderr,
608 _("*** Can't read seed configuration \"%s\"!\n"),
609 name);
610 exit(1);
611 }
Patrick Georgi0588d192009-08-12 15:00:51 +0000612 break;
613 }
614 switch (input_mode) {
Patrick Georgid5208402014-04-11 20:24:06 +0200615 case allnoconfig: name = "allno.config"; break;
616 case allyesconfig: name = "allyes.config"; break;
617 case allmodconfig: name = "allmod.config"; break;
618 case alldefconfig: name = "alldef.config"; break;
619 case randconfig: name = "allrandom.config"; break;
Patrick Georgi0588d192009-08-12 15:00:51 +0000620 default: break;
621 }
Patrick Georgid5208402014-04-11 20:24:06 +0200622 if (conf_read_simple(name, S_DEF_USER) &&
623 conf_read_simple("all.config", S_DEF_USER)) {
624 fprintf(stderr,
625 _("*** KCONFIG_ALLCONFIG set, but no \"%s\" or \"all.config\" file found\n"),
626 name);
627 exit(1);
628 }
Patrick Georgi0588d192009-08-12 15:00:51 +0000629 break;
630 default:
631 break;
632 }
633
Patrick Georgid5208402014-04-11 20:24:06 +0200634 if (sync_kconfig) {
635 if (conf_get_changed()) {
636 name = getenv("KCONFIG_NOSILENTUPDATE");
637 if (name && *name) {
638 fprintf(stderr,
639 _("\n*** The configuration requires explicit update.\n\n"));
640 return 1;
641 }
642 }
643 valid_stdin = tty_stdio;
644 }
645
646 switch (input_mode) {
647 case allnoconfig:
648 conf_set_all_new_symbols(def_no);
649 break;
650 case allyesconfig:
651 conf_set_all_new_symbols(def_yes);
652 break;
653 case allmodconfig:
654 conf_set_all_new_symbols(def_mod);
655 break;
656 case alldefconfig:
657 conf_set_all_new_symbols(def_default);
658 break;
659 case randconfig:
660 /* Really nothing to do in this loop */
661 while (conf_set_all_new_symbols(def_random)) ;
662 break;
663 case defconfig:
664 conf_set_all_new_symbols(def_default);
665 break;
666 case savedefconfig:
667 break;
668 case oldaskconfig:
Patrick Georgi0588d192009-08-12 15:00:51 +0000669 rootEntry = &rootmenu;
670 conf(&rootmenu);
Patrick Georgid5208402014-04-11 20:24:06 +0200671 input_mode = silentoldconfig;
672 /* fall through */
673 case oldconfig:
674 case listnewconfig:
675 case olddefconfig:
676 case silentoldconfig:
677 /* Update until a loop caused no more changes */
678 do {
679 conf_cnt = 0;
680 check_conf(&rootmenu);
681 } while (conf_cnt &&
682 (input_mode != listnewconfig &&
683 input_mode != olddefconfig));
684 break;
685 }
686
Stefan Reinauer57a31312015-08-20 11:19:34 -0700687 env = getenv("KCONFIG_STRICT");
688 if (env && *env && kconfig_warnings) {
689 fprintf(stderr, _("\n*** ERROR: %d warnings encountered, and "
690 "warnings are errors.\n\n"), kconfig_warnings);
691 exit(1);
692 }
693
Patrick Georgid5208402014-04-11 20:24:06 +0200694 if (sync_kconfig) {
695 /* silentoldconfig is used during the build so we shall update autoconf.
696 * All other commands are only used to generate a config.
697 */
698 if (conf_get_changed() && conf_write(NULL)) {
699 fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
700 exit(1);
Patrick Georgi0588d192009-08-12 15:00:51 +0000701 }
Patrick Georgid5208402014-04-11 20:24:06 +0200702 if (conf_write_autoconf()) {
703 fprintf(stderr, _("\n*** Error during update of the configuration.\n\n"));
Patrick Georgi0588d192009-08-12 15:00:51 +0000704 return 1;
705 }
Patrick Georgid5208402014-04-11 20:24:06 +0200706 } else if (input_mode == savedefconfig) {
707 if (conf_write_defconfig(defconfig_file)) {
708 fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
Stefan Reinauer3ec23b32015-04-06 00:59:23 +0200709 defconfig_file);
Patrick Georgid5208402014-04-11 20:24:06 +0200710 return 1;
711 }
712 } else if (input_mode != listnewconfig) {
713 if (conf_write(NULL)) {
714 fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
715 exit(1);
716 }
Patrick Georgi0588d192009-08-12 15:00:51 +0000717 }
Patrick Georgi0588d192009-08-12 15:00:51 +0000718 return 0;
719}
Patrick Georgid5208402014-04-11 20:24:06 +0200720
721/*
722 * Helper function to facilitate fgets() by Jean Sacren.
723 */
724void xfgets(char *str, int size, FILE *in)
725{
726 if (fgets(str, size, in) == NULL)
727 fprintf(stderr, "\nError in reading or end of file.\n");
728}