mailing list of musl libc
 help / color / mirror / code / Atom feed
* getopt_long_only and slightly unambiguous options
@ 2015-01-18 17:51 Felix Janda
  2015-01-18 18:14 ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: Felix Janda @ 2015-01-18 17:51 UTC (permalink / raw)
  To: musl

Hello,

since widl from wine uses the combination, get_opt_long_only seems to
be supposed to be able to differentiate between a short option "-h"
and a long option "--help". Together with the possibility of option
abbreviations, the behavior we are trying to copy is:

-h     -> -h
--help -> --help
-help  -> --help
-he    -> --help
--h    -> --help

However musl maps all of them to --help.

The man page is ambiguous about this aspect and I'm not sure if the
BSDs have the same behavior here. (However I would suspect that the
breakage in widl, when the --help option was added in 2012, would
have been noticed.) As always, it is hard to measure how many
applications (and scripts written against these applications) might
depend on this behavior. Since getopt_long_only is discouraged
maybe these are actually quite few, though.

All in all I think that this a bug in musl which should be fixed.


For the implementation, is it maybe enough in __getopt_long_core to
pass options starting with '-' and of exactly two characters
directly to getopt?

Thanks,
Felix


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: getopt_long_only and slightly unambiguous options
  2015-01-18 17:51 getopt_long_only and slightly unambiguous options Felix Janda
@ 2015-01-18 18:14 ` Rich Felker
  2015-01-18 18:27   ` Felix Janda
  0 siblings, 1 reply; 4+ messages in thread
From: Rich Felker @ 2015-01-18 18:14 UTC (permalink / raw)
  To: musl

On Sun, Jan 18, 2015 at 06:51:59PM +0100, Felix Janda wrote:
> Hello,
> 
> since widl from wine uses the combination, get_opt_long_only seems to
> be supposed to be able to differentiate between a short option "-h"
> and a long option "--help". Together with the possibility of option
> abbreviations, the behavior we are trying to copy is:
> 
> -h     -> -h
> --help -> --help
> -help  -> --help
> -he    -> --help
> --h    -> --help
> 
> However musl maps all of them to --help.
> 
> The man page is ambiguous about this aspect and I'm not sure if the
> BSDs have the same behavior here. (However I would suspect that the
> breakage in widl, when the --help option was added in 2012, would
> have been noticed.) As always, it is hard to measure how many
> applications (and scripts written against these applications) might
> depend on this behavior. Since getopt_long_only is discouraged
> maybe these are actually quite few, though.
> 
> All in all I think that this a bug in musl which should be fixed.
> 
> 
> For the implementation, is it maybe enough in __getopt_long_core to
> pass options starting with '-' and of exactly two characters
> directly to getopt?

I would think getopt_long_only would even want to treat "-he" as "-h"
and "-e", i.e. abbreviations should be suppressed entirely when only a
single leading "-" appears instead of "--". However I'd rather follow
historical practice unless it's something stupid and complex (and
violating the principle of least surprise for users) like checking
whether each char is a valid short option and basing the decision on
that.

Rich


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: getopt_long_only and slightly unambiguous options
  2015-01-18 18:14 ` Rich Felker
@ 2015-01-18 18:27   ` Felix Janda
  2015-01-19  6:24     ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: Felix Janda @ 2015-01-18 18:27 UTC (permalink / raw)
  To: musl

Rich Felker wrote:
> On Sun, Jan 18, 2015 at 06:51:59PM +0100, Felix Janda wrote:
> > Hello,
> > 
> > since widl from wine uses the combination, get_opt_long_only seems to
> > be supposed to be able to differentiate between a short option "-h"
> > and a long option "--help". Together with the possibility of option
> > abbreviations, the behavior we are trying to copy is:
> > 
> > -h     -> -h
> > --help -> --help
> > -help  -> --help
> > -he    -> --help
> > --h    -> --help
> > 
> > However musl maps all of them to --help.
> > 
> > The man page is ambiguous about this aspect and I'm not sure if the
> > BSDs have the same behavior here. (However I would suspect that the
> > breakage in widl, when the --help option was added in 2012, would
> > have been noticed.) As always, it is hard to measure how many
> > applications (and scripts written against these applications) might
> > depend on this behavior. Since getopt_long_only is discouraged
> > maybe these are actually quite few, though.
> > 
> > All in all I think that this a bug in musl which should be fixed.
> > 
> > 
> > For the implementation, is it maybe enough in __getopt_long_core to
> > pass options starting with '-' and of exactly two characters
> > directly to getopt?
> 
> I would think getopt_long_only would even want to treat "-he" as "-h"
> and "-e", i.e. abbreviations should be suppressed entirely when only a
> single leading "-" appears instead of "--". However I'd rather follow
> historical practice unless it's something stupid and complex (and
> violating the principle of least surprise for users) like checking
> whether each char is a valid short option and basing the decision on
> that.

I've just checked that even when there are both -h and -e short
options glibc getopt_long_only treats -he as --help.

Felix


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: getopt_long_only and slightly unambiguous options
  2015-01-18 18:27   ` Felix Janda
@ 2015-01-19  6:24     ` Rich Felker
  0 siblings, 0 replies; 4+ messages in thread
From: Rich Felker @ 2015-01-19  6:24 UTC (permalink / raw)
  To: musl

On Sun, Jan 18, 2015 at 07:27:23PM +0100, Felix Janda wrote:
> Rich Felker wrote:
> > On Sun, Jan 18, 2015 at 06:51:59PM +0100, Felix Janda wrote:
> > > Hello,
> > > 
> > > since widl from wine uses the combination, get_opt_long_only seems to
> > > be supposed to be able to differentiate between a short option "-h"
> > > and a long option "--help". Together with the possibility of option
> > > abbreviations, the behavior we are trying to copy is:
> > > 
> > > -h     -> -h
> > > --help -> --help
> > > -help  -> --help
> > > -he    -> --help
> > > --h    -> --help
> > > 
> > > However musl maps all of them to --help.
> > > 
> > > The man page is ambiguous about this aspect and I'm not sure if the
> > > BSDs have the same behavior here. (However I would suspect that the
> > > breakage in widl, when the --help option was added in 2012, would
> > > have been noticed.) As always, it is hard to measure how many
> > > applications (and scripts written against these applications) might
> > > depend on this behavior. Since getopt_long_only is discouraged
> > > maybe these are actually quite few, though.
> > > 
> > > All in all I think that this a bug in musl which should be fixed.
> > > 
> > > 
> > > For the implementation, is it maybe enough in __getopt_long_core to
> > > pass options starting with '-' and of exactly two characters
> > > directly to getopt?
> > 
> > I would think getopt_long_only would even want to treat "-he" as "-h"
> > and "-e", i.e. abbreviations should be suppressed entirely when only a
> > single leading "-" appears instead of "--". However I'd rather follow
> > historical practice unless it's something stupid and complex (and
> > violating the principle of least surprise for users) like checking
> > whether each char is a valid short option and basing the decision on
> > that.
> 
> I've just checked that even when there are both -h and -e short
> options glibc getopt_long_only treats -he as --help.

OK, so I'll go ahead with making getopt_long_core ignore abbreviations
of the form "-" followed by one character.

BTW I realized another related issue we should handle -- in the case
of long options containing multibyte characters, the abbreviation code
is wrongly accepting incomplete multibyte sequences as "abbreviations"
for the full character. I don't know if this is worth fixing, It
should be as easy as checking that the next (unmatched) byte of the
full option is either in the ASCII range or is a lead-byte.

Rich


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-01-19  6:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-18 17:51 getopt_long_only and slightly unambiguous options Felix Janda
2015-01-18 18:14 ` Rich Felker
2015-01-18 18:27   ` Felix Janda
2015-01-19  6:24     ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).