Bug 30912 - patch to allow handling of arguments like options
patch to allow handling of arguments like options
Status: CLOSED RAWHIDE
Product: Red Hat Linux
Classification: Retired
Component: popt (Show other bugs)
7.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jeff Johnson
: FutureFeature
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-03-07 01:33 EST by Matthew Mueller
Modified: 2008-05-01 11:37 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-03-07 01:33:54 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Matthew Mueller 2001-03-07 01:33:47 EST
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
Comment 1 Jeff Johnson 2001-06-16 21:07:51 EDT
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.

Note You need to log in before you can comment on or make changes to this bug.