From 9d64c336f82a14f19a344825df2ff713aa4e9f08 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 9 Jul 2023 17:55:22 -0700 Subject: til: introduce til_module_setup_full() This moves the core til_module_setup() functionality out into a more composable helper with an eye towards all meta-modules using it for doing their module setup instead of all the ad-hoc stuff occurring presently. Since til_module_setup_full() needs more paramaters to influence its behavior, it's not directly usable as a "setup_func". But is trivially wrapped into one, which is what til_module_setup() has now become. It's in the wrapper that users are expected to do specify what's necessary for influencing til_module_setup_full() to do what's appropriate for their needs. --- src/til.c | 71 +++++++++++++++++++++++++++++++++++++++------------------------ src/til.h | 1 + 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/src/til.c b/src/til.c index d343d2a..f8e8d4a 100644 --- a/src/til.c +++ b/src/til.c @@ -499,45 +499,44 @@ int til_module_create_context(const til_module_t *module, til_stream_t *stream, } -/* select module if not yet selected, then setup the module. */ -int til_module_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup) +int til_module_setup_full(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup, const char *name, const char *preferred, unsigned flags_excluded, const char **exclusions) { + const char *module_name; til_setting_t *setting; const til_module_t *module; - const char *name; - name = til_settings_get_value_by_idx(settings, 0, &setting); - if (!name || !setting->desc) { + assert(settings); + assert(name); + assert(preferred); + + module_name = til_settings_get_value_by_idx(settings, 0, &setting); + if (!module_name || !setting->desc) { const char *values[nelems(modules) + 1] = {}; const char *annotations[nelems(modules) + 1] = {}; - const til_settings_t *parent; int r, filtered = 1; - /* Only disable filtering if a *valid* name is providead. + /* Only disable filtering if a *valid* module_name is providead. * This is so fat-fingered names don't suddenly include a bunch of broken options. */ - if (name && til_lookup_module(name)) + if (module_name && til_lookup_module(module_name)) filtered = 0; - parent = til_settings_get_parent(settings); - for (unsigned i = 0, j = 0; i < nelems(modules); i++) { - /* XXX: This only skips experimental modules when no module setting was pre-specified, - * which allows accessing the experimental modules via the CLI without showing them - * in the interactive setup where the desc provides the displayed list of values before - * the module setting gets added. It seems a bit kludge-y and fragile, but works well - * enough for now to get at the experimental modules during testing/development. - * - * XXX: To enable using this in nested setup scenarios, where HERMETIC modules really - * shouldn't be listed, it now skips hermetic if settings->parent is set. That's - * used to imply this isn't the "root" module setup, hence hermetic is inappropriate. - */ if (filtered) { - if (modules[i]->flags & TIL_MODULE_EXPERIMENTAL) + if (modules[i]->flags & flags_excluded) continue; - if (modules[i]->flags & (parent ? TIL_MODULE_HERMETIC : 0)) - continue; + if (exclusions) { + const char *excl = *exclusions; + + for (; excl; excl++) { + if (!strcasecmp(excl, modules[i]->name)) + break; + } + + if (excl) + continue; + } } values[j] = modules[i]->name; @@ -547,10 +546,10 @@ int til_module_setup(const til_settings_t *settings, til_setting_t **res_setting r = til_setting_desc_new( settings, &(til_setting_spec_t){ - .name = "Renderer module", + .name = name, .key = NULL, .regex = "[a-zA-Z0-9]+", - .preferred = parent ? TIL_DEFAULT_NESTED_MODULE : TIL_DEFAULT_ROOT_MODULE, + .preferred = preferred, .values = values, .annotations = annotations, .as_label = 1 @@ -558,12 +557,12 @@ int til_module_setup(const til_settings_t *settings, til_setting_t **res_setting if (r < 0) return r; - *res_setting = name ? setting : NULL; + *res_setting = module_name ? setting : NULL; return 1; } - module = til_lookup_module(name); + module = til_lookup_module(module_name); if (!module) return -EINVAL; @@ -577,6 +576,24 @@ int til_module_setup(const til_settings_t *settings, til_setting_t **res_setting } +/* select module if not yet selected, then setup the module. */ +int til_module_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup) +{ + const til_settings_t *parent; + + parent = til_settings_get_parent(settings); + + return til_module_setup_full(settings, + res_setting, + res_desc, + res_setup, + "Renderer Module", + parent ? TIL_DEFAULT_NESTED_MODULE : TIL_DEFAULT_ROOT_MODULE, + (TIL_MODULE_EXPERIMENTAL | (parent ? TIL_MODULE_HERMETIC : 0)), + NULL); +} + + /* originally taken from rtv, this randomizes a module's setup @res_setup, args @res_arg * returns 0 on on setup successful with results stored @res_*, -errno on error. */ diff --git a/src/til.h b/src/til.h index 6ec43e6..eea8009 100644 --- a/src/til.h +++ b/src/til.h @@ -48,6 +48,7 @@ void til_module_render(til_module_context_t *context, til_stream_t *stream, unsi int til_module_create_contexts(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup, size_t n_contexts, til_module_context_t **res_contexts); 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); +int til_module_setup_full(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup, const char *name, const char *preferred, unsigned flags_excluded, const char **exclusions); int til_module_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup); int til_module_setup_randomize(const til_module_t *module, til_settings_t *settings, unsigned seed, til_setup_t **res_setup, char **res_arg); int til_module_setup_finalize(const til_module_t *module, const til_settings_t *module_settings, til_setup_t **res_setup); -- cgit v1.2.3