summaryrefslogtreecommitdiff
path: root/src/rototiller.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2019-11-10 18:49:28 -0800
committerVito Caputo <vcaputo@pengaru.com>2019-11-10 18:49:28 -0800
commit44ec797349713f28314bd329bee940cd55fad411 (patch)
tree2128c6ba385d4969b30b54259791811df315daf4 /src/rototiller.c
parent4b82076cb381f91c1225eb39efa924e935043d8b (diff)
settings: s/setting_desc_new/setting_desc_clone/
Slight refactor to make call sites less annoying. Now takes a (setting_desc_t *) instead of the members as discrete parameters, and returns an errno on error so callers can simply propagate error codes out rather than having to get access to errno defines, check for NULL and return -ENOMEM etc. It also makes the call sites self documenting by employing designated initializers in compound literals for the supplied setting_desc_t. This is in prep for runtime-configurable module settings.
Diffstat (limited to 'src/rototiller.c')
-rw-r--r--src/rototiller.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/rototiller.c b/src/rototiller.c
index 92821c2..7203ca2 100644
--- a/src/rototiller.c
+++ b/src/rototiller.c
@@ -162,17 +162,18 @@ static int setup_video(settings_t *settings, setting_desc_t **next_setting)
"sdl",
NULL,
};
-
- desc = setting_desc_new("Video Backend",
- NULL,
- "[a-z]+",
- DEFAULT_VIDEO,
- values,
- NULL);
- if (!desc)
- return -ENOMEM;
-
- *next_setting = desc;
+ int r;
+
+ r = setting_desc_clone(&(setting_desc_t){
+ .name = "Video Backend",
+ .key = NULL,
+ .regex = "[a-z]+",
+ .preferred = DEFAULT_VIDEO,
+ .values = values,
+ .annotations = NULL
+ }, next_setting);
+ if (r < 0)
+ return r;
return 1;
}
@@ -207,22 +208,23 @@ static int setup_module(settings_t *settings, setting_desc_t **next_setting)
const char *annotations[nelems(modules) + 1] = {};
setting_desc_t *desc;
unsigned i;
+ int r;
for (i = 0; i < nelems(modules); i++) {
values[i] = modules[i]->name;
annotations[i] = modules[i]->description;
}
- desc = setting_desc_new("Renderer Module",
- NULL,
- "[a-zA-Z0-9]+",
- DEFAULT_MODULE,
- values,
- annotations);
- if (!desc)
- return -ENOMEM;
-
- *next_setting = desc;
+ r = setting_desc_clone(&(setting_desc_t){
+ .name = "Renderer Module",
+ .key = NULL,
+ .regex = "[a-zA-Z0-9]+",
+ .preferred = DEFAULT_MODULE,
+ .values = values,
+ .annotations = annotations
+ }, next_setting);
+ if (r < 0)
+ return r;
return 1;
}
© All Rights Reserved