Skip to content

Commit

Permalink
- Remove Q_strrchr(), replace with standard, portable strrchr()
Browse files Browse the repository at this point in the history
- Add strrchr() to bg_lib.c, patch by DevHC
  • Loading branch information
Thilo Schulz committed May 15, 2011
1 parent 3ddc59a commit b509d77
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion code/cgame/cg_info.c
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion code/client/cl_main.c
Expand Up @@ -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))
{
Expand Down
18 changes: 18 additions & 0 deletions code/game/bg_lib.c
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions code/game/bg_lib.h
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion code/game/g_bot.c
Expand Up @@ -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';
}
Expand Down
2 changes: 1 addition & 1 deletion code/game/g_client.c
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion code/q3_ui/ui_splevel.c
Expand Up @@ -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';
}
Expand Down
2 changes: 1 addition & 1 deletion code/q3_ui/ui_startserver.c
Expand Up @@ -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';
}
Expand Down
2 changes: 1 addition & 1 deletion code/qcommon/files.c
Expand Up @@ -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));
Expand Down
20 changes: 0 additions & 20 deletions code/qcommon/q_shared.c
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion code/qcommon/q_shared.h
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/server/sv_client.c
Expand Up @@ -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)
{
Expand Down

0 comments on commit b509d77

Please sign in to comment.