From f371a0c5f32b03e97e4ed2771431891ca4603db6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 17 Nov 2016 10:32:20 +0100 Subject: [PATCH] eliminate unused callback module. what was I thinking when I wrote this? --- src/CMakeLists.txt | 2 -- src/callback.c | 61 --------------------------------------------- src/callback.h | 16 ------------ src/callback.test.c | 51 ------------------------------------- src/test_eressea.c | 1 - 5 files changed, 131 deletions(-) delete mode 100644 src/callback.c delete mode 100644 src/callback.h delete mode 100644 src/callback.test.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 109a212f1..34cea4037 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -99,7 +99,6 @@ set (ERESSEA_SRC prefix.c donations.c eressea.c - callback.c direction.c keyword.c skill.c @@ -205,7 +204,6 @@ set(TESTS_SRC report.test.c summary.test.c travelthru.test.c - callback.test.c direction.test.c economy.test.c json.test.c diff --git a/src/callback.c b/src/callback.c deleted file mode 100644 index 79bd69b71..000000000 --- a/src/callback.c +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include "callback.h" -#include -#include - -static struct reg { - struct reg * next; - HCALLBACK cb; - char *name; -} *registry; - -HCALLBACK create_callback(void(*cbv)(va_list va)) { - HCALLBACK cb; - cb.cbv = cbv; - return cb; -} - -void reset_callbacks(void) { - while (registry) { - struct reg *r = registry; - registry = r->next; - free(r->name); - free(r); - } - registry = 0; -} - -HCALLBACK register_callback(const char *name, void(*cbv)(va_list va)) -{ - struct reg * r = (struct reg *)malloc(sizeof(struct reg)); - r->next = registry; - r->name = _strdup(name); - r->cb.cbv = cbv; - registry = r; - return r->cb; -} - -int find_callback(const char *name, HCALLBACK *result) { - if (result && name) { - struct reg *r; - for (r = registry; r; r = r->next) { - if (strcmp(r->name, name) == 0) { - *result = r->cb; - return 0; - } - } - } - return -1; -} - -int call_callback(HCALLBACK cb, const char *name, ...) { - va_list ap; - if (name) { - int err = find_callback(name, &cb); - if (err) return err; - } - va_start(ap, name); - cb.cbv(ap); - va_end(ap); - return 0; -} diff --git a/src/callback.h b/src/callback.h deleted file mode 100644 index 288a148e9..000000000 --- a/src/callback.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef H_CALLBACK_H -#define H_CALLBACK_H - -#include - -typedef struct { - void(*cbv)(va_list va); -} HCALLBACK; - -HCALLBACK register_callback(const char *name, void(*cbv)(va_list va)); -HCALLBACK create_callback(void(*cbv)(va_list va)); -int find_callback(const char *name, HCALLBACK *result); -int call_callback(HCALLBACK cb, const char *name, ...); -void reset_callbacks(void); - -#endif diff --git a/src/callback.test.c b/src/callback.test.c deleted file mode 100644 index 317cc6d50..000000000 --- a/src/callback.test.c +++ /dev/null @@ -1,51 +0,0 @@ -#include "callback.h" -#include -#include - -void callback(va_list ap) { - int i = (int)va_arg(ap, int); - int *p = va_arg(ap, int *); - *p += i; -} - -static void test_find_callback(CuTest *tc) { - HCALLBACK cb; - reset_callbacks(); - CuAssertIntEquals(tc, -1, find_callback("test", &cb)); - cb = register_callback("test", callback); - CuAssertIntEquals(tc, 0, find_callback("test", &cb)); - reset_callbacks(); -} - -static void test_call_by_handle(CuTest *tc) { - HCALLBACK cb; - int x = 0; - reset_callbacks(); - cb = create_callback(callback); - CuAssertIntEquals(tc, 0, call_callback(cb, 0, 42, &x)); - CuAssertIntEquals(tc, 42, x); - reset_callbacks(); -} - -static void test_call_by_name(CuTest *tc) { - HCALLBACK cb = { 0 }; - HCALLBACK ca = { 0 }; - int x = 0; - reset_callbacks(); - CuAssertIntEquals(tc, -1, call_callback(cb, "test", 42, &x)); - cb = register_callback("test", callback); - CuAssertIntEquals(tc, 0, call_callback(cb, "test", 42, &x)); - CuAssertIntEquals(tc, 42, x); - CuAssertIntEquals(tc, 0, call_callback(ca, "test", 42, &x)); - CuAssertIntEquals(tc, 84, x); - reset_callbacks(); -} - -CuSuite *get_callback_suite(void) -{ - CuSuite *suite = CuSuiteNew(); - SUITE_ADD_TEST(suite, test_find_callback); - SUITE_ADD_TEST(suite, test_call_by_name); - SUITE_ADD_TEST(suite, test_call_by_handle); - return suite; -} diff --git a/src/test_eressea.c b/src/test_eressea.c index 330afd5bc..71cf008f2 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -60,7 +60,6 @@ int RunAllTests(int argc, char *argv[]) { /* self-test */ ADD_SUITE(tests); - ADD_SUITE(callback); ADD_SUITE(json); ADD_SUITE(jsonconf); ADD_SUITE(direction);