#Generates html for SPAR Java Applet.

#!/opt/ucl/bin/perl
# SDP File and Plugins file:
open(SDP, "$sdp");
open(PLUGINS, "$plugins");

@sep=("|","#","!","^","~","|#","|#|");
@sdp=<SDP>;
$sep=shift(@sep);
for ($i=0; $i<@sdp; $i++) {
        chop($sdp[$i]);
        $sdp[$i] =~ s/\r//g;
        $sdp[$i] =~ s/&/&amp;/g;
        $sdp[$i] =~ s/"/&quot;/g;
        while(index($sdp[$i],$sep) >= 0) {
                $sep=shift(@sep);
        }
}

$browser=$ENV{HTTP_USER_AGENT};
if(($browser =~/Mozilla\/4/) && ($browser =~ /MSIE/)) {
	$browser = "IE";
}
elsif(($browser =~/Mozilla\/4/) && ($browser !~ /MSIE/)) {
	$browser = "NS";
}
else {
	$browser = "not NS or IE";
}

if($browser eq "IE") {
	print <<EOF
<applet codebase="/java" code="IEmain.class" height=285 width=580>
<PARAM name="cabbase" value="spar.cab">
EOF
;
}
else {
	print <<EOF
<applet codebase="/java" code="NSmain.class" archive="spar.jar" height=285 width=580>
EOF
;
}

print "<PARAM NAME=\"Separator\" VALUE=\"$sep\">\n";
print "<PARAM NAME=\"SDP\" VALUE=\"";
foreach $line (@sdp) {
        print "$line$sep\n" if $line ne "";
}
print "\">\n";
print "<PARAM NAME=\"plugins\" VALUE=\"";

while($line=<PLUGINS>){
        if(substr($line,0,1) eq "#") {
                next;
        }
	 chop($line);
        $line =~ s/&/&amp;/g;
        $line =~ s/"/&quot;/g;
        print "$line|\n";
}
print "\">\n";
print <<EOF
</applet>
