Configuration file routines - Evaluation

    #include <mplib1/cfg_file.h>


eval_private_default

    char *eval_private_default( const char *list_name,
				const char *config_name,
				const char *def_name );

    #define eval_config_default(cfg,def) eval_private_default( NULL, cfg, def )
This function checks whether a given config keyword exists. If it does, the value is passed to eval_private_str() and a pointer to the result is returned to the caller. If the keyword does not exist, the def_name parameter is passed to eval_private_str() instead, and the result returned to the caller.

So, when the environment contains

    LOG_DIR=/var/log
    TMPDIR=/var/tmp
and the configuration file contains
    LOG_FILE=$LOG_DIR/mylogfile
    ERROR_FILE=$LOG_DIR/%(PROGNAME).err
    PROGNAME=kibolater
Among the possible evaluations are:
    eval_config_default( "LOG_FILE", "$LOGDIR/log.tmp" );
gives
    /var/log/mylogfile
And
    eval_config_default( "ERROR_FILE", "$TMPDIR/error_file" );
gives
    /var/log/kibolater.err

Note that it is only environment variables and configuration variables in the initial value or default that are expanded.


eval_private_str

    char *eval_private_str( const char *list_name, const char *value );

    #define eval_config_str(from) eval_private_str( NULL, from )
This function returns a pointer to string which is the result of expanding any components of the supplied value which refer to environment variables or configuration variables in the supplied list.

This is best illustrated by considering the following example.

Suppose the environment contains

    LOG_DIR=/var/log
and that the configuration has
    LOG_FILE=log_file.now
the string returned by
    eval_config_str( "$LOG_DIR/%LOG_FILE" );
would be
	/var/log/log_file.now
The config value may contain multiple environment variables, or none at all.

In addition, a '%' character followed by a variable name is assumed to refer to another configuration value, and is also evaluated.
So, if the environment has

    LOG_DIR=/var/log
and the configuration has
    LOG_FILE=$LOG_DIR/%LOG_UNIT/log_file.now
    LOG_UNIT=mylogdir
then the string returned by
    eval_config_str( "LOG_FILE" );
would be
	/var/log/mylogdir/log_file.now

There is a further variation which can be used. Any '$' or '%' character may be followed by the other character (preceding the variable name). In this case, if the variable is not found in the first location, it is searched for in the second.

To produce a '$' or '%' in an evaluated string the character should be doubled. Therefore '$$' produces '$' and '%%' produces '%'.

No nested evaluatiuon takes place in an effort to avoid looped contructs.

Note:

By default, evaluation of config variables will produce a result which will be stored in a malloced buffer which will be stored against the variable in case it is needed again. These stored evaluations will be freed any time an item is added to the list, or a value is changed.

This behavour can be inhibited by performing

    set_config_flags( list_name, CONFIG_NO_EVAL );
on the requisite list.