Index: trunk/psModules/src/config/pmConfig.c
===================================================================
--- trunk/psModules/src/config/pmConfig.c	(revision 5355)
+++ trunk/psModules/src/config/pmConfig.c	(revision 5356)
@@ -3,6 +3,6 @@
  *  @author PAP, IfA
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-10-17 21:34:12 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-17 23:37:11 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -13,10 +13,9 @@
 #include <assert.h>
 #include "pslib.h"
-#include "psAdditionals.h"
+//#include "psAdditionals.h"
 #include "pmConfig.h"
 
-// XXX: These comments should have PS-specific prefixes.
-#define PS_SITE "PS_SITE"  // Name of the environment variable containing the site config file
-#define DEFAULT_SITE "ipprc.config" // Default site config file
+#define PS_SITE "PS_SITE"               // Name of the environment variable containing the site config file
+#define PS_DEFAULT_SITE "ipprc.config"     // Default site config file
 
 
@@ -41,16 +40,24 @@
                  description, name);
     }
-    if (! *config) {
+    if (!*config) {
         psError(PS_ERR_IO, false, "Unable to read %s configuration from %s\n",
                 description, name);
         return false;
     }
+
     return true;
 }
 
 
-
+/******************************************************************************
+pmConfigRead(**site, **camera, **recipe, *argc, **argv, char *recipeName)
+ 
+XXX: The log/trace command line options (as processed by psArgumentVerbosity)
+must take precedence override the values set here.  This must be, somehow,
+coded.
+ *****************************************************************************/
 bool pmConfigRead(
-    psMetadata **site, psMetadata **camera,
+    psMetadata **site,
+    psMetadata **camera,
     psMetadata **recipe,
     int *argc,
@@ -76,7 +83,12 @@
     // First, try command line
     //
-    int argNum = 0;
-    if ((argNum = psArgumentGet(*argc, argv, "-site"))) {
-        (void)psArgumentRemove(argNum, argc, argv);
+    psS32 argNum = psArgumentGet(*argc, argv, "-site");
+    if (argNum != 0) {
+        //
+        // We remove the "-site" argument from argv.  Then
+        // we look for the next argument, which should be the filename, and
+        // remove it as well.
+        //
+        psArgumentRemove(argNum, argc, argv);
         if (argNum >= *argc) {
             psLogMsg(__func__, PS_LOG_WARN,
@@ -84,12 +96,11 @@
         } else {
             siteName = argv[argNum];
-            (void)psArgumentRemove(argNum, argc, argv);
-        }
-    }
-
+            psArgumentRemove(argNum, argc, argv);
+        }
+    }
     //
     // Next, try environment variable
     //
-    if (! siteName) {
+    if (!siteName) {
         siteName = getenv(PS_SITE);
     }
@@ -99,68 +110,87 @@
     //
     bool cleanupSiteName = false; // Do I have to psFree siteName?
-    if (! siteName) {
-        siteName = psStringCopy(DEFAULT_SITE);
+    if (!siteName) {
+        siteName = psStringCopy(PS_DEFAULT_SITE);
         cleanupSiteName = true;
     }
 
-    if (! readConfig(site, siteName, "site")) {
-        if (cleanupSiteName) {
-            psFree(siteName);
-        }
+    //
+    // We have the connfiguration filename; now we read and parse the config
+    // file and store in psMetadata struct site.
+    //
+    if (!readConfig(site, siteName, "site")) {
         return false;
     }
-
-
-    //
-    // Next is the camera configuration
-    //
-    if ((argNum = psArgumentGet(*argc, argv, "-camera"))) {
-        (void)psArgumentRemove(argNum, argc, argv);
+    if (cleanupSiteName) {
+        psFree(siteName);
+    }
+
+
+    //
+    // Next, we do a similar thing for the recipe configuration file.  The
+    // file is read and parsed into psMetadata struct "recipe".
+    //
+    //
+    argNum = psArgumentGet(*argc, argv, "-recipe");
+    if (argNum > 0) {
+        psArgumentRemove(argNum, argc, argv);
+        if (argNum >= *argc) {
+            psLogMsg(__func__, PS_LOG_WARN,
+                     "-recipe command-line switch provided without the required filename --- ignored.\n");
+        } else {
+            psArgumentRemove(argNum, argc, argv);
+            readConfig(recipe, argv[argNum], "recipe");
+        }
+    }
+    // Or, load the recipe from the camera file, if appropriate
+    if (! *recipe && *camera && recipeName) {
+        *recipe = pmConfigRecipeFromCamera(*camera, recipeName);
+    }
+
+
+    //
+    // Next, we do a similar thing for the camera configuration file.  The
+    // file is read and parsed into psMetadata struct "camera".
+    //
+    argNum = psArgumentGet(*argc, argv, "-camera");
+    if (argNum > 0) {
+        psArgumentRemove(argNum, argc, argv);
         if (argNum >= *argc) {
             psLogMsg(__func__, PS_LOG_WARN,
                      "-camera command-line switch provided without the required filename --- ignored.\n");
         } else {
-            (void)psArgumentRemove(argNum, argc, argv);
-            (void)readConfig(camera, argv[argNum], "camera");
-        }
-    }
-
-    //
-    // And then the recipe configuration
-    //
-    if ((argNum = psArgumentGet(*argc, argv, "-recipe"))) {
-        (void)psArgumentRemove(argNum, argc, argv);
-        if (argNum >= *argc) {
-            psLogMsg(__func__, PS_LOG_WARN,
-                     "-recipe command-line switch provided without the required filename --- ignored.\n");
-        } else {
-            (void)psArgumentRemove(argNum, argc, argv);
-            (void)readConfig(recipe, argv[argNum], "recipe");
-        }
-    }
-    // Or, load the recipe from the camera file, if appropriate
-    if (! *recipe && *camera && recipeName) {
-        *recipe = pmConfigRecipeFromCamera(*camera, recipeName);
-    }
-
-
-    //
-    // Now we can look into the site configuration and do the required stuff
+            psArgumentRemove(argNum, argc, argv);
+            readConfig(camera, argv[argNum], "camera");
+        }
+    } else {
+        // XXX: Not sure is this is correct.
+        *camera = NULL;
+    }
+
+
+    //
+    // We now have the config, camera, and recipe files parsed and stored in
+    // metadata.  Now, we can look into the site configuration and do
+    // the required stuff.
     //
     bool mdok = true;   // Status of MD lookup result
-    psString timeName = psMetadataLookupString(&mdok, *site, "TIME"); // Name of time file
+
+    //
+    // If TIME is specified in the configuration file, then we must initialize
+    // with a call to psTimeInitialize.
+    //
+    psString timeName = psMetadataLookupStr(&mdok, *site, "TIME");
     if (mdok && timeName) {
         psTrace(__func__, 7, "Initialising psTime with file %s\n", timeName);
-        #ifdef PRODUCTION
-
+        // XXX: PAP had a call to psLibInit is PRODUCTION not set.  Why?
         psTimeInitialize(timeName);
-        #else
-
-        psLibInit(timeName);
-        #endif
-
-    }
-
-    int logLevel = psMetadataLookupS32(&mdok, *site, "LOGLEVEL"); // Logging level
+    }
+
+
+    //
+    // If LOGLEVEL is specified in the configuration file, then we must initialize
+    // with a call to psLogSetLevel().
+    //
+    int logLevel = psMetadataLookupS32(&mdok, *site, "LOGLEVEL");
     if (mdok && logLevel >= 0) {
         psTrace(__func__, 7, "Setting log level to %d\n", logLevel);
@@ -168,5 +198,10 @@
     }
 
-    psString logFormat = psMetadataLookupString(&mdok, *site, "LOGLEVEL"); // Log format
+
+    //
+    // If LOGFORMAT is specified in the configuration file, then we must initialize
+    // with a call to psLogSetFormat().
+    //
+    psString logFormat = psMetadataLookupStr(&mdok, *site, "LOGFORMAT");
     if (mdok && logFormat) {
         psTrace(__func__, 7, "Setting log format to %s\n", logFormat);
@@ -174,8 +209,14 @@
     }
 
-    psString logDest = psMetadataLookupString(&mdok, *site, "LOGDEST"); // Log destination
+
+    //
+    // If LOGDEST is specified in the configuration file, then we must initialize
+    // with a call to psLogSetDestination().
+    // XXX: This is not spec'ed in the SDRS.
+    //
+    psString logDest = psMetadataLookupStr(&mdok, *site, "LOGDEST");
     if (mdok && logDest) {
-        // XXX: Only stdout is provided for now; this section should be expanded in the future to do files,
-        // and perhaps even sockets.
+        // XXX: Only stdout is provided for now; this section should be
+        // expanded in the future to do files, and perhaps even sockets.
         if (strcasecmp(logDest, "STDOUT") != 0) {
             psLogMsg(__func__, PS_LOG_WARN, "Only STDOUT is currently supported as a log destination.\n");
@@ -186,5 +227,11 @@
     }
 
-    psMetadata *trace = psMetadataLookupMD(&mdok, *site, "TRACE"); // Trace levels
+
+    //
+    // If TRACE is specified in the configuration file, then we must initialize
+    // with a call to psTraceSetLevel().
+    // XXX: This is not spec'ed in the SDRS.
+    //
+    psMetadata *trace = psMetadataLookupMD(&mdok, *site, "TRACE");
     if (mdok && trace) {
         psMetadataIterator *traceIter = psMetadataIteratorAlloc(trace, PS_LIST_HEAD, NULL); // Iterator
@@ -197,13 +244,10 @@
             }
             psTrace(__func__, 7, "Setting trace level for %s to %d\n", traceItem->name, traceItem->data.S32);
-            (void)psTraceSetLevel(traceItem->name, traceItem->data.S32);
+            psTraceSetLevel(traceItem->name, traceItem->data.S32);
         }
         psFree(traceIter);
     }
 
-    if (cleanupSiteName) {
-        psFree(siteName);
-    }
-    return true;
+    return(true);
 }
 
@@ -213,5 +257,5 @@
 {
     // Read the rule for that camera
-    bool mdStatus = true;  // Status of MD lookup
+    bool mdStatus = true;
     psMetadata *rule = psMetadataLookupMD(&mdStatus, camera, "RULE");
     if (! mdStatus || ! rule) {
@@ -276,7 +320,6 @@
 
 
-// Work out what camera we have, based on the FITS header and a set of rules specified in the IPP
-// configuration; return the camera configuration
-
+// Work out what camera we have, based on the FITS header and a set of
+// rules specified in the IPP configuration; return the camera configuration
 psMetadata *pmConfigCameraFromHeader(
     const psMetadata *ipprc,            // The IPP configuration
@@ -289,10 +332,10 @@
         return NULL;
     }
-
-    psMetadata *winner = NULL;       // The camera configuration whose rule first matches the supplied header
-
+    psMetadata *winner = NULL;       // The camera configuration whose rule first matches
+    //  the supplied header
     // Iterate over the cameras
-    psMetadataIterator *iterator = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, NULL); // MD Iterator
+    psMetadataIterator *iterator = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, NULL);
     psMetadataItem *cameraItem = NULL; // Item from the metadata
+
     while ((cameraItem = psMetadataGetAndIncrement(iterator))) {
         // Open the camera information
@@ -355,5 +398,5 @@
         psLogMsg(__func__, PS_LOG_WARN, "RECIPES in the camera configuration file is not of type METADATA\n");
     } else {
-        psString recipeFileName = psMetadataLookupString(&mdok, recipes, recipeName);
+        psString recipeFileName = psMetadataLookupStr(&mdok, recipes, recipeName);
         (void)readConfig(&recipe, recipeFileName, "recipe");
     }
