#include <mplib1/cfg_file.h>
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/tmpand the configuration file contains
LOG_FILE=$LOG_DIR/mylogfile ERROR_FILE=$LOG_DIR/%(PROGNAME).err PROGNAME=kibolaterAmong the possible evaluations are:
eval_config_default( "LOG_FILE", "$LOGDIR/log.tmp" );gives
/var/log/mylogfileAnd
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.
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/logand that the configuration has
LOG_FILE=log_file.nowthe string returned by
eval_config_str( "$LOG_DIR/%LOG_FILE" );would be
/var/log/log_file.nowThe 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/logand the configuration has
LOG_FILE=$LOG_DIR/%LOG_UNIT/log_file.now LOG_UNIT=mylogdirthen 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.
This behavour can be inhibited by performing
set_config_flags( list_name, CONFIG_NO_EVAL );on the requisite list.