diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2022-03-11 11:42:44 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2022-03-11 11:45:00 -0800 |
commit | 078c3790b8b30b2198480160315edde3f884a42d (patch) | |
tree | f4fc86a6f91b18370053d4bf858e17ebfc45958d | |
parent | 34c28d6f7b8d52b760d0669d66c07d4295980ecc (diff) |
main: simplify setup_from_args()
Just removing some copy pasta from the error paths, nothing
functionally different.
-rw-r--r-- | src/main.c | 37 |
1 files changed, 15 insertions, 22 deletions
@@ -109,45 +109,38 @@ static int setup_video(til_settings_t *settings, til_setting_desc_t **next_setti /* returns negative value on error, 0 when settings unchanged from args, 1 when changed */ static int setup_from_args(til_args_t *args, setup_t *res_setup) { - int r, changes = 0; - setup_t setup; + int r = -ENOMEM, changes = 0; + setup_t setup = {}; setup.module = til_settings_new(args->module); if (!setup.module) - return -ENOMEM; + goto _err; setup.video = til_settings_new(args->video); - if (!setup.video) { - til_settings_free(setup.module); - - return -ENOMEM; - } + if (!setup.video) + goto _err; r = setup_interactively(setup.module, til_module_setup, args->use_defaults); - if (r < 0) { - til_settings_free(setup.module); - til_settings_free(setup.video); - - return r; - } - + if (r < 0) + goto _err; if (r) changes = 1; r = setup_interactively(setup.video, setup_video, args->use_defaults); - if (r < 0) { - til_settings_free(setup.module); - til_settings_free(setup.video); - - return r; - } - + if (r < 0) + goto _err; if (r) changes = 1; *res_setup = setup; return changes; + +_err: + til_settings_free(setup.module); + til_settings_free(setup.video); + + return r; } |