From 6114156b49fe6cbaa00c308f8f673bbebb9843a6 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 5 Jul 2011 21:59:47 +0900 Subject: [PATCH] Add Cvar_RemoveAlias. Now aliases can be deleted (needed for menus). --- include/QF/cvar.h | 1 + libs/util/cvar.c | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/include/QF/cvar.h b/include/QF/cvar.h index 97ac96109..63070feef 100644 --- a/include/QF/cvar.h +++ b/include/QF/cvar.h @@ -84,6 +84,7 @@ cvar_t *Cvar_Get (const char *name, const char *value, int cvarflags, cvar_t *Cvar_FindAlias (const char *alias_name); cvar_t *Cvar_MakeAlias (const char *name, cvar_t *cvar); +cvar_t *Cvar_RemoveAlias (const char *name); // equivelants to " " typed at the console void Cvar_Set (cvar_t *var, const char *value); diff --git a/libs/util/cvar.c b/libs/util/cvar.c index 9bcccdb7a..e61d8f947 100644 --- a/libs/util/cvar.c +++ b/libs/util/cvar.c @@ -76,7 +76,7 @@ Cvar_FindAlias (const char *alias_name) { cvar_alias_t *alias; - alias = (cvar_alias_t*) Hash_Find (calias_hash, alias_name); + alias = (cvar_alias_t *) Hash_Find (calias_hash, alias_name); if (alias) return alias->cvar; return 0; @@ -85,7 +85,7 @@ Cvar_FindAlias (const char *alias_name) cvar_t * Cvar_MakeAlias (const char *name, cvar_t *cvar) { - cvar_alias_t *alias; + cvar_alias_t *alias; cvar_t *var; if (Cmd_Exists (name)) { @@ -115,6 +115,22 @@ Cvar_MakeAlias (const char *name, cvar_t *cvar) return cvar; } +cvar_t * +Cvar_RemoveAlias (const char *name) +{ + cvar_alias_t *alias; + cvar_t *var; + + alias = (cvar_alias_t *) Hash_Find (calias_hash, name); + if (!alias) { + Sys_Printf ("Cvar_RemoveAlias: %s is not an alias\n", name); + return 0; + } + var = alias->cvar; + Hash_Free (calias_hash, Hash_Del (calias_hash, name)); + return var; +} + VISIBLE float Cvar_VariableValue (const char *var_name) { @@ -570,7 +586,7 @@ cvar_get_key (void *c, void *unused) static void calias_free (void *c, void *unused) { - cvar_alias_t *calias = (cvar_alias_t*)c; + cvar_alias_t *calias = (cvar_alias_t *) c; free (calias->name); free (calias); } @@ -578,7 +594,7 @@ calias_free (void *c, void *unused) static const char * calias_get_key (void *c, void *unused) { - cvar_alias_t *calias = (cvar_alias_t*)c; + cvar_alias_t *calias = (cvar_alias_t *) c; return calias->name; }