From gavin@avcpc2.york.ac.uk  Tue Feb 19 05:52:12 2002
Return-Path: <gavin@avcpc2.york.ac.uk>
Received: from pump3.york.ac.uk (pump3.york.ac.uk [144.32.128.131])
	by hub.freebsd.org (Postfix) with ESMTP id B559337B402
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 19 Feb 2002 05:52:11 -0800 (PST)
Received: from avcpc2.york.ac.uk (avcpc2.york.ac.uk [144.32.116.84])
	by pump3.york.ac.uk (8.10.2/8.10.2) with ESMTP id g1JDpaN07061
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 19 Feb 2002 13:52:06 GMT
Received: (from gavin@localhost)
	by avcpc2.york.ac.uk (8.11.6/8.11.6) id g1JDpcj00684;
	Tue, 19 Feb 2002 13:51:38 GMT
	(envelope-from gavin)
Message-Id: <200202191351.g1JDpcj00684@avcpc2.york.ac.uk>
Date: Tue, 19 Feb 2002 13:51:38 GMT
From: Gavin Atkinson <gavin.atkinson@ury.york.ac.uk>
Reply-To: Gavin Atkinson <gavin.atkinson@ury.york.ac.uk>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: grdc enhancement: countdown timer mode
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         35113
>Category:       bin
>Synopsis:       [patch] grdc(6) 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:  Wed May 21 21:27:16 UTC 2008
>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:

From: Gavin Atkinson <gavin.atkinson@ury.york.ac.uk>
To: <freebsd-gnats-submit@freebsd.org>
Cc:  
Subject: Re: bin/35113: grdc enhancement: countdown time mode
Date: Fri, 22 Feb 2002 19:38:46 +0000 (GMT)

 Modified to add a count-up timer, due to popular demand (first request
 was from Andy Farkas <andyf@speednet.com.au>).
 
 Patches at http://ury.york.ac.uk/~gavin/grdc.diff
 
 Applies cleanly to stable and current.
 
 Gavin
 

From: Gavin Atkinson <gavin.atkinson@ury.york.ac.uk>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/35113: grdc enhancement: countdown timer mode
Date: Tue, 17 Feb 2004 19:34:38 +0000 (GMT)

 Updated patch at http://www.devrandom.co.uk/freebsd/grdc.diff - tested on
 i386 and sparc64. Now compiles cleanly at WARNS=6.
 
 Gavin
>Unformatted:
