More alias shit

git-svn-id: https://svn.eduke32.com/eduke32@818 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2008-06-30 00:18:59 +00:00
parent d3e54859c2
commit f6999157f7
3 changed files with 54 additions and 35 deletions

View file

@ -13,6 +13,19 @@ typedef struct {
const char *raw; const char *raw;
} osdfuncparm_t; } osdfuncparm_t;
typedef struct _symbol
{
const char *name;
struct _symbol *next;
const char *help;
int (*func)(const osdfuncparm_t *);
} symbol_t;
extern symbol_t *symbols;
#define OSD_ALIAS 0x1337
#define OSDCMD_OK 0 #define OSDCMD_OK 0
#define OSDCMD_SHOWHELP 1 #define OSDCMD_SHOWHELP 1

View file

@ -7,17 +7,7 @@
#include "compat.h" #include "compat.h"
#include "baselayer.h" #include "baselayer.h"
symbol_t *symbols = NULL;
typedef struct _symbol
{
const char *name;
struct _symbol *next;
const char *help;
int (*func)(const osdfuncparm_t *);
} symbol_t;
static symbol_t *symbols = NULL;
static symbol_t *addnewsymbol(const char *name); static symbol_t *addnewsymbol(const char *name);
static symbol_t *findsymbol(const char *name, symbol_t *startingat); static symbol_t *findsymbol(const char *name, symbol_t *startingat);
static symbol_t *findexactsymbol(const char *name); static symbol_t *findexactsymbol(const char *name);
@ -27,7 +17,6 @@ static symbol_t *findexactsymbol(const char *name);
static int _internal_osdfunc_listsymbols(const osdfuncparm_t *); static int _internal_osdfunc_listsymbols(const osdfuncparm_t *);
static int _internal_osdfunc_help(const osdfuncparm_t *); static int _internal_osdfunc_help(const osdfuncparm_t *);
static int _internal_osdfunc_alias(const osdfuncparm_t *); static int _internal_osdfunc_alias(const osdfuncparm_t *);
static int _internal_osdfunc_aliasfunc(const osdfuncparm_t *);
// static int _internal_osdfunc_dumpbuildinfo(const osdfuncparm_t *); // static int _internal_osdfunc_dumpbuildinfo(const osdfuncparm_t *);
// static int _internal_osdfunc_setrendermode(const osdfuncparm_t *); // static int _internal_osdfunc_setrendermode(const osdfuncparm_t *);
@ -223,27 +212,32 @@ static int _internal_osdfunc_alias(const osdfuncparm_t *parm)
{ {
OSD_Printf("Alias listing:\n"); OSD_Printf("Alias listing:\n");
for (i=symbols; i!=NULL; i=i->next) for (i=symbols; i!=NULL; i=i->next)
if (i->func == (void *)_internal_osdfunc_aliasfunc) if (i->func == (void *)OSD_ALIAS)
OSD_Printf(" %s\n", i->name); OSD_Printf(" %s\n", i->name);
return OSDCMD_OK; return OSDCMD_OK;
} }
for (i=symbols; i!=NULL; i=i->next)
{
if (parm->numparms < 2) if (parm->numparms < 2)
{ {
for (i=symbols; i!=NULL; i=i->next)
if (!Bstrcasecmp(parm->parms[0],i->name)) if (!Bstrcasecmp(parm->parms[0],i->name))
OSD_Printf("alias %s \"%s\"\n", i->name, i->help);
return OSDCMD_OK;
}
OSD_RegisterFunction(Bstrdup(parm->parms[0]),Bstrdup(parm->parms[1]),_internal_osdfunc_aliasfunc);
OSD_Printf("%s\n",parm->raw);
return OSDCMD_OK;
}
static int _internal_osdfunc_aliasfunc(const osdfuncparm_t *parm)
{ {
UNREFERENCED_PARAMETER(parm); if (i->func == (void *)OSD_ALIAS)
OSD_Printf("alias %s \"%s\"\n", i->name, i->help);
else OSD_Printf("%s is a function, not an alias\n",i->name);
}
return OSDCMD_OK;
}
if (i != NULL && !Bstrcasecmp(parm->parms[0],i->name) && i->func != (void *)OSD_ALIAS)
{
OSD_Printf("Cannot override function \"%s\" with alias\n",i->name);
return OSDCMD_OK;
}
}
OSD_RegisterFunction(Bstrdup(parm->parms[0]),Bstrdup(parm->parms[1]),(void *)OSD_ALIAS);
OSD_Printf("%s\n",parm->raw);
return OSDCMD_OK; return OSDCMD_OK;
} }
@ -1198,8 +1192,10 @@ int OSD_Dispatch(const char *cmd)
ofp.numparms = numparms; ofp.numparms = numparms;
ofp.parms = (const char **)parms; ofp.parms = (const char **)parms;
ofp.raw = cmd; ofp.raw = cmd;
if (symb->func == _internal_osdfunc_aliasfunc) if (symb->func == (void *)OSD_ALIAS)
OSD_Dispatch(symb->help); OSD_Dispatch(symb->help);
else
{
switch (symb->func(&ofp)) switch (symb->func(&ofp))
{ {
case OSDCMD_OK: case OSDCMD_OK:
@ -1208,6 +1204,7 @@ int OSD_Dispatch(const char *cmd)
OSD_Printf("%s\n", symb->help); OSD_Printf("%s\n", symb->help);
break; break;
} }
}
state = wtp; state = wtp;
} }
@ -1268,8 +1265,11 @@ int OSD_RegisterFunction(const char *name, const char *help, int (*func)(const o
symb = findexactsymbol(name); symb = findexactsymbol(name);
if (symb) // allow this now for reusing an alias name if (symb) // allow this now for reusing an alias name
{ {
// OSD_Printf("OSD_RegisterFunction(): \"%s\" is already defined\n", name); if (symb->func != (void *)OSD_ALIAS)
// return -1; {
OSD_Printf("OSD_RegisterFunction(): \"%s\" is already defined\n", name);
return -1;
}
// Bfree(symb->help); // Bfree(symb->help);
symb->help = help; symb->help = help;
symb->func = func; symb->func = func;

View file

@ -785,16 +785,22 @@ int32 CONFIG_ReadSetup(void)
=================== ===================
*/ */
void CONFIG_WriteBinds(void) void CONFIG_WriteBinds(void) // save binds and aliases to disk
{ {
int i; int i;
FILE *fp = fopen("binds.cfg", "wt"); FILE *fp = fopen("binds.cfg", "wt");
if (fp) if (fp)
{ {
symbol_t *symb;
fprintf(fp,"// this file automatically generated by EDuke32\n// do not modify if you lack common sense\n"); fprintf(fp,"// this file automatically generated by EDuke32\n// do not modify if you lack common sense\n");
for (i=0;i<MAXBOUNDKEYS;i++)if (*boundkeys[i].name) for (i=0;i<MAXBOUNDKEYS;i++)if (*boundkeys[i].name)
fprintf(fp,"bind %s \"%s\"\n",boundkeys[i].key,boundkeys[i].name); fprintf(fp,"bind %s%s \"%s\"\n",boundkeys[i].key,boundkeys[i].repeat?"":" norepeat",boundkeys[i].name);
for (symb=symbols; symb!=NULL; symb=symb->next)
if (symb->func == (void *)OSD_ALIAS)
fprintf(fp,"alias %s \"%s\"\n", symb->name, symb->help);
fclose(fp); fclose(fp);
} }
} }