Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 Nov 2004 23:19:48 GMT
From:      Rostislav Krasny <rosti_bsd@yahoo.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   misc/74178: grdc(6) - scrolling does not work and "AM"/"PM" string is erased when program has been run with scrolling
Message-ID:  <200411202319.iAKNJms6023147@www.freebsd.org>
Resent-Message-ID: <200411202320.iAKNKT95055990@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         74178
>Category:       misc
>Synopsis:       grdc(6) - scrolling does not work and "AM"/"PM" string is erased when program has been run with scrolling
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov 20 23:20:29 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Rostislav Krasny
>Release:        
>Organization:
>Environment:
FreeBSD saturn 5.3-RELEASE-p1 FreeBSD 5.3-RELEASE-p1 #0: Sat Nov 20 10:16:34 IST 2004     root@saturn:/usr/obj/usr/src/sys/MYKERNEL  i386
>Description:
When you run 'grdc -s' the scrolling is so quick that you can't see it. When you run 'grdc -st' the "AM"/"PM" string is erased by the left scrolling digit above it.

My patch fixes the both problems and also makes the code more style clean.
>How-To-Repeat:
Run 'grdc -s' and watch how the scrolling doesn't work.
Run 'grdc -t' and then 'grdc -st' and watch how the "AM"/"PM" string is erased.
>Fix:
--- /usr/src/games/grdc/grdc.c	Mon Jun 23 19:02:40 2003
+++ grdc.c	Sun Nov 21 01:15:57 2004
@@ -15,17 +15,18 @@
  */
 
 #include <err.h>
-#include <time.h>
-#include <signal.h>
 #include <ncurses.h>
+#include <signal.h>
 #include <stdlib.h>
+#include <sys/time.h>
+#include <time.h>
 #ifndef NONPOSIX
 #include <unistd.h>
 #endif
 
 #define YBASE	10
-#define XBASE	10
-#define XLENGTH 58
+#define XBASE	11
+int XLENGTH = 60;
 #define YDEPTH  7
 
 /* it won't be */
@@ -36,6 +37,7 @@
 	075557, 011111, 071747, 071717, 055711,
 	074717, 074757, 071111, 075757, 075717, 002020
 };
+
 long old[6], next[6], new[6], mask;
 
 volatile sig_atomic_t sigtermed;
@@ -44,29 +46,25 @@
 
 void set(int, int);
 void standt(int);
-void movto(int, int);
 void sighndl(int);
 void usage(void);
 
-void sighndl(signo)
-int signo;
+void
+sighndl(int signo)
 {
 	sigtermed=signo;
 }
 
 int
-main(argc, argv)
-int argc;
-char **argv;
+main(int argc, char *argv[])
 {
 long t, a;
 int i, j, s, k;
 int n;
 int ch;
-int scrol;
-int t12;
-
-	t12 = scrol = 0;
+int scrol=0;
+int t12=0;
+struct timespec tmsp;
 
 	while ((ch = getopt(argc, argv, "ts")) != -1)
 	switch (ch) {
@@ -75,8 +73,8 @@
 		break;
 	case 't':
 		t12 = 1;
+		XLENGTH++;
 		break;
-	case '?':
 	default:
 		usage();
 		/* NOTREACHED */
@@ -89,16 +87,13 @@
 		/* NOTREACHED */
 	}
 
-	if (argc > 0)
-		n = atoi(*argv);
-	else
-		n = 0;
+	n = (argc > 0)? atoi(*argv) : 0;
 
 	initscr();
 
-	signal(SIGINT,sighndl);
-	signal(SIGTERM,sighndl);
-	signal(SIGHUP,sighndl);
+	signal(SIGINT, sighndl);
+	signal(SIGTERM, sighndl);
+	signal(SIGHUP, sighndl);
 
 	cbreak();
 	noecho();
@@ -106,7 +101,7 @@
 
 	hascolor = has_colors();
 
-	if(hascolor) {
+	if (hascolor) {
 		start_color();
 		init_pair(1, COLOR_BLACK, COLOR_RED);
 		init_pair(2, COLOR_RED, COLOR_BLACK);
@@ -117,28 +112,28 @@
 	clear();
 	refresh();
 
-	if(hascolor) {
+	if (hascolor) {
 		attrset(COLOR_PAIR(3));
 
-		mvaddch(YBASE - 2,  XBASE - 3, ACS_ULCORNER);
+		mvaddch(YBASE - 2,  XBASE - 4, ACS_ULCORNER);
 		hline(ACS_HLINE, XLENGTH);
-		mvaddch(YBASE - 2,  XBASE - 2 + XLENGTH, ACS_URCORNER);
+		mvaddch(YBASE - 2,  XBASE - 3 + XLENGTH, ACS_URCORNER);
 
-		mvaddch(YBASE + YDEPTH - 1,  XBASE - 3, ACS_LLCORNER);
+		mvaddch(YBASE + YDEPTH - 1,  XBASE - 4, ACS_LLCORNER);
 		hline(ACS_HLINE, XLENGTH);
-		mvaddch(YBASE + YDEPTH - 1,  XBASE - 2 + XLENGTH, ACS_LRCORNER);
+		mvaddch(YBASE + YDEPTH - 1,  XBASE - 3 + XLENGTH, ACS_LRCORNER);
 
-		move(YBASE - 1,  XBASE - 3);
+		move(YBASE - 1,  XBASE - 4);
 		vline(ACS_VLINE, YDEPTH);
 
-		move(YBASE - 1,  XBASE - 2 + XLENGTH);
+		move(YBASE - 1,  XBASE - 3 + XLENGTH);
 		vline(ACS_VLINE, YDEPTH);
 
 		attrset(COLOR_PAIR(2));
 	}
 	do {
-		mask = 0;
 		time(&now);
+		mask = 0;
 		tm = localtime(&now);
 		set(tm->tm_sec%10, 0);
 		set(tm->tm_sec/10, 4);
@@ -148,12 +143,11 @@
 		if (t12) {
 			if (tm->tm_hour > 12) {
 				tm->tm_hour -= 12;
-				mvaddstr(YBASE + 5, XBASE + 52, "PM");
+				mvaddstr(YBASE + 4, XBASE + 55, "PM");
 			} else {
 				if (tm->tm_hour == 0)
 					tm->tm_hour = 12;
-
-				mvaddstr(YBASE + 5, XBASE + 52, "AM");
+				mvaddstr(YBASE + 4, XBASE + 55, "AM");
 			}
 		}
 
@@ -161,39 +155,40 @@
 		set(tm->tm_hour/10, 24);
 		set(10, 7);
 		set(10, 17);
-		for(k=0; k<6; k++) {
-			if(scrol) {
-				for(i=0; i<5; i++)
+		for (k=0; k<6; k++) {
+			if (scrol) {
+				for (i=0; i<5; i++) {
 					new[i] = (new[i]&~mask) | (new[i+1]&mask);
+					usleep(1);
+				}
 				new[5] = (new[5]&~mask) | (next[k]&mask);
 			} else
 				new[k] = (new[k]&~mask) | (next[k]&mask);
 			next[k] = 0;
-			for(s=1; s>=0; s--) {
+			for (s=1; s>=0; s--) {
 				standt(s);
-				for(i=0; i<6; i++) {
-					if((a = (new[i]^old[i])&(s ? new : old)[i]) != 0) {
-						for(j=0,t=1<<26; t; t>>=1,j++) {
-							if(a&t) {
-								if(!(a&(t<<1))) {
-									movto(YBASE + i, XBASE + 2*j);
+				for (i=0; i<6; i++) {
+					if ((a = (new[i]^old[i])&(s ? new : old)[i]) != 0) {
+						for (j=0, t=1<<26; t; t>>=1, j++) {
+							if (a&t) {
+								if (!(a&(t<<1))) {
+									move(YBASE + i, XBASE + 2*j);
 								}
 								addstr("  ");
 							}
 						}
 					}
-					if(!s) {
+					if (!s) {
 						old[i] = new[i];
 					}
 				}
-				if(!s) {
+				if (!s) {
 					refresh();
 				}
 			}
 		}
-		movto(6, 0);
+		move(6, 0);
 		refresh();
-		sleep(1);
 		if (sigtermed) {
 			standend();
 			clear();
@@ -201,7 +196,11 @@
 			endwin();
 			errx(1, "terminated by signal %d", (int)sigtermed);
 		}
-	} while(--n);
+                clock_gettime(CLOCK_REALTIME, &tmsp);
+                tmsp.tv_sec = 0;
+                tmsp.tv_nsec = 1000000000 - tmsp.tv_nsec;
+                nanosleep(&tmsp, NULL);
+	} while (--n);
 	standend();
 	clear();
 	refresh();
@@ -215,11 +214,11 @@
 int i, m;
 
 	m = 7<<n;
-	for(i=0; i<5; i++) {
+	for (i=0; i<5; i++) {
 		next[i] |= ((disp[t]>>(4-i)*3)&07)<<n;
 		mask |= (next[i]^old[i])&m;
 	}
-	if(mask&m)
+	if (mask&m)
 		mask |= m;
 }
 
@@ -227,13 +226,13 @@
 standt(int on)
 {
 	if (on) {
-		if(hascolor) {
+		if (hascolor) {
 			attron(COLOR_PAIR(1));
 		} else {
 			attron(A_STANDOUT);
 		}
 	} else {
-		if(hascolor) {
+		if (hascolor) {
 			attron(COLOR_PAIR(2));
 		} else {
 			attroff(A_STANDOUT);
@@ -242,15 +241,8 @@
 }
 
 void
-movto(int line, int col)
-{
-	move(line, col);
-}
-
-void
 usage(void)
 {
-
 	(void)fprintf(stderr, "usage: grdc [-st] [n]\n");
 	exit(1);
 }

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200411202319.iAKNJms6023147>