From b509d770a7934c40f2081d0a90d28bbe35c61b82 Mon Sep 17 00:00:00 2001 From: Thilo Schulz Date: Sun, 15 May 2011 14:08:03 +0000 Subject: [PATCH] - Remove Q_strrchr(), replace with standard, portable strrchr() - Add strrchr() to bg_lib.c, patch by DevHC --- code/cgame/cg_info.c | 2 +- code/client/cl_main.c | 2 +- code/game/bg_lib.c | 18 ++++++++++++++++++ code/game/bg_lib.h | 1 + code/game/g_bot.c | 2 +- code/game/g_client.c | 2 +- code/q3_ui/ui_splevel.c | 2 +- code/q3_ui/ui_startserver.c | 2 +- code/qcommon/files.c | 2 +- code/qcommon/q_shared.c | 20 -------------------- code/qcommon/q_shared.h | 1 - code/server/sv_client.c | 2 +- 12 files changed, 27 insertions(+), 29 deletions(-) diff --git a/code/cgame/cg_info.c b/code/cgame/cg_info.c index fba60fb2..1bf23ec1 100644 --- a/code/cgame/cg_info.c +++ b/code/cgame/cg_info.c @@ -104,7 +104,7 @@ void CG_LoadingClient( int clientNum ) { if ( loadingPlayerIconCount < MAX_LOADING_PLAYER_ICONS ) { Q_strncpyz( model, Info_ValueForKey( info, "model" ), sizeof( model ) ); - skin = Q_strrchr( model, '/' ); + skin = strrchr( model, '/' ); if ( skin ) { *skin++ = '\0'; } else { diff --git a/code/client/cl_main.c b/code/client/cl_main.c index 93d325b7..6e6303a9 100644 --- a/code/client/cl_main.c +++ b/code/client/cl_main.c @@ -966,7 +966,7 @@ void CL_PlayDemo_f( void ) { CL_Disconnect( qtrue ); // check for an extension .DEMOEXT_?? (?? is protocol) - ext_test = Q_strrchr(arg, '.'); + ext_test = strrchr(arg, '.'); if(ext_test && !Q_stricmpn(ext_test + 1, DEMOEXT, ARRAY_LEN(DEMOEXT) - 1)) { diff --git a/code/game/bg_lib.c b/code/game/bg_lib.c index 7003b8dd..c9ef4715 100644 --- a/code/game/bg_lib.c +++ b/code/game/bg_lib.c @@ -240,6 +240,24 @@ char *strchr( const char *string, int c ) { return (char *) string; } +char *strrchr(const char *string, int c) +{ + const char *found = 0; + + while(*string) + { + if(*string == c) + found = string; + + string++; + } + + if(c) + return (char *) found; + else + return (char *) string; +} + char *strstr( const char *string, const char *strCharSet ) { while ( *string ) { int i; diff --git a/code/game/bg_lib.h b/code/game/bg_lib.h index cd9826e7..305edca5 100644 --- a/code/game/bg_lib.h +++ b/code/game/bg_lib.h @@ -88,6 +88,7 @@ char *strcat( char *strDestination, const char *strSource ); char *strcpy( char *strDestination, const char *strSource ); int strcmp( const char *string1, const char *string2 ); char *strchr( const char *string, int c ); +char *strrchr(const char *string, int c); char *strstr( const char *string, const char *strCharSet ); char *strncpy( char *strDest, const char *strSource, size_t count ); int tolower( int c ); diff --git a/code/game/g_bot.c b/code/game/g_bot.c index 4c9cf8ce..cecf40c8 100644 --- a/code/game/g_bot.c +++ b/code/game/g_bot.c @@ -213,7 +213,7 @@ static void PlayerIntroSound( const char *modelAndSkin ) { char *skin; Q_strncpyz( model, modelAndSkin, sizeof(model) ); - skin = Q_strrchr( model, '/' ); + skin = strrchr( model, '/' ); if ( skin ) { *skin++ = '\0'; } diff --git a/code/game/g_client.c b/code/game/g_client.c index 29e1fac9..441030bd 100644 --- a/code/game/g_client.c +++ b/code/game/g_client.c @@ -626,7 +626,7 @@ Forces a client's skin (for teamplay) static void ForceClientSkin( gclient_t *client, char *model, const char *skin ) { char *p; - if ((p = Q_strrchr(model, '/')) != 0) { + if ((p = strrchr(model, '/')) != 0) { *p = 0; } diff --git a/code/q3_ui/ui_splevel.c b/code/q3_ui/ui_splevel.c index 0c3b08f5..4c7ebc95 100644 --- a/code/q3_ui/ui_splevel.c +++ b/code/q3_ui/ui_splevel.c @@ -130,7 +130,7 @@ static void PlayerIcon( const char *modelAndSkin, char *iconName, int iconNameMa char model[MAX_QPATH]; Q_strncpyz( model, modelAndSkin, sizeof(model)); - skin = Q_strrchr( model, '/' ); + skin = strrchr( model, '/' ); if ( skin ) { *skin++ = '\0'; } diff --git a/code/q3_ui/ui_startserver.c b/code/q3_ui/ui_startserver.c index 4230dc33..ce9080c7 100644 --- a/code/q3_ui/ui_startserver.c +++ b/code/q3_ui/ui_startserver.c @@ -1617,7 +1617,7 @@ static void ServerPlayerIcon( const char *modelAndSkin, char *iconName, int icon char model[MAX_QPATH]; Q_strncpyz( model, modelAndSkin, sizeof(model)); - skin = Q_strrchr( model, '/' ); + skin = strrchr( model, '/' ); if ( skin ) { *skin++ = '\0'; } diff --git a/code/qcommon/files.c b/code/qcommon/files.c index 9988e539..6ccba98f 100644 --- a/code/qcommon/files.c +++ b/code/qcommon/files.c @@ -1022,7 +1022,7 @@ qboolean FS_IsDemoExt(const char *filename, int namelen) char *ext_test; int index, protocol; - ext_test = Q_strrchr(filename, '.'); + ext_test = strrchr(filename, '.'); if(ext_test && !Q_stricmpn(ext_test + 1, DEMOEXT, ARRAY_LEN(DEMOEXT) - 1)) { protocol = atoi(ext_test + ARRAY_LEN(DEMOEXT)); diff --git a/code/qcommon/q_shared.c b/code/qcommon/q_shared.c index 36261335..3b39ccad 100644 --- a/code/qcommon/q_shared.c +++ b/code/qcommon/q_shared.c @@ -683,26 +683,6 @@ int Q_isalpha( int c ) return ( 0 ); } -char* Q_strrchr( const char* string, int c ) -{ - char cc = c; - char *s; - char *sp=(char *)0; - - s = (char*)string; - - while (*s) - { - if (*s == cc) - sp = s; - s++; - } - if (cc == 0) - sp = s; - - return sp; -} - qboolean Q_isanumber( const char *s ) { char *p; diff --git a/code/qcommon/q_shared.h b/code/qcommon/q_shared.h index 9f614a50..01341f44 100644 --- a/code/qcommon/q_shared.h +++ b/code/qcommon/q_shared.h @@ -734,7 +734,6 @@ int Q_strncmp (const char *s1, const char *s2, int n); int Q_stricmpn (const char *s1, const char *s2, int n); char *Q_strlwr( char *s1 ); char *Q_strupr( char *s1 ); -char *Q_strrchr( const char* string, int c ); const char *Q_stristr( const char *s, const char *find); // buffer size safe library replacements diff --git a/code/server/sv_client.c b/code/server/sv_client.c index 9f5a9a8d..32cafee1 100644 --- a/code/server/sv_client.c +++ b/code/server/sv_client.c @@ -864,7 +864,7 @@ void SV_WriteDownloadToClient( client_t *cl , msg_t *msg ) // Chop off filename extension. Com_sprintf(pakbuf, sizeof(pakbuf), "%s", cl->downloadName); - pakptr = Q_strrchr(pakbuf, '.'); + pakptr = strrchr(pakbuf, '.'); if(pakptr) {