Rev 4268 | Rev 4515 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4268 | Rev 4488 | ||
---|---|---|---|
1 | /* $OpenBSD: scores.c,v 1.11 2006/04/20 03:25:36 ray Exp $ */ |
1 | /* $OpenBSD: scores.c,v 1.11 2006/04/20 03:25:36 ray Exp $ */ |
2 | /* $NetBSD: scores.c,v 1.2 1995/04/22 07:42:38 cgd Exp $ */ |
2 | /* $NetBSD: scores.c,v 1.2 1995/04/22 07:42:38 cgd Exp $ */ |
3 | 3 | ||
4 | /*- |
4 | /*- |
5 | * Copyright (c) 1992, 1993 |
5 | * Copyright (c) 1992, 1993 |
6 | * The Regents of the University of California. All rights reserved. |
6 | * The Regents of the University of California. All rights reserved. |
7 | * |
7 | * |
8 | * This code is derived from software contributed to Berkeley by |
8 | * This code is derived from software contributed to Berkeley by |
9 | * Chris Torek and Darren F. Provine. |
9 | * Chris Torek and Darren F. Provine. |
10 | * |
10 | * |
11 | * Redistribution and use in source and binary forms, with or without |
11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions |
12 | * modification, are permitted provided that the following conditions |
13 | * are met: |
13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright |
14 | * 1. Redistributions of source code must retain the above copyright |
15 | * notice, this list of conditions and the following disclaimer. |
15 | * notice, this list of conditions and the following disclaimer. |
16 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * 2. Redistributions in binary form must reproduce the above copyright |
17 | * notice, this list of conditions and the following disclaimer in the |
17 | * notice, this list of conditions and the following disclaimer in the |
18 | * documentation and/or other materials provided with the distribution. |
18 | * documentation and/or other materials provided with the distribution. |
19 | * 3. Neither the name of the University nor the names of its contributors |
19 | * 3. Neither the name of the University nor the names of its contributors |
20 | * may be used to endorse or promote products derived from this software |
20 | * may be used to endorse or promote products derived from this software |
21 | * without specific prior written permission. |
21 | * without specific prior written permission. |
22 | * |
22 | * |
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
33 | * SUCH DAMAGE. |
33 | * SUCH DAMAGE. |
34 | * |
34 | * |
35 | * @(#)scores.c 8.1 (Berkeley) 5/31/93 |
35 | * @(#)scores.c 8.1 (Berkeley) 5/31/93 |
36 | */ |
36 | */ |
37 | 37 | ||
38 | /** @addtogroup tetris |
38 | /** @addtogroup tetris |
39 | * @{ |
39 | * @{ |
40 | */ |
40 | */ |
41 | /** @file |
41 | /** @file |
42 | */ |
42 | */ |
43 | 43 | ||
44 | /* |
44 | /* |
45 | * Score code for Tetris, by Darren Provine (kilroy@gboro.glassboro.edu) |
45 | * Score code for Tetris, by Darren Provine (kilroy@gboro.glassboro.edu) |
46 | * modified 22 January 1992, to limit the number of entries any one |
46 | * modified 22 January 1992, to limit the number of entries any one |
47 | * person has. |
47 | * person has. |
48 | * |
48 | * |
49 | * Major whacks since then. |
49 | * Major whacks since then. |
50 | */ |
50 | */ |
51 | #include <errno.h> |
51 | #include <errno.h> |
52 | /* #include <err.h> */ |
52 | /* #include <err.h> */ |
53 | /* #include <fcntl.h> */ |
53 | /* #include <fcntl.h> */ |
54 | /* #include <pwd.h> */ |
54 | /* #include <pwd.h> */ |
55 | #include <stdio.h> |
55 | #include <stdio.h> |
56 | /* #include <stdlib.h> */ |
56 | /* #include <stdlib.h> */ |
57 | #include <string.h> |
57 | #include <string.h> |
58 | #include <kbd/kbd.h> |
58 | #include <io/console.h> |
59 | #include <kbd/keycode.h> |
59 | #include <io/keycode.h> |
- | 60 | #include <vfs/vfs.h> |
|
60 | #include <stdlib.h> |
61 | #include <stdlib.h> |
61 | /* #include <time.h> */ |
62 | /* #include <time.h> */ |
62 | /* #include <term.h> */ |
63 | /* #include <term.h> */ |
63 | /* #include <unistd.h> */ |
64 | /* #include <unistd.h> */ |
64 | /* #include <sys/param.h> */ |
65 | /* #include <sys/param.h> */ |
65 | /* #include <sys/stat.h> */ |
66 | /* #include <sys/stat.h> */ |
66 | /* #include <sys/types.h> */ |
67 | /* #include <sys/types.h> */ |
67 | 68 | ||
68 | #include "pathnames.h" |
69 | #include "pathnames.h" |
69 | #include "screen.h" |
70 | #include "screen.h" |
70 | #include "tetris.h" |
71 | #include "tetris.h" |
71 | #include "scores.h" |
72 | #include "scores.h" |
72 | 73 | ||
73 | /* |
74 | /* |
74 | * Within this code, we can hang onto one extra "high score", leaving |
75 | * Within this code, we can hang onto one extra "high score", leaving |
75 | * room for our current score (whether or not it is high). |
76 | * room for our current score (whether or not it is high). |
76 | * |
77 | * |
77 | * We also sometimes keep tabs on the "highest" score on each level. |
78 | * We also sometimes keep tabs on the "highest" score on each level. |
78 | * As long as the scores are kept sorted, this is simply the first one at |
79 | * As long as the scores are kept sorted, this is simply the first one at |
79 | * that level. |
80 | * that level. |
80 | */ |
81 | */ |
81 | #define NUMSPOTS (MAXHISCORES + 1) |
82 | #define NUMSPOTS (MAXHISCORES + 1) |
82 | #define NLEVELS (MAXLEVEL + 1) |
83 | #define NLEVELS (MAXLEVEL + 1) |
83 | 84 | ||
84 | /* static time_t now; */ |
85 | /* static time_t now; */ |
85 | /* static int nscores; */ |
86 | /* static int nscores; */ |
86 | /* static int gotscores; */ |
87 | /* static int gotscores; */ |
87 | /* static struct highscore scores[NUMSPOTS]; */ |
88 | /* static struct highscore scores[NUMSPOTS]; */ |
88 | static struct highscore scores[NUMSPOTS]; |
89 | static struct highscore scores[NUMSPOTS]; |
89 | 90 | ||
90 | /* static int checkscores(struct highscore *, int); */ |
91 | /* static int checkscores(struct highscore *, int); */ |
91 | /* static int cmpscores(const void *, const void *); */ |
92 | /* static int cmpscores(const void *, const void *); */ |
92 | /* static void getscores(FILE **); */ |
93 | /* static void getscores(FILE **); */ |
93 | /* static void printem(int, int, struct highscore *, int, const char *); */ |
94 | /* static void printem(int, int, struct highscore *, int, const char *); */ |
94 | /* static char *thisuser(void); */ |
95 | /* static char *thisuser(void); */ |
95 | 96 | ||
96 | void showscores(int firstgame) |
97 | void showscores(int firstgame) |
97 | { |
98 | { |
98 | int i; |
99 | int i; |
99 | 100 | ||
100 | clear_screen(); |
101 | clear_screen(); |
101 | moveto(10, 0); |
102 | moveto(10, 0); |
102 | printf("\tRank \tLevel \tName\t points\n"); |
103 | printf("\tRank \tLevel \tName\t points\n"); |
103 | printf("\t========================================================\n"); |
104 | printf("\t========================================================\n"); |
104 | for (i = 0; i < NUMSPOTS - 1; i++) { |
105 | for (i = 0; i < NUMSPOTS - 1; i++) { |
105 | printf("\t%6d %6d %-16s %20d\n", i+1, scores[i].hs_level, scores[i].hs_name, scores[i].hs_score); |
106 | printf("\t%6d %6d %-16s %20d\n", i+1, scores[i].hs_level, scores[i].hs_name, scores[i].hs_score); |
106 | } |
107 | } |
107 | if (!firstgame) { |
108 | if (!firstgame) { |
108 | printf("\t========================================================\n"); |
109 | printf("\t========================================================\n"); |
109 | printf("\t Last %6d %-16s %20d\n", scores[NUMSPOTS - 1].hs_level, scores[NUMSPOTS - 1].hs_name, scores[NUMSPOTS - 1].hs_score); |
110 | printf("\t Last %6d %-16s %20d\n", scores[NUMSPOTS - 1].hs_level, scores[NUMSPOTS - 1].hs_name, scores[NUMSPOTS - 1].hs_score); |
110 | } |
111 | } |
111 | printf("\n\n\n\n\tPress any key to return to main menu."); |
112 | printf("\n\n\n\n\tPress any key to return to main menu."); |
112 | getchar(); |
113 | getchar(); |
113 | } |
114 | } |
114 | 115 | ||
115 | /** Copy from hiscore table score with index src to dest |
116 | /** Copy from hiscore table score with index src to dest |
116 | * |
117 | * |
117 | */ |
118 | */ |
118 | static void copyhiscore(int dest, int src) |
119 | static void copyhiscore(int dest, int src) |
119 | { |
120 | { |
120 | str_cpy(scores[dest].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, |
121 | str_cpy(scores[dest].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, |
121 | scores[src].hs_name); |
122 | scores[src].hs_name); |
122 | scores[dest].hs_score = scores[src].hs_score; |
123 | scores[dest].hs_score = scores[src].hs_score; |
123 | scores[dest].hs_level = scores[src].hs_level; |
124 | scores[dest].hs_level = scores[src].hs_level; |
124 | } |
125 | } |
125 | 126 | ||
126 | void insertscore(int score, int level) |
127 | void insertscore(int score, int level) |
127 | { |
128 | { |
128 | int i,j; |
129 | int i,j; |
129 | size_t off; |
130 | size_t off; |
130 | kbd_event_t ev; |
131 | console_event_t ev; |
131 | 132 | ||
132 | clear_screen(); |
133 | clear_screen(); |
133 | moveto(10 , 10); |
134 | moveto(10 , 10); |
134 | puts("Insert your name: "); |
135 | puts("Insert your name: "); |
135 | str_cpy(scores[NUMSPOTS - 1].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, |
136 | str_cpy(scores[NUMSPOTS - 1].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, |
136 | "Player"); |
137 | "Player"); |
137 | i = 6; off = 6; |
138 | i = 6; off = 6; |
138 | 139 | ||
139 | moveto(10 , 28); |
140 | moveto(10 , 28); |
140 | printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................"); |
141 | printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................"); |
141 | 142 | ||
142 | while (1) { |
143 | while (1) { |
143 | fflush(stdout); |
144 | fflush(stdout); |
144 | if (kbd_get_event(&ev) != EOK) |
145 | if (!console_get_event(fphone(stdin), &ev)) |
145 | exit(1); |
146 | exit(1); |
146 | 147 | ||
147 | if (ev.type == KE_RELEASE) |
148 | if (ev.type == KEY_RELEASE) |
148 | continue; |
149 | continue; |
149 | 150 | ||
150 | if (ev.key == KC_ENTER || ev.key == KC_NENTER) |
151 | if (ev.key == KC_ENTER || ev.key == KC_NENTER) |
151 | break; |
152 | break; |
152 | 153 | ||
153 | if (ev.key == KC_BACKSPACE) { |
154 | if (ev.key == KC_BACKSPACE) { |
154 | if (i > 0) { |
155 | if (i > 0) { |
155 | wchar_t uc; |
156 | wchar_t uc; |
156 | 157 | ||
157 | --i; |
158 | --i; |
158 | while (off > 0) { |
159 | while (off > 0) { |
159 | --off; |
160 | --off; |
160 | size_t otmp = off; |
161 | size_t otmp = off; |
161 | uc = str_decode(scores[NUMSPOTS - 1].hs_name, |
162 | uc = str_decode(scores[NUMSPOTS - 1].hs_name, |
162 | &otmp, STR_BOUNDS(MAXLOGNAME) + 1); |
163 | &otmp, STR_BOUNDS(MAXLOGNAME) + 1); |
163 | if (uc != U_SPECIAL) |
164 | if (uc != U_SPECIAL) |
164 | break; |
165 | break; |
165 | } |
166 | } |
166 | 167 | ||
167 | scores[NUMSPOTS - 1].hs_name[off] = '\0'; |
168 | scores[NUMSPOTS - 1].hs_name[off] = '\0'; |
168 | } |
169 | } |
169 | } else if (ev.c != '\0') { |
170 | } else if (ev.c != '\0') { |
170 | if (i < (MAXLOGNAME - 1)) { |
171 | if (i < (MAXLOGNAME - 1)) { |
171 | if (chr_encode(ev.c, scores[NUMSPOTS - 1].hs_name, |
172 | if (chr_encode(ev.c, scores[NUMSPOTS - 1].hs_name, |
172 | &off, STR_BOUNDS(MAXLOGNAME) + 1) == EOK) { |
173 | &off, STR_BOUNDS(MAXLOGNAME) + 1) == EOK) { |
173 | ++i; |
174 | ++i; |
174 | } |
175 | } |
175 | scores[NUMSPOTS - 1].hs_name[off] = '\0'; |
176 | scores[NUMSPOTS - 1].hs_name[off] = '\0'; |
176 | } |
177 | } |
177 | } |
178 | } |
178 | 179 | ||
179 | moveto(10 , 28); |
180 | moveto(10 , 28); |
180 | printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................"); |
181 | printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................"); |
181 | } |
182 | } |
182 | 183 | ||
183 | scores[NUMSPOTS - 1].hs_score = score; |
184 | scores[NUMSPOTS - 1].hs_score = score; |
184 | scores[NUMSPOTS - 1].hs_level = level; |
185 | scores[NUMSPOTS - 1].hs_level = level; |
185 | 186 | ||
186 | i = NUMSPOTS-1; |
187 | i = NUMSPOTS-1; |
187 | while ((i > 0) && (scores[i - 1].hs_score < score)) |
188 | while ((i > 0) && (scores[i - 1].hs_score < score)) |
188 | i--; |
189 | i--; |
189 | 190 | ||
190 | for (j = NUMSPOTS - 2; j > i; j--) { |
191 | for (j = NUMSPOTS - 2; j > i; j--) { |
191 | copyhiscore(j,j-1); |
192 | copyhiscore(j,j-1); |
192 | } |
193 | } |
193 | copyhiscore(i, NUMSPOTS - 1); |
194 | copyhiscore(i, NUMSPOTS - 1); |
194 | } |
195 | } |
195 | 196 | ||
196 | void initscores(void) |
197 | void initscores(void) |
197 | { |
198 | { |
198 | int i; |
199 | int i; |
199 | for(i = 0; i < NUMSPOTS; i++) { |
200 | for(i = 0; i < NUMSPOTS; i++) { |
200 | str_cpy(scores[i].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, "HelenOS Team"); |
201 | str_cpy(scores[i].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, "HelenOS Team"); |
201 | scores[i].hs_score = (NUMSPOTS - i) * 200; |
202 | scores[i].hs_score = (NUMSPOTS - i) * 200; |
202 | scores[i].hs_level = (i + 1 > MAXLEVEL?MAXLEVEL:i + 1); |
203 | scores[i].hs_level = (i + 1 > MAXLEVEL?MAXLEVEL:i + 1); |
203 | } |
204 | } |
204 | } |
205 | } |
205 | 206 | ||
206 | /* |
207 | /* |
207 | * Read the score file. Can be called from savescore (before showscores) |
208 | * Read the score file. Can be called from savescore (before showscores) |
208 | * or showscores (if savescore will not be called). If the given pointer |
209 | * or showscores (if savescore will not be called). If the given pointer |
209 | * is not NULL, sets *fpp to an open file pointer that corresponds to a |
210 | * is not NULL, sets *fpp to an open file pointer that corresponds to a |
210 | * read/write score file that is locked with LOCK_EX. Otherwise, the |
211 | * read/write score file that is locked with LOCK_EX. Otherwise, the |
211 | * file is locked with LOCK_SH for the read and closed before return. |
212 | * file is locked with LOCK_SH for the read and closed before return. |
212 | * |
213 | * |
213 | * Note, we assume closing the stdio file releases the lock. |
214 | * Note, we assume closing the stdio file releases the lock. |
214 | */ |
215 | */ |
215 | /* static void */ |
216 | /* static void */ |
216 | /* getscores(FILE **fpp) */ |
217 | /* getscores(FILE **fpp) */ |
217 | /* { */ |
218 | /* { */ |
218 | /* int sd, mint, lck, mask, i; */ |
219 | /* int sd, mint, lck, mask, i; */ |
219 | /* char *mstr, *human; */ |
220 | /* char *mstr, *human; */ |
220 | /* FILE *sf; */ |
221 | /* FILE *sf; */ |
221 | 222 | ||
222 | /* if (fpp != NULL) { */ |
223 | /* if (fpp != NULL) { */ |
223 | /* mint = O_RDWR | O_CREAT; */ |
224 | /* mint = O_RDWR | O_CREAT; */ |
224 | /* mstr = "r+"; */ |
225 | /* mstr = "r+"; */ |
225 | /* human = "read/write"; */ |
226 | /* human = "read/write"; */ |
226 | /* lck = LOCK_EX; */ |
227 | /* lck = LOCK_EX; */ |
227 | /* } else { */ |
228 | /* } else { */ |
228 | /* mint = O_RDONLY; */ |
229 | /* mint = O_RDONLY; */ |
229 | /* mstr = "r"; */ |
230 | /* mstr = "r"; */ |
230 | /* human = "reading"; */ |
231 | /* human = "reading"; */ |
231 | /* lck = LOCK_SH; */ |
232 | /* lck = LOCK_SH; */ |
232 | /* } */ |
233 | /* } */ |
233 | /* setegid(egid); */ |
234 | /* setegid(egid); */ |
234 | /* mask = umask(S_IWOTH); */ |
235 | /* mask = umask(S_IWOTH); */ |
235 | /* sd = open(_PATH_SCOREFILE, mint, 0666); */ |
236 | /* sd = open(_PATH_SCOREFILE, mint, 0666); */ |
236 | /* (void)umask(mask); */ |
237 | /* (void)umask(mask); */ |
237 | /* setegid(gid); */ |
238 | /* setegid(gid); */ |
238 | /* if (sd < 0) { */ |
239 | /* if (sd < 0) { */ |
239 | /* if (fpp == NULL) { */ |
240 | /* if (fpp == NULL) { */ |
240 | /* nscores = 0; */ |
241 | /* nscores = 0; */ |
241 | /* return; */ |
242 | /* return; */ |
242 | /* } */ |
243 | /* } */ |
243 | /* err(1, "cannot open %s for %s", _PATH_SCOREFILE, human); */ |
244 | /* err(1, "cannot open %s for %s", _PATH_SCOREFILE, human); */ |
244 | /* } */ |
245 | /* } */ |
245 | /* setegid(egid); */ |
246 | /* setegid(egid); */ |
246 | /* if ((sf = fdopen(sd, mstr)) == NULL) */ |
247 | /* if ((sf = fdopen(sd, mstr)) == NULL) */ |
247 | /* err(1, "cannot fdopen %s for %s", _PATH_SCOREFILE, human); */ |
248 | /* err(1, "cannot fdopen %s for %s", _PATH_SCOREFILE, human); */ |
248 | /* setegid(gid); */ |
249 | /* setegid(gid); */ |
249 | 250 | ||
250 | /* /\* */ |
251 | /* /\* */ |
251 | /* * Grab a lock. */ |
252 | /* * Grab a lock. */ |
252 | /* *\/ */ |
253 | /* *\/ */ |
253 | /* if (flock(sd, lck)) */ |
254 | /* if (flock(sd, lck)) */ |
254 | /* warn("warning: score file %s cannot be locked", */ |
255 | /* warn("warning: score file %s cannot be locked", */ |
255 | /* _PATH_SCOREFILE); */ |
256 | /* _PATH_SCOREFILE); */ |
256 | 257 | ||
257 | /* nscores = fread(scores, sizeof(scores[0]), MAXHISCORES, sf); */ |
258 | /* nscores = fread(scores, sizeof(scores[0]), MAXHISCORES, sf); */ |
258 | /* if (ferror(sf)) */ |
259 | /* if (ferror(sf)) */ |
259 | /* err(1, "error reading %s", _PATH_SCOREFILE); */ |
260 | /* err(1, "error reading %s", _PATH_SCOREFILE); */ |
260 | /* for (i = 0; i < nscores; i++) */ |
261 | /* for (i = 0; i < nscores; i++) */ |
261 | /* if (scores[i].hs_level < MINLEVEL || */ |
262 | /* if (scores[i].hs_level < MINLEVEL || */ |
262 | /* scores[i].hs_level > MAXLEVEL) */ |
263 | /* scores[i].hs_level > MAXLEVEL) */ |
263 | /* errx(1, "scorefile %s corrupt", _PATH_SCOREFILE); */ |
264 | /* errx(1, "scorefile %s corrupt", _PATH_SCOREFILE); */ |
264 | 265 | ||
265 | /* if (fpp) */ |
266 | /* if (fpp) */ |
266 | /* *fpp = sf; */ |
267 | /* *fpp = sf; */ |
267 | /* else */ |
268 | /* else */ |
268 | /* (void)fclose(sf); */ |
269 | /* (void)fclose(sf); */ |
269 | /* } */ |
270 | /* } */ |
270 | 271 | ||
271 | void |
272 | void |
272 | savescore(int level) |
273 | savescore(int level) |
273 | { |
274 | { |
274 | return; |
275 | return; |
275 | } |
276 | } |
276 | /* struct highscore *sp; */ |
277 | /* struct highscore *sp; */ |
277 | /* int i; */ |
278 | /* int i; */ |
278 | /* int change; */ |
279 | /* int change; */ |
279 | /* FILE *sf; */ |
280 | /* FILE *sf; */ |
280 | /* const char *me; */ |
281 | /* const char *me; */ |
281 | 282 | ||
282 | /* getscores(&sf); */ |
283 | /* getscores(&sf); */ |
283 | /* gotscores = 1; */ |
284 | /* gotscores = 1; */ |
284 | /* (void)time(&now); */ |
285 | /* (void)time(&now); */ |
285 | 286 | ||
286 | /* /\* */ |
287 | /* /\* */ |
287 | /* * Allow at most one score per person per level -- see if we */ |
288 | /* * Allow at most one score per person per level -- see if we */ |
288 | /* * can replace an existing score, or (easiest) do nothing. */ |
289 | /* * can replace an existing score, or (easiest) do nothing. */ |
289 | /* * Otherwise add new score at end (there is always room). */ |
290 | /* * Otherwise add new score at end (there is always room). */ |
290 | /* *\/ */ |
291 | /* *\/ */ |
291 | /* change = 0; */ |
292 | /* change = 0; */ |
292 | /* me = thisuser(); */ |
293 | /* me = thisuser(); */ |
293 | /* for (i = 0, sp = &scores[0]; i < nscores; i++, sp++) { */ |
294 | /* for (i = 0, sp = &scores[0]; i < nscores; i++, sp++) { */ |
294 | /* if (sp->hs_level != level || str_cmp(sp->hs_name, me) != 0) */ |
295 | /* if (sp->hs_level != level || str_cmp(sp->hs_name, me) != 0) */ |
295 | /* continue; */ |
296 | /* continue; */ |
296 | /* if (score > sp->hs_score) { */ |
297 | /* if (score > sp->hs_score) { */ |
297 | /* (void)printf("%s bettered %s %d score of %d!\n", */ |
298 | /* (void)printf("%s bettered %s %d score of %d!\n", */ |
298 | /* "\nYou", "your old level", level, */ |
299 | /* "\nYou", "your old level", level, */ |
299 | /* sp->hs_score * sp->hs_level); */ |
300 | /* sp->hs_score * sp->hs_level); */ |
300 | /* sp->hs_score = score; /\* new score *\/ */ |
301 | /* sp->hs_score = score; /\* new score *\/ */ |
301 | /* sp->hs_time = now; /\* and time *\/ */ |
302 | /* sp->hs_time = now; /\* and time *\/ */ |
302 | /* change = 1; */ |
303 | /* change = 1; */ |
303 | /* } else if (score == sp->hs_score) { */ |
304 | /* } else if (score == sp->hs_score) { */ |
304 | /* (void)printf("%s tied %s %d high score.\n", */ |
305 | /* (void)printf("%s tied %s %d high score.\n", */ |
305 | /* "\nYou", "your old level", level); */ |
306 | /* "\nYou", "your old level", level); */ |
306 | /* sp->hs_time = now; /\* renew it *\/ */ |
307 | /* sp->hs_time = now; /\* renew it *\/ */ |
307 | /* change = 1; /\* gotta rewrite, sigh *\/ */ |
308 | /* change = 1; /\* gotta rewrite, sigh *\/ */ |
308 | /* } /\* else new score < old score: do nothing *\/ */ |
309 | /* } /\* else new score < old score: do nothing *\/ */ |
309 | /* break; */ |
310 | /* break; */ |
310 | /* } */ |
311 | /* } */ |
311 | /* if (i >= nscores) { */ |
312 | /* if (i >= nscores) { */ |
312 | /* strlcpy(sp->hs_name, me, sizeof sp->hs_name); */ |
313 | /* strlcpy(sp->hs_name, me, sizeof sp->hs_name); */ |
313 | /* sp->hs_level = level; */ |
314 | /* sp->hs_level = level; */ |
314 | /* sp->hs_score = score; */ |
315 | /* sp->hs_score = score; */ |
315 | /* sp->hs_time = now; */ |
316 | /* sp->hs_time = now; */ |
316 | /* nscores++; */ |
317 | /* nscores++; */ |
317 | /* change = 1; */ |
318 | /* change = 1; */ |
318 | /* } */ |
319 | /* } */ |
319 | 320 | ||
320 | /* if (change) { */ |
321 | /* if (change) { */ |
321 | /* /\* */ |
322 | /* /\* */ |
322 | /* * Sort & clean the scores, then rewrite. */ |
323 | /* * Sort & clean the scores, then rewrite. */ |
323 | /* *\/ */ |
324 | /* *\/ */ |
324 | /* nscores = checkscores(scores, nscores); */ |
325 | /* nscores = checkscores(scores, nscores); */ |
325 | /* rewind(sf); */ |
326 | /* rewind(sf); */ |
326 | /* if (fwrite(scores, sizeof(*sp), nscores, sf) != nscores || */ |
327 | /* if (fwrite(scores, sizeof(*sp), nscores, sf) != nscores || */ |
327 | /* fflush(sf) == EOF) */ |
328 | /* fflush(sf) == EOF) */ |
328 | /* warnx("error writing %s: %s\n\t-- %s", */ |
329 | /* warnx("error writing %s: %s\n\t-- %s", */ |
329 | /* _PATH_SCOREFILE, strerror(errno), */ |
330 | /* _PATH_SCOREFILE, strerror(errno), */ |
330 | /* "high scores may be damaged"); */ |
331 | /* "high scores may be damaged"); */ |
331 | /* } */ |
332 | /* } */ |
332 | /* (void)fclose(sf); /\* releases lock *\/ */ |
333 | /* (void)fclose(sf); /\* releases lock *\/ */ |
333 | /* } */ |
334 | /* } */ |
334 | 335 | ||
335 | /* |
336 | /* |
336 | * Get login name, or if that fails, get something suitable. |
337 | * Get login name, or if that fails, get something suitable. |
337 | * The result is always trimmed to fit in a score. |
338 | * The result is always trimmed to fit in a score. |
338 | */ |
339 | */ |
339 | /* static char * */ |
340 | /* static char * */ |
340 | /* thisuser(void) */ |
341 | /* thisuser(void) */ |
341 | /* { */ |
342 | /* { */ |
342 | /* const char *p; */ |
343 | /* const char *p; */ |
343 | /* struct passwd *pw; */ |
344 | /* struct passwd *pw; */ |
344 | /* static char u[sizeof(scores[0].hs_name)]; */ |
345 | /* static char u[sizeof(scores[0].hs_name)]; */ |
345 | 346 | ||
346 | /* if (u[0]) */ |
347 | /* if (u[0]) */ |
347 | /* return (u); */ |
348 | /* return (u); */ |
348 | /* p = getlogin(); */ |
349 | /* p = getlogin(); */ |
349 | /* if (p == NULL || *p == '\0') { */ |
350 | /* if (p == NULL || *p == '\0') { */ |
350 | /* pw = getpwuid(getuid()); */ |
351 | /* pw = getpwuid(getuid()); */ |
351 | /* if (pw != NULL) */ |
352 | /* if (pw != NULL) */ |
352 | /* p = pw->pw_name; */ |
353 | /* p = pw->pw_name; */ |
353 | /* else */ |
354 | /* else */ |
354 | /* p = " ???"; */ |
355 | /* p = " ???"; */ |
355 | /* } */ |
356 | /* } */ |
356 | /* strlcpy(u, p, sizeof(u)); */ |
357 | /* strlcpy(u, p, sizeof(u)); */ |
357 | /* return (u); */ |
358 | /* return (u); */ |
358 | /* } */ |
359 | /* } */ |
359 | 360 | ||
360 | /* |
361 | /* |
361 | * Score comparison function for qsort. |
362 | * Score comparison function for qsort. |
362 | * |
363 | * |
363 | * If two scores are equal, the person who had the score first is |
364 | * If two scores are equal, the person who had the score first is |
364 | * listed first in the highscore file. |
365 | * listed first in the highscore file. |
365 | */ |
366 | */ |
366 | /* static int */ |
367 | /* static int */ |
367 | /* cmpscores(const void *x, const void *y) */ |
368 | /* cmpscores(const void *x, const void *y) */ |
368 | /* { */ |
369 | /* { */ |
369 | /* const struct highscore *a, *b; */ |
370 | /* const struct highscore *a, *b; */ |
370 | /* long l; */ |
371 | /* long l; */ |
371 | 372 | ||
372 | /* a = x; */ |
373 | /* a = x; */ |
373 | /* b = y; */ |
374 | /* b = y; */ |
374 | /* l = (long)b->hs_level * b->hs_score - (long)a->hs_level * a->hs_score; */ |
375 | /* l = (long)b->hs_level * b->hs_score - (long)a->hs_level * a->hs_score; */ |
375 | /* if (l < 0) */ |
376 | /* if (l < 0) */ |
376 | /* return (-1); */ |
377 | /* return (-1); */ |
377 | /* if (l > 0) */ |
378 | /* if (l > 0) */ |
378 | /* return (1); */ |
379 | /* return (1); */ |
379 | /* if (a->hs_time < b->hs_time) */ |
380 | /* if (a->hs_time < b->hs_time) */ |
380 | /* return (-1); */ |
381 | /* return (-1); */ |
381 | /* if (a->hs_time > b->hs_time) */ |
382 | /* if (a->hs_time > b->hs_time) */ |
382 | /* return (1); */ |
383 | /* return (1); */ |
383 | /* return (0); */ |
384 | /* return (0); */ |
384 | /* } */ |
385 | /* } */ |
385 | 386 | ||
386 | /* |
387 | /* |
387 | * If we've added a score to the file, we need to check the file and ensure |
388 | * If we've added a score to the file, we need to check the file and ensure |
388 | * that this player has only a few entries. The number of entries is |
389 | * that this player has only a few entries. The number of entries is |
389 | * controlled by MAXSCORES, and is to ensure that the highscore file is not |
390 | * controlled by MAXSCORES, and is to ensure that the highscore file is not |
390 | * monopolised by just a few people. People who no longer have accounts are |
391 | * monopolised by just a few people. People who no longer have accounts are |
391 | * only allowed the highest score. Scores older than EXPIRATION seconds are |
392 | * only allowed the highest score. Scores older than EXPIRATION seconds are |
392 | * removed, unless they are someone's personal best. |
393 | * removed, unless they are someone's personal best. |
393 | * Caveat: the highest score on each level is always kept. |
394 | * Caveat: the highest score on each level is always kept. |
394 | */ |
395 | */ |
395 | /* static int */ |
396 | /* static int */ |
396 | /* checkscores(struct highscore *hs, int num) */ |
397 | /* checkscores(struct highscore *hs, int num) */ |
397 | /* { */ |
398 | /* { */ |
398 | /* struct highscore *sp; */ |
399 | /* struct highscore *sp; */ |
399 | /* int i, j, k, numnames; */ |
400 | /* int i, j, k, numnames; */ |
400 | /* int levelfound[NLEVELS]; */ |
401 | /* int levelfound[NLEVELS]; */ |
401 | /* struct peruser { */ |
402 | /* struct peruser { */ |
402 | /* char *name; */ |
403 | /* char *name; */ |
403 | /* int times; */ |
404 | /* int times; */ |
404 | /* } count[NUMSPOTS]; */ |
405 | /* } count[NUMSPOTS]; */ |
405 | /* struct peruser *pu; */ |
406 | /* struct peruser *pu; */ |
406 | 407 | ||
407 | /* /\* */ |
408 | /* /\* */ |
408 | /* * Sort so that highest totals come first. */ |
409 | /* * Sort so that highest totals come first. */ |
409 | /* * */ |
410 | /* * */ |
410 | /* * levelfound[i] becomes set when the first high score for that */ |
411 | /* * levelfound[i] becomes set when the first high score for that */ |
411 | /* * level is encountered. By definition this is the highest score. */ |
412 | /* * level is encountered. By definition this is the highest score. */ |
412 | /* *\/ */ |
413 | /* *\/ */ |
413 | /* qsort((void *)hs, nscores, sizeof(*hs), cmpscores); */ |
414 | /* qsort((void *)hs, nscores, sizeof(*hs), cmpscores); */ |
414 | /* for (i = MINLEVEL; i < NLEVELS; i++) */ |
415 | /* for (i = MINLEVEL; i < NLEVELS; i++) */ |
415 | /* levelfound[i] = 0; */ |
416 | /* levelfound[i] = 0; */ |
416 | /* numnames = 0; */ |
417 | /* numnames = 0; */ |
417 | /* for (i = 0, sp = hs; i < num;) { */ |
418 | /* for (i = 0, sp = hs; i < num;) { */ |
418 | /* /\* */ |
419 | /* /\* */ |
419 | /* * This is O(n^2), but do you think we care? */ |
420 | /* * This is O(n^2), but do you think we care? */ |
420 | /* *\/ */ |
421 | /* *\/ */ |
421 | /* for (j = 0, pu = count; j < numnames; j++, pu++) */ |
422 | /* for (j = 0, pu = count; j < numnames; j++, pu++) */ |
422 | /* if (str_cmp(sp->hs_name, pu->name) == 0) */ |
423 | /* if (str_cmp(sp->hs_name, pu->name) == 0) */ |
423 | /* break; */ |
424 | /* break; */ |
424 | /* if (j == numnames) { */ |
425 | /* if (j == numnames) { */ |
425 | /* /\* */ |
426 | /* /\* */ |
426 | /* * Add new user, set per-user count to 1. */ |
427 | /* * Add new user, set per-user count to 1. */ |
427 | /* *\/ */ |
428 | /* *\/ */ |
428 | /* pu->name = sp->hs_name; */ |
429 | /* pu->name = sp->hs_name; */ |
429 | /* pu->times = 1; */ |
430 | /* pu->times = 1; */ |
430 | /* numnames++; */ |
431 | /* numnames++; */ |
431 | /* } else { */ |
432 | /* } else { */ |
432 | /* /\* */ |
433 | /* /\* */ |
433 | /* * Two ways to keep this score: */ |
434 | /* * Two ways to keep this score: */ |
434 | /* * - Not too many (per user), still has acct, & */ |
435 | /* * - Not too many (per user), still has acct, & */ |
435 | /* * score not dated; or */ |
436 | /* * score not dated; or */ |
436 | /* * - High score on this level. */ |
437 | /* * - High score on this level. */ |
437 | /* *\/ */ |
438 | /* *\/ */ |
438 | /* if ((pu->times < MAXSCORES && */ |
439 | /* if ((pu->times < MAXSCORES && */ |
439 | /* getpwnam(sp->hs_name) != NULL && */ |
440 | /* getpwnam(sp->hs_name) != NULL && */ |
440 | /* sp->hs_time + EXPIRATION >= now) || */ |
441 | /* sp->hs_time + EXPIRATION >= now) || */ |
441 | /* levelfound[sp->hs_level] == 0) */ |
442 | /* levelfound[sp->hs_level] == 0) */ |
442 | /* pu->times++; */ |
443 | /* pu->times++; */ |
443 | /* else { */ |
444 | /* else { */ |
444 | /* /\* */ |
445 | /* /\* */ |
445 | /* * Delete this score, do not count it, */ |
446 | /* * Delete this score, do not count it, */ |
446 | /* * do not pass go, do not collect $200. */ |
447 | /* * do not pass go, do not collect $200. */ |
447 | /* *\/ */ |
448 | /* *\/ */ |
448 | /* num--; */ |
449 | /* num--; */ |
449 | /* for (k = i; k < num; k++) */ |
450 | /* for (k = i; k < num; k++) */ |
450 | /* hs[k] = hs[k + 1]; */ |
451 | /* hs[k] = hs[k + 1]; */ |
451 | /* continue; */ |
452 | /* continue; */ |
452 | /* } */ |
453 | /* } */ |
453 | /* } */ |
454 | /* } */ |
454 | /* levelfound[sp->hs_level] = 1; */ |
455 | /* levelfound[sp->hs_level] = 1; */ |
455 | /* i++, sp++; */ |
456 | /* i++, sp++; */ |
456 | /* } */ |
457 | /* } */ |
457 | /* return (num > MAXHISCORES ? MAXHISCORES : num); */ |
458 | /* return (num > MAXHISCORES ? MAXHISCORES : num); */ |
458 | /* } */ |
459 | /* } */ |
459 | 460 | ||
460 | /* |
461 | /* |
461 | * Show current scores. This must be called after savescore, if |
462 | * Show current scores. This must be called after savescore, if |
462 | * savescore is called at all, for two reasons: |
463 | * savescore is called at all, for two reasons: |
463 | * - Showscores munches the time field. |
464 | * - Showscores munches the time field. |
464 | * - Even if that were not the case, a new score must be recorded |
465 | * - Even if that were not the case, a new score must be recorded |
465 | * before it can be shown anyway. |
466 | * before it can be shown anyway. |
466 | */ |
467 | */ |
467 | /* |
468 | /* |
468 | void |
469 | void |
469 | showscores(int level) |
470 | showscores(int level) |
470 | { |
471 | { |
471 | return; |
472 | return; |
472 | } |
473 | } |
473 | */ |
474 | */ |
474 | /* struct highscore *sp; */ |
475 | /* struct highscore *sp; */ |
475 | /* int i, n, c; */ |
476 | /* int i, n, c; */ |
476 | /* const char *me; */ |
477 | /* const char *me; */ |
477 | /* int levelfound[NLEVELS]; */ |
478 | /* int levelfound[NLEVELS]; */ |
478 | 479 | ||
479 | /* if (!gotscores) */ |
480 | /* if (!gotscores) */ |
480 | /* getscores((FILE **)NULL); */ |
481 | /* getscores((FILE **)NULL); */ |
481 | /* (void)printf("\n\t\t Tetris High Scores\n"); */ |
482 | /* (void)printf("\n\t\t Tetris High Scores\n"); */ |
482 | 483 | ||
483 | /* /\* */ |
484 | /* /\* */ |
484 | /* * If level == 0, the person has not played a game but just asked for */ |
485 | /* * If level == 0, the person has not played a game but just asked for */ |
485 | /* * the high scores; we do not need to check for printing in highlight */ |
486 | /* * the high scores; we do not need to check for printing in highlight */ |
486 | /* * mode. If SOstr is null, we can't do highlighting anyway. */ |
487 | /* * mode. If SOstr is null, we can't do highlighting anyway. */ |
487 | /* *\/ */ |
488 | /* *\/ */ |
488 | /* me = level && SOstr ? thisuser() : NULL; */ |
489 | /* me = level && SOstr ? thisuser() : NULL; */ |
489 | 490 | ||
490 | /* /\* */ |
491 | /* /\* */ |
491 | /* * Set times to 0 except for high score on each level. */ |
492 | /* * Set times to 0 except for high score on each level. */ |
492 | /* *\/ */ |
493 | /* *\/ */ |
493 | /* for (i = MINLEVEL; i < NLEVELS; i++) */ |
494 | /* for (i = MINLEVEL; i < NLEVELS; i++) */ |
494 | /* levelfound[i] = 0; */ |
495 | /* levelfound[i] = 0; */ |
495 | /* for (i = 0, sp = scores; i < nscores; i++, sp++) { */ |
496 | /* for (i = 0, sp = scores; i < nscores; i++, sp++) { */ |
496 | /* if (levelfound[sp->hs_level]) */ |
497 | /* if (levelfound[sp->hs_level]) */ |
497 | /* sp->hs_time = 0; */ |
498 | /* sp->hs_time = 0; */ |
498 | /* else { */ |
499 | /* else { */ |
499 | /* sp->hs_time = 1; */ |
500 | /* sp->hs_time = 1; */ |
500 | /* levelfound[sp->hs_level] = 1; */ |
501 | /* levelfound[sp->hs_level] = 1; */ |
501 | /* } */ |
502 | /* } */ |
502 | /* } */ |
503 | /* } */ |
503 | 504 | ||
504 | /* /\* */ |
505 | /* /\* */ |
505 | /* * Page each screenful of scores. */ |
506 | /* * Page each screenful of scores. */ |
506 | /* *\/ */ |
507 | /* *\/ */ |
507 | /* for (i = 0, sp = scores; i < nscores; sp += n) { */ |
508 | /* for (i = 0, sp = scores; i < nscores; sp += n) { */ |
508 | /* n = 20; */ |
509 | /* n = 20; */ |
509 | /* if (i + n > nscores) */ |
510 | /* if (i + n > nscores) */ |
510 | /* n = nscores - i; */ |
511 | /* n = nscores - i; */ |
511 | /* printem(level, i + 1, sp, n, me); */ |
512 | /* printem(level, i + 1, sp, n, me); */ |
512 | /* if ((i += n) < nscores) { */ |
513 | /* if ((i += n) < nscores) { */ |
513 | /* (void)printf("\nHit RETURN to continue."); */ |
514 | /* (void)printf("\nHit RETURN to continue."); */ |
514 | /* (void)fflush(stdout); */ |
515 | /* (void)fflush(stdout); */ |
515 | /* while ((c = getchar()) != '\n') */ |
516 | /* while ((c = getchar()) != '\n') */ |
516 | /* if (c == EOF) */ |
517 | /* if (c == EOF) */ |
517 | /* break; */ |
518 | /* break; */ |
518 | /* (void)printf("\n"); */ |
519 | /* (void)printf("\n"); */ |
519 | /* } */ |
520 | /* } */ |
520 | /* } */ |
521 | /* } */ |
521 | 522 | ||
522 | /* if (nscores == 0) */ |
523 | /* if (nscores == 0) */ |
523 | /* printf("\t\t\t - none to date.\n"); */ |
524 | /* printf("\t\t\t - none to date.\n"); */ |
524 | /* } */ |
525 | /* } */ |
525 | 526 | ||
526 | /* static void */ |
527 | /* static void */ |
527 | /* printem(int level, int offset, struct highscore *hs, int n, const char *me) */ |
528 | /* printem(int level, int offset, struct highscore *hs, int n, const char *me) */ |
528 | /* { */ |
529 | /* { */ |
529 | /* struct highscore *sp; */ |
530 | /* struct highscore *sp; */ |
530 | /* int row, highlight, i; */ |
531 | /* int row, highlight, i; */ |
531 | /* char buf[100]; */ |
532 | /* char buf[100]; */ |
532 | /* #define TITLE "Rank Score Name (points/level)" */ |
533 | /* #define TITLE "Rank Score Name (points/level)" */ |
533 | /* #define TITL2 "==========================================================" */ |
534 | /* #define TITL2 "==========================================================" */ |
534 | 535 | ||
535 | /* printf("%s\n%s\n", TITLE, TITL2); */ |
536 | /* printf("%s\n%s\n", TITLE, TITL2); */ |
536 | 537 | ||
537 | /* highlight = 0; */ |
538 | /* highlight = 0; */ |
538 | 539 | ||
539 | /* for (row = 0; row < n; row++) { */ |
540 | /* for (row = 0; row < n; row++) { */ |
540 | /* sp = &hs[row]; */ |
541 | /* sp = &hs[row]; */ |
541 | /* (void)snprintf(buf, sizeof(buf), */ |
542 | /* (void)snprintf(buf, sizeof(buf), */ |
542 | /* "%3d%c %6d %-31s (%6d on %d)\n", */ |
543 | /* "%3d%c %6d %-31s (%6d on %d)\n", */ |
543 | /* row + offset, sp->hs_time ? '*' : ' ', */ |
544 | /* row + offset, sp->hs_time ? '*' : ' ', */ |
544 | /* sp->hs_score * sp->hs_level, */ |
545 | /* sp->hs_score * sp->hs_level, */ |
545 | /* sp->hs_name, sp->hs_score, sp->hs_level); */ |
546 | /* sp->hs_name, sp->hs_score, sp->hs_level); */ |
546 | /* /\* Print leaders every three lines *\/ */ |
547 | /* /\* Print leaders every three lines *\/ */ |
547 | /* if ((row + 1) % 3 == 0) { */ |
548 | /* if ((row + 1) % 3 == 0) { */ |
548 | /* for (i = 0; i < sizeof(buf); i++) */ |
549 | /* for (i = 0; i < sizeof(buf); i++) */ |
549 | /* if (buf[i] == ' ') */ |
550 | /* if (buf[i] == ' ') */ |
550 | /* buf[i] = '_'; */ |
551 | /* buf[i] = '_'; */ |
551 | /* } */ |
552 | /* } */ |
552 | /* /\* */ |
553 | /* /\* */ |
553 | /* * Highlight if appropriate. This works because */ |
554 | /* * Highlight if appropriate. This works because */ |
554 | /* * we only get one score per level. */ |
555 | /* * we only get one score per level. */ |
555 | /* *\/ */ |
556 | /* *\/ */ |
556 | /* if (me != NULL && */ |
557 | /* if (me != NULL && */ |
557 | /* sp->hs_level == level && */ |
558 | /* sp->hs_level == level && */ |
558 | /* sp->hs_score == score && */ |
559 | /* sp->hs_score == score && */ |
559 | /* str_cmp(sp->hs_name, me) == 0) { */ |
560 | /* str_cmp(sp->hs_name, me) == 0) { */ |
560 | /* putpad(SOstr); */ |
561 | /* putpad(SOstr); */ |
561 | /* highlight = 1; */ |
562 | /* highlight = 1; */ |
562 | /* } */ |
563 | /* } */ |
563 | /* (void)printf("%s", buf); */ |
564 | /* (void)printf("%s", buf); */ |
564 | /* if (highlight) { */ |
565 | /* if (highlight) { */ |
565 | /* putpad(SEstr); */ |
566 | /* putpad(SEstr); */ |
566 | /* highlight = 0; */ |
567 | /* highlight = 0; */ |
567 | /* } */ |
568 | /* } */ |
568 | /* } */ |
569 | /* } */ |
569 | /* } */ |
570 | /* } */ |
570 | 571 | ||
571 | /** @} |
572 | /** @} |
572 | */ |
573 | */ |
573 | 574 | ||
574 | 575 |