From 9048028faab21a19b90ae8fae2f29e9e03d75fab Mon Sep 17 00:00:00 2001 From: Garux Date: Fri, 24 Jan 2020 02:47:33 +0300 Subject: [PATCH] wrap Q_strncasecmp use --- tools/quake3/common/cmdlib.c | 2 +- tools/quake3/common/cmdlib.h | 6 +++--- tools/quake3/q3map2/autopk3.c | 12 ++++++------ tools/quake3/q3map2/convert_map.c | 8 ++++---- tools/quake3/q3map2/light.c | 4 ++-- tools/quake3/q3map2/map.c | 2 +- tools/quake3/q3map2/model.c | 14 +++++--------- tools/quake3/q3map2/shaders.c | 4 ++-- tools/quake3/q3map2/writebsp.c | 2 +- 9 files changed, 25 insertions(+), 29 deletions(-) diff --git a/tools/quake3/common/cmdlib.c b/tools/quake3/common/cmdlib.c index 862c6cac..d39a8510 100644 --- a/tools/quake3/common/cmdlib.c +++ b/tools/quake3/common/cmdlib.c @@ -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 diff --git a/tools/quake3/common/cmdlib.h b/tools/quake3/common/cmdlib.h index bbf2f808..7f35a09c 100644 --- a/tools/quake3/common/cmdlib.h +++ b/tools/quake3/common/cmdlib.h @@ -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 ){ diff --git a/tools/quake3/q3map2/autopk3.c b/tools/quake3/q3map2/autopk3.c index fa61707b..3254c17c 100644 --- a/tools/quake3/q3map2/autopk3.c +++ b/tools/quake3/q3map2/autopk3.c @@ -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 ){ diff --git a/tools/quake3/q3map2/convert_map.c b/tools/quake3/q3map2/convert_map.c index 81695c14..8e734155 100644 --- a/tools/quake3/q3map2/convert_map.c +++ b/tools/quake3/q3map2/convert_map.c @@ -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{ diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index e91f4702..def54626 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -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{ diff --git a/tools/quake3/q3map2/map.c b/tools/quake3/q3map2/map.c index ec18f375..2c54a0ce 100644 --- a/tools/quake3/q3map2/map.c +++ b/tools/quake3/q3map2/map.c @@ -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; } diff --git a/tools/quake3/q3map2/model.c b/tools/quake3/q3map2/model.c index d8983121..3f2517d8 100644 --- a/tools/quake3/q3map2/model.c +++ b/tools/quake3/q3map2/model.c @@ -378,14 +378,10 @@ 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 ) ){ - rmto = rm; - if( shaderLen == suffixLen ) // exact match priority - break; - } + else if( striEqualSuffix( picoShaderName, rm->from ) ){ + rmto = rm; + if( strlen( picoShaderName ) == strlen( rm->from ) ) // exact match priority + break; } } if( rmto ){ @@ -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 ) ); diff --git a/tools/quake3/q3map2/shaders.c b/tools/quake3/q3map2/shaders.c index da0c3bd3..3009fbcf 100644 --- a/tools/quake3/q3map2/shaders.c +++ b/tools/quake3/q3map2/shaders.c @@ -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 (inherit this shader's parameters) */ if ( striEqual( token, "q3map_baseShader" ) ) { shaderInfo_t *si2; diff --git a/tools/quake3/q3map2/writebsp.c b/tools/quake3/q3map2/writebsp.c index 126e858c..cd8e3ecd 100644 --- a/tools/quake3/q3map2/writebsp.c +++ b/tools/quake3/q3map2/writebsp.c @@ -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" );