#!/bin/perl

my $O = $0;

$O =~ s@.*[\/\\]@@;
$O =~ s@.pl$@@i;

if ($#ARGV != 1) {
	printf STDERR "$O: usage is $O zone.tab tz-binary-directory\n";
	exit(1);
}

my ($zonetab, $tzdir) = @ARGV;

open(S, "<$zonetab") || die("cannot open $zonetab");
while(<S>) {
	s@[\r\n]@@g;
	s@\s*#.*@@;
	$zone = (split())[2];
	$zone eq "" && next;
	$binary = "$tzdir/$zone";
	open(T, "<$binary") || die("cannot open $binary");
	$posix = ();
	while (<T>) {
		$posix = $_;
	}
	close(T);
	$posix =~ s@[\r\n]@@g;
	if ($posix eq "") {
		$posix = $zone;
	}
	$result = $results{$posix};
	if ($result ne "") {
		$result .= " ";
	}
	$result .= $zone;
	$results{$posix} = $result;
}
close(S);

foreach (sort keys %results) {
	print "$_\t$results{$_}\n";
}


exit(0);

