Path: blob/main/contrib/libyaml/tests/example-deconstructor.c
39507 views
1#include <yaml.h>23#include <stdlib.h>4#include <stdio.h>56int7main(int argc, char *argv[])8{9int help = 0;10int canonical = 0;11int unicode = 0;12int k;13int done = 0;1415yaml_parser_t parser;16yaml_emitter_t emitter;17yaml_event_t input_event;18yaml_event_t output_event;1920/* Clear the objects. */2122memset(&parser, 0, sizeof(parser));23memset(&emitter, 0, sizeof(emitter));24memset(&input_event, 0, sizeof(input_event));25memset(&output_event, 0, sizeof(output_event));2627/* Analyze command line options. */2829for (k = 1; k < argc; k ++)30{31if (strcmp(argv[k], "-h") == 032|| strcmp(argv[k], "--help") == 0) {33help = 1;34}3536else if (strcmp(argv[k], "-c") == 037|| strcmp(argv[k], "--canonical") == 0) {38canonical = 1;39}4041else if (strcmp(argv[k], "-u") == 042|| strcmp(argv[k], "--unicode") == 0) {43unicode = 1;44}4546else {47fprintf(stderr, "Unrecognized option: %s\n"48"Try `%s --help` for more information.\n",49argv[k], argv[0]);50return 1;51}52}5354/* Display the help string. */5556if (help)57{58printf("%s <input\n"59"or\n%s -h | --help\nDeconstruct a YAML stream\n\nOptions:\n"60"-h, --help\t\tdisplay this help and exit\n"61"-c, --canonical\t\toutput in the canonical YAML format\n"62"-u, --unicode\t\toutput unescaped non-ASCII characters\n",63argv[0], argv[0]);64return 0;65}6667/* Initialize the parser and emitter objects. */6869if (!yaml_parser_initialize(&parser)) {70fprintf(stderr, "Could not initialize the parser object\n");71return 1;72}7374if (!yaml_emitter_initialize(&emitter)) {75yaml_parser_delete(&parser);76fprintf(stderr, "Could not inialize the emitter object\n");77return 1;78}7980/* Set the parser parameters. */8182yaml_parser_set_input_file(&parser, stdin);8384/* Set the emitter parameters. */8586yaml_emitter_set_output_file(&emitter, stdout);8788yaml_emitter_set_canonical(&emitter, canonical);89yaml_emitter_set_unicode(&emitter, unicode);9091/* Create and emit the STREAM-START event. */9293if (!yaml_stream_start_event_initialize(&output_event, YAML_UTF8_ENCODING))94goto event_error;95if (!yaml_emitter_emit(&emitter, &output_event))96goto emitter_error;9798/* Create and emit the DOCUMENT-START event. */99100if (!yaml_document_start_event_initialize(&output_event,101NULL, NULL, NULL, 0))102goto event_error;103if (!yaml_emitter_emit(&emitter, &output_event))104goto emitter_error;105106/* Create and emit the SEQUENCE-START event. */107108if (!yaml_sequence_start_event_initialize(&output_event,109NULL, (yaml_char_t *)"tag:yaml.org,2002:seq", 1,110YAML_BLOCK_SEQUENCE_STYLE))111goto event_error;112if (!yaml_emitter_emit(&emitter, &output_event))113goto emitter_error;114115/* Loop through the input events. */116117while (!done)118{119/* Get the next event. */120121if (!yaml_parser_parse(&parser, &input_event))122goto parser_error;123124/* Check if this is the stream end. */125126if (input_event.type == YAML_STREAM_END_EVENT) {127done = 1;128}129130/* Create and emit a MAPPING-START event. */131132if (!yaml_mapping_start_event_initialize(&output_event,133NULL, (yaml_char_t *)"tag:yaml.org,2002:map", 1,134YAML_BLOCK_MAPPING_STYLE))135goto event_error;136if (!yaml_emitter_emit(&emitter, &output_event))137goto emitter_error;138139/* Analyze the event. */140141switch (input_event.type)142{143case YAML_STREAM_START_EVENT:144145/* Write 'type'. */146147if (!yaml_scalar_event_initialize(&output_event,148NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"type", -1,1491, 1, YAML_PLAIN_SCALAR_STYLE))150goto event_error;151if (!yaml_emitter_emit(&emitter, &output_event))152goto emitter_error;153154/* Write 'STREAM-START'. */155156if (!yaml_scalar_event_initialize(&output_event,157NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"STREAM-START", -1,1581, 1, YAML_PLAIN_SCALAR_STYLE))159goto event_error;160if (!yaml_emitter_emit(&emitter, &output_event))161goto emitter_error;162163/* Display encoding information. */164165if (input_event.data.stream_start.encoding)166{167yaml_encoding_t encoding168= input_event.data.stream_start.encoding;169170/* Write 'encoding'. */171172if (!yaml_scalar_event_initialize(&output_event,173NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"encoding", -1,1741, 1, YAML_PLAIN_SCALAR_STYLE))175goto event_error;176if (!yaml_emitter_emit(&emitter, &output_event))177goto emitter_error;178179/* Write the stream encoding. */180181if (!yaml_scalar_event_initialize(&output_event,182NULL, (yaml_char_t *)"tag:yaml.org,2002:str",183(yaml_char_t *)(encoding == YAML_UTF8_ENCODING ? "utf-8" :184encoding == YAML_UTF16LE_ENCODING ? "utf-16-le" :185encoding == YAML_UTF16BE_ENCODING ? "utf-16-be" :186"unknown"), -1,1871, 1, YAML_PLAIN_SCALAR_STYLE))188goto event_error;189if (!yaml_emitter_emit(&emitter, &output_event))190goto emitter_error;191}192193break;194195case YAML_STREAM_END_EVENT:196197/* Write 'type'. */198199if (!yaml_scalar_event_initialize(&output_event,200NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"type", -1,2011, 1, YAML_PLAIN_SCALAR_STYLE))202goto event_error;203if (!yaml_emitter_emit(&emitter, &output_event))204goto emitter_error;205206/* Write 'STREAM-END'. */207208if (!yaml_scalar_event_initialize(&output_event,209NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"STREAM-END", -1,2101, 1, YAML_PLAIN_SCALAR_STYLE))211goto event_error;212if (!yaml_emitter_emit(&emitter, &output_event))213goto emitter_error;214215break;216217case YAML_DOCUMENT_START_EVENT:218219/* Write 'type'. */220221if (!yaml_scalar_event_initialize(&output_event,222NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"type", -1,2231, 1, YAML_PLAIN_SCALAR_STYLE))224goto event_error;225if (!yaml_emitter_emit(&emitter, &output_event))226goto emitter_error;227228/* Write 'DOCUMENT-START'. */229230if (!yaml_scalar_event_initialize(&output_event,231NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"DOCUMENT-START", -1,2321, 1, YAML_PLAIN_SCALAR_STYLE))233goto event_error;234if (!yaml_emitter_emit(&emitter, &output_event))235goto emitter_error;236237/* Display the document version numbers. */238239if (input_event.data.document_start.version_directive)240{241yaml_version_directive_t *version242= input_event.data.document_start.version_directive;243char number[64];244245/* Write 'version'. */246247if (!yaml_scalar_event_initialize(&output_event,248NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"version", -1,2491, 1, YAML_PLAIN_SCALAR_STYLE))250goto event_error;251if (!yaml_emitter_emit(&emitter, &output_event))252goto emitter_error;253254/* Write '{'. */255256if (!yaml_mapping_start_event_initialize(&output_event,257NULL, (yaml_char_t *)"tag:yaml.org,2002:map", 1,258YAML_FLOW_MAPPING_STYLE))259goto event_error;260if (!yaml_emitter_emit(&emitter, &output_event))261goto emitter_error;262263/* Write 'major'. */264265if (!yaml_scalar_event_initialize(&output_event,266NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"major", -1,2671, 1, YAML_PLAIN_SCALAR_STYLE))268goto event_error;269if (!yaml_emitter_emit(&emitter, &output_event))270goto emitter_error;271272/* Write a number. */273274sprintf(number, "%d", version->major);275if (!yaml_scalar_event_initialize(&output_event,276NULL, (yaml_char_t *)"tag:yaml.org,2002:int", (yaml_char_t *)number, -1,2771, 1, YAML_PLAIN_SCALAR_STYLE))278goto event_error;279if (!yaml_emitter_emit(&emitter, &output_event))280goto emitter_error;281282/* Write 'minor'. */283284if (!yaml_scalar_event_initialize(&output_event,285NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"minor", -1,2861, 1, YAML_PLAIN_SCALAR_STYLE))287goto event_error;288if (!yaml_emitter_emit(&emitter, &output_event))289goto emitter_error;290291/* Write a number. */292293sprintf(number, "%d", version->minor);294if (!yaml_scalar_event_initialize(&output_event,295NULL, (yaml_char_t *)"tag:yaml.org,2002:int", (yaml_char_t *)number, -1,2961, 1, YAML_PLAIN_SCALAR_STYLE))297goto event_error;298if (!yaml_emitter_emit(&emitter, &output_event))299goto emitter_error;300301/* Write '}'. */302303if (!yaml_mapping_end_event_initialize(&output_event))304goto event_error;305if (!yaml_emitter_emit(&emitter, &output_event))306goto emitter_error;307}308309/* Display the document tag directives. */310311if (input_event.data.document_start.tag_directives.start312!= input_event.data.document_start.tag_directives.end)313{314yaml_tag_directive_t *tag;315316/* Write 'tags'. */317318if (!yaml_scalar_event_initialize(&output_event,319NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"tags", -1,3201, 1, YAML_PLAIN_SCALAR_STYLE))321goto event_error;322if (!yaml_emitter_emit(&emitter, &output_event))323goto emitter_error;324325/* Start a block sequence. */326327if (!yaml_sequence_start_event_initialize(&output_event,328NULL, (yaml_char_t *)"tag:yaml.org,2002:seq", 1,329YAML_BLOCK_SEQUENCE_STYLE))330goto event_error;331if (!yaml_emitter_emit(&emitter, &output_event))332goto emitter_error;333334for (tag = input_event.data.document_start.tag_directives.start;335tag != input_event.data.document_start.tag_directives.end;336tag ++)337{338/* Write '{'. */339340if (!yaml_mapping_start_event_initialize(&output_event,341NULL, (yaml_char_t *)"tag:yaml.org,2002:map", 1,342YAML_FLOW_MAPPING_STYLE))343goto event_error;344if (!yaml_emitter_emit(&emitter, &output_event))345goto emitter_error;346347/* Write 'handle'. */348349if (!yaml_scalar_event_initialize(&output_event,350NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"handle", -1,3511, 1, YAML_PLAIN_SCALAR_STYLE))352goto event_error;353if (!yaml_emitter_emit(&emitter, &output_event))354goto emitter_error;355356/* Write the tag directive handle. */357358if (!yaml_scalar_event_initialize(&output_event,359NULL, (yaml_char_t *)"tag:yaml.org,2002:str",360tag->handle, -1,3610, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE))362goto event_error;363if (!yaml_emitter_emit(&emitter, &output_event))364goto emitter_error;365366/* Write 'prefix'. */367368if (!yaml_scalar_event_initialize(&output_event,369NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"prefix", -1,3701, 1, YAML_PLAIN_SCALAR_STYLE))371goto event_error;372if (!yaml_emitter_emit(&emitter, &output_event))373goto emitter_error;374375/* Write the tag directive prefix. */376377if (!yaml_scalar_event_initialize(&output_event,378NULL, (yaml_char_t *)"tag:yaml.org,2002:str",379tag->prefix, -1,3800, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE))381goto event_error;382if (!yaml_emitter_emit(&emitter, &output_event))383goto emitter_error;384385/* Write '}'. */386387if (!yaml_mapping_end_event_initialize(&output_event))388goto event_error;389if (!yaml_emitter_emit(&emitter, &output_event))390goto emitter_error;391}392393/* End a block sequence. */394395if (!yaml_sequence_end_event_initialize(&output_event))396goto event_error;397if (!yaml_emitter_emit(&emitter, &output_event))398goto emitter_error;399}400401/* Write 'implicit'. */402403if (!yaml_scalar_event_initialize(&output_event,404NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"implicit", -1,4051, 1, YAML_PLAIN_SCALAR_STYLE))406goto event_error;407if (!yaml_emitter_emit(&emitter, &output_event))408goto emitter_error;409410/* Write if the document is implicit. */411412if (!yaml_scalar_event_initialize(&output_event,413NULL, (yaml_char_t *)"tag:yaml.org,2002:bool",414(yaml_char_t *)(input_event.data.document_start.implicit ?415"true" : "false"), -1,4161, 0, YAML_PLAIN_SCALAR_STYLE))417goto event_error;418if (!yaml_emitter_emit(&emitter, &output_event))419goto emitter_error;420421break;422423case YAML_DOCUMENT_END_EVENT:424425/* Write 'type'. */426427if (!yaml_scalar_event_initialize(&output_event,428NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"type", -1,4291, 1, YAML_PLAIN_SCALAR_STYLE))430goto event_error;431if (!yaml_emitter_emit(&emitter, &output_event))432goto emitter_error;433434/* Write 'DOCUMENT-END'. */435436if (!yaml_scalar_event_initialize(&output_event,437NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"DOCUMENT-END", -1,4381, 1, YAML_PLAIN_SCALAR_STYLE))439goto event_error;440if (!yaml_emitter_emit(&emitter, &output_event))441goto emitter_error;442443/* Write 'implicit'. */444445if (!yaml_scalar_event_initialize(&output_event,446NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"implicit", -1,4471, 1, YAML_PLAIN_SCALAR_STYLE))448goto event_error;449if (!yaml_emitter_emit(&emitter, &output_event))450goto emitter_error;451452/* Write if the document is implicit. */453454if (!yaml_scalar_event_initialize(&output_event,455NULL, (yaml_char_t *)"tag:yaml.org,2002:bool",456(yaml_char_t *)(input_event.data.document_end.implicit ?457"true" : "false"), -1,4581, 0, YAML_PLAIN_SCALAR_STYLE))459goto event_error;460if (!yaml_emitter_emit(&emitter, &output_event))461goto emitter_error;462463break;464465case YAML_ALIAS_EVENT:466467/* Write 'type'. */468469if (!yaml_scalar_event_initialize(&output_event,470NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"type", -1,4711, 1, YAML_PLAIN_SCALAR_STYLE))472goto event_error;473if (!yaml_emitter_emit(&emitter, &output_event))474goto emitter_error;475476/* Write 'ALIAS'. */477478if (!yaml_scalar_event_initialize(&output_event,479NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"ALIAS", -1,4801, 1, YAML_PLAIN_SCALAR_STYLE))481goto event_error;482if (!yaml_emitter_emit(&emitter, &output_event))483goto emitter_error;484485/* Write 'anchor'. */486487if (!yaml_scalar_event_initialize(&output_event,488NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"anchor", -1,4891, 1, YAML_PLAIN_SCALAR_STYLE))490goto event_error;491if (!yaml_emitter_emit(&emitter, &output_event))492goto emitter_error;493494/* Write the alias anchor. */495496if (!yaml_scalar_event_initialize(&output_event,497NULL, (yaml_char_t *)"tag:yaml.org,2002:str",498input_event.data.alias.anchor, -1,4990, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE))500goto event_error;501if (!yaml_emitter_emit(&emitter, &output_event))502goto emitter_error;503504break;505506case YAML_SCALAR_EVENT:507508/* Write 'type'. */509510if (!yaml_scalar_event_initialize(&output_event,511NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"type", -1,5121, 1, YAML_PLAIN_SCALAR_STYLE))513goto event_error;514if (!yaml_emitter_emit(&emitter, &output_event))515goto emitter_error;516517/* Write 'SCALAR'. */518519if (!yaml_scalar_event_initialize(&output_event,520NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"SCALAR", -1,5211, 1, YAML_PLAIN_SCALAR_STYLE))522goto event_error;523if (!yaml_emitter_emit(&emitter, &output_event))524goto emitter_error;525526/* Display the scalar anchor. */527528if (input_event.data.scalar.anchor)529{530/* Write 'anchor'. */531532if (!yaml_scalar_event_initialize(&output_event,533NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"anchor", -1,5341, 1, YAML_PLAIN_SCALAR_STYLE))535goto event_error;536if (!yaml_emitter_emit(&emitter, &output_event))537goto emitter_error;538539/* Write the scalar anchor. */540541if (!yaml_scalar_event_initialize(&output_event,542NULL, (yaml_char_t *)"tag:yaml.org,2002:str",543input_event.data.scalar.anchor, -1,5440, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE))545goto event_error;546if (!yaml_emitter_emit(&emitter, &output_event))547goto emitter_error;548}549550/* Display the scalar tag. */551552if (input_event.data.scalar.tag)553{554/* Write 'tag'. */555556if (!yaml_scalar_event_initialize(&output_event,557NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"tag", -1,5581, 1, YAML_PLAIN_SCALAR_STYLE))559goto event_error;560if (!yaml_emitter_emit(&emitter, &output_event))561goto emitter_error;562563/* Write the scalar tag. */564565if (!yaml_scalar_event_initialize(&output_event,566NULL, (yaml_char_t *)"tag:yaml.org,2002:str",567input_event.data.scalar.tag, -1,5680, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE))569goto event_error;570if (!yaml_emitter_emit(&emitter, &output_event))571goto emitter_error;572}573574/* Display the scalar value. */575576/* Write 'value'. */577578if (!yaml_scalar_event_initialize(&output_event,579NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"value", -1,5801, 1, YAML_PLAIN_SCALAR_STYLE))581goto event_error;582if (!yaml_emitter_emit(&emitter, &output_event))583goto emitter_error;584585/* Write the scalar value. */586587if (!yaml_scalar_event_initialize(&output_event,588NULL, (yaml_char_t *)"tag:yaml.org,2002:str",589input_event.data.scalar.value,590input_event.data.scalar.length,5910, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE))592goto event_error;593if (!yaml_emitter_emit(&emitter, &output_event))594goto emitter_error;595596/* Display if the scalar tag is implicit. */597598/* Write 'implicit'. */599600if (!yaml_scalar_event_initialize(&output_event,601NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"implicit", -1,6021, 1, YAML_PLAIN_SCALAR_STYLE))603goto event_error;604if (!yaml_emitter_emit(&emitter, &output_event))605goto emitter_error;606607/* Write '{'. */608609if (!yaml_mapping_start_event_initialize(&output_event,610NULL, (yaml_char_t *)"tag:yaml.org,2002:map", 1,611YAML_FLOW_MAPPING_STYLE))612goto event_error;613if (!yaml_emitter_emit(&emitter, &output_event))614goto emitter_error;615616/* Write 'plain'. */617618if (!yaml_scalar_event_initialize(&output_event,619NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"plain", -1,6201, 1, YAML_PLAIN_SCALAR_STYLE))621goto event_error;622if (!yaml_emitter_emit(&emitter, &output_event))623goto emitter_error;624625/* Write if the scalar is implicit in the plain style. */626627if (!yaml_scalar_event_initialize(&output_event,628NULL, (yaml_char_t *)"tag:yaml.org,2002:bool",629(yaml_char_t * )(input_event.data.scalar.plain_implicit ?630"true" : "false"), -1,6311, 0, YAML_PLAIN_SCALAR_STYLE))632goto event_error;633if (!yaml_emitter_emit(&emitter, &output_event))634goto emitter_error;635636/* Write 'quoted'. */637638if (!yaml_scalar_event_initialize(&output_event,639NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"non-plain", -1,6401, 1, YAML_PLAIN_SCALAR_STYLE))641goto event_error;642if (!yaml_emitter_emit(&emitter, &output_event))643goto emitter_error;644645/* Write if the scalar is implicit in a non-plain style. */646647if (!yaml_scalar_event_initialize(&output_event,648NULL, (yaml_char_t *)"tag:yaml.org,2002:bool",649(yaml_char_t *)(input_event.data.scalar.quoted_implicit ?650"true" : "false"), -1,6511, 0, YAML_PLAIN_SCALAR_STYLE))652goto event_error;653if (!yaml_emitter_emit(&emitter, &output_event))654goto emitter_error;655656/* Write '}'. */657658if (!yaml_mapping_end_event_initialize(&output_event))659goto event_error;660if (!yaml_emitter_emit(&emitter, &output_event))661goto emitter_error;662663/* Display the style information. */664665if (input_event.data.scalar.style)666{667yaml_scalar_style_t style = input_event.data.scalar.style;668669/* Write 'style'. */670671if (!yaml_scalar_event_initialize(&output_event,672NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"style", -1,6731, 1, YAML_PLAIN_SCALAR_STYLE))674goto event_error;675if (!yaml_emitter_emit(&emitter, &output_event))676goto emitter_error;677678/* Write the scalar style. */679680if (!yaml_scalar_event_initialize(&output_event,681NULL, (yaml_char_t *)"tag:yaml.org,2002:str",682(yaml_char_t *)(style == YAML_PLAIN_SCALAR_STYLE ? "plain" :683style == YAML_SINGLE_QUOTED_SCALAR_STYLE ?684"single-quoted" :685style == YAML_DOUBLE_QUOTED_SCALAR_STYLE ?686"double-quoted" :687style == YAML_LITERAL_SCALAR_STYLE ? "literal" :688style == YAML_FOLDED_SCALAR_STYLE ? "folded" :689"unknown"), -1,6901, 1, YAML_PLAIN_SCALAR_STYLE))691goto event_error;692if (!yaml_emitter_emit(&emitter, &output_event))693goto emitter_error;694}695696break;697698case YAML_SEQUENCE_START_EVENT:699700/* Write 'type'. */701702if (!yaml_scalar_event_initialize(&output_event,703NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"type", -1,7041, 1, YAML_PLAIN_SCALAR_STYLE))705goto event_error;706if (!yaml_emitter_emit(&emitter, &output_event))707goto emitter_error;708709/* Write 'SEQUENCE-START'. */710711if (!yaml_scalar_event_initialize(&output_event,712NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"SEQUENCE-START", -1,7131, 1, YAML_PLAIN_SCALAR_STYLE))714goto event_error;715if (!yaml_emitter_emit(&emitter, &output_event))716goto emitter_error;717718/* Display the sequence anchor. */719720if (input_event.data.sequence_start.anchor)721{722/* Write 'anchor'. */723724if (!yaml_scalar_event_initialize(&output_event,725NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"anchor", -1,7261, 1, YAML_PLAIN_SCALAR_STYLE))727goto event_error;728if (!yaml_emitter_emit(&emitter, &output_event))729goto emitter_error;730731/* Write the sequence anchor. */732733if (!yaml_scalar_event_initialize(&output_event,734NULL, (yaml_char_t *)"tag:yaml.org,2002:str",735input_event.data.sequence_start.anchor, -1,7360, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE))737goto event_error;738if (!yaml_emitter_emit(&emitter, &output_event))739goto emitter_error;740}741742/* Display the sequence tag. */743744if (input_event.data.sequence_start.tag)745{746/* Write 'tag'. */747748if (!yaml_scalar_event_initialize(&output_event,749NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"tag", -1,7501, 1, YAML_PLAIN_SCALAR_STYLE))751goto event_error;752if (!yaml_emitter_emit(&emitter, &output_event))753goto emitter_error;754755/* Write the sequence tag. */756757if (!yaml_scalar_event_initialize(&output_event,758NULL, (yaml_char_t *)"tag:yaml.org,2002:str",759input_event.data.sequence_start.tag, -1,7600, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE))761goto event_error;762if (!yaml_emitter_emit(&emitter, &output_event))763goto emitter_error;764}765766/* Write 'implicit'. */767768if (!yaml_scalar_event_initialize(&output_event,769NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"implicit", -1,7701, 1, YAML_PLAIN_SCALAR_STYLE))771goto event_error;772if (!yaml_emitter_emit(&emitter, &output_event))773goto emitter_error;774775/* Write if the sequence tag is implicit. */776777if (!yaml_scalar_event_initialize(&output_event,778NULL, (yaml_char_t *)"tag:yaml.org,2002:bool",779(yaml_char_t *)(input_event.data.sequence_start.implicit ?780"true" : "false"), -1,7811, 0, YAML_PLAIN_SCALAR_STYLE))782goto event_error;783if (!yaml_emitter_emit(&emitter, &output_event))784goto emitter_error;785786/* Display the style information. */787788if (input_event.data.sequence_start.style)789{790yaml_sequence_style_t style791= input_event.data.sequence_start.style;792793/* Write 'style'. */794795if (!yaml_scalar_event_initialize(&output_event,796NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"style", -1,7971, 1, YAML_PLAIN_SCALAR_STYLE))798goto event_error;799if (!yaml_emitter_emit(&emitter, &output_event))800goto emitter_error;801802/* Write the scalar style. */803804if (!yaml_scalar_event_initialize(&output_event,805NULL, (yaml_char_t *)"tag:yaml.org,2002:str",806(yaml_char_t *)(style == YAML_BLOCK_SEQUENCE_STYLE ? "block" :807style == YAML_FLOW_SEQUENCE_STYLE ? "flow" :808"unknown"), -1,8091, 1, YAML_PLAIN_SCALAR_STYLE))810goto event_error;811if (!yaml_emitter_emit(&emitter, &output_event))812goto emitter_error;813}814815break;816817case YAML_SEQUENCE_END_EVENT:818819/* Write 'type'. */820821if (!yaml_scalar_event_initialize(&output_event,822NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"type", -1,8231, 1, YAML_PLAIN_SCALAR_STYLE))824goto event_error;825if (!yaml_emitter_emit(&emitter, &output_event))826goto emitter_error;827828/* Write 'SEQUENCE-END'. */829830if (!yaml_scalar_event_initialize(&output_event,831NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"SEQUENCE-END", -1,8321, 1, YAML_PLAIN_SCALAR_STYLE))833goto event_error;834if (!yaml_emitter_emit(&emitter, &output_event))835goto emitter_error;836837break;838839case YAML_MAPPING_START_EVENT:840841/* Write 'type'. */842843if (!yaml_scalar_event_initialize(&output_event,844NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"type", -1,8451, 1, YAML_PLAIN_SCALAR_STYLE))846goto event_error;847if (!yaml_emitter_emit(&emitter, &output_event))848goto emitter_error;849850/* Write 'MAPPING-START'. */851852if (!yaml_scalar_event_initialize(&output_event,853NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"MAPPING-START", -1,8541, 1, YAML_PLAIN_SCALAR_STYLE))855goto event_error;856if (!yaml_emitter_emit(&emitter, &output_event))857goto emitter_error;858859/* Display the mapping anchor. */860861if (input_event.data.mapping_start.anchor)862{863/* Write 'anchor'. */864865if (!yaml_scalar_event_initialize(&output_event,866NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"anchor", -1,8671, 1, YAML_PLAIN_SCALAR_STYLE))868goto event_error;869if (!yaml_emitter_emit(&emitter, &output_event))870goto emitter_error;871872/* Write the mapping anchor. */873874if (!yaml_scalar_event_initialize(&output_event,875NULL, (yaml_char_t *)"tag:yaml.org,2002:str",876input_event.data.mapping_start.anchor, -1,8770, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE))878goto event_error;879if (!yaml_emitter_emit(&emitter, &output_event))880goto emitter_error;881}882883/* Display the mapping tag. */884885if (input_event.data.mapping_start.tag)886{887/* Write 'tag'. */888889if (!yaml_scalar_event_initialize(&output_event,890NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"tag", -1,8911, 1, YAML_PLAIN_SCALAR_STYLE))892goto event_error;893if (!yaml_emitter_emit(&emitter, &output_event))894goto emitter_error;895896/* Write the mapping tag. */897898if (!yaml_scalar_event_initialize(&output_event,899NULL, (yaml_char_t *)"tag:yaml.org,2002:str",900input_event.data.mapping_start.tag, -1,9010, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE))902goto event_error;903if (!yaml_emitter_emit(&emitter, &output_event))904goto emitter_error;905}906907/* Write 'implicit'. */908909if (!yaml_scalar_event_initialize(&output_event,910NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"implicit", -1,9111, 1, YAML_PLAIN_SCALAR_STYLE))912goto event_error;913if (!yaml_emitter_emit(&emitter, &output_event))914goto emitter_error;915916/* Write if the mapping tag is implicit. */917918if (!yaml_scalar_event_initialize(&output_event,919NULL, (yaml_char_t *)"tag:yaml.org,2002:bool",920(yaml_char_t *)(input_event.data.mapping_start.implicit ?921"true" : "false"), -1,9221, 0, YAML_PLAIN_SCALAR_STYLE))923goto event_error;924if (!yaml_emitter_emit(&emitter, &output_event))925goto emitter_error;926927/* Display the style information. */928929if (input_event.data.mapping_start.style)930{931yaml_mapping_style_t style932= input_event.data.mapping_start.style;933934/* Write 'style'. */935936if (!yaml_scalar_event_initialize(&output_event,937NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"style", -1,9381, 1, YAML_PLAIN_SCALAR_STYLE))939goto event_error;940if (!yaml_emitter_emit(&emitter, &output_event))941goto emitter_error;942943/* Write the scalar style. */944945if (!yaml_scalar_event_initialize(&output_event,946NULL, (yaml_char_t *)"tag:yaml.org,2002:str",947(yaml_char_t *)(style == YAML_BLOCK_MAPPING_STYLE ? "block" :948style == YAML_FLOW_MAPPING_STYLE ? "flow" :949"unknown"), -1,9501, 1, YAML_PLAIN_SCALAR_STYLE))951goto event_error;952if (!yaml_emitter_emit(&emitter, &output_event))953goto emitter_error;954}955956break;957958case YAML_MAPPING_END_EVENT:959960/* Write 'type'. */961962if (!yaml_scalar_event_initialize(&output_event,963NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"type", -1,9641, 1, YAML_PLAIN_SCALAR_STYLE))965goto event_error;966if (!yaml_emitter_emit(&emitter, &output_event))967goto emitter_error;968969/* Write 'MAPPING-END'. */970971if (!yaml_scalar_event_initialize(&output_event,972NULL, (yaml_char_t *)"tag:yaml.org,2002:str", (yaml_char_t *)"MAPPING-END", -1,9731, 1, YAML_PLAIN_SCALAR_STYLE))974goto event_error;975if (!yaml_emitter_emit(&emitter, &output_event))976goto emitter_error;977978break;979980default:981/* It couldn't really happen. */982break;983}984985/* Delete the event object. */986987yaml_event_delete(&input_event);988989/* Create and emit a MAPPING-END event. */990991if (!yaml_mapping_end_event_initialize(&output_event))992goto event_error;993if (!yaml_emitter_emit(&emitter, &output_event))994goto emitter_error;995}996997/* Create and emit the SEQUENCE-END event. */998999if (!yaml_sequence_end_event_initialize(&output_event))1000goto event_error;1001if (!yaml_emitter_emit(&emitter, &output_event))1002goto emitter_error;10031004/* Create and emit the DOCUMENT-END event. */10051006if (!yaml_document_end_event_initialize(&output_event, 0))1007goto event_error;1008if (!yaml_emitter_emit(&emitter, &output_event))1009goto emitter_error;10101011/* Create and emit the STREAM-END event. */10121013if (!yaml_stream_end_event_initialize(&output_event))1014goto event_error;1015if (!yaml_emitter_emit(&emitter, &output_event))1016goto emitter_error;10171018yaml_parser_delete(&parser);1019yaml_emitter_delete(&emitter);10201021return 0;10221023parser_error:10241025/* Display a parser error message. */10261027switch (parser.error)1028{1029case YAML_MEMORY_ERROR:1030fprintf(stderr, "Memory error: Not enough memory for parsing\n");1031break;10321033case YAML_READER_ERROR:1034if (parser.problem_value != -1) {1035fprintf(stderr, "Reader error: %s: #%X at %ld\n", parser.problem,1036parser.problem_value, (long)parser.problem_offset);1037}1038else {1039fprintf(stderr, "Reader error: %s at %ld\n", parser.problem,1040(long)parser.problem_offset);1041}1042break;10431044case YAML_SCANNER_ERROR:1045if (parser.context) {1046fprintf(stderr, "Scanner error: %s at line %d, column %d\n"1047"%s at line %d, column %d\n", parser.context,1048(int)parser.context_mark.line+1, (int)parser.context_mark.column+1,1049parser.problem, (int)parser.problem_mark.line+1,1050(int)parser.problem_mark.column+1);1051}1052else {1053fprintf(stderr, "Scanner error: %s at line %d, column %d\n",1054parser.problem, (int)parser.problem_mark.line+1,1055(int)parser.problem_mark.column+1);1056}1057break;10581059case YAML_PARSER_ERROR:1060if (parser.context) {1061fprintf(stderr, "Parser error: %s at line %d, column %d\n"1062"%s at line %d, column %d\n", parser.context,1063(int)parser.context_mark.line+1, (int)parser.context_mark.column+1,1064parser.problem, (int)parser.problem_mark.line+1,1065(int)parser.problem_mark.column+1);1066}1067else {1068fprintf(stderr, "Parser error: %s at line %d, column %d\n",1069parser.problem, (int)parser.problem_mark.line+1,1070(int)parser.problem_mark.column+1);1071}1072break;10731074default:1075/* Couldn't happen. */1076fprintf(stderr, "Internal error\n");1077break;1078}10791080yaml_event_delete(&input_event);1081yaml_parser_delete(&parser);1082yaml_emitter_delete(&emitter);10831084return 1;10851086emitter_error:10871088/* Display an emitter error message. */10891090switch (emitter.error)1091{1092case YAML_MEMORY_ERROR:1093fprintf(stderr, "Memory error: Not enough memory for emitting\n");1094break;10951096case YAML_WRITER_ERROR:1097fprintf(stderr, "Writer error: %s\n", emitter.problem);1098break;10991100case YAML_EMITTER_ERROR:1101fprintf(stderr, "Emitter error: %s\n", emitter.problem);1102break;11031104default:1105/* Couldn't happen. */1106fprintf(stderr, "Internal error\n");1107break;1108}11091110yaml_event_delete(&input_event);1111yaml_parser_delete(&parser);1112yaml_emitter_delete(&emitter);11131114return 1;11151116event_error:11171118fprintf(stderr, "Memory error: Not enough memory for creating an event\n");11191120yaml_event_delete(&input_event);1121yaml_parser_delete(&parser);1122yaml_emitter_delete(&emitter);11231124return 1;1125}1126112711281129