summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-04-22 12:19:49 -0700
committerVito Caputo <vcaputo@pengaru.com>2022-04-22 12:19:49 -0700
commit7f872664738b45c982f3e95749f2136a0de4c19a (patch)
tree6e29ea43fba6350e5e413b56d065811455bf720a /src/modules
parent10fca58ba81c3c9bc14212d4ae4c7bc83deafcec (diff)
til: add til_module_randomize_setup() from rtv
This commit pulls the setup randomizer out of rtv into libtil proper, so other modules may make use of it. Other than adding an assert no functional changes occurred. It may make sense to split this into two functions; one which takes a til_module_t as-is, and a lower-level bare setup function callback based function that doesn't know about til_module_t the former would call into. That way generic setup randomization can occur (the same setup machinery is used in video contexts for example) without necessarily having a til_module_t on hand.
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/rtv/rtv.c43
1 files changed, 1 insertions, 42 deletions
diff --git a/src/modules/rtv/rtv.c b/src/modules/rtv/rtv.c
index a236f96..19dcdca 100644
--- a/src/modules/rtv/rtv.c
+++ b/src/modules/rtv/rtv.c
@@ -110,47 +110,6 @@ static void randomize_channels(rtv_context_t *ctxt)
}
-static char * randomize_module_setup(const til_module_t *module, void **res_setup)
-{
- til_settings_t *settings;
- til_setting_t *setting;
- const til_setting_desc_t *desc;
- char *arg;
-
- if (!module->setup)
- return NULL;
-
- settings = til_settings_new(NULL);
- if (!settings)
- return NULL;
-
- while (module->setup(settings, &setting, &desc, res_setup) > 0) {
- if (desc->random) {
- char *value;
-
- value = desc->random();
- til_settings_add_value(settings, desc->key, value, desc);
- free(value);
- } else if (desc->values) {
- int n;
-
- for (n = 0; desc->values[n]; n++);
-
- n = rand() % n;
-
- til_settings_add_value(settings, desc->key, desc->values[n], desc);
- } else {
- til_settings_add_value(settings, desc->key, desc->preferred, desc);
- }
- }
-
- arg = til_settings_as_arg(settings);
- til_settings_free(settings);
-
- return arg;
-}
-
-
static void setup_next_channel(rtv_context_t *ctxt, unsigned ticks)
{
time_t now = time(NULL);
@@ -199,7 +158,7 @@ static void setup_next_channel(rtv_context_t *ctxt, unsigned ticks)
char *settings;
txt_t *caption;
- settings = randomize_module_setup(ctxt->channel->module, &ctxt->channel->module_setup);
+ settings = til_module_randomize_setup(ctxt->channel->module, &ctxt->channel->module_setup);
caption = txt_newf("Title: %s%s%s\nDescription: %s%s%s",
ctxt->channel->module->name,
ctxt->channel->module->author ? "\nAuthor: " : "",
© All Rights Reserved