int listIteratorSetCurEntry(LIST_ITERATOR_T *iter, LIST_ENTRY_T *entry, bool_t validateEnt) { LIST_ENTRY_T *savedCurEnt; LIST_ENTRY_T *ent; if (validateEnt) { bool_t found = FALSE; savedCurEnt = iter->curEnt; iter->curEnt = listGetFrontEntry(iter->list); for (ent = listIteratorGetCurEntry(iter); ! listIteratorIsEndOfList(iter); listIteratorNext(iter, (LIST_ENTRY_T **)&ent)) { if (ent == entry) { found = TRUE; break; } } if (! found) { listerrno = LIST_ERR_BADARG; iter->curEnt = savedCurEnt; return -1; } } iter->curEnt = entry; return 0; }
LIST_T* listDup(LIST_T* list, int sizeOfEntry) { LIST_T *newList; LIST_ENTRY_T *listEntry; LIST_ENTRY_T *newListEntry; LIST_ITERATOR_T iter; newList = listCreate(list->name); if (! newList) { return NULL; } LIST_ITERATOR_ZERO_OUT(&iter); listIteratorAttach(&iter, list); for (listEntry = listIteratorGetCurEntry(&iter); listEntry != NULL; listIteratorNext(&iter, &listEntry)) { newListEntry = (LIST_ENTRY_T *)calloc(1, sizeOfEntry); memcpy(newListEntry, listEntry, sizeOfEntry); listInsertEntryAtBack(newList, newListEntry); } listIteratorDetach(&iter); return newList; }
void listDisplay(LIST_T *list, int direction, void (*displayFunc)(LIST_ENTRY_T *, void *), void *hint) { LIST_ITERATOR_T iter; LIST_ENTRY_T *entry; if (direction == 0) direction = LIST_TRAVERSE_FORWARD; LIST_ITERATOR_ZERO_OUT(&iter); listIteratorAttach(&iter, list); if (direction & LIST_TRAVERSE_BACKWARD) listIteratorSetCurEntry(&iter, listGetBackEntry(list), FALSE); for (entry = listIteratorGetCurEntry(&iter); entry != NULL; (direction & LIST_TRAVERSE_FORWARD) ? listIteratorNext(&iter, &entry) : listIteratorPrev(&iter, &entry)) { (*displayFunc)(entry, hint); } }
void list2Vector(LIST_T *list, int direction, void *vector, void (*putVecEnt)(void *vector, int index, LIST_ENTRY_T *entry)) { LIST_ITERATOR_T iter; LIST_ENTRY_T *entry; int entIdx; if (direction == 0) direction = LIST_TRAVERSE_FORWARD; LIST_ITERATOR_ZERO_OUT(&iter); listIteratorAttach(&iter, list); if (direction & LIST_TRAVERSE_BACKWARD) listIteratorSetCurEntry(&iter, listGetBackEntry(list), FALSE); entIdx = 0; for (entry = listIteratorGetCurEntry(&iter); entry != NULL; (direction & LIST_TRAVERSE_FORWARD) ? listIteratorNext(&iter, &entry) : listIteratorPrev(&iter, &entry)) { if (putVecEnt != NULL) (*putVecEnt)(vector, entIdx, entry); else *(void **)((long)vector + entIdx * sizeof(void *)) = (void *)entry; entIdx++; } }
int listNotifyObservers(LIST_T *list, LIST_EVENT_T *event) { LIST_OBSERVER_T *observer; LIST_ITERATOR_T iter; listIteratorAttach(&iter, list->observers); for (observer = (LIST_OBSERVER_T *)listIteratorGetCurEntry(&iter); ! listIteratorIsEndOfList(&iter); listIteratorNext(&iter, (LIST_ENTRY_T **)&observer)) { if (observer->select != NULL) { if (! (*observer->select)(observer->extra, event)) continue; } switch (event->type) { case (int) LIST_EVENT_ENTER: if (observer->enter) (*observer->enter)(list, observer->extra, event); break; case (int) LIST_EVENT_LEAVE: if (observer->leave_) (*observer->leave_)(list, observer->extra, event); break; default: listerrno = LIST_ERR_BADARG; return -1; } } return 0; }
void listCat(LIST_T *list, int direction, char *buffer, int bufferSize, char * (*catFunc)(LIST_ENTRY_T *, void *), void *hint) { LIST_ITERATOR_T iter; LIST_ENTRY_T *entry; int curSize; buffer[0] = '\000'; if (direction == 0) direction = LIST_TRAVERSE_FORWARD; LIST_ITERATOR_ZERO_OUT(&iter); listIteratorAttach(&iter, list); if (direction & LIST_TRAVERSE_BACKWARD) listIteratorSetCurEntry(&iter, listGetBackEntry(list), FALSE); curSize = 0; for (entry = listIteratorGetCurEntry(&iter); entry != NULL; (direction & LIST_TRAVERSE_FORWARD) ? listIteratorNext(&iter, &entry) : listIteratorPrev(&iter, &entry)) { char *str; str = (*catFunc)(entry, hint); if (! str) { continue; } if (curSize + strlen(str) > bufferSize - 1) { break; } strcat(buffer, str); curSize += strlen(str); } }
void renderList(sLinkedList* list, sSdlWrapper* wrap) { Uint32 bg = makeColor(255, 50, 25, 175); Uint32 fg = makeColor(255, 75, 50, 200); if(listEmpty(list)) return; sListIterator* it = 0; listHead(list, &it); point* toDraw = 0; int x = 0; int y = 0; while(!listIteratorEnd(it)) { toDraw = (point*)listGet(it); pointGetPos(toDraw, &x, &y); drawBevel(wrap, x*25, y*25, 25, 25, bg, fg); listIteratorNext(it); } free(it); }
LIST_ENTRY_T * listSearchEntry(LIST_T *list, void *subject, bool_t (*equal)(void *, void *, int), int hint) { LIST_ITERATOR_T iter; LIST_ENTRY_T *ent; LIST_ITERATOR_ZERO_OUT(&iter); listIteratorAttach(&iter, list); for (ent = listIteratorGetCurEntry(&iter); ent != NULL; listIteratorNext(&iter, &ent)) { if ((*equal)((void *)ent, subject, hint) == TRUE) return ent; } return NULL; }
void listDump(LIST_T* list) { LIST_ITERATOR_T iter; LIST_ENTRY_T *listEntry; LIST_ITERATOR_ZERO_OUT(&iter); listIteratorAttach(&iter, list); for (listEntry = listIteratorGetCurEntry(&iter); ! listIteratorIsEndOfList(&iter); listIteratorNext(&iter, &listEntry)) { ls_syslog(LOG_DEBUG,"\ %s: Entry=<%x> is in list=<%s>", __func__, listEntry, list->name); } listIteratorDetach(&iter); }