Source:NetHack 5.0.0/src/sys.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to sys.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/sys.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	sys.c	$NHDT-Date: 1717449153 2024/06/03 21:12:33 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.64 $ */
2. /* Copyright (c) Kenneth Lorber, Kensington, Maryland, 2008. */
3. /* NetHack may be freely redistributed.  See license for details. */
4. 
5. #include "hack.h"
6. 
7. #ifndef SYSCF
8. /* !SYSCF configurations need '#define DEBUGFILES "foo.c bar.c"'
9.  * to enable debugging feedback for source files foo.c and bar.c;
10.  * to activate debugpline(), set an appropriate value and uncomment
11.  */
12. /* # define DEBUGFILES "*" */
13. 
14. /* note: DEBUGFILES value here or in sysconf.DEBUGFILES can be overridden
15.    at runtime by setting up a value for "DEBUGFILES" in the environment */
16. #endif
17. 
18. struct sysopt_s sysopt;
19. 
20. void
21. sys_early_init(void)
22. {
23.     const char *p;
24. 
25.     /* Don't assume that these are not already set, and that it is
26.      * safe to dupstr() without orphaning any pointers. Check them. */
27. 
28.     sysopt.support = (char *) 0;
29.     sysopt.recover = (char *) 0;
30. #ifdef SYSCF
31.     sysopt.wizards = (char *) 0;
32. #else
33.     if (sysopt.wizards)
34.         free((genericptr_t) sysopt.wizards);
35.     sysopt.wizards = dupstr(WIZARD_NAME);
36. #endif
37. 
38.     if ((p = getenv("DEBUGFILES")) != 0) {
39.         if (sysopt.debugfiles)
40.             free((genericptr_t) sysopt.debugfiles);
41.         sysopt.debugfiles = dupstr(p);
42.         sysopt.env_dbgfl = 1; /* prevent sysconf processing from overriding */
43.     } else {
44. #if defined(SYSCF) || !defined(DEBUGFILES)
45.         sysopt.debugfiles = (char *) 0;
46. #else
47.         if (sysopt.debugfiles)
48.             free((genericptr_t) sysopt.debugfiles);
49.         sysopt.debugfiles = dupstr(DEBUGFILES);
50. #endif
51.         sysopt.env_dbgfl = 0;
52.     }
53. 
54. #ifdef DUMPLOG
55.     sysopt.dumplogfile = (char *) 0;
56. #endif
57.     sysopt.shellers = (char *) 0;
58.     sysopt.explorers = (char *) 0;
59.     sysopt.genericusers = (char *) 0;
60.     sysopt.msghandler = (char *) 0;
61.     sysopt.maxplayers = 0; /* XXX eventually replace MAX_NR_OF_PLAYERS */
62.     sysopt.bones_pools = 0;
63.     sysopt.livelog = LL_NONE;
64. 
65.     /* record file */
66.     sysopt.persmax = max(PERSMAX, 1);
67.     sysopt.entrymax = max(ENTRYMAX, 10);
68.     sysopt.pointsmin = max(POINTSMIN, 1);
69.     sysopt.pers_is_uid = PERS_IS_UID;
70.     sysopt.tt_oname_maxrank = 10;
71. 
72.     /* sanity checks */
73.     if (sysopt.pers_is_uid != 0 && sysopt.pers_is_uid != 1)
74.         panic("config error: PERS_IS_UID must be either 0 or 1");
75. 
76. #ifdef PANICTRACE
77.     /* panic options */
78.     if (sysopt.gdbpath)
79.         free((genericptr_t) sysopt.gdbpath);
80.     sysopt.gdbpath = dupstr(GDBPATH);
81.     if (sysopt.greppath)
82.         free((genericptr_t) sysopt.greppath);
83.     sysopt.greppath = dupstr(GREPPATH);
84. #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED)
85.     sysopt.panictrace_gdb = 1;
86. #ifdef PANICTRACE_LIBC
87.     sysopt.panictrace_libc = 2;
88. #endif
89. #else
90.     sysopt.panictrace_gdb = 0;
91. #ifdef PANICTRACE_LIBC
92.     sysopt.panictrace_libc = 0;
93. #endif
94. #endif
95. #endif
96.     sysopt.crashreporturl = NULL;
97. 
98.     sysopt.check_save_uid = 1;
99.     sysopt.check_plname = 0;
100.     sysopt.seduce = 1; /* if it's compiled in, default to on */
101.     sysopt_seduce_set(sysopt.seduce);
102.     sysopt.saveformat[0] = sysopt.bonesformat[0] = historical;
103.     sysopt.accessibility = 0;
104. #ifdef WIN32
105.     sysopt.portable_device_paths = 0;
106. #endif
107. 
108.     /* help menu */
109.     sysopt.hideusage = 0;
110. 
111.     return;
112. }
113. 
114. void
115. sysopt_release(void)
116. {
117.     if (sysopt.support)
118.         free((genericptr_t) sysopt.support), sysopt.support = (char *) 0;
119.     if (sysopt.recover)
120.         free((genericptr_t) sysopt.recover), sysopt.recover = (char *) 0;
121.     if (sysopt.wizards)
122.         free((genericptr_t) sysopt.wizards), sysopt.wizards = (char *) 0;
123.     if (sysopt.explorers)
124.         free((genericptr_t) sysopt.explorers), sysopt.explorers = (char *) 0;
125.     if (sysopt.shellers)
126.         free((genericptr_t) sysopt.shellers), sysopt.shellers = (char *) 0;
127.     if (sysopt.debugfiles)
128.         free((genericptr_t) sysopt.debugfiles),
129.         sysopt.debugfiles = (char *) 0;
130.     sysopt.env_dbgfl = 0;
131.     if (sysopt.msghandler)
132.         free((genericptr_t) sysopt.msghandler), sysopt.msghandler = (char *) 0;
133. #ifdef DUMPLOG
134.     if (sysopt.dumplogfile)
135.         free((genericptr_t) sysopt.dumplogfile), sysopt.dumplogfile=(char *) 0;
136. #endif
137.     if (sysopt.genericusers)
138.         free((genericptr_t) sysopt.genericusers),
139.             sysopt.genericusers = (char *) 0;
140.     if (sysopt.gdbpath)
141.         free((genericptr_t) sysopt.gdbpath), sysopt.gdbpath = (char *) 0;
142.     if (sysopt.greppath)
143.         free((genericptr_t) sysopt.greppath), sysopt.greppath = (char *) 0;
144. 
145. #ifdef CRASHREPORT
146.     if (gc.crash_email)
147.         free((genericptr_t) gc.crash_email), gc.crash_email = (char *) NULL;
148.     if (gc.crash_name)
149.         free((genericptr_t) gc.crash_name), gc.crash_name = (char *) NULL;
150. #endif
151. 
152.     /* this one's last because it might be used in panic feedback, although
153.        none of the preceding ones are likely to trigger a controlled panic */
154.     if (sysopt.fmtd_wizard_list)
155.         free((genericptr_t) sysopt.fmtd_wizard_list),
156.             sysopt.fmtd_wizard_list = (char *) 0;
157.     return;
158. }
159. 
160. extern const struct attack c_sa_yes[NATTK];
161. extern const struct attack c_sa_no[NATTK];
162. 
163. void
164. sysopt_seduce_set(
165. #if 0
166. int val)
167. {
168. /*
169.  * Attack substitution is now done on the fly in getmattk(mhitu.c).
170.  */
171.     struct attack *setval = val ? c_sa_yes : c_sa_no;
172.     int x;
173. 
174.     for (x = 0; x < NATTK; x++) {
175.         mons[PM_INCUBUS].mattk[x] = setval[x];
176.         mons[PM_SUCCUBUS].mattk[x] = setval[x];
177.     }
178. #else
179. int val UNUSED)
180. {
181. #endif
182.     return;
183. }
184. 
185. /*sys.c*/