8 main(int argc, char *argv[])
17 yaml_emitter_t emitter;
18 yaml_event_t input_event;
19 yaml_document_t output_document;
23 /* Clear the objects. */
25 memset(&parser, 0, sizeof(parser));
26 memset(&emitter, 0, sizeof(emitter));
27 memset(&input_event, 0, sizeof(input_event));
28 memset(&output_document, 0, sizeof(output_document));
30 /* Analyze command line options. */
32 for (k = 1; k < argc; k ++)
34 if (strcmp(argv[k], "-h") == 0
35 || strcmp(argv[k], "--help") == 0) {
39 else if (strcmp(argv[k], "-c") == 0
40 || strcmp(argv[k], "--canonical") == 0) {
44 else if (strcmp(argv[k], "-u") == 0
45 || strcmp(argv[k], "--unicode") == 0) {
50 fprintf(stderr, "Unrecognized option: %s\n"
51 "Try `%s --help` for more information.\n",
57 /* Display the help string. */
62 "or\n%s -h | --help\nDeconstruct a YAML stream\n\nOptions:\n"
63 "-h, --help\t\tdisplay this help and exit\n"
64 "-c, --canonical\t\toutput in the canonical YAML format\n"
65 "-u, --unicode\t\toutput unescaped non-ASCII characters\n",
70 /* Initialize the parser and emitter objects. */
72 if (!yaml_parser_initialize(&parser)) {
73 fprintf(stderr, "Could not initialize the parser object\n");
77 if (!yaml_emitter_initialize(&emitter)) {
78 yaml_parser_delete(&parser);
79 fprintf(stderr, "Could not inialize the emitter object\n");
83 /* Set the parser parameters. */
85 yaml_parser_set_input_file(&parser, stdin);
87 /* Set the emitter parameters. */
89 yaml_emitter_set_output_file(&emitter, stdout);
91 yaml_emitter_set_canonical(&emitter, canonical);
92 yaml_emitter_set_unicode(&emitter, unicode);
94 /* Create and emit the STREAM-START event. */
96 if (!yaml_emitter_open(&emitter))
99 /* Create a output_document object. */
101 if (!yaml_document_initialize(&output_document, NULL, NULL, NULL, 0, 0))
104 /* Create the root sequence. */
106 root = yaml_document_add_sequence(&output_document, NULL,
107 YAML_BLOCK_SEQUENCE_STYLE);
108 if (!root) goto document_error;
110 /* Loop through the input events. */
114 int properties, key, value, map, seq;
116 /* Get the next event. */
118 if (!yaml_parser_parse(&parser, &input_event))
121 /* Check if this is the stream end. */
123 if (input_event.type == YAML_STREAM_END_EVENT) {
127 /* Create a mapping node and attach it to the root sequence. */
129 properties = yaml_document_add_mapping(&output_document, NULL,
130 YAML_BLOCK_MAPPING_STYLE);
131 if (!properties) goto document_error;
132 if (!yaml_document_append_sequence_item(&output_document,
133 root, properties)) goto document_error;
135 /* Analyze the event. */
137 switch (input_event.type)
139 case YAML_STREAM_START_EVENT:
141 /* Add 'type': 'STREAM-START'. */
143 key = yaml_document_add_scalar(&output_document, NULL,
144 "type", -1, YAML_PLAIN_SCALAR_STYLE);
145 if (!key) goto document_error;
146 value = yaml_document_add_scalar(&output_document, NULL,
147 "STREAM-START", -1, YAML_PLAIN_SCALAR_STYLE);
148 if (!value) goto document_error;
149 if (!yaml_document_append_mapping_pair(&output_document,
150 properties, key, value)) goto document_error;
152 /* Add 'encoding': <encoding>. */
154 if (input_event.data.stream_start.encoding)
156 yaml_encoding_t encoding
157 = input_event.data.stream_start.encoding;
159 key = yaml_document_add_scalar(&output_document, NULL,
160 "encoding", -1, YAML_PLAIN_SCALAR_STYLE);
161 if (!key) goto document_error;
162 value = yaml_document_add_scalar(&output_document, NULL,
163 (encoding == YAML_UTF8_ENCODING ? "utf-8" :
164 encoding == YAML_UTF16LE_ENCODING ? "utf-16-le" :
165 encoding == YAML_UTF16BE_ENCODING ? "utf-16-be" :
166 "unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
167 if (!value) goto document_error;
168 if (!yaml_document_append_mapping_pair(&output_document,
169 properties, key, value)) goto document_error;
174 case YAML_STREAM_END_EVENT:
176 /* Add 'type': 'STREAM-END'. */
178 key = yaml_document_add_scalar(&output_document, NULL,
179 "type", -1, YAML_PLAIN_SCALAR_STYLE);
180 if (!key) goto document_error;
181 value = yaml_document_add_scalar(&output_document, NULL,
182 "STREAM-END", -1, YAML_PLAIN_SCALAR_STYLE);
183 if (!value) goto document_error;
184 if (!yaml_document_append_mapping_pair(&output_document,
185 properties, key, value)) goto document_error;
189 case YAML_DOCUMENT_START_EVENT:
191 /* Add 'type': 'DOCUMENT-START'. */
193 key = yaml_document_add_scalar(&output_document, NULL,
194 "type", -1, YAML_PLAIN_SCALAR_STYLE);
195 if (!key) goto document_error;
196 value = yaml_document_add_scalar(&output_document, NULL,
197 "DOCUMENT-START", -1, YAML_PLAIN_SCALAR_STYLE);
198 if (!value) goto document_error;
199 if (!yaml_document_append_mapping_pair(&output_document,
200 properties, key, value)) goto document_error;
202 /* Display the output_document version numbers. */
204 if (input_event.data.document_start.version_directive)
206 yaml_version_directive_t *version
207 = input_event.data.document_start.version_directive;
210 /* Add 'version': {}. */
212 key = yaml_document_add_scalar(&output_document, NULL,
213 "version", -1, YAML_PLAIN_SCALAR_STYLE);
214 if (!key) goto document_error;
215 map = yaml_document_add_mapping(&output_document, NULL,
216 YAML_FLOW_MAPPING_STYLE);
217 if (!map) goto document_error;
218 if (!yaml_document_append_mapping_pair(&output_document,
219 properties, key, map)) goto document_error;
221 /* Add 'major': <number>. */
223 key = yaml_document_add_scalar(&output_document, NULL,
224 "major", -1, YAML_PLAIN_SCALAR_STYLE);
225 if (!key) goto document_error;
226 sprintf(number, "%d", version->major);
227 value = yaml_document_add_scalar(&output_document, YAML_INT_TAG,
228 number, -1, YAML_PLAIN_SCALAR_STYLE);
229 if (!value) goto document_error;
230 if (!yaml_document_append_mapping_pair(&output_document,
231 map, key, value)) goto document_error;
233 /* Add 'minor': <number>. */
235 key = yaml_document_add_scalar(&output_document, NULL,
236 "minor", -1, YAML_PLAIN_SCALAR_STYLE);
237 if (!key) goto document_error;
238 sprintf(number, "%d", version->minor);
239 value = yaml_document_add_scalar(&output_document, YAML_INT_TAG,
240 number, -1, YAML_PLAIN_SCALAR_STYLE);
241 if (!value) goto document_error;
242 if (!yaml_document_append_mapping_pair(&output_document,
243 map, key, value)) goto document_error;
246 /* Display the output_document tag directives. */
248 if (input_event.data.document_start.tag_directives.start
249 != input_event.data.document_start.tag_directives.end)
251 yaml_tag_directive_t *tag;
253 /* Add 'tags': []. */
255 key = yaml_document_add_scalar(&output_document, NULL,
256 "tags", -1, YAML_PLAIN_SCALAR_STYLE);
257 if (!key) goto document_error;
258 seq = yaml_document_add_sequence(&output_document, NULL,
259 YAML_BLOCK_SEQUENCE_STYLE);
260 if (!seq) goto document_error;
261 if (!yaml_document_append_mapping_pair(&output_document,
262 properties, key, seq)) goto document_error;
264 for (tag = input_event.data.document_start.tag_directives.start;
265 tag != input_event.data.document_start.tag_directives.end;
270 map = yaml_document_add_mapping(&output_document, NULL,
271 YAML_FLOW_MAPPING_STYLE);
272 if (!map) goto document_error;
273 if (!yaml_document_append_sequence_item(&output_document,
274 seq, map)) goto document_error;
276 /* Add 'handle': <handle>. */
278 key = yaml_document_add_scalar(&output_document, NULL,
279 "handle", -1, YAML_PLAIN_SCALAR_STYLE);
280 if (!key) goto document_error;
281 value = yaml_document_add_scalar(&output_document, NULL,
282 tag->handle, -1, YAML_DOUBLE_QUOTED_SCALAR_STYLE);
283 if (!value) goto document_error;
284 if (!yaml_document_append_mapping_pair(&output_document,
285 map, key, value)) goto document_error;
287 /* Add 'prefix': <prefix>. */
289 key = yaml_document_add_scalar(&output_document, NULL,
290 "prefix", -1, YAML_PLAIN_SCALAR_STYLE);
291 if (!key) goto document_error;
292 value = yaml_document_add_scalar(&output_document, NULL,
293 tag->prefix, -1, YAML_DOUBLE_QUOTED_SCALAR_STYLE);
294 if (!value) goto document_error;
295 if (!yaml_document_append_mapping_pair(&output_document,
296 map, key, value)) goto document_error;
300 /* Add 'implicit': <flag>. */
302 key = yaml_document_add_scalar(&output_document, NULL,
303 "implicit", -1, YAML_PLAIN_SCALAR_STYLE);
304 if (!key) goto document_error;
305 value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG,
306 (input_event.data.document_start.implicit ?
307 "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
308 if (!value) goto document_error;
309 if (!yaml_document_append_mapping_pair(&output_document,
310 properties, key, value)) goto document_error;
314 case YAML_DOCUMENT_END_EVENT:
316 /* Add 'type': 'DOCUMENT-END'. */
318 key = yaml_document_add_scalar(&output_document, NULL,
319 "type", -1, YAML_PLAIN_SCALAR_STYLE);
320 if (!key) goto document_error;
321 value = yaml_document_add_scalar(&output_document, NULL,
322 "DOCUMENT-END", -1, YAML_PLAIN_SCALAR_STYLE);
323 if (!value) goto document_error;
324 if (!yaml_document_append_mapping_pair(&output_document,
325 properties, key, value)) goto document_error;
327 /* Add 'implicit': <flag>. */
329 key = yaml_document_add_scalar(&output_document, NULL,
330 "implicit", -1, YAML_PLAIN_SCALAR_STYLE);
331 if (!key) goto document_error;
332 value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG,
333 (input_event.data.document_end.implicit ?
334 "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
335 if (!value) goto document_error;
336 if (!yaml_document_append_mapping_pair(&output_document,
337 properties, key, value)) goto document_error;
341 case YAML_ALIAS_EVENT:
343 /* Add 'type': 'ALIAS'. */
345 key = yaml_document_add_scalar(&output_document, NULL,
346 "type", -1, YAML_PLAIN_SCALAR_STYLE);
347 if (!key) goto document_error;
348 value = yaml_document_add_scalar(&output_document, NULL,
349 "ALIAS", -1, YAML_PLAIN_SCALAR_STYLE);
350 if (!value) goto document_error;
351 if (!yaml_document_append_mapping_pair(&output_document,
352 properties, key, value)) goto document_error;
354 /* Add 'anchor': <anchor>. */
356 key = yaml_document_add_scalar(&output_document, NULL,
357 "anchor", -1, YAML_PLAIN_SCALAR_STYLE);
358 if (!key) goto document_error;
359 value = yaml_document_add_scalar(&output_document, NULL,
360 input_event.data.alias.anchor, -1,
361 YAML_DOUBLE_QUOTED_SCALAR_STYLE);
362 if (!value) goto document_error;
363 if (!yaml_document_append_mapping_pair(&output_document,
364 properties, key, value)) goto document_error;
368 case YAML_SCALAR_EVENT:
370 /* Add 'type': 'SCALAR'. */
372 key = yaml_document_add_scalar(&output_document, NULL,
373 "type", -1, YAML_PLAIN_SCALAR_STYLE);
374 if (!key) goto document_error;
375 value = yaml_document_add_scalar(&output_document, NULL,
376 "SCALAR", -1, YAML_PLAIN_SCALAR_STYLE);
377 if (!value) goto document_error;
378 if (!yaml_document_append_mapping_pair(&output_document,
379 properties, key, value)) goto document_error;
381 /* Add 'anchor': <anchor>. */
383 if (input_event.data.scalar.anchor)
385 key = yaml_document_add_scalar(&output_document, NULL,
386 "anchor", -1, YAML_PLAIN_SCALAR_STYLE);
387 if (!key) goto document_error;
388 value = yaml_document_add_scalar(&output_document, NULL,
389 input_event.data.scalar.anchor, -1,
390 YAML_DOUBLE_QUOTED_SCALAR_STYLE);
391 if (!value) goto document_error;
392 if (!yaml_document_append_mapping_pair(&output_document,
393 properties, key, value)) goto document_error;
396 /* Add 'tag': <tag>. */
398 if (input_event.data.scalar.tag)
400 key = yaml_document_add_scalar(&output_document, NULL,
401 "tag", -1, YAML_PLAIN_SCALAR_STYLE);
402 if (!key) goto document_error;
403 value = yaml_document_add_scalar(&output_document, NULL,
404 input_event.data.scalar.tag, -1,
405 YAML_DOUBLE_QUOTED_SCALAR_STYLE);
406 if (!value) goto document_error;
407 if (!yaml_document_append_mapping_pair(&output_document,
408 properties, key, value)) goto document_error;
411 /* Add 'value': <value>. */
413 key = yaml_document_add_scalar(&output_document, NULL,
414 "value", -1, YAML_PLAIN_SCALAR_STYLE);
415 if (!key) goto document_error;
416 value = yaml_document_add_scalar(&output_document, NULL,
417 input_event.data.scalar.value,
418 input_event.data.scalar.length,
419 YAML_DOUBLE_QUOTED_SCALAR_STYLE);
420 if (!value) goto document_error;
421 if (!yaml_document_append_mapping_pair(&output_document,
422 properties, key, value)) goto document_error;
424 /* Display if the scalar tag is implicit. */
426 /* Add 'implicit': {} */
428 key = yaml_document_add_scalar(&output_document, NULL,
429 "version", -1, YAML_PLAIN_SCALAR_STYLE);
430 if (!key) goto document_error;
431 map = yaml_document_add_mapping(&output_document, NULL,
432 YAML_FLOW_MAPPING_STYLE);
433 if (!map) goto document_error;
434 if (!yaml_document_append_mapping_pair(&output_document,
435 properties, key, map)) goto document_error;
437 /* Add 'plain': <flag>. */
439 key = yaml_document_add_scalar(&output_document, NULL,
440 "plain", -1, YAML_PLAIN_SCALAR_STYLE);
441 if (!key) goto document_error;
442 value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG,
443 (input_event.data.scalar.plain_implicit ?
444 "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
445 if (!value) goto document_error;
446 if (!yaml_document_append_mapping_pair(&output_document,
447 map, key, value)) goto document_error;
449 /* Add 'quoted': <flag>. */
451 key = yaml_document_add_scalar(&output_document, NULL,
452 "quoted", -1, YAML_PLAIN_SCALAR_STYLE);
453 if (!key) goto document_error;
454 value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG,
455 (input_event.data.scalar.quoted_implicit ?
456 "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
457 if (!value) goto document_error;
458 if (!yaml_document_append_mapping_pair(&output_document,
459 map, key, value)) goto document_error;
461 /* Display the style information. */
463 if (input_event.data.scalar.style)
465 yaml_scalar_style_t style = input_event.data.scalar.style;
467 /* Add 'style': <style>. */
469 key = yaml_document_add_scalar(&output_document, NULL,
470 "style", -1, YAML_PLAIN_SCALAR_STYLE);
471 if (!key) goto document_error;
472 value = yaml_document_add_scalar(&output_document, NULL,
473 (style == YAML_PLAIN_SCALAR_STYLE ? "plain" :
474 style == YAML_SINGLE_QUOTED_SCALAR_STYLE ?
476 style == YAML_DOUBLE_QUOTED_SCALAR_STYLE ?
478 style == YAML_LITERAL_SCALAR_STYLE ? "literal" :
479 style == YAML_FOLDED_SCALAR_STYLE ? "folded" :
480 "unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
481 if (!value) goto document_error;
482 if (!yaml_document_append_mapping_pair(&output_document,
483 properties, key, value)) goto document_error;
488 case YAML_SEQUENCE_START_EVENT:
490 /* Add 'type': 'SEQUENCE-START'. */
492 key = yaml_document_add_scalar(&output_document, NULL,
493 "type", -1, YAML_PLAIN_SCALAR_STYLE);
494 if (!key) goto document_error;
495 value = yaml_document_add_scalar(&output_document, NULL,
496 "SEQUENCE-START", -1, YAML_PLAIN_SCALAR_STYLE);
497 if (!value) goto document_error;
498 if (!yaml_document_append_mapping_pair(&output_document,
499 properties, key, value)) goto document_error;
501 /* Add 'anchor': <anchor>. */
503 if (input_event.data.sequence_start.anchor)
505 key = yaml_document_add_scalar(&output_document, NULL,
506 "anchor", -1, YAML_PLAIN_SCALAR_STYLE);
507 if (!key) goto document_error;
508 value = yaml_document_add_scalar(&output_document, NULL,
509 input_event.data.sequence_start.anchor, -1,
510 YAML_DOUBLE_QUOTED_SCALAR_STYLE);
511 if (!value) goto document_error;
512 if (!yaml_document_append_mapping_pair(&output_document,
513 properties, key, value)) goto document_error;
516 /* Add 'tag': <tag>. */
518 if (input_event.data.sequence_start.tag)
520 key = yaml_document_add_scalar(&output_document, NULL,
521 "tag", -1, YAML_PLAIN_SCALAR_STYLE);
522 if (!key) goto document_error;
523 value = yaml_document_add_scalar(&output_document, NULL,
524 input_event.data.sequence_start.tag, -1,
525 YAML_DOUBLE_QUOTED_SCALAR_STYLE);
526 if (!value) goto document_error;
527 if (!yaml_document_append_mapping_pair(&output_document,
528 properties, key, value)) goto document_error;
531 /* Add 'implicit': <flag>. */
533 key = yaml_document_add_scalar(&output_document, NULL,
534 "implicit", -1, YAML_PLAIN_SCALAR_STYLE);
535 if (!key) goto document_error;
536 value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG,
537 (input_event.data.sequence_start.implicit ?
538 "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
539 if (!value) goto document_error;
540 if (!yaml_document_append_mapping_pair(&output_document,
541 properties, key, value)) goto document_error;
543 /* Display the style information. */
545 if (input_event.data.sequence_start.style)
547 yaml_sequence_style_t style
548 = input_event.data.sequence_start.style;
550 /* Add 'style': <style>. */
552 key = yaml_document_add_scalar(&output_document, NULL,
553 "style", -1, YAML_PLAIN_SCALAR_STYLE);
554 if (!key) goto document_error;
555 value = yaml_document_add_scalar(&output_document, NULL,
556 (style == YAML_BLOCK_SEQUENCE_STYLE ? "block" :
557 style == YAML_FLOW_SEQUENCE_STYLE ? "flow" :
558 "unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
559 if (!value) goto document_error;
560 if (!yaml_document_append_mapping_pair(&output_document,
561 properties, key, value)) goto document_error;
566 case YAML_SEQUENCE_END_EVENT:
568 /* Add 'type': 'SEQUENCE-END'. */
570 key = yaml_document_add_scalar(&output_document, NULL,
571 "type", -1, YAML_PLAIN_SCALAR_STYLE);
572 if (!key) goto document_error;
573 value = yaml_document_add_scalar(&output_document, NULL,
574 "SEQUENCE-END", -1, YAML_PLAIN_SCALAR_STYLE);
575 if (!value) goto document_error;
576 if (!yaml_document_append_mapping_pair(&output_document,
577 properties, key, value)) goto document_error;
581 case YAML_MAPPING_START_EVENT:
583 /* Add 'type': 'MAPPING-START'. */
585 key = yaml_document_add_scalar(&output_document, NULL,
586 "type", -1, YAML_PLAIN_SCALAR_STYLE);
587 if (!key) goto document_error;
588 value = yaml_document_add_scalar(&output_document, NULL,
589 "MAPPING-START", -1, YAML_PLAIN_SCALAR_STYLE);
590 if (!value) goto document_error;
591 if (!yaml_document_append_mapping_pair(&output_document,
592 properties, key, value)) goto document_error;
594 /* Add 'anchor': <anchor>. */
596 if (input_event.data.mapping_start.anchor)
598 key = yaml_document_add_scalar(&output_document, NULL,
599 "anchor", -1, YAML_PLAIN_SCALAR_STYLE);
600 if (!key) goto document_error;
601 value = yaml_document_add_scalar(&output_document, NULL,
602 input_event.data.mapping_start.anchor, -1,
603 YAML_DOUBLE_QUOTED_SCALAR_STYLE);
604 if (!value) goto document_error;
605 if (!yaml_document_append_mapping_pair(&output_document,
606 properties, key, value)) goto document_error;
609 /* Add 'tag': <tag>. */
611 if (input_event.data.mapping_start.tag)
613 key = yaml_document_add_scalar(&output_document, NULL,
614 "tag", -1, YAML_PLAIN_SCALAR_STYLE);
615 if (!key) goto document_error;
616 value = yaml_document_add_scalar(&output_document, NULL,
617 input_event.data.mapping_start.tag, -1,
618 YAML_DOUBLE_QUOTED_SCALAR_STYLE);
619 if (!value) goto document_error;
620 if (!yaml_document_append_mapping_pair(&output_document,
621 properties, key, value)) goto document_error;
624 /* Add 'implicit': <flag>. */
626 key = yaml_document_add_scalar(&output_document, NULL,
627 "implicit", -1, YAML_PLAIN_SCALAR_STYLE);
628 if (!key) goto document_error;
629 value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG,
630 (input_event.data.mapping_start.implicit ?
631 "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE);
632 if (!value) goto document_error;
633 if (!yaml_document_append_mapping_pair(&output_document,
634 properties, key, value)) goto document_error;
636 /* Display the style information. */
638 if (input_event.data.sequence_start.style)
640 yaml_sequence_style_t style
641 = input_event.data.mapping_start.style;
643 /* Add 'style': <style>. */
645 key = yaml_document_add_scalar(&output_document, NULL,
646 "style", -1, YAML_PLAIN_SCALAR_STYLE);
647 if (!key) goto document_error;
648 value = yaml_document_add_scalar(&output_document, NULL,
649 (style == YAML_BLOCK_MAPPING_STYLE ? "block" :
650 style == YAML_FLOW_MAPPING_STYLE ? "flow" :
651 "unknown"), -1, YAML_PLAIN_SCALAR_STYLE);
652 if (!value) goto document_error;
653 if (!yaml_document_append_mapping_pair(&output_document,
654 properties, key, value)) goto document_error;
659 case YAML_MAPPING_END_EVENT:
661 /* Add 'type': 'MAPPING-END'. */
663 key = yaml_document_add_scalar(&output_document, NULL,
664 "type", -1, YAML_PLAIN_SCALAR_STYLE);
665 if (!key) goto document_error;
666 value = yaml_document_add_scalar(&output_document, NULL,
667 "MAPPING-END", -1, YAML_PLAIN_SCALAR_STYLE);
668 if (!value) goto document_error;
669 if (!yaml_document_append_mapping_pair(&output_document,
670 properties, key, value)) goto document_error;
675 /* It couldn't really happen. */
679 /* Delete the event object. */
681 yaml_event_delete(&input_event);
684 if (!yaml_emitter_dump(&emitter, &output_document))
686 if (!yaml_emitter_close(&emitter))
689 yaml_parser_delete(&parser);
690 yaml_emitter_delete(&emitter);
696 /* Display a parser error message. */
698 switch (parser.error)
700 case YAML_MEMORY_ERROR:
701 fprintf(stderr, "Memory error: Not enough memory for parsing\n");
704 case YAML_READER_ERROR:
705 if (parser.problem_value != -1) {
706 fprintf(stderr, "Reader error: %s: #%X at %d\n", parser.problem,
707 parser.problem_value, parser.problem_offset);
710 fprintf(stderr, "Reader error: %s at %d\n", parser.problem,
711 parser.problem_offset);
715 case YAML_SCANNER_ERROR:
716 if (parser.context) {
717 fprintf(stderr, "Scanner error: %s at line %d, column %d\n"
718 "%s at line %d, column %d\n", parser.context,
719 parser.context_mark.line+1, parser.context_mark.column+1,
720 parser.problem, parser.problem_mark.line+1,
721 parser.problem_mark.column+1);
724 fprintf(stderr, "Scanner error: %s at line %d, column %d\n",
725 parser.problem, parser.problem_mark.line+1,
726 parser.problem_mark.column+1);
730 case YAML_PARSER_ERROR:
731 if (parser.context) {
732 fprintf(stderr, "Parser error: %s at line %d, column %d\n"
733 "%s at line %d, column %d\n", parser.context,
734 parser.context_mark.line+1, parser.context_mark.column+1,
735 parser.problem, parser.problem_mark.line+1,
736 parser.problem_mark.column+1);
739 fprintf(stderr, "Parser error: %s at line %d, column %d\n",
740 parser.problem, parser.problem_mark.line+1,
741 parser.problem_mark.column+1);
746 /* Couldn't happen. */
747 fprintf(stderr, "Internal error\n");
751 yaml_event_delete(&input_event);
752 yaml_document_delete(&output_document);
753 yaml_parser_delete(&parser);
754 yaml_emitter_delete(&emitter);
760 /* Display an emitter error message. */
762 switch (emitter.error)
764 case YAML_MEMORY_ERROR:
765 fprintf(stderr, "Memory error: Not enough memory for emitting\n");
768 case YAML_WRITER_ERROR:
769 fprintf(stderr, "Writer error: %s\n", emitter.problem);
772 case YAML_EMITTER_ERROR:
773 fprintf(stderr, "Emitter error: %s\n", emitter.problem);
777 /* Couldn't happen. */
778 fprintf(stderr, "Internal error\n");
782 yaml_event_delete(&input_event);
783 yaml_document_delete(&output_document);
784 yaml_parser_delete(&parser);
785 yaml_emitter_delete(&emitter);
791 fprintf(stderr, "Memory error: Not enough memory for creating a document\n");
793 yaml_event_delete(&input_event);
794 yaml_document_delete(&output_document);
795 yaml_parser_delete(&parser);
796 yaml_emitter_delete(&emitter);