engine: use new Q_splitstr to work with single character delimited strings
This commit is contained in:
parent
ac7617990a
commit
31a86d8af2
3 changed files with 94 additions and 92 deletions
|
@ -960,6 +960,16 @@ static void Cvar_SetGL( const char *name, const char *value )
|
||||||
Cvar_FullSet( name, value, FCVAR_GLCONFIG );
|
Cvar_FullSet( name, value, FCVAR_GLCONFIG );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ShouldSetCvar_splitstr_handler( char *prev, char *next, void *userdata )
|
||||||
|
{
|
||||||
|
size_t len = next - prev;
|
||||||
|
|
||||||
|
if( !Q_strnicmp( prev, userdata, len ))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static qboolean Cvar_ShouldSetCvar( convar_t *v, qboolean isPrivileged )
|
static qboolean Cvar_ShouldSetCvar( convar_t *v, qboolean isPrivileged )
|
||||||
{
|
{
|
||||||
const char *prefixes[] = { "cl_", "gl_", "m_", "r_", "hud_", "joy_", "con_", "scr_" };
|
const char *prefixes[] = { "cl_", "gl_", "m_", "r_", "hud_", "joy_", "con_", "scr_" };
|
||||||
|
@ -978,31 +988,8 @@ static qboolean Cvar_ShouldSetCvar( convar_t *v, qboolean isPrivileged )
|
||||||
// TODO: for cmd exceptions, make generic function
|
// TODO: for cmd exceptions, make generic function
|
||||||
if( cvar_active_filter_quirks )
|
if( cvar_active_filter_quirks )
|
||||||
{
|
{
|
||||||
const char *cur, *next;
|
if( Q_splitstr((char *)cvar_active_filter_quirks->cvars, ';', v->name, ShouldSetCvar_splitstr_handler ))
|
||||||
|
|
||||||
cur = cvar_active_filter_quirks->cvars;
|
|
||||||
next = Q_strchr( cur, ';' );
|
|
||||||
|
|
||||||
// TODO: implement Q_strchrnul
|
|
||||||
while( cur && *cur )
|
|
||||||
{
|
|
||||||
size_t len = next ? next - cur : Q_strlen( cur );
|
|
||||||
|
|
||||||
// found, quit
|
|
||||||
if( !Q_strnicmp( cur, v->name, len ))
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if( next )
|
|
||||||
{
|
|
||||||
cur = next + 1;
|
|
||||||
next = Q_strchr( cur, ';' );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// stop
|
|
||||||
cur = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( FBitSet( v->flags, FCVAR_FILTERABLE ))
|
if( FBitSet( v->flags, FCVAR_FILTERABLE ))
|
||||||
|
|
|
@ -889,41 +889,47 @@ static void Host_RunTests( int stage )
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static uint32_t Host_CheckBugcomp( void )
|
static int Host_CheckBugcomp_splitstr_handler( char *prev, char *next, void *userdata )
|
||||||
{
|
{
|
||||||
const char *prev, *next;
|
|
||||||
uint32_t flags = 0;
|
|
||||||
string args, arg;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
uint32_t *flags = userdata;
|
||||||
|
|
||||||
if( !Sys_CheckParm( "-bugcomp" ))
|
*next = '\0';
|
||||||
|
|
||||||
|
if( !COM_CheckStringEmpty( prev ))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if( Sys_GetParmFromCmdLine( "-bugcomp", args ) && isalpha( args[0] ))
|
|
||||||
{
|
|
||||||
for( prev = args, next = Q_strchrnul( prev, '+' ); ; prev = next + 1, next = Q_strchrnul( prev, '+' ))
|
|
||||||
{
|
|
||||||
Q_strncpy( arg, prev, next - prev + 1 );
|
|
||||||
for( i = 0; i < ARRAYSIZE( bugcomp_features ); i++ )
|
for( i = 0; i < ARRAYSIZE( bugcomp_features ); i++ )
|
||||||
{
|
{
|
||||||
if( !Q_stricmp( bugcomp_features[i].arg, arg ))
|
if( !Q_stricmp( bugcomp_features[i].arg, prev ))
|
||||||
{
|
{
|
||||||
SetBits( flags, bugcomp_features[i].mask );
|
SetBits( *flags, bugcomp_features[i].mask );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( i == ARRAYSIZE( bugcomp_features ))
|
if( i == ARRAYSIZE( bugcomp_features ))
|
||||||
{
|
{
|
||||||
Con_Printf( S_ERROR "Unknown bugcomp flag %s\n", arg );
|
Con_Printf( S_ERROR "Unknown bugcomp flag %s\n", prev );
|
||||||
Con_Printf( "Valid flags are:\n" );
|
Con_Printf( "Valid flags are:\n" );
|
||||||
for( i = 0; i < ARRAYSIZE( bugcomp_features ); i++ )
|
for( i = 0; i < ARRAYSIZE( bugcomp_features ); i++ )
|
||||||
Con_Printf( "\t%s: %s\n", bugcomp_features[i].arg, bugcomp_features[i].msg );
|
Con_Printf( "\t%s: %s\n", bugcomp_features[i].arg, bugcomp_features[i].msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !*next )
|
return 0;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
static uint32_t Host_CheckBugcomp( void )
|
||||||
|
{
|
||||||
|
uint32_t flags = 0;
|
||||||
|
string args;
|
||||||
|
|
||||||
|
if( !Sys_CheckParm( "-bugcomp" ))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if( Sys_GetParmFromCmdLine( "-bugcomp", args ) && isalpha( args[0] ))
|
||||||
|
{
|
||||||
|
Q_splitstr( args, '+', &flags, Host_CheckBugcomp_splitstr_handler );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1910,6 +1910,32 @@ static void Mod_LoadSubmodels( model_t *mod, dbspmodel_t *bmod )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int Mod_LoadEntities_splitstr_handler( char *prev, char *next, void *userdata )
|
||||||
|
{
|
||||||
|
string token;
|
||||||
|
|
||||||
|
*next = '\0';
|
||||||
|
|
||||||
|
if( !COM_CheckStringEmpty( prev ))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
COM_FixSlashes( prev );
|
||||||
|
COM_FileBase( prev, token, sizeof( token ));
|
||||||
|
|
||||||
|
// make sure that wad is really exist
|
||||||
|
if( FS_FileExists( va( "%s.wad", token ), false ))
|
||||||
|
{
|
||||||
|
int num = world.wadlist.count++;
|
||||||
|
Q_strncpy( world.wadlist.wadnames[num], token, sizeof( world.wadlist.wadnames[0] ));
|
||||||
|
world.wadlist.wadusage[num] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( world.wadlist.count >= MAX_MAP_WADS )
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
=================
|
=================
|
||||||
Mod_LoadEntities
|
Mod_LoadEntities
|
||||||
|
@ -1919,7 +1945,6 @@ static void Mod_LoadEntities( model_t *mod, dbspmodel_t *bmod )
|
||||||
{
|
{
|
||||||
byte *entpatch = NULL;
|
byte *entpatch = NULL;
|
||||||
char token[MAX_TOKEN];
|
char token[MAX_TOKEN];
|
||||||
char wadstring[MAX_TOKEN];
|
|
||||||
string keyname;
|
string keyname;
|
||||||
char *pfile;
|
char *pfile;
|
||||||
|
|
||||||
|
@ -1927,13 +1952,13 @@ static void Mod_LoadEntities( model_t *mod, dbspmodel_t *bmod )
|
||||||
{
|
{
|
||||||
char entfilename[MAX_QPATH];
|
char entfilename[MAX_QPATH];
|
||||||
fs_offset_t entpatchsize;
|
fs_offset_t entpatchsize;
|
||||||
size_t ft1, ft2;
|
int ft1, ft2;
|
||||||
|
|
||||||
// world is check for entfile too
|
// if world check for entfile too
|
||||||
Q_strncpy( entfilename, mod->name, sizeof( entfilename ));
|
Q_strncpy( entfilename, mod->name, sizeof( entfilename ));
|
||||||
COM_ReplaceExtension( entfilename, ".ent", sizeof( entfilename ));
|
COM_ReplaceExtension( entfilename, ".ent", sizeof( entfilename ));
|
||||||
|
|
||||||
// make sure what entity patch is never than bsp
|
// make sure that entity patch is never than bsp
|
||||||
ft1 = FS_FileTime( mod->name, false );
|
ft1 = FS_FileTime( mod->name, false );
|
||||||
ft2 = FS_FileTime( entfilename, true );
|
ft2 = FS_FileTime( entfilename, true );
|
||||||
|
|
||||||
|
@ -1952,11 +1977,19 @@ static void Mod_LoadEntities( model_t *mod, dbspmodel_t *bmod )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure what we really has terminator
|
// make sure that we really have null terminator
|
||||||
mod->entities = Mem_Calloc( mod->mempool, bmod->entdatasize + 1 );
|
mod->entities = Mem_Malloc( mod->mempool, bmod->entdatasize + 1 );
|
||||||
memcpy( mod->entities, bmod->entdata, bmod->entdatasize ); // moving to private model pool
|
memcpy( mod->entities, bmod->entdata, bmod->entdatasize ); // moving to private model pool
|
||||||
if( entpatch ) Mem_Free( entpatch ); // release entpatch if present
|
mod->entities[bmod->entdatasize] = 0;
|
||||||
if( !bmod->isworld ) return;
|
|
||||||
|
if( entpatch )
|
||||||
|
{
|
||||||
|
Mem_Free( entpatch ); // release entpatch if present
|
||||||
|
entpatch = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !bmod->isworld )
|
||||||
|
return;
|
||||||
|
|
||||||
pfile = (char *)mod->entities;
|
pfile = (char *)mod->entities;
|
||||||
world.generator[0] = '\0';
|
world.generator[0] = '\0';
|
||||||
|
@ -1975,7 +2008,9 @@ static void Mod_LoadEntities( model_t *mod, dbspmodel_t *bmod )
|
||||||
// parse key
|
// parse key
|
||||||
if(( pfile = COM_ParseFile( pfile, token, sizeof( token ))) == NULL )
|
if(( pfile = COM_ParseFile( pfile, token, sizeof( token ))) == NULL )
|
||||||
Host_Error( "%s: EOF without closing brace\n", __func__ );
|
Host_Error( "%s: EOF without closing brace\n", __func__ );
|
||||||
if( token[0] == '}' ) break; // end of desc
|
|
||||||
|
if( token[0] == '}' )
|
||||||
|
break; // end of desc
|
||||||
|
|
||||||
Q_strncpy( keyname, token, sizeof( keyname ));
|
Q_strncpy( keyname, token, sizeof( keyname ));
|
||||||
|
|
||||||
|
@ -1987,33 +2022,7 @@ static void Mod_LoadEntities( model_t *mod, dbspmodel_t *bmod )
|
||||||
Host_Error( "%s: closing brace without data\n", __func__ );
|
Host_Error( "%s: closing brace without data\n", __func__ );
|
||||||
|
|
||||||
if( !Q_stricmp( keyname, "wad" ))
|
if( !Q_stricmp( keyname, "wad" ))
|
||||||
{
|
Q_splitstr( token, ';', NULL, Mod_LoadEntities_splitstr_handler );
|
||||||
char *pszWadFile;
|
|
||||||
|
|
||||||
Q_strncpy( wadstring, token, sizeof( wadstring ) - 2 );
|
|
||||||
wadstring[sizeof( wadstring ) - 2] = 0;
|
|
||||||
|
|
||||||
if( !Q_strchr( wadstring, ';' ))
|
|
||||||
Q_strncat( wadstring, ";", sizeof( wadstring ));
|
|
||||||
|
|
||||||
// parse wad pathes
|
|
||||||
for( pszWadFile = strtok( wadstring, ";" ); pszWadFile != NULL; pszWadFile = strtok( NULL, ";" ))
|
|
||||||
{
|
|
||||||
COM_FixSlashes( pszWadFile );
|
|
||||||
COM_FileBase( pszWadFile, token, sizeof( token ));
|
|
||||||
|
|
||||||
// make sure that wad is really exist
|
|
||||||
if( FS_FileExists( va( "%s.wad", token ), false ))
|
|
||||||
{
|
|
||||||
int num = world.wadlist.count++;
|
|
||||||
Q_strncpy( world.wadlist.wadnames[num], token, sizeof( world.wadlist.wadnames[0] ));
|
|
||||||
world.wadlist.wadusage[num] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( world.wadlist.count >= MAX_MAP_WADS )
|
|
||||||
break; // too many wads...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( !Q_stricmp( keyname, "message" ))
|
else if( !Q_stricmp( keyname, "message" ))
|
||||||
Q_strncpy( world.message, token, sizeof( world.message ));
|
Q_strncpy( world.message, token, sizeof( world.message ));
|
||||||
else if( !Q_stricmp( keyname, "compiler" ) || !Q_stricmp( keyname, "_compiler" ))
|
else if( !Q_stricmp( keyname, "compiler" ) || !Q_stricmp( keyname, "_compiler" ))
|
||||||
|
|
Loading…
Add table
Reference in a new issue