summaryrefslogtreecommitdiffstats
path: root/worms
diff options
context:
space:
mode:
authorcgd <cgd@NetBSD.org>1995-04-22 08:00:54 +0000
committercgd <cgd@NetBSD.org>1995-04-22 08:00:54 +0000
commita74d1c0ac1878b07db35d5fdcc2fca6476b89cda (patch)
treece010a1e1d6d963bffc9425bb40f5f42a158d669 /worms
parenteca13b621f4cb1080cd5a74cc3e8bb5225935ef0 (diff)
downloadbsdgames-darwin-a74d1c0ac1878b07db35d5fdcc2fca6476b89cda.tar.gz
bsdgames-darwin-a74d1c0ac1878b07db35d5fdcc2fca6476b89cda.tar.zst
bsdgames-darwin-a74d1c0ac1878b07db35d5fdcc2fca6476b89cda.zip
rough cleanup of import. RCS Ids
Diffstat (limited to 'worms')
-rw-r--r--worms/Makefile4
-rw-r--r--worms/worms.636
-rw-r--r--worms/worms.c64
3 files changed, 55 insertions, 49 deletions
diff --git a/worms/Makefile b/worms/Makefile
index e2bd525f..ea9c3bf2 100644
--- a/worms/Makefile
+++ b/worms/Makefile
@@ -1,5 +1,5 @@
-# from: @(#)Makefile 5.3 (Berkeley) 5/11/90
-# $Id: Makefile,v 1.4 1994/12/22 09:36:35 cgd Exp $
+# $NetBSD: Makefile,v 1.5 1995/04/22 08:00:54 cgd Exp $
+# @(#)Makefile 8.1 (Berkeley) 5/31/93
PROG= worms
MAN= worms.6
diff --git a/worms/worms.6 b/worms/worms.6
index 9368eb58..f2f68158 100644
--- a/worms/worms.6
+++ b/worms/worms.6
@@ -1,5 +1,7 @@
-.\" Copyright (c) 1989 The Regents of the University of California.
-.\" All rights reserved.
+.\" $NetBSD: worms.6,v 1.5 1995/04/22 08:00:57 cgd Exp $
+.\"
+.\" Copyright (c) 1989, 1993
+.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -29,10 +31,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" from: @(#)worms.6 6.4 (Berkeley) 6/23/90
-.\" $Id: worms.6,v 1.4 1995/01/31 15:54:01 jtc Exp $
+.\" @(#)worms.6 8.1 (Berkeley) 5/31/93
.\"
-.Dd June 23, 1990
+.Dd May 31, 1993
.Dt WORMS 6
.Os
.Sh NAME
@@ -44,27 +45,20 @@
.Op Fl l Ar #
.Op Fl n Ar #
.Sh DESCRIPTION
-Brian Horn (cithep!bdh) showed me a
-.Tn TOPS-20
-program on the DEC-2136 machine called
-.Nm WORM ,
-and suggested that I write a similar program that would run under
-.Ux .
-I did, and no apologies.
+A
+.Tn UNIX
+version of the DEC-2136 program ``worms''.
.Pp
The options are as follows:
.Bl -tag -width indent
.It Fl f
-makes a ``field'' for the worm(s) to eat.
+Makes a ``field'' for the worm(s) to eat.
.It Fl t
-causes each worm to leave a trail behind it.
-.It Fl n Ar #
-start # worms.
-.It Fl l Ar #
-worms are # chars long.
-.El
-.Sh AUTHOR
-Eric P. Scott
+Makes each worm leave a trail behind it.
+.It Fl l
+Specifies a length for each worm; the default is 16.
+.It Fl n
+Specifies the number of worms; the default is 3.
.Sh BUGS
The lower-right-hand character position will not be updated properly
on a terminal that wraps at the right margin.
diff --git a/worms/worms.c b/worms/worms.c
index 959106b4..2f2e3272 100644
--- a/worms/worms.c
+++ b/worms/worms.c
@@ -1,6 +1,8 @@
+/* $NetBSD: worms.c,v 1.6 1995/04/22 08:00:58 cgd Exp $ */
+
/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,14 +34,17 @@
*/
#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1980 Regents of the University of California.\n\
- All rights reserved.\n";
+static char copyright[] =
+"@(#) Copyright (c) 1980, 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
-/*static char sccsid[] = "from: @(#)worms.c 5.9 (Berkeley) 2/28/91";*/
-static char rcsid[] = "$Id: worms.c,v 1.5 1995/01/31 15:54:02 jtc Exp $";
+#if 0
+static char sccsid[] = "@(#)worms.c 8.1 (Berkeley) 5/31/93";
+#else
+static char rcsid[] = "$NetBSD: worms.c,v 1.6 1995/04/22 08:00:58 cgd Exp $";
+#endif
#endif /* not lint */
/*
@@ -60,11 +65,11 @@ static char rcsid[] = "$Id: worms.c,v 1.5 1995/01/31 15:54:02 jtc Exp $";
*
*/
#include <sys/types.h>
+
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
-#include <termios.h>
-#include <signal.h>
-#include <sys/ioctl.h>
+#include <unistd.h>
static struct options {
int nopts;
@@ -163,7 +168,6 @@ static struct options {
#define cursor(c, r) tputs(tgoto(CM, c, r), 1, putchar)
char *tcp;
-
static char flavor[] = {
'O', '*', '#', '$', '%', '0', '@', '~'
};
@@ -177,11 +181,16 @@ static struct worm {
short *xpos, *ypos;
} *worm;
-char *tgetstr(), *tgoto();
+void 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)));
+int
main(argc, argv)
int argc;
- char **argv;
+ char *argv[];
{
extern int optind;
extern char *optarg, *UP;
@@ -191,15 +200,10 @@ main(argc, argv)
register short *ip;
register char *term;
int CO, IN, LI, last, bottom, ch, length, number, trail, Wrap;
- void onsig();
short **ref;
char *AL, *BC, *CM, *EI, *HO, *IC, *IM, *IP, *SR;
char *field, tcb[100], *mp;
long random();
- struct termios ti;
-#ifdef TIOCGWINSZ
- struct winsize ws;
-#endif
length = 16;
number = 3;
@@ -231,7 +235,7 @@ main(argc, argv)
case '?':
default:
(void)fprintf(stderr,
- "usage: worms [-ft] [-l #] [-n #]\n");
+ "usage: worms [-ft] [-l length] [-n number]\n");
exit(1);
}
@@ -239,8 +243,8 @@ main(argc, argv)
(void)fprintf(stderr, "worms: no TERM environment variable.\n");
exit(1);
}
- if (!(worm = (struct worm *)malloc((u_int)number *
- sizeof(struct worm))) || !(mp = malloc((u_int)1024)))
+ if (!(worm = malloc((size_t)number *
+ sizeof(struct worm))) || !(mp = malloc((size_t)1024)))
nomem();
if (tgetent(mp, term) <= 0) {
(void)fprintf(stderr, "worms: %s: unknown terminal type.\n",
@@ -280,9 +284,9 @@ main(argc, argv)
bottom = LI - 1;
tcgetattr(fileno(stdout), &ti);
Wrap = tgetflag("am");
- if (!(ip = (short *)malloc((u_int)(LI * CO * sizeof(short)))))
+ if (!(ip = malloc((size_t)(LI * CO * sizeof(short)))))
nomem();
- if (!(ref = (short **)malloc((u_int)(LI * sizeof(short *)))))
+ if (!(ref = malloc((size_t)(LI * sizeof(short *)))))
nomem();
for (n = 0; n < LI; ++n) {
ref[n] = ip;
@@ -294,12 +298,12 @@ main(argc, argv)
ref[bottom][last] = 1;
for (n = number, w = &worm[0]; --n >= 0; w++) {
w->orientation = w->head = 0;
- if (!(ip = (short *)malloc((u_int)(length * sizeof(short)))))
+ if (!(ip = malloc((size_t)(length * sizeof(short)))))
nomem();
w->xpos = ip;
for (x = length; --x >= 0;)
*ip++ = -1;
- if (!(ip = (short *)malloc((u_int)(length * sizeof(short)))))
+ if (!(ip = malloc((size_t)(length * sizeof(short)))))
nomem();
w->ypos = ip;
for (y = length; --y >= 0;)
@@ -425,13 +429,21 @@ main(argc, argv)
}
void
-onsig()
+onsig(signo)
+ int signo;
{
tputs(tgetstr("cl", &tcp), 1, putchar);
tputs(tgetstr("te", &tcp), 1, putchar);
exit(0);
}
+void
+fputchar(c)
+ int c;
+{
+ (void)putchar(c);
+}
+
nomem()
{
(void)fprintf(stderr, "worms: not enough memory.\n");