summaryrefslogtreecommitdiff
path: root/popt/test1.c
diff options
context:
space:
mode:
authorjbj <devnull@localhost>1999-10-22 18:25:39 +0000
committerjbj <devnull@localhost>1999-10-22 18:25:39 +0000
commite2d517c67ce9c4a100bad0e44f17b930e4b457b7 (patch)
tree32e16697774f0a0a55eceb58796b1dd7b54c9b93 /popt/test1.c
parentd4fed4bde1aafd03c328b7ebd710a8e33c7f2203 (diff)
downloadlibrpm-tizen-e2d517c67ce9c4a100bad0e44f17b930e4b457b7.tar.gz
librpm-tizen-e2d517c67ce9c4a100bad0e44f17b930e4b457b7.tar.bz2
librpm-tizen-e2d517c67ce9c4a100bad0e44f17b930e4b457b7.zip
Modify test1 to do poptResetContext before parsing args.
CVS patchset: 3397 CVS date: 1999/10/22 18:25:39
Diffstat (limited to 'popt/test1.c')
-rw-r--r--popt/test1.c47
1 files changed, 34 insertions, 13 deletions
diff --git a/popt/test1.c b/popt/test1.c
index 4a33287f7..cd8e8977a 100644
--- a/popt/test1.c
+++ b/popt/test1.c
@@ -1,5 +1,5 @@
/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING
- file accompanying popt source distributions, available from
+ file accompanying popt source distributions, available from
ftp://ftp.redhat.com/pub/code/popt */
#include <stdio.h>
@@ -7,10 +7,12 @@
#include "popt.h"
+static int pass2 = 0;
static void option_callback(poptContext con, enum poptCallbackReason reason,
- const struct poptOption * opt,
+ const struct poptOption * opt,
char * arg, void * data) {
- fprintf(stdout, "callback: %c %s %s ", opt->val, (char *) data, arg);
+ if (pass2)
+ fprintf(stdout, "callback: %c %s %s ", opt->val, (char *) data, arg);
}
int arg1 = 0;
@@ -21,41 +23,52 @@ int shortopt = 0;
int singleDash = 0;
static struct poptOption moreCallbackArgs[] = {
- { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA,
+ { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA,
(void *)option_callback, 0, NULL },
{ "cb2", 'c', POPT_ARG_STRING, NULL, 'c', "Test argument callbacks" },
- { NULL, '\0', 0, NULL, 0 }
+ { NULL, '\0', 0, NULL, 0 }
};
static struct poptOption callbackArgs[] = {
{ NULL, '\0', POPT_ARG_CALLBACK, (void *)option_callback, 0, "sampledata" },
{ "cb", 'c', POPT_ARG_STRING, NULL, 'c', "Test argument callbacks" },
{ "long", '\0', 0, NULL, 'l', "Unused option for help testing" },
- { NULL, '\0', 0, NULL, 0 }
+ { NULL, '\0', 0, NULL, 0 }
};
static struct poptOption moreArgs[] = {
{ "inc", 'i', 0, &inc, 0, "An included argument" },
- { NULL, '\0', 0, NULL, 0 }
+ { NULL, '\0', 0, NULL, 0 }
};
static struct poptOption options[] = {
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, &moreCallbackArgs, 0, "arg for cb2" },
- { "arg1", '\0', 0, &arg1, 0, "First argument with a really long"
+ { "arg1", '\0', 0, &arg1, 0, "First argument with a really long"
" description. After all, we have to test argument help"
" 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 },
- { "hidden", '\0', POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN, NULL, 0,
+ { "hidden", '\0', POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN, NULL, 0,
"This shouldn't show up", NULL },
- { "unused", '\0', POPT_ARG_STRING, NULL, 0,
+ { "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
- { NULL, '\0', 0, NULL, 0 }
+ { NULL, '\0', 0, NULL, 0 }
};
+static void resetVars(void)
+{
+ arg1 = 0;
+ arg2 = "(none)";
+ arg3 = 0;
+ inc = 0;
+ shortopt = 0;
+ singleDash = 0;
+ pass2 = 0;
+}
+
int main(int argc, char ** argv) {
int rc;
poptContext optCon;
@@ -63,12 +76,20 @@ int main(int argc, char ** argv) {
int help = 0;
int usage = 0;
+ resetVars();
optCon = poptGetContext("test1", argc, argv, options, 0);
poptReadConfigFile(optCon, "./test-poptrc");
+ while ((rc = poptGetNextOpt(optCon)) > 0) /* Read all the options ... */
+ ;
+
+ poptResetContext(optCon); /* ... and then start over. */
+ resetVars();
+
+ pass2 = 1;
if ((rc = poptGetNextOpt(optCon)) < -1) {
- fprintf(stderr, "test1: bad argument %s: %s\n",
- poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
+ fprintf(stderr, "test1: bad argument %s: %s\n",
+ poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
poptStrerror(rc));
return 2;
}