View | Details | Raw Unified | Return to bug 74178
Collapse All | Expand All

(-)grdc.c (-60 / +52 lines)
Lines 15-31 Link Here
15
 */
15
 */
16
16
17
#include <err.h>
17
#include <err.h>
18
#include <time.h>
19
#include <signal.h>
20
#include <ncurses.h>
18
#include <ncurses.h>
19
#include <signal.h>
21
#include <stdlib.h>
20
#include <stdlib.h>
21
#include <sys/time.h>
22
#include <time.h>
22
#ifndef NONPOSIX
23
#ifndef NONPOSIX
23
#include <unistd.h>
24
#include <unistd.h>
24
#endif
25
#endif
25
26
26
#define YBASE	10
27
#define YBASE	10
27
#define XBASE	10
28
#define XBASE	11
28
#define XLENGTH 58
29
int XLENGTH = 60;
29
#define YDEPTH  7
30
#define YDEPTH  7
30
31
31
/* it won't be */
32
/* it won't be */
Lines 36-41 Link Here
36
	075557, 011111, 071747, 071717, 055711,
37
	075557, 011111, 071747, 071717, 055711,
37
	074717, 074757, 071111, 075757, 075717, 002020
38
	074717, 074757, 071111, 075757, 075717, 002020
38
};
39
};
40
39
long old[6], next[6], new[6], mask;
41
long old[6], next[6], new[6], mask;
40
42
41
volatile sig_atomic_t sigtermed;
43
volatile sig_atomic_t sigtermed;
Lines 44-72 Link Here
44
46
45
void set(int, int);
47
void set(int, int);
46
void standt(int);
48
void standt(int);
47
void movto(int, int);
48
void sighndl(int);
49
void sighndl(int);
49
void usage(void);
50
void usage(void);
50
51
51
void sighndl(signo)
52
void
52
int signo;
53
sighndl(int signo)
53
{
54
{
54
	sigtermed=signo;
55
	sigtermed=signo;
55
}
56
}
56
57
57
int
58
int
58
main(argc, argv)
59
main(int argc, char *argv[])
59
int argc;
60
char **argv;
61
{
60
{
62
long t, a;
61
long t, a;
63
int i, j, s, k;
62
int i, j, s, k;
64
int n;
63
int n;
65
int ch;
64
int ch;
66
int scrol;
65
int scrol=0;
67
int t12;
66
int t12=0;
68
67
struct timespec tmsp;
69
	t12 = scrol = 0;
70
68
71
	while ((ch = getopt(argc, argv, "ts")) != -1)
69
	while ((ch = getopt(argc, argv, "ts")) != -1)
72
	switch (ch) {
70
	switch (ch) {
Lines 75-82 Link Here
75
		break;
73
		break;
76
	case 't':
74
	case 't':
77
		t12 = 1;
75
		t12 = 1;
76
		XLENGTH++;
78
		break;
77
		break;
79
	case '?':
80
	default:
78
	default:
81
		usage();
79
		usage();
82
		/* NOTREACHED */
80
		/* NOTREACHED */
Lines 89-104 Link Here
89
		/* NOTREACHED */
87
		/* NOTREACHED */
90
	}
88
	}
91
89
92
	if (argc > 0)
90
	n = (argc > 0)? atoi(*argv) : 0;
93
		n = atoi(*argv);
94
	else
95
		n = 0;
96
91
97
	initscr();
92
	initscr();
98
93
99
	signal(SIGINT,sighndl);
94
	signal(SIGINT, sighndl);
100
	signal(SIGTERM,sighndl);
95
	signal(SIGTERM, sighndl);
101
	signal(SIGHUP,sighndl);
96
	signal(SIGHUP, sighndl);
102
97
103
	cbreak();
98
	cbreak();
104
	noecho();
99
	noecho();
Lines 106-112 Link Here
106
101
107
	hascolor = has_colors();
102
	hascolor = has_colors();
108
103
109
	if(hascolor) {
104
	if (hascolor) {
110
		start_color();
105
		start_color();
111
		init_pair(1, COLOR_BLACK, COLOR_RED);
106
		init_pair(1, COLOR_BLACK, COLOR_RED);
112
		init_pair(2, COLOR_RED, COLOR_BLACK);
107
		init_pair(2, COLOR_RED, COLOR_BLACK);
Lines 117-144 Link Here
117
	clear();
112
	clear();
118
	refresh();
113
	refresh();
119
114
120
	if(hascolor) {
115
	if (hascolor) {
121
		attrset(COLOR_PAIR(3));
116
		attrset(COLOR_PAIR(3));
122
117
123
		mvaddch(YBASE - 2,  XBASE - 3, ACS_ULCORNER);
118
		mvaddch(YBASE - 2,  XBASE - 4, ACS_ULCORNER);
124
		hline(ACS_HLINE, XLENGTH);
119
		hline(ACS_HLINE, XLENGTH);
125
		mvaddch(YBASE - 2,  XBASE - 2 + XLENGTH, ACS_URCORNER);
120
		mvaddch(YBASE - 2,  XBASE - 3 + XLENGTH, ACS_URCORNER);
126
121
127
		mvaddch(YBASE + YDEPTH - 1,  XBASE - 3, ACS_LLCORNER);
122
		mvaddch(YBASE + YDEPTH - 1,  XBASE - 4, ACS_LLCORNER);
128
		hline(ACS_HLINE, XLENGTH);
123
		hline(ACS_HLINE, XLENGTH);
129
		mvaddch(YBASE + YDEPTH - 1,  XBASE - 2 + XLENGTH, ACS_LRCORNER);
124
		mvaddch(YBASE + YDEPTH - 1,  XBASE - 3 + XLENGTH, ACS_LRCORNER);
130
125
131
		move(YBASE - 1,  XBASE - 3);
126
		move(YBASE - 1,  XBASE - 4);
132
		vline(ACS_VLINE, YDEPTH);
127
		vline(ACS_VLINE, YDEPTH);
133
128
134
		move(YBASE - 1,  XBASE - 2 + XLENGTH);
129
		move(YBASE - 1,  XBASE - 3 + XLENGTH);
135
		vline(ACS_VLINE, YDEPTH);
130
		vline(ACS_VLINE, YDEPTH);
136
131
137
		attrset(COLOR_PAIR(2));
132
		attrset(COLOR_PAIR(2));
138
	}
133
	}
139
	do {
134
	do {
140
		mask = 0;
141
		time(&now);
135
		time(&now);
136
		mask = 0;
142
		tm = localtime(&now);
137
		tm = localtime(&now);
143
		set(tm->tm_sec%10, 0);
138
		set(tm->tm_sec%10, 0);
144
		set(tm->tm_sec/10, 4);
139
		set(tm->tm_sec/10, 4);
Lines 148-159 Link Here
148
		if (t12) {
143
		if (t12) {
149
			if (tm->tm_hour > 12) {
144
			if (tm->tm_hour > 12) {
150
				tm->tm_hour -= 12;
145
				tm->tm_hour -= 12;
151
				mvaddstr(YBASE + 5, XBASE + 52, "PM");
146
				mvaddstr(YBASE + 4, XBASE + 55, "PM");
152
			} else {
147
			} else {
153
				if (tm->tm_hour == 0)
148
				if (tm->tm_hour == 0)
154
					tm->tm_hour = 12;
149
					tm->tm_hour = 12;
155
150
				mvaddstr(YBASE + 4, XBASE + 55, "AM");
156
				mvaddstr(YBASE + 5, XBASE + 52, "AM");
157
			}
151
			}
158
		}
152
		}
159
153
Lines 161-199 Link Here
161
		set(tm->tm_hour/10, 24);
155
		set(tm->tm_hour/10, 24);
162
		set(10, 7);
156
		set(10, 7);
163
		set(10, 17);
157
		set(10, 17);
164
		for(k=0; k<6; k++) {
158
		for (k=0; k<6; k++) {
165
			if(scrol) {
159
			if (scrol) {
166
				for(i=0; i<5; i++)
160
				for (i=0; i<5; i++) {
167
					new[i] = (new[i]&~mask) | (new[i+1]&mask);
161
					new[i] = (new[i]&~mask) | (new[i+1]&mask);
162
					usleep(1);
163
				}
168
				new[5] = (new[5]&~mask) | (next[k]&mask);
164
				new[5] = (new[5]&~mask) | (next[k]&mask);
169
			} else
165
			} else
170
				new[k] = (new[k]&~mask) | (next[k]&mask);
166
				new[k] = (new[k]&~mask) | (next[k]&mask);
171
			next[k] = 0;
167
			next[k] = 0;
172
			for(s=1; s>=0; s--) {
168
			for (s=1; s>=0; s--) {
173
				standt(s);
169
				standt(s);
174
				for(i=0; i<6; i++) {
170
				for (i=0; i<6; i++) {
175
					if((a = (new[i]^old[i])&(s ? new : old)[i]) != 0) {
171
					if ((a = (new[i]^old[i])&(s ? new : old)[i]) != 0) {
176
						for(j=0,t=1<<26; t; t>>=1,j++) {
172
						for (j=0, t=1<<26; t; t>>=1, j++) {
177
							if(a&t) {
173
							if (a&t) {
178
								if(!(a&(t<<1))) {
174
								if (!(a&(t<<1))) {
179
									movto(YBASE + i, XBASE + 2*j);
175
									move(YBASE + i, XBASE + 2*j);
180
								}
176
								}
181
								addstr("  ");
177
								addstr("  ");
182
							}
178
							}
183
						}
179
						}
184
					}
180
					}
185
					if(!s) {
181
					if (!s) {
186
						old[i] = new[i];
182
						old[i] = new[i];
187
					}
183
					}
188
				}
184
				}
189
				if(!s) {
185
				if (!s) {
190
					refresh();
186
					refresh();
191
				}
187
				}
192
			}
188
			}
193
		}
189
		}
194
		movto(6, 0);
190
		move(6, 0);
195
		refresh();
191
		refresh();
196
		sleep(1);
197
		if (sigtermed) {
192
		if (sigtermed) {
198
			standend();
193
			standend();
199
			clear();
194
			clear();
Lines 201-207 Link Here
201
			endwin();
196
			endwin();
202
			errx(1, "terminated by signal %d", (int)sigtermed);
197
			errx(1, "terminated by signal %d", (int)sigtermed);
203
		}
198
		}
204
	} while(--n);
199
                clock_gettime(CLOCK_REALTIME, &tmsp);
200
                tmsp.tv_sec = 0;
201
                tmsp.tv_nsec = 1000000000 - tmsp.tv_nsec;
202
                nanosleep(&tmsp, NULL);
203
	} while (--n);
205
	standend();
204
	standend();
206
	clear();
205
	clear();
207
	refresh();
206
	refresh();
Lines 215-225 Link Here
215
int i, m;
214
int i, m;
216
215
217
	m = 7<<n;
216
	m = 7<<n;
218
	for(i=0; i<5; i++) {
217
	for (i=0; i<5; i++) {
219
		next[i] |= ((disp[t]>>(4-i)*3)&07)<<n;
218
		next[i] |= ((disp[t]>>(4-i)*3)&07)<<n;
220
		mask |= (next[i]^old[i])&m;
219
		mask |= (next[i]^old[i])&m;
221
	}
220
	}
222
	if(mask&m)
221
	if (mask&m)
223
		mask |= m;
222
		mask |= m;
224
}
223
}
225
224
Lines 227-239 Link Here
227
standt(int on)
226
standt(int on)
228
{
227
{
229
	if (on) {
228
	if (on) {
230
		if(hascolor) {
229
		if (hascolor) {
231
			attron(COLOR_PAIR(1));
230
			attron(COLOR_PAIR(1));
232
		} else {
231
		} else {
233
			attron(A_STANDOUT);
232
			attron(A_STANDOUT);
234
		}
233
		}
235
	} else {
234
	} else {
236
		if(hascolor) {
235
		if (hascolor) {
237
			attron(COLOR_PAIR(2));
236
			attron(COLOR_PAIR(2));
238
		} else {
237
		} else {
239
			attroff(A_STANDOUT);
238
			attroff(A_STANDOUT);
Lines 242-256 Link Here
242
}
241
}
243
242
244
void
243
void
245
movto(int line, int col)
246
{
247
	move(line, col);
248
}
249
250
void
251
usage(void)
244
usage(void)
252
{
245
{
253
254
	(void)fprintf(stderr, "usage: grdc [-st] [n]\n");
246
	(void)fprintf(stderr, "usage: grdc [-st] [n]\n");
255
	exit(1);
247
	exit(1);
256
}
248
}

Return to bug 74178