pthreads changed
[eleutheria.git] / proplib / prop_array1.c
blob24413131ef2b150267ee6babc9c2d824e8a0f3f6
1 #include <err.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <prop/proplib.h>
6 int
7 main(int argc, char *argv[])
9 /*
10 * Declare a pointer to a prop_array object
11 * Note that prop_array_t is a pointer being
12 * hidden inside a typedef, i.e.
13 * typedef struct _prop_array *prop_array_t;
15 prop_array_t pa;
16 prop_string_t ps;
17 int i;
20 * Create array object with initial capacity 10
21 * Note that the array will expand on demand
22 * by the prop_array_add() with `EXPAND_STEP' step
23 * as defined in libprop/prop_array.c
25 pa = prop_array_create_with_capacity(10);
26 if (pa == NULL)
27 errx(EXIT_FAILURE, "prop_array_create_with_capacity()");
29 /*
30 * For every argument, create a prop_string_t object
31 * that references it and store it in the array
33 for (i = 0; i < argc; i++) {
34 ps = prop_string_create_cstring_nocopy(argv[i]);
35 if (ps == NULL) {
36 prop_object_release(pa);
37 errx(EXIT_FAILURE, "prop_string_create_cstring_nocopy()");
40 if (prop_array_add(pa, ps) == FALSE) {
41 prop_object_release(pa);
42 errx(EXIT_FAILURE, "prop_array_add()");
45 prop_object_release(ps);
48 /* Export array contents to file as XML */
49 if (prop_array_externalize_to_file(pa, "./data.xml") == FALSE) {
50 prop_object_release(pa);
51 errx(EXIT_FAILURE, "prop_array_externalize_to_file()");
54 /* Release array object */
55 prop_object_release(pa);
57 return EXIT_SUCCESS;