00001 00023 // ################################################################## 00024 // file input of gsp (GMN Soft Parser) 00025 // Has to be adapted depending on platform. 00026 // This is for PC. 00027 // ################################################################## 00028 00029 #include "GSP_File.h" 00030 00031 #ifdef WX 00032 #include "wx/textfile.h" 00033 #else 00034 #include <fstream> 00035 #endif 00036 00037 #ifdef WX 00038 mutString CurrentLine;//[GSP_MAX_LINE]; 00039 #else 00040 mutChar CurrentLine[GSP_MAX_LINE]; 00041 #endif 00042 size_t CurrentPos; 00043 int Eof; 00044 00045 mutTextStream* File; // the file 00046 00047 #ifdef WX 00048 00049 static bool initialized = false; 00050 00051 static int bad = 0; 00052 00053 #endif 00054 00055 // ################################################################## 00056 // basic file operations 00057 // Return values that are not 0 means, that an error occured. 00058 // A call back implemented in ReadNewLine may be used for displaying 00059 // the current line number. 00060 00061 // opens the file 00062 int OpenFile(const mutString &Name) 00063 { 00064 // File = new STD_PRE::ifstream(Name, STD_PRE::ios::in/*, 0/*int = filebuf::openprot*/); 00065 File = new mutOpenITextStream(,Name); 00066 #ifdef WX 00067 initialized = false; 00068 return bad=(!(File->Open())); 00069 #else 00070 return mutStreamBad(*File); 00071 #endif 00072 } 00073 00074 // closes the file 00075 int CloseFile() 00076 { 00077 delete File; 00078 return 0; 00079 } 00080 00081 00082 // reads a line into CurrentLine 00083 int ReadNewLine() 00084 { 00085 CurrentPos = 0; 00086 #ifdef WX 00087 00088 if ( (Eof = mutStreamEOF(*File)) || bad ) { 00089 CurrentLine = mutEmptyString; 00090 return bad; 00091 } 00092 00093 if (initialized) 00094 CurrentLine = File->GetNextLine(); 00095 else { 00096 CurrentLine = File->GetFirstLine(); 00097 initialized = true; 00098 } 00099 00100 GspCurrentLineNr++; 00101 00102 return bad; 00103 #else 00104 00105 if ( (Eof = mutStreamEOF(*File)) || mutStreamBad(*File) ) { 00106 CurrentLine[0] = 0; 00107 return mutStreamBad(*File); 00108 } 00109 00110 File->getline(CurrentLine, GSP_MAX_LINE); 00111 00112 GspCurrentLineNr++; 00113 return mutStreamBad(*File); 00114 #endif 00115 } 00116 00117 00118