dlb.h

Go to the documentation of this file.
00001 /*      SCCS Id: @(#)dlb.h      3.4     1997/07/29      */
00002 /* Copyright (c) Kenneth Lorber, Bethesda, Maryland, 1993. */
00003 /* NetHack may be freely redistributed.  See license for details. */
00004 
00005 #ifndef DLB_H
00006 #define DLB_H
00007 /* definitions for data library */
00008 
00009 #ifdef DLB
00010 
00011 /* implementations */
00012 #ifdef MAC
00013 # define DLBRSRC        /* use Mac resources */
00014 #else
00015 # define DLBLIB         /* use a set of external files */
00016 #endif
00017 
00018 #ifdef DLBLIB
00019 /* directory structure in memory */
00020 typedef struct dlb_directory {
00021     char *fname;        /* file name as seen from calling code */
00022     long foffset;       /* offset in lib file to start of this file */
00023     long fsize;         /* file size */
00024     char handling;      /* how to handle the file (compression, etc) */
00025 } libdir;
00026 
00027 /* information about each open library */
00028 typedef struct dlb_library {
00029     FILE *fdata;        /* opened data file */
00030     long fmark;         /* current file mark */
00031     libdir *dir;        /* directory of library file */
00032     char *sspace;       /* pointer to string space */
00033     long nentries;      /* # of files in directory */
00034     long rev;           /* dlb file revision */
00035     long strsize;       /* dlb file string size */
00036 } library;
00037 
00038 /* library definitions */
00039 # ifndef DLBFILE
00040 #  define DLBFILE       "nhdat"                 /* name of library */
00041 # endif
00042 # ifndef FILENAME_CMP
00043 #  define FILENAME_CMP  strcmp                  /* case sensitive */
00044 # endif
00045 
00046 #endif /* DLBLIB */
00047 
00048 
00049 typedef struct dlb_handle {
00050     FILE *fp;           /* pointer to an external file, use if non-null */
00051 #ifdef DLBLIB
00052     library *lib;       /* pointer to library structure */
00053     long start;         /* offset of start of file */
00054     long size;          /* size of file */
00055     long mark;          /* current file marker */
00056 #endif
00057 #ifdef DLBRSRC
00058     int fd;             /* HandleFile file descriptor */
00059 #endif
00060 } dlb;
00061 
00062 #if defined(ULTRIX_PROTO) && !defined(__STDC__)
00063  /* buggy old Ultrix compiler wants this for the (*dlb_fread_proc)
00064     and (*dlb_fgets_proc) prototypes in struct dlb_procs (dlb.c);
00065     we'll use it in all the declarations for consistency */
00066 #define DLB_P struct dlb_handle *
00067 #else
00068 #define DLB_P dlb *
00069 #endif
00070 
00071 boolean NDECL(dlb_init);
00072 void NDECL(dlb_cleanup);
00073 
00074 dlb *FDECL(dlb_fopen, (const char *,const char *));
00075 int FDECL(dlb_fclose, (DLB_P));
00076 int FDECL(dlb_fread, (char *,int,int,DLB_P));
00077 int FDECL(dlb_fseek, (DLB_P,long,int));
00078 char *FDECL(dlb_fgets, (char *,int,DLB_P));
00079 int FDECL(dlb_fgetc, (DLB_P));
00080 long FDECL(dlb_ftell, (DLB_P));
00081 
00082 
00083 /* Resource DLB entry points */
00084 #ifdef DLBRSRC
00085         boolean rsrc_dlb_init(void);
00086         void rsrc_dlb_cleanup(void);
00087         boolean rsrc_dlb_fopen(dlb *dp, const char *name, const char *mode);
00088         int rsrc_dlb_fclose(dlb *dp);
00089         int rsrc_dlb_fread(char *buf, int size, int quan, dlb *dp);
00090         int rsrc_dlb_fseek(dlb *dp, long pos, int whence);
00091         char *rsrc_dlb_fgets(char *buf, int len, dlb *dp);
00092         int rsrc_dlb_fgetc(dlb *dp);
00093         long rsrc_dlb_ftell(dlb *dp);
00094 #endif
00095 
00096 
00097 #else /* DLB */
00098 
00099 # define dlb FILE
00100 
00101 # define dlb_init()
00102 # define dlb_cleanup()
00103 
00104 # define dlb_fopen      fopen
00105 # define dlb_fclose     fclose
00106 # define dlb_fread      fread
00107 # define dlb_fseek      fseek
00108 # define dlb_fgets      fgets
00109 # define dlb_fgetc      fgetc
00110 # define dlb_ftell      ftell
00111 
00112 #endif /* DLB */
00113 
00114 
00115 /* various other I/O stuff we don't want to replicate everywhere */
00116 
00117 #ifndef SEEK_SET
00118 # define SEEK_SET 0
00119 #endif
00120 #ifndef SEEK_CUR
00121 # define SEEK_CUR 1
00122 #endif
00123 #ifndef SEEK_END
00124 # define SEEK_END 2
00125 #endif
00126 
00127 #define RDTMODE "r"
00128 #if (defined(MSDOS) || defined(WIN32) || defined(TOS) || defined(OS2)) && defined(DLB)
00129 #define WRTMODE "w+b"
00130 #else
00131 #define WRTMODE "w+"
00132 #endif
00133 #if (defined(MICRO) && !defined(AMIGA)) || defined(THINK_C) || defined(__MWERKS__) || defined(WIN32)
00134 # define RDBMODE "rb"
00135 # define WRBMODE "w+b"
00136 #else
00137 # define RDBMODE "r"
00138 # define WRBMODE "w+"
00139 #endif
00140 
00141 #endif  /* DLB_H */