Source:NetHack 5.0.0/include/dlb.h

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to dlb.h from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/include/dlb.h#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	dlb.h	$NHDT-Date: 1596498534 2020/08/03 23:48:54 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.12 $ */
2. /* Copyright (c) Kenneth Lorber, Bethesda, Maryland, 1993. */
3. /* NetHack may be freely redistributed.  See license for details. */
4. 
5. #ifndef DLB_H
6. #define DLB_H
7. /* definitions for data library */
8. 
9. #ifdef DLB
10. 
11. /* implementations */
12. #if defined(MACOS9) && !defined(MACOS9_CROSS)
13. #define DLBRSRC /* use Mac resources */
14. #else
15. #define DLBLIB /* use a set of external files */
16. #endif
17. 
18. #ifdef DLBLIB
19. /* directory structure in memory */
20. typedef struct dlb_directory {
21.     char *fname;   /* file name as seen from calling code */
22.     long foffset;  /* offset in lib file to start of this file */
23.     long fsize;    /* file size */
24.     char handling; /* how to handle the file (compression, etc) */
25. } libdir;
26. 
27. /* information about each open library */
28. typedef struct dlb_library {
29.     FILE *fdata;   /* opened data file */
30.     long fmark;    /* current file mark */
31.     libdir *dir;   /* directory of library file */
32.     char *sspace;  /* pointer to string space */
33.     long nentries; /* # of files in directory */
34.     long rev;      /* dlb file revision */
35.     long strsize;  /* dlb file string size */
36. } library;
37. 
38. /* library definitions */
39. #ifndef DLBFILE
40. #ifndef VERSION_IN_DLB_FILENAME
41. #define DLBFILE "nhdat" /* name of library */
42. #else
43. #define MAX_DLB_FILENAME 256
44. #define DLBFILE dlbfilename
45. #define DLBBASENAME "nhdat"
46. extern char dlbfilename[MAX_DLB_FILENAME];
47. extern char *build_dlb_filename(const char *);
48. #endif
49. #endif
50. #ifndef FILENAME_CMP
51. #define FILENAME_CMP strcmp /* case sensitive */
52. #endif
53. 
54. #endif /* DLBLIB */
55. 
56. typedef struct dlb_handle {
57.     FILE *fp; /* pointer to an external file, use if non-null */
58. #ifdef DLBLIB
59.     library *lib; /* pointer to library structure */
60.     long start;   /* offset of start of file */
61.     long size;    /* size of file */
62.     long mark;    /* current file marker */
63. #endif
64. #ifdef DLBRSRC
65.     int fd; /* HandleFile file descriptor */
66. #endif
67. } dlb;
68. 
69. #if defined(ULTRIX_PROTO) && !defined(__STDC__)
70. /* buggy old Ultrix compiler wants this for the (*dlb_fread_proc)
71.    and (*dlb_fgets_proc) prototypes in struct dlb_procs (dlb.c);
72.    we'll use it in all the declarations for consistency */
73. #define DLB_P struct dlb_handle *
74. #else
75. #define DLB_P dlb *
76. #endif
77. 
78. boolean dlb_init(void);
79. void dlb_cleanup(void);
80. 
81. dlb *dlb_fopen(const char *, const char *);
82. int dlb_fclose(DLB_P);
83. int dlb_fread(char *, int, int, DLB_P);
84. int dlb_fseek(DLB_P, long, int);
85. char *dlb_fgets(char *, int, DLB_P);
86. int dlb_fgetc(DLB_P);
87. long dlb_ftell(DLB_P);
88. 
89. /* Resource DLB entry points */
90. #ifdef DLBRSRC
91. boolean rsrc_dlb_init(void);
92. void rsrc_dlb_cleanup(void);
93. boolean rsrc_dlb_fopen(dlb *dp, const char *name, const char *mode);
94. int rsrc_dlb_fclose(dlb *dp);
95. int rsrc_dlb_fread(char *buf, int size, int quan, dlb *dp);
96. int rsrc_dlb_fseek(dlb *dp, long pos, int whence);
97. char *rsrc_dlb_fgets(char *buf, int len, dlb *dp);
98. int rsrc_dlb_fgetc(dlb *dp);
99. long rsrc_dlb_ftell(dlb *dp);
100. #endif
101. 
102. #else /* DLB */
103. 
104. #define dlb FILE
105. 
106. #define dlb_init()
107. #define dlb_cleanup()
108. 
109. #define dlb_fopen fopen
110. #define dlb_fclose fclose
111. #define dlb_fread fread
112. #define dlb_fseek fseek
113. #define dlb_fgets fgets
114. #define dlb_fgetc fgetc
115. #define dlb_ftell ftell
116. 
117. #endif /* DLB */
118. 
119. /* various other I/O stuff we don't want to replicate everywhere */
120. 
121. #ifndef SEEK_SET
122. #define SEEK_SET 0
123. #endif
124. #ifndef SEEK_CUR
125. #define SEEK_CUR 1
126. #endif
127. #ifndef SEEK_END
128. #define SEEK_END 2
129. #endif
130. 
131. #define RDTMODE "r"
132. #if (defined(MSDOS) || defined(WIN32) || defined(TOS) || defined(OS2)) \
133.     && defined(DLB)
134. #define WRTMODE "w+b"
135. #else
136. #define WRTMODE "w+"
137. #endif
138. #if (defined(MICRO) && !defined(AMIGA)) || defined(THINK_C) \
139.     || defined(__MWERKS__) || defined(WIN32)
140. #define RDBMODE "rb"
141. #define WRBMODE "w+b"
142. #else
143. #define RDBMODE "r"
144. #define WRBMODE "w+"
145. #endif
146. 
147. #endif /* DLB_H */