2 * Grand digital clock for curses compatible terminals
3 * Usage: grdc [-s] [-d msecs] [n] -- run for n seconds (default infinity)
4 * Flags: -s: scroll (default scroll duration 120msec)
5 * -d msecs: specify scroll duration (implies -s)
7 * modified 10-18-89 for curses (jrl)
8 * 10-18-89 added signal handling
9 * 03-23-04 added centering, scroll delay (cap)
11 * $FreeBSD: src/games/grdc/grdc.c,v 1.8.2.1 2001/10/02 11:51:49 ru Exp $
30 075557, 011111, 071747, 071717, 055711,
31 074717, 074757, 071111, 075757, 075717, 002020
33 long old[6], next[6], new[6], mask;
35 volatile sig_atomic_t sigtermed;
38 long int scroll_msecs = 120;
39 int xbase, ybase, xmax, ymax;
41 static void set(int, int);
42 static void standt(int);
43 static void sighndl(int);
44 static void usage(void);
45 static void draw_row(int, int);
46 static void snooze(long int);
55 main(int argc, char **argv)
66 while ((ch = getopt(argc, argv, "d:s")) != -1)
69 scroll_msecs = atol(optarg);
71 errx(1, "scroll duration may not be negative");
96 getmaxyx(stdscr, ymax, xmax);
97 if (ymax < YDEPTH + 2 || xmax < XLENGTH + 4) {
99 errx(1, "terminal too small");
101 xbase = (xmax - XLENGTH) / 2 + 2;
102 ybase = (ymax - YDEPTH) / 2 + 1;
104 signal(SIGINT, sighndl);
105 signal(SIGTERM, sighndl);
106 signal(SIGHUP, sighndl);
112 hascolor = has_colors();
116 init_pair(1, COLOR_BLACK, COLOR_RED);
117 init_pair(2, COLOR_RED, COLOR_BLACK);
118 init_pair(3, COLOR_WHITE, COLOR_BLACK);
119 attrset(COLOR_PAIR(2));
126 attrset(COLOR_PAIR(3));
128 mvaddch(ybase - 2, xbase - 3, ACS_ULCORNER);
129 hline(ACS_HLINE, XLENGTH);
130 mvaddch(ybase - 2, xbase - 2 + XLENGTH, ACS_URCORNER);
132 mvaddch(ybase + YDEPTH - 1, xbase - 3, ACS_LLCORNER);
133 hline(ACS_HLINE, XLENGTH);
134 mvaddch(ybase + YDEPTH - 1, xbase - 2 + XLENGTH, ACS_LRCORNER);
136 move(ybase - 1, xbase - 3);
137 vline(ACS_VLINE, YDEPTH);
139 move(ybase - 1, xbase - 2 + XLENGTH);
140 vline(ACS_VLINE, YDEPTH);
142 attrset(COLOR_PAIR(2));
148 tm = localtime(&now);
149 set(tm->tm_sec % 10, 0);
150 set(tm->tm_sec / 10, 4);
151 set(tm->tm_min % 10, 10);
152 set(tm->tm_min / 10, 14);
153 set(tm->tm_hour % 10, 20);
154 set(tm->tm_hour / 10, 24);
157 for(k = 0; k < 6; k++) {
159 snooze(scroll_msecs / 6);
160 for(i = 0; i < 5; i++)
161 new[i] = (new[i] & ~mask) |
163 new[5] = (new[5] & ~mask) | (next[k] & mask);
165 new[k] = (new[k] & ~mask) | (next[k] & mask);
167 for (s = 1; s >= 0; s--) {
169 for (i = 0; i < 6; i++) {
180 snooze(1000 - (scrol ? scroll_msecs : 0));
181 } while (forever ? 1 : --n);
190 snooze(long int msecs)
195 ts.tv_nsec = 1000000 * msecs;
197 nanosleep(&ts, NULL);
204 errx(1, "terminated by signal %d", (int)sigtermed);
209 draw_row(int i, int s)
214 if ((a = (new[i] ^ old[i]) & (s ? new : old)[i]) != 0) {
215 for (j = 0, t = 1 << 26; t; t >>= 1, j++) {
217 if (!(a & (t << 1))) {
218 move(ybase + i, xbase + 2 * j);
235 for (i = 0; i < 5; i++) {
236 next[i] |= ((disp[t] >> (4 - i) * 3) & 07) << n;
237 mask |= (next[i] ^ old[i]) & m;
248 attron(COLOR_PAIR(1));
254 attron(COLOR_PAIR(2));
264 fprintf(stderr, "usage: grdc [-s] [-d msecs] [n]\n");