wrap Q_strncasecmp use

This commit is contained in:
Garux 2020-01-24 02:47:33 +03:00
parent c7f1391177
commit 9048028faa
9 changed files with 25 additions and 29 deletions

View File

@ -162,7 +162,7 @@ void SetQdirFromPath( const char *path ){
len = strlen( BASEDIRNAME );
for ( c = path + strlen( path ) - 1 ; c != path ; c-- )
{
if ( !Q_strncasecmp( c, BASEDIRNAME, len ) ) {
if ( strniEqual( c, BASEDIRNAME, len ) ) {
//
//strncpy (qdir, path, c+len+2-path);
// the +2 assumes a 2 or 3 following quake which is not the

View File

@ -95,10 +95,10 @@ static inline char *copystring( const char *src ){ // version of strdup() with s
char* strIstr( const char* haystack, const char* needle );
#ifdef WIN32
#define Q_stricmp stricmp
#define Q_strncasecmp strnicmp
#define Q_strnicmp strnicmp
#else
#define Q_stricmp strcasecmp
#define Q_strncasecmp strncasecmp
#define Q_strnicmp strncasecmp
#endif
static inline bool strEqual( const char* string, const char* other ){
return strcmp( string, other ) == 0;
@ -110,7 +110,7 @@ static inline bool striEqual( const char* string, const char* other ){
return Q_stricmp( string, other ) == 0;
}
static inline bool strniEqual( const char* string, const char* other, size_t n ){
return Q_strncasecmp( string, other, n ) == 0;
return Q_strnicmp( string, other, n ) == 0;
}
static inline bool strEqualPrefix( const char* string, const char* prefix ){

View File

@ -309,8 +309,8 @@ int pk3BSPMain( int argc, char **argv ){
epair_t *ep;
for ( ep = entities[0].epairs; ep != NULL; ep = ep->next )
{
if ( !Q_strncasecmp( ep->key, "vertexremapshader", 17 ) ) {
sscanf( ep->value, "%*[^;] %*[;] %s", str );
if ( striEqualPrefix( ep->key, "vertexremapshader" ) ) {
sscanf( ep->value, "%*[^;] %*[;] %s", str ); // textures/remap/from;textures/remap/to
res2list( pk3Shaders, str );
}
}
@ -588,7 +588,7 @@ int pk3BSPMain( int argc, char **argv ){
}
}
}
else if ( !Q_strncasecmp( token, "implicit", 8 ) ){
else if ( striEqualPrefix( token, "implicit" ) ){
Sys_FPrintf( SYS_WRN, "WARNING5: %s : line %d : unsupported %s shader\n", scriptFile, scriptline, token );
}
/* skip the shader */
@ -981,8 +981,8 @@ int repackBSPMain( int argc, char **argv ){
epair_t *ep;
for ( ep = entities[0].epairs; ep != NULL; ep = ep->next )
{
if ( !Q_strncasecmp( ep->key, "vertexremapshader", 17 ) ) {
sscanf( ep->value, "%*[^;] %*[;] %s", str );
if ( striEqualPrefix( ep->key, "vertexremapshader" ) ) {
sscanf( ep->value, "%*[^;] %*[;] %s", str ); // textures/remap/from;textures/remap/to
res2list( pk3Shaders, str );
}
}
@ -1378,7 +1378,7 @@ int repackBSPMain( int argc, char **argv ){
GetToken( false );
StrBuf_cat2( shaderText, " ", token );
}
else if ( !Q_strncasecmp( token, "implicit", 8 ) ){
else if ( striEqualPrefix( token, "implicit" ) ){
Sys_FPrintf( SYS_WRN, "WARNING5: %s : %s shader\n", pk3Shaders->s[shader], token );
hasmap = true;
if ( line == scriptline ){

View File

@ -321,7 +321,7 @@ static void ConvertBrushFast( FILE *f, int num, bspBrush_t *brush, vec3_t origin
}
/* get texture name */
if ( !Q_strncasecmp( buildSide->shaderInfo->shader, "textures/", 9 ) ) {
if ( striEqualPrefix( buildSide->shaderInfo->shader, "textures/" ) ) {
texture = buildSide->shaderInfo->shader + 9;
}
else{
@ -484,7 +484,7 @@ static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, vec3_t origin, bo
GetBestSurfaceTriangleMatchForBrushside( buildSide, vert );
/* get texture name */
if ( !Q_strncasecmp( buildSide->shaderInfo->shader, "textures/", 9 ) ) {
if ( striEqualPrefix( buildSide->shaderInfo->shader, "textures/" ) ) {
texture = buildSide->shaderInfo->shader + 9;
}
else{
@ -777,7 +777,7 @@ for ( i = 0; i < brush->numSides; i++ )
}
/* get texture name */
if ( !Q_strncasecmp( shader->shader, "textures/", 9 ) ) {
if ( striEqualPrefix( shader->shader, "textures/" ) ) {
texture = shader->shader + 9;
}
else{
@ -852,7 +852,7 @@ static void ConvertPatch( FILE *f, int num, bspDrawSurface_t *ds, vec3_t origin
shader = &bspShaders[ ds->shaderNum ];
/* get texture name */
if ( !Q_strncasecmp( shader->shader, "textures/", 9 ) ) {
if ( striEqualPrefix( shader->shader, "textures/" ) ) {
texture = shader->shader + 9;
}
else{

View File

@ -235,10 +235,10 @@ void CreateEntityLights( void ){
name = ValueForKey( e, "classname" );
/* ydnar: check for lightJunior */
if ( Q_strncasecmp( name, "lightJunior", 11 ) == 0 ) {
if ( striEqualPrefix( name, "lightJunior" ) ) {
junior = true;
}
else if ( Q_strncasecmp( name, "light", 5 ) == 0 ) {
else if ( striEqualPrefix( name, "light" ) ) {
junior = false;
}
else{

View File

@ -1796,7 +1796,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
classname = ValueForKey( mapEnt, "classname" );
/* ydnar: only lights? */
if ( onlyLights && Q_strncasecmp( classname, "light", 5 ) ) {
if ( onlyLights && !striEqualPrefix( classname, "light" ) ) {
numEntities--;
return true;
}

View File

@ -378,16 +378,12 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
if ( rm->from[ 0 ] == '*' && rm->from[ 1 ] == '\0' ) {
glob = rm;
}
else{
const size_t shaderLen = strlen( picoShaderName );
const size_t suffixLen = strlen( rm->from );
if( shaderLen >= suffixLen && !Q_strncasecmp( picoShaderName + shaderLen - suffixLen, rm->from, suffixLen ) ){
else if( striEqualSuffix( picoShaderName, rm->from ) ){
rmto = rm;
if( shaderLen == suffixLen ) // exact match priority
if( strlen( picoShaderName ) == strlen( rm->from ) ) // exact match priority
break;
}
}
}
if( rmto ){
Sys_FPrintf( SYS_VRB, "Remapping '%s' to '%s'\n", picoShaderName, rmto->to );
picoShaderName = rmto->to;
@ -1501,7 +1497,7 @@ void AddTriangleModels( entity_t *e ){
/* look for keys prefixed with "_remap" */
if ( ep->key != NULL && ep->value != NULL &&
ep->key[ 0 ] != '\0' && ep->value[ 0 ] != '\0' &&
!Q_strncasecmp( ep->key, "_remap", 6 ) ) {
striEqualPrefix( ep->key, "_remap" ) ) {
/* create new remapping */
remap2 = remap;
remap = safe_malloc( sizeof( *remap ) );

View File

@ -1122,7 +1122,7 @@ static void ParseShaderFile( const char *filename ){
GetTokenAppend( shaderText, false );
/* deformVertexes autosprite(2) */
if ( !Q_strncasecmp( token, "autosprite", 10 ) ) {
if ( striEqualPrefix( token, "autosprite" ) ) {
/* set it as autosprite and detail */
si->autosprite = true;
ApplySurfaceParm( "detail", &si->contentFlags, &si->surfaceFlags, &si->compileFlags );
@ -1333,7 +1333,7 @@ static void ParseShaderFile( const char *filename ){
}
/* match q3map_ */
else if ( !Q_strncasecmp( token, "q3map_", 6 ) ) {
else if ( striEqualPrefix( token, "q3map_" ) ) {
/* ydnar: q3map_baseShader <shader> (inherit this shader's parameters) */
if ( striEqual( token, "q3map_baseShader" ) ) {
shaderInfo_t *si2;

View File

@ -309,7 +309,7 @@ void SetLightStyles( void ){
e = &entities[ i ];
t = ValueForKey( e, "classname" );
if ( Q_strncasecmp( t, "light", 5 ) ) {
if ( !striEqualPrefix( t, "light" ) ) {
continue;
}
t = ValueForKey( e, "targetname" );