diff options
-rw-r--r-- | games/banner/banner.6 | 2 | ||||
-rw-r--r-- | games/caesar/caesar.c | 87 | ||||
-rw-r--r-- | games/rain/Makefile | 6 | ||||
-rw-r--r-- | games/rain/rain.6 | 6 | ||||
-rw-r--r-- | games/worms/worms.6 | 4 |
5 files changed, 63 insertions, 42 deletions
diff --git a/games/banner/banner.6 b/games/banner/banner.6 index 0e2de635dc4..3c991aa83f2 100644 --- a/games/banner/banner.6 +++ b/games/banner/banner.6 @@ -68,5 +68,7 @@ The option is implemented by skipping some rows and columns. The smaller it gets, the grainier the output. Sometimes it runs letters together. +.Sh SEE ALSO +.Xr banner 1 .Sh AUTHOR Mark Horton diff --git a/games/caesar/caesar.c b/games/caesar/caesar.c index 604883f6fa1..57894c909c7 100644 --- a/games/caesar/caesar.c +++ b/games/caesar/caesar.c @@ -55,10 +55,13 @@ static char rcsid[] = "$NetBSD: caesar.c,v 1.4 1996/02/06 22:47:15 jtc Exp $"; #endif #endif /* not lint */ +#include <stdlib.h> +#include <string.h> #include <math.h> #include <stdio.h> #include <ctype.h> #include <unistd.h> +#include <err.h> #include <errno.h> #define LINELENGTH 2048 @@ -76,40 +79,51 @@ double stdf[26] = { 2.62, 0.81, 1.88, 0.23, 2.07, 0.06, }; +void printit __P((int)); +void usage __P(()); + + +int main(argc, argv) int argc; char **argv; { - register int ch, dot, i, nread, winnerdot; - register char *inbuf; + register int ch, dot, i, nread, winnerdot = 0; + register char *inbuf, *p, **av; int obs[26], try, winner; - char *malloc(), *strerror(); /* revoke privs */ setegid(getgid()); setgid(getgid()); - if (argc > 1) - printit(argv[1]); - - if (!(inbuf = malloc(LINELENGTH))) { - (void)fprintf(stderr, "caesar: out of memory.\n"); - exit(1); + if (argc > 1) { + if ((i = atoi(argv[1]))) + printit(atoi(argv[1])); + else + usage(); } + /* check to see if we were called as rot13 */ + av = argv; + p = strrchr(*av, '/'); + if (p++ == NULL) + p = *av; + if (strcmp(p,"rot13") == 0) + printit(13); + + if (!(inbuf = malloc(LINELENGTH))) + errx(1, "out of memory."); + /* adjust frequency table to weight low probs REAL low */ for (i = 0; i < 26; ++i) stdf[i] = log(stdf[i]) + log(26.0 / 100.0); /* zero out observation table */ - bzero(obs, 26 * sizeof(int)); + memset(obs, 0, 26 * sizeof(int)); - if ((nread = read(STDIN_FILENO, inbuf, LINELENGTH)) < 0) { - (void)fprintf(stderr, "caesar: %s\n", strerror(errno)); - exit(1); - } - for (i = nread; i--;) { - ch = inbuf[i]; + nread = 0; + while ((nread < LINELENGTH) && ((ch = getchar()) != EOF)) { + inbuf[nread++] = ch; if (islower(ch)) ++obs[ch - 'a']; else if (isupper(ch)) @@ -124,9 +138,6 @@ main(argc, argv) dot = 0; for (i = 0; i < 26; i++) dot += obs[i] * stdf[(i + try) % 26]; - /* initialize winning score */ - if (try == 0) - winnerdot = dot; if (dot > winnerdot) { /* got a new winner! */ winner = try; @@ -134,31 +145,31 @@ main(argc, argv) } } - for (;;) { - for (i = 0; i < nread; ++i) { - ch = inbuf[i]; - putchar(ROTATE(ch, winner)); - } - if (nread < LINELENGTH) - break; - if ((nread = read(STDIN_FILENO, inbuf, LINELENGTH)) < 0) { - (void)fprintf(stderr, "caesar: %s\n", strerror(errno)); - exit(1); - } + /* dump the buffer before calling printit */ + for (i = 0; i < nread; ++i) { + ch = inbuf[i]; + putchar(ROTATE(ch, winner)); } - exit(0); + printit(winner); + /* NOT REACHED */ } -printit(arg) - char *arg; +void +printit(int rot) { - register int ch, rot; + register int ch; - if ((rot = atoi(arg)) < 0) { - (void)fprintf(stderr, "caesar: bad rotation value.\n"); - exit(1); - } + if ((rot < 0) || ( rot >= 26)) + errx(1, "bad rotation value"); + while ((ch = getchar()) != EOF) putchar(ROTATE(ch, rot)); exit(0); } + +void +usage() +{ + fprintf(stderr,"usage: caesar [rotation]\n"); + exit(1); +} diff --git a/games/rain/Makefile b/games/rain/Makefile index b116f03e850..070cedf16ef 100644 --- a/games/rain/Makefile +++ b/games/rain/Makefile @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile,v 1.3 1997/09/21 11:36:48 deraadt Exp $ +# $OpenBSD: Makefile,v 1.4 1998/02/22 13:16:40 deraadt Exp $ PROG= rain MAN= rain.6 -DPADD= ${LIBTERMCAP} ${LIBCOMPAT} -LDADD= -ltermcap -lcompat +DPADD= ${LIBTERMLIB} +LDADD= -ltermlib .include <bsd.prog.mk> diff --git a/games/rain/rain.6 b/games/rain/rain.6 index 2ba613458b3..db3fcf6767f 100644 --- a/games/rain/rain.6 +++ b/games/rain/rain.6 @@ -46,7 +46,11 @@ display is modeled after the .Tn VAX/VMS program of the same name. -The terminal has to be set for 9600 baud to obtain the proper effect. +To obtain the proper effect, either the terminal must be set for 9600 baud +or the +.Nm -d +option must be used to specify a delay, in milliseconds, between each update. A +reasonable delay is 120; the default is 0. .Pp As with all programs that use .Tn termcap , diff --git a/games/worms/worms.6 b/games/worms/worms.6 index 4a757bedba3..66a77398b4b 100644 --- a/games/worms/worms.6 +++ b/games/worms/worms.6 @@ -41,6 +41,7 @@ .Sh SYNOPSIS .Nm worms .Op Fl ft +.Op Fl d Ar delay .Op Fl l Ar length .Op Fl n Ar number .Sh DESCRIPTION @@ -54,6 +55,9 @@ The options are as follows: Makes a ``field'' for the worm(s) to eat. .It Fl t Makes each worm leave a trail behind it. +.It Fl d +Specifies a delay, in milliseconds, between each update. This is useful for +fast terminals. Reasonable values are around 20-200. The default is 0. .It Fl l Specifies a length for each worm; the default is 16. .It Fl n |