]> matita.cs.unibo.it Git - helm.git/blob - helm/cgi/mkindextheory.pl
getter flags considered
[helm.git] / helm / cgi / mkindextheory.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 use URI::Escape;
18 use LWP::UserAgent;
19 use CGI;
20
21 my $cgi = new CGI($ENV{"REQUEST_URL"});
22 $uri = $cgi->param('theoryuri');
23 $uri =~ s/(.*)\/$/$1/; # Remove a final slash if present
24 $uri .= "/"; # Put a final slash
25 $myurl = $cgi->url();
26
27 $cont = ""; # modified by side-effect by &callback
28 my $ua = LWP::UserAgent->new;
29 my $request = HTTP::Request->new(GET => $getter_url."ls?format=txt&baseuri=".$uri);
30 my $response = $ua->request($request, \&callback);
31  
32 @filenames = split(/\n/, $cont);
33
34 my $uridotdot = $uri;
35 $uridotdot =~ s/(.*)\/.+/$1/;
36 if ($uri ne "theory:/") {
37  # Let's print the link to the parent directory
38  $output = <<EOT;
39 <tr>
40 <td><img border="0" src="/icons/back.gif" alt="[BACK]"></td>
41 <td><a href="$myurl" onClick="top.frames[0].document.forms[0].hiddentheoryuri.value='$uridotdot'; refreshReload(); refreshTheoryHeader(); this.search='?theoryuri=$uridotdot';" onMouseOver="window.status='$uridotdot'; return true">Parent Directory</a></td>
42 </tr>
43 EOT
44 }
45
46 foreach $i (@filenames) {
47    my ($type,$name,$flags) = split(/, /, $i);
48    my ($flagscic, $flagstypes) = split(/,/, $flags);
49    $flagscic =~ s/^<(.*)/$1/;
50    $flagstypes =~ s/(.*)>$/$1/;
51    if ($type eq "dir") {
52       $output .= <<EOT;
53 <tr>
54 <td><img border="0" src="/icons/folder.gif" alt="[DIR]"></td>
55 <td><a href="$myurl" onClick="top.frames[0].document.forms[0].hiddentheoryuri.value='$uri$name'; refreshReload(); refreshTheoryHeader(); this.search='?theoryuri=$uri$name';" onMouseOver="window.status='$uri$name'; return true">$name</a></td>
56 </tr>
57 EOT
58    } elsif ($type eq "object") {
59          if ($name =~ /\.theory$/) {
60             # theory file
61             $output .= <<EOT;
62 <tr>
63 <td><img border="0" src="/icons/generic.red.gif" alt="[DIR]"></td>
64 <td><a href="" target="theory" onClick="this.href=makeURL('theory','$uri$name','$processor_url','$getter_url','$flagscic','$flagstypes')" onMouseOver="window.status='$uri$name'; return true">$name</a>
65 </tr>
66 EOT
67          } else {
68             $output .= <<EOT;
69 <tr>
70 <td><img border="0" src="/icons/unknown.gif" alt="[DIR]"></td>
71 <td>$name</td>
72 </tr>
73 EOT
74          }
75    } else {
76       $output .= <<EOT;
77 <tr>
78 <td><img border="0" src="/icons/burst.gif" alt="[DIR]"></td>
79 <td>$name</td>
80 </tr>
81 EOT
82    }
83 }
84
85 print <<EOT;
86 Content-type: text/html
87
88 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
89 "http://www.w3.org/TR/REC-html40/loose.dtd">
90 <html>
91 <head>
92 <title>Index of $uri</title>
93 <script language="JavaScript" src="http://phd.cs.unibo.it/helm/javascript/control.js">
94 </script>
95 </head>
96 <body bgcolor="#ffffff" text="#000000">
97 <table>
98 $output
99 </table>
100 <hr noshade align="left" width="80%">
101 </body>
102 </html>
103 EOT
104
105 #================================
106
107 sub callback
108 {
109  my ($data) = @_;
110  $cont .= $data;
111 }