#!/usr/local/bin/perl
#
# Brad Donison bdonison@grmi.org
# 4 Aug 95
#
# updates the access count and prints it for a specified file
#
# usage:
# counter
#
# NOTE: it looks at the url that is running, and creates a counter file if
#       none exists.  Then it just appends a single character to the file,
#       and then prints the size of the file.

#unshift(@INC, '/local/www/tools');
unshift(@INC, '.');

require "digits.pl";
require "counter.pl";

$c = &counter;
&rain($c);

#sub counter {
#  $base = "/local/www/tools/counters/";
#  $me = $ENV{'DOCUMENT_URI'};
#  $me =~ s/\//=/g;
#  $log = $base.$me.".count";
#
#  open (LOGFILE, ">> $log");
#  print LOGFILE "x";
#  close (LOGFILE);
#  @info = stat($log);
#  return ($info[7]);
#}

sub rain {
  local($number) = @_;

  local($base) = "/local/www/httpd/htdocs/pics/meter/";
  local($me) = $ENV{'DOCUMENT_URI'};
  $me =~ s/\//=/g;
  local($numfile) = "/tmp/".$me.$$.".xbm";
  local($pbmfile) = "/tmp/".$me.$$.".pbm";
  local($pgmfile) = "/tmp/".$me.$$.".pgm";
  local($ppmfile) = "/tmp/".$me.$$.".ppm";
  local($file1) = "/local/www/tools/bow.ppm";
  local($file2) = "/tmp/".$me.$$."1.ppm";
  local($result) = "/tmp/".$me.$$."mixd.ppm";
  local($giffile) = $base.$me.".gif";

  if (!$number) {
    exit;
  }

  &digits($number, $numfile);
  select STDOUT;
  system "/usr/local/bin/xbmtopbm $numfile > $pbmfile";
  sleep 1;
  system "/usr/local/bin/pbmtopgm 2 2 $pbmfile > $pgmfile";
  unlink $numfile;
  system "/usr/local/bin/pgmtoppm \"#E0E0E0E0E0E0\" $pgmfile > $ppmfile";
  unlink $pbmfile;
  system "/usr/local/bin/pnmdepth 255 $ppmfile > $file2";
  unlink $pgmfile;
  system "/usr/local/bin/ppmmix 0.5 $file1 $file2 > $result";
  unlink $ppmfile;
  system "/usr/local/bin/ppmtogif -sort $result > $giffile";
  unlink $file2;
  print "ContentType: text/html\n\n";
  print "<IMG SRC=\"/pics/meter/", $me, ".gif\" height=16 width=80>\n";
  unlink $result;
}
