2 * Grand digital clock for curses compatible terminals
3 * Usage: grdc [-st] [n] -- run for n seconds (default infinity)
5 * -t: output time in 12-hour format
8 * modified 10-18-89 for curses (jrl)
9 * 10-18-89 added signal handling
11 * modified 03-25-03 for 12 hour option
12 * - Samy Al Bahra <samy@kerneled.com>
32 time_t now; /* yeah! */
36 075557, 011111, 071747, 071717, 055711,
37 074717, 074757, 071111, 075757, 075717, 002020
39 long old[6], next[6], new[6], mask;
41 volatile sig_atomic_t sigtermed;
71 while ((ch = getopt(argc, argv, "ts")) != -1)
99 signal(SIGINT,sighndl);
100 signal(SIGTERM,sighndl);
101 signal(SIGHUP,sighndl);
107 hascolor = has_colors();
111 init_pair(1, COLOR_BLACK, COLOR_RED);
112 init_pair(2, COLOR_RED, COLOR_BLACK);
113 init_pair(3, COLOR_WHITE, COLOR_BLACK);
114 attrset(COLOR_PAIR(2));
121 attrset(COLOR_PAIR(3));
123 mvaddch(YBASE - 2, XBASE - 3, ACS_ULCORNER);
124 hline(ACS_HLINE, XLENGTH);
125 mvaddch(YBASE - 2, XBASE - 2 + XLENGTH, ACS_URCORNER);
127 mvaddch(YBASE + YDEPTH - 1, XBASE - 3, ACS_LLCORNER);
128 hline(ACS_HLINE, XLENGTH);
129 mvaddch(YBASE + YDEPTH - 1, XBASE - 2 + XLENGTH, ACS_LRCORNER);
131 move(YBASE - 1, XBASE - 3);
132 vline(ACS_VLINE, YDEPTH);
134 move(YBASE - 1, XBASE - 2 + XLENGTH);
135 vline(ACS_VLINE, YDEPTH);
137 attrset(COLOR_PAIR(2));
142 tm = localtime(&now);
143 set(tm->tm_sec%10, 0);
144 set(tm->tm_sec/10, 4);
145 set(tm->tm_min%10, 10);
146 set(tm->tm_min/10, 14);
149 if (tm->tm_hour > 12) {
151 mvaddstr(YBASE + 5, XBASE + 52, "PM");
153 if (tm->tm_hour == 0)
156 mvaddstr(YBASE + 5, XBASE + 52, "AM");
160 set(tm->tm_hour%10, 20);
161 set(tm->tm_hour/10, 24);
167 new[i] = (new[i]&~mask) | (new[i+1]&mask);
168 new[5] = (new[5]&~mask) | (next[k]&mask);
170 new[k] = (new[k]&~mask) | (next[k]&mask);
172 for(s=1; s>=0; s--) {
175 if((a = (new[i]^old[i])&(s ? new : old)[i]) != 0) {
176 for(j=0,t=1<<26; t; t>>=1,j++) {
179 movto(YBASE + i, XBASE + 2*j);
202 errx(1, "terminated by signal %d", (int)sigtermed);
219 next[i] |= ((disp[t]>>(4-i)*3)&07)<<n;
220 mask |= (next[i]^old[i])&m;
231 attron(COLOR_PAIR(1));
237 attron(COLOR_PAIR(2));
245 movto(int line, int col)
254 (void)fprintf(stderr, "usage: grdc [-st] [n]\n");