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/';
36 my $hlformat = "grafite";
40 my $query = CGI->new; # used globally by some 'sub' below
41 print $query->header, $query->start_html;
43 sub die_invalid_file() {
44 print 'Invalid script.';
45 print $query->end_html;
49 sub lookup_script($) {
51 die_invalid_file() unless $f =~ /^(.*)(\.ma)$/;
53 die_invalid_file() unless $base =~ /[-a-zA-Z_]+(\/[-a-zA-Z_])*/;
54 my $path = $scriptsdir . $f;
55 die_invalid_file() unless -f $path;
59 my $fname = $query->param('f');
61 my $highlighter = Syntax::Highlight::Universal->new;
62 $highlighter->addConfig($protohrc);
64 my $script = lookup_script($fname);
65 open SCRIPT, "< $script" or die "Can't open Matita script \"$script\"\n";
67 my $text = join "", @lines;
70 my $result = $highlighter->highlight($hlformat, $text);
73 print $query->end_html;