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;
72 while ((ch = getopt(argc, argv, "ts")) != -1)
100 signal(SIGINT,sighndl);
101 signal(SIGTERM,sighndl);
102 signal(SIGHUP,sighndl);
108 hascolor = has_colors();
112 init_pair(1, COLOR_BLACK, COLOR_RED);
113 init_pair(2, COLOR_RED, COLOR_BLACK);
114 init_pair(3, COLOR_WHITE, COLOR_BLACK);
115 attrset(COLOR_PAIR(2));
122 attrset(COLOR_PAIR(3));
124 mvaddch(YBASE - 2, XBASE - 3, ACS_ULCORNER);
125 hline(ACS_HLINE, XLENGTH);
126 mvaddch(YBASE - 2, XBASE - 2 + XLENGTH, ACS_URCORNER);
128 mvaddch(YBASE + YDEPTH - 1, XBASE - 3, ACS_LLCORNER);
129 hline(ACS_HLINE, XLENGTH);
130 mvaddch(YBASE + YDEPTH - 1, XBASE - 2 + XLENGTH, ACS_LRCORNER);
132 move(YBASE - 1, XBASE - 3);
133 vline(ACS_VLINE, YDEPTH);
135 move(YBASE - 1, XBASE - 2 + XLENGTH);
136 vline(ACS_VLINE, YDEPTH);
138 attrset(COLOR_PAIR(2));
143 tm = localtime(&now);
144 set(tm->tm_sec%10, 0);
145 set(tm->tm_sec/10, 4);
146 set(tm->tm_min%10, 10);
147 set(tm->tm_min/10, 14);
150 if (tm->tm_hour > 12) {
152 mvaddstr(YBASE + 5, XBASE + 52, "PM");
154 if (tm->tm_hour == 0)
157 mvaddstr(YBASE + 5, XBASE + 52, "AM");
161 set(tm->tm_hour%10, 20);
162 set(tm->tm_hour/10, 24);
168 new[i] = (new[i]&~mask) | (new[i+1]&mask);
169 new[5] = (new[5]&~mask) | (next[k]&mask);
171 new[k] = (new[k]&~mask) | (next[k]&mask);
173 for(s=1; s>=0; s--) {
176 if((a = (new[i]^old[i])&(s ? new : old)[i]) != 0) {
177 for(j=0,t=1<<26; t; t>>=1,j++) {
180 movto(YBASE + i, XBASE + 2*j);
197 clock_gettime(CLOCK_REALTIME_FAST, &ts);
198 if (ts.tv_sec == now) {
199 if (ts.tv_nsec > 0) {
201 ts.tv_nsec = 1000000000 - ts.tv_nsec;
206 nanosleep(&ts, NULL);
215 errx(1, "terminated by signal %d", (int)sigtermed);
232 next[i] |= ((disp[t]>>(4-i)*3)&07)<<n;
233 mask |= (next[i]^old[i])&m;
244 attron(COLOR_PAIR(1));
250 attron(COLOR_PAIR(2));
258 movto(int line, int col)
267 (void)fprintf(stderr, "usage: grdc [-st] [n]\n");