4
#define CHAR_TAB 9 // '"'
5
#define CHAR_QUOTE 34 // '"'
10
// Get a string from a text string.
21
const TCHAR* Found = Strfind(Stream, Match);
26
Start = Found + StringLength(Match);
27
if( *Start == '\x22' ) // Character '"'
29
// The value begins with the quotation mark character: ". We skip it.
30
Strncpy( Value, Size, Start+1, MaxLen );
32
TCHAR* Temp = Strstr( Value, TEXT("\x22") );
35
// We read in the termination quotation mark. Set it t0 0 to null terminate the Value buffer.
41
// Non-quoted string without spaces.
42
Strncpy( Value, Size, Start, MaxLen );
45
Temp = Strstr( Value, TEXT(" ") ); if( Temp ) *Temp=0;
46
Temp = Strstr( Value, TEXT("\r") ); if( Temp ) *Temp=0;
47
Temp = Strstr( Value, TEXT("\n") ); if( Temp ) *Temp=0;
48
Temp = Strstr( Value, TEXT("\t") ); if( Temp ) *Temp=0;
49
Temp = Strstr( Value, TEXT(",") ); if( Temp ) *Temp=0;
58
// Checks if a command-line parameter exists in the stream.
60
BOOL ParseParam( const TCHAR* Stream, const TCHAR* Param )
62
const TCHAR* Start = Stream;
65
while( (Start=Strfind(Start+1,Param)) != NULL )
67
if( Start>Stream && (Start[-1]=='-' || Start[-1]=='/') )
69
const TCHAR* End = Start + StringLength(Param);
70
if ( End == NULL || *End == 0 || IsWhitespaceChar(*End) )
81
BOOL ParseFString( const TCHAR* Stream, const TCHAR* Match, NString& Value )
83
TCHAR Temp[4096]=TEXT("");
84
if( ParseTCHAR( Stream, Match, Temp, INL_ARRAY_COUNT(Temp), INL_ARRAY_COUNT(Temp) ) )
95
BOOL ParseQWORD( const TCHAR* Stream, const TCHAR* Match, QWORD& Value )
97
return ParseSQWORD( Stream, Match, *(SQWORD*)&Value );
101
// Parse a signed quadword.
103
BOOL ParseSQWORD( const TCHAR* Stream, const TCHAR* Match, SQWORD& Value )
105
TCHAR Temp[4096]=TEXT(""), *Ptr=Temp;
106
if( ParseTCHAR( Stream, Match, Temp, INL_ARRAY_COUNT(Temp), INL_ARRAY_COUNT(Temp) ) )
109
BOOL Negative = (*Ptr=='-');
111
while( *Ptr>='0' && *Ptr<='9' )
112
Value = Value*10 + *Ptr++ - '0';
123
BOOL ParseDWORD( const TCHAR* Stream, const TCHAR* Match, DWORD& Value )
125
const TCHAR* Temp = Strfind(Stream, Match);
129
Value = Strtoi( Temp + StringLength(Match), &End, 10 );
137
BOOL ParseBYTE( const TCHAR* Stream, const TCHAR* Match, BYTE& Value )
139
const TCHAR* Temp = Strfind(Stream,Match);
142
Temp += StringLength( Match );
143
Value = (BYTE)CharToInteger( Temp );
144
return Value!=0 || IsDigitChar(Temp[0]);
148
// Get a signed byte.
150
BOOL ParseSBYTE( const TCHAR* Stream, const TCHAR* Match, SBYTE& Value )
152
const TCHAR* Temp = Strfind(Stream,Match);
155
Temp += StringLength( Match );
156
Value = CharToInteger( Temp );
157
return Value!=0 || IsDigitChar(Temp[0]);
163
BOOL ParseWORD( const TCHAR* Stream, const TCHAR* Match, WORD& Value )
165
const TCHAR* Temp = Strfind( Stream, Match );
168
Temp += StringLength( Match );
169
Value = (WORD)CharToInteger( Temp );
170
return Value!=0 || IsDigitChar(Temp[0]);
174
// Get a signed word.
176
BOOL ParseSWORD( const TCHAR* Stream, const TCHAR* Match, SWORD& Value )
178
const TCHAR* Temp = Strfind( Stream, Match );
181
Temp += StringLength( Match );
182
Value = (SWORD)CharToInteger( Temp );
183
return Value!=0 || IsDigitChar(Temp[0]);
187
// Get a floating-point number.
189
BOOL ParseFLOAT( const TCHAR* Stream, const TCHAR* Match, float& Value )
191
const TCHAR* Temp = Strfind( Stream, Match );
194
Value = CharToFloat(Temp+StringLength(Match));
199
// Get a signed double word.
201
BOOL ParseINT( const TCHAR* Stream, const TCHAR* Match, INT& Value )
203
const TCHAR* Temp = Strfind( Stream, Match );
206
Value = CharToInteger( Temp + StringLength(Match) );
211
// Get a boolean value.
213
BOOL ParseUBOOL( const TCHAR* Stream, const TCHAR* Match, BOOL& OnOff )
216
if( ParseTCHAR( Stream, Match, TempStr, INL_ARRAY_COUNT(TempStr), INL_ARRAY_COUNT(TempStr)-1 ) )
219
= !Stricmp(TempStr,TEXT("On"))
220
|| !Stricmp(TempStr,TEXT("True"))
221
|| !Stricmp(TempStr,TEXT("1"));
229
// Sees if Stream starts with the named command. If it does,
230
// skips through the command and blanks past it. Returns 1 of match,
235
const TCHAR** Stream,
239
while( (**Stream==' ')||(**Stream==9) )
242
if( TCharStringNICompare(*Stream,Match,StringLength(Match))==0 )
244
*Stream += StringLength(Match);
245
if( !IsAlphanumericChar(**Stream) )
247
while ((**Stream==' ')||(**Stream==9)) (*Stream)++;
248
return 1; // Success.
252
*Stream -= StringLength(Match);
253
return 0; // Only found partial match.
256
else return 0; // No match.
260
// Get next command. Skips past comments and cr's.
262
void ParseNext( const TCHAR** Stream )
264
// Skip over spaces, tabs, cr's, and linefeeds.
266
while( **Stream==' ' || **Stream==9 || **Stream==13 || **Stream==10 )
271
// Skip past comments.
272
while( **Stream!=0 && **Stream!=10 && **Stream!=13 )
277
// Upon exit, *Stream either points to valid Stream or a nul.
281
// Grab the next space-delimited string from the input stream.
282
// If quoted, gets entire quoted string.
284
BOOL ParseToken( const TCHAR*& Str, TCHAR* Result, INT MaxLen, BOOL UseEscape )
288
// Skip spaces and tabs.
289
while( *Str==' ' || *Str==9 )
293
// Get quoted string.
295
while( *Str && *Str!=34 && (Len+1)<MaxLen )
298
if( c=='\\' && UseEscape )
313
// Get unquoted string.
314
for( ; *Str && *Str!=' ' && *Str!=9; Str++ )
316
Result[Len++] = *Str;
321
BOOL ParseToken( const TCHAR*& Str, NString& Arg, BOOL UseEscape )
325
// Skip spaces and tabs.
326
while( IsWhitespaceChar(*Str) )
329
if ( *Str == TEXT('"') )
331
// Get quoted string.
333
while( *Str && *Str != TEXT('"') )
336
if( c == TEXT('\\') && UseEscape )
347
if ( *Str == TEXT('"') )
352
// Get unquoted string.
353
for( ; *Str && !IsWhitespaceChar(*Str); Str++ )
359
return Arg.Length() > 0;
361
NString ParseToken( const TCHAR*& Str, BOOL UseEscape )
364
if( ParseToken( Str, Buffer, INL_ARRAY_COUNT(Buffer), UseEscape ) )
371
// Get a line of Stream (everything up to, but not including, CR/LF.
372
// Returns 0 if ok, nonzero if at end of stream and returned 0-length string.
376
const TCHAR** Stream,
387
while( **Stream!=0 && **Stream!=10 && **Stream!=13 && --MaxLen>0 )
389
// Start of comments.
390
if( !IsQuoted && !Exact && (*Stream)[0]=='/' && (*Stream)[1]=='/' )
394
if( !IsQuoted && !Exact && **Stream=='|' )
398
IsQuoted = IsQuoted ^ (**Stream==34);
403
*(Result++) = *((*Stream)++);
409
// Eat up exactly one CR/LF.
417
// Eat up all CR/LF's.
418
while( **Stream==10 || **Stream==13 || **Stream=='|' )
422
return **Stream!=0 || GotStream;
426
const TCHAR** Stream,
437
while( **Stream!=0 && **Stream!=10 && **Stream!=13 )
439
// Start of comments.
440
if( !IsQuoted && !Exact && (*Stream)[0]=='/' && (*Stream)[1]=='/' )
444
if( !IsQuoted && !Exact && **Stream=='|' )
448
IsQuoted = IsQuoted ^ (**Stream==34);
454
Result += ( *((*Stream)++) );
463
// Eat up exactly one CR/LF.
471
// Eat up all CR/LF's.
472
while( **Stream==10 || **Stream==13 || **Stream=='|' )
476
return **Stream!=0 || GotStream;