Index: trunk/psLib/src/astronomy/psMetadata.c
===================================================================
--- trunk/psLib/src/astronomy/psMetadata.c	(revision 2204)
+++ trunk/psLib/src/astronomy/psMetadata.c	(revision 2273)
@@ -12,6 +12,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-10-27 00:57:30 $
+*  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-11-04 01:04:57 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -35,4 +35,6 @@
 #include "psMetadata.h"
 #include "psString.h"
+#include "psAstronomyErrors.h"
+#include "psConstants.h"
 
 /******************************************************************************/
@@ -123,8 +125,6 @@
 
 
-    if (name == NULL) {
-        psError(__func__, "Null value for name not allowed");
-        return NULL;
-    }
+    PS_PTR_CHECK_NULL(name,NULL);
+
     // Allocate metadata item
     metadataItem = (psMetadataItem* ) psAlloc(sizeof(psMetadataItem));
@@ -147,9 +147,16 @@
     // Set metadata item type
     metadataItem->type = type;
+    metadataItem->data.V = NULL;
+
+    // Allocate metadata items with same name.
+    metadataItem->items = psListAlloc(NULL);
+
+    // Allocate and set metadata item name
+    metadataItem->name = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH);
+    vsprintf(metadataItem->name, name, argPtr);
 
     // Set metadata item value
     switch (type) {
     case PS_META_ITEM_SET:
-        metadataItem->data.V = NULL;
         break;
     case PS_META_BOOL:
@@ -180,13 +187,10 @@
     case PS_META_UNKNOWN:
     default:
-        psError(__func__, "Invalid psMetadataType: %d", type);
-    }
-
-    // Allocate and set metadata item name
-    metadataItem->name = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH);
-    vsprintf(metadataItem->name, name, argPtr);
-
-    // Allocate metadata items with same name.
-    metadataItem->items = psListAlloc(NULL);
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                PS_ERRORTEXT_psMetadata_METATYPE_INVALID,
+                type);
+        psFree(metadataItem);
+        metadataItem = NULL;
+    }
 
     return metadataItem;
@@ -224,33 +228,14 @@
     psMetadataType newType = PS_META_ITEM_SET;
 
-    if(md == NULL) {
-        psError( __func__, "Null metadata collection not allowed" );
-        return false;
-    }
-
-    if(metadataItem == NULL) {
-        psError( __func__, "Null metadata item not allowed" );
-        return false;
-    }
+    PS_PTR_CHECK_NULL(md,NULL);
+    PS_PTR_CHECK_NULL(md->table,NULL);
+    PS_PTR_CHECK_NULL(md->list,NULL);
+    PS_PTR_CHECK_NULL(metadataItem,NULL);
+    PS_PTR_CHECK_NULL(metadataItem->name,NULL);
 
     newType = metadataItem->type;
-
     mdTable = md->table;
-    if(mdTable == NULL) {
-        psError( __func__, "Null metadata table not allowed" );
-        return false;
-    }
-
     mdList = md->list;
-    if(mdList == NULL) {
-        psError( __func__, "Null metadata list not allowed");
-        return false;
-    }
-
     key = metadataItem->name;
-    if(key == NULL) {
-        psError(__func__, "Null key item not allowed");
-        return false;
-    }
 
     // See if key is already in table
@@ -262,6 +247,7 @@
             // Add leaf node to existing folder node
             if(!psListAdd(existingEntry->items, PS_LIST_TAIL, metadataItem)) {
-                psError( __func__, "Couldn't add metadata item to items list. Name: %s",
-                         metadataItem->name );
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED,
+                        metadataItem->name );
                 return false;
             }
@@ -272,5 +258,7 @@
 
             if(!psListAdd(newFolderEntry->items, PS_LIST_TAIL, existingEntry)) {
-                psError( __func__, "Couldn't add metadata item to items list. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED,
+                        key);
                 psFree(newFolderEntry);
                 return false;
@@ -278,5 +266,7 @@
 
             if(!psListAdd(newFolderEntry->items, PS_LIST_TAIL, metadataItem)) {
-                psError( __func__, "Couldn't add metadata item to items list. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED,
+                        key);
                 psFree(newFolderEntry);
                 return false;
@@ -284,5 +274,7 @@
 
             if(!psHashRemove(mdTable, key)) {
-                psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED,
+                        key);
                 psFree(newFolderEntry);
                 return false;
@@ -290,5 +282,7 @@
 
             if(!psHashAdd(mdTable, key, newFolderEntry)) {
-                psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED,
+                        key);
                 psFree(newFolderEntry);
                 return false;
@@ -301,15 +295,21 @@
             // Folder node replaces leaf or folder node - Put old node into new folder and remove from table
             if(!psListAdd(metadataItem->items, PS_LIST_TAIL, existingEntry)) {
-                psError( __func__, "Couldn't add metadata item to items list. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED,
+                        key);
                 return false;
             }
 
             if(!psHashRemove(mdTable, key)) {
-                psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED,
+                        key);
                 return false;
             }
 
             if(!psHashAdd(mdTable, key, metadataItem)) {
-                psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED,
+                        key);
                 return false;
             }
@@ -319,5 +319,7 @@
         // Node doesn't exist - Add new metadata item to metadata collection's hash
         if(!psHashAdd(mdTable, key, metadataItem)) {
-            psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key);
+            psError(PS_ERR_UNKNOWN,false,
+                    PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED,
+                    key);
             return false;
         }
@@ -328,6 +330,7 @@
     if(metadataItem->type != PS_META_ITEM_SET) {
         if(!psListAdd(mdList, location, metadataItem)) {
-            psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",
-                     metadataItem->name );
+            psError(PS_ERR_UNKNOWN,false,
+                    PS_ERRORTEXT_psMetadata_ADD_COLLECTION_FAILED,
+                    key);
             return false;
         }
@@ -348,6 +351,6 @@
 
     if (!psMetadataAddItem(md, metadataItem, where)) {
-        psError(__func__, "Couldn't add metadata item to metadata collection list. Name: %s",
-                metadataItem->name);
+        psError(PS_ERR_UNKNOWN,false,
+                PS_ERRORTEXT_psMetadata_ADD_FAILED);
         psFree(metadataItem);
         return false;
@@ -368,20 +371,11 @@
 
 
-    if (md == NULL) {
-        psError(__func__, "Null metadata collection not allowed");
-        return false;
-    }
+    PS_PTR_CHECK_NULL(md,NULL);
+    PS_PTR_CHECK_NULL(md->table,NULL);
+    PS_PTR_CHECK_NULL(md->list,NULL);
 
     mdList = md->list;
-    if (mdList == NULL) {
-        psError(__func__, "Null metadata list not allowed");
-        return false;
-    }
-
     mdTable = md->table;
-    if (mdTable == NULL) {
-        psError(__func__, "Null metadata table not allowed");
-        return false;
-    }
+
     // Select removal by key or index
     if (key != NULL) {
@@ -390,5 +384,7 @@
         entry = (psMetadataItem* ) psHashLookup(mdTable, key);
         if (entry == NULL) {
-            psError(__func__, "Couldn't find metadata item. Name: %s", key);
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                    PS_ERRORTEXT_psMetadata_FIND_FAILED,
+                    key);
             return false;
         }
@@ -402,5 +398,7 @@
             while (entryChild != NULL) {
                 if (!psListRemove(mdList, PS_LIST_UNKNOWN, entryChild)) {
-                    psError(__func__, "Couldn't remove metadata item from list. Name: %s", key);
+                    psError(PS_ERR_UNKNOWN,false,
+                            PS_ERRORTEXT_psMetadata_REMOVE_LIST_FAILED,
+                            key);
                     return false;
                 }
@@ -411,5 +409,7 @@
             // Table entry has no children. Remove entry from metadata collection's list
             if (!psListRemove(mdList, PS_LIST_UNKNOWN, entry)) {
-                psError(__func__, "Couldn't remove metadata item from list. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_REMOVE_LIST_FAILED,
+                        key);
                 return false;
             }
@@ -417,5 +417,7 @@
         // Remove entry from metadata collection's table
         if (!psHashRemove(mdTable, key)) {
-            psError(__func__, "Couldn't remove metadata item from table. Name: %s", key);
+            psError(PS_ERR_UNKNOWN,false,
+                    PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED,
+                    key);
             return false;
         }
@@ -425,5 +427,7 @@
         entry = psListGet(mdList, where);
         if (entry == NULL) {
-            psError(__func__, "Couldn't find metadata item in list. Index: %d", where);
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                    PS_ERRORTEXT_psMetadata_FIND_INDEX_FAILED,
+                    where);
             return false;
         }
@@ -431,5 +435,7 @@
         key = entry->name;
         if (key == NULL) {
-            psError(__func__, "Null key name not allowed. Index: %d", where);
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                    PS_ERRORTEXT_psMetadata_REMOVE_LIST_INDEX_FAILED,
+                    where);
             return false;
         }
@@ -447,19 +453,9 @@
 
 
-    if (md == NULL) {
-        psError(__func__, "Null metadata collection not allowed");
-        return NULL;
-    }
+    PS_PTR_CHECK_NULL(md,NULL);
+    PS_PTR_CHECK_NULL(md->table,NULL);
+    PS_PTR_CHECK_NULL(key,NULL);
 
     mdTable = md->table;
-    if (mdTable == NULL) {
-        psError(__func__, "Null metadata table not allowed");
-        return NULL;
-    }
-
-    if (key == NULL) {
-        psError(__func__, "Null key name not allowed");
-        return NULL;
-    }
 
     entry = (psMetadataItem* ) psHashLookup(mdTable, key);
@@ -473,64 +469,40 @@
 psMetadataItem* psMetadataGet(psMetadata* restrict md, psS32 where)
 {
+    psMetadataItem* entry = NULL;
+
+    PS_PTR_CHECK_NULL(md,NULL);
+    PS_PTR_CHECK_NULL(md->list,NULL);
+
+    entry = (psMetadataItem* ) psListGet(md->list, where);
+    if (entry == NULL) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                PS_ERRORTEXT_psMetadata_FIND_INDEX_FAILED,
+                where);
+        return NULL;
+    }
+
+    return entry;
+}
+
+psBool psMetadataSetIterator(psMetadata* restrict md, psS32 where)
+{
+    PS_PTR_CHECK_NULL(md,NULL);
+    PS_PTR_CHECK_NULL(md->list,NULL);
+
+    psListSetIterator(md->list, where);
+
+    return true;
+}
+
+psMetadataItem* psMetadataGetNext(psMetadata* restrict md, const char *restrict match, psS32 which)
+{
     psList* mdList = NULL;
     psMetadataItem* entry = NULL;
 
 
-    if (md == NULL) {
-        psError(__func__, "Null metadata collection not allowed");
-        return NULL;
-    }
+    PS_PTR_CHECK_NULL(md,NULL);
+    PS_PTR_CHECK_NULL(md->list,NULL);
 
     mdList = md->list;
-    if (mdList == NULL) {
-        psError(__func__, "Null metadata list not allowed");
-        return NULL;
-    }
-
-    entry = (psMetadataItem* ) psListGet(mdList, where);
-    if (entry == NULL) {
-        psError(__func__, "Couldn't find metadata item with given index. Index: %d", where);
-        return NULL;
-    }
-
-    return entry;
-}
-
-psBool psMetadataSetIterator(psMetadata* restrict md, psS32 where)
-{
-    psList* mdList = NULL;
-
-    if (md == NULL) {
-        psError(__func__, "Null metadata collection not allowed");
-        return false;
-    }
-
-    mdList = md->list;
-    if (mdList == NULL) {
-        psError(__func__, "Null metadata list not allowed");
-        return false;
-    }
-
-    psListSetIterator(mdList, where);
-
-    return true;
-}
-
-psMetadataItem* psMetadataGetNext(psMetadata* restrict md, const char *restrict match, psS32 which)
-{
-    psList* mdList = NULL;
-    psMetadataItem* entry = NULL;
-
-
-    if (md == NULL) {
-        psError(__func__, "Null metadata collection not allowed");
-        return NULL;
-    }
-
-    mdList = md->list;
-    if (mdList == NULL) {
-        psError(__func__, "Null metadata list not allowed");
-        return NULL;
-    }
 
     psListSetIterator(mdList, which);
@@ -559,14 +531,8 @@
 
 
-    if (md == NULL) {
-        psError(__func__, "Null metadata collection not allowed");
-        return NULL;
-    }
+    PS_PTR_CHECK_NULL(md,NULL);
+    PS_PTR_CHECK_NULL(md->list,NULL);
 
     mdList = md->list;
-    if (mdList == NULL) {
-        psError(__func__, "Null metadata list not allowed");
-        return NULL;
-    }
 
     psListSetIterator(mdList, which);
