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