FILE.H 9.3 KB

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