1 /* NetHack 3.6 dlb.h $NHDT-Date: 1432512780 2015/05/25 00:13:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
2 /* Copyright (c) Kenneth Lorber, Bethesda, Maryland, 1993. */
3 /* NetHack may be freely redistributed. See license for details. */
7 /* definitions for data library */
13 #define DLBRSRC /* use Mac resources */
15 #define DLBLIB /* use a set of external files */
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) */
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 */
38 /* library definitions */
40 #define DLBFILE "nhdat" /* name of library */
43 #define FILENAME_CMP strcmp /* case sensitive */
48 typedef struct dlb_handle {
49 FILE *fp; /* pointer to an external file, use if non-null */
51 library *lib; /* pointer to library structure */
52 long start; /* offset of start of file */
53 long size; /* size of file */
54 long mark; /* current file marker */
57 int fd; /* HandleFile file descriptor */
61 #if defined(ULTRIX_PROTO) && !defined(__STDC__)
62 /* buggy old Ultrix compiler wants this for the (*dlb_fread_proc)
63 and (*dlb_fgets_proc) prototypes in struct dlb_procs (dlb.c);
64 we'll use it in all the declarations for consistency */
65 #define DLB_P struct dlb_handle *
70 boolean NDECL(dlb_init);
71 void NDECL(dlb_cleanup);
73 dlb *FDECL(dlb_fopen, (const char *, const char *));
74 int FDECL(dlb_fclose, (DLB_P));
75 int FDECL(dlb_fread, (char *, int, int, DLB_P));
76 int FDECL(dlb_fseek, (DLB_P, long, int));
77 char *FDECL(dlb_fgets, (char *, int, DLB_P));
78 int FDECL(dlb_fgetc, (DLB_P));
79 long FDECL(dlb_ftell, (DLB_P));
81 /* Resource DLB entry points */
83 boolean rsrc_dlb_init(void);
84 void rsrc_dlb_cleanup(void);
85 boolean rsrc_dlb_fopen(dlb *dp, const char *name, const char *mode);
86 int rsrc_dlb_fclose(dlb *dp);
87 int rsrc_dlb_fread(char *buf, int size, int quan, dlb *dp);
88 int rsrc_dlb_fseek(dlb *dp, long pos, int whence);
89 char *rsrc_dlb_fgets(char *buf, int len, dlb *dp);
90 int rsrc_dlb_fgetc(dlb *dp);
91 long rsrc_dlb_ftell(dlb *dp);
101 #define dlb_fopen fopen
102 #define dlb_fclose fclose
103 #define dlb_fread fread
104 #define dlb_fseek fseek
105 #define dlb_fgets fgets
106 #define dlb_fgetc fgetc
107 #define dlb_ftell ftell
111 /* various other I/O stuff we don't want to replicate everywhere */
124 #if (defined(MSDOS) || defined(WIN32) || defined(TOS) || defined(OS2)) \
126 #define WRTMODE "w+b"
130 #if (defined(MICRO) && !defined(AMIGA)) || defined(THINK_C) \
131 || defined(__MWERKS__) || defined(WIN32)
133 #define WRBMODE "w+b"