conf.c 17 KB

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