X-Git-Url: https://git.distorted.org.uk/~mdw/odin-cgi/blobdiff_plain/fc8074b35d1b16d35726247fcc0dc86d59b83a3a..cc346ee1adf852ba0f4322bc04a78ec64206d37a:/lib/Odin.pm diff --git a/lib/Odin.pm b/lib/Odin.pm index 26a2f80..e373dcc 100644 --- a/lib/Odin.pm +++ b/lib/Odin.pm @@ -5,6 +5,7 @@ package Odin; use DBI; use Digest::SHA qw(sha256_hex); use MIME::Base64; +use POSIX; ###-------------------------------------------------------------------------- ### Early utilities. @@ -87,6 +88,26 @@ sub nice_name ($) { return lc $s; } +sub print_columns (@) { + my @col = reverse @_; + my @fmt = (); + my @val = (); + while (@col && $col[1] eq "") { splice @col, 0, 2; } + my ($wd, $v) = splice @col, 0, 2; + push @fmt, "%s"; push @val, $v; + while (@col) { + my ($wd, $v) = splice @col, 0, 2; + push @fmt, "%-${wd}s"; + push @val, $v; + } + printf join(" ", reverse @fmt) . "\n", reverse @val; +} + +sub fmt_time ($) { + my ($t) = @_; + return $t == -1 ? "--" : strftime "%Y-%m-%d %H:%M:%S %z", localtime $t; +} + ###-------------------------------------------------------------------------- ### Database utilities.