]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/www/matita/cgi-bin/hl.cgi
mod change (-x)
[helm.git] / helm / www / matita / cgi-bin / hl.cgi
old mode 100755 (executable)
new mode 100644 (file)
index 25e7bcf..f2a146c
@@ -33,14 +33,19 @@ use Syntax::Highlight::Universal;
 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(-type=>'text/html', -charset=>'utf-8');
 
 sub die_invalid_file() {
+  print $query->start_html;
   print 'Invalid script.';
   print $query->end_html;
   exit 0;
@@ -48,12 +53,14 @@ sub die_invalid_file() {
 
 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');
@@ -61,14 +68,17 @@ 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;
+my $text = join '', @lines;
 close SCRIPT;
 
-my $result = $highlighter->highlight($hlformat, $text);
+print $query->start_html(-style=>{'src'=>"/$format-format.css"},
+                        -encoding=>'utf-8');
+my $result = $highlighter->highlight($format, $text);
+print "<pre>\n";
 print $result;
-
+print "</pre>\n";
 print $query->end_html;