From d402e0941196131533b92b51243fda9268fa6069 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 2 Jun 2017 15:01:52 -0400 Subject: [PATCH] Header consolidation - main.h, misc.h, and share.h merge to advent.h. For a project this small size with a small type ontology, it's better C style to have one header where all the assumptions about types and structures are immediately visible. This is a first step towards turning all that global state into a handful of structures - probably just two, one saveable as a binary game state. --- Makefile | 14 +++++++------- actions1.c | 4 +--- actions2.c | 4 +--- misc.h => advent.h | 40 ++++++++++++++++++++++++++++++++++++++++ init.c | 4 +--- main.c | 3 +-- main.h | 16 ---------------- misc.c | 4 +--- score.c | 4 +--- share.h | 24 ------------------------ 10 files changed, 53 insertions(+), 64 deletions(-) rename misc.h => advent.h (66%) delete mode 100644 main.h delete mode 100644 share.h diff --git a/Makefile b/Makefile index c2f34d4..bdd19de 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ ifeq ($(UNAME_S),Linux) endif OBJS=main.o init.o actions1.o actions2.o score.o misc.o database.o -SOURCES=$(OBJS:.o=.c) COPYING NEWS README TODO adventure.text advent.text control misc.h main.h share.h funcs.h +SOURCES=$(OBJS:.o=.c) COPYING NEWS README TODO adventure.text advent.text control advent.h funcs.h .c.o: $(CC) $(CCFLAGS) -O $(DBX) -c $< @@ -17,17 +17,17 @@ SOURCES=$(OBJS:.o=.c) COPYING NEWS README TODO adventure.text advent.text contro advent: $(OBJS) database.o $(CC) $(CCFLAGS) -O $(DBX) -o advent $(OBJS) $(LIBS) -main.o: main.h misc.h funcs.h database.h +main.o: advent.h funcs.h database.h -init.o: misc.h main.h share.h funcs.h database.h +init.o: advent.h funcs.h database.h -actions1.o: misc.h main.h share.h funcs.h database.h +actions1.o: advent.h funcs.h database.h -actions2.o: misc.h main.h share.h funcs.h +actions2.o: advent.h funcs.h -score.o: misc.h main.h share.h database.h +score.o: advent.h database.h -misc.o: misc.h main.h database.h +misc.o: advent.h database.h database.o: database.h diff --git a/actions1.c b/actions1.c index 5ef0953..791e0c2 100644 --- a/actions1.c +++ b/actions1.c @@ -1,8 +1,6 @@ #include #include -#include "misc.h" -#include "main.h" -#include "share.h" +#include "advent.h" #include "funcs.h" #include "database.h" diff --git a/actions2.c b/actions2.c index 6b28895..f208a49 100644 --- a/actions2.c +++ b/actions2.c @@ -1,6 +1,4 @@ -#include "misc.h" -#include "main.h" -#include "share.h" +#include "advent.h" #include "funcs.h" /* Carry an object. Special cases for bird and cage (if bird in cage, can't diff --git a/misc.h b/advent.h similarity index 66% rename from misc.h rename to advent.h index e16c308..421c481 100644 --- a/misc.h +++ b/advent.h @@ -1,6 +1,21 @@ #include #include +#define LINESIZE 100 + +typedef struct lcg_state +{ + unsigned long a, c, m, x; +} lcg_state; + +extern long ABB[], ATLOC[], BLKLIN, DFLAG, DLOC[], FIXED[], HOLDNG, + LINK[], LNLENG, LNPOSN, + PARMS[], PLACE[]; +extern char rawbuf[LINESIZE], INLINE[LINESIZE+1], MAP1[], MAP2[]; +extern FILE *logfp; +extern bool oldstyle; +extern lcg_state lcgstate; + /* b is not needed for POSIX but harmless */ #define READ_MODE "rb" #define WRITE_MODE "wb" @@ -75,3 +90,28 @@ extern long fMOD(long,long); extern void set_seed(long); extern unsigned long get_next_lcg_value(void); extern long randrange(long); + +extern void score(long); +extern long ABBNUM, AMBER, ATTACK, AXE, BACK, BATTER, BEAR, + BIRD, BLOOD, BONUS, + BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, CHLOC, CHLOC2, + CLAM, CLOCK1, CLOCK2, CLOSED, CLOSNG, CLSHNT, + COINS, CONDS, DALTLC, DETAIL, + DKILL, DOOR, DPRSSN, DRAGON, DSEEN[], DTOTAL, DWARF, EGGS, + EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOBAR, FOOD, + GRATE, HINT, HINTED[], HINTLC[], + I, INVENT, IGO, IWEST, J, JADE, K, K2, KEYS, KK, + KNFLOC, KNIFE, KQ, L, LAMP, LIMIT, LL, + LMWARN, LOC, LOCK, LOOK, + MAGZIN, MAXDIE, MAXTRS, MESSAG, MIRROR, MXSCOR, + NEWLOC, NOVICE, NUGGET, NUL, NUMDIE, OBJ, + ODLOC[], OGRE, OIL, OLDLC2, OLDLOC, OLDOBJ, OYSTER, + PANIC, PEARL, PILLOW, PLANT, PLANT2, PROP[], PYRAM, + RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAVED, SAY, + SCORE, SECT, SETUP, SIGN, SNAKE, SPK, STEPS, STICK, + STREAM, TALLY, THRESH, THROW, TK[], TRIDNT, + TRNDEX, TRNLUZ, TROLL, TROLL2, + TURNS, URN, V1, V2, VASE, VEND, VERB, + VOLCAN, VRSION, WATER, WD1, WD1X, WD2, WD2X, + WZDARK, ZZWORD; + diff --git a/init.c b/init.c index 69901c1..c5486cf 100644 --- a/init.c +++ b/init.c @@ -3,9 +3,7 @@ #include #include -#include "misc.h" -#include "main.h" -#include "share.h" +#include "advent.h" #include "funcs.h" #include "database.h" diff --git a/main.c b/main.c index 400abd8..6c55127 100644 --- a/main.c +++ b/main.c @@ -9,9 +9,8 @@ #include #include #include -#include "main.h" +#include "advent.h" #include "database.h" -#include "misc.h" long ABB[186], ATLOC[186], BLKLIN = true, DFLAG, DLOC[7], FIXED[101], HOLDNG, diff --git a/main.h b/main.h deleted file mode 100644 index 259170a..0000000 --- a/main.h +++ /dev/null @@ -1,16 +0,0 @@ -#include - -#define LINESIZE 100 - -typedef struct lcg_state -{ - unsigned long a, c, m, x; -} lcg_state; - -extern long ABB[], ATLOC[], BLKLIN, DFLAG, DLOC[], FIXED[], HOLDNG, - LINK[], LNLENG, LNPOSN, - PARMS[], PLACE[]; -extern char rawbuf[LINESIZE], INLINE[LINESIZE+1], MAP1[], MAP2[]; -extern FILE *logfp; -extern bool oldstyle; -extern lcg_state lcgstate; diff --git a/misc.c b/misc.c index 3aca465..adbccdb 100644 --- a/misc.c +++ b/misc.c @@ -3,9 +3,7 @@ #include #include #include -#include "main.h" -#include "share.h" /* for SETUP */ -#include "misc.h" +#include "advent.h" #include "funcs.h" #include "database.h" diff --git a/score.c b/score.c index 4ef68ad..31994c2 100644 --- a/score.c +++ b/score.c @@ -1,7 +1,5 @@ #include -#include "misc.h" -#include "main.h" -#include "share.h" +#include "advent.h" #include "database.h" /* diff --git a/share.h b/share.h deleted file mode 100644 index 4fd867c..0000000 --- a/share.h +++ /dev/null @@ -1,24 +0,0 @@ -extern void score(long); -extern long ABBNUM, AMBER, ATTACK, AXE, BACK, BATTER, BEAR, - BIRD, BLOOD, BONUS, - BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, CHLOC, CHLOC2, - CLAM, CLOCK1, CLOCK2, CLOSED, CLOSNG, CLSHNT, - COINS, CONDS, DALTLC, DETAIL, - DKILL, DOOR, DPRSSN, DRAGON, DSEEN[], DTOTAL, DWARF, EGGS, - EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOBAR, FOOD, - GRATE, HINT, HINTED[], HINTLC[], - I, INVENT, IGO, IWEST, J, JADE, K, K2, KEYS, KK, - KNFLOC, KNIFE, KQ, L, LAMP, LIMIT, LL, - LMWARN, LOC, LOCK, LOOK, - MAGZIN, MAXDIE, MAXTRS, MESSAG, MIRROR, MXSCOR, - NEWLOC, NOVICE, NUGGET, NUL, NUMDIE, OBJ, - ODLOC[], OGRE, OIL, OLDLC2, OLDLOC, OLDOBJ, OYSTER, - PANIC, PEARL, PILLOW, PLANT, PLANT2, PROP[], PYRAM, - RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAVED, SAY, - SCORE, SECT, SETUP, SIGN, SNAKE, SPK, STEPS, STICK, - STREAM, TALLY, THRESH, THROW, TK[], TRIDNT, - TRNDEX, TRNLUZ, TROLL, TROLL2, - TURNS, URN, V1, V2, VASE, VEND, VERB, - VOLCAN, VRSION, WATER, WD1, WD1X, WD2, WD2X, - WZDARK, ZZWORD; - -- 2.31.1