From ee5dd2cf32f6674ad6baf952c7388ade80c0e03a Mon Sep 17 00:00:00 2001 From: helixhorned Date: Mon, 26 Mar 2012 22:03:20 +0000 Subject: [PATCH] Add common.[ch] which should be used for common non-engine types/functions/data. As inauguration, move G_AddGroup, G_AddPath and struct strllist there. The header is located in build/include, because in the future, code that resides closer to (but is not strictly part of) the engine might need to be factored into here. The source file, however, is in the source/ directory. git-svn-id: https://svn.eduke32.com/eduke32@2542 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/Makefile | 2 ++ polymer/eduke32/build/include/common.h | 27 ++++++++++++++ polymer/eduke32/source/astub.c | 49 +------------------------- polymer/eduke32/source/common.c | 48 +++++++++++++++++++++++++ polymer/eduke32/source/game.c | 49 +------------------------- 5 files changed, 79 insertions(+), 96 deletions(-) create mode 100644 polymer/eduke32/build/include/common.h create mode 100644 polymer/eduke32/source/common.c diff --git a/polymer/eduke32/Makefile b/polymer/eduke32/Makefile index 25ffe7335..53cb7b588 100644 --- a/polymer/eduke32/Makefile +++ b/polymer/eduke32/Makefile @@ -103,6 +103,7 @@ JMACTOBJ=$(OBJ)/file_lib.$o \ GAMEOBJS=$(OBJ)/game.$o \ $(OBJ)/actors.$o \ $(OBJ)/anim.$o \ + $(OBJ)/common.$o \ $(OBJ)/config.$o \ $(OBJ)/demo.$o \ $(OBJ)/gamedef.$o \ @@ -124,6 +125,7 @@ GAMEOBJS=$(OBJ)/game.$o \ $(JMACTOBJ) EDITOROBJS=$(OBJ)/astub.$o \ + $(OBJ)/common.$o \ $(OBJ)/m32def.$o \ $(OBJ)/m32exec.$o \ $(OBJ)/m32vars.$o \ diff --git a/polymer/eduke32/build/include/common.h b/polymer/eduke32/build/include/common.h new file mode 100644 index 000000000..36f62efad --- /dev/null +++ b/polymer/eduke32/build/include/common.h @@ -0,0 +1,27 @@ +// +// Definitions of common non-engine data structures/functions +// (and declarations of data appearing in both) +// for EDuke32 and Mapster32 +// + +#ifndef EDUKE32_COMMON_H_ +#define EDUKE32_COMMON_H_ + + +//// TYPES +struct strllist +{ + struct strllist *next; + char *str; +}; + + +//// EXTERN DECLS +extern struct strllist *CommandPaths, *CommandGrps; + + +//// FUNCTIONS +void G_AddGroup(const char *buffer); +void G_AddPath(const char *buffer); + +#endif diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 10aad0054..2ce86cc21 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -31,6 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "osdfuncs.h" #include "names.h" +#include "common.h" #include "mapster32.h" #include "keys.h" @@ -120,13 +121,6 @@ static int32_t lastupdate, mousecol, mouseadd = 1, bstatus; static int32_t usecwd = 0; #endif -static struct strllist -{ - struct strllist *next; - char *str; -} -*CommandPaths = NULL, *CommandGrps = NULL; - const char *scripthist[SCRIPTHISTSIZ]; int32_t scripthistend = 0; @@ -8384,47 +8378,6 @@ static void G_ShowParameterHelp(void) } -// CODEDUP game.c -static void G_AddPath(const char *buffer) -{ - struct strllist *s = Bcalloc(1,sizeof(struct strllist)); - s->str = Bstrdup(buffer); - - if (CommandPaths) - { - struct strllist *t; - for (t = CommandPaths; t->next; t=t->next) ; - t->next = s; - return; - } - - CommandPaths = s; -} - -// CODEDUP game.c -static void G_AddGroup(const char *buffer) -{ - char buf[BMAX_PATH]; - - struct strllist *s = Bcalloc(1,sizeof(struct strllist)); - - Bstrcpy(buf, buffer); - - if (Bstrchr(buf,'.') == 0) - Bstrcat(buf,".grp"); - - s->str = Bstrdup(buf); - - if (CommandGrps) - { - struct strllist *t; - for (t = CommandGrps; t->next; t=t->next) ; - t->next = s; - return; - } - CommandGrps = s; -} - #define COPYARG(i) \ Bmemcpy(&testplay_addparam[j], argv[i], lengths[i]); \ j += lengths[i]; \ diff --git a/polymer/eduke32/source/common.c b/polymer/eduke32/source/common.c new file mode 100644 index 000000000..d9cc3c8a5 --- /dev/null +++ b/polymer/eduke32/source/common.c @@ -0,0 +1,48 @@ +// +// Common non-engine code/data for EDuke32 and Mapster32 +// + +#include "compat.h" + +#include "common.h" + + +struct strllist *CommandPaths, *CommandGrps; + +void G_AddGroup(const char *buffer) +{ + char buf[BMAX_PATH]; + + struct strllist *s = Bcalloc(1,sizeof(struct strllist)); + + Bstrcpy(buf, buffer); + + if (Bstrchr(buf,'.') == 0) + Bstrcat(buf,".grp"); + + s->str = Bstrdup(buf); + + if (CommandGrps) + { + struct strllist *t; + for (t = CommandGrps; t->next; t=t->next) ; + t->next = s; + return; + } + CommandGrps = s; +} + +void G_AddPath(const char *buffer) +{ + struct strllist *s = Bcalloc(1,sizeof(struct strllist)); + s->str = Bstrdup(buffer); + + if (CommandPaths) + { + struct strllist *t; + for (t = CommandPaths; t->next; t=t->next) ; + t->next = s; + return; + } + CommandPaths = s; +} diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index c030f2301..24762a540 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -51,6 +51,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "savegame.h" #include "anim.h" #include "demo.h" +#include "common.h" #ifdef LUNATIC_ENABLE # include "lunatic.h" @@ -91,13 +92,6 @@ static char *CommandMap = NULL; static char *CommandName = NULL; int32_t g_forceWeaponChoice = 0; -static struct strllist -{ - struct strllist *next; - char *str; -} -*CommandPaths = NULL, *CommandGrps = NULL; - char boardfilename[BMAX_PATH] = {0}, currentboardfilename[BMAX_PATH] = {0}; static char g_rootDir[BMAX_PATH]; @@ -8571,47 +8565,6 @@ static int32_t loaddefinitions_game(const char *fn, int32_t preload) } -// CODEDUP astub.c -static void G_AddGroup(const char *buffer) -{ - char buf[BMAX_PATH]; - - struct strllist *s = Bcalloc(1,sizeof(struct strllist)); - - Bstrcpy(buf, buffer); - - if (Bstrchr(buf,'.') == 0) - Bstrcat(buf,".grp"); - - s->str = Bstrdup(buf); - - if (CommandGrps) - { - struct strllist *t; - for (t = CommandGrps; t->next; t=t->next) ; - t->next = s; - return; - } - CommandGrps = s; -} - -// CODEDUP astub.c -static void G_AddPath(const char *buffer) -{ - struct strllist *s = Bcalloc(1,sizeof(struct strllist)); - s->str = Bstrdup(buffer); - - if (CommandPaths) - { - struct strllist *t; - for (t = CommandPaths; t->next; t=t->next) ; - t->next = s; - return; - } - CommandPaths = s; -} - - static void G_CheckCommandLine(int32_t argc, const char **argv) { int16_t i = 1, j;