introduce parse_optional_no()

This commit is contained in:
NRK 2024-06-14 00:53:55 +00:00
parent c61b84975d
commit 0ddf494437

View file

@ -67,6 +67,13 @@ static void print_version(void)
"\n", stdout); "\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) void parse_options(int argc, char **argv)
{ {
enum { enum {
@ -265,24 +272,16 @@ void parse_options(int argc, char **argv)
_options.using_null = true; _options.using_null = true;
break; break;
case OPT_AA: case OPT_AA:
if (op.optarg != NULL && !STREQ(op.optarg, "no")) _options.anti_alias = parse_optional_no("anti-alias", op.optarg);
error(EXIT_FAILURE, 0, "Invalid argument for option --anti-alias: %s", op.optarg);
_options.anti_alias = op.optarg == NULL;
break; break;
case OPT_AL: case OPT_AL:
if (op.optarg != NULL && !STREQ(op.optarg, "no")) _options.alpha_layer = parse_optional_no("alpha-layer", op.optarg);
error(EXIT_FAILURE, 0, "Invalid argument for option --alpha-layer: %s", op.optarg);
_options.alpha_layer = op.optarg == NULL;
break; break;
case OPT_THUMB: case OPT_THUMB:
if (op.optarg != NULL && !STREQ(op.optarg, "no")) _options.thumb_mode = parse_optional_no("thumbnail", op.optarg);
error(EXIT_FAILURE, 0, "Invalid argument for option --thumbnail: %s", op.optarg);
_options.thumb_mode = op.optarg == NULL;
break; break;
case OPT_BG: case OPT_BG:
if (op.optarg != NULL && !STREQ(op.optarg, "no")) _options.background_cache = parse_optional_no("bg-cache", op.optarg);
error(EXIT_FAILURE, 0, "Invalid argument for option --bg-cache: %s", op.optarg);
_options.background_cache = op.optarg == NULL;
break; break;
case OPT_CA: case OPT_CD: case OPT_CA: case OPT_CD:
_options.tns_filters = op.optarg; _options.tns_filters = op.optarg;