Subversion Repositories Games.Carmageddon

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include "file.h"
  2. #include "CORE/FW/fwsetup.h"
  3. #include "CORE/FW/resource.h"
  4. #include "CORE/FW/scratch.h"
  5. #include "CORE/STD/brstdlib.h"
  6. #include "harness/trace.h"
  7. #include <stdarg.h>
  8. #include <stddef.h>
  9. #ifdef BRENDER_FIX_BUGS
  10. #include <ctype.h>
  11. #include <string.h>
  12. #endif
  13.  
  14. // IDA: void __cdecl _BrFileFree(void *res, br_uint_8 res_class, br_size_t size)
  15. void _BrFileFree(void* res, br_uint_8 res_class, br_size_t size) {
  16.     br_file* file;
  17.  
  18.     file = (br_file*)res;
  19.     fw.fsys->close(file->raw_file);
  20. }
  21.  
  22. // IDA: br_uint_32 __cdecl BrFileAttributes()
  23. br_uint_32 BrFileAttributes(void) {
  24.     LOG_TRACE("()");
  25.  
  26.     return fw.fsys->attributes();
  27. }
  28.  
  29. // IDA: void* __cdecl BrFileOpenRead(char *name, br_size_t n_magics, br_mode_test_cbfn *mode_test, int *mode_result)
  30. void* BrFileOpenRead(char* name, br_size_t n_magics, br_mode_test_cbfn* mode_test, int* mode_result) {
  31.     void* raw_file;
  32.     br_file* file;
  33.     int bin_mode;
  34. #ifdef BRENDER_FIX_BUGS
  35.     char *s;
  36. #endif
  37.     LOG_TRACE("(\"%s\", %d, %p, %p)", name, n_magics, mode_test, mode_result);
  38.  
  39.     bin_mode = 0;
  40.     if (mode_result != NULL) {
  41.         raw_file = fw.fsys->open_read(name, n_magics, mode_test, mode_result);
  42.     } else {
  43.         raw_file = fw.fsys->open_read(name, n_magics, mode_test, &bin_mode);
  44.     }
  45.  
  46.     if (raw_file == NULL) {
  47.         return NULL;
  48.     }
  49.     file = BrResAllocate(fw.res, sizeof(br_file) + BrStrLen(name) + 1, BR_MEMORY_FILE);
  50.  
  51.     file->writing = 0;
  52.     if (mode_result != 0) {
  53.         file->mode = *mode_result;
  54.     } else {
  55.         file->mode = 0;
  56.     }
  57.     file->raw_file = raw_file;
  58.     BrStrCpy(file->name, name);
  59.     return file;
  60. }
  61.  
  62. // IDA: void* __cdecl BrFileOpenWrite(char *name, int mode)
  63. void* BrFileOpenWrite(char* name, int mode) {
  64.     void* raw_file;
  65.     br_file* file;
  66.  
  67.     raw_file = fw.fsys->open_write(name, mode);
  68.     if (raw_file == NULL) {
  69.         return NULL;
  70.     }
  71.     file = BrResAllocate(fw.res, sizeof(br_file) + BrStrLen(name) + 1, BR_MEMORY_FILE);
  72.     file->writing = 1;
  73.     file->mode = mode;
  74.     file->raw_file = raw_file;
  75.     BrStrCpy(file->name, name);
  76.     return file;
  77. }
  78.  
  79. // IDA: void __cdecl BrFileClose(void *f)
  80. void BrFileClose(void* f) {
  81.     LOG_TRACE("(%p)", f);
  82.     BrResFree(f);
  83. }
  84.  
  85. // IDA: int __cdecl BrFileEof(void *f)
  86. int BrFileEof(void* f) {
  87.     return fw.fsys->eof(((br_file*)f)->raw_file);
  88. }
  89.  
  90. // IDA: int __cdecl BrFileGetChar(void *f)
  91. int BrFileGetChar(void* f) {
  92.     return fw.fsys->getchr(((br_file*)f)->raw_file);
  93. }
  94.  
  95. // IDA: void __cdecl BrFilePutChar(int c, void *f)
  96. void BrFilePutChar(int c, void* f) {
  97.     fw.fsys->putchr(c, ((br_file*)f)->raw_file);
  98. }
  99.  
  100. // IDA: int __cdecl BrFileRead(void *buf, int size, int n, void *f)
  101. int BrFileRead(void* buf, int size, int n, void* f) {
  102.     return fw.fsys->read(buf, size, n, ((br_file*)f)->raw_file);
  103. }
  104.  
  105. // IDA: int __cdecl BrFileWrite(void *buf, int size, int n, void *f)
  106. int BrFileWrite(void* buf, int size, int n, void* f) {
  107.     return fw.fsys->write(buf, size, n, ((br_file*)f)->raw_file);
  108. }
  109.  
  110. // IDA: int __cdecl BrFileGetLine(char *buf, br_size_t buf_len, void *f)
  111. int BrFileGetLine(char* buf, br_size_t buf_len, void* f) {
  112.     return fw.fsys->getline(buf, buf_len, ((br_file*)f)->raw_file);
  113. }
  114.  
  115. // IDA: void __cdecl BrFilePutLine(char *buf, void *f)
  116. void BrFilePutLine(char* buf, void* f) {
  117.     fw.fsys->putline(buf, ((br_file*)f)->raw_file);
  118. }
  119.  
  120. // IDA: void __cdecl BrFileAdvance(long count, void *f)
  121. void BrFileAdvance(long count, void* f) {
  122.     fw.fsys->advance(count, ((br_file*)f)->raw_file);
  123. }
  124.  
  125. // IDA: int __cdecl BrFilePrintf(void *f, char *fmt, ...)
  126. int BrFilePrintf(void* f, char* fmt, ...) {
  127.     int n;
  128.     va_list args;
  129.     LOG_TRACE9("(%p, \"%s\")", f, fmt);
  130.  
  131.     va_start(args, fmt);
  132.     n = BrVSprintf(BrScratchString(), fmt, args);
  133.     va_end(args);
  134.     BrFileWrite(BrScratchString(), 1, n, f);
  135.     return n;
  136. }
  137.