#!/usr/bin/perl
#
sub htencode {
    local($htencd) = shift;
    $htencd =~ s/&/&amp;/g;
    $htencd =~ s/"/&quot;/g;
    $htencd =~ s/</&lt;/g;
    $htencd =~ s/>/&gt;/g;
    $htencd;
}
  do "acqPATHs.pl";
  $str = $ENV{"QUERY_STRING"};
  ($dir, $fnm, $len) = split(/\+/, $str);
  if ($dir ne "") { $dir .= "/"; }
  $path = "$DATAPATH/$dir$fnm";
  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 tail</title>
<script type="text/javascript">
<!--
function cancel() {
  location.replace("/AMXS/forms/blank.html");
}
//-->
</script>
</head>
<body bgcolor="ivory" style="margin: 4px 7px;">
<form name="FM">
<b>[ tail -__LEN__ &nbsp; __DFN__ ]</b> &nbsp; &nbsp; &nbsp; &nbsp;
 <input type="button" value="OK" onclick="cancel()">
EOM
  $htmlbody =~ s/__DFN__/$dir$fnm/;
  $htmlbody =~ s/__LEN__/$len/;
  print $htmlbody;
#
  if (open(IN, "tail -$len $path 2>&1 |")) {
    print "<pre>";
    while ($line=<IN>) { print &htencode($line); }
    close(IN);
    print "</pre>\n";
  } else {
    print "<br><font color=\"red\"><b>ERROR:</b></font>\n";
    print " File open fail.\n";
  }  
#
  print "</form>\n</body>\n</html>\n";
  exit(0);
