summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjbj <jbj>2000-09-11 16:04:15 +0000
committerjbj <jbj>2000-09-11 16:04:15 +0000
commit5e8fd8371bf240a8241b7f799adf80ffdd31532d (patch)
treec1096104c41f627e64ed666d4735f5a737831f82
parent56a8f0e55a92ef6bc6313ecc253c37db68aa2b63 (diff)
downloadlibpopt-rpm-3_0_5.tar.gz
- popt: support for float/double args.rpm-3_0_6rpm-3_0_5
-rw-r--r--po/popt.pot6
-rw-r--r--po/ro.po17
-rw-r--r--po/sk.po6
-rw-r--r--popt.319
-rw-r--r--popt.c356
-rw-r--r--popt.h19
-rw-r--r--test1.c12
-rwxr-xr-xtestit.sh24
8 files changed, 177 insertions, 282 deletions
diff --git a/po/popt.pot b/po/popt.pot
index a8101ef..655275e 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-08-27 14:45-0400\n"
+"POT-Creation-Date: 2000-09-11 11:42-0400\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"
@@ -14,10 +14,10 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: ENCODING\n"
-#: popthelp.c:27
+#: popthelp.c:23
msgid "Show this help message"
msgstr ""
-#: popthelp.c:28
+#: popthelp.c:24
msgid "Display brief usage message"
msgstr ""
diff --git a/po/ro.po b/po/ro.po
index 374856e..1df575a 100644
--- a/po/ro.po
+++ b/po/ro.po
@@ -1,19 +1,24 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR Free Software Foundation, Inc.
+# Cristian Gafton <gafton@redhat.com>, 1998.
+#
+#, fuzzy
msgid ""
msgstr ""
-"Project-Id-Version: popt 1.6\n"
-"POT-Creation-Date: 2000-08-27 14:45-0400\n"
-"PO-Revision-Date: 2000-06-14 23:23+EST\n"
+"Project-Id-Version: POPT\n"
+"POT-Creation-Date: 2000-09-11 11:42-0400\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Cristian Gafton <gafton@redhat.com>\n"
-"Language-Team: Romanian <ro@li.org>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ISO-8859-2\n"
"Content-Transfer-Encoding: 8bit\n"
-#: popthelp.c:27
+#: popthelp.c:23
msgid "Show this help message"
msgstr "Afisare mesaj de help"
-#: popthelp.c:28
+#: popthelp.c:24
msgid "Display brief usage message"
msgstr "Afisare mesaj sintaxa sumar"
diff --git a/po/sk.po b/po/sk.po
index 5350784..df36821 100644
--- a/po/sk.po
+++ b/po/sk.po
@@ -5,7 +5,7 @@
msgid ""
msgstr ""
"Project-Id-Version: popt\n"
-"POT-Creation-Date: 2000-08-27 14:45-0400\n"
+"POT-Creation-Date: 2000-09-11 11:42-0400\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"
@@ -13,10 +13,10 @@ msgstr ""
"Content-Type: text/plain; charset=iso-8859-2\n"
"Content-Transfer-Encoding: 8bit\n"
-#: popthelp.c:27
+#: popthelp.c:23
msgid "Show this help message"
msgstr "Vypísať túto správu"
-#: popthelp.c:28
+#: popthelp.c:24
msgid "Display brief usage message"
msgstr "Zobraziť stručný návod na použitie"
diff --git a/popt.3 b/popt.3
index 29a6309..1ab1807 100644
--- a/popt.3
+++ b/popt.3
@@ -128,14 +128,10 @@ POPT_ARG_STRING No type checking to be performed char *
POPT_ARG_INT An integer argument is expected int
POPT_ARG_LONG A long integer is expected long
POPT_ARG_VAL Integer value taken from \f(CWval\fR int
+POPT_ARG_FLOAT An float argument is expected float
+POPT_ARG_DOUBLE A double argument is expected double
.TE
.sp
-For numeric values, if the \fIargInfo\fR value is bitwise or'd with one of
-\fBPOPT_ARGFLAG_OR\fR, \fBPOPT_ARGFLAG_AND\fR, or \fBPOPT_ARGFLAG_XOR\fR,
-the value is saved by performing an OR, AND, or XOR.
-If the \fIargInfo\fR value is bitwise or'd with \fBPOPT_ARGFLAG_NOT\fR,
-the value will be negated before saving.
-.sp
If the \fIargInfo\fR value is bitwise or'd with \fBPOPT_ARGFLAG_ONEDASH\fR,
the long argument may be given with a single - instead of two. For example,
if \fB--longopt\fR is an option with \fBPOPT_ARGFLAG_ONEDASH\fR, is
@@ -155,8 +151,9 @@ will perhaps not escape the attention of hunt-and-peck typists that
an argument, the variable that
.IR arg " points to is updated to reflect the value of the argument."
.RB "Any string is acceptable for " POPT_ARG_STRING " arguments, but "
-.BR POPT_ARG_INT " and " POPT_ARG_LONG " are converted to the
-appropriate type, and an error returned if the conversion fails.
+.BR POPT_ARG_INT ", " POPT_ARG_LONG ", " POPT_ARG_FLOAT ", and "
+.BR POPT_ARG_DOUBLE " are converted to the appropriate type, and an "
+error returned if the conversion fails.
.sp
\fBPOPT_ARG_VAL\fR causes \fIarg\fP to be set to the (integer) value of
\fIval\fP when the argument is found. This is most often useful for
@@ -445,14 +442,16 @@ A parsed string has a quotation mismatch (such as a single quotation
A conversion from a string to a number (int or long) failed due
to the string containing nonnumeric characters. This occurs when
.BR poptGetNextOpt() " is processing an argument of type "
-.BR POPT_ARG_INT " or " POPT_ARG_LONG .
+.BR POPT_ARG_INT ", " POPT_ARG_LONG ", "
+.RB POPT_ARG_FLOAT ", or " POPT_ARG_DOUBLE "."
.sp
.TP
.B POPT_ERROR_OVERFLOW
A string-to-number conversion failed because the number was too
.RB "large or too small. Like " POPT_ERROR_BADNUMBER ", this error
.RB "can occur only when " poptGetNextOpt() " is processing an "
-.RB "argument of type " POPT_ARG_INT " or " POPT_ARG_LONG .
+.RB "argument of type " POPT_ARG_INT ", " POPT_ARG_LONG ", "
+.RB POPT_ARG_FLOAT ", or " POPT_ARG_DOUBLE "."
.sp
.TP
.B POPT_ERROR_ERRNO
diff --git a/popt.c b/popt.c
index 0726c32..54e2784 100644
--- a/popt.c
+++ b/popt.c
@@ -1,14 +1,11 @@
-/** \ingroup popt
- * \file popt/popt.c
- */
-
/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from
ftp://ftp.redhat.com/pub/code/popt */
-#undef MYDEBUG
-
#include "system.h"
+
+#include <math.h>
+
#include "findme.h"
#include "poptint.h"
@@ -30,72 +27,27 @@ void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) {
con->execAbsolute = allowAbsolute;
}
-static void invokeCallbacksPRE(poptContext con, const struct poptOption * opt)
-{
- for (; opt->longName || opt->shortName || opt->arg; opt++) {
- if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
- /* Recurse on included sub-tables. */
- invokeCallbacksPRE(con, opt->arg);
- } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK &&
- (opt->argInfo & POPT_CBFLAG_PRE))
- { poptCallbackType cb = (poptCallbackType)opt->arg;
- /* Perform callback. */
- cb(con, POPT_CALLBACK_REASON_PRE, NULL, NULL, opt->descrip);
- }
- }
-}
-
-static void invokeCallbacksPOST(poptContext con, const struct poptOption * opt)
-{
- for (; opt->longName || opt->shortName || opt->arg; opt++) {
- if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
- /* Recurse on included sub-tables. */
- invokeCallbacksPOST(con, opt->arg);
- } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK &&
- (opt->argInfo & POPT_CBFLAG_POST))
- { poptCallbackType cb = (poptCallbackType)opt->arg;
- /* Perform callback. */
- cb(con, POPT_CALLBACK_REASON_POST, NULL, NULL, opt->descrip);
- }
- }
-}
-
-static void invokeCallbacksOPTION(poptContext con,
- const struct poptOption * opt,
- const struct poptOption * myOpt,
- const void * myData, int shorty)
-{
- const struct poptOption * cbopt = NULL;
+static void invokeCallbacks(poptContext con, const struct poptOption * table,
+ int post) {
+ const struct poptOption * opt = table;
+ poptCallbackType cb;
- for (; opt->longName || opt->shortName || opt->arg; opt++) {
+ while (opt->longName || opt->shortName || opt->arg) {
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
- /* Recurse on included sub-tables. */
- invokeCallbacksOPTION(con, opt->arg, myOpt, myData, shorty);
- } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK &&
- !(opt->argInfo & POPT_CBFLAG_SKIPOPTION)) {
- /* Save callback info. */
- cbopt = opt;
- } else if (cbopt != NULL &&
- ((myOpt->shortName && opt->shortName && shorty &&
- myOpt->shortName == opt->shortName) ||
- (myOpt->longName && opt->longName &&
- !strcmp(myOpt->longName, opt->longName)))
- )
- { poptCallbackType cb = (poptCallbackType)cbopt->arg;
- const void * cbData = (cbopt->descrip ? cbopt->descrip : myData);
- /* Perform callback. */
- cb(con, POPT_CALLBACK_REASON_OPTION, myOpt,
- con->os->nextArg, cbData);
- /* Terminate (unless explcitly continuing). */
- if (!(cbopt->argInfo & POPT_CBFLAG_CONTINUE))
- return;
+ invokeCallbacks(con, opt->arg, post);
+ } else if (((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK) &&
+ ((!post && (opt->argInfo & POPT_CBFLAG_PRE)) ||
+ ( post && (opt->argInfo & POPT_CBFLAG_POST)))) {
+ cb = (poptCallbackType)opt->arg;
+ cb(con, post ? POPT_CALLBACK_REASON_POST : POPT_CALLBACK_REASON_PRE,
+ NULL, NULL, opt->descrip);
}
+ opt++;
}
}
poptContext poptGetContext(const char * name, int argc, const char ** argv,
- const struct poptOption * options, int flags)
-{
+ const struct poptOption * options, int flags) {
poptContext con = malloc(sizeof(*con));
memset(con, 0, sizeof(*con));
@@ -126,7 +78,7 @@ poptContext poptGetContext(const char * name, int argc, const char ** argv,
if (name)
con->appName = strcpy(malloc(strlen(name) + 1), name);
- invokeCallbacksPRE(con, con->options);
+ invokeCallbacks(con, con->options, 0);
return con;
}
@@ -269,43 +221,37 @@ static int handleAlias(poptContext con, const char * longName, char shortName,
static void execCommand(poptContext con) {
const char ** argv;
- int argc = 0;
- const char ** sargv;
- int sargc = 0;
-
- poptParseArgvString(con->doExec->script, &sargc, &sargv);
-
- if (sargv == NULL || sargc < 1 ||
- (!con->execAbsolute && strchr(sargv[0], '/')))
- return;
+ int pos = 0;
+ const char * script = con->doExec->script;
argv = malloc(sizeof(*argv) *
- (6 + sargc + con->numLeftovers + con->finalArgvCount));
+ (6 + con->numLeftovers + con->finalArgvCount));
+
+ if (!con->execAbsolute && strchr(script, '/')) return;
- if (!strchr(sargv[0], '/') && con->execPath) {
- char *s = alloca(strlen(con->execPath) + strlen(sargv[0]) + sizeof("/"));
- sprintf(s, "%s/%s", con->execPath, sargv[0]);
- argv[argc] = s;
+ if (!strchr(script, '/') && con->execPath) {
+ char *s = alloca(strlen(con->execPath) + strlen(script) + 2);
+ sprintf(s, "%s/%s", con->execPath, script);
+ argv[pos] = s;
} else {
- argv[argc] = findProgramPath(sargv[0]);
+ argv[pos] = script;
}
- if (argv[argc++] == NULL) return;
+ pos++;
- if (sargc > 1) {
- memcpy(argv + argc, sargv + 1, sizeof(*argv) * (sargc - 1));
- argc += (sargc - 1);
- }
+ argv[pos] = findProgramPath(con->os->argv[0]);
+ if (argv[pos]) pos++;
+ argv[pos++] = ";";
- memcpy(argv + argc, con->finalArgv, sizeof(*argv) * con->finalArgvCount);
- argc += con->finalArgvCount;
+ memcpy(argv + pos, con->finalArgv, sizeof(*argv) * con->finalArgvCount);
+ pos += con->finalArgvCount;
if (con->numLeftovers) {
- argv[argc++] = "--";
- memcpy(argv + argc, con->leftovers, sizeof(*argv) * con->numLeftovers);
- argc += con->numLeftovers;
+ argv[pos++] = "--";
+ memcpy(argv + pos, con->leftovers, sizeof(*argv) * con->numLeftovers);
+ pos += con->numLeftovers;
}
- argv[argc++] = NULL;
+ argv[pos++] = NULL;
#ifdef __hpux
setresuid(getuid(), getuid(),-1);
@@ -324,42 +270,29 @@ static void execCommand(poptContext con) {
#endif
#endif
- if (argv[0] == NULL)
- return;
-#ifdef MYDEBUG
- { const char ** arg;
- fprintf(stderr, "==> execvp(%s):", argv[0]);
- for (arg = argv; *arg; arg++)
- fprintf(stderr, " %s", *arg);
- fprintf(stderr, "\n");
- }
-#endif
-
execvp(argv[0], (char *const *)argv);
}
/*@observer@*/ static const struct poptOption *
-findOption(const struct poptOption * opt, const char * longName,
+findOption(const struct poptOption * table, const char * longName,
char shortName,
/*@out@*/ poptCallbackType * callback, /*@out@*/ const void ** callbackData,
int singleDash)
{
+ const struct poptOption * opt = table;
+ const struct poptOption * opt2;
const struct poptOption * cb = NULL;
/* This happens when a single - is given */
if (singleDash && !shortName && !*longName)
shortName = '-';
- for (; opt->longName || opt->shortName || opt->arg; opt++) {
-
+ while (opt->longName || opt->shortName || opt->arg) {
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
- const struct poptOption * opt2;
- /* Recurse on included sub-tables. */
opt2 = findOption(opt->arg, longName, shortName, callback,
callbackData, singleDash);
if (opt2) {
- /* Sub-table data will be inheirited if no data yet. */
- if (*callback && *callbackData == NULL)
+ if (*callback && !*callbackData)
*callbackData = opt->descrip;
return opt2;
}
@@ -372,10 +305,10 @@ findOption(const struct poptOption * opt, const char * longName,
} else if (shortName && shortName == opt->shortName) {
break;
}
+ opt++;
}
- if (!opt->longName && !opt->shortName)
- return NULL;
+ if (!opt->longName && !opt->shortName) return NULL;
*callbackData = NULL;
*callback = NULL;
if (cb) {
@@ -456,71 +389,12 @@ static /*@only@*/ const char * expandNextArg(poptContext con, const char * s)
static void poptStripArg(poptContext con, int which)
{
- if (con->arg_strip == NULL)
+ if(con->arg_strip == NULL) {
con->arg_strip = PBM_ALLOC(con->optionStack[0].argc);
- PBM_SET(which, con->arg_strip);
-}
-
-static int poptSaveLong(const struct poptOption * opt, long aLong) {
- if (opt->argInfo & POPT_ARGFLAG_NOT)
- aLong = ~aLong;
- switch (opt->argInfo & POPT_ARGFLAG_LOGICALOPS) {
- case 0:
- *((long *) opt->arg) = aLong;
- break;
- case POPT_ARGFLAG_OR:
- *((long *) opt->arg) |= aLong;
- break;
- case POPT_ARGFLAG_AND:
- *((long *) opt->arg) &= aLong;
- break;
- case POPT_ARGFLAG_XOR:
- *((long *) opt->arg) ^= aLong;
- break;
- default:
- return POPT_ERROR_BADOPERATION;
- break;
- }
- return 0;
-}
-
-static int poptSaveInt(const struct poptOption * opt, long aLong) {
- if (opt->argInfo & POPT_ARGFLAG_NOT)
- aLong = ~aLong;
- switch (opt->argInfo & POPT_ARGFLAG_LOGICALOPS) {
- case 0:
- *((int *) opt->arg) = aLong;
- break;
- case POPT_ARGFLAG_OR:
- *((int *) opt->arg) |= aLong;
- break;
- case POPT_ARGFLAG_AND:
- *((int *) opt->arg) &= aLong;
- break;
- case POPT_ARGFLAG_XOR:
- *((int *) opt->arg) ^= aLong;
- break;
- default:
- return POPT_ERROR_BADOPERATION;
- break;
}
- return 0;
+ PBM_SET(which, con->arg_strip);
}
-#ifdef MYDEBUG
-static void prtcon(const char *msg, poptContext con)
-{
- if (msg) fprintf(stderr, "%s", msg);
- fprintf(stderr, "\tcon %p os %p nextCharArg \"%s\" nextArg \"%s\" argv[%d] \"%s\"\n",
- con, con->os,
- (con->os->nextCharArg ? con->os->nextCharArg : ""),
- (con->os->nextArg ? con->os->nextArg : ""),
- con->os->next,
- (con->os->argv && con->os->argv[con->os->next]
- ? con->os->argv[con->os->next] : ""));
-}
-#endif
-
/* returns 'val' element, -1 on last item, POPT_ERROR_* on error */
int poptGetNextOpt(poptContext con)
{
@@ -533,14 +407,13 @@ int poptGetNextOpt(poptContext con)
const void * cbData = NULL;
const char * longArg = NULL;
int canstrip = 0;
- int shorty = 0;
while (!con->os->nextCharArg && con->os->next == con->os->argc
&& con->os > con->optionStack) {
cleanOSE(con->os--);
}
if (!con->os->nextCharArg && con->os->next == con->os->argc) {
- invokeCallbacksPOST(con, con->options);
+ invokeCallbacks(con, con->options, 1);
if (con->doExec) execCommand(con);
return -1;
}
@@ -554,7 +427,7 @@ int poptGetNextOpt(poptContext con)
con->os->next++;
continue;
}
- thisopt = con->os->next;
+ thisopt=con->os->next;
origOptString = con->os->argv[con->os->next++];
if (con->restLeftover || *origOptString != '-') {
@@ -609,12 +482,11 @@ int poptGetNextOpt(poptContext con)
if (!opt) {
con->os->nextCharArg = origOptString + 1;
} else {
- if (con->os == con->optionStack &&
+ if(con->os == con->optionStack &&
opt->argInfo & POPT_ARGFLAG_STRIP) {
canstrip = 1;
poptStripArg(con, thisopt);
}
- shorty = 0;
}
}
@@ -626,33 +498,27 @@ int poptGetNextOpt(poptContext con)
if (handleAlias(con, NULL, *origOptString,
origOptString + 1)) {
- continue;
- }
- if (handleExec(con, NULL, *origOptString)) {
- /* Restore rest of short options for further processing */
origOptString++;
- if (*origOptString) con->os->nextCharArg = origOptString;
continue;
}
+ if (handleExec(con, NULL, *origOptString))
+ continue;
opt = findOption(con->options, NULL, *origOptString, &cb,
&cbData, 0);
if (!opt)
return POPT_ERROR_BADOPT;
- shorty = 1;
origOptString++;
- if (*origOptString) con->os->nextCharArg = origOptString;
+ if (*origOptString)
+ con->os->nextCharArg = origOptString;
}
if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) {
- if (poptSaveInt(opt, 1L))
- return POPT_ERROR_BADOPERATION;
+ *((int *)opt->arg) = 1;
} else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL) {
- if (opt->arg) {
- if (poptSaveInt(opt, (long)opt->val))
- return POPT_ERROR_BADOPERATION;
- }
+ if (opt->arg)
+ *((int *) opt->arg) = opt->val;
} else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) {
if (con->os->nextArg) {
xfree(con->os->nextArg);
@@ -673,7 +539,7 @@ int poptGetNextOpt(poptContext con)
/* make sure this isn't part of a short arg or the
result of an alias expansion */
- if (con->os == con->optionStack &&
+ if(con->os == con->optionStack &&
opt->argInfo & POPT_ARGFLAG_STRIP &&
canstrip) {
poptStripArg(con, con->os->next);
@@ -683,35 +549,60 @@ int poptGetNextOpt(poptContext con)
}
if (opt->arg) {
+ double aDouble;
+ long aLong;
+ char *end;
+
switch (opt->argInfo & POPT_ARG_MASK) {
- case POPT_ARG_STRING:
+ case POPT_ARG_STRING:
/* XXX memory leak, hard to plug */
*((const char **) opt->arg) = xstrdup(con->os->nextArg);
break;
- case POPT_ARG_INT:
- case POPT_ARG_LONG:
- { long aLong;
- char *end;
-
+ case POPT_ARG_INT:
+ case POPT_ARG_LONG:
aLong = strtol(con->os->nextArg, &end, 0);
if (!(end && *end == '\0'))
return POPT_ERROR_BADNUMBER;
+ if (aLong == LONG_MIN || aLong == LONG_MAX)
+ return POPT_ERROR_OVERFLOW;
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {
- if (aLong == LONG_MIN || aLong == LONG_MAX)
- return POPT_ERROR_OVERFLOW;
- if (poptSaveLong(opt, aLong))
- return POPT_ERROR_BADOPERATION;
+ *((long *) opt->arg) = aLong;
} else {
if (aLong > INT_MAX || aLong < INT_MIN)
return POPT_ERROR_OVERFLOW;
- if (poptSaveInt(opt, aLong))
- return POPT_ERROR_BADOPERATION;
+ *((int *) opt->arg) = aLong;
+ }
+ break;
+
+ case POPT_ARG_FLOAT:
+ case POPT_ARG_DOUBLE:
+ aDouble = strtod(con->os->nextArg, &end);
+ if (*end)
+ return POPT_ERROR_BADNUMBER;
+
+ if (aDouble == +HUGE_VAL || aDouble == -HUGE_VAL)
+ return POPT_ERROR_OVERFLOW;
+ if (aDouble == 0.0 && errno == ERANGE)
+ return POPT_ERROR_OVERFLOW;
+ if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_DOUBLE) {
+ *((double *) opt->arg) = aDouble;
+ } else {
+#ifdef ABS
+#undef ABS
+#endif
+#define ABS(a) (((a) < 0) ? -(a) : (a))
+ if (ABS(aDouble) > FLT_MAX)
+ return POPT_ERROR_OVERFLOW;
+ if (ABS(aDouble) < FLT_MIN)
+ return POPT_ERROR_OVERFLOW;
+ *((float *) opt->arg) = aDouble;
}
- } break;
- default:
+ break;
+
+ default:
fprintf(stdout, POPT_("option type (%d) not implemented in popt\n"),
opt->argInfo & POPT_ARG_MASK);
exit(EXIT_FAILURE);
@@ -720,7 +611,7 @@ int poptGetNextOpt(poptContext con)
}
if (cb)
- invokeCallbacksOPTION(con, con->options, opt, cbData, shorty);
+ cb(con, POPT_CALLBACK_REASON_OPTION, opt, con->os->nextArg, cbData);
else if (opt->val && ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL))
done = 1;
@@ -730,21 +621,16 @@ int poptGetNextOpt(poptContext con)
sizeof(*con->finalArgv) * con->finalArgvAlloced);
}
- { char *s = malloc((opt->longName ? strlen(opt->longName) : 0) + 3);
+ { char *s = malloc((opt->longName ? strlen(opt->longName) : 0) + 3);
if (opt->longName)
- sprintf(s, "%s%s",
- ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "-" : "--"),
- opt->longName);
+ sprintf(s, "--%s", opt->longName);
else
sprintf(s, "-%c", opt->shortName);
con->finalArgv[con->finalArgvCount++] = s;
}
- if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE)
- /*@-ifempty@*/ ;
- else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL)
- /*@-ifempty@*/ ;
- else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) {
+ if (opt->arg && (opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE
+ && (opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL) {
con->finalArgv[con->finalArgvCount++] = xstrdup(con->os->nextArg);
}
}
@@ -759,15 +645,13 @@ const char * poptGetOptArg(poptContext con) {
}
const char * poptGetArg(poptContext con) {
- const char * ret = (con->nextLeftover < con->numLeftovers)
- ? con->leftovers[con->nextLeftover++] : NULL;
- return ret;
+ if (con->numLeftovers == con->nextLeftover) return NULL;
+ return con->leftovers[con->nextLeftover++];
}
const char * poptPeekArg(poptContext con) {
- const char * ret = (con->nextLeftover < con->numLeftovers)
- ? con->leftovers[con->nextLeftover] : NULL;
- return ret;
+ if (con->numLeftovers == con->nextLeftover) return NULL;
+ return con->leftovers[con->nextLeftover];
}
const char ** poptGetArgs(poptContext con) {
@@ -842,14 +726,18 @@ const char * poptBadOption(poptContext con, int flags) {
return os->argv[os->next - 1];
}
+#define POPT_ERROR_NOARG -10
+#define POPT_ERROR_BADOPT -11
+#define POPT_ERROR_OPTSTOODEEP -13
+#define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */
+#define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */
+
const char *const poptStrerror(const int error) {
switch (error) {
case POPT_ERROR_NOARG:
return POPT_("missing argument");
case POPT_ERROR_BADOPT:
return POPT_("unknown option");
- case POPT_ERROR_BADOPERATION:
- return POPT_("mutually exclusive logical operations requested");
case POPT_ERROR_OPTSTOODEEP:
return POPT_("aliases nested too deeply");
case POPT_ERROR_BADQUOTE:
@@ -894,17 +782,23 @@ int poptStrippedArgv(poptContext con, int argc, char **argv)
{
int i,j=1, numargs=argc;
- for (i = 1; i < argc; i++) {
- if (PBM_ISSET(i, con->arg_strip))
+ for(i=1; i<argc; i++) {
+ if(PBM_ISSET(i, con->arg_strip)) {
numargs--;
+ }
}
- for (i = 1; i < argc; i++) {
- if (PBM_ISSET(i, con->arg_strip))
+ for(i=1; i<argc; i++) {
+ if(PBM_ISSET(i, con->arg_strip)) {
continue;
- argv[j] = (j < numargs) ? argv[i] : '\0';
- j++;
+ } else {
+ if(j<numargs) {
+ argv[j++]=argv[i];
+ } else {
+ argv[j++]='\0';
+ }
+ }
}
- return numargs;
+ return(numargs);
}
diff --git a/popt.h b/popt.h
index b6e1f6b..a5263ee 100644
--- a/popt.h
+++ b/popt.h
@@ -1,7 +1,3 @@
-/** \ingroup popt
- * \file popt/popt.h
- */
-
/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from
ftp://ftp.redhat.com/pub/code/popt */
@@ -31,27 +27,17 @@ extern "C" {
included tables; arg points
to the domain string */
#define POPT_ARG_VAL 7 /* arg should take value val */
+#define POPT_ARG_FLOAT 8
+#define POPT_ARG_DOUBLE 9
#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_OR 0x08000000 /* arg will be or'ed */
-#define POPT_ARGFLAG_NOR 0x09000000 /* arg will be nor'ed */
-#define POPT_ARGFLAG_AND 0x04000000 /* arg will be and'ed */
-#define POPT_ARGFLAG_NAND 0x05000000 /* arg will be nand'ed */
-#define POPT_ARGFLAG_XOR 0x02000000 /* arg will be xor'ed */
-#define POPT_ARGFLAG_NOT 0x01000000 /* arg will be negated */
-#define POPT_ARGFLAG_LOGICALOPS \
- (POPT_ARGFLAG_OR|POPT_ARGFLAG_AND|POPT_ARGFLAG_XOR)
-
#define POPT_CBFLAG_PRE 0x80000000 /* call the callback before parse */
#define POPT_CBFLAG_POST 0x40000000 /* call the callback after parse */
#define POPT_CBFLAG_INC_DATA 0x20000000 /* use data from the include line,
not the subtable */
-#define POPT_CBFLAG_SKIPOPTION 0x10000000 /* don't callback with option */
-#define POPT_CBFLAG_CONTINUE 0x08000000 /* continue callbacks with option */
#define POPT_ERROR_NOARG -10
#define POPT_ERROR_BADOPT -11
@@ -60,7 +46,6 @@ extern "C" {
#define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */
#define POPT_ERROR_BADNUMBER -17
#define POPT_ERROR_OVERFLOW -18
-#define POPT_ERROR_BADOPERATION -19
/* poptBadOption() flags */
#define POPT_BADOPTION_NOALIAS (1 << 0) /* don't go into an alias */
diff --git a/test1.c b/test1.c
index 416d59e..fdd3a4a 100644
--- a/test1.c
+++ b/test1.c
@@ -17,6 +17,8 @@ char * arg2 = "(none)";
int arg3 = 0;
int inc = 0;
int shortopt = 0;
+float aFloat = 0.0;
+double aDouble = 0.0;
int singleDash = 0;
static struct poptOption moreCallbackArgs[] = {
@@ -48,6 +50,10 @@ static struct poptOption options[] = {
"This shouldn't show up", NULL },
{ "unused", '\0', POPT_ARG_STRING, NULL, 0,
"Unused option for help testing", "UNUSED" },
+ { "float", 'f', POPT_ARG_FLOAT, &aFloat, 0,
+ "A float argument", "FLOAT" },
+ { "double", 'd', POPT_ARG_DOUBLE, &aDouble, 0,
+ "A double argument", "DOUBLE" },
{ 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" },
@@ -62,6 +68,8 @@ static void resetVars(void)
arg3 = 0;
inc = 0;
shortopt = 0;
+ aFloat = 0.0;
+ aDouble = 0.0;
singleDash = 0;
pass2 = 0;
}
@@ -116,6 +124,10 @@ int main(int argc, const char ** argv) {
fprintf(stdout, " inc: %d", inc);
if (shortopt)
fprintf(stdout, " short: %d", shortopt);
+ if (aFloat != 0.0)
+ fprintf(stdout, " aFloat: %g", aFloat);
+ if (aDouble != 0.0)
+ fprintf(stdout, " aDouble: %g", aDouble);
if (singleDash)
fprintf(stdout, " -");
diff --git a/testit.sh b/testit.sh
index d73dfb2..1923765 100755
--- a/testit.sh
+++ b/testit.sh
@@ -15,7 +15,6 @@ run() {
}
builddir=`pwd`
-srcdir=$builddir
cd ${srcdir}
test1=${builddir}/test1
echo "Running tests in `pwd`"
@@ -37,18 +36,14 @@ run test1 "test1 - 12" "arg1: 1 arg2: (none)" -O
run test1 "test1 - 13" "arg1: 1 arg2: foo" -OT foo
run test1 "test1 - 14" "arg1: 0 arg2: (none) inc: 1" --inc
run test1 "test1 - 15" "arg1: 0 arg2: foo inc: 1" -i --arg2 foo
-export POSIX_ME_HARDER=1
-run test1 "test1 - 16" "arg1: 1 arg2: (none) rest: foo --arg2 something" --arg1 foo --arg2 something
-unset POSIX_ME_HARDER
-export POSIXLY_CORRECT=1
-run test1 "test1 - 17" "arg1: 1 arg2: (none) rest: foo --arg2 something" --arg1 foo --arg2 something
-unset POSIXLY_CORRECT
+POSIX_ME_HARDER=1 run test1 "test1 - 16" "arg1: 1 arg2: (none) rest: foo --arg2 something" --arg1 foo --arg2 something
+POSIXLY_CORRECT=1 run test1 "test1 - 17" "arg1: 1 arg2: (none) rest: foo --arg2 something" --arg1 foo --arg2 something
run test1 "test1 - 18" "callback: c sampledata bar arg1: 1 arg2: (none)" --arg1 --cb bar
-run test1 "test1 - 19" "" --echo-args
-run test1 "test1 - 20" "--arg1" --echo-args --arg1
-run test1 "test1 - 21" "--arg2 something" -T something -e
-run test1 "test1 - 22" "--arg2 something -- more args" -T something -a more args
-run test1 "test1 - 23" "--echo-args -a" --echo-args -e -a
+run test1 "test1 - 19" "${test1} ;" --echo-args
+run test1 "test1 - 20" "${test1} ; --arg1" --echo-args --arg1
+run test1 "test1 - 21" "${test1} ; --arg2 something" -T something -e
+run test1 "test1 - 22" "${test1} ; --arg2 something -- more args" -T something -a more args
+run test1 "test1 - 23" "${test1} ; --echo-args -a" --echo-args -e -a
run test1 "test1 - 24" "arg1: 0 arg2: (none) short: 1" -shortoption
run test1 "test1 - 25" "arg1: 0 arg2: (none) short: 1" --shortoption
run test1 "test1 - 26" "callback: c arg for cb2 foo arg1: 0 arg2: (none)" --cb2 foo
@@ -58,5 +53,10 @@ run test1 "test1 - 29" "arg1: 0 arg2: bbbb" --arg2=aaaa -2 bbbb
run test1 "test1 - 30" "arg1: 0 arg2: 'foo bingo' rest: boggle" --grab bingo boggle
run test1 "test1 - 31" "arg1: 0 arg2: 'foo bar' rest: boggle" --grabbar boggle
+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
+
echo ""
echo "Passed."