#!/usr/bin/perl
$pwd = `pwd`; chomp $pwd;
@f = @d = ();
opendir D, $pwd;
while($f = readdir D) {
push @d, $f if -d $f;
push @f, $f unless -d $f;
}
closedir D;
@d = sort {lc($a) cmp lc($b)} @d;
@f = sort {(lc(substr($a,rindex($a,"."))) cmp lc(substr($b,rindex($b,".")))) || (lc($a) cmp lc($b))} @f;
@d = (@d, @f);
for($i=0; $i<@d;) {
($d[$i] =~ m/^\./ or $d[$i] eq "index.cgi" or $d[$i] eq "pics") ? splice @d, $i, 1 : $i++;
}
($dir = $pwd) =~ s!^.*/([^/]*)$!$1!;
$descs{"MOO"} = "MOOCode and Extensions";
$descs{"VB"} = "Visual Basic";
$descs{"Shell"} = "Shell Scripts";
$pageicon = "smallfolder";
$pageicon = "smalldrive" if $pwd =~ m|www/Code$|;
print "Content-type: text/html\n\n";
print << "END";
Martian's Code - $dir
|
|
|
File Edit View Help
|
END
$cols = 3; $cols = 5 if @d > 9; $cols = 7 if @d > 25;
$c=0;
for($i=0; $i<@d; $i++) {
$file = $d[$i];
$icon = "unknown";
$icon = "folder" if -d $file;
$icon = "cfile" if $file =~ m/\.c$/i;
$icon = "cfile" if $file =~ m/\.cpp$/i;
$icon = "hfile" if $file =~ m/\.h$/i;
$icon = "html" if $file =~ m/\.html?$/i;
$icon = "text" if $file =~ m/\.txt$/i;
$icon = "text" if $file =~ m/\.sql$/i;
$icon = "java" if $file =~ m/\.java$/i;
$icon = "script" if $file =~ m/\.p[lm]$/i;
$icon = "script" if $file =~ m/\.cgi$/i;
$icon = "lisp" if $file =~ m/\.li?sp$/i;
$icon = "gif" if $file =~ m/\.gif$/i;
$icon = "moo" if $file =~ m/\.moo$/i;
$icon = "jpeg" if $file =~ m/\.jpe?g$/i;
# $icon = "png" if $file =~ m/\.png$/i;
$icon = "script" if $file =~ m/\.js$/i or $file =~ m/\.php3?$/i or $file =~ m/\.rb$/i;
$desc = $descs{$file} || $file;
$file .= "/" if -d $file;
print " \n" if $i % $cols == 0;
print << "END";
 $desc |
|
END
print " \n" if $i % $cols == ($cols-1);
}
if(@d < $cols) {
for($j=$i; $j<$cols; $j++) {
print << "END";
|
END
}
print " \n";
}
print << "END";
|
END
print " | ";
print scalar(@d), " object", (@d==1) ? "":"s";
print " | ";
print << "END";
 |
END