engine: client: simplified strings operations.

This commit is contained in:
Andrey Akhmichin 2020-11-29 04:05:42 +05:00 committed by Alibek Omarov
parent 69e15e9c7b
commit 5aef09ce5d
15 changed files with 51 additions and 51 deletions

View File

@ -126,7 +126,7 @@ void CL_PlayCDTrack_f( void )
int i, maxTrack;
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 );
if( track )
@ -360,7 +360,7 @@ void CL_SaveShot_f( void )
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
}

View File

@ -39,7 +39,7 @@ qboolean CL_CheckFile( sizebuf_t *msg, resource_t *pResource )
}
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 ));
if( !COM_IsSafeFileToDownload( filepath ))

View File

@ -1185,7 +1185,7 @@ int GAME_EXPORT CL_GetDemoComment( const char *demoname, char *comment )
demfile = FS_Open( demoname, "rb", false );
if( !demfile )
{
Q_strncpy( comment, "", MAX_STRING );
comment[0] = '\0';
return false;
}
@ -1226,7 +1226,7 @@ int GAME_EXPORT CL_GetDemoComment( const char *demoname, char *comment )
// split comment to sections
Q_strncpy( comment, demohdr.mapname, 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
FS_Close( demfile );

View File

@ -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->trainmap, in->trainmap, sizeof( out->trainmap ));
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->update_url, in->update_url, sizeof( out->update_url ));

View File

@ -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 )
{
int sound_len = Q_strlen( DEFAULT_SOUNDPATH );
int sound_len = sizeof( DEFAULT_SOUNDPATH ) - 1;
byte rgucMD5_hash[16];
const char *pfilename;
resource_t *p;
@ -2666,7 +2666,7 @@ qboolean CL_PrecacheResources( void )
{
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_index[pRes->nIndex] = 0;
}

View File

@ -501,11 +501,8 @@ void CL_BatchResourceRequest( qboolean initialize )
{
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_WriteString( &msg, va( "dlfile %s", filename ));
MSG_WriteString( &msg, va( "dlfile !MD5%s", MD5_Print( p->rgucMD5_hash ) ) );
SetBits( p->ucFlags, RES_REQUESTED );
}
break;
@ -560,7 +557,7 @@ int CL_EstimateNeededResources( void )
switch( p->type )
{
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 );
nTotalSize += p->nDownloadSize;
@ -1496,7 +1493,7 @@ void CL_SendConsistencyInfo( sizebuf_t *msg )
MSG_WriteUBitLong( msg, pc->orig_index, MAX_MODEL_BITS );
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 ));
if( Q_strstr( filename, "models/" ))
@ -2805,7 +2802,7 @@ void CL_LegacyParseResourceList( sizebuf_t *msg )
const char *path;
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];
if( FS_FileExists( path, false ))

View File

@ -163,7 +163,7 @@ void CL_AddClientResources( void )
// then check sounds
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 ))
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++ )
{
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 ))
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++ )
{
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 ))
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
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 ))
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 ));
break;
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;
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
fvol = 0.5f;
break;
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
break;
case BOUNCE_CONCRETE:
@ -1522,7 +1522,7 @@ void GAME_EXPORT R_RicochetSound( const vec3_t pos )
char soundpath[32];
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 );
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 ))
{
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 );
}
}

View File

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

View File

@ -447,7 +447,7 @@ touch_button_t *Touch_FindFirst( touchbuttonlist_t *list, const char *name )
touch_button_t *button;
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 NULL;
}
@ -534,7 +534,7 @@ void Touch_SetColor( touchbuttonlist_t *list, const char *name, byte *color )
touch_button_t *button;
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] );
}
}
@ -570,7 +570,7 @@ void Touch_HideButtons( const char *name, byte hide )
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 )
button->flags |= TOUCH_FL_HIDE;
@ -602,7 +602,7 @@ void Touch_FadeButtons( touchbuttonlist_t *list, const char *name, float speed,
touch_button_t *button;
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 )
button->fade = start;

View File

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

View File

@ -508,7 +508,7 @@ void R_Shutdown( void )
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;

View File

@ -56,7 +56,7 @@ void S_SoundList_f( void )
else Con_Printf( " " );
if( sfx->name[0] == '*' )
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++;
}
}

View File

@ -525,7 +525,7 @@ void S_StartSound( const vec3_t pos, int ent, int chan, sound_t handle, float fv
if( !target_chan )
{
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;
}
@ -637,7 +637,7 @@ void S_RestoreSound( const vec3_t pos, int ent, int chan, sound_t handle, float
if( !target_chan )
{
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;
}

View File

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

View File

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