diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/rtv/rtv.c | 43 | ||||
-rw-r--r-- | src/til.c | 44 | ||||
-rw-r--r-- | src/til.h | 1 |
3 files changed, 46 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: " : "", @@ -234,3 +234,47 @@ int til_module_setup(til_settings_t *settings, til_setting_t **res_setting, cons return 0; } + + +/* originally taken from rtv, this randomizes a module's setup @res_setup, returning args form as well */ +char * til_module_randomize_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; + + assert(module); + + 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; +} @@ -33,5 +33,6 @@ void til_module_render(const til_module_t *module, void *context, unsigned ticks int til_module_create_context(const til_module_t *module, unsigned ticks, void *setup, void **res_context); void * til_module_destroy_context(const til_module_t *module, void *context); int til_module_setup(til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup); +char * til_module_randomize_setup(const til_module_t *module, void **res_setup); #endif |