"abbreviation" has two Bs.diff -r1.15 -r1.16 src/games/trek/getpar.c
(dholland)
--- src/games/trek/getpar.c 2009/05/24 23:20:22 1.15
+++ src/games/trek/getpar.c 2009/05/25 00:39:45 1.16
@@ -1,302 +1,302 @@ | @@ -1,302 +1,302 @@ | |||
1 | /* $NetBSD: getpar.c,v 1.15 2009/05/24 23:20:22 dholland Exp $ */ | 1 | /* $NetBSD: getpar.c,v 1.16 2009/05/25 00:39:45 dholland Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1980, 1993 | 4 | * Copyright (c) 1980, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3. Neither the name of the University nor the names of its contributors | 15 | * 3. Neither the name of the University nor the names of its contributors | |
16 | * may be used to endorse or promote products derived from this software | 16 | * may be used to endorse or promote products derived from this software | |
17 | * without specific prior written permission. | 17 | * without specific prior written permission. | |
18 | * | 18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | #ifndef lint | 33 | #ifndef lint | |
34 | #if 0 | 34 | #if 0 | |
35 | static char sccsid[] = "@(#)getpar.c 8.1 (Berkeley) 5/31/93"; | 35 | static char sccsid[] = "@(#)getpar.c 8.1 (Berkeley) 5/31/93"; | |
36 | #else | 36 | #else | |
37 | __RCSID("$NetBSD: getpar.c,v 1.15 2009/05/24 23:20:22 dholland Exp $"); | 37 | __RCSID("$NetBSD: getpar.c,v 1.16 2009/05/25 00:39:45 dholland Exp $"); | |
38 | #endif | 38 | #endif | |
39 | #endif /* not lint */ | 39 | #endif /* not lint */ | |
40 | 40 | |||
41 | #include <stdio.h> | 41 | #include <stdio.h> | |
42 | #include <stdlib.h> | 42 | #include <stdlib.h> | |
43 | #include <string.h> | 43 | #include <string.h> | |
44 | #include "getpar.h" | 44 | #include "getpar.h" | |
45 | #include "trek.h" | 45 | #include "trek.h" | |
46 | 46 | |||
47 | static int testterm(void); | 47 | static int testterm(void); | |
48 | 48 | |||
49 | /** | 49 | /** | |
50 | ** get integer parameter | 50 | ** get integer parameter | |
51 | **/ | 51 | **/ | |
52 | 52 | |||
53 | int | 53 | int | |
54 | getintpar(const char *s) | 54 | getintpar(const char *s) | |
55 | { | 55 | { | |
56 | int i; | 56 | int i; | |
57 | int n; | 57 | int n; | |
58 | 58 | |||
59 | while (1) { | 59 | while (1) { | |
60 | if (testnl() && s) | 60 | if (testnl() && s) | |
61 | printf("%s: ", s); | 61 | printf("%s: ", s); | |
62 | i = scanf("%d", &n); | 62 | i = scanf("%d", &n); | |
63 | if (i < 0) | 63 | if (i < 0) | |
64 | exit(1); | 64 | exit(1); | |
65 | if (i > 0 && testterm()) | 65 | if (i > 0 && testterm()) | |
66 | return (n); | 66 | return (n); | |
67 | printf("invalid input; please enter an integer\n"); | 67 | printf("invalid input; please enter an integer\n"); | |
68 | skiptonl(0); | 68 | skiptonl(0); | |
69 | } | 69 | } | |
70 | } | 70 | } | |
71 | 71 | |||
72 | /** | 72 | /** | |
73 | ** get floating parameter | 73 | ** get floating parameter | |
74 | **/ | 74 | **/ | |
75 | 75 | |||
76 | double | 76 | double | |
77 | getfltpar(const char *s) | 77 | getfltpar(const char *s) | |
78 | { | 78 | { | |
79 | int i; | 79 | int i; | |
80 | double d; | 80 | double d; | |
81 | 81 | |||
82 | while (1) { | 82 | while (1) { | |
83 | if (testnl() && s) | 83 | if (testnl() && s) | |
84 | printf("%s: ", s); | 84 | printf("%s: ", s); | |
85 | i = scanf("%lf", &d); | 85 | i = scanf("%lf", &d); | |
86 | if (i < 0) | 86 | if (i < 0) | |
87 | exit(1); | 87 | exit(1); | |
88 | if (i > 0 && testterm()) | 88 | if (i > 0 && testterm()) | |
89 | return (d); | 89 | return (d); | |
90 | printf("invalid input; please enter a double\n"); | 90 | printf("invalid input; please enter a double\n"); | |
91 | skiptonl(0); | 91 | skiptonl(0); | |
92 | } | 92 | } | |
93 | } | 93 | } | |
94 | 94 | |||
95 | /** | 95 | /** | |
96 | ** get yes/no parameter | 96 | ** get yes/no parameter | |
97 | **/ | 97 | **/ | |
98 | 98 | |||
99 | const struct cvntab Yntab[] = { | 99 | const struct cvntab Yntab[] = { | |
100 | { "y", "es", (cmdfun)1, 1 }, | 100 | { "y", "es", (cmdfun)1, 1 }, | |
101 | { "n", "o", (cmdfun)0, 0 }, | 101 | { "n", "o", (cmdfun)0, 0 }, | |
102 | { NULL, NULL, NULL, 0 } | 102 | { NULL, NULL, NULL, 0 } | |
103 | }; | 103 | }; | |
104 | 104 | |||
105 | int | 105 | int | |
106 | getynpar(const char *s) | 106 | getynpar(const char *s) | |
107 | { | 107 | { | |
108 | const struct cvntab *r; | 108 | const struct cvntab *r; | |
109 | 109 | |||
110 | r = getcodpar(s, Yntab); | 110 | r = getcodpar(s, Yntab); | |
111 | return r->value2; | 111 | return r->value2; | |
112 | } | 112 | } | |
113 | 113 | |||
114 | 114 | |||
115 | /** | 115 | /** | |
116 | ** get coded parameter | 116 | ** get coded parameter | |
117 | **/ | 117 | **/ | |
118 | 118 | |||
119 | const struct cvntab * | 119 | const struct cvntab * | |
120 | getcodpar(const char *s, const struct cvntab tab[]) | 120 | getcodpar(const char *s, const struct cvntab tab[]) | |
121 | { | 121 | { | |
122 | char input[100]; | 122 | char input[100]; | |
123 | const struct cvntab *r; | 123 | const struct cvntab *r; | |
124 | int flag; | 124 | int flag; | |
125 | const char *p, *q; | 125 | const char *p, *q; | |
126 | int c; | 126 | int c; | |
127 | int f; | 127 | int f; | |
128 | 128 | |||
129 | flag = 0; | 129 | flag = 0; | |
130 | while (1) { | 130 | while (1) { | |
131 | flag |= (f = testnl()); | 131 | flag |= (f = testnl()); | |
132 | if (flag) | 132 | if (flag) | |
133 | printf("%s: ", s); | 133 | printf("%s: ", s); | |
134 | if (f) { | 134 | if (f) { | |
135 | /* throw out the newline */ | 135 | /* throw out the newline */ | |
136 | getchar(); | 136 | getchar(); | |
137 | } | 137 | } | |
138 | scanf("%*[ \t;]"); | 138 | scanf("%*[ \t;]"); | |
139 | if ((c = scanf("%99[^ \t;\n]", input)) < 0) | 139 | if ((c = scanf("%99[^ \t;\n]", input)) < 0) | |
140 | exit(1); | 140 | exit(1); | |
141 | if (c == 0) | 141 | if (c == 0) | |
142 | continue; | 142 | continue; | |
143 | flag = 1; | 143 | flag = 1; | |
144 | 144 | |||
145 | /* if command list, print four per line */ | 145 | /* if command list, print four per line */ | |
146 | if (input[0] == '?' && input[1] == 0) { | 146 | if (input[0] == '?' && input[1] == 0) { | |
147 | c = 4; | 147 | c = 4; | |
148 | for (r = tab; r->abrev; r++) { | 148 | for (r = tab; r->abbrev; r++) { | |
149 | strcpy(input, r->abrev); | 149 | strcpy(input, r->abbrev); | |
150 | strcat(input, r->full); | 150 | strcat(input, r->full); | |
151 | printf("%14.14s", input); | 151 | printf("%14.14s", input); | |
152 | if (--c > 0) | 152 | if (--c > 0) | |
153 | continue; | 153 | continue; | |
154 | c = 4; | 154 | c = 4; | |
155 | printf("\n"); | 155 | printf("\n"); | |
156 | } | 156 | } | |
157 | if (c != 4) | 157 | if (c != 4) | |
158 | printf("\n"); | 158 | printf("\n"); | |
159 | continue; | 159 | continue; | |
160 | } | 160 | } | |
161 | 161 | |||
162 | /* search for in table */ | 162 | /* search for in table */ | |
163 | for (r = tab; r->abrev; r++) { | 163 | for (r = tab; r->abbrev; r++) { | |
164 | p = input; | 164 | p = input; | |
165 | for (q = r->abrev; *q; q++) | 165 | for (q = r->abbrev; *q; q++) | |
166 | if (*p++ != *q) | 166 | if (*p++ != *q) | |
167 | break; | 167 | break; | |
168 | if (!*q) { | 168 | if (!*q) { | |
169 | for (q = r->full; *p && *q; q++, p++) | 169 | for (q = r->full; *p && *q; q++, p++) | |
170 | if (*p != *q) | 170 | if (*p != *q) | |
171 | break; | 171 | break; | |
172 | if (!*p || !*q) | 172 | if (!*p || !*q) | |
173 | break; | 173 | break; | |
174 | } | 174 | } | |
175 | } | 175 | } | |
176 | 176 | |||
177 | /* check for not found */ | 177 | /* check for not found */ | |
178 | if (!r->abrev) { | 178 | if (!r->abbrev) { | |
179 | printf("invalid input; ? for valid inputs\n"); | 179 | printf("invalid input; ? for valid inputs\n"); | |
180 | skiptonl(0); | 180 | skiptonl(0); | |
181 | } else | 181 | } else | |
182 | return (r); | 182 | return (r); | |
183 | } | 183 | } | |
184 | } | 184 | } | |
185 | 185 | |||
186 | 186 | |||
187 | /** | 187 | /** | |
188 | ** get string parameter | 188 | ** get string parameter | |
189 | **/ | 189 | **/ | |
190 | 190 | |||
191 | void | 191 | void | |
192 | getstrpar(const char *s, char *r, int l, const char *t) | 192 | getstrpar(const char *s, char *r, int l, const char *t) | |
193 | { | 193 | { | |
194 | int i; | 194 | int i; | |
195 | char format[20]; | 195 | char format[20]; | |
196 | int f; | 196 | int f; | |
197 | 197 | |||
198 | if (t == 0) | 198 | if (t == 0) | |
199 | t = " \t\n;"; | 199 | t = " \t\n;"; | |
200 | (void)sprintf(format, "%%%d[^%s]", l, t); | 200 | (void)sprintf(format, "%%%d[^%s]", l, t); | |
201 | while (1) { | 201 | while (1) { | |
202 | if ((f = testnl()) && s) | 202 | if ((f = testnl()) && s) | |
203 | printf("%s: ", s); | 203 | printf("%s: ", s); | |
204 | if (f) | 204 | if (f) | |
205 | getchar(); | 205 | getchar(); | |
206 | scanf("%*[\t ;]"); | 206 | scanf("%*[\t ;]"); | |
207 | i = scanf(format, r); | 207 | i = scanf(format, r); | |
208 | if (i < 0) | 208 | if (i < 0) | |
209 | exit(1); | 209 | exit(1); | |
210 | if (i != 0) | 210 | if (i != 0) | |
211 | return; | 211 | return; | |
212 | } | 212 | } | |
213 | } | 213 | } | |
214 | 214 | |||
215 | 215 | |||
216 | /** | 216 | /** | |
217 | ** test if newline is next valid character | 217 | ** test if newline is next valid character | |
218 | **/ | 218 | **/ | |
219 | 219 | |||
220 | int | 220 | int | |
221 | testnl(void) | 221 | testnl(void) | |
222 | { | 222 | { | |
223 | int c; | 223 | int c; | |
224 | 224 | |||
225 | while ((c = getchar()) != '\n') { | 225 | while ((c = getchar()) != '\n') { | |
226 | if (c == EOF) { | 226 | if (c == EOF) { | |
227 | exit(1); | 227 | exit(1); | |
228 | } | 228 | } | |
229 | if ((c >= '0' && c <= '9') || c == '.' || c == '!' || | 229 | if ((c >= '0' && c <= '9') || c == '.' || c == '!' || | |
230 | (c >= 'A' && c <= 'Z') || | 230 | (c >= 'A' && c <= 'Z') || | |
231 | (c >= 'a' && c <= 'z') || c == '-') { | 231 | (c >= 'a' && c <= 'z') || c == '-') { | |
232 | ungetc(c, stdin); | 232 | ungetc(c, stdin); | |
233 | return(0); | 233 | return(0); | |
234 | } | 234 | } | |
235 | } | 235 | } | |
236 | ungetc(c, stdin); | 236 | ungetc(c, stdin); | |
237 | return (1); | 237 | return (1); | |
238 | } | 238 | } | |
239 | 239 | |||
240 | 240 | |||
241 | /** | 241 | /** | |
242 | ** scan for newline | 242 | ** scan for newline | |
243 | **/ | 243 | **/ | |
244 | 244 | |||
245 | void | 245 | void | |
246 | skiptonl(int c) | 246 | skiptonl(int c) | |
247 | { | 247 | { | |
248 | while (c != '\n') { | 248 | while (c != '\n') { | |
249 | c = getchar(); | 249 | c = getchar(); | |
250 | if (c == EOF) { | 250 | if (c == EOF) { | |
251 | exit(1); | 251 | exit(1); | |
252 | } | 252 | } | |
253 | } | 253 | } | |
254 | ungetc('\n', stdin); | 254 | ungetc('\n', stdin); | |
255 | return; | 255 | return; | |
256 | } | 256 | } | |
257 | 257 | |||
258 | 258 | |||
259 | /** | 259 | /** | |
260 | ** test for valid terminator | 260 | ** test for valid terminator | |
261 | **/ | 261 | **/ | |
262 | 262 | |||
263 | static int | 263 | static int | |
264 | testterm(void) | 264 | testterm(void) | |
265 | { | 265 | { | |
266 | int c; | 266 | int c; | |
267 | 267 | |||
268 | c = getchar(); | 268 | c = getchar(); | |
269 | if (c == EOF) { | 269 | if (c == EOF) { | |
270 | exit(1); | 270 | exit(1); | |
271 | } | 271 | } | |
272 | if (c == '.') | 272 | if (c == '.') | |
273 | return (0); | 273 | return (0); | |
274 | if (c == '\n' || c == ';') | 274 | if (c == '\n' || c == ';') | |
275 | ungetc(c, stdin); | 275 | ungetc(c, stdin); | |
276 | return (1); | 276 | return (1); | |
277 | } | 277 | } | |
278 | 278 | |||
279 | 279 | |||
280 | /* | 280 | /* | |
281 | ** TEST FOR SPECIFIED DELIMITER | 281 | ** TEST FOR SPECIFIED DELIMITER | |
282 | ** | 282 | ** | |
283 | ** The standard input is scanned for the parameter. If found, | 283 | ** The standard input is scanned for the parameter. If found, | |
284 | ** it is thrown away and non-zero is returned. If not found, | 284 | ** it is thrown away and non-zero is returned. If not found, | |
285 | ** zero is returned. | 285 | ** zero is returned. | |
286 | */ | 286 | */ | |
287 | 287 | |||
288 | int | 288 | int | |
289 | readdelim(int d) | 289 | readdelim(int d) | |
290 | { | 290 | { | |
291 | int c; | 291 | int c; | |
292 | 292 | |||
293 | while ((c = getchar()) != EOF) { | 293 | while ((c = getchar()) != EOF) { | |
294 | if (c == d) | 294 | if (c == d) | |
295 | return (1); | 295 | return (1); | |
296 | if (c == ' ') | 296 | if (c == ' ') | |
297 | continue; | 297 | continue; | |
298 | ungetc(c, stdin); | 298 | ungetc(c, stdin); | |
299 | return 0; | 299 | return 0; | |
300 | } | 300 | } | |
301 | exit(1); | 301 | exit(1); | |
302 | } | 302 | } |
--- src/games/trek/getpar.h 2009/05/24 21:44:56 1.11
+++ src/games/trek/getpar.h 2009/05/25 00:39:45 1.12
@@ -1,54 +1,54 @@ | @@ -1,54 +1,54 @@ | |||
1 | /* $NetBSD: getpar.h,v 1.11 2009/05/24 21:44:56 dholland Exp $ */ | 1 | /* $NetBSD: getpar.h,v 1.12 2009/05/25 00:39:45 dholland Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1980, 1993 | 4 | * Copyright (c) 1980, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3. Neither the name of the University nor the names of its contributors | 15 | * 3. Neither the name of the University nor the names of its contributors | |
16 | * may be used to endorse or promote products derived from this software | 16 | * may be used to endorse or promote products derived from this software | |
17 | * without specific prior written permission. | 17 | * without specific prior written permission. | |
18 | * | 18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | * | 30 | * | |
31 | * @(#)getpar.h 8.1 (Berkeley) 5/31/93 | 31 | * @(#)getpar.h 8.1 (Berkeley) 5/31/93 | |
32 | */ | 32 | */ | |
33 | 33 | |||
34 | typedef void (*cmdfun)(int); | 34 | typedef void (*cmdfun)(int); | |
35 | 35 | |||
36 | /* used for getcodpar() parameter list */ | 36 | /* used for getcodpar() parameter list */ | |
37 | struct cvntab { | 37 | struct cvntab { | |
38 | const char *abrev; | 38 | const char *abbrev; | |
39 | const char *full; | 39 | const char *full; | |
40 | cmdfun value; | 40 | cmdfun value; | |
41 | int value2; | 41 | int value2; | |
42 | }; | 42 | }; | |
43 | 43 | |||
44 | extern const struct cvntab Skitab[]; | 44 | extern const struct cvntab Skitab[]; | |
45 | extern const struct cvntab Lentab[]; | 45 | extern const struct cvntab Lentab[]; | |
46 | 46 | |||
47 | int getintpar(const char *); | 47 | int getintpar(const char *); | |
48 | double getfltpar(const char *); | 48 | double getfltpar(const char *); | |
49 | int getynpar(const char *); | 49 | int getynpar(const char *); | |
50 | const struct cvntab *getcodpar(const char *, const struct cvntab[]); | 50 | const struct cvntab *getcodpar(const char *, const struct cvntab[]); | |
51 | void getstrpar(const char *, char *, int, const char *); | 51 | void getstrpar(const char *, char *, int, const char *); | |
52 | int testnl(void); | 52 | int testnl(void); | |
53 | void skiptonl(int); | 53 | void skiptonl(int); | |
54 | int readdelim(int); | 54 | int readdelim(int); |
--- src/games/trek/win.c 2009/05/24 23:00:46 1.11
+++ src/games/trek/win.c 2009/05/25 00:39:45 1.12
@@ -1,93 +1,93 @@ | @@ -1,93 +1,93 @@ | |||
1 | /* $NetBSD: win.c,v 1.11 2009/05/24 23:00:46 dholland Exp $ */ | 1 | /* $NetBSD: win.c,v 1.12 2009/05/25 00:39:45 dholland Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1980, 1993 | 4 | * Copyright (c) 1980, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3. Neither the name of the University nor the names of its contributors | 15 | * 3. Neither the name of the University nor the names of its contributors | |
16 | * may be used to endorse or promote products derived from this software | 16 | * may be used to endorse or promote products derived from this software | |
17 | * without specific prior written permission. | 17 | * without specific prior written permission. | |
18 | * | 18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | #ifndef lint | 33 | #ifndef lint | |
34 | #if 0 | 34 | #if 0 | |
35 | static char sccsid[] = "@(#)win.c 8.1 (Berkeley) 5/31/93"; | 35 | static char sccsid[] = "@(#)win.c 8.1 (Berkeley) 5/31/93"; | |
36 | #else | 36 | #else | |
37 | __RCSID("$NetBSD: win.c,v 1.11 2009/05/24 23:00:46 dholland Exp $"); | 37 | __RCSID("$NetBSD: win.c,v 1.12 2009/05/25 00:39:45 dholland Exp $"); | |
38 | #endif | 38 | #endif | |
39 | #endif /* not lint */ | 39 | #endif /* not lint */ | |
40 | 40 | |||
41 | #include <stdio.h> | 41 | #include <stdio.h> | |
42 | #include <unistd.h> | 42 | #include <unistd.h> | |
43 | #include <setjmp.h> | 43 | #include <setjmp.h> | |
44 | #include "trek.h" | 44 | #include "trek.h" | |
45 | #include "getpar.h" | 45 | #include "getpar.h" | |
46 | 46 | |||
47 | /* | 47 | /* | |
48 | ** Signal game won | 48 | ** Signal game won | |
49 | ** | 49 | ** | |
50 | ** This routine prints out the win message, arranges to print out | 50 | ** This routine prints out the win message, arranges to print out | |
51 | ** your score, tells you if you have a promotion coming to you, | 51 | ** your score, tells you if you have a promotion coming to you, | |
52 | ** cleans up the current input line, and arranges to have you | 52 | ** cleans up the current input line, and arranges to have you | |
53 | ** asked whether or not you want another game (via the longjmp() | 53 | ** asked whether or not you want another game (via the longjmp() | |
54 | ** call). | 54 | ** call). | |
55 | ** | 55 | ** | |
56 | ** Pretty straightforward, although the promotion algorithm is | 56 | ** Pretty straightforward, although the promotion algorithm is | |
57 | ** pretty off the wall. | 57 | ** pretty off the wall. | |
58 | */ | 58 | */ | |
59 | 59 | |||
60 | extern jmp_buf env; | 60 | extern jmp_buf env; | |
61 | 61 | |||
62 | void | 62 | void | |
63 | win(void) | 63 | win(void) | |
64 | { | 64 | { | |
65 | long s; | 65 | long s; | |
66 | const struct cvntab *p; | 66 | const struct cvntab *p; | |
67 | 67 | |||
68 | sleep(1); | 68 | sleep(1); | |
69 | printf("\nCongratulations, you have saved the Federation\n"); | 69 | printf("\nCongratulations, you have saved the Federation\n"); | |
70 | Move.endgame = 1; | 70 | Move.endgame = 1; | |
71 | 71 | |||
72 | /* print and return the score */ | 72 | /* print and return the score */ | |
73 | s = score(); | 73 | s = score(); | |
74 | 74 | |||
75 | /* decide if she gets a promotion */ | 75 | /* decide if she gets a promotion */ | |
76 | if (Game.helps == 0 && Game.killb == 0 && Game.killinhab == 0 && | 76 | if (Game.helps == 0 && Game.killb == 0 && Game.killinhab == 0 && | |
77 | 5 * Game.kills + Game.deaths < 100 && | 77 | 5 * Game.kills + Game.deaths < 100 && | |
78 | s >= 1000 && Ship.ship == ENTERPRISE) { | 78 | s >= 1000 && Ship.ship == ENTERPRISE) { | |
79 | printf("In fact, you are promoted one step in rank,\n"); | 79 | printf("In fact, you are promoted one step in rank,\n"); | |
80 | if (Game.skill >= 6) { | 80 | if (Game.skill >= 6) { | |
81 | printf("to the exalted rank of Commodore Emeritus\n"); | 81 | printf("to the exalted rank of Commodore Emeritus\n"); | |
82 | } else { | 82 | } else { | |
83 | p = &Skitab[Game.skill - 1]; | 83 | p = &Skitab[Game.skill - 1]; | |
84 | printf("from %s%s ", p->abrev, p->full); | 84 | printf("from %s%s ", p->abbrev, p->full); | |
85 | p++; | 85 | p++; | |
86 | printf("to %s%s\n", p->abrev, p->full); | 86 | printf("to %s%s\n", p->abbrev, p->full); | |
87 | } | 87 | } | |
88 | } | 88 | } | |
89 | 89 | |||
90 | /* clean out input, and request new game */ | 90 | /* clean out input, and request new game */ | |
91 | skiptonl(0); | 91 | skiptonl(0); | |
92 | longjmp(env, 1); | 92 | longjmp(env, 1); | |
93 | } | 93 | } |
--- src/games/trek/score.c 2009/05/25 00:03:18 1.10
+++ src/games/trek/score.c 2009/05/25 00:39:45 1.11
@@ -1,131 +1,131 @@ | @@ -1,131 +1,131 @@ | |||
1 | /* $NetBSD: score.c,v 1.10 2009/05/25 00:03:18 dholland Exp $ */ | 1 | /* $NetBSD: score.c,v 1.11 2009/05/25 00:39:45 dholland Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1980, 1993 | 4 | * Copyright (c) 1980, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3. Neither the name of the University nor the names of its contributors | 15 | * 3. Neither the name of the University nor the names of its contributors | |
16 | * may be used to endorse or promote products derived from this software | 16 | * may be used to endorse or promote products derived from this software | |
17 | * without specific prior written permission. | 17 | * without specific prior written permission. | |
18 | * | 18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | #ifndef lint | 33 | #ifndef lint | |
34 | #if 0 | 34 | #if 0 | |
35 | static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93"; | 35 | static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93"; | |
36 | #else | 36 | #else | |
37 | __RCSID("$NetBSD: score.c,v 1.10 2009/05/25 00:03:18 dholland Exp $"); | 37 | __RCSID("$NetBSD: score.c,v 1.11 2009/05/25 00:39:45 dholland Exp $"); | |
38 | #endif | 38 | #endif | |
39 | #endif /* not lint */ | 39 | #endif /* not lint */ | |
40 | 40 | |||
41 | #include <stdarg.h> | 41 | #include <stdarg.h> | |
42 | #include <stdio.h> | 42 | #include <stdio.h> | |
43 | #include "trek.h" | 43 | #include "trek.h" | |
44 | #include "getpar.h" | 44 | #include "getpar.h" | |
45 | 45 | |||
46 | /* | 46 | /* | |
47 | ** PRINT OUT THE CURRENT SCORE | 47 | ** PRINT OUT THE CURRENT SCORE | |
48 | */ | 48 | */ | |
49 | 49 | |||
50 | static void scoreitem(long amount, const char *descfmt, ...) | 50 | static void scoreitem(long amount, const char *descfmt, ...) | |
51 | __printflike(2, 3); | 51 | __printflike(2, 3); | |
52 | 52 | |||
53 | static void | 53 | static void | |
54 | scoreitem(long amount, const char *descfmt, ...) | 54 | scoreitem(long amount, const char *descfmt, ...) | |
55 | { | 55 | { | |
56 | va_list ap; | 56 | va_list ap; | |
57 | char buf[128]; | 57 | char buf[128]; | |
58 | 58 | |||
59 | if (amount == 0) | 59 | if (amount == 0) | |
60 | return; | 60 | return; | |
61 | 61 | |||
62 | va_start(ap, descfmt); | 62 | va_start(ap, descfmt); | |
63 | vsnprintf(buf, sizeof(buf), descfmt, ap); | 63 | vsnprintf(buf, sizeof(buf), descfmt, ap); | |
64 | va_end(ap); | 64 | va_end(ap); | |
65 | 65 | |||
66 | printf("%-40s %10ld\n", buf, amount); | 66 | printf("%-40s %10ld\n", buf, amount); | |
67 | } | 67 | } | |
68 | 68 | |||
69 | long | 69 | long | |
70 | score(void) | 70 | score(void) | |
71 | { | 71 | { | |
72 | int u; | 72 | int u; | |
73 | int t; | 73 | int t; | |
74 | long s; | 74 | long s; | |
75 | double r; | 75 | double r; | |
76 | 76 | |||
77 | printf("\n*** Your score:\n"); | 77 | printf("\n*** Your score:\n"); | |
78 | 78 | |||
79 | s = t = Param.klingpwr / 4 * (u = Game.killk); | 79 | s = t = Param.klingpwr / 4 * (u = Game.killk); | |
80 | scoreitem(t, "%d Klingons killed", u); | 80 | scoreitem(t, "%d Klingons killed", u); | |
81 | 81 | |||
82 | r = Now.date - Param.date; | 82 | r = Now.date - Param.date; | |
83 | if (r < 1.0) | 83 | if (r < 1.0) | |
84 | r = 1.0; | 84 | r = 1.0; | |
85 | r = Game.killk / r; | 85 | r = Game.killk / r; | |
86 | s += (t = 400 * r); | 86 | s += (t = 400 * r); | |
87 | scoreitem(t, "Kill rate %.2f Klingons/stardate", r); | 87 | scoreitem(t, "Kill rate %.2f Klingons/stardate", r); | |
88 | 88 | |||
89 | r = Now.klings; | 89 | r = Now.klings; | |
90 | r /= Game.killk + 1; | 90 | r /= Game.killk + 1; | |
91 | s += (t = -400 * r); | 91 | s += (t = -400 * r); | |
92 | scoreitem(t, "Penalty for %d klingons remaining", Now.klings); | 92 | scoreitem(t, "Penalty for %d klingons remaining", Now.klings); | |
93 | 93 | |||
94 | if (Move.endgame > 0) { | 94 | if (Move.endgame > 0) { | |
95 | s += (t = 100 * (u = Game.skill)); | 95 | s += (t = 100 * (u = Game.skill)); | |
96 | scoreitem(t, "Bonus for winning a %s%s game", | 96 | scoreitem(t, "Bonus for winning a %s%s game", | |
97 | Skitab[u - 1].abrev, Skitab[u - 1].full); | 97 | Skitab[u - 1].abbrev, Skitab[u - 1].full); | |
98 | } | 98 | } | |
99 | 99 | |||
100 | if (Game.killed) { | 100 | if (Game.killed) { | |
101 | s -= 500; | 101 | s -= 500; | |
102 | scoreitem(-500, "Penalty for getting killed"); | 102 | scoreitem(-500, "Penalty for getting killed"); | |
103 | } | 103 | } | |
104 | 104 | |||
105 | s += (t = -100 * (u = Game.killb)); | 105 | s += (t = -100 * (u = Game.killb)); | |
106 | scoreitem(t, "%d starbases killed", u); | 106 | scoreitem(t, "%d starbases killed", u); | |
107 | 107 | |||
108 | s += (t = -100 * (u = Game.helps)); | 108 | s += (t = -100 * (u = Game.helps)); | |
109 | scoreitem(t, "%d calls for help", u); | 109 | scoreitem(t, "%d calls for help", u); | |
110 | 110 | |||
111 | s += (t = -5 * (u = Game.kills)); | 111 | s += (t = -5 * (u = Game.kills)); | |
112 | scoreitem(t, "%d stars destroyed", u); | 112 | scoreitem(t, "%d stars destroyed", u); | |
113 | 113 | |||
114 | s += (t = -150 * (u = Game.killinhab)); | 114 | s += (t = -150 * (u = Game.killinhab)); | |
115 | scoreitem(t, "%d inhabited starsystems destroyed", u); | 115 | scoreitem(t, "%d inhabited starsystems destroyed", u); | |
116 | 116 | |||
117 | if (Ship.ship != ENTERPRISE) { | 117 | if (Ship.ship != ENTERPRISE) { | |
118 | s -= 200; | 118 | s -= 200; | |
119 | scoreitem(-200, "penalty for abandoning ship"); | 119 | scoreitem(-200, "penalty for abandoning ship"); | |
120 | } | 120 | } | |
121 | 121 | |||
122 | s += (t = 3 * (u = Game.captives)); | 122 | s += (t = 3 * (u = Game.captives)); | |
123 | scoreitem(t, "%d Klingons captured", u); | 123 | scoreitem(t, "%d Klingons captured", u); | |
124 | 124 | |||
125 | s += (t = -(u = Game.deaths)); | 125 | s += (t = -(u = Game.deaths)); | |
126 | scoreitem(t, "%d casualties", u); | 126 | scoreitem(t, "%d casualties", u); | |
127 | 127 | |||
128 | printf("\n"); | 128 | printf("\n"); | |
129 | scoreitem(s, "*** TOTAL"); | 129 | scoreitem(s, "*** TOTAL"); | |
130 | return (s); | 130 | return (s); | |
131 | } | 131 | } |
--- src/games/trek/srscan.c 2009/05/24 22:55:03 1.9
+++ src/games/trek/srscan.c 2009/05/25 00:39:45 1.10
@@ -1,183 +1,183 @@ | @@ -1,183 +1,183 @@ | |||
1 | /* $NetBSD: srscan.c,v 1.9 2009/05/24 22:55:03 dholland Exp $ */ | 1 | /* $NetBSD: srscan.c,v 1.10 2009/05/25 00:39:45 dholland Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1980, 1993 | 4 | * Copyright (c) 1980, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3. Neither the name of the University nor the names of its contributors | 15 | * 3. Neither the name of the University nor the names of its contributors | |
16 | * may be used to endorse or promote products derived from this software | 16 | * may be used to endorse or promote products derived from this software | |
17 | * without specific prior written permission. | 17 | * without specific prior written permission. | |
18 | * | 18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | #ifndef lint | 33 | #ifndef lint | |
34 | #if 0 | 34 | #if 0 | |
35 | static char sccsid[] = "@(#)srscan.c 8.1 (Berkeley) 5/31/93"; | 35 | static char sccsid[] = "@(#)srscan.c 8.1 (Berkeley) 5/31/93"; | |
36 | #else | 36 | #else | |
37 | __RCSID("$NetBSD: srscan.c,v 1.9 2009/05/24 22:55:03 dholland Exp $"); | 37 | __RCSID("$NetBSD: srscan.c,v 1.10 2009/05/25 00:39:45 dholland Exp $"); | |
38 | #endif | 38 | #endif | |
39 | #endif /* not lint */ | 39 | #endif /* not lint */ | |
40 | 40 | |||
41 | #include <stdio.h> | 41 | #include <stdio.h> | |
42 | #include "trek.h" | 42 | #include "trek.h" | |
43 | #include "getpar.h" | 43 | #include "getpar.h" | |
44 | 44 | |||
45 | /* | 45 | /* | |
46 | ** SHORT RANGE SENSOR SCAN | 46 | ** SHORT RANGE SENSOR SCAN | |
47 | ** | 47 | ** | |
48 | ** A short range scan is taken of the current quadrant. If the | 48 | ** A short range scan is taken of the current quadrant. If the | |
49 | ** flag 'f' is one, it is an "auto srscan", which is not done | 49 | ** flag 'f' is one, it is an "auto srscan", which is not done | |
50 | ** unless in 'fast' mode. It does a status report and a srscan. | 50 | ** unless in 'fast' mode. It does a status report and a srscan. | |
51 | ** If 'f' is -1, you get a status report only. If it is zero, | 51 | ** If 'f' is -1, you get a status report only. If it is zero, | |
52 | ** you get a srscan and an optional status report. The status | 52 | ** you get a srscan and an optional status report. The status | |
53 | ** report is taken if you enter "srscan yes"; for all srscans | 53 | ** report is taken if you enter "srscan yes"; for all srscans | |
54 | ** thereafter you get a status report with your srscan until | 54 | ** thereafter you get a status report with your srscan until | |
55 | ** you type "srscan no". It defaults to on. | 55 | ** you type "srscan no". It defaults to on. | |
56 | ** | 56 | ** | |
57 | ** The current quadrant is filled in on the computer chart. | 57 | ** The current quadrant is filled in on the computer chart. | |
58 | */ | 58 | */ | |
59 | 59 | |||
60 | const char *const Color[4] = { | 60 | const char *const Color[4] = { | |
61 | "GREEN", | 61 | "GREEN", | |
62 | "DOCKED", | 62 | "DOCKED", | |
63 | "YELLOW", | 63 | "YELLOW", | |
64 | "RED" | 64 | "RED" | |
65 | }; | 65 | }; | |
66 | 66 | |||
67 | void | 67 | void | |
68 | srscan(int f) | 68 | srscan(int f) | |
69 | { | 69 | { | |
70 | int i, j; | 70 | int i, j; | |
71 | int statinfo; | 71 | int statinfo; | |
72 | const char *s; | 72 | const char *s; | |
73 | int percent; | 73 | int percent; | |
74 | struct quad *q = NULL; | 74 | struct quad *q = NULL; | |
75 | const struct cvntab *p; | 75 | const struct cvntab *p; | |
76 | 76 | |||
77 | if (f >= 0 && check_out(SRSCAN)) { | 77 | if (f >= 0 && check_out(SRSCAN)) { | |
78 | return; | 78 | return; | |
79 | } | 79 | } | |
80 | if (f) { | 80 | if (f) { | |
81 | statinfo = 1; | 81 | statinfo = 1; | |
82 | } else { | 82 | } else { | |
83 | if (!testnl()) | 83 | if (!testnl()) | |
84 | Etc.statreport = getynpar("status report"); | 84 | Etc.statreport = getynpar("status report"); | |
85 | statinfo = Etc.statreport; | 85 | statinfo = Etc.statreport; | |
86 | } | 86 | } | |
87 | if (f > 0) { | 87 | if (f > 0) { | |
88 | Etc.statreport = 1; | 88 | Etc.statreport = 1; | |
89 | if (!Etc.fast) | 89 | if (!Etc.fast) | |
90 | return; | 90 | return; | |
91 | } | 91 | } | |
92 | if (f >= 0) { | 92 | if (f >= 0) { | |
93 | printf("\nShort range sensor scan\n"); | 93 | printf("\nShort range sensor scan\n"); | |
94 | q = &Quad[Ship.quadx][Ship.quady]; | 94 | q = &Quad[Ship.quadx][Ship.quady]; | |
95 | q->scanned = q->klings * 100 + q->bases * 10 + q->stars; | 95 | q->scanned = q->klings * 100 + q->bases * 10 + q->stars; | |
96 | printf(" "); | 96 | printf(" "); | |
97 | for (i = 0; i < NSECTS; i++) { | 97 | for (i = 0; i < NSECTS; i++) { | |
98 | printf("%d ", i); | 98 | printf("%d ", i); | |
99 | } | 99 | } | |
100 | printf("\n"); | 100 | printf("\n"); | |
101 | } | 101 | } | |
102 | 102 | |||
103 | for (i = 0; i < NSECTS; i++) { | 103 | for (i = 0; i < NSECTS; i++) { | |
104 | if (f >= 0) { | 104 | if (f >= 0) { | |
105 | printf("%d ", i); | 105 | printf("%d ", i); | |
106 | for (j = 0; j < NSECTS; j++) | 106 | for (j = 0; j < NSECTS; j++) | |
107 | printf("%c ", Sect[i][j]); | 107 | printf("%c ", Sect[i][j]); | |
108 | printf("%d", i); | 108 | printf("%d", i); | |
109 | if (statinfo) | 109 | if (statinfo) | |
110 | printf(" "); | 110 | printf(" "); | |
111 | } | 111 | } | |
112 | if (statinfo) | 112 | if (statinfo) | |
113 | switch (i) { | 113 | switch (i) { | |
114 | case 0: | 114 | case 0: | |
115 | printf("stardate %.2f", Now.date); | 115 | printf("stardate %.2f", Now.date); | |
116 | break; | 116 | break; | |
117 | case 1: | 117 | case 1: | |
118 | printf("condition %s", Color[Ship.cond]); | 118 | printf("condition %s", Color[Ship.cond]); | |
119 | if (Ship.cloaked) | 119 | if (Ship.cloaked) | |
120 | printf(", CLOAKED"); | 120 | printf(", CLOAKED"); | |
121 | break; | 121 | break; | |
122 | case 2: | 122 | case 2: | |
123 | printf("position %d,%d/%d,%d", Ship.quadx, | 123 | printf("position %d,%d/%d,%d", Ship.quadx, | |
124 | Ship.quady, Ship.sectx, Ship.secty); | 124 | Ship.quady, Ship.sectx, Ship.secty); | |
125 | break; | 125 | break; | |
126 | case 3: | 126 | case 3: | |
127 | printf("warp factor %.1f", Ship.warp); | 127 | printf("warp factor %.1f", Ship.warp); | |
128 | break; | 128 | break; | |
129 | case 4: | 129 | case 4: | |
130 | printf("total energy %d", Ship.energy); | 130 | printf("total energy %d", Ship.energy); | |
131 | break; | 131 | break; | |
132 | case 5: | 132 | case 5: | |
133 | printf("torpedoes %d", Ship.torped); | 133 | printf("torpedoes %d", Ship.torped); | |
134 | break; | 134 | break; | |
135 | case 6: | 135 | case 6: | |
136 | s = "down"; | 136 | s = "down"; | |
137 | if (Ship.shldup) | 137 | if (Ship.shldup) | |
138 | s = "up"; | 138 | s = "up"; | |
139 | if (damaged(SHIELD)) | 139 | if (damaged(SHIELD)) | |
140 | s = "damaged"; | 140 | s = "damaged"; | |
141 | percent = 100.0 * Ship.shield / Param.shield; | 141 | percent = 100.0 * Ship.shield / Param.shield; | |
142 | printf("shields %s, %d%%", s, percent); | 142 | printf("shields %s, %d%%", s, percent); | |
143 | break; | 143 | break; | |
144 | case 7: | 144 | case 7: | |
145 | printf("Klingons left %d", Now.klings); | 145 | printf("Klingons left %d", Now.klings); | |
146 | break; | 146 | break; | |
147 | case 8: | 147 | case 8: | |
148 | printf("time left %.2f", Now.time); | 148 | printf("time left %.2f", Now.time); | |
149 | break; | 149 | break; | |
150 | case 9: | 150 | case 9: | |
151 | printf("life support "); | 151 | printf("life support "); | |
152 | if (damaged(LIFESUP)) { | 152 | if (damaged(LIFESUP)) { | |
153 | printf("damaged, reserves = %.2f", | 153 | printf("damaged, reserves = %.2f", | |
154 | Ship.reserves); | 154 | Ship.reserves); | |
155 | break; | 155 | break; | |
156 | } | 156 | } | |
157 | printf("active"); | 157 | printf("active"); | |
158 | break; | 158 | break; | |
159 | } | 159 | } | |
160 | printf("\n"); | 160 | printf("\n"); | |
161 | } | 161 | } | |
162 | if (f < 0) { | 162 | if (f < 0) { | |
163 | printf("current crew %d\n", Ship.crew); | 163 | printf("current crew %d\n", Ship.crew); | |
164 | printf("brig space %d\n", Ship.brigfree); | 164 | printf("brig space %d\n", Ship.brigfree); | |
165 | printf("Klingon power %d\n", Param.klingpwr); | 165 | printf("Klingon power %d\n", Param.klingpwr); | |
166 | p = &Lentab[Game.length - 1]; | 166 | p = &Lentab[Game.length - 1]; | |
167 | if (Game.length > 2) | 167 | if (Game.length > 2) | |
168 | p--; | 168 | p--; | |
169 | printf("Length, Skill %s%s, ", p->abrev, p->full); | 169 | printf("Length, Skill %s%s, ", p->abbrev, p->full); | |
170 | p = &Skitab[Game.skill - 1]; | 170 | p = &Skitab[Game.skill - 1]; | |
171 | printf("%s%s\n", p->abrev, p->full); | 171 | printf("%s%s\n", p->abbrev, p->full); | |
172 | return; | 172 | return; | |
173 | } | 173 | } | |
174 | printf(" "); | 174 | printf(" "); | |
175 | for (i = 0; i < NSECTS; i++) | 175 | for (i = 0; i < NSECTS; i++) | |
176 | printf("%d ", i); | 176 | printf("%d ", i); | |
177 | printf("\n"); | 177 | printf("\n"); | |
178 | 178 | |||
179 | if (q->qsystemname & Q_DISTRESSED) | 179 | if (q->qsystemname & Q_DISTRESSED) | |
180 | printf("Distressed "); | 180 | printf("Distressed "); | |
181 | if (q->qsystemname) | 181 | if (q->qsystemname) | |
182 | printf("Starsystem %s\n", systemname(q)); | 182 | printf("Starsystem %s\n", systemname(q)); | |
183 | } | 183 | } |