summaryrefslogtreecommitdiffstats
path: root/worm
diff options
context:
space:
mode:
authordholland <dholland@NetBSD.org>2015-08-17 17:17:01 +0000
committerdholland <dholland@NetBSD.org>2015-08-17 17:17:01 +0000
commitf3d1cce411cc6eac7290df12d80c9824869bbb5b (patch)
tree428c7ae033a33d9d9cbe3a27dbd35e494d636a84 /worm
parentac993d78a557211a3c93c9e8f76d8e14e501932d (diff)
downloadbsdgames-darwin-f3d1cce411cc6eac7290df12d80c9824869bbb5b.tar.gz
bsdgames-darwin-f3d1cce411cc6eac7290df12d80c9824869bbb5b.tar.zst
bsdgames-darwin-f3d1cce411cc6eac7290df12d80c9824869bbb5b.zip
remove cpp abuse
Diffstat (limited to 'worm')
-rw-r--r--worm/worm.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/worm/worm.c b/worm/worm.c
index 2c4b2086..225ed0a1 100644
--- a/worm/worm.c
+++ b/worm/worm.c
@@ -1,4 +1,4 @@
-/* $NetBSD: worm.c,v 1.30 2011/05/23 23:03:38 joerg Exp $ */
+/* $NetBSD: worm.c,v 1.31 2015/08/17 17:17:01 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\
#if 0
static char sccsid[] = "@(#)worm.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: worm.c,v 1.30 2011/05/23 23:03:38 joerg Exp $");
+__RCSID("$NetBSD: worm.c,v 1.31 2015/08/17 17:17:01 dholland Exp $");
#endif
#endif /* not lint */
@@ -56,7 +56,6 @@ __RCSID("$NetBSD: worm.c,v 1.30 2011/05/23 23:03:38 joerg Exp $");
#include <termios.h>
#include <unistd.h>
-#define newlink() (struct body *) malloc(sizeof (struct body));
#define HEAD '@'
#define BODY 'o'
#define LENGTH 7
@@ -94,6 +93,18 @@ static int rnd(int);
static void setup(void);
static void wake(int);
+static struct body *
+newlink(void)
+{
+ struct body *b;
+
+ b = malloc(sizeof(*b));
+ if (b == NULL) {
+ err(EXIT_FAILURE, NULL);
+ }
+ return b;
+}
+
int
main(int argc, char **argv)
{
@@ -163,16 +174,12 @@ life(void)
np = NULL;
head = newlink();
- if (head == NULL)
- err(1, NULL);
head->x = start_len % (COLS-5) + 2;
head->y = LINES / 2;
head->next = NULL;
display(head, HEAD);
for (i = 0, bp = head; i < start_len; i++, bp = np) {
np = newlink();
- if (np == NULL)
- err(1, NULL);
np->next = bp;
bp->prev = np;
if (((bp->x <= 2) && (j == 1)) || ((bp->x >= COLS-4) && (j == -1))) {
@@ -326,8 +333,6 @@ process(int ch)
}
else if(ch != ' ') crash();
nh = newlink();
- if (nh == NULL)
- err(1, NULL);
nh->next = NULL;
nh->prev = head;
head->next = nh;