libCfg Documentation


written by David Anderson and Joey Mukherjee -
joey@swri.org

Last updated: 05/10/2001 by Joey Mukherjee

Table of contents

  1. Overview
  2. Public Routines
    1. CfgInit
    2. CfgInitSCF
    3. CfgTerm
    4. CfgGetPath
    5. CfgGetItem

Overview

libCfg offers the interface into the DB.cfg and the PROJECTS.cfg file. The programmer need not know/care what file he is accessing since the interface to access either file is the same and the contents of both are rolled into one complex opaque data structure.

To use these routines, include "libCfg.h" into the source.

CfgInit

The prototype is as follows:

void CfgInit ();

CfgInit will read the contents of DB.cfg, PROJECTS.cfg, and sddas.cfg into memory. It returns nothing and accepts no arguments. In case of errors, error messages are printed to the console. The configuration is defined by the file $SDDAS_HOME/config/PROJECTS.cfg and $SDDAS_HOME/DB.cfg ($SDDAS_HOME is an environment variable). If the environment variable SDDAS_CONFIG exists then both configuration files PROJECTS.cfg and DB.cfg will be read from the path defined in this variable. If one of the files does not exist in SDDAS_CONFIG, it will use the one in $SDDAS_HOME/config.

You must call this routine if you wish to use the config files.

The sddas.cfg file is a new file which contains items which can be overridden by environment variables. The current way to set these variables is with the .sddasrc file, but as we move to new platforms, the sddas.cfg may take effect.

CfgInitSCF

The prototype is as follows:

void CfgInitSCF ();
Same as above, but this routine will also load SCF information into memory along with the config information. This is a new feature will incorporate SCF filenames into the hierarchy as they were part of the projects list. Most people do not need to call this routine regardless if they use SCF's.

CfgGetItem

The prototype is as follows:

char *CfgGetItem (char *token, int element_number, ...);

CfgItem takes a token to look for (i.e. "NetID"), and and element into the array of return values and a NULL terminated variable length hierarchy (i.e. you do not have to fully specify the hierarchy). It will return a pointer to the string value associated with the 'item'. There may be more than one string value, therefore the element number acts as an index into the array of string values.

The string returned is static - do not free it.

Example:


char *exe = CfgGetItem ("DataPromote", 0, "UARS", "UARS-1", NULL);

will return the value of DataPromote for the UARS-1 mission. If a value does not exist, it will return the value of UARS.DataPromote.VALUE. If this too does not exist, the default DataPromote.VALUE will be returned. See the database DB.cfg documention for more information.

CfgGetPath

The prototype is as follows:

char *CfgGetPath (char *path_requested, ...);

This routine is similar to CfgGetItem; however, it is used only for path names just as RealTimePath, PostTimePath, or DatabasePath. It takes as parameters the item to look for (i.e. "RealTimePath") and a NULL terminated variable length hierarchy. Certain path information is based on the parent name of the source. See the database DB.cfg documention for more information.

The string returned is static - do not free it.

CfgTerm

The prototype is as follows:

void CfgTerm ();

This routine accepts no arguments and returns nothing. It frees all memory associated with the config routines and should be called at the end of your program.