- (popt): add POPT_ARGFLAG_OPTIONAL for long options with optional arg.
authorjbj <devnull@localhost>
Sun, 31 Dec 2000 20:30:37 +0000 (20:30 +0000)
committerjbj <devnull@localhost>
Sun, 31 Dec 2000 20:30:37 +0000 (20:30 +0000)
- (popt): diddle auto-help to include type of arg expected.

CVS patchset: 4394
CVS date: 2000/12/31 20:30:37

39 files changed:
CHANGES
Makefile.am
popt/po/cs.po
popt/po/da.po
popt/po/de.po
popt/po/es.po
popt/po/fi.po
popt/po/fr.po
popt/po/gl.po
popt/po/hu.po
popt/po/id.po
popt/po/is.po
popt/po/it.po
popt/po/ja.po
popt/po/ko.po
popt/po/no.po
popt/po/pl.po
popt/po/popt.pot
popt/po/pt.po
popt/po/pt_BR.po
popt/po/ro.po
popt/po/ru.po
popt/po/sk.po
popt/po/sl.po
popt/po/sr.po
popt/po/sv.po
popt/po/tr.po
popt/po/uk.po
popt/po/wa.po
popt/po/zh.po
popt/po/zh_CN.GB2312.po
popt/popt.3
popt/popt.c
popt/popt.h
popt/popthelp.c
popt/test1.c
popt/testit.sh
rpm.spec
rpm.spec.in

diff --git a/CHANGES b/CHANGES
index 6570e8d..dc79e8b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -86,6 +86,8 @@
        - (python): bind initdb (#20988).
        - (popt): fix float/double handling (#19701).
        - (popt): non-linux needs <float.h> (#22732).
+       - (popt): add POPT_ARGFLAG_OPTIONAL for long options with optional arg.
+       - (popt): diddle auto-help to include type of arg expected.
 
 3.0.6 -> 4.0
        - use DIRNAMES/BASENAMES/DIRINDICES not FILENAMES in packages and db.
index fa44df9..60dabf9 100644 (file)
@@ -50,37 +50,37 @@ rpm_LDFLAGS =               @LDFLAGS_STATIC@ $(myLDFLAGS)
 rpm_LDADD =            $(myLDADD) @LIBMISC@
 
 rpmb_SOURCES =         build.c
-rpmb_LDFLAGS =         @LDFLAGS_STATIC@ $(myLDFLAGS)
+rpmb_LDFLAGS =         $(myLDFLAGS)
 rpmb_LDADD =           rpmb.o $(myLDADD)
 rpmb.o:        rpmqv.c
        $(COMPILE) -DIAM_RPMBT -o $@ -c $<
 
 rpmdb_SOURCES =
-rpmdb_LDFLAGS =                @LDFLAGS_STATIC@ $(myLDFLAGS)
+rpmdb_LDFLAGS =                $(myLDFLAGS)
 rpmdb_LDADD =          rpmdb.o $(myLDADD)
 rpmdb.o:       rpmqv.c
        $(COMPILE) -DIAM_RPMDB -o $@ -c $<
 
 rpmi_SOURCES =
-rpmi_LDFLAGS =         @LDFLAGS_STATIC@ $(myLDFLAGS)
+rpmi_LDFLAGS =         $(myLDFLAGS)
 rpmi_LDADD =           rpmi.o $(myLDADD)
 rpmi.o:        rpmqv.c
        $(COMPILE) -DIAM_RPMEIU -o $@ -c $<
 
 rpmk_SOURCES =
-rpmk_LDFLAGS =         @LDFLAGS_STATIC@ $(myLDFLAGS)
+rpmk_LDFLAGS =         $(myLDFLAGS)
 rpmk_LDADD =           rpmk.o $(myLDADD)
 rpmk.o:        rpmqv.c
        $(COMPILE) -DIAM_RPMK -o $@ -c $<
 
 rpmq_SOURCES =
-rpmq_LDFLAGS =         @LDFLAGS_STATIC@ $(myLDFLAGS)
+rpmq_LDFLAGS =         $(myLDFLAGS)
 rpmq_LDADD =           rpmq.o $(myLDADD)
 rpmq.o:        rpmqv.c
        $(COMPILE) -DIAM_RPMQV -o $@ -c $<
 
 rpm2cpio_SOURCES =     rpm2cpio.c
-rpm2cpio_LDFLAGS =     @LDFLAGS_STATIC@ $(myLDFLAGS)
+rpm2cpio_LDFLAGS =     $(myLDFLAGS)
 rpm2cpio_LDADD =       $(myLDADD) @LIBMISC@
 
 $(PROGRAMS):           $(myLDADD) @WITH_APIDOCS_TARGET@
index d81453b..b453b9f 100644 (file)
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 2000-08-23 22:24+0100\n"
 "Last-Translator: Milan Kerslager <milan.kerslager@spsselib.hiedu.cz>\n"
 "Language-Team: Czech <cs@li.org>\n"
index ab784a5..348e8c2 100644 (file)
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 2000-03-07 05:17+01:00\n"
 "Last-Translator: K. Christiansen <kenneth@gnu.org>\n"
 "Language-Team: Danish/Dansk <dansk@klid.dk>\n"
index 35c4226..92426ed 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 35c4226..92426ed 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 35c4226..92426ed 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 35c4226..92426ed 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 989e963..38f2893 100644 (file)
@@ -10,7 +10,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 2000-01-06 20:31+0100\n"
 "Last-Translator: Jesús Bravo Álvarez <jba@pobox.com>\n"
 "Language-Team: Galician <gpul-traduccion@ceu.fi.udc.es>\n"
index 22b953f..d90a9ee 100644 (file)
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 2000-08-03 23:26+0200\n"
 "Last-Translator: László Németh <nemeth@qwertynet.hu>\n"
 "Language-Team: Hungarian\n"
index 35c4226..92426ed 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 2e582b2..6d6d63d 100644 (file)
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 2000-06-16 02:12+0000\n"
 "Last-Translator: Richard Allen <ra@hp.is>\n"
 "Language-Team: is <kde-isl@mmedia.is>\n"
index 35c4226..92426ed 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 35c4226..92426ed 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 35c4226..92426ed 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 4443b98..4864b41 100644 (file)
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 2000-06-21 16:11+02:00\n"
 "Last-Translator: Kjartan Maraas <kmaraas@online.no>\n"
 "Language-Team: Norwegian <no@li.org>\n"
index 35c4226..92426ed 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 4fb4a86..acd8de0 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 398e7f7..9b10b57 100644 (file)
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 2000-06-22 01:02+01:00\n"
 "Last-Translator: Pedro Morais <morais@kde.org>\n"
 "Language-Team: pt <morais@kde.org>\n"
index 35c4226..92426ed 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index cf36c52..c721649 100644 (file)
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 2000-06-14 23:23+EST\n"
 "Last-Translator: Cristian Gafton <gafton@redhat.com>\n"
 "Language-Team: Romanian <ro@li.org>\n"
index 692381b..f8f053b 100644 (file)
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 2000-08-13 21:00+0300\n"
 "Last-Translator: Leon Kanter <leon@blackcatlinux.com>\n"
 "Language-Team: Black Cat Linux Team <blackcat-support@blackcatlinux.com>\n"
index 1a7cf7a..d17e683 100644 (file)
@@ -5,7 +5,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 1999-08-04 21:40+0200\n"
 "Last-Translator: Stanislav Meduna <stano@eunet.sk>\n"
 "Language-Team: Slovak <sk-i18n@rak.isternet.sk>\n"
index 35071ed..d332612 100644 (file)
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 2000-09-05 12:30+0200\n"
 "Last-Translator: Roman Maurer <roman.maurer@hermes.si>\n"
 "Language-Team: Slovenian <sl@li.org>\n"
index 35c4226..92426ed 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 32fd97d..e2f1328 100644 (file)
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 2000-06-20 00:07+0200\n"
 "Last-Translator: Christian Rose <menthos@menthos.com>\n"
 "Language-Team: Swedish <sv@li.org>\n"
index 8e5c43d..e528034 100644 (file)
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 2000-01-06 13:01+0100\n"
 "Last-Translator: Görkem Çetin <kabalak@gmx.net>\n"
 "Language-Team: Gelecek A.Þ <gorkem@gelecek.com.tr>\n"
index 94d6890..913a46a 100644 (file)
@@ -5,7 +5,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 1999-09-30 16:54+0200\n"
 "Last-Translator: Yuri Syrota <rasta@renome.rovno.ua>\n"
 "Language-Team: Ukrainian <uk@li.org>\n"
index 8731d70..c0c7ef5 100644 (file)
@@ -9,7 +9,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 1999-03-18 23:11+0100\n"
 "Last-Translator: Nobody yet\n"
 "Language-Team: walon <linux-wa@chanae.alphanet.ch>\n"
index 35c4226..92426ed 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index 4459f61..64932fa 100644 (file)
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: popt 1.6.1\n"
-"POT-Creation-Date: 2000-12-30 14:24-0500\n"
+"POT-Creation-Date: 2000-12-31 15:18-0500\n"
 "PO-Revision-Date: 1999-11-11 05:04+0800\n"
 "Last-Translator: Dillion Chen <dillon.chen@turbolinux.com.cn>\n"
 "Language-Team: TLDN\n"
index 8d17f17..0d9e0b0 100644 (file)
@@ -169,6 +169,12 @@ specified to win; for example, "rm -i -f".  \fBPOPT_ARG_VAL\fP causes
 the parsing function not to return a value, since the value of \fIval\fP
 has already been used.
 .sp
+If the \fIargInfo\fR value is bitwise or'd with \fBPOPT_ARGFLAG_OPTIONAL\fR,
+the argument to the long option may be omitted. If the long option
+is used without an argument, a default value of zero or NULL will be saved
+(if the arg pointer is present), otherwise behavior will be identical to
+a long option with argument.
+.sp
 .RI "The next option, " val ", is the value popt's parsing function 
 should return when the option is encountered.  If it is 0, the parsing
 function does not return a value, instead parsing the next 
index 79bfdaa..d67e313 100644 (file)
@@ -674,35 +674,43 @@ int poptGetNextOpt(poptContext con)
                       con->os > con->optionStack) {
                    cleanOSE(con->os--);
                }
-               if (con->os->next == con->os->argc)
-                   return POPT_ERROR_NOARG;
-
-               /* make sure this isn't part of a short arg or the
-                   result of an alias expansion */
-               if (con->os == con->optionStack &&
-                  opt->argInfo & POPT_ARGFLAG_STRIP &&
-                  canstrip) {
-                   poptStripArg(con, con->os->next);
-               }
+               if (con->os->next == con->os->argc) {
+                   if (opt->argInfo & POPT_ARGFLAG_OPTIONAL)
+                       con->os->nextArg = NULL;
+                   else
+                       return POPT_ERROR_NOARG;
+               } else {
+
+                   /* make sure this isn't part of a short arg or the
+                       result of an alias expansion */
+                   if (con->os == con->optionStack &&
+                       opt->argInfo & POPT_ARGFLAG_STRIP &&
+                       canstrip) {
+                       poptStripArg(con, con->os->next);
+                   }
                
-               con->os->nextArg = expandNextArg(con, con->os->argv[con->os->next++]);
+                   con->os->nextArg = expandNextArg(con, con->os->argv[con->os->next++]);
+               }
            }
 
            if (opt->arg) {
                switch (opt->argInfo & POPT_ARG_MASK) {
                case POPT_ARG_STRING:
                    /* XXX memory leak, hard to plug */
-                   *((const char **) opt->arg) = xstrdup(con->os->nextArg);
+                   *((const char **) opt->arg) = (con->os->nextArg)
+                       ? xstrdup(con->os->nextArg) : NULL;
                    break;
 
                case POPT_ARG_INT:
                case POPT_ARG_LONG:
-               {   long aLong;
+               {   long aLong = 0;
                    char *end;
 
-                   aLong = strtol(con->os->nextArg, &end, 0);
-                   if (!(end && *end == '\0'))
-                       return POPT_ERROR_BADNUMBER;
+                   if (con->os->nextArg) {
+                       aLong = strtol(con->os->nextArg, &end, 0);
+                       if (!(end && *end == '\0'))
+                           return POPT_ERROR_BADNUMBER;
+                   }
 
                    if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {
                        if (aLong == LONG_MIN || aLong == LONG_MAX)
@@ -719,12 +727,14 @@ int poptGetNextOpt(poptContext con)
 
                case POPT_ARG_FLOAT:
                case POPT_ARG_DOUBLE:
-               {   double aDouble;
+               {   double aDouble = 0.0;
                    char *end;
 
-                   aDouble = strtod(con->os->nextArg, &end);
-                   if (*end)
-                       return POPT_ERROR_BADNUMBER;
+                   if (con->os->nextArg) {
+                       aDouble = strtod(con->os->nextArg, &end);
+                       if (*end)
+                           return POPT_ERROR_BADNUMBER;
+                   }
 
                    if (aDouble == +HUGE_VAL || aDouble == -HUGE_VAL)
                        return POPT_ERROR_OVERFLOW;
@@ -778,7 +788,9 @@ int poptGetNextOpt(poptContext con)
        else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL)
            /*@-ifempty@*/ ;
        else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) {
-           con->finalArgv[con->finalArgvCount++] = xstrdup(con->os->nextArg);
+           if (con->os->nextArg)
+               con->finalArgv[con->finalArgvCount++] =
+                       xstrdup(con->os->nextArg);
        }
     }
 
index 7a0a6b1..5bae679 100644 (file)
@@ -37,7 +37,8 @@ extern "C" {
 #define POPT_ARG_MASK          0x0000FFFF
 #define POPT_ARGFLAG_ONEDASH   0x80000000  /* allow -longoption */
 #define POPT_ARGFLAG_DOC_HIDDEN 0x40000000  /* don't show in help/usage */
-#define POPT_ARGFLAG_STRIP     0x20000000  /* strip this arg from argv (only applies to long args) */
+#define POPT_ARGFLAG_STRIP     0x20000000  /* strip this arg from argv(only applies to long args) */
+#define        POPT_ARGFLAG_OPTIONAL   0x10000000  /* arg may be missing */
 
 #define        POPT_ARGFLAG_OR         0x08000000 /* arg will be or'ed */
 #define        POPT_ARGFLAG_NOR        0x09000000 /* arg will be nor'ed */
index c88d094..12fb484 100644 (file)
@@ -54,7 +54,17 @@ getArgDescrip(const struct poptOption * opt, const char *translation_domain)
        if (opt->argDescrip) return POPT_(opt->argDescrip);
 
     if (opt->argDescrip) return D_(translation_domain, opt->argDescrip);
-    return POPT_("ARG");
+
+    switch (opt->argInfo & POPT_ARG_MASK) {
+    case POPT_ARG_NONE:                return POPT_("NONE");
+    case POPT_ARG_VAL:         return POPT_("VAL");
+    case POPT_ARG_INT:         return POPT_("INT");
+    case POPT_ARG_LONG:                return POPT_("LONG");
+    case POPT_ARG_STRING:      return POPT_("STRING");
+    case POPT_ARG_FLOAT:       return POPT_("FLOAT");
+    case POPT_ARG_DOUBLE:      return POPT_("DOUBLE");
+    default:                   return POPT_("ARG");
+    }
 }
 
 static void singleOptionHelp(FILE * f, int maxLeftCol, 
@@ -70,18 +80,60 @@ static void singleOptionHelp(FILE * f, int maxLeftCol,
     const char * argDescrip = getArgDescrip(opt, translation_domain);
 
     left = malloc(maxLeftCol + 1);
-    *left = '\0';
+    left[0] = left[maxLeftCol] = '\0';
 
     if (opt->longName && opt->shortName)
-       sprintf(left, "-%c, --%s", opt->shortName, opt->longName);
+       snprintf(left, maxLeftCol, "-%c, --%s", opt->shortName, opt->longName);
     else if (opt->shortName) 
-       sprintf(left, "-%c", opt->shortName);
+       snprintf(left, maxLeftCol, "-%c", opt->shortName);
     else if (opt->longName)
-       sprintf(left, "--%s", opt->longName);
+       snprintf(left, maxLeftCol, "--%s", opt->longName);
     if (!*left) return ;
     if (argDescrip) {
-       strcat(left, "=");
-       strcat(left, argDescrip);
+       char * le = left + strlen(left);
+       int nl = maxLeftCol - (le - left);
+       if (opt->argInfo & POPT_ARGFLAG_OPTIONAL) {
+           *le++ = '['; nl--;
+       }
+       if (opt->argDescrip == NULL) {
+           switch (opt->argInfo & POPT_ARG_MASK) {
+           case POPT_ARG_NONE:
+               snprintf(le, nl-1, "[true]");
+               break;
+           case POPT_ARG_VAL:
+           {   long aLong = opt->val;
+
+               if (opt->argInfo & POPT_ARGFLAG_NOT) aLong = ~aLong;
+               switch (opt->argInfo & POPT_ARGFLAG_LOGICALOPS) {
+               case POPT_ARGFLAG_OR:
+                   snprintf(le, nl-1, "[|=0x%lx]", aLong);     break;
+               case POPT_ARGFLAG_AND:
+                   snprintf(le, nl-1, "[&=0x%lx]", aLong);     break;
+               case POPT_ARGFLAG_XOR:
+                   snprintf(le, nl-1, "[^=0x%lx]", aLong);     break;
+               default:
+                   if (!(aLong == 0L || aLong == 1L || aLong == -1L))
+                       snprintf(le, nl-1, "[=%ld]", aLong);
+                   break;
+               }
+           }   break;
+           case POPT_ARG_INT:
+           case POPT_ARG_LONG:
+           case POPT_ARG_STRING:
+           case POPT_ARG_FLOAT:
+           case POPT_ARG_DOUBLE:
+               snprintf(le, nl-1, "=%s", argDescrip);
+               break;
+           }
+       } else {
+           snprintf(le, nl-1, "=%s", argDescrip);
+       }
+       nl -= strlen(le);
+       le += strlen(le);
+       if (opt->argInfo & POPT_ARGFLAG_OPTIONAL) {
+           *le++ = ']'; nl--;
+       }
+       *le = '\0';
     }
 
     if (help)
index 5b6aeb7..7b7f55f 100644 (file)
@@ -19,6 +19,7 @@ int inc = 0;
 int shortopt = 0;
 float aFloat = 0.0;
 double aDouble = 0.0;
+char * oStr = (char *)-1;
 int singleDash = 0;
 
 static struct poptOption moreCallbackArgs[] = {
@@ -54,6 +55,9 @@ static struct poptOption options[] = {
            "A float argument", "FLOAT" },
        { "double", 'd', POPT_ARG_DOUBLE, &aDouble, 0,
            "A double argument", "DOUBLE" },
+       { "ostr", '\0', POPT_ARG_STRING|POPT_ARGFLAG_OPTIONAL, &oStr, 0,
+           "An optional str", "ARG" },
+
        { NULL, '-', POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN, &singleDash, 0 },
        { NULL, '\0', POPT_ARG_INCLUDE_TABLE, &moreArgs, 0, NULL },
        { NULL, '\0', POPT_ARG_INCLUDE_TABLE, &callbackArgs, 0, "Callback arguments" },
@@ -128,6 +132,8 @@ int main(int argc, const char ** argv) {
        fprintf(stdout, " aFloat: %g", aFloat);
     if (aDouble != 0.0)
        fprintf(stdout, " aDouble: %g", aDouble);
+    if (oStr != (char *)-1)
+       fprintf(stdout, " oStr: %s", (oStr ? oStr : "(none)"));
     if (singleDash)
        fprintf(stdout, " -");
 
index 975b5ef..ce5530a 100755 (executable)
@@ -62,6 +62,11 @@ run test1 "test1 - 32" "arg1: 0 arg2: (none) aFloat: 10.1" -f 10.1
 run test1 "test1 - 33" "arg1: 0 arg2: (none) aFloat: 10.1" --float 10.1
 run test1 "test1 - 34" "arg1: 0 arg2: (none) aDouble: 10.1" -d 10.1
 run test1 "test1 - 35" "arg1: 0 arg2: (none) aDouble: 10.1" --double 10.1
+run test1 "test1 - 36" "arg1: 0 arg2: (none) oStr: (none)" --ostr
+run test1 "test1 - 37" "arg1: 0 arg2: (none) oStr: yadda" --ostr=yadda
+run test1 "test1 - 38" "arg1: 0 arg2: (none) oStr: yadda" --ostr yadda
+run test1 "test1 - 39" "arg1: 0 arg2: (none) oStr: ping rest: pong" --ostr=ping pong
+run test1 "test1 - 40" "arg1: 0 arg2: (none) oStr: ping rest: pong" --ostr ping pong
 
 echo ""
 echo "Passed."
index 5c6debb..b3155ee 100644 (file)
--- a/rpm.spec
+++ b/rpm.spec
@@ -13,7 +13,7 @@ Summary: The Red Hat package management system.
 Name: rpm
 %define version 4.0.2
 Version: %{version}
-Release: 0.12
+Release: 0.13
 Group: System Environment/Base
 Source: ftp://ftp.rpm.org/pub/rpm/dist/rpm-4.0.x/rpm-%{version}.tar.gz
 Copyright: GPL
@@ -309,6 +309,12 @@ fi
 %{__prefix}/include/popt.h
 
 %changelog
+* Sun Dec 31 2000 Jeff Johnson <jbj@redhat.com>
+- (popt): fix float/double handling (#19701).
+- (popt): non-linux needs <float.h> (#22732).
+- (popt): add POPT_ARGFLAG_OPTIONAL for long options with optional arg.
+- (popt): diddle auto-help to include type of arg expected.
+
 * Sat Dec 30 2000 Jeff Johnson <jbj@redhat.com>
 - (non-linux): move stubs.c to rpmio (#21132).
 - (python): bind initdb (#20988).
index d6384ae..a1f60a1 100644 (file)
@@ -13,7 +13,7 @@ Summary: The Red Hat package management system.
 Name: rpm
 %define version @VERSION@
 Version: %{version}
-Release: 0.12
+Release: 0.13
 Group: System Environment/Base
 Source: ftp://ftp.rpm.org/pub/rpm/dist/rpm-4.0.x/rpm-%{version}.tar.gz
 Copyright: GPL
@@ -309,6 +309,12 @@ fi
 %{__prefix}/include/popt.h
 
 %changelog
+* Sun Dec 31 2000 Jeff Johnson <jbj@redhat.com>
+- (popt): fix float/double handling (#19701).
+- (popt): non-linux needs <float.h> (#22732).
+- (popt): add POPT_ARGFLAG_OPTIONAL for long options with optional arg.
+- (popt): diddle auto-help to include type of arg expected.
+
 * Sat Dec 30 2000 Jeff Johnson <jbj@redhat.com>
 - (non-linux): move stubs.c to rpmio (#21132).
 - (python): bind initdb (#20988).