Next Previous Contents

7. Configuration Files

Run time options are provided by the command line arguments and values in the configuration files. By convention, the configuration files are named ifhp.conf.

In order to provide a flexible run time configuration facility, the location of the configuration files is specifed as follows.

  1. The default list of configuration files is:
    ./ifhp.conf,/etc/ifhp.conf,./ifhp.conf
  2. The command line option
    -Tconfig=/path,/path,...
    can be used to override the default list of configuration files.

Here is a section of a simple configuration file.

# languages
pcl
statusfile=status
status
sync=pcl
sync_interval=20
# we force pagecounting off
#pagecount=pcl
pagecount@
[ HP4Si ]
status@
end
[ HP5Si ]
pjl
sync=pjl

The configuration file is used to set flags, option values, and to cause various ifhp actions. The file has the following structure.

  1. Blank lines and lines starting with # are ignored.
  2. Keys or flags start in column 1. The syntax is similar to the LPRng and BSD file.
    Syntax             Equivalent To    Class
    flag               flag=1           (FLAG)
    flag@       flag=0           (FLAG)
    flag=val           flag=val (string value) STRING
    flag=] v v  ... [          LIST
    
  3. Flags are used for options which take a TRUE/FALSE, 0/1, or ON/OFF value, and ifhp will substitute the appropriate form or perform the assocated action if the flag is TRUE.
  4. Strings are used to set options which require a multicharacter value. The special form flag@ is used to indicate that the operation related to this option is not to be performed.
  5. Lists are used to specify a list of options which can be flags or string values. Lists have the property of recursive evaluation which means that the individual items in the list will be acted upon in order. This is discussed later in detail.
  6. The list entries are separated by whitespace, and each entry can have the form v, v@, v=word, or v1#word, where word does not contain whitespace or the [] characters.
  7. Flag values can be spread over multiple lines. Lines starting with whitespace, are treated as a continuation of the previous flags line value. For example:
    # set string x value 'first\n  second\n  third'
    x= first
      second
      third
    # set list y value [ f1 f2 ]
    y=[ f1
     f2 ]
    
  8. Selection lines have the form:
    [ glob glob ... ]
    

    Selection lines divide the configuration file into sections corresponding to a particular printer model. Configuration information is extracted from a file until either an 'end' line or a selection line is encountered.

  9. An 'end' line consisting of the single work 'end' will terminate reading lines from a configuration file.
  10. As the configuration file is read, flag lines and values are accumulated. Later values encountered in the file will replace earlier values.

7.1 Configuration Selection

The recommended format for a configuration file is to put common (default) flag settings at the start of the configuration file, followed by selection sections with overridding and additional flag values.

To allow a single file to be used for multiple printer configurations, you can specify that a section of the file is to be used ONLY by a various models of printers. This is is controlled by the value of the 'model' flag and selection lines of the form:

  [ glob glob ... ]

The first occurrence of a 'model=xx' line in either the -T options or the configuration file will set the model flag value to 'xx'.

The 'model' value is matched against the modelglob values using GLOB matching. For example:

hp*      matches hp4 hp5x
hp[45]   matches hp4 hp5, but not hp5x
hp[3-6]* matches hp3, hp5, hp5x, but not hpiii

If a matching entry is found, successive lines will be used until either another selection line or an 'end' line is encountered. An 'end' line will terminate reading the current file, and the next configuration file will be read.

The default list of configuration files is:

ifhp.conf, /etc/ifhp.conf, ifhp.conf

This arrangement allows you to read the ifhp.conf file to get various model settings, scan the /etc/ifhp.conf file to get the generic ones, and then to rescan the local ifhp.conf file to provide overrides to values set in the /etc/ifhp.conf file.

7.2 Option Use

Options and their values are used to control printer operation. There are two types of options: those with a predefined or builtin meaning to the ifhp filter and those which are simply used to supply values for expansion during operation.

The builtin options are listed in later sections, and their use is explained. These options can have flag, string, or list values as is appropriate to their corresponding actions.

7.3 Recursive List Expansion

During normal operation, the ifhp filter will perform an operation by producing a set of strings which will be sent to the printer or output device. These strings may be obtained by using the values of predefined or builtin option names, or by expanding a LIST value.

A LIST value has the form X=[ v1 v2 ... ]. When a list value is expanded each of v1, v2 is examined in turn and the corresponding action or string substitution or builtin evaluation is carried out. If v1 has a string value and is not recognized as a builtin or special option then normally the string value will be used.

t1=[ p1 p2 p3=end ]
p1=this is
p2=[ p3 p4 ]
p3=a
p4=test
p3=living\020\%{p3}

For example, when expanding t1 each of p1 and p1 is in turn expanded. This will produce the strings "this is", "a", "test" and "living end" in turn.

Some LIST variables are used in printer language specific contexts and their values are processed appropriately. For example, pjl_init=[...] specifies a set of operations to be carried out for printers that support PJL, and pcl_init=[...] for PCL printers. The expansion of the LIST entries is done in the language specific context. For PJL this requires that the output be well formed PJL commands, and for PCL that all whitespace be removed.

The context dependent expansion is required because sometimes it is necessary to do operations both using PJL and PCL or PJL and PS combinations to ensure correct printer operation. For this reason, during expansion the language name and an underscore is prefixed to the list entry name, and this is used as the option name during the search.

For example, suppose that we have:

    pjl_init=[ test ]
    pcl_init=[ test ]
    initstr=NO
    pjl_initstr=@PJL ECHO YES
    pcl_initstr=\033(*yeS

When PJL initialization is done, the 'pjl_test' LIST will be expanded, and the PJL string '@PJL ECHO YES' will obtained. When PCL language specific processing is done, then the \033(*yeS string will be obtained.

7.4 String Expansion

String values are encoded using a simple PERL/C language like method. The \ (escape) character introduces a replacement string. This has the form:

Standard Character Replacement

\f \r \n \t \nnn where nnn are 3 octal digits are replaced by the standard PERL or C character substutions.

Option Value Replacement

\%format{option} \%format[option]

The option name will be relaced by the formatted option value.

Option Search Order

The option value is located using a simple set of rules.

  1. During a recursive option evaluation, expanding option=word will push the option=word combination onto an evaluation stack. This stack is searched in oldest to newest order for a match.
  2. If no match was found, and the expression has the form {option} then the -Zoption=value command line options will be searched for a match.
  3. If no match was found, then the -Toption=value command line options will be searched for a match. This allows the {option} to start searching from the -Z command line options and [option] to start searching from the -T command line options.
  4. If no match was found, then the configuration information is searched.
  5. If no match was found, then the value is considered undefined, and a "0" value is used.
Format

The format specifies how the value is to appear, and is similar to the printf format usage:

   %[-][0][length[.precision]][format]

The default format is %d, ie, \%{val} would be \%d{val}. The numerical formats supported are: %d, %o, %x, %X, %e, %f, and %g; The %s format use the option string value.

The format is usually not required, except when fractional values of point sizes or string substition rather than numerical substition is required.

For example:

Configuration:
  pjl_user_opts=[ ... outbin intray ...]
  pjl_outbin=@PJL SET OUTBIN=\%s{outbin}
  intraynum=4
  pjl_intray=@PJL SET INTRAY=\%{intraynum}

Command:
  ifhp -Zoutbin=LEFT

During PJL language processing, the -Z command line options will be scanned for options which appear in the pjl_user_opts list. The -Toutbin=LEFT option will be found and will be expanded in the PJL context by prefixing pjl_ and looking for a string or list value. The pjl_outbin option will be found, and the @PJL SET OUTBIN=\%s{outbin} string will be expanded.

Now we need to search for the outbin value. We first search for it on the evaluation stack, but there is nothing there yet. We then search the -Z options and find the outbin value, and substition yields @PJL SET OUTBIN=LEFT.

Next, the intray option is found and pjl_intray is expanded, which needs a value for intraynum. This is found in the configuration information, and finally in @PJL SET INTRAY=4.

cpi=5.5
pcl_cpi=\033\%3.2f{cpi}D

During PCL option expansion, we might need to expand the pcl_cpi option. When the pcl_cpi=\033\%3.2f{cpi}D string is expanded, the result is \033\%5.00D. If the user has specified -Tcpi=9 on the command line then the result is \033\%9.00D.

7.5 Language Context

The Tifhp filter sends initialization and configuration commands to the printer. Depending on the language, these commands have specific forms and requirements. Rather than requiring the user to remember the details, Tifhp uses the following conventions.

PJL Language

A PJL command has the form @PJL OPCODE .... A command must start with @PJL and consist of a single string value. You cannot patch together options to make a single PJL command.

  1. Before sending any PJL command to the printer, the PJL Universal Exit Command (\033%-12345X) string is sent to the printer.
  2. Because not all printers support all PJL commands, the Tifhp filter performs a couple of checks using the pjl_only and pjl_except configuration options. The OPCODE must appear in the pjl_only list and not in the pjl_except list.
  3. Leading and trailing whitespace is removed, and all characters are converted to uppercase.
  4. Individual commands have a newline (\n) appended to them before being sent to the printer.

PCL Lanaguage

When sending PCL initialization strings to a printer, it is essential to send nothing that could cause a printable character to be sent before the actual file contents. Such output could cause the location and positioning of text to be altered in unexpected ways. To avoid this, the following steps are taken when processing PCL strings.

  1. Before any PCL string is sent to the printer, the PCL End of Job (\033E) string is sent to the printer.
  2. First, all whitespace (blanks, tabs, etc) are removed from the string value.
  3. Next, all escaped values are substituted. At this point you can force printable strings containing whitespace into the output by using the \nnn escape mechanism.

PostScript Language

The PostScript language processing is very minimal, as there are few problems sending PostScript to a printer.

  1. Before sending any PostScript initialization strings, the PostScript End of Job indicator (\004 or Control-D) is sent.
  2. Strings are then expanded and the escape sequences are substituted.
  3. Individual strings have a newline (\n) appended to them before being sent to the printer.

Next Previous Contents