summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjbj <jbj>2000-12-31 20:30:37 +0000
committerjbj <jbj>2000-12-31 20:30:37 +0000
commit5c317e5c54ed6e16d1cfeccf5e20f897a5edbd5c (patch)
treea6cd5dc445f46f967d4165d2b3b4ae9141b20bec
parent8f65d3cff4f356bd80797a4038a158aa2b0c619f (diff)
downloadlibpopt-5c317e5c54ed6e16d1cfeccf5e20f897a5edbd5c.tar.gz
- (popt): add POPT_ARGFLAG_OPTIONAL for long options with optional arg.
- (popt): diddle auto-help to include type of arg expected.
-rw-r--r--po/cs.po2
-rw-r--r--po/da.po2
-rw-r--r--po/de.po2
-rw-r--r--po/es.po2
-rw-r--r--po/fi.po2
-rw-r--r--po/fr.po2
-rw-r--r--po/gl.po2
-rw-r--r--po/hu.po2
-rw-r--r--po/id.po2
-rw-r--r--po/is.po2
-rw-r--r--po/it.po2
-rw-r--r--po/ja.po2
-rw-r--r--po/ko.po2
-rw-r--r--po/no.po2
-rw-r--r--po/pl.po2
-rw-r--r--po/popt.pot2
-rw-r--r--po/pt.po2
-rw-r--r--po/pt_BR.po2
-rw-r--r--po/ro.po2
-rw-r--r--po/ru.po2
-rw-r--r--po/sk.po2
-rw-r--r--po/sl.po2
-rw-r--r--po/sr.po2
-rw-r--r--po/sv.po2
-rw-r--r--po/tr.po2
-rw-r--r--po/uk.po2
-rw-r--r--po/wa.po2
-rw-r--r--po/zh.po2
-rw-r--r--po/zh_CN.GB2312.po2
-rw-r--r--popt.36
-rw-r--r--popt.c54
-rw-r--r--popt.h3
-rw-r--r--popthelp.c66
-rw-r--r--test1.c6
-rwxr-xr-xtestit.sh5
35 files changed, 140 insertions, 58 deletions
diff --git a/po/cs.po b/po/cs.po
index d81453b..b453b9f 100644
--- a/po/cs.po
+++ b/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/po/da.po b/po/da.po
index ab784a5..348e8c2 100644
--- a/po/da.po
+++ b/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/po/de.po b/po/de.po
index 35c4226..92426ed 100644
--- a/po/de.po
+++ b/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/po/es.po b/po/es.po
index 35c4226..92426ed 100644
--- a/po/es.po
+++ b/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/po/fi.po b/po/fi.po
index 35c4226..92426ed 100644
--- a/po/fi.po
+++ b/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/po/fr.po b/po/fr.po
index 35c4226..92426ed 100644
--- a/po/fr.po
+++ b/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/po/gl.po b/po/gl.po
index 989e963..38f2893 100644
--- a/po/gl.po
+++ b/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/po/hu.po b/po/hu.po
index 22b953f..d90a9ee 100644
--- a/po/hu.po
+++ b/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/po/id.po b/po/id.po
index 35c4226..92426ed 100644
--- a/po/id.po
+++ b/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/po/is.po b/po/is.po
index 2e582b2..6d6d63d 100644
--- a/po/is.po
+++ b/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/po/it.po b/po/it.po
index 35c4226..92426ed 100644
--- a/po/it.po
+++ b/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/po/ja.po b/po/ja.po
index 35c4226..92426ed 100644
--- a/po/ja.po
+++ b/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/po/ko.po b/po/ko.po
index 35c4226..92426ed 100644
--- a/po/ko.po
+++ b/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/po/no.po b/po/no.po
index 4443b98..4864b41 100644
--- a/po/no.po
+++ b/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/po/pl.po b/po/pl.po
index 35c4226..92426ed 100644
--- a/po/pl.po
+++ b/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/po/popt.pot b/po/popt.pot
index 4fb4a86..acd8de0 100644
--- a/po/popt.pot
+++ b/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/po/pt.po b/po/pt.po
index 398e7f7..9b10b57 100644
--- a/po/pt.po
+++ b/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/po/pt_BR.po b/po/pt_BR.po
index 35c4226..92426ed 100644
--- a/po/pt_BR.po
+++ b/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/po/ro.po b/po/ro.po
index cf36c52..c721649 100644
--- a/po/ro.po
+++ b/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/po/ru.po b/po/ru.po
index 692381b..f8f053b 100644
--- a/po/ru.po
+++ b/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/po/sk.po b/po/sk.po
index 1a7cf7a..d17e683 100644
--- a/po/sk.po
+++ b/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/po/sl.po b/po/sl.po
index 35071ed..d332612 100644
--- a/po/sl.po
+++ b/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/po/sr.po b/po/sr.po
index 35c4226..92426ed 100644
--- a/po/sr.po
+++ b/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/po/sv.po b/po/sv.po
index 32fd97d..e2f1328 100644
--- a/po/sv.po
+++ b/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/po/tr.po b/po/tr.po
index 8e5c43d..e528034 100644
--- a/po/tr.po
+++ b/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/po/uk.po b/po/uk.po
index 94d6890..913a46a 100644
--- a/po/uk.po
+++ b/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/po/wa.po b/po/wa.po
index 8731d70..c0c7ef5 100644
--- a/po/wa.po
+++ b/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/po/zh.po b/po/zh.po
index 35c4226..92426ed 100644
--- a/po/zh.po
+++ b/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/po/zh_CN.GB2312.po b/po/zh_CN.GB2312.po
index 4459f61..64932fa 100644
--- a/po/zh_CN.GB2312.po
+++ b/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.3 b/popt.3
index 8d17f17..0d9e0b0 100644
--- a/popt.3
+++ b/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.c b/popt.c
index 79bfdaa..d67e313 100644
--- a/popt.c
+++ b/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.h b/popt.h
index 7a0a6b1..5bae679 100644
--- a/popt.h
+++ b/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/popthelp.c b/popthelp.c
index c88d094..12fb484 100644
--- a/popthelp.c
+++ b/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/test1.c b/test1.c
index 5b6aeb7..7b7f55f 100644
--- a/test1.c
+++ b/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/testit.sh b/testit.sh
index 975b5ef..ce5530a 100755
--- a/testit.sh
+++ b/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."