Hi all,
Collin Funk wrote:
It also creates a tiny bug where '--help' doesn't work independent from
it's position in the argument list:
$ seq 0 --help
seq: invalid floating point argument: '--help'
Try 'seq --help' for more information.
Bruno Haible wrote:
optc = getopt_long (argc, argv, "+f:s:w", long_options, nullptr);
Note also the first character '+' (or '-') in the 3rd argument to
getopt_long(). This is necessary, because without it, getopt_long()
reorders the arguments so that those that start with '-' all come
before the arguments that do not start with '-'. Which probably leads
to nonsense if some of these arguments are negative numbers.
IMHO the parsing of negative numbers can only be fully fixed in the parser.
I have added a check for negative numbers to Arg_parser (the command-line
argument parser that I use) and now it can optionally parse the negative
numbers as non-option arguments without reordering them and without hacks or
bugs. For example, '--help' works in any position. Here is a sample output:
$ arg_parser +15 -Inf 0 -20 -a -nan -c -.5
option '-a'
option '-c'
non-option argument '+15'
non-option argument '-Inf'
non-option argument '0'
non-option argument '-20'
non-option argument '-nan'
non-option argument '-.5'
(options are reordered and negative numbers are treated as non-options)
Maybe Argp and getopt_long can be extended like this.
Best regards,
Antonio.