SUMMARY -- lpd filters

We need to access the printer in multiple modes, to print different
types of files.

Configuration:

. HP LaserJet II
. Sun 3/50
. SunOS 4.1.1

We need to print both Unix text files and "binary" files generated by
specialized software, e.g., WordPerfect on a PC (these files are not so
much "binary" as a bunch of escape sequences with a few words of text
interspersed).

. Unix text files have newlines as line terminators.
. "binary" files do not -- should be printed "as is"
. (i.e., do not transform "\n" to "\r\n").

I received a number of suggestions, usually in the form "here's my
configuration, it works for me....". Basically, these suggestions
divided into four groups formed by a 2X2 matrix.

One axis of the matrix is concerned with how to handle different
classes of files:

. define a single printer with different filters
. define separate logical printers in the printcap
. (which would all print to the same physical device)

The other axis concerns where to do transformations (if any):

. on the sun
. program the printer (via escape sequences) to do them

Eventually, I chose to use different filters and to program the printer
to do the transformations.

The principal problem with this method is getting the "of" filter
(which prints the banner pages and ordinary text files) to stop when
another filter is required to print a specialized document. TFM is
irritatingly vague on this point (System & Network Admin, p. 351):

If entries for both "of" and one of the other filters are
specified, the output filter is used only to print the banner
page; it is then stopped to allow other filters access to the
printer.

Just how it is "stopped" is nowhere described!

Here, BTW, is what the Sun "Answerline" had to say:

.... Regarding your printer filter questions, I'm afraid I won't
be able to assist you in debugging this.

Technical bookstores might have some documentation in writing
filters. Also, we do have a consulting group that can assist you
in writing customized applications/utilities....

Thanks a bunch, Answerline, sure glad we pay you all that money so you
can be so helpful!!!!!

The solution came from Matt Larson (uunet!avalon.eecs.nwu.edu!matt),
who forwarded a configuration originally written in Dec '87 by Brian
Utterback. My code is essentially just a stripped down version of
Brian's.

The key to writing an lpd filter is knowing that the daemon sends a
^Y^A (control/Y, control/A) character sequence to the "of" filter as a
signal that it is to stop itself! (Why the daemon doesn't simply send
a signal to the child is a mystery some Unix historian will have to
unearth :-). The "of" filter sends itself a stop signal, the daemon
fires up the alternate filter to process the data, then restarts the
"of" filter to print the next banner page.

If lpr is invoked with the "-l" option, the daemon instructs
the "if" filter not to filter control characters ("if" is
invoked with the "-c" option). Since I never filter control
characters, I use this option as an alternate way of specifying
"binary" printing; unfortunately, the software on the PCs does
not support the "-l" option. :-(

The "vf" filter is supposed to be used to print raster images,
e.g., something created by screendump. Since we don't do that,
I use it to print "binary" files. The PCs do support the "-v"
option. :-)

If you try to print a file with the character sequence ^Y^A in
the name (unlikely, but legal in Unix), the result is curious.
Even more so if the name has more than one occurrence of the
sequence.

As indicated earlier, some respondants used multiple logical printers
to print different types of documents on the laserjet (presumably the
spooler system uses some kind of locking on the output file to keep
multiple daemons from tripping over each other). In addition to
designating different printers for text and binary files, this
technique could be used, e.g. to differentiate portrait and landscape
modes. One respondant mapped the different PC printer devices (LPT1,
LPT2, etc.) to corresponding logical printer spools.

However (IMHO), at least within Unix, these capabilities are better
realized by massaging the data before sending them to lpd, using a tool
to insert the appropriate escape sequences in the data stream. Ours is
called "laser", it's not great (I'm sure there are better tools by
now), but it's available if you want it.

The rest of this email is a shar file of the filters I am using and my
printcap. If anybody wants info on other methods, or has any other
questions, please send email, I'll be happy to send you everything I
have.