#!/usr/local/bin/perl
#Displays the current directory with information about each script.

%icons = ('cgi',['/icons/script.gif','CGI'],
	  'html',['/icons/layout.gif','HTML'],
	  'pl',['/icons/p.gif','PERL'],
	  'txt',['/icons/text.gif','TEXT'],
	  'unknown', ['/myicons/huh.gif', 'UNKNOWN']);



print <<HTML;
Pragma: no-cache
Content-type: text/html

<html>
<head>
<title>Directory Listing of Scripts
</title>
<style>
<!--
    body {
	background-color: #00cccc;
	font-size: large;
    }
A:link {
  color: #c86464;
  }
span.heading {
}
-->
</style>
</head>
<body>
HTML
    ;
$has_html=0;
foreach (<*>) 
{

    if(-f $_ && (-x $_ || /html$/) && /[^~\#]$/) 
    {
	open FILE, $_;
	($ext) = /\.([^.]*)$/;
	$command = <FILE>;
	$desc = <FILE>;
	$exec = <FILE>;
	$noexec = ($exec =~ /noexec/i);
	($line) = $desc =~ /^#*(.*)/;
	if ($ext =~ /^txt$/i) {
	    $noexec = 1;
	    $line = "";
	}
	close FILE;
	print "<br><span class=heading>$line</span>\n" if ($line);
	$lookup_ext = "unknown";
	if (defined ($icons{$ext})) {
	    $lookup_ext = $ext;
	}
	if (!$noexec) {
	    print "<br><IMG SRC=\"$icons{$lookup_ext}[0]\" ALT=\"[$icons{$lookup_ext}[1]]\">";
	    print "Run it: <A href=\"/scripts/$_\">$_</a>\n";
	}
	if (!($ext =~ /^cgi$/)) {
	    if ($ext =~ /^html$/i) {
		print "<br><IMG SRC=\"$icons{$lookup_ext}[0]\" ALT=\"[$icons{$lookup_ext}[1]]\">"; 
	    } else {
		print "<br><IMG SRC=\"/icons/text.gif\" ALT=\"[TEXT]\">";
	    }
	    print "See it: <A href=\"/scripts-source/$_\">$_</a>\n";
	    print "<br>\n";
	}
    }
}			    
print <<END;
</body>
</html>
END
    ;