From 5d2b147658331973165e6c791956a9bb4c901f51 Mon Sep 17 00:00:00 2001 From: terminx Date: Mon, 30 Jun 2008 01:03:51 +0000 Subject: [PATCH] added support for removing aliases git-svn-id: https://svn.eduke32.com/eduke32@820 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/build/include/osd.h | 1 + polymer/build/src/osd.c | 40 +++++++++++++++++++++--- polymer/eduke32/source/config.c | 5 +++ polymer/eduke32/source/osdcmds.c | 32 +++++--------------- polymer/eduke32/source/osdcmds.h | 52 +++++++++++++++++++++++--------- 5 files changed, 86 insertions(+), 44 deletions(-) diff --git a/polymer/build/include/osd.h b/polymer/build/include/osd.h index 1361e2b29..f472be370 100644 --- a/polymer/build/include/osd.h +++ b/polymer/build/include/osd.h @@ -25,6 +25,7 @@ typedef struct _symbol extern symbol_t *symbols; #define OSD_ALIAS 1337 +#define OSD_UNALIASED 1338 #define OSDCMD_OK 0 #define OSDCMD_SHOWHELP 1 diff --git a/polymer/build/src/osd.c b/polymer/build/src/osd.c index d7918b55e..ee286a151 100644 --- a/polymer/build/src/osd.c +++ b/polymer/build/src/osd.c @@ -228,7 +228,7 @@ static int _internal_osdfunc_alias(const osdfuncparm_t *parm) else OSD_Printf("%s is a function, not an alias\n",i->name); return OSDCMD_OK; } - if (i->func != (void *)OSD_ALIAS) + if (i->func != (void *)OSD_ALIAS && i->func != (void *)OSD_UNALIASED) { OSD_Printf("Cannot override function \"%s\" with alias\n",i->name); return OSDCMD_OK; @@ -241,6 +241,33 @@ static int _internal_osdfunc_alias(const osdfuncparm_t *parm) return OSDCMD_OK; } +static int _internal_osdfunc_unalias(const osdfuncparm_t *parm) +{ + symbol_t *i; + + if (parm->numparms < 1) + return OSDCMD_SHOWHELP; + + for (i=symbols; i!=NULL; i=i->next) + { + if (!Bstrcasecmp(parm->parms[0],i->name)) + { + if (parm->numparms < 2) + { + if (i->func == (void *)OSD_ALIAS) + { + OSD_Printf("Removed alias %s \(\"%s\"\)\n", i->name, i->help); + i->func = (void *)OSD_UNALIASED; + } + else OSD_Printf("Invalid alias %s\n",i->name); + return OSDCMD_OK; + } + } + } + OSD_Printf("Invalid alias %s\n",parm->parms[0]); + return OSDCMD_OK; +} + static int _internal_osdfunc_vars(const osdfuncparm_t *parm) { int showval = (parm->numparms < 1); @@ -278,7 +305,8 @@ static int _internal_osdfunc_listsymbols(const osdfuncparm_t *parm) OSD_Printf("Symbol listing:\n"); for (i=symbols; i!=NULL; i=i->next) - OSD_Printf(" %s\n", i->name); + if (i->func != (void *)OSD_UNALIASED) + OSD_Printf(" %s\n", i->name); return OSDCMD_OK; } @@ -348,6 +376,7 @@ void OSD_Init(void) OSD_RegisterFunction("logcutoff","logcutoff: sets the maximal line count of the log file",_internal_osdfunc_vars); OSD_RegisterFunction("clear","clear: clears the console text buffer",_internal_osdfunc_clear); OSD_RegisterFunction("alias","alias: creates an alias for calling multiple commands",_internal_osdfunc_alias); + OSD_RegisterFunction("unalias","unalias: removes an alias created with \"alias\"",_internal_osdfunc_unalias); atexit(OSD_Cleanup); } @@ -1194,7 +1223,7 @@ int OSD_Dispatch(const char *cmd) ofp.raw = cmd; if (symb->func == (void *)OSD_ALIAS) OSD_Dispatch(symb->help); - else + else if (symb->func != (void *)OSD_UNALIASED) { switch (symb->func(&ofp)) { @@ -1265,13 +1294,14 @@ int OSD_RegisterFunction(const char *name, const char *help, int (*func)(const o symb = findexactsymbol(name); if (symb) // allow this now for reusing an alias name { - if (symb->func != (void *)OSD_ALIAS) + if (symb->func != (void *)OSD_ALIAS && symb->func != (void *)OSD_UNALIASED) { OSD_Printf("OSD_RegisterFunction(): \"%s\" is already defined\n", name); return -1; } Bfree((char *)symb->help); symb->help = help; + symb->func = func; return 0; } @@ -1354,7 +1384,7 @@ static symbol_t *findsymbol(const char *name, symbol_t *startingat) if (!startingat) return NULL; for (; startingat; startingat=startingat->next) - if (!Bstrncasecmp(name, startingat->name, Bstrlen(name))) return startingat; + if (startingat->func != (void *)OSD_UNALIASED && !Bstrncasecmp(name, startingat->name, Bstrlen(name))) return startingat; return NULL; } diff --git a/polymer/eduke32/source/config.c b/polymer/eduke32/source/config.c index d037bd2f2..aadfe92d6 100644 --- a/polymer/eduke32/source/config.c +++ b/polymer/eduke32/source/config.c @@ -33,6 +33,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "duke3d.h" #include "scriplib.h" #include "osd.h" +#include "osdcmds.h" #include "baselayer.h" @@ -801,6 +802,10 @@ void CONFIG_WriteBinds(void) // save binds and aliases to disk if (symb->func == (void *)OSD_ALIAS) fprintf(fp,"alias %s \"%s\"\n", symb->name, symb->help); +/* for (i = 0; i < sizeof(cvar)/sizeof(cvarmappings); i++) + if (!(cvar[i].type&CVAR_NOSAVE)) + fprintf(fp,"%s \"%d\"\n",cvar[i].name,*(int*)cvar[i].var); + */ fclose(fp); } } diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index ff32af161..27f701ff9 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -645,31 +645,13 @@ static int osdcmd_exec(const osdfuncparm_t *parm) return OSDCMD_OK; } -enum cvartypes -{ - CVAR_INT, - CVAR_UNSIGNEDINT, - CVAR_BOOL, - CVAR_STRING -}; - -struct cvarmappings -{ - char *name; - char *helpstr; - void *var; - int type; // 0 = integer, 1 = unsigned integer, 2 = boolean, 3 = string, |128 = not in multiplayer, |256 = update multi - int extra; // for string, is the length - int min; - int max; -} -cvar[] = +cvarmappings cvar[] = { { "crosshair", "crosshair: enable/disable crosshair", (void*)&ud.crosshair, CVAR_INT, 0, 0, 3 }, - { "cl_autoaim", "cl_autoaim: enable/disable weapon autoaim", (void*)&ud.config.AutoAim, CVAR_INT|256, 0, 0, 2 }, + { "cl_autoaim", "cl_autoaim: enable/disable weapon autoaim", (void*)&ud.config.AutoAim, CVAR_INT|CVAR_MULTI, 0, 0, 2 }, { "cl_automsg", "cl_automsg: enable/disable automatically sending messages to all players", (void*)&ud.automsg, CVAR_BOOL, 0, 0, 1 }, - { "cl_autovote", "cl_autovote: enable/disable automatic voting", (void*)&ud.autovote, CVAR_INT|256, 0, 0, 2 }, + { "cl_autovote", "cl_autovote: enable/disable automatic voting", (void*)&ud.autovote, CVAR_INT|CVAR_MULTI, 0, 0, 2 }, { "cl_deathmessages", "cl_deathmessages: enable/disable multiplayer death messages", (void*)&ud.deathmsgs, CVAR_BOOL, 0, 0, 1 }, @@ -690,7 +672,7 @@ cvar[] = { "cl_viewbob", "cl_viewbob: enable/disable player head bobbing\n", (void*)&ud.viewbob, CVAR_BOOL, 0, 0, 1 }, { "cl_weaponsway", "cl_weaponsway: enable/disable player weapon swaying\n", (void*)&ud.weaponsway, CVAR_BOOL, 0, 0, 1 }, - { "cl_weaponswitch", "cl_weaponswitch: enable/disable auto weapon switching", (void*)&ud.weaponswitch, CVAR_INT|256, 0, 0, 3 }, + { "cl_weaponswitch", "cl_weaponswitch: enable/disable auto weapon switching", (void*)&ud.weaponswitch, CVAR_INT|CVAR_MULTI, 0, 0, 3 }, { "cl_angleinterpolation", "cl_angleinterpolation: enable/disable angle interpolation", (void*)&ud.angleinterpolation, CVAR_INT, 0, 0, 256 }, #if defined(POLYMOST) && defined(USE_OPENGL) { "r_anamorphic", "r_anamorphic: enable/disable widescreen mode", (void*)&glwidescreen, CVAR_BOOL, 0, 0, 1 }, @@ -724,11 +706,11 @@ static int osdcmd_cvar_set(const osdfuncparm_t *parm) int showval = (parm->numparms == 0); unsigned int i; - for (i = 0; i < sizeof(cvar)/sizeof(struct cvarmappings); i++) + for (i = 0; i < sizeof(cvar)/sizeof(cvarmappings); i++) { if (!Bstrcasecmp(parm->name, cvar[i].name)) { - if ((cvar[i].type & 0x80) && numplayers > 1) + if ((cvar[i].type & CVAR_NOMULTI) && numplayers > 1) { // sound the alarm OSD_Printf("Cvar \"%s\" locked in multiplayer.\n",cvar[i].name); @@ -778,7 +760,7 @@ static int osdcmd_cvar_set(const osdfuncparm_t *parm) default: break; } - if (cvar[i].type&256) + if (cvar[i].type&CVAR_MULTI) updateplayer(); } } diff --git a/polymer/eduke32/source/osdcmds.h b/polymer/eduke32/source/osdcmds.h index d0c77b7b7..c2d31672c 100644 --- a/polymer/eduke32/source/osdcmds.h +++ b/polymer/eduke32/source/osdcmds.h @@ -1,14 +1,38 @@ -#ifndef __osdcmds_h__ -#define __osdcmds_h__ - -struct osdcmd_cheatsinfo { - int cheatnum; // -1 = none, else = see cheats() - int volume,level; -}; - -extern struct osdcmd_cheatsinfo osdcmd_cheatsinfo_stat; - -int registerosdcommands(void); - -#endif // __osdcmds_h__ - +#ifndef __osdcmds_h__ +#define __osdcmds_h__ + +struct osdcmd_cheatsinfo { + int cheatnum; // -1 = none, else = see cheats() + int volume,level; +}; + +extern struct osdcmd_cheatsinfo osdcmd_cheatsinfo_stat; + +int registerosdcommands(void); + +enum cvartypes +{ + CVAR_INT, + CVAR_UNSIGNEDINT, + CVAR_BOOL, + CVAR_STRING, + CVAR_NOMULTI = 128, + CVAR_MULTI = 256, + CVAR_NOSAVE = 512 +}; + +typedef struct +{ + char *name; + char *helpstr; + void *var; + int type; // 0 = integer, 1 = unsigned integer, 2 = boolean, 3 = string, |128 = not in multiplayer, |256 = update multi + int extra; // for string, is the length + int min; + int max; +} cvarmappings; + +extern cvarmappings cvar[]; + +#endif // __osdcmds_h__ +