#!/usr/local/bin/perl
# Written by Ch. Tronche (http://tronche.com/)
# Copyright by the author. This is unmaintained, no-warranty free software. 
# Please use freely. It is appreciated (but by no means mandatory) to
# acknowledge the author's contribution. Thank you.
# Started on Wed Mar 4 11:49:54 1998

# Adapted for CASL on Tue Feb 23 15:00:41 MET 1999
# by Kolyang, Till Mossakowski, and Pascal Schmidt

print "Content-Type: text/html\n\n";

$parser = "/home/cofi/bin/casl";

%hex = (0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7,
	8 => 8, 9 => 9, a => 10, b => 11, c => 12, d => 13, e => 14, f => 15,
	A => 10, B => 11, C => 12, D => 13, E => 14, F => 15);


$_ = $ENV{'QUERY_STRING'};

if ($_) {
    $fileName = "/tmp/web.casl.$$";
    open(FILE, "| $parser -cgi \"$_\" >$fileName 2>$fileName.err") || die;
    print FILE "$_\n";
    close(FILE);


    s/^spec=//o;
    s/\&[a-zA-Z]+=[a-zA-Z]+//go;
    s/%0D//go;
    s/\+/ /go;
    s/%([0-9a-f])([0-9a-f])/chr($hex{$1} * 16 + $hex{$2})/egoi;
	print <<END;
<HTML>
<head>
<title>HOL-CASL results</title>
</head>
<body backgr=#c0c0c0 text=#000000>
<H1>You have submitted the CASL library:</H1>
<PRE>
$_
</PRE>
    

<H1>Result of parsing and static checking:</H1>
END
        open(FILE, "<$fileName") || die;
	while(<FILE>) {
	    print;
	}
	print "<PRE>\n";
	open(FILE, "<$fileName.err") || die;
	while(<FILE>) {
	    s/\&/&amp;/go;
	    s/</&lt;/go;
	    s/>/&gt;/go;
	    print;
	}
	print "</PRE>\n";
    print <<END;
<HR>

<P>
Not the result you expected ? Please check the <A HREF="http://www.informatik.uni-bremen.de/~cofi/CASL/parser/problems.html">known problems list</A> and then 
<A HREF="mailto:cofi\@informatik.uni-bremen.de">complain</A> !

</BODY>
</HTML>
END
} else {
    print <<END;
<HTML>
<head>
<title>HOL-CASL web interface</title>
</head>
<body backgr=#c0c0c0 text=#000000>
END
    print"<H1>";
    open(FILE, "/home/cofi/www/CASL/parser/version") || die;
	while(<FILE>) {
	    s/\&/&amp;/go;
	    s/</&lt;/go;
	    s/>/&gt;/go;
	    print;
	}
    print"</H1>";

print <<END;
Enter a CASL specification or library in the input zone, then press SUBMIT:

<FORM>
<TEXTAREA NAME="spec" COLS=80 ROWS=24></TEXTAREA><br>
<INPUT TYPE=submit>
<INPUT TYPE=reset>
<INPUT TYPE="checkbox" NAME="tree" VALUE="yes">Output parse tree
<INPUT TYPE="checkbox" NAME="env" VALUE="yes">Output global environment
<INPUT TYPE="checkbox" NAME="tex" VALUE="yes">Output LaTeX
</FORM>

END
}

print <<END;

<HR>
Contact address:&nbsp;
<A HREF=\"mailto:cofi\@informatik.uni-bremen.de\">cofi\@informatik.uni-bremen.de</A>
</BODY>
</HTML>
END


