Give files descriptive names
[eleutheria.git] / proplib / prop_array2.c
bloba6ab3651417eef67309e0a90da0d021cf4aab081
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 /* Check argument count */
15 if (argc != 2) {
16 fprintf(stderr, "usage: %s <data.xml>\n", getprogname());
17 exit(EXIT_FAILURE);
20 /* Read array contents from external XML file */
21 pa = prop_array_internalize_from_file(argv[1]);
22 if (pa == NULL)
23 errx(EXIT_FAILURE, "prop_array_internalize_from_file() failed\n");
25 /* Skim through every item of the array */
26 for (i = 0; i < prop_array_count(pa); i++) {
27 s = prop_string_cstring_nocopy(prop_array_get(pa, i));
28 printf("%s\n", s);
31 /* We will now iterate through the items of the array,
32 * but this time we will exploit a prop_array_iterator_t
34 pit = prop_array_iterator(pa);
35 if (pit == NULL) {
36 prop_object_release(pa);
37 errx(EXIT_FAILURE, "prop_array_iterator() failed\n");
40 while((po = prop_object_iterator_next(pit)) != NULL)
41 printf("%s\n", prop_string_cstring_nocopy(po));
43 /* Release objects */
44 prop_object_release(pa);
45 prop_object_iterator_release(pit);
47 return EXIT_SUCCESS;