
Article Title           : Using_SysV_spoolers
Creation Date           : 09/23/93
Message ID              : 
Last Update             :
Expiration Rules        : valid for pre-3.1 releases only
=================================================================

NOTE: NCD print utilities changed in NCDware 3.1   This article
documents the earlier version.  If you have NCDware 3.1 or later
version, please see information on the NCDware Contribution CD-ROM 
/src/NCD/ncdprint/README.  This information is also available on 
our ftp site in /pub/ncd/Archive/PublicSrc/ncdprint.fast.tar.Z
----------------------------------------------------------------

The System V.4 spooling system is a very flexible and configurable 
system. It allows the system administrator several choices in setting
up an interface to a printer connected to the serial port of an NCD.
This note discusses several approaches, but in no way should these 
approaches be considered "the best". Several decisions can be made based
on the local environment and users that could result in drastically 
different solutions. There are several good references to the intricacies
of the spooling system that can be consulted for further detail. This
note will only deal with a few specific points.


Using the spooler for single output type
----------------------------------------

If the output to the printer is expected to be of a single type, e.g., all
ASCII, or all PostScript, then the spooler configuration is quite straight
forward. A sample set of steps would be:

1) install the appropriate NCD binary. For example, if the printer is a
   PostScript printer, put 'ps2ncd' in an appropriate bin directory. At 
   this point you should verify that the basic connection works by sending
   a file to the printer. This can be done by invoking the binary directly,
   without spooler intervention. 
   
   [NOTE: it is important that this step be done first! If the basic 
   connection to the NCD/printer does not work, there is no point to 
   configuring the spooler!]

2) add the NCD as a 'logical' printer to the spooling system. For example,
   if you wish users to see the printer as 'ncd', you could use the command:

	lpadmin -p ncd -v /dev/null

   Note that the device file '/dev/null' is used because the printer is
   not physically attached to the host. 

   [NOTE: an alternate to /dev/null is to create a file for lpadmin to 
   'use' as the device. This could avoid the potential problems of a 
   utility changing the modes of /dev/null, for example.]

   This command will create several system files and directories. Of 
   particular interest is the 'interface' program. This is a shell script
   created in the directory '/etc/lp/interfaces'.

3) edit the interface program to output using the NCD print binary. A 
   simple way is to look for the section of the script that initializes
   the variable 'LPCAT'. The default action is to set this to a binary
   call '/usr/spool/lp/bin/lp.cat'. Change this to use 'ncd.cat'.

4) create a script in /usr/spool/lp/bin called 'ncd.cat'. Assuming that
   there is no processing necessary other than sending the data to the
   NCD, this can be as simple as:

	#!/bin/sh
	# 
	# ncd.cat, version 1
	#
	/usr/local/bin/cat2ncd <name_of_NCD_with_terminal_attached>

   Verify that this script is executable, since it will be invoked by the
   spooler when the interface program is executed.

5) issue the appropriate 'accept' and enable commands for the spooler, and
   the users should be able to access the printer.


Using the spooler for mixed ASCII and PostScript
------------------------------------------------

The description above explicitly assumes that the data going to the printer
will be of one type. A more typical situation is the use of a PostScript
printer in an environment with users who want to print both PostScript 
documents and straight ASCII text. Most PostScript printers will not accept
raw ASCII text, so the spooling system must 'wrap' the ASCII text with
PostScript headers and trailers. There are two alternate paths the 
administrator can choose; the spooler can be set up using the standard
System V.4 'filter' mechanisms, or the 'ncd.cat' script mentioned above
can be made a bit more intelligent. 

To understand the native 'filter' mechanism, it is necessary to understand
the mechanisms of the spooler in a bit more detail. (This note won't attempt
to go very far with this, and the user should consult a reference manual 
for detailed explanation if desired.) In the SysV.4 spooler, output data 
is defined to have a certain 'content type'. Printers are defined to have
a list of 'content types' that they understand. 'Filters' are utilities 
used by the spooler to process output data whose content type does not
match the content type understood by the destination printer. 

As an example, consider the typical PostScript printer. This printer only
understands data with the content type of 'postscript'. A straight ASCII file,
however, has a content type of 'simple'. The spooler will notice this 
mismatch, and will search the list of known filters for one that converts
'simple' data to 'postscript' data. An example of this filter can be found
as /usr/lib/lp/postscript/postprint. To see a complete list of available 
filters on the host, type

			lpfilter -f all -l

To tell the spooling system that the printer attached to the NCD, as in 
the above example, is a PostScript printer, the lpadmin command:

			lpadmin -p ncd -I postscript

configures the spooler to only send PostScript data to this printer. Since
the default content type is 'simple', typing the command:

			lp -d ncd <ASCII_file_name> 

will automatically invoke the ASCII-to-PostScript filter before sending
the data to the printer. An important limitation to this mechanism, however,
is that the user must explicitly tell the spooler about PostScript data
when spooling, since the spooler does not attempt to read the actual data.
For example, to print a data file that is already PostScript, the user would
need to type:

		lp -d ncd -T postscript <PS_file_name>

If the user fails to do this, the spooler will assume that the PostScript
data is ASCII, (i.e., type 'simple'), and will wrap PostScript with 
Postscript.

An alternative to this scheme is to use some of the sample code provided 
on the NCDware distribution. Using the provided utilities, it is possible
to build a more intelligent version of the script 'ncd.cat' as follows:

	#!/bin/sh
	#
	# ncd.cat, version 2
	#
	# READN: program to extract first two bytes of data. Used to check
	#	 for PostScript.
	READN=/usr/local/bin/readn
	#
	# LWF: program to 'wrap' ASCII text in PostScript
	LWF=/usr/lib/lp/postscript/postprint
	#
	# PRINT: program to output data with no cr/lf
	PRINT=/usr/local/bin/print
	#
	# NCDPRINT: program to actually send data to the NCD
	NCDPRINT=/usr/local/bin/ncdprint
	#
	# NCD: name of terminal with attached printer
	NCD=ndg
	#
	# PS_OUTPUT: command to print PostScript data
	PS_OUTPUT="$NCDPRINT $NCD"
	#
	# ASCII_OUTPUT: command to print ASCII data after PostScript wrap
	ASCII_OUTPUT="cat |$LWF |$PS_OUTPUT"
	#
	# The actual work. For details see READMORE on NCD tape.

	cat - | \
	(   A=`$READN 2`; \
	    ( $PRINT "$A"; cat ) | \
	    if [ "$A" = "%!" ]; \
	    then \
		eval $PS_OUTPUT; \
	    else \
		eval $ASCII_OUTPUT; \
	    fi; \
	)


With this script, the printer can now be considered capable of accepting
output data of types 'simple' and 'postscript', since the interface program
will 'peek' at the data stream to check for any required preprocessing. 

[NOTE: for more information on the extra utilities used, or the script logic
itself, see the normal NCDware distribution.] 

The correct initialization for the printer using this script would be:

		lpadmin -p ncd -I postscript,simple

Users can now simply submit either ASCII or PostScript data to the spooler,
with the correct output being sent to the printer automatically.


Going Further
-------------

It is highly recommended that the system administrator look into the 
spooling literature more carefully, as there are many more options and
configurations available. The standard samples on the NCDware distribution
have more extensive error checking and return codes, and can provide a
good basis for adding to the ncd.cat scripts described in this note. 













