diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2019-11-10 18:49:28 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2019-11-10 18:49:28 -0800 |
commit | 44ec797349713f28314bd329bee940cd55fad411 (patch) | |
tree | 2128c6ba385d4969b30b54259791811df315daf4 /src/sdl_fb.c | |
parent | 4b82076cb381f91c1225eb39efa924e935043d8b (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/sdl_fb.c')
-rw-r--r-- | src/sdl_fb.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/src/sdl_fb.c b/src/sdl_fb.c index 80a63dd..f85e9ca 100644 --- a/src/sdl_fb.c +++ b/src/sdl_fb.c @@ -36,18 +36,18 @@ int sdl_fb_setup(const settings_t *settings, setting_desc_t **next_setting) "on", NULL }; - setting_desc_t *desc; - - desc = setting_desc_new("SDL Fullscreen Mode", - "fullscreen", - NULL, - values[0], - values, - NULL); - if (!desc) - return -ENOMEM; - - *next_setting = desc; + int r; + + r = setting_desc_clone(&(setting_desc_t){ + .name = "SDL Fullscreen Mode", + .key = "fullscreen", + .regex = NULL, + .preferred = values[0], + .values = values, + .annotations = NULL + }, next_setting); + if (r < 0) + return r; return 1; } @@ -57,18 +57,19 @@ int sdl_fb_setup(const settings_t *settings, setting_desc_t **next_setting) size = settings_get_value(settings, "size"); if (!size) { - setting_desc_t *desc; - - desc = setting_desc_new("SDL Window size", - "size", - "[1-9][0-9]*[xX][1-9][0-9]*", - "640x480", - NULL, - NULL); - if (!desc) - return -ENOMEM; - - *next_setting = desc; + int r; + + r = setting_desc_clone(&(setting_desc_t){ + .name = "SDL Window size", + .key = "size", + .regex = "[1-9][0-9]*[xX][1-9][0-9]*", + .preferred = "640x480", + .values = NULL, + .annotations = NULL + }, + next_setting); + if (r < 0) + return r; return 1; } |