X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/f12b51f99bbe8bb6ad7eca12b047ba9b46836ee6..c1e12dd54872604e41653ab8349f4a906fab5b9a:/worms/worms.c diff --git a/worms/worms.c b/worms/worms.c index dac6fa9c..b69ec125 100644 --- a/worms/worms.c +++ b/worms/worms.c @@ -1,4 +1,4 @@ -/* $NetBSD: worms.c,v 1.12 2003/08/07 09:37:57 agc Exp $ */ +/* $NetBSD: worms.c,v 1.22 2012/06/19 05:46:09 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -31,15 +31,15 @@ #include #ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\ - The Regents of the University of California. All rights reserved.\n"); +__COPYRIGHT("@(#) Copyright (c) 1980, 1993\ + The Regents of the University of California. All rights reserved."); #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)worms.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: worms.c,v 1.12 2003/08/07 09:37:57 agc Exp $"); +__RCSID("$NetBSD: worms.c,v 1.22 2012/06/19 05:46:09 dholland Exp $"); #endif #endif /* not lint */ @@ -177,16 +177,14 @@ static struct worm { short *xpos, *ypos; } *worm; -volatile sig_atomic_t sig_caught = 0; +static volatile sig_atomic_t sig_caught = 0; -int main __P((int, char **)); -void nomem __P((void)) __attribute__((__noreturn__)); -void onsig __P((int)); +int main(int, char **); +static void nomem(void) __dead; +static void onsig(int); int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { int x, y, h, n; struct worm *w; @@ -206,7 +204,7 @@ main(argc, argv) while ((ch = getopt(argc, argv, "d:fl:n:t")) != -1) switch(ch) { case 'd': - if ((delay = (unsigned int)strtoul(optarg, (char **)NULL, 10)) < 1 || delay > 1000) + if ((delay = (unsigned int)strtoul(optarg, NULL, 10)) < 1 || delay > 1000) errx(1, "invalid delay (1-1000)"); delay *= 1000; /* ms -> us */ break; @@ -237,7 +235,9 @@ main(argc, argv) if (!(worm = malloc((size_t)number * sizeof(struct worm))) || !(mp = malloc((size_t)1024))) nomem(); - initscr(); + if (!initscr()) + errx(0, "couldn't initialize screen"); + curs_set(0); CO = COLS; LI = LINES; last = CO - 1; @@ -269,7 +269,6 @@ main(argc, argv) (void)signal(SIGHUP, onsig); (void)signal(SIGINT, onsig); (void)signal(SIGQUIT, onsig); - (void)signal(SIGSTOP, onsig); (void)signal(SIGTSTP, onsig); (void)signal(SIGTERM, onsig); @@ -291,7 +290,12 @@ main(argc, argv) endwin(); exit(0); } - if (delay) usleep(delay); + if (delay) { + if (delay % 1000000 != 0) + usleep(delay % 1000000); + if (delay >= 1000000) + sleep(delay / 1000000); + } for (n = 0, w = &worm[0]; n < number; n++, w++) { if ((x = w->xpos[h = w->head]) < 0) { mvaddch(y = w->ypos[h] = bottom, @@ -333,15 +337,14 @@ main(argc, argv) } } -void -onsig(signo) - int signo __attribute__((__unused__)); +static void +onsig(int signo __unused) { sig_caught = 1; } -void -nomem() +static void +nomem(void) { errx(1, "not enough memory."); }