From 8dc099b955197c7100937d5fafc60c4b9681a5ab Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 2 Jun 2023 18:04:00 -0700 Subject: til: add til_get_module_names() helper Composite modules that want to provide "all" aliases for modules like rtv have to construct a comma-separated string of all module names, usually filtered by some flags. This helper does just that, but it does add yet another open_memstream() user to revisit when those all get fixed up. --- src/til.c | 30 ++++++++++++++++++++++++++++++ src/til.h | 1 + 2 files changed, 31 insertions(+) diff --git a/src/til.c b/src/til.c index c680db8..ee42e68 100644 --- a/src/til.c +++ b/src/til.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -166,6 +167,35 @@ void til_get_modules(const til_module_t ***res_modules, size_t *res_n_modules) } +char * til_get_module_names(unsigned flags_excluded) +{ + const til_module_t **modules; + size_t n_modules; + char *buf; + size_t bufsz; + FILE *fp; + + /* FIXME TODO: more unportable memstream! */ + fp = open_memstream(&buf, &bufsz); + if (!fp) + return NULL; + + til_get_modules(&modules, &n_modules); + for (size_t i = 0, j = 0; i < n_modules; i++) { + const til_module_t *mod = modules[i]; + + if ((mod->flags & flags_excluded)) + continue; + + fprintf(fp, "%s%s", j ? "," : "", mod->name); + j++; + } + fclose(fp); + + return buf; +} + + static void module_render_fragment(til_module_context_t *context, til_stream_t *stream, til_threads_t *threads, unsigned ticks, til_fb_fragment_t **fragment_ptr) { const til_module_t *module; diff --git a/src/til.h b/src/til.h index 6388a32..0a0cd6d 100644 --- a/src/til.h +++ b/src/til.h @@ -42,6 +42,7 @@ void til_quiesce(void); void til_shutdown(void); const til_module_t * til_lookup_module(const char *name); void til_get_modules(const til_module_t ***res_modules, size_t *res_n_modules); +char * til_get_module_names(unsigned flags_excluded); void til_module_render(til_module_context_t *context, til_stream_t *stream, unsigned ticks, til_fb_fragment_t **fragment_ptr); int til_module_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup, til_module_context_t **res_context); til_module_context_t * til_module_destroy_context(til_module_context_t *context, til_stream_t *stream); -- cgit v1.2.1