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>
33 075557, 011111, 071747, 071717, 055711,
34 074717, 074757, 071111, 075757, 075717, 002020
36 long old[6], next[6], new[6], mask;
38 volatile sig_atomic_t sigtermed;
55 main(int argc, char *argv[])
57 struct timespec delay;
68 while ((ch = getopt(argc, argv, "ts")) != -1)
92 warnx("number of seconds is out of range");
101 signal(SIGINT,sighndl);
102 signal(SIGTERM,sighndl);
103 signal(SIGHUP,sighndl);
109 hascolor = has_colors();
113 init_pair(1, COLOR_BLACK, COLOR_RED);
114 init_pair(2, COLOR_RED, COLOR_BLACK);
115 init_pair(3, COLOR_WHITE, COLOR_BLACK);
116 attrset(COLOR_PAIR(2));
123 attrset(COLOR_PAIR(3));
125 mvaddch(YBASE - 2, XBASE - 3, ACS_ULCORNER);
126 hline(ACS_HLINE, XLENGTH);
127 mvaddch(YBASE - 2, XBASE - 2 + XLENGTH, ACS_URCORNER);
129 mvaddch(YBASE + YDEPTH - 1, XBASE - 3, ACS_LLCORNER);
130 hline(ACS_HLINE, XLENGTH);
131 mvaddch(YBASE + YDEPTH - 1, XBASE - 2 + XLENGTH, ACS_LRCORNER);
133 move(YBASE - 1, XBASE - 3);
134 vline(ACS_VLINE, YDEPTH);
136 move(YBASE - 1, XBASE - 2 + XLENGTH);
137 vline(ACS_VLINE, YDEPTH);
139 attrset(COLOR_PAIR(2));
141 clock_gettime(CLOCK_REALTIME_FAST, &now);
142 prev_sec = now.tv_sec;
145 tm = localtime(&now.tv_sec);
146 set(tm->tm_sec%10, 0);
147 set(tm->tm_sec/10, 4);
148 set(tm->tm_min%10, 10);
149 set(tm->tm_min/10, 14);
152 if (tm->tm_hour > 12) {
154 mvaddstr(YBASE + 5, XBASE + 52, "PM");
156 if (tm->tm_hour == 0)
159 mvaddstr(YBASE + 5, XBASE + 52, "AM");
163 set(tm->tm_hour%10, 20);
164 set(tm->tm_hour/10, 24);
170 new[i] = (new[i]&~mask) | (new[i+1]&mask);
171 new[5] = (new[5]&~mask) | (next[k]&mask);
173 new[k] = (new[k]&~mask) | (next[k]&mask);
175 for(s=1; s>=0; s--) {
178 if((a = (new[i]^old[i])&(s ? new : old)[i]) != 0) {
179 for(j=0,t=1<<26; t; t>>=1,j++) {
182 movto(YBASE + i, XBASE + 2*j);
199 clock_gettime(CLOCK_REALTIME_FAST, &now);
200 if (now.tv_sec == prev_sec) {
201 if (delay.tv_nsec > 0) {
203 delay.tv_nsec = 1000000000 - now.tv_nsec;
208 nanosleep(&delay, NULL);
209 clock_gettime(CLOCK_REALTIME_FAST, &now);
211 n -= now.tv_sec - prev_sec;
212 prev_sec = now.tv_sec;
218 errx(1, "terminated by signal %d", (int)sigtermed);
235 next[i] |= ((disp[t]>>(4-i)*3)&07)<<n;
236 mask |= (next[i]^old[i])&m;
247 attron(COLOR_PAIR(1));
253 attron(COLOR_PAIR(2));
261 movto(int line, int col)
270 (void)fprintf(stderr, "usage: grdc [-st] [n]\n");