From b2731cdafd5bca3290ac5fd47b4aaaefa8c531c3 Mon Sep 17 00:00:00 2001 From: glenux Date: Thu, 26 Feb 2004 07:19:08 +0000 Subject: [PATCH] *** empty log message *** --- src/spaceListFindId.c | 76 ++++---------------------- src/spaceListRem.c | 120 +++++++++++++++++++++++------------------- 2 files changed, 75 insertions(+), 121 deletions(-) diff --git a/src/spaceListFindId.c b/src/spaceListFindId.c index 8b1132e..6b92a49 100644 --- a/src/spaceListFindId.c +++ b/src/spaceListFindId.c @@ -19,78 +19,20 @@ int msgSpaceListFindId(msgSpaceId spaceId){ if (DEBUG) { printf("After ListStrCpy\n"); } if ((strcmp(listHeadElemId,listId)==0) && strcmp(listTailElemId,listId)==0){ + // si la liste est vide if (DEBUG) { printf("SpaceList : vide\n"); } return 1; } else { - bool found=false; - msgSpaceListElemId prevElemId; - msgSpaceListElemId currElemId; - msgSpaceListElemId nextElemId; - msgSpaceListElem prevElem; - msgSpaceListElem currElem; - msgSpaceListElem nextElem; - msgSpaceId currSpaceId; - - strcpy(prevElemId,listHeadElemId,list->headId); - strcpy(currElemId,listHeadElemId,list->headId); - while(!found){ - printf("Recherche dans l'element %s\n",listHeadElemId); - listElem=msgSpaceListElemOpen(elemId); - if (listElem==NULL){ - NZG_ERROR("msgSpaceListElemOpen",elemId); - goto ERROR; - } - strcpy(nextElemId,listElem->next); - strcpy(currSpaceId,listElem->spaceId); - if (msgSpaceListElemClose(listElem) <0){ - NZG_ERROR("msgSpaceListElemClose",elemId); - goto ERROR; - } - if (strcmp(prevElemId,nextElemId)==0){ - // list à 1 seul élement - if (strcmp(listElem->spaceId,spaceId)==0){ - // on a trouvé l'elem - strcpy(list->headId,list->id); - strcpy(list->tailId,list->id); - // on efface - shm_unlink(currElemId); - found=true; - } else { - break; - } - } else { - // liste à plusieurs élements... - if (strcmp(listElem->spaceId,spaceId)==0){ - // ca correspond - // si on est en début de liste (prev=current) - // - la tete de liste pointe sur le suivant - // - on détruit l'actuel - // si on est en find de liste (current=next) - // - on fait pointer le précédent sur luimeme - // - on fait pointer la queue de liste sur le précédent - // - on détruit l'actuel - // sinon : - // - on fait pointer le précédent sur le suivant - // - on détruit l'actuel - found=true; - break; - } else { - //cela ne correspond pas - //on recopie - strcpy(prevElemId,currElemId); - strcpu(currElemId,nextElemId); - } - } - - } - if (msgSpaceListClose(list) < 0){ - NZG_ERROR("msgSpaceListClose",""); - goto ERROR; - } - return 0; + return msgSpaceListElemFindId(listId,spaceId); } + if (msgSpaceListClose(list) < 0){ + NZG_ERROR("msgSpaceListClose",""); + goto ERROR; + } + return 0; +} ERROR: - return -1; +return -1; } int msgSpaceListElemFindId(msgSpaceListElemId elemId,msgSpaceId spaceId){ diff --git a/src/spaceListRem.c b/src/spaceListRem.c index 06af47f..c0ae30c 100644 --- a/src/spaceListRem.c +++ b/src/spaceListRem.c @@ -17,67 +17,79 @@ int msgSpaceListRem(msgSpaceId spaceId){ strcpy(listTailElemId,list->tailId); strcpy(listId,list->id); if (DEBUG) { printf("After ListStrCpy\n"); } - if (msgSpaceListClose(list) < 0){ - NZG_ERROR("msgSpaceListClose",""); - goto ERROR; - } if ((strcmp(listHeadElemId,listId)==0) && strcmp(listTailElemId,listId)==0){ if (DEBUG) { printf("SpaceList : vide\n"); } return 1; } else { - printf("RechercheRem dans l'element %s\n",listHeadElemId); - return msgSpaceListElemRem(listHeadElemId,spaceId); + bool found=false; + msgSpaceListElemId prevElemId; + msgSpaceListElemId currElemId; + msgSpaceListElemId nextElemId; + msgSpaceListElem prevElem; + msgSpaceListElem currElem; + msgSpaceListElem nextElem; + msgSpaceId currSpaceId; + + strcpy(prevElemId,listHeadElemId,list->headId); + strcpy(currElemId,listHeadElemId,list->headId); + while(!found){ + printf("Recherche dans l'element %s\n",listHeadElemId); + listElem=msgSpaceListElemOpen(elemId); + if (listElem==NULL){ + NZG_ERROR("msgSpaceListElemOpen",elemId); + goto ERROR; + } + strcpy(nextElemId,listElem->next); + strcpy(currSpaceId,listElem->spaceId); + if (msgSpaceListElemClose(listElem) <0){ + NZG_ERROR("msgSpaceListElemClose",elemId); + goto ERROR; + } + if (strcmp(prevElemId,nextElemId)==0){ + // list à 1 seul élement + if (strcmp(listElem->spaceId,spaceId)==0){ + // on a trouvé l'elem + strcpy(list->headId,list->id); + strcpy(list->tailId,list->id); + // on efface + shm_unlink(currElemId); + found=true; + } else { + break; + } + } else { + // liste à plusieurs élements... + if (strcmp(listElem->spaceId,spaceId)==0){ + // ca correspond + // si on est en début de liste (prev=current) + // - la tete de liste pointe sur le suivant + // - on détruit l'actuel + // si on est en find de liste (current=next) + // - on fait pointer le précédent sur luimeme + // - on fait pointer la queue de liste sur le précédent + // - on détruit l'actuel + // sinon : + // - on fait pointer le précédent sur le suivant + // - on détruit l'actuel + found=true; + break; + } else { + //cela ne correspond pas + //on recopie + strcpy(prevElemId,currElemId); + strcpu(currElemId,nextElemId); + } + } + + } + if (msgSpaceListClose(list) < 0){ + NZG_ERROR("msgSpaceListClose",""); + goto ERROR; + } + return 0; } ERROR: return -1; } -int msgSpaceListElemRem(msgSpaceListElemId elemId,msgSpaceId spaceId){ - msgSpaceListElem * listElem; - msgSpaceListElemId listElemIdNext; - msgSpaceId currentElemSpaceId; - - listElem=msgSpaceListElemOpen(elemId); - if (listElem==NULL){ - NZG_ERROR("msgSpaceListElemOpen",elemId); - goto ERROR; - } - strcpy(listElemIdNext,listElem->next); - strcpy(currentElemSpaceId,listElem->spaceId); - printf("Current ListElem: Next:%s, Sid:%s\n", - listElemIdNext,currentElemSpaceId); - if (msgSpaceListElemClose(listElem) <0){ - NZG_ERROR("msgSpaceListElemClose",elemId); - goto ERROR; - } -printf("comparisons...\n"); -if (strcmp(listElemIdNext,elemId)==0){ - //on a rien trouvé avant et on est au bout - return -1; -} else { - msgSpaceListElem * listElemNext; - msgSpaceListElemId spaceIdNext; - listElemNext=msgSpaceListElemOpen(listElemIdNext); - strcpy(spaceIdNext,listElemNext->spaceId); - strcpy(listElemIdNextNext,listElemNext->next); - msgSpaceListElemClose(listElemNext); - if (strcmp(spaceIdNext,spaceId)==0) { - printf("Found/Rem %s in spaceList !\n",spaceId); - // l'element suivant correspond - // on ouvre l'elem courant - // si l'id(nextnext) == id(next) alors on met notre propre id - // sinon on met notre propre id dans next - // on unlinke l'ancien suivant - return 0; - } else { - return msgSpaceListElemRem(listElemIdNext,spaceId); - - } -} - - return 0; -ERROR: - return -1; -} -