]> matita.cs.unibo.it Git - helm.git/blob - helm/cgi/webeqp.pl
Added Files (for webeq):
[helm.git] / helm / cgi / webeqp.pl
1 #!/usr/bin/perl
2
3 require HTTP::Request;
4 require LWP::UserAgent;
5 require "/local/lib/helm/configuration.pl";
6 use CGI;
7
8 $url = $ENV{"REQUEST_URI"};
9 $url =~ s/.*mmlurl=(.*)/$1/;
10
11 $content = "";
12
13 $ua = LWP::UserAgent->new;
14 $request = HTTP::Request->new(GET => "$url");
15 $response = $ua->request($request, \&callback);
16
17 $content =~ s/\r//sg;
18 $content =~ s/\n/ /sg;
19 $content =~ s/<!DOCTYPE[^>]*>//sg;
20 $content =~ s/<\?xml[^?]*\?>//sg;
21 $content =~ s/"/'/g;
22 $content =~ s/&/&amp;/g;
23 $content =~ s/<m:/</g;
24 $content =~ s/<\/m:/<\//g;
25 $content =~ s/<math[^>]*>/<math>/sg;
26 $content =~ s/(<\/?semantics[^>]*>)/<!-- $1 -->/sg;
27 $content =~ s/(<annotation-xml)/<!-- $1/sg;
28 $content =~ s/(<\/annotation-xml>)/$1 -->/sg;
29 $content =~ s/<mo helm:xref='[^']*' xlink:href='([^']*)'>([^<]*)<\/mo>/<maction actiontype='href' other='$use_webeqp_url?uri=$1'><mo>$2<\/mo><\/maction>/sg;
30 $content =~ s/<mi helm:xref='[^']*' xlink:href='([^']*)'>([^<]*)<\/mi>/<maction actiontype='href' other='$use_webeqp_url?uri=$1'><mi>$2<\/mi><\/maction>/sg;
31 $content =~ s/helm:xref='[^']*'//sg;
32 $content =~ s/xmlns:helm='[^']*'//sg;
33 $content =~ s/xlink:href='[^']*'//sg;
34 $content =~ s/xmlns:xlink='[^']*'//sg;
35 $content =~ s/<mchar name='([^']*)' \/>/&$1;/sg;
36
37 print <<EOT;
38 Content-type: text/html
39
40 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
41 "http://www.w3.org/TR/REC-html40/loose.dtd">
42 <html>
43 <head>
44 <title>Generato in automatico a partire da $url</title>
45 </head>
46 <body bgcolor="#ffffff" text="#000000">
47 <applet codebase="http://www.webeq.com/WebEQ/2.2/classes" code="webeq.Main"
48 +width=600 height=2000 align=middle>
49 <param name=eq value="$content">
50 <param name=color value="#cccccc">
51 <param name=parser value="mathml">
52 <param name=size value="14">
53 </applet>
54 </body>
55 </html>
56 EOT
57
58 #=========================
59
60 sub callback
61
62  my ($data) = @_;
63  $content .= $data;
64 }