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