From: Phil Sutter Date: Sat, 2 Dec 2023 10:10:34 +0000 (+0100) Subject: main: Refer to nft_options in nft_options_check() X-Git-Tag: v1.1.0~189 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c9c2f54c6fb8f9303372202eab5b3e00088c7577;p=thirdparty%2Fnftables.git main: Refer to nft_options in nft_options_check() Consult the array when determining whether a given option is followed by an argument or not instead of hard-coding those that do. The array holds both short and long option name, so one extra pitfall removed. Signed-off-by: Phil Sutter Signed-off-by: Florian Westphal --- diff --git a/src/main.c b/src/main.c index c3c7fe23..d3491cda 100644 --- a/src/main.c +++ b/src/main.c @@ -325,6 +325,7 @@ static bool nft_options_check(int argc, char * const argv[]) { bool skip = false, nonoption = false; int pos = 0, i; + size_t j; for (i = 1; i < argc; i++) { pos += strlen(argv[i - 1]) + 1; @@ -341,16 +342,14 @@ static bool nft_options_check(int argc, char * const argv[]) nft_options_error(argc, argv, pos); return false; } - if (argv[i][1] == 'd' || - argv[i][1] == 'I' || - argv[i][1] == 'f' || - argv[i][1] == 'D' || - !strcmp(argv[i], "--debug") || - !strcmp(argv[i], "--includepath") || - !strcmp(argv[i], "--define") || - !strcmp(argv[i], "--file")) { - skip = true; - continue; + for (j = 0; j < NR_NFT_OPTIONS; j++) { + if (nft_options[j].arg && + (argv[i][1] == (char)nft_options[j].val || + (argv[i][1] == '-' && + !strcmp(argv[i] + 2, nft_options[j].name)))) { + skip = true; + break; + } } }