Jason King writes:
> Apparently getopt_long_only() allows '-longoption' and '--longoption',

Right; you don't want that.  It wrecks POSIX by making it impossible
to write "-long" where "-l -o -n -g" was meant.

> I'm curious for this behavior, as it pretty much means any short
> option cannot use any letters that start a long option.  At first
> glance, this seems somewhat less than useful, so I'm curious to
> understand the rationale behind it (or if there's an open ARC case I
> can look at, that'll work to).

The rationale was to provide a function that certain groups of people
may want to have.  The "-longoption" style of processing is common in
the X Window System and compiler communities, for example.

Contrary to some popular opinion, getopt and CLIP (the two ARC cases
that define command line processing standards in OpenSolaris) do not
strictly mandate POSIX.  Instead, the top level rule is "When In
Rome."

The "When In Rome" rule means that it's much more important that a new
command line tool (or a new feature added to an existing one) behaves
as the user of such a tool would expect based on context that it is
for the tool to conform to any arbitrarily selected standard.  Sure,
we'd like to see everyone adopt standards (such as POSIX), but it'd be
downright frustrating to find that the old "fooadm" and "fooctl"
commands use flags to select actions, and the new "foostat" command is
completely different and uses keywords.  (For instance.)

Figuring out which Rome you're in and the commonly-accepted rules for
that area are important issues for some projects.  In most cases, it's
easy to tell ("this is yet another Sun Cluster tool, so ...").  In
others it may be a little harder, and being more conservative might be
warranted.  When in doubt, ask around.

> So I'm a bit stuck then how to add compatibility long options while
> not breaking POSIX, and it looks like (unless I'm missing something)
> that Opensolaris does not provide any way to do that.  Can someone not
> only tell me I'm wrong, but what the answer is? :)

If you don't need optional option arguments, then getopt_clip() is
likely the best answer.  If you do need them, then getopt_long() is
probably the one you want.  You need a durned good reason to reach for
getopt_long_only() ... as outlined above.

-- 
James Carlson, Solaris Networking              <james.d.carl...@sun.com>
Sun Microsystems / 35 Network Drive        71.232W   Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757   42.496N   Fax +1 781 442 1677
_______________________________________________
opensolaris-code mailing list
opensolaris-code@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to