From f5b65ffb86c9b11e13a81c7afae3531aac062142 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 8 Mar 2025 11:15:24 +0100 Subject: Use eprintf rather than deferring exit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/options.c | 76 ++++++++++++++++++++--------------------------------------- 1 file changed, 25 insertions(+), 51 deletions(-) (limited to 'src/options.c') diff --git a/src/options.c b/src/options.c index 3369fe1..fafc603 100644 --- a/src/options.c +++ b/src/options.c @@ -293,7 +293,7 @@ options_init(struct options *options) } /* Parse a single option from the command-line. */ -static int +static void parse_command_line_option(const char option, char *value, struct options *options) { const char *provider_name; @@ -314,8 +314,7 @@ parse_command_line_option(const char option, char *value, struct options *option r = parse_gamma_string(value, options->scheme.day.gamma); if (r < 0) { weprintf(_("Malformed gamma argument.")); - weprintf(_("Try `-h' for more information.")); - return -1; + eprintf(_("Try `-h' for more information.")); } /* Set night gamma to the same value as day gamma. To set these to distinct values use the config file. */ @@ -356,10 +355,8 @@ parse_command_line_option(const char option, char *value, struct options *option /* Lookup provider from name. */ options->provider = find_location_provider(provider_name); - if (!options->provider) { - weprintf(_("Unknown location provider `%s'."), provider_name); - return -1; - } + if (!options->provider) + eprintf(_("Unknown location provider `%s'."), provider_name); /* Print provider help if arg is `help'. */ if (options->provider_args && !strcasecmp(options->provider_args, "help")) { @@ -386,8 +383,7 @@ parse_command_line_option(const char option, char *value, struct options *option options->method = find_gamma_method(value); if (!options->method) { /* TRANSLATORS: This refers to the method used to adjust colors e.g. VidMode */ - weprintf(_("Unknown adjustment method `%s'."), value); - return -1; + eprintf(_("Unknown adjustment method `%s'."), value); } /* Print method help if arg is `help'. */ @@ -422,8 +418,7 @@ parse_command_line_option(const char option, char *value, struct options *option s = strchr(value, ':'); if (!s) { weprintf(_("Malformed temperature argument.")); - weprintf(_("Try `-h' for more information.")); - return -1; + eprintf(_("Try `-h' for more information.")); } *s++ = '\0'; options->scheme.day.temperature = atoi(value); @@ -443,12 +438,9 @@ parse_command_line_option(const char option, char *value, struct options *option options->mode = PROGRAM_MODE_RESET; break; - case '?': - weprintf(_("Try `-h' for more information.")); - return -1; + default: + eprintf(_("Try `-h' for more information.")); } - - return 0; } /* Parse command line arguments. */ @@ -457,12 +449,11 @@ options_parse_args(struct options *options, int argc, char *argv[]) { int opt; while ((opt = getopt(argc, argv, "b:c:g:hl:m:oO:pPrt:vVx")) != -1) - if (parse_command_line_option(opt, optarg, options) < 0) - exit(1); + parse_command_line_option(opt, optarg, options); } /* Parse a single key-value pair from the configuration file. */ -static int +static void parse_config_file_option(const char *key, const char *value, struct options *options) { if (!strcasecmp(key, "temp-day")) { @@ -492,25 +483,19 @@ parse_config_file_option(const char *key, const char *value, struct options *opt options->scheme.low = atof(value); } else if (!strcasecmp(key, "gamma")) { if (isnan(options->scheme.day.gamma[0])) { - if (parse_gamma_string(value, options->scheme.day.gamma) < 0) { - weprintf(_("Malformed gamma setting.")); - return -1; - } + if (parse_gamma_string(value, options->scheme.day.gamma) < 0) + eprintf(_("Malformed gamma setting.")); memcpy(options->scheme.night.gamma, options->scheme.day.gamma, sizeof(options->scheme.night.gamma)); } } else if (!strcasecmp(key, "gamma-day")) { if (isnan(options->scheme.day.gamma[0])) { - if (parse_gamma_string(value, options->scheme.day.gamma) < 0) { - weprintf(_("Malformed gamma setting.")); - return -1; - } + if (parse_gamma_string(value, options->scheme.day.gamma) < 0) + eprintf(_("Malformed gamma setting.")); } } else if (!strcasecmp(key, "gamma-night")) { if (isnan(options->scheme.night.gamma[0])) { - if (parse_gamma_string(value, options->scheme.night.gamma) < 0) { - weprintf(_("Malformed gamma setting.")); - return -1; - } + if (parse_gamma_string(value, options->scheme.night.gamma) < 0) + eprintf(_("Malformed gamma setting.")); } } else if (!strcasecmp(key, "preserve-gamma")) { if (options->preserve_gamma == 1) @@ -518,38 +503,28 @@ parse_config_file_option(const char *key, const char *value, struct options *opt } else if (!strcasecmp(key, "adjustment-method")) { if (!options->method) { options->method = find_gamma_method(value); - if (!options->method) { - weprintf(_("Unknown adjustment method `%s'."), value); - return -1; - } + if (!options->method) + eprintf(_("Unknown adjustment method `%s'."), value); } } else if (!strcasecmp(key, "location-provider")) { if (!options->provider) { options->provider = find_location_provider(value); - if (!options->provider) { - weprintf(_("Unknown location provider `%s'."), value); - return -1; - } + if (!options->provider) + eprintf(_("Unknown location provider `%s'."), value); } } else if (!strcasecmp(key, "dawn-time")) { if (options->scheme.dawn.start < 0) { - if (parse_transition_range(value, &options->scheme.dawn) < 0) { - weprintf(_("Malformed dawn-time setting `%s'."), value); - return -1; - } + if (parse_transition_range(value, &options->scheme.dawn) < 0) + eprintf(_("Malformed dawn-time setting `%s'."), value); } } else if (!strcasecmp(key, "dusk-time")) { if (options->scheme.dusk.start < 0) { - if (parse_transition_range(value, &options->scheme.dusk) < 0) { - weprintf(_("Malformed dusk-time setting `%s'."), value); - return -1; - } + if (parse_transition_range(value, &options->scheme.dusk) < 0) + eprintf(_("Malformed dusk-time setting `%s'."), value); } } else { weprintf(_("Unknown configuration setting `%s'."), key); } - - return 0; } /* Parse options defined in the config file. */ @@ -565,8 +540,7 @@ options_parse_config_file(struct options *options, struct config_ini_state *conf return; for (setting = section->settings; setting; setting = setting->next) - if (parse_config_file_option(setting->name, setting->value, options) < 0) - exit(1); + parse_config_file_option(setting->name, setting->value, options); } /* Replace unspecified options with default values. */ -- cgit v1.2.3-70-g09d2