l3.libnazgul/src/spaceListFindId.c
2020-03-03 23:46:32 +01:00

76 lines
1.8 KiB
C

#include "libnazgul.h"
#define DEBUG 1
int msgSpaceListFindId(msgSpaceId spaceId){
msgSpaceList * list;
msgSpaceListElemId listHeadElemId;
msgSpaceListElemId listTailElemId;
msgSpaceListId listId;
list=msgSpaceListOpen();
if (list==NULL){
NZG_ERROR("msgSpaceListOpen","");
goto ERROR;
}
if (DEBUG) { printf("Before ListStrCpy\n"); }
strcpy(listHeadElemId,list->headId);
strcpy(listTailElemId,list->tailId);
strcpy(listId,list->id);
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 {
return msgSpaceListElemFindId(listId,spaceId);
}
if (msgSpaceListClose(list) < 0){
NZG_ERROR("msgSpaceListClose","");
goto ERROR;
}
return 0;
ERROR:
return -1;
}
int msgSpaceListElemFindId(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);
if (msgSpaceListElemClose(listElem) < 0){
NZG_ERROR("msgSpaceListElemClose",elemId);
goto ERROR;
}
printf("Current ListElem: Next:%s, Sid:%s\n",
listElemIdNext,currentElemSpaceId);
printf("comparisons...\n");
if (strcmp(currentElemSpaceId,spaceId)==0) {
printf("Found %s in spaceList !\n",spaceId);
return 0;
} else {
if (strcmp(listElemIdNext,elemId)==0){
printf("End of spaceList reached.\n");
/* fin de liste ?? */
return 1;
} else {
/* continuer sur l'element suivant */
return msgSpaceListElemFindId(listElemIdNext,spaceId);
}
}
return 0;
ERROR:
return -1;
}