FILE.H 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /***************************************************************************
  15. ** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
  16. ***************************************************************************
  17. * *
  18. * Project Name : Library - Filio header stuff. *
  19. * *
  20. * File Name : FILE.H *
  21. * *
  22. * Programmer : Scott K. Bowen *
  23. * *
  24. * Start Date : September 13, 1993 *
  25. * *
  26. * Last Update : April 11, 1994 *
  27. * *
  28. *-------------------------------------------------------------------------*
  29. * Functions: *
  30. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  31. #ifndef FILE_H
  32. #define FILE_H
  33. #ifndef FILETEMP_H
  34. // This should be removed once the library is all intacked.
  35. #include "filetemp.h"
  36. #endif
  37. /*=========================================================================*/
  38. /* File IO system defines and enumerations */
  39. /*=========================================================================*/
  40. #define XMAXPATH 80
  41. /*
  42. ** These are the Open_File, Read_File, and Seek_File constants.
  43. */
  44. #ifndef READ
  45. #define READ 1 // Read access.
  46. #endif
  47. #ifndef WRITE
  48. #define WRITE 2 // Write access.
  49. #endif
  50. #ifndef SEEK_SET
  51. #define SEEK_SET 0 // Seek from start of file.
  52. #define SEEK_CUR 1 // Seek relative from current location.
  53. #define SEEK_END 2 // Seek from end of file.
  54. #endif
  55. typedef enum {
  56. FILEB_PROCESSED=8,// Was the packed file header of this file processed?
  57. FILEB_PRELOAD, // Scan for and make file resident at WWDOS_Init time?
  58. FILEB_RESIDENT, // Make resident at Open_File time?
  59. FILEB_FLUSH, // Un-resident at Close_File time?
  60. FILEB_PACKED, // Is this file packed?
  61. FILEB_KEEP, // Don't ever flush this resident file?
  62. FILEB_PRIORITY, // Flush this file last?
  63. FILEB_LAST
  64. } FileFlags_Type;
  65. #define FILEF_NONE 0
  66. #define FILEF_PROCESSED (1<<FILEB_PROCESSED)
  67. #define FILEF_PRELOAD (1<<FILEB_PRELOAD)
  68. #define FILEF_RESIDENT (1<<FILEB_RESIDENT)
  69. #define FILEF_FLUSH (1<<FILEB_FLUSH)
  70. #define FILEF_PACKED (1<<FILEB_PACKED)
  71. #define FILEF_KEEP (1<<FILEB_KEEP)
  72. #define FILEF_PRIORITY (1<<FILEB_PRIORITY)
  73. /*
  74. ** These errors are returned by WWDOS_Init(). All errors encountered are
  75. ** or'd together so there may be more then one error returned. Not all
  76. ** errors are fatal, such as the cache errors.
  77. */
  78. typedef enum {
  79. FI_SUCCESS = 0x00,
  80. FI_CACHE_TOO_BIG = 0x01,
  81. FI_CACHE_ALREADY_INIT = 0x02,
  82. FI_FILEDATA_FILE_NOT_FOUND = 0x04,
  83. FI_FILEDATA_TOO_BIG = 0x08,
  84. FI_SEARCH_PATH_NOT_FOUND = 0x10,
  85. FI_STARTUP_PATH_NOT_FOUND = 0x20,
  86. FI_NO_CACHE_FOR_PRELOAD = 0x40,
  87. FI_FILETABLE_NOT_INIT = 0x80,
  88. } FileInitErrorType;
  89. /*
  90. ** These are the errors that are detected by the File I/O system and
  91. ** passed to the io error routine.
  92. */
  93. //lint -strong(AJX,FileErrorType)
  94. typedef enum {
  95. CANT_CREATE_FILE,
  96. BAD_OPEN_MODE,
  97. COULD_NOT_OPEN,
  98. TOO_MANY_FILES,
  99. CLOSING_NON_HANDLE,
  100. READING_NON_HANDLE,
  101. WRITING_NON_HANDLE,
  102. SEEKING_NON_HANDLE,
  103. SEEKING_BAD_OFFSET,
  104. WRITING_RESIDENT,
  105. UNKNOWN_INDEX,
  106. DID_NOT_CLOSE,
  107. FATAL_ERROR,
  108. FILE_NOT_LISTED,
  109. FILE_LENGTH_MISMATCH,
  110. INTERNAL_ERROR,
  111. MAKE_RESIDENT_ZERO_SIZE,
  112. RESIDENT_SORT_FAILURE,
  113. NUMBER_OF_ERRORS /* MAKE SURE THIS IS THE LAST ENTRY */
  114. } FileErrorType;
  115. // This is here tempararaly until library is put together.
  116. //extern WORD __cdecl ( __cdecl IO_Error)(FileErrorType error, BYTE const *filename);
  117. extern short (*Open_Error)(FileErrorType, BYTE const *);
  118. /*=========================================================================*/
  119. /* File IO system structures */
  120. /*=========================================================================*/
  121. //lint -strong(AJX,FileDataType)
  122. typedef struct {
  123. char *Name; // File name (include sub-directory but not volume).
  124. long Size; // File size (0=indeterminate).
  125. void *Ptr; // Resident file pointer.
  126. long Start; // Starting offset in DOS handle file.
  127. unsigned char Disk; // Disk number location.
  128. unsigned char OpenCount; // Count of open locks on resident file.
  129. unsigned short Flag; // File control flags.
  130. } FileDataType;
  131. /*=========================================================================*/
  132. /* FIle IO system globals. */
  133. /*=========================================================================*/
  134. // These are cpp errors in funtions declarations JULIO JEREZ
  135. // extern FileDataType __cdecl FileData[];
  136. // extern BYTE __cdecl ExecPath[XMAXPATH + 1];
  137. // extern BYTE __cdecl DataPath[XMAXPATH + 1];
  138. // extern BYTE __cdecl StartPath[XMAXPATH + 1];
  139. // extern BOOL __cdecl UseCD;
  140. // The correct syntax is NO TYPE MODIFIER APPLY TO DATA DECLARATIONS
  141. extern FileDataType FileData[];
  142. extern char ExecPath[XMAXPATH + 1];
  143. extern char DataPath[XMAXPATH + 1];
  144. extern char StartPath[XMAXPATH + 1];
  145. extern BOOL UseCD;
  146. /*=========================================================================*/
  147. /* The following prototypes are for the file: FILEINIT.CPP */
  148. /*=========================================================================*/
  149. void __cdecl WWDOS_Shutdown(void);
  150. FileInitErrorType __cdecl WWDOS_Init(unsigned long cachesize, char *filedata, char *cdpath);
  151. /*=========================================================================*/
  152. /* The following prototypes are for the file: FILE.CPP */
  153. /*=========================================================================*/
  154. int __cdecl Open_File(char const *file_name, int mode);
  155. void __cdecl Close_File(int handle);
  156. long __cdecl Read_File(int handle, void *buf, unsigned long bytes);
  157. int __cdecl Load_File ( const char *file_name , void *load_addr);
  158. long __cdecl Write_File(int handle, void const *buf, unsigned long bytes);
  159. unsigned long __cdecl Seek_File(int handle, long offset, int starting);
  160. int __cdecl File_Exists(char const *file_name);
  161. unsigned long __cdecl File_Size(int handle);
  162. BOOL __cdecl Is_Handle_Valid(int handle, FileErrorType error, char const *name);
  163. int __cdecl Open_File_With_Recovery( char const *file_name, unsigned int mode );
  164. /*=========================================================================*/
  165. /* The following prototypes are for the file: FILECACH.CPP */
  166. /*=========================================================================*/
  167. void Unfragment_File_Cache(void);
  168. BOOL __cdecl Make_File_Resident(char const *filename);
  169. int __cdecl Flush_Unused_File_Cache(int flush_keeps);
  170. BOOL __cdecl Free_Resident_File(char const *file);
  171. /*=========================================================================*/
  172. /* The following prototypes are for the file: FILECHNG.CPP */
  173. /*=========================================================================*/
  174. int __cdecl Create_File(char const *file_name);
  175. int __cdecl Delete_File(char const *file_name);
  176. BOOL __cdecl Change_File_Size(int handle, unsigned long new_size);
  177. /*=========================================================================*/
  178. /* The following prototypes are for the file: FILEINFO.CPP */
  179. /*=========================================================================*/
  180. int __cdecl Get_DOS_Handle(int fh);
  181. int __cdecl Free_Handles(void);
  182. int __cdecl Find_Disk_Number(char const *file_name);
  183. int __cdecl Set_File_Flags(char const *filename, int flags);
  184. int __cdecl Clear_File_Flags(char const *filename, int flags);
  185. int __cdecl Get_File_Flags(char const *filename);
  186. BOOL __cdecl Multi_Drive_Search(BOOL on);
  187. /*=========================================================================*/
  188. /* The following prototypes are for the file: FINDFILE.CPP */
  189. /*=========================================================================*/
  190. int __cdecl Find_File(char const *file_name);
  191. int __cdecl Find_File_Index(char const *filename);
  192. /*=========================================================================*/
  193. /* The following prototypes are for the file: FFIRST.ASM */
  194. /*=========================================================================*/
  195. #include <dos.h>
  196. #ifdef __cplusplus
  197. extern "C" {
  198. #endif
  199. extern int __cdecl Find_First(unsigned char *fname, unsigned int mode, struct find_t *ffblk);
  200. extern int __cdecl Find_Next(struct find_t *ffblk);
  201. #ifdef __cplusplus
  202. }
  203. #endif
  204. #endif