From 7a77cc1a7c6c05c6623d78b5a895f2f004ba6cf9 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Wed, 20 Nov 2019 12:50:20 -0800 Subject: settings: add setting_desc_t.random() method To facilitate random setting of these flexible string-oriented settings, support a random helper supplied with the description. This helper would return a valid random string to be used with the respective setting being described. Immediate use case is the rtv module, which also gets fixed up to use it in this commit. --- src/modules/rtv/rtv.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/rtv/rtv.c b/src/modules/rtv/rtv.c index a9d0399..c4c6dd2 100644 --- a/src/modules/rtv/rtv.c +++ b/src/modules/rtv/rtv.c @@ -73,7 +73,13 @@ static char * randomize_module_setup(const rototiller_module_t *module) return NULL; while (module->setup(settings, &desc) > 0) { - if (desc->values) { + if (desc->random) { + char *value; + + value = desc->random(); + settings_add_value(settings, desc->key, value); + free(value); + } else if (desc->values) { int n; for (n = 0; desc->values[n]; n++); -- cgit v1.2.3