Browse Source

engine: client: simplified strings operations.

pull/2/head
Andrey Akhmichin 4 years ago committed by Alibek Omarov
parent
commit
5aef09ce5d
  1. 4
      engine/client/cl_cmds.c
  2. 2
      engine/client/cl_custom.c
  3. 4
      engine/client/cl_demo.c
  4. 2
      engine/client/cl_gameui.c
  5. 4
      engine/client/cl_main.c
  6. 11
      engine/client/cl_parse.c
  7. 18
      engine/client/cl_tent.c
  8. 8
      engine/client/console.c
  9. 8
      engine/client/in_touch.c
  10. 22
      engine/client/keys.c
  11. 2
      engine/client/ref_common.c
  12. 2
      engine/client/s_load.c
  13. 4
      engine/client/s_main.c
  14. 9
      engine/client/s_vox.c
  15. 2
      engine/client/titles.c

4
engine/client/cl_cmds.c

@ -126,7 +126,7 @@ void CL_PlayCDTrack_f( void )
int i, maxTrack; int i, maxTrack;
for( maxTrack = i = 0; i < MAX_CDTRACKS; i++ ) for( maxTrack = i = 0; i < MAX_CDTRACKS; i++ )
if( Q_strlen( clgame.cdtracks[i] )) maxTrack++; if( COM_CheckStringEmpty( clgame.cdtracks[i] ) ) maxTrack++;
Con_Printf( "%u tracks\n", maxTrack ); Con_Printf( "%u tracks\n", maxTrack );
if( track ) if( track )
@ -360,7 +360,7 @@ void CL_SaveShot_f( void )
return; return;
} }
Q_sprintf( cls.shotname, "%s%s.bmp", DEFAULT_SAVE_DIRECTORY, Cmd_Argv( 1 )); Q_sprintf( cls.shotname, DEFAULT_SAVE_DIRECTORY "%s.bmp", Cmd_Argv( 1 ));
cls.scrshot_action = scrshot_savegame; // build new frame for saveshot cls.scrshot_action = scrshot_savegame; // build new frame for saveshot
} }

2
engine/client/cl_custom.c

@ -39,7 +39,7 @@ qboolean CL_CheckFile( sizebuf_t *msg, resource_t *pResource )
} }
if( pResource->type == t_sound ) if( pResource->type == t_sound )
Q_strncpy( filepath, va( "%s%s", DEFAULT_SOUNDPATH, pResource->szFileName ), sizeof( filepath )); Q_snprintf( filepath, sizeof( filepath ), DEFAULT_SOUNDPATH "%s", pResource->szFileName );
else Q_strncpy( filepath, pResource->szFileName, sizeof( filepath )); else Q_strncpy( filepath, pResource->szFileName, sizeof( filepath ));
if( !COM_IsSafeFileToDownload( filepath )) if( !COM_IsSafeFileToDownload( filepath ))

4
engine/client/cl_demo.c

@ -1185,7 +1185,7 @@ int GAME_EXPORT CL_GetDemoComment( const char *demoname, char *comment )
demfile = FS_Open( demoname, "rb", false ); demfile = FS_Open( demoname, "rb", false );
if( !demfile ) if( !demfile )
{ {
Q_strncpy( comment, "", MAX_STRING ); comment[0] = '\0';
return false; return false;
} }
@ -1226,7 +1226,7 @@ int GAME_EXPORT CL_GetDemoComment( const char *demoname, char *comment )
// split comment to sections // split comment to sections
Q_strncpy( comment, demohdr.mapname, CS_SIZE ); Q_strncpy( comment, demohdr.mapname, CS_SIZE );
Q_strncpy( comment + CS_SIZE, demohdr.comment, CS_SIZE ); Q_strncpy( comment + CS_SIZE, demohdr.comment, CS_SIZE );
Q_strncpy( comment + CS_SIZE * 2, va( "%g sec", playtime ), CS_TIME ); Q_snprintf( comment + CS_SIZE * 2, CS_TIME, "%g sec", playtime );
// all done // all done
FS_Close( demfile ); FS_Close( demfile );

2
engine/client/cl_gameui.c

@ -403,7 +403,7 @@ static void UI_ConvertGameInfo( GAMEINFO *out, gameinfo_t *in )
Q_strncpy( out->startmap, in->startmap, sizeof( out->startmap )); Q_strncpy( out->startmap, in->startmap, sizeof( out->startmap ));
Q_strncpy( out->trainmap, in->trainmap, sizeof( out->trainmap )); Q_strncpy( out->trainmap, in->trainmap, sizeof( out->trainmap ));
Q_strncpy( out->title, in->title, sizeof( out->title )); Q_strncpy( out->title, in->title, sizeof( out->title ));
Q_strncpy( out->version, va( "%g", in->version ), sizeof( out->version )); Q_snprintf( out->version, sizeof( out->version ), "%g", in->version );
Q_strncpy( out->game_url, in->game_url, sizeof( out->game_url )); Q_strncpy( out->game_url, in->game_url, sizeof( out->game_url ));
Q_strncpy( out->update_url, in->update_url, sizeof( out->update_url )); Q_strncpy( out->update_url, in->update_url, sizeof( out->update_url ));

4
engine/client/cl_main.c

@ -2397,7 +2397,7 @@ A file has been received via the fragmentation/reassembly layer, put it in the r
*/ */
void CL_ProcessFile( qboolean successfully_received, const char *filename ) void CL_ProcessFile( qboolean successfully_received, const char *filename )
{ {
int sound_len = Q_strlen( DEFAULT_SOUNDPATH ); int sound_len = sizeof( DEFAULT_SOUNDPATH ) - 1;
byte rgucMD5_hash[16]; byte rgucMD5_hash[16];
const char *pfilename; const char *pfilename;
resource_t *p; resource_t *p;
@ -2666,7 +2666,7 @@ qboolean CL_PrecacheResources( void )
{ {
if( FBitSet( pRes->ucFlags, RES_WASMISSING )) if( FBitSet( pRes->ucFlags, RES_WASMISSING ))
{ {
Con_Printf( S_ERROR "Could not load sound %s%s\n", DEFAULT_SOUNDPATH, pRes->szFileName ); Con_Printf( S_ERROR "Could not load sound " DEFAULT_SOUNDPATH "%s\n", pRes->szFileName );
cl.sound_precache[pRes->nIndex][0] = 0; cl.sound_precache[pRes->nIndex][0] = 0;
cl.sound_index[pRes->nIndex] = 0; cl.sound_index[pRes->nIndex] = 0;
} }

11
engine/client/cl_parse.c

@ -501,11 +501,8 @@ void CL_BatchResourceRequest( qboolean initialize )
{ {
if( !FBitSet( p->ucFlags, RES_REQUESTED )) if( !FBitSet( p->ucFlags, RES_REQUESTED ))
{ {
string filename;
Q_snprintf( filename, sizeof( filename ), "!MD5%s", MD5_Print( p->rgucMD5_hash ));
MSG_BeginClientCmd( &msg, clc_stringcmd ); MSG_BeginClientCmd( &msg, clc_stringcmd );
MSG_WriteString( &msg, va( "dlfile %s", filename )); MSG_WriteString( &msg, va( "dlfile !MD5%s", MD5_Print( p->rgucMD5_hash ) ) );
SetBits( p->ucFlags, RES_REQUESTED ); SetBits( p->ucFlags, RES_REQUESTED );
} }
break; break;
@ -560,7 +557,7 @@ int CL_EstimateNeededResources( void )
switch( p->type ) switch( p->type )
{ {
case t_sound: case t_sound:
if( p->szFileName[0] != '*' && !FS_FileExists( va( "%s%s", DEFAULT_SOUNDPATH, p->szFileName ), false ) ) if( p->szFileName[0] != '*' && !FS_FileExists( va( DEFAULT_SOUNDPATH "%s", p->szFileName ), false ) )
{ {
SetBits( p->ucFlags, RES_WASMISSING ); SetBits( p->ucFlags, RES_WASMISSING );
nTotalSize += p->nDownloadSize; nTotalSize += p->nDownloadSize;
@ -1496,7 +1493,7 @@ void CL_SendConsistencyInfo( sizebuf_t *msg )
MSG_WriteUBitLong( msg, pc->orig_index, MAX_MODEL_BITS ); MSG_WriteUBitLong( msg, pc->orig_index, MAX_MODEL_BITS );
if( pc->issound ) if( pc->issound )
Q_snprintf( filename, sizeof( filename ), "%s%s", DEFAULT_SOUNDPATH, pc->filename ); Q_snprintf( filename, sizeof( filename ), DEFAULT_SOUNDPATH "%s", pc->filename );
else Q_strncpy( filename, pc->filename, sizeof( filename )); else Q_strncpy( filename, pc->filename, sizeof( filename ));
if( Q_strstr( filename, "models/" )) if( Q_strstr( filename, "models/" ))
@ -2805,7 +2802,7 @@ void CL_LegacyParseResourceList( sizebuf_t *msg )
const char *path; const char *path;
if( reslist.restype[i] == t_sound ) if( reslist.restype[i] == t_sound )
path = va( "sound/%s", reslist.resnames[i] ); path = va( DEFAULT_SOUNDPATH "%s", reslist.resnames[i] );
else path = reslist.resnames[i]; else path = reslist.resnames[i];
if( FS_FileExists( path, false )) if( FS_FileExists( path, false ))

18
engine/client/cl_tent.c

@ -163,7 +163,7 @@ void CL_AddClientResources( void )
// then check sounds // then check sounds
for( i = 0; i < ARRAYSIZE( cl_player_shell_sounds ); i++ ) for( i = 0; i < ARRAYSIZE( cl_player_shell_sounds ); i++ )
{ {
Q_snprintf( filepath, sizeof( filepath ), "%s%s", DEFAULT_SOUNDPATH, cl_player_shell_sounds[i] ); Q_snprintf( filepath, sizeof( filepath ), DEFAULT_SOUNDPATH "%s", cl_player_shell_sounds[i] );
if( !FS_FileExists( filepath, false )) if( !FS_FileExists( filepath, false ))
CL_AddClientResource( cl_player_shell_sounds[i], t_sound ); CL_AddClientResource( cl_player_shell_sounds[i], t_sound );
@ -171,7 +171,7 @@ void CL_AddClientResources( void )
for( i = 0; i < ARRAYSIZE( cl_weapon_shell_sounds ); i++ ) for( i = 0; i < ARRAYSIZE( cl_weapon_shell_sounds ); i++ )
{ {
Q_snprintf( filepath, sizeof( filepath ), "%s%s", DEFAULT_SOUNDPATH, cl_weapon_shell_sounds[i] ); Q_snprintf( filepath, sizeof( filepath ), DEFAULT_SOUNDPATH "%s", cl_weapon_shell_sounds[i] );
if( !FS_FileExists( filepath, false )) if( !FS_FileExists( filepath, false ))
CL_AddClientResource( cl_weapon_shell_sounds[i], t_sound ); CL_AddClientResource( cl_weapon_shell_sounds[i], t_sound );
@ -179,7 +179,7 @@ void CL_AddClientResources( void )
for( i = 0; i < ARRAYSIZE( cl_explode_sounds ); i++ ) for( i = 0; i < ARRAYSIZE( cl_explode_sounds ); i++ )
{ {
Q_snprintf( filepath, sizeof( filepath ), "%s%s", DEFAULT_SOUNDPATH, cl_explode_sounds[i] ); Q_snprintf( filepath, sizeof( filepath ), DEFAULT_SOUNDPATH "%s", cl_explode_sounds[i] );
if( !FS_FileExists( filepath, false )) if( !FS_FileExists( filepath, false ))
CL_AddClientResource( cl_explode_sounds[i], t_sound ); CL_AddClientResource( cl_explode_sounds[i], t_sound );
@ -188,7 +188,7 @@ void CL_AddClientResources( void )
#if 0 // ric sounds was precached by server-side #if 0 // ric sounds was precached by server-side
for( i = 0; i < ARRAYSIZE( cl_ricochet_sounds ); i++ ) for( i = 0; i < ARRAYSIZE( cl_ricochet_sounds ); i++ )
{ {
Q_snprintf( filepath, sizeof( filepath ), "%s%s", DEFAULT_SOUNDPATH, cl_ricochet_sounds[i] ); Q_snprintf( filepath, sizeof( filepath ), DEFAULT_SOUNDPATH "%s", cl_ricochet_sounds[i] );
if( !FS_FileExists( filepath, false )) if( !FS_FileExists( filepath, false ))
CL_AddClientResource( cl_ricochet_sounds[i], t_sound ); CL_AddClientResource( cl_ricochet_sounds[i], t_sound );
@ -322,15 +322,15 @@ void CL_TempEntPlaySound( TEMPENTITY *pTemp, float damp )
Q_snprintf( soundname, sizeof( soundname ), "debris/wood%i.wav", COM_RandomLong( 1, 4 )); Q_snprintf( soundname, sizeof( soundname ), "debris/wood%i.wav", COM_RandomLong( 1, 4 ));
break; break;
case BOUNCE_SHRAP: case BOUNCE_SHRAP:
Q_snprintf( soundname, sizeof( soundname ), "%s", cl_ricochet_sounds[COM_RandomLong( 0, 4 )] ); Q_strncpy( soundname, cl_ricochet_sounds[COM_RandomLong( 0, 4 )], sizeof( soundname ) );
break; break;
case BOUNCE_SHOTSHELL: case BOUNCE_SHOTSHELL:
Q_snprintf( soundname, sizeof( soundname ), "%s", cl_weapon_shell_sounds[COM_RandomLong( 0, 2 )] ); Q_strncpy( soundname, cl_weapon_shell_sounds[COM_RandomLong( 0, 2 )], sizeof( soundname ) );
isshellcasing = true; // shell casings have different playback parameters isshellcasing = true; // shell casings have different playback parameters
fvol = 0.5f; fvol = 0.5f;
break; break;
case BOUNCE_SHELL: case BOUNCE_SHELL:
Q_snprintf( soundname, sizeof( soundname ), "%s", cl_player_shell_sounds[COM_RandomLong( 0, 2 )] ); Q_strncpy( soundname, cl_player_shell_sounds[COM_RandomLong( 0, 2 )], sizeof( soundname ) );
isshellcasing = true; // shell casings have different playback parameters isshellcasing = true; // shell casings have different playback parameters
break; break;
case BOUNCE_CONCRETE: case BOUNCE_CONCRETE:
@ -1522,7 +1522,7 @@ void GAME_EXPORT R_RicochetSound( const vec3_t pos )
char soundpath[32]; char soundpath[32];
sound_t handle; sound_t handle;
Q_snprintf( soundpath, sizeof( soundpath ), "%s", cl_ricochet_sounds[COM_RandomLong( 0, 4 )] ); Q_strncpy( soundpath, cl_ricochet_sounds[COM_RandomLong( 0, 4 )], sizeof( soundpath ) );
handle = S_RegisterSound( soundpath ); handle = S_RegisterSound( soundpath );
S_StartSound( pos, 0, CHAN_AUTO, handle, fvol, ATTN_NORM, iPitch, 0 ); S_StartSound( pos, 0, CHAN_AUTO, handle, fvol, ATTN_NORM, iPitch, 0 );
@ -1672,7 +1672,7 @@ void GAME_EXPORT R_Explosion( vec3_t pos, int model, float scale, float framerat
if( !FBitSet( flags, TE_EXPLFLAG_NOSOUND )) if( !FBitSet( flags, TE_EXPLFLAG_NOSOUND ))
{ {
hSound = S_RegisterSound( va( "%s", cl_explode_sounds[COM_RandomLong( 0, 2 )] )); hSound = S_RegisterSound( cl_explode_sounds[COM_RandomLong( 0, 2 )] );
S_StartSound( pos, 0, CHAN_STATIC, hSound, VOL_NORM, 0.3f, PITCH_NORM, 0 ); S_StartSound( pos, 0, CHAN_STATIC, hSound, VOL_NORM, 0.3f, PITCH_NORM, 0 );
} }
} }

8
engine/client/console.c

@ -2427,13 +2427,13 @@ void Con_VidInit( void )
lmp_t *cb = (lmp_t *)FS_LoadFile( "gfx/conback.lmp", &length, false ); lmp_t *cb = (lmp_t *)FS_LoadFile( "gfx/conback.lmp", &length, false );
char ver[64]; char ver[64];
byte *dest; byte *dest;
int x, y; int x, y, len;
if( cb && cb->width == 320 && cb->height == 200 ) if( cb && cb->width == 320 && cb->height == 200 )
{ {
Q_snprintf( ver, 64, "%i", Q_buildnum( )); // can store only buildnum len = Q_snprintf( ver, 64, "%i", Q_buildnum( )); // can store only buildnum
dest = (byte *)(cb + 1) + 320 * 186 + 320 - 11 - 8 * Q_strlen( ver ); dest = (byte *)(cb + 1) + 320 * 186 + 320 - 11 - 8 * len;
y = Q_strlen( ver ); y = len;
for( x = 0; x < y; x++ ) for( x = 0; x < y; x++ )
Con_DrawCharToConback( ver[x], buf, dest + (x << 3)); Con_DrawCharToConback( ver[x], buf, dest + (x << 3));
con.background = ref.dllFuncs.GL_LoadTexture( "#gfx/conback.lmp", (byte *)cb, length, TF_IMAGE ); con.background = ref.dllFuncs.GL_LoadTexture( "#gfx/conback.lmp", (byte *)cb, length, TF_IMAGE );

8
engine/client/in_touch.c

@ -447,7 +447,7 @@ touch_button_t *Touch_FindFirst( touchbuttonlist_t *list, const char *name )
touch_button_t *button; touch_button_t *button;
for ( button = list->first; button; button = button->next ) for ( button = list->first; button; button = button->next )
if( ( Q_strstr( name, "*" ) && Q_stricmpext( name, button->name ) ) || !Q_strncmp( name, button->name, 32 ) ) if( ( Q_strchr( name, '*' ) && Q_stricmpext( name, button->name ) ) || !Q_strncmp( name, button->name, 32 ) )
return button; return button;
return NULL; return NULL;
} }
@ -534,7 +534,7 @@ void Touch_SetColor( touchbuttonlist_t *list, const char *name, byte *color )
touch_button_t *button; touch_button_t *button;
for( button = list->first; button; button = button->next ) for( button = list->first; button; button = button->next )
{ {
if( ( Q_strstr( name, "*" ) && Q_stricmpext( name, button->name ) ) || !Q_strncmp( name, button->name, 32 ) ) if( ( Q_strchr( name, '*' ) && Q_stricmpext( name, button->name ) ) || !Q_strncmp( name, button->name, 32 ) )
MakeRGBA( button->color, color[0], color[1], color[2], color[3] ); MakeRGBA( button->color, color[0], color[1], color[2], color[3] );
} }
} }
@ -570,7 +570,7 @@ void Touch_HideButtons( const char *name, byte hide )
for( button = touch.list_user.first; button; button = button->next) for( button = touch.list_user.first; button; button = button->next)
{ {
if( ( Q_strstr( name, "*" ) && Q_stricmpext( name, button->name ) ) || !Q_strncmp( name, button->name, 32 ) ) if( ( Q_strchr( name, '*' ) && Q_stricmpext( name, button->name ) ) || !Q_strncmp( name, button->name, 32 ) )
{ {
if( hide ) if( hide )
button->flags |= TOUCH_FL_HIDE; button->flags |= TOUCH_FL_HIDE;
@ -602,7 +602,7 @@ void Touch_FadeButtons( touchbuttonlist_t *list, const char *name, float speed,
touch_button_t *button; touch_button_t *button;
for( button = list->first; button; button = button->next) for( button = list->first; button; button = button->next)
{ {
if( ( Q_strstr( name, "*" ) && Q_stricmpext( name, button->name ) ) || !Q_strncmp( name, button->name, 32 ) ) if( ( Q_strchr( name, '*' ) && Q_stricmpext( name, button->name ) ) || !Q_strncmp( name, button->name, 32 ) )
{ {
if( start >= 0 ) if( start >= 0 )
button->fade = start; button->fade = start;

22
engine/client/keys.c

@ -313,25 +313,25 @@ Key_GetKey
*/ */
int Key_GetKey( const char *pBinding ) int Key_GetKey( const char *pBinding )
{ {
int i; int i, len;
const char *p;
if( !pBinding ) return -1; if( !pBinding ) return -1;
len = Q_strlen( pBinding );
for( i = 0; i < 256; i++ ) for( i = 0; i < 256; i++ )
{ {
if( !keys[i].binding ) if( !keys[i].binding )
continue; continue;
if( *keys[i].binding == '+' ) p = keys[i].binding;
{
if( !Q_strnicmp( keys[i].binding + 1, pBinding, Q_strlen( pBinding ))) if( *p == '+' )
return i; p++;
}
else if( !Q_strnicmp( p, pBinding, len ) )
{ return i;
if( !Q_strnicmp( keys[i].binding, pBinding, Q_strlen( pBinding )))
return i;
}
} }
return -1; return -1;

2
engine/client/ref_common.c

@ -508,7 +508,7 @@ void R_Shutdown( void )
static void R_GetRendererName( char *dest, size_t size, const char *opt ) static void R_GetRendererName( char *dest, size_t size, const char *opt )
{ {
if( !Q_strstr( opt, va( ".%s", OS_LIB_EXT ))) if( !Q_strstr( opt, "." OS_LIB_EXT ))
{ {
const char *format; const char *format;

2
engine/client/s_load.c

@ -56,7 +56,7 @@ void S_SoundList_f( void )
else Con_Printf( " " ); else Con_Printf( " " );
if( sfx->name[0] == '*' ) if( sfx->name[0] == '*' )
Con_Printf( " (%2db) %s : %s\n", sc->width * 8, Q_memprint( sc->size ), sfx->name ); Con_Printf( " (%2db) %s : %s\n", sc->width * 8, Q_memprint( sc->size ), sfx->name );
else Con_Printf( " (%2db) %s : %s%s\n", sc->width * 8, Q_memprint( sc->size ), DEFAULT_SOUNDPATH, sfx->name ); else Con_Printf( " (%2db) %s : " DEFAULT_SOUNDPATH "%s\n", sc->width * 8, Q_memprint( sc->size ), sfx->name );
totalSfx++; totalSfx++;
} }
} }

4
engine/client/s_main.c

@ -525,7 +525,7 @@ void S_StartSound( const vec3_t pos, int ent, int chan, sound_t handle, float fv
if( !target_chan ) if( !target_chan )
{ {
if( !bIgnore ) if( !bIgnore )
Con_DPrintf( S_ERROR "dropped sound \"%s%s\"\n", DEFAULT_SOUNDPATH, sfx->name ); Con_DPrintf( S_ERROR "dropped sound \"" DEFAULT_SOUNDPATH "%s\"\n", sfx->name );
return; return;
} }
@ -637,7 +637,7 @@ void S_RestoreSound( const vec3_t pos, int ent, int chan, sound_t handle, float
if( !target_chan ) if( !target_chan )
{ {
if( !bIgnore ) if( !bIgnore )
Con_DPrintf( S_ERROR "dropped sound \"%s%s\"\n", DEFAULT_SOUNDPATH, sfx->name ); Con_DPrintf( S_ERROR "dropped sound \"" DEFAULT_SOUNDPATH "%s\"\n", sfx->name );
return; return;
} }

9
engine/client/s_vox.c

@ -76,8 +76,11 @@ static char *ScanForwardUntil( char *string, const char scan )
static char *VOX_GetDirectory( char *szpath, char *psz ) static char *VOX_GetDirectory( char *szpath, char *psz )
{ {
char c; char c;
int cb = 0; int cb = 0, len;
char *p = psz + Q_strlen( psz ) - 1; char *p;
len = Q_strlen( psz );
p = psz + len - 1;
// scan backwards until first '/' or start of string // scan backwards until first '/' or start of string
c = *p; c = *p;
@ -94,7 +97,7 @@ static char *VOX_GetDirectory( char *szpath, char *psz )
return psz; return psz;
} }
cb = Q_strlen( psz ) - cb; cb = len - cb;
memcpy( szpath, psz, cb ); memcpy( szpath, psz, cb );
szpath[cb] = 0; szpath[cb] = 0;

2
engine/client/titles.c

@ -275,7 +275,7 @@ void CL_TextMessageParse( byte *pMemFile, int fileSize )
// Save name/text on heap // Save name/text on heap
textMessages[messageCount] = gMessageParms; textMessages[messageCount] = gMessageParms;
textMessages[messageCount].pName = nameHeap + lastNamePos; textMessages[messageCount].pName = nameHeap + lastNamePos;
lastNamePos += Q_strlen( currentName ) + 1; lastNamePos += length + 1;
textMessages[messageCount].pMessage = pCurrentText; textMessages[messageCount].pMessage = pCurrentText;
messageCount++; messageCount++;

Loading…
Cancel
Save