1 /* SCCS Id: @(#)dlb.h 3.4 1997/07/29 */
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 */
49 typedef struct dlb_handle {
50 FILE *fp; /* pointer to an external file, use if non-null */
52 library *lib; /* pointer to library structure */
53 long start; /* offset of start of file */
54 long size; /* size of file */
55 long mark; /* current file marker */
58 int fd; /* HandleFile file descriptor */
62 #if defined(ULTRIX_PROTO) && !defined(__STDC__)
63 /* buggy old Ultrix compiler wants this for the (*dlb_fread_proc)
64 and (*dlb_fgets_proc) prototypes in struct dlb_procs (dlb.c);
65 we'll use it in all the declarations for consistency */
66 #define DLB_P struct dlb_handle *
71 boolean NDECL(dlb_init);
72 void NDECL(dlb_cleanup);
74 dlb *FDECL(dlb_fopen, (const char *,const char *));
75 int FDECL(dlb_fclose, (DLB_P));
76 int FDECL(dlb_fread, (char *,int,int,DLB_P));
77 int FDECL(dlb_fseek, (DLB_P,long,int));
78 char *FDECL(dlb_fgets, (char *,int,DLB_P));
79 int FDECL(dlb_fgetc, (DLB_P));
80 long FDECL(dlb_ftell, (DLB_P));
83 /* Resource DLB entry points */
85 boolean rsrc_dlb_init(void);
86 void rsrc_dlb_cleanup(void);
87 boolean rsrc_dlb_fopen(dlb *dp, const char *name, const char *mode);
88 int rsrc_dlb_fclose(dlb *dp);
89 int rsrc_dlb_fread(char *buf, int size, int quan, dlb *dp);
90 int rsrc_dlb_fseek(dlb *dp, long pos, int whence);
91 char *rsrc_dlb_fgets(char *buf, int len, dlb *dp);
92 int rsrc_dlb_fgetc(dlb *dp);
93 long rsrc_dlb_ftell(dlb *dp);
102 # define dlb_cleanup()
104 # define dlb_fopen fopen
105 # define dlb_fclose fclose
106 # define dlb_fread fread
107 # define dlb_fseek fseek
108 # define dlb_fgets fgets
109 # define dlb_fgetc fgetc
110 # define dlb_ftell ftell
115 /* various other I/O stuff we don't want to replicate everywhere */
128 #if (defined(MSDOS) || defined(WIN32) || defined(TOS) || defined(OS2)) && defined(DLB)
129 #define WRTMODE "w+b"
133 #if (defined(MICRO) && !defined(AMIGA)) || defined(THINK_C) || defined(__MWERKS__) || defined(WIN32)
134 # define RDBMODE "rb"
135 # define WRBMODE "w+b"
138 # define WRBMODE "w+"