Subject: Re: How to strip ^D from print file?

From: [email-masked] (Rob McMahon)
Date: 26 May 1994 17:19:38 +0100

In article <[email-masked]>, [email-masked] (Robert
Seals) writes: 
>I print from MS windows to unix machines using an lpr spooler program that
>runs with winsock. When one of our unix systems changed from sunos to
>solaris, this method no longer works.  I believe it is because the Windows
>Postscript driver inserts a ^D before the good stuff, and whatever the lp
>system in system 5 does to identify files can't figure out what a ^D file is,
>so it gives up.

What I did was to mv /usr/lib/lp/postscript/postprint{,.real} and install this
as /usr/lib/lp/postscript/postprint:

------------------------------------------------------------------------------
#!/usr/bin/perl
$line1 = <STDIN>;
# Groan, the Windows HP-IIIsi driver sticks this crud on the beginning
$line1 = <STDIN> if $line1 =~ /^\033%-12345X@/;
$line2 = <STDIN>;
$line1 =~ s/[\001-\007\016-\032\034-\037]//g;
$line2 =~ s/[\001-\007\016-\032\034-\037]//g;
if ( $line1 =~ /[\000\033]/ || $line2 =~ /[\000\033]/ ) {
   print STDERR "Binary file rejected\n";
   exit 1;
}
if ( $line1 eq "save\n" && $line2 eq "initgraphics\n" ) {
   # this is a nasty horrible chart file maybe ?
   # guessing ... but it sure looks like PostScript
   print "%!\n";
} elsif ( $line1 =~ /^%!/
	  # && $line1 !~ /EPSF/
	  && $line2 =~ /^PS[pl]/ ) {
   # Word output, without word header, tack on the word header
   # print "%!\n(prolog/word) run\n";
   open(PROLOG, "</usr/local/lib/ps/word5.pro");
   while (<PROLOG>) {
      print;
   }
   close(PROLOG);
} elsif ( $line1 !~ /^%!/ ) {
   open(POSTPRINT, "|-") || exec "/usr/lib/lp/postscript/postprint.real", @ARGV;
   select(POSTPRINT);
}
print $line1, $line2;
while(<STDIN>) {
   next if /^\004\033%-12345X/;		# AAGH!
   s/[\001-\007\016-\032\034-\037]//g;
   print; 
}
------------------------------------------------------------------------------

It's a ghastly kludge, but it doesn't rely on everyone setting up their
printer drivers correctly (which is of course doomed).

Cheers,

Rob
-- 
UUCP:	...!mcsun!uknet!warwick!cudcv	PHONE:  +44 203 523037
INET:	[email-masked]
Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England