From 7b45ad3f89cc4d65a23f7d034329dd3f8dd3105f Mon Sep 17 00:00:00 2001 From: "Simon J. Gerraty" Date: Wed, 9 Mar 2022 22:19:53 -0800 Subject: [PATCH] script -T skip timstamps for same second The result is much more readable if we only output the time-stamp when it is at least 1s since last one. --- usr.bin/script/script.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c index 2e540a935ec..e469b13fc65 100644 --- a/usr.bin/script/script.c +++ b/usr.bin/script/script.c @@ -523,12 +523,14 @@ playback(FILE *fp) off_t nread, save_len; size_t l; time_t tclock; + time_t lclock; int reg; if (fstat(fileno(fp), &pst) == -1) err(1, "fstat failed"); reg = S_ISREG(pst.st_mode); + lclock = 0; for (nread = 0; !reg || nread < pst.st_size; nread += save_len) { if (fread(&stamp, sizeof(stamp), 1, fp) != 1) { @@ -574,9 +576,12 @@ playback(FILE *fp) if (tflg) { if (stamp.scr_len == 0) continue; - l = strftime(buf, sizeof buf, tstamp_fmt, - localtime(&tclock)); - (void)write(STDOUT_FILENO, buf, l); + if (tclock - lclock > 0) { + l = strftime(buf, sizeof buf, tstamp_fmt, + localtime(&tclock)); + (void)write(STDOUT_FILENO, buf, l); + } + lclock = tclock; } else { tsi.tv_sec = tso.tv_sec - tsi.tv_sec; tsi.tv_nsec = tso.tv_nsec - tsi.tv_nsec;