Hello Berny and all, On 2018-11-29 1:48 a.m., Bernhard Voelker wrote:
The attached are quite raw attempts to address this - yes, as a function instead of a macro. ;-) * [PATCH] long-options: add parse_gnu_standard_options_only gnulib patch!
For the gnulib patch, I believe the following is needed: ==== diff --git a/lib/long-options.c b/lib/long-options.c index 52ef1f2f8..9567d5135 100644 --- a/lib/long-options.c +++ b/lib/long-options.c @@ -139,7 +139,7 @@ parse_gnu_standard_options_only (int argc, /* Restore previous value. */ opterr = saved_opterr; - /* Reset this to zero so that getopt internals get initialized from + /* Reset this to one so that getopt internals get initialized from the probably-new parameters when/if getopt is called later. */ - optind = 0; + optind = 1; } ==== Otherwise many things fail like so: $ ./src/dd ./src/dd: unrecognized operand ‘./src/dd’ Try './src/dd --help' for more information. The "1" value matches the instructions in the getopt_long(3) man page.
* [PATCH] all: detect --help and --version more consistently [FIXME] FIXME: NEWS, syntax-check, tests.
With the above 'optind=1' change, there are only two major differences: --- $ nohup-8.30 -/ ; echo $? nohup: invalid option -- '/' Try 'nohup --help' for more information. 125 $ ./src/nohup -/ ; echo $? src/nohup: invalid option -- '/' Try 'src/nohup --help' for more information. 1 $ dd-8.30 -- if=/dev/null 0+0 records in 0+0 records out 0 bytes copied, 3.9014e-05 s, 0.0 kB/s $ ./src/dd -- if=/dev/null ./src/dd: unrecognized operand ‘--’ Try './src/dd --help' for more information. --- Which in turn cause "tests/misc/invalid-opt", "tests/misc/usage_vs_getopt", and "tests/dd/misc" to fail. All other test pass as before (tested only on Debian Stretch). regards, - assaf P.S. https://bugs.gnu.org/29617 "seq: `seq 1 --help' doesn't give help" will also likely be fixed by your patch.