pthreads changed
[eleutheria.git] / proplib / prop_array2.c
blob9758103f115091262068ec1819f45b33be2c9961
1 #include <err.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <prop/proplib.h>
6 int main(int argc, char *argv[])
8 prop_array_t pa;
9 prop_object_t po;
10 prop_object_iterator_t pit;
11 unsigned int i;
12 const char *s;
14 /* */
15 setprogname(argv[0]);
17 /* Check argument count */
18 if (argc != 2) {
19 fprintf(stderr, "Usage: %s <data.xml>\n", getprogname());
20 exit(EXIT_FAILURE);
23 /* Read array contents from external XML file */
24 pa = prop_array_internalize_from_file(argv[1]);
25 if (pa == NULL)
26 errx(EXIT_FAILURE, "prop_array_internalize_from_file()");
28 /* Skim through every item of the array */
29 for (i = 0; i < prop_array_count(pa); i++) {
30 s = prop_string_cstring_nocopy(prop_array_get(pa, i));
31 printf("%s\n", s);
35 * We will now iterate through the items of the array,
36 * but this time we will exploit a prop_array_iterator_t
38 pit = prop_array_iterator(pa);
39 if (pit == NULL) {
40 prop_object_release(pa);
41 errx(EXIT_FAILURE, "prop_array_iterator()");
44 /* Traverse */
45 while((po = prop_object_iterator_next(pit)) != NULL)
46 printf("%s\n", prop_string_cstring_nocopy(po));
48 /* Release objects */
49 prop_object_release(pa);
50 prop_object_iterator_release(pit);
52 return EXIT_SUCCESS;