Factor out various instances of getatoken() into common.c.

Alongside, these make into into the header:
 - the 'tokenlist' type (a typedef'd struct)
 - the T_EOF and T_ERROR enumeration values

git-svn-id: https://svn.eduke32.com/eduke32@2549 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-03-26 22:05:23 +00:00
parent b7495ef5bd
commit e7f091cd90
7 changed files with 40 additions and 74 deletions

View file

@ -7,6 +7,8 @@
#ifndef EDUKE32_COMMON_H_
#define EDUKE32_COMMON_H_
#include "scriptfile.h"
//// TYPES
struct strllist
@ -15,6 +17,19 @@ struct strllist
char *str;
};
typedef struct
{
const char *text;
int32_t tokenid;
}
tokenlist;
enum
{
T_EOF = -2,
T_ERROR = -1,
};
//// EXTERN DECLS
extern struct strllist *CommandPaths, *CommandGrps;
@ -24,4 +39,6 @@ extern struct strllist *CommandPaths, *CommandGrps;
void G_AddGroup(const char *buffer);
void G_AddPath(const char *buffer);
int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens);
#endif

View file

@ -13,11 +13,10 @@
#include "cache1d.h"
#include "kplib.h"
#include "quicklz.h"
#include "common.h" // tokenlist
enum scripttoken_t
{
T_EOF = -2,
T_ERROR = -1,
T_INCLUDE = 0,
T_DEFINE,
T_DEFINETEXTURE,
@ -86,26 +85,6 @@ enum scripttoken_t
T_ECHO,
};
typedef struct { const char *text; int32_t tokenid; } tokenlist;
static int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens)
{
char *tok;
int32_t i;
if (!sf) return T_ERROR;
tok = scriptfile_gettoken(sf);
if (!tok) return T_EOF;
for (i=ntokens-1; i>=0; i--)
{
if (!Bstrcasecmp(tok, tl[i].text))
return tl[i].tokenid;
}
return T_ERROR;
}
static int32_t lastmodelid = -1, lastvoxid = -1, modelskin = -1, lastmodelskin = -1, seenframe = 0;
int32_t nextvoxid = 0;

View file

@ -9633,8 +9633,6 @@ int32_t loadmaphack(const char *filename)
#ifdef USE_OPENGL
enum
{
T_EOF = -2,
T_ERROR = -1,
T_SPRITE = 0,
T_ANGOFF,
T_NOMODEL,

View file

@ -9476,8 +9476,6 @@ static void m32_osdsetfunctions(void)
enum
{
T_EOF = -2,
T_ERROR = -1,
T_INCLUDE = 0,
T_DEFINE = 1,
T_LOADGRP,
@ -9501,30 +9499,6 @@ enum
T_INCLUDEDEFAULT,
};
typedef struct
{
const char *text;
int32_t tokenid;
}
tokenlist;
static int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens)
{
char *tok;
int32_t i;
if (!sf) return T_ERROR;
tok = scriptfile_gettoken(sf);
if (!tok) return T_EOF;
for (i=0; i<ntokens; i++)
{
if (!Bstrcasecmp(tok, tl[i].text))
return tl[i].tokenid;
}
return T_ERROR;
}
static void DoAutoload(const char *fn)
{
static const char *extensions[3] = { "*.grp", "*.zip", "*.pk3" };

View file

@ -3,6 +3,7 @@
//
#include "compat.h"
#include "scriptfile.h"
#include "common.h"
@ -46,3 +47,22 @@ void G_AddPath(const char *buffer)
}
CommandPaths = s;
}
//////////
int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens)
{
char *tok;
int32_t i;
if (!sf) return T_ERROR;
tok = scriptfile_gettoken(sf);
if (!tok) return T_EOF;
for (i=ntokens-1; i>=0; i--)
{
if (!Bstrcasecmp(tok, tl[i].text))
return tl[i].tokenid;
}
return T_ERROR;
}

View file

@ -212,8 +212,6 @@ char *defaultconfile(void)
enum gametokens
{
T_EOF = -2,
T_ERROR = -1,
T_INCLUDE = 0,
T_INTERFACE = 0,
T_LOADGRP = 1,
@ -230,22 +228,6 @@ enum gametokens
T_ID
};
static int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens)
{
char *tok;
int32_t i;
if (!sf) return T_ERROR;
tok = scriptfile_gettoken(sf);
if (!tok) return T_EOF;
for (i=ntokens-1; i>=0; i--)
{
if (!Bstrcasecmp(tok, tl[i].text))
return tl[i].tokenid;
}
return T_ERROR;
}
inline void G_SetStatusBarScale(int32_t sc)
{

View file

@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef _gamedef_h_
#define _gamedef_h_
#include "common.h" // tokenlist
#define MAXGAMEEVENTS 128
#define LABEL_HASPARM2 1
#define LABEL_ISSTRING 2
@ -85,12 +87,6 @@ typedef struct
int32_t maxParm2;
} memberlabel_t;
typedef struct
{
const char *text;
int32_t tokenid;
} tokenlist;
extern const tokenlist EventNames[]; // MAXEVENTS
extern const memberlabel_t SectorLabels[];
extern const memberlabel_t WallLabels[];