Filters

Virtual printer definitions contain predefined and open (undefined) filter attributes.

For example, an AIX® Version 4 ASCII queue on an IBM® 4029 LaserPrinter offers the following filter attributes:

  • f1, f2, f3, f4, and f5 - open, user-defined filters
  • fb - bidi filter for Hebrew/Arabic.
  • fc - cifplot filter
  • fd - TeX (DVI) filter
  • ff - FORTRAN filter
  • fg - plot filter
  • fl - passthru filter
  • fn - ditroff filter
  • fp - pr filter
  • fv Raster image filter
  • fc, fd, ff, fg, fl, fn ,ft, fv - open, user-defined filters
  • fp - pr filter

Filters are the first programs in the input data stream processing pipeline set up by the piobe command that have an opportunity to selectively manipulate the data stream. A particular filter can be selected from the command line on a per-job basis, or permanently selected by modifying the virtual printer definition.

The qprt command uses the -f flag to select a particular filter on a per-job basis. The argument to the -f flag is the second letter of the two letters that name the filter attribute in the virtual printer definition. For example, to select the pr filter for a job on an ASCII queue named asc on an IBM 4029 LaserPrinter, you could issue this command:

qprt -Pasc -fp /etc/motd

The filter attribute that selects the pr filter is named fp, so the argument to the -f flag is just p, the second letter.

To permanently select the pr filter, use the lsvirprt command to edit the virtual printer definition and set the value of the _f attribute to p. The _f attribute selects a filter that will be used to pre-process any job submitted to the queue associated with this virtual printer definition.

Because lp, lpr, and qprt are all just front ends to the enq command, the true entry point to the spooler, you would suppose that enq must support the -f flag. If you issue the enq command with the -f flag, however, you will receive an error message; enq does not support the -f flag. This is a situation where the previously described technique (see Spooler data flow (enq command)) of mounting /bin/echo over /bin/enq proves useful.

The root user can issue these commands from a shell prompt:

  1. mount /bin/echo /bin/enq
  2. qprt -Pasc -fp /etc/motd
  3. umount /bin/enq

After the second command is issued, the following appears in the display element defined by your TERM environment variable:

-P asc -o -f -o p /etc/motd

These are the arguments qprt tried to pass to enq. You see them because qprt found echo instead of enq. The following command is equivalent to the command shown in step 2 above:

enq -P asc -o -f -o p /etc/motd

The -o option specifies that flags specific to the backend should be passed to the backend. The -o option can be thought of as a free pass through the syntax checking that occurs before the enq command builds a job description file and notifies the qdaemon of the existence of a new job.

Suppose that you want to set up a queue that will print a range of lines from an ASCII file. For example, suppose you read /usr/lpp/bos/README and find 35 lines that you want to print so you can fax them to someone or tack them to your wall for reference. You could edit /etc/qconfig and add the following lines:

partial:
        device = partial
partial:
        file = FALSE
        backend = /usr/bin/partial

The file /usr/bin/partial could be a shell script with ownership of root.printq and with permissions of 755. Its contents could be as follows:

#!/bin/ksh
BEGIN=$1
END=$2
let DIFF=END-BEGIN+1
FILE=$3
/usr/bin/head -${END} ${FILE} | tail -${DIFF} | /usr/bin/qprt -Pasc

If you wanted to print lines 189 through 223 of /usr/lpp/bos/README, you could use the partial queue as follows:

qprt -Ppartial -o 189 -o 223 /usr/lpp/bos/README

When the backend executes, BEGIN is assigned 189, END is assigned 223, and DIFF is assigned 35, which is the number of chosen lines. FILE is assigned /usr/lpp/bos/README. The head command truncates /usr/lpp/bos/README immediately after the last requested line. The output is piped to the tail command, which selects the last 35 lines of the truncated file and pipes them to the qprt command, which will take input from stdin. The qprt command submits the lines to the queue named asc.