From b1700594c3cae193d8e9e1b3d72cf815a3d91add Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 13 Sep 2023 00:13:14 -0500 Subject: [PATCH] Variable declarations go at the start of blocks (see design.html Coding Style) and we already have a "rel" variable for relative time: use the more obvious initialization for that. --- toys/other/ts.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/toys/other/ts.c b/toys/other/ts.c index f548aaaf..553af7d6 100644 --- a/toys/other/ts.c +++ b/toys/other/ts.c @@ -35,18 +35,18 @@ static long long millinow(void) void ts_main(void) { - char *mm = toybuf+sizeof(toybuf)-8, + char *line, *mm = toybuf+sizeof(toybuf)-8, *format = toys.optflags ? "%T" : "%b %d %T"; - long long start = millinow(), now, diff, rel = !!(toys.optflags&~FLAG_m); + long long start = millinow(), now, diff, rel = FLAG(i) || FLAG(s); struct tm *tm; time_t tt; - for (char *line; (line = xgetline(stdin)); free(line)) { + for (; (line = xgetline(stdin)); free(line)) { now = millinow(); diff = now - start*rel; if (FLAG(m)) sprintf(mm, ".%03lld", diff%1000); tt = diff/1000; - tm = (FLAG(i) || FLAG(s)) ? gmtime(&tt) : localtime(&tt); + tm = rel ? gmtime(&tt) : localtime(&tt); if (FLAG(i)) start = now; strftime(toybuf, sizeof(toybuf)-16, *toys.optargs ? : format, tm); xprintf("%s%s %s\n", toybuf, mm, line); -- 2.39.2