#!/usr/local/bin/perl
#
# Directory list CGI by Hironori Sakamoto (hsaka@mth.biglobe.ne.jp)
#
$CYGWIN = 0;
$RC_DIR = '~/.w3m/';
$RC_DIR =~ s@^~/@$ENV{'HOME'}/@;
$CONFIG = "$RC_DIR/dirlist";
$CGI = $ENV{'SCRIPT_NAME'} || $0;
$CGI = &html_quote(&form_encode("file:$CGI"));
$AFMT = '%s';
$NOW = time();
@OPT = &init_option($CONFIG);
$query = $ENV{'QUERY_STRING'};
$cmd = '';
$cgi = 0;
if ($query eq '') {
$_ = `pwd`;
chop;
s/\r$//;
$dir = $_;
$cgi = 0;
} elsif ($query =~ /^(opt\d+|dir|cmd)=/) {
foreach(split(/\&/, $query)) {
if (s/^dir=//) {
$dir = &form_decode($_);
} elsif (s/^opt(\d+)=//) {
$OPT[$1] = $_;
} elsif (s/^cmd=//) {
$cmd = $_;
}
}
$cgi = 1;
} else {
$dir = $query;
if (($dir !~ m@^/@) &&
($CYGWIN && $dir !~ /^[a-z]:/i)) {
$_ = `pwd`;
chop;
s/\r$//;
$dir = "$_/$dir";
}
$cgi = -1;
}
if ($dir !~ m@/$@) {
$dir .= '/';
}
$ROOT = '';
if ($CYGWIN) {
if (($dir =~ s@^//[^/]+@@) || ($dir =~ s@^[a-z]:@@i)) {
$ROOT = $&;
}
}
if ($cgi) {
$dir = &cleanup($dir);
}
$TYPE = $OPT[$OPT_TYPE];
$FORMAT = $OPT[$OPT_FORMAT];
$SORT = $OPT[$OPT_SORT];
if ($cmd) {
&update_option($CONFIG);
}
$qdir = &html_quote("$ROOT$dir");
$edir = &html_quote(&form_encode("$ROOT$dir"));
if (! opendir(DIR, "$ROOT$dir")) {
print <
Directory list of $qdir
$qdir: $! !