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
)
68 while ((ch
= getopt(argc
, argv
, "d:s")) != -1)
71 scroll_msecs
= atol(optarg
);
73 errx(1, "scroll duration may not be negative");
98 getmaxyx(stdscr
, ymax
, xmax
);
99 if (ymax
< YDEPTH
+ 2 || xmax
< XLENGTH
+ 4) {
101 errx(1, "terminal too small");
103 xbase
= (xmax
- XLENGTH
) / 2 + 2;
104 ybase
= (ymax
- YDEPTH
) / 2 + 1;
106 signal(SIGINT
, sighndl
);
107 signal(SIGTERM
, sighndl
);
108 signal(SIGHUP
, sighndl
);
114 hascolor
= has_colors();
118 init_pair(1, COLOR_BLACK
, COLOR_RED
);
119 init_pair(2, COLOR_RED
, COLOR_BLACK
);
120 init_pair(3, COLOR_WHITE
, COLOR_BLACK
);
121 attrset(COLOR_PAIR(2));
128 attrset(COLOR_PAIR(3));
130 mvaddch(ybase
- 2, xbase
- 3, ACS_ULCORNER
);
131 hline(ACS_HLINE
, XLENGTH
);
132 mvaddch(ybase
- 2, xbase
- 2 + XLENGTH
, ACS_URCORNER
);
134 mvaddch(ybase
+ YDEPTH
- 1, xbase
- 3, ACS_LLCORNER
);
135 hline(ACS_HLINE
, XLENGTH
);
136 mvaddch(ybase
+ YDEPTH
- 1, xbase
- 2 + XLENGTH
, ACS_LRCORNER
);
138 move(ybase
- 1, xbase
- 3);
139 vline(ACS_VLINE
, YDEPTH
);
141 move(ybase
- 1, xbase
- 2 + XLENGTH
);
142 vline(ACS_VLINE
, YDEPTH
);
144 attrset(COLOR_PAIR(2));
150 tm
= localtime(&now
);
151 set(tm
->tm_sec
% 10, 0);
152 set(tm
->tm_sec
/ 10, 4);
153 set(tm
->tm_min
% 10, 10);
154 set(tm
->tm_min
/ 10, 14);
155 set(tm
->tm_hour
% 10, 20);
156 set(tm
->tm_hour
/ 10, 24);
159 for(k
= 0; k
< 6; k
++) {
161 snooze(scroll_msecs
/ 6);
162 for(i
= 0; i
< 5; i
++)
163 new[i
] = (new[i
] & ~mask
) |
165 new[5] = (new[5] & ~mask
) | (next
[k
] & mask
);
167 new[k
] = (new[k
] & ~mask
) | (next
[k
] & mask
);
169 for (s
= 1; s
>= 0; s
--) {
171 for (i
= 0; i
< 6; i
++) {
182 snooze(1000 - (scrol
? scroll_msecs
: 0));
183 } while (forever
? 1 : --n
);
192 snooze(long int msecs
)
197 ts
.tv_nsec
= 1000000 * msecs
;
199 nanosleep(&ts
, NULL
);
206 errx(1, "terminated by signal %d", (int)sigtermed
);
211 draw_row(int i
, int s
)
216 if ((a
= (new[i
] ^ old
[i
]) & (s
? new : old
)[i
]) != 0) {
217 for (j
= 0, t
= 1 << 26; t
; t
>>= 1, j
++) {
219 if (!(a
& (t
<< 1))) {
220 move(ybase
+ i
, xbase
+ 2 * j
);
237 for (i
= 0; i
< 5; i
++) {
238 next
[i
] |= ((disp
[t
] >> (4 - i
) * 3) & 07) << n
;
239 mask
|= (next
[i
] ^ old
[i
]) & m
;
250 attron(COLOR_PAIR(1));
256 attron(COLOR_PAIR(2));
266 fprintf(stderr
, "usage: grdc [-s] [-d msecs] [n]\n");