Changeset 302 for cpp/frams/virtfile/virtfile.cpp
- Timestamp:
- 01/20/15 10:24:05 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/virtfile/virtfile.cpp
r301 r302 12 12 VirtFileSystem *VirtFILE::vfs = NULL; 13 13 14 //#define DEBUG_ DLL_CALLS15 16 VirtFILE *Vfopen(const char* path, const char* mode)17 { 18 #ifdef DEBUG_ DLL_CALLS19 printf("VirtFILE::Vfopen %s %s (vfs=%p)\n",path,mode,VirtFILE::vfs);20 #endif 21 return VirtFILE::vfs ? VirtFILE::vfs->Vfopen(path,mode) : NULL;14 //#define DEBUG_VIRTFILE 15 16 VirtFILE *Vfopen(const char* path, const char* mode) 17 { 18 #ifdef DEBUG_VIRTFILE 19 printf("VirtFILE::Vfopen %s %s (vfs=%p)\n",path,mode,VirtFILE::vfs); 20 #endif 21 return VirtFILE::vfs ? VirtFILE::vfs->Vfopen(path, mode) : NULL; 22 22 } 23 23 24 24 VirtDIR *Vopendir(const char* path) 25 25 { 26 #ifdef DEBUG_ DLL_CALLS27 printf("VirtFILE::Vfopendir %s (vfs=%p)\n",path,VirtFILE::vfs);28 #endif 29 return VirtFILE::vfs ? VirtFILE::vfs->Vopendir(path) : NULL;26 #ifdef DEBUG_VIRTFILE 27 printf("VirtFILE::Vfopendir %s (vfs=%p)\n",path,VirtFILE::vfs); 28 #endif 29 return VirtFILE::vfs ? VirtFILE::vfs->Vopendir(path) : NULL; 30 30 } 31 31 32 32 bool Vfexists(const char* path) 33 33 { 34 return VirtFILE::vfs ? VirtFILE::vfs->Vfexists(path) : false;35 } 36 37 bool Vdirexists(const char* path, bool is_writable)38 { 39 return VirtFILE::vfs ? VirtFILE::vfs->Vdirexists(path,is_writable) : false;34 return VirtFILE::vfs ? VirtFILE::vfs->Vfexists(path) : false; 35 } 36 37 bool Vdirexists(const char* path, bool is_writable) 38 { 39 return VirtFILE::vfs ? VirtFILE::vfs->Vdirexists(path, is_writable) : false; 40 40 } 41 41 42 42 bool Vmkdir(const char* path) 43 43 { 44 return VirtFILE::vfs ? VirtFILE::vfs->Vmkdir(path) : false;44 return VirtFILE::vfs ? VirtFILE::vfs->Vmkdir(path) : false; 45 45 } 46 46 47 47 bool Vmkdirs(const char* path) 48 48 { 49 return VirtFILE::vfs ? VirtFILE::vfs->Vmkdirs(path) : false;49 return VirtFILE::vfs ? VirtFILE::vfs->Vmkdirs(path) : false; 50 50 } 51 51 … … 55 55 void VirtFILE::selectFileSystem(VirtFileSystem *s) 56 56 { 57 vfs=s;58 #ifdef DEBUG_ DLL_CALLS59 ::printf("VirtFILE::selectFileSystem: %p := %p\n",vfs,s);57 vfs = s; 58 #ifdef DEBUG_VIRTFILE 59 ::printf("VirtFILE::selectFileSystem: %p := %p\n",vfs,s); 60 60 #endif 61 61 } … … 63 63 int VirtFILE::Vprintf(const char *format, va_list args) 64 64 { 65 string s=ssprintf_va(format,args);66 return Vwrite(s.c_str(),1,s.size());65 string s = ssprintf_va(format, args); 66 return Vwrite(s.c_str(), 1, s.size()); 67 67 } 68 68 69 69 int VirtFILE::printf(const char *format, ...) 70 70 { 71 int ret; va_list argptr;72 va_start(argptr,format);73 ret=Vprintf(format,argptr);74 va_end(argptr);75 return ret;71 int ret; va_list argptr; 72 va_start(argptr, format); 73 ret = Vprintf(format, argptr); 74 va_end(argptr); 75 return ret; 76 76 } 77 77 78 78 int VirtFILE::getSize() 79 79 { 80 81 82 83 84 85 } 86 87 void VirtFILE::setVstdin(VirtFILE *f) { Vstdin=f;}88 void VirtFILE::setVstdout(VirtFILE *f) { Vstdout=f;}89 void VirtFILE::setVstderr(VirtFILE *f) { Vstderr=f;}90 VirtFILE* VirtFILE::getVstdin() { return Vstdin;}91 VirtFILE* VirtFILE::getVstdout() { return Vstdout;}92 VirtFILE* VirtFILE::getVstderr() { return Vstderr;}80 int saved_pos = Vtell(); 81 Vseek(0, SEEK_END); 82 int size = Vtell(); 83 Vseek(saved_pos, SEEK_SET); 84 return size; 85 } 86 87 void VirtFILE::setVstdin(VirtFILE *f) { Vstdin = f; } 88 void VirtFILE::setVstdout(VirtFILE *f) { Vstdout = f; } 89 void VirtFILE::setVstderr(VirtFILE *f) { Vstderr = f; } 90 VirtFILE* VirtFILE::getVstdin() { return Vstdin; } 91 VirtFILE* VirtFILE::getVstdout() { return Vstdout; } 92 VirtFILE* VirtFILE::getVstderr() { return Vstderr; } 93 93 ////////////////////////////////////////////////////////////////////////// 94 94 95 95 // base class only returns NULL/false/not supported - implementations perform the actual work 96 VirtFILE* VirtFileSystem::Vfopen(const char* path, const char* mode) {return NULL;}97 bool VirtFileSystem::Vfexists(const char* path) { return false;}98 VirtDIR* VirtFileSystem::Vopendir(const char* path) { return NULL;}99 bool VirtFileSystem::Vmkdir(const char* path) { return false;}100 bool VirtFileSystem::Vdirexists(const char* path, bool is_writable) {return false;}96 VirtFILE* VirtFileSystem::Vfopen(const char* path, const char* mode) { return NULL; } 97 bool VirtFileSystem::Vfexists(const char* path) { return false; } 98 VirtDIR* VirtFileSystem::Vopendir(const char* path) { return NULL; } 99 bool VirtFileSystem::Vmkdir(const char* path) { return false; } 100 bool VirtFileSystem::Vdirexists(const char* path, bool is_writable) { return false; } 101 101 102 102 ////////////////////////////////////////////////////////////////////////// … … 104 104 105 105 106 int fread(void *ptr, size_t size, size_t nmemb, VirtFILE* f) { return f->Vread(ptr,size,nmemb);}107 int fwrite(const void *ptr, size_t size, size_t nmemb, VirtFILE* f) { return f->Vwrite(ptr,size,nmemb);}106 int fread(void *ptr, size_t size, size_t nmemb, VirtFILE* f) { return f->Vread(ptr, size, nmemb); } 107 int fwrite(const void *ptr, size_t size, size_t nmemb, VirtFILE* f) { return f->Vwrite(ptr, size, nmemb); } 108 108 109 109 110 110 //since we want our own feof(VirtFILE*) function and some systems unfortunately define feof as a macro, we need to #undef it. Same as in virtfile.h 111 111 #if defined _MSC_VER || defined __CYGWIN__ || defined SHP || defined __ANDROID__ 112 113 112 #pragma push_macro("feof") 113 #undef feof 114 114 #endif 115 115 #if defined __BORLANDC__ //does not support #pragma push_macro/pop_macro 116 117 #endif 118 119 int feof(VirtFILE* f) { return f->Veof();}116 #undef feof 117 #endif 118 119 int feof(VirtFILE* f) { return f->Veof(); } 120 120 121 121 //...and then restore the original macro: 122 122 #if defined _MSC_VER || defined __CYGWIN__ || defined SHP || defined __ANDROID__ 123 123 #pragma pop_macro("feof") 124 124 #endif 125 125 #if defined __BORLANDC__ 126 127 #endif 128 129 130 int fputc(int c, VirtFILE* f) {return f->Vputc(c);}131 int fputs(const char *s, VirtFILE* f) {return f->Vputs(s);}132 int fgetc(VirtFILE* f) { return f->Vgetc();}133 int fseek(VirtFILE* f, long offset, int whence) {return f->Vseek(offset,whence);}134 int ftell(VirtFILE* f) { return f->Vtell();}135 void rewind(VirtFILE* f) { f->Vrewind();}136 int fflush(VirtFILE* f) { return f->Vflush();}137 char *fgets(char *s, int size, VirtFILE* f) { return f->Vgets(s,size);}138 int fprintf(VirtFILE* f, const char *format, ...)139 126 #define feof(__f) ((__f)->flags & _F_EOF) 127 #endif 128 129 130 int fputc(int c, VirtFILE* f) { return f->Vputc(c); } 131 int fputs(const char *s, VirtFILE* f) { return f->Vputs(s); } 132 int fgetc(VirtFILE* f) { return f->Vgetc(); } 133 int fseek(VirtFILE* f, long offset, int whence) { return f->Vseek(offset, whence); } 134 int ftell(VirtFILE* f) { return f->Vtell(); } 135 void rewind(VirtFILE* f) { f->Vrewind(); } 136 int fflush(VirtFILE* f) { return f->Vflush(); } 137 char *fgets(char *s, int size, VirtFILE* f) { return f->Vgets(s, size); } 138 int fprintf(VirtFILE* f, const char *format, ...) 139 { 140 140 int ret; va_list argptr; 141 va_start(argptr, format);142 ret =f->Vprintf(format,argptr);141 va_start(argptr, format); 142 ret = f->Vprintf(format, argptr); 143 143 va_end(argptr); 144 144 return ret; 145 146 int fclose(VirtFILE* f) { delete f; return 0;}147 148 int closedir(VirtDIR* d) { delete d; return 0;}149 dirent* readdir(VirtDIR* d) { return d->Vreaddir();}145 } 146 int fclose(VirtFILE* f) { delete f; return 0; } 147 148 int closedir(VirtDIR* d) { delete d; return 0; } 149 dirent* readdir(VirtDIR* d) { return d->Vreaddir(); } 150 150 151 151 ///////// … … 153 153 bool VirtFileSystem::Vmkdirs(const char* path) 154 154 { 155 if (Vdirexists(path,true)) return true;156 string parentdir = getFileDir(path);157 if (!Vmkdirs(parentdir.c_str())) return false;158 return Vmkdir(path);155 if (Vdirexists(path, true)) return true; 156 string parentdir = getFileDir(path); 157 if (!Vmkdirs(parentdir.c_str())) return false; 158 return Vmkdir(path); 159 159 } 160 160 … … 164 164 ChainFileSystem::ChainFileSystem(VirtFileSystem *_chain) 165 165 { 166 chain =_chain;167 #ifdef DEBUG_ DLL_CALLS168 printf("ChainFileSystem constructor: %p := %p\n",chain,_chain);166 chain = _chain; 167 #ifdef DEBUG_VIRTFILE 168 printf("ChainFileSystem constructor: %p := %p\n",chain,_chain); 169 169 #endif 170 170 } … … 173 173 VirtFILE *ChainFileSystem::Vfopen(const char* path, const char* mode) 174 174 { 175 #ifdef DEBUG_ DLL_CALLS176 printf("ChainFileSystem::Vfopen %s %s (chain=%p)\n",path,mode,chain);175 #ifdef DEBUG_VIRTFILE 176 printf("ChainFileSystem::Vfopen %s %s (chain=%p)\n",path,mode,chain); 177 177 #endif 178 178 return (chain != NULL) ? chain->Vfopen(path, mode) : NULL; … … 186 186 VirtDIR *ChainFileSystem::Vopendir(const char* path) 187 187 { 188 #ifdef DEBUG_ DLL_CALLS189 printf("ChainFileSystem::Vfopendir %s (chain=%p)\n",path,chain);188 #ifdef DEBUG_VIRTFILE 189 printf("ChainFileSystem::Vfopendir %s (chain=%p)\n",path,chain); 190 190 #endif 191 191 return (chain != NULL) ? chain->Vopendir(path) : NULL; … … 202 202 } 203 203 204 bool ChainFileSystem::Vdirexists(const char* path, bool is_writable)205 { 206 return (chain != NULL) ? chain->Vdirexists(path, is_writable) : false;207 } 204 bool ChainFileSystem::Vdirexists(const char* path, bool is_writable) 205 { 206 return (chain != NULL) ? chain->Vdirexists(path, is_writable) : false; 207 }
Note: See TracChangeset
for help on using the changeset viewer.