Hide Forgot
getopt has a handy ability, where if you put - as the first char of the opt string, it'll hanle all non-option arguments as an argument with an option code of 1. Popt has no comparable functionality, though it would make my interface much easier to use... Here is a simple patch to add option-like handling of args with a return value of 0 (since 0 is not used/usable by anything in popt at the moment.): Note that I wasn't sure if the return should be strdup'd or not, so I just left it as is since it worked for me.. Index: popt.c =================================================================== RCS file: /cvs/devel/popt/popt.c,v retrieving revision 1.71 diff -u -r1.71 popt.c --- popt.c 2001/01/16 12:54:00 1.71 +++ popt.c 2001/03/07 06:06:05 @@ -564,9 +564,13 @@ origOptString = con->os->argv[con->os->next++]; if (con->restLeftover || *origOptString != '-') { - con->leftovers[con->numLeftovers++] = origOptString; if (con->flags & POPT_CONTEXT_POSIXMEHARDER) con->restLeftover = 1; + if (con->flags & POPT_CONTEXT_ARG_OPTS) { + con->os->nextArg = origOptString; + return 0; + }else + con->leftovers[con->numLeftovers++] = origOptString; continue; } Index: popt.h =================================================================== RCS file: /cvs/devel/popt/popt.h,v retrieving revision 1.37 diff -u -r1.37 popt.h --- popt.h 2001/01/02 17:19:43 1.37 +++ popt.h 2001/03/07 06:06:05 @@ -100,6 +100,7 @@ #define POPT_CONTEXT_NO_EXEC (1 << 0) /*!< ignore exec expansions */ #define POPT_CONTEXT_KEEP_FIRST (1 << 1) /*!< pay attention to argv[0] */ #define POPT_CONTEXT_POSIXMEHARDER (1 << 2) /*!< options can't follow args */ +#define POPT_CONTEXT_ARG_OPTS (1 << 4) /*!< return args as options with val 0 */ /*@}*/ /** \ingroup popt
Yes, con->os->nextArg needs a strdup. Patch added in next checkin, should be in popt-1.6.3-0.42. Thanks for the patch and patience.