123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #define HOOKS
- #ifndef LINKED_LIST
- #include "linkedList.h"
- #endif
- struct hook {
- LISTEL *start;
- int insertDirection;
- };
- struct hookFunction {
- void (*function)();
- };
- typedef struct hook HOOK;
- typedef struct hookFunction HOOKFUNC;
- void runHook(HOOK * hook) {
- LISTEL * head = hook->start;
- while (head != NULL) {
- /* void *function = head->data; */
- /* ((void*)function)(); */
- ((HOOKFUNC*)(head->data))->function();
- head = head->next;
- }
- }
- void addToHook(HOOK * hook, void (*function)()) {
- HOOKFUNC *hookFunction = malloc(sizeof(HOOKFUNC));
- hookFunction->function = function;
- if (hook->start == NULL)
- {
- LISTEL *element = malloc(sizeof(LISTEL));
- element->data = (void*) hookFunction;
- hook->start = element;
- }
- else if (hook->insertDirection == 0)
- {
- LISTEL *newHead = insertBefore((void*) hookFunction, hook->start);
- hook->start = newHead;
- }
- else
- {
- LISTEL *addAfter = hook->start;
- while (addAfter->next != NULL)
- addAfter = addAfter->next;
- insertAfter((void*) hookFunction, addAfter);
- }
- }
- HOOK * initializeHook(int direction)
- {
- HOOK * theReturn = malloc(sizeof(HOOK));
- theReturn->insertDirection = direction;
- return theReturn;
- }
|