This is a library package (libDefaults) to maintain a set of configuration
values which are stored in files much like the ini settings used by
windows.

There are a number of key differences between the windows ini settings
mechanism and this implementation.

Windows ini files contain sections which can be used to group ini
settings.  There are no sections in libDefaults, however settings can be
grouped by hierarchy, in that directries are also part of the settings
database so that a section can be represented in a file of settings.
To illustrate this take the setting;

    /etc/defaults/customers/w/wigwam/accounts/account_no=W12345

account_no is a setting with a value, within the 'accounts' group (ini
file or section) and everything above is a directory (or set of
defaults).

Windows ini files may be located anywhere within the file system,
whereas libDefaults is limited to 3 distinct directory prefixes;

    /etc/defaults
    /usr/local/defaults
    ${HOME}/defaults

Windows has only one ini setting value whereas libDefaults has 3
distinct settings for the same value each of which have a preference.
Global settings have the lowest preference and reside in /etc/defaults.
Local settings have the next lowest preference and reside in
/usr/local/defaults.  User settings have the highest preference and
reside in ${HOME}/defaults.  Thus

    ${HOME}/defaults/syscontrol/monitor/colours/background=Blue
has preference over
    usr/local/defaults/syscontrol/monitor/colours/background=Green
which has preference over
    etc/defaults/syscontrol/monitor/colours/background=Black

So the value used will be Blue.

To get/set a settings you set values in a DfltsInfo structure and pass
it the interface routines.  For example the above would be;

    DfltsInfo   *di;

    di.group = "syscontrol/monitor/colours";
    di.tag = "background";
    di.base = ANY_DFLT_SET;

You can set default values that will be returned if the setting doesn't exist.

    di.val = "unknown"; /* for string settings */
    di.num = -1;        /* for integer settings */

This means that you must ensure the DfltsInfo structure is initialised to
null before use.

-------------------------------------

Installing the library

You might need to fiddle with V.h and Vport.h for you system.

type make to build the library and the test program

copy global_test_defaults to /etc/defaults/test
copy local_test_defaults to /usr/local/defaults/test
copy user_test_defaults to ${HOME}/defaults/test

then run the test program

The tag "test_int" is in both the global set and the user set, this
proves that USER defaults override LOCAL defaults which override GLOBAL
defaults.  If you have the same tag in these files then if the test
program specifies ANY set then it will find them in this order of
preference.

In your programs you would normally use ANY_DFLT_SET to indicate that
you don't care where the value comes from.  The it is a local
configuration issue so that a user can override certain values in their
own defaults settings.  There isn't much difference between LOCAL and
GLOBAL defaults but the intention is that local defaults would be used
by a site administrator to override values in global defaults which
would have been installed with the software.  This implies that software
developers should distribute a defaults file with instructions to
install it in /etc/defaults.

damian@cablenet.net
