From 0cd8ff510370153f4728a5cc46cb4d4123ae553f Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Wed, 13 May 2020 12:18:25 +0200
Subject: [PATCH] Register functions in modules, using .def files (gitlab
 things that there is some php files in the project...)

---
 inc/lektor/{config.inc => config.def} |  0
 inc/lektor/config.h                   |  2 +-
 inc/lektor/module/module_sdl2.h       |  1 -
 inc/lektor/reg.h                      |  9 +++++----
 src/database/config.c                 |  2 +-
 src/module/module_sdl2.c              | 13 +++++++++++++
 src/module/module_x11.c               | 13 +++++++++++++
 7 files changed, 33 insertions(+), 7 deletions(-)
 rename inc/lektor/{config.inc => config.def} (100%)

diff --git a/inc/lektor/config.inc b/inc/lektor/config.def
similarity index 100%
rename from inc/lektor/config.inc
rename to inc/lektor/config.def
diff --git a/inc/lektor/config.h b/inc/lektor/config.h
index 22c200b1..e7d75bd1 100644
--- a/inc/lektor/config.h
+++ b/inc/lektor/config.h
@@ -12,7 +12,7 @@ struct lkt_state;
 #define value(key, val)     key " = " val "\n"
 #define value_opt(key, val) value(key, val)
 static const char *const lkt_default_config_file =
-#include <lektor/config.inc>
+#include <lektor/config.def>
     ;
 #undef value
 #undef value_opt
diff --git a/inc/lektor/module/module_sdl2.h b/inc/lektor/module/module_sdl2.h
index cdd608eb..30dea574 100644
--- a/inc/lektor/module/module_sdl2.h
+++ b/inc/lektor/module/module_sdl2.h
@@ -17,7 +17,6 @@ int load_sdl2(void *mod, struct lkt_state *srv, void *handle);
 bool module_sdl2_new(struct lkt_win *const win);
 void module_sdl2_close(struct lkt_win *const win);
 void module_sdl2_free(struct lkt_win *const win);
-void module_sdl2_attach(struct lkt_win *const win, void *server);
 
 bool module_sdl2_toggle_pause(struct lkt_win *const win);
 bool module_sdl2_load_file(struct lkt_win *const win, const char *filepath);
diff --git a/inc/lektor/reg.h b/inc/lektor/reg.h
index d156b68b..50049e70 100644
--- a/inc/lektor/reg.h
+++ b/inc/lektor/reg.h
@@ -6,14 +6,15 @@ struct lkt_state;
    with a name that can be generated or red from a config file. */
 struct module_reg {
     const char *name;
-    int (*func)(void *, struct lkt_state *, void *);
+    void (*func)(void);
 };
 
 extern struct module_reg *reg;
 
-#define REG_BEGIN(reg)  struct module_reg reg[] = {
-#define REG_ADD(__func) { .name = #__func,  .func = __func  },
-#define REG_END()       { .name = NULL,     .func = NULL    } };
+#define REG_BEGIN(reg)          struct module_reg reg[] = {
+#define REG_ADD(__f)            { .name = #__f,  .func = (void(*)(void)) __f    },
+#define REG_ADD_NAMED(__n, __f) { .name = __n,   .func = (void(*)(void)) __f    },
+#define REG_END()               { .name = NULL,  .func = NULL                   } };
 
 /* If handle is NULL, file is unused and the reg is red. Otherwise,
    we use dlfcn to search for the symbol which is returned. If *handle
diff --git a/src/database/config.c b/src/database/config.c
index 3c53210f..098377b2 100644
--- a/src/database/config.c
+++ b/src/database/config.c
@@ -171,7 +171,7 @@ database_validate_conf(volatile sqlite3 *db)
                       section);                                               \
         return false;                                                         \
     }
-#include <lektor/config.inc>
+#include <lektor/config.def>
 #undef section
 #undef value
 #undef value_opt
diff --git a/src/module/module_sdl2.c b/src/module/module_sdl2.c
index e2f75ec4..50aa7e1d 100644
--- a/src/module/module_sdl2.c
+++ b/src/module/module_sdl2.c
@@ -6,6 +6,7 @@
 #include <lektor/module/mpv.h>
 #include <mthread/mthread.h>
 #include <lektor/thread.h>
+#include <lektor/reg.h>
 
 #include <sched.h>
 #include <assert.h>
@@ -405,3 +406,15 @@ module_sdl2_handle_events(struct lkt_win *const win, volatile sqlite3 *db,
     UNUSED(win, db, mpd_idle_events);
     return true;
 }
+
+REG_BEGIN(sdl2_reg)
+REG_ADD_NAMED("new",    module_sdl2_new)
+REG_ADD_NAMED("free",   module_sdl2_free)
+REG_ADD_NAMED("handle", module_sdl2_handle_events)
+REG_ADD(module_sdl2_close)
+REG_ADD(module_sdl2_toggle_pause)
+REG_ADD(module_sdl2_load_file)
+REG_ADD(module_sdl2_set_volume)
+REG_ADD(module_sdl2_get_duration)
+REG_ADD(module_sdl2_get_elapsed)
+REG_END()
diff --git a/src/module/module_x11.c b/src/module/module_x11.c
index d9231806..9c10b1f4 100644
--- a/src/module/module_x11.c
+++ b/src/module/module_x11.c
@@ -5,6 +5,7 @@
 #include <lektor/module/mpv.h>
 #include <lektor/database.h>
 #include <lektor/commands.h>
+#include <lektor/reg.h>
 
 #include <string.h>
 #include <unistd.h>
@@ -276,3 +277,15 @@ module_x11_handle_events(struct lkt_win *const win, volatile sqlite3 *db,
            ! lmpv_handle(win, xwin->mpv, db, mpd_idle_events,
                          &xwin->mpv_time_pos, &xwin->mpv_duration);
 }
+
+REG_BEGIN(x11_reg)
+REG_ADD_NAMED("new",    module_x11_new)
+REG_ADD_NAMED("free",   module_x11_free)
+REG_ADD_NAMED("handle", module_x11_handle_events)
+REG_ADD(module_x11_close)
+REG_ADD(module_x11_toggle_pause)
+REG_ADD(module_x11_load_file)
+REG_ADD(module_x11_set_volume)
+REG_ADD(module_x11_get_duration)
+REG_ADD(module_x11_get_elapsed)
+REG_END()
-- 
GitLab