Date: Fri, 22 Feb 2002 19:27:13 +0000 (GMT) From: Gavin Atkinson <gavin.atkinson@ury.york.ac.uk> To: Andy Farkas <andyf@speednet.com.au> Cc: <FreeBSD-bugs@FreeBSD.ORG> Subject: Re: bin/35113: grdc enhancement: countdown timer mode Message-ID: <Pine.BSF.4.33.0202221921210.50930-100000@ury.york.ac.uk> In-Reply-To: <Pine.BSF.4.33.0202201111220.10335-100000@backup.af.speednet.com.au>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 20 Feb 2002, Andy Farkas wrote:
> I would like to see grdc learn to count up from 0 seconds, maybe -c flag.
> It could then perhaps be used as crude visual running timer...?
OK... try this...
-t gives a timer starting from zero, -c gives a countdown timer. Applies
cleanly to both -CURRENT and -STABLE.
gavin
--- /5.0/usr/src/games/grdc/grdc.c Tue Sep 25 14:45:46 2001
+++ grdc.c Fri Feb 22 19:16:12 2002
@@ -1,10 +1,15 @@
/*
* Grand digital clock for curses compatible terminals
* Usage: grdc [-s] [n] -- run for n seconds (default infinity)
+ * grdc -c n -- countdown n seconds
+ * grdc -t [n] -- upward count for n seconds (defaults infinity)
* Flags: -s: scroll
+ * -c: countdown timer mode
+ * -t: upward timer
*
* modified 10-18-89 for curses (jrl)
* 10-18-89 added signal handling
+ * 02-18-02 added countdown and timer mode
*
* $FreeBSD: src/games/grdc/grdc.c,v 1.9 2001/09/25 13:45:46 ru Exp $
*/
@@ -25,6 +30,8 @@
/* it won't be */
time_t now; /* yeah! */
+time_t start; /* for timer mode */
+time_t end; /* for countdown mode */
struct tm *tm;
short disp[11] = {
@@ -58,15 +65,22 @@
int i, j, s, k;
int n;
int ch;
-int scrol;
+int remain, duration;
+int scrol = 0;
+int timer = 0, ctimer = 0;
+int hour, minute, second;
- scrol = 0;
-
- while ((ch = getopt(argc, argv, "s")) != -1)
+ while ((ch = getopt(argc, argv, "cst")) != -1)
switch (ch) {
+ case 'c':
+ ctimer = 1;
+ break;
case 's':
scrol = 1;
break;
+ case 't':
+ timer = 1;
+ break;
case '?':
default:
usage();
@@ -75,15 +89,18 @@
argc -= optind;
argv += optind;
- if (argc > 1) {
+ if ((argc > 1) || (argc == 0 && ctimer)) {
usage();
/* NOTREACHED */
}
if (argc > 0)
- n = atoi(*argv);
+ duration = atoi(*argv);
else
- n = 0;
+ duration = 0;
+
+ if (ctimer && duration == 0)
+ return(0);
initscr();
@@ -127,16 +144,43 @@
attrset(COLOR_PAIR(2));
}
+ time(&start);
+ end = start;
+ remain = duration;
+ if (duration) {
+ end +=duration;
+ }
do {
mask = 0;
time(&now);
- tm = localtime(&now);
- set(tm->tm_sec%10, 0);
- set(tm->tm_sec/10, 4);
- set(tm->tm_min%10, 10);
- set(tm->tm_min/10, 14);
- set(tm->tm_hour%10, 20);
- set(tm->tm_hour/10, 24);
+ if (!ctimer && !timer) {
+ tm = localtime(&now);
+ hour = tm->tm_hour;
+ minute = tm->tm_min;
+ second = tm->tm_sec;
+ if (duration)
+ remain = end - now;
+ } else {
+ if (ctimer) {
+ n = end - now;
+ remain = n;
+ if (remain <= 0)
+ break;
+ } else {
+ n = now - start;
+ if (duration)
+ remain = duration - n;
+ }
+ hour = (n/3600)%100;
+ minute = (n/60)%60;
+ second = n%60;
+ }
+ set(second%10, 0);
+ set(second/10, 4);
+ set(minute%10, 10);
+ set(minute/10, 14);
+ set(hour%10, 20);
+ set(hour/10, 24);
set(10, 7);
set(10, 17);
for(k=0; k<6; k++) {
@@ -179,7 +223,7 @@
endwin();
errx(1, "terminated by signal %d", (int)sigtermed);
}
- } while(--n);
+ } while(--remain);
standend();
clear();
refresh();
@@ -229,6 +273,9 @@
usage(void)
{
- (void)fprintf(stderr, "usage: grdc [-s] [n]\n");
+ (void)fprintf(stderr, "%s\n%s\n%s\n",
+ "usage: grdc [-s] [n]",
+ " grdc -c n",
+ " grdc -t [n]");
exit(1);
}
--- /5.0/usr/src/games/grdc/grdc.6 Tue Sep 25 14:45:46 2001
+++ grdc.6 Fri Feb 22 19:14:30 2002
@@ -1,5 +1,5 @@
.\" $FreeBSD: src/games/grdc/grdc.6,v 1.3 2001/09/25 13:45:46 ru Exp $
-.Dd September 25, 2001
+.Dd February 18, 2002
.Dt GRDC 6
.Sh NAME
.Nm grdc
@@ -8,22 +8,48 @@
.Nm
.Op Fl s
.Op Ar n
+.Nm
+.Fl c
+.Ar n
+.Nm
+.Fl t
+.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
+The clock can act as a countdown timer with the
+.Fl c
+flag or a stopwatch timer with the
+.Fl t
+flag.
+The optional numeric argument
.Ar n
-it stops after
+makes the clock or timer stop after
.Ar n
seconds (default never).
+.Ar n
+is required for countdown timer mode.
The optional
.Fl s
flag makes digits scroll as they change.
In this curses mode implementation,
the scrolling option has trouble keeping up.
+.Sh NOTES
+In countdown timer mode, the specifying of
+.Fl n
+> 360000 seconds (100 hours) will lead to the counter displaying
+incorrect remaining time, however it will time correctly, and
+display correctly when the remaining time becomes less than
+100 hours.
+.Pp
+The clock may appear to miss seconds out. This is because the
+clock is as accurate as possible but only updates once per second.
+On slower computers, may lead to occasional jumping of the clock.
.Sh AUTHORS
.An -nosplit
.An Amos Shapir ,
modified for curses by
.An John Lupien .
+Countdown timer mode by
+.An Gavin Atkinson .
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.33.0202221921210.50930-100000>
