index — thing @ f374d62fedbd4198fca488799457c925e6fe4eb5

A little something I'm working on

plugins: find configs
crispy-caesus crispy@crispy-caesus.eu
Wed, 23 Sep 2026 10:48:15 +0200
commit

f374d62fedbd4198fca488799457c925e6fe4eb5

parent

d37a9d14311d58e370b9de38e7be99dcd6d3ca5d

3 files changed, 41 insertions(+), 11 deletions(-)

jump to
M libthingplugins/include/plugins.h → libthingplugins/include/plugins.h

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

-int readplugins(void); +int readplugins(char **plugins);
M libthingplugins/src/plugins.c → libthingplugins/src/plugins.c

@@ -1,29 +1,44 @@

#include <dirent.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -int readplugins(void) { +int readplugins(char **plugins) { struct dirent *de; DIR *dr = opendir("/usr/share/thing/plugins/"); if (dr == NULL) { - printf("Could not open plugin capability directory " + perror("Could not open plugin capability directory " "(/usr/share/thing/plugins/)"); return 1; } + int i = 0; // plugin counter while ((de = readdir(dr)) != NULL) { - // if filename shorter than x.toml -> 6 - if (sizeof(de->d_name) / sizeof(de->d_name[0]) - 1 < 6) + // find actual name end, as d_name is fixed length 256 bytes + char *nend = strchr(de->d_name, '\0'); + if (nend - de->d_name < 7) + continue; + + // only match toml files + char ext[6]; + strncpy(ext, nend - 5, 6); + if ((strcmp(ext, ".toml"))) continue; - // if it ends with toml - char *ext = strrchr(de->d_name, '.'); - if (!(strcmp(ext, ".toml"))) - printf("%s\n", de->d_name); + // retrieve only plugin name from filename + // add it to plugins[] + int nlen = nend - de->d_name - 5; + plugins[i] = malloc(nlen); + strncpy(plugins[i], de->d_name, nlen); + i++; } - closedir(dr); + + // add end signal + if (i < 256) + plugins[i] = ""; + return 0; }
M thing/src/thing.c → thing/src/thing.c

@@ -3,12 +3,27 @@ #include <libthingterm/menu.h>

#include <libthingterm/term.h> #include <stdio.h> +#include <string.h> #include <termios.h> int main(void) { uint8_t ret = 0; struct termios old_term; - readplugins(); + + // scan for plugins + char *plugins[256]; // hardcoded limit of 255 for plugins + if (readplugins(plugins)) + return 1; + int i; + printf("found plugins:\n"); + for (i = 0; i < 256; i++) { + if (!strcmp(plugins[i], "")) + goto plugins_done; + printf(" %s\n", plugins[i]); + } +plugins_done: + + // setup term setup_term(&old_term); static char *elements[] = {"hi", "hello", "what's up", "dang",