#!/usr/bin/perl # classic_print: pass a Postscript file to the appropriate PrinterProxy # Usage: classic_print_wrapper printer_name file1 file2 ... # printer_name: the name of the printer # file1 file2 ... : the names of the files # Written by Toshi Nagata, 2005/03/11 # Copyright 2005 (c) Toshi Nagata. All rights reserved. use POSIX qw(strftime); $home = $ENV{"HOME"}; open(LOG, ">>$home/Library/Logs/classic_print.log"); $tmpdir = "/tmp/$> 8); exit(1); } else { unlink($file); print LOG header(), "PrinterProxy successful. \'$file\' is deleted.\n"; } } else { print LOG header(), "failed to read through \'$file\'... wrong Postscript file?\n"; } } exit(0); sub header { return strftime "%Y/%m/%d %H:%M:%S classic_print: ", localtime; } sub wait_for_eof { my ($file) = @_; local $/; if (!open($file, $file)) { return 0; } $/ = "\r"; # Macintosh EOL while (1) { my $line = <$file>; while (substr($line, -1) ne "\r" && $line !~ /^%%EOF/) { my $line2; my $time = time; while (!($line2 = <$file>)) { if (time > $time + 600) { print LOG header(), "timeout: 600 seconds passed without new input.\n"; close($file); return 0; } } $line .= $line2; } if ($line =~ /^%%EOF/) { close($file); return 1; } } }