const char * longName,
const char shortName,
poptCallbackType * callback,
- void ** callbackData) {
+ void ** callbackData,
+ int singleDash) {
const struct poptOption * opt = table;
const struct poptOption * opt2;
const struct poptOption * cb = NULL;
while (opt->longName || opt->shortName || opt->arg) {
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
opt2 = findOption(opt->arg, longName, shortName, callback,
- callbackData);
+ callbackData, singleDash);
if (opt2) return opt2;
} else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK) {
cb = opt;
} else if (longName && opt->longName &&
+ (!singleDash || (opt->argInfo & POPT_ARGFLAG_ONEDASH)) &&
!strcmp(longName, opt->longName)) {
break;
} else if (shortName && shortName == opt->shortName) {
int i;
poptCallbackType cb;
void * cbData;
+ int singleDash;
while (!done) {
while (!con->os->nextCharArg && con->os->next == con->os->argc
if (optString[1] == '-' && !optString[2]) {
con->restLeftover = 1;
continue;
- } else if (optString[1] == '-') {
- optString += 2;
+ } else {
+ optString++;
+ if (*optString == '-')
+ singleDash = 0, optString++;
+ else
+ singleDash = 1;
if (handleAlias(con, optString, '\0', NULL))
continue;
*chptr = '\0';
}
- opt = findOption(con->options, optString, '\0', &cb, &cbData);
- if (!opt) return POPT_ERROR_BADOPT;
- } else
+ opt = findOption(con->options, optString, '\0', &cb, &cbData,
+ singleDash);
+ if (!opt && !singleDash) return POPT_ERROR_BADOPT;
+ }
+
+ if (!opt)
con->os->nextCharArg = origOptString + 1;
}
if (handleExec(con, NULL, *origOptString))
continue;
- opt = findOption(con->options, NULL, *origOptString, &cb, &cbData);
+ opt = findOption(con->options, NULL, *origOptString, &cb,
+ &cbData, 0);
if (!opt) return POPT_ERROR_BADOPT;
origOptString++;
to callback, descrip points to
callback data to pass */
#define POPT_ARG_MASK 0x0000FFFF
-#define POPT_ARGFLAG_MULTIPLE 0x80000000
+#define POPT_ARGFLAG_ONEDASH 0x80000000 /* allow -longoption */
#define POPT_ERROR_NOARG -10
#define POPT_ERROR_BADOPT -11
int inc = 0;
int help = 0;
int usage = 0;
+ int shortopt = 0;
struct poptOption callbackArgs[] = {
{ NULL, '\0', POPT_ARG_CALLBACK, option_callback, 0, "sampledata" },
{ "cb", 'c', POPT_ARG_STRING, NULL, 'c', "Test argument callbacks" },
" wrapping somehow, right?", NULL },
{ "arg2", '2', POPT_ARG_STRING, &arg2, 0, "Another argument", "ARG" },
{ "arg3", '3', POPT_ARG_INT, &arg3, 0, "A third argument", "ANARG" },
+ { "shortoption", '\0', POPT_ARGFLAG_ONEDASH, &shortopt, 0,
+ "Needs a single -", NULL },
{ "unused", '\0', POPT_ARG_STRING, NULL, 0,
"Unused option for help testing", "UNUSED" },
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, &moreArgs, 0, NULL },
fprintf(stdout, " arg3: %d", arg3);
if (inc)
fprintf(stdout, " inc: %d", inc);
+ if (shortopt)
+ fprintf(stdout, " short: %d", shortopt);
rest = poptGetArgs(optCon);
if (rest) {
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
echo ""
echo "Passed."