[121] | 1 | // This file is a part of the Framsticks GDK. |
---|
| 2 | // Copyright (C) 2002-2014 Maciej Komosinski and Szymon Ulatowski. See LICENSE.txt for details. |
---|
[109] | 3 | // Refer to http://www.framsticks.com/ for further information. |
---|
| 4 | |
---|
| 5 | #ifndef _VIRTFILE_H_ |
---|
| 6 | #define _VIRTFILE_H_ |
---|
| 7 | |
---|
| 8 | #include <stdio.h> |
---|
| 9 | #include <stdarg.h> |
---|
| 10 | #include <common/nonstd_dir.h> |
---|
| 11 | //#include <dirent.h> //to jest inkludowane przez powyzsze |
---|
| 12 | //struct dirent; //kiedys byla ta linia jak nie bylo jeszcze implementacji windowsowej dirent, ale borlandowi sie nie podoba jak s¹ obie |
---|
| 13 | |
---|
| 14 | #ifdef DLLEXPORTACTIVE //tylko w tym pliku uzyte |
---|
| 15 | #define DLLEXP __declspec(dllexport) |
---|
| 16 | #else |
---|
| 17 | #define DLLEXP |
---|
| 18 | #endif |
---|
| 19 | |
---|
| 20 | class DLLEXP VirtFileSystem; |
---|
| 21 | |
---|
| 22 | class DLLEXP VirtFILE |
---|
| 23 | { |
---|
| 24 | public: |
---|
| 25 | virtual int Vread(void *ptr, size_t size, size_t nmemb)=0; |
---|
| 26 | virtual int Vwrite(const void *ptr, size_t size, size_t nmemb)=0; |
---|
| 27 | virtual int Veof()=0; |
---|
| 28 | virtual int Vputc(int c)=0; |
---|
| 29 | virtual int Vputs(const char *s)=0; |
---|
| 30 | virtual int Vgetc()=0; |
---|
| 31 | virtual int Vseek(long offset, int whence)=0; |
---|
| 32 | virtual int Vtell()=0; |
---|
| 33 | virtual void Vrewind()=0; |
---|
| 34 | virtual int Vflush()=0; |
---|
| 35 | virtual char *Vgets(char *s, int size)=0; |
---|
| 36 | virtual int Vprintf(const char *format, va_list args)=0; |
---|
| 37 | int printf(const char *format, ...); |
---|
| 38 | virtual const char *VgetPath() {return 0;} // 0=unspecified path |
---|
| 39 | virtual ~VirtFILE(); |
---|
| 40 | static VirtFILE *Vstdin,*Vstdout,*Vstderr; |
---|
| 41 | static void setVstdin(VirtFILE *); |
---|
| 42 | static void setVstdout(VirtFILE *); |
---|
| 43 | static void setVstderr(VirtFILE *); |
---|
| 44 | static VirtFILE* getVstdin(); |
---|
| 45 | static VirtFILE* getVstdout(); |
---|
| 46 | static VirtFILE* getVstderr(); |
---|
| 47 | static VirtFileSystem *vfs; |
---|
| 48 | static void selectFileSystem(VirtFileSystem *s); |
---|
| 49 | }; |
---|
| 50 | |
---|
| 51 | class DLLEXP VirtDIR |
---|
| 52 | { |
---|
| 53 | public: |
---|
| 54 | virtual ~VirtDIR() {} |
---|
| 55 | virtual dirent* Vreaddir() {return 0;} |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | class DLLEXP VirtFileSystem |
---|
| 59 | { |
---|
| 60 | public: |
---|
| 61 | virtual VirtFILE *Vfopen(const char* path,const char*mode); |
---|
| 62 | virtual int Vfexists(const char* path); |
---|
| 63 | virtual VirtDIR *Vopendir(const char* path); |
---|
| 64 | }; |
---|
| 65 | |
---|
| 66 | DLLEXP VirtFILE *Vfopen(const char* path,const char*mode); |
---|
| 67 | DLLEXP VirtDIR *Vopendir(const char* path); |
---|
| 68 | DLLEXP int Vfexists(const char* path); |
---|
| 69 | |
---|
| 70 | DLLEXP int fread(void *ptr, size_t size, size_t nmemb, VirtFILE* f); |
---|
| 71 | DLLEXP int fwrite(const void *ptr, size_t size, size_t nmemb, VirtFILE* f); |
---|
[123] | 72 | |
---|
| 73 | |
---|
[131] | 74 | //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.cpp |
---|
| 75 | #if defined _MSC_VER || defined __CYGWIN__ || defined SHP |
---|
| 76 | #pragma push_macro("feof") |
---|
[123] | 77 | #undef feof |
---|
| 78 | #endif |
---|
[131] | 79 | #if defined __BORLANDC__ //does not support #pragma push_macro/pop_macro |
---|
| 80 | #undef feof |
---|
| 81 | #endif |
---|
[123] | 82 | |
---|
| 83 | DLLEXP int feof(VirtFILE* f);// {return f->Veof();} |
---|
| 84 | |
---|
| 85 | //...and then restore the original macro: |
---|
[131] | 86 | #if defined _MSC_VER || defined __CYGWIN__ || defined SHP |
---|
| 87 | #pragma pop_macro("feof") |
---|
| 88 | #endif |
---|
[109] | 89 | #ifdef __BORLANDC__ |
---|
[123] | 90 | #define feof(__f) ((__f)->flags & _F_EOF) |
---|
[109] | 91 | #endif |
---|
| 92 | |
---|
[123] | 93 | |
---|
[109] | 94 | DLLEXP int fputc(int c,VirtFILE* f); |
---|
| 95 | DLLEXP int fputs(const char *s,VirtFILE* f); |
---|
| 96 | DLLEXP int fgetc(VirtFILE* f); |
---|
| 97 | DLLEXP int fseek(VirtFILE* f,long offset, int whence); |
---|
| 98 | DLLEXP int ftell(VirtFILE* f); |
---|
| 99 | DLLEXP void rewind(VirtFILE* f); |
---|
| 100 | DLLEXP int fflush(VirtFILE* f); |
---|
| 101 | DLLEXP char *fgets(char *s, int size, VirtFILE* f); |
---|
| 102 | DLLEXP int fprintf(VirtFILE* f,const char *format, ...); |
---|
| 103 | DLLEXP int fclose(VirtFILE* f); |
---|
| 104 | |
---|
| 105 | DLLEXP dirent* readdir(VirtDIR* d); |
---|
| 106 | DLLEXP int closedir(VirtDIR* d); |
---|
| 107 | |
---|
| 108 | #endif |
---|
| 109 | |
---|