#!/usr/bin/perl -w

# specify complete path+name for RAV program
my $ravprogram = '/usr/local/rav8/bin/ravlin8';


# Unfortunately Rav Antivirus truncates filenames when writing to STDOUT but
# preserves them when writing to his report file, so I run the antivirus
# with --report option and then print the report file to STDOUT and return
# the original ERRORLEVEL to sweep.pl

# build report filename using the last parameter (basedir)
my $reportfile = sprintf('%s/report.vir', $ARGV[$#ARGV]);

# build command line for rav antivirus program
my $command = sprintf('%s --report=%s %s/ > /dev/null', $ravprogram, $reportfile, join(" ", @ARGV));

# run program and store system error
my $error = system($command);

# if a report is produced...
if(-f $reportfile) {
  # open the report...
  open(RPT, "<".$reportfile);
  while(<RPT>) {
    # and print it to standard output...
    print $_;
  }
  close(RPT);
  # delete report file
  unlink($reportfile);
}

# exit using stored system error
exit($error);
