From: Andre Noll Date: Thu, 15 Mar 2018 01:31:10 +0000 (+0100) Subject: play: Use lsu_merge_config_file_options(). X-Git-Tag: v0.6.2~2^2 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=d3f0eb9a37a63319de4e191dce4c82d8877d778b;p=paraslash.git play: Use lsu_merge_config_file_options(). Besides parsing the command line options and the config file, parse_config_or_die() also checks the key map arguments syntactically. This check needs to be kept of course. play.c already includes lsu.h because it calls lsu_com_help(). --- diff --git a/play.c b/play.c index 233da700..647367a3 100644 --- a/play.c +++ b/play.c @@ -151,73 +151,38 @@ static void handle_help_flags(void) static void parse_config_or_die(int argc, char *argv[]) { - const struct lls_command *cmd = CMD_PTR; - int i, ret, cf_argc; - char *cf, *errctx, **cf_argv; - struct lls_parse_result *cf_lpr, *merged_lpr; + int i, ret; unsigned num_kmas; - void *map; - size_t sz; + char *errctx; - ret = lls(lls_parse(argc, argv, cmd, &play_lpr, &errctx)); - if (ret < 0) - goto fail; + ret = lls(lls_parse(argc, argv, CMD_PTR, &play_lpr, &errctx)); + if (ret < 0) { + if (errctx) + PARA_EMERG_LOG("%s\n", errctx); + free(errctx); + PARA_EMERG_LOG("failed to parse command line options: %s\n", + para_strerror(-ret)); + exit(EXIT_FAILURE); + } loglevel = OPT_UINT32_VAL(LOGLEVEL); version_handle_flag("play", OPT_GIVEN(VERSION)); handle_help_flags(); /* also handles the zero-arg case */ - if (OPT_GIVEN(CONFIG_FILE)) - cf = para_strdup(OPT_STRING_VAL(CONFIG_FILE)); - else { - char *home = para_homedir(); - cf = make_message("%s/.paraslash/play.conf", home); - free(home); - } - ret = mmap_full_file(cf, O_RDONLY, &map, &sz, NULL); + ret = lsu_merge_config_file_options(OPT_STRING_VAL(CONFIG_FILE), + "play.conf", &play_lpr, CMD_PTR, play_suite, 0 /* flags */); if (ret < 0) { - if (ret != -E_EMPTY && ret != -ERRNO_TO_PARA_ERROR(ENOENT)) - goto free_cf; - if (ret == -ERRNO_TO_PARA_ERROR(ENOENT) && OPT_GIVEN(CONFIG_FILE)) - goto free_cf; - ret = 0; - goto setup_keymap; + PARA_EMERG_LOG("failed to parse config file: %s\n", + para_strerror(-ret)); + exit(EXIT_FAILURE); } - ret = lls(lls_convert_config(map, sz, NULL, &cf_argv, &errctx)); - para_munmap(map, sz); - if (ret < 0) - goto free_cf; - cf_argc = ret; - ret = lls(lls_parse(cf_argc, cf_argv, cmd, &cf_lpr, &errctx)); - lls_free_argv(cf_argv); - if (ret < 0) - goto free_cf; - ret = lls(lls_merge(play_lpr, cf_lpr, cmd, &merged_lpr, &errctx)); - lls_free_parse_result(cf_lpr, cmd); - if (ret < 0) - goto free_cf; - lls_free_parse_result(play_lpr, cmd); - play_lpr = merged_lpr; loglevel = OPT_UINT32_VAL(LOGLEVEL); -setup_keymap: num_kmas = OPT_GIVEN(KEY_MAP); for (i = 0; i < num_kmas; i++) { const char *kma = lls_string_val(i, OPT_RESULT(KEY_MAP)); if (*kma && strchr(kma + 1, ':')) continue; PARA_EMERG_LOG("invalid key map arg: %s\n", kma); - goto free_cf; + exit(EXIT_FAILURE); } - ret = 1; -free_cf: - free(cf); - if (ret >= 0) - return; - lls_free_parse_result(play_lpr, cmd); -fail: - if (errctx) - PARA_EMERG_LOG("%s\n", errctx); - free(errctx); - PARA_EMERG_LOG("%s\n", para_strerror(-ret)); - exit(EXIT_FAILURE); } static char get_playback_state(void)