#!/usr/bin/perl -w
#
# This is purely used to generate a page on the website; it's not intended
# to be distributed or installed.

my $tmpl = q{
  <tr __BGCOLOR__><td><strong>

  __TYPE__

  </strong></td><td>
  <font size=-1>

  __DESCRIPTION__

  </font>
  </td><td>
  <font size=-1>

  __NAME__

  </font>
  </td><td>

  __SCORE__

  </td></tr>
};

while (<>) {
  s/#.*$//g; s/^\s+//; s/\s+$//;

  if (/^(header|body|full|describe)\s+(\S+)\s+(.+)$/) {
    if (!defined $test{$2}) {
      push (@testnames, $2);
      $type{$2} = $1;
    }
    $test{$2} = $3;
  }
  if (/^score\s+(\S+)\s+(.+)$/) {
    $score{$1} = $2;
  }
}

my $n = 0;
foreach my $t (@testnames) {
  $n++;
  $_ = $tmpl;
  $test = $test{$t};

  $test =~ s,&,&amp;,gs;	# protect HTML
  $test =~ s,<,&lt;,gs;
  $test =~ s,>,&gt;,gs;
  $test =~ s,\|,| ,gs;		# allow line breaks on pipes

  my $bgcolor = '';
  if ($n % 2 == 0) { $bgcolor = ' bgcolor=#ccffcc'; }

  s/__BGCOLOR__/$bgcolor/gs;
  s/__NAME__/$t/gs;
  s/__DESCRIPTION__/$test/gs;
  s/__TYPE__/$type{$t}/gs;
  s/__SCORE__/$score{$t} or 1/ges;
  print;
}

