Deleted Added
full compact
grdc.c (203920) grdc.c (210755)
1/*
2 * Grand digital clock for curses compatible terminals
3 * Usage: grdc [-st] [n] -- run for n seconds (default infinity)
4 * Flags: -s: scroll
5 * -t: output time in 12-hour format
6 *
7 *
8 * modified 10-18-89 for curses (jrl)
9 * 10-18-89 added signal handling
10 *
11 * modified 03-25-03 for 12 hour option
12 * - Samy Al Bahra <samy@kerneled.com>
13 *
1/*
2 * Grand digital clock for curses compatible terminals
3 * Usage: grdc [-st] [n] -- run for n seconds (default infinity)
4 * Flags: -s: scroll
5 * -t: output time in 12-hour format
6 *
7 *
8 * modified 10-18-89 for curses (jrl)
9 * 10-18-89 added signal handling
10 *
11 * modified 03-25-03 for 12 hour option
12 * - Samy Al Bahra <samy@kerneled.com>
13 *
14 * $FreeBSD: head/games/grdc/grdc.c 203920 2010-02-15 14:30:37Z uqs $
14 * $FreeBSD: head/games/grdc/grdc.c 210755 2010-08-02 12:15:22Z uqs $
15 */
16
17#include <err.h>
18#include <time.h>
19#include <signal.h>
20#include <ncurses.h>
21#include <stdlib.h>
22#ifndef NONPOSIX
23#include <unistd.h>
24#endif
25
26#define YBASE 10
27#define XBASE 10
28#define XLENGTH 58
29#define YDEPTH 7
30
31/* it won't be */
15 */
16
17#include <err.h>
18#include <time.h>
19#include <signal.h>
20#include <ncurses.h>
21#include <stdlib.h>
22#ifndef NONPOSIX
23#include <unistd.h>
24#endif
25
26#define YBASE 10
27#define XBASE 10
28#define XLENGTH 58
29#define YDEPTH 7
30
31/* it won't be */
32time_t now; /* yeah! */
32struct timespec now; /* yeah! */
33struct tm *tm;
34
35short disp[11] = {
36 075557, 011111, 071747, 071717, 055711,
37 074717, 074757, 071111, 075757, 075717, 002020
38};
39long old[6], next[6], new[6], mask;
40

--- 11 unchanged lines hidden (view full) ---

52sighndl(int signo)
53{
54 sigtermed=signo;
55}
56
57int
58main(int argc, char *argv[])
59{
33struct tm *tm;
34
35short disp[11] = {
36 075557, 011111, 071747, 071717, 055711,
37 074717, 074757, 071111, 075757, 075717, 002020
38};
39long old[6], next[6], new[6], mask;
40

--- 11 unchanged lines hidden (view full) ---

52sighndl(int signo)
53{
54 sigtermed=signo;
55}
56
57int
58main(int argc, char *argv[])
59{
60 struct timespec ts;
60 struct timespec delay;
61 long t, a;
62 int i, j, s, k;
63 int n;
64 int ch;
65 int scrol;
66 int t12;
67
68 t12 = scrol = 0;

--- 15 unchanged lines hidden (view full) ---

84 argv += optind;
85
86 if (argc > 1) {
87 usage();
88 /* NOTREACHED */
89 }
90
91 if (argc > 0)
61 long t, a;
62 int i, j, s, k;
63 int n;
64 int ch;
65 int scrol;
66 int t12;
67
68 t12 = scrol = 0;

--- 15 unchanged lines hidden (view full) ---

84 argv += optind;
85
86 if (argc > 1) {
87 usage();
88 /* NOTREACHED */
89 }
90
91 if (argc > 0)
92 n = atoi(*argv);
92 n = atoi(*argv) + 1;
93 else
94 n = 0;
95
96 initscr();
97
98 signal(SIGINT,sighndl);
99 signal(SIGTERM,sighndl);
100 signal(SIGHUP,sighndl);

--- 29 unchanged lines hidden (view full) ---

130 move(YBASE - 1, XBASE - 3);
131 vline(ACS_VLINE, YDEPTH);
132
133 move(YBASE - 1, XBASE - 2 + XLENGTH);
134 vline(ACS_VLINE, YDEPTH);
135
136 attrset(COLOR_PAIR(2));
137 }
93 else
94 n = 0;
95
96 initscr();
97
98 signal(SIGINT,sighndl);
99 signal(SIGTERM,sighndl);
100 signal(SIGHUP,sighndl);

--- 29 unchanged lines hidden (view full) ---

130 move(YBASE - 1, XBASE - 3);
131 vline(ACS_VLINE, YDEPTH);
132
133 move(YBASE - 1, XBASE - 2 + XLENGTH);
134 vline(ACS_VLINE, YDEPTH);
135
136 attrset(COLOR_PAIR(2));
137 }
138 time(&now);
138 clock_gettime(CLOCK_REALTIME_FAST, &now);
139 do {
140 mask = 0;
139 do {
140 mask = 0;
141 tm = localtime(&now);
141 tm = localtime(&now.tv_sec);
142 set(tm->tm_sec%10, 0);
143 set(tm->tm_sec/10, 4);
144 set(tm->tm_min%10, 10);
145 set(tm->tm_min/10, 14);
146
147 if (t12) {
148 if (tm->tm_hour > 12) {
149 tm->tm_hour -= 12;

--- 37 unchanged lines hidden (view full) ---

187 }
188 if(!s) {
189 refresh();
190 }
191 }
192 }
193 movto(6, 0);
194 refresh();
142 set(tm->tm_sec%10, 0);
143 set(tm->tm_sec/10, 4);
144 set(tm->tm_min%10, 10);
145 set(tm->tm_min/10, 14);
146
147 if (t12) {
148 if (tm->tm_hour > 12) {
149 tm->tm_hour -= 12;

--- 37 unchanged lines hidden (view full) ---

187 }
188 if(!s) {
189 refresh();
190 }
191 }
192 }
193 movto(6, 0);
194 refresh();
195 clock_gettime(CLOCK_REALTIME_FAST, &ts);
196 if (ts.tv_sec == now) {
197 if (ts.tv_nsec > 0) {
198 ts.tv_sec = 0;
199 ts.tv_nsec = 1000000000 - ts.tv_nsec;
200 } else {
201 ts.tv_sec = 1;
202 ts.tv_nsec = 0;
203 }
204 nanosleep(&ts, NULL);
205 now = ts.tv_sec + 1;
206 } else
207 now = ts.tv_sec;
195 clock_gettime(CLOCK_REALTIME_FAST, &now);
196 if (delay.tv_nsec > 0) {
197 delay.tv_sec = 0;
198 delay.tv_nsec = 1000000000 - now.tv_nsec;
199 } else {
200 delay.tv_sec = 1;
201 delay.tv_nsec = 0;
202 }
203 nanosleep(&delay, NULL);
204 now.tv_sec++;
208 if (sigtermed) {
209 standend();
210 clear();
211 refresh();
212 endwin();
213 errx(1, "terminated by signal %d", (int)sigtermed);
214 }
215 } while(--n);

--- 52 unchanged lines hidden ---
205 if (sigtermed) {
206 standend();
207 clear();
208 refresh();
209 endwin();
210 errx(1, "terminated by signal %d", (int)sigtermed);
211 }
212 } while(--n);

--- 52 unchanged lines hidden ---