diff options
author | Guy Harris <guy@alum.mit.edu> | 2018-09-14 17:48:45 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2018-09-14 17:48:45 -0700 |
commit | a5eca2cbbfa991c0ae26d0b039bf303fa92734ac (patch) | |
tree | c2c3b5e7aecd821c1b19bf1d094d73489816b6a2 | |
parent | 3ad93074c1f679f6b2791f97ce301459a5ded35a (diff) | |
download | tcpdump-a5eca2cbbfa991c0ae26d0b039bf303fa92734ac.tar.gz |
Clean up the code a bit.
This eliminates a warning from MSVC, and makes the flow a little
clearer.
(Yes, it duplicates some code, but compilers have been pretty good at
merging common code sequences, so it might just turn it into the
equivalent of
if (optopt == (int)':')
goto label;
oli = strchr(ostr, optopt);
if (!oli) {
label:
/*
* Unknown option character.
*/
if (!*place)
++optind;
...
}
although it does mean that the same C code exists in two places.)
-rw-r--r-- | missing/getopt_long.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/missing/getopt_long.c b/missing/getopt_long.c index 80857369..37062404 100644 --- a/missing/getopt_long.c +++ b/missing/getopt_long.c @@ -495,16 +495,32 @@ start: } } - if ((optchar = (int)*place++) == (int)':' || - (optchar == (int)'-' && *place != '\0') || - (oli = strchr(options, optchar)) == NULL) { + optchar = (int)*place++; + /* + * If the user specified "-" and '-' isn't listed in + * options, return -1 (non-option) as per POSIX. + */ + if (optchar == (int)'-' && *place == '\0') + return (-1); + if (optchar == (int)':') { + if (!*place) + ++optind; +#ifdef GNU_COMPATIBLE + if (PRINT_ERROR) + warnx(posixly_correct ? illoptchar : gnuoptchar, + optchar); +#else + if (PRINT_ERROR) + warnx(illoptchar, optchar); +#endif + optopt = optchar; + return (BADCH); + } + oli = strchr(options, optchar); + if (oli == NULL) { /* - * If the user specified "-" and '-' isn't listed in - * options, return -1 (non-option) as per POSIX. - * Otherwise, it is an unknown option character (or ':'). + * Unknown option character. */ - if (optchar == (int)'-' && *place == '\0') - return (-1); if (!*place) ++optind; #ifdef GNU_COMPATIBLE |