From owner-freebsd-bugs@FreeBSD.ORG Sat Nov 20 23:20:30 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 31E6216A4CE for ; Sat, 20 Nov 2004 23:20:30 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 89F1D43D55 for ; Sat, 20 Nov 2004 23:20:29 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id iAKNKTGX055992 for ; Sat, 20 Nov 2004 23:20:29 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id iAKNKT95055990; Sat, 20 Nov 2004 23:20:29 GMT (envelope-from gnats) Resent-Date: Sat, 20 Nov 2004 23:20:29 GMT Resent-Message-Id: <200411202320.iAKNKT95055990@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Rostislav Krasny Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2F92E16A51B for ; Sat, 20 Nov 2004 23:19:49 +0000 (GMT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 09BFE43D3F for ; Sat, 20 Nov 2004 23:19:49 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id iAKNJm1h023148 for ; Sat, 20 Nov 2004 23:19:48 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id iAKNJms6023147; Sat, 20 Nov 2004 23:19:48 GMT (envelope-from nobody) Message-Id: <200411202319.iAKNJms6023147@www.freebsd.org> Date: Sat, 20 Nov 2004 23:19:48 GMT From: Rostislav Krasny To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Subject: misc/74178: grdc(6) - scrolling does not work and "AM"/"PM" string is erased when program has been run with scrolling X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Nov 2004 23:20:30 -0000 >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 -#include -#include #include +#include #include +#include +#include #ifndef NONPOSIX #include #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<>(4-i)*3)&07)<Release-Note: >Audit-Trail: >Unformatted: