/src/libyaml_deconstructor_fuzzer.c
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2020 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include "yaml.h" |
16 | | #include "yaml_write_handler.h" |
17 | | #include <assert.h> |
18 | | #include <stdbool.h> |
19 | | #include <stdint.h> |
20 | | #include <stdio.h> |
21 | | #include <stdlib.h> |
22 | | #include <string.h> |
23 | | |
24 | | #ifdef NDEBUG |
25 | | #undef NDEBUG |
26 | | #endif |
27 | | |
28 | 9.29k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
29 | 9.29k | if (size < 2) |
30 | 1 | return 0; |
31 | | |
32 | 9.28k | bool done = false; |
33 | 9.28k | bool is_canonical = data[0] & 1; |
34 | 9.28k | bool is_unicode = data[1] & 1; |
35 | 9.28k | data += 2; |
36 | 9.28k | size -= 2; |
37 | | |
38 | 9.28k | yaml_parser_t parser; |
39 | 9.28k | yaml_emitter_t emitter; |
40 | 9.28k | yaml_event_t input_event; |
41 | 9.28k | yaml_event_t output_event; |
42 | | |
43 | | /* Initialize the parser and emitter objects. */ |
44 | | |
45 | 9.28k | if (!yaml_parser_initialize(&parser)) { |
46 | 0 | return 1; |
47 | 0 | } |
48 | | |
49 | 9.28k | if (!yaml_emitter_initialize(&emitter)) { |
50 | 0 | yaml_parser_delete(&parser); |
51 | 0 | return 1; |
52 | 0 | } |
53 | | |
54 | | /* Set the parser parameters. */ |
55 | | |
56 | 9.28k | yaml_parser_set_input_string(&parser, data, size); |
57 | | |
58 | | /* Set the emitter parameters. */ |
59 | 9.28k | yaml_output_buffer_t out = {/*buf=*/NULL, /*size=*/0, /*capacity=*/1000}; |
60 | 9.28k | yaml_emitter_set_output(&emitter, yaml_write_handler, &out); |
61 | | |
62 | 9.28k | yaml_emitter_set_canonical(&emitter, is_canonical); |
63 | 9.28k | yaml_emitter_set_unicode(&emitter, is_unicode); |
64 | | |
65 | | /* Create and emit the STREAM-START event. */ |
66 | | |
67 | 9.28k | if (!yaml_stream_start_event_initialize(&output_event, YAML_UTF8_ENCODING)) |
68 | 0 | goto error; |
69 | 9.28k | if (!yaml_emitter_emit(&emitter, &output_event)) |
70 | 0 | goto error; |
71 | | |
72 | | /* Create and emit the DOCUMENT-START event. */ |
73 | | |
74 | 9.28k | if (!yaml_document_start_event_initialize(&output_event, NULL, NULL, NULL, 0)) |
75 | 0 | goto error; |
76 | 9.28k | if (!yaml_emitter_emit(&emitter, &output_event)) |
77 | 0 | goto error; |
78 | | |
79 | | /* Create and emit the SEQUENCE-START event. */ |
80 | | |
81 | 9.28k | if (!yaml_sequence_start_event_initialize( |
82 | 9.28k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:seq", 1, |
83 | 9.28k | YAML_BLOCK_SEQUENCE_STYLE)) |
84 | 0 | goto error; |
85 | 9.28k | if (!yaml_emitter_emit(&emitter, &output_event)) |
86 | 0 | goto error; |
87 | | |
88 | | /* Loop through the input events. */ |
89 | | |
90 | 1.99M | while (!done) { |
91 | | /* Get the next event. */ |
92 | | |
93 | 1.99M | if (!yaml_parser_parse(&parser, &input_event)) |
94 | 5.34k | goto error; |
95 | | |
96 | | /* Check if this is the stream end. */ |
97 | | |
98 | 1.98M | done = (input_event.type == YAML_STREAM_END_EVENT); |
99 | | |
100 | | /* Create and emit a MAPPING-START event. */ |
101 | | |
102 | 1.98M | if (!yaml_mapping_start_event_initialize( |
103 | 1.98M | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:map", 1, |
104 | 1.98M | YAML_BLOCK_MAPPING_STYLE)) |
105 | 0 | goto error; |
106 | 1.98M | if (!yaml_emitter_emit(&emitter, &output_event)) |
107 | 0 | goto error; |
108 | | |
109 | | /* Analyze the event. */ |
110 | | |
111 | 1.98M | switch (input_event.type) { |
112 | 9.07k | case YAML_STREAM_START_EVENT: |
113 | | |
114 | | /* Write 'type'. */ |
115 | | |
116 | 9.07k | if (!yaml_scalar_event_initialize( |
117 | 9.07k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
118 | 9.07k | (yaml_char_t *)"type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
119 | 0 | goto error; |
120 | 9.07k | if (!yaml_emitter_emit(&emitter, &output_event)) |
121 | 0 | goto error; |
122 | | |
123 | | /* Write 'STREAM-START'. */ |
124 | | |
125 | 9.07k | if (!yaml_scalar_event_initialize( |
126 | 9.07k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
127 | 9.07k | (yaml_char_t *)"STREAM-START", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
128 | 0 | goto error; |
129 | 9.07k | if (!yaml_emitter_emit(&emitter, &output_event)) |
130 | 0 | goto error; |
131 | | |
132 | | /* Display encoding information. */ |
133 | | |
134 | 9.07k | if (input_event.data.stream_start.encoding) { |
135 | 9.07k | yaml_encoding_t encoding = input_event.data.stream_start.encoding; |
136 | | |
137 | | /* Write 'encoding'. */ |
138 | | |
139 | 9.07k | if (!yaml_scalar_event_initialize( |
140 | 9.07k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
141 | 9.07k | (yaml_char_t *)"encoding", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
142 | 0 | goto error; |
143 | 9.07k | if (!yaml_emitter_emit(&emitter, &output_event)) |
144 | 0 | goto error; |
145 | | |
146 | | /* Write the stream encoding. */ |
147 | | |
148 | 9.07k | if (!yaml_scalar_event_initialize( |
149 | 9.07k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
150 | 9.07k | (yaml_char_t *)(encoding == YAML_UTF8_ENCODING |
151 | 9.07k | ? "utf-8" |
152 | 9.07k | : encoding == YAML_UTF16LE_ENCODING |
153 | 423 | ? "utf-16-le" |
154 | 423 | : encoding == YAML_UTF16BE_ENCODING |
155 | 342 | ? "utf-16-be" |
156 | 342 | : "unknown"), |
157 | 9.07k | -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
158 | 0 | goto error; |
159 | 9.07k | if (!yaml_emitter_emit(&emitter, &output_event)) |
160 | 0 | goto error; |
161 | 9.07k | } |
162 | | |
163 | 9.07k | break; |
164 | | |
165 | 9.07k | case YAML_STREAM_END_EVENT: |
166 | | |
167 | | /* Write 'type'. */ |
168 | | |
169 | 3.91k | if (!yaml_scalar_event_initialize( |
170 | 3.91k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
171 | 3.91k | (yaml_char_t *)"type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
172 | 0 | goto error; |
173 | 3.91k | if (!yaml_emitter_emit(&emitter, &output_event)) |
174 | 0 | goto error; |
175 | | |
176 | | /* Write 'STREAM-END'. */ |
177 | | |
178 | 3.91k | if (!yaml_scalar_event_initialize( |
179 | 3.91k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
180 | 3.91k | (yaml_char_t *)"STREAM-END", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
181 | 0 | goto error; |
182 | 3.91k | if (!yaml_emitter_emit(&emitter, &output_event)) |
183 | 0 | goto error; |
184 | | |
185 | 3.91k | break; |
186 | | |
187 | 214k | case YAML_DOCUMENT_START_EVENT: |
188 | | |
189 | | /* Write 'type'. */ |
190 | | |
191 | 214k | if (!yaml_scalar_event_initialize( |
192 | 214k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
193 | 214k | (yaml_char_t *)"type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
194 | 0 | goto error; |
195 | 214k | if (!yaml_emitter_emit(&emitter, &output_event)) |
196 | 0 | goto error; |
197 | | |
198 | | /* Write 'DOCUMENT-START'. */ |
199 | | |
200 | 214k | if (!yaml_scalar_event_initialize(&output_event, NULL, |
201 | 214k | (yaml_char_t *)"tag:yaml.org,2002:str", |
202 | 214k | (yaml_char_t *)"DOCUMENT-START", -1, 1, |
203 | 214k | 1, YAML_PLAIN_SCALAR_STYLE)) |
204 | 0 | goto error; |
205 | 214k | if (!yaml_emitter_emit(&emitter, &output_event)) |
206 | 0 | goto error; |
207 | | |
208 | | /* Display the document version numbers. */ |
209 | | |
210 | 214k | if (input_event.data.document_start.version_directive) { |
211 | 191k | yaml_version_directive_t *version = |
212 | 191k | input_event.data.document_start.version_directive; |
213 | 191k | char number[64]; |
214 | | |
215 | | /* Write 'version'. */ |
216 | 191k | if (!yaml_scalar_event_initialize( |
217 | 191k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
218 | 191k | (yaml_char_t *)"version", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
219 | 0 | goto error; |
220 | 191k | if (!yaml_emitter_emit(&emitter, &output_event)) |
221 | 0 | goto error; |
222 | | |
223 | | /* Write '{'. */ |
224 | | |
225 | 191k | if (!yaml_mapping_start_event_initialize( |
226 | 191k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:map", 1, |
227 | 191k | YAML_FLOW_MAPPING_STYLE)) |
228 | 0 | goto error; |
229 | 191k | if (!yaml_emitter_emit(&emitter, &output_event)) |
230 | 0 | goto error; |
231 | | |
232 | | /* Write 'major'. */ |
233 | | |
234 | 191k | if (!yaml_scalar_event_initialize( |
235 | 191k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
236 | 191k | (yaml_char_t *)"major", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
237 | 0 | goto error; |
238 | 191k | if (!yaml_emitter_emit(&emitter, &output_event)) |
239 | 0 | goto error; |
240 | | |
241 | | /* Write a number. */ |
242 | | |
243 | 191k | sprintf(number, "%d", version->major); |
244 | 191k | if (!yaml_scalar_event_initialize( |
245 | 191k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:int", |
246 | 191k | (yaml_char_t *)number, -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
247 | 0 | goto error; |
248 | 191k | if (!yaml_emitter_emit(&emitter, &output_event)) |
249 | 0 | goto error; |
250 | | |
251 | | /* Write 'minor'. */ |
252 | | |
253 | 191k | if (!yaml_scalar_event_initialize( |
254 | 191k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
255 | 191k | (yaml_char_t *)"minor", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
256 | 0 | goto error; |
257 | 191k | if (!yaml_emitter_emit(&emitter, &output_event)) |
258 | 0 | goto error; |
259 | | |
260 | | /* Write a number. */ |
261 | | |
262 | 191k | sprintf(number, "%d", version->minor); |
263 | 191k | if (!yaml_scalar_event_initialize( |
264 | 191k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:int", |
265 | 191k | (yaml_char_t *)number, -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
266 | 0 | goto error; |
267 | 191k | if (!yaml_emitter_emit(&emitter, &output_event)) |
268 | 0 | goto error; |
269 | | |
270 | | /* Write '}'. */ |
271 | | |
272 | 191k | if (!yaml_mapping_end_event_initialize(&output_event)) |
273 | 0 | goto error; |
274 | 191k | if (!yaml_emitter_emit(&emitter, &output_event)) |
275 | 0 | goto error; |
276 | 191k | } |
277 | | |
278 | | /* Display the document tag directives. */ |
279 | | |
280 | 214k | if (input_event.data.document_start.tag_directives.start != |
281 | 214k | input_event.data.document_start.tag_directives.end) { |
282 | 4.97k | yaml_tag_directive_t *tag; |
283 | | |
284 | | /* Write 'tags'. */ |
285 | 4.97k | if (!yaml_scalar_event_initialize( |
286 | 4.97k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
287 | 4.97k | (yaml_char_t *)"tags", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
288 | 0 | goto error; |
289 | 4.97k | if (!yaml_emitter_emit(&emitter, &output_event)) |
290 | 0 | goto error; |
291 | | |
292 | | /* Start a block sequence. */ |
293 | | |
294 | 4.97k | if (!yaml_sequence_start_event_initialize( |
295 | 4.97k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:seq", 1, |
296 | 4.97k | YAML_BLOCK_SEQUENCE_STYLE)) |
297 | 0 | goto error; |
298 | 4.97k | if (!yaml_emitter_emit(&emitter, &output_event)) |
299 | 0 | goto error; |
300 | | |
301 | 4.97k | for (tag = input_event.data.document_start.tag_directives.start; |
302 | 16.7k | tag != input_event.data.document_start.tag_directives.end; tag++) { |
303 | | /* Write '{'. */ |
304 | | |
305 | 11.7k | if (!yaml_mapping_start_event_initialize( |
306 | 11.7k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:map", |
307 | 11.7k | 1, YAML_FLOW_MAPPING_STYLE)) |
308 | 0 | goto error; |
309 | 11.7k | if (!yaml_emitter_emit(&emitter, &output_event)) |
310 | 0 | goto error; |
311 | | |
312 | | /* Write 'handle'. */ |
313 | | |
314 | 11.7k | if (!yaml_scalar_event_initialize( |
315 | 11.7k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
316 | 11.7k | (yaml_char_t *)"handle", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
317 | 0 | goto error; |
318 | 11.7k | if (!yaml_emitter_emit(&emitter, &output_event)) |
319 | 0 | goto error; |
320 | | |
321 | | /* Write the tag directive handle. */ |
322 | | |
323 | 11.7k | if (!yaml_scalar_event_initialize( |
324 | 11.7k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
325 | 11.7k | (yaml_char_t *)tag->handle, -1, 0, 1, |
326 | 11.7k | YAML_DOUBLE_QUOTED_SCALAR_STYLE)) |
327 | 0 | goto error; |
328 | 11.7k | if (!yaml_emitter_emit(&emitter, &output_event)) |
329 | 0 | goto error; |
330 | | |
331 | | /* Write 'prefix'. */ |
332 | | |
333 | 11.7k | if (!yaml_scalar_event_initialize( |
334 | 11.7k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
335 | 11.7k | (yaml_char_t *)"prefix", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
336 | 0 | goto error; |
337 | 11.7k | if (!yaml_emitter_emit(&emitter, &output_event)) |
338 | 0 | goto error; |
339 | | |
340 | | /* Write the tag directive prefix. */ |
341 | | |
342 | 11.7k | if (!yaml_scalar_event_initialize( |
343 | 11.7k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
344 | 11.7k | (yaml_char_t *)tag->prefix, -1, 0, 1, |
345 | 11.7k | YAML_DOUBLE_QUOTED_SCALAR_STYLE)) |
346 | 2 | goto error; |
347 | 11.7k | if (!yaml_emitter_emit(&emitter, &output_event)) |
348 | 0 | goto error; |
349 | | |
350 | | /* Write '}'. */ |
351 | | |
352 | 11.7k | if (!yaml_mapping_end_event_initialize(&output_event)) |
353 | 0 | goto error; |
354 | 11.7k | if (!yaml_emitter_emit(&emitter, &output_event)) |
355 | 0 | goto error; |
356 | 11.7k | } |
357 | | |
358 | | /* End a block sequence. */ |
359 | | |
360 | 4.97k | if (!yaml_sequence_end_event_initialize(&output_event)) |
361 | 0 | goto error; |
362 | 4.97k | if (!yaml_emitter_emit(&emitter, &output_event)) |
363 | 0 | goto error; |
364 | 4.97k | } |
365 | | |
366 | | /* Write 'implicit'. */ |
367 | | |
368 | 214k | if (!yaml_scalar_event_initialize( |
369 | 214k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
370 | 214k | (yaml_char_t *)"implicit", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
371 | 0 | goto error; |
372 | 214k | if (!yaml_emitter_emit(&emitter, &output_event)) |
373 | 0 | goto error; |
374 | | |
375 | | /* Write if the document is implicit. */ |
376 | | |
377 | 214k | if (!yaml_scalar_event_initialize( |
378 | 214k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:bool", |
379 | 214k | (yaml_char_t *)(input_event.data.document_start.implicit |
380 | 214k | ? "true" |
381 | 214k | : "false"), |
382 | 214k | -1, 1, 0, YAML_PLAIN_SCALAR_STYLE)) |
383 | 0 | goto error; |
384 | 214k | if (!yaml_emitter_emit(&emitter, &output_event)) |
385 | 0 | goto error; |
386 | | |
387 | 214k | break; |
388 | | |
389 | 214k | case YAML_DOCUMENT_END_EVENT: |
390 | | |
391 | | /* Write 'type'. */ |
392 | | |
393 | 212k | if (!yaml_scalar_event_initialize( |
394 | 212k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
395 | 212k | (yaml_char_t *)"type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
396 | 0 | goto error; |
397 | 212k | if (!yaml_emitter_emit(&emitter, &output_event)) |
398 | 0 | goto error; |
399 | | |
400 | | /* Write 'DOCUMENT-END'. */ |
401 | | |
402 | 212k | if (!yaml_scalar_event_initialize( |
403 | 212k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
404 | 212k | (yaml_char_t *)"DOCUMENT-END", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
405 | 0 | goto error; |
406 | 212k | if (!yaml_emitter_emit(&emitter, &output_event)) |
407 | 0 | goto error; |
408 | | |
409 | | /* Write 'implicit'. */ |
410 | | |
411 | 212k | if (!yaml_scalar_event_initialize( |
412 | 212k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
413 | 212k | (yaml_char_t *)"implicit", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
414 | 0 | goto error; |
415 | 212k | if (!yaml_emitter_emit(&emitter, &output_event)) |
416 | 0 | goto error; |
417 | | |
418 | | /* Write if the document is implicit. */ |
419 | | |
420 | 212k | if (!yaml_scalar_event_initialize( |
421 | 212k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:bool", |
422 | 212k | (yaml_char_t *)(input_event.data.document_end.implicit ? "true" |
423 | 212k | : "false"), |
424 | 212k | -1, 1, 0, YAML_PLAIN_SCALAR_STYLE)) |
425 | 0 | goto error; |
426 | 212k | if (!yaml_emitter_emit(&emitter, &output_event)) |
427 | 0 | goto error; |
428 | | |
429 | 212k | break; |
430 | | |
431 | 212k | case YAML_ALIAS_EVENT: |
432 | | |
433 | | /* Write 'type'. */ |
434 | | |
435 | 959 | if (!yaml_scalar_event_initialize( |
436 | 959 | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
437 | 959 | (yaml_char_t *)"type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
438 | 0 | goto error; |
439 | 959 | if (!yaml_emitter_emit(&emitter, &output_event)) |
440 | 0 | goto error; |
441 | | |
442 | | /* Write 'ALIAS'. */ |
443 | | |
444 | 959 | if (!yaml_scalar_event_initialize( |
445 | 959 | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
446 | 959 | (yaml_char_t *)"ALIAS", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
447 | 0 | goto error; |
448 | 959 | if (!yaml_emitter_emit(&emitter, &output_event)) |
449 | 0 | goto error; |
450 | | |
451 | | /* Write 'anchor'. */ |
452 | | |
453 | 959 | if (!yaml_scalar_event_initialize( |
454 | 959 | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
455 | 959 | (yaml_char_t *)"anchor", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
456 | 0 | goto error; |
457 | 959 | if (!yaml_emitter_emit(&emitter, &output_event)) |
458 | 0 | goto error; |
459 | | |
460 | | /* Write the alias anchor. */ |
461 | | |
462 | 959 | if (!yaml_scalar_event_initialize(&output_event, NULL, |
463 | 959 | (yaml_char_t *)"tag:yaml.org,2002:str", |
464 | 959 | input_event.data.alias.anchor, -1, 0, 1, |
465 | 959 | YAML_DOUBLE_QUOTED_SCALAR_STYLE)) |
466 | 0 | goto error; |
467 | 959 | if (!yaml_emitter_emit(&emitter, &output_event)) |
468 | 0 | goto error; |
469 | | |
470 | 959 | break; |
471 | | |
472 | 883k | case YAML_SCALAR_EVENT: |
473 | | |
474 | | /* Write 'type'. */ |
475 | | |
476 | 883k | if (!yaml_scalar_event_initialize( |
477 | 883k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
478 | 883k | (yaml_char_t *)"type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
479 | 0 | goto error; |
480 | 883k | if (!yaml_emitter_emit(&emitter, &output_event)) |
481 | 0 | goto error; |
482 | | |
483 | | /* Write 'SCALAR'. */ |
484 | | |
485 | 883k | if (!yaml_scalar_event_initialize( |
486 | 883k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
487 | 883k | (yaml_char_t *)"SCALAR", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
488 | 0 | goto error; |
489 | 883k | if (!yaml_emitter_emit(&emitter, &output_event)) |
490 | 0 | goto error; |
491 | | |
492 | | /* Display the scalar anchor. */ |
493 | | |
494 | 883k | if (input_event.data.scalar.anchor) { |
495 | | /* Write 'anchor'. */ |
496 | | |
497 | 1.82k | if (!yaml_scalar_event_initialize( |
498 | 1.82k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
499 | 1.82k | (yaml_char_t *)"anchor", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
500 | 0 | goto error; |
501 | 1.82k | if (!yaml_emitter_emit(&emitter, &output_event)) |
502 | 0 | goto error; |
503 | | |
504 | | /* Write the scalar anchor. */ |
505 | | |
506 | 1.82k | if (!yaml_scalar_event_initialize( |
507 | 1.82k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
508 | 1.82k | input_event.data.scalar.anchor, -1, 0, 1, |
509 | 1.82k | YAML_DOUBLE_QUOTED_SCALAR_STYLE)) |
510 | 0 | goto error; |
511 | 1.82k | if (!yaml_emitter_emit(&emitter, &output_event)) |
512 | 0 | goto error; |
513 | 1.82k | } |
514 | | |
515 | | /* Display the scalar tag. */ |
516 | | |
517 | 883k | if (input_event.data.scalar.tag) { |
518 | | /* Write 'tag'. */ |
519 | | |
520 | 71.5k | if (!yaml_scalar_event_initialize( |
521 | 71.5k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
522 | 71.5k | (yaml_char_t *)"tag", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
523 | 0 | goto error; |
524 | 71.5k | if (!yaml_emitter_emit(&emitter, &output_event)) |
525 | 0 | goto error; |
526 | | |
527 | | /* Write the scalar tag. */ |
528 | | |
529 | 71.5k | if (!yaml_scalar_event_initialize( |
530 | 71.5k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
531 | 71.5k | input_event.data.scalar.tag, -1, 0, 1, |
532 | 71.5k | YAML_DOUBLE_QUOTED_SCALAR_STYLE)) |
533 | 26 | goto error; |
534 | 71.5k | if (!yaml_emitter_emit(&emitter, &output_event)) |
535 | 0 | goto error; |
536 | 71.5k | } |
537 | | |
538 | | /* Display the scalar value. */ |
539 | | |
540 | | /* Write 'value'. */ |
541 | | |
542 | 883k | if (!yaml_scalar_event_initialize( |
543 | 883k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
544 | 883k | (yaml_char_t *)"value", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
545 | 0 | goto error; |
546 | 883k | if (!yaml_emitter_emit(&emitter, &output_event)) |
547 | 0 | goto error; |
548 | | |
549 | | /* Write the scalar value. */ |
550 | | |
551 | 883k | if (!yaml_scalar_event_initialize( |
552 | 883k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
553 | 883k | input_event.data.scalar.value, input_event.data.scalar.length, 0, |
554 | 883k | 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) |
555 | 0 | goto error; |
556 | 883k | if (!yaml_emitter_emit(&emitter, &output_event)) |
557 | 0 | goto error; |
558 | | |
559 | | /* Display if the scalar tag is implicit. */ |
560 | | |
561 | | /* Write 'implicit'. */ |
562 | | |
563 | 883k | if (!yaml_scalar_event_initialize( |
564 | 883k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
565 | 883k | (yaml_char_t *)"implicit", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
566 | 0 | goto error; |
567 | 883k | if (!yaml_emitter_emit(&emitter, &output_event)) |
568 | 0 | goto error; |
569 | | |
570 | | /* Write '{'. */ |
571 | | |
572 | 883k | if (!yaml_mapping_start_event_initialize( |
573 | 883k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:map", 1, |
574 | 883k | YAML_FLOW_MAPPING_STYLE)) |
575 | 0 | goto error; |
576 | 883k | if (!yaml_emitter_emit(&emitter, &output_event)) |
577 | 0 | goto error; |
578 | | |
579 | | /* Write 'plain'. */ |
580 | | |
581 | 883k | if (!yaml_scalar_event_initialize( |
582 | 883k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
583 | 883k | (yaml_char_t *)"plain", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
584 | 0 | goto error; |
585 | 883k | if (!yaml_emitter_emit(&emitter, &output_event)) |
586 | 0 | goto error; |
587 | | |
588 | | /* Write if the scalar is implicit in the plain style. */ |
589 | | |
590 | 883k | if (!yaml_scalar_event_initialize( |
591 | 883k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:bool", |
592 | 883k | (yaml_char_t *)(input_event.data.scalar.plain_implicit ? "true" |
593 | 883k | : "false"), |
594 | 883k | -1, 1, 0, YAML_PLAIN_SCALAR_STYLE)) |
595 | 0 | goto error; |
596 | 883k | if (!yaml_emitter_emit(&emitter, &output_event)) |
597 | 0 | goto error; |
598 | | |
599 | | /* Write 'quoted'. */ |
600 | | |
601 | 883k | if (!yaml_scalar_event_initialize( |
602 | 883k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
603 | 883k | (yaml_char_t *)"non-plain", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
604 | 0 | goto error; |
605 | 883k | if (!yaml_emitter_emit(&emitter, &output_event)) |
606 | 0 | goto error; |
607 | | |
608 | | /* Write if the scalar is implicit in a non-plain style. */ |
609 | | |
610 | 883k | if (!yaml_scalar_event_initialize( |
611 | 883k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:bool", |
612 | 883k | (yaml_char_t *)(input_event.data.scalar.quoted_implicit |
613 | 883k | ? "true" |
614 | 883k | : "false"), |
615 | 883k | -1, 1, 0, YAML_PLAIN_SCALAR_STYLE)) |
616 | 0 | goto error; |
617 | 883k | if (!yaml_emitter_emit(&emitter, &output_event)) |
618 | 0 | goto error; |
619 | | |
620 | | /* Write '}'. */ |
621 | | |
622 | 883k | if (!yaml_mapping_end_event_initialize(&output_event)) |
623 | 0 | goto error; |
624 | 883k | if (!yaml_emitter_emit(&emitter, &output_event)) |
625 | 0 | goto error; |
626 | | |
627 | | /* Display the style information. */ |
628 | | |
629 | 883k | if (input_event.data.scalar.style) { |
630 | 883k | yaml_scalar_style_t style = input_event.data.scalar.style; |
631 | | |
632 | | /* Write 'style'. */ |
633 | | |
634 | 883k | if (!yaml_scalar_event_initialize( |
635 | 883k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
636 | 883k | (yaml_char_t *)"style", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
637 | 0 | goto error; |
638 | 883k | if (!yaml_emitter_emit(&emitter, &output_event)) |
639 | 0 | goto error; |
640 | | |
641 | | /* Write the scalar style. */ |
642 | | |
643 | 883k | if (!yaml_scalar_event_initialize( |
644 | 883k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
645 | 883k | (yaml_char_t |
646 | 883k | *)(style == YAML_PLAIN_SCALAR_STYLE |
647 | 883k | ? "plain" |
648 | 883k | : style == YAML_SINGLE_QUOTED_SCALAR_STYLE |
649 | 18.3k | ? "single-quoted" |
650 | 18.3k | : style == YAML_DOUBLE_QUOTED_SCALAR_STYLE |
651 | 14.4k | ? "double-quoted" |
652 | 14.4k | : style == YAML_LITERAL_SCALAR_STYLE |
653 | 12.7k | ? "literal" |
654 | 12.7k | : style == |
655 | 8.72k | YAML_FOLDED_SCALAR_STYLE |
656 | 8.72k | ? "folded" |
657 | 8.72k | : "unknown"), |
658 | 883k | -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
659 | 0 | goto error; |
660 | 883k | if (!yaml_emitter_emit(&emitter, &output_event)) |
661 | 0 | goto error; |
662 | 883k | } |
663 | | |
664 | 883k | break; |
665 | | |
666 | 883k | case YAML_SEQUENCE_START_EVENT: |
667 | | |
668 | | /* Write 'type'. */ |
669 | | |
670 | 132k | if (!yaml_scalar_event_initialize( |
671 | 132k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
672 | 132k | (yaml_char_t *)"type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
673 | 0 | goto error; |
674 | 132k | if (!yaml_emitter_emit(&emitter, &output_event)) |
675 | 0 | goto error; |
676 | | |
677 | | /* Write 'SEQUENCE-START'. */ |
678 | | |
679 | 132k | if (!yaml_scalar_event_initialize(&output_event, NULL, |
680 | 132k | (yaml_char_t *)"tag:yaml.org,2002:str", |
681 | 132k | (yaml_char_t *)"SEQUENCE-START", -1, 1, |
682 | 132k | 1, YAML_PLAIN_SCALAR_STYLE)) |
683 | 0 | goto error; |
684 | 132k | if (!yaml_emitter_emit(&emitter, &output_event)) |
685 | 0 | goto error; |
686 | | |
687 | | /* Display the sequence anchor. */ |
688 | | |
689 | 132k | if (input_event.data.sequence_start.anchor) { |
690 | | /* Write 'anchor'. */ |
691 | | |
692 | 1.11k | if (!yaml_scalar_event_initialize( |
693 | 1.11k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
694 | 1.11k | (yaml_char_t *)"anchor", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
695 | 0 | goto error; |
696 | 1.11k | if (!yaml_emitter_emit(&emitter, &output_event)) |
697 | 0 | goto error; |
698 | | |
699 | | /* Write the sequence anchor. */ |
700 | | |
701 | 1.11k | if (!yaml_scalar_event_initialize( |
702 | 1.11k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
703 | 1.11k | input_event.data.sequence_start.anchor, -1, 0, 1, |
704 | 1.11k | YAML_DOUBLE_QUOTED_SCALAR_STYLE)) |
705 | 0 | goto error; |
706 | 1.11k | if (!yaml_emitter_emit(&emitter, &output_event)) |
707 | 0 | goto error; |
708 | 1.11k | } |
709 | | |
710 | | /* Display the sequence tag. */ |
711 | | |
712 | 132k | if (input_event.data.sequence_start.tag) { |
713 | | /* Write 'tag'. */ |
714 | | |
715 | 3.51k | if (!yaml_scalar_event_initialize( |
716 | 3.51k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
717 | 3.51k | (yaml_char_t *)"tag", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
718 | 0 | goto error; |
719 | 3.51k | if (!yaml_emitter_emit(&emitter, &output_event)) |
720 | 0 | goto error; |
721 | | |
722 | | /* Write the sequence tag. */ |
723 | | |
724 | 3.51k | if (!yaml_scalar_event_initialize( |
725 | 3.51k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
726 | 3.51k | input_event.data.sequence_start.tag, -1, 0, 1, |
727 | 3.51k | YAML_DOUBLE_QUOTED_SCALAR_STYLE)) |
728 | 1 | goto error; |
729 | 3.51k | if (!yaml_emitter_emit(&emitter, &output_event)) |
730 | 0 | goto error; |
731 | 3.51k | } |
732 | | |
733 | | /* Write 'implicit'. */ |
734 | | |
735 | 132k | if (!yaml_scalar_event_initialize( |
736 | 132k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
737 | 132k | (yaml_char_t *)"implicit", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
738 | 0 | goto error; |
739 | 132k | if (!yaml_emitter_emit(&emitter, &output_event)) |
740 | 0 | goto error; |
741 | | |
742 | | /* Write if the sequence tag is implicit. */ |
743 | | |
744 | 132k | if (!yaml_scalar_event_initialize( |
745 | 132k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:bool", |
746 | 132k | (yaml_char_t *)(input_event.data.sequence_start.implicit |
747 | 132k | ? "true" |
748 | 132k | : "false"), |
749 | 132k | -1, 1, 0, YAML_PLAIN_SCALAR_STYLE)) |
750 | 0 | goto error; |
751 | 132k | if (!yaml_emitter_emit(&emitter, &output_event)) |
752 | 0 | goto error; |
753 | | |
754 | | /* Display the style information. */ |
755 | | |
756 | 132k | if (input_event.data.sequence_start.style) { |
757 | 132k | yaml_sequence_style_t style = input_event.data.sequence_start.style; |
758 | | |
759 | | /* Write 'style'. */ |
760 | | |
761 | 132k | if (!yaml_scalar_event_initialize( |
762 | 132k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
763 | 132k | (yaml_char_t *)"style", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
764 | 0 | goto error; |
765 | 132k | if (!yaml_emitter_emit(&emitter, &output_event)) |
766 | 0 | goto error; |
767 | | |
768 | | /* Write the scalar style. */ |
769 | | |
770 | 132k | if (!yaml_scalar_event_initialize( |
771 | 132k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
772 | 132k | (yaml_char_t *)(style == YAML_BLOCK_SEQUENCE_STYLE |
773 | 132k | ? "block" |
774 | 132k | : style == YAML_FLOW_SEQUENCE_STYLE |
775 | 18.1k | ? "flow" |
776 | 18.1k | : "unknown"), |
777 | 132k | -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
778 | 0 | goto error; |
779 | 132k | if (!yaml_emitter_emit(&emitter, &output_event)) |
780 | 0 | goto error; |
781 | 132k | } |
782 | | |
783 | 132k | break; |
784 | | |
785 | 132k | case YAML_SEQUENCE_END_EVENT: |
786 | | |
787 | | /* Write 'type'. */ |
788 | | |
789 | 115k | if (!yaml_scalar_event_initialize( |
790 | 115k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
791 | 115k | (yaml_char_t *)"type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
792 | 0 | goto error; |
793 | 115k | if (!yaml_emitter_emit(&emitter, &output_event)) |
794 | 0 | goto error; |
795 | | |
796 | | /* Write 'SEQUENCE-END'. */ |
797 | | |
798 | 115k | if (!yaml_scalar_event_initialize( |
799 | 115k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
800 | 115k | (yaml_char_t *)"SEQUENCE-END", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
801 | 0 | goto error; |
802 | 115k | if (!yaml_emitter_emit(&emitter, &output_event)) |
803 | 0 | goto error; |
804 | | |
805 | 115k | break; |
806 | | |
807 | 214k | case YAML_MAPPING_START_EVENT: |
808 | | |
809 | | /* Write 'type'. */ |
810 | | |
811 | 214k | if (!yaml_scalar_event_initialize( |
812 | 214k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
813 | 214k | (yaml_char_t *)"type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
814 | 0 | goto error; |
815 | 214k | if (!yaml_emitter_emit(&emitter, &output_event)) |
816 | 0 | goto error; |
817 | | |
818 | | /* Write 'MAPPING-START'. */ |
819 | | |
820 | 214k | if (!yaml_scalar_event_initialize(&output_event, NULL, |
821 | 214k | (yaml_char_t *)"tag:yaml.org,2002:str", |
822 | 214k | (yaml_char_t *)"MAPPING-START", -1, 1, |
823 | 214k | 1, YAML_PLAIN_SCALAR_STYLE)) |
824 | 0 | goto error; |
825 | 214k | if (!yaml_emitter_emit(&emitter, &output_event)) |
826 | 0 | goto error; |
827 | | |
828 | | /* Display the mapping anchor. */ |
829 | | |
830 | 214k | if (input_event.data.mapping_start.anchor) { |
831 | | /* Write 'anchor'. */ |
832 | | |
833 | 360 | if (!yaml_scalar_event_initialize( |
834 | 360 | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
835 | 360 | (yaml_char_t *)"anchor", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
836 | 0 | goto error; |
837 | 360 | if (!yaml_emitter_emit(&emitter, &output_event)) |
838 | 0 | goto error; |
839 | | |
840 | | /* Write the mapping anchor. */ |
841 | | |
842 | 360 | if (!yaml_scalar_event_initialize( |
843 | 360 | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
844 | 360 | input_event.data.mapping_start.anchor, -1, 0, 1, |
845 | 360 | YAML_DOUBLE_QUOTED_SCALAR_STYLE)) |
846 | 0 | goto error; |
847 | 360 | if (!yaml_emitter_emit(&emitter, &output_event)) |
848 | 0 | goto error; |
849 | 360 | } |
850 | | |
851 | | /* Display the mapping tag. */ |
852 | | |
853 | 214k | if (input_event.data.mapping_start.tag) { |
854 | | /* Write 'tag'. */ |
855 | | |
856 | 535 | if (!yaml_scalar_event_initialize( |
857 | 535 | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
858 | 535 | (yaml_char_t *)"tag", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
859 | 0 | goto error; |
860 | 535 | if (!yaml_emitter_emit(&emitter, &output_event)) |
861 | 0 | goto error; |
862 | | |
863 | | /* Write the mapping tag. */ |
864 | | |
865 | 535 | if (!yaml_scalar_event_initialize( |
866 | 535 | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
867 | 535 | input_event.data.mapping_start.tag, -1, 0, 1, |
868 | 535 | YAML_DOUBLE_QUOTED_SCALAR_STYLE)) |
869 | 1 | goto error; |
870 | 534 | if (!yaml_emitter_emit(&emitter, &output_event)) |
871 | 0 | goto error; |
872 | 534 | } |
873 | | |
874 | | /* Write 'implicit'. */ |
875 | | |
876 | 214k | if (!yaml_scalar_event_initialize( |
877 | 214k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
878 | 214k | (yaml_char_t *)"implicit", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
879 | 0 | goto error; |
880 | 214k | if (!yaml_emitter_emit(&emitter, &output_event)) |
881 | 0 | goto error; |
882 | | |
883 | | /* Write if the mapping tag is implicit. */ |
884 | | |
885 | 214k | if (!yaml_scalar_event_initialize( |
886 | 214k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:bool", |
887 | 214k | (yaml_char_t *)(input_event.data.mapping_start.implicit |
888 | 214k | ? "true" |
889 | 214k | : "false"), |
890 | 214k | -1, 1, 0, YAML_PLAIN_SCALAR_STYLE)) |
891 | 0 | goto error; |
892 | 214k | if (!yaml_emitter_emit(&emitter, &output_event)) |
893 | 0 | goto error; |
894 | | |
895 | | /* Display the style information. */ |
896 | | |
897 | 214k | if (input_event.data.mapping_start.style) { |
898 | 214k | yaml_mapping_style_t style = input_event.data.mapping_start.style; |
899 | | |
900 | | /* Write 'style'. */ |
901 | | |
902 | 214k | if (!yaml_scalar_event_initialize( |
903 | 214k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
904 | 214k | (yaml_char_t *)"style", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
905 | 0 | goto error; |
906 | 214k | if (!yaml_emitter_emit(&emitter, &output_event)) |
907 | 0 | goto error; |
908 | | |
909 | | /* Write the scalar style. */ |
910 | | |
911 | 214k | if (!yaml_scalar_event_initialize( |
912 | 214k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
913 | 214k | (yaml_char_t *)(style == YAML_BLOCK_MAPPING_STYLE |
914 | 214k | ? "block" |
915 | 214k | : style == YAML_FLOW_MAPPING_STYLE |
916 | 19.7k | ? "flow" |
917 | 19.7k | : "unknown"), |
918 | 214k | -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
919 | 0 | goto error; |
920 | 214k | if (!yaml_emitter_emit(&emitter, &output_event)) |
921 | 0 | goto error; |
922 | 214k | } |
923 | | |
924 | 214k | break; |
925 | | |
926 | 214k | case YAML_MAPPING_END_EVENT: |
927 | | |
928 | | /* Write 'type'. */ |
929 | | |
930 | 198k | if (!yaml_scalar_event_initialize( |
931 | 198k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
932 | 198k | (yaml_char_t *)"type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
933 | 0 | goto error; |
934 | 198k | if (!yaml_emitter_emit(&emitter, &output_event)) |
935 | 0 | goto error; |
936 | | |
937 | | /* Write 'MAPPING-END'. */ |
938 | | |
939 | 198k | if (!yaml_scalar_event_initialize( |
940 | 198k | &output_event, NULL, (yaml_char_t *)"tag:yaml.org,2002:str", |
941 | 198k | (yaml_char_t *)"MAPPING-END", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) |
942 | 0 | goto error; |
943 | 198k | if (!yaml_emitter_emit(&emitter, &output_event)) |
944 | 0 | goto error; |
945 | | |
946 | 198k | break; |
947 | | |
948 | 198k | default: |
949 | | /* It couldn't really happen. */ |
950 | 0 | break; |
951 | 1.98M | } |
952 | | |
953 | | /* Delete the event object. */ |
954 | | |
955 | 1.98M | yaml_event_delete(&input_event); |
956 | | |
957 | | /* Create and emit a MAPPING-END event. */ |
958 | | |
959 | 1.98M | if (!yaml_mapping_end_event_initialize(&output_event)) |
960 | 0 | goto error; |
961 | 1.98M | if (!yaml_emitter_emit(&emitter, &output_event)) |
962 | 0 | goto error; |
963 | 1.98M | } |
964 | | |
965 | | /* Create and emit the SEQUENCE-END event. */ |
966 | | |
967 | 3.91k | if (!yaml_sequence_end_event_initialize(&output_event)) |
968 | 0 | goto error; |
969 | 3.91k | if (!yaml_emitter_emit(&emitter, &output_event)) |
970 | 0 | goto error; |
971 | | |
972 | | /* Create and emit the DOCUMENT-END event. */ |
973 | | |
974 | 3.91k | if (!yaml_document_end_event_initialize(&output_event, 0)) |
975 | 0 | goto error; |
976 | 3.91k | if (!yaml_emitter_emit(&emitter, &output_event)) |
977 | 2.70k | goto error; |
978 | | |
979 | | /* Create and emit the STREAM-END event. */ |
980 | | |
981 | 1.20k | if (!yaml_stream_end_event_initialize(&output_event)) |
982 | 0 | goto error; |
983 | 1.20k | yaml_emitter_emit(&emitter, &output_event); |
984 | | |
985 | 9.28k | error: |
986 | | |
987 | 9.28k | free(out.buf); |
988 | | |
989 | 9.28k | yaml_event_delete(&input_event); |
990 | 9.28k | yaml_parser_delete(&parser); |
991 | 9.28k | yaml_emitter_delete(&emitter); |
992 | | |
993 | 9.28k | return 0; |
994 | 1.20k | } |