#!/project/perl/perls/perl-5.20.2/bin/perl


require '../wp4.pl';


$horse = $ARGV[0];
$banusi = $ARGV[1];
$reisei = $ARGV[2];

&print_header();

&get_data("1999.dat");
&get_data("2000.dat");

print "<table class='default'>\n";
print "<th>出走レース名<th>競馬場<th>コース<th>天候・馬場<th>着順<th>斤量<th>ポイント<th>条件\n";
for $_ (@data)
{
    ($rname, $grade, $loc, $sd, $distance, $weather, $cond, $desc, $jun, $kinryo, $point) = split;

    print "<tr>\n";
    print "<td nowrap><font color=$color{$grade}>［$grade］</font> $rname\n";
    print "<td nowrap align = center>$loc\n";
    print "<td nowrap>$sd$distance\n";
    print "<td nowrap>$weather・$cond\n";
    print "<td nowrap align = center>$jun\n";
    print "<td nowrap align = center>$kinryo kg\n";
    print "<td align = right>$point\n";
    print "<td nowrap align = left>$desc\n";
    print "</tr>\n";
}


print << "EOF";

</table>
</BODY>
</html>

EOF


sub print_header
{
    print << "EOF";
Content-type: text/html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>$horse の戦績</title>
<link rel="stylesheet" type="text/css" href="/css/style.css" />
</HEAD>
<body>

<h1>$horse　$reisei　$banusi氏所有</h1>

EOF

}


sub get_data
{
    open(IN, $_[0]);
    while (<IN>) {
    
    next if /\\begin/;

    chomp;

    if (/\\race/) {
        ($dum, $rname, $grade, $loc, $sd, $distance, $weather, $cond, $desc) = split;
        $desc = "-" if $desc eq "";
        $loc = "-" if $loc eq "";
        $weather = "-" if $weather eq "";
        $cond = "-" if $cond eq "";
        $sd = "-" if $sd eq "";
        $distance = "-" if $distance eq "";
    }
    else {
        ($jun, $hname, $hreisei, $kinryo, $hbanusi, $time, $point) = split;

        $point = 0 if $point eq "";
        if ($hname eq $horse && $hbanusi eq $banusi) {
            push(@data, "$rname $grade $loc $sd $distance $weather $cond $desc $jun $kinryo $point");
        }
    }
}
close(IN);
}
