Infrasctucture Cfg Function Reference

Cfg
The cfg (confiuration) layer reads a text file to configure a process or system of processes.    There are two ways to automatically initialize the configurable variables in a program: dynamically and specifically.    The dynamic initialization method is the most powerful since it allows not only initialization from the config file, but also dynamic loading from the cfgCache (configuration cache) server and by an event message, and modification via the infrastrucure control tool.    Dynamic variables are always strings and may be access directly from your 'C' code by using the variable name as if it was defined as a char*.    In order to use this feature, you must:
include "inf.h"
Insert one or more lines like //~VARS Var1 Var2 VAR3l
If the current C file is named xxx.c: #include "xxxVars.c".
   Be sure that makefile runs varCfg.pl on all .c files which creates the xxxVars.c files.   

During the initialization phase of your program and after infInit(), run: caGetCfg( ProgNam ); (you may rerun it at anytime).    Now you may reference Var1 or any of the others from anywhere in your C code just as if you had defined: static char *Var1; at the beginning of your code.   

   Using the specific initialization the programmer can build a table (see CFG_xxx macros below) using macros which will directly associate keywords in the config file and place their associated values into program variables for use at run-time.    The infCtl tool can change these same variables dynamically in real-time.

cfAllEnv     cfDfltCfg     cfGetEnv     cfGetVar     cfInit     cfPutEnv    
CFG_BGN     CFG_INT     CFG_STR     CFG_FUN     CFG_FLG     CFG_END    
CFG_REG    

int  cfAllEnv( char* name, char* arg )
Allows viewing of all infrastructure's environment variables. If the "name" argument points to a NULL string, the internal pointer is set to the beginning of the environment table. The variable and it's value ("name=value") will be copied to the output buffer. Following calls will sequentially proceed through all environment variables. Returns OK if found a valid environment variable, else NOTFND.

int  cfDfltCfg( char* fileName )
Set the default config file name so no config must be supplied on the command line.

char*  cfGetEnv( char* name, char* barf )
Get an infrastructure environment variable. If name is not found in the infrastructure cache, the UNIX environment is queried.

int  cfGetVar( char* out, char* varNam )
Get the named (varNam) infrastructure configuration variable.    If name is not found in the registered variable tables, return NOTFND, else return character count of output.

int  cfInit( int argc, char** argv )
Causes the config module to locate, open, and read the configuration file, searching registered config variables performing the required functions. All Name Value pairs found in the config file that do not match any registered names will be placed in the infrastructure environment. cfInit is calle from infInit().

int  cfPutEnv( char* format, elipsis )
After formatting, the result is placed in the infrastructure's environment. The result of the formatting must be in the form: "name=value".

int  CFG_BGN( char* modName )
Creates a table of configuration structures, called "CfgTbl". You must call CFG_REG in your init function for this to be registered.

int  CFG_INT( char* keyword, int* variable )
When the keyword is matched (found) in the configuration file, it's following argument is evaluated and the result placed in the named integer variable.

int  CFG_STR( char* keyword, char* variable )
When the keyword is matched (found) in the configuration file, it's following argument string is duplicated and a pointer to this new string is placed in the named char pointer.

int  CFG_FUN( char* keyword, int function, void* argument )
When the keyword is matched (found) in the configuration file, it's following string argument is passed to the supplied function as a calling argument.

int  CFG_FLG( char* keyword, char* variable, int value )
When the keyword is matched (found) in the configuration file, the supplied value is placed in the named character variable.

int  CFG_END( )
Terminates the CfgTbl array.

int  CFG_REG( )
Placed in initialization code, this registers the CfgTbl so that when the config file is read, the registered keywords will be active.