summaryrefslogtreecommitdiff
path: root/test1.c
diff options
context:
space:
mode:
authorewt <ewt>1998-09-27 14:57:03 +0000
committerewt <ewt>1998-09-27 14:57:03 +0000
commit9798051c445d4275f5fb8c30d99d58c032b0f600 (patch)
treed2543f005624bcb97cac9c74ff4968548a414e72 /test1.c
parent0acab4ff56dbbe67e0b217ab6675729a608f7665 (diff)
downloadlibpopt-9798051c445d4275f5fb8c30d99d58c032b0f600.tar.gz
1) added included tables
2) added option callbacks 3) added automatic help/usage messages
Diffstat (limited to 'test1.c')
-rw-r--r--test1.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/test1.c b/test1.c
index dc6be87..a1559f0 100644
--- a/test1.c
+++ b/test1.c
@@ -3,6 +3,10 @@
#include "popt.h"
+void option_callback(poptContext con, int key, char * arg, void * data) {
+ printf("callback: %s %s ", (char *) data, arg);
+}
+
int main(int argc, char ** argv) {
int rc;
int arg1 = 0;
@@ -10,10 +14,29 @@ int main(int argc, char ** argv) {
poptContext optCon;
char ** rest;
int arg3 = 0;
+ int inc = 0;
+ int help = 0;
+ int usage = 0;
+ struct poptOption callbackArgs[] = {
+ { NULL, '\0', POPT_ARG_CALLBACK, option_callback, 0, "sampledata" },
+ { "cb", 'c', POPT_ARG_STRING, NULL, 0, "Test argument callbacks" },
+ { "long", '\0', 0, NULL, 0, "Unused option for help testing" },
+ { NULL, '\0', 0, NULL, 0 }
+ };
+ struct poptOption moreArgs[] = {
+ { "inc", 'i', 0, &inc, 0, "An included argument" },
+ { NULL, '\0', 0, NULL, 0 }
+ };
struct poptOption options[] = {
- { "arg1", '\0', 0, &arg1, 0 },
- { "arg2", '2', POPT_ARG_STRING, &arg2, 0 },
- { "arg3", '3', POPT_ARG_INT, &arg3, 0 },
+ { "arg1", '\0', 0, &arg1, 0, "First argument with a really long"
+ " description. After all, we have to test argument help"
+ " wrapping somehow, right?", "ARG1"},
+ { "arg2", '2', POPT_ARG_STRING, &arg2, 0, "Another argument", "ARG" },
+ { "arg3", '3', POPT_ARG_INT, &arg3, 0, "A third argument", "ANARG" },
+ { "unused", '\0', 0, NULL, 0, "Unused option for help testing" },
+ { 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 }
};
@@ -27,10 +50,20 @@ int main(int argc, char ** argv) {
return 2;
}
+ if (help) {
+ poptPrintHelp(optCon, stdout, 0);
+ return 0;
+ } if (usage) {
+ poptPrintUsage(optCon, stdout, 0);
+ return 0;
+ }
+
printf("arg1: %d arg2: %s", arg1, arg2);
if (arg3)
printf(" arg3: %d", arg3);
+ if (inc)
+ printf(" inc: %d", inc);
rest = poptGetArgs(optCon);
if (rest) {