From bfb8488c10a5dfccbcb7c556408b300f8901cd88 Mon Sep 17 00:00:00 2001 From: jbj Date: Sat, 20 Jul 2002 19:02:40 +0000 Subject: - popt: parse file into string of options (#56860). CVS patchset: 5560 CVS date: 2002/07/20 19:02:40 --- popt/test3.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 popt/test3.c (limited to 'popt/test3.c') 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 +#include +#include +#include +#include + +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; +} -- cgit v1.2.3