summaryrefslogtreecommitdiff
path: root/popt
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2000-12-31 20:30:37 +0000
committerjbj <devnull@localhost>2000-12-31 20:30:37 +0000
commit37a87e6f14cc9f4e81779c4777454e331934bb96 (patch)
treed9119b78799db87fc4cc916e39f75a453e05aef9 /popt
parentb9145eabe09db09a56c9daf3006426b08182d848 (diff)
downloadlibrpm-tizen-37a87e6f14cc9f4e81779c4777454e331934bb96.tar.gz
librpm-tizen-37a87e6f14cc9f4e81779c4777454e331934bb96.tar.bz2
librpm-tizen-37a87e6f14cc9f4e81779c4777454e331934bb96.zip
- (popt): add POPT_ARGFLAG_OPTIONAL for long options with optional arg.
- (popt): diddle auto-help to include type of arg expected. CVS patchset: 4394 CVS date: 2000/12/31 20:30:37
Diffstat (limited to 'popt')
-rw-r--r--popt/po/cs.po2
-rw-r--r--popt/po/da.po2
-rw-r--r--popt/po/de.po2
-rw-r--r--popt/po/es.po2
-rw-r--r--popt/po/fi.po2
-rw-r--r--popt/po/fr.po2
-rw-r--r--popt/po/gl.po2
-rw-r--r--popt/po/hu.po2
-rw-r--r--popt/po/id.po2
-rw-r--r--popt/po/is.po2
-rw-r--r--popt/po/it.po2
-rw-r--r--popt/po/ja.po2
-rw-r--r--popt/po/ko.po2
-rw-r--r--popt/po/no.po2
-rw-r--r--popt/po/pl.po2
-rw-r--r--popt/po/popt.pot2
-rw-r--r--popt/po/pt.po2
-rw-r--r--popt/po/pt_BR.po2
-rw-r--r--popt/po/ro.po2
-rw-r--r--popt/po/ru.po2
-rw-r--r--popt/po/sk.po2
-rw-r--r--popt/po/sl.po2
-rw-r--r--popt/po/sr.po2
-rw-r--r--popt/po/sv.po2
-rw-r--r--popt/po/tr.po2
-rw-r--r--popt/po/uk.po2
-rw-r--r--popt/po/wa.po2
-rw-r--r--popt/po/zh.po2
-rw-r--r--popt/po/zh_CN.GB2312.po2
-rw-r--r--popt/popt.36
-rw-r--r--popt/popt.c54
-rw-r--r--popt/popt.h3
-rw-r--r--popt/popthelp.c66
-rw-r--r--popt/test1.c6
-rwxr-xr-xpopt/testit.sh5
35 files changed, 140 insertions, 58 deletions
diff --git a/popt/po/cs.po b/popt/po/cs.po
index d81453bdf..b453b9f30 100644
--- a/popt/po/cs.po
+++ b/popt/po/cs.po
@@ -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"
diff --git a/popt/po/da.po b/popt/po/da.po
index ab784a524..348e8c2ec 100644
--- a/popt/po/da.po
+++ b/popt/po/da.po
@@ -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"
diff --git a/popt/po/de.po b/popt/po/de.po
index 35c422612..92426ed88 100644
--- a/popt/po/de.po
+++ b/popt/po/de.po
@@ -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"
diff --git a/popt/po/es.po b/popt/po/es.po
index 35c422612..92426ed88 100644
--- a/popt/po/es.po
+++ b/popt/po/es.po
@@ -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"
diff --git a/popt/po/fi.po b/popt/po/fi.po
index 35c422612..92426ed88 100644
--- a/popt/po/fi.po
+++ b/popt/po/fi.po
@@ -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"
diff --git a/popt/po/fr.po b/popt/po/fr.po
index 35c422612..92426ed88 100644
--- a/popt/po/fr.po
+++ b/popt/po/fr.po
@@ -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"
diff --git a/popt/po/gl.po b/popt/po/gl.po
index 989e96354..38f28935d 100644
--- a/popt/po/gl.po
+++ b/popt/po/gl.po
@@ -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"
diff --git a/popt/po/hu.po b/popt/po/hu.po
index 22b953f0d..d90a9ee6e 100644
--- a/popt/po/hu.po
+++ b/popt/po/hu.po
@@ -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"
diff --git a/popt/po/id.po b/popt/po/id.po
index 35c422612..92426ed88 100644
--- a/popt/po/id.po
+++ b/popt/po/id.po
@@ -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"
diff --git a/popt/po/is.po b/popt/po/is.po
index 2e582b259..6d6d63ded 100644
--- a/popt/po/is.po
+++ b/popt/po/is.po
@@ -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"
diff --git a/popt/po/it.po b/popt/po/it.po
index 35c422612..92426ed88 100644
--- a/popt/po/it.po
+++ b/popt/po/it.po
@@ -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"
diff --git a/popt/po/ja.po b/popt/po/ja.po
index 35c422612..92426ed88 100644
--- a/popt/po/ja.po
+++ b/popt/po/ja.po
@@ -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"
diff --git a/popt/po/ko.po b/popt/po/ko.po
index 35c422612..92426ed88 100644
--- a/popt/po/ko.po
+++ b/popt/po/ko.po
@@ -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"
diff --git a/popt/po/no.po b/popt/po/no.po
index 4443b9847..4864b4168 100644
--- a/popt/po/no.po
+++ b/popt/po/no.po
@@ -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"
diff --git a/popt/po/pl.po b/popt/po/pl.po
index 35c422612..92426ed88 100644
--- a/popt/po/pl.po
+++ b/popt/po/pl.po
@@ -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"
diff --git a/popt/po/popt.pot b/popt/po/popt.pot
index 4fb4a861d..acd8de004 100644
--- a/popt/po/popt.pot
+++ b/popt/po/popt.pot
@@ -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"
diff --git a/popt/po/pt.po b/popt/po/pt.po
index 398e7f799..9b10b57e3 100644
--- a/popt/po/pt.po
+++ b/popt/po/pt.po
@@ -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"
diff --git a/popt/po/pt_BR.po b/popt/po/pt_BR.po
index 35c422612..92426ed88 100644
--- a/popt/po/pt_BR.po
+++ b/popt/po/pt_BR.po
@@ -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"
diff --git a/popt/po/ro.po b/popt/po/ro.po
index cf36c526d..c721649aa 100644
--- a/popt/po/ro.po
+++ b/popt/po/ro.po
@@ -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"
diff --git a/popt/po/ru.po b/popt/po/ru.po
index 692381b3a..f8f053b92 100644
--- a/popt/po/ru.po
+++ b/popt/po/ru.po
@@ -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"
diff --git a/popt/po/sk.po b/popt/po/sk.po
index 1a7cf7a3b..d17e68373 100644
--- a/popt/po/sk.po
+++ b/popt/po/sk.po
@@ -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"
diff --git a/popt/po/sl.po b/popt/po/sl.po
index 35071edbe..d33261225 100644
--- a/popt/po/sl.po
+++ b/popt/po/sl.po
@@ -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"
diff --git a/popt/po/sr.po b/popt/po/sr.po
index 35c422612..92426ed88 100644
--- a/popt/po/sr.po
+++ b/popt/po/sr.po
@@ -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"
diff --git a/popt/po/sv.po b/popt/po/sv.po
index 32fd97d91..e2f13287f 100644
--- a/popt/po/sv.po
+++ b/popt/po/sv.po
@@ -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"
diff --git a/popt/po/tr.po b/popt/po/tr.po
index 8e5c43d3e..e5280342f 100644
--- a/popt/po/tr.po
+++ b/popt/po/tr.po
@@ -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"
diff --git a/popt/po/uk.po b/popt/po/uk.po
index 94d689028..913a46a67 100644
--- a/popt/po/uk.po
+++ b/popt/po/uk.po
@@ -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"
diff --git a/popt/po/wa.po b/popt/po/wa.po
index 8731d70fb..c0c7ef51e 100644
--- a/popt/po/wa.po
+++ b/popt/po/wa.po
@@ -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"
diff --git a/popt/po/zh.po b/popt/po/zh.po
index 35c422612..92426ed88 100644
--- a/popt/po/zh.po
+++ b/popt/po/zh.po
@@ -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"
diff --git a/popt/po/zh_CN.GB2312.po b/popt/po/zh_CN.GB2312.po
index 4459f615a..64932fa1d 100644
--- a/popt/po/zh_CN.GB2312.po
+++ b/popt/po/zh_CN.GB2312.po
@@ -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"
diff --git a/popt/popt.3 b/popt/popt.3
index 8d17f17c8..0d9e0b0d3 100644
--- a/popt/popt.3
+++ b/popt/popt.3
@@ -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
diff --git a/popt/popt.c b/popt/popt.c
index 79bfdaaa0..d67e31373 100644
--- a/popt/popt.c
+++ b/popt/popt.c
@@ -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);
}
}
diff --git a/popt/popt.h b/popt/popt.h
index 7a0a6b1b6..5bae6793b 100644
--- a/popt/popt.h
+++ b/popt/popt.h
@@ -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 */
diff --git a/popt/popthelp.c b/popt/popthelp.c
index c88d09440..12fb484ea 100644
--- a/popt/popthelp.c
+++ b/popt/popthelp.c
@@ -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)
diff --git a/popt/test1.c b/popt/test1.c
index 5b6aeb723..7b7f55fe0 100644
--- a/popt/test1.c
+++ b/popt/test1.c
@@ -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, " -");
diff --git a/popt/testit.sh b/popt/testit.sh
index 975b5efde..ce5530a97 100755
--- a/popt/testit.sh
+++ b/popt/testit.sh
@@ -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."