diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1998-02-14 20:40:43 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1998-02-14 20:40:43 +0000 |
commit | 120f15f4d62ba4f717d7c7095fa9741a9a639d92 (patch) | |
tree | 3b12b660d82c13f96cb9d4d94dc3bdc0a1eef981 /games | |
parent | 6de8cb0481bd793706e38dead271f9233a57b7e5 (diff) |
further fixes from pjanzen@foatdi.harvard.edu
Diffstat (limited to 'games')
-rw-r--r-- | games/rain/rain.c | 66 | ||||
-rw-r--r-- | games/worms/worms.c | 33 | ||||
-rw-r--r-- | games/wump/wump.c | 2 |
3 files changed, 70 insertions, 31 deletions
diff --git a/games/rain/rain.c b/games/rain/rain.c index b8e2d03e340..56f2052be4e 100644 --- a/games/rain/rain.c +++ b/games/rain/rain.c @@ -54,16 +54,21 @@ static char rcsid[] = "$NetBSD: rain.c,v 1.7 1995/04/29 00:51:04 mycroft Exp $"; #include <sys/types.h> #include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <term.h> #include <termios.h> #include <signal.h> +#include <string.h> #define cursor(c, r) tputs(tgoto(CM, c, r), 1, fputchar) static struct termios sg, old_tty; -void fputchar __P((int)); -char *LL, *TE, *tgoto(); +int fputchar __P((int)); +char *LL, *TE, *VE; +int main(argc, argv) int argc; char **argv; @@ -72,9 +77,12 @@ main(argc, argv) extern char *UP; register int x, y, j; register char *CM, *BC, *DN, *ND, *term; - char *TI, *tcp, *mp, tcb[100], - *malloc(), *getenv(), *strcpy(), *tgetstr(); - long cols, lines, random(); + char *TI, *tcp, *mp, tcb[100]; + long tcols, tlines; + u_int delay = 0; + extern int optind; + extern char *optarg; + char ch; int xpos[5], ypos[5]; static void onsig(); #ifdef TIOCGWINSZ @@ -85,6 +93,22 @@ main(argc, argv) setegid(getgid()); setgid(getgid()); + while ((ch = getopt(argc, argv, "d:h")) != -1) + switch(ch) { + case 'd': + if ((delay = (u_int)strtoul(optarg,(char **)NULL,10)) < 1 + || delay > 1000) { + (void)fprintf(stderr,"rain: invalid delay (1-1000)\n"); + exit(1); + } + delay *= 1000; /* ms -> us */ + break; + case 'h': + default: + (void)fprintf(stderr,"usage: rain [-d delay]\n"); + exit(1); + } + if (!(term = getenv("TERM"))) { fprintf(stderr, "%s: TERM: parameter not set\n", *argv); exit(1); @@ -108,21 +132,22 @@ main(argc, argv) DN = "\n"; if (!(ND = tgetstr("nd", &tcp))) ND = " "; + VE = tgetstr("ve", &tcp); #ifdef TIOCGWINSZ if (ioctl(fileno(stdout), TIOCGWINSZ, &ws) != -1 && ws.ws_col && ws.ws_row) { - cols = ws.ws_col; - lines = ws.ws_row; + tcols = ws.ws_col; + tlines = ws.ws_row; } else #endif { - if ((cols = tgetnum("co")) == -1) - cols = 80; - if ((lines = tgetnum("li")) == -1) - lines = 24; + if ((tcols = tgetnum("co")) == -1) + tcols = 80; + if ((tlines = tgetnum("li")) == -1) + tlines = 24; } - cols -= 4; - lines -= 4; + tcols -= 4; + tlines -= 4; TE = tgetstr("te", &tcp); TI = tgetstr("ti", &tcp); UP = tgetstr("up", &tcp); @@ -149,14 +174,15 @@ main(argc, argv) if (TI) tputs(TI, 1, fputchar); tputs(tgetstr("cl", &tcp), 1, fputchar); + tputs(tgetstr("vi", &tcp), 1, fputchar); (void)fflush(stdout); for (j = 4; j >= 0; --j) { - xpos[j] = random() % cols + 2; - ypos[j] = random() % lines + 2; + xpos[j] = random() % tcols + 2; + ypos[j] = random() % tlines + 2; } for (j = 0;;) { - x = random() % cols + 2; - y = random() % lines + 2; + x = random() % tcols + 2; + y = random() % tlines + 2; cursor(x, y); fputchar('.'); cursor(xpos[j], ypos[j]); @@ -220,12 +246,14 @@ main(argc, argv) xpos[j] = x; ypos[j] = y; (void)fflush(stdout); + if (delay) usleep(delay); } } static void onsig() { + tputs(VE, 1, fputchar); tputs(LL, 1, fputchar); if (TE) tputs(TE, 1, fputchar); @@ -234,9 +262,9 @@ onsig() exit(0); } -void +int fputchar(c) int c; { - (void)putchar(c); + return(putchar(c)); } diff --git a/games/worms/worms.c b/games/worms/worms.c index f99c232b886..c7b4fc3056b 100644 --- a/games/worms/worms.c +++ b/games/worms/worms.c @@ -70,7 +70,7 @@ static char rcsid[] = "$NetBSD: worms.c,v 1.8 1995/04/22 08:09:22 cgd Exp $"; #include <signal.h> #include <stdio.h> #include <stdlib.h> -#include <termios.h> +#include <term.h> #include <unistd.h> static struct options { @@ -183,11 +183,9 @@ static struct worm { short *xpos, *ypos; } *worm; -void fputchar __P((int)); +int fputchar __P((int)); void onsig __P((int)); -char *tgetstr __P((char *, char **)); -char *tgoto __P((char *, int, int)); -int tputs __P((char *, int, void (*)(int))); +void nomem __P(()); int main(argc, argv) @@ -206,6 +204,7 @@ main(argc, argv) char *AL, *BC, *CM, *EI, *HO, *IC, *IM, *IP, *SR; char *field, tcb[100], *mp; long random(); + u_int delay = 0; struct termios ti; #ifdef TIOCGWINSZ struct winsize ws; @@ -219,8 +218,16 @@ main(argc, argv) number = 3; trail = ' '; field = NULL; - while ((ch = getopt(argc, argv, "fl:n:t")) != -1) + while ((ch = getopt(argc, argv, "d:fhl:n:t")) != -1) switch(ch) { + case 'd': + if ((delay = (u_int)strtoul(optarg,(char **)NULL,10)) < 1 + || delay > 1000) { + (void)fprintf(stderr,"worms: invalid delay (1-1000)\n"); + exit(1); + } + delay *= 1000; /* ms -> us */ + break; case 'f': field = "WORM"; break; @@ -242,10 +249,10 @@ main(argc, argv) case 't': trail = '.'; break; - case '?': + case '?': case 'h': default: (void)fprintf(stderr, - "usage: worms [-ft] [-l length] [-n number]\n"); + "usage: worms [-ft] [-d delay] [-l length] [-n number]\n"); exit(1); } @@ -329,6 +336,7 @@ main(argc, argv) tputs(tgetstr("ti", &tcp), 1, fputchar); tputs(tgetstr("cl", &tcp), 1, fputchar); + tputs(tgetstr("vi", &tcp), 1, fputchar); if (field) { register char *p = field; @@ -394,6 +402,7 @@ main(argc, argv) } for (;;) { (void)fflush(stdout); + if (delay) usleep(delay); for (n = 0, w = &worm[0]; n < number; n++, w++) { if ((x = w->xpos[h = w->head]) < 0) { cursor(x = w->xpos[h] = 0, @@ -421,7 +430,7 @@ main(argc, argv) case 0: (void)fflush(stdout); abort(); - return; + return(0); case 1: w->orientation = op->opts[0]; break; @@ -442,18 +451,20 @@ void onsig(signo) int signo; { + tputs(tgetstr("ve", &tcp), 1, fputchar); tputs(tgetstr("cl", &tcp), 1, fputchar); tputs(tgetstr("te", &tcp), 1, fputchar); exit(0); } -void +int fputchar(c) int c; { - (void)putchar(c); + return(putchar(c)); } +void nomem() { (void)fprintf(stderr, "worms: not enough memory.\n"); diff --git a/games/wump/wump.c b/games/wump/wump.c index 29177b3d1b3..4b7994d9b9a 100644 --- a/games/wump/wump.c +++ b/games/wump/wump.c @@ -578,7 +578,7 @@ cave_init() cave[i].tunnel[j] = -1; /* choose a random 'hop' delta for our guaranteed link */ - while (!(delta = random() % (room_num - 1))); + while (!(delta = random() % ((room_num - 1) / 2))); for (i = 1; i <= room_num; ++i) { link = ((i + delta) % room_num) + 1; /* connection */ |