00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "InStreams.h"
00011 #include <string.h>
00012 #include "Platform/GTAssert.h"
00013
00014 void StreamReader::skipData(int size, PhysicalInStream& stream)
00015 {
00016
00017 char* dummy = new char[size];
00018 readData(dummy, size, stream);
00019 delete [] dummy;
00020 }
00021
00022 void PhysicalInStream::skipInStream(int size)
00023 {
00024
00025 char* dummy = new char[size];
00026 readFromStream(dummy, size);
00027 delete [] dummy;
00028 }
00029
00030 void InText::readString(char* value, PhysicalInStream& stream)
00031 {
00032 skipWhitespace(stream);
00033 while(!isEof(stream) && !isWhitespace())
00034 {
00035 if(theChar == '\\')
00036 nextChar(stream);
00037 *value++ = theChar;
00038 if(!isEof(stream))
00039 nextChar(stream);
00040 }
00041 *value = 0;
00042 skipWhitespace(stream);
00043 }
00044
00045 void InText::readData(void *p,int size, PhysicalInStream& stream)
00046 {
00047 for(int i = 0; i < size; ++i)
00048 readChar(*((char*&) p)++,stream);
00049 }
00050
00051 bool InText::isWhitespace()
00052 {
00053 return theChar == ' ' || theChar == '\n' || theChar == '\r' || theChar == '\t';
00054 }
00055
00056 void InText::skipWhitespace(PhysicalInStream& stream)
00057 {
00058 while(!isEof(stream) && isWhitespace())
00059 nextChar(stream);
00060 }
00061
00062 void InConfig::create(const char* sectionName, PhysicalInStream& stream)
00063 {
00064 if(stream.exists() && sectionName)
00065 {
00066 char fileEntry[200];
00067 char section[200];
00068
00069 ASSERT(strlen(sectionName) + 2 < sizeof(section));
00070 strcpy(section,"[");
00071 strcat(section,sectionName);
00072 strcat(section,"]");
00073
00074 while(!isEof(stream))
00075 {
00076 readString(fileEntry,stream);
00077 if(!strcmp(fileEntry,section))
00078 break;
00079 }
00080 readSection = true;
00081 }
00082 }
00083
00084 bool InConfig::isWhitespace()
00085 {
00086 return theChar == '/' || theChar == '#' || InText::isWhitespace();
00087 }
00088
00089 void InConfig::skipWhitespace(PhysicalInStream& stream)
00090 {
00091 while(!isEof(stream) && isWhitespace())
00092 {
00093 while(!isEof(stream) && InText::isWhitespace())
00094 nextChar(stream);
00095 if(!isEof(stream))
00096 if(theChar == '/')
00097 {
00098 nextChar(stream);
00099 if(theChar == '/')
00100 skipLine(stream);
00101 else if(theChar == '*')
00102 skipComment(stream);
00103 else
00104 ASSERT(false);
00105 }
00106 else if(theChar == '#')
00107 skipLine(stream);
00108 }
00109 }
00110
00111 void InConfig::nextChar(PhysicalInStream& stream)
00112 {
00113 InText::nextChar(stream);
00114 if (readSection && theChar == '[')
00115 while (!isEof(stream))
00116 InText::nextChar(stream);
00117 }
00118
00119 void InConfig::skipLine(PhysicalInStream& stream)
00120 {
00121 while(!isEof(stream) && theChar != '\n')
00122 nextChar(stream);
00123 if(!isEof(stream))
00124 nextChar(stream);
00125 }
00126
00127 void InConfig::skipComment(PhysicalInStream& stream)
00128 {
00129 while(!isEof(stream) && theChar != '/')
00130 {
00131 while(!isEof(stream) && theChar != '*')
00132 nextChar(stream);
00133 if(!isEof(stream))
00134 nextChar(stream);
00135 }
00136 if(!isEof(stream))
00137 nextChar(stream);
00138 }
00139
00140 void InMemory::readFromStream(void* p, int size)
00141 {
00142 if (memory!=0)
00143 {
00144 memcpy(p,memory,size);
00145 memory += size;
00146 }
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201