1 /* $Header: /usr/home/yav/lupe/RCS/timer.c,v 1.3 1998/08/26 07:37:01 yav Exp $ 2 * Lupe Time control routine 3 * written by yav <yav@mte.biglobe.ne.jp> 4 */ 5 6 char rcsid_timer[] = "$Id: timer.c,v 1.3 1998/08/26 07:37:01 yav Exp $"; 7 8 #include <X11/Xos.h> 9 #include <stdio.h> 10 #include "config.h" 11 12 #include "timer.h" 13 14 diff_time(p1,p0)15long diff_time(p1, p0) 16 struct TMV *p1; 17 struct TMV *p0; 18 { 19 struct TMV tm; 20 21 tm.tv_sec = p1->tv_sec - p0->tv_sec; 22 tm.tv_usec = p1->tv_usec - p0->tv_usec; 23 if (tm.tv_usec < 0) { 24 tm.tv_usec += 1000000; 25 tm.tv_sec--; 26 } 27 if (tm.tv_sec > 86400L) /* 24 hour */ 28 tm.tv_sec = 86400L; 29 return tm.tv_sec * 1000 + tm.tv_usec / 1000; 30 } 31 add_time(p,n)32void add_time(p, n) 33 struct TMV *p; 34 long n; /* milliseconds */ 35 { 36 p->tv_sec += n / 1000; 37 p->tv_usec += (n % 1000) * 1000; 38 if (p->tv_usec < 0) { 39 p->tv_usec += 1000000; 40 p->tv_sec--; 41 } else if (p->tv_usec >= 1000000) { 42 p->tv_usec -= 1000000; 43 p->tv_sec++; 44 } 45 } 46 47 /* End of file */ 48