예제 #1
0
파일: list.c 프로젝트: CraigNoble/openlava
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;

}
예제 #2
0
파일: list.c 프로젝트: CraigNoble/openlava
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;
}
예제 #3
0
파일: list.c 프로젝트: CraigNoble/openlava
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);
    }
}
예제 #4
0
파일: list.c 프로젝트: CraigNoble/openlava
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++;
    }
}
예제 #5
0
파일: list.c 프로젝트: FSchumacher/openlava
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;
}
예제 #6
0
파일: list.c 프로젝트: CraigNoble/openlava
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);
    }

}
예제 #7
0
파일: main.c 프로젝트: senilica/IOOPM
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);
}
예제 #8
0
파일: list.c 프로젝트: CraigNoble/openlava
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;
}
예제 #9
0
파일: list.c 프로젝트: CraigNoble/openlava
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);

}