From 0ddf494437a7688d00ac077203bef9ee3ecd08bd Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 14 Jun 2024 00:53:55 +0000 Subject: [PATCH] introduce parse_optional_no() --- options.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/options.c b/options.c index 49e5c1e..1837fe6 100644 --- a/options.c +++ b/options.c @@ -67,6 +67,13 @@ static void print_version(void) "\n", stdout); } +static bool parse_optional_no(const char *flag, const char *arg) +{ + if (arg != NULL && !STREQ(arg, "no")) + error(EXIT_FAILURE, 0, "Invalid argument for option --%s: %s", flag, arg); + return arg == NULL; +} + void parse_options(int argc, char **argv) { enum { @@ -265,24 +272,16 @@ void parse_options(int argc, char **argv) _options.using_null = true; break; case OPT_AA: - if (op.optarg != NULL && !STREQ(op.optarg, "no")) - error(EXIT_FAILURE, 0, "Invalid argument for option --anti-alias: %s", op.optarg); - _options.anti_alias = op.optarg == NULL; + _options.anti_alias = parse_optional_no("anti-alias", op.optarg); break; case OPT_AL: - if (op.optarg != NULL && !STREQ(op.optarg, "no")) - error(EXIT_FAILURE, 0, "Invalid argument for option --alpha-layer: %s", op.optarg); - _options.alpha_layer = op.optarg == NULL; + _options.alpha_layer = parse_optional_no("alpha-layer", op.optarg); break; case OPT_THUMB: - if (op.optarg != NULL && !STREQ(op.optarg, "no")) - error(EXIT_FAILURE, 0, "Invalid argument for option --thumbnail: %s", op.optarg); - _options.thumb_mode = op.optarg == NULL; + _options.thumb_mode = parse_optional_no("thumbnail", op.optarg); break; case OPT_BG: - if (op.optarg != NULL && !STREQ(op.optarg, "no")) - error(EXIT_FAILURE, 0, "Invalid argument for option --bg-cache: %s", op.optarg); - _options.background_cache = op.optarg == NULL; + _options.background_cache = parse_optional_no("bg-cache", op.optarg); break; case OPT_CA: case OPT_CD: _options.tns_filters = op.optarg;