From 5350d88f570597e20b206f35ffcd9ffdfd84dab7 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 11 Jul 2022 00:34:48 +0300 Subject: [PATCH] public: crtlib: add quotation mark support for ParseFile, required for filesystem_stdio --- engine/client/cl_game.c | 6 +----- engine/client/cl_gameui.c | 7 ++++++- engine/client/cl_mobile.c | 7 ++++++- engine/client/cl_qparse.c | 2 +- engine/common/cmd.c | 2 +- engine/common/common.c | 12 ++++++------ public/crtlib.c | 8 +++++++- public/crtlib.h | 6 ++++-- 8 files changed, 32 insertions(+), 18 deletions(-) diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index e516f423..f7e6d1dc 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -3098,11 +3098,7 @@ handle colon separately */ char *pfnParseFile( char *data, char *token ) { - char *out; - - out = _COM_ParseFileSafe( data, token, PFILE_TOKEN_MAX_LENGTH, PFILE_HANDLECOLON, NULL ); - - return out; + return COM_ParseFileSafe( data, token, PFILE_TOKEN_MAX_LENGTH, PFILE_HANDLECOLON, NULL, NULL ); } /* diff --git a/engine/client/cl_gameui.c b/engine/client/cl_gameui.c index f295e701..bae521d0 100644 --- a/engine/client/cl_gameui.c +++ b/engine/client/cl_gameui.c @@ -1224,6 +1224,11 @@ static int pfnGetRenderers( unsigned int num, char *shortName, size_t size1, cha return 1; } +static char *pfnParseFileSafe( char *data, char *buf, const int size, unsigned int flags, int *len ) +{ + return COM_ParseFileSafe( data, buf, size, flags, len, NULL ); +} + static ui_extendedfuncs_t gExtendedfuncs = { pfnEnableTextInput, @@ -1232,7 +1237,7 @@ static ui_extendedfuncs_t gExtendedfuncs = Con_UtfMoveRight, pfnGetRenderers, Sys_DoubleTime, - _COM_ParseFileSafe, + pfnParseFileSafe, NET_AdrToString }; diff --git a/engine/client/cl_mobile.c b/engine/client/cl_mobile.c index 2dc84d34..3e59b85a 100644 --- a/engine/client/cl_mobile.c +++ b/engine/client/cl_mobile.c @@ -103,6 +103,11 @@ static void pfnTouch_RemoveButton( const char *name ) Touch_RemoveButton( name, true ); } +static char *pfnParseFileSafe( char *data, char *buf, const int size, unsigned int flags, int *len ) +{ + return COM_ParseFileSafe( data, buf, size, flags, len, NULL ); +} + static mobile_engfuncs_t gpMobileEngfuncs = { MOBILITY_API_VERSION, @@ -118,7 +123,7 @@ static mobile_engfuncs_t gpMobileEngfuncs = Sys_Warn, pfnGetNativeObject, ID_SetCustomClientID, - _COM_ParseFileSafe + pfnParseFileSafe }; qboolean Mobile_Init( void ) diff --git a/engine/client/cl_qparse.c b/engine/client/cl_qparse.c index bfdf753e..76865362 100644 --- a/engine/client/cl_qparse.c +++ b/engine/client/cl_qparse.c @@ -864,7 +864,7 @@ void CL_QuakeExecStuff( void ) if( !*text ) break; - text = _COM_ParseFileSafe( text, token, sizeof( token ), PFILE_IGNOREBRACKET, NULL ); + text = COM_ParseFileSafe( text, token, sizeof( token ), PFILE_IGNOREBRACKET, NULL, NULL ); if( !text ) break; diff --git a/engine/common/cmd.c b/engine/common/cmd.c index 3a268e5a..1df7287b 100644 --- a/engine/common/cmd.c +++ b/engine/common/cmd.c @@ -647,7 +647,7 @@ void Cmd_TokenizeString( const char *text ) if( cmd_argc == 1 ) cmd_args = text; - text = _COM_ParseFileSafe( (char*)text, cmd_token, sizeof( cmd_token ), PFILE_IGNOREBRACKET, NULL ); + text = COM_ParseFileSafe( (char*)text, cmd_token, sizeof( cmd_token ), PFILE_IGNOREBRACKET, NULL, NULL ); if( !text ) return; diff --git a/engine/common/common.c b/engine/common/common.c index c8baf28b..2e00df6a 100644 --- a/engine/common/common.c +++ b/engine/common/common.c @@ -1182,22 +1182,22 @@ void Test_RunCommon( void ) Msg( "Checking COM_ParseFile...\n" ); - file = _COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len ); + file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL ); TASSERT( !Q_strcmp( buf, "q" ) && len == 1); - file = _COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len ); + file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL ); TASSERT( !Q_strcmp( buf, "asdf" ) && len == 4); - file = _COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len ); + file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL ); TASSERT( !Q_strcmp( buf, "qwer" ) && len == -1); - file = _COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len ); + file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL ); TASSERT( !Q_strcmp( buf, "f \"f" ) && len == 4); - file = _COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len ); + file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL ); TASSERT( !Q_strcmp( buf, "meow" ) && len == -1); - file = _COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len ); + file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL ); TASSERT( !Q_strcmp( buf, "bark" ) && len == 4); } #endif diff --git a/public/crtlib.c b/public/crtlib.c index 2cc3e4e9..d183c7a5 100644 --- a/public/crtlib.c +++ b/public/crtlib.c @@ -889,11 +889,14 @@ COM_ParseFile text parser ============== */ -char *_COM_ParseFileSafe( char *data, char *token, const int size, unsigned int flags, int *plen ) +char *COM_ParseFileSafe( char *data, char *token, const int size, unsigned int flags, int *plen, qboolean *quoted ) { int c, len = 0; qboolean overflow = false; + if( quoted ) + *quoted = false; + if( !token || !size ) { if( plen ) *plen = 0; @@ -927,6 +930,9 @@ skipwhite: // handle quoted strings specially if( c == '\"' ) { + if( quoted ) + *quoted = true; + data++; while( 1 ) { diff --git a/public/crtlib.h b/public/crtlib.h index 43a0c775..6c1ad224 100644 --- a/public/crtlib.h +++ b/public/crtlib.h @@ -37,6 +37,7 @@ enum #define PFILE_IGNOREBRACKET (1<<0) #define PFILE_HANDLECOLON (1<<1) #define PFILE_TOKEN_MAX_LENGTH 1024 +#define PFILE_FS_TOKEN_MAX_LENGTH 512 // // crtlib.c @@ -83,10 +84,11 @@ void COM_RemoveLineFeed( char *str ); void COM_PathSlashFix( char *path ); char COM_Hex2Char( uint8_t hex ); void COM_Hex2String( uint8_t hex, char *str ); +// return 0 on empty or null string, 1 otherwise #define COM_CheckString( string ) ( ( !string || !*string ) ? 0 : 1 ) #define COM_CheckStringEmpty( string ) ( ( !*string ) ? 0 : 1 ) -char *_COM_ParseFileSafe( char *data, char *token, const int size, unsigned int flags, int *len ); -#define COM_ParseFile( data, token, size ) _COM_ParseFileSafe( data, token, size, 0, NULL ) +char *COM_ParseFileSafe( char *data, char *token, const int size, unsigned int flags, int *len, qboolean *quoted ); +#define COM_ParseFile( data, token, size ) COM_ParseFileSafe( data, token, size, 0, NULL, NULL ) int matchpattern( const char *in, const char *pattern, qboolean caseinsensitive ); int matchpattern_with_separator( const char *in, const char *pattern, qboolean caseinsensitive, const char *separators, qboolean wildcard_least_one );