[121] | 1 | // This file is a part of the Framsticks GDK. |
---|
[197] | 2 | // Copyright (C) 1999-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: |
---|
[247] | 25 | virtual size_t Vread(void *ptr, size_t size, size_t nmemb)=0; |
---|
| 26 | virtual size_t Vwrite(const void *ptr, size_t size, size_t nmemb)=0; |
---|
[109] | 27 | virtual int Veof()=0; |
---|
[211] | 28 | virtual int Vputc(int c) {unsigned char data=(unsigned char)c; return (Vwrite(&data,1,1)==1)?data:EOF;} |
---|
[109] | 29 | virtual int Vputs(const char *s)=0; |
---|
[206] | 30 | virtual int Vgetc() {unsigned char data; if (Vread(&data,1,1)==1) return data; else return EOF;} |
---|
[109] | 31 | virtual int Vseek(long offset, int whence)=0; |
---|
[247] | 32 | virtual long Vtell()=0; |
---|
[206] | 33 | virtual void Vrewind() {Vseek(0,SEEK_SET);} |
---|
[109] | 34 | virtual int Vflush()=0; |
---|
| 35 | virtual char *Vgets(char *s, int size)=0; |
---|
[206] | 36 | virtual int Vprintf(const char *format, va_list args); |
---|
[109] | 37 | int printf(const char *format, ...); |
---|
| 38 | virtual const char *VgetPath() {return 0;} // 0=unspecified path |
---|
[247] | 39 | virtual int getSize(); |
---|
[109] | 40 | virtual ~VirtFILE(); |
---|
| 41 | static VirtFILE *Vstdin,*Vstdout,*Vstderr; |
---|
| 42 | static void setVstdin(VirtFILE *); |
---|
| 43 | static void setVstdout(VirtFILE *); |
---|
| 44 | static void setVstderr(VirtFILE *); |
---|
| 45 | static VirtFILE* getVstdin(); |
---|
| 46 | static VirtFILE* getVstdout(); |
---|
| 47 | static VirtFILE* getVstderr(); |
---|
| 48 | static VirtFileSystem *vfs; |
---|
| 49 | static void selectFileSystem(VirtFileSystem *s); |
---|
| 50 | }; |
---|
| 51 | |
---|
| 52 | class DLLEXP VirtDIR |
---|
| 53 | { |
---|
| 54 | public: |
---|
| 55 | virtual ~VirtDIR() {} |
---|
| 56 | virtual dirent* Vreaddir() {return 0;} |
---|
| 57 | }; |
---|
| 58 | |
---|
| 59 | class DLLEXP VirtFileSystem |
---|
| 60 | { |
---|
| 61 | public: |
---|
| 62 | virtual VirtFILE *Vfopen(const char* path,const char*mode); |
---|
| 63 | virtual int Vfexists(const char* path); |
---|
| 64 | virtual VirtDIR *Vopendir(const char* path); |
---|
| 65 | }; |
---|
| 66 | |
---|
| 67 | DLLEXP VirtFILE *Vfopen(const char* path,const char*mode); |
---|
| 68 | DLLEXP VirtDIR *Vopendir(const char* path); |
---|
| 69 | DLLEXP int Vfexists(const char* path); |
---|
| 70 | |
---|
| 71 | DLLEXP int fread(void *ptr, size_t size, size_t nmemb, VirtFILE* f); |
---|
| 72 | DLLEXP int fwrite(const void *ptr, size_t size, size_t nmemb, VirtFILE* f); |
---|
[123] | 73 | |
---|
| 74 | |
---|
[131] | 75 | //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 |
---|
[225] | 76 | #if defined _MSC_VER || defined __CYGWIN__ || defined SHP || defined __ANDROID__ |
---|
[131] | 77 | #pragma push_macro("feof") |
---|
[123] | 78 | #undef feof |
---|
| 79 | #endif |
---|
[131] | 80 | #if defined __BORLANDC__ //does not support #pragma push_macro/pop_macro |
---|
| 81 | #undef feof |
---|
| 82 | #endif |
---|
[123] | 83 | |
---|
| 84 | DLLEXP int feof(VirtFILE* f);// {return f->Veof();} |
---|
| 85 | |
---|
| 86 | //...and then restore the original macro: |
---|
[225] | 87 | #if defined _MSC_VER || defined __CYGWIN__ || defined SHP || defined __ANDROID__ |
---|
[131] | 88 | #pragma pop_macro("feof") |
---|
| 89 | #endif |
---|
[225] | 90 | #if defined __BORLANDC__ |
---|
[123] | 91 | #define feof(__f) ((__f)->flags & _F_EOF) |
---|
[109] | 92 | #endif |
---|
| 93 | |
---|
[123] | 94 | |
---|
[109] | 95 | DLLEXP int fputc(int c,VirtFILE* f); |
---|
| 96 | DLLEXP int fputs(const char *s,VirtFILE* f); |
---|
| 97 | DLLEXP int fgetc(VirtFILE* f); |
---|
| 98 | DLLEXP int fseek(VirtFILE* f,long offset, int whence); |
---|
| 99 | DLLEXP int ftell(VirtFILE* f); |
---|
| 100 | DLLEXP void rewind(VirtFILE* f); |
---|
| 101 | DLLEXP int fflush(VirtFILE* f); |
---|
| 102 | DLLEXP char *fgets(char *s, int size, VirtFILE* f); |
---|
| 103 | DLLEXP int fprintf(VirtFILE* f,const char *format, ...); |
---|
| 104 | DLLEXP int fclose(VirtFILE* f); |
---|
| 105 | |
---|
| 106 | DLLEXP dirent* readdir(VirtDIR* d); |
---|
| 107 | DLLEXP int closedir(VirtDIR* d); |
---|
| 108 | |
---|
| 109 | #endif |
---|
| 110 | |
---|