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


$kaisai_name = $ARGV[0];
$file = $ARGV[1];

&print_header();

print "<table>\n";

open(IN, $file);
while (<IN>)
{
    next if !/\\begin/;

    chomp;
    @tmp = split;

    if ($tmp[1] eq $kaisai_name) {

        while (<IN>) {
            chomp;
            @tmp = split;

            if (/\\begin/) {
                last;
            }

            elsif (/\\race/) {
                $tmp[8] = "条件なし" if $tmp[8] eq "";
                print "<tr bgcolor=#FFFF88>\n";
                print "<td nowrap>$tmp[2]\n";
                print "<td nowrap>$tmp[1]\n";
                print "<td colspan=6>$tmp[4]$tmp[5]　$tmp[3]　$tmp[6]　$tmp[7]<br>$tmp[8]\n";
            }

            else {
                print "<tr>\n";
                print "<td align = right nowrap>$tmp[0]\n";
                print "<td nowrap>$tmp[1]\n";
                print "<td nowrap>$tmp[2]\n";
                print "<td align = center nowrap>$tmp[3]\n";
                print "<td nowrap>$tmp[4]\n";
                print "<td align = right nowrap>$tmp[5]\n";
                print "<td align = right>$tmp[6]\n";
                print "<td nowrap><br>\n";
            }
        }
        last;
    }
}

print "</table></BODY></html>\n";


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>$kaisai_name の結果</title>
<link rel="stylesheet" type="text/css" href="/css/style.css" />
</HEAD>
<body>

<h1>$kaisai_name の結果</h1>
<hr>

EOF

}
