DragonFly BSD
DragonFly submit List (threaded) for 2004-07
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Patch so grdc ticks when it should


From: Paul Herman <pherman@xxxxxxxxxxxxxxx>
Date: Wed, 28 Jul 2004 17:11:04 -0700 (PDT)

Right now /usr/games/grdc simply sleeps one second and then refreshes then screen. Slightly annoying if you have two synced machines next to each other that display different times.

The following patch fixes that behavior.

-Paul.

--- grdc.c.orig	2004-07-28 15:49:50.000000000 -0700
+++ grdc.c	2004-07-28 16:59:10.000000000 -0700
@@ -25,7 +25,7 @@
 #define XLENGTH 58
 #define YDEPTH  7

-time_t now;
+struct timespec now;
 struct tm *tm;

 short disp[11] = {
@@ -55,6 +55,7 @@
 int
 main(int argc, char **argv)
 {
+	struct timespec ts;
 	int i, s, k;
 	int n;
 	int ch;
@@ -144,8 +145,19 @@
 	}
 	do {
 		mask = 0;
-		time(&now);
-		tm = localtime(&now);
+		clock_gettime(CLOCK_REALTIME, &now);
+		if (scrol) {
+			/*
+			 * The time we really wish to display is now + scroll_msecs
+			 */
+			now.tv_nsec /= 1000;
+			now.tv_nsec += scroll_msecs * 1000;
+			while (now.tv_nsec > 1000000) {
+				now.tv_sec++;
+				now.tv_nsec -= 1000000;
+			}
+		}
+		tm = localtime(&now.tv_sec);
 		set(tm->tm_sec % 10, 0);
 		set(tm->tm_sec / 10, 4);
 		set(tm->tm_min % 10, 10);
@@ -156,7 +168,7 @@
 		set(10, 17);
 		for(k = 0; k < 6; k++) {
 			if (scrol) {
-				snooze(scroll_msecs / 6);
+				usleep(1000 * scroll_msecs / 6);
 				for(i = 0; i < 5; i++)
 					new[i] = (new[i] & ~mask) |
 						 (new[i+1] & mask);
@@ -177,7 +189,7 @@
 		}
 		move(ybase, 0);
 		refresh();
-		snooze(1000 - (scrol ? scroll_msecs : 0));
+		snooze(scrol ? scroll_msecs : 0);
 	} while (forever ? 1 : --n);
 	standend();
 	clear();
@@ -191,9 +203,9 @@
 {
 	struct timespec ts;

+	clock_gettime(CLOCK_REALTIME, &ts);
+	ts.tv_nsec = 1000000000L - ts.tv_nsec - 1000000*msecs;
 	ts.tv_sec = 0;
-	ts.tv_nsec = 1000000 * msecs;
-
 	nanosleep(&ts, NULL);

if (sigtermed) {



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]