From c9da283d84d89ab295f157e976cf884c05156db3 Mon Sep 17 00:00:00 2001 From: Jonathan Gray Date: Tue, 7 May 2013 02:56:48 +1000 Subject: [PATCH] add Cmd_TokenizeStringIgnoreQuotes modelled after ioquake3 --- codemp/qcommon/cmd_common.cpp | 23 ++++++++++++++++++++--- codemp/qcommon/qcommon.h | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/codemp/qcommon/cmd_common.cpp b/codemp/qcommon/cmd_common.cpp index 35f4bf2..a21fab4 100644 --- a/codemp/qcommon/cmd_common.cpp +++ b/codemp/qcommon/cmd_common.cpp @@ -395,7 +395,7 @@ are inserted in the apropriate place, The argv array will point into this temporary buffer. ============ */ -void Cmd_TokenizeString( const char *text_in ) { +void Cmd_TokenizeString2( const char *text_in, qboolean ignoreQuotes ) { const char *text; char *textOut; @@ -443,7 +443,8 @@ void Cmd_TokenizeString( const char *text_in ) { } // handle quoted strings - if ( *text == '"' ) { + // NOTE TTimo this doesn't handle \" escaping + if ( !ignoreQuotes && *text == '"' ) { cmd_argv[cmd_argc] = textOut; cmd_argc++; text++; @@ -465,7 +466,7 @@ void Cmd_TokenizeString( const char *text_in ) { // skip until whitespace, quote, or command while ( *(const unsigned char* /*eurofix*/)text > ' ' ) { - if ( text[0] == '"' ) { + if ( !ignoreQuotes && text[0] == '"' ) { break; } @@ -490,7 +491,23 @@ void Cmd_TokenizeString( const char *text_in ) { } +/* +============ +Cmd_TokenizeString +============ +*/ +void Cmd_TokenizeString( const char *text_in ) { + Cmd_TokenizeString2( text_in, qfalse ); +} +/* +============ +Cmd_TokenizeStringIgnoreQuotes +============ +*/ +void Cmd_TokenizeStringIgnoreQuotes( const char *text_in ) { + Cmd_TokenizeString2( text_in, qtrue ); +} /* ============ diff --git a/codemp/qcommon/qcommon.h b/codemp/qcommon/qcommon.h index a14816d..3fb25d0 100644 --- a/codemp/qcommon/qcommon.h +++ b/codemp/qcommon/qcommon.h @@ -387,6 +387,7 @@ void Cmd_ArgsBuffer( char *buffer, int bufferLength ); // if arg > argc, so string operations are allways safe. void Cmd_TokenizeString( const char *text ); +void Cmd_TokenizeStringIgnoreQuotes( const char *text ); // Takes a null terminated string. Does not need to be /n terminated. // breaks the string up into arg tokens.