Bruno Haible via Gnulib discussion list <[email protected]> ha escrit:

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

Both are possible, and boil down to suppressing error output and
handling error returns explictly:

For getopt_long, suppress error messages by setting opterr to 0,
check for '?' return from getopt_long to see if it was a negative
number.  If not, report an error.

Alternatively, start optstring with ':' to suppress error messages
and check for ':' return from getopt_long, proceding as described above.

For argp, set the ARGP_NO_ERRS flag and check for ARGP_KEY_ERROR
in the option parser to discern between actual errors and negative
numbers. 

Regards,
Sergey

Reply via email to