summaryrefslogtreecommitdiffstats
path: root/usr.bin/tip/libacu/tod.c
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1995-03-31 11:47:39 +0000
committerjkh <jkh@FreeBSD.org>1995-03-31 11:47:39 +0000
commit3242e11e9593d569dc8e7447c3b6b26c72b02b36 (patch)
tree4b4b5f98381e910933ef0179588ce521ea608ffb /usr.bin/tip/libacu/tod.c
parent18a762fab9a5d5516afdc13d9767d3e1923b75f4 (diff)
downloadFreeBSD-src-3242e11e9593d569dc8e7447c3b6b26c72b02b36.zip
FreeBSD-src-3242e11e9593d569dc8e7447c3b6b26c72b02b36.tar.gz
Tom Gray's new tip changes to support a modem capabilities database and
fixes to many assorted bugs and misfeatures. Submitted by: Tom Gray - DCA <dcasba@rain.org>
Diffstat (limited to 'usr.bin/tip/libacu/tod.c')
-rw-r--r--usr.bin/tip/libacu/tod.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/usr.bin/tip/libacu/tod.c b/usr.bin/tip/libacu/tod.c
new file mode 100644
index 0000000..62ccddc
--- /dev/null
+++ b/usr.bin/tip/libacu/tod.c
@@ -0,0 +1,107 @@
+/*
+ * tod.c -- time of day pseudo-class implementation
+ *
+ * Copyright (c) 1995 John H. Poplett
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice immediately at the beginning of the file, without modification,
+ * this list of conditions, and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Absolutely no warranty of function or purpose is made by the author
+ * John H. Poplett.
+ * 4. This work was done expressly for inclusion into FreeBSD. Other use
+ * is allowed if this notation is included.
+ * 5. Modifications may be freely made to this file if the above conditions
+ * are met.
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include <assert.h>
+#include <stdio.h>
+
+#include "tod.h"
+
+#define USP 1000000
+
+int tod_cmp (const struct timeval *a, const struct timeval *b)
+{
+ int rc;
+ assert (a->tv_usec <= USP);
+ assert (b->tv_usec <= USP);
+ rc = a->tv_sec - b->tv_sec;
+ if (rc == 0)
+ rc = a->tv_usec - b->tv_usec;
+ return rc;
+}
+
+/*
+ TOD < command
+*/
+int tod_lt (const struct timeval *a, const struct timeval *b)
+{
+ return tod_cmp (a, b) < 0;
+}
+
+int tod_gt (const struct timeval *a, const struct timeval *b)
+{
+ return tod_cmp (a, b) > 0;
+}
+
+int tod_lte (const struct timeval *a, const struct timeval *b)
+{
+ return tod_cmp (a, b) <= 0;
+}
+
+int tod_gte (const struct timeval *a, const struct timeval *b)
+{
+ return tod_cmp (a, b) >= 0;
+}
+
+int tod_eq (const struct timeval *a, const struct timeval *b)
+{
+ return tod_cmp (a, b) == 0;
+}
+
+/*
+ TOD += command
+*/
+void tod_addto (struct timeval *a, const struct timeval *b)
+{
+ a->tv_usec += b->tv_usec;
+ a->tv_sec += b->tv_sec + a->tv_usec / USP;
+ a->tv_usec %= USP;
+}
+
+/*
+ TOD -= command
+*/
+void tod_subfrom (struct timeval *a, struct timeval b)
+{
+ assert (a->tv_usec <= USP);
+ assert (b.tv_usec <= USP);
+ if (b.tv_usec > a->tv_usec)
+ {
+ a->tv_usec += USP;
+ a->tv_sec -= 1;
+ }
+ a->tv_usec -= b.tv_usec;
+ a->tv_sec -= b.tv_sec;
+}
+
+void tod_gettime (struct timeval *tp)
+{
+ gettimeofday (tp, NULL);
+ tp->tv_sec += tp->tv_usec / USP;
+ tp->tv_usec %= USP;
+}
+
+/* end of tod.c */
OpenPOWER on IntegriCloud