FILEINFO.CPP 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 - Fileio information functions. *
  23. * *
  24. * File Name : FILE.CPP *
  25. * *
  26. * Programmer : Scott K. Bowen *
  27. * *
  28. * Start Date : September 13, 1993 *
  29. * *
  30. * Last Update : April 19, 1994 [SKB] *
  31. * *
  32. *-------------------------------------------------------------------------*
  33. * Functions: *
  34. * Get_DOS_Handle -- Fetches system specific DOS file handle. *
  35. * Find_Disk_Number -- Determine disk a file resides upon. *
  36. * Set_File_Flags -- Sets flags for file if FileData table. *
  37. * Get_File_Flags -- Gets the flags on a file in the FileData table. *
  38. * Free_Handles -- Returns number of free file handles in WW system. *
  39. * Multi_Drive_Search -- Turns Multi search drive on and off. *
  40. * Clear_File_Flags -- Clears flags specified for file. *
  41. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  42. #ifndef WWSTD_H
  43. #include "wwstd.h"
  44. #endif
  45. #ifndef _FILE_H
  46. #include "_file.h"
  47. #endif
  48. /*=========================================================================*/
  49. /* The following PRIVATE functions are in this file: */
  50. /*=========================================================================*/
  51. /*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
  52. /***************************************************************************
  53. * GET_DOS_HANDLE -- Fetches system specific DOS file handle. *
  54. * *
  55. * This routine will return with the system specific DOS file handle. *
  56. * On the IBM, this is a WORD, on the Amiga, it is a LONG (BPTR). Use *
  57. * this routine with caution, because the value returned is NOT *
  58. * portable. *
  59. * *
  60. * INPUT: fh -- Westwood file system handle. *
  61. * *
  62. * OUTPUT: Returns with the system DOS file handle (WORD or LONG). *
  63. * *
  64. * WARNINGS: If you pass in an invalid file handle, or a file handle *
  65. * that references a resident file, then the ERROR code is *
  66. * returned. Be SURE to check for this. *
  67. * *
  68. * HISTORY: *
  69. * 08/21/1991 JLB : Created. *
  70. * 11/09/1991 JLB : Checks for illegal file handle passed in. *
  71. *=========================================================================*/
  72. WORD cdecl Get_DOS_Handle(WORD fh)
  73. {
  74. /*
  75. ** If an illegal file handle is passed in then always abort.
  76. */
  77. if (fh >= 0 && fh < TABLE_MAX) {
  78. if (!FileHandleTable[fh].Empty || FileHandleTable[fh].Handle) {
  79. return(FileHandleTable[fh].Handle);
  80. }
  81. /*
  82. ** If it falls through here, then the file must be resident. It is
  83. ** illegal to get a DOS handle to a resident file.
  84. */
  85. }
  86. return(FILEOPENERROR);
  87. }
  88. /***************************************************************************
  89. * FREE_HANDLES -- Returns number of free file handles in WW system. *
  90. * *
  91. * INPUT: NONE. *
  92. * *
  93. * OUTPUT: NONE. *
  94. * *
  95. * WARNINGS: *
  96. * *
  97. * HISTORY: *
  98. * 09/13/1993 SKB : Created. *
  99. *=========================================================================*/
  100. WORD cdecl Free_Handles(VOID)
  101. {
  102. WORD count; // Count of the number of free file handles.
  103. WORD index; // Working file handle index var.
  104. count = 0;
  105. for (index = 0; index < TABLE_MAX; index++) {
  106. if (FileHandleTable[index].Empty) count++;
  107. }
  108. return(count);
  109. }
  110. /***************************************************************************
  111. * FIND_DISK_NUMBER -- Determine disk a file resides upon. *
  112. * *
  113. * This routine will determine the disk number that the specified *
  114. * file resides upon. It determines this by scanning through the *
  115. * FileData table. If the specified file is a packed file, then it *
  116. * will reference the parent packed file to determine the disk number. *
  117. * *
  118. * INPUT: file_name -- Pointer to the file name to check. *
  119. * *
  120. * OUTPUT: Returns with the disk number that the file resides upon. If *
  121. * ERROR is returned, then the file does not exist in the *
  122. * FileTable. The number returned is 0=A, 1=B, etc. *
  123. * *
  124. * WARNINGS: none *
  125. * *
  126. * HISTORY: *
  127. * 11/22/1991 JLB : Created. *
  128. *=========================================================================*/
  129. WORD cdecl Find_Disk_Number(BYTE const *file_name)
  130. {
  131. FileDataType *filedata; // Pointer to the current FileData.
  132. WORD index; // FileTable index.
  133. index = Find_File_Index(file_name);
  134. if (index != ERROR) {
  135. filedata = &FileDataPtr[index];
  136. if (filedata->Flag & FILEF_PACKED) {
  137. return (Find_Disk_Number(FileDataPtr[filedata->Disk].Name));
  138. }
  139. return(filedata->Disk);
  140. }
  141. return (index);
  142. }
  143. /***************************************************************************
  144. * SET_FILE_FLAGS -- Sets flags for file if FileData table. *
  145. * *
  146. * INPUT: BYTE *filename - file to modify. *
  147. * WORD flags - flags to set in file. *
  148. * *
  149. * OUTPUT: WORD - if file found in FileData table. *
  150. * *
  151. * WARNINGS: *
  152. * *
  153. * HISTORY: *
  154. * 10/04/1993 SKB : Created. *
  155. *=========================================================================*/
  156. WORD cdecl Set_File_Flags(BYTE const *filename, WORD flags)
  157. {
  158. FileDataType *filedata; // Pointer to the current FileData.
  159. WORD index; // FileTable index.
  160. index = Find_File_Index(filename);
  161. if (index != ERROR) {
  162. filedata = &FileDataPtr[index];
  163. filedata->Flag |= flags;
  164. return (TRUE);
  165. }
  166. return (FALSE);
  167. }
  168. /***************************************************************************
  169. * CLEAR_FILE_FLAGS -- Clears flags specified for file. *
  170. * *
  171. * INPUT: BYTE *filename - file to modify. *
  172. * WORD flags - flags to set in file. *
  173. * *
  174. * OUTPUT: WORD - if file found in FileData table. *
  175. * *
  176. * WARNINGS: *
  177. * *
  178. * HISTORY: *
  179. * 04/19/1994 SKB : Created. *
  180. *=========================================================================*/
  181. WORD cdecl Clear_File_Flags(BYTE const *filename, WORD flags)
  182. {
  183. FileDataType *filedata; // Pointer to the current FileData.
  184. WORD index; // FileTable index.
  185. index = Find_File_Index(filename);
  186. if (index != ERROR) {
  187. filedata = &FileDataPtr[index];
  188. filedata->Flag &= ~flags;
  189. return (TRUE);
  190. }
  191. return (FALSE);
  192. }
  193. /***************************************************************************
  194. * GET_FILE_FLAGS -- Gets the flags on a file in the FileData table. *
  195. * *
  196. * *
  197. * INPUT: BYTE *filename - file to modify. *
  198. * *
  199. * OUTPUT: *
  200. * *
  201. * OUTPUT: WORD - if file found in FileData table. *
  202. * *
  203. * HISTORY: *
  204. * 10/04/1993 SKB : Created. *
  205. *=========================================================================*/
  206. WORD cdecl Get_File_Flags(BYTE const *filename)
  207. {
  208. FileDataType *filedata; // Pointer to the current FileData.
  209. WORD index; // FileTable index.
  210. index = Find_File_Index(filename);
  211. if (index != ERROR) {
  212. filedata = &FileDataPtr[index];
  213. return (filedata->Flag);
  214. }
  215. return (FALSE);
  216. }
  217. /***************************************************************************
  218. * MULTI_DRIVE_SEARCH -- Turns Multi search drive on and off. *
  219. * *
  220. * *
  221. * *
  222. * INPUT: *
  223. * *
  224. * OUTPUT: *
  225. * *
  226. * WARNINGS: *
  227. * *
  228. * HISTORY: *
  229. * 09/13/1993 SKB : Created. *
  230. *=========================================================================*/
  231. BOOL cdecl Multi_Drive_Search(BOOL on)
  232. {
  233. BOOL old;
  234. Hard_Error_Occured = 0;
  235. old = MultiDriveSearch;
  236. MultiDriveSearch = on;
  237. return(old);
  238. }