Bug 30912

Summary: patch to allow handling of arguments like options
Product: [Retired] Red Hat Linux Reporter: Matthew Mueller <donut>
Component: poptAssignee: Jeff Johnson <jbj>
Status: CLOSED RAWHIDE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 7.0Keywords: FutureFeature
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2001-03-07 06:33:54 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Matthew Mueller 2001-03-07 06:33:47 UTC
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-17 01:07:51 UTC
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.