l3.libnazgul/src/spaceListFindId.c

77 lines
1.8 KiB
C
Raw Normal View History

2004-02-26 00:08:11 +00:00
#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){
2004-02-26 07:19:08 +00:00
// si la liste est vide
2004-02-26 00:08:11 +00:00
if (DEBUG) { printf("SpaceList : vide\n"); }
return 1;
} else {
2004-02-26 08:00:56 +00:00
return msgSpaceListElemFindId(listHeadElemId,spaceId);
2004-02-26 00:08:11 +00:00
}
2004-02-26 07:19:08 +00:00
if (msgSpaceListClose(list) < 0){
NZG_ERROR("msgSpaceListClose","");
goto ERROR;
}
return 0;
2004-02-26 00:08:11 +00:00
ERROR:
2004-02-26 07:19:08 +00:00
return -1;
2004-02-26 00:08:11 +00:00
}
int msgSpaceListElemFindId(msgSpaceListElemId elemId,msgSpaceId spaceId){
msgSpaceListElem * listElem;
msgSpaceListElemId listElemIdNext;
msgSpaceId currentElemSpaceId;
2004-02-26 07:36:00 +00:00
listElem=msgSpaceListElemOpen(elemId);
if (listElem==NULL){
NZG_ERROR("msgSpaceListElemOpen",elemId);
goto ERROR;
}
2004-02-26 00:08:11 +00:00
strcpy(listElemIdNext,listElem->next);
strcpy(currentElemSpaceId,listElem->spaceId);
2004-02-26 07:36:00 +00:00
if (msgSpaceListElemClose(listElem) < 0){
NZG_ERROR("msgSpaceListElemClose",elemId);
goto ERROR;
}
2004-02-26 00:08:11 +00:00
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;
}