From fb3a8a316c1960990044b83faf0ffc188d6400a6 Mon Sep 17 00:00:00 2001 From: Paul Janzen Date: Thu, 24 Sep 1998 06:45:09 +0000 Subject: NetBSD changes and a few obvious fixes --- games/boggle/README | 2 +- games/boggle/boggle/bog.c | 17 +++++++---- games/boggle/boggle/bog.h | 1 + games/boggle/boggle/boggle.6 | 4 +-- games/boggle/boggle/extern.h | 1 + games/boggle/boggle/help.c | 8 +++-- games/boggle/boggle/helpfile | 15 ---------- games/boggle/boggle/mach.c | 7 +++-- games/boggle/boggle/prtable.c | 1 + games/boggle/boggle/timer.c | 3 +- games/boggle/boggle/word.c | 17 ++++++----- games/boggle/mkdict/Makefile | 1 + games/boggle/mkdict/mkdict.c | 11 +++---- games/boggle/mkindex/Makefile | 1 + games/boggle/mkindex/mkindex.c | 3 +- games/tetris/Makefile | 10 ++++++- games/tetris/input.c | 1 + games/tetris/input.h | 1 + games/tetris/pathnames.h | 1 + games/tetris/scores.c | 39 ++++++++++-------------- games/tetris/scores.h | 1 + games/tetris/screen.c | 68 +++++++++++++++++++----------------------- games/tetris/screen.h | 1 + games/tetris/shapes.c | 39 ++++++++++++------------ games/tetris/tetris.6 | 12 ++++---- games/tetris/tetris.c | 31 ++++++++++--------- games/tetris/tetris.h | 1 + 27 files changed, 151 insertions(+), 146 deletions(-) diff --git a/games/boggle/README b/games/boggle/README index 47c0938205e..b67c66c702d 100644 --- a/games/boggle/README +++ b/games/boggle/README @@ -1,4 +1,4 @@ -$NetBSD: README,v 1.2 1995/03/21 12:14:21 cgd Exp $ +$OpenBSD: README,v 1.3 1998/09/24 06:45:05 pjanzen Exp $ Bog is a fairly portable simulation of Parker Brother's game of Boggle and is similar to the 4.[23] BSD "boggle" and Sun's "boggletool". diff --git a/games/boggle/boggle/bog.c b/games/boggle/boggle/bog.c index 9c2213bab1b..d545e609216 100644 --- a/games/boggle/boggle/bog.c +++ b/games/boggle/boggle/bog.c @@ -1,3 +1,4 @@ +/* $OpenBSD: bog.c,v 1.5 1998/09/24 06:45:05 pjanzen Exp $ */ /* $NetBSD: bog.c,v 1.5 1995/04/24 12:22:32 cgd Exp $ */ /*- @@ -46,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)bog.c 8.1 (Berkeley) 6/11/93"; #else -static char rcsid[] = "$NetBSD: bog.c,v 1.5 1995/04/24 12:22:32 cgd Exp $"; +static char rcsid[] = "$OpenBSD: bog.c,v 1.5 1998/09/24 06:45:05 pjanzen Exp $"; #endif #endif /* not lint */ @@ -56,6 +57,7 @@ static char rcsid[] = "$NetBSD: bog.c,v 1.5 1995/04/24 12:22:32 cgd Exp $"; #include #include #include +#include #include "bog.h" #include "extern.h" @@ -126,12 +128,15 @@ main(argc, argv) int argc; char *argv[]; { - long seed; + time_t seed; int ch, done, i, selfuse, sflag; char *bspec, *p; + /* revoke */ + setegid(getgid()); setgid(getgid()); + seed = 0; batch = debug = reuse = selfuse = sflag = 0; bspec = NULL; minlength = 3; @@ -165,18 +170,19 @@ main(argc, argv) argv += optind; /* process final arguments */ - if (argc > 0) + if (argc > 0) { if (strcmp(argv[0], "+") == 0) reuse = 1; else if (strcmp(argv[0], "++") == 0) selfuse = 1; + } if (reuse || selfuse) { argc -= 1; argv += 1; } - if (argc > 0) + if (argc > 0) { if (islower(argv[0][0])) { if (strlen(argv[0]) != 16) { usage(); @@ -187,6 +193,7 @@ main(argc, argv) } else { usage(); } + } if (batch && bspec == NULL) errx(1, "must give both -b and a board setup"); @@ -595,7 +602,7 @@ checkdict() } mword[nmwords++] = mwordsp; p = w; - while (*mwordsp++ = *p++); + while ((*mwordsp++ = *p++)); } } diff --git a/games/boggle/boggle/bog.h b/games/boggle/boggle/bog.h index ae6654ebabc..4d92a0f77db 100644 --- a/games/boggle/boggle/bog.h +++ b/games/boggle/boggle/bog.h @@ -1,3 +1,4 @@ +/* $OpenBSD: bog.h,v 1.2 1998/09/24 06:45:05 pjanzen Exp $ */ /* $NetBSD: bog.h,v 1.2 1995/03/21 12:14:32 cgd Exp $ */ /*- diff --git a/games/boggle/boggle/boggle.6 b/games/boggle/boggle/boggle.6 index 9133cecb49f..ddade009b58 100644 --- a/games/boggle/boggle/boggle.6 +++ b/games/boggle/boggle/boggle.6 @@ -1,4 +1,4 @@ -.\" $OpenBSD: boggle.6,v 1.2 1997/08/04 11:51:29 downsj Exp $ +.\" $OpenBSD: boggle.6,v 1.3 1998/09/24 06:45:05 pjanzen Exp $ .\" $NetBSD: boggle.6,v 1.2 1995/03/21 12:14:35 cgd Exp $ .\" .\" Copyright (c) 1997, Jason Downs. All rights reserved. @@ -138,7 +138,7 @@ Help is available during play by typing More detailed information on the game is given there. .Sh BUGS If there are a great many words in the cube the final display of the words -may scroll off of the screen. (On a 25 line screen about 130 words can be +may scroll off the screen. (On a 25 line screen about 130 words can be displayed.) .Pp No word can contain a diff --git a/games/boggle/boggle/extern.h b/games/boggle/boggle/extern.h index fb0614ec538..0149a49f10c 100644 --- a/games/boggle/boggle/extern.h +++ b/games/boggle/boggle/extern.h @@ -1,3 +1,4 @@ +/* $OpenBSD: extern.h,v 1.2 1998/09/24 06:45:05 pjanzen Exp $ */ /* $NetBSD: extern.h,v 1.3 1995/04/24 12:22:37 cgd Exp $ */ /*- diff --git a/games/boggle/boggle/help.c b/games/boggle/boggle/help.c index b7de8a2e084..a17cea01ac3 100644 --- a/games/boggle/boggle/help.c +++ b/games/boggle/boggle/help.c @@ -1,3 +1,4 @@ +/* $OpenBSD: help.c,v 1.2 1998/09/24 06:45:06 pjanzen Exp $ */ /* $NetBSD: help.c,v 1.2 1995/03/21 12:14:38 cgd Exp $ */ /*- @@ -40,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)help.c 8.1 (Berkeley) 6/11/93"; #else -static char rcsid[] = "$NetBSD: help.c,v 1.2 1995/03/21 12:14:38 cgd Exp $"; +static char rcsid[] = "$OpenBSD: help.c,v 1.2 1998/09/24 06:45:06 pjanzen Exp $"; #endif #endif /* not lint */ @@ -62,7 +63,7 @@ help() if ((fp = fopen(HELPFILE, "r")) == NULL) return(-1); win = newwin(0, 0, 0, 0); - clearok(win, 1); + clearok(win, TRUE); eof = 0; if (ungetc(getc(fp), fp) == EOF) { @@ -101,7 +102,8 @@ help() inputch(); } delwin(win); - clearok(stdscr, 1); + clearok(stdscr, TRUE); + touchwin(stdscr); refresh(); return(0); } diff --git a/games/boggle/boggle/helpfile b/games/boggle/boggle/helpfile index 39fcd7b949f..7144e514a72 100644 --- a/games/boggle/boggle/helpfile +++ b/games/boggle/boggle/helpfile @@ -55,21 +55,6 @@ The time limit can be changed from the default 3 minutes by using the flag '-t#', where # is the duration (in seconds) of each game. The minimum word length can be changed from 3 letters by specifying 'w#', where # is the minimum number of letters to use. -. - Bugs and Limitations - -The following bugs and problems are known to exist: - -- If there are a great many words in the cube the final display of the words - may scroll off of the screen. (On a 25 line screen about 130 words can be - displayed.) - -- Computing the complete word list can be too slow on small machines. - -- No word can contain a 'q' that is not immediately followed by a 'u'. - -- When using the '+' or '++' options the display of words found in the board - doesn't indicate reused cubes. . Copyright (c) 1988 Barry Brachman | UUCP: {alberta,uw-beaver,uunet}! diff --git a/games/boggle/boggle/mach.c b/games/boggle/boggle/mach.c index 74e0ecaa3d9..9e2a86349ba 100644 --- a/games/boggle/boggle/mach.c +++ b/games/boggle/boggle/mach.c @@ -1,3 +1,4 @@ +/* $OpenBSD: mach.c,v 1.3 1998/09/24 06:45:06 pjanzen Exp $ */ /* $NetBSD: mach.c,v 1.5 1995/04/28 22:28:48 mycroft Exp $ */ /*- @@ -40,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)mach.c 8.1 (Berkeley) 6/11/93"; #else -static char rcsid[] = "$NetBSD: mach.c,v 1.5 1995/04/28 22:28:48 mycroft Exp $"; +static char rcsid[] = "$OpenBSD: mach.c,v 1.3 1998/09/24 06:45:06 pjanzen Exp $"; #endif #endif /* not lint */ @@ -49,6 +50,8 @@ static char rcsid[] = "$NetBSD: mach.c,v 1.5 1995/04/28 22:28:48 mycroft Exp $"; * * Input is raw and unechoed */ +#include + #include #include #include @@ -97,7 +100,7 @@ setup(sflag, seed) time(&seed); srandom(seed); if (debug) - (void) printf("seed = %ld\n", seed); + (void) printf("seed = %ld\n", (long) seed); return(0); } diff --git a/games/boggle/boggle/prtable.c b/games/boggle/boggle/prtable.c index 9017b9decc3..5d83448c968 100644 --- a/games/boggle/boggle/prtable.c +++ b/games/boggle/boggle/prtable.c @@ -1,3 +1,4 @@ +/* $OpenBSD: prtable.c,v 1.4 1998/09/24 06:45:06 pjanzen Exp $ */ /* $NetBSD: prtable.c,v 1.2 1995/03/21 12:14:42 cgd Exp $ */ /*- diff --git a/games/boggle/boggle/timer.c b/games/boggle/boggle/timer.c index 6f9a0430734..8160eda534b 100644 --- a/games/boggle/boggle/timer.c +++ b/games/boggle/boggle/timer.c @@ -1,3 +1,4 @@ +/* $OpenBSD: timer.c,v 1.2 1998/09/24 06:45:06 pjanzen Exp $ */ /* $NetBSD: timer.c,v 1.3 1995/04/24 12:22:45 cgd Exp $ */ /*- @@ -40,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)timer.c 8.2 (Berkeley) 2/22/94"; #else -static char rcsid[] = "$NetBSD: timer.c,v 1.3 1995/04/24 12:22:45 cgd Exp $"; +static char rcsid[] = "$OpenBSD: timer.c,v 1.2 1998/09/24 06:45:06 pjanzen Exp $"; #endif #endif /* not lint */ diff --git a/games/boggle/boggle/word.c b/games/boggle/boggle/word.c index 9ad16f199e4..62d0d16aafb 100644 --- a/games/boggle/boggle/word.c +++ b/games/boggle/boggle/word.c @@ -1,3 +1,4 @@ +/* $OpenBSD: word.c,v 1.2 1998/09/24 06:45:06 pjanzen Exp $ */ /* $NetBSD: word.c,v 1.2 1995/03/21 12:14:45 cgd Exp $ */ /*- @@ -40,13 +41,14 @@ #if 0 static char sccsid[] = "@(#)word.c 8.1 (Berkeley) 6/11/93"; #else -static char rcsid[] = "$NetBSD: word.c,v 1.2 1995/03/21 12:14:45 cgd Exp $"; +static char rcsid[] = "$OpenBSD: word.c,v 1.2 1998/09/24 06:45:06 pjanzen Exp $"; #endif #endif /* not lint */ #include #include +#include #include #include #include @@ -171,7 +173,7 @@ loaddict(fp) } if (st < 0) { (void)fclose(fp); - (void)fprintf(stderr, "Error reading dictionary\n"); + warnx("Error reading dictionary"); return (-1); } *p = '\0'; @@ -194,27 +196,26 @@ loadindex(indexfile) extern struct dictindex dictindex[]; if ((fp = fopen(indexfile, "r")) == NULL) { - (void) fprintf(stderr, "Can't open '%s'\n", indexfile); + warnx("Can't open '%s'", indexfile); return (-1); } i = 0; while (fgets(buf, sizeof(buf), fp) != NULL) { if (strchr(buf, '\n') == NULL) { - (void)fprintf(stderr, - "A line in the index file is too long\n"); + warnx("A line in the index file is too long"); return(-1); } j = *buf - 'a'; if (i != j) { - (void) fprintf(stderr, "Bad index order\n"); - return(-1); + warnx("Bad index order"); + return(-1); } dictindex[j].start = atol(buf + 1); dictindex[j].length = atol(buf + 9) - dictindex[j].start; i++; } if (i != 26) { - (void) fprintf(stderr, "Bad index length\n"); + warnx("Bad index length"); return(-1); } (void) fclose(fp); diff --git a/games/boggle/mkdict/Makefile b/games/boggle/mkdict/Makefile index 825cbe81c3a..f6d23d27efa 100644 --- a/games/boggle/mkdict/Makefile +++ b/games/boggle/mkdict/Makefile @@ -1,3 +1,4 @@ +# $OpenBSD: Makefile,v 1.3 1998/09/24 06:45:06 pjanzen Exp $ # $NetBSD: Makefile,v 1.2 1995/03/21 12:14:47 cgd Exp $ # @(#)Makefile 8.1 (Berkeley) 6/11/93 diff --git a/games/boggle/mkdict/mkdict.c b/games/boggle/mkdict/mkdict.c index c0f3948a3db..561f0da39e9 100644 --- a/games/boggle/mkdict/mkdict.c +++ b/games/boggle/mkdict/mkdict.c @@ -1,3 +1,4 @@ +/* $OpenBSD: mkdict.c,v 1.3 1998/09/24 06:45:06 pjanzen Exp $ */ /* $NetBSD: mkdict.c,v 1.2 1995/03/21 12:14:49 cgd Exp $ */ /*- @@ -46,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mkdict.c 8.1 (Berkeley) 6/11/93"; #else -static char rcsid[] = "$NetBSD: mkdict.c,v 1.2 1995/03/21 12:14:49 cgd Exp $"; +static char rcsid[] = "$OpenBSD: mkdict.c,v 1.3 1998/09/24 06:45:06 pjanzen Exp $"; #endif #endif /* not lint */ @@ -59,6 +60,7 @@ static char rcsid[] = "$NetBSD: mkdict.c,v 1.2 1995/03/21 12:14:49 cgd Exp $"; */ #include +#include #include #include #include @@ -84,8 +86,7 @@ main(argc, argv) for (nwords = 1; fgets(buf[current], MAXWORDLEN + 1, stdin) != NULL; ++nwords) { if ((p = strchr(buf[current], '\n')) == NULL) { - fprintf(stderr, - "mkdict: word too long: %s\n", buf[current]); + warnx("word too long: %s", buf[current]); while ((ch = getc(stdin)) != EOF && ch != '\n') ; if (ch == EOF) @@ -101,7 +102,7 @@ main(argc, argv) if (*q != 'u') break; else { - while (*q = *(q + 1)) + while ((*q = *(q + 1))) q++; } len++; @@ -125,6 +126,6 @@ main(argc, argv) prev = !prev; current = !current; } - fprintf(stderr, "%d words\n", nwords); + warnx("%d words", nwords); exit(0); } diff --git a/games/boggle/mkindex/Makefile b/games/boggle/mkindex/Makefile index 90903fe1b79..68eedb21581 100644 --- a/games/boggle/mkindex/Makefile +++ b/games/boggle/mkindex/Makefile @@ -1,3 +1,4 @@ +# $OpenBSD: Makefile,v 1.3 1998/09/24 06:45:06 pjanzen Exp $ # $NetBSD: Makefile,v 1.2 1995/03/21 12:14:51 cgd Exp $ # @(#)Makefile 8.1 (Berkeley) 6/11/93 diff --git a/games/boggle/mkindex/mkindex.c b/games/boggle/mkindex/mkindex.c index 4d29da49cd4..4efaf57c7f3 100644 --- a/games/boggle/mkindex/mkindex.c +++ b/games/boggle/mkindex/mkindex.c @@ -1,3 +1,4 @@ +/* $OpenBSD: mkindex.c,v 1.2 1998/09/24 06:45:07 pjanzen Exp $ */ /* $NetBSD: mkindex.c,v 1.2 1995/03/21 12:14:52 cgd Exp $ */ /*- @@ -46,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mkindex.c 8.1 (Berkeley) 6/11/93"; #else -static char rcsid[] = "$NetBSD: mkindex.c,v 1.2 1995/03/21 12:14:52 cgd Exp $"; +static char rcsid[] = "$OpenBSD: mkindex.c,v 1.2 1998/09/24 06:45:07 pjanzen Exp $"; #endif #endif /* not lint */ diff --git a/games/tetris/Makefile b/games/tetris/Makefile index 5e1f1b71cab..473ec891619 100644 --- a/games/tetris/Makefile +++ b/games/tetris/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.4 1998/07/24 00:10:44 millert Exp $ +# $OpenBSD: Makefile,v 1.5 1998/09/24 06:45:07 pjanzen Exp $ PROG= tetris SRCS= input.c screen.c shapes.c scores.c tetris.c @@ -7,4 +7,12 @@ DPADD= ${LIBCURSES} LDADD= -lcurses HIDEGAME=hidegame +beforeinstall: + @if [ ! -f ${DESTDIR}/var/games/tetris.scores ]; then \ + ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 664 \ + /dev/null ${DESTDIR}/var/games/tetris.scores ; \ + else \ + true ; \ + fi + .include diff --git a/games/tetris/input.c b/games/tetris/input.c index 1f879419c42..63f15ec92aa 100644 --- a/games/tetris/input.c +++ b/games/tetris/input.c @@ -1,3 +1,4 @@ +/* $OpenBSD: input.c,v 1.3 1998/09/24 06:45:07 pjanzen Exp $ */ /* $NetBSD: input.c,v 1.3 1996/02/06 22:47:33 jtc Exp $ */ /*- diff --git a/games/tetris/input.h b/games/tetris/input.h index d9616b1d99f..25836409d44 100644 --- a/games/tetris/input.h +++ b/games/tetris/input.h @@ -1,3 +1,4 @@ +/* $OpenBSD: input.h,v 1.2 1998/09/24 06:45:07 pjanzen Exp $ */ /* $NetBSD: input.h,v 1.2 1995/04/22 07:42:36 cgd Exp $ */ /*- diff --git a/games/tetris/pathnames.h b/games/tetris/pathnames.h index 7425133e1c0..c3191fbf93c 100644 --- a/games/tetris/pathnames.h +++ b/games/tetris/pathnames.h @@ -1,3 +1,4 @@ +/* $OpenBSD: pathnames.h,v 1.2 1998/09/24 06:45:07 pjanzen Exp $ */ /* $NetBSD: pathnames.h,v 1.2 1995/04/22 07:42:37 cgd Exp $ */ /*- diff --git a/games/tetris/scores.c b/games/tetris/scores.c index 1dddd6408cf..4338ee2fa98 100644 --- a/games/tetris/scores.c +++ b/games/tetris/scores.c @@ -1,3 +1,4 @@ +/* $OpenBSD: scores.c,v 1.3 1998/09/24 06:45:07 pjanzen Exp $ */ /* $NetBSD: scores.c,v 1.2 1995/04/22 07:42:38 cgd Exp $ */ /*- @@ -46,19 +47,17 @@ * Major whacks since then. */ #include +#include #include #include #include #include #include #include +#include #include #include - -/* - * XXX - need a - */ -int tputs __P((const char *, int, int (*)(int))); +#include #include "pathnames.h" #include "screen.h" @@ -119,36 +118,29 @@ getscores(fpp) mask = umask(S_IWOTH); sd = open(_PATH_SCOREFILE, mint, 0666); (void)umask(mask); + setegid(gid); if (sd < 0) { if (fpp == NULL) { nscores = 0; return; } - (void)fprintf(stderr, "tetris: cannot open %s for %s: %s\n", - _PATH_SCOREFILE, human, strerror(errno)); - exit(1); - } - if ((sf = fdopen(sd, mstr)) == NULL) { - (void)fprintf(stderr, "tetris: cannot fdopen %s for %s: %s\n", - _PATH_SCOREFILE, human, strerror(errno)); - exit(1); + err(1, "cannot open %s for %s", _PATH_SCOREFILE, human); } + setegid(egid); + if ((sf = fdopen(sd, mstr)) == NULL) + err(1, "cannot fdopen %s for %s", _PATH_SCOREFILE, human); setegid(gid); /* * Grab a lock. */ if (flock(sd, lck)) - (void)fprintf(stderr, - "tetris: warning: score file %s cannot be locked: %s\n", - _PATH_SCOREFILE, strerror(errno)); + warn("warning: score file %s cannot be locked", + _PATH_SCOREFILE); nscores = fread(scores, sizeof(scores[0]), MAXHISCORES, sf); - if (ferror(sf)) { - (void)fprintf(stderr, "tetris: error reading %s: %s\n", - _PATH_SCOREFILE, strerror(errno)); - exit(1); - } + if (ferror(sf)) + err(1, "error reading %s", _PATH_SCOREFILE); if (fpp) *fpp = sf; @@ -212,8 +204,7 @@ savescore(level) rewind(sf); if (fwrite(scores, sizeof(*sp), nscores, sf) != nscores || fflush(sf) == EOF) - (void)fprintf(stderr, - "tetris: error writing %s: %s -- %s\n", + warnx("error writing %s: %s -- %s\n", _PATH_SCOREFILE, strerror(errno), "high scores may be damaged"); } @@ -245,7 +236,7 @@ thisuser() l = strlen(p); if (l >= sizeof(u)) l = sizeof(u) - 1; - bcopy(p, u, l); + memcpy(u, p, l); u[l] = '\0'; return (u); } diff --git a/games/tetris/scores.h b/games/tetris/scores.h index 387d02185ac..de4dc5c5fd8 100644 --- a/games/tetris/scores.h +++ b/games/tetris/scores.h @@ -1,3 +1,4 @@ +/* $OpenBSD: scores.h,v 1.2 1998/09/24 06:45:07 pjanzen Exp $ */ /* $NetBSD: scores.h,v 1.2 1995/04/22 07:42:40 cgd Exp $ */ /*- diff --git a/games/tetris/screen.c b/games/tetris/screen.c index 99a9d3e71d4..b2985cf31f1 100644 --- a/games/tetris/screen.c +++ b/games/tetris/screen.c @@ -1,3 +1,4 @@ +/* $OpenBSD: screen.c,v 1.2 1998/09/24 06:45:07 pjanzen Exp $ */ /* $NetBSD: screen.c,v 1.4 1995/04/29 01:11:36 mycroft Exp $ */ /*- @@ -44,11 +45,13 @@ #include +#include #include #include #include #include #include +#include #include #include @@ -59,22 +62,14 @@ #include "screen.h" #include "tetris.h" -/* - * XXX - need a - */ -int tgetent __P((char *, const char *)); -int tgetflag __P((const char *)); -int tgetnum __P((const char *)); -int tputs __P((const char *, int, int (*)(int))); - static cell curscreen[B_SIZE]; /* 1 => standout (or otherwise marked) */ static int curscore; static int isset; /* true => terminal is in game mode */ static struct termios oldtt; -static void (*tstp)(); - -char *tgetstr(), *tgoto(); +static void (*tstp) __P((int)); +static void scr_stop __P((int)); +static void stopset __P((int)); /* * Capabilities from TERMCAP. @@ -108,21 +103,21 @@ struct tcsinfo { /* termcap string info; some abbrevs above */ char tcname[3]; char **tcaddr; } tcstrings[] = { - "bc", &bcstr, - "ce", &CEstr, - "cl", &CLstr, - "cm", &CMstr, + {"bc", &bcstr}, + {"ce", &CEstr}, + {"cl", &CLstr}, + {"cm", &CMstr}, #ifdef unneeded - "cr", &CRstr, + {"cr", &CRstr}, #endif - "le", &BC, /* move cursor left one space */ - "pc", &pcstr, - "se", &SEstr, - "so", &SOstr, - "te", &TEstr, - "ti", &TIstr, - "up", &UP, /* cursor up */ - 0 + {"le", &BC}, /* move cursor left one space */ + {"pc", &pcstr}, + {"se", &SEstr}, + {"so", &SOstr}, + {"te", &TEstr}, + {"ti", &TIstr}, + {"up", &UP}, /* cursor up */ + { {0}, NULL} }; /* This is where we will actually stuff the information */ @@ -164,18 +159,18 @@ scr_init() char tcname[3]; int *tcaddr; } tcflags[] = { - "bs", &bsflag, - "ms", &MSflag, + {"bs", &bsflag}, + {"ms", &MSflag}, #ifdef unneeded - "nc", &ncflag, + {"nc", &ncflag}, #endif - "xs", &xsflag, - 0 + {"xs", &xsflag}, + { {0}, NULL} }, tcnums[] = { - "co", &COnum, - "li", &LInum, - "sg", &sgnum, - 0 + {"co", &COnum}, + {"li", &LInum}, + {"sg", &sgnum}, + { {0}, NULL} }; if ((term = getenv("TERM")) == NULL) @@ -257,7 +252,7 @@ scr_set() struct winsize ws; struct termios newtt; sigset_t sigset, osigset; - void (*ttou)(); + void (*ttou) __P((int)); sigemptyset(&sigset); sigaddset(&sigset, SIGTSTP); @@ -350,8 +345,7 @@ stop(why) if (isset) scr_end(); - (void) fprintf(stderr, "aborting: %s\n", why); - exit(1); + errx(1, "aborting: %s", why); } /* @@ -363,7 +357,7 @@ scr_clear() putpad(CLstr); curscore = -1; - bzero((char *)curscreen, sizeof(curscreen)); + memset((char *)curscreen, 0, sizeof(curscreen)); } #if vax && !__GNUC__ diff --git a/games/tetris/screen.h b/games/tetris/screen.h index 7bb10ae1261..efe382da9f6 100644 --- a/games/tetris/screen.h +++ b/games/tetris/screen.h @@ -1,3 +1,4 @@ +/* $OpenBSD: screen.h,v 1.2 1998/09/24 06:45:07 pjanzen Exp $ */ /* $NetBSD: screen.h,v 1.2 1995/04/22 07:42:42 cgd Exp $ */ /*- diff --git a/games/tetris/shapes.c b/games/tetris/shapes.c index 8e4525cc911..f5d9f4e3d56 100644 --- a/games/tetris/shapes.c +++ b/games/tetris/shapes.c @@ -1,3 +1,4 @@ +/* $OpenBSD: shapes.c,v 1.3 1998/09/24 06:45:07 pjanzen Exp $ */ /* $NetBSD: shapes.c,v 1.2 1995/04/22 07:42:44 cgd Exp $ */ /*- @@ -57,25 +58,25 @@ #define BR B_COLS+1 /* bottom right */ struct shape shapes[] = { - /* 0*/ 7, TL, TC, MR, - /* 1*/ 8, TC, TR, ML, - /* 2*/ 9, ML, MR, BC, - /* 3*/ 3, TL, TC, ML, - /* 4*/ 12, ML, BL, MR, - /* 5*/ 15, ML, BR, MR, - /* 6*/ 18, ML, MR, /* sticks out */ 2, - /* 7*/ 0, TC, ML, BL, - /* 8*/ 1, TC, MR, BR, - /* 9*/ 10, TC, MR, BC, - /*10*/ 11, TC, ML, MR, - /*11*/ 2, TC, ML, BC, - /*12*/ 13, TC, BC, BR, - /*13*/ 14, TR, ML, MR, - /*14*/ 4, TL, TC, BC, - /*15*/ 16, TR, TC, BC, - /*16*/ 17, TL, MR, ML, - /*17*/ 5, TC, BC, BL, - /*18*/ 6, TC, BC, /* sticks out */ 2*B_COLS, + /* 0*/ { 7, { TL, TC, MR } }, + /* 1*/ { 8, { TC, TR, ML } }, + /* 2*/ { 9, { ML, MR, BC } }, + /* 3*/ { 3, { TL, TC, ML } }, + /* 4*/ { 12, { ML, BL, MR } }, + /* 5*/ { 15, { ML, BR, MR } }, + /* 6*/ { 18, { ML, MR, 2 } }, /* sticks out */ + /* 7*/ { 0, { TC, ML, BL } }, + /* 8*/ { 1, { TC, MR, BR } }, + /* 9*/ { 10, { TC, MR, BC } }, + /*10*/ { 11, { TC, ML, MR } }, + /*11*/ { 2, { TC, ML, BC } }, + /*12*/ { 13, { TC, BC, BR } }, + /*13*/ { 14, { TR, ML, MR } }, + /*14*/ { 4, { TL, TC, BC } }, + /*15*/ { 16, { TR, TC, BC } }, + /*16*/ { 17, { TL, MR, ML } }, + /*17*/ { 5, { TC, BC, BL } }, + /*18*/ { 6, { TC, BC, 2*B_COLS } }/* sticks out */ }; /* diff --git a/games/tetris/tetris.6 b/games/tetris/tetris.6 index 1a6ecd5aa97..ad78e53b871 100644 --- a/games/tetris/tetris.6 +++ b/games/tetris/tetris.6 @@ -1,4 +1,4 @@ -.\" $NetBSD: tetris.6,v 1.2 1995/04/22 07:42:45 cgd Exp $ +.\" $OpenBSD: tetris.6,v 1.4 1998/09/24 06:45:07 pjanzen Exp $ .\" .\" Copyright (c) 1992, 1993 .\" The Regents of the University of California. All rights reserved. @@ -50,11 +50,11 @@ .Sh DESCRIPTION The .Nm -command runs display-based game which must be played on a CRT terminal. -The object is to fit the shapes together forming complete rows, +command runs a display-based game. +The object is to fit shapes together to form complete rows, which then vanish. When the shapes fill up to the top, the game ends. -You can optionally select a level of play, or custom-select control keys. +You can optionally select a level of play or custom-select control keys. .Pp The default level of play is 2. .Pp @@ -83,13 +83,13 @@ The default control keys can be changed using the option. The .Ar keys -argument must have the six keys in order, and, remember to quote any +argument must have the six keys in order; remember to quote any space or tab characters from the shell. For example: .sp .Dl "tetris -l 2 -k 'jkl pq'" .sp -will play the default games, i.e. level 2 and with the default +will play the default game, i.e. level 2 with the default control keys. The current key settings are displayed at the bottom of the screen during play. diff --git a/games/tetris/tetris.c b/games/tetris/tetris.c index 4756bb1ef0a..d8274180879 100644 --- a/games/tetris/tetris.c +++ b/games/tetris/tetris.c @@ -1,3 +1,4 @@ +/* $OpenBSD: tetris.c,v 1.4 1998/09/24 06:45:08 pjanzen Exp $ */ /* $NetBSD: tetris.c,v 1.2 1995/04/22 07:42:47 cgd Exp $ */ /*- @@ -49,7 +50,9 @@ static char copyright[] = */ #include +#include +#include #include #include #include @@ -61,8 +64,10 @@ static char copyright[] = #include "screen.h" #include "tetris.h" -void onintr __P((int)); -void usage __P((void)); +static void elide __P((void)); +static void setup_board __P((void)); +void onintr __P((int)); +void usage __P((void)); /* * Set up the initial board. The bottom display row is completely set, @@ -99,7 +104,7 @@ elide() for (j = B_COLS - 2; *p++ != 0;) { if (--j <= 0) { /* this row is to be elided */ - bzero(&board[base], B_COLS - 2); + memset(&board[base], 0, B_COLS - 2); scr_update(); tsleep(); while (--base != 0) @@ -130,7 +135,7 @@ main(argc, argv) egid = getegid(); setegid(gid); - while ((ch = getopt(argc, argv, "k:l:s")) != -1) + while ((ch = getopt(argc, argv, "hk:l:s")) != -1) switch(ch) { case 'k': if (strlen(keys = optarg) != 6) @@ -138,17 +143,15 @@ main(argc, argv) break; case 'l': level = atoi(optarg); - if (level < MINLEVEL || level > MAXLEVEL) { - (void)fprintf(stderr, - "tetris: level must be from %d to %d", + if (level < MINLEVEL || level > MAXLEVEL) + errx(1, "level must be from %d to %d", MINLEVEL, MAXLEVEL); - exit(1); - } break; case 's': showscores(0); exit(0); case '?': + case 'h': default: usage(); } @@ -163,12 +166,8 @@ main(argc, argv) 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); - } + if (keys[i] == keys[j]) + errx(1, "Duplicate command keys specified."); } if (keys[i] == ' ') strcpy(key_write[i], ""); @@ -313,6 +312,6 @@ onintr(signo) void usage() { - (void)fprintf(stderr, "usage: tetris [-s] [-l level] [-keys]\n"); + (void)fprintf(stderr, "usage: tetris [-s] [-l level] [-k keys]\n"); exit(1); } diff --git a/games/tetris/tetris.h b/games/tetris/tetris.h index 1e995c32a64..15523f0c67f 100644 --- a/games/tetris/tetris.h +++ b/games/tetris/tetris.h @@ -1,3 +1,4 @@ +/* $OpenBSD: tetris.h,v 1.3 1998/09/24 06:45:08 pjanzen Exp $ */ /* $NetBSD: tetris.h,v 1.2 1995/04/22 07:42:48 cgd Exp $ */ /*- -- cgit v1.2.3