#!/usr/bin/perl

@manifest=`cat manifest.dat`;

$fullPFX="full-";
$basicPFX="basic-";
$tinyPFX="tiny-";


sub splitManifestLine
{
	mkdir '../svg', 0777;
	my @token = split /	/, $line;
	$thisTest 		= $token[0];
	$thisProfile 	= $token[1];
	$thisOriginal 	= $token[2];
	$thisSection 	= $token[3];
	$thisLink 		= $token[4];
	$thisComment 	= $token[5];
}

sub makeQuery
{
	print QUERY "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

	print QUERY "<!-- shortName=A unique abbreviation to be used for a file name for this file             -->\n";
	print QUERY "<!--        and column header for the matrix.  MUST be a legal xml id prefix and fileName -->\n";
	print QUERY "<!--       (shortName.xml) please make it 3-12 characters and do not use spaces.          -->\n";
	print QUERY "<!-- company=Your company name as you would like it to appear in documentation            -->\n";
	print QUERY "<!-- product=The name of the product you are running the test on                          -->\n";
	print QUERY "<!-- version=The version number of the product being tested                               -->\n";
	print QUERY "<!-- platform=The platform(s) that the product is tested on                               -->\n";
	print QUERY "<!-- date=The date of the submission in the form year/month/day, eg. 2002/08/30           -->\n";

	print QUERY "<svg-status-query company=\"\"\n";
	print QUERY "		date=\"\"\n";
	print QUERY "		product=\"\"\n";
	print QUERY "		version=\"\"\n";
	print QUERY "		shortName=\"\"\n";
	print QUERY "		profile=\"". substr( $pfx, 0, -1 )."\">\n";

	$index = '0';

	while( $index <= $#data )
	{
		$line = $data[$index];
		splitManifestLine;
		if( $index == 0 )
		{
    		print QUERY "<!-- test attributes:                                                                   -->\n";
    		print QUERY "<!--    status=must be one of 'OK', 'PARTIAL', or 'FAIL'                                -->\n";
    		print QUERY "<!--    comment=optional comment to publish with the result, like why you don't pass :) -->\n";
		}
        
        my ($revision);
        $revision = "unknown";

        $testName = "../svg/".$thisTest.".svg";
        open (TEST, $testName) || die "can't open file: $testName";
        while (<TEST>) {
            if (/Revision:/) {
                $i = index $_, "Revision:";
                $revisionSubstring = substr $_, $i;
                ($Fld1,$revision) = split(' ', $revisionSubstring, 9999);
                last;
            }
        }

		print QUERY "	<test name=\"$thisTest\" revision=\"$revision\" status=\"\" comment=\"\"/>\n";
		++$index;
	}
	print QUERY "</svg-status-query>";
}

sub makeQueries
{
	print "generating Implementation Queries.\n";

	$pfx = $fullPFX;
	open QUERY, ">../status/$pfx" . "query.xml";
	@data = @fullData;
	makeQuery();
	close QUERY;

	$pfx = $basicPFX;
	open QUERY, ">../status/$pfx" . "query.xml";
	@data = @basicData;
	makeQuery();
	close QUERY;

	$pfx = $tinyPFX;
	open QUERY, ">../status/$pfx" . "query.xml";
	@data = @tinyData;
	makeQuery();
	close QUERY;
}

sub createListings
{
    foreach $line ( @manifest )
    {
        splitManifestLine();
        if( $thisProfile eq 'f' )
        {
            push( @fullData, $line );
        }
        elsif( $thisProfile eq 'b' )
        {
            push( @basicData, $line );
            push( @fullData, $line );
        }
        elsif( $thisProfile eq 't' )
        {
            push( @tinyData, $line );
            push( @basicData, $line );
            push( @fullData, $line );
        }
        else
        {
            print "\n\nDanger Will Robinson!!!, bad profile on manifest line {{{$line}}}\n\n";
        }
    }
}

createListings();
makeQueries();

