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
This commit is contained in:
Thilo Schulz 2008-03-25 16:20:03 +00:00
parent 7a5243a3b2
commit 302b1b49ff
2 changed files with 71 additions and 87 deletions

1
README
View file

@ -144,6 +144,7 @@ New cvars
New commands
video [filename] - start video capture (use with demo command)
stopvideo - stop video capture
print - print out the contents of a cvar
------------------------------------------------------------ Miscellaneous -----

View file

@ -294,6 +294,33 @@ cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) {
return var;
}
/*
============
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 @@ qboolean Cvar_Command( void ) {
// 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;
}
@ -534,6 +545,18 @@ qboolean Cvar_Command( void ) {
}
/*
============
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
@ -565,11 +588,19 @@ weren't declared in C code.
*/
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;
}
@ -586,73 +617,24 @@ void Cvar_Set_f( void ) {
}
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");
return;
}
Cvar_Set_f();
v = Cvar_FindVar( Cmd_Argv( 1 ) );
if ( !v ) {
v = Cvar_Set2 (Cmd_Argv(1), combined, qfalse);
if( !v ) {
return;
}
switch( cmd[3] ) {
default:
case '\0':
break;
case 'u':
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;
}
break;
case 's':
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;
}
break;
case 'a':
v->flags |= CVAR_ARCHIVE;
break;
}
}
/*
@ -940,11 +922,12 @@ Reads in all archived cvars
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);