grdc.c (210809) | grdc.c (210827) |
---|---|
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 210809 2010-08-03 16:02:57Z uqs $ | 14 * $FreeBSD: head/games/grdc/grdc.c 210827 2010-08-03 20:56:23Z uqs $ |
15 */ 16 17#include <err.h> 18#include <ncurses.h> 19#include <signal.h> 20#include <stdlib.h> 21#include <time.h> 22#include <unistd.h> --- 27 unchanged lines hidden (view full) --- 50{ 51 sigtermed=signo; 52} 53 54int 55main(int argc, char *argv[]) 56{ 57 struct timespec delay; | 15 */ 16 17#include <err.h> 18#include <ncurses.h> 19#include <signal.h> 20#include <stdlib.h> 21#include <time.h> 22#include <unistd.h> --- 27 unchanged lines hidden (view full) --- 50{ 51 sigtermed=signo; 52} 53 54int 55main(int argc, char *argv[]) 56{ 57 struct timespec delay; |
58 time_t prev_sec; |
|
58 long t, a; 59 int i, j, s, k; 60 int n; 61 int ch; 62 int scrol; 63 int t12; 64 65 t12 = scrol = 0; --- 67 unchanged lines hidden (view full) --- 133 vline(ACS_VLINE, YDEPTH); 134 135 move(YBASE - 1, XBASE - 2 + XLENGTH); 136 vline(ACS_VLINE, YDEPTH); 137 138 attrset(COLOR_PAIR(2)); 139 } 140 clock_gettime(CLOCK_REALTIME_FAST, &now); | 59 long t, a; 60 int i, j, s, k; 61 int n; 62 int ch; 63 int scrol; 64 int t12; 65 66 t12 = scrol = 0; --- 67 unchanged lines hidden (view full) --- 134 vline(ACS_VLINE, YDEPTH); 135 136 move(YBASE - 1, XBASE - 2 + XLENGTH); 137 vline(ACS_VLINE, YDEPTH); 138 139 attrset(COLOR_PAIR(2)); 140 } 141 clock_gettime(CLOCK_REALTIME_FAST, &now); |
142 prev_sec = now.tv_sec; |
|
141 do { 142 mask = 0; 143 tm = localtime(&now.tv_sec); 144 set(tm->tm_sec%10, 0); 145 set(tm->tm_sec/10, 4); 146 set(tm->tm_min%10, 10); 147 set(tm->tm_min/10, 14); 148 --- 40 unchanged lines hidden (view full) --- 189 } 190 if(!s) { 191 refresh(); 192 } 193 } 194 } 195 movto(6, 0); 196 refresh(); | 143 do { 144 mask = 0; 145 tm = localtime(&now.tv_sec); 146 set(tm->tm_sec%10, 0); 147 set(tm->tm_sec/10, 4); 148 set(tm->tm_min%10, 10); 149 set(tm->tm_min/10, 14); 150 --- 40 unchanged lines hidden (view full) --- 191 } 192 if(!s) { 193 refresh(); 194 } 195 } 196 } 197 movto(6, 0); 198 refresh(); |
197 clock_gettime(CLOCK_REALTIME_FAST, &delay); 198 if (delay.tv_sec == now.tv_sec) { | 199 clock_gettime(CLOCK_REALTIME_FAST, &now); 200 if (now.tv_sec == prev_sec) { |
199 if (delay.tv_nsec > 0) { 200 delay.tv_sec = 0; | 201 if (delay.tv_nsec > 0) { 202 delay.tv_sec = 0; |
201 delay.tv_nsec = 1000000000 - delay.tv_nsec; | 203 delay.tv_nsec = 1000000000 - now.tv_nsec; |
202 } else { 203 delay.tv_sec = 1; 204 delay.tv_nsec = 0; 205 } 206 nanosleep(&delay, NULL); | 204 } else { 205 delay.tv_sec = 1; 206 delay.tv_nsec = 0; 207 } 208 nanosleep(&delay, NULL); |
207 clock_gettime(CLOCK_REALTIME_FAST, &delay); | 209 clock_gettime(CLOCK_REALTIME_FAST, &now); |
208 } | 210 } |
209 n -= delay.tv_sec - now.tv_sec; 210 now.tv_sec = delay.tv_sec; | 211 n -= now.tv_sec - prev_sec; 212 prev_sec = now.tv_sec; |
211 if (sigtermed) { 212 standend(); 213 clear(); 214 refresh(); 215 endwin(); 216 errx(1, "terminated by signal %d", (int)sigtermed); 217 } 218 } while (n); --- 52 unchanged lines hidden --- | 213 if (sigtermed) { 214 standend(); 215 clear(); 216 refresh(); 217 endwin(); 218 errx(1, "terminated by signal %d", (int)sigtermed); 219 } 220 } while (n); --- 52 unchanged lines hidden --- |