- 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.
This commit is contained in:
christos 2004-05-02 21:31:23 +00:00
parent 2745d2d566
commit fc21964e2e

View File

@ -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;
}