#! /usr/local/bin/perl

sub usage {
    print STDERR <<EOH;
Usage: make_plane_list file1 file2
        file1:  result of show plane build
        file2:  result of show plane cap
EOH
}
&usage if (! $#ARGV == 1);

$BUILD_FILE = $ARGV[0]; $CAPAB_FILE = $ARGV[1];

open(build, $BUILD_FILE) || die "Could not open $BUILD_FILE: $!\n";
$first_line = <build>;
while (<build>) {
    chop;
    ($plane, $lcm, $hcm, $crew, $avail, $tech, $foo, $cost) = 
          unpack("A14 A4 A3 A4 A6 A5 A2 A6", $_);

    $PLANE{$plane} = pack("A3 A3 A4 A6 A5 A6", $lcm, $hcm, $crew, $avail, $tech, $cost);
}

open(capab, $CAPAB_FILE) || die "Could not open $CAPAB_FILE: $!\n";
$first_line = <capab>;
print "        Plane tech hcm/lcm(av)   ran/fuel at/df load\n";
while (<capab>) {
    chop;
    ($plane, $acc, $load, $att, $def, $ran, $fuel, $abilites) = 
          unpack("A14 A3 A5 A4 A4 A4 A6 A99", $_);
    ($lcm, $hcm, $crew, $avail, $tech, $cost) = unpack("A3 A3 A4 A6 A5 A6", $PLANE{$plane});

    $plane     =~ s/^\s//;  $abilites  =~ s/^\s//;

    $tech      =~ s/\s//g;  $avail     =~ s/\s//g;  $lcm       =~ s/\s//g;  $hcm       =~ s/\s//g;
    $cost      =~ s/\s//g;  $ran       =~ s/\s//g;  $fuel      =~ s/\s//g;  $att       =~ s/\s//g;
    $def       =~ s/\s//g;  $load      =~ s/\s//g;  $abilites  =~ s/^\s//;  

    printf("%13s %3s   %2s/%-2s(%2s) \$%-5s %2s/%-1s %2s/%-2s %1s %s\n",
                $plane, $tech, $lcm, $hcm, $avail, $cost, 
                $ran, $fuel, $att, $def, $load, $abilites);
}

