- 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:
parent
8712e867e1
commit
fb2473d217
@ -1,6 +1,7 @@
|
|||||||
# $FreeBSD$
|
# $FreeBSD$
|
||||||
|
|
||||||
PROG= grdc
|
PROG= grdc
|
||||||
|
WARNS?= 2
|
||||||
MAN= grdc.6
|
MAN= grdc.6
|
||||||
DPADD= ${LIBNCURSES}
|
DPADD= ${LIBNCURSES}
|
||||||
LDADD= -lncurses
|
LDADD= -lncurses
|
||||||
|
@ -1,22 +1,29 @@
|
|||||||
.TH GRDC 6
|
.\" $FreeBSD$
|
||||||
.SH NAME
|
.Dd September 25, 2001
|
||||||
grdc \- grand digital clock (curses)
|
.Dt GRDC 6
|
||||||
.SH SYNOPSIS
|
.Sh NAME
|
||||||
.B grdc
|
.Nm grdc
|
||||||
[-s] [
|
.Nd grand digital clock (curses)
|
||||||
.I n
|
.Sh SYNOPSIS
|
||||||
]
|
.Nm
|
||||||
.SH DESCRIPTION
|
.Op Fl s
|
||||||
.I Grdc
|
.Op Ar n
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
.Nm
|
||||||
runs a digital clock made of reverse-video blanks on a curses
|
runs a digital clock made of reverse-video blanks on a curses
|
||||||
compatible VDU screen. With an optional numeric argument
|
compatible VDU screen.
|
||||||
.I n
|
With an optional numeric argument
|
||||||
|
.Ar n
|
||||||
it stops after
|
it stops after
|
||||||
.I n
|
.Ar n
|
||||||
seconds (default never).
|
seconds (default never).
|
||||||
The optional
|
The optional
|
||||||
.B -s
|
.Fl s
|
||||||
flag makes digits scroll as they change. In this curses mode implementation,
|
flag makes digits scroll as they change.
|
||||||
|
In this curses mode implementation,
|
||||||
the scrolling option has trouble keeping up.
|
the scrolling option has trouble keeping up.
|
||||||
.SH AUTHOR
|
.Sh AUTHORS
|
||||||
Amos Shapir, modified for curses by John Lupien.
|
.An -nosplit
|
||||||
|
.An Amos Shapir ,
|
||||||
|
modified for curses by
|
||||||
|
.An John Lupien .
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
* $FreeBSD$
|
* $FreeBSD$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
@ -31,9 +32,8 @@ short disp[11] = {
|
|||||||
074717, 074757, 071111, 075757, 075717, 002020
|
074717, 074757, 071111, 075757, 075717, 002020
|
||||||
};
|
};
|
||||||
long old[6], next[6], new[6], mask;
|
long old[6], next[6], new[6], mask;
|
||||||
char scrol;
|
|
||||||
|
|
||||||
int sigtermed=0;
|
volatile sig_atomic_t sigtermed;
|
||||||
|
|
||||||
int hascolor = 0;
|
int hascolor = 0;
|
||||||
|
|
||||||
@ -41,6 +41,7 @@ void set(int, int);
|
|||||||
void standt(int);
|
void standt(int);
|
||||||
void movto(int, int);
|
void movto(int, int);
|
||||||
void sighndl(int);
|
void sighndl(int);
|
||||||
|
void usage(void);
|
||||||
|
|
||||||
void sighndl(signo)
|
void sighndl(signo)
|
||||||
int signo;
|
int signo;
|
||||||
@ -55,7 +56,34 @@ char **argv;
|
|||||||
{
|
{
|
||||||
long t, a;
|
long t, a;
|
||||||
int i, j, s, k;
|
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();
|
initscr();
|
||||||
|
|
||||||
@ -79,12 +107,6 @@ int n = 0;
|
|||||||
|
|
||||||
clear();
|
clear();
|
||||||
refresh();
|
refresh();
|
||||||
while(--argc > 0) {
|
|
||||||
if(**++argv == '-')
|
|
||||||
scrol = 1;
|
|
||||||
else
|
|
||||||
n = atoi(*argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(hascolor) {
|
if(hascolor) {
|
||||||
attrset(COLOR_PAIR(3));
|
attrset(COLOR_PAIR(3));
|
||||||
@ -155,8 +177,7 @@ int n = 0;
|
|||||||
clear();
|
clear();
|
||||||
refresh();
|
refresh();
|
||||||
endwin();
|
endwin();
|
||||||
fprintf(stderr, "grdc terminated by signal %d\n", sigtermed);
|
errx(1, "terminated by signal %d", (int)sigtermed);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
} while(--n);
|
} while(--n);
|
||||||
standend();
|
standend();
|
||||||
@ -204,3 +225,10 @@ movto(int line, int col)
|
|||||||
move(line, col);
|
move(line, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
usage(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
(void)fprintf(stderr, "usage: grdc [-s] [n]\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user