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.10 1997/10/18 20:06:06 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 older[6], next[6], newer[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);
52 chtype bottom[XLENGTH+1];
56 attrset(COLOR_PAIR(3));
58 mvaddch(YBASE - 1, XBASE - 1, ACS_ULCORNER);
59 hline(ACS_HLINE, XLENGTH);
60 mvaddch(YBASE - 1, XBASE + XLENGTH, ACS_URCORNER);
62 mvaddch(YBASE + YDEPTH, XBASE - 1, ACS_LLCORNER);
63 mvinchnstr(YBASE + YDEPTH, XBASE, bottom, XLENGTH);
64 for (n = 0; n < XLENGTH; n++)
65 bottom[n] = ACS_HLINE | (bottom[n] & (A_ATTRIBUTES | A_COLOR));
66 mvaddchnstr(YBASE + YDEPTH, XBASE, bottom, XLENGTH);
67 mvaddch(YBASE + YDEPTH, XBASE + XLENGTH, ACS_LRCORNER);
69 move(YBASE, XBASE - 1);
70 vline(ACS_VLINE, YDEPTH);
72 move(YBASE, XBASE + XLENGTH);
73 vline(ACS_VLINE, YDEPTH);
76 attrset(COLOR_PAIR(2));
80 main(int argc, char *argv[])
86 signal(SIGINT,sighndl);
87 signal(SIGTERM,sighndl);
88 signal(SIGKILL,sighndl);
96 hascolor = has_colors();
101 #ifdef NCURSES_VERSION
102 if (use_default_colors() == OK)
105 init_pair(1, COLOR_BLACK, COLOR_RED);
106 init_pair(2, COLOR_RED, bg);
107 init_pair(3, COLOR_WHITE, bg);
108 attrset(COLOR_PAIR(2));
126 tm = localtime(&now);
127 set(tm->tm_sec%10, 0);
128 set(tm->tm_sec/10, 4);
129 set(tm->tm_min%10, 10);
130 set(tm->tm_min/10, 14);
131 set(tm->tm_hour%10, 20);
132 set(tm->tm_hour/10, 24);
138 newer[i] = (newer[i]&~mask) | (newer[i+1]&mask);
139 newer[5] = (newer[5]&~mask) | (next[k]&mask);
141 newer[k] = (newer[k]&~mask) | (next[k]&mask);
143 for(s=1; s>=0; s--) {
146 if((a = (newer[i]^older[i])&(s ? newer : older)[i]) != 0) {
147 for(j=0,t=1<<26; t; t>>=1,j++) {
150 movto(YBASE + i, XBASE + 2*j);
170 /* this depends on the detailed format of ctime(3) */
171 (void) strcpy(buf, ctime(&now));
172 (void) strcpy(buf + 10, buf + 19);
173 mvaddstr(16, 30, buf);
179 while(wgetch(stdscr) != ERR)
187 fprintf(stderr, "gdc terminated by signal %d\n", sigtermed);
206 next[i] |= ((disp[t]>>(4-i)*3)&07)<<n;
207 mask |= (next[i]^older[i])&m;
218 attron(COLOR_PAIR(1));
224 attron(COLOR_PAIR(2));
232 movto(int line, int col)