Index: /trunk/psLib/psLib.kdevses
===================================================================
--- /trunk/psLib/psLib.kdevses	(revision 2693)
+++ /trunk/psLib/psLib.kdevses	(revision 2694)
@@ -2,23 +2,11 @@
 <!DOCTYPE KDevPrjSession>
 <KDevPrjSession>
- <DocsAndViews NumberOfDocuments="6" >
-  <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/src/Makefile" >
-   <View0 line="225" Type="Source" />
+ <DocsAndViews NumberOfDocuments="2" >
+  <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/test/astronomy/tst_psMetadataIO.c" >
+   <View0 line="49" Type="Source" />
   </Doc0>
-  <Doc1 NumberOfViews="1" URL="file:/home/desonia/psLib/src/fileUtils/psFits.c" >
-   <View0 line="585" Type="Source" />
+  <Doc1 NumberOfViews="1" URL="file:/home/desonia/psLib/test/astronomy/tst_psMetadata_01.c" >
+   <View0 line="76" Type="Source" />
   </Doc1>
-  <Doc2 NumberOfViews="1" URL="file:/home/desonia/psLib/src/fileUtils/psFits.h" >
-   <View0 line="144" Type="Source" />
-  </Doc2>
-  <Doc3 NumberOfViews="1" URL="file:/home/desonia/psLib/src/fileUtils/psFileUtilsErrors.dat" >
-   <View0 line="35" Type="Source" />
-  </Doc3>
-  <Doc4 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psList.h" >
-   <View0 line="166" Type="Source" />
-  </Doc4>
-  <Doc5 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psList.c" >
-   <View0 line="46" Type="Source" />
-  </Doc5>
  </DocsAndViews>
  <pluginList>
Index: /trunk/psLib/src/collections/psList.c
===================================================================
--- /trunk/psLib/src/collections/psList.c	(revision 2693)
+++ /trunk/psLib/src/collections/psList.c	(revision 2694)
@@ -6,6 +6,6 @@
  *  @author Robert Daniel DeSonia, MHPCC
  *
- *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-10 02:50:14 $
+ *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-12-10 21:43:16 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -74,5 +74,5 @@
 static psBool listIteratorRemove(psListIterator* iterator)
 {
-    if (iterator == NULL) {
+    if (iterator == NULL || iterator->cursor == NULL) {
         return false;
     }
@@ -102,5 +102,5 @@
         if (iter->cursor == elem) {
             iter->cursor = NULL;
-        } else if (iter->index > index) {
+        } else if (iter->index > index && iter->index > 0) {
             iter->index--;
         }
@@ -183,5 +183,5 @@
     psList* list = iterator->list;
 
-    if (location >= list->size) {
+    if (location >= (int)list->size) {
         psLogMsg(__func__, PS_LOG_WARN,
                  "Specified index, %d, is beyond the end of the psList, which "
@@ -283,6 +283,7 @@
 
     psListElem* cursor = iterator->cursor;
-
-    if (cursor == NULL) {
+    psList* list = iterator->list;
+
+    if (cursor == NULL && list->head != NULL) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                 PS_ERRORTEXT_psList_ITERATOR_INVALID);
@@ -290,5 +291,4 @@
     }
 
-    psList* list = iterator->list;
     psListElem* elem = psAlloc(sizeof(psListElem));
 
@@ -297,9 +297,20 @@
 
     // set the new list element's attributes
-    elem->prev = cursor;
-    elem->next = cursor->next;
-    elem->data = data;
-
-    cursor->next = elem;
+    if (cursor == NULL) { // must be an empty list
+        elem->prev = NULL;
+        elem->next = NULL;
+        list->head = elem;
+        list->tail = elem;
+    } else {
+        elem->prev = cursor;
+        elem->next = cursor->next;
+        cursor->next = elem;
+        if (elem->next == NULL) {
+            list->tail = elem;
+        }
+    }
+
+    elem->data = psMemIncrRefCounter(data);
+
     list->size++;
 
@@ -338,6 +349,7 @@
 
     psListElem* cursor = iterator->cursor;
-
-    if (cursor == NULL) {
+    psList* list = iterator->list;
+
+    if (cursor == NULL && list->head != NULL) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                 PS_ERRORTEXT_psList_ITERATOR_INVALID);
@@ -345,5 +357,4 @@
     }
 
-    psList* list = iterator->list;
     psListElem* elem = psAlloc(sizeof(psListElem));
 
@@ -352,9 +363,20 @@
 
     // set the new list element's attributes
-    elem->prev = cursor->prev;
-    elem->next = cursor;
-    elem->data = data;
-
-    cursor->prev = elem;
+    if (cursor == NULL) { // empty list.
+        elem->prev = NULL;
+        elem->next = NULL;
+        list->head = elem;
+        list->tail = elem;
+    } else {
+        elem->prev = cursor->prev;
+        elem->next = cursor;
+        cursor->prev = elem;
+        if (elem->prev == NULL) {
+            list->head = elem;
+        }
+    }
+
+    elem->data = psMemIncrRefCounter(data);
+
     list->size++;
 
@@ -435,4 +457,10 @@
 psPtr psListGet(psList* list, psS32 location)
 {
+    if (list == NULL) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true,
+                PS_ERRORTEXT_psList_LIST_NULL);
+        return false;
+    }
+
     psListIterator* iterator = list->iterators->data[0];
 
Index: /trunk/psLib/src/types/psList.c
===================================================================
--- /trunk/psLib/src/types/psList.c	(revision 2693)
+++ /trunk/psLib/src/types/psList.c	(revision 2694)
@@ -6,6 +6,6 @@
  *  @author Robert Daniel DeSonia, MHPCC
  *
- *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-10 02:50:14 $
+ *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-12-10 21:43:16 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -74,5 +74,5 @@
 static psBool listIteratorRemove(psListIterator* iterator)
 {
-    if (iterator == NULL) {
+    if (iterator == NULL || iterator->cursor == NULL) {
         return false;
     }
@@ -102,5 +102,5 @@
         if (iter->cursor == elem) {
             iter->cursor = NULL;
-        } else if (iter->index > index) {
+        } else if (iter->index > index && iter->index > 0) {
             iter->index--;
         }
@@ -183,5 +183,5 @@
     psList* list = iterator->list;
 
-    if (location >= list->size) {
+    if (location >= (int)list->size) {
         psLogMsg(__func__, PS_LOG_WARN,
                  "Specified index, %d, is beyond the end of the psList, which "
@@ -283,6 +283,7 @@
 
     psListElem* cursor = iterator->cursor;
-
-    if (cursor == NULL) {
+    psList* list = iterator->list;
+
+    if (cursor == NULL && list->head != NULL) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                 PS_ERRORTEXT_psList_ITERATOR_INVALID);
@@ -290,5 +291,4 @@
     }
 
-    psList* list = iterator->list;
     psListElem* elem = psAlloc(sizeof(psListElem));
 
@@ -297,9 +297,20 @@
 
     // set the new list element's attributes
-    elem->prev = cursor;
-    elem->next = cursor->next;
-    elem->data = data;
-
-    cursor->next = elem;
+    if (cursor == NULL) { // must be an empty list
+        elem->prev = NULL;
+        elem->next = NULL;
+        list->head = elem;
+        list->tail = elem;
+    } else {
+        elem->prev = cursor;
+        elem->next = cursor->next;
+        cursor->next = elem;
+        if (elem->next == NULL) {
+            list->tail = elem;
+        }
+    }
+
+    elem->data = psMemIncrRefCounter(data);
+
     list->size++;
 
@@ -338,6 +349,7 @@
 
     psListElem* cursor = iterator->cursor;
-
-    if (cursor == NULL) {
+    psList* list = iterator->list;
+
+    if (cursor == NULL && list->head != NULL) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                 PS_ERRORTEXT_psList_ITERATOR_INVALID);
@@ -345,5 +357,4 @@
     }
 
-    psList* list = iterator->list;
     psListElem* elem = psAlloc(sizeof(psListElem));
 
@@ -352,9 +363,20 @@
 
     // set the new list element's attributes
-    elem->prev = cursor->prev;
-    elem->next = cursor;
-    elem->data = data;
-
-    cursor->prev = elem;
+    if (cursor == NULL) { // empty list.
+        elem->prev = NULL;
+        elem->next = NULL;
+        list->head = elem;
+        list->tail = elem;
+    } else {
+        elem->prev = cursor->prev;
+        elem->next = cursor;
+        cursor->prev = elem;
+        if (elem->prev == NULL) {
+            list->head = elem;
+        }
+    }
+
+    elem->data = psMemIncrRefCounter(data);
+
     list->size++;
 
@@ -435,4 +457,10 @@
 psPtr psListGet(psList* list, psS32 location)
 {
+    if (list == NULL) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true,
+                PS_ERRORTEXT_psList_LIST_NULL);
+        return false;
+    }
+
     psListIterator* iterator = list->iterators->data[0];
 
