--- /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)<