diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/rtv/rtv.c | 4 | ||||
-rw-r--r-- | src/til.c | 25 | ||||
-rw-r--r-- | src/til.h | 2 |
3 files changed, 21 insertions, 10 deletions
diff --git a/src/modules/rtv/rtv.c b/src/modules/rtv/rtv.c index 19dcdca..742b2bc 100644 --- a/src/modules/rtv/rtv.c +++ b/src/modules/rtv/rtv.c @@ -155,10 +155,10 @@ static void setup_next_channel(rtv_context_t *ctxt, unsigned ticks) ctxt->channel = &ctxt->channels[i]; if (!ctxt->channel->settings) { - char *settings; + char *settings = NULL; txt_t *caption; - settings = til_module_randomize_setup(ctxt->channel->module, &ctxt->channel->module_setup); + (void) til_module_randomize_setup(ctxt->channel->module, &ctxt->channel->module_setup, &settings); caption = txt_newf("Title: %s%s%s\nDescription: %s%s%s", ctxt->channel->module->name, ctxt->channel->module->author ? "\nAuthor: " : "", @@ -236,22 +236,24 @@ int til_module_setup(til_settings_t *settings, til_setting_t **res_setting, cons } -/* 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) +/* originally taken from rtv, this randomizes a module's setup @res_setup, args @res_arg + * returns 0 on no setup, 1 on setup successful with results stored @res_*, -errno on error. + */ +int til_module_randomize_setup(const til_module_t *module, void **res_setup, char **res_arg) { til_settings_t *settings; til_setting_t *setting; const til_setting_desc_t *desc; - char *arg; + int r = 1; assert(module); if (!module->setup) - return NULL; + return 0; settings = til_settings_new(NULL); if (!settings) - return NULL; + return -ENOMEM; while (module->setup(settings, &setting, &desc, res_setup) > 0) { if (desc->random) { @@ -273,8 +275,17 @@ char * til_module_randomize_setup(const til_module_t *module, void **res_setup) } } - arg = til_settings_as_arg(settings); + if (res_arg) { + char *arg; + + arg = til_settings_as_arg(settings); + if (!arg) + r = -ENOMEM; + else + *res_arg = arg; + } + til_settings_free(settings); - return arg; + return r; } @@ -33,6 +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); +int til_module_randomize_setup(const til_module_t *module, void **res_setup, char **res_arg); #endif |