#!/usr/bin/perl
#
  do "acqPATHs.pl";
  $wdr = $ENV{"QUERY_STRING"};
  if ($wdr ne "") { $wdr .= "/"; }
  print "Content-type: text/html; charset=iso-8859-1\n\n";
#
  $htmlbody =<<EOM;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<link rel="stylesheet" type="text/css" href="/AMXS/amxs.css">
<title>AMXS files</title>
<script type="text/javascript">
<!--
function RmCWD() {
  location.replace("/cgi/AMXS/rmcwd.cgi?__CWD__");
}
function cancel() {
  location.replace("/AMXS/forms/blank.html");
}
//-->
</script>
</head>
<body bgcolor="ivory" style="margin: 4px 7px;">
<form name="FM">
<hr>
<i>Existing files</i> : &nbsp; &nbsp; &nbsp;
 <input type="button" value="OK" onclick="cancel()"><br>
<table>
EOM
  $htmlbody =~ s/__CWD__/$wdr/g;
  print $htmlbody;
#
  $n = 0;
  opendir(DIR, "$DATAPATH/$wdr");
  while ($fnam = readdir(DIR)) {
    if ($fnam =~ /^(\w+\.)*\w+$/) {
      if (-f "$DATAPATH/$wdr$fnam") { $rnam[$n] = $fnam; $n++; }
    }
  }
  closedir(DIR);
  @dnam = sort(@rnam);
  if ($n < 5) { $nl = $n;
  } elsif ($n < 30) { $nl = 5;
  } else { $nl = ($n + 5 - (($n-1) % 6)) / 6; }
  for ($l=0; $l<$nl; $l++) {
    print " <tr>\n";
    for ($c=0; $c<6; $c++) {
      $m = $c*$nl + $l;
      if ($m < $n) {
        print "  <td> &nbsp; $dnam[$m]</td>\n";
      }
      else { print "  <td> &nbsp; </td>\n"; }
    }
    print " </tr>\n";
  }
  close(IN);
  print "</table>\n";
  if ($n == 0) {
    print "<br> &nbsp; &nbsp; &nbsp; &nbsp; none <br><br>\n";
    print " &nbsp; &nbsp; ";
    print '<input type="button" value="rmCWD" onclick="RmCWD()">', "\n";
    print "(Remove current working directory)\n";
  }
#
  print "</form>\n</body>\n</html>\n";
  exit(0);
