]> icculus.org git repositories - divverent/darkplaces.git/blob - cvar.c
Merge branch 'master' into cmd_unset
[divverent/darkplaces.git] / cvar.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
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.
8
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.
12
13 See the GNU General Public License for more details.
14
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.
18
19 */
20 // cvar.c -- dynamic variable tracking
21
22 #include "quakedef.h"
23
24 char *cvar_dummy_description = "custom cvar";
25
26 cvar_t *cvar_vars = NULL;
27 cvar_t *cvar_hashtable[65536];
28 char *cvar_null_string = "";
29
30 /*
31 ============
32 Cvar_FindVar
33 ============
34 */
35 cvar_t *Cvar_FindVar (const char *var_name)
36 {
37         int hashindex;
38         cvar_t *var;
39
40         // use hash lookup to minimize search time
41         hashindex = CRC_Block((const unsigned char *)var_name, strlen(var_name));
42         for (var = cvar_hashtable[hashindex];var;var = var->nextonhashchain)
43                 if (!strcmp (var_name, var->name))
44                         return var;
45
46         return NULL;
47 }
48
49 cvar_t *Cvar_FindVarAfter (const char *prev_var_name, int neededflags)
50 {
51         cvar_t *var;
52
53         if (*prev_var_name)
54         {
55                 var = Cvar_FindVar (prev_var_name);
56                 if (!var)
57                         return NULL;
58                 var = var->next;
59         }
60         else
61                 var = cvar_vars;
62
63         // search for the next cvar matching the needed flags
64         while (var)
65         {
66                 if ((var->flags & neededflags) || !neededflags)
67                         break;
68                 var = var->next;
69         }
70         return var;
71 }
72
73 cvar_t *Cvar_FindVarLink (const char *var_name, cvar_t **parent, cvar_t ***link, cvar_t **prev_alpha)
74 {
75         int hashindex;
76         cvar_t *var;
77
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)
84         {
85                 if (!strcmp (var_name, var->name))
86                 {
87                         if(!prev_alpha || var == cvar_vars)
88                                 return var;
89
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;
95                         return var;
96                 }
97                 if(parent) *parent = var;
98         }
99
100         return NULL;
101 }
102
103 /*
104 ============
105 Cvar_VariableValue
106 ============
107 */
108 float Cvar_VariableValue (const char *var_name)
109 {
110         cvar_t *var;
111
112         var = Cvar_FindVar (var_name);
113         if (!var)
114                 return 0;
115         return atof (var->string);
116 }
117
118
119 /*
120 ============
121 Cvar_VariableString
122 ============
123 */
124 const char *Cvar_VariableString (const char *var_name)
125 {
126         cvar_t *var;
127
128         var = Cvar_FindVar (var_name);
129         if (!var)
130                 return cvar_null_string;
131         return var->string;
132 }
133
134 /*
135 ============
136 Cvar_VariableDefString
137 ============
138 */
139 const char *Cvar_VariableDefString (const char *var_name)
140 {
141         cvar_t *var;
142
143         var = Cvar_FindVar (var_name);
144         if (!var)
145                 return cvar_null_string;
146         return var->defstring;
147 }
148
149 /*
150 ============
151 Cvar_VariableDescription
152 ============
153 */
154 const char *Cvar_VariableDescription (const char *var_name)
155 {
156         cvar_t *var;
157
158         var = Cvar_FindVar (var_name);
159         if (!var)
160                 return cvar_null_string;
161         return var->description;
162 }
163
164
165 /*
166 ============
167 Cvar_CompleteVariable
168 ============
169 */
170 const char *Cvar_CompleteVariable (const char *partial)
171 {
172         cvar_t          *cvar;
173         size_t          len;
174
175         len = strlen(partial);
176
177         if (!len)
178                 return NULL;
179
180 // check functions
181         for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
182                 if (!strncasecmp (partial,cvar->name, len))
183                         return cvar->name;
184
185         return NULL;
186 }
187
188
189 /*
190         CVar_CompleteCountPossible
191
192         New function for tab-completion system
193         Added by EvilTypeGuy
194         Thanks to Fett erich@heintz.com
195
196 */
197 int Cvar_CompleteCountPossible (const char *partial)
198 {
199         cvar_t  *cvar;
200         size_t  len;
201         int             h;
202
203         h = 0;
204         len = strlen(partial);
205
206         if (!len)
207                 return  0;
208
209         // Loop through the cvars and count all possible matches
210         for (cvar = cvar_vars; cvar; cvar = cvar->next)
211                 if (!strncasecmp(partial, cvar->name, len))
212                         h++;
213
214         return h;
215 }
216
217 /*
218         CVar_CompleteBuildList
219
220         New function for tab-completion system
221         Added by EvilTypeGuy
222         Thanks to Fett erich@heintz.com
223         Thanks to taniwha
224
225 */
226 const char **Cvar_CompleteBuildList (const char *partial)
227 {
228         const cvar_t *cvar;
229         size_t len = 0;
230         size_t bpos = 0;
231         size_t sizeofbuf = (Cvar_CompleteCountPossible (partial) + 1) * sizeof (const char *);
232         const char **buf;
233
234         len = strlen(partial);
235         buf = (const char **)Mem_Alloc(tempmempool, sizeofbuf + sizeof (const char *));
236         // Loop through the alias list and print all matches
237         for (cvar = cvar_vars; cvar; cvar = cvar->next)
238                 if (!strncasecmp(partial, cvar->name, len))
239                         buf[bpos++] = cvar->name;
240
241         buf[bpos] = NULL;
242         return buf;
243 }
244
245 // written by LordHavoc
246 void Cvar_CompleteCvarPrint (const char *partial)
247 {
248         cvar_t *cvar;
249         size_t len = strlen(partial);
250         // Loop through the command list and print all matches
251         for (cvar = cvar_vars; cvar; cvar = cvar->next)
252                 if (!strncasecmp(partial, cvar->name, len))
253                         Con_Printf ("^3%s^7 is \"%s\" [\"%s\"] %s\n", cvar->name, cvar->string, cvar->defstring, cvar->description);
254 }
255
256
257 /*
258 ============
259 Cvar_Set
260 ============
261 */
262 void Cvar_SetQuick_Internal (cvar_t *var, const char *value)
263 {
264         qboolean changed;
265         size_t valuelen;
266
267         changed = strcmp(var->string, value);
268         // LordHavoc: don't reallocate when there is no change
269         if (!changed)
270                 return;
271
272         // LordHavoc: don't reallocate when the buffer is the same size
273         valuelen = strlen(value);
274         if (!var->string || strlen(var->string) != valuelen)
275         {
276                 Z_Free (var->string);   // free the old value string
277
278                 var->string = (char *)Z_Malloc (valuelen + 1);
279         }
280         memcpy (var->string, value, valuelen + 1);
281         var->value = atof (var->string);
282         var->integer = (int) var->value;
283         if ((var->flags & CVAR_NOTIFY) && changed && sv.active)
284                 SV_BroadcastPrintf("\"%s\" changed to \"%s\"\n", var->name, var->string);
285 #if 0
286         // TODO: add infostring support to the server?
287         if ((var->flags & CVAR_SERVERINFO) && changed && sv.active)
288         {
289                 InfoString_SetValue(svs.serverinfo, sizeof(svs.serverinfo), var->name, var->string);
290                 if (sv.active)
291                 {
292                         MSG_WriteByte (&sv.reliable_datagram, svc_serverinfostring);
293                         MSG_WriteString (&sv.reliable_datagram, var->name);
294                         MSG_WriteString (&sv.reliable_datagram, var->string);
295                 }
296         }
297 #endif
298         if ((var->flags & CVAR_USERINFO) && cls.state != ca_dedicated)
299                 CL_SetInfo(var->name, var->string, true, false, false, false);
300         else if ((var->flags & CVAR_NQUSERINFOHACK) && cls.state != ca_dedicated)
301         {
302                 // update the cls.userinfo to have proper values for the
303                 // silly nq config variables.
304                 //
305                 // this is done when these variables are changed rather than at
306                 // connect time because if the user or code checks the userinfo and it
307                 // holds weird values it may cause confusion...
308                 if (!strcmp(var->name, "_cl_color"))
309                 {
310                         int top = (var->integer >> 4) & 15, bottom = var->integer & 15;
311                         CL_SetInfo("topcolor", va("%i", top), true, false, false, false);
312                         CL_SetInfo("bottomcolor", va("%i", bottom), true, false, false, false);
313                         if (cls.protocol != PROTOCOL_QUAKEWORLD && cls.netcon)
314                         {
315                                 MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
316                                 MSG_WriteString(&cls.netcon->message, va("color %i %i", top, bottom));
317                         }
318                 }
319                 else if (!strcmp(var->name, "_cl_rate"))
320                         CL_SetInfo("rate", va("%i", var->integer), true, false, false, false);
321                 else if (!strcmp(var->name, "_cl_playerskin"))
322                         CL_SetInfo("playerskin", var->string, true, false, false, false);
323                 else if (!strcmp(var->name, "_cl_playermodel"))
324                         CL_SetInfo("playermodel", var->string, true, false, false, false);
325                 else if (!strcmp(var->name, "_cl_name"))
326                         CL_SetInfo("name", var->string, true, false, false, false);
327                 else if (!strcmp(var->name, "rcon_secure"))
328                 {
329                         // whenever rcon_secure is changed to 0, clear rcon_password for
330                         // security reasons (prevents a send-rcon-password-as-plaintext
331                         // attack based on NQ protocol session takeover and svc_stufftext)
332                         if(!var->integer)
333                                 Cvar_Set("rcon_password", "");
334                 }
335                 else if (!strcmp(var->name, "net_slist_favorites"))
336                         NetConn_UpdateFavorites();
337         }
338 }
339
340 void Cvar_SetQuick (cvar_t *var, const char *value)
341 {
342         if (var == NULL)
343         {
344                 Con_Print("Cvar_SetQuick: var == NULL\n");
345                 return;
346         }
347
348         if (developer.integer >= 100)
349                 Con_Printf("Cvar_SetQuick({\"%s\", \"%s\", %i, \"%s\"}, \"%s\");\n", var->name, var->string, var->flags, var->defstring, value);
350
351         Cvar_SetQuick_Internal(var, value);
352 }
353
354 void Cvar_Set (const char *var_name, const char *value)
355 {
356         cvar_t *var;
357         var = Cvar_FindVar (var_name);
358         if (var == NULL)
359         {
360                 Con_Printf("Cvar_Set: variable %s not found\n", var_name);
361                 return;
362         }
363         Cvar_SetQuick(var, value);
364 }
365
366 /*
367 ============
368 Cvar_SetValue
369 ============
370 */
371 void Cvar_SetValueQuick(cvar_t *var, float value)
372 {
373         char val[MAX_INPUTLINE];
374
375         if ((float)((int)value) == value)
376                 dpsnprintf(val, sizeof(val), "%i", (int)value);
377         else
378                 dpsnprintf(val, sizeof(val), "%f", value);
379         Cvar_SetQuick(var, val);
380 }
381
382 void Cvar_SetValue(const char *var_name, float value)
383 {
384         char val[MAX_INPUTLINE];
385
386         if ((float)((int)value) == value)
387                 dpsnprintf(val, sizeof(val), "%i", (int)value);
388         else
389                 dpsnprintf(val, sizeof(val), "%f", value);
390         Cvar_Set(var_name, val);
391 }
392
393 /*
394 ============
395 Cvar_RegisterVariable
396
397 Adds a freestanding variable to the variable list.
398 ============
399 */
400 void Cvar_RegisterVariable (cvar_t *variable)
401 {
402         int hashindex;
403         cvar_t *current, *next, *cvar;
404         char *oldstr;
405         size_t alloclen;
406
407         if (developer.integer >= 100)
408                 Con_Printf("Cvar_RegisterVariable({\"%s\", \"%s\", %i});\n", variable->name, variable->string, variable->flags);
409
410 // first check to see if it has already been defined
411         cvar = Cvar_FindVar (variable->name);
412         if (cvar)
413         {
414                 if (cvar->flags & CVAR_ALLOCATED)
415                 {
416                         if (developer.integer >= 100)
417                                 Con_Printf("...  replacing existing allocated cvar {\"%s\", \"%s\", %i}\n", cvar->name, cvar->string, cvar->flags);
418                         // fixed variables replace allocated ones
419                         // (because the engine directly accesses fixed variables)
420                         // NOTE: this isn't actually used currently
421                         // (all cvars are registered before config parsing)
422                         variable->flags |= (cvar->flags & ~CVAR_ALLOCATED);
423                         // cvar->string is now owned by variable instead
424                         variable->string = cvar->string;
425                         variable->defstring = cvar->defstring;
426                         variable->value = atof (variable->string);
427                         variable->integer = (int) variable->value;
428                         // replace cvar with this one...
429                         variable->next = cvar->next;
430                         if (cvar_vars == cvar)
431                         {
432                                 // head of the list is easy to change
433                                 cvar_vars = variable;
434                         }
435                         else
436                         {
437                                 // otherwise find it somewhere in the list
438                                 for (current = cvar_vars;current->next != cvar;current = current->next)
439                                         ;
440                                 current->next = variable;
441                         }
442
443                         // get rid of old allocated cvar
444                         // (but not cvar->string and cvar->defstring, because we kept those)
445                         Z_Free(cvar->name);
446                         Z_Free(cvar);
447                 }
448                 else
449                         Con_Printf("Can't register variable %s, already defined\n", variable->name);
450                 return;
451         }
452
453 // check for overlap with a command
454         if (Cmd_Exists (variable->name))
455         {
456                 Con_Printf("Cvar_RegisterVariable: %s is a command\n", variable->name);
457                 return;
458         }
459
460 // copy the value off, because future sets will Z_Free it
461         oldstr = variable->string;
462         alloclen = strlen(variable->string) + 1;
463         variable->string = (char *)Z_Malloc (alloclen);
464         memcpy (variable->string, oldstr, alloclen);
465         variable->defstring = (char *)Z_Malloc (alloclen);
466         memcpy (variable->defstring, oldstr, alloclen);
467         variable->value = atof (variable->string);
468         variable->integer = (int) variable->value;
469
470 // link the variable in
471 // alphanumerical order
472         for( current = NULL, next = cvar_vars ; next && strcmp( next->name, variable->name ) < 0 ; current = next, next = next->next )
473                 ;
474         if( current ) {
475                 current->next = variable;
476         } else {
477                 cvar_vars = variable;
478         }
479         variable->next = next;
480
481         // link to head of list in this hash table index
482         hashindex = CRC_Block((const unsigned char *)variable->name, strlen(variable->name));
483         variable->nextonhashchain = cvar_hashtable[hashindex];
484         cvar_hashtable[hashindex] = variable;
485 }
486
487 /*
488 ============
489 Cvar_Get
490
491 Adds a newly allocated variable to the variable list or sets its value.
492 ============
493 */
494 cvar_t *Cvar_Get (const char *name, const char *value, int flags, const char *newdescription)
495 {
496         int hashindex;
497         cvar_t *current, *next, *cvar;
498         size_t alloclen;
499
500         if (developer.integer >= 100)
501                 Con_Printf("Cvar_Get(\"%s\", \"%s\", %i);\n", name, value, flags);
502
503 // first check to see if it has already been defined
504         cvar = Cvar_FindVar (name);
505         if (cvar)
506         {
507                 cvar->flags |= flags;
508                 Cvar_SetQuick_Internal (cvar, value);
509                 if(newdescription && (cvar->flags & CVAR_ALLOCATED))
510                 {
511                         if(cvar->description != cvar_dummy_description)
512                                 Z_Free(cvar->description);
513
514                         if(*newdescription)
515                         {
516                                 alloclen = strlen(newdescription) + 1;
517                                 cvar->description = (char *)Z_Malloc(alloclen);
518                                 memcpy(cvar->description, newdescription, alloclen);
519                         }
520                         else
521                                 cvar->description = cvar_dummy_description;
522                 }
523                 return cvar;
524         }
525
526 // check for overlap with a command
527         if (Cmd_Exists (name))
528         {
529                 Con_Printf("Cvar_Get: %s is a command\n", name);
530                 return NULL;
531         }
532
533 // allocate a new cvar, cvar name, and cvar string
534 // TODO: factorize the following code with the one at the end of Cvar_RegisterVariable()
535 // FIXME: these never get Z_Free'd
536         cvar = (cvar_t *)Z_Malloc(sizeof(cvar_t));
537         cvar->flags = flags | CVAR_ALLOCATED;
538         alloclen = strlen(name) + 1;
539         cvar->name = (char *)Z_Malloc(alloclen);
540         memcpy(cvar->name, name, alloclen);
541         alloclen = strlen(value) + 1;
542         cvar->string = (char *)Z_Malloc(alloclen);
543         memcpy(cvar->string, value, alloclen);
544         cvar->defstring = (char *)Z_Malloc(alloclen);
545         memcpy(cvar->defstring, value, alloclen);
546         cvar->value = atof (cvar->string);
547         cvar->integer = (int) cvar->value;
548
549         if(newdescription && *newdescription)
550         {
551                 alloclen = strlen(newdescription) + 1;
552                 cvar->description = (char *)Z_Malloc(alloclen);
553                 memcpy(cvar->description, newdescription, alloclen);
554         }
555         else
556                 cvar->description = cvar_dummy_description; // actually checked by VM_cvar_type
557
558 // link the variable in
559 // alphanumerical order
560         for( current = NULL, next = cvar_vars ; next && strcmp( next->name, cvar->name ) < 0 ; current = next, next = next->next )
561                 ;
562         if( current )
563                 current->next = cvar;
564         else
565                 cvar_vars = cvar;
566         cvar->next = next;
567
568         // link to head of list in this hash table index
569         hashindex = CRC_Block((const unsigned char *)cvar->name, strlen(cvar->name));
570         cvar->nextonhashchain = cvar_hashtable[hashindex];
571         cvar_hashtable[hashindex] = cvar;
572
573         return cvar;
574 }
575
576
577 /*
578 ============
579 Cvar_Command
580
581 Handles variable inspection and changing from the console
582 ============
583 */
584 qboolean        Cvar_Command (void)
585 {
586         cvar_t                  *v;
587
588 // check variables
589         v = Cvar_FindVar (Cmd_Argv(0));
590         if (!v)
591                 return false;
592
593 // perform a variable print or set
594         if (Cmd_Argc() == 1)
595         {
596                 Con_Printf("\"%s\" is \"%s\" [\"%s\"]\n", v->name, v->string, v->defstring);
597                 return true;
598         }
599
600         if (developer.integer >= 100)
601                 Con_DPrint("Cvar_Command: ");
602
603         if (v->flags & CVAR_READONLY)
604         {
605                 Con_Printf("%s is read-only\n", v->name);
606                 return true;
607         }
608         Cvar_Set (v->name, Cmd_Argv(1));
609         if (developer.integer >= 100)
610                 Con_DPrint("\n");
611         return true;
612 }
613
614
615 void Cvar_UnlockDefaults (void)
616 {
617         cvar_t *var;
618         // unlock the default values of all cvars
619         for (var = cvar_vars ; var ; var = var->next)
620                 var->flags &= ~CVAR_DEFAULTSET;
621 }
622
623
624 void Cvar_LockDefaults_f (void)
625 {
626         cvar_t *var;
627         // lock in the default values of all cvars
628         for (var = cvar_vars ; var ; var = var->next)
629         {
630                 if (!(var->flags & CVAR_DEFAULTSET))
631                 {
632                         size_t alloclen;
633
634                         //Con_Printf("locking cvar %s (%s -> %s)\n", var->name, var->string, var->defstring);
635                         var->flags |= CVAR_DEFAULTSET;
636                         Z_Free(var->defstring);
637                         alloclen = strlen(var->string) + 1;
638                         var->defstring = (char *)Z_Malloc(alloclen);
639                         memcpy(var->defstring, var->string, alloclen);
640                 }
641         }
642 }
643
644
645 void Cvar_ResetToDefaults_All_f (void)
646 {
647         cvar_t *var;
648         // restore the default values of all cvars
649         for (var = cvar_vars ; var ; var = var->next)
650                 if((var->flags & CVAR_NORESETTODEFAULTS) == 0)
651                         Cvar_SetQuick(var, var->defstring);
652 }
653
654
655 void Cvar_ResetToDefaults_NoSaveOnly_f (void)
656 {
657         cvar_t *var;
658         // restore the default values of all cvars
659         for (var = cvar_vars ; var ; var = var->next)
660                 if ((var->flags & (CVAR_NORESETTODEFAULTS | CVAR_SAVE)) == 0)
661                         Cvar_SetQuick(var, var->defstring);
662 }
663
664
665 void Cvar_ResetToDefaults_SaveOnly_f (void)
666 {
667         cvar_t *var;
668         // restore the default values of all cvars
669         for (var = cvar_vars ; var ; var = var->next)
670                 if ((var->flags & (CVAR_NORESETTODEFAULTS | CVAR_SAVE)) == CVAR_SAVE)
671                         Cvar_SetQuick(var, var->defstring);
672 }
673
674
675 /*
676 ============
677 Cvar_WriteVariables
678
679 Writes lines containing "set variable value" for all variables
680 with the archive flag set to true.
681 ============
682 */
683 void Cvar_WriteVariables (qfile_t *f)
684 {
685         cvar_t  *var;
686
687         // don't save cvars that match their default value
688         for (var = cvar_vars ; var ; var = var->next)
689                 if ((var->flags & CVAR_SAVE) && (strcmp(var->string, var->defstring) || (var->flags & CVAR_ALLOCATED)))
690                         FS_Printf(f, "%s%s \"%s\"\n", var->flags & CVAR_ALLOCATED ? "seta " : "", var->name, var->string);
691 }
692
693
694 // Added by EvilTypeGuy eviltypeguy@qeradiant.com
695 // 2000-01-09 CvarList command By Matthias "Maddes" Buecher, http://www.inside3d.com/qip/
696 /*
697 =========
698 Cvar_List
699 =========
700 */
701 void Cvar_List_f (void)
702 {
703         cvar_t *cvar;
704         const char *partial;
705         size_t len;
706         int count;
707         qboolean ispattern;
708
709         if (Cmd_Argc() > 1)
710         {
711                 partial = Cmd_Argv (1);
712                 len = strlen(partial);
713         }
714         else
715         {
716                 partial = NULL;
717                 len = 0;
718         }
719
720         ispattern = partial && (strchr(partial, '*') || strchr(partial, '?'));
721
722         count = 0;
723         for (cvar = cvar_vars; cvar; cvar = cvar->next)
724         {
725                 if (len && (ispattern ? !matchpattern_with_separator(cvar->name, partial, false, "", false) : strncmp (partial,cvar->name,len)))
726                         continue;
727
728                 Con_Printf("%s is \"%s\" [\"%s\"] %s\n", cvar->name, cvar->string, cvar->defstring, cvar->description);
729                 count++;
730         }
731
732         if (len)
733         {
734                 if(ispattern)
735                         Con_Printf("%i cvar%s matching \"%s\"\n", count, (count > 1) ? "s" : "", partial);
736                 else
737                         Con_Printf("%i cvar%s beginning with \"%s\"\n", count, (count > 1) ? "s" : "", partial);
738         }
739         else
740                 Con_Printf("%i cvar(s)\n", count);
741 }
742 // 2000-01-09 CvarList command by Maddes
743
744 void Cvar_Set_f (void)
745 {
746         cvar_t *cvar;
747
748         // make sure it's the right number of parameters
749         if (Cmd_Argc() < 3)
750         {
751                 Con_Printf("Set: wrong number of parameters, usage: set <variablename> <value> [<description>]\n");
752                 return;
753         }
754
755         // check if it's read-only
756         cvar = Cvar_FindVar(Cmd_Argv(1));
757         if (cvar && cvar->flags & CVAR_READONLY)
758         {
759                 Con_Printf("Set: %s is read-only\n", cvar->name);
760                 return;
761         }
762
763         if (developer.integer >= 100)
764                 Con_DPrint("Set: ");
765
766         // all looks ok, create/modify the cvar
767         Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), 0, Cmd_Argc() > 3 ? Cmd_Argv(3) : NULL);
768 }
769
770 void Cvar_SetA_f (void)
771 {
772         cvar_t *cvar;
773
774         // make sure it's the right number of parameters
775         if (Cmd_Argc() < 3)
776         {
777                 Con_Printf("SetA: wrong number of parameters, usage: seta <variablename> <value> [<description>]\n");
778                 return;
779         }
780
781         // check if it's read-only
782         cvar = Cvar_FindVar(Cmd_Argv(1));
783         if (cvar && cvar->flags & CVAR_READONLY)
784         {
785                 Con_Printf("SetA: %s is read-only\n", cvar->name);
786                 return;
787         }
788
789         if (developer.integer >= 100)
790                 Con_DPrint("SetA: ");
791
792         // all looks ok, create/modify the cvar
793         Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), CVAR_SAVE, Cmd_Argc() > 3 ? Cmd_Argv(3) : NULL);
794 }
795
796 void Cvar_Del_f (void)
797 {
798         int i;
799         cvar_t *cvar, *parent, **link, *prev;
800
801         if(Cmd_Argc() < 2)
802         {
803                 Con_Printf("Del: wrong number of parameters, useage: unset <variablename1> [<variablename2> ...]\n");
804                 return;
805         }
806         for(i = 1; i < Cmd_Argc(); ++i)
807         {
808                 cvar = Cvar_FindVarLink(Cmd_Argv(i), &parent, &link, &prev);
809                 if(!cvar)
810                 {
811                         Con_Printf("Del: %s is not defined\n", Cmd_Argv(i));
812                         continue;
813                 }
814                 if(cvar->flags & CVAR_READONLY)
815                 {
816                         Con_Printf("Del: %s is read-only\n", cvar->name);
817                         continue;
818                 }
819                 if(!(cvar->flags & CVAR_ALLOCATED))
820                 {
821                         Con_Printf("Del: %s is static and cannot be deleted\n", cvar->name);
822                         continue;
823                 }
824                 if(cvar == cvar_vars)
825                 {
826                         cvar_vars = cvar->next;
827                 }
828                 else
829                 {
830                         // in this case, prev must be set, otherwise there has been some inconsistensy
831                         // elsewhere already... should I still check for prev != NULL?
832                         prev->next = cvar->next;
833                 }
834
835                 if(parent)
836                         parent->nextonhashchain = cvar->nextonhashchain;
837                 else if(link)
838                         *link = cvar->nextonhashchain;
839
840                 if(cvar->description != cvar_dummy_description)
841                         Z_Free(cvar->description);
842
843                 Z_Free(cvar->name);
844                 Z_Free(cvar->string);
845                 Z_Free(cvar->defstring);
846                 Z_Free(cvar);
847         }
848 }
849
850 #ifdef FILLALLCVARSWITHRUBBISH
851 void Cvar_FillAll_f()
852 {
853         char *buf, *p, *q;
854         int n, i;
855         cvar_t *var;
856         qboolean verify;
857         if(Cmd_Argc() != 2)
858         {
859                 Con_Printf("Usage: %s length to plant rubbish\n", Cmd_Argv(0));
860                 Con_Printf("Usage: %s -length to verify that the rubbish is still there\n", Cmd_Argv(0));
861                 return;
862         }
863         n = atoi(Cmd_Argv(1));
864         verify = (n < 0);
865         if(verify)
866                 n = -n;
867         buf = Z_Malloc(n + 1);
868         buf[n] = 0;
869         for(var = cvar_vars; var; var = var->next)
870         {
871                 for(i = 0, p = buf, q = var->name; i < n; ++i)
872                 {
873                         *p++ = *q++;
874                         if(!*q)
875                                 q = var->name;
876                 }
877                 if(verify && strcmp(var->string, buf))
878                 {
879                         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);
880                 }
881                 Cvar_SetQuick(var, buf);
882         }
883         Z_Free(buf);
884 }
885 #endif /* FILLALLCVARSWITHRUBBISH */