git: 7b45ad3f89cc - main - script -T skip timstamps for same second

From: Simon J. Gerraty <sjg_at_FreeBSD.org>
Date: Thu, 10 Mar 2022 06:20:00 UTC
The branch main has been updated by sjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=7b45ad3f89cc4d65a23f7d034329dd3f8dd3105f

commit 7b45ad3f89cc4d65a23f7d034329dd3f8dd3105f
Author:     Simon J. Gerraty <sjg@FreeBSD.org>
AuthorDate: 2022-03-10 06:19:53 +0000
Commit:     Simon J. Gerraty <sjg@FreeBSD.org>
CommitDate: 2022-03-10 06:19:53 +0000

    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 2e540a935ecd..e469b13fc65b 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;