*** empty log message ***

This commit is contained in:
hjp 2003-01-08 15:15:32 +00:00
parent 670b1bac07
commit a1164ac024
1 changed files with 68 additions and 0 deletions

68
jetdirectprint/jetdirectprint Executable file
View File

@ -0,0 +1,68 @@
#!/usr/bin/perl
# Direct-to-printer (old HP Jetdirect style printers) filter
# to integrate with rhs-printfilters.
# Supplied by Joshua Buysse, University of Minnesota
# needs perl 5.004 for IO:Socket
require 5.004;
# Maximum number of times to retry connection
$max_retries = 3600; # at one second each, one hour.
# needed for the dirname() function
use File::Basename;
use IO::Socket;
$config_file = "script.cfg";
open(CONFIG, $config_file) || die "No config file found!";
while (<CONFIG>) {
chomp;
s/#.*//; # no comments
s/^\s+//; # no leading white
s/\s+$//; # no trailing white
# If there's nothing left, we're done.
next unless length;
# split the fields
my ($key,$value) = split /\s*=\s*/, $_, 2;
$config{$key} = $value;
}
# the config hash should contain port and printer_ip as keys
# if the port isn't set, use the default of 9100
$config{'port'} = 9100 unless $config{'port'};
$config{'printer_ip'} || die "Config file does not specify printer IP.";
# now, open a socket to the printer.
$retry_count = 0;
do {
$socket = IO::Socket::INET->new(PeerAddr => $config{'printer_ip'},
PeerPort => $config{'port'},
Proto => "tcp",
Type => SOCK_STREAM);
if (! $socket) {
sleep 1;
$retry_count++;
}
} until ($socket || ($retry_count > $max_retries));
$socket || die "Unable to open socket after $retry_count retries.";
while (<STDIN>) {
print $socket $_;
}
close($socket);