Skip to content

Commit ef49c17

Browse files
hubertfhubertf
authored andcommitted
This patch fixes adventure(6) to use `extern' on declarations of
objects in its header file, and to add corresponding definitions to init.c accordingly. (See the C standard - relying on linker commons where there are multiple uninitialised declarations of an object in the program traditionally works on Unix, but is not standard C.) The patch also removes a bit-rotten code fragment under #ifdef OLDSTUFF. Patch submitted in PR 8105 by Joseph Myers <jsm28@cam.ac.uk>
1 parent c26f3e0 commit ef49c17

File tree

2 files changed

+100
-40
lines changed

2 files changed

+100
-40
lines changed

games/adventure/hdr.h

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: hdr.h,v 1.7 1999/07/16 01:38:20 hubertf Exp $ */
1+
/* $NetBSD: hdr.h,v 1.8 1999/07/28 23:23:39 hubertf Exp $ */
22

33
/*-
44
* Copyright (c) 1991, 1993
@@ -60,91 +60,87 @@
6060

6161
#include <signal.h>
6262

63-
int datfd; /* message file descriptor */
64-
volatile sig_atomic_t delhit;
65-
int yea;
63+
extern int datfd; /* message file descriptor */
64+
extern volatile sig_atomic_t delhit;
65+
extern int yea;
6666
extern char data_file[]; /* Virtual data file */
6767

6868
#define TAB 011
6969
#define LF 012
7070
#define FLUSHLINE do { int flushline_ch; while ((flushline_ch = getchar()) != EOF && flushline_ch != '\n'); } while (0)
7171
#define FLUSHLF while (next()!=LF)
7272

73-
int loc, newloc, oldloc, oldlc2, wzdark, gaveup, kq, k, k2;
74-
char *wd1, *wd2; /* the complete words */
75-
int verb, obj, spk;
73+
extern int loc, newloc, oldloc, oldlc2, wzdark, gaveup, kq, k, k2;
74+
extern char *wd1, *wd2; /* the complete words */
75+
extern int verb, obj, spk;
7676
extern int blklin;
77-
int saveday, savet, mxscor, latncy;
77+
extern int saveday, savet, mxscor, latncy;
7878

7979
#define SHORT 50 /* How short is a demo game? */
8080

8181
#define MAXSTR 20 /* max length of user's words */
8282

8383
#define HTSIZE 512 /* max number of vocab words */
84-
struct hashtab { /* hash table for vocabulary */
84+
extern struct hashtab { /* hash table for vocabulary */
8585
int val; /* word type &index (ktab) */
8686
char *atab; /* pointer to actual string */
8787
} voc[HTSIZE];
8888
#define SEED 1815622 /* "Encryption" seed */
8989

9090
struct text
91-
#ifdef OLDSTUFF
92-
{
93-
int seekadr; /* DATFILE must be < 2**16 */
94-
#endif /* OLDSTUFF */
9591
{
9692
char *seekadr;/* Msg start in virtual disk */
9793
int txtlen; /* length of msg starting here */
9894
};
9995

10096
#define RTXSIZ 205
101-
struct text rtext[RTXSIZ]; /* random text messages */
97+
extern struct text rtext[RTXSIZ]; /* random text messages */
10298

10399
#define MAGSIZ 35
104-
struct text mtext[MAGSIZ]; /* magic messages */
100+
extern struct text mtext[MAGSIZ]; /* magic messages */
105101

106-
int clsses;
102+
extern int clsses;
107103
#define CLSMAX 12
108-
struct text ctext[CLSMAX]; /* classes of adventurer */
109-
int cval[CLSMAX];
104+
extern struct text ctext[CLSMAX]; /* classes of adventurer */
105+
extern int cval[CLSMAX];
110106

111-
struct text ptext[101]; /* object descriptions */
107+
extern struct text ptext[101]; /* object descriptions */
112108

113109
#define LOCSIZ 141 /* number of locations */
114-
struct text ltext[LOCSIZ]; /* long loc description */
115-
struct text stext[LOCSIZ]; /* short loc descriptions */
110+
extern struct text ltext[LOCSIZ]; /* long loc description */
111+
extern struct text stext[LOCSIZ]; /* short loc descriptions */
116112

117-
struct travlist { /* direcs & conditions of travel */
113+
extern struct travlist { /* direcs & conditions of travel */
118114
struct travlist *next; /* ptr to next list entry */
119115
int conditions; /* m in writeup (newloc / 1000) */
120116
int tloc; /* n in writeup (newloc % 1000) */
121117
int tverb; /* the verb that takes you there */
122118
} *travel[LOCSIZ], *tkk; /* travel is closer to keys(...) */
123119

124-
int atloc[LOCSIZ];
120+
extern int atloc[LOCSIZ];
125121

126-
int plac[101]; /* initial object placement */
127-
int fixd[101], fixed[101]; /* location fixed? */
122+
extern int plac[101]; /* initial object placement */
123+
extern int fixd[101], fixed[101]; /* location fixed? */
128124

129-
int actspk[35]; /* rtext msg for verb <n> */
125+
extern int actspk[35]; /* rtext msg for verb <n> */
130126

131-
int cond[LOCSIZ]; /* various condition bits */
127+
extern int cond[LOCSIZ]; /* various condition bits */
132128

133129
extern int setbit[16]; /* bit defn masks 1,2,4,... */
134130

135-
int hntmax;
136-
int hints[20][5]; /* info on hints */
137-
int hinted[20], hintlc[20];
131+
extern int hntmax;
132+
extern int hints[20][5]; /* info on hints */
133+
extern int hinted[20], hintlc[20];
138134

139-
int place[101], prop[101], links[201];
140-
int abb[LOCSIZ];
135+
extern int place[101], prop[101], links[201];
136+
extern int abb[LOCSIZ];
141137

142-
int maxtrs, tally, tally2; /* treasure values */
138+
extern int maxtrs, tally, tally2; /* treasure values */
143139

144140
#define FALSE 0
145141
#define TRUE 1
146142

147-
int keys, lamp, grate, cage, rod, rod2, steps, /* mnemonics */
143+
extern int keys, lamp, grate, cage, rod, rod2, steps, /* mnemonics */
148144
bird, door, pillow, snake, fissur, tablet, clam, oyster,
149145
magzin, dwarf, knife, food, bottle, water, oil, plant, plant2,
150146
axe, mirror, dragon, chasm, troll, troll2, bear, messag,
@@ -153,15 +149,15 @@ struct text
153149
null, entrnc, dprssn, enter, stream, pour, say, lock, throw,
154150
find, invent;
155151

156-
int chloc, chloc2, dseen[7], dloc[7], /* dwarf stuff */
152+
extern int chloc, chloc2, dseen[7], dloc[7], /* dwarf stuff */
157153
odloc[7], dflag, daltlc;
158154

159-
int tk[21], stick, dtotal, attack;
160-
int turns, lmwarn, iwest, knfloc, detail, /* various flags and
155+
extern int tk[21], stick, dtotal, attack;
156+
extern int turns, lmwarn, iwest, knfloc, detail, /* various flags and
161157
* counters */
162158
abbnum, maxdie, numdie, holdng, dkill, foobar, bonus, clock1,
163159
clock2, saved, closng, panic, closed, scorng;
164160

165-
int demo, newloc, limit;
161+
extern int demo, newloc, limit;
166162

167163
#define DECR(a,b,c,d,e) decr(a+'+',b+'-',c+'#',d+'&',e+'%')

games/adventure/init.c

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: init.c,v 1.11 1999/02/10 12:38:54 hubertf Exp $ */
1+
/* $NetBSD: init.c,v 1.12 1999/07/28 23:23:39 hubertf Exp $ */
22

33
/*-
44
* Copyright (c) 1993
@@ -43,7 +43,7 @@
4343
#if 0
4444
static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 6/2/93";
4545
#else
46-
__RCSID("$NetBSD: init.c,v 1.11 1999/02/10 12:38:54 hubertf Exp $");
46+
__RCSID("$NetBSD: init.c,v 1.12 1999/07/28 23:23:39 hubertf Exp $");
4747
#endif
4848
#endif /* not lint */
4949

@@ -64,6 +64,70 @@ int blklin = TRUE;
6464
int setbit[16] = {1, 2, 4, 010, 020, 040, 0100, 0200, 0400, 01000, 02000, 04000,
6565
010000, 020000, 040000, 0100000};
6666

67+
int datfd; /* message file descriptor */
68+
volatile sig_atomic_t delhit;
69+
int yea;
70+
71+
int loc, newloc, oldloc, oldlc2, wzdark, gaveup, kq, k, k2;
72+
char *wd1, *wd2; /* the complete words */
73+
int verb, obj, spk;
74+
int saveday, savet, mxscor, latncy;
75+
76+
struct hashtab voc[HTSIZE];
77+
78+
struct text rtext[RTXSIZ]; /* random text messages */
79+
80+
struct text mtext[MAGSIZ]; /* magic messages */
81+
82+
int clsses;
83+
84+
struct text ctext[CLSMAX]; /* classes of adventurer */
85+
int cval[CLSMAX];
86+
87+
struct text ptext[101]; /* object descriptions */
88+
89+
struct text ltext[LOCSIZ]; /* long loc description */
90+
struct text stext[LOCSIZ]; /* short loc descriptions */
91+
92+
struct travlist *travel[LOCSIZ], *tkk; /* travel is closer to keys(...) */
93+
94+
int atloc[LOCSIZ];
95+
96+
int plac[101]; /* initial object placement */
97+
int fixd[101], fixed[101]; /* location fixed? */
98+
99+
int actspk[35]; /* rtext msg for verb <n> */
100+
101+
int cond[LOCSIZ]; /* various condition bits */
102+
103+
int hntmax;
104+
int hints[20][5]; /* info on hints */
105+
int hinted[20], hintlc[20];
106+
107+
int place[101], prop[101], links[201];
108+
int abb[LOCSIZ];
109+
110+
int maxtrs, tally, tally2; /* treasure values */
111+
112+
int keys, lamp, grate, cage, rod, rod2, steps, /* mnemonics */
113+
bird, door, pillow, snake, fissur, tablet, clam, oyster,
114+
magzin, dwarf, knife, food, bottle, water, oil, plant, plant2,
115+
axe, mirror, dragon, chasm, troll, troll2, bear, messag,
116+
vend, batter, nugget, coins, chest, eggs, tridnt, vase,
117+
emrald, pyram, pearl, rug, chain, spices, back, look, cave,
118+
null, entrnc, dprssn, enter, stream, pour, say, lock, throw,
119+
find, invent;
120+
121+
int chloc, chloc2, dseen[7], dloc[7], /* dwarf stuff */
122+
odloc[7], dflag, daltlc;
123+
124+
int tk[21], stick, dtotal, attack;
125+
int turns, lmwarn, iwest, knfloc, detail, /* various flags and
126+
* counters */
127+
abbnum, maxdie, numdie, holdng, dkill, foobar, bonus, clock1,
128+
clock2, saved, closng, panic, closed, scorng;
129+
130+
int demo, newloc, limit;
67131

68132
void
69133
init() /* everything for 1st time run */

0 commit comments

Comments
 (0)