Subject: Re: RFC: getopt_long(3) change
To: None <tech-userlevel@NetBSD.org>
From: Brian Ginsbach <ginsbach@NetBSD.org>
List: tech-userlevel
Date: 06/26/2007 21:18:06
On Sat, Jun 23, 2007 at 09:05:11AM +0200, Alan Barrett wrote:
> On Fri, 22 Jun 2007, Brian Ginsbach wrote:
> > The long options are set so that both "color" and "colour" would
> > be supported and both return the same value when parsed.  There
> > are no other long options that start with "col".
> > 
> > A command is passed the option --col.  The current version of NetBSD
> > getopt_long(3) treats this as an ambiguous argument.  This was the
> > behavior of GNU getopt_long(3) for GNU C library 2.1.3.  Later
> > versions of the GNU C library doesn't treat this as ambiguous.
> 
> Thank you.  So the fix is something like "if it looks like an ambiguous
> abbreviation of two or more long options, but all the possible
> interpretations would return the same value, then just return that value
> without complaining that it's ambiguous."  This seems sensible.
> 

Yes.  I believe this is exactly why the GNU developers made this same
change long ago.  To do otherwise seems to violate POLA.

> > The change also fixes the handling of single character options that
> > are both a long option and a short option and there are options
> > that start with the same character.  Note the long option parses
> > to a different value than the short option.
> 
> And here, I assume the fix is "if it could be interpreted either as an
> exact match for one long option, or as an abbreviation for one or more
> other long options, then treat it as the exact match."  This too seems
> sensible.

Yes, I believe that this accurately describes the situation.  I did all
of this over a year ago.  I think I'm describing the situation accurately.

> 
> Please update the man page, which currently doesn't say anything about
> abbreviations.
> 

This is definitely a bug.  Even the current code, w/o the proposed change,
will support abbreviations!  I'll work on adding something similar to what
GNU has:

       The getopt_long() function works like getopt() except that
       it also accepts long options, started out by  two  dashes.
****   Long  option  names may be abbreviated if the abbreviation   ****
****   is unique or is an exact match for some defined option.  A   ****
       long  option may take a parameter, of the form --arg=param
       or --arg param.

Any suggestions on wording or where to add to the current man page
would be greatly appreciated.

> --apb (Alan Barrett)