#include <mplib1/cfg_file.h>
The configuration file routines can be used in a number of ways. The
most obvious example is signalling whether to output debugging
information. So, suppose we have a routine which we are writing which
looks up an employee name for a given an employee ID.
get_emp_name( int emp_id, char *emp_name )
{
int get_emp_name_debug,rv;
*emp_name='\0';
get_emp_name_debug = get_config_flag("GET_EMP_NAME_DEBUG");
if (get_emp_name_debug)
fprintfile(stderr,"get_emp_name: entry: id=%d\n", emp_id );
.... do fetch ....
if (get_emp_name_debug)
{
if (rv==FAIL)
fprintfile(stderr,"get_emp_name: failed\n" );
else
fprintfile(stderr,"get_emp_name: name=<%s>\n", emp_name );
}
return(rv);
}
So, instead of making the debug portion compile conditional which
leads to a different set of code being produced for production than
that tested, the same routine goes to production. Since the default
for a flag variable is false the debug output is suppressed until
a configuration variable is provided which changes the value.
Another example would be to determine the name of a logfile.
char *logname;
FILE *log_fh;
logname = eval_config_default( "LOGFILE_NAME", "$LOG_DIR/progname.log" );
log_fh = fopen( logname, "a" );
if (log_fh)
fprintfile( log_fh, "logfile %s opened\n", logname );
Where progname is replaced with the name of the program
being developed.