Rev 1419 | Rev 1472 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1419 | Rev 1449 | ||
---|---|---|---|
Line 48... | Line 48... | ||
48 | #include <sys/param.h> |
48 | #include <sys/param.h> |
49 | #include <sys/time.h> |
49 | #include <sys/time.h> |
50 | #include <sys/types.h> |
50 | #include <sys/types.h> |
51 | 51 | ||
52 | #include <err.h> |
52 | #include <err.h> |
53 | #include <signal.h> |
53 | //#include <signal.h> |
54 | #include <stdio.h> |
54 | #include <stdio.h> |
55 | #include <stdlib.h> |
55 | #include <stdlib.h> |
56 | #include <string.h> |
56 | #include <string.h> |
57 | #include <unistd.h> |
57 | #include <unistd.h> |
58 | 58 | ||
Line 65... | Line 65... | ||
65 | int Rows, Cols; |
65 | int Rows, Cols; |
66 | const struct shape *curshape; |
66 | const struct shape *curshape; |
67 | const struct shape *nextshape; |
67 | const struct shape *nextshape; |
68 | long fallrate; |
68 | long fallrate; |
69 | int score; |
69 | int score; |
70 | gid_t gid, egid; |
70 | //gid_t gid, egid; |
71 | char key_msg[100]; |
71 | char key_msg[100]; |
72 | int showpreview, classic; |
72 | int showpreview, classic; |
73 | 73 | ||
74 | static void elide(void); |
74 | static void elide(void); |
75 | static void setup_board(void); |
75 | static void setup_board(void); |
Line 163... | Line 163... | ||
163 | const char *errstr; |
163 | const char *errstr; |
164 | int ch, i, j; |
164 | int ch, i, j; |
165 | 165 | ||
166 | keys = "jkl pq"; |
166 | keys = "jkl pq"; |
167 | 167 | ||
168 | gid = getgid(); |
168 | // gid = getgid(); |
169 | egid = getegid(); |
169 | // egid = getegid(); |
170 | setegid(gid); |
170 | // setegid(gid); |
171 | 171 | ||
172 | classic = showpreview = 0; |
172 | classic = showpreview = 0; |
173 | while ((ch = getopt(argc, argv, "ck:l:ps")) != -1) |
- | |
174 | switch(ch) { |
- | |
175 | case 'c': |
- | |
176 | /* |
- | |
177 | * this means: |
- | |
178 | * - rotate the other way; |
- | |
179 | * - no reverse video. |
- | |
180 | */ |
- | |
181 | classic = 1; |
- | |
182 | break; |
- | |
183 | case 'k': |
- | |
184 | if (strlen(keys = optarg) != 6) |
- | |
185 | usage(); |
- | |
186 | break; |
- | |
187 | case 'l': |
- | |
188 | level = (int)strtonum(optarg, MINLEVEL, MAXLEVEL, |
- | |
189 | &errstr); |
- | |
190 | if (errstr) |
- | |
191 | errx(1, "level must be from %d to %d", |
- | |
192 | MINLEVEL, MAXLEVEL); |
- | |
193 | break; |
- | |
194 | case 'p': |
- | |
195 | showpreview = 1; |
- | |
196 | break; |
- | |
197 | case 's': |
- | |
198 | showscores(0); |
- | |
199 | exit(0); |
- | |
200 | default: |
- | |
201 | usage(); |
- | |
202 | } |
- | |
203 | 173 | ||
- | 174 | /* while ((ch = getopt(argc, argv, "ck:l:ps")) != -1) */ |
|
- | 175 | /* switch(ch) { */ |
|
- | 176 | /* case 'c': */ |
|
- | 177 | /* /\* */ |
|
- | 178 | /* * this means: */ |
|
- | 179 | /* * - rotate the other way; */ |
|
- | 180 | /* * - no reverse video. */ |
|
- | 181 | /* *\/ */ |
|
- | 182 | /* classic = 1; */ |
|
- | 183 | /* break; */ |
|
- | 184 | /* case 'k': */ |
|
- | 185 | /* if (strlen(keys = optarg) != 6) */ |
|
- | 186 | /* usage(); */ |
|
- | 187 | /* break; */ |
|
- | 188 | /* case 'l': */ |
|
- | 189 | /* level = (int)strtonum(optarg, MINLEVEL, MAXLEVEL, */ |
|
- | 190 | /* &errstr); */ |
|
- | 191 | /* if (errstr) */ |
|
- | 192 | /* errx(1, "level must be from %d to %d", */ |
|
- | 193 | /* MINLEVEL, MAXLEVEL); */ |
|
- | 194 | /* break; */ |
|
- | 195 | /* case 'p': */ |
|
- | 196 | /* showpreview = 1; */ |
|
- | 197 | /* break; */ |
|
- | 198 | /* case 's': */ |
|
- | 199 | /* showscores(0); */ |
|
- | 200 | /* exit(0); */ |
|
- | 201 | /* default: */ |
|
- | 202 | /* usage(); */ |
|
- | 203 | /* } */ |
|
- | 204 | ||
204 | argc -= optind; |
205 | /* argc -= optind; */ |
205 | argv += optind; |
206 | /* argv += optind; */ |
206 | 207 | ||
207 | if (argc) |
208 | /* if (argc) */ |
208 | usage(); |
209 | /* usage(); */ |
209 | 210 | ||
210 | fallrate = 1000000 / level; |
211 | fallrate = 1000000 / level; |
211 | 212 | ||
212 | for (i = 0; i <= 5; i++) { |
213 | for (i = 0; i <= 5; i++) { |
213 | for (j = i+1; j <= 5; j++) { |
214 | for (j = i+1; j <= 5; j++) { |
Line 225... | Line 226... | ||
225 | snprintf(key_msg, sizeof key_msg, |
226 | snprintf(key_msg, sizeof key_msg, |
226 | "%s - left %s - rotate %s - right %s - drop %s - pause %s - quit", |
227 | "%s - left %s - rotate %s - right %s - drop %s - pause %s - quit", |
227 | key_write[0], key_write[1], key_write[2], key_write[3], |
228 | key_write[0], key_write[1], key_write[2], key_write[3], |
228 | key_write[4], key_write[5]); |
229 | key_write[4], key_write[5]); |
229 | 230 | ||
230 | (void)signal(SIGINT, onintr); |
231 | // (void)signal(SIGINT, onintr); |
231 | scr_init(); |
232 | scr_init(); |
232 | setup_board(); |
233 | setup_board(); |
233 | 234 | ||
234 | srandomdev(); |
235 | srandomdev(); |
235 | scr_set(); |
236 | scr_set(); |
Line 355... | Line 356... | ||
355 | showscores(level); |
356 | showscores(level); |
356 | 357 | ||
357 | exit(0); |
358 | exit(0); |
358 | } |
359 | } |
359 | 360 | ||
360 | void |
361 | /* void */ |
361 | onintr(int signo) |
362 | /* onintr(int signo) */ |
362 | { |
363 | /* { */ |
363 | scr_clear(); /* XXX signal race */ |
364 | /* scr_clear(); /\* XXX signal race *\/ */ |
364 | scr_end(); /* XXX signal race */ |
365 | /* scr_end(); /\* XXX signal race *\/ */ |
365 | _exit(0); |
366 | /* _exit(0); */ |
366 | } |
367 | /* } */ |
367 | 368 | ||
368 | void |
369 | void |
369 | usage(void) |
370 | usage(void) |
370 | { |
371 | { |
371 | (void)fprintf(stderr, "usage: tetris [-ps] [-k keys] [-l level]\n"); |
372 | (void)fprintf(stderr, "usage: tetris [-ps] [-k keys] [-l level]\n"); |