• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <errno.h>
4 #include <string.h>
5 #include <popt.h>
6 
main(int argc,char ** argv)7 int main (int argc, char **argv) {
8     char *out;
9     int newargc, j, f, ret;
10     const char **newargv;
11     FILE *fp;
12 
13     if (argc == 1) {
14 	printf ("usage: test-popt file_1 file_2 ...\n");
15 	printf ("you may specify many files\n");
16 	exit (1);
17     }
18 
19     for (f = 1; f < argc; f++) {
20 	fp = fopen (argv[f], "r");
21 	if (fp == NULL) {
22 	    printf ("cannot read file %s.  errno=%s\n", argv[f],
23 		strerror(errno));
24 	    continue;
25 	}
26 
27 	ret = poptConfigFileToString (fp, &out, 0);
28 	if (ret != 0) {
29 	    printf ("cannot parse %s. ret=%d\n", argv[f], ret);
30 	    continue;
31 	}
32 
33 	printf ("single string: '%s'\n", out);
34 
35 	poptParseArgvString (out, &newargc, &newargv);
36 
37 	printf ("popt array: size=%d\n", newargc);
38 	for (j = 0; j < newargc; j++)
39 	    printf ("'%s'\n", newargv[j]);
40 
41 	printf ("\n");
42 	free(out);
43 	fclose (fp);
44     }
45     return 0;
46 }
47