]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/cgi/mkindexcic.pl
New on-line interface
[helm.git] / helm / cgi / mkindexcic.pl
diff --git a/helm/cgi/mkindexcic.pl b/helm/cgi/mkindexcic.pl
new file mode 100755 (executable)
index 0000000..6f816d3
--- /dev/null
@@ -0,0 +1,119 @@
+#!/usr/bin/perl
+
+# First of all, let's load HELM configuration
+use Env;
+my $HELM_LIB_DIR = $ENV{"HELM_LIB_DIR"};
+# this should be the only fixed constant
+my $DEFAULT_HELM_LIB_DIR = "/projects/helm/on-line/local/lib/helm";
+if (defined ($HELM_LIB_DIR)) {
+   $HELM_LIB_PATH = $HELM_LIB_DIR."/configuration.pl";
+} else {
+   $HELM_LIB_PATH = $DEFAULT_HELM_LIB_DIR."/configuration.pl";
+}
+
+# next require defines: $helm_dir, $html_link, $dtd_dir, $uris_dbm
+require $HELM_LIB_PATH;
+
+use URI::Escape;
+use LWP::UserAgent;
+use CGI;
+
+my $cgi = new CGI($ENV{"REQUEST_URL"});
+$uri = $cgi->param('cicuri');
+$uri =~ s/(.*)\/$/$1/; # Remove a final slash if present
+$uri .= "/"; # Put a final slash
+$myurl = $cgi->url();
+
+$cont = ""; # modified by side-effect by &callback
+my $ua = LWP::UserAgent->new;
+my $request = HTTP::Request->new(GET => $getter_url."ls?format=txt&baseuri=".$uri);
+my $response = $ua->request($request, \&callback);
+@filenames = split(/\n/, $cont);
+
+my $uridotdot = $uri;
+$uridotdot =~ s/(.*)\/.+/$1/;
+if ($uri ne "cic:/") {
+ # Let's print the link to the parent directory
+ $output = <<EOT;
+<tr>
+<td><img border="0" src="/icons/back.gif" alt="[BACK]"></td>
+<td><a href="$myurl" onClick="top.frames[0].document.forms[0].hiddencicuri.value='$uridotdot'; refreshReload(); refreshCICHeader(); this.search='?cicuri=$uridotdot';" onMouseOver="window.status='$uridotdot'; return true">Parent Directory</a></td>
+</tr>
+EOT
+}
+
+foreach $i (@filenames) {
+   my ($type,$name) = split(/,/, $i);
+   if ($type eq "dir") {
+      $output .= <<EOT;
+<tr>
+<td><img border="0" src="/icons/folder.gif" alt="[DIR]"></td>
+<td><a href="$myurl" onClick="top.frames[0].document.forms[0].hiddencicuri.value='$uri$name'; refreshReload(); refreshCICHeader(); this.search='?cicuri=$uri$name';" onMouseOver="window.status='$uri$name'; return true">$name</a></td>
+</tr>
+</tr>
+EOT
+   } elsif ($type eq "object") {
+        if ($name =~ /\.(con|var|ind)(\.types)?$/) {
+           # cic file
+            $output .= <<EOT;
+<tr>
+<td><img border="0" src="/icons/generic.red.gif" alt="[DIR]"></td>
+<td><a href="" target="cic" onClick="this.href=makeURL('cic','$uri$name','$processor_url','$getter_url')" onMouseOver="window.status='$uri$name'; return true">$name</a>
+</tr>
+EOT
+        } elsif ($name =~ /\.(con|var|ind)\.ann$/) {
+            my $name_without_ann = $name;
+            $name_without_ann_and_xml =~ s/(.*)\.ann/$1/;
+           # cic file
+            $output .= <<EOT;
+<tr>
+<td><img border="0" src="/icons/generic.red.gif" alt="[DIR]"></td>
+<td><a href="" target="cic" onClick="this.href=makeURL('cic','$uri$name_without_ann&annuri=$uri$name','$processor_url','$getter_url')" onMouseOver="window.status='$uri$name'; return true">$name</a>
+</tr>
+EOT
+         } else {
+            $output .= <<EOT;
+<tr>
+<td><img border="0" src="/icons/unknown.gif" alt="[DIR]"></td>
+<td>$name</td>
+</tr>
+EOT
+        }
+   } else {
+      $output .= <<EOT;
+<tr>
+<td><img border="0" src="/icons/burst.gif" alt="[DIR]"></td>
+<td>$name</td>
+</tr>
+EOT
+   }
+}
+
+print <<EOT;
+Content-type: text/html
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
+"http://www.w3.org/TR/REC-html40/loose.dtd">
+<html>
+<head>
+<title>Index of $uri</title>
+<script language="JavaScript" src="http://phd.cs.unibo.it/helm/library3/control.js">
+</script>
+</head>
+<body bgcolor="#ffffff" text="#000000">
+<table>
+$output
+</table>
+<hr noshade align="left" width="80%">
+</body>
+</html>
+EOT
+
+#================================
+
+sub callback
+{
+ my ($data) = @_;
+ $cont .= $data;
+}