Filters are used to handle device dependencies and accounting functions.
The filters include the following:
An output filter isn't suitable for accounting purposes because it's started only once, all text files are filtered through it, it doesn't pass owners'login names, and it doesn't identify the beginnings and ends of jobs.
va|varian|Benson-Varian:\ :lp=/dev/va0:sd=/usr/spool/vad:of=/usr/lib/vpf:\ :tf=/usr/lib/rvcat:mx#2000:pl#58:px=2112:py=1700:tr=\f:
The tf entry specifies /usr/lib/rvcat as the filter to use when printing troff output. This filter is needed to set the device into print mode for text and into plot mode for printing troff files and raster images. Note that the page length is set to 58 lines by the pl entry for 8.5″ by 11″ fanfold paper.
To enable accounting, add an af filter to the varian entry, like this:
va|varian|Benson-Varian:\ :lp=/dev/va0:sd=/usr/spool/vad:of=/usr/lib/vpf:\ :if=/usr/lib/vpf:tf=/usr/lib/rvcat:af=/usr/adm/vaacct:\ :mx#2000:pl#58:px=2112:py=1700:tr=\f:
The lpd daemon spawns the filters; their standard input is the data to be printed; their standard output is the printer. Standard error is attached to the lf file for logging errors (or you can use syslogd). A filter must return an exit code of 0 if there were no errors, 1 if the job should be reprinted, or 2 if the job should be thrown away.
When lprrm sends a SIGINT signal to the lpd process that controls the printing, lpd sends a SIGINT signal to all filters and their descendants. Filters that need to do cleanup operations, such as deleting temporary files, can trap this signal.
The arguments lpd passes to a filter depend on the filter type:
filter -wwidth -llength
The width and length values come from the pw and pl entries in the /etc/printcap database.
filter [-c] -wwidth -llength -iindent -nlogin -hhost acct_file
The optional -c flag is used only when control characters are to be passed uninterpreted to the printer (when using the -l option of lpr to print the file). The -w and -l parameters are the same as for of filters. The -n and -h parameters specify the login name and hostname of the job owner. The last argument is the name of the accounting file from /etc/printcap.
filter -xwidth -ylength -nlogin -hhost acct_file
The -x and -y options specify the horizontal and vertical page size in pixels (from the px and py entries in the /etc/printcap file). The rest of the arguments are the same as for if filters.