Hi Antonio,

> 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.

I don't know how widespread this requirement to have negative numbers as
command-line arguments _and_ short options at the same time — because in
that case, it makes for a more understandable user interface to not allow
any short options at all, only long options.

But if you are working on it, I have two thoughts:

  1) It would be useful to generalize "negative number token" to a
     function
        bool arg_is_not_an_option (const char *argument)
     that, in the special case, could be defined by use of strtod().

  2) Is it possible to integrate such a feature into a program that
     uses getopt_long() without changing getopt_long() itself?
     Is it possible to integrate such a feature into a program that
     uses argp without changing the argp implementation itself?

Bruno




Reply via email to