|
@@ -16,15 +16,25 @@ struct hookFunction {
|
|
|
typedef struct hook HOOK;
|
|
|
typedef struct hookFunction HOOKFUNC;
|
|
|
|
|
|
+HOOK * initializeHook(int direction)
|
|
|
+{
|
|
|
+ HOOK * theReturn = malloc(sizeof(HOOK));
|
|
|
+ theReturn->insertDirection = direction;
|
|
|
+ return theReturn;
|
|
|
+}
|
|
|
+
|
|
|
void runHook(HOOK * hook) {
|
|
|
- LISTEL * head = hook->start;
|
|
|
- while (head != NULL) {
|
|
|
- ((HOOKFUNC*)(head->data))->function();
|
|
|
- head = head->next;
|
|
|
+ if (hook != NULL) {
|
|
|
+ LISTEL * head = hook->start;
|
|
|
+ while (head != NULL) {
|
|
|
+ ((HOOKFUNC*)(head->data))->function();
|
|
|
+ head = head->next;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void addToHook(HOOK * hook, void (*function)()) {
|
|
|
+ if (hook == NULL) hook = initializeHook(1);
|
|
|
HOOKFUNC *hookFunction = malloc(sizeof(HOOKFUNC));
|
|
|
hookFunction->function = function;
|
|
|
if (hook->start == NULL)
|
|
@@ -46,10 +56,3 @@ void addToHook(HOOK * hook, void (*function)()) {
|
|
|
insertAfter((void*) hookFunction, addAfter);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-HOOK * initializeHook(int direction)
|
|
|
-{
|
|
|
- HOOK * theReturn = malloc(sizeof(HOOK));
|
|
|
- theReturn->insertDirection = direction;
|
|
|
- return theReturn;
|
|
|
-}
|