From 2491528e5542153370122aa6f64424d30610562e Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sun, 21 Jun 2020 21:09:18 +0000 Subject: Add s6-tai64ndiff ; prepare for 2.2.3.0 --- src/skaembutils/deps-exe/s6-tai64ndiff | 1 + src/skaembutils/s6-tai64ndiff.c | 74 ++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/skaembutils/deps-exe/s6-tai64ndiff create mode 100644 src/skaembutils/s6-tai64ndiff.c (limited to 'src/skaembutils') diff --git a/src/skaembutils/deps-exe/s6-tai64ndiff b/src/skaembutils/deps-exe/s6-tai64ndiff new file mode 100644 index 0000000..e7187fe --- /dev/null +++ b/src/skaembutils/deps-exe/s6-tai64ndiff @@ -0,0 +1 @@ +-lskarnet diff --git a/src/skaembutils/s6-tai64ndiff.c b/src/skaembutils/s6-tai64ndiff.c new file mode 100644 index 0000000..25abea3 --- /dev/null +++ b/src/skaembutils/s6-tai64ndiff.c @@ -0,0 +1,74 @@ +/* ISC license. */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +int main (int argc, char const *const *argv) +{ + stralloc sa = STRALLOC_ZERO ; + tain_t prev ; + int defined = 0 ; + PROG = "s6-tai64ndiff" ; + + for (;;) + { + unsigned int p = 0 ; + char prefix[23] = "[ . ]" ; + int r = skagetln(buffer_0f1, &sa, '\n') ; + if (r == -1) + if (errno != EPIPE) + strerr_diefu1sys(111, "read from stdin") ; + else r = 1 ; + else if (!r) break ; + if (sa.len > TIMESTAMP) + { + tain_t cur ; + p = timestamp_scan(sa.s, &cur) ; + if (p) + { + if (defined) + { + tain_t diff ; + int64_t secs ; + size_t len ; + tain_sub(&diff, &cur, &prev) ; + secs = tai_sec(tain_secp(&diff)) ; + len = int64_fmt(0, secs) ; + if (len > 10) + { + char fmtn[9] ; + size_t m = 1 + (len < 20) ; + m += int64_fmt(prefix + m, secs) ; + prefix[m++] = '.' ; + uint320_fmt(fmtn, tain_nano(&diff), 9) ; + memcpy(prefix + m, fmtn, 22 - m) ; + } + else + { + int64_fmt(prefix + 11 - len, secs) ; + uint320_fmt(prefix + 12, tain_nano(&diff), 9) ; + } + } + prev = cur ; + defined = 1 ; + if (buffer_put(buffer_1, prefix, 23) < 23) + strerr_diefu1sys(111, "write to stdout") ; + } + else defined = 0 ; + } + else defined = 0 ; + if (buffer_put(buffer_1, sa.s + p, sa.len - p) < (ssize_t)(sa.len - p)) + strerr_diefu1sys(111, "write to stdout") ; + sa.len = 0 ; + } + return 0 ; +} -- cgit v1.2.3