Clarify comment
[eleutheria.git] / proplib / prop_array1.c
blob9d158b3d9e0c4a3dd304178c9426a2668c8eb400
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 /* Declare a pointer to a prop_array object
9 * Note that prop_array_t is a pointer being
10 * hidden inside a typedef, i.e.
11 * typedef struct _prop_array *prop_array_t;
13 prop_array_t pa;
14 prop_string_t ps;
15 int i;
17 /* Create array object with initial capacity 10
18 * Note that the array will expand on demand
19 * by the prop_array_add()
21 pa = prop_array_create_with_capacity(10);
22 if (pa == NULL)
23 errx(EXIT_FAILURE, "prop_array_create_with_capacity()");
25 /* For every argument, create a prop_string_t object
26 * that references it and store it in the array
28 for (i = 0; i < argc; i++) {
29 ps = prop_string_create_cstring_nocopy(argv[i]);
30 if (ps == NULL) {
31 prop_object_release(pa);
32 errx(EXIT_FAILURE, "prop_string_create_cstring_nocopy()");
35 if (prop_array_add(pa, ps) == FALSE) {
36 prop_object_release(pa);
37 errx(EXIT_FAILURE, "prop_array_add()");
40 prop_object_release(ps);
43 /* Export array contents to file as XML */
44 if (prop_array_externalize_to_file(pa, "./data.xml") == FALSE) {
45 prop_object_release(pa);
46 errx(EXIT_FAILURE, "prop_array_externalize_to_file()");
49 /* Release array object */
50 prop_object_release(pa);
52 return EXIT_SUCCESS;