|
|
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-listThe 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.
These names should either match the types of printers you have on your system or match the input types handled by other filters. The print service groups filters together in a shell pipeline if it finds that several passes by different filters are needed to convert a file. Try to find a set of filters that takes (as input types) all the different files your users may want printed and converts those files directly into types your printers can handle.
For example, you may have a printer that is given a single type for purposes of initialization (see the ``Printer types'' section), but which can recognize several different types of files. In essence, this printer has an internal filter that converts the various types into one with which it can handle. Thus, a filter may produce one of several output types that match the ``file types'' that the printer can handle. Mark filter as working with that printer type.
As another example, you may have two different models of printers that are listed as accepting the same types of files. However, due to slight differences in manufacture, one printer deviates in the results it produces. You label the printers as being of different printer types, say A and B, where B is the one that deviates. You create a filter that adjusts files to account for the deviation produced by printers of type B. Because this filter is needed only for those printer types, you list it as working only on type B printers.
For most printers and filters, you can leave this part of the filter definition blank.
In most cases, a filter works with all printers that accept its output, so you can usually skip this part of the filter definition.
Slow filters are filters that incur a lot of overhead in preparing a file and don't require access to a printer. The print service runs slow filters in the background, without tying up a printer. This allows files that don't need slow filtering to move ahead; printers will not be left idle while a slow filter works on a file if other files can be printed simultaneously.
Slow filters that are invoked by modes (via the -y option), must be run on the computer where the print request was issued. The print service can't pass values for modes to server machines. It can, however, match a file content type (specified after the -T option of the lp command) to a content type on a server machine. Therefore, to activate special modes on a server machine, you must specify content types that will allow the print service to match input types and output types.
There are 13 sources of information, each of which is represented by a ``keyword.'' Each option is defined in a ``template,'' a statement in the following format:
keyword pattern=replacementThis 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.''
The options specified in a filter definition may include none, all, or any subset of these 13 keywords. In addition, a single keyword may be defined more than once, if multiple definitions are required for a complete filter definition. See ``Defining options with templates''.
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.
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=replacementThis 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:
Options: OUTPUT impress=-I, OUTPUT postscript=-PIf 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.
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.
The following examples show how this works.
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
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:
the filter command will be run
with the following arguments:
/usr/bin/col -x -p -f
the filter command will be run
with the following arguments:
/usr/bin/col -x
Qualifier: The default printer is not of type 450.
the filter command will be run
with the following arguments:
/usr/bin/col -b -x
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
You add the following option template to the previous example:
Options: MODES group\=\([1-9]\) = -n\lThis template is used to convert a MODES option of the form
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''.)