- 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
This commit is contained in:
Ruslan Ermilov 2001-09-25 13:45:46 +00:00
parent 8712e867e1
commit fb2473d217
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=83928
3 changed files with 64 additions and 28 deletions

View File

@ -1,6 +1,7 @@
# $FreeBSD$
PROG= grdc
WARNS?= 2
MAN= grdc.6
DPADD= ${LIBNCURSES}
LDADD= -lncurses

View File

@ -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 .

View File

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