icculus quake2 doxygen  1.0 dev
cvar.c File Reference
#include "qcommon.h"

Go to the source code of this file.

Functions

static qboolean Cvar_InfoValidate (char *s)
 
static cvar_tCvar_FindVar (char *var_name)
 
float Cvar_VariableValue (char *var_name)
 
char * Cvar_VariableString (char *var_name)
 
char * Cvar_CompleteVariable (char *partial)
 
cvar_tCvar_Get (char *var_name, char *var_value, int flags)
 
cvar_tCvar_Set2 (char *var_name, char *value, qboolean force)
 
cvar_tCvar_ForceSet (char *var_name, char *value)
 
cvar_tCvar_Set (char *var_name, char *value)
 
cvar_tCvar_FullSet (char *var_name, char *value, int flags)
 
void Cvar_SetValue (char *var_name, float value)
 
void Cvar_GetLatchedVars (void)
 
qboolean Cvar_Command (void)
 
void Cvar_Set_f (void)
 
void Cvar_WriteVariables (char *path)
 
void Cvar_List_f (void)
 
char * Cvar_BitInfo (int bit)
 
char * Cvar_Userinfo (void)
 
char * Cvar_Serverinfo (void)
 
void Cvar_Init (void)
 

Variables

cvar_tcvar_vars
 
qboolean userinfo_modified
 

Function Documentation

◆ Cvar_BitInfo()

char* Cvar_BitInfo ( int  bit)

Definition at line 488 of file cvar.c.

489 {
490  static char info[MAX_INFO_STRING];
491  cvar_t *var;
492 
493  info[0] = 0;
494 
495  for (var = cvar_vars ; var ; var = var->next)
496  {
497  if (var->flags & bit)
498  Info_SetValueForKey (info, var->name, var->string);
499  }
500  return info;
501 }

Referenced by Cvar_Serverinfo(), and Cvar_Userinfo().

◆ Cvar_Command()

qboolean Cvar_Command ( void  )

Definition at line 363 of file cvar.c.

364 {
365  cvar_t *v;
366 
367 // check variables
368  v = Cvar_FindVar (Cmd_Argv(0));
369  if (!v)
370  return false;
371 
372 // perform a variable print or set
373  if (Cmd_Argc() == 1)
374  {
375  Com_Printf ("\"%s\" is \"%s\"\n", v->name, v->string);
376  return true;
377  }
378 
379  Cvar_Set (v->name, Cmd_Argv(1));
380  return true;
381 }

Referenced by Cmd_ExecuteString().

◆ Cvar_CompleteVariable()

char* Cvar_CompleteVariable ( char *  partial)

Definition at line 95 of file cvar.c.

96 {
97  cvar_t *cvar;
98  int len;
99 
100  len = strlen(partial);
101 
102  if (!len)
103  return NULL;
104 
105  // check exact match
106  for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
107  if (!strcmp (partial,cvar->name))
108  return cvar->name;
109 
110  // check partial match
111  for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
112  if (!strncmp (partial,cvar->name, len))
113  return cvar->name;
114 
115  return NULL;
116 }

Referenced by CompleteCommand().

◆ Cvar_FindVar()

static cvar_t* Cvar_FindVar ( char *  var_name)
static

Definition at line 47 of file cvar.c.

48 {
49  cvar_t *var;
50 
51  for (var=cvar_vars ; var ; var=var->next)
52  if (!strcmp (var_name, var->name))
53  return var;
54 
55  return NULL;
56 }

Referenced by Cvar_Command(), Cvar_FullSet(), Cvar_Get(), Cvar_Set2(), Cvar_VariableString(), and Cvar_VariableValue().

◆ Cvar_ForceSet()

cvar_t* Cvar_ForceSet ( char *  var_name,
char *  value 
)

Definition at line 268 of file cvar.c.

269 {
270  return Cvar_Set2 (var_name, value, true);
271 }

Referenced by EasyGameFunc(), HardGameFunc(), MediumGameFunc(), SV_InitGameProgs(), and SV_ReadServerFile().

◆ Cvar_FullSet()

cvar_t* Cvar_FullSet ( char *  var_name,
char *  value,
int  flags 
)

Definition at line 288 of file cvar.c.

289 {
290  cvar_t *var;
291 
292  var = Cvar_FindVar (var_name);
293  if (!var)
294  { // create it
295  return Cvar_Get (var_name, value, flags);
296  }
297 
298  var->modified = true;
299 
300  if (var->flags & CVAR_USERINFO)
301  userinfo_modified = true; // transmit at next oportunity
302 
303  Z_Free (var->string); // free the old value string
304 
305  var->string = CopyString(value);
306  var->value = atof (var->string);
307  var->flags = flags;
308 
309  return var;
310 }

Referenced by Cvar_Set_f(), FS_SetGamedir(), SV_InitGame(), and SV_SpawnServer().

◆ Cvar_Get()

cvar_t* Cvar_Get ( char *  var_name,
char *  var_value,
int  flags 
)

Definition at line 127 of file cvar.c.

128 {
129  cvar_t *var;
130 
131  if (flags & (CVAR_USERINFO | CVAR_SERVERINFO))
132  {
133  if (!Cvar_InfoValidate (var_name))
134  {
135  Com_Printf("invalid info cvar name\n");
136  return NULL;
137  }
138  }
139 
140  var = Cvar_FindVar (var_name);
141  if (var)
142  {
143  var->flags |= flags;
144  return var;
145  }
146 
147  if (!var_value)
148  return NULL;
149 
150  if (flags & (CVAR_USERINFO | CVAR_SERVERINFO))
151  {
152  if (!Cvar_InfoValidate (var_value))
153  {
154  Com_Printf("invalid info cvar value\n");
155  return NULL;
156  }
157  }
158 
159  var = Z_Malloc (sizeof(*var));
160  var->name = CopyString (var_name);
161  var->string = CopyString (var_value);
162  var->modified = true;
163  var->value = atof (var->string);
164 
165  // link the variable in
166  var->next = cvar_vars;
167  cvar_vars = var;
168 
169  var->flags = flags;
170 
171  return var;
172 }

Referenced by AddressBook_MenuInit(), CDAudio_RandomPlay(), CL_FixCvarCheats(), CL_InitInput(), CL_InitLocal(), CL_PingServers_f(), CM_LoadMap(), Con_Init(), Cvar_FullSet(), Cvar_Set2(), FS_InitFilesystem(), IN_Init(), IN_StartupJoystick(), IN_StartupMouse(), NET_Init(), NET_OpenIP(), NET_OpenIPX(), Netchan_Init(), Options_MenuInit(), PlayerConfig_MenuInit(), Qcommon_Init(), S_Init(), SCR_Init(), SNDDMA_Init(), SV_Init(), SV_InitGameProgs(), V_Init(), VID_Init(), VID_LoadRefresh(), and VID_MenuInit().

◆ Cvar_GetLatchedVars()

void Cvar_GetLatchedVars ( void  )

Definition at line 336 of file cvar.c.

337 {
338  cvar_t *var;
339 
340  for (var = cvar_vars ; var ; var = var->next)
341  {
342  if (!var->latched_string)
343  continue;
344  Z_Free (var->string);
345  var->string = var->latched_string;
346  var->latched_string = NULL;
347  var->value = atof(var->string);
348  if (!strcmp(var->name, "game"))
349  {
350  FS_SetGamedir (var->string);
351  FS_ExecAutoexec ();
352  }
353  }
354 }

Referenced by SV_InitGame().

◆ Cvar_InfoValidate()

static qboolean Cvar_InfoValidate ( char *  s)
static

Definition at line 31 of file cvar.c.

32 {
33  if (strstr (s, "\\"))
34  return false;
35  if (strstr (s, "\""))
36  return false;
37  if (strstr (s, ";"))
38  return false;
39  return true;
40 }

Referenced by Cvar_Get(), and Cvar_Set2().

◆ Cvar_Init()

void Cvar_Init ( void  )

Definition at line 522 of file cvar.c.

523 {
524  Cmd_AddCommand ("set", Cvar_Set_f);
525  Cmd_AddCommand ("cvarlist", Cvar_List_f);
526 
527 }

Referenced by Qcommon_Init().

◆ Cvar_List_f()

void Cvar_List_f ( void  )

Definition at line 453 of file cvar.c.

454 {
455  cvar_t *var;
456  int i;
457 
458  i = 0;
459  for (var = cvar_vars ; var ; var = var->next, i++)
460  {
461  if (var->flags & CVAR_ARCHIVE)
462  Com_Printf ("*");
463  else
464  Com_Printf (" ");
465  if (var->flags & CVAR_USERINFO)
466  Com_Printf ("U");
467  else
468  Com_Printf (" ");
469  if (var->flags & CVAR_SERVERINFO)
470  Com_Printf ("S");
471  else
472  Com_Printf (" ");
473  if (var->flags & CVAR_NOSET)
474  Com_Printf ("-");
475  else if (var->flags & CVAR_LATCH)
476  Com_Printf ("L");
477  else
478  Com_Printf (" ");
479  Com_Printf (" %s \"%s\"\n", var->name, var->string);
480  }
481  Com_Printf ("%i cvars\n", i);
482 }

Referenced by Cvar_Init().

◆ Cvar_Serverinfo()

char* Cvar_Serverinfo ( void  )

Definition at line 510 of file cvar.c.

511 {
512  return Cvar_BitInfo (CVAR_SERVERINFO);
513 }

Referenced by SV_Serverinfo_f(), SV_ShowServerinfo_f(), and SV_StatusString().

◆ Cvar_Set()

◆ Cvar_Set2()

cvar_t* Cvar_Set2 ( char *  var_name,
char *  value,
qboolean  force 
)

Definition at line 179 of file cvar.c.

180 {
181  cvar_t *var;
182 
183  var = Cvar_FindVar (var_name);
184  if (!var)
185  { // create it
186  return Cvar_Get (var_name, value, 0);
187  }
188 
189  if (var->flags & (CVAR_USERINFO | CVAR_SERVERINFO))
190  {
191  if (!Cvar_InfoValidate (value))
192  {
193  Com_Printf("invalid info cvar value\n");
194  return var;
195  }
196  }
197 
198  if (!force)
199  {
200  if (var->flags & CVAR_NOSET)
201  {
202  Com_Printf ("%s is write protected.\n", var_name);
203  return var;
204  }
205 
206  if (var->flags & CVAR_LATCH)
207  {
208  if (var->latched_string)
209  {
210  if (strcmp(value, var->latched_string) == 0)
211  return var;
212  Z_Free (var->latched_string);
213  }
214  else
215  {
216  if (strcmp(value, var->string) == 0)
217  return var;
218  }
219 
220  if (Com_ServerState())
221  {
222  Com_Printf ("%s will be changed for next game.\n", var_name);
224  }
225  else
226  {
227  var->string = CopyString(value);
228  var->value = atof (var->string);
229  if (!strcmp(var->name, "game"))
230  {
231  FS_SetGamedir (var->string);
232  FS_ExecAutoexec ();
233  }
234  }
235  return var;
236  }
237  }
238  else
239  {
240  if (var->latched_string)
241  {
242  Z_Free (var->latched_string);
243  var->latched_string = NULL;
244  }
245  }
246 
247  if (!strcmp(value, var->string))
248  return var; // not changed
249 
250  var->modified = true;
251 
252  if (var->flags & CVAR_USERINFO)
253  userinfo_modified = true; // transmit at next oportunity
254 
255  Z_Free (var->string); // free the old value string
256 
257  var->string = CopyString(value);
258  var->value = atof (var->string);
259 
260  return var;
261 }

Referenced by Cvar_ForceSet(), and Cvar_Set().

◆ Cvar_Set_f()

void Cvar_Set_f ( void  )

Definition at line 391 of file cvar.c.

392 {
393  int c;
394  int flags;
395 
396  c = Cmd_Argc();
397  if (c != 3 && c != 4)
398  {
399  Com_Printf ("usage: set <variable> <value> [u / s]\n");
400  return;
401  }
402 
403  if (c == 4)
404  {
405  if (!strcmp(Cmd_Argv(3), "u"))
406  flags = CVAR_USERINFO;
407  else if (!strcmp(Cmd_Argv(3), "s"))
408  flags = CVAR_SERVERINFO;
409  else
410  {
411  Com_Printf ("flags can only be 'u' or 's'\n");
412  return;
413  }
414  Cvar_FullSet (Cmd_Argv(1), Cmd_Argv(2), flags);
415  }
416  else
417  Cvar_Set (Cmd_Argv(1), Cmd_Argv(2));
418 }

Referenced by Cvar_Init().

◆ Cvar_SetValue()

◆ Cvar_Userinfo()

char* Cvar_Userinfo ( void  )

Definition at line 504 of file cvar.c.

505 {
506  return Cvar_BitInfo (CVAR_USERINFO);
507 }

Referenced by CL_SendCmd(), CL_SendConnectPacket(), and CL_Userinfo_f().

◆ Cvar_VariableString()

char* Cvar_VariableString ( char *  var_name)

Definition at line 79 of file cvar.c.

80 {
81  cvar_t *var;
82 
83  var = Cvar_FindVar (var_name);
84  if (!var)
85  return "";
86  return var->string;
87 }

Referenced by CL_PingServers_f(), Cmd_AddCommand(), Cmd_MacroExpandString(), StartServer_MenuInit(), SV_New_f(), SV_Nextserver(), and SV_ServerRecord_f().

◆ Cvar_VariableValue()

◆ Cvar_WriteVariables()

void Cvar_WriteVariables ( char *  path)

Definition at line 429 of file cvar.c.

430 {
431  cvar_t *var;
432  char buffer[1024];
433  FILE *f;
434 
435  f = fopen (path, "a");
436  for (var = cvar_vars ; var ; var = var->next)
437  {
438  if (var->flags & CVAR_ARCHIVE)
439  {
440  Com_sprintf (buffer, sizeof(buffer), "set %s \"%s\"\n", var->name, var->string);
441  fprintf (f, "%s", buffer);
442  }
443  }
444  fclose (f);
445 }

Referenced by CL_WriteConfiguration().

Variable Documentation

◆ cvar_vars

◆ userinfo_modified

qboolean userinfo_modified

Definition at line 485 of file cvar.c.

Referenced by CL_SendCmd(), CL_SendConnectPacket(), Cvar_FullSet(), and Cvar_Set2().

cvar_s::flags
int flags
Definition: q_shared.h:322
cvar_vars
cvar_t * cvar_vars
Definition: cvar.c:24
value
GLfloat value
Definition: qgl_win.c:63
CVAR_NOSET
#define CVAR_NOSET
Definition: q_shared.h:312
v
GLdouble v
Definition: qgl_win.c:143
cvar_s::modified
qboolean modified
Definition: q_shared.h:323
FS_SetGamedir
void FS_SetGamedir(char *dir)
Definition: files.c:638
cvar_s::string
char * string
Definition: q_shared.h:320
i
int i
Definition: q_shared.c:305
buffer
GLenum GLfloat * buffer
Definition: qgl_win.c:151
CopyString
char * CopyString(char *in)
Definition: common.c:1057
Cvar_Get
cvar_t * Cvar_Get(char *var_name, char *var_value, int flags)
Definition: cvar.c:127
cvar_s::next
struct cvar_s * next
Definition: q_shared.h:325
cvar_s
Definition: q_shared.h:317
MAX_INFO_STRING
#define MAX_INFO_STRING
Definition: q_shared.h:252
CVAR_SERVERINFO
#define CVAR_SERVERINFO
Definition: q_shared.h:311
Cmd_Argv
char * Cmd_Argv(int arg)
Definition: cmd.c:517
Cvar_BitInfo
char * Cvar_BitInfo(int bit)
Definition: cvar.c:488
Cmd_Argc
int Cmd_Argc(void)
Definition: cmd.c:507
userinfo_modified
qboolean userinfo_modified
Definition: cvar.c:485
cvar_s::latched_string
char * latched_string
Definition: q_shared.h:321
cvar_s::name
char * name
Definition: q_shared.h:319
Cvar_FullSet
cvar_t * Cvar_FullSet(char *var_name, char *value, int flags)
Definition: cvar.c:288
FS_ExecAutoexec
void FS_ExecAutoexec(void)
Definition: files.c:600
Cmd_AddCommand
void Cmd_AddCommand(char *cmd_name, xcommand_t function)
Definition: cmd.c:691
Cvar_Set2
cvar_t * Cvar_Set2(char *var_name, char *value, qboolean force)
Definition: cvar.c:179
CVAR_ARCHIVE
#define CVAR_ARCHIVE
Definition: q_shared.h:309
cvar_s::value
float value
Definition: q_shared.h:324
NULL
#define NULL
Definition: q_shared.h:60
CVAR_LATCH
#define CVAR_LATCH
Definition: q_shared.h:314
Z_Malloc
void * Z_Malloc(int size)
Definition: common.c:1223
Info_SetValueForKey
void Info_SetValueForKey(char *s, char *key, char *value)
Definition: q_shared.c:1375
Cvar_FindVar
static cvar_t * Cvar_FindVar(char *var_name)
Definition: cvar.c:47
Cvar_List_f
void Cvar_List_f(void)
Definition: cvar.c:453
Z_Free
void Z_Free(void *ptr)
Definition: common.c:1141
Cvar_Set_f
void Cvar_Set_f(void)
Definition: cvar.c:391
Com_ServerState
int Com_ServerState(void)
Definition: common.c:275
Cvar_InfoValidate
static qboolean Cvar_InfoValidate(char *s)
Definition: cvar.c:31
CVAR_USERINFO
#define CVAR_USERINFO
Definition: q_shared.h:310
Cvar_Set
cvar_t * Cvar_Set(char *var_name, char *value)
Definition: cvar.c:278
Com_Printf
void Com_Printf(char *fmt,...)
Definition: common.c:102
Com_sprintf
void Com_sprintf(char *dest, int size, char *fmt,...)
Definition: q_shared.c:1236