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 $
12 * $DragonFly: src/games/grdc/grdc.c,v 1.6 2007/04/18 18:32:12 swildner Exp $
32 075557, 011111, 071747, 071717, 055711,
33 074717, 074757, 071111, 075757, 075717, 002020
35 long old[6], next[6], new[6], mask;
37 volatile sig_atomic_t sigtermed;
40 long int scroll_msecs = 120;
41 int xbase, ybase, xmax, ymax;
43 static void set(int, int);
44 static void standt(int);
45 static void sighndl(int);
46 static void usage(void);
47 static void draw_row(int, int);
48 static void snooze(long int);
57 main(int argc, char **argv)
67 while ((ch = getopt(argc, argv, "d:s")) != -1)
70 scroll_msecs = atol(optarg);
72 errx(1, "scroll duration may not be negative");
97 getmaxyx(stdscr, ymax, xmax);
98 if (ymax < YDEPTH + 2 || xmax < XLENGTH + 4) {
100 errx(1, "terminal too small");
102 xbase = (xmax - XLENGTH) / 2 + 2;
103 ybase = (ymax - YDEPTH) / 2 + 1;
105 signal(SIGINT, sighndl);
106 signal(SIGTERM, sighndl);
107 signal(SIGHUP, sighndl);
113 hascolor = has_colors();
117 init_pair(1, COLOR_BLACK, COLOR_RED);
118 init_pair(2, COLOR_RED, COLOR_BLACK);
119 init_pair(3, COLOR_WHITE, COLOR_BLACK);
120 attrset(COLOR_PAIR(2));
127 attrset(COLOR_PAIR(3));
129 mvaddch(ybase - 2, xbase - 3, ACS_ULCORNER);
130 hline(ACS_HLINE, XLENGTH);
131 mvaddch(ybase - 2, xbase - 2 + XLENGTH, ACS_URCORNER);
133 mvaddch(ybase + YDEPTH - 1, xbase - 3, ACS_LLCORNER);
134 hline(ACS_HLINE, XLENGTH);
135 mvaddch(ybase + YDEPTH - 1, xbase - 2 + XLENGTH, ACS_LRCORNER);
137 move(ybase - 1, xbase - 3);
138 vline(ACS_VLINE, YDEPTH);
140 move(ybase - 1, xbase - 2 + XLENGTH);
141 vline(ACS_VLINE, YDEPTH);
143 attrset(COLOR_PAIR(2));
149 tm = localtime(&now);
150 set(tm->tm_sec % 10, 0);
151 set(tm->tm_sec / 10, 4);
152 set(tm->tm_min % 10, 10);
153 set(tm->tm_min / 10, 14);
154 set(tm->tm_hour % 10, 20);
155 set(tm->tm_hour / 10, 24);
158 for(k = 0; k < 6; k++) {
160 snooze(scroll_msecs / 6);
161 for(i = 0; i < 5; i++)
162 new[i] = (new[i] & ~mask) |
164 new[5] = (new[5] & ~mask) | (next[k] & mask);
166 new[k] = (new[k] & ~mask) | (next[k] & mask);
168 for (s = 1; s >= 0; s--) {
170 for (i = 0; i < 6; i++) {
181 snooze(1000 - (scrol ? scroll_msecs : 0));
182 } while (forever ? 1 : --n);
191 snooze(long int msecs)
196 ts.tv_nsec = 1000000 * msecs;
198 nanosleep(&ts, NULL);
205 errx(1, "terminated by signal %d", (int)sigtermed);
210 draw_row(int i, int s)
215 if ((a = (new[i] ^ old[i]) & (s ? new : old)[i]) != 0) {
216 for (j = 0, t = 1 << 26; t; t >>= 1, j++) {
218 if (!(a & (t << 1))) {
219 move(ybase + i, xbase + 2 * j);
236 for (i = 0; i < 5; i++) {
237 next[i] |= ((disp[t] >> (4 - i) * 3) & 07) << n;
238 mask |= (next[i] ^ old[i]) & m;
249 attron(COLOR_PAIR(1));
255 attron(COLOR_PAIR(2));
265 fprintf(stderr, "usage: grdc [-s] [-d msecs] [n]\n");