File: test3.c

package info (click to toggle)
popt 1.10-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,412 kB
  • ctags: 914
  • sloc: sh: 8,843; ansic: 7,538; makefile: 430; yacc: 316
file content (48 lines) | stat: -rw-r--r-- 944 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;
}