IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2694


Ignore:
Timestamp:
Dec 10, 2004, 11:43:16 AM (22 years ago)
Author:
desonia
Message:

fixed some psList problems. More exist.

Location:
trunk/psLib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/psLib.kdevses

    r2681 r2694  
    22<!DOCTYPE KDevPrjSession>
    33<KDevPrjSession>
    4  <DocsAndViews NumberOfDocuments="6" >
    5   <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/src/Makefile" >
    6    <View0 line="225" Type="Source" />
     4 <DocsAndViews NumberOfDocuments="2" >
     5  <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/test/astronomy/tst_psMetadataIO.c" >
     6   <View0 line="49" Type="Source" />
    77  </Doc0>
    8   <Doc1 NumberOfViews="1" URL="file:/home/desonia/psLib/src/fileUtils/psFits.c" >
    9    <View0 line="585" Type="Source" />
     8  <Doc1 NumberOfViews="1" URL="file:/home/desonia/psLib/test/astronomy/tst_psMetadata_01.c" >
     9   <View0 line="76" Type="Source" />
    1010  </Doc1>
    11   <Doc2 NumberOfViews="1" URL="file:/home/desonia/psLib/src/fileUtils/psFits.h" >
    12    <View0 line="144" Type="Source" />
    13   </Doc2>
    14   <Doc3 NumberOfViews="1" URL="file:/home/desonia/psLib/src/fileUtils/psFileUtilsErrors.dat" >
    15    <View0 line="35" Type="Source" />
    16   </Doc3>
    17   <Doc4 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psList.h" >
    18    <View0 line="166" Type="Source" />
    19   </Doc4>
    20   <Doc5 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psList.c" >
    21    <View0 line="46" Type="Source" />
    22   </Doc5>
    2311 </DocsAndViews>
    2412 <pluginList>
  • trunk/psLib/src/collections/psList.c

    r2681 r2694  
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-12-10 02:50:14 $
     8 *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-12-10 21:43:16 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7474static psBool listIteratorRemove(psListIterator* iterator)
    7575{
    76     if (iterator == NULL) {
     76    if (iterator == NULL || iterator->cursor == NULL) {
    7777        return false;
    7878    }
     
    102102        if (iter->cursor == elem) {
    103103            iter->cursor = NULL;
    104         } else if (iter->index > index) {
     104        } else if (iter->index > index && iter->index > 0) {
    105105            iter->index--;
    106106        }
     
    183183    psList* list = iterator->list;
    184184
    185     if (location >= list->size) {
     185    if (location >= (int)list->size) {
    186186        psLogMsg(__func__, PS_LOG_WARN,
    187187                 "Specified index, %d, is beyond the end of the psList, which "
     
    283283
    284284    psListElem* cursor = iterator->cursor;
    285 
    286     if (cursor == NULL) {
     285    psList* list = iterator->list;
     286
     287    if (cursor == NULL && list->head != NULL) {
    287288        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    288289                PS_ERRORTEXT_psList_ITERATOR_INVALID);
     
    290291    }
    291292
    292     psList* list = iterator->list;
    293293    psListElem* elem = psAlloc(sizeof(psListElem));
    294294
     
    297297
    298298    // set the new list element's attributes
    299     elem->prev = cursor;
    300     elem->next = cursor->next;
    301     elem->data = data;
    302 
    303     cursor->next = elem;
     299    if (cursor == NULL) { // must be an empty list
     300        elem->prev = NULL;
     301        elem->next = NULL;
     302        list->head = elem;
     303        list->tail = elem;
     304    } else {
     305        elem->prev = cursor;
     306        elem->next = cursor->next;
     307        cursor->next = elem;
     308        if (elem->next == NULL) {
     309            list->tail = elem;
     310        }
     311    }
     312
     313    elem->data = psMemIncrRefCounter(data);
     314
    304315    list->size++;
    305316
     
    338349
    339350    psListElem* cursor = iterator->cursor;
    340 
    341     if (cursor == NULL) {
     351    psList* list = iterator->list;
     352
     353    if (cursor == NULL && list->head != NULL) {
    342354        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    343355                PS_ERRORTEXT_psList_ITERATOR_INVALID);
     
    345357    }
    346358
    347     psList* list = iterator->list;
    348359    psListElem* elem = psAlloc(sizeof(psListElem));
    349360
     
    352363
    353364    // set the new list element's attributes
    354     elem->prev = cursor->prev;
    355     elem->next = cursor;
    356     elem->data = data;
    357 
    358     cursor->prev = elem;
     365    if (cursor == NULL) { // empty list.
     366        elem->prev = NULL;
     367        elem->next = NULL;
     368        list->head = elem;
     369        list->tail = elem;
     370    } else {
     371        elem->prev = cursor->prev;
     372        elem->next = cursor;
     373        cursor->prev = elem;
     374        if (elem->prev == NULL) {
     375            list->head = elem;
     376        }
     377    }
     378
     379    elem->data = psMemIncrRefCounter(data);
     380
    359381    list->size++;
    360382
     
    435457psPtr psListGet(psList* list, psS32 location)
    436458{
     459    if (list == NULL) {
     460        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     461                PS_ERRORTEXT_psList_LIST_NULL);
     462        return false;
     463    }
     464
    437465    psListIterator* iterator = list->iterators->data[0];
    438466
  • trunk/psLib/src/types/psList.c

    r2681 r2694  
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-12-10 02:50:14 $
     8 *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-12-10 21:43:16 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7474static psBool listIteratorRemove(psListIterator* iterator)
    7575{
    76     if (iterator == NULL) {
     76    if (iterator == NULL || iterator->cursor == NULL) {
    7777        return false;
    7878    }
     
    102102        if (iter->cursor == elem) {
    103103            iter->cursor = NULL;
    104         } else if (iter->index > index) {
     104        } else if (iter->index > index && iter->index > 0) {
    105105            iter->index--;
    106106        }
     
    183183    psList* list = iterator->list;
    184184
    185     if (location >= list->size) {
     185    if (location >= (int)list->size) {
    186186        psLogMsg(__func__, PS_LOG_WARN,
    187187                 "Specified index, %d, is beyond the end of the psList, which "
     
    283283
    284284    psListElem* cursor = iterator->cursor;
    285 
    286     if (cursor == NULL) {
     285    psList* list = iterator->list;
     286
     287    if (cursor == NULL && list->head != NULL) {
    287288        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    288289                PS_ERRORTEXT_psList_ITERATOR_INVALID);
     
    290291    }
    291292
    292     psList* list = iterator->list;
    293293    psListElem* elem = psAlloc(sizeof(psListElem));
    294294
     
    297297
    298298    // set the new list element's attributes
    299     elem->prev = cursor;
    300     elem->next = cursor->next;
    301     elem->data = data;
    302 
    303     cursor->next = elem;
     299    if (cursor == NULL) { // must be an empty list
     300        elem->prev = NULL;
     301        elem->next = NULL;
     302        list->head = elem;
     303        list->tail = elem;
     304    } else {
     305        elem->prev = cursor;
     306        elem->next = cursor->next;
     307        cursor->next = elem;
     308        if (elem->next == NULL) {
     309            list->tail = elem;
     310        }
     311    }
     312
     313    elem->data = psMemIncrRefCounter(data);
     314
    304315    list->size++;
    305316
     
    338349
    339350    psListElem* cursor = iterator->cursor;
    340 
    341     if (cursor == NULL) {
     351    psList* list = iterator->list;
     352
     353    if (cursor == NULL && list->head != NULL) {
    342354        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    343355                PS_ERRORTEXT_psList_ITERATOR_INVALID);
     
    345357    }
    346358
    347     psList* list = iterator->list;
    348359    psListElem* elem = psAlloc(sizeof(psListElem));
    349360
     
    352363
    353364    // set the new list element's attributes
    354     elem->prev = cursor->prev;
    355     elem->next = cursor;
    356     elem->data = data;
    357 
    358     cursor->prev = elem;
     365    if (cursor == NULL) { // empty list.
     366        elem->prev = NULL;
     367        elem->next = NULL;
     368        list->head = elem;
     369        list->tail = elem;
     370    } else {
     371        elem->prev = cursor->prev;
     372        elem->next = cursor;
     373        cursor->prev = elem;
     374        if (elem->prev == NULL) {
     375            list->head = elem;
     376        }
     377    }
     378
     379    elem->data = psMemIncrRefCounter(data);
     380
    359381    list->size++;
    360382
     
    435457psPtr psListGet(psList* list, psS32 location)
    436458{
     459    if (list == NULL) {
     460        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     461                PS_ERRORTEXT_psList_LIST_NULL);
     462        return false;
     463    }
     464
    437465    psListIterator* iterator = list->iterators->data[0];
    438466
Note: See TracChangeset for help on using the changeset viewer.