summaryrefslogtreecommitdiff
path: root/src/help.c
diff options
context:
space:
mode:
authorAriadne Conill <ariadne@dereferenced.org>2021-12-10 14:33:52 -0600
committerTimo Teräs <timo.teras@iki.fi>2021-12-14 21:10:26 +0200
commit0fd415faf57bdf6e3e459b8315c3d9c8d69b0136 (patch)
treebff68e521ba540effc90868e99c40a972e2eaf05 /src/help.c
parenteab6645cb8c03282fbe6b8484c3fd390cfd91a9c (diff)
downloadapk-tools-0fd415faf57bdf6e3e459b8315c3d9c8d69b0136.tar.gz
apk-tools-0fd415faf57bdf6e3e459b8315c3d9c8d69b0136.tar.bz2
apk-tools-0fd415faf57bdf6e3e459b8315c3d9c8d69b0136.tar.xz
apk-tools-0fd415faf57bdf6e3e459b8315c3d9c8d69b0136.zip
applet: rework APK_DEFINE_APPLET to use constructor attribute
this allows the applet registration to work in a portable way, without having to weird things with the linker. ref #10794 [TT: rebased for 2.12]
Diffstat (limited to 'src/help.c')
-rw-r--r--src/help.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/help.c b/src/help.c
index 3034da2..c8bba70 100644
--- a/src/help.c
+++ b/src/help.c
@@ -10,6 +10,27 @@
#include "apk_applet.h"
#include "apk_print.h"
+static LIST_HEAD(apk_applet_list);
+
+#define apk_applet_foreach(iter) list_for_each_entry(iter, &apk_applet_list, node)
+
+void apk_applet_register(struct apk_applet *applet)
+{
+ list_init(&applet->node);
+ list_add_tail(&applet->node, &apk_applet_list);
+}
+
+struct apk_applet *apk_applet_find(const char *name)
+{
+ struct apk_applet *a;
+
+ apk_applet_foreach(a) {
+ if (strcmp(name, a->name) == 0)
+ return a;
+ }
+ return NULL;
+}
+
static inline int is_group(struct apk_applet *applet, const char *topic)
{
if (!applet) return strcasecmp(topic, "apk") == 0;
@@ -19,7 +40,7 @@ static inline int is_group(struct apk_applet *applet, const char *topic)
return 0;
}
-void apk_help(struct apk_applet *applet)
+void apk_applet_help(struct apk_applet *applet)
{
#include "help.h"