grdc.c (116739) | grdc.c (203760) |
---|---|
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 116739 2003-06-23 16:01:11Z will $ | 14 * $FreeBSD: head/games/grdc/grdc.c 203760 2010-02-10 18:20:20Z delphij $ |
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 --- 31 unchanged lines hidden (view full) --- 54 sigtermed=signo; 55} 56 57int 58main(argc, argv) 59int argc; 60char **argv; 61{ | 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 --- 31 unchanged lines hidden (view full) --- 54 sigtermed=signo; 55} 56 57int 58main(argc, argv) 59int argc; 60char **argv; 61{ |
62struct timespec ts; |
|
62long t, a; 63int i, j, s, k; 64int n; 65int ch; 66int scrol; 67int t12; 68 69 t12 = scrol = 0; --- 61 unchanged lines hidden (view full) --- 131 move(YBASE - 1, XBASE - 3); 132 vline(ACS_VLINE, YDEPTH); 133 134 move(YBASE - 1, XBASE - 2 + XLENGTH); 135 vline(ACS_VLINE, YDEPTH); 136 137 attrset(COLOR_PAIR(2)); 138 } | 63long t, a; 64int i, j, s, k; 65int n; 66int ch; 67int scrol; 68int t12; 69 70 t12 = scrol = 0; --- 61 unchanged lines hidden (view full) --- 132 move(YBASE - 1, XBASE - 3); 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 time(&now); |
|
139 do { 140 mask = 0; | 141 do { 142 mask = 0; |
141 time(&now); | |
142 tm = localtime(&now); 143 set(tm->tm_sec%10, 0); 144 set(tm->tm_sec/10, 4); 145 set(tm->tm_min%10, 10); 146 set(tm->tm_min/10, 14); 147 148 if (t12) { 149 if (tm->tm_hour > 12) { --- 38 unchanged lines hidden (view full) --- 188 } 189 if(!s) { 190 refresh(); 191 } 192 } 193 } 194 movto(6, 0); 195 refresh(); | 143 tm = localtime(&now); 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 149 if (t12) { 150 if (tm->tm_hour > 12) { --- 38 unchanged lines hidden (view full) --- 189 } 190 if(!s) { 191 refresh(); 192 } 193 } 194 } 195 movto(6, 0); 196 refresh(); |
196 sleep(1); | 197 clock_gettime(CLOCK_REALTIME_FAST, &ts); 198 if (ts.tv_sec == now) { 199 if (ts.tv_nsec > 0) { 200 ts.tv_sec = 0; 201 ts.tv_nsec = 1000000000 - ts.tv_nsec; 202 } else { 203 ts.tv_sec = 1; 204 ts.tv_nsec = 0; 205 } 206 nanosleep(&ts, NULL); 207 now = ts.tv_sec + 1; 208 } else 209 now = ts.tv_sec; |
197 if (sigtermed) { 198 standend(); 199 clear(); 200 refresh(); 201 endwin(); 202 errx(1, "terminated by signal %d", (int)sigtermed); 203 } 204 } while(--n); --- 52 unchanged lines hidden --- | 210 if (sigtermed) { 211 standend(); 212 clear(); 213 refresh(); 214 endwin(); 215 errx(1, "terminated by signal %d", (int)sigtermed); 216 } 217 } while(--n); --- 52 unchanged lines hidden --- |