diff options
author | ru <ru@FreeBSD.org> | 2001-09-25 13:45:46 +0000 |
---|---|---|
committer | ru <ru@FreeBSD.org> | 2001-09-25 13:45:46 +0000 |
commit | 293d121c6bc633b0cbc60970add1c5e92d82d4ba (patch) | |
tree | b1de8df73638351767580a9be9a11fe51560d1b4 /games/grdc | |
parent | 2462e13fc46de3099c72f5003f4270cbb1200188 (diff) | |
download | FreeBSD-src-293d121c6bc633b0cbc60970add1c5e92d82d4ba.zip FreeBSD-src-293d121c6bc633b0cbc60970add1c5e92d82d4ba.tar.gz |
- Only use sig_atomic_t objects in signal handlers.
- Use getopt() to parse command line.
- Add usage().
- WARNSify.
- Convert manpage to mdoc(7).
PR: bin/30641
Submitted by: Andrey Simonenko <simon@simon.org.ua>, ru
MFC after: 1 week
Diffstat (limited to 'games/grdc')
-rw-r--r-- | games/grdc/Makefile | 1 | ||||
-rw-r--r-- | games/grdc/grdc.6 | 41 | ||||
-rw-r--r-- | games/grdc/grdc.c | 50 |
3 files changed, 64 insertions, 28 deletions
diff --git a/games/grdc/Makefile b/games/grdc/Makefile index a0d362e..0aeea1e 100644 --- a/games/grdc/Makefile +++ b/games/grdc/Makefile @@ -1,6 +1,7 @@ # $FreeBSD$ PROG= grdc +WARNS?= 2 MAN= grdc.6 DPADD= ${LIBNCURSES} LDADD= -lncurses diff --git a/games/grdc/grdc.6 b/games/grdc/grdc.6 index d5938c6..c73e6a2 100644 --- a/games/grdc/grdc.6 +++ b/games/grdc/grdc.6 @@ -1,22 +1,29 @@ -.TH GRDC 6 -.SH NAME -grdc \- grand digital clock (curses) -.SH SYNOPSIS -.B grdc -[-s] [ -.I n -] -.SH DESCRIPTION -.I Grdc +.\" $FreeBSD$ +.Dd September 25, 2001 +.Dt GRDC 6 +.Sh NAME +.Nm grdc +.Nd grand digital clock (curses) +.Sh SYNOPSIS +.Nm +.Op Fl s +.Op Ar n +.Sh DESCRIPTION +.Nm runs a digital clock made of reverse-video blanks on a curses -compatible VDU screen. With an optional numeric argument -.I n +compatible VDU screen. +With an optional numeric argument +.Ar n it stops after -.I n +.Ar n seconds (default never). The optional -.B -s -flag makes digits scroll as they change. In this curses mode implementation, +.Fl s +flag makes digits scroll as they change. +In this curses mode implementation, the scrolling option has trouble keeping up. -.SH AUTHOR -Amos Shapir, modified for curses by John Lupien. +.Sh AUTHORS +.An -nosplit +.An Amos Shapir , +modified for curses by +.An John Lupien . diff --git a/games/grdc/grdc.c b/games/grdc/grdc.c index 881428f..97d956f 100644 --- a/games/grdc/grdc.c +++ b/games/grdc/grdc.c @@ -9,6 +9,7 @@ * $FreeBSD$ */ +#include <err.h> #include <time.h> #include <signal.h> #include <ncurses.h> @@ -31,9 +32,8 @@ short disp[11] = { 074717, 074757, 071111, 075757, 075717, 002020 }; long old[6], next[6], new[6], mask; -char scrol; -int sigtermed=0; +volatile sig_atomic_t sigtermed; int hascolor = 0; @@ -41,6 +41,7 @@ void set(int, int); void standt(int); void movto(int, int); void sighndl(int); +void usage(void); void sighndl(signo) int signo; @@ -55,7 +56,34 @@ char **argv; { long t, a; int i, j, s, k; -int n = 0; +int n; +int ch; +int scrol; + + scrol = 0; + + while ((ch = getopt(argc, argv, "s")) != -1) + switch (ch) { + case 's': + scrol = 1; + break; + case '?': + default: + usage(); + /* NOTREACHED */ + } + argc -= optind; + argv += optind; + + if (argc > 1) { + usage(); + /* NOTREACHED */ + } + + if (argc > 0) + n = atoi(*argv); + else + n = 0; initscr(); @@ -79,12 +107,6 @@ int n = 0; clear(); refresh(); - while(--argc > 0) { - if(**++argv == '-') - scrol = 1; - else - n = atoi(*argv); - } if(hascolor) { attrset(COLOR_PAIR(3)); @@ -155,8 +177,7 @@ int n = 0; clear(); refresh(); endwin(); - fprintf(stderr, "grdc terminated by signal %d\n", sigtermed); - exit(1); + errx(1, "terminated by signal %d", (int)sigtermed); } } while(--n); standend(); @@ -204,3 +225,10 @@ movto(int line, int col) move(line, col); } +void +usage(void) +{ + + (void)fprintf(stderr, "usage: grdc [-s] [n]\n"); + exit(1); +} |