3 * gcc prop_read_array.c -o prop_read_array -lprop -Wall -W -Wextra -ansi -pedantic
9 #include <prop/proplib.h>
11 int main(int argc
, char *argv
[])
15 prop_object_iterator_t pit
;
19 /* No effect in NetBSD, but increases portability */
22 /* Check argument count */
24 fprintf(stderr
, "Usage: %s <data.xml>\n", getprogname());
28 /* Read array contents from external XML file */
29 pa
= prop_array_internalize_from_file(argv
[1]);
31 err(EXIT_FAILURE
, "prop_array_internalize_from_file()");
33 /* Skim through every item of the array */
34 for (i
= 0; i
< prop_array_count(pa
); i
++) {
35 po
= prop_array_get(pa
, i
);
36 if (prop_object_type(po
) != PROP_TYPE_STRING
) {
37 prop_object_release(pa
);
38 errx(EXIT_FAILURE
, "invalid string type");
40 s
= prop_string_cstring_nocopy(po
);
45 * We will now iterate through the items of the array,
46 * but this time we will exploit a prop_array_iterator_t
48 pit
= prop_array_iterator(pa
);
50 prop_object_release(pa
);
51 err(EXIT_FAILURE
, "prop_array_iterator()");
55 while((po
= prop_object_iterator_next(pit
)) != NULL
) {
56 s
= prop_string_cstring_nocopy(po
);
61 prop_object_release(pa
);
62 prop_object_iterator_release(pit
);