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