#!/usr/bin/perl

#
# LiveCounter Classic 97B
# Copyright (C) 1996-1998, by Chaminda Wickremasinghe (72223.10@compuserve.com)
# http://www.chami.com/
#
# This copy is not registered for business use.
#

{
  $__COUNTER_DAT = "livecntr.dat";

  if( $ARGV[0] )
  {
    local( $nCount ) = 0;
    local( $Temp );

    print "Content-type: text/plain\n\n";

    if("" ne $ARGV[4])
    {
      $ENV{'HTTP_REFERER'} = $ARGV[4];
    }

    if( $ARGV[1] && ($ARGV[1] ne "0") )
    {
      $__COUNTER_DAT = $ARGV[1] . "\.lcd";
    }

    if( -w "$__COUNTER_DAT" )
    {
      open( F, "+<$__COUNTER_DAT" );

      flock( F, 2 );
      seek( F, 0, 0 );

      ( $Temp, $nCount ) = split( /\s/, <F> );

      if( "i" eq $ARGV[0] )
      {
        seek( F, 0, 0 );
        ++$nCount;
        print F "Total: $nCount\n";
      }
      flock( F, 8 );
      close( F );
    }
    elsif( !( -e "$__COUNTER_DAT" ) )
    {
      open( F, ">$__COUNTER_DAT" );
      print F "Total: 0\n";
      close( F );
    }

    print "c0=$nCount\n";
    if( "v" eq $ARGV[0] )
    {
      print "vr=97BX\n";
    }
  }
}
