summaryrefslogtreecommitdiff
path: root/popt/test3.c
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2002-07-20 19:02:40 +0000
committerjbj <devnull@localhost>2002-07-20 19:02:40 +0000
commitbfb8488c10a5dfccbcb7c556408b300f8901cd88 (patch)
tree452ff018c24cfb886d68e42f7e1e92563a421bb6 /popt/test3.c
parentc499cd119c15536c0d4742077fa8c73fa92dace6 (diff)
downloadlibrpm-tizen-bfb8488c10a5dfccbcb7c556408b300f8901cd88.tar.gz
librpm-tizen-bfb8488c10a5dfccbcb7c556408b300f8901cd88.tar.bz2
librpm-tizen-bfb8488c10a5dfccbcb7c556408b300f8901cd88.zip
- popt: parse file into string of options (#56860).
CVS patchset: 5560 CVS date: 2002/07/20 19:02:40
Diffstat (limited to 'popt/test3.c')
-rw-r--r--popt/test3.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/popt/test3.c b/popt/test3.c
new file mode 100644
index 000000000..5290a9a3d
--- /dev/null
+++ b/popt/test3.c
@@ -0,0 +1,48 @@
+// vim:ts=8:sts=4
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <popt.h>
+
+int main (int argc, char **argv) {
+ char *out;
+ int newargc, j, f, ret;
+ char **newargv;
+ FILE *fp;
+
+ if (argc == 1) {
+ printf ("usage: test-popt file_1 file_2 ...\n");
+ printf ("you may specify many files\n");
+ exit (1);
+ }
+
+ for (f = 1; f < argc; f++) {
+ fp = fopen (argv[f], "r");
+ if (fp == NULL) {
+ printf ("cannot read file %s. errno=%s\n", argv[f],
+ strerror(errno));
+ continue;
+ }
+
+ ret = poptConfigFileToString (fp, &out, 0);
+ if (ret != 0) {
+ printf ("cannot parse %s. ret=%d\n", argv[f], ret);
+ continue;
+ }
+
+ printf ("single string: '%s'\n", out);
+
+ poptParseArgvString (out, &newargc, &newargv);
+
+ printf ("popt array: size=%d\n", newargc);
+ for (j = 0; j < newargc; j++)
+ printf ("'%s'\n", newargv[j]);
+
+ printf ("\n");
+ free(out);
+ fclose (fp);
+ }
+ return 0;
+}