|
|
@ -476,11 +476,11 @@ COM_ParseFile |
|
|
|
text parser |
|
|
|
text parser |
|
|
|
============== |
|
|
|
============== |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
char *COM_ParseFile( char *data, char *token ) |
|
|
|
char *COM_ParseFileSafe( char *data, char *token, const size_t size ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int c, len; |
|
|
|
int c, len; |
|
|
|
|
|
|
|
|
|
|
|
if( !token ) |
|
|
|
if( !token || !size ) |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
|
|
|
|
|
|
|
|
len = 0; |
|
|
|
len = 0; |
|
|
@ -523,7 +523,13 @@ skipwhite: |
|
|
|
|
|
|
|
|
|
|
|
if( c == '\\' && *data == '"' ) |
|
|
|
if( c == '\\' && *data == '"' ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
token[len++] = (byte)*data++; |
|
|
|
if( len + 1 < size ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
token[len] = (byte)*data; |
|
|
|
|
|
|
|
len++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data++; |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -532,26 +538,43 @@ skipwhite: |
|
|
|
token[len] = 0; |
|
|
|
token[len] = 0; |
|
|
|
return data; |
|
|
|
return data; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( len + 1 < size ) |
|
|
|
|
|
|
|
{ |
|
|
|
token[len] = c; |
|
|
|
token[len] = c; |
|
|
|
len++; |
|
|
|
len++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// parse single characters
|
|
|
|
// parse single characters
|
|
|
|
if( COM_IsSingleChar( c )) |
|
|
|
if( COM_IsSingleChar( c )) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if( size >= 2 ) // char and \0
|
|
|
|
{ |
|
|
|
{ |
|
|
|
token[len] = c; |
|
|
|
token[len] = c; |
|
|
|
len++; |
|
|
|
len++; |
|
|
|
token[len] = 0; |
|
|
|
token[len] = 0; |
|
|
|
return data + 1; |
|
|
|
return data + 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// couldn't pass anything
|
|
|
|
|
|
|
|
token[0] = 0; |
|
|
|
|
|
|
|
return data; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// parse a regular word
|
|
|
|
// parse a regular word
|
|
|
|
do |
|
|
|
do |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if( len + 1 < size ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
token[len] = c; |
|
|
|
token[len] = c; |
|
|
|
data++; |
|
|
|
|
|
|
|
len++; |
|
|
|
len++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data++; |
|
|
|
c = ((byte)*data); |
|
|
|
c = ((byte)*data); |
|
|
|
|
|
|
|
|
|
|
|
if( COM_IsSingleChar( c )) |
|
|
|
if( COM_IsSingleChar( c )) |
|
|
@ -563,6 +586,19 @@ skipwhite: |
|
|
|
return data; |
|
|
|
return data; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
================ |
|
|
|
|
|
|
|
COM_ParseFile |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
old unsafe version of ParseFile, deprecated |
|
|
|
|
|
|
|
only for API compatibility |
|
|
|
|
|
|
|
================ |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
char *COM_ParseFile( char *data, char *token ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return COM_ParseFileSafe( data, token, -1 ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
================ |
|
|
|
================ |
|
|
|
COM_ParseVector |
|
|
|
COM_ParseVector |
|
|
@ -613,21 +649,6 @@ qboolean COM_ParseVector( char **pfile, float *v, size_t size ) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
============= |
|
|
|
|
|
|
|
COM_CheckString |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
============= |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
|
|
|
int COM_CheckString( const char *string ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if( !string || !*string ) |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
============= |
|
|
|
============= |
|
|
|
COM_FileSize |
|
|
|
COM_FileSize |
|
|
@ -1296,3 +1317,34 @@ only exists in PlayStation version |
|
|
|
void GAME_EXPORT pfnResetTutorMessageDecayData( void ) |
|
|
|
void GAME_EXPORT pfnResetTutorMessageDecayData( void ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if XASH_ENGINE_TESTS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "tests.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Test_RunCommon( void ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
char *file = (char*)"q asdf \"qwerty\" \"f \\\"f\" meowmeow\n// comment \"stuff ignored\"\nbark"; |
|
|
|
|
|
|
|
char buf[5]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Msg( "Checking COM_ParseFile...\n" ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file = COM_ParseFileSafe( file, buf, sizeof( buf )); |
|
|
|
|
|
|
|
TASSERT( !Q_strcmp( buf, "q" )); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file = COM_ParseFileSafe( file, buf, sizeof( buf )); |
|
|
|
|
|
|
|
TASSERT( !Q_strcmp( buf, "asdf" )); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file = COM_ParseFileSafe( file, buf, sizeof( buf )); |
|
|
|
|
|
|
|
TASSERT( !Q_strcmp( buf, "qwer" )); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file = COM_ParseFileSafe( file, buf, sizeof( buf )); |
|
|
|
|
|
|
|
TASSERT( !Q_strcmp( buf, "f \"f" )); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file = COM_ParseFileSafe( file, buf, sizeof( buf )); |
|
|
|
|
|
|
|
TASSERT( !Q_strcmp( buf, "meow" )); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file = COM_ParseFileSafe( file, buf, sizeof( buf )); |
|
|
|
|
|
|
|
TASSERT( !Q_strcmp( buf, "bark" )); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|