#!/usr/bin/perl
# This script collects the set of CVS changes for a particular date 
# and builds a web page for them. This script was originally going to
# be a CGI script which is why it is written in perl, but there were
# problems accessesing CVS anonymously from the web server, so it is
# now only run at build time.
#
# usage: whatsNew YYYY-MM-DD
#
#

use CGI qw(:standard);

sub getPreviousVersion {
    local($version) = @_;
    ($major, $minor) = split(/\./, $version);
    $newVersion = $major . "." . ($minor -1);
}

$queryDate = param("date");
$queryDate = $ARGV[0] if $queryDate eq "";
$module = param("module");
$module = "sphinx4" if $module eq "";

$viewCVS = "http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/cmusphinx/";

print header();
print start_html("CMU Sphinx Source Changes on $queryDate") . "\n";

print table({cellpadding=>'0',
	     cellspacing=>'0',
	     border=>'0',
	     width=>'100%',
	     align=>'center',
	     bgcolor=>'#ccccff'},
	    Tr({valign=>'top',
		align=>'center'},
	       td(br,
		  big(big(b("\u$module", "Source Changes for", $queryDate))),
		  br,
		  br)
	      ),
	   ) . "\n";

print br, br, br . "\n";


#$cvs_history = "/usr/bin/cvs -d:pserver:anonymous\@cvs1:/cvsroot/cmusphinx history -ac";

$cvs_history_file = "cvs_history.gz";
$cvs_history = "gunzip -c $cvs_history_file";

open(HIST, "$cvs_history | ") or print "<p>Can't open cvs history.</p>";


@rows = th({align=>'CENTER',
	    valign=>'TOP', 
	    bgcolor=>'#ccccff'},
	   ["Path", "File", "Version", "Who"]
	  );

while (<HIST>) {
    next unless /$module/;
    next unless /$queryDate/;
    ($op, $date, $time, $lines, $who, $version, $file, $path, $foo,
    $bar) = split(/\s+/, $_);
    $fullPath = $path . "/" . $file;
    $versionURL = $viewCVS . $path . "/" . $file . "?rev=" . $version . 
	 "&content-type=text/vnd.viewcvs-markup";

    $diffURL = $viewCVS . $path . "/" . $file . ".diff?r1=" . $version
        . "&r2=" . getPreviousVersion($version);

    if ($file ne "regression.log") {
      push(@rows, 
	   td({align=>'LEFT',
	       valign=>'TOP'},
	      [$path,
	       a({href=>"$versionURL"}, $file),
	       a({href=>"$diffURL"},$version),
	       $who])
	  );
    }
}

close(HIST);

print table({align=>'center',
	     cellpadding=>'2',
	     cellspacing=>'2',
	     border=>'1',
	     width=>'80%'},
	    Tr((\@rows))
	   ) . "\n";

$date_string = (stat($cvs_history_file))[9];
if ((localtime($date_string))[8]) {
   $timeZone = localtime($date_string) . " PDT";
} else {
   $timeZone = localtime($date_string) . " PST";
}

print ul(
	 li(" Includes checkins up to", $timeZone),
	 li(" Click File to show source code"),
	 li(" Click Version to show changes made since last version")
	) . "\n";


print end_html();
