cvar_t *var;
for (var = cvar_vars;var;var = var->next)
- if (!strcmp (var_name, var->name))
+ if (!strcasecmp (var_name, var->name))
return var;
return NULL;
// check functions
for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
- if (!strncmp (partial,cvar->name, len))
+ if (!strncasecmp (partial,cvar->name, len))
return cvar->name;
return NULL;
Cvar_Set
============
*/
-void Cvar_SetQuick (cvar_t *var, const char *value)
+void Cvar_SetQuick_Internal (cvar_t *var, const char *value)
{
qboolean changed;
- if (var == NULL)
- {
- Con_Print("Cvar_SetQuick: var == NULL\n");
- return;
- }
-
changed = strcmp(var->string, value);
// LordHavoc: don't reallocate when there is no change
if (!changed)
SV_BroadcastPrintf("\"%s\" changed to \"%s\"\n", var->name, var->string);
}
+void Cvar_SetQuick (cvar_t *var, const char *value)
+{
+ if (var == NULL)
+ {
+ Con_Print("Cvar_SetQuick: var == NULL\n");
+ return;
+ }
+
+ if (developer.integer)
+ Con_Printf("Cvar_SetQuick({\"%s\", \"%s\", %i}, \"%s\");\n", var->name, var->string, var->flags, value);
+
+ Cvar_SetQuick_Internal(var, value);
+}
+
void Cvar_Set (const char *var_name, const char *value)
{
cvar_t *var;
var = Cvar_FindVar (var_name);
if (var == NULL)
{
- // there is an error in C code if this happens
Con_Printf("Cvar_Set: variable %s not found\n", var_name);
return;
}
- if (var->flags & CVAR_READONLY)
- {
- Con_Printf("Cvar_Set: %s is read-only\n", var_name);
- return;
- }
-
Cvar_SetQuick(var, value);
}
*/
void Cvar_RegisterVariable (cvar_t *variable)
{
- char *oldstr;
+ cvar_t *cvar, *cvar2;
+ char *oldstr;
+
+ if (developer.integer)
+ Con_Printf("Cvar_RegisterVariable({\"%s\", \"%s\", %i});\n", variable->name, variable->string, variable->flags);
// first check to see if it has already been defined
- if (Cvar_FindVar (variable->name))
+ cvar = Cvar_FindVar (variable->name);
+ if (cvar)
{
- Con_Printf("Can't register variable %s, already defined\n", variable->name);
+ if (cvar->flags & CVAR_ALLOCATED)
+ {
+ if (developer.integer)
+ Con_Printf("... replacing existing allocated cvar {\"%s\", \"%s\", %i}", cvar->name, cvar->string, cvar->flags);
+ // fixed variables replace allocated ones
+ // (because the engine directly accesses fixed variables)
+ // NOTE: this isn't actually used currently
+ // (all cvars are registered before config parsing)
+ variable->flags |= (cvar->flags & ~CVAR_ALLOCATED);
+ // cvar->string is now owned by variable instead
+ variable->string = cvar->string;
+ variable->value = atof (variable->string);
+ variable->integer = (int) variable->value;
+ // replace cvar with this one...
+ variable->next = cvar->next;
+ if (cvar_vars == cvar)
+ {
+ // head of the list is easy to change
+ cvar_vars = variable;
+ }
+ 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;
+ }
+
+ // get rid of old allocated cvar
+ // (but not the cvar->string, because we kept that)
+ Z_Free(cvar->name);
+ Z_Free(cvar);
+ }
+ else
+ Con_Printf("Can't register variable %s, already defined\n", variable->name);
return;
}
cvar_vars = variable;
}
+/*
+============
+Cvar_Get
+
+Adds a newly allocated variable to the variable list or sets its value.
+============
+*/
+cvar_t *Cvar_Get (const char *name, const char *value, int flags)
+{
+ cvar_t *cvar;
+
+ 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);
+ return cvar;
+ }
+
+// check for overlap with a command
+ if (Cmd_Exists (name))
+ {
+ Con_Printf("Cvar_Get: %s is a command\n", name);
+ return NULL;
+ }
+
+// 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->name = Z_Malloc(strlen(name)+1);
+ strcpy(cvar->name, name);
+ cvar->string = Z_Malloc(strlen(value)+1);
+ strcpy(cvar->string, value);
+ cvar->value = atof (cvar->string);
+ cvar->integer = (int) cvar->value;
+
+// link the variable in
+ cvar->next = cvar_vars;
+ cvar_vars = cvar;
+ return cvar;
+}
+
+
/*
============
Cvar_Command
return true;
}
+ if (developer.integer)
+ Con_Print("Cvar_Command: ");
+
+ if (v->flags & CVAR_READONLY)
+ {
+ Con_Printf("%s is read-only\n", v->name);
+ return true;
+ }
Cvar_Set (v->name, Cmd_Argv(1));
return true;
}
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, "seta %s \"%s\"\n", var->name, var->string);
}
count = 0;
for (cvar = cvar_vars; cvar; cvar = cvar->next)
{
- if (partial && strncmp (partial,cvar->name,len))
+ if (partial && strncasecmp (partial,cvar->name,len))
continue;
Con_Printf("%s is \"%s\"\n", cvar->name, cvar->string);
}
// 2000-01-09 CvarList command by Maddes
+void Cvar_Set_f (void)
+{
+ cvar_t *cvar;
+
+ // make sure it's the right number of parameters
+ if (Cmd_Argc() < 3)
+ {
+ Con_Printf("Set: wrong number of parameters, usage: set <variablename> <value>\n");
+ return;
+ }
+
+ // check if it's read-only
+ cvar = Cvar_FindVar(Cmd_Argv(1));
+ if (cvar && cvar->flags & CVAR_READONLY)
+ {
+ Con_Printf("Set: %s is read-only\n", cvar->name);
+ return;
+ }
+
+ if (developer.integer)
+ Con_Print("Set: ");
+
+ // all looks ok, create/modify the cvar
+ Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), 0);
+}
+
+void Cvar_SetA_f (void)
+{
+ cvar_t *cvar;
+
+ // make sure it's the right number of parameters
+ if (Cmd_Argc() < 3)
+ {
+ Con_Printf("SetA: wrong number of parameters, usage: seta <variablename> <value>\n");
+ return;
+ }
+
+ // check if it's read-only
+ cvar = Cvar_FindVar(Cmd_Argv(1));
+ if (cvar && cvar->flags & CVAR_READONLY)
+ {
+ Con_Printf("SetA: %s is read-only\n", cvar->name);
+ return;
+ }
+
+ if (developer.integer)
+ Con_Print("SetA: ");
+
+ // all looks ok, create/modify the cvar
+ Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), CVAR_SAVE);
+}
+
+