conf.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. /*
  2. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  3. * Released under the terms of the GNU GPL v2.0.
  4. */
  5. #include <locale.h>
  6. #include <ctype.h>
  7. #include <limits.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <time.h>
  12. #include <unistd.h>
  13. #include <sys/stat.h>
  14. #include <sys/time.h>
  15. #include <errno.h>
  16. #include "lkc.h"
  17. static void conf(struct menu *menu);
  18. static void check_conf(struct menu *menu);
  19. static void xfgets(char *str, int size, FILE *in);
  20. enum input_mode {
  21. oldaskconfig,
  22. silentoldconfig,
  23. oldconfig,
  24. allnoconfig,
  25. allyesconfig,
  26. allmodconfig,
  27. alldefconfig,
  28. randconfig,
  29. defconfig,
  30. savedefconfig,
  31. listnewconfig,
  32. olddefconfig,
  33. } input_mode = oldaskconfig;
  34. static int indent = 1;
  35. static int tty_stdio;
  36. static int valid_stdin = 1;
  37. static int sync_kconfig;
  38. static int conf_cnt;
  39. static char line[PATH_MAX];
  40. static struct menu *rootEntry;
  41. static void print_help(struct menu *menu)
  42. {
  43. struct gstr help = str_new();
  44. menu_get_ext_help(menu, &help);
  45. printf("\n%s\n", str_get(&help));
  46. str_free(&help);
  47. }
  48. static void strip(char *str)
  49. {
  50. char *p = str;
  51. int l;
  52. while ((isspace(*p)))
  53. p++;
  54. l = strlen(p);
  55. if (p != str)
  56. memmove(str, p, l + 1);
  57. if (!l)
  58. return;
  59. p = str + l - 1;
  60. while ((isspace(*p)))
  61. *p-- = 0;
  62. }
  63. static void check_stdin(void)
  64. {
  65. if (!valid_stdin) {
  66. printf(_("aborted!\n\n"));
  67. printf(_("Console input/output is redirected. "));
  68. printf(_("Run 'make oldconfig' to update configuration.\n\n"));
  69. exit(1);
  70. }
  71. }
  72. static int conf_askvalue(struct symbol *sym, const char *def)
  73. {
  74. enum symbol_type type = sym_get_type(sym);
  75. if (!sym_has_value(sym))
  76. printf(_("(NEW) "));
  77. line[0] = '\n';
  78. line[1] = 0;
  79. if (!sym_is_changable(sym)) {
  80. printf("%s\n", def);
  81. line[0] = '\n';
  82. line[1] = 0;
  83. return 0;
  84. }
  85. switch (input_mode) {
  86. case oldconfig:
  87. case silentoldconfig:
  88. if (sym_has_value(sym)) {
  89. printf("%s\n", def);
  90. return 0;
  91. }
  92. check_stdin();
  93. /* fall through */
  94. case oldaskconfig:
  95. fflush(stdout);
  96. xfgets(line, sizeof(line), stdin);
  97. if (!tty_stdio)
  98. printf("\n");
  99. return 1;
  100. default:
  101. break;
  102. }
  103. switch (type) {
  104. case S_INT:
  105. case S_HEX:
  106. case S_STRING:
  107. printf("%s\n", def);
  108. return 1;
  109. default:
  110. ;
  111. }
  112. printf("%s", line);
  113. return 1;
  114. }
  115. static int conf_string(struct menu *menu)
  116. {
  117. struct symbol *sym = menu->sym;
  118. const char *def;
  119. while (1) {
  120. printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
  121. printf("(%s) ", sym->name);
  122. def = sym_get_string_value(sym);
  123. if (sym_get_string_value(sym))
  124. printf("[%s] ", def);
  125. if (!conf_askvalue(sym, def))
  126. return 0;
  127. switch (line[0]) {
  128. case '\n':
  129. break;
  130. case '?':
  131. /* print help */
  132. if (line[1] == '\n') {
  133. print_help(menu);
  134. def = NULL;
  135. break;
  136. }
  137. /* fall through */
  138. default:
  139. line[strlen(line)-1] = 0;
  140. def = line;
  141. }
  142. if (def && sym_set_string_value(sym, def))
  143. return 0;
  144. }
  145. }
  146. static int conf_sym(struct menu *menu)
  147. {
  148. struct symbol *sym = menu->sym;
  149. tristate oldval, newval;
  150. while (1) {
  151. printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
  152. if (sym->name)
  153. printf("(%s) ", sym->name);
  154. putchar('[');
  155. oldval = sym_get_tristate_value(sym);
  156. switch (oldval) {
  157. case no:
  158. putchar('N');
  159. break;
  160. case mod:
  161. putchar('M');
  162. break;
  163. case yes:
  164. putchar('Y');
  165. break;
  166. }
  167. if (oldval != no && sym_tristate_within_range(sym, no))
  168. printf("/n");
  169. if (oldval != mod && sym_tristate_within_range(sym, mod))
  170. printf("/m");
  171. if (oldval != yes && sym_tristate_within_range(sym, yes))
  172. printf("/y");
  173. if (menu_has_help(menu))
  174. printf("/?");
  175. printf("] ");
  176. if (!conf_askvalue(sym, sym_get_string_value(sym)))
  177. return 0;
  178. strip(line);
  179. switch (line[0]) {
  180. case 'n':
  181. case 'N':
  182. newval = no;
  183. if (!line[1] || !strcmp(&line[1], "o"))
  184. break;
  185. continue;
  186. case 'm':
  187. case 'M':
  188. newval = mod;
  189. if (!line[1])
  190. break;
  191. continue;
  192. case 'y':
  193. case 'Y':
  194. newval = yes;
  195. if (!line[1] || !strcmp(&line[1], "es"))
  196. break;
  197. continue;
  198. case 0:
  199. newval = oldval;
  200. break;
  201. case '?':
  202. goto help;
  203. default:
  204. continue;
  205. }
  206. if (sym_set_tristate_value(sym, newval))
  207. return 0;
  208. help:
  209. print_help(menu);
  210. }
  211. }
  212. static int conf_choice(struct menu *menu)
  213. {
  214. struct symbol *sym, *def_sym;
  215. struct menu *child;
  216. bool is_new;
  217. sym = menu->sym;
  218. is_new = !sym_has_value(sym);
  219. if (sym_is_changable(sym)) {
  220. conf_sym(menu);
  221. sym_calc_value(sym);
  222. switch (sym_get_tristate_value(sym)) {
  223. case no:
  224. return 1;
  225. case mod:
  226. return 0;
  227. case yes:
  228. break;
  229. }
  230. } else {
  231. switch (sym_get_tristate_value(sym)) {
  232. case no:
  233. return 1;
  234. case mod:
  235. printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
  236. return 0;
  237. case yes:
  238. break;
  239. }
  240. }
  241. while (1) {
  242. int cnt, def;
  243. printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
  244. def_sym = sym_get_choice_value(sym);
  245. cnt = def = 0;
  246. line[0] = 0;
  247. for (child = menu->list; child; child = child->next) {
  248. if (!menu_is_visible(child))
  249. continue;
  250. if (!child->sym) {
  251. printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
  252. continue;
  253. }
  254. cnt++;
  255. if (child->sym == def_sym) {
  256. def = cnt;
  257. printf("%*c", indent, '>');
  258. } else
  259. printf("%*c", indent, ' ');
  260. printf(" %d. %s", cnt, _(menu_get_prompt(child)));
  261. if (child->sym->name)
  262. printf(" (%s)", child->sym->name);
  263. if (!sym_has_value(child->sym))
  264. printf(_(" (NEW)"));
  265. printf("\n");
  266. }
  267. printf(_("%*schoice"), indent - 1, "");
  268. if (cnt == 1) {
  269. printf("[1]: 1\n");
  270. goto conf_childs;
  271. }
  272. printf("[1-%d", cnt);
  273. if (menu_has_help(menu))
  274. printf("?");
  275. printf("]: ");
  276. switch (input_mode) {
  277. case oldconfig:
  278. case silentoldconfig:
  279. if (!is_new) {
  280. cnt = def;
  281. printf("%d\n", cnt);
  282. break;
  283. }
  284. check_stdin();
  285. /* fall through */
  286. case oldaskconfig:
  287. fflush(stdout);
  288. xfgets(line, sizeof(line), stdin);
  289. strip(line);
  290. if (line[0] == '?') {
  291. print_help(menu);
  292. continue;
  293. }
  294. if (!line[0])
  295. cnt = def;
  296. else if (isdigit(line[0]))
  297. cnt = atoi(line);
  298. else
  299. continue;
  300. break;
  301. default:
  302. break;
  303. }
  304. conf_childs:
  305. for (child = menu->list; child; child = child->next) {
  306. if (!child->sym || !menu_is_visible(child))
  307. continue;
  308. if (!--cnt)
  309. break;
  310. }
  311. if (!child)
  312. continue;
  313. if (line[0] && line[strlen(line) - 1] == '?') {
  314. print_help(child);
  315. continue;
  316. }
  317. sym_set_choice_value(sym, child->sym);
  318. for (child = child->list; child; child = child->next) {
  319. indent += 2;
  320. conf(child);
  321. indent -= 2;
  322. }
  323. return 1;
  324. }
  325. }
  326. static void conf(struct menu *menu)
  327. {
  328. struct symbol *sym;
  329. struct property *prop;
  330. struct menu *child;
  331. if (!menu_is_visible(menu))
  332. return;
  333. sym = menu->sym;
  334. prop = menu->prompt;
  335. if (prop) {
  336. const char *prompt;
  337. switch (prop->type) {
  338. case P_MENU:
  339. if ((input_mode == silentoldconfig ||
  340. input_mode == listnewconfig ||
  341. input_mode == olddefconfig) &&
  342. rootEntry != menu) {
  343. check_conf(menu);
  344. return;
  345. }
  346. /* fall through */
  347. case P_COMMENT:
  348. prompt = menu_get_prompt(menu);
  349. if (prompt)
  350. printf("%*c\n%*c %s\n%*c\n",
  351. indent, '*',
  352. indent, '*', _(prompt),
  353. indent, '*');
  354. default:
  355. ;
  356. }
  357. }
  358. if (!sym)
  359. goto conf_childs;
  360. if (sym_is_choice(sym)) {
  361. conf_choice(menu);
  362. if (sym->curr.tri != mod)
  363. return;
  364. goto conf_childs;
  365. }
  366. switch (sym->type) {
  367. case S_INT:
  368. case S_HEX:
  369. case S_STRING:
  370. conf_string(menu);
  371. break;
  372. default:
  373. conf_sym(menu);
  374. break;
  375. }
  376. conf_childs:
  377. if (sym)
  378. indent += 2;
  379. for (child = menu->list; child; child = child->next)
  380. conf(child);
  381. if (sym)
  382. indent -= 2;
  383. }
  384. static void check_conf(struct menu *menu)
  385. {
  386. struct symbol *sym;
  387. struct menu *child;
  388. if (!menu_is_visible(menu))
  389. return;
  390. sym = menu->sym;
  391. if (sym && !sym_has_value(sym)) {
  392. if (sym_is_changable(sym) ||
  393. (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
  394. if (input_mode == listnewconfig) {
  395. if (sym->name && !sym_is_choice_value(sym)) {
  396. printf("%s%s\n", CONFIG_, sym->name);
  397. }
  398. } else if (input_mode != olddefconfig) {
  399. if (!conf_cnt++)
  400. printf(_("*\n* Restart config...\n*\n"));
  401. rootEntry = menu_get_parent_menu(menu);
  402. conf(rootEntry);
  403. }
  404. }
  405. }
  406. for (child = menu->list; child; child = child->next)
  407. check_conf(child);
  408. }
  409. #if 00 // || !defined __UCLIBC__ || \
  410. defined __UCLIBC_HAS_GETOPT_LONG__
  411. static struct option long_opts[] = {
  412. {"oldaskconfig", no_argument, NULL, oldaskconfig},
  413. {"oldconfig", no_argument, NULL, oldconfig},
  414. {"silentoldconfig", no_argument, NULL, silentoldconfig},
  415. {"defconfig", optional_argument, NULL, defconfig},
  416. {"savedefconfig", required_argument, NULL, savedefconfig},
  417. {"allnoconfig", no_argument, NULL, allnoconfig},
  418. {"allyesconfig", no_argument, NULL, allyesconfig},
  419. {"allmodconfig", no_argument, NULL, allmodconfig},
  420. {"alldefconfig", no_argument, NULL, alldefconfig},
  421. {"randconfig", no_argument, NULL, randconfig},
  422. {"listnewconfig", no_argument, NULL, listnewconfig},
  423. {"olddefconfig", no_argument, NULL, olddefconfig},
  424. /*
  425. * oldnoconfig is an alias of olddefconfig, because people already
  426. * are dependent on its behavior(sets new symbols to their default
  427. * value but not 'n') with the counter-intuitive name.
  428. */
  429. {"oldnoconfig", no_argument, NULL, olddefconfig},
  430. {NULL, 0, NULL, 0}
  431. };
  432. static void conf_usage(const char *progname)
  433. {
  434. printf("Usage: %s [option] <kconfig-file>\n", progname);
  435. printf("[option] is _one_ of the following:\n");
  436. printf(" --listnewconfig List new options\n");
  437. printf(" --oldaskconfig Start a new configuration using a line-oriented program\n");
  438. printf(" --oldconfig Update a configuration using a provided .config as base\n");
  439. printf(" --silentoldconfig Same as oldconfig, but quietly, additionally update deps\n");
  440. printf(" --olddefconfig Same as silentoldconfig but sets new symbols to their default value\n");
  441. printf(" --oldnoconfig An alias of olddefconfig\n");
  442. printf(" --defconfig <file> New config with default defined in <file>\n");
  443. printf(" --savedefconfig <file> Save the minimal current configuration to <file>\n");
  444. printf(" --allnoconfig New config where all options are answered with no\n");
  445. printf(" --allyesconfig New config where all options are answered with yes\n");
  446. printf(" --allmodconfig New config where all options are answered with mod\n");
  447. printf(" --alldefconfig New config with all symbols set to default\n");
  448. printf(" --randconfig New config with random answer to all options\n");
  449. }
  450. #else
  451. static void conf_usage(const char *progname)
  452. {
  453. printf("Usage: %s [option] <kconfig-file>\n", progname);
  454. printf("[option] is _one_ of the following:\n");
  455. printf(" -a, --oldaskconfig Start a new configuration using a line-oriented program\n");
  456. printf(" -s, --silentoldconfig Same as oldconfig, but quietly, additionally update deps\n");
  457. printf(" -o, --oldconfig Update a configuration using a provided .config as base\n");
  458. printf(" -n, --allnoconfig New config where all options are answered with no\n");
  459. printf(" -y, --allyesconfig New config where all options are answered with yes\n");
  460. printf(" -m, --allmodconfig New config where all options are answered with mod\n");
  461. printf(" -A, --alldefconfig New config with all symbols set to default\n");
  462. printf(" -r, --randconfig New config with random answer to all options\n");
  463. printf(" -D, --defconfig <file> New config with default defined in <file>\n");
  464. printf(" -S, --savedefconfig <file> Save the minimal current configuration to <file>\n");
  465. printf(" -l, --listnewconfig List new options\n");
  466. printf(" -d, --olddefconfig Same as silentoldconfig but sets new symbols to their default value\n");
  467. printf(" --oldnoconfig An alias of olddefconfig\n");
  468. }
  469. #endif
  470. int main(int ac, char **av)
  471. {
  472. const char *progname = av[0];
  473. int opt;
  474. const char *name, *defconfig_file = NULL /* gcc uninit */;
  475. struct stat tmpstat;
  476. setlocale(LC_ALL, "");
  477. bindtextdomain(PACKAGE, LOCALEDIR);
  478. textdomain(PACKAGE);
  479. tty_stdio = isatty(0) && isatty(1) && isatty(2);
  480. #if 00// !defined __UCLIBC__ || \
  481. defined __UCLIBC_HAS_GETOPT_LONG__
  482. while ((opt = getopt_long(ac, av, "", long_opts, NULL)) != -1)
  483. #else
  484. char *gch = "asonymArDSld";
  485. while ((opt = getopt(ac, av, "asonymArD:S:ldh")) != -1)
  486. #endif
  487. {
  488. char *x = memchr(gch, opt, strlen(gch));
  489. if (x == NULL)
  490. opt = '?';
  491. else
  492. opt = x - gch;
  493. input_mode = (enum input_mode)opt;
  494. switch (opt) {
  495. case silentoldconfig:
  496. sync_kconfig = 1;
  497. break;
  498. case defconfig:
  499. case savedefconfig:
  500. defconfig_file = optarg;
  501. break;
  502. case randconfig:
  503. {
  504. struct timeval now;
  505. unsigned int seed;
  506. char *seed_env;
  507. /*
  508. * Use microseconds derived seed,
  509. * compensate for systems where it may be zero
  510. */
  511. gettimeofday(&now, NULL);
  512. seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
  513. seed_env = getenv("KCONFIG_SEED");
  514. if( seed_env && *seed_env ) {
  515. char *endp;
  516. int tmp = (int)strtol(seed_env, &endp, 0);
  517. if (*endp == '\0') {
  518. seed = tmp;
  519. }
  520. }
  521. fprintf( stderr, "KCONFIG_SEED=0x%X\n", seed );
  522. srand(seed);
  523. break;
  524. }
  525. case oldaskconfig:
  526. case oldconfig:
  527. case allnoconfig:
  528. case allyesconfig:
  529. case allmodconfig:
  530. case alldefconfig:
  531. case listnewconfig:
  532. case olddefconfig:
  533. break;
  534. case '?':
  535. conf_usage(progname);
  536. exit(1);
  537. break;
  538. }
  539. }
  540. if (ac == optind) {
  541. printf(_("%s: Kconfig file missing\n"), av[0]);
  542. conf_usage(progname);
  543. exit(1);
  544. }
  545. name = av[optind];
  546. conf_parse(name);
  547. //zconfdump(stdout);
  548. if (sync_kconfig) {
  549. name = conf_get_configname();
  550. if (stat(name, &tmpstat)) {
  551. fprintf(stderr, _("***\n"
  552. "*** Configuration file \"%s\" not found!\n"
  553. "***\n"
  554. "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
  555. "*** \"make menuconfig\" or \"make xconfig\").\n"
  556. "***\n"), name);
  557. exit(1);
  558. }
  559. }
  560. switch (input_mode) {
  561. case defconfig:
  562. if (!defconfig_file)
  563. defconfig_file = conf_get_default_confname();
  564. if (conf_read(defconfig_file)) {
  565. printf(_("***\n"
  566. "*** Can't find default configuration \"%s\"!\n"
  567. "***\n"), defconfig_file);
  568. exit(1);
  569. }
  570. break;
  571. case savedefconfig:
  572. case silentoldconfig:
  573. case oldaskconfig:
  574. case oldconfig:
  575. case listnewconfig:
  576. case olddefconfig:
  577. conf_read(NULL);
  578. break;
  579. case allnoconfig:
  580. case allyesconfig:
  581. case allmodconfig:
  582. case alldefconfig:
  583. case randconfig:
  584. name = getenv("KCONFIG_ALLCONFIG");
  585. if (!name)
  586. break;
  587. if ((strcmp(name, "") != 0) && (strcmp(name, "1") != 0)) {
  588. if (conf_read_simple(name, S_DEF_USER)) {
  589. fprintf(stderr,
  590. _("*** Can't read seed configuration \"%s\"!\n"),
  591. name);
  592. exit(1);
  593. }
  594. break;
  595. }
  596. switch (input_mode) {
  597. case allnoconfig: name = "allno.config"; break;
  598. case allyesconfig: name = "allyes.config"; break;
  599. case allmodconfig: name = "allmod.config"; break;
  600. case alldefconfig: name = "alldef.config"; break;
  601. case randconfig: name = "allrandom.config"; break;
  602. default: break;
  603. }
  604. if (conf_read_simple(name, S_DEF_USER) &&
  605. conf_read_simple("all.config", S_DEF_USER)) {
  606. fprintf(stderr,
  607. _("*** KCONFIG_ALLCONFIG set, but no \"%s\" or \"all.config\" file found\n"),
  608. name);
  609. exit(1);
  610. }
  611. break;
  612. default:
  613. break;
  614. }
  615. if (sync_kconfig) {
  616. if (conf_get_changed()) {
  617. name = getenv("KCONFIG_NOSILENTUPDATE");
  618. if (name && *name) {
  619. fprintf(stderr,
  620. _("\n*** The configuration requires explicit update.\n\n"));
  621. return 1;
  622. }
  623. }
  624. valid_stdin = tty_stdio;
  625. }
  626. switch (input_mode) {
  627. case allnoconfig:
  628. conf_set_all_new_symbols(def_no);
  629. break;
  630. case allyesconfig:
  631. conf_set_all_new_symbols(def_yes);
  632. break;
  633. case allmodconfig:
  634. conf_set_all_new_symbols(def_mod);
  635. break;
  636. case alldefconfig:
  637. conf_set_all_new_symbols(def_default);
  638. break;
  639. case randconfig:
  640. /* Really nothing to do in this loop */
  641. while (conf_set_all_new_symbols(def_random)) ;
  642. break;
  643. case defconfig:
  644. conf_set_all_new_symbols(def_default);
  645. break;
  646. case savedefconfig:
  647. break;
  648. case oldaskconfig:
  649. rootEntry = &rootmenu;
  650. conf(&rootmenu);
  651. input_mode = silentoldconfig;
  652. /* fall through */
  653. case oldconfig:
  654. case listnewconfig:
  655. case olddefconfig:
  656. case silentoldconfig:
  657. /* Update until a loop caused no more changes */
  658. do {
  659. conf_cnt = 0;
  660. check_conf(&rootmenu);
  661. } while (conf_cnt &&
  662. (input_mode != listnewconfig &&
  663. input_mode != olddefconfig));
  664. break;
  665. }
  666. if (sync_kconfig) {
  667. /* silentoldconfig is used during the build so we shall update autoconf.
  668. * All other commands are only used to generate a config.
  669. */
  670. if (conf_get_changed() && conf_write(NULL)) {
  671. fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
  672. exit(1);
  673. }
  674. if (conf_write_autoconf()) {
  675. fprintf(stderr, _("\n*** Error during update of the configuration.\n\n"));
  676. return 1;
  677. }
  678. } else if (input_mode == savedefconfig) {
  679. if (conf_write_defconfig(defconfig_file)) {
  680. fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
  681. defconfig_file);
  682. return 1;
  683. }
  684. } else if (input_mode != listnewconfig) {
  685. if (conf_write(NULL)) {
  686. fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
  687. exit(1);
  688. }
  689. }
  690. return 0;
  691. }
  692. /*
  693. * Helper function to facilitate fgets() by Jean Sacren.
  694. */
  695. void xfgets(char *str, int size, FILE *in)
  696. {
  697. if (fgets(str, size, in) == NULL)
  698. fprintf(stderr, "\nError in reading or end of file.\n");
  699. }