From owner-freebsd-bugs Fri Feb 22 11:27:25 2002 Delivered-To: freebsd-bugs@freebsd.org Received: from pump3.york.ac.uk (pump3.york.ac.uk [144.32.128.131]) by hub.freebsd.org (Postfix) with ESMTP id A8EDF37B404 for ; Fri, 22 Feb 2002 11:27:16 -0800 (PST) Received: from ury.york.ac.uk (ury.york.ac.uk [144.32.108.81]) by pump3.york.ac.uk (8.10.2/8.10.2) with ESMTP id g1MJRFN03147; Fri, 22 Feb 2002 19:27:15 GMT Received: from localhost (gavin@localhost) by ury.york.ac.uk (8.11.6/8.11.3) with ESMTP id g1MJRDb51097; Fri, 22 Feb 2002 19:27:15 GMT (envelope-from gavin.atkinson@ury.york.ac.uk) X-Authentication-Warning: ury.york.ac.uk: gavin owned process doing -bs Date: Fri, 22 Feb 2002 19:27:13 +0000 (GMT) From: Gavin Atkinson X-X-Sender: To: Andy Farkas Cc: Subject: Re: bin/35113: grdc enhancement: countdown timer mode In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org 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