aboutsummaryrefslogtreecommitdiffstats
path: root/code/qcommon
diff options
context:
space:
mode:
Diffstat (limited to 'code/qcommon')
-rw-r--r--code/qcommon/common.c5
-rw-r--r--code/qcommon/cvar.c25
-rw-r--r--code/qcommon/q_shared.c20
-rw-r--r--code/qcommon/q_shared.h3
4 files changed, 48 insertions, 5 deletions
diff --git a/code/qcommon/common.c b/code/qcommon/common.c
index eb46426..7848dee 100644
--- a/code/qcommon/common.c
+++ b/code/qcommon/common.c
@@ -2965,8 +2965,11 @@ PrintCvarMatches
===============
*/
static void PrintCvarMatches( const char *s ) {
+ char value[ TRUNCATE_LENGTH ];
+
if ( !Q_stricmpn( s, shortestMatch, strlen( shortestMatch ) ) ) {
- Com_Printf( " %s = \"%s\"\n", s, Cvar_VariableString( s ) );
+ Com_TruncateLongString( value, Cvar_VariableString( s ) );
+ Com_Printf( " %s = \"%s\"\n", s, value );
}
}
diff --git a/code/qcommon/cvar.c b/code/qcommon/cvar.c
index 2f59810..2600880 100644
--- a/code/qcommon/cvar.c
+++ b/code/qcommon/cvar.c
@@ -469,7 +469,10 @@ Handles variable inspection and changing from the console
============
*/
qboolean Cvar_Command( void ) {
- cvar_t *v;
+ cvar_t *v;
+ char string[ TRUNCATE_LENGTH ];
+ char resetString[ TRUNCATE_LENGTH ];
+ char latchedString[ TRUNCATE_LENGTH ];
// check variables
v = Cvar_FindVar (Cmd_Argv(0));
@@ -479,9 +482,13 @@ qboolean Cvar_Command( void ) {
// perform a variable print or set
if ( Cmd_Argc() == 1 ) {
- Com_Printf ("\"%s\" is:\"%s" S_COLOR_WHITE "\" default:\"%s" S_COLOR_WHITE "\"\n", v->name, v->string, v->resetString );
+ Com_TruncateLongString( string, v->string );
+ Com_TruncateLongString( resetString, v->resetString );
+ Com_Printf ("\"%s\" is:\"%s" S_COLOR_WHITE "\" default:\"%s" S_COLOR_WHITE "\"\n",
+ v->name, string, resetString );
if ( v->latchedString ) {
- Com_Printf( "latched: \"%s\"\n", v->latchedString );
+ Com_TruncateLongString( latchedString, v->latchedString );
+ Com_Printf( "latched: \"%s\"\n", latchedString );
}
return qtrue;
}
@@ -645,11 +652,21 @@ void Cvar_WriteVariables( fileHandle_t f ) {
if( var->flags & CVAR_ARCHIVE ) {
// write the latched value, even if it hasn't taken effect yet
if ( var->latchedString ) {
+ if( strlen( var->name ) + strlen( var->latchedString ) + 10 > sizeof( buffer ) ) {
+ Com_Printf( S_COLOR_YELLOW "WARNING: value of variable "
+ "\"%s\" too long to write to file\n", var->name );
+ continue;
+ }
Com_sprintf (buffer, sizeof(buffer), "seta %s \"%s\"\n", var->name, var->latchedString);
} else {
+ if( strlen( var->name ) + strlen( var->string ) + 10 > sizeof( buffer ) ) {
+ Com_Printf( S_COLOR_YELLOW "WARNING: value of variable "
+ "\"%s\" too long to write to file\n", var->name );
+ continue;
+ }
Com_sprintf (buffer, sizeof(buffer), "seta %s \"%s\"\n", var->name, var->string);
}
- FS_Printf (f, "%s", buffer);
+ FS_Write( buffer, strlen( buffer ), f );
}
}
}
diff --git a/code/qcommon/q_shared.c b/code/qcommon/q_shared.c
index 2100390..de54e17 100644
--- a/code/qcommon/q_shared.c
+++ b/code/qcommon/q_shared.c
@@ -918,6 +918,26 @@ char * QDECL va( char *format, ... ) {
return buf;
}
+/*
+============
+Com_TruncateLongString
+
+Assumes buffer is atleast TRUNCATE_LENGTH big
+============
+*/
+void Com_TruncateLongString( char *buffer, const char *s )
+{
+ int length = strlen( s );
+
+ if( length <= TRUNCATE_LENGTH )
+ Q_strncpyz( buffer, s, TRUNCATE_LENGTH );
+ else
+ {
+ Q_strncpyz( buffer, s, ( TRUNCATE_LENGTH / 2 ) - 3 );
+ Q_strcat( buffer, TRUNCATE_LENGTH, " ... " );
+ Q_strcat( buffer, TRUNCATE_LENGTH, s + length - ( TRUNCATE_LENGTH / 2 ) + 3 );
+ }
+}
/*
=====================================================================
diff --git a/code/qcommon/q_shared.h b/code/qcommon/q_shared.h
index 2dc5500..6e55a4d 100644
--- a/code/qcommon/q_shared.h
+++ b/code/qcommon/q_shared.h
@@ -682,6 +682,9 @@ void Swap_Init (void);
*/
char * QDECL va(char *format, ...);
+#define TRUNCATE_LENGTH 64
+void Com_TruncateLongString( char *buffer, const char *s );
+
//=============================================
//