mailing list of musl libc
 help / color / mirror / code / Atom feed
* getopt_long permutation algorithm questions
@ 2014-12-03 19:29 Rich Felker
  2014-12-03 19:43 ` Jens Gustedt
  0 siblings, 1 reply; 8+ messages in thread
From: Rich Felker @ 2014-12-03 19:29 UTC (permalink / raw)
  To: musl

As part of resolving the rest of the dist-local changes Alpine is
applying to musl, I'm trying to figure out how to add GNU-style
argument permutation to getopt_long. The basic concept is simple: when
a non-option argument is encountered, skip forward until the next
option (argument beginning with '-') and move it (and possibly its
argument) before the non-option arguments. However, there are some
ugly corner cases like:

arg1 -ab foo arg2

where 'a' and 'b' are options, and 'b' takes an argument, foo. Here it
seems like, in order to perform the correct permutation, lookahead is
required to see that foo also needs to be moved. Is this correct?

For long options, it's immediately decidable from the option being
processed whether it has no argument, or an argument that's part of
the same argv[] string, or a separate option in the next argv[] slot.
For short options, it seems necessary to scan each character of the
argv[] string to be moved, looking for the first option that takes an
argument. If none is found, or if such a character is found in a
non-final position, only this string needs to be moved. If an option
needing an argument is found in the final position, two argv[] strings
need to be moved. Is this correct?

Rich


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

end of thread, other threads:[~2014-12-06 19:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-03 19:29 getopt_long permutation algorithm questions Rich Felker
2014-12-03 19:43 ` Jens Gustedt
2014-12-03 19:56   ` Rich Felker
2014-12-03 20:47     ` Jens Gustedt
2014-12-04  0:04       ` Rich Felker
2014-12-04  6:25         ` Timo Teras
2014-12-06 17:47           ` Rich Felker
2014-12-06 19:22             ` 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).