1247738Sbapt 2247738Sbapt#include <yaml.h> 3247738Sbapt 4247738Sbapt#include <stdlib.h> 5247738Sbapt#include <stdio.h> 6247738Sbapt 7247738Sbaptint 8247738Sbaptmain(int argc, char *argv[]) 9247738Sbapt{ 10247738Sbapt int help = 0; 11247738Sbapt int canonical = 0; 12247738Sbapt int unicode = 0; 13247738Sbapt int k; 14247738Sbapt int done = 0; 15247738Sbapt 16247738Sbapt yaml_parser_t parser; 17247738Sbapt yaml_emitter_t emitter; 18247738Sbapt yaml_event_t input_event; 19247738Sbapt yaml_event_t output_event; 20247738Sbapt 21247738Sbapt /* Clear the objects. */ 22247738Sbapt 23247738Sbapt memset(&parser, 0, sizeof(parser)); 24247738Sbapt memset(&emitter, 0, sizeof(emitter)); 25247738Sbapt memset(&input_event, 0, sizeof(input_event)); 26247738Sbapt memset(&output_event, 0, sizeof(output_event)); 27247738Sbapt 28247738Sbapt /* Analyze command line options. */ 29247738Sbapt 30247738Sbapt for (k = 1; k < argc; k ++) 31247738Sbapt { 32247738Sbapt if (strcmp(argv[k], "-h") == 0 33247738Sbapt || strcmp(argv[k], "--help") == 0) { 34247738Sbapt help = 1; 35247738Sbapt } 36247738Sbapt 37247738Sbapt else if (strcmp(argv[k], "-c") == 0 38247738Sbapt || strcmp(argv[k], "--canonical") == 0) { 39247738Sbapt canonical = 1; 40247738Sbapt } 41247738Sbapt 42247738Sbapt else if (strcmp(argv[k], "-u") == 0 43247738Sbapt || strcmp(argv[k], "--unicode") == 0) { 44247738Sbapt unicode = 1; 45247738Sbapt } 46247738Sbapt 47247738Sbapt else { 48247738Sbapt fprintf(stderr, "Unrecognized option: %s\n" 49247738Sbapt "Try `%s --help` for more information.\n", 50247738Sbapt argv[k], argv[0]); 51247738Sbapt return 1; 52247738Sbapt } 53247738Sbapt } 54247738Sbapt 55247738Sbapt /* Display the help string. */ 56247738Sbapt 57247738Sbapt if (help) 58247738Sbapt { 59247738Sbapt printf("%s <input\n" 60247738Sbapt "or\n%s -h | --help\nDeconstruct a YAML stream\n\nOptions:\n" 61247738Sbapt "-h, --help\t\tdisplay this help and exit\n" 62247738Sbapt "-c, --canonical\t\toutput in the canonical YAML format\n" 63247738Sbapt "-u, --unicode\t\toutput unescaped non-ASCII characters\n", 64247738Sbapt argv[0], argv[0]); 65247738Sbapt return 0; 66247738Sbapt } 67247738Sbapt 68247738Sbapt /* Initialize the parser and emitter objects. */ 69247738Sbapt 70247738Sbapt if (!yaml_parser_initialize(&parser)) { 71247738Sbapt fprintf(stderr, "Could not initialize the parser object\n"); 72247738Sbapt return 1; 73247738Sbapt } 74247738Sbapt 75247738Sbapt if (!yaml_emitter_initialize(&emitter)) { 76247738Sbapt yaml_parser_delete(&parser); 77247738Sbapt fprintf(stderr, "Could not inialize the emitter object\n"); 78247738Sbapt return 1; 79247738Sbapt } 80247738Sbapt 81247738Sbapt /* Set the parser parameters. */ 82247738Sbapt 83247738Sbapt yaml_parser_set_input_file(&parser, stdin); 84247738Sbapt 85247738Sbapt /* Set the emitter parameters. */ 86247738Sbapt 87247738Sbapt yaml_emitter_set_output_file(&emitter, stdout); 88247738Sbapt 89247738Sbapt yaml_emitter_set_canonical(&emitter, canonical); 90247738Sbapt yaml_emitter_set_unicode(&emitter, unicode); 91247738Sbapt 92247738Sbapt /* Create and emit the STREAM-START event. */ 93247738Sbapt 94247738Sbapt if (!yaml_stream_start_event_initialize(&output_event, YAML_UTF8_ENCODING)) 95247738Sbapt goto event_error; 96247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 97247738Sbapt goto emitter_error; 98247738Sbapt 99247738Sbapt /* Create and emit the DOCUMENT-START event. */ 100247738Sbapt 101247738Sbapt if (!yaml_document_start_event_initialize(&output_event, 102247738Sbapt NULL, NULL, NULL, 0)) 103247738Sbapt goto event_error; 104247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 105247738Sbapt goto emitter_error; 106247738Sbapt 107247738Sbapt /* Create and emit the SEQUENCE-START event. */ 108247738Sbapt 109247738Sbapt if (!yaml_sequence_start_event_initialize(&output_event, 110247738Sbapt NULL, "tag:yaml.org,2002:seq", 1, 111247738Sbapt YAML_BLOCK_SEQUENCE_STYLE)) 112247738Sbapt goto event_error; 113247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 114247738Sbapt goto emitter_error; 115247738Sbapt 116247738Sbapt /* Loop through the input events. */ 117247738Sbapt 118247738Sbapt while (!done) 119247738Sbapt { 120247738Sbapt /* Get the next event. */ 121247738Sbapt 122247738Sbapt if (!yaml_parser_parse(&parser, &input_event)) 123247738Sbapt goto parser_error; 124247738Sbapt 125247738Sbapt /* Check if this is the stream end. */ 126247738Sbapt 127247738Sbapt if (input_event.type == YAML_STREAM_END_EVENT) { 128247738Sbapt done = 1; 129247738Sbapt } 130247738Sbapt 131247738Sbapt /* Create and emit a MAPPING-START event. */ 132247738Sbapt 133247738Sbapt if (!yaml_mapping_start_event_initialize(&output_event, 134247738Sbapt NULL, "tag:yaml.org,2002:map", 1, 135247738Sbapt YAML_BLOCK_MAPPING_STYLE)) 136247738Sbapt goto event_error; 137247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 138247738Sbapt goto emitter_error; 139247738Sbapt 140247738Sbapt /* Analyze the event. */ 141247738Sbapt 142247738Sbapt switch (input_event.type) 143247738Sbapt { 144247738Sbapt case YAML_STREAM_START_EVENT: 145247738Sbapt 146247738Sbapt /* Write 'type'. */ 147247738Sbapt 148247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 149247738Sbapt NULL, "tag:yaml.org,2002:str", "type", -1, 150247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 151247738Sbapt goto event_error; 152247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 153247738Sbapt goto emitter_error; 154247738Sbapt 155247738Sbapt /* Write 'STREAM-START'. */ 156247738Sbapt 157247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 158247738Sbapt NULL, "tag:yaml.org,2002:str", "STREAM-START", -1, 159247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 160247738Sbapt goto event_error; 161247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 162247738Sbapt goto emitter_error; 163247738Sbapt 164247738Sbapt /* Display encoding information. */ 165247738Sbapt 166247738Sbapt if (input_event.data.stream_start.encoding) 167247738Sbapt { 168247738Sbapt yaml_encoding_t encoding 169247738Sbapt = input_event.data.stream_start.encoding; 170247738Sbapt 171247738Sbapt /* Write 'encoding'. */ 172247738Sbapt 173247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 174247738Sbapt NULL, "tag:yaml.org,2002:str", "encoding", -1, 175247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 176247738Sbapt goto event_error; 177247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 178247738Sbapt goto emitter_error; 179247738Sbapt 180247738Sbapt /* Write the stream encoding. */ 181247738Sbapt 182247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 183247738Sbapt NULL, "tag:yaml.org,2002:str", 184247738Sbapt (encoding == YAML_UTF8_ENCODING ? "utf-8" : 185247738Sbapt encoding == YAML_UTF16LE_ENCODING ? "utf-16-le" : 186247738Sbapt encoding == YAML_UTF16BE_ENCODING ? "utf-16-be" : 187247738Sbapt "unknown"), -1, 188247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 189247738Sbapt goto event_error; 190247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 191247738Sbapt goto emitter_error; 192247738Sbapt } 193247738Sbapt 194247738Sbapt break; 195247738Sbapt 196247738Sbapt case YAML_STREAM_END_EVENT: 197247738Sbapt 198247738Sbapt /* Write 'type'. */ 199247738Sbapt 200247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 201247738Sbapt NULL, "tag:yaml.org,2002:str", "type", -1, 202247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 203247738Sbapt goto event_error; 204247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 205247738Sbapt goto emitter_error; 206247738Sbapt 207247738Sbapt /* Write 'STREAM-END'. */ 208247738Sbapt 209247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 210247738Sbapt NULL, "tag:yaml.org,2002:str", "STREAM-END", -1, 211247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 212247738Sbapt goto event_error; 213247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 214247738Sbapt goto emitter_error; 215247738Sbapt 216247738Sbapt break; 217247738Sbapt 218247738Sbapt case YAML_DOCUMENT_START_EVENT: 219247738Sbapt 220247738Sbapt /* Write 'type'. */ 221247738Sbapt 222247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 223247738Sbapt NULL, "tag:yaml.org,2002:str", "type", -1, 224247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 225247738Sbapt goto event_error; 226247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 227247738Sbapt goto emitter_error; 228247738Sbapt 229247738Sbapt /* Write 'DOCUMENT-START'. */ 230247738Sbapt 231247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 232247738Sbapt NULL, "tag:yaml.org,2002:str", "DOCUMENT-START", -1, 233247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 234247738Sbapt goto event_error; 235247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 236247738Sbapt goto emitter_error; 237247738Sbapt 238247738Sbapt /* Display the document version numbers. */ 239247738Sbapt 240247738Sbapt if (input_event.data.document_start.version_directive) 241247738Sbapt { 242247738Sbapt yaml_version_directive_t *version 243247738Sbapt = input_event.data.document_start.version_directive; 244247738Sbapt char number[64]; 245247738Sbapt 246247738Sbapt /* Write 'version'. */ 247247738Sbapt 248247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 249247738Sbapt NULL, "tag:yaml.org,2002:str", "version", -1, 250247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 251247738Sbapt goto event_error; 252247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 253247738Sbapt goto emitter_error; 254247738Sbapt 255247738Sbapt /* Write '{'. */ 256247738Sbapt 257247738Sbapt if (!yaml_mapping_start_event_initialize(&output_event, 258247738Sbapt NULL, "tag:yaml.org,2002:map", 1, 259247738Sbapt YAML_FLOW_MAPPING_STYLE)) 260247738Sbapt goto event_error; 261247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 262247738Sbapt goto emitter_error; 263247738Sbapt 264247738Sbapt /* Write 'major'. */ 265247738Sbapt 266247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 267247738Sbapt NULL, "tag:yaml.org,2002:str", "major", -1, 268247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 269247738Sbapt goto event_error; 270247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 271247738Sbapt goto emitter_error; 272247738Sbapt 273247738Sbapt /* Write a number. */ 274247738Sbapt 275247738Sbapt sprintf(number, "%d", version->major); 276247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 277247738Sbapt NULL, "tag:yaml.org,2002:int", number, -1, 278247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 279247738Sbapt goto event_error; 280247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 281247738Sbapt goto emitter_error; 282247738Sbapt 283247738Sbapt /* Write 'minor'. */ 284247738Sbapt 285247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 286247738Sbapt NULL, "tag:yaml.org,2002:str", "minor", -1, 287247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 288247738Sbapt goto event_error; 289247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 290247738Sbapt goto emitter_error; 291247738Sbapt 292247738Sbapt /* Write a number. */ 293247738Sbapt 294247738Sbapt sprintf(number, "%d", version->minor); 295247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 296247738Sbapt NULL, "tag:yaml.org,2002:int", number, -1, 297247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 298247738Sbapt goto event_error; 299247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 300247738Sbapt goto emitter_error; 301247738Sbapt 302247738Sbapt /* Write '}'. */ 303247738Sbapt 304247738Sbapt if (!yaml_mapping_end_event_initialize(&output_event)) 305247738Sbapt goto event_error; 306247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 307247738Sbapt goto emitter_error; 308247738Sbapt } 309247738Sbapt 310247738Sbapt /* Display the document tag directives. */ 311247738Sbapt 312247738Sbapt if (input_event.data.document_start.tag_directives.start 313247738Sbapt != input_event.data.document_start.tag_directives.end) 314247738Sbapt { 315247738Sbapt yaml_tag_directive_t *tag; 316247738Sbapt 317247738Sbapt /* Write 'tags'. */ 318247738Sbapt 319247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 320247738Sbapt NULL, "tag:yaml.org,2002:str", "tags", -1, 321247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 322247738Sbapt goto event_error; 323247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 324247738Sbapt goto emitter_error; 325247738Sbapt 326247738Sbapt /* Start a block sequence. */ 327247738Sbapt 328247738Sbapt if (!yaml_sequence_start_event_initialize(&output_event, 329247738Sbapt NULL, "tag:yaml.org,2002:seq", 1, 330247738Sbapt YAML_BLOCK_SEQUENCE_STYLE)) 331247738Sbapt goto event_error; 332247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 333247738Sbapt goto emitter_error; 334247738Sbapt 335247738Sbapt for (tag = input_event.data.document_start.tag_directives.start; 336247738Sbapt tag != input_event.data.document_start.tag_directives.end; 337247738Sbapt tag ++) 338247738Sbapt { 339247738Sbapt /* Write '{'. */ 340247738Sbapt 341247738Sbapt if (!yaml_mapping_start_event_initialize(&output_event, 342247738Sbapt NULL, "tag:yaml.org,2002:map", 1, 343247738Sbapt YAML_FLOW_MAPPING_STYLE)) 344247738Sbapt goto event_error; 345247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 346247738Sbapt goto emitter_error; 347247738Sbapt 348247738Sbapt /* Write 'handle'. */ 349247738Sbapt 350247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 351247738Sbapt NULL, "tag:yaml.org,2002:str", "handle", -1, 352247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 353247738Sbapt goto event_error; 354247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 355247738Sbapt goto emitter_error; 356247738Sbapt 357247738Sbapt /* Write the tag directive handle. */ 358247738Sbapt 359247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 360247738Sbapt NULL, "tag:yaml.org,2002:str", 361247738Sbapt tag->handle, -1, 362247738Sbapt 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) 363247738Sbapt goto event_error; 364247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 365247738Sbapt goto emitter_error; 366247738Sbapt 367247738Sbapt /* Write 'prefix'. */ 368247738Sbapt 369247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 370247738Sbapt NULL, "tag:yaml.org,2002:str", "prefix", -1, 371247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 372247738Sbapt goto event_error; 373247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 374247738Sbapt goto emitter_error; 375247738Sbapt 376247738Sbapt /* Write the tag directive prefix. */ 377247738Sbapt 378247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 379247738Sbapt NULL, "tag:yaml.org,2002:str", 380247738Sbapt tag->prefix, -1, 381247738Sbapt 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) 382247738Sbapt goto event_error; 383247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 384247738Sbapt goto emitter_error; 385247738Sbapt 386247738Sbapt /* Write '}'. */ 387247738Sbapt 388247738Sbapt if (!yaml_mapping_end_event_initialize(&output_event)) 389247738Sbapt goto event_error; 390247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 391247738Sbapt goto emitter_error; 392247738Sbapt } 393247738Sbapt 394247738Sbapt /* End a block sequence. */ 395247738Sbapt 396247738Sbapt if (!yaml_sequence_end_event_initialize(&output_event)) 397247738Sbapt goto event_error; 398247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 399247738Sbapt goto emitter_error; 400247738Sbapt } 401247738Sbapt 402247738Sbapt /* Write 'implicit'. */ 403247738Sbapt 404247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 405247738Sbapt NULL, "tag:yaml.org,2002:str", "implicit", -1, 406247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 407247738Sbapt goto event_error; 408247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 409247738Sbapt goto emitter_error; 410247738Sbapt 411247738Sbapt /* Write if the document is implicit. */ 412247738Sbapt 413247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 414247738Sbapt NULL, "tag:yaml.org,2002:bool", 415247738Sbapt (input_event.data.document_start.implicit ? 416247738Sbapt "true" : "false"), -1, 417247738Sbapt 1, 0, YAML_PLAIN_SCALAR_STYLE)) 418247738Sbapt goto event_error; 419247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 420247738Sbapt goto emitter_error; 421247738Sbapt 422247738Sbapt break; 423247738Sbapt 424247738Sbapt case YAML_DOCUMENT_END_EVENT: 425247738Sbapt 426247738Sbapt /* Write 'type'. */ 427247738Sbapt 428247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 429247738Sbapt NULL, "tag:yaml.org,2002:str", "type", -1, 430247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 431247738Sbapt goto event_error; 432247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 433247738Sbapt goto emitter_error; 434247738Sbapt 435247738Sbapt /* Write 'DOCUMENT-END'. */ 436247738Sbapt 437247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 438247738Sbapt NULL, "tag:yaml.org,2002:str", "DOCUMENT-END", -1, 439247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 440247738Sbapt goto event_error; 441247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 442247738Sbapt goto emitter_error; 443247738Sbapt 444247738Sbapt /* Write 'implicit'. */ 445247738Sbapt 446247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 447247738Sbapt NULL, "tag:yaml.org,2002:str", "implicit", -1, 448247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 449247738Sbapt goto event_error; 450247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 451247738Sbapt goto emitter_error; 452247738Sbapt 453247738Sbapt /* Write if the document is implicit. */ 454247738Sbapt 455247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 456247738Sbapt NULL, "tag:yaml.org,2002:bool", 457247738Sbapt (input_event.data.document_end.implicit ? 458247738Sbapt "true" : "false"), -1, 459247738Sbapt 1, 0, YAML_PLAIN_SCALAR_STYLE)) 460247738Sbapt goto event_error; 461247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 462247738Sbapt goto emitter_error; 463247738Sbapt 464247738Sbapt break; 465247738Sbapt 466247738Sbapt case YAML_ALIAS_EVENT: 467247738Sbapt 468247738Sbapt /* Write 'type'. */ 469247738Sbapt 470247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 471247738Sbapt NULL, "tag:yaml.org,2002:str", "type", -1, 472247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 473247738Sbapt goto event_error; 474247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 475247738Sbapt goto emitter_error; 476247738Sbapt 477247738Sbapt /* Write 'ALIAS'. */ 478247738Sbapt 479247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 480247738Sbapt NULL, "tag:yaml.org,2002:str", "ALIAS", -1, 481247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 482247738Sbapt goto event_error; 483247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 484247738Sbapt goto emitter_error; 485247738Sbapt 486247738Sbapt /* Write 'anchor'. */ 487247738Sbapt 488247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 489247738Sbapt NULL, "tag:yaml.org,2002:str", "anchor", -1, 490247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 491247738Sbapt goto event_error; 492247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 493247738Sbapt goto emitter_error; 494247738Sbapt 495247738Sbapt /* Write the alias anchor. */ 496247738Sbapt 497247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 498247738Sbapt NULL, "tag:yaml.org,2002:str", 499247738Sbapt input_event.data.alias.anchor, -1, 500247738Sbapt 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) 501247738Sbapt goto event_error; 502247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 503247738Sbapt goto emitter_error; 504247738Sbapt 505247738Sbapt break; 506247738Sbapt 507247738Sbapt case YAML_SCALAR_EVENT: 508247738Sbapt 509247738Sbapt /* Write 'type'. */ 510247738Sbapt 511247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 512247738Sbapt NULL, "tag:yaml.org,2002:str", "type", -1, 513247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 514247738Sbapt goto event_error; 515247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 516247738Sbapt goto emitter_error; 517247738Sbapt 518247738Sbapt /* Write 'SCALAR'. */ 519247738Sbapt 520247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 521247738Sbapt NULL, "tag:yaml.org,2002:str", "SCALAR", -1, 522247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 523247738Sbapt goto event_error; 524247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 525247738Sbapt goto emitter_error; 526247738Sbapt 527247738Sbapt /* Display the scalar anchor. */ 528247738Sbapt 529247738Sbapt if (input_event.data.scalar.anchor) 530247738Sbapt { 531247738Sbapt /* Write 'anchor'. */ 532247738Sbapt 533247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 534247738Sbapt NULL, "tag:yaml.org,2002:str", "anchor", -1, 535247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 536247738Sbapt goto event_error; 537247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 538247738Sbapt goto emitter_error; 539247738Sbapt 540247738Sbapt /* Write the scalar anchor. */ 541247738Sbapt 542247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 543247738Sbapt NULL, "tag:yaml.org,2002:str", 544247738Sbapt input_event.data.scalar.anchor, -1, 545247738Sbapt 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) 546247738Sbapt goto event_error; 547247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 548247738Sbapt goto emitter_error; 549247738Sbapt } 550247738Sbapt 551247738Sbapt /* Display the scalar tag. */ 552247738Sbapt 553247738Sbapt if (input_event.data.scalar.tag) 554247738Sbapt { 555247738Sbapt /* Write 'tag'. */ 556247738Sbapt 557247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 558247738Sbapt NULL, "tag:yaml.org,2002:str", "tag", -1, 559247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 560247738Sbapt goto event_error; 561247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 562247738Sbapt goto emitter_error; 563247738Sbapt 564247738Sbapt /* Write the scalar tag. */ 565247738Sbapt 566247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 567247738Sbapt NULL, "tag:yaml.org,2002:str", 568247738Sbapt input_event.data.scalar.tag, -1, 569247738Sbapt 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) 570247738Sbapt goto event_error; 571247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 572247738Sbapt goto emitter_error; 573247738Sbapt } 574247738Sbapt 575247738Sbapt /* Display the scalar value. */ 576247738Sbapt 577247738Sbapt /* Write 'value'. */ 578247738Sbapt 579247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 580247738Sbapt NULL, "tag:yaml.org,2002:str", "value", -1, 581247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 582247738Sbapt goto event_error; 583247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 584247738Sbapt goto emitter_error; 585247738Sbapt 586247738Sbapt /* Write the scalar value. */ 587247738Sbapt 588247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 589247738Sbapt NULL, "tag:yaml.org,2002:str", 590247738Sbapt input_event.data.scalar.value, 591247738Sbapt input_event.data.scalar.length, 592247738Sbapt 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) 593247738Sbapt goto event_error; 594247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 595247738Sbapt goto emitter_error; 596247738Sbapt 597247738Sbapt /* Display if the scalar tag is implicit. */ 598247738Sbapt 599247738Sbapt /* Write 'implicit'. */ 600247738Sbapt 601247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 602247738Sbapt NULL, "tag:yaml.org,2002:str", "implicit", -1, 603247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 604247738Sbapt goto event_error; 605247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 606247738Sbapt goto emitter_error; 607247738Sbapt 608247738Sbapt /* Write '{'. */ 609247738Sbapt 610247738Sbapt if (!yaml_mapping_start_event_initialize(&output_event, 611247738Sbapt NULL, "tag:yaml.org,2002:map", 1, 612247738Sbapt YAML_FLOW_MAPPING_STYLE)) 613247738Sbapt goto event_error; 614247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 615247738Sbapt goto emitter_error; 616247738Sbapt 617247738Sbapt /* Write 'plain'. */ 618247738Sbapt 619247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 620247738Sbapt NULL, "tag:yaml.org,2002:str", "plain", -1, 621247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 622247738Sbapt goto event_error; 623247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 624247738Sbapt goto emitter_error; 625247738Sbapt 626247738Sbapt /* Write if the scalar is implicit in the plain style. */ 627247738Sbapt 628247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 629247738Sbapt NULL, "tag:yaml.org,2002:bool", 630247738Sbapt (input_event.data.scalar.plain_implicit ? 631247738Sbapt "true" : "false"), -1, 632247738Sbapt 1, 0, YAML_PLAIN_SCALAR_STYLE)) 633247738Sbapt goto event_error; 634247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 635247738Sbapt goto emitter_error; 636247738Sbapt 637247738Sbapt /* Write 'quoted'. */ 638247738Sbapt 639247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 640247738Sbapt NULL, "tag:yaml.org,2002:str", "non-plain", -1, 641247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 642247738Sbapt goto event_error; 643247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 644247738Sbapt goto emitter_error; 645247738Sbapt 646247738Sbapt /* Write if the scalar is implicit in a non-plain style. */ 647247738Sbapt 648247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 649247738Sbapt NULL, "tag:yaml.org,2002:bool", 650247738Sbapt (input_event.data.scalar.quoted_implicit ? 651247738Sbapt "true" : "false"), -1, 652247738Sbapt 1, 0, YAML_PLAIN_SCALAR_STYLE)) 653247738Sbapt goto event_error; 654247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 655247738Sbapt goto emitter_error; 656247738Sbapt 657247738Sbapt /* Write '}'. */ 658247738Sbapt 659247738Sbapt if (!yaml_mapping_end_event_initialize(&output_event)) 660247738Sbapt goto event_error; 661247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 662247738Sbapt goto emitter_error; 663247738Sbapt 664247738Sbapt /* Display the style information. */ 665247738Sbapt 666247738Sbapt if (input_event.data.scalar.style) 667247738Sbapt { 668247738Sbapt yaml_scalar_style_t style = input_event.data.scalar.style; 669247738Sbapt 670247738Sbapt /* Write 'style'. */ 671247738Sbapt 672247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 673247738Sbapt NULL, "tag:yaml.org,2002:str", "style", -1, 674247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 675247738Sbapt goto event_error; 676247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 677247738Sbapt goto emitter_error; 678247738Sbapt 679247738Sbapt /* Write the scalar style. */ 680247738Sbapt 681247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 682247738Sbapt NULL, "tag:yaml.org,2002:str", 683247738Sbapt (style == YAML_PLAIN_SCALAR_STYLE ? "plain" : 684247738Sbapt style == YAML_SINGLE_QUOTED_SCALAR_STYLE ? 685247738Sbapt "single-quoted" : 686247738Sbapt style == YAML_DOUBLE_QUOTED_SCALAR_STYLE ? 687247738Sbapt "double-quoted" : 688247738Sbapt style == YAML_LITERAL_SCALAR_STYLE ? "literal" : 689247738Sbapt style == YAML_FOLDED_SCALAR_STYLE ? "folded" : 690247738Sbapt "unknown"), -1, 691247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 692247738Sbapt goto event_error; 693247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 694247738Sbapt goto emitter_error; 695247738Sbapt } 696247738Sbapt 697247738Sbapt break; 698247738Sbapt 699247738Sbapt case YAML_SEQUENCE_START_EVENT: 700247738Sbapt 701247738Sbapt /* Write 'type'. */ 702247738Sbapt 703247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 704247738Sbapt NULL, "tag:yaml.org,2002:str", "type", -1, 705247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 706247738Sbapt goto event_error; 707247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 708247738Sbapt goto emitter_error; 709247738Sbapt 710247738Sbapt /* Write 'SEQUENCE-START'. */ 711247738Sbapt 712247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 713247738Sbapt NULL, "tag:yaml.org,2002:str", "SEQUENCE-START", -1, 714247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 715247738Sbapt goto event_error; 716247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 717247738Sbapt goto emitter_error; 718247738Sbapt 719247738Sbapt /* Display the sequence anchor. */ 720247738Sbapt 721247738Sbapt if (input_event.data.sequence_start.anchor) 722247738Sbapt { 723247738Sbapt /* Write 'anchor'. */ 724247738Sbapt 725247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 726247738Sbapt NULL, "tag:yaml.org,2002:str", "anchor", -1, 727247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 728247738Sbapt goto event_error; 729247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 730247738Sbapt goto emitter_error; 731247738Sbapt 732247738Sbapt /* Write the sequence anchor. */ 733247738Sbapt 734247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 735247738Sbapt NULL, "tag:yaml.org,2002:str", 736247738Sbapt input_event.data.sequence_start.anchor, -1, 737247738Sbapt 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) 738247738Sbapt goto event_error; 739247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 740247738Sbapt goto emitter_error; 741247738Sbapt } 742247738Sbapt 743247738Sbapt /* Display the sequence tag. */ 744247738Sbapt 745247738Sbapt if (input_event.data.sequence_start.tag) 746247738Sbapt { 747247738Sbapt /* Write 'tag'. */ 748247738Sbapt 749247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 750247738Sbapt NULL, "tag:yaml.org,2002:str", "tag", -1, 751247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 752247738Sbapt goto event_error; 753247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 754247738Sbapt goto emitter_error; 755247738Sbapt 756247738Sbapt /* Write the sequence tag. */ 757247738Sbapt 758247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 759247738Sbapt NULL, "tag:yaml.org,2002:str", 760247738Sbapt input_event.data.sequence_start.tag, -1, 761247738Sbapt 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) 762247738Sbapt goto event_error; 763247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 764247738Sbapt goto emitter_error; 765247738Sbapt } 766247738Sbapt 767247738Sbapt /* Write 'implicit'. */ 768247738Sbapt 769247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 770247738Sbapt NULL, "tag:yaml.org,2002:str", "implicit", -1, 771247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 772247738Sbapt goto event_error; 773247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 774247738Sbapt goto emitter_error; 775247738Sbapt 776247738Sbapt /* Write if the sequence tag is implicit. */ 777247738Sbapt 778247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 779247738Sbapt NULL, "tag:yaml.org,2002:bool", 780247738Sbapt (input_event.data.sequence_start.implicit ? 781247738Sbapt "true" : "false"), -1, 782247738Sbapt 1, 0, YAML_PLAIN_SCALAR_STYLE)) 783247738Sbapt goto event_error; 784247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 785247738Sbapt goto emitter_error; 786247738Sbapt 787247738Sbapt /* Display the style information. */ 788247738Sbapt 789247738Sbapt if (input_event.data.sequence_start.style) 790247738Sbapt { 791247738Sbapt yaml_sequence_style_t style 792247738Sbapt = input_event.data.sequence_start.style; 793247738Sbapt 794247738Sbapt /* Write 'style'. */ 795247738Sbapt 796247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 797247738Sbapt NULL, "tag:yaml.org,2002:str", "style", -1, 798247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 799247738Sbapt goto event_error; 800247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 801247738Sbapt goto emitter_error; 802247738Sbapt 803247738Sbapt /* Write the scalar style. */ 804247738Sbapt 805247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 806247738Sbapt NULL, "tag:yaml.org,2002:str", 807247738Sbapt (style == YAML_BLOCK_SEQUENCE_STYLE ? "block" : 808247738Sbapt style == YAML_FLOW_SEQUENCE_STYLE ? "flow" : 809247738Sbapt "unknown"), -1, 810247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 811247738Sbapt goto event_error; 812247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 813247738Sbapt goto emitter_error; 814247738Sbapt } 815247738Sbapt 816247738Sbapt break; 817247738Sbapt 818247738Sbapt case YAML_SEQUENCE_END_EVENT: 819247738Sbapt 820247738Sbapt /* Write 'type'. */ 821247738Sbapt 822247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 823247738Sbapt NULL, "tag:yaml.org,2002:str", "type", -1, 824247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 825247738Sbapt goto event_error; 826247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 827247738Sbapt goto emitter_error; 828247738Sbapt 829247738Sbapt /* Write 'SEQUENCE-END'. */ 830247738Sbapt 831247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 832247738Sbapt NULL, "tag:yaml.org,2002:str", "SEQUENCE-END", -1, 833247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 834247738Sbapt goto event_error; 835247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 836247738Sbapt goto emitter_error; 837247738Sbapt 838247738Sbapt break; 839247738Sbapt 840247738Sbapt case YAML_MAPPING_START_EVENT: 841247738Sbapt 842247738Sbapt /* Write 'type'. */ 843247738Sbapt 844247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 845247738Sbapt NULL, "tag:yaml.org,2002:str", "type", -1, 846247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 847247738Sbapt goto event_error; 848247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 849247738Sbapt goto emitter_error; 850247738Sbapt 851247738Sbapt /* Write 'MAPPING-START'. */ 852247738Sbapt 853247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 854247738Sbapt NULL, "tag:yaml.org,2002:str", "MAPPING-START", -1, 855247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 856247738Sbapt goto event_error; 857247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 858247738Sbapt goto emitter_error; 859247738Sbapt 860247738Sbapt /* Display the mapping anchor. */ 861247738Sbapt 862247738Sbapt if (input_event.data.mapping_start.anchor) 863247738Sbapt { 864247738Sbapt /* Write 'anchor'. */ 865247738Sbapt 866247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 867247738Sbapt NULL, "tag:yaml.org,2002:str", "anchor", -1, 868247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 869247738Sbapt goto event_error; 870247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 871247738Sbapt goto emitter_error; 872247738Sbapt 873247738Sbapt /* Write the mapping anchor. */ 874247738Sbapt 875247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 876247738Sbapt NULL, "tag:yaml.org,2002:str", 877247738Sbapt input_event.data.mapping_start.anchor, -1, 878247738Sbapt 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) 879247738Sbapt goto event_error; 880247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 881247738Sbapt goto emitter_error; 882247738Sbapt } 883247738Sbapt 884247738Sbapt /* Display the mapping tag. */ 885247738Sbapt 886247738Sbapt if (input_event.data.mapping_start.tag) 887247738Sbapt { 888247738Sbapt /* Write 'tag'. */ 889247738Sbapt 890247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 891247738Sbapt NULL, "tag:yaml.org,2002:str", "tag", -1, 892247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 893247738Sbapt goto event_error; 894247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 895247738Sbapt goto emitter_error; 896247738Sbapt 897247738Sbapt /* Write the mapping tag. */ 898247738Sbapt 899247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 900247738Sbapt NULL, "tag:yaml.org,2002:str", 901247738Sbapt input_event.data.mapping_start.tag, -1, 902247738Sbapt 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) 903247738Sbapt goto event_error; 904247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 905247738Sbapt goto emitter_error; 906247738Sbapt } 907247738Sbapt 908247738Sbapt /* Write 'implicit'. */ 909247738Sbapt 910247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 911247738Sbapt NULL, "tag:yaml.org,2002:str", "implicit", -1, 912247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 913247738Sbapt goto event_error; 914247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 915247738Sbapt goto emitter_error; 916247738Sbapt 917247738Sbapt /* Write if the mapping tag is implicit. */ 918247738Sbapt 919247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 920247738Sbapt NULL, "tag:yaml.org,2002:bool", 921247738Sbapt (input_event.data.mapping_start.implicit ? 922247738Sbapt "true" : "false"), -1, 923247738Sbapt 1, 0, YAML_PLAIN_SCALAR_STYLE)) 924247738Sbapt goto event_error; 925247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 926247738Sbapt goto emitter_error; 927247738Sbapt 928247738Sbapt /* Display the style information. */ 929247738Sbapt 930247738Sbapt if (input_event.data.mapping_start.style) 931247738Sbapt { 932247738Sbapt yaml_mapping_style_t style 933247738Sbapt = input_event.data.mapping_start.style; 934247738Sbapt 935247738Sbapt /* Write 'style'. */ 936247738Sbapt 937247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 938247738Sbapt NULL, "tag:yaml.org,2002:str", "style", -1, 939247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 940247738Sbapt goto event_error; 941247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 942247738Sbapt goto emitter_error; 943247738Sbapt 944247738Sbapt /* Write the scalar style. */ 945247738Sbapt 946247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 947247738Sbapt NULL, "tag:yaml.org,2002:str", 948247738Sbapt (style == YAML_BLOCK_MAPPING_STYLE ? "block" : 949247738Sbapt style == YAML_FLOW_MAPPING_STYLE ? "flow" : 950247738Sbapt "unknown"), -1, 951247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 952247738Sbapt goto event_error; 953247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 954247738Sbapt goto emitter_error; 955247738Sbapt } 956247738Sbapt 957247738Sbapt break; 958247738Sbapt 959247738Sbapt case YAML_MAPPING_END_EVENT: 960247738Sbapt 961247738Sbapt /* Write 'type'. */ 962247738Sbapt 963247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 964247738Sbapt NULL, "tag:yaml.org,2002:str", "type", -1, 965247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 966247738Sbapt goto event_error; 967247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 968247738Sbapt goto emitter_error; 969247738Sbapt 970247738Sbapt /* Write 'MAPPING-END'. */ 971247738Sbapt 972247738Sbapt if (!yaml_scalar_event_initialize(&output_event, 973247738Sbapt NULL, "tag:yaml.org,2002:str", "MAPPING-END", -1, 974247738Sbapt 1, 1, YAML_PLAIN_SCALAR_STYLE)) 975247738Sbapt goto event_error; 976247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 977247738Sbapt goto emitter_error; 978247738Sbapt 979247738Sbapt break; 980247738Sbapt 981247738Sbapt default: 982247738Sbapt /* It couldn't really happen. */ 983247738Sbapt break; 984247738Sbapt } 985247738Sbapt 986247738Sbapt /* Delete the event object. */ 987247738Sbapt 988247738Sbapt yaml_event_delete(&input_event); 989247738Sbapt 990247738Sbapt /* Create and emit a MAPPING-END event. */ 991247738Sbapt 992247738Sbapt if (!yaml_mapping_end_event_initialize(&output_event)) 993247738Sbapt goto event_error; 994247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 995247738Sbapt goto emitter_error; 996247738Sbapt } 997247738Sbapt 998247738Sbapt /* Create and emit the SEQUENCE-END event. */ 999247738Sbapt 1000247738Sbapt if (!yaml_sequence_end_event_initialize(&output_event)) 1001247738Sbapt goto event_error; 1002247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 1003247738Sbapt goto emitter_error; 1004247738Sbapt 1005247738Sbapt /* Create and emit the DOCUMENT-END event. */ 1006247738Sbapt 1007247738Sbapt if (!yaml_document_end_event_initialize(&output_event, 0)) 1008247738Sbapt goto event_error; 1009247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 1010247738Sbapt goto emitter_error; 1011247738Sbapt 1012247738Sbapt /* Create and emit the STREAM-END event. */ 1013247738Sbapt 1014247738Sbapt if (!yaml_stream_end_event_initialize(&output_event)) 1015247738Sbapt goto event_error; 1016247738Sbapt if (!yaml_emitter_emit(&emitter, &output_event)) 1017247738Sbapt goto emitter_error; 1018247738Sbapt 1019247738Sbapt yaml_parser_delete(&parser); 1020247738Sbapt yaml_emitter_delete(&emitter); 1021247738Sbapt 1022247738Sbapt return 0; 1023247738Sbapt 1024247738Sbaptparser_error: 1025247738Sbapt 1026247738Sbapt /* Display a parser error message. */ 1027247738Sbapt 1028247738Sbapt switch (parser.error) 1029247738Sbapt { 1030247738Sbapt case YAML_MEMORY_ERROR: 1031247738Sbapt fprintf(stderr, "Memory error: Not enough memory for parsing\n"); 1032247738Sbapt break; 1033247738Sbapt 1034247738Sbapt case YAML_READER_ERROR: 1035247738Sbapt if (parser.problem_value != -1) { 1036247738Sbapt fprintf(stderr, "Reader error: %s: #%X at %d\n", parser.problem, 1037247738Sbapt parser.problem_value, parser.problem_offset); 1038247738Sbapt } 1039247738Sbapt else { 1040247738Sbapt fprintf(stderr, "Reader error: %s at %d\n", parser.problem, 1041247738Sbapt parser.problem_offset); 1042247738Sbapt } 1043247738Sbapt break; 1044247738Sbapt 1045247738Sbapt case YAML_SCANNER_ERROR: 1046247738Sbapt if (parser.context) { 1047247738Sbapt fprintf(stderr, "Scanner error: %s at line %d, column %d\n" 1048247738Sbapt "%s at line %d, column %d\n", parser.context, 1049247738Sbapt parser.context_mark.line+1, parser.context_mark.column+1, 1050247738Sbapt parser.problem, parser.problem_mark.line+1, 1051247738Sbapt parser.problem_mark.column+1); 1052247738Sbapt } 1053247738Sbapt else { 1054247738Sbapt fprintf(stderr, "Scanner error: %s at line %d, column %d\n", 1055247738Sbapt parser.problem, parser.problem_mark.line+1, 1056247738Sbapt parser.problem_mark.column+1); 1057247738Sbapt } 1058247738Sbapt break; 1059247738Sbapt 1060247738Sbapt case YAML_PARSER_ERROR: 1061247738Sbapt if (parser.context) { 1062247738Sbapt fprintf(stderr, "Parser error: %s at line %d, column %d\n" 1063247738Sbapt "%s at line %d, column %d\n", parser.context, 1064247738Sbapt parser.context_mark.line+1, parser.context_mark.column+1, 1065247738Sbapt parser.problem, parser.problem_mark.line+1, 1066247738Sbapt parser.problem_mark.column+1); 1067247738Sbapt } 1068247738Sbapt else { 1069247738Sbapt fprintf(stderr, "Parser error: %s at line %d, column %d\n", 1070247738Sbapt parser.problem, parser.problem_mark.line+1, 1071247738Sbapt parser.problem_mark.column+1); 1072247738Sbapt } 1073247738Sbapt break; 1074247738Sbapt 1075247738Sbapt default: 1076247738Sbapt /* Couldn't happen. */ 1077247738Sbapt fprintf(stderr, "Internal error\n"); 1078247738Sbapt break; 1079247738Sbapt } 1080247738Sbapt 1081247738Sbapt yaml_event_delete(&input_event); 1082247738Sbapt yaml_event_delete(&output_event); 1083247738Sbapt yaml_parser_delete(&parser); 1084247738Sbapt yaml_emitter_delete(&emitter); 1085247738Sbapt 1086247738Sbapt return 1; 1087247738Sbapt 1088247738Sbaptemitter_error: 1089247738Sbapt 1090247738Sbapt /* Display an emitter error message. */ 1091247738Sbapt 1092247738Sbapt switch (emitter.error) 1093247738Sbapt { 1094247738Sbapt case YAML_MEMORY_ERROR: 1095247738Sbapt fprintf(stderr, "Memory error: Not enough memory for emitting\n"); 1096247738Sbapt break; 1097247738Sbapt 1098247738Sbapt case YAML_WRITER_ERROR: 1099247738Sbapt fprintf(stderr, "Writer error: %s\n", emitter.problem); 1100247738Sbapt break; 1101247738Sbapt 1102247738Sbapt case YAML_EMITTER_ERROR: 1103247738Sbapt fprintf(stderr, "Emitter error: %s\n", emitter.problem); 1104247738Sbapt break; 1105247738Sbapt 1106247738Sbapt default: 1107247738Sbapt /* Couldn't happen. */ 1108247738Sbapt fprintf(stderr, "Internal error\n"); 1109247738Sbapt break; 1110247738Sbapt } 1111247738Sbapt 1112247738Sbapt yaml_event_delete(&input_event); 1113247738Sbapt yaml_event_delete(&output_event); 1114247738Sbapt yaml_parser_delete(&parser); 1115247738Sbapt yaml_emitter_delete(&emitter); 1116247738Sbapt 1117247738Sbapt return 1; 1118247738Sbapt 1119247738Sbaptevent_error: 1120247738Sbapt 1121247738Sbapt fprintf(stderr, "Memory error: Not enough memory for creating an event\n"); 1122247738Sbapt 1123247738Sbapt yaml_event_delete(&input_event); 1124247738Sbapt yaml_event_delete(&output_event); 1125247738Sbapt yaml_parser_delete(&parser); 1126247738Sbapt yaml_emitter_delete(&emitter); 1127247738Sbapt 1128247738Sbapt return 1; 1129247738Sbapt} 1130247738Sbapt 1131