diff options
author | jbj <jbj> | 2002-07-20 19:04:08 +0000 |
---|---|---|
committer | jbj <jbj> | 2002-07-20 19:04:08 +0000 |
commit | ad190bcd9d2647616b3b0ab8ab473c0a54728543 (patch) | |
tree | e6361685d0d337f7f8296c2c053265497cfafa6f /test3.c | |
parent | 8da8c2c086f90406e8e4a02f189787a86af5a7dd (diff) | |
download | libpopt-ad190bcd9d2647616b3b0ab8ab473c0a54728543.tar.gz |
- popt: parse file into string of options (#56860).
Diffstat (limited to 'test3.c')
-rw-r--r-- | test3.c | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -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; +} |