Configuration File Basics
Most programs in this suite use a common set of routines to read
and interrogate configuration files. These configuration files
contain named variables and their corresponding values.
The routines then provide various ways of interpreting the value.
Files contains lines which are either comments, or variable names
and their corresponding values.
Comments are assumed to be lines which start with '#'.
Vaiables 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
variable.
Programs which use the configuration system enquire of the value
associated with a variable. There are then routines which will
interpret the value and return the result.
A value can be interpreted as:
There now follows 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 variable is checked and if it
is TRUE, or ON, or YES then the value
1 is returned to the calling program. If the variable value is not
one of the above, or the variable does not exist, then the value
0 is returned to the calling program.
SCREAM_AT_MONSTER=YES
An Integer
The value associated with the variable is converted to an integer
which is returned to the calling routine. If the variable 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 variable is converted to an floating point number
which is returned to the calling routine. If the variable 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 variable 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.
- If the value contains a '%' character, the following word
is treated as a configuration variable, and the value associated with the
variable is used in place of the variable.
- If the original variable 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 variable.
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:
VARIABLE DEFAULT RESULT
FULL_NAME NULL Mr. Leonardo Da Vinci
LOGFILE NULL NULL
LOGFILE $HOME/logfile.%FORENAME /home/me/logfile.Leonardo