Configuration file Basics

Configuration files contain lines which are either comments, or keywords and their corresponding values.

Comments are assumed to be lines which start with '#'. Keywords are any sequence of alpha-numerics ( plus '_', '.', '-' ) followed by a comma, space or equals symbol. The remainder of the line (starting from the next alpha-numeric) is assumed to be the value associated with that keyword.

Programs which use the configuration sytem enquire of the value associated with a keyword. There are then routines which will interpret the value and return the result.

A value can be interpreted as:

The following is a more detailed description of these types.

A String

This is simply a string of characters, exactly as stored by the configuration system. Any structure that is required must be applied by the calling program.

An example would be:

    MY_NAME=Michael Caine


A Flag

The value associated with the keyword is checked and if it is TRUE, or ON, or YES then the value 1 is returned to the calling program. If the keyword value is not one of the above, or the keyword does not exist, then the value 0 is returned to the calling program.
    SCREAM_AT_MONSTER=YES


An Integer

The value associated with the keyword is converted to an integer which is returned to the calling routine. If the keyword does not exist, or the value is not numeric, then the value returned to the calling program is 0.
    NUMBER_OF_PROGRAMMERS_TO_CHANGE_LIGHT_BULB=5


A Floating Point Number

The value associated with the keyword is converted to an floating point number which is returned to the calling routine. If the keyword does not exist, or the value is not numeric, then the value returned to the calling program is 0.0 .
    PI=3.14159265


A Dynamic String

The value associated with the keyword is evaluated as if it were a shell variable. For example, if the configuration system contains
    LOGFILE=$HOME/logfile
and the environment has
    HOME=/home/me
the result of evaluating LOGFILE would be /home/me/logfile.

There are a couple of other variations which are associated with dynamic evaluation.

  1. If the value contains a '%' character, the following word is treated as a configuration keyword, and the value associated with the keyword is used in place of the keyword.
  2. If the original keyword is not found, a NULL string is returned, unless a default string is supplied, in which case that is evaluated as if it were the value associated with the keyword.
To illustrate;
If the configuration file contains:
    FORENAME=Leonardo
    SURNAME=Da Vinci
    TITLE=Mr.
    FULL_NAME=%TITLE %FORENAME %SURNAME
and the environment has
    HOME=/home/me
Then the results of evaluation are:
KEYWORD DEFAULT RESULT
FULL_NAME NULL Mr. Leonardo Da Vinci
LOGFILE NULL NULL
LOGFILE $HOME/logfile.%FORENAME /home/me/logfile.Leonardo

There is are a couple of additional modes which may be used with evaluated strings.

The first of these is the ability to bracket the word to be referenced. This is done by following the % or $ with either ( or { followed by the keyword, and then a corresponding closing brace character.

As an example,

    FORENAME=Harold

    FULL_NAME=%{FORENAME}123456

The second mode available is that of specifying that a word should be evaluated as a configuration file string (%) and if not present, to be evaluated as an environment string, or vice-versa. This is done simply by placing the two meta-characters one after the other in the required order. i.e.

    LOG_DIR=/var/tmp

    LOG_NAME=$%LOG_DIR/log_name
will attempt to use the value of $LOG_DIR, and if not present use that of %LOG_DIR.