4 # Copyright (C) 2006, HELM Team.
6 # This file is part of HELM, an Hypertextual, Electronic
7 # Library of Mathematics, developed at the Computer Science
8 # Department, University of Bologna, Italy.
10 # HELM is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License
12 # as published by the Free Software Foundation; either version 2
13 # of the License, or (at your option) any later version.
15 # HELM is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with HELM; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 # For details, see the HELM World-Wide-Web page,
26 # http://helm.cs.unibo.it/
29 use Syntax::Highlight::Universal;
33 my $documentroot = '/projects/matita/public_html/';
34 my $protohrc = $documentroot . 'helm-proto.hrc';
35 my $scriptsdir = $documentroot . 'library/';
44 my $query = CGI->new; # used globally by some 'sub' below
45 print $query->header(-type=>'text/html', -charset=>'utf-8');
47 sub die_invalid_file() {
48 print $query->start_html;
49 print 'Invalid script.';
50 print $query->end_html;
54 sub lookup_script($) {
56 die_invalid_file() unless $f =~ /^(.*)(\.[^.]+)$/;
59 die_invalid_file() unless $base =~ /[-a-zA-Z_]+(\/[-a-zA-Z_])*/;
60 die_invalid_file() unless exists $formatmap{$extension};
61 my $path = $scriptsdir . $f;
62 die_invalid_file() unless -f $path;
63 return ($path, $formatmap{$extension});
66 my $fname = $query->param('f');
68 my $highlighter = Syntax::Highlight::Universal->new;
69 $highlighter->addConfig($protohrc);
71 my ($script, $format) = lookup_script($fname);
72 open SCRIPT, "< $script" or die "Can't open Matita script \"$script\"\n";
74 my $text = join '', @lines;
77 print $query->start_html(-style=>{'src'=>"/$format-format.css"},
79 my $result = $highlighter->highlight($format, $text);
83 print $query->end_html;