コード例 #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
void
listIteratorNext(LIST_ITERATOR_T *iter,
                 LIST_ENTRY_T **next)
{
    iter->curEnt = iter->curEnt->forw;
    *next = listIteratorGetCurEntry(iter);
}
コード例 #3
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;
}
コード例 #4
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);
    }
}
コード例 #5
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++;
    }
}
コード例 #6
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;
}
コード例 #7
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);
    }

}
コード例 #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);

}
コード例 #10
0
ファイル: list.c プロジェクト: CraigNoble/openlava
void
listIteratorPrev(LIST_ITERATOR_T *iter, LIST_ENTRY_T **prev)
{
    iter->curEnt = iter->curEnt->back;
    *prev = listIteratorGetCurEntry(iter);
}