index — thing @ d37a9d14311d58e370b9de38e7be99dcd6d3ca5d

A little something I'm working on

plugins: scan dir
crispy-caesus crispy@crispy-caesus.eu
Fri, 18 Sep 2026 14:18:24 +0200
commit

d37a9d14311d58e370b9de38e7be99dcd6d3ca5d

parent

087b8f718661f612ad52e764cfde5a8331476444

A libthingplugins/include/plugins.h

@@ -0,0 +1,1 @@

+int readplugins(void);
A libthingplugins/meson.build

@@ -0,0 +1,43 @@

+project( + 'libthingplugins', + 'c', + version: '0.0.1', + default_options: [ + 'c_std=c99', + 'warning_level=3', + ], +) + +libthingplugins_sources = files( + 'src/plugins.c', +) + +libthingplugins_headers = files( + 'include/plugins.h', +) + +libthingplugins_inc = include_directories('include') + +libthingplugins = library( + 'thingplugins', + libthingplugins_sources, + include_directories: libthingplugins_inc, + install: true, +) + +install_headers( + libthingplugins_headers, + subdir: 'libthingplugins', +) + +pkg = import('pkgconfig') + +pkg.generate( + libthingplugins, + name: 'libthingplugins', + description: 'thing\'s plugins library, to fetch and execute them', + version: meson.project_version(), + filebase: 'libthingplugins', + subdirs: 'libthingplugins', +) +
A libthingplugins/src/plugins.c

@@ -0,0 +1,29 @@

+#include <dirent.h> +#include <stdio.h> +#include <string.h> + +int readplugins(void) { + struct dirent *de; + + DIR *dr = opendir("/usr/share/thing/plugins/"); + + if (dr == NULL) { + printf("Could not open plugin capability directory " + "(/usr/share/thing/plugins/)"); + return 1; + } + + while ((de = readdir(dr)) != NULL) { + // if filename shorter than x.toml -> 6 + if (sizeof(de->d_name) / sizeof(de->d_name[0]) - 1 < 6) + continue; + + // if it ends with toml + char *ext = strrchr(de->d_name, '.'); + if (!(strcmp(ext, ".toml"))) + printf("%s\n", de->d_name); + } + + closedir(dr); + return 0; +}
M thing/meson.build → thing/meson.build

@@ -11,6 +11,7 @@ ]

project_dependencies = [ dependency('libthingterm'), + dependency('libthingplugins'), ] executable(
M thing/src/thing.c → thing/src/thing.c

@@ -1,3 +1,4 @@

+#include <libthingplugins/plugins.h> #include <libthingterm/menu.h> #include <libthingterm/term.h>

@@ -7,6 +8,7 @@

int main(void) { uint8_t ret = 0; struct termios old_term; + readplugins(); setup_term(&old_term); static char *elements[] = {"hi", "hello", "what's up", "dang",