From 58083ad34a6623a68888b91da04aade2c96ab84d Mon Sep 17 00:00:00 2001 From: Oliver Hartkopp Date: Mon, 12 Jun 2023 09:00:57 +0200 Subject: [PATCH] log2asc: fix logfiles where the timestamp starts with zero The ASC file banner, e.g. date Thu Jan 1 01:00:00 1970 base hex timestamps absolute no internal events logged should be printed when the first timestamp from the logfile has been processed. But for logfiles starting with zero (e.g. candump -tz option) this banner is printed every time the timestamps seconds equals zero. As it was obviously not a good idea to stick the condition for printing the banner based on some assumption about the timestamp a new variable 'print_banner' has been introduced. Reported-by: https://github.com/CaSchmidt Signed-off-by: Oliver Hartkopp --- log2asc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/log2asc.c b/log2asc.c index a1cf364..8b4bb34 100644 --- a/log2asc.c +++ b/log2asc.c @@ -190,6 +190,7 @@ int main(int argc, char **argv) FILE *infile = stdin; FILE *outfile = stdout; static int maxdev, devno, i, crlf, fdfmt, nortrdlc, d4, opt, mtu; + int print_banner = 1; while ((opt = getopt(argc, argv, "I:O:4nfr?")) != -1) { switch (opt) { @@ -272,7 +273,8 @@ int main(int argc, char **argv) } } - if (!start_tv.tv_sec) { /* print banner */ + if (print_banner) { /* print banner */ + print_banner = 0; start_tv = tv; fprintf(outfile, "date %s", ctime(&start_tv.tv_sec)); fprintf(outfile, "base hex timestamps absolute%s",