diff --git a/games/grdc/Makefile b/games/grdc/Makefile index a0d362e30b78..0aeea1e2ab2e 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 d5938c6d9602..c73e6a2e2388 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 881428f0e2a7..97d956fdc743 100644 --- a/games/grdc/grdc.c +++ b/games/grdc/grdc.c @@ -9,6 +9,7 @@ * $FreeBSD$ */ +#include #include #include #include @@ -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); +}