2 * Grand digital clock for curses compatible terminals
3 * Usage: gdc [-s] [n] -- run for n seconds (default infinity)
6 * modified 10-18-89 for curses (jrl)
7 * 10-18-89 added signal handling
9 * $Id: gdc.c,v 1.8 1997/01/19 00:59:28 tom Exp $
12 #include <test.priv.h>
24 static time_t now; /* yeah! */
27 static short disp[11] = {
28 075557, 011111, 071747, 071717, 055711,
29 074717, 074757, 071111, 075757, 075717, 002020
31 static long old[6], next[6], new[6], mask;
34 static int sigtermed = 0;
36 static int hascolor = 0;
38 static void set(int, int);
39 static void standt(int);
40 static void movto(int, int);
43 RETSIGTYPE sighndl(int signo)
45 signal(signo, sighndl);
50 main(int argc, char *argv[])
56 signal(SIGINT,sighndl);
57 signal(SIGTERM,sighndl);
58 signal(SIGKILL,sighndl);
65 hascolor = has_colors();
70 #ifdef NCURSES_VERSION
71 if (use_default_colors() == OK)
74 init_pair(1, COLOR_BLACK, COLOR_RED);
75 init_pair(2, COLOR_RED, bg);
76 init_pair(3, COLOR_WHITE, bg);
77 attrset(COLOR_PAIR(2));
90 attrset(COLOR_PAIR(3));
92 mvaddch(YBASE - 1, XBASE - 1, ACS_ULCORNER);
93 hline(ACS_HLINE, XLENGTH);
94 mvaddch(YBASE - 1, XBASE + XLENGTH, ACS_URCORNER);
96 mvaddch(YBASE + YDEPTH, XBASE - 1, ACS_LLCORNER);
97 hline(ACS_HLINE, XLENGTH);
98 mvaddch(YBASE + YDEPTH, XBASE + XLENGTH, ACS_LRCORNER);
100 move(YBASE, XBASE - 1);
101 vline(ACS_VLINE, YDEPTH);
103 move(YBASE, XBASE + XLENGTH);
104 vline(ACS_VLINE, YDEPTH);
106 attrset(COLOR_PAIR(2));
113 tm = localtime(&now);
114 set(tm->tm_sec%10, 0);
115 set(tm->tm_sec/10, 4);
116 set(tm->tm_min%10, 10);
117 set(tm->tm_min/10, 14);
118 set(tm->tm_hour%10, 20);
119 set(tm->tm_hour/10, 24);
125 new[i] = (new[i]&~mask) | (new[i+1]&mask);
126 new[5] = (new[5]&~mask) | (next[k]&mask);
128 new[k] = (new[k]&~mask) | (next[k]&mask);
130 for(s=1; s>=0; s--) {
133 if((a = (new[i]^old[i])&(s ? new : old)[i]) != 0) {
134 for(j=0,t=1<<26; t; t>>=1,j++) {
137 movto(YBASE + i, XBASE + 2*j);
153 /* this depends on the detailed format of ctime(3) */
154 (void) strcpy(buf, ctime(&now));
155 (void) strcpy(buf + 10, buf + 19);
156 mvaddstr(16, 30, buf);
161 while(wgetch(stdscr) != ERR)
168 fprintf(stderr, "gdc terminated by signal %d\n", sigtermed);
186 next[i] |= ((disp[t]>>(4-i)*3)&07)<<n;
187 mask |= (next[i]^old[i])&m;
198 attron(COLOR_PAIR(1));
204 attron(COLOR_PAIR(2));
212 movto(int line, int col)