Hi Mohammad,

Mohammad Akhlaghi <[email protected]> writes:

> Gnuastro uses Argp for its argument parsing and the experience has
> been very good! So first of all, I wanted to thank you very much for
> all the wonderful work :-).
>
> This email is about using '-inf' as an argument (negative infinity),
> not a short option '-i' in Argp. It happened to one of Gnuastro's
> users and the only solution that occurred to me was to set it to the
> vertical TAB (ASCII code 11) so Argp parses it as an argument, then
> convert it back afterward Argp (see [1]).
>
> But this is not the most elegant solution to this problem, so along
> with Antonio (in Cc), we became curious and wanted to share the
> situation with you to see what you would have done in this case (or if
> there is actually a solution in Argp that I had missed until now).

I don't really use argp, so maybe someone else will know better than
I do.

However, I know argp will use getopt_long at least in some cases, so I
do not think it will be able to handle "-inf".

GNU coreutils uses getopt_long and some programs need some trickery to
handle expected inputs. A good example is 'seq' which has the following:

  while (optind < argc)
    {
      if (argv[optind][0] == '-'
          && ((optc = argv[optind][1]) == '.' || c_isdigit (optc)))
        {
          /* means negative number */
          break;
        }

      optc = getopt_long (argc, argv, "+f:s:w", long_options, nullptr);
      if (optc == -1)
        break;
      /* Code to handle options snipped...  */
     }

This is required otherwise 'seq' would not work with negative numbers as
it should:

    $ seq -3 -1 
    -3
    -2
    -1

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.

Therefore, I don't think you should feel bad about using some hacky code
for this case. I don't see a way around it, unfortunately.

Collin

Reply via email to