Date: Tue, 19 Feb 2002 13:51:38 GMT From: Gavin Atkinson <gavin.atkinson@ury.york.ac.uk> To: FreeBSD-gnats-submit@freebsd.org Subject: bin/35113: grdc enhancement: countdown timer mode Message-ID: <200202191351.g1JDpcj00684@avcpc2.york.ac.uk>
next in thread | raw e-mail | index | archive | help
>Number: 35113 >Category: bin >Synopsis: grdc enhancement: countdown timer mode >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue Feb 19 06:00:05 PST 2002 >Closed-Date: >Last-Modified: >Originator: Gavin Atkinson >Release: FreeBSD 4.5-RELEASE i386 >Organization: none >Environment: System: FreeBSD epsilon.ury.york.ac.uk 4.5-RELEASE FreeBSD 4.5-RELEASE #3: Wed Feb 13 10:15:50 GMT 2002 root@epsilon.ury.york.ac.uk:/usr/obj/usr/src/sys/EPSILON i386 >Description: grdc lacks a countdown timer. This patch adds it. >How-To-Repeat: n/a >Fix: patch is against -CURRENT source. --- /5.0/usr/src/games/grdc/grdc.c Tue Sep 25 14:45:46 2001 +++ grdc.c Tue Feb 19 09:21:04 2002 @@ -1,10 +1,13 @@ /* * Grand digital clock for curses compatible terminals * Usage: grdc [-s] [n] -- run for n seconds (default infinity) + * grdc -t n -- countdown n seconds * Flags: -s: scroll + * -t: timer mode * * modified 10-18-89 for curses (jrl) * 10-18-89 added signal handling + * 02-18-02 added countdown timer mode * * $FreeBSD: src/games/grdc/grdc.c,v 1.9 2001/09/25 13:45:46 ru Exp $ */ @@ -25,6 +28,7 @@ /* it won't be */ time_t now; /* yeah! */ +time_t end; /* for timer mode */ struct tm *tm; short disp[11] = { @@ -58,15 +62,18 @@ int i, j, s, k; int n; int ch; -int scrol; +int scrol = 0; +int timer = 0; +int hour, minute, second; - scrol = 0; - - while ((ch = getopt(argc, argv, "s")) != -1) + while ((ch = getopt(argc, argv, "st")) != -1) switch (ch) { case 's': scrol = 1; break; + case 't': + timer = 1; + break; case '?': default: usage(); @@ -75,7 +82,7 @@ argc -= optind; argv += optind; - if (argc > 1) { + if ((argc > 1) || (argc == 0 && timer)) { usage(); /* NOTREACHED */ } @@ -85,6 +92,9 @@ else n = 0; + if (timer && n == 0) + return(0); + initscr(); signal(SIGINT,sighndl); @@ -127,16 +137,30 @@ attrset(COLOR_PAIR(2)); } + time(&end); + end += n; 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 (!timer) { + tm = localtime(&now); + hour = tm->tm_hour; + minute = tm->tm_min; + second = tm->tm_sec; + } else { + n = end - now; + if (n <= 0) + break; + 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++) { @@ -229,6 +253,6 @@ usage(void) { - (void)fprintf(stderr, "usage: grdc [-s] [n]\n"); + (void)fprintf(stderr, "usage: grdc [-s] [n]\n grdc -t n\n"); exit(1); } --- /5.0/usr/src/games/grdc/grdc.6 Tue Sep 25 14:45:46 2001 +++ grdc.6 Tue Feb 19 09:27:42 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,6 +8,9 @@ .Nm .Op Fl s .Op Ar n +.Nm +.Fl t +.Ar n .Sh DESCRIPTION .Nm runs a digital clock made of reverse-video blanks on a curses @@ -17,13 +20,27 @@ it stops after .Ar n seconds (default never). +The clock can act as a countdown timer with the +.Fl t +flag, +.Ar n +specifies the number of seconds to time for. 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. .Sh AUTHORS .An -nosplit .An Amos Shapir , modified for curses by .An John Lupien . +Countdown timer mode by +.An Gavin Atkinson . >Release-Note: >Audit-Trail: >Unformatted: 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?200202191351.g1JDpcj00684>