Yes, I agree, Greg; thanks for pointing this out (I should have put a
"todo" comment at that place in the code).
Since apr_getopt_long() doesn't support the behavior I was trying to
get, I'm using this as a workaround.
The change I was planning to propose/make for apr_getopt_long() was to
make it return something more distinctive than APR_EOF when it
encounters non-options. Something like:
while (apr_stat = apr_getopt_long (...))
{
if (APR_STATUS_IS_SUCCESS (apr_stat)) {
...;
}
else if (APR_STATUS_IS_NOTOPT (apr_stat)) {
...;
}
}
That way the caller loop has an approved way to detect the difference
between running out of argv, and simply encountering a non-option.
This is very useful for Subversion (and possibly for other programs),
because we still want to process the non-options in a loop, and it
might as well be the same loop. That way the issue of whether or not
to permit interleaved options and args is simply a matter of how the
caller writes the loop.
The purpose of the "--" option is mostly orthogonal to the issue of
interleaving opts and args, I think, though you're right that we're
violating its promise right now. However, it would be easy to make
apr_getopt_long() simply return NOTOPT every time after seeing "--".
Thoughts?,
-K
Greg Hudson <ghudson@mit.edu> writes:
> I just looked at how client/main.c invokes apr_getopt_long, and saw:
>
> /* Since arguments may be interleaved with options, we
> handle arguments right here in the option parsing loop,
> and manually bump opt->ind so apr_getopt_long() can
> continue.
>
> As I have said before, this approach is fundamentally incorrect. A
> bare "--" is supposed to terminate the options list, once and for all
> time, and if you dive back into apr_getopt_long after you see an
> APR_EOF, you'll violate that constraint.
>
> If we want to allow arguments to be interleaved with options, that
> will have to be implemented in apr_getopt_long itself, by permuting
> the argv array. (This is how the gnu getopt_long does it when you
> don't have POSIXLY_CORRECT set in the environment.)
Received on Sat Oct 21 14:36:15 2006