From 8069caca00caac8815078603ed1db91685a29fa2 Mon Sep 17 00:00:00 2001 From: ewt Date: Thu, 25 Feb 1999 20:16:43 +0000 Subject: [PATCH] allow single dash arguments (to represent stdin) CVS patchset: 2838 CVS date: 1999/02/25 20:16:43 --- popt/popt.c | 6 +++++- popt/test1.c | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/popt/popt.c b/popt/popt.c index 7dd453d..104623e 100644 --- a/popt/popt.c +++ b/popt/popt.c @@ -231,7 +231,7 @@ static void execCommand(poptContext con) { static const struct poptOption * findOption(const struct poptOption * table, const char * longName, - const char shortName, + char shortName, poptCallbackType * callback, void ** callbackData, int singleDash) { @@ -239,6 +239,10 @@ static const struct poptOption * findOption(const struct poptOption * table, const struct poptOption * opt2; const struct poptOption * cb = NULL; + /* This happens when a single - is given */ + if (singleDash && !shortName) + shortName = '-'; + while (opt->longName || opt->shortName || opt->arg) { if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { opt2 = findOption(opt->arg, longName, shortName, callback, diff --git a/popt/test1.c b/popt/test1.c index 28ee269..04b0299 100644 --- a/popt/test1.c +++ b/popt/test1.c @@ -24,6 +24,7 @@ int main(int argc, char ** argv) { int help = 0; int usage = 0; int shortopt = 0; + int singleDash = 0; struct poptOption moreCallbackArgs[] = { { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA, option_callback, 0, NULL }, @@ -53,6 +54,7 @@ int main(int argc, char ** argv) { "This shouldn't show up", NULL }, { "unused", '\0', POPT_ARG_STRING, NULL, 0, "Unused option for help testing", "UNUSED" }, + { 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" }, POPT_AUTOHELP @@ -85,6 +87,8 @@ int main(int argc, char ** argv) { fprintf(stdout, " inc: %d", inc); if (shortopt) fprintf(stdout, " short: %d", shortopt); + if (singleDash) + fprintf(stdout, " -", shortopt); rest = poptGetArgs(optCon); if (rest) { -- 2.7.4