summaryrefslogtreecommitdiffstats
path: root/rain
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2004-05-02 21:31:23 +0000
committerchristos <christos@NetBSD.org>2004-05-02 21:31:23 +0000
commitea47db964a175347fa88feaf15bd482c2e43515d (patch)
treeec6a05dd464e7eb466764446604a02d5304517a8 /rain
parent29d48d0bef41130215c4eb27582080e73178172d (diff)
downloadbsdgames-darwin-ea47db964a175347fa88feaf15bd482c2e43515d.tar.gz
bsdgames-darwin-ea47db964a175347fa88feaf15bd482c2e43515d.tar.zst
bsdgames-darwin-ea47db964a175347fa88feaf15bd482c2e43515d.zip
- don't catch STOP, TSTP, QUIT; the first you cannot catch and the other two
you should not. - don't accept delay == 1000, because it turns to 0 and fix the number parsing - misc KNF cleanups.
Diffstat (limited to 'rain')
-rw-r--r--rain/rain.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/rain/rain.c b/rain/rain.c
index 25048954..450778d8 100644
--- a/rain/rain.c
+++ b/rain/rain.c
@@ -1,4 +1,4 @@
-/* $NetBSD: rain.c,v 1.16 2004/02/08 22:21:57 jsm Exp $ */
+/* $NetBSD: rain.c,v 1.17 2004/05/02 21:31:23 christos Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
#if 0
static char sccsid[] = "@(#)rain.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: rain.c,v 1.16 2004/02/08 22:21:57 jsm Exp $");
+__RCSID("$NetBSD: rain.c,v 1.17 2004/05/02 21:31:23 christos Exp $");
#endif
#endif /* not lint */
@@ -55,36 +55,42 @@ __RCSID("$NetBSD: rain.c,v 1.16 2004/02/08 22:21:57 jsm Exp $");
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <errno.h>
+#include <limits.h>
-volatile sig_atomic_t sig_caught = 0;
+static volatile sig_atomic_t sig_caught = 0;
-int main(int, char **);
-void onsig(int);
+int main(int, char **);
+static void onsig(int);
int
-main(argc, argv)
- int argc;
- char **argv;
+main(int argc, char **argv)
{
int x, y, j;
long cols, lines;
unsigned int delay = 0;
+ unsigned long val = 0;
int ch;
+ char *ep;
int xpos[5], ypos[5];
- while ((ch = getopt(argc, argv, "d:h")) != -1)
+ while ((ch = getopt(argc, argv, "d:")) != -1)
switch (ch) {
case 'd':
- if ((delay = (unsigned int)strtoul(optarg, (char **)NULL, 10)) < 1
- || delay > 1000)
- errx(1, "invalid delay (1-1000)");
- delay *= 1000; /* ms -> us */
+ val = strtoul(optarg, &ep, 0);
+ if (ep == optarg || *ep)
+ errx(1, "Invalid delay `%s'", optarg);
+ if (errno == ERANGE && val == ULONG_MAX)
+ err(1, "Invalid delay `%s'", optarg);
+ if (val >= 1000)
+ errx(1, "Invalid delay `%s' (1-999)", optarg);
+ delay = (unsigned int)val * 1000; /* ms -> us */
break;
- case 'h':
default:
- (void)fprintf(stderr, "usage: rain [-d delay]\n");
- exit(1);
+ (void)fprintf(stderr, "Usage: %s [-d delay]\n",
+ getprogname());
+ return 1;
}
initscr();
@@ -93,9 +99,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);
curs_set(0);
@@ -141,9 +144,8 @@ main(argc, argv)
}
}
-void
-onsig(dummy)
- int dummy __attribute__((__unused__));
+static void
+onsig(int dummy __attribute__((__unused__)))
{
sig_caught = 1;
}