summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2023-12-02 11:10:34 +0100
committerFlorian Westphal <fw@strlen.de>2023-12-03 12:26:48 +0100
commitc9c2f54c6fb8f9303372202eab5b3e00088c7577 (patch)
treed699755cacf46bb73bc725bc0d74f89ef6d47d6f
parentbda378c2d9d561bdda9ce33aedc91bc11b402ac7 (diff)
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 <phil@nwl.cc> Signed-off-by: Florian Westphal <fw@strlen.de>
-rw-r--r--src/main.c19
1 files changed, 9 insertions, 10 deletions
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;
+ }
}
}