2000-05-10 20:33:16 +00:00
|
|
|
/*
|
2000-05-11 16:03:29 +00:00
|
|
|
cvar.c
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-16 04:47:41 +00:00
|
|
|
dynamic variable tracking
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2000-05-16 04:47:41 +00:00
|
|
|
Copyright (C) 1999,2000 Nelson Rush.
|
|
|
|
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
|
|
|
Please see the file "AUTHORS" for a list of contributors
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
2000-05-10 20:33:16 +00:00
|
|
|
*/
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-17 10:03:19 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-12-08 06:51:37 +00:00
|
|
|
# include "config.h"
|
2000-05-17 10:03:19 +00:00
|
|
|
#endif
|
2000-12-30 02:16:36 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
2001-02-07 05:45:59 +00:00
|
|
|
# include <string.h>
|
2000-12-30 02:16:36 +00:00
|
|
|
#endif
|
2000-06-12 06:14:00 +00:00
|
|
|
#ifdef HAVE_STRINGS_H
|
2001-02-07 05:45:59 +00:00
|
|
|
# include <strings.h>
|
2000-06-12 06:14:00 +00:00
|
|
|
#endif
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2001-02-07 05:45:59 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "commdef.h"
|
|
|
|
#include "cvar.h"
|
|
|
|
#include "console.h"
|
2001-01-04 19:10:38 +00:00
|
|
|
#include "hash.h"
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "qargs.h"
|
|
|
|
#include "cmd.h"
|
|
|
|
#include "commdef.h"
|
|
|
|
|
2001-02-10 00:31:50 +00:00
|
|
|
cvar_t *cvar_vars;
|
|
|
|
char *cvar_null_string = "";
|
|
|
|
extern cvar_t *developer;
|
|
|
|
cvar_alias_t *calias_vars;
|
|
|
|
hashtab_t *cvar_hash;
|
|
|
|
hashtab_t *calias_hash;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Cvar_FindVar
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-28 09:31:22 +00:00
|
|
|
cvar_t *
|
2000-12-08 06:51:37 +00:00
|
|
|
Cvar_FindVar (char *var_name)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2001-02-10 00:31:50 +00:00
|
|
|
return (cvar_t*) Hash_Find (cvar_hash, var_name);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-12-28 09:31:22 +00:00
|
|
|
cvar_t *
|
2000-12-08 06:51:37 +00:00
|
|
|
Cvar_FindAlias (char *alias_name)
|
2000-05-16 04:47:41 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_alias_t *alias;
|
2000-05-16 04:47:41 +00:00
|
|
|
|
2001-02-10 00:31:50 +00:00
|
|
|
alias = (cvar_alias_t*) Hash_Find (calias_hash, alias_name);
|
2001-01-04 19:10:38 +00:00
|
|
|
if (alias)
|
|
|
|
return alias->cvar;
|
|
|
|
return 0;
|
2000-05-16 04:47:41 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Cvar_Alias_Get (char *name, cvar_t *cvar)
|
2000-05-16 04:47:41 +00:00
|
|
|
{
|
2001-02-10 00:31:50 +00:00
|
|
|
cvar_alias_t *alias;
|
|
|
|
cvar_t *var;
|
2000-05-16 04:47:41 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (Cmd_Exists (name)) {
|
2000-05-16 04:47:41 +00:00
|
|
|
Con_Printf ("CAlias_Get: %s is a command\n", name);
|
|
|
|
return;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
if (Cvar_FindVar (name)) {
|
|
|
|
Con_Printf ("CAlias_Get: tried to alias used cvar name %s\n", name);
|
2000-05-16 04:47:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
var = Cvar_FindAlias (name);
|
|
|
|
if (!var) {
|
|
|
|
alias = (cvar_alias_t *) calloc (1, sizeof (cvar_alias_t));
|
|
|
|
|
2000-05-16 04:47:41 +00:00
|
|
|
alias->next = calias_vars;
|
|
|
|
calias_vars = alias;
|
2000-12-08 06:51:37 +00:00
|
|
|
alias->name = strdup (name);
|
2000-05-16 04:47:41 +00:00
|
|
|
alias->cvar = cvar;
|
2001-01-04 19:10:38 +00:00
|
|
|
Hash_Add (calias_hash, alias);
|
2000-05-16 04:47:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Cvar_VariableValue
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
float
|
|
|
|
Cvar_VariableValue (char *var_name)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_t *var;
|
2000-05-16 04:47:41 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
var = Cvar_FindVar (var_name);
|
2000-05-16 04:47:41 +00:00
|
|
|
if (!var)
|
2000-12-08 06:51:37 +00:00
|
|
|
var = Cvar_FindAlias (var_name);
|
2000-05-10 11:29:38 +00:00
|
|
|
if (!var)
|
|
|
|
return 0;
|
2000-05-21 08:24:45 +00:00
|
|
|
return atof (var->string);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Cvar_VariableString
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-28 09:31:22 +00:00
|
|
|
char *
|
2000-12-08 06:51:37 +00:00
|
|
|
Cvar_VariableString (char *var_name)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_t *var;
|
2000-05-16 04:47:41 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
var = Cvar_FindVar (var_name);
|
2000-05-16 04:47:41 +00:00
|
|
|
if (!var)
|
2000-12-08 06:51:37 +00:00
|
|
|
var = Cvar_FindAlias (var_name);
|
2000-05-10 11:29:38 +00:00
|
|
|
if (!var)
|
|
|
|
return cvar_null_string;
|
|
|
|
return var->string;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Cvar_CompleteVariable
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-28 09:31:22 +00:00
|
|
|
char *
|
2000-12-08 06:51:37 +00:00
|
|
|
Cvar_CompleteVariable (char *partial)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_t *cvar;
|
|
|
|
cvar_alias_t *alias;
|
|
|
|
int len;
|
2000-05-16 04:47:41 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
len = strlen (partial);
|
2000-05-16 04:47:41 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
if (!len)
|
|
|
|
return NULL;
|
2000-05-16 04:47:41 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
// check exact match
|
2000-12-08 06:51:37 +00:00
|
|
|
for (cvar = cvar_vars; cvar; cvar = cvar->next)
|
|
|
|
if (!strcasecmp (partial, cvar->name))
|
2000-05-10 11:29:38 +00:00
|
|
|
return cvar->name;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-05-16 04:47:41 +00:00
|
|
|
// check aliases too :)
|
2000-12-08 06:51:37 +00:00
|
|
|
for (alias = calias_vars; alias; alias = alias->next)
|
2000-06-11 03:47:11 +00:00
|
|
|
if (!strcasecmp (partial, alias->name))
|
2000-05-16 04:47:41 +00:00
|
|
|
return alias->name;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
// check partial match
|
2000-12-08 06:51:37 +00:00
|
|
|
for (cvar = cvar_vars; cvar; cvar = cvar->next)
|
|
|
|
if (!strncasecmp (partial, cvar->name, len))
|
2000-05-10 11:29:38 +00:00
|
|
|
return cvar->name;
|
|
|
|
|
2000-05-16 04:47:41 +00:00
|
|
|
// check aliases too :)
|
2000-12-08 06:51:37 +00:00
|
|
|
for (alias = calias_vars; alias; alias = alias->next)
|
2000-06-11 03:47:11 +00:00
|
|
|
if (!strncasecmp (partial, alias->name, len))
|
2000-05-16 04:47:41 +00:00
|
|
|
return alias->name;
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-05-11 10:04:50 +00:00
|
|
|
|
2000-12-28 09:31:22 +00:00
|
|
|
void Cvar_Info (cvar_t *var);
|
2000-05-11 10:04:50 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Cvar_Set
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-11-04 07:42:43 +00:00
|
|
|
void
|
|
|
|
Cvar_Set (cvar_t *var, char *value)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-05-23 08:33:30 +00:00
|
|
|
if (!var)
|
|
|
|
return;
|
2000-09-30 07:59:14 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (var->flags & CVAR_ROM) {
|
2000-11-04 07:42:43 +00:00
|
|
|
Con_DPrintf ("Cvar \"%s\" is read-only, cannot modify\n", var->name);
|
2000-05-23 08:33:30 +00:00
|
|
|
return;
|
2000-11-04 07:42:43 +00:00
|
|
|
}
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
free (var->string); // free the old value string
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2001-01-04 19:10:38 +00:00
|
|
|
var->string = strdup (value);
|
2000-05-23 08:33:30 +00:00
|
|
|
var->value = atof (var->string);
|
2000-09-26 03:17:09 +00:00
|
|
|
var->int_val = atoi (var->string);
|
2001-01-08 07:07:48 +00:00
|
|
|
sscanf (var->string, "%f %f %f", &var->vec[0], &var->vec[1], &var->vec[2]);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-11-04 07:42:43 +00:00
|
|
|
Cvar_Info (var);
|
2000-05-23 08:33:30 +00:00
|
|
|
}
|
|
|
|
|
2000-05-27 16:40:36 +00:00
|
|
|
|
|
|
|
/*
|
2000-05-23 08:33:30 +00:00
|
|
|
Cvar_SetROM
|
|
|
|
|
|
|
|
doesn't check for CVAR_ROM flag
|
|
|
|
*/
|
2000-11-04 07:42:43 +00:00
|
|
|
void
|
|
|
|
Cvar_SetROM (cvar_t *var, char *value)
|
2000-05-23 08:33:30 +00:00
|
|
|
{
|
|
|
|
if (!var)
|
|
|
|
return;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
free (var->string); // free the old value string
|
2000-05-23 08:33:30 +00:00
|
|
|
|
2001-01-04 19:10:38 +00:00
|
|
|
var->string = strdup (value);
|
2000-05-23 08:33:30 +00:00
|
|
|
var->value = atof (var->string);
|
2000-09-26 03:17:09 +00:00
|
|
|
var->int_val = atoi (var->string);
|
2001-01-08 07:07:48 +00:00
|
|
|
sscanf (var->string, "%f %f %f", &var->vec[0], &var->vec[1], &var->vec[2]);
|
2000-05-23 08:33:30 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
Cvar_Info (var);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
2000-05-17 23:16:23 +00:00
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Cvar_SetValue
|
2000-05-17 23:16:23 +00:00
|
|
|
*/
|
2000-08-17 18:28:28 +00:00
|
|
|
// 1999-09-07 weird cvar zeros fix by Maddes
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Cvar_SetValue (cvar_t *var, float value)
|
2000-05-17 23:16:23 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
char val[32];
|
|
|
|
int i;
|
2000-08-17 18:28:28 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
snprintf (val, sizeof (val), "%f", value);
|
|
|
|
for (i = strlen (val) - 1; i > 0 && val[i] == '0' && val[i - 1] != '.'; i--) {
|
2000-08-17 18:28:28 +00:00
|
|
|
val[i] = 0;
|
|
|
|
}
|
2000-09-22 15:38:05 +00:00
|
|
|
Cvar_Set (var, val);
|
2000-05-17 23:16:23 +00:00
|
|
|
}
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Cvar_Command
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2001-02-09 02:53:09 +00:00
|
|
|
Handles variable inspection and changing from the console
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-11-04 07:42:43 +00:00
|
|
|
qboolean
|
|
|
|
Cvar_Command (void)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_t *v;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-11-04 07:42:43 +00:00
|
|
|
// check variables
|
2000-12-08 06:51:37 +00:00
|
|
|
v = Cvar_FindVar (Cmd_Argv (0));
|
2000-05-16 04:47:41 +00:00
|
|
|
if (!v)
|
2000-12-08 06:51:37 +00:00
|
|
|
v = Cvar_FindAlias (Cmd_Argv (0));
|
2000-05-10 11:29:38 +00:00
|
|
|
if (!v)
|
|
|
|
return false;
|
2000-05-16 04:47:41 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
// perform a variable print or set
|
2000-12-08 06:51:37 +00:00
|
|
|
if (Cmd_Argc () == 1) {
|
2000-05-10 11:29:38 +00:00
|
|
|
Con_Printf ("\"%s\" is \"%s\"\n", v->name, v->string);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
Cvar_Set (v, Cmd_Argv (1));
|
2000-05-10 11:29:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Cvar_WriteVariables
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2001-02-09 02:53:09 +00:00
|
|
|
Writes lines containing "set variable value" for all variables
|
|
|
|
with the archive flag set to true.
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Cvar_WriteVariables (QFile *f)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_t *var;
|
2000-05-16 04:47:41 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (var = cvar_vars; var; var = var->next)
|
|
|
|
if (var->flags & CVAR_ARCHIVE)
|
2000-09-27 19:44:26 +00:00
|
|
|
Qprintf (f, "%s \"%s\"\n", var->name, var->string);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-11-04 07:42:43 +00:00
|
|
|
void
|
|
|
|
Cvar_Set_f (void)
|
2000-05-16 04:47:41 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_t *var;
|
|
|
|
char *value;
|
|
|
|
char *var_name;
|
2000-05-16 04:47:41 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (Cmd_Argc () != 3) {
|
2000-05-16 04:47:41 +00:00
|
|
|
Con_Printf ("usage: set <cvar> <value>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var_name = Cmd_Argv (1);
|
|
|
|
value = Cmd_Argv (2);
|
|
|
|
var = Cvar_FindVar (var_name);
|
2000-11-04 07:42:43 +00:00
|
|
|
|
2000-05-16 04:47:41 +00:00
|
|
|
if (!var)
|
|
|
|
var = Cvar_FindAlias (var_name);
|
2000-11-04 07:42:43 +00:00
|
|
|
|
|
|
|
if (var) {
|
|
|
|
if (var->flags & CVAR_ROM) {
|
|
|
|
Con_DPrintf ("Cvar \"%s\" is read-only, cannot modify\n", var_name);
|
|
|
|
} else {
|
|
|
|
Cvar_Set (var, value);
|
|
|
|
}
|
|
|
|
} else {
|
2000-09-22 15:32:52 +00:00
|
|
|
var = Cvar_Get (var_name, value, CVAR_USER_CREATED,
|
2000-12-08 06:51:37 +00:00
|
|
|
"User-created cvar");
|
2000-05-16 04:47:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-04 07:42:43 +00:00
|
|
|
void
|
|
|
|
Cvar_Setrom_f (void)
|
2000-05-23 08:33:30 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_t *var;
|
|
|
|
char *value;
|
|
|
|
char *var_name;
|
2000-05-23 08:33:30 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (Cmd_Argc () != 3) {
|
2000-11-04 07:42:43 +00:00
|
|
|
Con_Printf ("usage: setrom <cvar> <value>\n");
|
2000-05-23 08:33:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var_name = Cmd_Argv (1);
|
|
|
|
value = Cmd_Argv (2);
|
|
|
|
var = Cvar_FindVar (var_name);
|
2000-11-04 07:42:43 +00:00
|
|
|
|
2000-05-23 08:33:30 +00:00
|
|
|
if (!var)
|
|
|
|
var = Cvar_FindAlias (var_name);
|
2000-11-04 07:42:43 +00:00
|
|
|
|
|
|
|
if (var) {
|
|
|
|
if (var->flags & CVAR_ROM) {
|
|
|
|
Con_DPrintf ("Cvar \"%s\" is read-only, cannot modify\n", var_name);
|
|
|
|
} else {
|
|
|
|
Cvar_Set (var, value);
|
2001-02-10 00:31:50 +00:00
|
|
|
Cvar_SetFlags (var, var->flags | CVAR_ROM);
|
2000-11-04 07:42:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
2000-12-08 06:51:37 +00:00
|
|
|
var = Cvar_Get (var_name, value, CVAR_USER_CREATED | CVAR_ROM,
|
|
|
|
"User-created READ-ONLY Cvar");
|
2000-05-23 08:33:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Cvar_Toggle_f (void)
|
2000-05-16 04:47:41 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_t *var;
|
2000-05-16 04:47:41 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (Cmd_Argc () != 2) {
|
2000-05-16 04:47:41 +00:00
|
|
|
Con_Printf ("toggle <cvar> : toggle a cvar on/off\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
var = Cvar_FindVar (Cmd_Argv (1));
|
2000-05-16 04:47:41 +00:00
|
|
|
if (!var)
|
2000-12-08 06:51:37 +00:00
|
|
|
var = Cvar_FindAlias (Cmd_Argv (1));
|
|
|
|
if (!var) {
|
|
|
|
Con_Printf ("Unknown variable \"%s\"\n", Cmd_Argv (1));
|
2000-05-16 04:47:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-10-17 03:17:42 +00:00
|
|
|
Cvar_Set (var, var->int_val ? "0" : "1");
|
2000-05-16 04:47:41 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Cvar_Help_f (void)
|
2000-05-16 04:47:41 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
char *var_name;
|
|
|
|
cvar_t *var;
|
2000-05-16 04:47:41 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (Cmd_Argc () != 2) {
|
2000-05-16 04:47:41 +00:00
|
|
|
Con_Printf ("usage: help <cvar>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var_name = Cmd_Argv (1);
|
|
|
|
var = Cvar_FindVar (var_name);
|
|
|
|
if (!var)
|
|
|
|
var = Cvar_FindAlias (var_name);
|
2000-12-08 06:51:37 +00:00
|
|
|
if (var) {
|
|
|
|
Con_Printf ("%s\n", var->description);
|
2000-05-16 04:47:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Con_Printf ("variable not found\n");
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Cvar_CvarList_f (void)
|
2000-05-16 04:47:41 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_t *var;
|
|
|
|
int i;
|
2000-12-31 22:06:00 +00:00
|
|
|
int showhelp = 0;
|
2000-05-16 04:47:41 +00:00
|
|
|
|
2000-12-31 22:06:00 +00:00
|
|
|
if (Cmd_Argc () > 1)
|
|
|
|
showhelp = 1;
|
|
|
|
for (var = cvar_vars, i = 0; var; var = var->next, i++) {
|
2001-01-03 17:09:14 +00:00
|
|
|
Con_Printf ("%c%c%c%c ",
|
|
|
|
var->flags & CVAR_ROM ? 'r' : ' ',
|
2000-12-08 06:51:37 +00:00
|
|
|
var->flags & CVAR_ARCHIVE ? '*' : ' ',
|
|
|
|
var->flags & CVAR_USERINFO ? 'u' : ' ',
|
2000-12-31 22:06:00 +00:00
|
|
|
var->flags & CVAR_SERVERINFO ? 's' : ' ');
|
|
|
|
if (showhelp)
|
|
|
|
Con_Printf ("%-20s : %s\n", var->name, var->description);
|
|
|
|
else
|
|
|
|
Con_Printf ("%s\n", var->name);
|
|
|
|
}
|
2000-09-22 15:32:52 +00:00
|
|
|
|
2000-05-16 04:47:41 +00:00
|
|
|
Con_Printf ("------------\n%d variables\n", i);
|
|
|
|
}
|
|
|
|
|
2001-01-04 19:10:38 +00:00
|
|
|
static void
|
|
|
|
cvar_free (void *c)
|
|
|
|
{
|
|
|
|
cvar_t *cvar = (cvar_t*)c;
|
|
|
|
free (cvar->name);
|
|
|
|
free (cvar->string);
|
|
|
|
free (cvar);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
cvar_get_key (void *c)
|
|
|
|
{
|
|
|
|
cvar_t *cvar = (cvar_t*)c;
|
|
|
|
return cvar->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
calias_free (void *c)
|
|
|
|
{
|
|
|
|
cvar_alias_t *calias = (cvar_alias_t*)c;
|
|
|
|
free (calias->name);
|
|
|
|
free (calias);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
calias_get_key (void *c)
|
|
|
|
{
|
|
|
|
cvar_alias_t *calias = (cvar_alias_t*)c;
|
|
|
|
return calias->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Cvar_Init_Hash (void)
|
|
|
|
{
|
|
|
|
cvar_hash = Hash_NewTable (1021, cvar_get_key, cvar_free);
|
|
|
|
calias_hash = Hash_NewTable (1021, calias_get_key, calias_free);
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
2000-12-28 09:31:22 +00:00
|
|
|
Cvar_Init (void)
|
2000-05-16 04:47:41 +00:00
|
|
|
{
|
2000-12-31 04:46:04 +00:00
|
|
|
developer = Cvar_Get ("developer", "0", 0, "set to enable extra debugging information");
|
2000-05-16 04:47:41 +00:00
|
|
|
|
2001-02-06 02:56:14 +00:00
|
|
|
Cmd_AddCommand ("set", Cvar_Set_f, "Set the selected variable, useful on the command line (+set variablename setting)");
|
2001-02-06 19:45:24 +00:00
|
|
|
Cmd_AddCommand ("setrom", Cvar_Setrom_f, "Set the selected variable and make it read only, useful on the command line.\n"
|
|
|
|
"(+setrom variablename setting)");
|
2001-02-06 02:56:14 +00:00
|
|
|
Cmd_AddCommand ("toggle", Cvar_Toggle_f, "Toggle a cvar on or off");
|
|
|
|
Cmd_AddCommand ("help", Cvar_Help_f, "Display quake help");
|
|
|
|
Cmd_AddCommand ("cvarlist", Cvar_CvarList_f, "List all cvars");
|
2000-05-16 04:47:41 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Cvar_Shutdown (void)
|
2000-05-16 04:47:41 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_t *var, *next;
|
|
|
|
cvar_alias_t *alias, *nextalias;
|
2000-05-16 04:47:41 +00:00
|
|
|
|
|
|
|
// Free cvars
|
|
|
|
var = cvar_vars;
|
2000-12-08 06:51:37 +00:00
|
|
|
while (var) {
|
2000-05-16 04:47:41 +00:00
|
|
|
next = var->next;
|
2000-12-08 06:51:37 +00:00
|
|
|
free (var->string);
|
|
|
|
free (var->name);
|
|
|
|
free (var);
|
2000-05-16 04:47:41 +00:00
|
|
|
var = next;
|
|
|
|
}
|
|
|
|
// Free aliases
|
|
|
|
alias = calias_vars;
|
2000-12-08 06:51:37 +00:00
|
|
|
while (alias) {
|
2000-05-16 04:47:41 +00:00
|
|
|
nextalias = alias->next;
|
2000-12-08 06:51:37 +00:00
|
|
|
free (alias->name);
|
|
|
|
free (alias);
|
2000-05-16 04:47:41 +00:00
|
|
|
alias = nextalias;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-28 09:31:22 +00:00
|
|
|
cvar_t *
|
2000-12-08 06:51:37 +00:00
|
|
|
Cvar_Get (char *name, char *string, int cvarflags, char *description)
|
2000-05-16 04:47:41 +00:00
|
|
|
{
|
|
|
|
|
2001-02-06 17:34:18 +00:00
|
|
|
cvar_t *var;
|
2000-05-16 04:47:41 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (Cmd_Exists (name)) {
|
|
|
|
Con_Printf ("Cvar_Get: %s is a command\n", name);
|
2000-05-16 04:47:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-02-06 17:34:18 +00:00
|
|
|
var = Cvar_FindVar (name);
|
|
|
|
if (!var) {
|
|
|
|
cvar_t **v;
|
|
|
|
var = (cvar_t *) calloc (1, sizeof (cvar_t));
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-05-16 04:47:41 +00:00
|
|
|
// Cvar doesn't exist, so we create it
|
2001-02-06 17:34:18 +00:00
|
|
|
var->name = strdup (name);
|
|
|
|
var->string = strdup (string);
|
|
|
|
var->flags = cvarflags;
|
|
|
|
var->description = description;
|
|
|
|
var->value = atof (var->string);
|
|
|
|
var->int_val = atoi (var->string);
|
|
|
|
sscanf (var->string, "%f %f %f",
|
|
|
|
&var->vec[0], &var->vec[1], &var->vec[2]);
|
|
|
|
Hash_Add (cvar_hash, var);
|
|
|
|
|
|
|
|
for (v = &cvar_vars; *v; v = &(*v)->next)
|
|
|
|
if (strcmp ((*v)->name, var->name) >= 0)
|
|
|
|
break;
|
|
|
|
var->next = *v;
|
|
|
|
*v = var;
|
2000-12-24 23:39:43 +00:00
|
|
|
} else {
|
|
|
|
// Cvar does exist, so we update the flags and return.
|
2001-02-06 17:34:18 +00:00
|
|
|
var->flags &= ~CVAR_USER_CREATED;
|
|
|
|
var->flags |= cvarflags;
|
|
|
|
var->description = description;
|
2000-05-16 04:47:41 +00:00
|
|
|
}
|
2001-02-06 17:34:18 +00:00
|
|
|
Cvar_Info (var);
|
2000-09-22 15:32:52 +00:00
|
|
|
|
2001-02-06 17:34:18 +00:00
|
|
|
return var;
|
2000-05-16 04:47:41 +00:00
|
|
|
}
|
2000-05-27 16:40:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Cvar_SetFlags
|
|
|
|
|
|
|
|
sets a Cvar's flags simply and easily
|
|
|
|
*/
|
|
|
|
void
|
2000-05-28 11:09:59 +00:00
|
|
|
Cvar_SetFlags (cvar_t *var, int cvarflags)
|
2000-05-27 16:40:36 +00:00
|
|
|
{
|
|
|
|
if (var == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var->flags = cvarflags;
|
|
|
|
}
|