Source:NetHack 3.4.3/include/dlb.h

From NetHackWiki
Jump to: navigation, search

Below is the full text to include/dlb.h from NetHack 3.4.3. To link to a particular line, write [[dlb.h#line123]], for example.

  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. */

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