#!/s/std/bin/perl -w
#
# lpr.pl	Craig Huckabee
#
# This is a 'wrapper' around the real lpr that SAMBA uses.  It groks out
# the real document name from the print job, then prints the print job
# setting the title.  If no title is found, the original document name is
# used.  Obviously, this only works for Postscript files which are 99% of
# what print jobs are.
#
 
if ($#ARGV !=1){
  die "Usage: lpr <printer> <printjob>\n";
}

$printer = $ARGV[0];
$printjob = $ARGV[1];
$reallpr = "/s/std/bin/lpr";

open PJOB, $printjob || die "Error: could not open $printjob";

$title = $printjob;
while (<PJOB>) {
    if ($_ =~ /^%%Title: (Microsoft PowerPoint - |Microsoft Word - )?(.*)$/) {
        $title = $2;
        $title =~ s/
//g;
        last;
    }
}

close PJOB;

# Build up print command
$command = $reallpr." -P".$printer." -J\"".$title."\" -r ".$printjob;

# Go print the job
exec($command);
