1 /* Copyright (c) 2013, Vsevolod Stakhov
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
12 * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
13 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15 * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
16 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
19 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 main (int argc, char **argv)
32 ucl_object_t *obj, *cur, *ar;
34 const char *fname_out = NULL;
35 struct ucl_emitter_context *ctx;
36 struct ucl_emitter_functions *f;
45 if (fname_out != NULL) {
46 out = fopen (fname_out, "w");
55 obj = ucl_object_typed_new (UCL_OBJECT);
57 /* Create some strings */
58 cur = ucl_object_fromstring_common (" test string ", 0, UCL_STRING_TRIM);
59 ucl_object_insert_key (obj, cur, "key1", 0, false);
60 cur = ucl_object_fromstring_common (" test \nstring\n ", 0, UCL_STRING_TRIM | UCL_STRING_ESCAPE);
61 ucl_object_insert_key (obj, cur, "key2", 0, false);
62 cur = ucl_object_fromstring_common (" test string \n", 0, 0);
63 ucl_object_insert_key (obj, cur, "key3", 0, false);
65 f = ucl_object_emit_file_funcs (out);
66 ctx = ucl_object_emit_streamline_new (obj, UCL_EMIT_CONFIG, f);
70 /* Array of numbers */
71 ar = ucl_object_typed_new (UCL_ARRAY);
73 ar->keylen = sizeof ("key4") - 1;
75 ucl_object_emit_streamline_start_container (ctx, ar);
76 cur = ucl_object_fromint (10);
77 ucl_object_emit_streamline_add_object (ctx, cur);
78 cur = ucl_object_fromdouble (10.1);
79 ucl_object_emit_streamline_add_object (ctx, cur);
80 cur = ucl_object_fromdouble (9.999);
81 ucl_object_emit_streamline_add_object (ctx, cur);
84 ucl_object_emit_streamline_end_container (ctx);
85 ucl_object_emit_streamline_finish (ctx);
86 ucl_object_emit_funcs_free (f);
87 ucl_object_unref (obj);