1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
$NetBSD: patch-ab,v 1.4 2014/09/23 22:21:43 jperkin Exp $
- use standard headers
- don't declare own strchr, getenv, time, tgetent
- use random, not lrand48
- work around broken definition of COLOR_PAIR on netbsd <= 3.x
- don't use implicit int
- use ctype.h correctly
- avoid nasal demons by passing a matching callback function to tputs
- fix an uninitialized variable bug caught by gcc
--- greed.c.orig 2002-07-30 22:03:43.000000000 +0000
+++ greed.c
@@ -47,38 +47,38 @@
static char *version = "Greed v" RELEASE;
-#ifdef MSDOS
-#define NOTBSD
-#endif
#include <ctype.h>
-#include <curses.h>
#include <signal.h>
-#ifndef MSDOS
-#include <pwd.h>
-#endif
-#ifdef NOTBSD
#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#ifdef MSDOS
+#include <sys/types.h>
+#include <io.h>
#else
-#include <sys/file.h>
+#include <pwd.h>
+#ifndef __sun
+#include <termcap.h>
+#endif
+#include <unistd.h>
#endif
+
+#include <curses.h>
#ifdef A_COLOR
#include <ctype.h>
#endif
-#ifdef MSDOS
-#include <sys/types.h>
-#include <io.h>
-#include <stdlib.h>
+#ifdef MSDOS
+#define NOTBSD
#endif
#ifdef NOTBSD
#ifndef crmode
#define crmode cbreak
#endif
-#ifndef MSDOS
-#define random lrand48 /* use high quality random routines */
-#define srandom srand48
-#else
+#ifdef MSDOS
#define random rand
#define srandom srand
#define ESC 27
@@ -105,22 +105,21 @@ struct score { /* changing stuff in t
int allmoves = 0, score = 1, grid[22][79], y, x, havebotmsg = 0;
char *cmdname;
WINDOW *helpwin = NULL;
-#ifndef MSDOS
-extern long random();
-#endif
-void topscores();
#ifdef MSDOS
char scorepath [_MAX_PATH];
#endif
+void topscores(int);
+int othermove(int, int);
+
/* botmsg() writes "msg" at the middle of the bottom line of the screen. *
* Boolean "backcur" specifies whether to put cursor back on the grid or *
* leave it on the bottom line (e.g. for questions). */
void botmsg(msg, backcur)
register char *msg;
-register backcur;
+register int backcur;
{
mvaddstr(23, 40, msg);
clrtoeol();
@@ -134,7 +133,7 @@ register backcur;
* current score) and quits; otherwise, simply returns to the game. */
void quit() {
- register ch;
+ register int ch;
#ifdef NOTBSD
void (*osig)() = signal(SIGINT, SIG_IGN); /* save old signal */
#else
@@ -195,16 +194,14 @@ void showscore() {
void showmoves();
-main(argc, argv)
+int main(argc, argv)
int argc;
char *argv[];
{
- register val = 1;
- extern long time();
+ register int val = 1;
int attribs[9];
#ifdef A_COLOR
char *colors;
- extern char *getenv(), *strchr();
#endif
cmdname = argv[0]; /* save the command name */
@@ -274,10 +271,10 @@ char *argv[];
if (strchr(cnames, *cp) != (char *) NULL)
if (*cp != ' ') {
init_pair(cp-colors+1,
- strchr(cnames, tolower(*cp))-cnames,
+ strchr(cnames, tolower((unsigned char)*cp))-cnames,
COLOR_BLACK);
- attribs[cp-colors]=COLOR_PAIR(cp-colors+1);
- if (isupper(*cp))
+ attribs[cp-colors]=COLOR_PAIR((cp-colors+1));
+ if (isupper((unsigned char)*cp))
attribs[cp-colors] |= A_BOLD;
}
if (*cp == ':')
@@ -292,7 +289,7 @@ char *argv[];
for (x=0; x < 79; x++) /* print numbers out */
#ifdef A_COLOR
if (has_colors()) {
- register newval = rnd(9);
+ register int newval = rnd(9);
attron(attribs[newval - 1]);
mvaddch(y, x, (grid[y][x] = newval) + '0');
@@ -331,11 +328,11 @@ char *argv[];
/* tunnel() does the main game work. Returns 1 if everything's okay, 0 if *
* user "died", and -1 if user specified and confirmed 'q' (fast quit). */
-tunnel(cmd, attribs)
+int tunnel(cmd, attribs)
register chtype cmd;
int * attribs;
{
- register dy, dx, distance;
+ register int dy, dx, distance;
void help();
switch (cmd) { /* process user command */
@@ -396,7 +393,7 @@ int * attribs;
grid[y+dy][x+dx] : 0;
{
- register j = y, i = x, d = distance;
+ register int j = y, i = x, d = distance;
do { /* process move for validity */
j += dy;
@@ -450,10 +447,10 @@ int * attribs;
* direction variables that tell othermove() they are already no good, and to *
* not process them. I don't know if this is efficient, but it works! */
-othermove(bady, badx)
-register bady, badx;
+int othermove(bady, badx)
+register int bady, badx;
{
- register dy = -1, dx;
+ register int dy = -1, dx;
for (; dy <= 1; dy++)
for (dx = -1; dx <= 1; dx++)
@@ -462,7 +459,7 @@ register bady, badx;
/* don't do 0,0 or bad coordinates */
continue;
else {
- register j=y, i=x, d=grid[y+dy][x+dx];
+ register int j=y, i=x, d=grid[y+dy][x+dx];
if (!d) continue;
do { /* "walk" the path, checking */
@@ -481,15 +478,15 @@ register bady, badx;
/* moves instead. "on" tells showmoves() whether to add or remove moves. */
void showmoves(on, attribs)
-register on;
+register int on;
int * attribs;
{
- register dy = -1, dx;
+ register int dy = -1, dx;
for (; dy <= 1; dy++) {
if (y+dy < 0 || y+dy >= 22) continue;
for (dx = -1; dx <= 1; dx++) {
- register j=y, i=x, d=grid[y+dy][x+dx];
+ register int j=y, i=x, d=grid[y+dy][x+dx];
if (!d) continue;
do {
@@ -499,7 +496,7 @@ int * attribs;
|| i >= 79 || !grid[j][i]) break;
} while (--d);
if (!d) {
- register j=y, i=x, d=grid[y+dy][x+dx];
+ register int j=y, i=x, d=grid[y+dy][x+dx];
/* The next section chooses inverse-video *
* or not, and then "walks" chosen valid *
@@ -529,8 +526,8 @@ int * attribs;
/* doputc() simply prints out a character to stdout, used by tputs() */
-char doputc(c)
-register char c;
+int doputc(c)
+register int c;
{
return(fputc(c, stdout));
}
@@ -542,18 +539,19 @@ register char c;
void topscores(newscore)
register int newscore;
{
- register fd, count = 1;
+ register int fd, count = 1;
static char termbuf[BUFSIZ];
char *tptr = (char *) malloc(16), *boldon, *boldoff;
struct score *toplist = (struct score *) malloc(FILESIZE);
register struct score *ptrtmp, *eof = &toplist[MAXSCORE], *new = NULL;
- extern char *getenv(), *tgetstr();
#ifndef MSDOS
void lockit();
#else
char user_name[100];
#endif
+ boldon = boldoff = NULL;
+
(void) signal(SIGINT, SIG_IGN); /* Catch all signals, so high */
#ifndef MSDOS
(void) signal(SIGQUIT, SIG_IGN); /* score file doesn't get */
@@ -665,9 +663,9 @@ register int newscore;
#ifndef MSDOS
void lockit(on)
-register on;
+register int on;
{
- register fd, x = 1;
+ register int fd, x = 1;
if (on) {
while ((fd = creat(LOCKPATH, 0)) == -1) {
|