Source:NetHack 5.0.0/src/cfgfiles.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to cfgfiles.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/cfgfiles.c#line12]], for example.

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

1. /* NetHack 5.0	cfgfiles.c	$NHDT-Date: 1740532826 2025/02/25 17:20:26 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.417 $ */
2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3. /*-Copyright (c) Derek S. Ray, 2015. */
4. /* NetHack may be freely redistributed.  See license for details. */
5. 
6. #define NEED_VARARGS
7. 
8. #include "hack.h"
9. #include "dlb.h"
10. #include <errno.h>
11. 
12. #if (!defined(MACOS9) && !defined(O_WRONLY) && !defined(AZTEC_C)) \
13.     || defined(USE_FCNTL)
14. #include <fcntl.h>
15. #endif
16. 
17. #define BIGBUFSZ (5 * BUFSZ) /* big enough to format a 4*BUFSZ string (from
18.                               * config file parsing) with modest decoration;
19.                               * result will then be truncated to BUFSZ-1 */
20. 
21. #ifdef USER_SOUNDS
22. extern char *sounddir; /* defined in sounds.c */
23. #endif
24. 
25. staticfn void vconfig_error_add(const char *, va_list);
26. staticfn FILE *fopen_config_file(const char *, int);
27. staticfn int get_uchars(char *, uchar *, boolean, int, const char *);
28. #ifdef NOCWD_ASSUMPTIONS
29. staticfn void adjust_prefix(char *, int);
30. #endif
31. staticfn char *choose_random_part(char *, char);
32. staticfn boolean config_error_nextline(const char *);
33. staticfn void free_config_sections(void);
34. staticfn char *is_config_section(char *);
35. staticfn boolean handle_config_section(char *);
36. boolean parse_config_line(char *);
37. staticfn char *find_optparam(char *);
38. #ifndef SFCTOOL
39. staticfn boolean cnf_line_OPTIONS(char *);
40. staticfn boolean cnf_line_AUTOPICKUP_EXCEPTION(char *);
41. staticfn boolean cnf_line_BINDINGS(char *);
42. staticfn boolean cnf_line_AUTOCOMPLETE(char *);
43. staticfn boolean cnf_line_MSGTYPE(char *);
44. staticfn boolean cnf_line_HACKDIR(char *);
45. staticfn boolean cnf_line_LEVELDIR(char *);
46. staticfn boolean cnf_line_SAVEDIR(char *);
47. staticfn boolean cnf_line_BONESDIR(char *);
48. staticfn boolean cnf_line_DATADIR(char *);
49. staticfn boolean cnf_line_SCOREDIR(char *);
50. staticfn boolean cnf_line_LOCKDIR(char *);
51. staticfn boolean cnf_line_CONFIGDIR(char *);
52. staticfn boolean cnf_line_TROUBLEDIR(char *);
53. staticfn boolean cnf_line_NAME(char *);
54. staticfn boolean cnf_line_ROLE(char *);
55. staticfn boolean cnf_line_dogname(char *);
56. staticfn boolean cnf_line_catname(char *);
57. #endif /* SFCTOOL */
58. #ifdef SYSCF
59. staticfn boolean cnf_line_WIZARDS(char *);
60. staticfn boolean cnf_line_SHELLERS(char *);
61. staticfn boolean cnf_line_MSGHANDLER(char *);
62. staticfn boolean cnf_line_EXPLORERS(char *);
63. staticfn boolean cnf_line_DEBUGFILES(char *);
64. staticfn boolean cnf_line_DUMPLOGFILE(char *);
65. staticfn boolean cnf_line_GENERICUSERS(char *);
66. staticfn boolean cnf_line_BONES_POOLS(char *);
67. staticfn boolean cnf_line_SUPPORT(char *);
68. staticfn boolean cnf_line_RECOVER(char *);
69. staticfn boolean cnf_line_CHECK_SAVE_UID(char *);
70. staticfn boolean cnf_line_CHECK_PLNAME(char *);
71. staticfn boolean cnf_line_SEDUCE(char *);
72. staticfn boolean cnf_line_HIDEUSAGE(char *);
73. staticfn boolean cnf_line_MAXPLAYERS(char *);
74. staticfn boolean cnf_line_PERSMAX(char *);
75. staticfn boolean cnf_line_PERS_IS_UID(char *);
76. staticfn boolean cnf_line_ENTRYMAX(char *);
77. staticfn boolean cnf_line_POINTSMIN(char *);
78. staticfn boolean cnf_line_MAX_STATUENAME_RANK(char *);
79. staticfn boolean cnf_line_LIVELOG(char *);
80. staticfn boolean cnf_line_PANICTRACE_LIBC(char *);
81. staticfn boolean cnf_line_PANICTRACE_GDB(char *);
82. staticfn boolean cnf_line_GDBPATH(char *);
83. staticfn boolean cnf_line_GREPPATH(char *);
84. staticfn boolean cnf_line_CRASHREPORTURL(char *);
85. staticfn boolean cnf_line_ACCESSIBILITY(char *);
86. 
87. staticfn boolean cnf_line_PORTABLE_DEVICE_PATHS(char *);
88. #endif /* SYSCF */
89. #ifndef SFCTOOL
90. staticfn boolean cnf_line_BOULDER(char *);
91. staticfn boolean cnf_line_MENUCOLOR(char *);
92. staticfn boolean cnf_line_HILITE_STATUS(char *);
93. staticfn boolean cnf_line_WARNINGS(char *);
94. staticfn boolean cnf_line_ROGUESYMBOLS(char *);
95. staticfn boolean cnf_line_SYMBOLS(char *);
96. staticfn boolean cnf_line_WIZKIT(char *);
97. #ifdef USER_SOUNDS
98. staticfn boolean cnf_line_SOUNDDIR(char *);
99. staticfn boolean cnf_line_SOUND(char *);
100. #endif
101. staticfn boolean cnf_line_QT_TILEWIDTH(char *);
102. staticfn boolean cnf_line_QT_TILEHEIGHT(char *);
103. staticfn boolean cnf_line_QT_FONTSIZE(char *);
104. staticfn boolean cnf_line_QT_COMPACT(char *);
105. #endif /* SFCTOOL */
106. struct _cnf_parser_state; /* defined below (far below...) */
107. staticfn void cnf_parser_init(struct _cnf_parser_state *parser);
108. staticfn void cnf_parser_done(struct _cnf_parser_state *parser);
109. staticfn void parse_conf_buf(struct _cnf_parser_state *parser,
110.                            boolean (*proc)(char *arg));
111. /* next one is in extern.h; why here too? */
112. boolean parse_conf_str(const char *str, boolean (*proc)(char *arg));
113. static boolean ignore_errors_on_unmatched = FALSE,
114.                ignore_statement_errors = FALSE;
115. 
116. #ifdef SFCTOOL
117. #ifdef wait_synch
118. #undef wait_synch
119. #endif
120. #define wait_synch()
121. #endif /* SFCTOOL */
122. 
123. /* ----------  BEGIN CONFIG FILE HANDLING ----------- */
124. 
125. /* used for messaging. Also used in options.c */
126. static const char *default_configfile =
127. #ifdef UNIX
128.     ".nethackrc";
129. #else
130. #if defined(MACOS9) || defined(__BEOS__)
131.     "NetHack Defaults";
132. #else
133. #if defined(MSDOS) || defined(WIN32)
134.     CONFIG_FILE;
135. #else
136.     "NetHack.cnf";
137. #endif
138. #endif
139. #endif
140. static char configfile[BUFSZ];
141. 
142. char *
143. get_configfile(void)
144. {
145.     return configfile;
146. }
147. 
148. const char *
149. get_default_configfile(void)
150. {
151.     return default_configfile;
152. }
153. 
154. #ifdef MSDOS
155. /* conflict with speed-dial under windows
156.  * for XXX.cnf file so support of NetHack.cnf
157.  * is for backward compatibility only.
158.  * Preferred name (and first tried) is now defaults.nh but
159.  * the game will try the old name if there
160.  * is no defaults.nh.
161.  */
162. const char *backward_compat_configfile = "nethack.cnf";
163. #endif
164. 
165. #ifndef SFCTOOL
166. 
167. /* #saveoptions - save config options into file */
168. int
169. do_write_config_file(void)
170. {
171.     FILE *fp;
172.     char tmp[BUFSZ];
173. 
174.     if (!configfile[0]) {
175.         pline("Strange, could not figure out config file name.");
176.         return ECMD_OK;
177.     }
178.     if (flags.suppress_alert < FEATURE_NOTICE_VER(3,7,0)) {
179.         pline("Warning: saveoptions is highly experimental!");
180.         wait_synch();
181.         pline("Some settings are not saved!");
182.         wait_synch();
183.         pline("All manual customization and comments are removed"
184.               " from the file!");
185.         wait_synch();
186.     }
187. #define overwrite_prompt "Overwrite config file %.*s?"
188.     Sprintf(tmp, overwrite_prompt,
189.             (int) (BUFSZ - sizeof overwrite_prompt - 2), configfile);
190. #undef overwrite_prompt
191.     if (!paranoid_query(TRUE, tmp))
192.         return ECMD_OK;
193. 
194.     fp = fopen(configfile, "w");
195.     if (fp) {
196.         size_t len, wrote;
197.         strbuf_t buf;
198. 
199.         strbuf_init(&buf);
200.         all_options_strbuf(&buf);
201.         len = strlen(buf.str);
202.         wrote = fwrite(buf.str, 1, len, fp);
203.         fclose(fp);
204.         strbuf_empty(&buf);
205.         if (wrote != len)
206.             pline("An error occurred, wrote only partial data (%zu/%zu).",
207.                   wrote, len);
208.     }
209.     return ECMD_OK;
210. }
211. #endif /* SFCTOOL */
212. 
213. /* remember the name of the file we're accessing;
214.    if may be used in option reject messages */
215. void
216. set_configfile_name(const char *fname)
217. {
218.     (void) strncpy(configfile, fname, sizeof configfile - 1);
219.     configfile[sizeof configfile - 1] = '\0';
220. }
221. 
222. staticfn FILE *
223. fopen_config_file(const char *filename, int src)
224. {
225.     FILE *fp;
226. #if defined(UNIX) || defined(VMS)
227.     char tmp_config[BUFSZ];
228.     char *envp;
229. #endif
230. 
231.     if (src == set_in_sysconf) {
232.         /* SYSCF_FILE; if we can't open it, caller will bail */
233.         if (filename && *filename) {
234.             set_configfile_name(fqname(filename, SYSCONFPREFIX, 0));
235.             fp = fopen(configfile, "r");
236.         } else
237.             fp = (FILE *) 0;
238.         return  fp;
239.     }
240.     /* If src != set_in_sysconf, "filename" is an environment variable, so it
241.      * should hang around. If set, it is expected to be a full path name
242.      * (if relevant)
243.      */
244.     if (filename && *filename) {
245.         set_configfile_name(filename);
246. #ifdef UNIX
247.         if (!strncmp(configfile, "~/", 2) && (envp = nh_getenv("HOME")) != 0) {
248.             /* support for command line '--nethackrc=~/path' (or for
249.                NETHACKOPTIONS='@~/path'; we don't support ~user/path) */
250.             Snprintf(tmp_config, sizeof tmp_config, "%s/%s",
251.                      envp, configfile + 2); /* insert $HOME/ and remove ~/ */
252.             set_configfile_name(tmp_config);
253.         }
254.         if (access(configfile, 4) == -1) { /* 4 is R_OK on newer systems */
255.             /* nasty sneaky attempt to read file through
256.              * NetHack's setuid permissions -- this is the only
257.              * place a file name may be wholly under the player's
258.              * control (but SYSCF_FILE is not under the player's
259.              * control so it's OK).
260.              */
261.             raw_printf("Access to %s denied (%d).", configfile, errno);
262.             wait_synch();
263.             /* fall through to standard names */
264.         } else
265. #endif
266.         if ((fp = fopen(configfile, "r")) != (FILE *) 0) {
267.             return  fp;
268. #if defined(UNIX) || defined(VMS)
269.         } else {
270.             /* access() above probably caught most problems for UNIX */
271.             raw_printf("Couldn't open requested config file %s (%d).",
272.                        configfile, errno);
273.             wait_synch();
274. #endif
275.         }
276.     }
277.     /* fall through to standard names */
278. 
279. #if defined(MICRO) || defined(MACOS9) || defined(__BEOS__) || defined(WIN32)
280.     set_configfile_name(fqname(default_configfile, CONFIGPREFIX, 0));
281.     if ((fp = fopen(configfile, "r")) != (FILE *) 0) {
282.         return fp;
283.     } else if (strcmp(default_configfile, configfile)) {
284.         set_configfile_name(default_configfile);
285.         if ((fp = fopen(configfile, "r")) != (FILE *) 0)
286.             return fp;
287.     }
288. #ifdef MSDOS
289.     set_configfile_name(fqname(backward_compat_configfile, CONFIGPREFIX, 0));
290.     if ((fp = fopen(configfile, "r")) != (FILE *) 0) {
291.         return fp;
292.     } else if (strcmp(backward_compat_configfile, configfile)) {
293.         set_configfile_name(backward_compat_configfile);
294.         if ((fp = fopen(configfile, "r")) != (FILE *) 0)
295.             return fp;
296.     }
297. #endif
298. #else
299. /* constructed full path names don't need fqname() */
300. #ifdef VMS
301.     /* no punctuation, so might be a logical name */
302.     set_configfile_name("nethackini");
303.     if ((fp = fopen(configfile, "r")) != (FILE *) 0)
304.         return fp;
305.     set_configfile_name("sys$login:nethack.ini");
306.     if ((fp = fopen(configfile, "r")) != (FILE *) 0)
307.         return fp;
308. 
309.     envp = nh_getenv("HOME");
310.     if (!envp || !*envp)
311.         Strcpy(tmp_config, "NetHack.cnf");
312.     else
313.         Sprintf(tmp_config, "%s%s%s", envp,
314.                 !strchr(":]>/", envp[strlen(envp) - 1]) ? "/" : "",
315.                 "NetHack.cnf");
316.     set_configfile_name(tmp_config);
317.     if ((fp = fopen(configfile, "r")) != (FILE *) 0)
318.         return fp;
319. #else /* should be only UNIX left */
320.     envp = nh_getenv("HOME");
321.     if (!envp)
322.         Strcpy(tmp_config, ".nethackrc");
323.     else
324.         Sprintf(tmp_config, "%s/%s", envp, ".nethackrc");
325. 
326.     set_configfile_name(tmp_config);
327.     if ((fp = fopen(configfile, "r")) != (FILE *) 0)
328.         return fp;
329. #if defined(__APPLE__) /* UNIX+__APPLE__ => OSX || MacOS */
330.     /* try an alternative */
331.     if (envp) {
332.         /* keep 'tmp_config' intact here; if alternates fail, use it to
333.            restore configfile[] to its preferred setting (".nethackrc") */
334.         char alt_config[sizeof tmp_config];
335. 
336.         /* OSX-style configuration settings */
337.         Snprintf(alt_config, sizeof alt_config, "%s/%s", envp,
338.                  "Library/Preferences/NetHack Defaults");
339.         set_configfile_name(alt_config);
340.         if ((fp = fopen(configfile, "r")) != (FILE *) 0)
341.             return fp;
342.         /* may be easier for user to edit if filename has '.txt' suffix */
343.         Snprintf(alt_config, sizeof alt_config, "%s/%s", envp,
344.                  "Library/Preferences/NetHack Defaults.txt");
345.         set_configfile_name(alt_config);
346.         if ((fp = fopen(configfile, "r")) != (FILE *) 0)
347.             return fp;
348.         /* couldn't open either of the alternate names; for use in
349.            messages, put 'configfile' back to the normal value rather than
350.            leaving it set to last alternate; retry open() to reset 'errno' */
351.         set_configfile_name(tmp_config);
352.         if ((fp = fopen(configfile, "r")) != (FILE *) 0)
353.             return fp;
354.     }
355. #endif /*__APPLE__*/
356.     if (errno != ENOENT) {
357.         const char *details;
358. 
359.         /* e.g., problems when setuid NetHack can't search home
360.            directory restricted to user */
361. #if defined(NHSTDC) && !defined(NOTSTDC)
362.         if ((details = strerror(errno)) == 0)
363. #endif
364.             details = "";
365.         raw_printf("Couldn't open default config file %s %s(%d).",
366.                    configfile, details, errno);
367.         wait_synch();
368.     }
369. #endif /* !VMS => Unix */
370. #endif /* !(MICRO || MACOS9 || __BEOS__ || WIN32) */
371.     return (FILE *) 0;
372. }
373. 
374. /*
375.  * Retrieve a list of integers from buf into a uchar array.
376.  *
377.  * NOTE: zeros are inserted unless modlist is TRUE, in which case the list
378.  *  location is unchanged.  Callers must handle zeros if modlist is FALSE.
379.  */
380. staticfn int
381. get_uchars(char *bufp,       /* current pointer */
382.            uchar *list,      /* return list */
383.            boolean modlist,  /* TRUE: list is being modified in place */
384.            int size,         /* return list size */
385.            const char *name) /* name of option for error message */
386. {
387.     unsigned int num = 0;
388.     int count = 0;
389.     boolean havenum = FALSE;
390. 
391.     while (1) {
392.         switch (*bufp) {
393.         case ' ':
394.         case '\0':
395.         case '\t':
396.         case '\n':
397.             if (havenum) {
398.                 /* if modifying in place, don't insert zeros */
399.                 if (num || !modlist)
400.                     list[count] = num;
401.                 count++;
402.                 num = 0;
403.                 havenum = FALSE;
404.             }
405.             if (count == size || !*bufp)
406.                 return count;
407.             bufp++;
408.             break;
409. 
410.         case '0':
411.         case '1':
412.         case '2':
413.         case '3':
414.         case '4':
415.         case '5':
416.         case '6':
417.         case '7':
418.         case '8':
419.         case '9':
420.             havenum = TRUE;
421.             num = num * 10 + (*bufp - '0');
422.             bufp++;
423.             break;
424. 
425.         case '\\':
426.             goto gi_error;
427.             break;
428. 
429.         default:
430.  gi_error:
431.             raw_printf("Syntax error in %s", name);
432.             wait_synch();
433.             return count;
434.         }
435.     }
436.     /*NOTREACHED*/
437. }
438. 
439. #ifdef NOCWD_ASSUMPTIONS
440. staticfn void
441. adjust_prefix(char *bufp, int prefixid)
442. {
443.     char *ptr;
444. 
445.     if (!bufp)
446.         return;
447. #ifdef WIN32
448.     if (fqn_prefix_locked[prefixid])
449.         return;
450. #endif
451.     /* Backward compatibility, ignore trailing ;n */
452.     if ((ptr = strchr(bufp, ';')) != 0)
453.         *ptr = '\0';
454.     if (strlen(bufp) > 0) {
455.         gf.fqn_prefix[prefixid] = (char *) alloc(strlen(bufp) + 2);
456.         Strcpy(gf.fqn_prefix[prefixid], bufp);
457.         append_slash(gf.fqn_prefix[prefixid]);
458.     }
459. }
460. #endif
461. 
462. /* Choose at random one of the sep separated parts from str. Mangles str. */
463. staticfn char *
464. choose_random_part(char *str, char sep)
465. {
466.     int nsep = 1;
467.     int csep;
468.     int len = 0;
469.     char *begin = str;
470. 
471.     if (!str)
472.         return (char *) 0;
473. 
474.     while (*str) {
475.         if (*str == sep)
476.             nsep++;
477.         str++;
478.     }
479. #ifndef SFCTOOL
480.     csep = rn2(nsep);
481. #else
482.     nhUse(nsep);
483.     csep = 1;
484. #endif
485.     str = begin;
486.     while ((csep > 0) && *str) {
487.         str++;
488.         if (*str == sep)
489.             csep--;
490.     }
491.     if (*str) {
492.         if (*str == sep)
493.             str++;
494.         begin = str;
495.         while (*str && *str != sep) {
496.             str++;
497.             len++;
498.         }
499.         *str = '\0';
500.         if (len)
501.             return begin;
502.     }
503.     return (char *) 0;
504. }
505. 
506. staticfn void
507. free_config_sections(void)
508. {
509.     if (gc.config_section_chosen) {
510.         free(gc.config_section_chosen);
511.         gc.config_section_chosen = NULL;
512.     }
513.     if (gc.config_section_current) {
514.         free(gc.config_section_current);
515.         gc.config_section_current = NULL;
516.     }
517. }
518. 
519. /* check for " [ anything-except-bracket-or-empty ] # arbitrary-comment"
520.    with spaces optional; returns pointer to "anything-except..." (with
521.    trailing " ] #..." stripped) if ok, otherwise Null */
522. staticfn char *
523. is_config_section(
524.     char *str) /* trailing spaces are stripped, ']' too iff result is good */
525. {
526.     char *a, *c, *z;
527. 
528.     /* remove any spaces at start and end; won't significantly interfere
529.        with echoing the string in a config error message, if warranted */
530.     a = trimspaces(str);
531.     /* first character should be open square bracket; set pointer past it */
532.     if (*a++ != '[')
533.         return (char *) 0;
534.     /* last character should be close bracket, ignoring any comment */
535.     z = strchr(a, ']');
536.     if (!z)
537.         return (char *) 0;
538.     /* comment, if present, can be preceded by spaces */
539.     for (c = z + 1; *c == ' '; ++c)
540.         continue;
541.     if (*c && *c != '#')
542.         return (char *) 0;
543.     /* we now know that result is good; there won't be a config error
544.        message so we can modify the input string */
545.     *z = '\0';
546.     /* 'a' points past '[' and the string ends where ']' was; remove any
547.        spaces between '[' and choice-start and between choice-end and ']' */
548.     return trimspaces(a);
549. }
550. 
551. staticfn boolean
552. handle_config_section(char *buf)
553. {
554.     char *sect = is_config_section(buf);
555. 
556.     if (sect) {
557.         if (gc.config_section_current)
558.             free(gc.config_section_current), gc.config_section_current = 0;
559.         /* is_config_section() removed brackets from 'sect' */
560.         if (!gc.config_section_chosen) {
561.             config_error_add("Section \"[%s]\" without CHOOSE", sect);
562.             return TRUE;
563.         }
564.         if (*sect) { /* got a section name */
565.             gc.config_section_current = dupstr(sect);
566.             debugpline1("set config section: '%s'",
567.                         gc.config_section_current);
568.         } else { /* empty section name => end of sections */
569.             free_config_sections();
570.             debugpline0("unset config section");
571.         }
572.         return TRUE;
573.     }
574. 
575.     if (gc.config_section_current) {
576.         if (!gc.config_section_chosen)
577.             return TRUE;
578.         if (strcmp(gc.config_section_current, gc.config_section_chosen))
579.             return TRUE;
580.     }
581.     return FALSE;
582. }
583. 
584. #define match_varname(INP, NAM, LEN) match_optname(INP, NAM, LEN, TRUE)
585. 
586. /* find the '=' or ':' */
587. staticfn char *
588. find_optparam(char *buf)
589. {
590.     char *bufp, *altp;
591. 
592.     bufp = strchr(buf, '=');
593.     altp = strchr(buf, ':');
594.     if (!bufp || (altp && altp < bufp))
595.         bufp = altp;
596. 
597.     return bufp;
598. }
599. 
600. #ifndef SFCTOOL
601. 
602. staticfn boolean
603. cnf_line_OPTIONS(char *origbuf)
604. {
605.     char *bufp = find_optparam(origbuf);
606. 
607.     ++bufp; /* skip '='; parseoptions() handles spaces */
608.     return parseoptions(bufp, TRUE, TRUE);
609. }
610. 
611. staticfn boolean
612. cnf_line_AUTOPICKUP_EXCEPTION(char *bufp)
613. {
614.     add_autopickup_exception(bufp);
615.     return TRUE;
616. }
617. 
618. staticfn boolean
619. cnf_line_BINDINGS(char *bufp)
620. {
621.     return parsebindings(bufp);
622. }
623. 
624. staticfn boolean
625. cnf_line_AUTOCOMPLETE(char *bufp)
626. {
627.     parseautocomplete(bufp, TRUE);
628.     return TRUE;
629. }
630. 
631. staticfn boolean
632. cnf_line_MSGTYPE(char *bufp)
633. {
634.     return msgtype_parse_add(bufp);
635. }
636. 
637. staticfn boolean
638. cnf_line_HACKDIR(char *bufp)
639. {
640. #ifdef NOCWD_ASSUMPTIONS
641.     adjust_prefix(bufp, HACKPREFIX);
642. #else /*NOCWD_ASSUMPTIONS*/
643. #ifdef MICRO
644.     (void) strncpy(gh.hackdir, bufp, PATHLEN - 1);
645. #else /* MICRO */
646.     nhUse(bufp);
647. #endif /* MICRO */
648. #endif /*NOCWD_ASSUMPTIONS*/
649.     return TRUE;
650. }
651. 
652. staticfn boolean
653. cnf_line_LEVELDIR(char *bufp)
654. {
655. #ifdef NOCWD_ASSUMPTIONS
656.     adjust_prefix(bufp, LEVELPREFIX);
657. #else /*NOCWD_ASSUMPTIONS*/
658. #ifdef MICRO
659.     if (strlen(bufp) >= PATHLEN)
660.         bufp[PATHLEN - 1] = '\0';
661.     Strcpy(g.permbones, bufp);
662.     if (!ramdisk_specified || !*levels)
663.         Strcpy(levels, bufp);
664.     gr.ramdisk = (strcmp(g.permbones, levels) != 0);
665. #else /* MICRO */
666.     nhUse(bufp);
667. #endif /* MICRO */
668. #endif /*NOCWD_ASSUMPTIONS*/
669.     return TRUE;
670. }
671. 
672. staticfn boolean
673. cnf_line_SAVEDIR(char *bufp)
674. {
675. #ifdef NOCWD_ASSUMPTIONS
676.     adjust_prefix(bufp, SAVEPREFIX);
677. #else /*NOCWD_ASSUMPTIONS*/
678. #ifdef MICRO
679.     char *ptr;
680. 
681.     if ((ptr = strchr(bufp, ';')) != 0) {
682.         *ptr = '\0';
683.     }
684. 
685.     (void) strncpy(gs.SAVEP, bufp, SAVESIZE - 1);
686.     append_slash(gs.SAVEP);
687. #else /* MICRO */
688.     nhUse(bufp);
689. #endif /* MICRO */
690. #endif /*NOCWD_ASSUMPTIONS*/
691.     return TRUE;
692. }
693. 
694. staticfn boolean
695. cnf_line_BONESDIR(char *bufp)
696. {
697. #ifdef NOCWD_ASSUMPTIONS
698.     adjust_prefix(bufp, BONESPREFIX);
699. #else
700.     nhUse(bufp);
701. #endif
702.     return TRUE;
703. }
704. 
705. staticfn boolean
706. cnf_line_DATADIR(char *bufp)
707. {
708. #ifdef NOCWD_ASSUMPTIONS
709.     adjust_prefix(bufp, DATAPREFIX);
710. #else
711.     nhUse(bufp);
712. #endif
713.     return TRUE;
714. }
715. 
716. staticfn boolean
717. cnf_line_SCOREDIR(char *bufp)
718. {
719. #ifdef NOCWD_ASSUMPTIONS
720.     adjust_prefix(bufp, SCOREPREFIX);
721. #else
722.     nhUse(bufp);
723. #endif
724.     return TRUE;
725. }
726. 
727. staticfn boolean
728. cnf_line_LOCKDIR(char *bufp)
729. {
730. #ifdef NOCWD_ASSUMPTIONS
731.     adjust_prefix(bufp, LOCKPREFIX);
732. #else
733.     nhUse(bufp);
734. #endif
735.     return TRUE;
736. }
737. 
738. staticfn boolean
739. cnf_line_CONFIGDIR(char *bufp)
740. {
741. #ifdef NOCWD_ASSUMPTIONS
742.     adjust_prefix(bufp, CONFIGPREFIX);
743. #else
744.     nhUse(bufp);
745. #endif
746.     return TRUE;
747. }
748. 
749. staticfn boolean
750. cnf_line_TROUBLEDIR(char *bufp)
751. {
752. #ifdef NOCWD_ASSUMPTIONS
753.     adjust_prefix(bufp, TROUBLEPREFIX);
754. #else
755.     nhUse(bufp);
756. #endif
757.     return TRUE;
758. }
759. 
760. staticfn boolean
761. cnf_line_NAME(char *bufp)
762. {
763.     (void) strncpy(svp.plname, bufp, PL_NSIZ - 1);
764.     return TRUE;
765. }
766. 
767. staticfn boolean
768. cnf_line_ROLE(char *bufp)
769. {
770.     int len;
771. 
772.     if ((len = str2role(bufp)) >= 0)
773.         flags.initrole = len;
774.     return TRUE;
775. }
776. 
777. staticfn boolean
778. cnf_line_dogname(char *bufp)
779. {
780.     (void) strncpy(gd.dogname, bufp, PL_PSIZ - 1);
781.     return TRUE;
782. }
783. 
784. staticfn boolean
785. cnf_line_catname(char *bufp)
786. {
787.     (void) strncpy(gc.catname, bufp, PL_PSIZ - 1);
788.     return TRUE;
789. }
790. #endif /* SFCTOOL */
791. 
792. #ifdef SYSCF
793. 
794. staticfn boolean
795. cnf_line_WIZARDS(char *bufp)
796. {
797.     if (sysopt.wizards)
798.         free((genericptr_t) sysopt.wizards);
799.     sysopt.wizards = dupstr(bufp);
800.     if (strlen(sysopt.wizards) && strcmp(sysopt.wizards, "*")) {
801.         /* pre-format WIZARDS list now; it's displayed during a panic
802.            and since that panic might be due to running out of memory,
803.            we don't want to risk attempting to allocate any memory then */
804.         if (sysopt.fmtd_wizard_list)
805.             free((genericptr_t) sysopt.fmtd_wizard_list);
806.         sysopt.fmtd_wizard_list = build_english_list(sysopt.wizards);
807.     }
808.     return TRUE;
809. }
810. 
811. staticfn boolean
812. cnf_line_SHELLERS(char *bufp)
813. {
814.     if (sysopt.shellers)
815.         free((genericptr_t) sysopt.shellers);
816.     sysopt.shellers = dupstr(bufp);
817.     return TRUE;
818. }
819. 
820. staticfn boolean
821. cnf_line_MSGHANDLER(char *bufp)
822. {
823.     if (sysopt.msghandler)
824.         free((genericptr_t) sysopt.msghandler);
825.     sysopt.msghandler = dupstr(bufp);
826.     return TRUE;
827. }
828. 
829. staticfn boolean
830. cnf_line_EXPLORERS(char *bufp)
831. {
832.     if (sysopt.explorers)
833.         free((genericptr_t) sysopt.explorers);
834.     sysopt.explorers = dupstr(bufp);
835.     return TRUE;
836. }
837. 
838. staticfn boolean
839. cnf_line_DEBUGFILES(char *bufp)
840. {
841.     /* might already have a vaule from getenv("DEBUGFILES");
842.        if so, ignore this value from SYSCF */
843.     if (!sysopt.env_dbgfl) {
844.         if (sysopt.debugfiles)
845.             free((genericptr_t) sysopt.debugfiles);
846.         sysopt.debugfiles = dupstr(bufp);
847.     }
848.     return TRUE;
849. }
850. 
851. staticfn boolean
852. cnf_line_DUMPLOGFILE(char *bufp)
853. {
854. #ifdef DUMPLOG
855.     if (sysopt.dumplogfile)
856.         free((genericptr_t) sysopt.dumplogfile);
857.     sysopt.dumplogfile = dupstr(bufp);
858. #else
859.     nhUse(bufp);
860. #endif /*DUMPLOG*/
861.     return TRUE;
862. }
863. 
864. staticfn boolean
865. cnf_line_GENERICUSERS(char *bufp)
866. {
867.     if (sysopt.genericusers)
868.         free((genericptr_t) sysopt.genericusers);
869.     sysopt.genericusers = dupstr(bufp);
870.     return TRUE;
871. }
872. 
873. staticfn boolean
874. cnf_line_BONES_POOLS(char *bufp)
875. {
876.     /* max value of 10 guarantees (N % bones.pools) will be one digit
877.        so we don't lose control of the length of bones file names */
878.     int n = atoi(bufp);
879. 
880.     sysopt.bones_pools = (n <= 0) ? 0 : min(n, 10);
881.     /* note: right now bones_pools==0 is the same as bones_pools==1,
882.        but we could change that and make bones_pools==0 become an
883.        indicator to suppress bones usage altogether */
884.     return TRUE;
885. }
886. 
887. staticfn boolean
888. cnf_line_SUPPORT(char *bufp)
889. {
890.     if (sysopt.support)
891.         free((genericptr_t) sysopt.support);
892.     sysopt.support = dupstr(bufp);
893.     return TRUE;
894. }
895. 
896. staticfn boolean
897. cnf_line_RECOVER(char *bufp)
898. {
899.     if (sysopt.recover)
900.         free((genericptr_t) sysopt.recover);
901.     sysopt.recover = dupstr(bufp);
902.     return TRUE;
903. }
904. 
905. staticfn boolean
906. cnf_line_CHECK_SAVE_UID(char *bufp)
907. {
908.     int n = atoi(bufp);
909. 
910.     sysopt.check_save_uid = n;
911.     return TRUE;
912. }
913. 
914. staticfn boolean
915. cnf_line_CHECK_PLNAME(char *bufp)
916. {
917.     int n = atoi(bufp);
918. 
919.     sysopt.check_plname = n;
920.     return TRUE;
921. }
922. 
923. staticfn boolean
924. cnf_line_SEDUCE(char *bufp)
925. {
926.     int n = !!atoi(bufp); /* XXX this could be tighter */
927. #ifdef SYSCF
928.     int src = iflags.parse_config_file_src;
929.     boolean in_sysconf = (src == set_in_sysconf);
930. #else
931.     boolean in_sysconf = FALSE;
932. #endif
933. 
934.     /* allow anyone to disable it but can only enable it in sysconf
935.        or as a no-op for the user when sysconf hasn't disabled it */
936.     if (!in_sysconf && !sysopt.seduce && n != 0) {
937.         config_error_add("Illegal value in SEDUCE");
938.         n = 0;
939.     }
940.     sysopt.seduce = n;
941.     sysopt_seduce_set(sysopt.seduce);
942.     return TRUE;
943. }
944. 
945. staticfn boolean
946. cnf_line_HIDEUSAGE(char *bufp)
947. {
948.     int n = !!atoi(bufp);
949. 
950.     sysopt.hideusage = n;
951.     return TRUE;
952. }
953. 
954. staticfn boolean
955. cnf_line_MAXPLAYERS(char *bufp)
956. {
957.     int n = atoi(bufp);
958. 
959.     /* XXX to get more than 25, need to rewrite all lock code */
960.     if (n < 0 || n > 25) {
961.         config_error_add("Illegal value in MAXPLAYERS (maximum is 25)");
962.         n = 5;
963.     }
964.     sysopt.maxplayers = n;
965.     return TRUE;
966. }
967. 
968. staticfn boolean
969. cnf_line_PERSMAX(char *bufp)
970. {
971.     int n = atoi(bufp);
972. 
973.     if (n < 1) {
974.         config_error_add("Illegal value in PERSMAX (minimum is 1)");
975.         n = 0;
976.     }
977.     sysopt.persmax = n;
978.     return TRUE;
979. }
980. 
981. staticfn boolean
982. cnf_line_PERS_IS_UID(char *bufp)
983. {
984.     int n = atoi(bufp);
985. 
986.     if (n != 0 && n != 1) {
987.         config_error_add("Illegal value in PERS_IS_UID (must be 0 or 1)");
988.         n = 0;
989.     }
990.     sysopt.pers_is_uid = n;
991.     return TRUE;
992. }
993. 
994. staticfn boolean
995. cnf_line_ENTRYMAX(char *bufp)
996. {
997.     int n = atoi(bufp);
998. 
999.     if (n < 10) {
1000.         config_error_add("Illegal value in ENTRYMAX (minimum is 10)");
1001.         n = 10;
1002.     }
1003.     sysopt.entrymax = n;
1004.     return TRUE;
1005. }
1006. 
1007. staticfn boolean
1008. cnf_line_POINTSMIN(char *bufp)
1009. {
1010.     int n = atoi(bufp);
1011. 
1012.     if (n < 1) {
1013.         config_error_add("Illegal value in POINTSMIN (minimum is 1)");
1014.         n = 100;
1015.     }
1016.     sysopt.pointsmin = n;
1017.     return TRUE;
1018. }
1019. 
1020. staticfn boolean
1021. cnf_line_MAX_STATUENAME_RANK(char *bufp)
1022. {
1023.     int n = atoi(bufp);
1024. 
1025.     if (n < 1) {
1026.         config_error_add("Illegal value in MAX_STATUENAME_RANK"
1027.                          " (minimum is 1)");
1028.         n = 10;
1029.     }
1030.     sysopt.tt_oname_maxrank = n;
1031.     return TRUE;
1032. }
1033. 
1034. staticfn boolean
1035. cnf_line_LIVELOG(char *bufp)
1036. {
1037.     /* using 0 for base accepts "dddd" as decimal provided that first 'd'
1038.        isn't '0', "0xhhhh" as hexadecimal, and "0oooo" as octal; ignores
1039.        any trailing junk, including '8' or '9' for leading '0' octal */
1040.     long L = strtol(bufp, NULL, 0);
1041. 
1042.     if (L < 0L || L > 0xffffL) {
1043.         config_error_add("Illegal value for LIVELOG"
1044.                          " (must be between 0 and 0xFFFF).");
1045.         return 0;
1046.     }
1047.     sysopt.livelog = L;
1048.     return TRUE;
1049. }
1050. 
1051. staticfn boolean
1052. cnf_line_PANICTRACE_LIBC(char *bufp)
1053. {
1054.     int n = atoi(bufp);
1055. 
1056. #if defined(PANICTRACE) && defined(PANICTRACE_LIBC)
1057.     if (n < 0 || n > 2) {
1058.         config_error_add("Illegal value in PANICTRACE_LIBC (not 0,1,2)");
1059.         n = 0;
1060.     }
1061. #endif
1062.     sysopt.panictrace_libc = n;
1063.     return TRUE;
1064. }
1065. 
1066. staticfn boolean
1067. cnf_line_PANICTRACE_GDB(char *bufp)
1068. {
1069.     int n = atoi(bufp);
1070. 
1071. #if defined(PANICTRACE)
1072.     if (n < 0 || n > 2) {
1073.         config_error_add("Illegal value in PANICTRACE_GDB (not 0,1,2)");
1074.         n = 0;
1075.     }
1076. #endif
1077.     sysopt.panictrace_gdb = n;
1078.     return TRUE;
1079. }
1080. 
1081. staticfn boolean
1082. cnf_line_GDBPATH(char *bufp)
1083. {
1084. #if defined(PANICTRACE) && !defined(VMS)
1085.     if (!file_exists(bufp)) {
1086.         config_error_add("File specified in GDBPATH does not exist");
1087.         return FALSE;
1088.     }
1089. #endif
1090.     if (sysopt.gdbpath)
1091.         free((genericptr_t) sysopt.gdbpath);
1092.     sysopt.gdbpath = dupstr(bufp);
1093.     return TRUE;
1094. }
1095. 
1096. staticfn boolean
1097. cnf_line_GREPPATH(char *bufp)
1098. {
1099. #if defined(PANICTRACE) && !defined(VMS)
1100.     if (!file_exists(bufp)) {
1101.         config_error_add("File specified in GREPPATH does not exist");
1102.         return FALSE;
1103.     }
1104. #endif
1105.     if (sysopt.greppath)
1106.         free((genericptr_t) sysopt.greppath);
1107.     sysopt.greppath = dupstr(bufp);
1108.     return TRUE;
1109. }
1110. 
1111. staticfn boolean
1112. cnf_line_CRASHREPORTURL(char *bufp)
1113. {
1114.     if (sysopt.crashreporturl)
1115.         free((genericptr_t) sysopt.crashreporturl);
1116.     sysopt.crashreporturl = dupstr(bufp);
1117.     return TRUE;
1118. }
1119. 
1120. staticfn boolean
1121. cnf_line_ACCESSIBILITY(char *bufp)
1122. {
1123.     int n = atoi(bufp);
1124. 
1125.     if (n < 0 || n > 1) {
1126.         config_error_add("Illegal value in ACCESSIBILITY (not 0,1)");
1127.         n = 0;
1128.     }
1129.     sysopt.accessibility = n;
1130.     return TRUE;
1131. }
1132. 
1133. staticfn boolean
1134. cnf_line_PORTABLE_DEVICE_PATHS(char *bufp)
1135. {
1136. #ifdef WIN32
1137.     int n = atoi(bufp);
1138. 
1139.     if (n < 0 || n > 1) {
1140.         config_error_add("Illegal value in PORTABLE_DEVICE_PATHS"
1141.                          " (not 0 or 1)");
1142.         n = 0;
1143.     }
1144.     sysopt.portable_device_paths = n;
1145. #else   /* Windows-only directive encountered by non-Windows config */
1146.     nhUse(bufp);
1147.     config_error_add("PORTABLE_DEVICE_PATHS is not supported");
1148. #endif
1149.     return TRUE;
1150. }
1151. #endif  /* SYSCF */
1152. 
1153. #ifndef SFCTOOL
1154. 
1155. staticfn boolean
1156. cnf_line_BOULDER(char *bufp)
1157. {
1158.     (void) get_uchars(bufp, &go.ov_primary_syms[SYM_BOULDER + SYM_OFF_X],
1159.                       TRUE, 1, "BOULDER");
1160.     return TRUE;
1161. }
1162. 
1163. staticfn boolean
1164. cnf_line_MENUCOLOR(char *bufp)
1165. {
1166.     return add_menu_coloring(bufp);
1167. }
1168. 
1169. staticfn boolean
1170. cnf_line_HILITE_STATUS(char *bufp)
1171. {
1172. #ifdef STATUS_HILITES
1173.     return parse_status_hl1(bufp, TRUE);
1174. #else
1175.     nhUse(bufp);
1176.     return TRUE;
1177. #endif
1178. }
1179. 
1180. staticfn boolean
1181. cnf_line_WARNINGS(char *bufp)
1182. {
1183.     uchar translate[MAXPCHARS];
1184. 
1185.     (void) get_uchars(bufp, translate, FALSE, WARNCOUNT, "WARNINGS");
1186.     assign_warnings(translate);
1187.     return TRUE;
1188. }
1189. 
1190. staticfn boolean
1191. cnf_line_ROGUESYMBOLS(char *bufp)
1192. {
1193.     if (parsesymbols(bufp, ROGUESET)) {
1194.         switch_symbols(TRUE);
1195.         return TRUE;
1196.     }
1197.     config_error_add("Error in ROGUESYMBOLS definition '%s'", bufp);
1198.     return FALSE;
1199. }
1200. 
1201. staticfn boolean
1202. cnf_line_SYMBOLS(char *bufp)
1203. {
1204.     if (parsesymbols(bufp, PRIMARYSET)) {
1205.         switch_symbols(TRUE);
1206.         return TRUE;
1207.     }
1208.     if (!config_unmatched_ignored())
1209.         config_error_add("Error in SYMBOLS definition '%s'", bufp);
1210.     return FALSE;
1211. }
1212. 
1213. staticfn boolean
1214. cnf_line_WIZKIT(char *bufp)
1215. {
1216.     (void) strncpy(gw.wizkit, bufp, WIZKIT_MAX - 1);
1217.     return TRUE;
1218. }
1219. 
1220. #ifdef USER_SOUNDS
1221. staticfn boolean
1222. cnf_line_SOUNDDIR(char *bufp)
1223. {
1224.     if (sounddir)
1225.         free((genericptr_t) sounddir);
1226.     sounddir = dupstr(bufp);
1227.     return TRUE;
1228. }
1229. 
1230. staticfn boolean
1231. cnf_line_SOUND(char *bufp)
1232. {
1233.     add_sound_mapping(bufp);
1234.     return TRUE;
1235. }
1236. #endif /*USER_SOUNDS*/
1237. 
1238. staticfn boolean
1239. cnf_line_QT_TILEWIDTH(char *bufp)
1240. {
1241. #ifdef QT_GRAPHICS
1242.     extern char *qt_tilewidth;
1243. 
1244.     if (qt_tilewidth == NULL)
1245.         qt_tilewidth = dupstr(bufp);
1246. #else
1247.     nhUse(bufp);
1248. #endif
1249.     return TRUE;
1250. }
1251. 
1252. staticfn boolean
1253. cnf_line_QT_TILEHEIGHT(char *bufp)
1254. {
1255. #ifdef QT_GRAPHICS
1256.     extern char *qt_tileheight;
1257. 
1258.     if (qt_tileheight == NULL)
1259.         qt_tileheight = dupstr(bufp);
1260. #else
1261.     nhUse(bufp);
1262. #endif
1263.     return TRUE;
1264. }
1265. 
1266. staticfn boolean
1267. cnf_line_QT_FONTSIZE(char *bufp)
1268. {
1269. #ifdef QT_GRAPHICS
1270.     extern char *qt_fontsize;
1271. 
1272.     if (qt_fontsize == NULL)
1273.         qt_fontsize = dupstr(bufp);
1274. #else
1275.     nhUse(bufp);
1276. #endif
1277.     return TRUE;
1278. }
1279. 
1280. staticfn boolean
1281. cnf_line_QT_COMPACT(char *bufp)
1282. {
1283. #ifdef QT_GRAPHICS
1284.     extern int qt_compact_mode;
1285. 
1286.     qt_compact_mode = atoi(bufp);
1287. #else
1288.     nhUse(bufp);
1289. #endif
1290.     return TRUE;
1291. }
1292. #endif /* SFCTOOL */
1293. 
1294. typedef boolean (*config_line_stmt_func)(char *);
1295. 
1296. /* normal */
1297. #define CNFL_N(n, l) { #n, l, FALSE, FALSE, cnf_line_##n }
1298. /* normal, alias */
1299. #define CNFL_NA(n, l, f) { #n, l, FALSE, FALSE, cnf_line_##f }
1300. /* sysconf only */
1301. #define CNFL_S(n, l) { #n, l, TRUE, FALSE, cnf_line_##n }
1302. 
1303. static const struct match_config_line_stmt {
1304.     const char *name;
1305.     int len;
1306.     boolean syscnf_only;
1307.     boolean origbuf;
1308.     config_line_stmt_func fn;
1309. } config_line_stmt[] = {
1310. #ifndef SFCTOOL
1311.     /* OPTIONS handled separately */
1312.     { "OPTIONS", 4, FALSE, TRUE, cnf_line_OPTIONS },
1313.     CNFL_N(AUTOPICKUP_EXCEPTION, 5),
1314.     CNFL_N(BINDINGS, 4),
1315.     CNFL_N(AUTOCOMPLETE, 5),
1316.     CNFL_N(MSGTYPE, 7),
1317.     CNFL_N(HACKDIR, 4),
1318.     CNFL_N(LEVELDIR, 4),
1319.     CNFL_NA(LEVELS, 4, LEVELDIR),
1320.     CNFL_N(SAVEDIR, 4),
1321.     CNFL_N(BONESDIR, 5),
1322.     CNFL_N(DATADIR, 4),
1323.     CNFL_N(SCOREDIR, 4),
1324.     CNFL_N(LOCKDIR, 4),
1325.     CNFL_N(CONFIGDIR, 4),
1326.     CNFL_N(TROUBLEDIR, 4),
1327.     CNFL_N(NAME, 4),
1328.     CNFL_N(ROLE, 4),
1329.     CNFL_NA(CHARACTER, 4, ROLE),
1330.     CNFL_N(dogname, 3),
1331.     CNFL_N(catname, 3),
1332. #endif /* SFCTOOL */
1333. #ifdef SYSCF
1334.     CNFL_S(WIZARDS, 7),
1335.     CNFL_S(SHELLERS, 8),
1336.     CNFL_S(MSGHANDLER, 9),
1337.     CNFL_S(EXPLORERS, 7),
1338.     CNFL_S(DEBUGFILES, 5),
1339.     CNFL_S(DUMPLOGFILE, 7),
1340.     CNFL_S(GENERICUSERS, 12),
1341.     CNFL_S(BONES_POOLS, 10),
1342.     CNFL_S(SUPPORT, 7),
1343.     CNFL_S(RECOVER, 7),
1344.     CNFL_S(CHECK_SAVE_UID, 14),
1345.     CNFL_S(CHECK_PLNAME, 12),
1346.     CNFL_S(SEDUCE, 6),
1347.     CNFL_S(HIDEUSAGE, 9),
1348.     CNFL_S(MAXPLAYERS, 10),
1349.     CNFL_S(PERSMAX, 7),
1350.     CNFL_S(PERS_IS_UID, 11),
1351.     CNFL_S(ENTRYMAX, 8),
1352.     CNFL_S(POINTSMIN, 9),
1353.     CNFL_S(MAX_STATUENAME_RANK, 10),
1354.     CNFL_S(LIVELOG, 7),
1355.     CNFL_S(PANICTRACE_LIBC, 15),
1356.     CNFL_S(PANICTRACE_GDB, 14),
1357.     CNFL_S(CRASHREPORTURL, 13),
1358.     CNFL_S(GDBPATH, 7),
1359.     CNFL_S(GREPPATH, 7),
1360.     CNFL_S(ACCESSIBILITY, 13),
1361.     CNFL_S(PORTABLE_DEVICE_PATHS, 8),
1362. #endif /*SYSCF*/
1363. #ifndef SFCTOOL
1364.     CNFL_N(BOULDER, 3),
1365.     CNFL_N(MENUCOLOR, 9),
1366.     CNFL_N(HILITE_STATUS, 6),
1367.     CNFL_N(WARNINGS, 5),
1368.     CNFL_N(ROGUESYMBOLS, 4),
1369.     CNFL_N(SYMBOLS, 4),
1370.     CNFL_N(WIZKIT, 6),
1371. #ifdef USER_SOUNDS
1372.     CNFL_N(SOUNDDIR, 8),
1373.     CNFL_N(SOUND, 5),
1374. #endif /*USER_SOUNDS*/
1375.     CNFL_N(QT_TILEWIDTH, 12),
1376.     CNFL_N(QT_TILEHEIGHT, 13),
1377.     CNFL_N(QT_FONTSIZE, 11),
1378.     CNFL_N(QT_COMPACT, 10)
1379. #endif /* SFCTOOL */
1380. };
1381. 
1382. #undef CNFL_N
1383. #undef CNFL_NA
1384. #undef CNFL_S
1385. 
1386. static boolean disregarded_config_lines[SIZE(config_line_stmt)];
1387. 
1388. boolean
1389. parse_config_line(char *origbuf)
1390. {
1391. #if defined(MICRO) && !defined(NOCWD_ASSUMPTIONS)
1392.     static boolean ramdisk_specified = FALSE;
1393. #endif
1394. #ifdef SYSCF
1395.     int src = iflags.parse_config_file_src;
1396.     boolean in_sysconf = (src == set_in_sysconf);
1397. #endif
1398.     char *bufp, buf[4 * BUFSZ];
1399.     int i;
1400. 
1401.     while (*origbuf == ' ' || *origbuf == '\t') /* skip leading whitespace */
1402.         ++origbuf;                   /* (caller probably already did this) */
1403.     (void) strncpy(buf, origbuf, sizeof buf - 1);
1404.     buf[sizeof buf - 1] = '\0'; /* strncpy not guaranteed to NUL terminate */
1405.     /* convert any tab to space, condense consecutive spaces into one,
1406.        remove leading and trailing spaces (exception: if there is nothing
1407.        but spaces, one of them will be kept even though it leads/trails) */
1408.     mungspaces(buf);
1409. 
1410.     /* find the '=' or ':' */
1411.     bufp = find_optparam(buf);
1412.     if (!bufp) {
1413.         if (!ignore_statement_errors)
1414.             config_error_add("Not a config statement, missing '='");
1415.         return FALSE;
1416.     }
1417.     /* skip past '=', then space between it and value, if any */
1418.     ++bufp;
1419.     if (*bufp == ' ')
1420.         ++bufp;
1421. 
1422.     for (i = 0; i < SIZE(config_line_stmt); i++) {
1423. #ifdef SYSCF
1424.         if (config_line_stmt[i].syscnf_only && !in_sysconf)
1425.             continue;
1426. #endif
1427.         if (match_varname(buf, config_line_stmt[i].name,
1428.                           config_line_stmt[i].len)) {
1429.             char *parm = config_line_stmt[i].origbuf ? origbuf : bufp;
1430. 
1431.             if (!disregarded_config_lines[i])
1432.                 return config_line_stmt[i].fn(parm);
1433.         }
1434.     }
1435. 
1436.     if (!ignore_errors_on_unmatched)
1437.         config_error_add("Unknown config statement");
1438.     return FALSE;
1439. }
1440. 
1441. #ifdef USER_SOUNDS
1442. boolean
1443. can_read_file(const char *filename)
1444. {
1445.     return (boolean) (access(filename, 4) == 0);
1446. }
1447. #endif /* USER_SOUNDS */
1448. 
1449. struct _config_error_errmsg {
1450.     int line_num;
1451.     char *errormsg;
1452.     struct _config_error_errmsg *next;
1453. };
1454. 
1455. struct _config_error_frame {
1456.     int line_num;
1457.     int num_errors;
1458.     boolean origline_shown;
1459.     boolean fromfile;
1460.     boolean secure;
1461.     char origline[4 * BUFSZ];
1462.     char source[BUFSZ];
1463.     struct _config_error_frame *next;
1464. };
1465. 
1466. static struct _config_error_frame *config_error_data = 0;
1467. static struct _config_error_errmsg *config_error_msg = 0;
1468. 
1469. void
1470. config_error_init(boolean from_file, const char *sourcename, boolean secure)
1471. {
1472.     struct _config_error_frame *tmp = (struct _config_error_frame *)
1473.                                                            alloc(sizeof *tmp);
1474. 
1475.     tmp->line_num = 0;
1476.     tmp->num_errors = 0;
1477.     tmp->origline_shown = FALSE;
1478.     tmp->fromfile = from_file;
1479.     tmp->secure = secure;
1480.     tmp->origline[0] = '\0';
1481.     if (sourcename && sourcename[0]) {
1482.         (void) strncpy(tmp->source, sourcename, sizeof (tmp->source) - 1);
1483.         tmp->source[sizeof (tmp->source) - 1] = '\0';
1484.     } else
1485.         tmp->source[0] = '\0';
1486. 
1487.     tmp->next = config_error_data;
1488.     config_error_data = tmp;
1489.     program_state.config_error_ready = TRUE;
1490. }
1491. 
1492. staticfn boolean
1493. config_error_nextline(const char *line)
1494. {
1495.     struct _config_error_frame *ced = config_error_data;
1496. 
1497.     if (!ced)
1498.         return FALSE;
1499. 
1500.     if (ced->num_errors && ced->secure)
1501.         return FALSE;
1502. 
1503.     ced->line_num++;
1504.     ced->origline_shown = FALSE;
1505.     if (line && line[0]) {
1506.         (void) strncpy(ced->origline, line, sizeof (ced->origline) - 1);
1507.         ced->origline[sizeof (ced->origline) - 1] = '\0';
1508.     } else
1509.         ced->origline[0] = '\0';
1510. 
1511.     return TRUE;
1512. }
1513. 
1514. #ifndef SFCTOOL
1515. int
1516. l_get_config_errors(lua_State *L)
1517. {
1518.     struct _config_error_errmsg *dat = config_error_msg;
1519.     struct _config_error_errmsg *tmp;
1520.     int idx = 1;
1521. 
1522.     lua_newtable(L);
1523. 
1524.     while (dat) {
1525.         lua_pushinteger(L, idx++);
1526.         lua_newtable(L);
1527.         nhl_add_table_entry_int(L, "line", dat->line_num);
1528.         nhl_add_table_entry_str(L, "error", dat->errormsg);
1529.         lua_settable(L, -3);
1530.         tmp = dat->next;
1531.         free(dat->errormsg);
1532.         dat->errormsg = (char *) 0;
1533.         free(dat);
1534.         dat = tmp;
1535.     }
1536.     config_error_msg = (struct _config_error_errmsg *) 0;
1537. 
1538.     return 1;
1539. }
1540. #endif /* SFCTOOL */
1541. 
1542. /* varargs 'config_error_add()' moved to pline.c */
1543. void
1544. config_erradd(const char *buf)
1545. {
1546.     char lineno[QBUFSZ];
1547.     const char *punct;
1548. 
1549.     if (!buf || !*buf)
1550.         buf = "Unknown error";
1551. 
1552.     /* if buf[] doesn't end in a period, exclamation point, or question mark,
1553.        we'll include a period (in the message, not appended to buf[]) */
1554.     punct = c_eos((char *) buf) - 1; /* eos(buf)-1 is valid */
1555.     punct = strchr(".!?", *punct) ? "" : ".";
1556. 
1557.     if (!program_state.config_error_ready) {
1558.         /* either very early, where pline() will use raw_print(), or
1559.            player gave bad value when prompted by interactive 'O' command */
1560.         pline("%s%s%s", !iflags.window_inited ? "config_error_add: " : "",
1561.               buf, punct);
1562.         wait_synch();
1563.         return;
1564.     }
1565. 
1566.     if (iflags.in_lua) {
1567.         struct _config_error_errmsg *dat
1568.                          = (struct _config_error_errmsg *) alloc(sizeof *dat);
1569. 
1570.         dat->next = config_error_msg;
1571.         dat->line_num = config_error_data->line_num;
1572.         dat->errormsg = dupstr(buf);
1573.         config_error_msg = dat;
1574.         return;
1575.     }
1576. 
1577.     config_error_data->num_errors++;
1578.     if (!config_error_data->origline_shown && !config_error_data->secure) {
1579.         pline("\n%s", config_error_data->origline);
1580.         config_error_data->origline_shown = TRUE;
1581.     }
1582.     if (config_error_data->line_num > 0 && !config_error_data->secure) {
1583.         Sprintf(lineno, "Line %d: ", config_error_data->line_num);
1584.     } else
1585.         lineno[0] = '\0';
1586. 
1587.     pline("%s %s%s%s", config_error_data->secure ? "Error:" : " *",
1588.           lineno, buf, punct);
1589. }
1590. 
1591. int
1592. config_error_done(void)
1593. {
1594.     int n;
1595.     struct _config_error_frame *tmp = config_error_data;
1596. 
1597.     if (!config_error_data)
1598.         return 0;
1599.     n = config_error_data->num_errors;
1600. #ifndef USER_SOUNDS
1601.     if (gn.no_sound_notified > 0) {
1602.         /* no USER_SOUNDS; config_error_add() was called once for first
1603.            SOUND or SOUNDDIR entry seen, then skipped for any others;
1604.            include those skipped ones in the total error count */
1605.         n += (gn.no_sound_notified - 1);
1606.         gn.no_sound_notified = 0;
1607.     }
1608. #endif
1609.     if (n) {
1610.         boolean cmdline = !strcmp(config_error_data->source, "command line");
1611. 
1612.         pline("\n%d error%s %s %s.\n", n, plur(n), cmdline ? "on" : "in",
1613.               *config_error_data->source ? config_error_data->source
1614.                                          : configfile);
1615.         wait_synch();
1616.     }
1617.     config_error_data = tmp->next;
1618.     free(tmp);
1619.     program_state.config_error_ready = (config_error_data != 0);
1620.     return n;
1621. }
1622. 
1623. boolean
1624. read_config_file(const char *filename, int src)
1625. {
1626.     FILE *fp;
1627.     boolean rv = TRUE;
1628. 
1629.     if (!(fp = fopen_config_file(filename, src)))
1630.         return FALSE;
1631. #ifndef SFCTOOL
1632.     /* begin detection of duplicate configfile options */
1633.     reset_duplicate_opt_detection();
1634. #endif /* SFCTOOL */
1635.     free_config_sections();
1636.     iflags.parse_config_file_src = src;
1637. 
1638.     rv = parse_conf_file(fp, parse_config_line);
1639.     (void) fclose(fp);
1640. 
1641.     free_config_sections();
1642. #ifndef SFCTOOL
1643.     /* turn off detection of duplicate configfile options */
1644.     reset_duplicate_opt_detection();
1645. #endif /* SFCTOOL */
1646.     return rv;
1647. }
1648. 
1649. struct _cnf_parser_state {
1650.     char *inbuf;
1651.     unsigned inbufsz;
1652.     int rv;
1653.     char *ep;
1654.     char *buf;
1655.     boolean skip, morelines;
1656.     boolean cont;
1657.     boolean pbreak;
1658. };
1659. 
1660. /* Initialize config parser data */
1661. staticfn void
1662. cnf_parser_init(struct _cnf_parser_state *parser)
1663. {
1664.     parser->rv = TRUE; /* assume successful parse */
1665.     parser->ep = parser->buf = (char *) 0;
1666.     parser->skip = FALSE;
1667.     parser->morelines = FALSE;
1668.     parser->inbufsz = 4 * BUFSZ;
1669.     parser->inbuf = (char *) alloc(parser->inbufsz);
1670.     parser->cont = FALSE;
1671.     parser->pbreak = FALSE;
1672.     memset(parser->inbuf, 0, parser->inbufsz);
1673. }
1674. 
1675. /* caller has finished with 'parser' (except for 'rv' so leave that intact) */
1676. staticfn void
1677. cnf_parser_done(struct _cnf_parser_state *parser)
1678. {
1679.     parser->ep = 0; /* points into parser->inbuf, so becoming stale */
1680.     if (parser->inbuf)
1681.         free(parser->inbuf), parser->inbuf = 0;
1682.     if (parser->buf)
1683.         free(parser->buf), parser->buf = 0;
1684. }
1685. 
1686. /*
1687.  * Parse config buffer, handling comments, empty lines, config sections,
1688.  * CHOOSE, and line continuation, calling proc for every valid line.
1689.  *
1690.  * Continued lines are merged together with one space in between.
1691.  */
1692. staticfn void
1693. parse_conf_buf(struct _cnf_parser_state *p, boolean (*proc)(char *arg))
1694. {
1695.     p->cont = FALSE;
1696.     p->pbreak = FALSE;
1697.     p->ep = strchr(p->inbuf, '\n');
1698.     if (p->skip) { /* in case previous line was too long */
1699.         if (p->ep)
1700.             p->skip = FALSE; /* found newline; next line is normal */
1701.     } else {
1702.         if (!p->ep) {  /* newline missing */
1703.             if (strlen(p->inbuf) < (p->inbufsz - 2)) {
1704.                 /* likely the last line of file is just
1705.                    missing a newline; process it anyway  */
1706.                 p->ep = eos(p->inbuf);
1707.             } else {
1708.                 config_error_add("Line too long, skipping");
1709.                 p->skip = TRUE; /* discard next fgets */
1710.             }
1711.         } else {
1712.             *p->ep = '\0'; /* remove newline */
1713.         }
1714.         if (p->ep) {
1715.             char *tmpbuf = (char *) 0;
1716.             int len;
1717.             boolean ignoreline = FALSE;
1718.             boolean oldline = FALSE;
1719. 
1720.             /* line continuation (trailing '\') */
1721.             p->morelines = (--p->ep >= p->inbuf && *p->ep == '\\');
1722.             if (p->morelines)
1723.                 *p->ep = '\0';
1724. 
1725.             /* trim off spaces at end of line */
1726.             while (p->ep >= p->inbuf
1727.                    && (*p->ep == ' ' || *p->ep == '\t' || *p->ep == '\r'))
1728.                 *p->ep-- = '\0';
1729. 
1730.             if (!config_error_nextline(p->inbuf)) {
1731.                 p->rv = FALSE;
1732.                 if (p->buf)
1733.                     free(p->buf), p->buf = (char *) 0;
1734.                 p->pbreak = TRUE;
1735.                 return;
1736.             }
1737. 
1738.             p->ep = p->inbuf;
1739.             while (*p->ep == ' ' || *p->ep == '\t')
1740.                 ++p->ep;
1741. 
1742.             /* ignore empty lines and full-line comment lines */
1743.             if (!*p->ep || *p->ep == '#')
1744.                 ignoreline = TRUE;
1745. 
1746.             if (p->buf)
1747.                 oldline = TRUE;
1748. 
1749.             /* merge now read line with previous ones, if necessary */
1750.             if (!ignoreline) {
1751.                 len = (int) strlen(p->ep) + 1; /* +1: final '\0' */
1752.                 if (p->buf)
1753.                     len += (int) strlen(p->buf) + 1; /* +1: space */
1754.                 tmpbuf = (char *) alloc(len);
1755.                 *tmpbuf = '\0';
1756.                 if (p->buf) {
1757.                     Strcat(strcpy(tmpbuf, p->buf), " ");
1758.                     free(p->buf), p->buf = 0;
1759.                 }
1760.                 p->buf = strcat(tmpbuf, p->ep);
1761.                 if (strlen(p->buf) >= p->inbufsz)
1762.                     p->buf[p->inbufsz - 1] = '\0';
1763.             }
1764. 
1765.             if (p->morelines || (ignoreline && !oldline))
1766.                 return;
1767. 
1768.             if (handle_config_section(p->buf)) {
1769.                 free(p->buf), p->buf = (char *) 0;
1770.                 return;
1771.             }
1772. 
1773.             /* from here onwards, we'll handle buf only */
1774. 
1775.             if (match_varname(p->buf, "CHOOSE", 6)) {
1776.                 char *section;
1777.                 char *bufp = find_optparam(p->buf);
1778. 
1779.                 if (!bufp) {
1780.                     config_error_add("Format is CHOOSE=section1"
1781.                                      ",section2,...");
1782.                     p->rv = FALSE;
1783.                     free(p->buf), p->buf = (char *) 0;
1784.                     return;
1785.                 }
1786.                 bufp++;
1787.                 if (gc.config_section_chosen)
1788.                     free(gc.config_section_chosen),
1789.                         gc.config_section_chosen = 0;
1790.                 section = choose_random_part(bufp, ',');
1791.                 if (section) {
1792.                     gc.config_section_chosen = dupstr(section);
1793.                 } else {
1794.                     config_error_add("No config section to choose");
1795.                     p->rv = FALSE;
1796.                 }
1797.                 free(p->buf), p->buf = (char *) 0;
1798.                 return;
1799.             }
1800. 
1801.             if (!(*proc)(p->buf))
1802.                 p->rv = FALSE;
1803. 
1804.             free(p->buf), p->buf = (char *) 0;
1805.         }
1806.     }
1807. }
1808. 
1809. boolean
1810. parse_conf_str(const char *str, boolean (*proc)(char *arg))
1811. {
1812.     size_t len;
1813.     struct _cnf_parser_state parser;
1814. 
1815.     cnf_parser_init(&parser);
1816.     free_config_sections();
1817.     config_error_init(FALSE, "parse_conf_str", FALSE);
1818.     while (str && *str) {
1819.         len = 0;
1820.         while (*str && len < (parser.inbufsz-1)) {
1821.             parser.inbuf[len] = *str;
1822.             len++;
1823.             str++;
1824.             if (parser.inbuf[len-1] == '\n')
1825.                 break;
1826.         }
1827.         parser.inbuf[len] = '\0';
1828.         parse_conf_buf(&parser, proc);
1829.         if (parser.pbreak)
1830.             break;
1831.     }
1832.     cnf_parser_done(&parser);
1833. 
1834.     free_config_sections();
1835.     config_error_done();
1836.     return parser.rv;
1837. }
1838. 
1839. /* parse_conf_file
1840.  *
1841.  * Read from file fp, calling parse_conf_buf for each line.
1842.  */
1843. boolean
1844. parse_conf_file(FILE *fp, boolean (*proc)(char *arg))
1845. {
1846.     struct _cnf_parser_state parser;
1847. 
1848.     cnf_parser_init(&parser);
1849.     free_config_sections();
1850. 
1851.     while (fgets(parser.inbuf, parser.inbufsz, fp)) {
1852.         parse_conf_buf(&parser, proc);
1853.         if (parser.pbreak)
1854.             break;
1855.     }
1856.     cnf_parser_done(&parser);
1857. 
1858.     free_config_sections();
1859.     return parser.rv;
1860. }
1861. 
1862. DISABLE_WARNING_FORMAT_NONLITERAL
1863. 
1864. void
1865. config_error_add(const char *str, ...)
1866. {
1867.     va_list the_args;
1868. 
1869.     va_start(the_args, str);
1870.     vconfig_error_add(str, the_args);
1871.     va_end(the_args);
1872. }
1873. 
1874. staticfn void
1875. vconfig_error_add(const char *str, va_list the_args)
1876. { /* start of vconf...() or of nested block in USE_OLDARG's conf...() */
1877.     int vlen = 0;
1878.     char buf[BIGBUFSZ]; /* will be chopped down to BUFSZ-1 if longer */
1879. 
1880.     vlen = vsnprintf(buf, sizeof buf, str, the_args);
1881. #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED) && defined(DEBUG)
1882.     if (vlen >= (int) sizeof buf)
1883.         panic("%s: truncation of buffer at %zu of %d bytes",
1884.               "config_error_add", sizeof buf, vlen);
1885. #else
1886.     nhUse(vlen);
1887. #endif
1888.     buf[BUFSZ - 1] = '\0';
1889.     config_erradd(buf);
1890. }
1891. 
1892. #ifndef SFCTOOL
1893. void
1894. rcfile(void)
1895. {
1896.     char *opts = 0, *xtraopts = 0;
1897.     const char *envname, *namesrc, *nameval;
1898. 
1899.     go.opt_phase = environ_opt;
1900.     /* getenv() instead of nhgetenv(): let total length of options be long;
1901.        parseoptions() will check each individually */
1902.     envname = "NETHACKOPTIONS";
1903.     opts = getenv(envname);
1904.     if (!opts) {
1905.         /* fall back to original name; discouraged */
1906.         envname = "HACKOPTIONS";
1907.         opts = getenv(envname);
1908.     }
1909. 
1910.     if (gc.cmdline_rcfile) {
1911.         namesrc = "command line";
1912.         nameval = gc.cmdline_rcfile;
1913.         xtraopts = opts;
1914.         if (opts && (*opts == '/' || *opts == '\\' || *opts == '@'))
1915.             xtraopts = 0; /* NETHACKOPTIONS is a file name; ignore it */
1916.     } else if (opts && (*opts == '/' || *opts == '\\' || *opts == '@')) {
1917.         /* NETHACKOPTIONS is a file name; use that instead of the default */
1918.         if (*opts == '@')
1919.             ++opts; /* @filename */
1920.         namesrc = envname;
1921.         nameval = opts;
1922.         xtraopts = 0;
1923.     } else {
1924.         /* either no NETHACKOPTIONS or it wasn't a file name;
1925.            read the default configuration file */
1926.         nameval = namesrc = 0;
1927.         xtraopts = opts;
1928.     }
1929. 
1930.     go.opt_phase = rc_file_opt;
1931.     /* seemingly arbitrary name length restriction is to prevent error
1932.        messages, if any were to be delivered while accessing the file,
1933.        from potentially overflowing buffers */
1934.     if (nameval && (int) strlen(nameval) >= BUFSZ / 2) {
1935.         config_error_init(TRUE, namesrc, FALSE);
1936.         config_error_add(
1937.             "nethackrc file name \"%.40s\"... too long; using default",
1938.             nameval);
1939.         config_error_done();
1940.         nameval = namesrc = 0; /* revert to default nethackrc */
1941.     }
1942. 
1943.     config_error_init(TRUE, nameval, nameval ? CONFIG_ERROR_SECURE : FALSE);
1944.     (void) read_config_file(nameval, set_in_config);
1945.     config_error_done();
1946.     if (xtraopts) {
1947.         /* NETHACKOPTIONS is present and not a file name */
1948.         go.opt_phase = environ_opt;
1949.         config_error_init(FALSE, envname, FALSE);
1950.         (void) parseoptions(xtraopts, TRUE, FALSE);
1951.         config_error_done();
1952.     }
1953. 
1954.     if (gc.cmdline_rcfile)
1955.         free((genericptr_t) gc.cmdline_rcfile), gc.cmdline_rcfile = 0;
1956.     /*[end of nethackrc handling]*/
1957. }
1958. 
1959. void
1960. rcfile_interface_options(void)
1961. {
1962.     allopt_array_init();
1963.     disregard_all_options();
1964.     disregard_all_config_statements();
1965.     heed_this_option(opt_windowtype);
1966.     heed_this_option(opt_soundlib);
1967.     set_ignore_errors_on_unmatched();
1968.     ignore_statement_errors = TRUE;
1969.     rcfile();
1970.     heed_all_config_statements();
1971.     heed_all_options();
1972.     disregard_this_option(opt_windowtype);
1973.     disregard_this_option(opt_soundlib);
1974.     clear_ignore_errors_on_unmatched();
1975.     ignore_statement_errors = FALSE;
1976. }
1977. 
1978. void
1979. heed_all_config_statements(void)
1980. {
1981.     int i;
1982. 
1983.     for (i = 0; i < SIZE(disregarded_config_lines); i++) {
1984.         disregarded_config_lines[i] = FALSE;
1985.     }
1986. }
1987. void
1988. disregard_all_config_statements(void)
1989. {
1990.     int i;
1991. 
1992.     for (i = 0; i < SIZE(disregarded_config_lines); i++) {
1993.         disregarded_config_lines[i] = TRUE;
1994.     }
1995. }
1996. void
1997. heed_this_config_statement(int statement_idx)
1998. {
1999.     if (statement_idx >= 0 && statement_idx < SIZE(disregarded_config_lines))
2000.         disregarded_config_lines[statement_idx] = FALSE;
2001. }
2002. void
2003. disregard_this_config_statement(int statement_idx)
2004. {
2005.     if (statement_idx >= 0 && statement_idx < SIZE(disregarded_config_lines))
2006.         disregarded_config_lines[statement_idx] = TRUE;
2007. }
2008. 
2009. void
2010. clear_ignore_errors_on_unmatched(void)
2011. {
2012.     ignore_errors_on_unmatched = FALSE;
2013. }
2014. void
2015. set_ignore_errors_on_unmatched(void)
2016. {
2017.     ignore_errors_on_unmatched = TRUE;
2018. }
2019. boolean
2020. config_unmatched_ignored(void)
2021. {
2022.     if (ignore_errors_on_unmatched)
2023.         return TRUE;
2024.     return FALSE;
2025. }
2026. #endif /* SFCTOOL */
2027. 
2028. #ifdef SYSCF
2029. #ifdef SYSCF_FILE
2030. void
2031. assure_syscf_file(void)
2032. {
2033.     int fd;
2034. 
2035. #ifdef WIN32
2036.     /* We are checking that the sysconf exists ... lock the path */
2037.     fqn_prefix_locked[SYSCONFPREFIX] = TRUE;
2038. #endif
2039.     /*
2040.      * All we really care about is the end result - can we read the file?
2041.      * So just check that directly.
2042.      *
2043.      * Not tested on most of the old platforms (which don't attempt
2044.      * to implement SYSCF).
2045.      * Some ports don't like open()'s optional third argument;
2046.      * VMS overrides open() usage with a macro which requires it.
2047.      */
2048. #ifndef VMS
2049. #if defined(NOCWD_ASSUMPTIONS) && defined(WIN32)
2050.     fd = open(fqname(SYSCF_FILE, SYSCONFPREFIX, 0), O_RDONLY);
2051. #else
2052.     fd = open(SYSCF_FILE, O_RDONLY);
2053. #endif
2054. #else   /* VMS */
2055.     fd = open(SYSCF_FILE, O_RDONLY, 0);
2056. #endif  /* VMS */
2057.     if (fd >= 0) {
2058.         /* readable */
2059.         close(fd);
2060.         return;
2061.     }
2062. #ifndef SFCTOOL
2063.     if (gd.deferred_showpaths)
2064.         do_deferred_showpaths(1); /* does not return */
2065. #endif
2066.     raw_printf("Unable to open SYSCF_FILE.\n");
2067.     exit(EXIT_FAILURE);
2068. }
2069. 
2070. #endif /* SYSCF_FILE */
2071. #endif /* SYSCF */
2072. 
2073. /* ----------  END CONFIG FILE HANDLING ----------- */
2074. 
2075. /*cfgfiles.c*/
2076.