From e7f091cd9060cb275f8bef4f1dd6d46dbdde0784 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Mon, 26 Mar 2012 22:05:23 +0000 Subject: [PATCH] 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 --- polymer/eduke32/build/include/common.h | 17 +++++++++++++++++ polymer/eduke32/build/src/defs.c | 23 +---------------------- polymer/eduke32/build/src/engine.c | 2 -- polymer/eduke32/source/astub.c | 26 -------------------------- polymer/eduke32/source/common.c | 20 ++++++++++++++++++++ polymer/eduke32/source/game.c | 18 ------------------ polymer/eduke32/source/gamedef.h | 8 ++------ 7 files changed, 40 insertions(+), 74 deletions(-) diff --git a/polymer/eduke32/build/include/common.h b/polymer/eduke32/build/include/common.h index 36f62efad..3fa18d394 100644 --- a/polymer/eduke32/build/include/common.h +++ b/polymer/eduke32/build/include/common.h @@ -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 diff --git a/polymer/eduke32/build/src/defs.c b/polymer/eduke32/build/src/defs.c index 2a7a2a10d..2e6aa8541 100644 --- a/polymer/eduke32/build/src/defs.c +++ b/polymer/eduke32/build/src/defs.c @@ -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; diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index 8cb9155c4..b1da1d56e 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -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, diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 485d34b93..2b963c174 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -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=0; i--) + { + if (!Bstrcasecmp(tok, tl[i].text)) + return tl[i].tokenid; + } + return T_ERROR; +} diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index cb1d7b063..8de2d5cfd 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -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) { diff --git a/polymer/eduke32/source/gamedef.h b/polymer/eduke32/source/gamedef.h index daf1e119b..43685e369 100644 --- a/polymer/eduke32/source/gamedef.h +++ b/polymer/eduke32/source/gamedef.h @@ -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[];