This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: argp parser
- From: Jonathan Nieder <jrnieder at gmail dot com>
- To: libc-help at sourceware dot org
- Date: Sat, 9 Apr 2011 15:14:38 -0500
- Subject: Re: argp parser
- References: <BANLkTi=bhKMim+vPAPk-RzicVg16xLHo_A@mail.gmail.com><BANLkTinm+zArJwFUDECtZf2jVMf0TkW8hw@mail.gmail.com>
Karin en Edwin wrote:
> I am using the argp parser and I would like to make sure the argument
> always gets parsed before the options (default behaviour is the
> opposite). I have looked in the argp documentation, but cannot find
> anything.
> Anyone have an idea how I could do this?
I'm more familiar with getopt than argp, so others may have better
advice. I'd suggest enqueueing options (possibly in parsed form) for
later handling, then dealing with nonoptions, then popping options
from the queue. getopt (and hence argp) permutes the elements of argv
as it scans, so the non-option arguments are not necessarily
contiguous until it is done.
Another possibility is to use '-' (the RETURN_IN_ORDER flag) in the
option specification to learn about nonoptions as soon as possible,
(intermixed with options). That would seem to me to just complicate
life further, but it could speed up argument parsing by some miniscule
amount, which may or may not be important for your application.
AFAICT this is exposed in argp as ARGP_IN_ORDER.
Hope that helps,
Jonathan