#!@PERL@
#
# Directory list CGI by Hironori Sakamoto (hsaka@mth.biglobe.ne.jp)
#
if ( $^O =~ /^(ms)?(dos|win(32|nt)?)/i ) {
$WIN32 = 1;
$CYGPATH = 1;
}
elsif ( $^O =~ /cygwin|os2/i ) {
$WIN32 = 1;
$CYGPATH = 0;
}
else {
$WIN32 = 0;
$CYGPATH = 0;
}
$RC_DIR = '~/.w3m/';
$RC_DIR =~ s@^~/@$ENV{'HOME'}/@;
if ($CYGPATH) {
$RC_DIR = &cygwin_pathconv("$RC_DIR");
}
$CONFIG = "$RC_DIR/dirlist";
$CGI = $ENV{'SCRIPT_NAME'} || $0;
$CGI = "file://" . &file_encode("$CGI");
$AFMT = '%s';
$NOW = time();
@OPT = &init_option($CONFIG);
$query = $ENV{'QUERY_STRING'};
$cmd = '';
$cgi = 0;
if ($query eq '') {
$_ = `pwd`; # insecure?
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@^/@) &&
($WIN32 && $dir !~ /^[a-z]:/i)) {
$_ = `pwd`; # insecure?
chop;
s/\r$//;
$dir = "$_/$dir";
}
$cgi = -1;
}
if ($dir !~ m@/$@) {
$dir .= '/';
}
if ($dir =~ m@^/@ && $CYGPATH) {
$dir = &cygwin_pathconv("$dir");
}
$ROOT = '';
if ($WIN32) {
if (($dir =~ s@^//[^/]+@@) || ($dir =~ s@^[a-z]:@@i)) {
$ROOT = $&;
}
if ($CYGPATH) {
$ROOT = &cygwin_pathconv("$ROOT");
}
}
if ($cgi) {
$dir = &cleanup($dir);
}
$TYPE = $OPT[$OPT_TYPE];
$FORMAT = $OPT[$OPT_FORMAT];
$SORT = $OPT[$OPT_SORT];
if ($cmd) {
&update_option($CONFIG);
}
$qdir = "$ROOT" . &html_quote("$dir");
$edir = "$ROOT" . &file_encode("$dir");
if (! opendir(DIR, "$ROOT$dir")) {
print <
Directory list of $qdir
$qdir: $! !