Dummy commit to test new ssh key
[eleutheria.git] / proplib / prop_dict.c
blob7fd830d241bfac2c0fe15526d427cf7b7bb5b600
1 /*
2 * Compile with:
3 * gcc prop_dict.c -o prop_dict -lprop -Wall -W -Wextra -ansi -pedantic
4 */
6 #include <err.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <prop/proplib.h>
11 int main(int argc, char *argv[])
13 prop_dictionary_t pd;
14 prop_string_t ps;
15 unsigned int i;
17 /* Create a dictionary capable of holding `argc - 1' objects */
18 pd = prop_dictionary_create_with_capacity(argc - 1);
19 if (pd == NULL)
20 err(EXIT_FAILURE, "prop_dictionary_create_with_capacity()");
23 * For every supplied argument, create a <key, value> pair
24 * and store it inside the dictionary.
26 for (i = 1; i < argc; i++) {
27 ps = prop_string_create_cstring_nocopy(argv[i]);
28 if (ps == NULL) {
29 prop_object_release(pd);
30 err(EXIT_FAILURE, "prop_string_create_cstring_nocopy()");
33 if (prop_dictionary_set(pd, argv[i], ps) == false) {
34 prop_object_release(ps);
35 prop_object_release(pd);
36 err(EXIT_FAILURE, "prop_dictionary_set()");
39 prop_object_release(ps);
42 /* Output our property list as an XML file */
43 if (prop_dictionary_externalize_to_file(pd, "./data.xml") == false) {
44 prop_object_release(pd);
45 err(EXIT_FAILURE, "prop_dictionary_externalize_to_file()");
48 /* Release dictionary */
49 prop_object_release(pd);
51 return EXIT_SUCCESS;