diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-07-02 17:36:37 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-07-02 22:57:07 +1200 |
commit | 95276f25769a0607cda50041169197d0522b98ff (patch) | |
tree | 3a4738901390c94f76de6ee7b6394d39b4c1ed00 /bin/hms.awk | |
parent | Coerce seed to number (diff) | |
download | dotfiles-95276f25769a0607cda50041169197d0522b98ff.tar.gz dotfiles-95276f25769a0607cda50041169197d0522b98ff.zip |
Lots of cleanup of awk scripts
Mostly inspired by suggestions from gawk --lint
Diffstat (limited to 'bin/hms.awk')
-rw-r--r-- | bin/hms.awk | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/bin/hms.awk b/bin/hms.awk index 3054db44..2aa492a1 100644 --- a/bin/hms.awk +++ b/bin/hms.awk @@ -1,19 +1,23 @@ # Convert seconds to colon-delimited durations BEGIN { OFS = ":" + ex = 0 + stderr = "" } # Refuse to deal with anything that's not a positive (unsigned) integer /[^0-9]/ { - print "hms: Bad number" | "cat >&2" - err = 1 + if (!stderr) + stderr = "cat >&2" + print "hms: Bad number" | stderr + ex = 1 next } # Integer looks valid { # Break it down into hours, minutes, and seconds - s = $0 + s = int($0 + 0) h = int(s / 3600) s %= 3600 m = int(s / 60) @@ -29,4 +33,8 @@ BEGIN { } # Done, exit 1 if we had any errors on the way -END { exit(err > 0) } +END { + if (stderr) + close(stderr) + exit(ex) +} |