Source:NetHack 5.0.0/src/mdlib.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to mdlib.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/mdlib.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  mdlib.c  $NHDT-Date: 1701499945 2023/12/02 06:52:25 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.51 $ */
2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3. /*-Copyright (c) Kenneth Lorber, Kensington, Maryland, 2015. */
4. /* Copyright (c) M. Stephenson, 1990, 1991.                       */
5. /* Copyright (c) Dean Luick, 1990.                                */
6. /* NetHack may be freely redistributed.  See license for details. */
7. 
8. /*
9.  * This can be linked into a binary to provide the functionality
10.  * via the contained functions, or it can be #included directly
11.  * into util/makedefs.c to provide it there.
12.  */
13. 
14. #ifndef MAKEDEFS_C
15. #define MDLIB_C
16. #include "config.h"
17. #include "permonst.h"
18. #include "objclass.h"
19. #include "wintype.h"
20. #include "sym.h"
21. #include "artilist.h"
22. #include "dungeon.h"
23. #include "sndprocs.h"
24. #include "obj.h"
25. #include "monst.h"
26. #include "you.h"
27. #include "context.h"
28. #include "flag.h"
29. #include "dlb.h"
30. #include "hacklib.h"
31. 
32. /* version information */
33. #ifdef SHORT_FILENAMES
34. #include "patchlev.h"
35. #else
36. #include "patchlevel.h"
37. #endif
38. #define Fprintf (void) fprintf
39. #define Fclose (void) fclose
40. #define Unlink (void) unlink
41. #if !defined(AMIGA) || defined(AZTEC_C)
42. #define rewind(fp) fseek((fp), 0L, SEEK_SET) /* guarantee a return value */
43. #endif  /* AMIGA || AZTEC_C */
44. #else
45. #ifndef GLOBAL_H
46. #include "global.h"
47. #endif
48. #endif  /* !MAKEDEFS_C */
49. 
50. /* shorten up some lines */
51. #define FOR_RUNTIME
52. 
53. #if defined(MAKEDEFS_C) || defined(FOR_RUNTIME)
54. #include <stdarg.h>
55. /* REPRODUCIBLE_BUILD will change this to TRUE */
56. static boolean date_via_env = FALSE;
57. 
58. extern unsigned long md_ignored_features(void);
59. extern const char *datamodel(int);
60. char *version_id_string(char *, size_t, const char *) NONNULL NONNULLPTRS;
61. char *bannerc_string(char *, size_t, const char *) NONNULL NONNULLPTRS;
62. int case_insensitive_comp(const char *, const char *) NONNULLPTRS;
63. 
64. #ifndef SFCTOOL
65. staticfn
66. #endif /* SFCTOOL */
67. void make_version(void);
68. 
69. #ifndef HAS_NO_MKSTEMP
70. #ifdef _MSC_VER
71. static int mkstemp(char *);
72. #endif
73. #endif
74. 
75. #endif /* MAKEDEFS_C || FOR_RUNTIME */
76. 
77. #if !defined(MAKEDEFS_C) && defined(WIN32)
78. extern int GUILaunched;
79. #endif
80. 
81. /* these are in extern.h but we don't include hack.h */
82. /* XXX move to new file mdlib.h? */
83. extern void populate_nomakedefs(struct version_info *) NONNULLARG1; /*date.c*/
84. extern void free_nomakedefs(void); /* date.c */
85. void runtime_info_init(void);
86. const char *do_runtime_info(int *) NO_NNARGS;
87. void release_runtime_info(void);
88. char *mdlib_version_string(char *, const char *) NONNULL NONNULLPTRS;
89. 
90. staticfn void build_options(void);
91. staticfn int count_and_validate_winopts(void);
92. staticfn void opt_out_words(char *, int *) NONNULLPTRS;
93. staticfn void build_savebones_compat_string(void);
94. 
95. static int idxopttext, done_runtime_opt_init_once = 0;
96. #define MAXOPT 60 /* 5.0: currently 40 lines get inserted into opttext[] */
97. static char *opttext[MAXOPT] = { 0 };
98. #define STOREOPTTEXT(line) \
99.     ((void) ((idxopttext < MAXOPT)                      \
100.              ? (opttext[idxopttext++] = dupstr(line))   \
101.              : 0))
102. static char optbuf[COLBUFSZ];
103. static struct version_info version;
104. static const char opt_indent[] = "    ";
105. 
106. struct win_information {
107.     const char *id, /* windowtype value */
108.         *name;      /* description, often same as id */
109.     boolean valid;
110. };
111. 
112. static struct win_information window_opts[] = {
113. #ifdef TTY_GRAPHICS
114.     { "tty",
115.       /* testing TILES_IN_GLYPHMAP here would bring confusion because it could
116.          apply to another interface such as X11, so check MSDOS explicitly
117.          instead; even checking TTY_TILES_ESCCODES would probably be
118.          confusing to most users (and it will already be listed separately
119.          in the compiled options section so users aware of it can find it) */
120. #ifdef MSDOS
121.       "traditional text with optional 'tiles' graphics",
122. #else
123.       /* assume that one or more of IBMgraphics, DECgraphics
124.          can be enabled; we can't tell from here whether that is accurate */
125.       "traditional text with optional line-drawing",
126. #endif
127.       TRUE
128.     },
129. #endif /*TTY_GRAPHICS */
130. #ifdef CURSES_GRAPHICS
131.     { "curses", "terminal-based graphics", TRUE },
132. #endif
133. #ifdef X11_GRAPHICS
134.     { "X11", "X11", TRUE },
135. #endif
136. #ifdef QT_GRAPHICS /* too vague; there are multiple incompatible versions */
137.     { "Qt", "Qt", TRUE },
138. #endif
139. #ifdef MSWIN_GRAPHICS /* win32 */
140.     { "mswin", "Windows GUI", TRUE },
141. #endif
142. #ifdef SHIM_GRAPHICS
143.     { "shim", "NetHack Library Windowing Shim", TRUE },
144. #endif
145. 
146. #if 0  /* remainder have been retired */
147. #ifdef GNOME_GRAPHICS /* unmaintained/defunct */
148.     { "Gnome", "Gnome", TRUE },
149. #endif
150. #ifdef MACOS9 /* defunct OS 9 interface */
151.     { "mac", "Mac", TRUE },
152. #endif
153. #ifdef AMIGA_INTUITION /* unmaintained/defunct */
154.     { "amii", "Amiga Intuition", TRUE },
155. #endif
156. #ifdef GEM_GRAPHICS /* defunct Atari interface */
157.     { "Gem", "Gem", TRUE },
158. #endif
159. #ifdef BEOS_GRAPHICS /* unmaintained/defunct */
160.     { "BeOS", "BeOS InterfaceKit", TRUE },
161. #endif
162. #endif  /* 0 => retired */
163.     { 0, 0, FALSE }
164. };
165. 
166. #if !defined(MAKEDEFS_C)
167. staticfn int count_and_validate_soundlibopts(void);
168. 
169. struct soundlib_information {
170.     enum soundlib_ids id;
171.     const char *const text_id;
172.     const char *const Url;
173.     boolean valid;
174. };
175. 
176. /*
177.  * soundlibs
178.  *
179.  * None of these are endorsements or recommendations of one library
180.  * or another, in any way. They are just preprocessor conditionals
181.  * in the event that glue code for such a library is ever added into
182.  * NetHack.
183.  */
184. static struct soundlib_information soundlib_opts[] = {
185.     { soundlib_nosound, "soundlib_nosound", "", FALSE },
186. #ifdef SND_LIB_PORTAUDIO
187.     { soundlib_portaudio, "soundlib_portaudio",
188.         "http://www.portaudio.com/", FALSE },
189. #endif
190. #ifdef SND_LIB_OPENAL
191.     { soundlib_openal, "soundlib_openal",
192.         "https://www.openal.org/", FALSE },
193. #endif
194. #ifdef SND_LIB_SDL_MIXER
195.     { soundlib_sdl_mixer, "soundlib_sdl_mixer",
196.         "https://github.com/libsdl-org/SDL_mixer/", FALSE },
197. #endif
198. #ifdef SND_LIB_MINIAUDIO
199.     { soundlib_miniaudio, "soundlib_miniaudio",
200.         "https://miniaud.io/", FALSE },
201. #endif
202. #ifdef SND_LIB_FMOD
203.     /* proprietary, though a Free Indie License exists.
204.      * https://www.fmod.com/licensing#indie-note
205.      */
206.     { soundlib_fmod, "soundlib_fmod",
207.         "https://www.fmod.com/", FALSE },
208. #endif
209. #ifdef SND_LIB_SOUND_ESCCODES
210.     { soundlib_sound_esccodes, "sound_esccodes", "", FALSE },
211. #endif
212. #ifdef SND_LIB_VISSOUND
213.     { soundlib_vissound, "soundlib_vissound", "", FALSE },
214. #endif
215. #ifdef SND_LIB_WINDSOUND
216.     /* Uses Windows WIN32 API */
217.     { soundlib_windsound, "soundlib_windsound",
218.   "https://learn.microsoft.com/en-us/windows/win32/multimedia/waveform-audio",
219.         FALSE },
220. #endif
221. #ifdef SND_LIB_MACSOUND
222.     /* Uses AppKit NSSound */
223.     { soundlib_macsound, "soundlib_macsound",
224.         "https://developer.apple.com/documentation/appkit/nssound",
225.         FALSE },
226. #endif
227. #ifdef SND_LIB_QTSOUND
228.     { soundlib_qtsound, "soundlib_qtsound",
229.         "https://doc.qt.io/qt-5/qsoundeffect.html", FALSE },
230. #endif
231.     { 0, 0, 0, FALSE },
232. };
233. #endif  /* !MAKEDEFS_C */
234. 
235. unsigned long
236. md_ignored_features(void)
237. {
238.     return (0UL
239.             | (1UL << 19) /* SCORE_ON_BOTL */
240.             | SFCTOOL_BIT /* stored by SFCTOOL, not NetHack itself */
241.             );
242. }
243. 
244. #ifndef SFCTOOL
245. staticfn
246. #endif
247. void
248. make_version(void)
249. {
250.     int i;
251. 
252.     /*
253.      * integer version number
254.      */
255.     version.incarnation = ((unsigned long) VERSION_MAJOR << 24)
256.                           | ((unsigned long) VERSION_MINOR << 16)
257.                           | ((unsigned long) PATCHLEVEL << 8)
258.                           | ((unsigned long) EDITLEVEL);
259.     /*
260.      * encoded feature list
261.      * Note:  if any of these magic numbers are changed or reassigned,
262.      * EDITLEVEL in patchlevel.h should be incremented at the same time.
263.      * The actual values have no special meaning, and the category
264.      * groupings are just for convenience.
265.      */
266.     version.feature_set = (unsigned long) (0L
267. /* levels and/or topology (0..4) */
268. /* monsters (5..9) */
269. #ifdef MAIL_STRUCTURES
270.                                            | (1L << 6)
271. #endif
272. /* objects (10..14) */
273. /* flag bits and/or other global variables (15..26) */
274.  /* color support always*/                 | (1L << 17)
275. #ifdef INSURANCE
276.                                            | (1L << 18)
277. #endif
278. #ifdef SCORE_ON_BOTL
279.                                            | (1L << 19)
280. #endif
281.                                                );
282.     /*
283.      * Value used for object & monster sanity check.
284.      *    (NROFARTIFACTS<<24) | (NUM_OBJECTS<<12) | (NUMMONS<<0)
285.      */
286.     for (i = 1; artifact_names[i]; i++)
287.         continue;
288.     version.entity_count = (unsigned long) (i - 1);
289.     i = NUM_OBJECTS;
290.     version.entity_count = (version.entity_count << 12) | (unsigned long) i;
291.     i = NUMMONS;
292.     version.entity_count = (version.entity_count << 12) | (unsigned long) i;
293. /* free bits in here */
294.     return;
295. }
296. 
297. #if defined(MAKEDEFS_C) || defined(FOR_RUNTIME)
298. 
299. char *
300. mdlib_version_string(char *outbuf, const char *delim)
301. {
302.     Sprintf(outbuf, "%d%s%d%s%d", VERSION_MAJOR, delim, VERSION_MINOR, delim,
303.             PATCHLEVEL);
304. #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED)
305.     Sprintf(eos(outbuf), "-%d", EDITLEVEL);
306. #endif
307.     return outbuf;
308. }
309. 
310. #define Snprintf(str, size, ...) \
311.     nh_snprintf(__func__, __LINE__, str, size, __VA_ARGS__)
312. extern void nh_snprintf(const char *func, int line, char *str, size_t size,
313.                         const char *fmt, ...);
314. 
315. char *
316. version_id_string(char *outbuf, size_t bufsz, const char *build_date)
317. {
318.     char subbuf[64], versbuf[64];
319.     char statusbuf[64];
320. 
321. #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED)
322. #if (NH_DEVEL_STATUS == NH_STATUS_BETA)
323.     Strcpy(statusbuf, " Beta");
324. #else
325. #if (NH_DEVEL_STATUS == NH_STATUS_WIP)
326.     Strcpy(statusbuf, " Work-in-progress");
327. #else
328.     Strcpy(statusbuf, " post-release");
329. #endif
330. #endif
331. #else
332.     statusbuf[0] = '\0';
333. #endif
334.     subbuf[0] = '\0';
335. #ifdef PORT_SUB_ID
336.     subbuf[0] = ' ';
337.     Strcpy(&subbuf[1], PORT_SUB_ID);
338. #endif
339. 
340.     Snprintf(outbuf, bufsz, "%s NetHack%s Version %s%s - last %s %s.",
341.              PORT_ID, subbuf, mdlib_version_string(versbuf, "."), statusbuf,
342.              date_via_env ? "revision" : "build", build_date);
343.     return outbuf;
344. }
345. 
346. /* still within #if MAKDEFS_C || FOR_RUNTIME */
347. 
348. char *
349. bannerc_string(char *outbuf, size_t bufsz, const char *build_date)
350. {
351.     char subbuf[64], versbuf[64];
352. 
353.     subbuf[0] = '\0';
354. #ifdef PORT_SUB_ID
355.     subbuf[0] = ' ';
356.     Strcpy(&subbuf[1], PORT_SUB_ID);
357. #endif
358. #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED)
359. #if (NH_DEVEL_STATUS == NH_STATUS_BETA)
360.     Strcat(subbuf, " Beta");
361. #else
362.     Strcat(subbuf, " Work-in-progress");
363. #endif
364. #endif
365. 
366.     Snprintf(outbuf, bufsz, "         Version %s %s%s, %s %s.",
367.             mdlib_version_string(versbuf, "."), PORT_ID, subbuf,
368.             date_via_env ? "revised" : "built", build_date);
369.     return outbuf;
370. }
371. 
372. #ifndef HAS_NO_MKSTEMP
373. #ifdef _MSC_VER
374. int
375. mkstemp(char *template)
376. {
377.     int err;
378. 
379.     err = _mktemp_s(template, strlen(template) + 1);
380.     if( err != 0 )
381.         return -1;
382.     return _open(template,
383.                  _O_RDWR | _O_BINARY | _O_TEMPORARY | _O_CREAT,
384.                  _S_IREAD | _S_IWRITE);
385. }
386. #endif /* _MSC_VER */
387. #endif /* HAS_NO_MKSTEMP */
388. #endif /* MAKEDEFS_C || FOR_RUNTIME */
389. 
390. static char save_bones_compat_buf[BUFSZ];
391. 
392. staticfn void
393. build_savebones_compat_string(void)
394. {
395. #ifdef VERSION_COMPATIBILITY
396.     unsigned long uver = VERSION_COMPATIBILITY,
397.                   cver  = (((unsigned long) VERSION_MAJOR << 24)
398.                          | ((unsigned long) VERSION_MINOR << 16)
399.                          | ((unsigned long) PATCHLEVEL    <<  8));
400. #endif
401. 
402.     Strcpy(save_bones_compat_buf,
403.            "save and bones files accepted from version");
404. #ifdef VERSION_COMPATIBILITY
405.     if (uver != cver)
406.         Sprintf(eos(save_bones_compat_buf), "s %lu.%lu.%lu through %d.%d.%d",
407.                 ((uver >> 24) & 0x0ffUL),
408.                 ((uver >> 16) & 0x0ffUL),
409.                 ((uver >>  8) & 0x0ffUL),
410.                 VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL);
411.     else
412. #endif
413.         Sprintf(eos(save_bones_compat_buf), " %d.%d.%d only",
414.                 VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL);
415. }
416. 
417. static const char *const build_opts[] = {
418. #ifdef AMIGA_WBENCH
419.     "Amiga WorkBench support",
420. #endif
421. #ifdef ANSI_DEFAULT
422.     "ANSI default terminal",
423. #endif
424.     "color",
425. #ifdef TTY_GRAPHICS
426. #ifdef TTY_TILES_ESCCODES
427.     "console escape codes for tile hinting",
428. #endif
429. #endif
430. #ifdef LIFE
431.     "Conway's Game of Life",
432. #endif
433. #ifdef COMPRESS
434.     "data file compression",
435. #endif
436. #ifdef ZLIB_COMP
437.     "ZLIB data file compression",
438. #endif
439. #ifdef DLB
440. #ifndef VERSION_IN_DLB_FILENAME
441.     "data librarian",
442. #else
443.     "data librarian with a version-dependent name",
444. #endif
445. #endif
446. #ifdef EDIT_GETLIN
447.     "edit getlin - some prompts remember previous response",
448. #endif
449. #ifdef DUMPLOG
450.     "end-of-game dumplogs",
451. #endif
452. #ifdef HOLD_LOCKFILE_OPEN
453.     "exclusive lock on level 0 file",
454. #endif
455. #if defined(HANGUPHANDLING) && !defined(NO_SIGNAL)
456. #ifdef SAFERHANGUP
457.     "deferred handling of hangup signal",
458. #else
459.     "immediate handling of hangup signal",
460. #endif
461. #endif
462. #ifdef INSURANCE
463.     "insurance files for recovering from crashes",
464. #endif
465. #ifdef LIVELOG
466.     "live logging support",
467. #endif
468. #ifdef LOGFILE
469.     "log file",
470. #endif
471. #ifdef XLOGFILE
472.     "extended log file",
473. #endif
474. #ifdef PANICLOG
475.     "errors and warnings log file",
476. #endif
477. #ifdef MAIL
478.     "mail daemon",
479. #endif
480. #ifdef MONITOR_HEAP
481.     "monitor heap - record memory usage for later analysis",
482. #endif
483. #if defined(GNUDOS) || defined(__DJGPP__)
484.     "MSDOS protected mode",
485. #endif
486. #ifdef NEWS
487.     "news file",
488. #endif
489. #ifdef OVERLAY
490. #ifdef MOVERLAY
491.     "MOVE overlays",
492. #else
493. #ifdef VROOMM
494.     "VROOMM overlays",
495. #else
496.     "overlays",
497. #endif
498. #endif
499. #endif
500. #ifdef UNIX
501. #if defined(DEF_PAGER) && !defined(DLB)
502.     "external pager used for viewing help files",
503. #else
504.     "internal pager used for viewing help files",
505. #endif
506. #endif /* UNIX */
507.     /* pattern matching method will be substituted by nethack at run time */
508.     "pattern matching via :PATMATCH:",
509. #ifdef USE_ISAAC64
510.     "pseudo random numbers generated by ISAAC64",
511. #ifdef DEV_RANDOM
512.     /* include which specific one */
513.     "strong PRNG seed from " DEV_RANDOM,
514. #else
515. #ifdef WIN32
516.     "strong PRNG seed from CNG BCryptGenRandom()",
517. #endif
518. #endif  /* DEV_RANDOM */
519. #else   /* ISAAC64 */
520. #ifdef RANDOM
521.     "pseudo random numbers generated by random()",
522. #else
523.     "pseudo random numbers generated by C rand()",
524. #endif
525. #endif /* ISAAC64 */
526. #ifdef SELECTSAVED
527.     "restore saved games via menu",
528. #endif
529. #ifdef SCORE_ON_BOTL
530.     "score on status line",
531. #endif
532. #ifdef CLIPPING
533.     "screen clipping",
534. #endif
535. #ifdef NO_TERMS
536. #ifdef MACOS9
537.     "screen control via mactty",
538. #endif
539. #ifdef SCREEN_BIOS
540.     "screen control via BIOS",
541. #endif
542. #ifdef SCREEN_DJGPPFAST
543.     "screen control via DJGPP fast",
544. #endif
545. #ifdef SCREEN_VGA
546.     "screen control via VGA graphics",
547. #endif
548. #ifdef WIN32CON
549.     "screen control via WIN32 console I/O",
550. #endif
551. #endif /* NO_TERMS */
552. #ifdef SHELL
553.     "shell command",
554. #endif
555.     "traditional status display",
556. #ifdef STATUS_HILITES
557.     "status via windowport with highlighting",
558. #else
559.     "status via windowport without highlighting",
560. #endif
561. #ifdef SUSPEND
562.     "suspend command",
563. #endif
564. #ifdef TTY_GRAPHICS
565. #ifdef TERMINFO
566.     "terminal info library",
567. #else
568. #if defined(TERMLIB) || (!defined(MICRO) && !defined(WIN32))
569.     "terminal capability library",
570. #endif
571. #endif
572. #endif /*TTY_GRAPHICS*/
573. #ifdef USE_XPM
574.     "tiles file in XPM format",
575. #endif
576. #ifdef GRAPHIC_TOMBSTONE
577.     "graphical RIP screen",
578. #endif
579. #ifdef TIMED_DELAY
580.     "timed wait for display effects",
581. #endif
582. #ifdef PREFIXES_IN_USE
583.     "variable playground",
584. #endif
585. #ifdef VISION_TABLES
586.     "vision tables",
587. #endif
588. #ifdef SYSCF
589.     "system configuration at run-time",
590. #endif
591. #ifdef PANICTRACE
592.     "show stack trace on error",
593. #endif
594. #ifdef CRASHREPORT
595.     "launch browser to report issues",
596. #endif
597.     save_bones_compat_buf,
598.     "and basic NetHack features"
599. };
600. 
601. staticfn int
602. count_and_validate_winopts(void)
603. {
604.     int i, cnt = 0;
605. 
606.     /* window_opts has a fencepost entry at the end */
607.     for (i = 0; i < SIZE(window_opts) - 1; i++) {
608. #if !defined(MAKEDEFS_C) && defined(FOR_RUNTIME)
609. #ifdef WIN32
610.         window_opts[i].valid = FALSE;
611.         if ((GUILaunched
612.              && case_insensitive_comp(window_opts[i].id, "curses") != 0
613.              && case_insensitive_comp(window_opts[i].id, "mswin") != 0)
614.             || (!GUILaunched
615.                 && case_insensitive_comp(window_opts[i].id, "mswin") == 0))
616.             continue;
617. #endif
618. #endif /* !MAKEDEFS_C && FOR_RUNTIME */
619.         ++cnt;
620.         window_opts[i].valid = TRUE;
621.     }
622.     return cnt;
623. }
624. 
625. #if !defined(MAKEDEFS_C)
626. staticfn int
627. count_and_validate_soundlibopts(void)
628. {
629.     int i, cnt = 0;
630. 
631.     /* soundlib_opts has a fencepost entry at the end */
632.     for (i = 0; i < SIZE(soundlib_opts) - 1; i++) {
633.         ++cnt;
634.         soundlib_opts[i].valid = TRUE;
635.     }
636.     return cnt;
637. }
638. #endif
639. 
640. staticfn void
641. opt_out_words(
642.     char *str,     /* input, but modified during processing */
643.     int *length_p) /* in/out */
644. {
645.     char *word;
646. 
647.     while (*str) {
648.         word = strchr(str, ' ');
649. #if 0
650.         /* treat " (" as unbreakable space */
651.         if (word && *(word + 1) == '(')
652.             word = strchr(word + 1,  ' ');
653. #endif
654.         if (word)
655.             *word = '\0';
656.         if (*length_p + (int) strlen(str) > COLNO - 5) {
657.             STOREOPTTEXT(optbuf);
658.             Sprintf(optbuf, "%s", opt_indent),
659.                 *length_p = (int) strlen(opt_indent);
660.         } else {
661.             Sprintf(eos(optbuf), " "), (*length_p)++;
662.         }
663.         Sprintf(eos(optbuf), "%s", str), *length_p += (int) strlen(str);
664.         str += strlen(str) + (word ? 1 : 0);
665.     }
666. }
667. 
668. staticfn void
669. build_options(void)
670. {
671.     char buf[COLBUFSZ];
672.     int i, length, winsyscnt, cnt = 0;
673.     const char *defwinsys = DEFAULT_WINDOW_SYS;
674. #if !defined(MAKEDEFS_C) && defined(FOR_RUNTIME)
675.     int soundlibcnt;
676. 
677. #ifdef WIN32
678.     defwinsys = GUILaunched ? "mswin" : "tty";
679. #endif
680. #endif
681.     build_savebones_compat_string();
682.     STOREOPTTEXT(optbuf);
683. #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED)
684. #if (NH_DEVEL_STATUS == NH_STATUS_BETA)
685. #define STATUS_ARG " [beta]"
686. #else
687. #define STATUS_ARG " [work-in-progress]"
688. #endif
689. #else
690. #define STATUS_ARG ""
691. #endif /* NH_DEVEL_STATUS == NH_STATUS_RELEASED */
692.     Sprintf(optbuf, "%sNetHack version %d.%d.%d%s\n",
693.             opt_indent, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, STATUS_ARG);
694.     STOREOPTTEXT(optbuf);
695.     Sprintf(optbuf, "Options compiled into this edition:");
696.     STOREOPTTEXT(optbuf);
697.     optbuf[0] = '\0';
698.     length = COLNO + 1; /* force 1st item onto new line */
699.     Strcat(strcpy(buf, datamodel(0)), " data model,");
700.     opt_out_words(buf, &length);
701.     for (i = 0; i < SIZE(build_opts); i++) {
702. #if !defined(MAKEDEFS_C) && defined(FOR_RUNTIME)
703. #ifdef WIN32
704.         /* ignore the console entry if GUI version */
705.         if (GUILaunched
706.             && !strcmp("screen control via WIN32 console I/O", build_opts[i]))
707.             continue;
708. #endif
709. #endif /* !MAKEDEFS_C && FOR_RUNTIME */
710.         Strcat(strcpy(buf, build_opts[i]),
711.                (i < SIZE(build_opts) - 1) ? "," : ".");
712.         opt_out_words(buf, &length);
713.     }
714.     STOREOPTTEXT(optbuf);
715.     optbuf[0] = '\0';
716.     winsyscnt = count_and_validate_winopts();
717.     STOREOPTTEXT(optbuf);
718.     Sprintf(optbuf, "Supported windowing system%s:",
719.             (winsyscnt > 1) ? "s" : "");
720.     STOREOPTTEXT(optbuf);
721.     optbuf[0] = '\0';
722.     length = COLNO + 1; /* force 1st item onto new line */
723. 
724.     for (i = 0; i < SIZE(window_opts) - 1; i++) {
725.         if (!window_opts[i].valid)
726.             continue;
727.         Sprintf(buf, "\"%s\"", window_opts[i].id);
728.         if (strcmp(window_opts[i].name, window_opts[i].id))
729.             Sprintf(eos(buf), " (%s)", window_opts[i].name);
730.         /*
731.          * 1 : foo.
732.          * 2 : foo and bar,
733.          * 3+: for, bar, and quux,
734.          *
735.          * 2+ will be followed by " with a default of..."
736.          */
737.         Strcat(buf, (winsyscnt == 1) ? "." /* no 'default' */
738.                     : (winsyscnt == 2 && cnt == 0) ? " and"
739.                       : (cnt == winsyscnt - 2) ? ", and"
740.                         : ",");
741.         opt_out_words(buf, &length);
742.         cnt++;
743.     }
744.     if (cnt > 1) {
745.         /* loop ended with a comma; opt_out_words() will insert a space */
746.         Sprintf(buf, "with a default of \"%s\".", defwinsys);
747.         opt_out_words(buf, &length);
748.     }
749. 
750. #if !defined(MAKEDEFS_C)
751.     cnt = 0;
752.     STOREOPTTEXT(optbuf);
753.     optbuf[0] = '\0';
754.     soundlibcnt = count_and_validate_soundlibopts();
755.     STOREOPTTEXT(optbuf);
756.     Sprintf(optbuf, "Supported soundlib%s:", (soundlibcnt > 1) ? "s" : "");
757.     STOREOPTTEXT(optbuf);
758.     optbuf[0] = '\0';
759.     length = COLNO + 1; /* force 1st item onto new line */
760. 
761. #ifdef USER_SOUNDS
762.     soundlibcnt += 1;
763. #endif
764.     for (i = 0; i < SIZE(soundlib_opts) - 1; i++) {
765.         const char *soundlib;
766. 
767.         if (!soundlib_opts[i].valid)
768.             continue;
769.         soundlib = soundlib_opts[i].text_id;
770.         if (!strncmp(soundlib, "soundlib_", 9))
771.             soundlib += 9;
772.         Sprintf(buf, "\"%s\"", soundlib);
773.         /*
774.          * 1 : foo.
775.          * 2 : foo and bar.
776.          * 3+: for, bar, and quux.
777.          */
778.         Strcat(buf, (soundlibcnt == 1 || cnt == soundlibcnt - 1)
779.                     ? "." /* no 'with default' */
780.                     : (soundlibcnt == 2 && cnt == 0) ? " and"
781.                       : (cnt == soundlibcnt - 2) ? ", and"
782.                         : ",");
783.         opt_out_words(buf, &length);
784.         cnt++;
785.     }
786. #ifdef USER_SOUNDS
787.     if (cnt > 1) {
788.         /* loop ended with a comma; opt_out_words() will insert a space */
789.         Sprintf(buf, "user sounds.");
790.         opt_out_words(buf, &length);
791.     }
792. #endif
793. #endif  /* !MAKEDEFS_C */
794. 
795.     STOREOPTTEXT(optbuf);
796.     optbuf[0] = '\0';
797. 
798. #if defined(MAKEDEFS_C) || defined(FOR_RUNTIME)
799.     {
800.         static const char *const lua_info[] = {
801.  "", "NetHack 5.0.* uses the 'Lua' interpreter to process some data:", "",
802.  "    :LUACOPYRIGHT:", "",
803.  /*        1         2         3         4         5         6         7
804.   1234567890123456789012345678901234567890123456789012345678901234567890123456
805.   */
806.  ("    \"Permission is hereby granted, free of charge,"
807.   " to any person obtaining"),
808.  "     a copy of this software and associated documentation files (the ",
809.  "     \"Software\"), to deal in the Software without restriction including",
810.  "     without limitation the rights to use, copy, modify, merge, publish,",
811.  "     distribute, sublicense, and/or sell copies of the Software, and to ",
812.  "     permit persons to whom the Software is furnished to do so, subject to",
813.  "     the following conditions:",
814.  "     The above copyright notice and this permission notice shall be",
815.  "     included in all copies or substantial portions of the Software.\"",
816.             (const char *) 0
817.         };
818. 
819.         /* add lua copyright notice;
820.            ":TAG:" substitutions are deferred to caller */
821.         for (i = 0; lua_info[i]; ++i) {
822.             STOREOPTTEXT(lua_info[i]);
823.         }
824.     }
825. #endif /* MAKEDEFS_C || FOR_RUNTIME */
826. 
827.     /* end with a blank line */
828.     STOREOPTTEXT("");
829.     return;
830. }
831. 
832. #undef STOREOPTTEXT
833. 
834. void
835. runtime_info_init(void)
836. {
837.     if (!done_runtime_opt_init_once) {
838.         done_runtime_opt_init_once = 1;
839.         build_savebones_compat_string();
840.         /* construct the current version number */
841.         make_version();
842.         populate_nomakedefs(&version);          /* date.c */
843.         idxopttext = 0;
844.         build_options();
845.     }
846. }
847. 
848. const char *
849. do_runtime_info(int *rtcontext)
850. {
851.     const char *retval = (const char *) 0;
852. 
853.     if (!done_runtime_opt_init_once)
854.         runtime_info_init();
855.     if (idxopttext && rtcontext)
856.         if (*rtcontext >= 0 && *rtcontext < MAXOPT) {
857.             retval = opttext[*rtcontext];
858.             *rtcontext += 1;
859.         }
860.     return retval;
861. }
862. 
863. void
864. release_runtime_info(void)
865. {
866.     while (idxopttext > 0) {
867.         --idxopttext;
868.         free((genericptr_t) opttext[idxopttext]), opttext[idxopttext] = 0;
869.     }
870.     done_runtime_opt_init_once = 0;
871.     free_nomakedefs();
872. }
873. 
874. /*mdlib.c*/