return var->string;
}
+/*
+============
+Cvar_VariableDefString
+============
+*/
+const char *Cvar_VariableDefString (const char *var_name)
+{
+ cvar_t *var;
+
+ var = Cvar_FindVar (var_name);
+ if (!var)
+ return cvar_null_string;
+ return var->defstring;
+}
+
/*
============
const char *Cvar_CompleteVariable (const char *partial)
{
cvar_t *cvar;
- int len;
+ size_t len;
len = strlen(partial);
int Cvar_CompleteCountPossible (const char *partial)
{
cvar_t *cvar;
- int len;
+ size_t len;
int h;
h = 0;
const char **Cvar_CompleteBuildList (const char *partial)
{
const cvar_t *cvar;
- int len = 0;
- int bpos = 0;
- int sizeofbuf = (Cvar_CompleteCountPossible (partial) + 1) * sizeof (const char *);
+ size_t len = 0;
+ size_t bpos = 0;
+ size_t sizeofbuf = (Cvar_CompleteCountPossible (partial) + 1) * sizeof (const char *);
const char **buf;
len = strlen(partial);
}
if (developer.integer)
- Con_Printf("Cvar_SetQuick({\"%s\", \"%s\", %i}, \"%s\");\n", var->name, var->string, var->flags, value);
+ Con_Printf("Cvar_SetQuick({\"%s\", \"%s\", %i, \"%s\"}, \"%s\");\n", var->name, var->string, var->flags, var->defstring, value);
Cvar_SetQuick_Internal(var, value);
}
*/
void Cvar_RegisterVariable (cvar_t *variable)
{
- cvar_t *cvar, *cvar2;
+ cvar_t *current, *next, *cvar;
char *oldstr;
if (developer.integer)
variable->flags |= (cvar->flags & ~CVAR_ALLOCATED);
// cvar->string is now owned by variable instead
variable->string = cvar->string;
+ variable->defstring = cvar->defstring;
variable->value = atof (variable->string);
variable->integer = (int) variable->value;
// replace cvar with this one...
else
{
// otherwise find it somewhere in the list
- for (cvar2 = cvar_vars;cvar2->next != cvar;cvar2 = cvar2->next);
- if (cvar2->next == cvar)
- cvar2->next = variable;
+ for (current = cvar_vars;current->next != cvar;current = current->next)
+ ;
+ current->next = variable;
}
// get rid of old allocated cvar
- // (but not the cvar->string, because we kept that)
+ // (but not cvar->string and cvar->defstring, because we kept those)
Z_Free(cvar->name);
Z_Free(cvar);
}
oldstr = variable->string;
variable->string = Z_Malloc (strlen(variable->string)+1);
strcpy (variable->string, oldstr);
+ variable->defstring = Z_Malloc (strlen(variable->string)+1);
+ strcpy (variable->defstring, oldstr);
variable->value = atof (variable->string);
variable->integer = (int) variable->value;
// link the variable in
- variable->next = cvar_vars;
- cvar_vars = variable;
+// alphanumerical order
+ for( current = NULL, next = cvar_vars ; next && strcmp( next->name, variable->name ) < 0 ; current = next, next = next->next )
+ ;
+ if( current ) {
+ current->next = variable;
+ } else {
+ cvar_vars = variable;
+ }
+ variable->next = next;
}
/*
if (developer.integer)
Con_Printf("Cvar_Get(\"%s\", \"%s\", %i);\n", name, value, flags);
-
+
// first check to see if it has already been defined
cvar = Cvar_FindVar (name);
if (cvar)
{
cvar->flags |= flags;
Cvar_SetQuick_Internal (cvar, value);
+ // also set the default value (but only once)
+ if (~cvar->flags & CVAR_DEFAULTSET)
+ {
+ cvar->flags |= CVAR_DEFAULTSET;
+
+ Z_Free(cvar->defstring);
+ cvar->defstring = Z_Malloc(strlen(value) + 1);
+ strcpy(cvar->defstring, value);
+ }
return cvar;
}
// allocate a new cvar, cvar name, and cvar string
// FIXME: these never get Z_Free'd
cvar = Z_Malloc(sizeof(cvar_t));
- cvar->flags = flags | CVAR_ALLOCATED;
+ cvar->flags = flags | CVAR_ALLOCATED | CVAR_DEFAULTSET;
cvar->name = Z_Malloc(strlen(name)+1);
strcpy(cvar->name, name);
cvar->string = Z_Malloc(strlen(value)+1);
strcpy(cvar->string, value);
+ cvar->defstring = Z_Malloc(strlen(value)+1);
+ strcpy(cvar->defstring, value);
cvar->value = atof (cvar->string);
cvar->integer = (int) cvar->value;
// perform a variable print or set
if (Cmd_Argc() == 1)
{
- // only print if host_initialized (otherwise it could print twice if this is in a script)
- if (host_initialized)
- Con_Printf("\"%s\" is \"%s\"\n", v->name, v->string);
+ Con_Printf("\"%s\" is \"%s\" [\"%s\"]\n", v->name, v->string, v->defstring);
return true;
}
- if (developer.integer)
- Con_Print("Cvar_Command: ");
+ Con_DPrint("Cvar_Command: ");
if (v->flags & CVAR_READONLY)
{
for (var = cvar_vars ; var ; var = var->next)
if (var->flags & CVAR_SAVE)
- FS_Printf(f, "%s \"%s\"\n", var->name, var->string);
+ FS_Printf(f, "%s%s \"%s\"\n", var->flags & CVAR_ALLOCATED ? "seta " : "", var->name, var->string);
}
{
cvar_t *cvar;
const char *partial;
- int len, count;
+ size_t len;
+ int count;
if (Cmd_Argc() > 1)
{
if (partial && strncasecmp (partial,cvar->name,len))
continue;
- Con_Printf("%s is \"%s\"\n", cvar->name, cvar->string);
+ Con_Printf("%s is \"%s\" [\"%s\"]\n", cvar->name, cvar->string, cvar->defstring);
count++;
}
return;
}
- if (developer.integer)
- Con_Print("Set: ");
+ Con_DPrint("Set: ");
// all looks ok, create/modify the cvar
Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), 0);
return;
}
- if (developer.integer)
- Con_Print("SetA: ");
+ Con_DPrint("SetA: ");
// all looks ok, create/modify the cvar
Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), CVAR_SAVE);