my $documentroot = '/projects/matita/public_html/';
my $protohrc = $documentroot . 'helm-proto.hrc';
my $scriptsdir = $documentroot . 'library/';
-my $hlformat = "grafite";
+
+my %formatmap = (
+ ".ma" => "grafite",
+ ".c" => "c", # debug
+);
# Code
my $query = CGI->new; # used globally by some 'sub' below
-print $query->header, $query->start_html;
+print $query->header;
sub die_invalid_file() {
+ print $query->start_html;
print 'Invalid script.';
print $query->end_html;
exit 0;
sub lookup_script($) {
my ($f) = @_;
- die_invalid_file() unless $f =~ /^(.*)(\.ma)$/;
+ die_invalid_file() unless $f =~ /^(.*)(\.[^.]+)$/;
my $base = $1;
+ my $extension = $2;
die_invalid_file() unless $base =~ /[-a-zA-Z_]+(\/[-a-zA-Z_])*/;
+ die_invalid_file() unless exists $formatmap{$extension};
my $path = $scriptsdir . $f;
die_invalid_file() unless -f $path;
- return $path;
+ return ($path, $formatmap{$extension});
}
my $fname = $query->param('f');
my $highlighter = Syntax::Highlight::Universal->new;
$highlighter->addConfig($protohrc);
-my $script = lookup_script($fname);
+my ($script, $format) = lookup_script($fname);
open SCRIPT, "< $script" or die "Can't open Matita script \"$script\"\n";
my @lines = <SCRIPT>;
my $text = join "", @lines;
close SCRIPT;
-my $result = $highlighter->highlight($hlformat, $text);
+print $query->start_html(-style=>{"src"=>"/$format-format.css"});
+my $result = $highlighter->highlight($format, $text);
+print "<pre>\n";
print $result;
-
+print "</pre>\n";
print $query->end_html;