-/* $NetBSD: tetris.c,v 1.7 1999/01/03 17:13:51 hubertf Exp $ */
+/* $NetBSD: tetris.c,v 1.15 2002/06/02 22:17:38 wiz Exp $ */
/*-
* Copyright (c) 1992, 1993
#include <sys/time.h>
+#include <err.h>
+#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include "screen.h"
#include "tetris.h"
+cell board[B_SIZE]; /* 1 => occupied, 0 => empty */
+
+int Rows, Cols; /* current screen size */
+
+const struct shape *curshape;
+const struct shape *nextshape;
+
+long fallrate; /* less than 1 million; smaller => faster */
+
+int score; /* the obvious thing */
+gid_t gid, egid;
+
+char key_msg[100];
+int showpreview;
+
static void elide __P((void));
static void setup_board __P((void));
int main __P((int, char **));
static void
setup_board()
{
- register int i;
- register cell *p;
+ int i;
+ cell *p;
p = board;
for (i = B_SIZE; i; i--)
-#ifndef mips
*p++ = i <= (2 * B_COLS) || (i % B_COLS) < 2;
-#else /* work around compiler bug */
- *p++ = i <= (2 * B_COLS) || (i % B_COLS) < 2 ? 1 : 0;
-#endif
}
/*
static void
elide()
{
- register int i, j, base;
- register cell *p;
+ int i, j, base;
+ cell *p;
for (i = A_FIRST; i < A_LAST; i++) {
base = i * B_COLS + 1;
int argc;
char *argv[];
{
- register int pos, c;
- register char *keys;
- register int level = 2;
+ int pos, c;
+ const char *keys;
+ int level = 2;
char key_write[6][10];
int ch, i, j;
+ int fd;
+
+ gid = getgid();
+ egid = getegid();
+ setegid(gid);
+
+ fd = open("/dev/null", O_RDONLY);
+ if (fd < 3)
+ exit(1);
+ close(fd);
keys = "jkl pq";
case 'l':
level = atoi(optarg);
if (level < MINLEVEL || level > MAXLEVEL) {
- (void)fprintf(stderr,
- "tetris: level must be from %d to %d",
- MINLEVEL, MAXLEVEL);
- exit(1);
+ errx(1, "level must be from %d to %d",
+ MINLEVEL, MAXLEVEL);
}
break;
case 'p':
for (i = 0; i <= 5; i++) {
for (j = i+1; j <= 5; j++) {
if (keys[i] == keys[j]) {
- (void)fprintf(stderr,
- "%s: Duplicate command keys specified.\n",
- argv[0]);
- exit (1);
+ errx(1, "duplicate command keys specified.");
}
}
if (keys[i] == ' ')
}
if (c == keys[1]) {
/* turn */
- struct shape *new = &shapes[curshape->rot];
+ const struct shape *new = &shapes[curshape->rot];
if (fits_in(new, pos))
curshape = new;
void
onintr(signo)
- int signo;
+ int signo __attribute__((__unused__));
{
scr_clear();
scr_end();
void
usage()
{
- (void)fprintf(stderr, "usage: tetris [-ps] [-l level] [-keys]\n");
+ (void)fprintf(stderr, "usage: tetris [-ps] [-k keys] [-l level]\n");
exit(1);
}