From sa@simon.org.ua  Tue Sep 18 01:39:22 2001
Return-Path: <sa@simon.org.ua>
Received: from lion.com.ua (lion.com.ua [213.133.161.130])
	by hub.freebsd.org (Postfix) with ESMTP id 953C537B414
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 18 Sep 2001 01:39:16 -0700 (PDT)
Received: from localhost (localhost [127.0.0.1])
	by lion.com.ua (8.11.4/8.11.4) with ESMTP id f8I8dDF72293
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 18 Sep 2001 11:39:16 +0300 (EEST)
	(envelope-from sa@simon.org.ua)
Message-Id: <20010918113631.I72277-100000@lion.com.ua>
Date: Tue, 18 Sep 2001 11:39:12 +0300 (EEST)
From: Andrey Simonenko <simon@simon.org.ua>
To: <FreeBSD-gnats-submit@freebsd.org>
Subject: Patch for games/grdc

>Number:         30641
>Category:       bin
>Synopsis:       Patch for games/grdc
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    ru
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 18 01:40:00 PDT 2001
>Closed-Date:    Tue Sep 25 06:45:35 PDT 2001
>Last-Modified:  Tue Sep 25 06:46:39 PDT 2001
>Originator:     Andrey Simonenko
>Release:        FreeBSD 4.4-RC i386
>Organization:
>Environment:

System: FreeBSD 4.4-RC i386

>Description:

grdc(8) outputs big digital clock. Color of digits is red, if grdc(8)
is used on b/w display, then it is hard to see something.

This patch adds new flag to grdc(8): -b, which changes color of digits
to b/w. Also arguments checking is improved.

In this patch type of "sigtermed" variable is changed from "int" to
"voilatile sig_atomic_t", because "sigtermed" variable is changed in signal
handler.

In this patch also one fprintf(stderr) function is changed to
appropriate errx(3) function.

>How-To-Repeat:

Apply following patch.

>Fix:

diff -ru /usr/src/games/grdc/grdc.6 grdc/grdc.6
--- /usr/src/games/grdc/grdc.6	Mon Dec  5 19:29:59 1994
+++ grdc/grdc.6	Mon Sep 17 02:40:22 2001
@@ -3,7 +3,7 @@
 grdc \- grand digital clock (curses)
 .SH SYNOPSIS
 .B grdc
-[-s] [
+[-sb] [
 .I n
 ]
 .SH DESCRIPTION
@@ -18,5 +18,8 @@
 .B -s
 flag makes digits scroll as they change. In this curses mode implementation,
 the scrolling option has trouble keeping up.
+The optional
+.B -b
+flag changes color of digits to b/w (useful option for b/w displays).
 .SH AUTHOR
 Amos Shapir, modified for curses by John Lupien.
diff -ru /usr/src/games/grdc/grdc.c grdc/grdc.c
--- /usr/src/games/grdc/grdc.c	Sun Dec 12 03:04:17 1999
+++ grdc/grdc.c	Mon Sep 17 20:26:14 2001
@@ -1,18 +1,23 @@
 /*
  * Grand digital clock for curses compatible terminals
- * Usage: grdc [-s] [n]   -- run for n seconds (default infinity)
+ * Usage: grdc [-sb] [n]   -- run for n seconds (default infinity)
  * Flags: -s: scroll
+ *	  -b: b/w output
  *
  * modified 10-18-89 for curses (jrl)
  * 10-18-89 added signal handling
+ * 09-17-2001 added -b flag, improved arguments checking
  *
  * $FreeBSD: src/games/grdc/grdc.c,v 1.8 1999/12/12 03:04:17 billf Exp $
  */

+#include <ctype.h>
+#include <err.h>
 #include <time.h>
 #include <signal.h>
 #include <ncurses.h>
 #include <stdlib.h>
+#include <string.h>
 #ifndef NONPOSIX
 #include <unistd.h>
 #endif
@@ -31,9 +36,9 @@
 	074717, 074757, 071111, 075757, 075717, 002020
 };
 long old[6], next[6], new[6], mask;
-char scrol;
+int scrol = 0, bw = 0;

-int sigtermed=0;
+volatile sig_atomic_t sigtermed = 0;

 int hascolor = 0;

@@ -56,6 +61,32 @@
 long t, a;
 int i, j, s, k;
 int n = 0;
+int opt;
+
+	opterr = 0;
+	while ( (opt = getopt(argc, argv, "sb")) != -1)
+		switch (opt) {
+		case 's':
+			scrol = 1;
+			break;
+		case 'b':
+			bw = 1;
+			break;
+		case '?':
+			errx(1, "invalid switch -%c", optopt);
+			break;
+		default:
+			err(1, "getopt");
+		}
+	if (optind < argc) {
+		if (optind == argc - 1) {
+			for (i = 0; i < strlen(argv[optind]); ++i)
+				if (isdigit(argv[optind][i]) == 0)
+					errx(1, "incorrect number of seconds \"%s\"", argv[optind]);
+			n = atoi(argv[optind]);
+		} else
+			errx(1, "too many arguments \"%s\"", argv[optind + 1]);
+	}

 	initscr();

@@ -71,20 +102,19 @@

 	if(hascolor) {
 		start_color();
-		init_pair(1, COLOR_BLACK, COLOR_RED);
-		init_pair(2, COLOR_RED, COLOR_BLACK);
+		if (bw) {
+			init_pair(1, COLOR_BLACK, COLOR_WHITE);
+			init_pair(2, COLOR_WHITE, COLOR_BLACK);
+		} else {
+			init_pair(1, COLOR_BLACK, COLOR_RED);
+			init_pair(2, COLOR_RED, COLOR_BLACK);
+		}
 		init_pair(3, COLOR_WHITE, COLOR_BLACK);
 		attrset(COLOR_PAIR(2));
 	}

 	clear();
 	refresh();
-	while(--argc > 0) {
-		if(**++argv == '-')
-			scrol = 1;
-		else
-			n = atoi(*argv);
-	}

 	if(hascolor) {
 		attrset(COLOR_PAIR(3));
@@ -155,8 +185,7 @@
 			clear();
 			refresh();
 			endwin();
-			fprintf(stderr, "grdc terminated by signal %d\n", sigtermed);
-			exit(1);
+			errx(1, "terminated by signal %d", sigtermed);
 		}
 	} while(--n);
 	standend();

>Release-Note:
>Audit-Trail:

From: Ruslan Ermilov <ru@FreeBSD.org>
To: Andrey Simonenko <simon@simon.org.ua>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/30641: Patch for games/grdc
Date: Wed, 19 Sep 2001 15:58:08 +0300

 On Tue, Sep 18, 2001 at 11:39:12AM +0300, Andrey Simonenko wrote:
 > 
 > grdc(8) outputs big digital clock. Color of digits is red, if grdc(8)
 > is used on b/w display, then it is hard to see something.
 > 
 > This patch adds new flag to grdc(8): -b, which changes color of digits
 > to b/w. Also arguments checking is improved.
 > 
 Use the right (B/W) terminal type such as cons25-m.
 
 > In this patch type of "sigtermed" variable is changed from "int" to
 > "voilatile sig_atomic_t", because "sigtermed" variable is changed in signal
 > handler.
 > 
 This looks OK though a bit superflows in this case.  :-)
 Also, is sig_atomic_t guaranteed to be a superset of int?
 (I'm mostly concerned about the portability issues here,
 I know that in FreeBSD sig_atomic_t is ether int or long.)
 
 
 Cheers,
 -- 
 Ruslan Ermilov		Oracle Developer/DBA,
 ru@sunbay.com		Sunbay Software AG,
 ru@FreeBSD.org		FreeBSD committer,
 +380.652.512.251	Simferopol, Ukraine
 
 http://www.FreeBSD.org	The Power To Serve
 http://www.oracle.com	Enabling The Information Age

From: "Andrey Simonenko" <simon@comsys.ntu-kpi.kiev.ua>
To: "Ruslan Ermilov" <ru@FreeBSD.org>
Cc: <bug-followup@FreeBSD.org>
Subject: Re: bin/30641: Patch for games/grdc
Date: Wed, 19 Sep 2001 19:23:25 +0400

 ----- Original Message -----
 From: Ruslan Ermilov <ru@FreeBSD.org>
 To: Andrey Simonenko <simon@simon.org.ua>
 Cc: <bug-followup@FreeBSD.org>
 Sent: Wednesday, September 19, 2001 4:58 PM
 Subject: Re: bin/30641: Patch for games/grdc
 
 
 > On Tue, Sep 18, 2001 at 11:39:12AM +0300, Andrey Simonenko wrote:
 > >
 > > grdc(8) outputs big digital clock. Color of digits is red, if grdc(8)
 > > is used on b/w display, then it is hard to see something.
 > >
 > > This patch adds new flag to grdc(8): -b, which changes color of digits
 > > to b/w. Also arguments checking is improved.
 > >
 > Use the right (B/W) terminal type such as cons25-m.
 
 I don't know about it. Nevertheless given patch makes better arguments
 checking.
 
 >
 > > In this patch type of "sigtermed" variable is changed from "int" to
 > > "voilatile sig_atomic_t", because "sigtermed" variable is changed in
 signal
 > > handler.
 > >
 > This looks OK though a bit superflows in this case.  :-)
 > Also, is sig_atomic_t guaranteed to be a superset of int?
 > (I'm mostly concerned about the portability issues here,
 > I know that in FreeBSD sig_atomic_t is ether int or long.)
 
 I always use "volatile sig_atomic_t" type for variable, which can
 be changed in signal handlers. May be somebody another can
 help with answer about portability, I think that sig_atomic_t is correct
 type in this case.
 

From: Ruslan Ermilov <ru@FreeBSD.org>
To: Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/30641: Patch for games/grdc
Date: Thu, 20 Sep 2001 09:10:09 +0300

 On Wed, Sep 19, 2001 at 07:23:25PM +0400, Andrey Simonenko wrote:
 > 
 > ----- Original Message -----
 > From: Ruslan Ermilov <ru@FreeBSD.org>
 > To: Andrey Simonenko <simon@simon.org.ua>
 > Cc: <bug-followup@FreeBSD.org>
 > Sent: Wednesday, September 19, 2001 4:58 PM
 > Subject: Re: bin/30641: Patch for games/grdc
 > 
 > 
 > > On Tue, Sep 18, 2001 at 11:39:12AM +0300, Andrey Simonenko wrote:
 > > >
 > > > grdc(8) outputs big digital clock. Color of digits is red, if grdc(8)
 > > > is used on b/w display, then it is hard to see something.
 > > >
 > > > This patch adds new flag to grdc(8): -b, which changes color of digits
 > > > to b/w. Also arguments checking is improved.
 > > >
 > > Use the right (B/W) terminal type such as cons25-m.
 > 
 > I don't know about it. Nevertheless given patch makes better arguments
 > checking.
 > 
 cons25r-m is much like the cons25r, but with colors support disabled.
 You are not going to fix every program that uses colors, do you?  :-)
 You need to set the correct black&white terminal type for black&white
 hardware, that's all.  You are not expecting the correct behavior if
 you set the wrong terminal type, right?  If you set TERM=at386 for
 syscons(4) hardware, function keys will not work, and you will develop
 the patch to support cons25r keystorkes for grdc(8)?  :-)
 
 
 Cheers,
 -- 
 Ruslan Ermilov		Oracle Developer/DBA,
 ru@sunbay.com		Sunbay Software AG,
 ru@FreeBSD.org		FreeBSD committer,
 +380.652.512.251	Simferopol, Ukraine
 
 http://www.FreeBSD.org	The Power To Serve
 http://www.oracle.com	Enabling The Information Age

From: Andrey Simonenko <simon@simon.org.ua>
To: Ruslan Ermilov <ru@FreeBSD.org>
Cc: <bug-followup@FreeBSD.org>
Subject: Re: bin/30641: Patch for games/grdc
Date: Thu, 20 Sep 2001 17:22:05 +0300 (EEST)

 On Wed, 19 Sep 2001, Ruslan Ermilov wrote:
 
 > On Tue, Sep 18, 2001 at 11:39:12AM +0300, Andrey Simonenko wrote:
 > >
 > > grdc(8) outputs big digital clock. Color of digits is red, if grdc(8)
 > > is used on b/w display, then it is hard to see something.
 > >
 > > This patch adds new flag to grdc(8): -b, which changes color of digits
 > > to b/w. Also arguments checking is improved.
 > >
 > Use the right (B/W) terminal type such as cons25-m.
 >
 > > In this patch type of "sigtermed" variable is changed from "int" to
 > > "voilatile sig_atomic_t", because "sigtermed" variable is changed in signal
 > > handler.
 > >
 > This looks OK though a bit superflows in this case.  :-)
 > Also, is sig_atomic_t guaranteed to be a superset of int?
 > (I'm mostly concerned about the portability issues here,
 > I know that in FreeBSD sig_atomic_t is ether int or long.)
 >
 
 Ok, I understand that there isn't any sense in -b option, so I remove -b
 option support from my patch, but all other improvements I keep there:
 
 diff -ru /usr/src/games/grdc/grdc.c grdc/grdc.c
 --- /usr/src/games/grdc/grdc.c	Sun Dec 12 03:04:17 1999
 +++ grdc/grdc.c	Thu Sep 20 15:38:40 2001
 @@ -5,14 +5,18 @@
   *
   * modified 10-18-89 for curses (jrl)
   * 10-18-89 added signal handling
 + * 09-17-2001 improved arguments checking
   *
   * $FreeBSD: src/games/grdc/grdc.c,v 1.8 1999/12/12 03:04:17 billf Exp $
   */
 
 +#include <ctype.h>
 +#include <err.h>
  #include <time.h>
  #include <signal.h>
  #include <ncurses.h>
  #include <stdlib.h>
 +#include <string.h>
  #ifndef NONPOSIX
  #include <unistd.h>
  #endif
 @@ -31,9 +35,9 @@
  	074717, 074757, 071111, 075757, 075717, 002020
  };
  long old[6], next[6], new[6], mask;
 -char scrol;
 +int scrol = 0;
 
 -int sigtermed=0;
 +volatile sig_atomic_t sigtermed = 0;
 
  int hascolor = 0;
 
 @@ -56,6 +60,29 @@
  long t, a;
  int i, j, s, k;
  int n = 0;
 +int opt;
 +
 +	opterr = 0;
 +	while ( (opt = getopt(argc, argv, "s")) != -1)
 +		switch (opt) {
 +		case 's':
 +			scrol = 1;
 +			break;
 +		case '?':
 +			errx(1, "invalid switch -%c", optopt);
 +			break;
 +		default:
 +			err(1, "getopt");
 +		}
 +	if (optind < argc) {
 +		if (optind == argc - 1) {
 +			for (i = 0; i < strlen(argv[optind]); ++i)
 +				if (isdigit(argv[optind][i]) == 0)
 +					errx(1, "incorrect number of seconds \"%s\"", argv[optind]);
 +			n = atoi(argv[optind]);
 +		} else
 +			errx(1, "too many arguments \"%s\"", argv[optind + 1]);
 +	}
 
  	initscr();
 
 @@ -79,12 +106,6 @@
 
  	clear();
  	refresh();
 -	while(--argc > 0) {
 -		if(**++argv == '-')
 -			scrol = 1;
 -		else
 -			n = atoi(*argv);
 -	}
 
  	if(hascolor) {
  		attrset(COLOR_PAIR(3));
 @@ -155,8 +176,7 @@
  			clear();
  			refresh();
  			endwin();
 -			fprintf(stderr, "grdc terminated by signal %d\n", sigtermed);
 -			exit(1);
 +			errx(1, "terminated by signal %d", sigtermed);
  		}
  	} while(--n);
  	standend();
 
State-Changed-From-To: open->closed 
State-Changed-By: ru 
State-Changed-When: Tue Sep 25 06:45:35 PDT 2001 
State-Changed-Why:  
A slightly modified version committed, thanks. 


Responsible-Changed-From-To: freebsd-bugs->ru 
Responsible-Changed-By: ru 
Responsible-Changed-When: Tue Sep 25 06:45:35 PDT 2001 
Responsible-Changed-Why:  

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=30641 
>Unformatted:
