grdc.c (210755) | grdc.c (210809) |
---|---|
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 210755 2010-08-02 12:15:22Z uqs $ | 14 * $FreeBSD: head/games/grdc/grdc.c 210809 2010-08-03 16:02:57Z uqs $ |
15 */ 16 17#include <err.h> | 15 */ 16 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> |
22#ifndef NONPOSIX | 21#include <time.h> |
23#include <unistd.h> | 22#include <unistd.h> |
24#endif | |
25 26#define YBASE 10 27#define XBASE 10 28#define XLENGTH 58 29#define YDEPTH 7 30 | 23 24#define YBASE 10 25#define XBASE 10 26#define XLENGTH 58 27#define YDEPTH 7 28 |
31/* it won't be */ 32struct timespec now; /* yeah! */ | 29struct timespec now; |
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 --- 42 unchanged lines hidden (view full) --- 83 argc -= optind; 84 argv += optind; 85 86 if (argc > 1) { 87 usage(); 88 /* NOTREACHED */ 89 } 90 | 30struct tm *tm; 31 32short disp[11] = { 33 075557, 011111, 071747, 071717, 055711, 34 074717, 074757, 071111, 075757, 075717, 002020 35}; 36long old[6], next[6], new[6], mask; 37 --- 42 unchanged lines hidden (view full) --- 80 argc -= optind; 81 argv += optind; 82 83 if (argc > 1) { 84 usage(); 85 /* NOTREACHED */ 86 } 87 |
91 if (argc > 0) | 88 if (argc > 0) { |
92 n = atoi(*argv) + 1; | 89 n = atoi(*argv) + 1; |
93 else | 90 if (n < 1) { 91 warnx("number of seconds is out of range"); 92 usage(); 93 /* NOTREACHED */ 94 } 95 } else |
94 n = 0; 95 96 initscr(); 97 98 signal(SIGINT,sighndl); 99 signal(SIGTERM,sighndl); 100 signal(SIGHUP,sighndl); 101 --- 85 unchanged lines hidden (view full) --- 187 } 188 if(!s) { 189 refresh(); 190 } 191 } 192 } 193 movto(6, 0); 194 refresh(); | 96 n = 0; 97 98 initscr(); 99 100 signal(SIGINT,sighndl); 101 signal(SIGTERM,sighndl); 102 signal(SIGHUP,sighndl); 103 --- 85 unchanged lines hidden (view full) --- 189 } 190 if(!s) { 191 refresh(); 192 } 193 } 194 } 195 movto(6, 0); 196 refresh(); |
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; | 197 clock_gettime(CLOCK_REALTIME_FAST, &delay); 198 if (delay.tv_sec == now.tv_sec) { 199 if (delay.tv_nsec > 0) { 200 delay.tv_sec = 0; 201 delay.tv_nsec = 1000000000 - delay.tv_nsec; 202 } else { 203 delay.tv_sec = 1; 204 delay.tv_nsec = 0; 205 } 206 nanosleep(&delay, NULL); 207 clock_gettime(CLOCK_REALTIME_FAST, &delay); |
202 } | 208 } |
203 nanosleep(&delay, NULL); 204 now.tv_sec++; | 209 n -= delay.tv_sec - now.tv_sec; 210 now.tv_sec = delay.tv_sec; |
205 if (sigtermed) { 206 standend(); 207 clear(); 208 refresh(); 209 endwin(); 210 errx(1, "terminated by signal %d", (int)sigtermed); 211 } | 211 if (sigtermed) { 212 standend(); 213 clear(); 214 refresh(); 215 endwin(); 216 errx(1, "terminated by signal %d", (int)sigtermed); 217 } |
212 } while(--n); | 218 } while (n); |
213 standend(); 214 clear(); 215 refresh(); 216 endwin(); 217 return(0); 218} 219 220void --- 44 unchanged lines hidden --- | 219 standend(); 220 clear(); 221 refresh(); 222 endwin(); 223 return(0); 224} 225 226void --- 44 unchanged lines hidden --- |