diff options
author | Michael Smith <mikesmiffy128@gmail.com> | 2022-07-23 23:47:26 +0100 |
---|---|---|
committer | Michael Smith <mikesmiffy128@gmail.com> | 2022-07-23 23:47:26 +0100 |
commit | c8d7588251fd4fe63ac6afe2a90ca7066c786609 (patch) | |
tree | f547831424d20c6f1b3f2b6bdea97c2f53502deb /src/build/cmeta.c | |
parent | 8f5673d5f4e63b158b1cd2a2aef874ac83b3662d (diff) |
Add event system
Diffstat (limited to 'src/build/cmeta.c')
-rw-r--r-- | src/build/cmeta.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/build/cmeta.c b/src/build/cmeta.c index bf18903..3d49927 100644 --- a/src/build/cmeta.c +++ b/src/build/cmeta.c @@ -266,4 +266,36 @@ void cmeta_conmacros(const struct cmeta *cm, } } +void cmeta_evdefmacros(const struct cmeta *cm, void (*cb_def)(const char *name)) { + Token *tp = (Token *)cm; + if (!tp || !tp->next || !tp->next->next) return; // DEF_EVENT, (, name + while (tp) { + if (equal(tp, "DEF_EVENT") && equal(tp->next, "(")) { + tp = tp->next->next; + char *name = malloc(tp->len + 1); + if (!name) die1("couldn't allocate memory"); + memcpy(name, tp->loc, tp->len); + name[tp->len] = '\0'; + cb_def(name); + } + tp = tp->next; + } +} + +void cmeta_evhandlermacros(const struct cmeta *cm, const char *modname, + void (*cb_handler)(const char *evname, const char *modname)) { + Token *tp = (Token *)cm; + while (tp) { + if (equal(tp, "HANDLE_EVENT") && equal(tp->next, "(")) { + tp = tp->next->next; + char *name = malloc(tp->len + 1); + if (!name) die1("couldn't allocate memory"); + memcpy(name, tp->loc, tp->len); + name[tp->len] = '\0'; + cb_handler(name, modname); + } + tp = tp->next; + } +} + // vi: sw=4 ts=4 noet tw=80 cc=80 |