]> matita.cs.unibo.it Git - helm.git/blob - helm/cgi/mkindex.pl
WebEQ definitely no more used
[helm.git] / helm / cgi / mkindex.pl
1 #!/usr/bin/perl
2
3 # First of all, let's load HELM configuration
4 use Env;
5 my $HELM_LIB_DIR = $ENV{"HELM_LIB_DIR"};
6 # this should be the only fixed constant
7 my $DEFAULT_HELM_LIB_DIR = "/projects/helm/on-line/local/lib/helm";
8 if (defined ($HELM_LIB_DIR)) {
9    $HELM_LIB_PATH = $HELM_LIB_DIR."/configuration.pl";
10 } else {
11    $HELM_LIB_PATH = $DEFAULT_HELM_LIB_DIR."/configuration.pl";
12 }
13
14 # next require defines: $helm_dir, $html_link, $dtd_dir, $uris_dbm
15 require $HELM_LIB_PATH;
16
17 $getter_url_get_uri = $getter_url."get?uri=";
18 $html_keys   = "key=C1&key=HC2";
19
20 # LUCA
21 # the following lines precompute some escaped string so that they can
22 # be used safely in a URI as value for parameters.
23
24 use URI::Escape;
25
26 #$escape_these = "\;\/\?\:\@\&\=\+\,\$";
27 $escape_these = "&=;:?";
28 $esc_getter_url = uri_escape($getter_url, $escape_these);
29 $esc_processor_url = uri_escape($processor_url, $escape_these);
30 $esc_getter_url_get_uri = uri_escape($getter_url_get_uri, $escape_these);
31 $esc_html_keys = uri_escape($html_keys, $escape_these);
32
33 $baseuri0 = $dirname = $uri = $ENV{"REQUEST_URI"};
34
35 $dirname =~ s/$helm_url_path//;
36 $dirname = $library_dir_on_line.$dirname;
37
38 $baseuri0 =~ s/$helm_url_path//;
39
40 opendir(DIR, $dirname);
41 @filenames = readdir(DIR);
42 closedir(DIR);
43
44 $output = "";
45 foreach $i (@filenames) {
46    if ($i eq "..") {
47       $output .= <<EOT;
48 <tr>
49 <td><img border="0" src="/icons/back.gif" alt="[BACK]"></td>
50 <td><a href="$uri$i">Parent Directory</a></td>
51 </tr>
52 EOT
53    } elsif ($i !~ /^\./) {
54       # hidden files excluded
55       (undef,undef,$mode) = stat("$dirname$i");
56       if ($mode &= 16384) {
57          # directory
58          $output .= <<EOT;
59 <tr>
60 <td><img border="0" src="/icons/folder.gif" alt="[DIR]"></td>
61 <td><a href="$uri$i">$i</a></td>
62 </tr>
63 EOT
64       } else {
65          # file
66          if ($i =~ /\.(con|var|ind)(\.types)?\.xml(\.gz)?$/) {
67             my $i_without_xml = $i;
68             $i_without_xml =~ s/(.*)\.xml(\.gz)/$1/;
69             # cic file
70             my $baseuri = "cic:".$baseuri0;
71             $output .= <<EOT;
72 <tr>
73 <td><img border="0" src="/icons/generic.red.gif" alt="[DIR]"></td>
74 <td><a href="$uri$i">$i</a></td>
75 <td><a href="$processor_url/apply?key=C1&xmluri=$esc_getter_url_get_uri$baseuri$i_without_xml">MathML Content</a></td>
76 <td><a href="$processor_url/apply?key=C1&key=C2&xmluri=$esc_getter_url_get_uri$baseuri$i_without_xml">MathML Presentation</a></td>
77 <!--
78 <td><a href="$processor_url/apply?key=C1&key=C2&key=R2A&xmluri=$esc_getter_url_get_uri$baseuri$i_without_xml">MathML P Abs</a></td>
79 -->
80 <td><a href="$processor_url/apply?$html_keys&param.getterURL=$esc_getter_url&param.processorURL=$esc_processor_url&param.keys=$esc_html_keys&xmluri=$esc_getter_url_get_uri$baseuri$i_without_xml">HTML</a></td>
81 </tr>
82 EOT
83          } elsif ($i =~ /\.(con|var|ind)\.ann\.xml(\.gz)?$/) {
84             my $i_without_xml = $i;
85             my $i_without_ann_and_xml = $i;
86             $i_without_xml =~ s/(.*)\.xml(\.gz)/$1/;
87             $i_without_ann_and_xml =~ s/(.*)\.ann\.xml/$1/;
88             # cic file
89             my $baseuri = "cic:".$baseuri0;
90             $output .= <<EOT;
91 <tr>
92 <td><img border="0" src="/icons/text.gif" alt="[DIR]"></td>
93 <td><a href="$uri$i">$i</a></td>
94 <td><a href="$processor_url/apply?key=C1&xmluri=$esc_getter_url_get_uri$baseuri$i_without_ann_and_xml&annuri=$baseuri$i_without_xml">MathML Content</a></td>
95 <td><a href="$processor_url/apply?key=C1&key=C2&xmluri=$esc_getter_url_get_uri$baseuri$i_without_ann_and_xml&annuri=$baseuri$i_without_xml">MathML Presentation</a></td>
96 <!--
97 <td><a href="$processor_url/apply?key=C1&key=C2&key=R2A&xmluri=$esc_getter_url_get_uri$baseuri$i_without_xml">MathML P Abs</a></td>
98 -->
99 <td><a href="$processor_url/apply$html_keys&param.getterURL=$esc_getter_url&param.processorURL=$esc_processor_url&param.keys=$esc_html_keys&xmluri=$esc_getter_url_get_uri$baseuri$i_without_ann_and_xml&annuri=$baseuri$i_without_xml">HTML</a></td>
100 </tr>
101 EOT
102          } elsif ($i =~ /\.theory\.xml(\.gz)?$/) {
103             my $i_without_xml = $i;
104             $i_without_xml =~ s/(.*)\.xml(\.gz)/$1/;
105             # theory file
106             my $baseuri = "theory:".$baseuri0; $output .= <<EOT;
107 <tr>
108 <td><img border="0" src="/icons/layout.gif" alt="[DIR]"></td>
109 <td><a href="$uri$i">$i</a></td>
110 <td><a href="$processor_url/apply?key=T1&xmluri=$esc_getter_url_get_uri$baseuri$i_without_xml">MathML Content</a></td>
111 <td><a href="$processor_url/apply?key=T1&key=T2&xmluri=$esc_getter_url_get_uri$baseuri$i_without_xml">MathML Presentation</a></td>
112 <td><a href="$processor_url/apply?key=T1&key=T2&xmluri=$esc_getter_url_get_uri$baseuri$i_without_xml">HTML</a></td>
113 </tr>
114 EOT
115          } else {
116             # other file
117             $output .= <<EOT;
118 <tr>
119 <td><img border="0" src="/icons/unknown.gif" alt="[DIR]"></td>
120 <td><a href="$uri$i">$i</a></td>
121 </tr>
122 EOT
123          }
124       }
125    }
126 }
127
128 print <<EOT;
129 Content-type: text/html
130
131 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
132 "http://www.w3.org/TR/REC-html40/loose.dtd">
133 <html>
134 <head>
135 <title>Index of $uri</title>
136 </head>
137 <body bgcolor="#ffffff" text="#000000">
138 <table><tr><td bgcolor="#ffffff" class="title">
139 <font size="+3" face="Helvetica,Arial,sans-serif"><b>Index of $uri</b></font>
140 </td></tr></table>
141 <hr noshade align="left" width="80%">
142 <table>
143 $output
144 </table>
145 <hr noshade align="left" width="80%">
146 </body>
147 </html>
148 EOT