r1275 - in trunk: . code/qcommon

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue Mar 25 12:20:06 EDT 2008


Author: thilo
Date: 2008-03-25 12:20:03 -0400 (Tue, 25 Mar 2008)
New Revision: 1275

Modified:
   trunk/README
   trunk/code/qcommon/cvar.c
Log:
Applied patch to clean up code for reading cvars and add new command "print" for printing the content of cvars, by Ben Millwood.
See also https://bugzilla.icculus.org/show_bug.cgi?id=3546


Modified: trunk/README
===================================================================
--- trunk/README	2008-03-24 21:20:55 UTC (rev 1274)
+++ trunk/README	2008-03-25 16:20:03 UTC (rev 1275)
@@ -144,6 +144,7 @@
 New commands
   video [filename]        - start video capture (use with demo command)
   stopvideo               - stop video capture
+  print			  - print out the contents of a cvar
 
 
 ------------------------------------------------------------ Miscellaneous -----

Modified: trunk/code/qcommon/cvar.c
===================================================================
--- trunk/code/qcommon/cvar.c	2008-03-24 21:20:55 UTC (rev 1274)
+++ trunk/code/qcommon/cvar.c	2008-03-25 16:20:03 UTC (rev 1275)
@@ -296,6 +296,33 @@
 
 /*
 ============
+Cvar_Print
+
+Prints the value, default, and latched string of the given variable
+============
+*/
+void Cvar_Print( cvar_t *v ) {
+	Com_Printf ("\"%s\" is:\"%s" S_COLOR_WHITE "\"",
+			v->name, v->string );
+
+	if ( !( v->flags & CVAR_ROM ) ) {
+		if ( !Q_stricmp( v->string, v->resetString ) ) {
+			Com_Printf (", the default" );
+		} else {
+			Com_Printf (" default:\"%s" S_COLOR_WHITE "\"",
+					v->resetString );
+		}
+	}
+
+	Com_Printf ("\n");
+
+	if ( v->latchedString ) {
+		Com_Printf( "latched: \"%s\"\n", v->latchedString );
+	}
+}
+
+/*
+============
 Cvar_Set2
 ============
 */
@@ -508,23 +535,7 @@
 
 	// perform a variable print or set
 	if ( Cmd_Argc() == 1 ) {
-		Com_Printf ("\"%s\" is:\"%s" S_COLOR_WHITE "\"",
-				v->name, v->string );
-
-		if ( !( v->flags & CVAR_ROM ) ) {
-			if ( !Q_stricmp( v->string, v->resetString ) ) {
-				Com_Printf (", the default" );
-			} else {
-				Com_Printf (" default:\"%s" S_COLOR_WHITE "\"",
-						v->resetString );
-			}
-		}
-
-		Com_Printf ("\n");
-
-		if ( v->latchedString ) {
-			Com_Printf( "latched: \"%s\"\n", v->latchedString );
-		}
+		Cvar_Print( v );
 		return qtrue;
 	}
 
@@ -536,6 +547,18 @@
 
 /*
 ============
+Cvar_Print_f
+
+Prints the contents of a cvar 
+(preferred over Cvar_Command where cvar names and commands conflict)
+============
+*/
+void Cvar_Print_f( void ) {
+	Cvar_Print (Cvar_FindVar (Cmd_Argv(1)) );
+}
+
+/*
+============
 Cvar_Toggle_f
 
 Toggles a cvar for easy single key binding
@@ -565,13 +588,21 @@
 */
 void Cvar_Set_f( void ) {
 	int		i, c, l, len;
-	char	combined[MAX_STRING_TOKENS];
+	char	cmd[5], combined[MAX_STRING_TOKENS];
+	cvar_t *v;
 
 	c = Cmd_Argc();
-	if ( c < 3 ) {
-		Com_Printf ("usage: set <variable> <value>\n");
+	Q_strncpyz( cmd, Cmd_Argv(0), sizeof( cmd ) );
+
+	if ( c < 2 ) {
+		Com_Printf ("usage: %s <variable> <value>\n", cmd);
 		return;
 	}
+	if ( c == 2 ) {
+		v = Cvar_FindVar (Cmd_Argv(1));
+		Cvar_Print( v );
+		return;
+	}
 
 	combined[0] = 0;
 	l = 0;
@@ -586,77 +617,28 @@
 		}
 		l += len;
 	}
-	Cvar_Set2 (Cmd_Argv(1), combined, qfalse);
-}
-
-/*
-============
-Cvar_SetU_f
-
-As Cvar_Set, but also flags it as userinfo
-============
-*/
-void Cvar_SetU_f( void ) {
-	cvar_t	*v;
-
-	if ( Cmd_Argc() != 3 ) {
-		Com_Printf ("usage: setu <variable> <value>\n");
+	v = Cvar_Set2 (Cmd_Argv(1), combined, qfalse);
+	if( !v ) {
 		return;
 	}
-	Cvar_Set_f();
-	v = Cvar_FindVar( Cmd_Argv( 1 ) );
-	if ( !v ) {
-		return;
+	switch( cmd[3] ) {
+		default:
+		case '\0':
+			break;
+		case 'u':
+			v->flags |= CVAR_USERINFO;
+			break;
+		case 's':
+			v->flags |= CVAR_SERVERINFO;
+			break;
+		case 'a':
+			v->flags |= CVAR_ARCHIVE;
+			break;
 	}
-	v->flags |= CVAR_USERINFO;
 }
 
 /*
 ============
-Cvar_SetS_f
-
-As Cvar_Set, but also flags it as userinfo
-============
-*/
-void Cvar_SetS_f( void ) {
-	cvar_t	*v;
-
-	if ( Cmd_Argc() != 3 ) {
-		Com_Printf ("usage: sets <variable> <value>\n");
-		return;
-	}
-	Cvar_Set_f();
-	v = Cvar_FindVar( Cmd_Argv( 1 ) );
-	if ( !v ) {
-		return;
-	}
-	v->flags |= CVAR_SERVERINFO;
-}
-
-/*
-============
-Cvar_SetA_f
-
-As Cvar_Set, but also flags it as archived
-============
-*/
-void Cvar_SetA_f( void ) {
-	cvar_t	*v;
-
-	if ( Cmd_Argc() != 3 ) {
-		Com_Printf ("usage: seta <variable> <value>\n");
-		return;
-	}
-	Cvar_Set_f();
-	v = Cvar_FindVar( Cmd_Argv( 1 ) );
-	if ( !v ) {
-		return;
-	}
-	v->flags |= CVAR_ARCHIVE;
-}
-
-/*
-============
 Cvar_Reset_f
 ============
 */
@@ -940,11 +922,12 @@
 void Cvar_Init (void) {
 	cvar_cheats = Cvar_Get("sv_cheats", "1", CVAR_ROM | CVAR_SYSTEMINFO );
 
+	Cmd_AddCommand ("print", Cvar_Print_f);
 	Cmd_AddCommand ("toggle", Cvar_Toggle_f);
 	Cmd_AddCommand ("set", Cvar_Set_f);
-	Cmd_AddCommand ("sets", Cvar_SetS_f);
-	Cmd_AddCommand ("setu", Cvar_SetU_f);
-	Cmd_AddCommand ("seta", Cvar_SetA_f);
+	Cmd_AddCommand ("sets", Cvar_Set_f);
+	Cmd_AddCommand ("setu", Cvar_Set_f);
+	Cmd_AddCommand ("seta", Cvar_Set_f);
 	Cmd_AddCommand ("reset", Cvar_Reset_f);
 	Cmd_AddCommand ("cvarlist", Cvar_List_f);
 	Cmd_AddCommand ("cvar_restart", Cvar_Restart_f);




More information about the quake3-commits mailing list