mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-11 07:11:39 +00:00
added support for removing aliases
git-svn-id: https://svn.eduke32.com/eduke32@820 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
2b6f413f9c
commit
5d2b147658
5 changed files with 86 additions and 44 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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__
|
||||
|
||||
|
|
Loading…
Reference in a new issue