DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Advanced printer configuration

Defining a filter

When adding a new filter, you must define the characteristics of its use. To do this, issue the lpfilter command with arguments that specify the values of the following filter characteristics:

See the ``Adding a filter to the print service'' section for more information.

Filter definitions can be stored in a file or entered directly on the command line and have the following format:

   Command: command-pathname [options]
   Input types: input-type-list
   Output types: output-type-list
   Printer types: printer-type-list
   Printers: printer-list
   Filter type: fast or slow
   Options: template-list
The information can appear in any order. Not all the information has to be given. When you do not specify values for the items listed below, the values shown beside them are assigned by default.

lpfilter arguments

Item Default
Command: (no default)
Input types: any
Output types: any
Printer types: any
Printers: any
Filter type: slow
Options: (no default)

Default values define a flexible filter, so you probably have to supply at least the input and output type(s). When you enter a list, you can separate the items in it with blanks or commas, unless it is a template-list; items in a template-list must be separated by commas.

Each of these characteristics is described in the following paragraphs.

When you gathered enough information to define the characteristics of your filter, you are ready to run the lpfilter command, using your data as arguments. Because there are so many arguments and because some of them may need to be entered more than once (with different values), we recommend you record this information first in a separate file and edit it, if necessary. You can then use the file as input to the lpfilter command and avoid typing each piece of information separately.

Defining options with templates

A template is a statement in a filter definition that defines an option to be passed to the filter command based on the value of one of the characteristics of the filter. A filter definition may include more than one template. Multiple templates may be entered on a single line and separated with commas, or they may be entered on separate lines, preceded by the Options: prefix.

The format of a template is as follows:

   keyword pattern=replacement
This type of statement is interpreted by the print service to mean ``When the information referred to by keyword has the value matched by pattern, take the replacement string, replace any asterisks it contains with the pattern specified or expand any regular expressions it contains, and append the result to the command line.''

Let's look at an example of how an option is defined for a particular filter. Suppose you want to have the print service scheduler assign print requests to filters on the basis of the following criteria:

To specify these criteria, provide the following templates as options to the lpfilter command.
   Options: OUTPUT impress=-I, OUTPUT postscript=-P
If the Options: line becomes too long, put each template on a separate line, as follows:
   "Options: OUTPUT impress=-I"
   "Options: OUTPUT postscript=-P"
In both templates, the keyword is OUTPUT. In the first template, the value of pattern is impress and the value of the replacement is -I. In the second template, the value of pattern is postscript and the value of the replacement is -P.

Template keywords

The following 13 keywords are available for defining Options in a filter definition:

Keyword definitions and examples

Characteristic keyword Possible patterns Example
Content type (input) INPUT content-type troff
Content type (output) OUTPUT content-type postscript
Printer type TERM printer-type att495
Printer name PRINTER printer-name lp1
Character pitch CPI scaled-decimal 10
Line pitch LPI scaled-decimal 6
Page length LENGTH scaled-decimal 66
Page width WIDTH scaled-decimal 80
Pages to print PAGES page-list 1-5,13-20
Character set CHARSET character-set finnish
Form name FORM form-name invoice2
Number of copies COPIES integer 3
Special modes MODES mode landscape

To find out which values to supply for each type of template (that is, for the pattern and replacement arguments for each keyword), consider the following:

The replacement part of a template shows how the value of a template is given to the filter program. It is typically a literal option, sometimes with the place-holder * included to show where the value goes. The pattern and replacement can also use the regular expression syntax of ed(1) for more complex conversion of user input options into filter options. All of the regular expression syntax of ed(1) is supported, including the \( . . . \) and \n constructions, which can be used to extract portions of the pattern for copying into the replacement, and the &, which can be used to copy the entire pattern into the replacement.


NOTE: If a comma or an equal sign (=) is included in a pattern or a replacement, escape its special meaning by preceding it with a backslash (\). Note that some regular expressions include commas that will have to be escaped this way. A backslash in front of any of these characters is removed when the pattern or replacement is used.

The following examples show how this works.

Example: col filter

Suppose you already added a filter called col with the following definition:

   Input types:     N37, Nlp, simple
   Output types:    simple
   Command:         /usr/bin/col
   Options:         TERM 450 = -b, MODES expand = -x
   Options:         INPUT simple = -p -f


NOTE: If you provide more than one definition (that is, more than one line) for any filter characteristic other than Options, only the second definition will be used by the Print Service.

After you have ``registered'' this definition with the Print Service by entering it as input with the lpfilter command, users' print requests will be handled as follows:

Example: dpost filter

The filter program is called /usr/lib/lp/postscript/dpost. It takes one input type, troff, produces an output type called postscript and works with any printer of type PS (for PostScript). You've decided that your users need give just the abbreviations port and land when they ask for the paper orientation to be portrait mode and landscape mode, respectively. Because these options are not intrinsic to the print service, users must specify them using the -y option to the lp command.

The filter definition would look like this:

   Input types: troff
   Output types: postscript
   Printer types: PS
   Filter type: slow
   Command: /usr/lib/lp/postscript/dpost
   Options: LENGTH * = -l*
   Options: MODES portrait = -op, MODES land = -ol

A user submitting a file of type troff for printing on a PostScript printer (type PS), with requests for landscape orientation and a page length of 60 lines, would enter the following command:

lp -T troff -o length=60 -y land -d any

Then this filter would be invoked by the print service to convert the file as follows:

/usr/lib/lp/postscript/dpost -l60 -ol -pl

Example: option template

You add the following option template to the previous example:

   Options:  MODES group\=\([1-9]\) = -n\l
This template is used to convert a MODES option of the form

-y group=number

into filter options

-nnumber

So if a user gives the following command

lp -y group=4

the dpost command would include the following option:

-n4

For additional examples, run the command

/usr/sbin/lpfilter -f filter -l

where filter is the name of the factory-installed PostScript filters. (For a list of PostScript filters, see ``PostScript printers''.)


Next topic: Adding a filter to the print service
Previous topic: What programs make a good filter

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 22 April 2004