test_basic.c (6cec9cad762b6476313fb1f8e931a1647822db6b) test_basic.c (3dcf5eb70598c88befd62f61f81e283e568ec519)
1/* Copyright (c) 2013, Vsevolod Stakhov
2 * All rights reserved.
3 *
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

--- 19 unchanged lines hidden (view full) ---

28main (int argc, char **argv)
29{
30 char inbuf[8192], *test_in = NULL;
31 struct ucl_parser *parser = NULL, *parser2 = NULL;
32 ucl_object_t *obj;
33 FILE *in, *out;
34 unsigned char *emitted = NULL;
35 const char *fname_in = NULL, *fname_out = NULL;
1/* Copyright (c) 2013, Vsevolod Stakhov
2 * All rights reserved.
3 *
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

--- 19 unchanged lines hidden (view full) ---

28main (int argc, char **argv)
29{
30 char inbuf[8192], *test_in = NULL;
31 struct ucl_parser *parser = NULL, *parser2 = NULL;
32 ucl_object_t *obj;
33 FILE *in, *out;
34 unsigned char *emitted = NULL;
35 const char *fname_in = NULL, *fname_out = NULL;
36 int ret = 0, inlen, opt, json = 0;
36 int ret = 0, inlen, opt, json = 0, compact = 0, yaml = 0;
37
37
38 while ((opt = getopt(argc, argv, "j")) != -1) {
38 while ((opt = getopt(argc, argv, "jcy")) != -1) {
39 switch (opt) {
40 case 'j':
41 json = 1;
42 break;
39 switch (opt) {
40 case 'j':
41 json = 1;
42 break;
43 case 'c':
44 compact = 1;
45 break;
46 case 'y':
47 yaml = 1;
48 break;
43 default: /* '?' */
49 default: /* '?' */
44 fprintf (stderr, "Usage: %s [-j] [in] [out]\n",
50 fprintf (stderr, "Usage: %s [-jcy] [in] [out]\n",
45 argv[0]);
46 exit (EXIT_FAILURE);
47 }
48 }
49
50 argc -= optind;
51 argv += optind;
52

--- 46 unchanged lines hidden (view full) ---

99 }
100 if (ucl_parser_get_error (parser) != NULL) {
101 fprintf (out, "Error occurred: %s\n", ucl_parser_get_error(parser));
102 ret = 1;
103 goto end;
104 }
105 obj = ucl_parser_get_object (parser);
106 if (json) {
51 argv[0]);
52 exit (EXIT_FAILURE);
53 }
54 }
55
56 argc -= optind;
57 argv += optind;
58

--- 46 unchanged lines hidden (view full) ---

105 }
106 if (ucl_parser_get_error (parser) != NULL) {
107 fprintf (out, "Error occurred: %s\n", ucl_parser_get_error(parser));
108 ret = 1;
109 goto end;
110 }
111 obj = ucl_parser_get_object (parser);
112 if (json) {
107 emitted = ucl_object_emit (obj, UCL_EMIT_JSON);
113 if (compact) {
114 emitted = ucl_object_emit (obj, UCL_EMIT_JSON_COMPACT);
115 }
116 else {
117 emitted = ucl_object_emit (obj, UCL_EMIT_JSON);
118 }
108 }
119 }
120 else if (yaml) {
121 emitted = ucl_object_emit (obj, UCL_EMIT_YAML);
122 }
109 else {
110 emitted = ucl_object_emit (obj, UCL_EMIT_CONFIG);
111 }
112 ucl_parser_free (parser);
113 ucl_object_unref (obj);
114 parser2 = ucl_parser_new (UCL_PARSER_KEY_LOWERCASE);
115 ucl_parser_add_string (parser2, emitted, 0);
116
117 if (ucl_parser_get_error(parser2) != NULL) {
118 fprintf (out, "Error occurred: %s\n", ucl_parser_get_error(parser2));
119 fprintf (out, "%s\n", emitted);
120 ret = 1;
121 goto end;
122 }
123 if (emitted != NULL) {
124 free (emitted);
125 }
126 obj = ucl_parser_get_object (parser2);
127 if (json) {
123 else {
124 emitted = ucl_object_emit (obj, UCL_EMIT_CONFIG);
125 }
126 ucl_parser_free (parser);
127 ucl_object_unref (obj);
128 parser2 = ucl_parser_new (UCL_PARSER_KEY_LOWERCASE);
129 ucl_parser_add_string (parser2, emitted, 0);
130
131 if (ucl_parser_get_error(parser2) != NULL) {
132 fprintf (out, "Error occurred: %s\n", ucl_parser_get_error(parser2));
133 fprintf (out, "%s\n", emitted);
134 ret = 1;
135 goto end;
136 }
137 if (emitted != NULL) {
138 free (emitted);
139 }
140 obj = ucl_parser_get_object (parser2);
141 if (json) {
128 emitted = ucl_object_emit (obj, UCL_EMIT_JSON);
142 if (compact) {
143 emitted = ucl_object_emit (obj, UCL_EMIT_JSON_COMPACT);
144 }
145 else {
146 emitted = ucl_object_emit (obj, UCL_EMIT_JSON);
147 }
129 }
148 }
149 else if (yaml) {
150 emitted = ucl_object_emit (obj, UCL_EMIT_YAML);
151 }
130 else {
131 emitted = ucl_object_emit (obj, UCL_EMIT_CONFIG);
132 }
133
134 fprintf (out, "%s\n", emitted);
135 ucl_object_unref (obj);
136
137end:

--- 14 unchanged lines hidden ---
152 else {
153 emitted = ucl_object_emit (obj, UCL_EMIT_CONFIG);
154 }
155
156 fprintf (out, "%s\n", emitted);
157 ucl_object_unref (obj);
158
159end:

--- 14 unchanged lines hidden ---