Index: /branches/eam_branch_20080430/psLib/src/types/psMetadataConfig.c
===================================================================
--- /branches/eam_branch_20080430/psLib/src/types/psMetadataConfig.c	(revision 17506)
+++ /branches/eam_branch_20080430/psLib/src/types/psMetadataConfig.c	(revision 17507)
@@ -11,6 +11,6 @@
 *  @author Joshua Hoblitt, University of Hawaii 2006-2007
 *
-*  @version $Revision: 1.142.8.2 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2008-05-02 00:10:43 $
+*  @version $Revision: 1.142.8.3 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2008-05-04 23:40:26 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -63,26 +63,26 @@
 /*****************************************************************************/
 
-static psMetadata* genTypeTemplate(char *linePtr);
-static psMetadata* parseTypeValues(psMetadata* template, char* linePtr)
+static psMetadata *genTypeTemplate(char *linePtr);
+static psMetadata *parseTypeValues(psMetadata *template, char *linePtr)
 ;
-static bool parseLine(psArray* levelArray,
-                      char* linePtr,
+static bool parseLine(psArray *levelArray,
+                      char *linePtr,
                       bool overwrite,
                       bool *notBlank);
-static bool parseMetadataItem(char* keyName, psArray* levelArray,
-                              char* linePtr, psMetadataFlags flags);
+static bool parseMetadataItem(char *keyName, psArray *levelArray,
+                              char *linePtr, psMetadataFlags flags);
 static psString formatMetadataItem(psMetadataItem *item);
 static psArray *p_psMetadataKeyArray(psMetadata *md);
-static bool parseGeneric(char* keyName,
-                         psArray* levelArray,
-                         char* linePtr,
+static bool parseGeneric(char *keyName,
+                         psArray *levelArray,
+                         char *linePtr,
                          psMetadataFlags flags);
-static bool parseType(char* keyName,
-                      psArray* levelArray,
-                      char* linePtr,
+static bool parseType(char *keyName,
+                      psArray *levelArray,
+                      char *linePtr,
                       psMetadataFlags flags);
-static bool parseMetadataEnd(char* keyName,
-                             psArray* levelArray,
-                             char* linePtr,
+static bool parseMetadataEnd(char *keyName,
+                             psArray *levelArray,
+                             char *linePtr,
                              psMetadataFlags flags);
 
@@ -92,11 +92,11 @@
 typedef struct
 {
-    psArray*    nonUniqueKeyArray;      ///< non-unique key names
-    psHash*     typeTemplates;          ///< hash of user type templates
-    psMetadata* metadata;               ///< metadata container
+    psArray *   nonUniqueKeyArray;      ///< non-unique key names
+    psHash *    typeTemplates;          ///< hash of user type templates
+    psMetadata *metadata;               ///< metadata container
 }
 p_psParseLevelInfo;
 
-static void parseLevelInfoFree(p_psParseLevelInfo* info)
+static void parseLevelInfoFree(p_psParseLevelInfo *info)
 {
     psFree(info->nonUniqueKeyArray);
@@ -105,5 +105,5 @@
 }
 
-static p_psParseLevelInfo* p_psParseLevelInfoAlloc(void)
+static p_psParseLevelInfo *p_psParseLevelInfoAlloc(void)
 {
     // Allocate memory for parse level info
@@ -200,5 +200,9 @@
 // Returns cleaned token based on delimiter, but not including delimiter. Also changes the pointer location
 // the beginning of the string. Tokens are newly allocated null terminated strings.
-static char* getToken(char **inString,
+// XXX EAM : not sure this API is well-thought-out:
+// *status must be set to 0 going in.
+// status is 1 if delimeter is found, but no valid token
+// returned string is NULL if no valid token is found
+static char *getToken(char **inString,
                       char *delimiter,
                       psS32 *status,
@@ -353,5 +357,5 @@
 
 /** Returns parsed vector filled with with data. The input string must be null terminated. */
-static psVector* parseVector(char *inString,
+static psVector *parseVector(char *inString,
                              psElemType elemType,
                              psS32 *status)
@@ -436,5 +440,5 @@
 /*****************************************************************************/
 
-bool psMetadataItemPrint(FILE * fd,
+bool psMetadataItemPrint(FILE  *fd,
                          const char *format,
                          const psMetadataItem* item)
@@ -450,5 +454,5 @@
 
     // determining the format type
-    char* fType = strchr(format,'%');
+    char *fType = strchr(format,'%');
     if (fType == NULL) {
         // well, the format contains no reference to the metadataItem's data:
@@ -459,5 +463,5 @@
 
     // skip over any format modifiers
-    const char* formatEnd = format+strlen(format);
+    const char *formatEnd = format+strlen(format);
     while ( (fType < formatEnd) &&
         (strchr(" +-01234567890.$#, hlL",*(++fType)) != NULL) ) {}
@@ -549,5 +553,5 @@
 }
 
-static psMetadata* genTypeTemplate(char* linePtr)
+static psMetadata *genTypeTemplate(char *linePtr)
 {
     psMetadata*     metadataTemplate = NULL;
@@ -593,6 +597,6 @@
 
 
-static psMetadata* parseTypeValues(psMetadata* template,
-                                   char* linePtr)
+static psMetadata *parseTypeValues(psMetadata *template,
+                                   char *linePtr)
 {
     psMetadata*      md           = NULL;
@@ -660,7 +664,7 @@
 }
 
-bool parseMetadataItem(char* keyName,
-                       psArray* levelArray,
-                       char* linePtr,
+bool parseMetadataItem(char *keyName,
+                       psArray *levelArray,
+                       char *linePtr,
                        psMetadataFlags flags)
 {
@@ -804,19 +808,21 @@
     // If type is MULTI or META then check for the (optional) directives UPDATE or RESET;
     // otherwise, get the value and comment.
+    // line may have the following forms:
+    // NAME METADATA
+    // NAME METADATA # Comment
+    // NAME METADATA#Comment
+    // NAME METADATA UPDATE # Comment
+    // NAME METADATA RESET # Comment
+    // NAME METADATA UPDATE
+    // NAME METADATA RESET
     if((mdType == PS_DATA_METADATA_MULTI) || (mdType == PS_DATA_METADATA)) {
-        // Get the metadata item value if there is one.
+
+        // Get the metadata directive if there is one.
         status = 0;
         strValue = getToken (&linePtr, "#", &status, true);
-
-        if (status) {
-            psError(PS_ERR_IO, true, _("Failed to examine line for optional directive."));
-            psFree(strType);
-            psFree(strValue);
-            return false;
-        }
-
-        if (strValue) {
+       
+        if (!status && strValue) {
 	    // found a directive, what does it say?
-	    if (strcasecmp (strValue, "UPDATE") && strcasecmp (strValue, "UPDATE")) {
+	    if (strcasecmp (strValue, "UPDATE") && strcasecmp (strValue, "RESET")) {
 		psError(PS_ERR_IO, true, _("Invalid directive %s for METADATA or MULTI."), strValue);
 		psFree(strType);
@@ -834,7 +840,7 @@
 		flags |= PS_META_REPLACE;
 	    }
-        }
-	psFree(strValue);
-	strValue = NULL;
+	    psFree(strValue);
+	    strValue = NULL;
+	}
 
         // Not all lines will have comments, so NULL is ok.
@@ -846,5 +852,5 @@
 
         if (status) {
-            psError(PS_ERR_IO, true, _("Error reading a metadata comment"));
+            psError(PS_ERR_IO, true, _("Error reading metadata line"));
             psFree(strType);
             psFree(strComment);
@@ -965,4 +971,11 @@
         // Add key to non-unique array of keys
         // Check for duplicate MULTI lines
+
+      // XXX currently, we only place the name of the MULTI on this list.  we thus lose
+      // the associated comment (if any) and the flags (if any) we could probably fix this
+      // behavior by allowing psMetadataAddItem to be passed an empty MULTI, which would
+      // have a null data pointer until an element is added (in other words, treat MULTI
+      // as another type of folder, but without a link of its own on the metadata->list
+
         addStatus = true;
         for(psS32 k=0; k < nonUniqueKeys->n; k++) {
@@ -1034,6 +1047,6 @@
 }
 
-static bool parseLine(psArray* levelArray,
-                      char* linePtr,
+static bool parseLine(psArray *levelArray,
+                      char *linePtr,
                       bool overwrite,
                       bool *notBlank)
@@ -1101,7 +1114,7 @@
 }
 
-static bool parseGeneric(char* keyName,
-                         psArray* levelArray,
-                         char* linePtr,
+static bool parseGeneric(char *keyName,
+                         psArray *levelArray,
+                         char *linePtr,
                          psMetadataFlags flags)
 {
@@ -1130,7 +1143,7 @@
 }
 
-static bool parseType(char* keyName,
-                      psArray* levelArray,
-                      char* linePtr,
+static bool parseType(char *keyName,
+                      psArray *levelArray,
+                      char *linePtr,
                       psMetadataFlags flags)
 {
@@ -1188,7 +1201,7 @@
 }
 
-static bool parseMetadataEnd(char* keyName,
-                             psArray* levelArray,
-                             char* linePtr,
+static bool parseMetadataEnd(char *keyName,
+                             psArray *levelArray,
+                             char *linePtr,
                              psMetadataFlags flags)
 {
@@ -1214,5 +1227,5 @@
 }
 
-psMetadata* psMetadataConfigRead(psMetadata* md,
+psMetadata *psMetadataConfigRead(psMetadata *md,
                                  unsigned int *nFail,
                                  const char *filename,
@@ -1228,9 +1241,9 @@
         psError(PS_ERR_IO, true, _("failed to parse file '%s'"), filename);
         psFree(md);
-        return false;
+	psFree(file);
+        return NULL;
     }
 
     psFree(file);
-
     return md;
 }
