FILE.H 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. #define READ 1 // Read access.
  49. #define WRITE 2 // Write access.
  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. short cdecl Open_File(char const *file_name, short mode);
  155. void cdecl Close_File(short handle);
  156. LONG cdecl Read_File(short handle, void *buf, unsigned long bytes);
  157. LONG cdecl Write_File(short handle, void const *buf, unsigned long bytes);
  158. unsigned long cdecl Seek_File(short handle, LONG offset, short starting);
  159. short cdecl File_Exists(char const *file_name);
  160. unsigned long cdecl File_Size(short handle);
  161. BOOL cdecl Is_Handle_Valid(short handle, FileErrorType error, char const *name);
  162. short cdecl Open_File_With_Recovery( char const *file_name, unsigned short mode );
  163. /*=========================================================================*/
  164. /* The following prototypes are for the file: FILECACH.CPP */
  165. /*=========================================================================*/
  166. void Unfragment_File_Cache(void);
  167. BOOL cdecl Make_File_Resident(char const *filename);
  168. short cdecl Flush_Unused_File_Cache(short flush_keeps);
  169. BOOL cdecl Free_Resident_File(char const *file);
  170. /*=========================================================================*/
  171. /* The following prototypes are for the file: FILECHNG.CPP */
  172. /*=========================================================================*/
  173. short cdecl Create_File(char const *file_name);
  174. short cdecl Delete_File(char const *file_name);
  175. BOOL cdecl Change_File_Size(short handle, unsigned long new_size);
  176. /*=========================================================================*/
  177. /* The following prototypes are for the file: FILEINFO.CPP */
  178. /*=========================================================================*/
  179. short cdecl Get_DOS_Handle(short fh);
  180. short cdecl Free_Handles(void);
  181. short cdecl Find_Disk_Number(char const *file_name);
  182. short cdecl Set_File_Flags(char const *filename, short flags);
  183. short cdecl Clear_File_Flags(char const *filename, short flags);
  184. short cdecl Get_File_Flags(char const *filename);
  185. BOOL cdecl Multi_Drive_Search(BOOL on);
  186. /*=========================================================================*/
  187. /* The following prototypes are for the file: FINDFILE.CPP */
  188. /*=========================================================================*/
  189. short cdecl Find_File(char const *file_name);
  190. short cdecl Find_File_Index(char const *filename);
  191. /*=========================================================================*/
  192. /* The following prototypes are for the file: FFIRST.ASM */
  193. /*=========================================================================*/
  194. #include <dos.h>
  195. #ifdef __cplusplus
  196. extern "C" {
  197. #endif
  198. extern short Find_First(unsigned char *fname, unsigned short mode, struct find_t *ffblk);
  199. extern short Find_Next(struct find_t *ffblk);
  200. #ifdef __cplusplus
  201. }
  202. #endif
  203. #endif // FILE_H
  204.