00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "Input.hpp"
00035
00036 class FileParser : public Input
00037 {
00038 unsigned curlineno;
00039
00040 public:
00041
00042 char OpenFile(char *filename)
00043
00044 {
00045 curlineno=1;
00046
00047 return Input::OpenFile(filename);
00048 }
00049
00050 unsigned GetCurLineNo() { return curlineno; }
00051
00052 char ReadStringUntil(char **destptr,int *destlen,char stopatwspace,char c1,char c2)
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 {
00063 char *curptr,*ptr;
00064 int len,i;
00065
00066
00067 len=GetCurBlockPtr(&ptr);
00068 curptr=ptr;
00069
00070 i=len;
00071
00072
00073
00074 while(i!=0)
00075 {
00076 if(*curptr=='\n')
00077 curlineno++;
00078
00079 if((*curptr==c1)||(*curptr==c2))
00080 {
00081 curptr++;
00082 *destptr=ptr;
00083 *destlen=curptr-ptr;
00084 FastSkipData(*destlen);
00085 return 1;
00086 }
00087 if((stopatwspace)&&((*curptr==' ')||(*curptr=='\t')||(*curptr=='\r')||(*curptr=='\n')))
00088 {
00089 *destptr=ptr;
00090 *destlen=curptr-ptr;
00091 FastSkipData(*destlen);
00092 return 1;
00093 }
00094 curptr++;
00095 i--;
00096 }
00097
00098
00099
00100 RefillAndGetCurBlockPtr(&ptr,&len);
00101
00102 curptr=ptr;
00103
00104 i=len;
00105
00106
00107
00108
00109
00110
00111 while(i!=0)
00112 {
00113 if(*curptr=='\n')
00114 curlineno++;
00115
00116 if((*curptr==c1)||(*curptr==c2))
00117 {
00118 curptr++;
00119 *destptr=ptr;
00120 *destlen=curptr-ptr;
00121 FastSkipData(*destlen);
00122 return 1;
00123 }
00124 if((stopatwspace)&&((*curptr==' ')||(*curptr=='\t')||(*curptr=='\r')||(*curptr=='\n')))
00125 {
00126 *destptr=ptr;
00127 *destlen=curptr-ptr;
00128 FastSkipData(*destlen);
00129 return 1;
00130 }
00131 curptr++;
00132 i--;
00133 }
00134
00135 *destptr=ptr;
00136 *destlen=len;
00137 FastSkipData(len);
00138 return 0;
00139 }
00140
00141 char ReadStringUntil(char **destptr,int *destlen,char c1)
00142
00143
00144
00145
00146
00147
00148
00149 {
00150 char *curptr,*ptr;
00151 int len,i;
00152
00153 len=GetCurBlockPtr(&ptr);
00154 curptr=ptr;
00155
00156 i=len;
00157
00158
00159
00160
00161 while(i!=0)
00162 {
00163 if(*curptr==c1)
00164 {
00165 curptr++;
00166 *destptr=ptr;
00167 *destlen=curptr-ptr;
00168 FastSkipData(*destlen);
00169 return 1;
00170 }
00171 if(*curptr=='\n')
00172 curlineno++;
00173 curptr++;
00174 i--;
00175 }
00176
00177
00178
00179 RefillAndGetCurBlockPtr(&ptr,&len);
00180 curptr=ptr;
00181
00182 i=len;
00183
00184
00185
00186
00187
00188
00189 while(i!=0)
00190 {
00191 if(*curptr==c1)
00192 {
00193 curptr++;
00194 *destptr=ptr;
00195 *destlen=curptr-ptr;
00196 FastSkipData(*destlen);
00197 return 1;
00198 }
00199 if(*curptr=='\n')
00200 curlineno++;
00201 curptr++;
00202 i--;
00203 }
00204
00205 *destptr=ptr;
00206 *destlen=len;
00207 FastSkipData(len);
00208 return 0;
00209 }
00210
00211 char ReadWhiteSpaces(char **destptr,int *destlen)
00212
00213
00214
00215
00216
00217
00218
00219 {
00220 char *curptr,*ptr;
00221 int len,i;
00222
00223 len=GetCurBlockPtr(&ptr);
00224 curptr=ptr;
00225
00226 i=len;
00227
00228
00229
00230
00231 while(i!=0)
00232 {
00233 if((*curptr!=' ')&&(*curptr!='\t')&&(*curptr!='\r')&&(*curptr!='\n'))
00234
00235 {
00236 *destptr=ptr;
00237 *destlen=curptr-ptr;
00238 FastSkipData(*destlen);
00239 return 1;
00240 }
00241 if(*curptr=='\n')
00242 curlineno++;
00243 curptr++;
00244 i--;
00245 }
00246
00247
00248
00249 RefillAndGetCurBlockPtr(&ptr,&len);
00250 curptr=ptr;
00251
00252 i=len;
00253
00254
00255
00256
00257
00258
00259 while(i!=0)
00260 {
00261 if((*curptr!=' ')&&(*curptr!='\t')&&(*curptr!='\r')&&(*curptr!='\n'))
00262
00263 {
00264 *destptr=ptr;
00265 *destlen=curptr-ptr;
00266 FastSkipData(*destlen);
00267 return 1;
00268 }
00269 if(*curptr=='\n')
00270 curlineno++;
00271 curptr++;
00272 i--;
00273 }
00274
00275
00276
00277
00278 *destptr=ptr;
00279 *destlen=len;
00280 FastSkipData(len);
00281 return 0;
00282 }
00283
00284 char ReadStringUntil(char **destptr,int *destlen,char *searchstr)
00285
00286
00287
00288
00289
00290
00291 {
00292 char *ptr;
00293 int len,stringlen;
00294 char refilled=0;
00295 int curoffset=0,i;
00296 char *curptr;
00297
00298 len=GetCurBlockPtr(&ptr);
00299 stringlen=strlen(searchstr);
00300
00301 do
00302 {
00303
00304 curptr=ptr+curoffset;
00305 i=len-curoffset;
00306 while(i!=0)
00307 {
00308 if(*curptr==searchstr[0])
00309 break;
00310 if(*curptr=='\n')
00311 curlineno++;
00312 curptr++;
00313 i--;
00314 }
00315 if(i==0)
00316
00317 {
00318 if(!refilled)
00319 {
00320 curoffset=len;
00321 refilled=1;
00322 RefillAndGetCurBlockPtr(&ptr,&len);
00323 continue;
00324 }
00325 else
00326
00327 {
00328 *destptr=ptr;
00329 *destlen=len;
00330 FastSkipData(len);
00331 return 0;
00332 }
00333 }
00334
00335
00336
00337 curoffset=curptr-ptr;
00338
00339 if(curoffset+stringlen>len)
00340
00341 {
00342 if(!refilled)
00343 {
00344 refilled=1;
00345 RefillAndGetCurBlockPtr(&ptr,&len);
00346 }
00347 if(curoffset+stringlen>len)
00348 {
00349 *destptr=ptr;
00350 *destlen=curoffset;
00351 FastSkipData(curoffset);
00352 return 0;
00353 }
00354 }
00355
00356
00357 if(memcmp(ptr+curoffset,searchstr,stringlen)==0)
00358
00359 {
00360 *destptr=ptr;
00361 *destlen=curoffset+stringlen;
00362 FastSkipData(*destlen);
00363 return 1;
00364 }
00365
00366 curoffset++;
00367 }
00368 while(1);
00369 }
00370
00371 void SkipChar()
00372
00373 {
00374 char c;
00375 Input::GetChar(&c);
00376 if(c=='\n')
00377 curlineno++;
00378 }
00379
00380 void GetChar(char *c)
00381
00382 {
00383 Input::GetChar(c);
00384 if(*c=='\n')
00385 curlineno++;
00386 }
00387
00388 void SkipData(int len)
00389
00390 {
00391 char *ptr;
00392 int mylen;
00393 mylen=GetCurBlockPtr(&ptr);
00394
00395 for(int i=0;i<len;i++)
00396 {
00397 if(*ptr=='\n')
00398 curlineno++;
00399 ptr++;
00400 }
00401 Input::SkipData(len);
00402 }
00403 };