2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // cvar.c -- dynamic variable tracking
24 const char *cvar_dummy_description = "custom cvar";
26 cvar_t *cvar_vars = NULL;
27 cvar_t *cvar_hashtable[CVAR_HASHSIZE];
28 const char *cvar_null_string = "";
35 cvar_t *Cvar_FindVar (const char *var_name)
40 // use hash lookup to minimize search time
41 hashindex = CRC_Block((const unsigned char *)var_name, strlen(var_name)) % CVAR_HASHSIZE;
42 for (var = cvar_hashtable[hashindex];var;var = var->nextonhashchain)
43 if (!strcmp (var_name, var->name))
49 cvar_t *Cvar_FindVarAfter (const char *prev_var_name, int neededflags)
55 var = Cvar_FindVar (prev_var_name);
63 // search for the next cvar matching the needed flags
66 if ((var->flags & neededflags) || !neededflags)
73 static cvar_t *Cvar_FindVarLink (const char *var_name, cvar_t **parent, cvar_t ***link, cvar_t **prev_alpha)
78 // use hash lookup to minimize search time
79 hashindex = CRC_Block((const unsigned char *)var_name, strlen(var_name));
80 if(parent) *parent = NULL;
81 if(prev_alpha) *prev_alpha = NULL;
82 if(link) *link = &cvar_hashtable[hashindex];
83 for (var = cvar_hashtable[hashindex];var;var = var->nextonhashchain)
85 if (!strcmp (var_name, var->name))
87 if(!prev_alpha || var == cvar_vars)
90 *prev_alpha = cvar_vars;
91 // if prev_alpha happens to become NULL then there has been some inconsistency elsewhere
92 // already - should I still insert '*prev_alpha &&' in the loop?
93 while((*prev_alpha)->next != var)
94 *prev_alpha = (*prev_alpha)->next;
97 if(parent) *parent = var;
108 float Cvar_VariableValueOr (const char *var_name, float def)
112 var = Cvar_FindVar (var_name);
115 return atof (var->string);
118 float Cvar_VariableValue (const char *var_name)
120 return Cvar_VariableValueOr(var_name, 0);
128 const char *Cvar_VariableStringOr (const char *var_name, const char *def)
132 var = Cvar_FindVar (var_name);
138 const char *Cvar_VariableString (const char *var_name)
140 return Cvar_VariableStringOr(var_name, cvar_null_string);
145 Cvar_VariableDefString
148 const char *Cvar_VariableDefString (const char *var_name)
152 var = Cvar_FindVar (var_name);
154 return cvar_null_string;
155 return var->defstring;
160 Cvar_VariableDescription
163 const char *Cvar_VariableDescription (const char *var_name)
167 var = Cvar_FindVar (var_name);
169 return cvar_null_string;
170 return var->description;
176 Cvar_CompleteVariable
179 const char *Cvar_CompleteVariable (const char *partial)
184 len = strlen(partial);
190 for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
191 if (!strncasecmp (partial,cvar->name, len))
199 CVar_CompleteCountPossible
201 New function for tab-completion system
203 Thanks to Fett erich@heintz.com
206 int Cvar_CompleteCountPossible (const char *partial)
213 len = strlen(partial);
218 // Loop through the cvars and count all possible matches
219 for (cvar = cvar_vars; cvar; cvar = cvar->next)
220 if (!strncasecmp(partial, cvar->name, len))
227 CVar_CompleteBuildList
229 New function for tab-completion system
231 Thanks to Fett erich@heintz.com
235 const char **Cvar_CompleteBuildList (const char *partial)
240 size_t sizeofbuf = (Cvar_CompleteCountPossible (partial) + 1) * sizeof (const char *);
243 len = strlen(partial);
244 buf = (const char **)Mem_Alloc(tempmempool, sizeofbuf + sizeof (const char *));
245 // Loop through the alias list and print all matches
246 for (cvar = cvar_vars; cvar; cvar = cvar->next)
247 if (!strncasecmp(partial, cvar->name, len))
248 buf[bpos++] = cvar->name;
254 // written by LordHavoc
255 void Cvar_CompleteCvarPrint (const char *partial)
258 size_t len = strlen(partial);
259 // Loop through the command list and print all matches
260 for (cvar = cvar_vars; cvar; cvar = cvar->next)
261 if (!strncasecmp(partial, cvar->name, len))
262 Con_Printf ("^3%s^7 is \"%s\" [\"%s\"] %s\n", cvar->name, cvar->string, cvar->defstring, cvar->description);
265 // check if a cvar is held by some progs
266 static qboolean Cvar_IsAutoCvar(cvar_t *var)
270 for (i = 0;i < PRVM_PROG_MAX;i++)
272 prog = &prvm_prog_list[i];
273 if (prog->loaded && var->globaldefindex[i] >= 0)
279 // we assume that prog is already set to the target progs
280 static void Cvar_UpdateAutoCvar(cvar_t *var)
287 for (i = 0;i < PRVM_PROG_MAX;i++)
289 prog = &prvm_prog_list[i];
290 if (prog->loaded && var->globaldefindex[i] >= 0)
292 // MUST BE SYNCED WITH prvm_edict.c PRVM_LoadProgs
293 switch(prog->globaldefs[var->globaldefindex[i]].type & ~DEF_SAVEGLOBAL)
296 PRVM_GLOBALFIELDFLOAT(prog->globaldefs[var->globaldefindex[i]].ofs) = var->value;
301 for (j = 0;j < 3;j++)
303 while (*s && ISWHITESPACE(*s))
308 while (!ISWHITESPACE(*s))
313 VectorCopy(v, PRVM_GLOBALFIELDVECTOR(prog->globaldefs[var->globaldefindex[i]].ofs));
316 PRVM_ChangeEngineString(prog, var->globaldefindex_stringno[i], var->string);
317 PRVM_GLOBALFIELDSTRING(prog->globaldefs[var->globaldefindex[i]].ofs) = var->globaldefindex_stringno[i];
324 // called after loading a savegame
325 void Cvar_UpdateAllAutoCvars(void)
328 for (var = cvar_vars ; var ; var = var->next)
329 Cvar_UpdateAutoCvar(var);
337 extern cvar_t sv_disablenotify;
338 static void Cvar_SetQuick_Internal (cvar_t *var, const char *value)
344 changed = strcmp(var->string, value) != 0;
345 // LordHavoc: don't reallocate when there is no change
349 // LordHavoc: don't reallocate when the buffer is the same size
350 valuelen = strlen(value);
351 if (!var->string || strlen(var->string) != valuelen)
353 Z_Free ((char *)var->string); // free the old value string
355 var->string = (char *)Z_Malloc (valuelen + 1);
357 memcpy ((char *)var->string, value, valuelen + 1);
358 var->value = atof (var->string);
359 var->integer = (int) var->value;
360 if ((var->flags & CVAR_NOTIFY) && changed && sv.active && !sv_disablenotify.integer)
361 SV_BroadcastPrintf("\"%s\" changed to \"%s\"\n", var->name, var->string);
363 // TODO: add infostring support to the server?
364 if ((var->flags & CVAR_SERVERINFO) && changed && sv.active)
366 InfoString_SetValue(svs.serverinfo, sizeof(svs.serverinfo), var->name, var->string);
369 MSG_WriteByte (&sv.reliable_datagram, svc_serverinfostring);
370 MSG_WriteString (&sv.reliable_datagram, var->name);
371 MSG_WriteString (&sv.reliable_datagram, var->string);
375 if ((var->flags & CVAR_USERINFO) && cls.state != ca_dedicated)
376 CL_SetInfo(var->name, var->string, true, false, false, false);
377 else if ((var->flags & CVAR_NQUSERINFOHACK) && cls.state != ca_dedicated)
379 // update the cls.userinfo to have proper values for the
380 // silly nq config variables.
382 // this is done when these variables are changed rather than at
383 // connect time because if the user or code checks the userinfo and it
384 // holds weird values it may cause confusion...
385 if (!strcmp(var->name, "_cl_color"))
387 int top = (var->integer >> 4) & 15, bottom = var->integer & 15;
388 CL_SetInfo("topcolor", va(vabuf, sizeof(vabuf), "%i", top), true, false, false, false);
389 CL_SetInfo("bottomcolor", va(vabuf, sizeof(vabuf), "%i", bottom), true, false, false, false);
390 if (cls.protocol != PROTOCOL_QUAKEWORLD && cls.netcon)
392 MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
393 MSG_WriteString(&cls.netcon->message, va(vabuf, sizeof(vabuf), "color %i %i", top, bottom));
396 else if (!strcmp(var->name, "_cl_rate"))
397 CL_SetInfo("rate", va(vabuf, sizeof(vabuf), "%i", var->integer), true, false, false, false);
398 else if (!strcmp(var->name, "_cl_rate_burstsize"))
399 CL_SetInfo("rate_burstsize", va(vabuf, sizeof(vabuf), "%i", var->integer), true, false, false, false);
400 else if (!strcmp(var->name, "_cl_playerskin"))
401 CL_SetInfo("playerskin", var->string, true, false, false, false);
402 else if (!strcmp(var->name, "_cl_playermodel"))
403 CL_SetInfo("playermodel", var->string, true, false, false, false);
404 else if (!strcmp(var->name, "_cl_name"))
405 CL_SetInfo("name", var->string, true, false, false, false);
406 else if (!strcmp(var->name, "rcon_secure"))
408 // whenever rcon_secure is changed to 0, clear rcon_password for
409 // security reasons (prevents a send-rcon-password-as-plaintext
410 // attack based on NQ protocol session takeover and svc_stufftext)
411 if(var->integer <= 0)
412 Cvar_Set("rcon_password", "");
415 else if (!strcmp(var->name, "net_slist_favorites"))
416 NetConn_UpdateFavorites();
420 Cvar_UpdateAutoCvar(var);
423 void Cvar_SetQuick (cvar_t *var, const char *value)
427 Con_Print("Cvar_SetQuick: var == NULL\n");
431 if (developer_extra.integer)
432 Con_DPrintf("Cvar_SetQuick({\"%s\", \"%s\", %i, \"%s\"}, \"%s\");\n", var->name, var->string, var->flags, var->defstring, value);
434 Cvar_SetQuick_Internal(var, value);
437 void Cvar_Set (const char *var_name, const char *value)
440 var = Cvar_FindVar (var_name);
443 Con_Printf("Cvar_Set: variable %s not found\n", var_name);
446 Cvar_SetQuick(var, value);
454 void Cvar_SetValueQuick(cvar_t *var, float value)
456 char val[MAX_INPUTLINE];
458 if ((float)((int)value) == value)
459 dpsnprintf(val, sizeof(val), "%i", (int)value);
461 dpsnprintf(val, sizeof(val), "%f", value);
462 Cvar_SetQuick(var, val);
465 void Cvar_SetValue(const char *var_name, float value)
467 char val[MAX_INPUTLINE];
469 if ((float)((int)value) == value)
470 dpsnprintf(val, sizeof(val), "%i", (int)value);
472 dpsnprintf(val, sizeof(val), "%f", value);
473 Cvar_Set(var_name, val);
478 Cvar_RegisterVariable
480 Adds a freestanding variable to the variable list.
483 void Cvar_RegisterVariable (cvar_t *variable)
486 cvar_t *current, *next, *cvar;
490 if (developer_extra.integer)
491 Con_DPrintf("Cvar_RegisterVariable({\"%s\", \"%s\", %i});\n", variable->name, variable->string, variable->flags);
493 // first check to see if it has already been defined
494 cvar = Cvar_FindVar (variable->name);
497 if (cvar->flags & CVAR_ALLOCATED)
499 if (developer_extra.integer)
500 Con_DPrintf("... replacing existing allocated cvar {\"%s\", \"%s\", %i}\n", cvar->name, cvar->string, cvar->flags);
501 // fixed variables replace allocated ones
502 // (because the engine directly accesses fixed variables)
503 // NOTE: this isn't actually used currently
504 // (all cvars are registered before config parsing)
505 variable->flags |= (cvar->flags & ~CVAR_ALLOCATED);
506 // cvar->string is now owned by variable instead
507 variable->string = cvar->string;
508 variable->defstring = cvar->defstring;
509 variable->value = atof (variable->string);
510 variable->integer = (int) variable->value;
511 // replace cvar with this one...
512 variable->next = cvar->next;
513 if (cvar_vars == cvar)
515 // head of the list is easy to change
516 cvar_vars = variable;
520 // otherwise find it somewhere in the list
521 for (current = cvar_vars;current->next != cvar;current = current->next)
523 current->next = variable;
526 // get rid of old allocated cvar
527 // (but not cvar->string and cvar->defstring, because we kept those)
528 Z_Free((char *)cvar->name);
532 Con_DPrintf("Can't register variable %s, already defined\n", variable->name);
536 // check for overlap with a command
537 if (Cmd_Exists (variable->name))
539 Con_Printf("Cvar_RegisterVariable: %s is a command\n", variable->name);
543 // copy the value off, because future sets will Z_Free it
544 oldstr = (char *)variable->string;
545 alloclen = strlen(variable->string) + 1;
546 variable->string = (char *)Z_Malloc (alloclen);
547 memcpy ((char *)variable->string, oldstr, alloclen);
548 variable->defstring = (char *)Z_Malloc (alloclen);
549 memcpy ((char *)variable->defstring, oldstr, alloclen);
550 variable->value = atof (variable->string);
551 variable->integer = (int) variable->value;
553 // link the variable in
554 // alphanumerical order
555 for( current = NULL, next = cvar_vars ; next && strcmp( next->name, variable->name ) < 0 ; current = next, next = next->next )
558 current->next = variable;
560 cvar_vars = variable;
562 variable->next = next;
564 // link to head of list in this hash table index
565 hashindex = CRC_Block((const unsigned char *)variable->name, strlen(variable->name)) % CVAR_HASHSIZE;
566 variable->nextonhashchain = cvar_hashtable[hashindex];
567 cvar_hashtable[hashindex] = variable;
574 Adds a newly allocated variable to the variable list or sets its value.
577 cvar_t *Cvar_Get (const char *name, const char *value, int flags, const char *newdescription)
580 cvar_t *current, *next, *cvar;
582 if (developer_extra.integer)
583 Con_DPrintf("Cvar_Get(\"%s\", \"%s\", %i);\n", name, value, flags);
585 // first check to see if it has already been defined
586 cvar = Cvar_FindVar (name);
589 cvar->flags |= flags;
590 Cvar_SetQuick_Internal (cvar, value);
591 if(newdescription && (cvar->flags & CVAR_ALLOCATED))
593 if(cvar->description != cvar_dummy_description)
594 Z_Free((char *)cvar->description);
597 cvar->description = (char *)Mem_strdup(zonemempool, newdescription);
599 cvar->description = cvar_dummy_description;
604 // check for pure evil
607 Con_Printf("Cvar_Get: invalid variable name\n");
611 // check for overlap with a command
612 if (Cmd_Exists (name))
614 Con_Printf("Cvar_Get: %s is a command\n", name);
618 // allocate a new cvar, cvar name, and cvar string
619 // TODO: factorize the following code with the one at the end of Cvar_RegisterVariable()
620 // FIXME: these never get Z_Free'd
621 cvar = (cvar_t *)Z_Malloc(sizeof(cvar_t));
622 cvar->flags = flags | CVAR_ALLOCATED;
623 cvar->name = (char *)Mem_strdup(zonemempool, name);
624 cvar->string = (char *)Mem_strdup(zonemempool, value);
625 cvar->defstring = (char *)Mem_strdup(zonemempool, value);
626 cvar->value = atof (cvar->string);
627 cvar->integer = (int) cvar->value;
629 if(newdescription && *newdescription)
630 cvar->description = (char *)Mem_strdup(zonemempool, newdescription);
632 cvar->description = cvar_dummy_description; // actually checked by VM_cvar_type
634 // link the variable in
635 // alphanumerical order
636 for( current = NULL, next = cvar_vars ; next && strcmp( next->name, cvar->name ) < 0 ; current = next, next = next->next )
639 current->next = cvar;
644 // link to head of list in this hash table index
645 hashindex = CRC_Block((const unsigned char *)cvar->name, strlen(cvar->name)) % CVAR_HASHSIZE;
646 cvar->nextonhashchain = cvar_hashtable[hashindex];
647 cvar_hashtable[hashindex] = cvar;
657 Handles variable inspection and changing from the console
660 qboolean Cvar_Command (void)
665 v = Cvar_FindVar (Cmd_Argv(0));
669 // perform a variable print or set
672 Con_Printf("\"%s\" is \"%s\" [\"%s\"]\n", v->name, ((v->flags & CVAR_PRIVATE) ? "********"/*hunter2*/ : v->string), v->defstring);
676 if (developer_extra.integer)
677 Con_DPrint("Cvar_Command: ");
679 if (v->flags & CVAR_READONLY)
681 Con_Printf("%s is read-only\n", v->name);
684 Cvar_Set (v->name, Cmd_Argv(1));
685 if (developer_extra.integer)
691 void Cvar_UnlockDefaults (void)
694 // unlock the default values of all cvars
695 for (var = cvar_vars ; var ; var = var->next)
696 var->flags &= ~CVAR_DEFAULTSET;
700 void Cvar_LockDefaults_f (void)
703 // lock in the default values of all cvars
704 for (var = cvar_vars ; var ; var = var->next)
706 if (!(var->flags & CVAR_DEFAULTSET))
710 //Con_Printf("locking cvar %s (%s -> %s)\n", var->name, var->string, var->defstring);
711 var->flags |= CVAR_DEFAULTSET;
712 Z_Free((char *)var->defstring);
713 alloclen = strlen(var->string) + 1;
714 var->defstring = (char *)Z_Malloc(alloclen);
715 memcpy((char *)var->defstring, var->string, alloclen);
720 void Cvar_SaveInitState(void)
723 for (c = cvar_vars;c;c = c->next)
726 c->initflags = c->flags;
727 c->initdefstring = Mem_strdup(zonemempool, c->defstring);
728 c->initstring = Mem_strdup(zonemempool, c->string);
729 c->initvalue = c->value;
730 c->initinteger = c->integer;
731 VectorCopy(c->vector, c->initvector);
735 void Cvar_RestoreInitState(void)
740 for (cp = &cvar_vars;(c = *cp);)
744 // restore this cvar, it existed at init
745 if (((c->flags ^ c->initflags) & CVAR_MAXFLAGSVAL)
746 || strcmp(c->defstring ? c->defstring : "", c->initdefstring ? c->initdefstring : "")
747 || strcmp(c->string ? c->string : "", c->initstring ? c->initstring : ""))
749 Con_DPrintf("Cvar_RestoreInitState: Restoring cvar \"%s\"\n", c->name);
751 Z_Free((char *)c->defstring);
752 c->defstring = Mem_strdup(zonemempool, c->initdefstring);
754 Z_Free((char *)c->string);
755 c->string = Mem_strdup(zonemempool, c->initstring);
757 c->flags = c->initflags;
758 c->value = c->initvalue;
759 c->integer = c->initinteger;
760 VectorCopy(c->initvector, c->vector);
765 if (!(c->flags & CVAR_ALLOCATED))
767 Con_DPrintf("Cvar_RestoreInitState: Unable to destroy cvar \"%s\", it was registered after init!\n", c->name);
768 // In this case, at least reset it to the default.
769 if((c->flags & CVAR_NORESETTODEFAULTS) == 0)
770 Cvar_SetQuick(c, c->defstring);
774 if (Cvar_IsAutoCvar(c))
776 Con_DPrintf("Cvar_RestoreInitState: Unable to destroy cvar \"%s\", it is an autocvar used by running progs!\n", c->name);
777 // In this case, at least reset it to the default.
778 if((c->flags & CVAR_NORESETTODEFAULTS) == 0)
779 Cvar_SetQuick(c, c->defstring);
783 // remove this cvar, it did not exist at init
784 Con_DPrintf("Cvar_RestoreInitState: Destroying cvar \"%s\"\n", c->name);
785 // unlink struct from hash
786 hashindex = CRC_Block((const unsigned char *)c->name, strlen(c->name)) % CVAR_HASHSIZE;
787 for (cp2 = &cvar_hashtable[hashindex];(c2 = *cp2);)
791 *cp2 = c2->nextonhashchain;
795 cp2 = &c2->nextonhashchain;
797 // unlink struct from main list
801 Z_Free((char *)c->defstring);
803 Z_Free((char *)c->string);
804 if (c->description && c->description != cvar_dummy_description)
805 Z_Free((char *)c->description);
812 void Cvar_ResetToDefaults_All_f (void)
815 // restore the default values of all cvars
816 for (var = cvar_vars ; var ; var = var->next)
817 if((var->flags & CVAR_NORESETTODEFAULTS) == 0)
818 Cvar_SetQuick(var, var->defstring);
822 void Cvar_ResetToDefaults_NoSaveOnly_f (void)
825 // restore the default values of all cvars
826 for (var = cvar_vars ; var ; var = var->next)
827 if ((var->flags & (CVAR_NORESETTODEFAULTS | CVAR_SAVE)) == 0)
828 Cvar_SetQuick(var, var->defstring);
832 void Cvar_ResetToDefaults_SaveOnly_f (void)
835 // restore the default values of all cvars
836 for (var = cvar_vars ; var ; var = var->next)
837 if ((var->flags & (CVAR_NORESETTODEFAULTS | CVAR_SAVE)) == CVAR_SAVE)
838 Cvar_SetQuick(var, var->defstring);
846 Writes lines containing "set variable value" for all variables
847 with the archive flag set to true.
850 void Cvar_WriteVariables (qfile_t *f)
853 char buf1[MAX_INPUTLINE], buf2[MAX_INPUTLINE];
855 // don't save cvars that match their default value
856 for (var = cvar_vars ; var ; var = var->next)
857 if ((var->flags & CVAR_SAVE) && (strcmp(var->string, var->defstring) || ((var->flags & CVAR_ALLOCATED) && !(var->flags & CVAR_DEFAULTSET))))
859 Cmd_QuoteString(buf1, sizeof(buf1), var->name, "\"\\$", false);
860 Cmd_QuoteString(buf2, sizeof(buf2), var->string, "\"\\$", false);
861 FS_Printf(f, "%s\"%s\" \"%s\"\n", var->flags & CVAR_ALLOCATED ? "seta " : "", buf1, buf2);
866 // Added by EvilTypeGuy eviltypeguy@qeradiant.com
867 // 2000-01-09 CvarList command By Matthias "Maddes" Buecher, http://www.inside3d.com/qip/
873 void Cvar_List_f (void)
883 partial = Cmd_Argv (1);
884 len = strlen(partial);
885 ispattern = (strchr(partial, '*') || strchr(partial, '?'));
895 for (cvar = cvar_vars; cvar; cvar = cvar->next)
897 if (len && (ispattern ? !matchpattern_with_separator(cvar->name, partial, false, "", false) : strncmp (partial,cvar->name,len)))
900 Con_Printf("%s is \"%s\" [\"%s\"] %s\n", cvar->name, ((cvar->flags & CVAR_PRIVATE) ? "********"/*hunter2*/ : cvar->string), cvar->defstring, cvar->description);
907 Con_Printf("%i cvar%s matching \"%s\"\n", count, (count > 1) ? "s" : "", partial);
909 Con_Printf("%i cvar%s beginning with \"%s\"\n", count, (count > 1) ? "s" : "", partial);
912 Con_Printf("%i cvar(s)\n", count);
914 // 2000-01-09 CvarList command by Maddes
916 void Cvar_Set_f (void)
920 // make sure it's the right number of parameters
923 Con_Printf("Set: wrong number of parameters, usage: set <variablename> <value> [<description>]\n");
927 // check if it's read-only
928 cvar = Cvar_FindVar(Cmd_Argv(1));
929 if (cvar && cvar->flags & CVAR_READONLY)
931 Con_Printf("Set: %s is read-only\n", cvar->name);
935 if (developer_extra.integer)
938 // all looks ok, create/modify the cvar
939 Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), 0, Cmd_Argc() > 3 ? Cmd_Argv(3) : NULL);
942 void Cvar_SetA_f (void)
946 // make sure it's the right number of parameters
949 Con_Printf("SetA: wrong number of parameters, usage: seta <variablename> <value> [<description>]\n");
953 // check if it's read-only
954 cvar = Cvar_FindVar(Cmd_Argv(1));
955 if (cvar && cvar->flags & CVAR_READONLY)
957 Con_Printf("SetA: %s is read-only\n", cvar->name);
961 if (developer_extra.integer)
962 Con_DPrint("SetA: ");
964 // all looks ok, create/modify the cvar
965 Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), CVAR_SAVE, Cmd_Argc() > 3 ? Cmd_Argv(3) : NULL);
968 void Cvar_Del_f (void)
971 cvar_t *cvar, *parent, **link, *prev;
975 Con_Printf("Del: wrong number of parameters, useage: unset <variablename1> [<variablename2> ...]\n");
978 for(i = 1; i < Cmd_Argc(); ++i)
980 cvar = Cvar_FindVarLink(Cmd_Argv(i), &parent, &link, &prev);
983 Con_Printf("Del: %s is not defined\n", Cmd_Argv(i));
986 if(cvar->flags & CVAR_READONLY)
988 Con_Printf("Del: %s is read-only\n", cvar->name);
991 if(!(cvar->flags & CVAR_ALLOCATED))
993 Con_Printf("Del: %s is static and cannot be deleted\n", cvar->name);
996 if(cvar == cvar_vars)
998 cvar_vars = cvar->next;
1002 // in this case, prev must be set, otherwise there has been some inconsistensy
1003 // elsewhere already... should I still check for prev != NULL?
1004 prev->next = cvar->next;
1008 parent->nextonhashchain = cvar->nextonhashchain;
1010 *link = cvar->nextonhashchain;
1012 if(cvar->description != cvar_dummy_description)
1013 Z_Free((char *)cvar->description);
1015 Z_Free((char *)cvar->name);
1016 Z_Free((char *)cvar->string);
1017 Z_Free((char *)cvar->defstring);
1022 #ifdef FILLALLCVARSWITHRUBBISH
1023 void Cvar_FillAll_f()
1031 Con_Printf("Usage: %s length to plant rubbish\n", Cmd_Argv(0));
1032 Con_Printf("Usage: %s -length to verify that the rubbish is still there\n", Cmd_Argv(0));
1035 n = atoi(Cmd_Argv(1));
1039 buf = Z_Malloc(n + 1);
1041 for(var = cvar_vars; var; var = var->next)
1043 for(i = 0, p = buf, q = var->name; i < n; ++i)
1049 if(verify && strcmp(var->string, buf))
1051 Con_Printf("\n%s does not contain the right rubbish, either this is the first run or a possible overrun was detected, or something changed it intentionally; it DOES contain: %s\n", var->name, var->string);
1053 Cvar_SetQuick(var, buf);
1057 #endif /* FILLALLCVARSWITHRUBBISH */