package General;
 
# Generic subroutines.
#     * openLog: open the debugging log.
#     * log: actually log a message
#     * PrintHTMLTail: print the standard OI tailer
#     * PrintTemplate: print a template

sub openLog {
  open(LOG, ">/tmp/a") || Error::CantOpenFile("/tmp/a");
  select(LOG);
  $|=1;
  select(STDOUT);
  print LOG "-------------------------------------------------------\n";
  print LOG $_[0]."\n";
}
 
sub log {
  my $data=$_[0];
  local($oldfh);
# $0 is the name of the process that we're in...
  $_=$0;
# ...so the Server logs to its log, not the client log
  if (/Server/) {
    $oldfh=select(SERVER_LOG);
  } else {
    $oldfh=select(LOG);
  }
# turn off buffering
  $|=1;
  print "$data\n";
  select($oldfh);
}
 
sub PrintHTMLTail {
  my (@args)=@_;
  my ($OUT);
  if ($#args==-1) {
    $OUT=STDOUT;
  } else {
    $OUT=$args[0];
  }
  print $OUT "<p><hr>\n";
  print $OUT "<i>".Constants::get(SIG)." (<a href=\"".Constants::get(SIG_HREF).
    "\">".Constants::get(SIG_VALUE)."</a>)</i><p>\n";
  print $OUT "<font size=-1><center>\n";
  print $OUT "<a href=\"http://www.mit.edu/~dcltdw/OpenImpetus\"><b>OpenImpetus</b></a> $main::VERSION competition web registration software.<br>Copyright 1999 David Leung.  All Rights Reserved.\n";
  print $OUT "</center></font>\n";
  print $OUT "</BODY></HTML>\n";
# EVERYONE closes their connection to the Server here.
  Database::close_connection() if $#args==-1; # don't call this when writing to a file
}
 
sub PrintTemplate {
  my ($file, $OUT)=@_;
  General::log("PrintTemplate: $file") if $debug;

  open(FOO, $file) || return(1);
  while(<FOO>) {print $OUT $_;}
  close(FOO);
  General::log("PrintTemplate: returning") if $debug;
  return(1);
}

1;
