henesyinit from p9fd787fda5 years agoHistory
747 lines · 20.7 KB · HTML
RawDownload
<html><title>data</title><body BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#330088" ALINK="#FF0044"><H1>A Guide to the LpPrinter Spooler</H1><DL><DD><I>Paul Glick<br>pg@plan9.bell-labs.com<br></I></DL><DL><DD><H4>ABSTRACT</H4><P><I>Lp</I>is a collection of programs used to provide an easy-to-useinterface for printing a variety of document types on a varietyof printers.<I>Lp</I>is the glue that connects various document languagetranslators and printer communication programs together so thatthe users may have a consistent view of printers.Most of the glueis shell script, which can be easily modified.The user need notspecify options to get sensible output in most cases.<I>Lp</I>is described hereso that others may make additions and changes.</DL> </P><H4>1 Introduction</H4><P><I>Lp</I>is used to format and print data on a variety of output devices.The need for<I>lp</I>was rooted in the inability of other printer spoolers to do simpletasks without a great deal of user specification of options.At the time<I>lp</I>was written, there were several printerlanguages, such as ImPress and PostScript, andan internally developed printer that would accept<I>troff</I>output.Now, all our printers take PostScript,but printers that use HPCL and HPGL abound andsupport for those printers may be added easily.A great deal of what underlies<I>lp</I>is taken from BSD's<I>lpr</I>and System V's<I>lp</I>.The important features of this system are that most of the programsare easily modified shell scripts and the user need notlearn to use the large amount of underlying software developed by others.<I>Lp</I>runs under Plan 9 and several flavors ofUNIX.This document deals with<I>lp</I>as it relates to Plan 9.<I>Lp</I>was developed using both Datakit and Ethernet to transport data between machines.Now only the Ethernet transport mechanism remains.</P><P>Text, graphics, and formatted text files are appropriately processed andplaced into a spool directory from which they are taken to be printed by a daemon process.Additional functions include checking the status of a printer queueand removing jobs from the printer queue.</P><P>All the shell scripts (see<A href="/magic/man2html/1/rc"><I>rc</I>(1))</A>associated with<I>lp</I>reside in the spool directory<TT>/sys/lib/lp</TT>except for the<I>lp</I>command itself, which resides in<TT>/rc/bin</TT>.Commands related to<I>lp</I>that are not shell scripts can most often be foundin<TT>/$cputype/bin/aux</TT>.The directory where all the<I>lp</I>scripts  reside is defined within<I>lp</I>by the shell variable<TT>LPLIB</TT>.In the remainder of this document, file names will be specifiedwith this shell variable as their root.</P><H4>2 Usage</H4><P><I>Lp</I>requires an output device to be specifiedbefore it will process input.This can be done in any of three ways described here.</P><DL COMPACT><DT>1)<DD>The file<TT>$LPLIB/defdevice</TT>may contain the name of a default output device.This may not be practical for environments wherethere are many printers.<DT>2)<DD>The user's environment variable<TT>LPDEST</TT>may be set to the name of the device to be used.This is often a more practical solution when there are several printersavailable.This overrides a<TT>defdevice</TT>specification.<DT>3)<DD>The<TT>-d</TT><I>printer</I>option to the<I>lp</I>command specifies<I>printer</I>as the device to which output should be directed, overriding theprevious two specifications.</dl><P><br>If<I>printer</I>is<TT>?</TT>,a list of printers and other information in the<TT>devices</TT>file is printed, as shown in Figure 1.Quote the question mark to prevent it from beinginterpreted by the shell language as a metacharacter. <DL><DT><DD><TT><PRE>% lp -d'?'device   location  host             classfn       2C-501    helix            post/2+600dpi+duplexpcclone  -         -                post+noheadpeacock  2C-501    cetus            post/2+300dpi+nohead+colorps83     st8_fl3   rice             post+300dpi+reversepsu      2C-501    cetus            post/2+1200dpi     .     .     .%</PRE></TT></DL><I>Figure 1.  Sample listing of installed printers</I></P><P>Normally,<I>lp</I>uses the<TT>file</TT>command to figure out what type of input it is receiving.This is done within the<TT>generic</TT>process which is discussed later in this paper in the<B>Process directory</B>section.To select a specific input processor the<TT>-p</TT><I>process</I>option is used where<I>process</I>is one of the shell scripts in the<TT>process</TT>directory.</P><br>&#32;<br>Troffoutput can be printed, in this case, on printer<I>fn</I>with<DL><DT><DD><TT><PRE>% troff -ms lp.ms | lp -dfn</PRE></TT></DL><br>&#32;<br>A file can be converted to PostScript using the pseudo-printer<TT>stdout</TT>:<DL><DT><DD><TT><PRE>% troff -ms lp.ms | lp -dstdout &#62; lp.ps</PRE></TT></DL>LaTeX (and analogously TeX)documents are printed in two steps:<DL><DT><DD><TT><PRE>% latex lp.tex     .     .% lp lp.dvi     .     .%</PRE></TT></DL>LaTeXproduces a `.dvi' file anddoes not permit the use of a pipeconnection to the standard input of<I>lp</I>.To look at the status and queue of a device, use<TT>-q</TT>:<DL><DT><DD><TT><PRE>% lp -dpsu -qdaemon status::  67.17% sentprinter status:%%[ status: busy; source: lpd ]%% queue on cetus:job		user	try	sizerice29436.1	pg	0	17454slocum17565.1	ches	1	49995%</PRE></TT></DL>This command can print the status and queue of the localand remote hosts.Administrators should be advised that working in an environment where the<I>lp</I>spool directory is shared among the local and remote hosts,no spooling should be done on the local hosts.The format of the status and queue printout is up to the administrator.The job started above can be killed with<TT>-k</TT>:<DL><DT><DD><TT><PRE>$ lp -dpsu -k rice29436.1rice29436.1 removed from psu queue on cetus</PRE></TT></DL><H4>3 Options</H4><P>There are options available to modify the way in which a job is handled.It is the job of the<I>lp</I>programs to convert the option settings so they may be used by each of thedifferent translation and interface programs.Not all options are applicable to all printer environments.Table 1 lists the standard<I>lp</I>options, the shell variable settings, and description of the options. <br>&#32;<br><br><img src="data.15750.gif"><br><br>&#32;<br><I>Table 1. Lp Option List</I><br>&#32;<br> </P><H4>4 Devices file</H4><P>The<TT>devices</TT>file is found in the spool directory.Each line in the file is composed of 12 fields, separatedby tabs or spaces, that describe the attributesof the printer and how it should be serviced.Within the<TT>lp</TT>command, a shell variable is set for each attribute;the following list describes them:</P><DL COMPACT><DT><TT>0<DD>LPDEST0</TT> is the name of the device as given to<I>lp</I>with the<TT>-d</TT>optionor as specified by the shell environment variable<TT>LPDEST</TT>or as specified bythe file<TT>$LPLIB/defdevice</TT>.This name is used in creating directories and log files that are associated withthe printers operation.<DT><TT>0<DD>LOC0</TT> just describes where the printer is physically located.<DT><TT>0<DD>DEST_HOST0</TT> is the host from which the files are printed.Files may be spooled on other machines before being transferred to thedestination host.<DT><TT>0<DD>OUT_DEV0</TT> is the physical device name or network address needed by the printer daemonto connect to the printer.This field depends on the requirements of the daemon and may contain a `&#191;'if not required.<DT><TT>0<DD>SPEED0</TT> is the baud rate setting for the port.This field depends on the requirements of the daemon and may contain a `&#191;'if not required.<DT><TT>0<DD>LPCLASS0</TT> is used to encode minor printer differences.The keyword<TT>reverse</TT>is used by some of the preprocessorsto reverse the order the pages are printed to accommodate different outputtrays (either face up or face down).The keyword<TT>nohead</TT>is used to suppress the header page.This is used for special and color printers.The keyword<TT>duplex</TT>is used to coax double sided output from duplex printers.<DT><TT>0<DD>LPPROC0</TT> is the command from the<TT>LPLIB/process</TT>directory to be used to convert input to a formatthat will be accepted by the device.The preprocessor is invoked by the spooler.<DT><TT>0<DD>SPOOLER0</TT> is the command from the<TT>LPLIB/spooler</TT>directory which will select files using the<TT>SCHED</TT>command and invoke the<TT>LPPROC</TT>command, putting its outputinto the remote spool directory.The output is sent directly to the spool directory on thedestination machine to avoid conflicts when client andserver machines share spool directories.<DT><TT>0<DD>STAT0</TT> is the command from the<TT>LPLIB/stat</TT>directory that prints the status of the device and the list of jobswaiting on the queue for the device.The status information depends on what is available from the printerand interface software.The queue information should be changed to show informationuseful in tracking down problems.The<TT>SCHED</TT>command is used to show the jobs in the orderin which they will be printed.<DT><TT>0<DD>KILL0</TT> is the command from the<TT>LPLIB/kill</TT>that removes jobs from the queue.The jobs to be removed are given as arguments to the<I>lp</I>command.When possible, it should also abort the currently running jobif it has to be killed.<DT><TT>0<DD>DAEMON0</TT> is the command from the<TT>LPLIB/daemon</TT>that is meant to run asynchronously to removejobs from the queue.Jobs may either be passed on to another host or sent to theprinting device.<I>Lp</I>always tries to start a daemon process when one is specified.<DT><TT>0<DD>SCHED0</TT> is the command from the<TT>LPLIB/sched</TT>that is used to present the job names to thedaemon and stat programsin some order, e.g., first-in-first-out, smallest first.</dl><H4>5 Support programs</H4><P>The following sections describe the basic functions of the programsthat are found in the subdirectories of<TT>$LPLIB</TT>.The programs in a specific directory vary with thetype of output device or networks that have to be used.</P><H4>5.1 Process directory</H4><P>The<TT>generic</TT>preprocessoris the default preprocessor for most printers.It uses the<A href="/magic/man2html/1/file"><I>file</I>(1)</A>command to determine the format of the input file.The appropriate preprocessor is then selected to transform thefile to a format suitable for the printer.</P><P>Here is a list of some of the preprocessors anda description of their function.A complete list of preprocessors and their descriptions can be found in the manual page<A href="/magic/man2html/8/lp"><I>lp</I>(8).</A><br>&#32;<br></P><DL COMPACT><DT><TT>dvipost</TT><DD>Converts TeX or LaTeX output (<TT>.dvi</TT> files) to PostScript<DT><TT>ppost</TT><DD>Converts UTF text to PostScript.The default font is Courier with Lucida fonts filling inthe remainder of the (available) Unicode character space.<DT><TT>tr2post</TT><DD>Converts (device independent) troff output for the device type<TT>utf</TT>.See<TT>/sys/lib/troff/font/devutf</TT>directory for troff font width table descriptions.See also the<TT>/sys/lib/postscript/troff</TT>directory for mappings oftroff<TT>UTF</TT>character space to PostScript font space.<DT><TT>p9bitpost</TT><DD>Converts Plan 9 bitmaps (see<I>bitfile</I>(9.6))to PostScript.<DT><TT>g3post</TT><DD>Converts fax (CCITT-G31 format) to PostScript.<DT><TT>hpost</TT><DD>Does header page processing and page reversal processing, ifnecessary.Page reversal is done here so the header page always comesout at the beginning of the job.Header page processing is very location-dependent.</dl><H4>5.2 Spool directory</H4><P>The<TT>generic</TT>spooler is responsible for executing the preprocessorand directing its output to a file in the printer's queue.An additional file is created containing information such as the system name,user id, job number, and number of times this job was attempted.</P><P>Certain printer handling programs do not require separatepreprocessing and spooling.For such circumstances a<TT>nospool</TT>spooler is available that just executes the preprocessing program.The processing and spooling functions are assumed by this program and the output is sent to<TT>OUT_DEV</TT>or standard output if<TT>OUT_DEV</TT>is '-'.</P><P>The<TT>pcclone</TT>spooler is used to send print jobs directly to a printer connectedto a 386 compatible printer port (See<A href="/magic/man2html/3/lpt"><I>lpt</I>(3)).</A></P><H4>5.3 Stat directory</H4><P>The function of the shell scripts in the<TT>stat</TT>directory is to present status information about theprinter and its queue.When necessary, the<TT>stat</TT>scripts may be designedto return information about the local queue as well as the remote queue.This is not done on Plan 9 because many systems share the same queue directory.The scheduler is used to print the queue in the order in which the jobswill be executed.</P><H4>5.4 Kill directory</H4><P>The<TT>kill</TT>scripts receive command line arguments passed to them by<I>lp</I>and remove the job and id files which match the argumentsfor the particular queue.When a job is killed, the generic kill procedure:</P><DL COMPACT><DT>1)<DD>kills the daemon for this queue if the job being killedis first in the queue,<DT>2)<DD>removes the files associated with the job from the queue,<DT>3)<DD>attempts to restart the daemon.</dl><H4>5.5 Daemon directory</H4><P>

Lines 1–500 of 747.