#!/usr/bin/perl -w

# show sorted content of tar archive

$0 =~ s:.*/::;

$usage = "usage: $0 file.tar\n";
die $usage if scalar(@ARGV) != 1 or "@ARGV" =~ /^-/;

$file = shift @ARGV;

die "$0: \"$file\" does not exist\n"        unless -e $file;
die "$0: \"$file\" is not a regular file\n" unless -f $file;
die "$0: \"$file\" is not readable\n"       unless -r $file;

open $list,'-|',qw'tar tvf',$file or exit $?;

while (<$list>) {
  if (/(.+?) (.+?) +(\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d) (.+)/) {
    $p{$5} = $1;
    $u{$5} = $2;
    $s{$5} = $3;
    $d{$5} = $4;
  }
}

foreach $f (sort keys %p) {
  printf "%s %-17s %13d %s %s\n",$p{$f},$u{$f},$s{$f},$d{$f},$f;
}
