Filter

Top  Previous  Next

XSPOOL allows the possibility to process the file with a user-writted program, either before to store it in the repository or before to print it.

Pre-feeding filters

Print files may be processed by a filter program before they are stored in the repository. This kind of filtering allows to modify in permanent mode the print files: the result of the filtering process will be store in the repository and made available to the users.

This kind of filtering may be used to perform some changes on print file like, i.e., transforming characters from lower to upper case, to suppress blank line, to  transform ASA style printout into human-readable formats, etc.

This mode of filtering is activated by the "-f" option of xspooladd command.

Pre-printing filters

XSPOOL may invoke a filtering program before to process a file before to print it. This kind of filter does not modify the file stored in the repository, but simple changes what is delivered to the printing sub-systems.

Normally this kind of filter is used to adapt the file to the printer, adding specific print control characters.

The pre-printing filter is defined in the print class definition, that means that every single printer class may have its own private filtering program, like in the following sample:

#===========================================================================#
#   Destinations (printers or classes of printers)                          #
#===========================================================================#
[Class]
    id = CL01
    value = ijet
    description = InkJet Printer
    filter = /home/user/bin/ctrlchar_InkJet.sh
 
[Class]
    id = CLAB
    value = lasert
    description = Laser printer
    filter = /home/user/bin/ctrlchar_Laser.sh

Filter variable, if defined, contains the name (if it may be found in PATH) or the full path of an user-defined executable command.

Writing a filter

A Filter is an executable file, and they may be written in every programming or scripting language (C, Shell, Perl, etc). Their structure is quite easy:

read the input file
process the input
write the output

XSPOOL filters handle their I/O over the standard streams (STDIN/STDOUT). This means that XSPOOL will provide the input to the filter trough STDIN and it will retrieve the filter output on its STDOUT.

This is a sample of a filter that only translates from lower case to upper case:

#!/bin/sh
#
# script: filter.sh
# usage: filter.sh < INPUT_FILE > OUTPUT_FILE
#
 
tr '[a-z]' '[A-Z]'

 

If the environment variable XSPOOLADD_FILTER_BY_ARGUMENTS is set to YES, XSPOOL invokes the pre-feeding filters providing the input file name as first command line argument and the output file name as the second one. In this case the sample above would be coded as follows:

#!/bin/sh
#
# script: filter.sh
# usage: filter.sh INPUT_FILE OUTPUT_FILE
#
 
tr '[a-z]' '[A-Z]' < $1 > $2