mirror of
https://github.com/FWGS/xash3d-fwgs
synced 2024-11-22 01:45:19 +01:00
public: add optional feature for COM_ParseFileSafe to ignore shell like hash symbol prefixed comments
This commit is contained in:
parent
87f0217588
commit
fa272d9d93
@ -36,6 +36,7 @@ typedef int HIMAGE; // handle to a graphic
|
|||||||
// flags for COM_ParseFileSafe
|
// flags for COM_ParseFileSafe
|
||||||
#define PFILE_IGNOREBRACKET (1<<0)
|
#define PFILE_IGNOREBRACKET (1<<0)
|
||||||
#define PFILE_HANDLECOLON (1<<1)
|
#define PFILE_HANDLECOLON (1<<1)
|
||||||
|
#define PFILE_IGNOREHASHCMT (1<<2)
|
||||||
|
|
||||||
typedef struct ui_globalvars_s
|
typedef struct ui_globalvars_s
|
||||||
{
|
{
|
||||||
|
@ -54,6 +54,7 @@ extern "C" {
|
|||||||
// flags for COM_ParseFileSafe
|
// flags for COM_ParseFileSafe
|
||||||
#define PFILE_IGNOREBRACKET (1<<0)
|
#define PFILE_IGNOREBRACKET (1<<0)
|
||||||
#define PFILE_HANDLECOLON (1<<1)
|
#define PFILE_HANDLECOLON (1<<1)
|
||||||
|
#define PFILE_IGNOREHASHCMT (1<<2)
|
||||||
|
|
||||||
typedef struct mobile_engfuncs_s
|
typedef struct mobile_engfuncs_s
|
||||||
{
|
{
|
||||||
|
@ -758,8 +758,8 @@ skipwhite:
|
|||||||
data++;
|
data++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip // comments
|
// skip // or #, if requested, comments
|
||||||
if( c == '/' && data[1] == '/' )
|
if(( c == '/' && data[1] == '/' ) || ( c == '#' && FBitSet( flags, PFILE_IGNOREHASHCMT )))
|
||||||
{
|
{
|
||||||
while( *data && *data != '\n' )
|
while( *data && *data != '\n' )
|
||||||
data++;
|
data++;
|
||||||
|
@ -39,9 +39,11 @@ enum
|
|||||||
};
|
};
|
||||||
|
|
||||||
// a1ba: not using BIT macro, so flags can be copypasted into
|
// a1ba: not using BIT macro, so flags can be copypasted into
|
||||||
// exported APIs headers and will get nice warning in case of changing values
|
// exported APIs headers and will not get warning in case of changing values
|
||||||
#define PFILE_IGNOREBRACKET (1<<0)
|
#define PFILE_IGNOREBRACKET (1<<0)
|
||||||
#define PFILE_HANDLECOLON (1<<1)
|
#define PFILE_HANDLECOLON (1<<1)
|
||||||
|
#define PFILE_IGNOREHASHCMT (1<<2)
|
||||||
|
|
||||||
#define PFILE_TOKEN_MAX_LENGTH 1024
|
#define PFILE_TOKEN_MAX_LENGTH 1024
|
||||||
#define PFILE_FS_TOKEN_MAX_LENGTH 512
|
#define PFILE_FS_TOKEN_MAX_LENGTH 512
|
||||||
|
|
||||||
|
@ -1,34 +1,52 @@
|
|||||||
#include "crtlib.h"
|
#include "crtlib.h"
|
||||||
|
|
||||||
|
static const char *test_file =
|
||||||
|
"q asdf \"qwerty\" \"f \\\"f\" meowmeow\n"
|
||||||
|
"// comment \"stuff ignored\"\n"
|
||||||
|
"bark // ignore\n"
|
||||||
|
"bashlikecomment #notignored test\n"
|
||||||
|
"#ignore comment\n"
|
||||||
|
"thisshall #be ignored\n"
|
||||||
|
"test_sentinel\n";
|
||||||
|
|
||||||
int main( void )
|
int main( void )
|
||||||
{
|
{
|
||||||
char *file = (char *)"q asdf \"qwerty\" \"f \\\"f\" meowmeow\n// comment \"stuff ignored\"\nbark";
|
int i;
|
||||||
int len;
|
char *file = (char *)test_file;
|
||||||
char buf[5];
|
struct test
|
||||||
|
{
|
||||||
|
int bufsize;
|
||||||
|
const char *expected;
|
||||||
|
int expected_len;
|
||||||
|
int flags;
|
||||||
|
} testdata[] =
|
||||||
|
{
|
||||||
|
{ 5, "q", 1 },
|
||||||
|
{ 5, "asdf", 4 },
|
||||||
|
{ 5, "qwer", -1 },
|
||||||
|
{ 5, "f \"f", 4 },
|
||||||
|
{ 5, "meow", -1 },
|
||||||
|
{ 5, "bark", 4 },
|
||||||
|
{ 32, "bashlikecomment", 15 },
|
||||||
|
{ 32, "#notignored", 11 },
|
||||||
|
{ 32, "test", 4, PFILE_IGNOREHASHCMT },
|
||||||
|
{ 32, "thisshall", 9, PFILE_IGNOREHASHCMT },
|
||||||
|
{ 32, "test_sentinel", 13, PFILE_IGNOREHASHCMT },
|
||||||
|
};
|
||||||
|
|
||||||
file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL );
|
for( i = 0; i < sizeof( testdata ) / sizeof( testdata[0] ); i++ )
|
||||||
if( !( !Q_strcmp( buf, "q" ) && len == 1 ))
|
{
|
||||||
return 1;
|
string buf;
|
||||||
|
int len;
|
||||||
|
|
||||||
file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL );
|
file = COM_ParseFileSafe( file, buf, testdata[i].bufsize, testdata[i].flags, &len, NULL );
|
||||||
if( !( !Q_strcmp( buf, "asdf" ) && len == 4 ))
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL );
|
if( file == NULL )
|
||||||
if( !( !Q_strcmp( buf, "qwer" ) && len == -1 ))
|
return i;
|
||||||
return 3;
|
|
||||||
|
|
||||||
file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL );
|
if( !( !Q_strcmp( buf, testdata[i].expected ) && len == testdata[i].expected_len ))
|
||||||
if( !( !Q_strcmp( buf, "f \"f" ) && len == 4 ))
|
return i;
|
||||||
return 4;
|
}
|
||||||
|
|
||||||
file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL );
|
|
||||||
if( !( !Q_strcmp( buf, "meow" ) && len == -1 ))
|
|
||||||
return 5;
|
|
||||||
|
|
||||||
file = COM_ParseFileSafe( file, buf, sizeof( buf ), 0, &len, NULL );
|
|
||||||
if( !( !Q_strcmp( buf, "bark" ) && len == 4 ))
|
|
||||||
return 6;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user