From: Jason S. Ninneman Date: Sun, 28 May 2017 22:42:05 +0000 (-0700) Subject: Factor out handling of variables populated from the database. X-Git-Tag: seed~29 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=refs%2Fmerge-requests%2F14%2Fhead;p=open-adventure.git Factor out handling of variables populated from the database. This reorganization is a first step toward handling database compilation separately. --- diff --git a/Makefile b/Makefile index 84477c8..bd57958 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,28 @@ # Makefile for the open-source release of adventure 2.5 LIBS=-lrt -OBJS=main.o init.o actions1.o actions2.o score.o misc.o +OBJS=main.o init.o actions1.o actions2.o score.o misc.o database.o SOURCES=$(OBJS:.o=.c) COPYING NEWS README TODO advent.text control .c.o: gcc -O $(DBX) -c $< advent: $(OBJS) - gcc -std=c99 -O $(DBX) -o advent $(OBJS) $(LIBS) + gcc -Wall -std=c99 -O $(DBX) -o advent $(OBJS) $(LIBS) -main.o: main.h misc.h funcs.h +main.o: main.h misc.h funcs.h database.h -init.o: misc.h main.h share.h funcs.h +init.o: misc.h main.h share.h funcs.h database.h -actions1.o: misc.h main.h share.h funcs.h +actions1.o: misc.h main.h share.h funcs.h database.h actions2.o: misc.h main.h share.h funcs.h -score.o: misc.h main.h share.h +score.o: misc.h main.h share.h database.h -misc.o: misc.h main.h +misc.o: misc.h main.h database.h + +database.o: database.h clean: rm -f *.o advent advent.html advent.6 adventure.data diff --git a/actions1.c b/actions1.c index 79c0ea7..0cf8e97 100644 --- a/actions1.c +++ b/actions1.c @@ -4,6 +4,7 @@ #include "main.h" #include "share.h" #include "funcs.h" +#include "database.h" /* This stuff was broken off as part of an effort to get the main program * to compile without running out of memory. We're called with a number diff --git a/database.c b/database.c new file mode 100644 index 0000000..cacd79d --- /dev/null +++ b/database.c @@ -0,0 +1,36 @@ +#include "database.h" + +const long RTXSIZ = 277; +const long CLSMAX = 12; +const long LOCSIZ = 185; +const long LINSIZ = 12500; +const long TRNSIZ = 5; +const long TABSIZ = 330; +const long VRBSIZ = 35; +long LINUSE; +long TRVS; +long CLSSES; +long TRNVLS; +long TABNDX; +long HNTMAX; +long PTEXT[101]; +long RTEXT[278]; +long CTEXT[13]; +long OBJSND[101]; +long OBJTXT[101]; +long STEXT[186]; +long LTEXT[186]; +long COND[186]; +long KEY[186]; +long LOCSND[186]; +long LINES[12500]; +long CVAL[13]; +long TTEXT[6]; +long TRNVAL[6]; +long TRAVEL[886]; +long KTAB[331]; +long ATAB[331]; +long PLAC[101]; +long FIXD[101]; +long ACTSPK[36]; +long HINTS[21][5]; diff --git a/database.h b/database.h new file mode 100644 index 0000000..c9b5167 --- /dev/null +++ b/database.h @@ -0,0 +1,34 @@ +extern const long RTXSIZ; +extern const long CLSMAX; +extern const long LOCSIZ; +extern const long LINSIZ; +extern const long TRNSIZ; +extern const long TABSIZ; +extern const long VRBSIZ; +extern long LINUSE; +extern long TRVS; +extern long CLSSES; +extern long TRNVLS; +extern long TABNDX; +extern long HNTMAX; +extern long PTEXT[101]; +extern long RTEXT[278]; +extern long CTEXT[13]; +extern long OBJSND[101]; +extern long OBJTXT[101]; +extern long STEXT[186]; +extern long LTEXT[186]; +extern long COND[186]; +extern long KEY[186]; +extern long LOCSND[186]; +extern long LINES[12500]; +extern long CVAL[13]; +extern long TTEXT[6]; +extern long TRNVAL[6]; +extern long TRAVEL[886]; +extern long KTAB[331]; +extern long ATAB[331]; +extern long PLAC[101]; +extern long FIXD[101]; +extern long ACTSPK[36]; +extern long HINTS[21][5]; diff --git a/funcs.h b/funcs.h index 5f7c01d..34f69cd 100644 --- a/funcs.h +++ b/funcs.h @@ -1,4 +1,5 @@ #include +#include "database.h" /* Statement functions * diff --git a/init.c b/init.c index ba49245..d33dd92 100644 --- a/init.c +++ b/init.c @@ -7,6 +7,7 @@ #include "main.h" #include "share.h" #include "funcs.h" +#include "database.h" /* * Initialisation @@ -175,7 +176,7 @@ static void quick_io(void); void initialise(void) { if (oldstyle) printf("Initialising...\n"); - if(!quick_init()){raw_init(); report(); quick_save();} + if(!quick_init()){raw_init(); report(); quick_save();} finish_init(); } diff --git a/main.c b/main.c index d84e4f2..a72d3b5 100644 --- a/main.c +++ b/main.c @@ -9,37 +9,37 @@ #include #include #include "main.h" - +#include "database.h" #include "misc.h" -long ABB[186], ATAB[331], ATLOC[186], BLKLIN = true, DFLAG, +long ABB[186], ATLOC[186], BLKLIN = true, DFLAG, DLOC[7], FIXED[101], HOLDNG, - KTAB[331], *LINES, LINK[201], LNLENG, LNPOSN, - PARMS[26], PLACE[101], PTEXT[101], RTEXT[278], - SETUP = 0, TABSIZ = 330; + LINK[201], LNLENG, LNPOSN, + PARMS[26], PLACE[101], + SETUP = 0; signed char rawbuf[LINESIZE], INLINE[LINESIZE+1], MAP1[129], MAP2[129]; -long ABBNUM, ACTSPK[36], AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BIRD, BLOOD, BONUS, +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, CLSMAX = 12, CLSSES, - COINS, COND[186], CONDS, CTEXT[13], CVAL[13], DALTLC, DETAIL, + CLAM, CLOCK1, CLOCK2, CLOSED, CLOSNG, CLSHNT, + COINS, CONDS, DALTLC, DETAIL, DKILL, DOOR, DPRSSN, DRAGON, DSEEN[7], DTOTAL, DWARF, EGGS, - EMRALD, ENTER, ENTRNC, FIND, FISSUR, FIXD[101], FOOBAR, FOOD, - GRATE, HINT, HINTED[21], HINTLC[21], HINTS[21][5], HNTMAX, - HNTSIZ = 20, I, INVENT, IGO, IWEST, J, JADE, K, K2, KEY[186], KEYS, KK, - KNFLOC, KNIFE, KQ, L, LAMP, LIMIT, LINSIZ = 12500, LINUSE, LL, - LMWARN, LOC, LOCK, LOCSIZ = 185, LOCSND[186], LOOK, LTEXT[186], + EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOBAR, FOOD, + GRATE, HINT, HINTED[21], HINTLC[21], + HNTSIZ = 20, I, INVENT, IGO, IWEST, J, JADE, K, K2, KEYS, KK, + KNFLOC, KNIFE, KQ, L, LAMP, LIMIT, LL, + LMWARN, LOC, LOCK, LOOK, MAGZIN, MAXDIE, MAXTRS, MESH = 123456789, MESSAG, MIRROR, MXSCOR, - NEWLOC, NOVICE, NUGGET, NUL, NUMDIE, OBJ, OBJSND[101], - OBJTXT[101], ODLOC[7], OGRE, OIL, OLDLC2, OLDLOC, OLDOBJ, OYSTER, - PANIC, PEARL, PILLOW, PLAC[101], PLANT, PLANT2, PROP[101], PYRAM, - RESER, ROD, ROD2, RTXSIZ = 277, RUBY, RUG, SAPPH, SAVED, SAY, - SCORE, SECT, SIGN, SNAKE, SPK, STEPS, STEXT[186], STICK, - STREAM, TABNDX, TALLY, THRESH, THROW, TK[21], TRAVEL[886], TRIDNT, - TRNDEX, TRNLUZ, TRNSIZ = 5, TRNVAL[6], TRNVLS, TROLL, TROLL2, TRVS, - TRVSIZ = 885, TTEXT[6], TURNS, URN, V1, V2, VASE, VEND, VERB, - VOLCAN, VRBSIZ = 35, VRSION = 25, WATER, WD1, WD1X, WD2, WD2X, + NEWLOC, NOVICE, NUGGET, NUL, NUMDIE, OBJ, + ODLOC[7], OGRE, OIL, OLDLC2, OLDLOC, OLDOBJ, OYSTER, + PANIC, PEARL, PILLOW, PLANT, PLANT2, PROP[101], PYRAM, + RESER, ROD, ROD2, RUBY, RUG, SAPPH, SAVED, SAY, + SCORE, SECT, SIGN, SNAKE, SPK, STEPS, STICK, + STREAM, TALLY, THRESH, THROW, TK[21], TRIDNT, + TRNDEX, TRNLUZ, TROLL, TROLL2, + TRVSIZ = 885, TURNS, URN, V1, V2, VASE, VEND, VERB, + VOLCAN, VRSION = 25, WATER, WD1, WD1X, WD2, WD2X, WZDARK = false, ZZWORD; FILE *logfp; bool oldstyle = false; @@ -114,12 +114,6 @@ int main(int argc, char *argv[]) { /* Read the database if we have not yet done so */ - LINES = (long *)calloc(LINSIZ+1,sizeof(long)); - if(!LINES){ - printf("Not enough memory!\n"); - exit(1); - } - MAP2[1] = 0; if(!SETUP)initialise(); if(SETUP > 0) goto L1; diff --git a/main.h b/main.h index 184acee..2b33735 100644 --- a/main.h +++ b/main.h @@ -7,9 +7,9 @@ typedef struct lcg_state unsigned long a, c, m, x; } lcg_state; -extern long ABB[], ATAB[], ATLOC[], BLKLIN, DFLAG, DLOC[], FIXED[], HOLDNG, - KTAB[], *LINES, LINK[], LNLENG, LNPOSN, - PARMS[], PLACE[], PTEXT[], RTEXT[], TABSIZ; +extern long ABB[], ATLOC[], BLKLIN, DFLAG, DLOC[], FIXED[], HOLDNG, + LINK[], LNLENG, LNPOSN, + PARMS[], PLACE[]; extern signed char rawbuf[LINESIZE], INLINE[LINESIZE+1], MAP1[], MAP2[]; extern FILE *logfp; extern bool oldstyle; diff --git a/misc.c b/misc.c index 3fded19..111848e 100644 --- a/misc.c +++ b/misc.c @@ -6,6 +6,7 @@ #include "share.h" /* for SETUP */ #include "misc.h" #include "funcs.h" +#include "database.h" /* hack to ignore GCC Unused Result */ #define IGNORE(r) do{if(r){}}while(0) diff --git a/score.c b/score.c index 162cc5d..4ef68ad 100644 --- a/score.c +++ b/score.c @@ -2,6 +2,7 @@ #include "misc.h" #include "main.h" #include "share.h" +#include "database.h" /* * scoring and wrap-up diff --git a/share.h b/share.h index ff4252b..59ef9bb 100644 --- a/share.h +++ b/share.h @@ -1,24 +1,24 @@ extern void score(long); -extern long ABBNUM, ACTSPK[], AMBER, ATTACK, AXE, BACK, BATTER, BEAR, +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, CLSMAX, CLSSES, - COINS, COND[], CONDS, CTEXT[], CVAL[], DALTLC, DETAIL, + CLAM, CLOCK1, CLOCK2, CLOSED, CLOSNG, CLSHNT, + COINS, CONDS, DALTLC, DETAIL, DKILL, DOOR, DPRSSN, DRAGON, DSEEN[], DTOTAL, DWARF, EGGS, - EMRALD, ENTER, ENTRNC, FIND, FISSUR, FIXD[], FOOBAR, FOOD, - GRATE, HINT, HINTED[], HINTLC[], HINTS[][5], HNTMAX, - HNTSIZ, I, INVENT, IGO, IWEST, J, JADE, K, K2, KEY[], KEYS, KK, - KNFLOC, KNIFE, KQ, L, LAMP, LIMIT, LINSIZ, LINUSE, LL, - LMWARN, LOC, LOCK, LOCSIZ, LOCSND[], LOOK, LTEXT[], + EMRALD, ENTER, ENTRNC, FIND, FISSUR, FOOBAR, FOOD, + GRATE, HINT, HINTED[], HINTLC[], + HNTSIZ, I, INVENT, IGO, IWEST, J, JADE, K, K2, KEYS, KK, + KNFLOC, KNIFE, KQ, L, LAMP, LIMIT, LL, + LMWARN, LOC, LOCK, LOOK, MAGZIN, MAXDIE, MAXTRS, MESH, MESSAG, MIRROR, MXSCOR, - NEWLOC, NOVICE, NUGGET, NUL, NUMDIE, OBJ, OBJSND[], - OBJTXT[], ODLOC[], OGRE, OIL, OLDLC2, OLDLOC, OLDOBJ, OYSTER, - PANIC, PEARL, PILLOW, PLAC[], PLANT, PLANT2, PROP[], PYRAM, - RESER, ROD, ROD2, RTXSIZ, RUBY, RUG, SAPPH, SAVED, SAY, - SCORE, SECT, SETUP, SIGN, SNAKE, SPK, STEPS, STEXT[], STICK, - STREAM, TABNDX, TALLY, THRESH, THROW, TK[], TRAVEL[], TRIDNT, - TRNDEX, TRNLUZ, TRNSIZ, TRNVAL[], TRNVLS, TROLL, TROLL2, TRVS, - TRVSIZ, TTEXT[], TURNS, URN, V1, V2, VASE, VEND, VERB, - VOLCAN, VRBSIZ, VRSION, WATER, WD1, WD1X, WD2, WD2X, + 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, + TRVSIZ, TURNS, URN, V1, V2, VASE, VEND, VERB, + VOLCAN, VRSION, WATER, WD1, WD1X, WD2, WD2X, WZDARK, ZZWORD;