From: ewt Date: Wed, 21 Oct 1998 20:31:23 +0000 (+0000) Subject: added POPT_ARGFLAG_ONEDASH X-Git-Tag: tznext/4.11.0.1.tizen20130304~9618 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=46e27fdf22ebbcf2f215486d22ff80eb3986607b;p=tools%2Flibrpm-tizen.git added POPT_ARGFLAG_ONEDASH CVS patchset: 2471 CVS date: 1998/10/21 20:31:23 --- diff --git a/popt/popt.c b/popt/popt.c index a836710..be9a181 100644 --- a/popt/popt.c +++ b/popt/popt.c @@ -211,7 +211,8 @@ static const struct poptOption * findOption(const struct poptOption * table, 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; @@ -219,11 +220,12 @@ static const struct poptOption * findOption(const struct poptOption * table, 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) { @@ -255,6 +257,7 @@ int poptGetNextOpt(poptContext con) { int i; poptCallbackType cb; void * cbData; + int singleDash; while (!done) { while (!con->os->nextCharArg && con->os->next == con->os->argc @@ -287,8 +290,12 @@ int poptGetNextOpt(poptContext con) { 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; @@ -302,9 +309,12 @@ int poptGetNextOpt(poptContext con) { *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; } @@ -321,7 +331,8 @@ int poptGetNextOpt(poptContext con) { 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++; diff --git a/popt/popt.h b/popt/popt.h index aee7ccb..64c7b80 100644 --- a/popt/popt.h +++ b/popt/popt.h @@ -19,7 +19,7 @@ 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 diff --git a/popt/test1.c b/popt/test1.c index 91624ad..8f53723 100644 --- a/popt/test1.c +++ b/popt/test1.c @@ -22,6 +22,7 @@ int main(int argc, char ** argv) { 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" }, @@ -38,6 +39,8 @@ int main(int argc, char ** argv) { " 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 }, @@ -70,6 +73,8 @@ int main(int argc, char ** argv) { fprintf(stdout, " arg3: %d", arg3); if (inc) fprintf(stdout, " inc: %d", inc); + if (shortopt) + fprintf(stdout, " short: %d", shortopt); rest = poptGetArgs(optCon); if (rest) { diff --git a/popt/testit.sh b/popt/testit.sh index 5bdedf3..a231df8 100755 --- a/popt/testit.sh +++ b/popt/testit.sh @@ -39,6 +39,8 @@ 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 echo "" echo "Passed."