#ident "$URL: svn://elmer/devel/SVN/SDDAS/trunk/libCfg/CfgInit.c $ %D% SwRI" #include #include #include #define _CfgInit_ #include "ant.h" /* needed for InitSDDASCfg and FreeSDDASCfg */ #include "libCfg.h" #include "libCfg_local.h" /* * Initialize the Projects tree by reading the file defined by the variable * PROJECTScfg (in libCfg.h). Also read information to be stored at various * nodes of the tree defined by the routine DB_Config() */ char *GetGoodPath (char *fileName) { static char path [256]; char *config; short GoodPath; GoodPath = 0; if ((config = getenv("SDDAS_CONFIG")) != NULL) { snprintf(path, sizeof (path), "%s/%s", config, fileName); if (access(path, R_OK) != 0) fprintf(stderr, "Defaulting to $SDDAS_HOME for %s.\n", fileName); else GoodPath = 1; } if (!GoodPath && (config = getenv("SDDAS_HOME")) != NULL) { snprintf(path, sizeof (path), "%s/config/%s", config, fileName); if (access(path, R_OK) == 0) GoodPath = 1; } if (!GoodPath) return NULL; return path; } void CfgInit() { char *path; if (Projects == 0x0) { /* This is a non fatal error! */ /* Must be before reading the DB.cfg file because we want to use the values in this file for expanding environment variables used in that file */ path = GetGoodPath ("sddas.cfg"); if (path != NULL) { InitSDDASCfg (path); } path = GetGoodPath (PROJECTScfg); if (path == NULL) { fprintf (stderr, "Cannot read PROJECTS configuration [NULL]\nIs SDDAS_HOME set?\n"); exit (2); } Projects = (LinkList)P_Config(path); path = GetGoodPath (ITEMcfg); if (path == NULL) { fprintf (stderr, "Cannot read DB configuration [%s]\n", path); exit (2); } DB_Config(path, Projects); } }