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.
This commit is contained in:
Eric S. Raymond 2017-06-02 15:01:52 -04:00
parent 4209b82c5a
commit d402e09411
10 changed files with 53 additions and 64 deletions

View file

@ -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

View file

@ -1,8 +1,6 @@
#include <stdlib.h>
#include <stdbool.h>
#include "misc.h"
#include "main.h"
#include "share.h"
#include "advent.h"
#include "funcs.h"
#include "database.h"

View file

@ -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

View file

@ -1,6 +1,21 @@
#include <stdio.h>
#include <stdbool.h>
#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;

4
init.c
View file

@ -3,9 +3,7 @@
#include <stdio.h>
#include <stdbool.h>
#include "misc.h"
#include "main.h"
#include "share.h"
#include "advent.h"
#include "funcs.h"
#include "database.h"

3
main.c
View file

@ -9,9 +9,8 @@
#include <getopt.h>
#include <signal.h>
#include <time.h>
#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,

16
main.h
View file

@ -1,16 +0,0 @@
#include <stdbool.h>
#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;

4
misc.c
View file

@ -3,9 +3,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include "main.h"
#include "share.h" /* for SETUP */
#include "misc.h"
#include "advent.h"
#include "funcs.h"
#include "database.h"

View file

@ -1,7 +1,5 @@
#include <stdlib.h>
#include "misc.h"
#include "main.h"
#include "share.h"
#include "advent.h"
#include "database.h"
/*

24
share.h
View file

@ -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;