yaml-0.1.4/0000755000175000017500000000000011571045640007462 500000000000000yaml-0.1.4/tests/0000755000175000017500000000000011571045641010625 500000000000000yaml-0.1.4/tests/example-reformatter-alt.c0000644000175000017500000001402311570357736015464 00000000000000 #include #include #include int main(int argc, char *argv[]) { int help = 0; int canonical = 0; int unicode = 0; int k; int done = 0; yaml_parser_t parser; yaml_emitter_t emitter; yaml_document_t document; /* Clear the objects. */ memset(&parser, 0, sizeof(parser)); memset(&emitter, 0, sizeof(emitter)); memset(&document, 0, sizeof(document)); /* Analyze command line options. */ for (k = 1; k < argc; k ++) { if (strcmp(argv[k], "-h") == 0 || strcmp(argv[k], "--help") == 0) { help = 1; } else if (strcmp(argv[k], "-c") == 0 || strcmp(argv[k], "--canonical") == 0) { canonical = 1; } else if (strcmp(argv[k], "-u") == 0 || strcmp(argv[k], "--unicode") == 0) { unicode = 1; } else { fprintf(stderr, "Unrecognized option: %s\n" "Try `%s --help` for more information.\n", argv[k], argv[0]); return 1; } } /* Display the help string. */ if (help) { printf("%s [--canonical] [--unicode] output\n" "or\n%s -h | --help\nReformat a YAML stream\n\nOptions:\n" "-h, --help\t\tdisplay this help and exit\n" "-c, --canonical\t\toutput in the canonical YAML format\n" "-u, --unicode\t\toutput unescaped non-ASCII characters\n", argv[0], argv[0]); return 0; } /* Initialize the parser and emitter objects. */ if (!yaml_parser_initialize(&parser)) goto parser_error; if (!yaml_emitter_initialize(&emitter)) goto emitter_error; /* Set the parser parameters. */ yaml_parser_set_input_file(&parser, stdin); /* Set the emitter parameters. */ yaml_emitter_set_output_file(&emitter, stdout); yaml_emitter_set_canonical(&emitter, canonical); yaml_emitter_set_unicode(&emitter, unicode); /* The main loop. */ while (!done) { /* Get the next event. */ if (!yaml_parser_load(&parser, &document)) goto parser_error; /* Check if this is the stream end. */ if (!yaml_document_get_root_node(&document)) { done = 1; } /* Emit the event. */ if (!yaml_emitter_dump(&emitter, &document)) goto emitter_error; } yaml_parser_delete(&parser); yaml_emitter_delete(&emitter); return 0; parser_error: /* Display a parser error message. */ switch (parser.error) { case YAML_MEMORY_ERROR: fprintf(stderr, "Memory error: Not enough memory for parsing\n"); break; case YAML_READER_ERROR: if (parser.problem_value != -1) { fprintf(stderr, "Reader error: %s: #%X at %d\n", parser.problem, parser.problem_value, parser.problem_offset); } else { fprintf(stderr, "Reader error: %s at %d\n", parser.problem, parser.problem_offset); } break; case YAML_SCANNER_ERROR: if (parser.context) { fprintf(stderr, "Scanner error: %s at line %d, column %d\n" "%s at line %d, column %d\n", parser.context, parser.context_mark.line+1, parser.context_mark.column+1, parser.problem, parser.problem_mark.line+1, parser.problem_mark.column+1); } else { fprintf(stderr, "Scanner error: %s at line %d, column %d\n", parser.problem, parser.problem_mark.line+1, parser.problem_mark.column+1); } break; case YAML_PARSER_ERROR: if (parser.context) { fprintf(stderr, "Parser error: %s at line %d, column %d\n" "%s at line %d, column %d\n", parser.context, parser.context_mark.line+1, parser.context_mark.column+1, parser.problem, parser.problem_mark.line+1, parser.problem_mark.column+1); } else { fprintf(stderr, "Parser error: %s at line %d, column %d\n", parser.problem, parser.problem_mark.line+1, parser.problem_mark.column+1); } break; case YAML_COMPOSER_ERROR: if (parser.context) { fprintf(stderr, "Composer error: %s at line %d, column %d\n" "%s at line %d, column %d\n", parser.context, parser.context_mark.line+1, parser.context_mark.column+1, parser.problem, parser.problem_mark.line+1, parser.problem_mark.column+1); } else { fprintf(stderr, "Composer error: %s at line %d, column %d\n", parser.problem, parser.problem_mark.line+1, parser.problem_mark.column+1); } break; default: /* Couldn't happen. */ fprintf(stderr, "Internal error\n"); break; } yaml_parser_delete(&parser); yaml_emitter_delete(&emitter); return 1; emitter_error: /* Display an emitter error message. */ switch (emitter.error) { case YAML_MEMORY_ERROR: fprintf(stderr, "Memory error: Not enough memory for emitting\n"); break; case YAML_WRITER_ERROR: fprintf(stderr, "Writer error: %s\n", emitter.problem); break; case YAML_EMITTER_ERROR: fprintf(stderr, "Emitter error: %s\n", emitter.problem); break; default: /* Couldn't happen. */ fprintf(stderr, "Internal error\n"); break; } yaml_parser_delete(&parser); yaml_emitter_delete(&emitter); return 1; } yaml-0.1.4/tests/example-deconstructor.c0000644000175000017500000012576411570357736015271 00000000000000 #include #include #include int main(int argc, char *argv[]) { int help = 0; int canonical = 0; int unicode = 0; int k; int done = 0; yaml_parser_t parser; yaml_emitter_t emitter; yaml_event_t input_event; yaml_event_t output_event; /* Clear the objects. */ memset(&parser, 0, sizeof(parser)); memset(&emitter, 0, sizeof(emitter)); memset(&input_event, 0, sizeof(input_event)); memset(&output_event, 0, sizeof(output_event)); /* Analyze command line options. */ for (k = 1; k < argc; k ++) { if (strcmp(argv[k], "-h") == 0 || strcmp(argv[k], "--help") == 0) { help = 1; } else if (strcmp(argv[k], "-c") == 0 || strcmp(argv[k], "--canonical") == 0) { canonical = 1; } else if (strcmp(argv[k], "-u") == 0 || strcmp(argv[k], "--unicode") == 0) { unicode = 1; } else { fprintf(stderr, "Unrecognized option: %s\n" "Try `%s --help` for more information.\n", argv[k], argv[0]); return 1; } } /* Display the help string. */ if (help) { printf("%s major); if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:int", number, -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write 'minor'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "minor", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write a number. */ sprintf(number, "%d", version->minor); if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:int", number, -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write '}'. */ if (!yaml_mapping_end_event_initialize(&output_event)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; } /* Display the document tag directives. */ if (input_event.data.document_start.tag_directives.start != input_event.data.document_start.tag_directives.end) { yaml_tag_directive_t *tag; /* Write 'tags'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "tags", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Start a block sequence. */ if (!yaml_sequence_start_event_initialize(&output_event, NULL, "tag:yaml.org,2002:seq", 1, YAML_BLOCK_SEQUENCE_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; for (tag = input_event.data.document_start.tag_directives.start; tag != input_event.data.document_start.tag_directives.end; tag ++) { /* Write '{'. */ if (!yaml_mapping_start_event_initialize(&output_event, NULL, "tag:yaml.org,2002:map", 1, YAML_FLOW_MAPPING_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write 'handle'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "handle", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write the tag directive handle. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", tag->handle, -1, 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write 'prefix'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "prefix", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write the tag directive prefix. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", tag->prefix, -1, 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write '}'. */ if (!yaml_mapping_end_event_initialize(&output_event)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; } /* End a block sequence. */ if (!yaml_sequence_end_event_initialize(&output_event)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; } /* Write 'implicit'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "implicit", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write if the document is implicit. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:bool", (input_event.data.document_start.implicit ? "true" : "false"), -1, 1, 0, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; break; case YAML_DOCUMENT_END_EVENT: /* Write 'type'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write 'DOCUMENT-END'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "DOCUMENT-END", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write 'implicit'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "implicit", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write if the document is implicit. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:bool", (input_event.data.document_end.implicit ? "true" : "false"), -1, 1, 0, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; break; case YAML_ALIAS_EVENT: /* Write 'type'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write 'ALIAS'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "ALIAS", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write 'anchor'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "anchor", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write the alias anchor. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", input_event.data.alias.anchor, -1, 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; break; case YAML_SCALAR_EVENT: /* Write 'type'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write 'SCALAR'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "SCALAR", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Display the scalar anchor. */ if (input_event.data.scalar.anchor) { /* Write 'anchor'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "anchor", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write the scalar anchor. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", input_event.data.scalar.anchor, -1, 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; } /* Display the scalar tag. */ if (input_event.data.scalar.tag) { /* Write 'tag'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "tag", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write the scalar tag. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", input_event.data.scalar.tag, -1, 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; } /* Display the scalar value. */ /* Write 'value'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "value", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write the scalar value. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", input_event.data.scalar.value, input_event.data.scalar.length, 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Display if the scalar tag is implicit. */ /* Write 'implicit'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "implicit", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write '{'. */ if (!yaml_mapping_start_event_initialize(&output_event, NULL, "tag:yaml.org,2002:map", 1, YAML_FLOW_MAPPING_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write 'plain'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "plain", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write if the scalar is implicit in the plain style. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:bool", (input_event.data.scalar.plain_implicit ? "true" : "false"), -1, 1, 0, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write 'quoted'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "non-plain", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write if the scalar is implicit in a non-plain style. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:bool", (input_event.data.scalar.quoted_implicit ? "true" : "false"), -1, 1, 0, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write '}'. */ if (!yaml_mapping_end_event_initialize(&output_event)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Display the style information. */ if (input_event.data.scalar.style) { yaml_scalar_style_t style = input_event.data.scalar.style; /* Write 'style'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "style", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write the scalar style. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", (style == YAML_PLAIN_SCALAR_STYLE ? "plain" : style == YAML_SINGLE_QUOTED_SCALAR_STYLE ? "single-quoted" : style == YAML_DOUBLE_QUOTED_SCALAR_STYLE ? "double-quoted" : style == YAML_LITERAL_SCALAR_STYLE ? "literal" : style == YAML_FOLDED_SCALAR_STYLE ? "folded" : "unknown"), -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; } break; case YAML_SEQUENCE_START_EVENT: /* Write 'type'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write 'SEQUENCE-START'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "SEQUENCE-START", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Display the sequence anchor. */ if (input_event.data.sequence_start.anchor) { /* Write 'anchor'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "anchor", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write the sequence anchor. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", input_event.data.sequence_start.anchor, -1, 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; } /* Display the sequence tag. */ if (input_event.data.sequence_start.tag) { /* Write 'tag'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "tag", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write the sequence tag. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", input_event.data.sequence_start.tag, -1, 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; } /* Write 'implicit'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "implicit", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write if the sequence tag is implicit. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:bool", (input_event.data.sequence_start.implicit ? "true" : "false"), -1, 1, 0, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Display the style information. */ if (input_event.data.sequence_start.style) { yaml_sequence_style_t style = input_event.data.sequence_start.style; /* Write 'style'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "style", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write the scalar style. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", (style == YAML_BLOCK_SEQUENCE_STYLE ? "block" : style == YAML_FLOW_SEQUENCE_STYLE ? "flow" : "unknown"), -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; } break; case YAML_SEQUENCE_END_EVENT: /* Write 'type'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write 'SEQUENCE-END'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "SEQUENCE-END", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; break; case YAML_MAPPING_START_EVENT: /* Write 'type'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write 'MAPPING-START'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "MAPPING-START", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Display the mapping anchor. */ if (input_event.data.mapping_start.anchor) { /* Write 'anchor'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "anchor", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write the mapping anchor. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", input_event.data.mapping_start.anchor, -1, 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; } /* Display the mapping tag. */ if (input_event.data.mapping_start.tag) { /* Write 'tag'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "tag", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write the mapping tag. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", input_event.data.mapping_start.tag, -1, 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; } /* Write 'implicit'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "implicit", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write if the mapping tag is implicit. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:bool", (input_event.data.mapping_start.implicit ? "true" : "false"), -1, 1, 0, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Display the style information. */ if (input_event.data.mapping_start.style) { yaml_mapping_style_t style = input_event.data.mapping_start.style; /* Write 'style'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "style", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write the scalar style. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", (style == YAML_BLOCK_MAPPING_STYLE ? "block" : style == YAML_FLOW_MAPPING_STYLE ? "flow" : "unknown"), -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; } break; case YAML_MAPPING_END_EVENT: /* Write 'type'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "type", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Write 'MAPPING-END'. */ if (!yaml_scalar_event_initialize(&output_event, NULL, "tag:yaml.org,2002:str", "MAPPING-END", -1, 1, 1, YAML_PLAIN_SCALAR_STYLE)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; break; default: /* It couldn't really happen. */ break; } /* Delete the event object. */ yaml_event_delete(&input_event); /* Create and emit a MAPPING-END event. */ if (!yaml_mapping_end_event_initialize(&output_event)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; } /* Create and emit the SEQUENCE-END event. */ if (!yaml_sequence_end_event_initialize(&output_event)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Create and emit the DOCUMENT-END event. */ if (!yaml_document_end_event_initialize(&output_event, 0)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; /* Create and emit the STREAM-END event. */ if (!yaml_stream_end_event_initialize(&output_event)) goto event_error; if (!yaml_emitter_emit(&emitter, &output_event)) goto emitter_error; yaml_parser_delete(&parser); yaml_emitter_delete(&emitter); return 0; parser_error: /* Display a parser error message. */ switch (parser.error) { case YAML_MEMORY_ERROR: fprintf(stderr, "Memory error: Not enough memory for parsing\n"); break; case YAML_READER_ERROR: if (parser.problem_value != -1) { fprintf(stderr, "Reader error: %s: #%X at %d\n", parser.problem, parser.problem_value, parser.problem_offset); } else { fprintf(stderr, "Reader error: %s at %d\n", parser.problem, parser.problem_offset); } break; case YAML_SCANNER_ERROR: if (parser.context) { fprintf(stderr, "Scanner error: %s at line %d, column %d\n" "%s at line %d, column %d\n", parser.context, parser.context_mark.line+1, parser.context_mark.column+1, parser.problem, parser.problem_mark.line+1, parser.problem_mark.column+1); } else { fprintf(stderr, "Scanner error: %s at line %d, column %d\n", parser.problem, parser.problem_mark.line+1, parser.problem_mark.column+1); } break; case YAML_PARSER_ERROR: if (parser.context) { fprintf(stderr, "Parser error: %s at line %d, column %d\n" "%s at line %d, column %d\n", parser.context, parser.context_mark.line+1, parser.context_mark.column+1, parser.problem, parser.problem_mark.line+1, parser.problem_mark.column+1); } else { fprintf(stderr, "Parser error: %s at line %d, column %d\n", parser.problem, parser.problem_mark.line+1, parser.problem_mark.column+1); } break; default: /* Couldn't happen. */ fprintf(stderr, "Internal error\n"); break; } yaml_event_delete(&input_event); yaml_event_delete(&output_event); yaml_parser_delete(&parser); yaml_emitter_delete(&emitter); return 1; emitter_error: /* Display an emitter error message. */ switch (emitter.error) { case YAML_MEMORY_ERROR: fprintf(stderr, "Memory error: Not enough memory for emitting\n"); break; case YAML_WRITER_ERROR: fprintf(stderr, "Writer error: %s\n", emitter.problem); break; case YAML_EMITTER_ERROR: fprintf(stderr, "Emitter error: %s\n", emitter.problem); break; default: /* Couldn't happen. */ fprintf(stderr, "Internal error\n"); break; } yaml_event_delete(&input_event); yaml_event_delete(&output_event); yaml_parser_delete(&parser); yaml_emitter_delete(&emitter); return 1; event_error: fprintf(stderr, "Memory error: Not enough memory for creating an event\n"); yaml_event_delete(&input_event); yaml_event_delete(&output_event); yaml_parser_delete(&parser); yaml_emitter_delete(&emitter); return 1; } yaml-0.1.4/tests/test-reader.c0000644000175000017500000003000711570357736013142 00000000000000#include YAML_DECLARE(int) yaml_parser_update_buffer(yaml_parser_t *parser, size_t length); #include #include #ifdef NDEBUG #undef NDEBUG #endif #include /* * Test cases are stolen from * http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt */ typedef struct { char *title; char *test; int result; } test_case; test_case utf8_sequences[] = { /* {"title", "test 1|test 2|...|test N!", (0 or 1)}, */ {"a simple test", "'test' is '\xd0\xbf\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb5\xd1\x80\xd0\xba\xd0\xb0' in Russian!", 1}, {"an empty line", "!", 1}, {"u-0 is a control character", "\x00!", 0}, {"u-80 is a control character", "\xc2\x80!", 0}, {"u-800 is valid", "\xe0\xa0\x80!", 1}, {"u-10000 is valid", "\xf0\x90\x80\x80!", 1}, {"5 bytes sequences are not allowed", "\xf8\x88\x80\x80\x80!", 0}, {"6 bytes sequences are not allowed", "\xfc\x84\x80\x80\x80\x80!", 0}, {"u-7f is a control character", "\x7f!", 0}, {"u-7FF is valid", "\xdf\xbf!", 1}, {"u-FFFF is a control character", "\xef\xbf\xbf!", 0}, {"u-1FFFFF is too large", "\xf7\xbf\xbf\xbf!", 0}, {"u-3FFFFFF is 5 bytes", "\xfb\xbf\xbf\xbf\xbf!", 0}, {"u-7FFFFFFF is 6 bytes", "\xfd\xbf\xbf\xbf\xbf\xbf!", 0}, {"u-D7FF", "\xed\x9f\xbf!", 1}, {"u-E000", "\xee\x80\x80!", 1}, {"u-FFFD", "\xef\xbf\xbd!", 1}, {"u-10FFFF", "\xf4\x8f\xbf\xbf!", 1}, {"u-110000", "\xf4\x90\x80\x80!", 0}, {"first continuation byte", "\x80!", 0}, {"last continuation byte", "\xbf!", 0}, {"2 continuation bytes", "\x80\xbf!", 0}, {"3 continuation bytes", "\x80\xbf\x80!", 0}, {"4 continuation bytes", "\x80\xbf\x80\xbf!", 0}, {"5 continuation bytes", "\x80\xbf\x80\xbf\x80!", 0}, {"6 continuation bytes", "\x80\xbf\x80\xbf\x80\xbf!", 0}, {"7 continuation bytes", "\x80\xbf\x80\xbf\x80\xbf\x80!", 0}, {"sequence of all 64 possible continuation bytes", "\x80|\x81|\x82|\x83|\x84|\x85|\x86|\x87|\x88|\x89|\x8a|\x8b|\x8c|\x8d|\x8e|\x8f|" "\x90|\x91|\x92|\x93|\x94|\x95|\x96|\x97|\x98|\x99|\x9a|\x9b|\x9c|\x9d|\x9e|\x9f|" "\xa0|\xa1|\xa2|\xa3|\xa4|\xa5|\xa6|\xa7|\xa8|\xa9|\xaa|\xab|\xac|\xad|\xae|\xaf|" "\xb0|\xb1|\xb2|\xb3|\xb4|\xb5|\xb6|\xb7|\xb8|\xb9|\xba|\xbb|\xbc|\xbd|\xbe|\xbf!", 0}, {"32 first bytes of 2-byte sequences {0xc0-0xdf}", "\xc0 |\xc1 |\xc2 |\xc3 |\xc4 |\xc5 |\xc6 |\xc7 |\xc8 |\xc9 |\xca |\xcb |\xcc |\xcd |\xce |\xcf |" "\xd0 |\xd1 |\xd2 |\xd3 |\xd4 |\xd5 |\xd6 |\xd7 |\xd8 |\xd9 |\xda |\xdb |\xdc |\xdd |\xde |\xdf !", 0}, {"16 first bytes of 3-byte sequences {0xe0-0xef}", "\xe0 |\xe1 |\xe2 |\xe3 |\xe4 |\xe5 |\xe6 |\xe7 |\xe8 |\xe9 |\xea |\xeb |\xec |\xed |\xee |\xef !", 0}, {"8 first bytes of 4-byte sequences {0xf0-0xf7}", "\xf0 |\xf1 |\xf2 |\xf3 |\xf4 |\xf5 |\xf6 |\xf7 !", 0}, {"4 first bytes of 5-byte sequences {0xf8-0xfb}", "\xf8 |\xf9 |\xfa |\xfb !", 0}, {"2 first bytes of 6-byte sequences {0xfc-0xfd}", "\xfc |\xfd !", 0}, {"sequences with last byte missing {u-0}", "\xc0|\xe0\x80|\xf0\x80\x80|\xf8\x80\x80\x80|\xfc\x80\x80\x80\x80!", 0}, {"sequences with last byte missing {u-...FF}", "\xdf|\xef\xbf|\xf7\xbf\xbf|\xfb\xbf\xbf\xbf|\xfd\xbf\xbf\xbf\xbf!", 0}, {"impossible bytes", "\xfe|\xff|\xfe\xfe\xff\xff!", 0}, {"overlong sequences {u-2f}", "\xc0\xaf|\xe0\x80\xaf|\xf0\x80\x80\xaf|\xf8\x80\x80\x80\xaf|\xfc\x80\x80\x80\x80\xaf!", 0}, {"maximum overlong sequences", "\xc1\xbf|\xe0\x9f\xbf|\xf0\x8f\xbf\xbf|\xf8\x87\xbf\xbf\xbf|\xfc\x83\xbf\xbf\xbf\xbf!", 0}, {"overlong representation of the NUL character", "\xc0\x80|\xe0\x80\x80|\xf0\x80\x80\x80|\xf8\x80\x80\x80\x80|\xfc\x80\x80\x80\x80\x80!", 0}, {"single UTF-16 surrogates", "\xed\xa0\x80|\xed\xad\xbf|\xed\xae\x80|\xed\xaf\xbf|\xed\xb0\x80|\xed\xbe\x80|\xed\xbf\xbf!", 0}, {"paired UTF-16 surrogates", "\xed\xa0\x80\xed\xb0\x80|\xed\xa0\x80\xed\xbf\xbf|\xed\xad\xbf\xed\xb0\x80|" "\xed\xad\xbf\xed\xbf\xbf|\xed\xae\x80\xed\xb0\x80|\xed\xae\x80\xed\xbf\xbf|" "\xed\xaf\xbf\xed\xb0\x80|\xed\xaf\xbf\xed\xbf\xbf!", 0}, {"other illegal code positions", "\xef\xbf\xbe|\xef\xbf\xbf!", 0}, {NULL, NULL, 0} }; test_case boms[] = { /* {"title", "test!", lenth}, */ {"no bom (utf-8)", "Hi is \xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82!", 13}, {"bom (utf-8)", "\xef\xbb\xbfHi is \xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82!", 13}, {"bom (utf-16-le)", "\xff\xfeH\x00i\x00 \x00i\x00s\x00 \x00\x1f\x04@\x04""8\x04""2\x04""5\x04""B\x04!", 13}, {"bom (utf-16-be)", "\xfe\xff\x00H\x00i\x00 \x00i\x00s\x00 \x04\x1f\x04@\x04""8\x04""2\x04""5\x04""B!", 13}, {NULL, NULL, 0} }; char *bom_original = "Hi is \xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82"; int check_utf8_sequences(void) { yaml_parser_t parser; int failed = 0; int k; printf("checking utf-8 sequences...\n"); for (k = 0; utf8_sequences[k].test; k++) { char *title = utf8_sequences[k].title; int check = utf8_sequences[k].result; int result; char *start = utf8_sequences[k].test; char *end = start; printf("\t%s:\n", title); while(1) { while (*end != '|' && *end != '!') end++; yaml_parser_initialize(&parser); yaml_parser_set_input_string(&parser, (unsigned char *)start, end-start); result = yaml_parser_update_buffer(&parser, end-start); if (result != check) { printf("\t\t- "); failed ++; } else { printf("\t\t+ "); } if (!parser.error) { printf("(no error)\n"); } else if (parser.error == YAML_READER_ERROR) { if (parser.problem_value != -1) { printf("(reader error: %s: #%X at %d)\n", parser.problem, parser.problem_value, parser.problem_offset); } else { printf("(reader error: %s at %d)\n", parser.problem, parser.problem_offset); } } if (*end == '!') break; start = ++end; yaml_parser_delete(&parser); }; printf("\n"); } printf("checking utf-8 sequences: %d fail(s)\n", failed); return failed; } int check_boms(void) { yaml_parser_t parser; int failed = 0; int k; printf("checking boms...\n"); for (k = 0; boms[k].test; k++) { char *title = boms[k].title; int check = boms[k].result; int result; char *start = boms[k].test; char *end = start; while (*end != '!') end++; printf("\t%s: ", title); yaml_parser_initialize(&parser); yaml_parser_set_input_string(&parser, (unsigned char *)start, end-start); result = yaml_parser_update_buffer(&parser, end-start); if (!result) { printf("- (reader error: %s at %d)\n", parser.problem, parser.problem_offset); failed++; } else { if (parser.unread != check) { printf("- (length=%d while expected length=%d)\n", parser.unread, check); failed++; } else if (memcmp(parser.buffer.start, bom_original, check) != 0) { printf("- (value '%s' does not equal to the original value '%s')\n", parser.buffer.start, bom_original); failed++; } else { printf("+\n"); } } yaml_parser_delete(&parser); } printf("checking boms: %d fail(s)\n", failed); return failed; } #define LONG 100000 int check_long_utf8(void) { yaml_parser_t parser; int k = 0; int j; int failed = 0; unsigned char ch0, ch1; unsigned char *buffer = malloc(3+LONG*2); assert(buffer); printf("checking a long utf8 sequence...\n"); buffer[k++] = '\xef'; buffer[k++] = '\xbb'; buffer[k++] = '\xbf'; for (j = 0; j < LONG; j ++) { if (j % 2) { buffer[k++] = '\xd0'; buffer[k++] = '\x90'; } else { buffer[k++] = '\xd0'; buffer[k++] = '\xaf'; } } yaml_parser_initialize(&parser); yaml_parser_set_input_string(&parser, buffer, 3+LONG*2); for (k = 0; k < LONG; k++) { if (!parser.unread) { if (!yaml_parser_update_buffer(&parser, 1)) { printf("\treader error: %s at %d\n", parser.problem, parser.problem_offset); failed = 1; break; } } if (!parser.unread) { printf("\tnot enough characters at %d\n", k); failed = 1; break; } if (k % 2) { ch0 = '\xd0'; ch1 = '\x90'; } else { ch0 = '\xd0'; ch1 = '\xaf'; } if (parser.buffer.pointer[0] != ch0 || parser.buffer.pointer[1] != ch1) { printf("\tincorrect UTF-8 sequence: %X %X instead of %X %X\n", (int)parser.buffer.pointer[0], (int)parser.buffer.pointer[1], (int)ch0, (int)ch1); failed = 1; break; } parser.buffer.pointer += 2; parser.unread -= 1; } if (!failed) { if (!yaml_parser_update_buffer(&parser, 1)) { printf("\treader error: %s at %d\n", parser.problem, parser.problem_offset); failed = 1; } else if (parser.buffer.pointer[0] != '\0') { printf("\texpected NUL, found %X (eof=%d, unread=%d)\n", (int)parser.buffer.pointer[0], parser.eof, parser.unread); failed = 1; } } yaml_parser_delete(&parser); free(buffer); printf("checking a long utf8 sequence: %d fail(s)\n", failed); return failed; } int check_long_utf16(void) { yaml_parser_t parser; int k = 0; int j; int failed = 0; unsigned char ch0, ch1; unsigned char *buffer = malloc(2+LONG*2); assert(buffer); printf("checking a long utf16 sequence...\n"); buffer[k++] = '\xff'; buffer[k++] = '\xfe'; for (j = 0; j < LONG; j ++) { if (j % 2) { buffer[k++] = '\x10'; buffer[k++] = '\x04'; } else { buffer[k++] = '/'; buffer[k++] = '\x04'; } } yaml_parser_initialize(&parser); yaml_parser_set_input_string(&parser, buffer, 2+LONG*2); for (k = 0; k < LONG; k++) { if (!parser.unread) { if (!yaml_parser_update_buffer(&parser, 1)) { printf("\treader error: %s at %d\n", parser.problem, parser.problem_offset); failed = 1; break; } } if (!parser.unread) { printf("\tnot enough characters at %d\n", k); failed = 1; break; } if (k % 2) { ch0 = '\xd0'; ch1 = '\x90'; } else { ch0 = '\xd0'; ch1 = '\xaf'; } if (parser.buffer.pointer[0] != ch0 || parser.buffer.pointer[1] != ch1) { printf("\tincorrect UTF-8 sequence: %X %X instead of %X %X\n", (int)parser.buffer.pointer[0], (int)parser.buffer.pointer[1], (int)ch0, (int)ch1); failed = 1; break; } parser.buffer.pointer += 2; parser.unread -= 1; } if (!failed) { if (!yaml_parser_update_buffer(&parser, 1)) { printf("\treader error: %s at %d\n", parser.problem, parser.problem_offset); failed = 1; } else if (parser.buffer.pointer[0] != '\0') { printf("\texpected NUL, found %X (eof=%d, unread=%d)\n", (int)parser.buffer.pointer[0], parser.eof, parser.unread); failed = 1; } } yaml_parser_delete(&parser); free(buffer); printf("checking a long utf16 sequence: %d fail(s)\n", failed); return failed; } int main(void) { return check_utf8_sequences() + check_boms() + check_long_utf8() + check_long_utf16(); } yaml-0.1.4/tests/Makefile.am0000644000175000017500000000055611570357736012621 00000000000000AM_CPPFLAGS = -I$(top_srcdir)/include #AM_CFLAGS = -Wno-pointer-sign LDADD = $(top_builddir)/src/libyaml.la TESTS = test-version test-reader check_PROGRAMS = test-version test-reader noinst_PROGRAMS = run-scanner run-parser run-loader run-emitter run-dumper \ example-reformatter example-reformatter-alt \ example-deconstructor example-deconstructor-alt yaml-0.1.4/tests/test-version.c0000644000175000017500000000112011570357736013357 00000000000000#include #include #include #ifdef NDEBUG #undef NDEBUG #endif #include int main(void) { int major = -1; int minor = -1; int patch = -1; char buf[64]; yaml_get_version(&major, &minor, &patch); sprintf(buf, "%d.%d.%d", major, minor, patch); assert(strcmp(buf, yaml_get_version_string()) == 0); /* Print structure sizes. */ printf("sizeof(token) = %d\n", sizeof(yaml_token_t)); printf("sizeof(event) = %d\n", sizeof(yaml_event_t)); printf("sizeof(parser) = %d\n", sizeof(yaml_parser_t)); return 0; } yaml-0.1.4/tests/run-dumper.c0000644000175000017500000002463611570357736013034 00000000000000#include #include #include #include #ifdef NDEBUG #undef NDEBUG #endif #include #define BUFFER_SIZE 65536 #define MAX_DOCUMENTS 16 int copy_document(yaml_document_t *document_to, yaml_document_t *document_from) { yaml_node_t *node; yaml_node_item_t *item; yaml_node_pair_t *pair; if (!yaml_document_initialize(document_to, document_from->version_directive, document_from->tag_directives.start, document_from->tag_directives.end, document_from->start_implicit, document_from->end_implicit)) return 0; for (node = document_from->nodes.start; node < document_from->nodes.top; node ++) { switch (node->type) { case YAML_SCALAR_NODE: if (!yaml_document_add_scalar(document_to, node->tag, node->data.scalar.value, node->data.scalar.length, node->data.scalar.style)) goto error; break; case YAML_SEQUENCE_NODE: if (!yaml_document_add_sequence(document_to, node->tag, node->data.sequence.style)) goto error; break; case YAML_MAPPING_NODE: if (!yaml_document_add_mapping(document_to, node->tag, node->data.mapping.style)) goto error; break; default: assert(0); break; } } for (node = document_from->nodes.start; node < document_from->nodes.top; node ++) { switch (node->type) { case YAML_SEQUENCE_NODE: for (item = node->data.sequence.items.start; item < node->data.sequence.items.top; item ++) { if (!yaml_document_append_sequence_item(document_to, node - document_from->nodes.start + 1, *item)) goto error; } break; case YAML_MAPPING_NODE: for (pair = node->data.mapping.pairs.start; pair < node->data.mapping.pairs.top; pair ++) { if (!yaml_document_append_mapping_pair(document_to, node - document_from->nodes.start + 1, pair->key, pair->value)) goto error; } break; default: break; } } return 1; error: yaml_document_delete(document_to); return 0; } int compare_nodes(yaml_document_t *document1, int index1, yaml_document_t *document2, int index2) { yaml_node_t *node1 = yaml_document_get_node(document1, index1); yaml_node_t *node2 = yaml_document_get_node(document2, index2); int k; assert(node1); assert(node2); if (node1->type != node2->type) return 0; if (strcmp((char *)node1->tag, (char *)node2->tag) != 0) return 0; switch (node1->type) { case YAML_SCALAR_NODE: if (node1->data.scalar.length != node2->data.scalar.length) return 0; if (strncmp((char *)node1->data.scalar.value, (char *)node2->data.scalar.value, node1->data.scalar.length) != 0) return 0; break; case YAML_SEQUENCE_NODE: if ((node1->data.sequence.items.top - node1->data.sequence.items.start) != (node2->data.sequence.items.top - node2->data.sequence.items.start)) return 0; for (k = 0; k < (node1->data.sequence.items.top - node1->data.sequence.items.start); k ++) { if (!compare_nodes(document1, node1->data.sequence.items.start[k], document2, node2->data.sequence.items.start[k])) return 0; } break; case YAML_MAPPING_NODE: if ((node1->data.mapping.pairs.top - node1->data.mapping.pairs.start) != (node2->data.mapping.pairs.top - node2->data.mapping.pairs.start)) return 0; for (k = 0; k < (node1->data.mapping.pairs.top - node1->data.mapping.pairs.start); k ++) { if (!compare_nodes(document1, node1->data.mapping.pairs.start[k].key, document2, node2->data.mapping.pairs.start[k].key)) return 0; if (!compare_nodes(document1, node1->data.mapping.pairs.start[k].value, document2, node2->data.mapping.pairs.start[k].value)) return 0; } break; default: assert(0); break; } return 1; } int compare_documents(yaml_document_t *document1, yaml_document_t *document2) { int k; if ((document1->version_directive && !document2->version_directive) || (!document1->version_directive && document2->version_directive) || (document1->version_directive && document2->version_directive && (document1->version_directive->major != document2->version_directive->major || document1->version_directive->minor != document2->version_directive->minor))) return 0; if ((document1->tag_directives.end - document1->tag_directives.start) != (document2->tag_directives.end - document2->tag_directives.start)) return 0; for (k = 0; k < (document1->tag_directives.end - document1->tag_directives.start); k ++) { if ((strcmp((char *)document1->tag_directives.start[k].handle, (char *)document2->tag_directives.start[k].handle) != 0) || (strcmp((char *)document1->tag_directives.start[k].prefix, (char *)document2->tag_directives.start[k].prefix) != 0)) return 0; } if ((document1->nodes.top - document1->nodes.start) != (document2->nodes.top - document2->nodes.start)) return 0; if (document1->nodes.top != document1->nodes.start) { if (!compare_nodes(document1, 1, document2, 1)) return 0; } return 1; } int print_output(char *name, unsigned char *buffer, size_t size, int count) { FILE *file; char data[BUFFER_SIZE]; size_t data_size = 1; size_t total_size = 0; if (count >= 0) { printf("FAILED (at the document #%d)\nSOURCE:\n", count+1); } file = fopen(name, "rb"); assert(file); while (data_size > 0) { data_size = fread(data, 1, BUFFER_SIZE, file); assert(!ferror(file)); if (!data_size) break; assert(fwrite(data, 1, data_size, stdout) == data_size); total_size += data_size; if (feof(file)) break; } fclose(file); printf("#### (length: %d)\n", total_size); printf("OUTPUT:\n%s#### (length: %d)\n", buffer, size); return 0; } int main(int argc, char *argv[]) { int number; int canonical = 0; int unicode = 0; number = 1; while (number < argc) { if (strcmp(argv[number], "-c") == 0) { canonical = 1; } else if (strcmp(argv[number], "-u") == 0) { unicode = 1; } else if (argv[number][0] == '-') { printf("Unknown option: '%s'\n", argv[number]); return 0; } if (argv[number][0] == '-') { if (number < argc-1) { memmove(argv+number, argv+number+1, (argc-number-1)*sizeof(char *)); } argc --; } else { number ++; } } if (argc < 2) { printf("Usage: %s [-c] [-u] file1.yaml ...\n", argv[0]); return 0; } for (number = 1; number < argc; number ++) { FILE *file; yaml_parser_t parser; yaml_emitter_t emitter; yaml_document_t document; unsigned char buffer[BUFFER_SIZE]; size_t written = 0; yaml_document_t documents[MAX_DOCUMENTS]; size_t document_number = 0; int done = 0; int count = 0; int error = 0; int k; memset(buffer, 0, BUFFER_SIZE); memset(documents, 0, MAX_DOCUMENTS*sizeof(yaml_document_t)); printf("[%d] Loading, dumping, and loading again '%s': ", number, argv[number]); fflush(stdout); file = fopen(argv[number], "rb"); assert(file); assert(yaml_parser_initialize(&parser)); yaml_parser_set_input_file(&parser, file); assert(yaml_emitter_initialize(&emitter)); if (canonical) { yaml_emitter_set_canonical(&emitter, 1); } if (unicode) { yaml_emitter_set_unicode(&emitter, 1); } yaml_emitter_set_output_string(&emitter, buffer, BUFFER_SIZE, &written); yaml_emitter_open(&emitter); while (!done) { if (!yaml_parser_load(&parser, &document)) { error = 1; break; } done = (!yaml_document_get_root_node(&document)); if (!done) { assert(document_number < MAX_DOCUMENTS); assert(copy_document(&(documents[document_number++]), &document)); assert(yaml_emitter_dump(&emitter, &document) || (yaml_emitter_flush(&emitter) && print_output(argv[number], buffer, written, count))); count ++; } else { yaml_document_delete(&document); } } yaml_parser_delete(&parser); assert(!fclose(file)); yaml_emitter_close(&emitter); yaml_emitter_delete(&emitter); if (!error) { count = done = 0; assert(yaml_parser_initialize(&parser)); yaml_parser_set_input_string(&parser, buffer, written); while (!done) { assert(yaml_parser_load(&parser, &document) || print_output(argv[number], buffer, written, count)); done = (!yaml_document_get_root_node(&document)); if (!done) { assert(compare_documents(documents+count, &document) || print_output(argv[number], buffer, written, count)); count ++; } yaml_document_delete(&document); } yaml_parser_delete(&parser); } for (k = 0; k < document_number; k ++) { yaml_document_delete(documents+k); } printf("PASSED (length: %d)\n", written); print_output(argv[number], buffer, written, -1); } return 0; } yaml-0.1.4/tests/run-emitter.c0000644000175000017500000003160011570357736013176 00000000000000#include #include #include #include #ifdef NDEBUG #undef NDEBUG #endif #include #define BUFFER_SIZE 65536 #define MAX_EVENTS 1024 int copy_event(yaml_event_t *event_to, yaml_event_t *event_from) { switch (event_from->type) { case YAML_STREAM_START_EVENT: return yaml_stream_start_event_initialize(event_to, event_from->data.stream_start.encoding); case YAML_STREAM_END_EVENT: return yaml_stream_end_event_initialize(event_to); case YAML_DOCUMENT_START_EVENT: return yaml_document_start_event_initialize(event_to, event_from->data.document_start.version_directive, event_from->data.document_start.tag_directives.start, event_from->data.document_start.tag_directives.end, event_from->data.document_start.implicit); case YAML_DOCUMENT_END_EVENT: return yaml_document_end_event_initialize(event_to, event_from->data.document_end.implicit); case YAML_ALIAS_EVENT: return yaml_alias_event_initialize(event_to, event_from->data.alias.anchor); case YAML_SCALAR_EVENT: return yaml_scalar_event_initialize(event_to, event_from->data.scalar.anchor, event_from->data.scalar.tag, event_from->data.scalar.value, event_from->data.scalar.length, event_from->data.scalar.plain_implicit, event_from->data.scalar.quoted_implicit, event_from->data.scalar.style); case YAML_SEQUENCE_START_EVENT: return yaml_sequence_start_event_initialize(event_to, event_from->data.sequence_start.anchor, event_from->data.sequence_start.tag, event_from->data.sequence_start.implicit, event_from->data.sequence_start.style); case YAML_SEQUENCE_END_EVENT: return yaml_sequence_end_event_initialize(event_to); case YAML_MAPPING_START_EVENT: return yaml_mapping_start_event_initialize(event_to, event_from->data.mapping_start.anchor, event_from->data.mapping_start.tag, event_from->data.mapping_start.implicit, event_from->data.mapping_start.style); case YAML_MAPPING_END_EVENT: return yaml_mapping_end_event_initialize(event_to); default: assert(1); } return 0; } int compare_events(yaml_event_t *event1, yaml_event_t *event2) { int k; if (event1->type != event2->type) return 0; switch (event1->type) { case YAML_STREAM_START_EVENT: return 1; /* return (event1->data.stream_start.encoding == event2->data.stream_start.encoding); */ case YAML_DOCUMENT_START_EVENT: if ((event1->data.document_start.version_directive && !event2->data.document_start.version_directive) || (!event1->data.document_start.version_directive && event2->data.document_start.version_directive) || (event1->data.document_start.version_directive && event2->data.document_start.version_directive && (event1->data.document_start.version_directive->major != event2->data.document_start.version_directive->major || event1->data.document_start.version_directive->minor != event2->data.document_start.version_directive->minor))) return 0; if ((event1->data.document_start.tag_directives.end - event1->data.document_start.tag_directives.start) != (event2->data.document_start.tag_directives.end - event2->data.document_start.tag_directives.start)) return 0; for (k = 0; k < (event1->data.document_start.tag_directives.end - event1->data.document_start.tag_directives.start); k ++) { if ((strcmp((char *)event1->data.document_start.tag_directives.start[k].handle, (char *)event2->data.document_start.tag_directives.start[k].handle) != 0) || (strcmp((char *)event1->data.document_start.tag_directives.start[k].prefix, (char *)event2->data.document_start.tag_directives.start[k].prefix) != 0)) return 0; } /* if (event1->data.document_start.implicit != event2->data.document_start.implicit) return 0; */ return 1; case YAML_DOCUMENT_END_EVENT: return 1; /* return (event1->data.document_end.implicit == event2->data.document_end.implicit); */ case YAML_ALIAS_EVENT: return (strcmp((char *)event1->data.alias.anchor, (char *)event2->data.alias.anchor) == 0); case YAML_SCALAR_EVENT: if ((event1->data.scalar.anchor && !event2->data.scalar.anchor) || (!event1->data.scalar.anchor && event2->data.scalar.anchor) || (event1->data.scalar.anchor && event2->data.scalar.anchor && strcmp((char *)event1->data.scalar.anchor, (char *)event2->data.scalar.anchor) != 0)) return 0; if ((event1->data.scalar.tag && !event2->data.scalar.tag && strcmp((char *)event1->data.scalar.tag, "!") != 0) || (!event1->data.scalar.tag && event2->data.scalar.tag && strcmp((char *)event2->data.scalar.tag, "!") != 0) || (event1->data.scalar.tag && event2->data.scalar.tag && strcmp((char *)event1->data.scalar.tag, (char *)event2->data.scalar.tag) != 0)) return 0; if ((event1->data.scalar.length != event2->data.scalar.length) || memcmp(event1->data.scalar.value, event2->data.scalar.value, event1->data.scalar.length) != 0) return 0; if ((event1->data.scalar.plain_implicit != event2->data.scalar.plain_implicit) || (event2->data.scalar.quoted_implicit != event2->data.scalar.quoted_implicit) /* || (event2->data.scalar.style != event2->data.scalar.style) */) return 0; return 1; case YAML_SEQUENCE_START_EVENT: if ((event1->data.sequence_start.anchor && !event2->data.sequence_start.anchor) || (!event1->data.sequence_start.anchor && event2->data.sequence_start.anchor) || (event1->data.sequence_start.anchor && event2->data.sequence_start.anchor && strcmp((char *)event1->data.sequence_start.anchor, (char *)event2->data.sequence_start.anchor) != 0)) return 0; if ((event1->data.sequence_start.tag && !event2->data.sequence_start.tag) || (!event1->data.sequence_start.tag && event2->data.sequence_start.tag) || (event1->data.sequence_start.tag && event2->data.sequence_start.tag && strcmp((char *)event1->data.sequence_start.tag, (char *)event2->data.sequence_start.tag) != 0)) return 0; if ((event1->data.sequence_start.implicit != event2->data.sequence_start.implicit) /* || (event2->data.sequence_start.style != event2->data.sequence_start.style) */) return 0; return 1; case YAML_MAPPING_START_EVENT: if ((event1->data.mapping_start.anchor && !event2->data.mapping_start.anchor) || (!event1->data.mapping_start.anchor && event2->data.mapping_start.anchor) || (event1->data.mapping_start.anchor && event2->data.mapping_start.anchor && strcmp((char *)event1->data.mapping_start.anchor, (char *)event2->data.mapping_start.anchor) != 0)) return 0; if ((event1->data.mapping_start.tag && !event2->data.mapping_start.tag) || (!event1->data.mapping_start.tag && event2->data.mapping_start.tag) || (event1->data.mapping_start.tag && event2->data.mapping_start.tag && strcmp((char *)event1->data.mapping_start.tag, (char *)event2->data.mapping_start.tag) != 0)) return 0; if ((event1->data.mapping_start.implicit != event2->data.mapping_start.implicit) /* || (event2->data.mapping_start.style != event2->data.mapping_start.style) */) return 0; return 1; default: return 1; } } int print_output(char *name, unsigned char *buffer, size_t size, int count) { FILE *file; char data[BUFFER_SIZE]; size_t data_size = 1; size_t total_size = 0; if (count >= 0) { printf("FAILED (at the event #%d)\nSOURCE:\n", count+1); } file = fopen(name, "rb"); assert(file); while (data_size > 0) { data_size = fread(data, 1, BUFFER_SIZE, file); assert(!ferror(file)); if (!data_size) break; assert(fwrite(data, 1, data_size, stdout) == data_size); total_size += data_size; if (feof(file)) break; } fclose(file); printf("#### (length: %d)\n", total_size); printf("OUTPUT:\n%s#### (length: %d)\n", buffer, size); return 0; } int main(int argc, char *argv[]) { int number; int canonical = 0; int unicode = 0; number = 1; while (number < argc) { if (strcmp(argv[number], "-c") == 0) { canonical = 1; } else if (strcmp(argv[number], "-u") == 0) { unicode = 1; } else if (argv[number][0] == '-') { printf("Unknown option: '%s'\n", argv[number]); return 0; } if (argv[number][0] == '-') { if (number < argc-1) { memmove(argv+number, argv+number+1, (argc-number-1)*sizeof(char *)); } argc --; } else { number ++; } } if (argc < 2) { printf("Usage: %s [-c] [-u] file1.yaml ...\n", argv[0]); return 0; } for (number = 1; number < argc; number ++) { FILE *file; yaml_parser_t parser; yaml_emitter_t emitter; yaml_event_t event; unsigned char buffer[BUFFER_SIZE]; size_t written = 0; yaml_event_t events[MAX_EVENTS]; size_t event_number = 0; int done = 0; int count = 0; int error = 0; int k; memset(buffer, 0, BUFFER_SIZE); memset(events, 0, MAX_EVENTS*sizeof(yaml_event_t)); printf("[%d] Parsing, emitting, and parsing again '%s': ", number, argv[number]); fflush(stdout); file = fopen(argv[number], "rb"); assert(file); assert(yaml_parser_initialize(&parser)); yaml_parser_set_input_file(&parser, file); assert(yaml_emitter_initialize(&emitter)); if (canonical) { yaml_emitter_set_canonical(&emitter, 1); } if (unicode) { yaml_emitter_set_unicode(&emitter, 1); } yaml_emitter_set_output_string(&emitter, buffer, BUFFER_SIZE, &written); while (!done) { if (!yaml_parser_parse(&parser, &event)) { error = 1; break; } done = (event.type == YAML_STREAM_END_EVENT); assert(event_number < MAX_EVENTS); assert(copy_event(&(events[event_number++]), &event)); assert(yaml_emitter_emit(&emitter, &event) || (yaml_emitter_flush(&emitter) && print_output(argv[number], buffer, written, count))); count ++; } yaml_parser_delete(&parser); assert(!fclose(file)); yaml_emitter_delete(&emitter); if (!error) { count = done = 0; assert(yaml_parser_initialize(&parser)); yaml_parser_set_input_string(&parser, buffer, written); while (!done) { assert(yaml_parser_parse(&parser, &event) || print_output(argv[number], buffer, written, count)); done = (event.type == YAML_STREAM_END_EVENT); assert(compare_events(events+count, &event) || print_output(argv[number], buffer, written, count)); yaml_event_delete(&event); count ++; } yaml_parser_delete(&parser); } for (k = 0; k < event_number; k ++) { yaml_event_delete(events+k); } printf("PASSED (length: %d)\n", written); print_output(argv[number], buffer, written, -1); } return 0; } yaml-0.1.4/tests/run-parser.c0000644000175000017500000000222611570357736013023 00000000000000#include #include #include #ifdef NDEBUG #undef NDEBUG #endif #include int main(int argc, char *argv[]) { int number; if (argc < 2) { printf("Usage: %s file1.yaml ...\n", argv[0]); return 0; } for (number = 1; number < argc; number ++) { FILE *file; yaml_parser_t parser; yaml_event_t event; int done = 0; int count = 0; int error = 0; printf("[%d] Parsing '%s': ", number, argv[number]); fflush(stdout); file = fopen(argv[number], "rb"); assert(file); assert(yaml_parser_initialize(&parser)); yaml_parser_set_input_file(&parser, file); while (!done) { if (!yaml_parser_parse(&parser, &event)) { error = 1; break; } done = (event.type == YAML_STREAM_END_EVENT); yaml_event_delete(&event); count ++; } yaml_parser_delete(&parser); assert(!fclose(file)); printf("%s (%d events)\n", (error ? "FAILURE" : "SUCCESS"), count); } return 0; } yaml-0.1.4/tests/run-scanner.c0000644000175000017500000000222611570357736013160 00000000000000#include #include #include #ifdef NDEBUG #undef NDEBUG #endif #include int main(int argc, char *argv[]) { int number; if (argc < 2) { printf("Usage: %s file1.yaml ...\n", argv[0]); return 0; } for (number = 1; number < argc; number ++) { FILE *file; yaml_parser_t parser; yaml_token_t token; int done = 0; int count = 0; int error = 0; printf("[%d] Scanning '%s': ", number, argv[number]); fflush(stdout); file = fopen(argv[number], "rb"); assert(file); assert(yaml_parser_initialize(&parser)); yaml_parser_set_input_file(&parser, file); while (!done) { if (!yaml_parser_scan(&parser, &token)) { error = 1; break; } done = (token.type == YAML_STREAM_END_TOKEN); yaml_token_delete(&token); count ++; } yaml_parser_delete(&parser); assert(!fclose(file)); printf("%s (%d tokens)\n", (error ? "FAILURE" : "SUCCESS"), count); } return 0; } yaml-0.1.4/tests/run-loader.c0000644000175000017500000000226611570357736013001 00000000000000#include #include #include #ifdef NDEBUG #undef NDEBUG #endif #include int main(int argc, char *argv[]) { int number; if (argc < 2) { printf("Usage: %s file1.yaml ...\n", argv[0]); return 0; } for (number = 1; number < argc; number ++) { FILE *file; yaml_parser_t parser; yaml_document_t document; int done = 0; int count = 0; int error = 0; printf("[%d] Loading '%s': ", number, argv[number]); fflush(stdout); file = fopen(argv[number], "rb"); assert(file); assert(yaml_parser_initialize(&parser)); yaml_parser_set_input_file(&parser, file); while (!done) { if (!yaml_parser_load(&parser, &document)) { error = 1; break; } done = (!yaml_document_get_root_node(&document)); yaml_document_delete(&document); if (!done) count ++; } yaml_parser_delete(&parser); assert(!fclose(file)); printf("%s (%d documents)\n", (error ? "FAILURE" : "SUCCESS"), count); } return 0; } yaml-0.1.4/tests/Makefile.in0000644000175000017500000005422211571045616012621 00000000000000# Makefile.in generated by automake 1.11.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, # 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, # Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ TESTS = test-version$(EXEEXT) test-reader$(EXEEXT) check_PROGRAMS = test-version$(EXEEXT) test-reader$(EXEEXT) noinst_PROGRAMS = run-scanner$(EXEEXT) run-parser$(EXEEXT) \ run-loader$(EXEEXT) run-emitter$(EXEEXT) run-dumper$(EXEEXT) \ example-reformatter$(EXEEXT) example-reformatter-alt$(EXEEXT) \ example-deconstructor$(EXEEXT) \ example-deconstructor-alt$(EXEEXT) subdir = tests DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = PROGRAMS = $(noinst_PROGRAMS) example_deconstructor_SOURCES = example-deconstructor.c example_deconstructor_OBJECTS = example-deconstructor.$(OBJEXT) example_deconstructor_LDADD = $(LDADD) example_deconstructor_DEPENDENCIES = $(top_builddir)/src/libyaml.la example_deconstructor_alt_SOURCES = example-deconstructor-alt.c example_deconstructor_alt_OBJECTS = \ example-deconstructor-alt.$(OBJEXT) example_deconstructor_alt_LDADD = $(LDADD) example_deconstructor_alt_DEPENDENCIES = \ $(top_builddir)/src/libyaml.la example_reformatter_SOURCES = example-reformatter.c example_reformatter_OBJECTS = example-reformatter.$(OBJEXT) example_reformatter_LDADD = $(LDADD) example_reformatter_DEPENDENCIES = $(top_builddir)/src/libyaml.la example_reformatter_alt_SOURCES = example-reformatter-alt.c example_reformatter_alt_OBJECTS = example-reformatter-alt.$(OBJEXT) example_reformatter_alt_LDADD = $(LDADD) example_reformatter_alt_DEPENDENCIES = $(top_builddir)/src/libyaml.la run_dumper_SOURCES = run-dumper.c run_dumper_OBJECTS = run-dumper.$(OBJEXT) run_dumper_LDADD = $(LDADD) run_dumper_DEPENDENCIES = $(top_builddir)/src/libyaml.la run_emitter_SOURCES = run-emitter.c run_emitter_OBJECTS = run-emitter.$(OBJEXT) run_emitter_LDADD = $(LDADD) run_emitter_DEPENDENCIES = $(top_builddir)/src/libyaml.la run_loader_SOURCES = run-loader.c run_loader_OBJECTS = run-loader.$(OBJEXT) run_loader_LDADD = $(LDADD) run_loader_DEPENDENCIES = $(top_builddir)/src/libyaml.la run_parser_SOURCES = run-parser.c run_parser_OBJECTS = run-parser.$(OBJEXT) run_parser_LDADD = $(LDADD) run_parser_DEPENDENCIES = $(top_builddir)/src/libyaml.la run_scanner_SOURCES = run-scanner.c run_scanner_OBJECTS = run-scanner.$(OBJEXT) run_scanner_LDADD = $(LDADD) run_scanner_DEPENDENCIES = $(top_builddir)/src/libyaml.la test_reader_SOURCES = test-reader.c test_reader_OBJECTS = test-reader.$(OBJEXT) test_reader_LDADD = $(LDADD) test_reader_DEPENDENCIES = $(top_builddir)/src/libyaml.la test_version_SOURCES = test-version.c test_version_OBJECTS = test-version.$(OBJEXT) test_version_LDADD = $(LDADD) test_version_DEPENDENCIES = $(top_builddir)/src/libyaml.la DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/config/depcomp am__depfiles_maybe = depfiles am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ SOURCES = example-deconstructor.c example-deconstructor-alt.c \ example-reformatter.c example-reformatter-alt.c run-dumper.c \ run-emitter.c run-loader.c run-parser.c run-scanner.c \ test-reader.c test-version.c DIST_SOURCES = example-deconstructor.c example-deconstructor-alt.c \ example-reformatter.c example-reformatter-alt.c run-dumper.c \ run-emitter.c run-loader.c run-parser.c run-scanner.c \ test-reader.c test-version.c ETAGS = etags CTAGS = ctags am__tty_colors = \ red=; grn=; lgn=; blu=; std= DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DOXYGEN = @DOXYGEN@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ YAML_LT_AGE = @YAML_LT_AGE@ YAML_LT_CURRENT = @YAML_LT_CURRENT@ YAML_LT_RELEASE = @YAML_LT_RELEASE@ YAML_LT_REVISION = @YAML_LT_REVISION@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AM_CPPFLAGS = -I$(top_srcdir)/include #AM_CFLAGS = -Wno-pointer-sign LDADD = $(top_builddir)/src/libyaml.la all: all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign tests/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --foreign tests/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): clean-checkPROGRAMS: @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \ echo " rm -f" $$list; \ rm -f $$list || exit $$?; \ test -n "$(EXEEXT)" || exit 0; \ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ echo " rm -f" $$list; \ rm -f $$list clean-noinstPROGRAMS: @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \ echo " rm -f" $$list; \ rm -f $$list || exit $$?; \ test -n "$(EXEEXT)" || exit 0; \ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ echo " rm -f" $$list; \ rm -f $$list example-deconstructor$(EXEEXT): $(example_deconstructor_OBJECTS) $(example_deconstructor_DEPENDENCIES) @rm -f example-deconstructor$(EXEEXT) $(LINK) $(example_deconstructor_OBJECTS) $(example_deconstructor_LDADD) $(LIBS) example-deconstructor-alt$(EXEEXT): $(example_deconstructor_alt_OBJECTS) $(example_deconstructor_alt_DEPENDENCIES) @rm -f example-deconstructor-alt$(EXEEXT) $(LINK) $(example_deconstructor_alt_OBJECTS) $(example_deconstructor_alt_LDADD) $(LIBS) example-reformatter$(EXEEXT): $(example_reformatter_OBJECTS) $(example_reformatter_DEPENDENCIES) @rm -f example-reformatter$(EXEEXT) $(LINK) $(example_reformatter_OBJECTS) $(example_reformatter_LDADD) $(LIBS) example-reformatter-alt$(EXEEXT): $(example_reformatter_alt_OBJECTS) $(example_reformatter_alt_DEPENDENCIES) @rm -f example-reformatter-alt$(EXEEXT) $(LINK) $(example_reformatter_alt_OBJECTS) $(example_reformatter_alt_LDADD) $(LIBS) run-dumper$(EXEEXT): $(run_dumper_OBJECTS) $(run_dumper_DEPENDENCIES) @rm -f run-dumper$(EXEEXT) $(LINK) $(run_dumper_OBJECTS) $(run_dumper_LDADD) $(LIBS) run-emitter$(EXEEXT): $(run_emitter_OBJECTS) $(run_emitter_DEPENDENCIES) @rm -f run-emitter$(EXEEXT) $(LINK) $(run_emitter_OBJECTS) $(run_emitter_LDADD) $(LIBS) run-loader$(EXEEXT): $(run_loader_OBJECTS) $(run_loader_DEPENDENCIES) @rm -f run-loader$(EXEEXT) $(LINK) $(run_loader_OBJECTS) $(run_loader_LDADD) $(LIBS) run-parser$(EXEEXT): $(run_parser_OBJECTS) $(run_parser_DEPENDENCIES) @rm -f run-parser$(EXEEXT) $(LINK) $(run_parser_OBJECTS) $(run_parser_LDADD) $(LIBS) run-scanner$(EXEEXT): $(run_scanner_OBJECTS) $(run_scanner_DEPENDENCIES) @rm -f run-scanner$(EXEEXT) $(LINK) $(run_scanner_OBJECTS) $(run_scanner_LDADD) $(LIBS) test-reader$(EXEEXT): $(test_reader_OBJECTS) $(test_reader_DEPENDENCIES) @rm -f test-reader$(EXEEXT) $(LINK) $(test_reader_OBJECTS) $(test_reader_LDADD) $(LIBS) test-version$(EXEEXT): $(test_version_OBJECTS) $(test_version_DEPENDENCIES) @rm -f test-version$(EXEEXT) $(LINK) $(test_version_OBJECTS) $(test_version_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/example-deconstructor-alt.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/example-deconstructor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/example-reformatter-alt.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/example-reformatter.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run-dumper.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run-emitter.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run-loader.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run-parser.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run-scanner.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-reader.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-version.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c $< .c.obj: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) set x; \ here=`pwd`; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: CTAGS CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags check-TESTS: $(TESTS) @failed=0; all=0; xfail=0; xpass=0; skip=0; \ srcdir=$(srcdir); export srcdir; \ list=' $(TESTS) '; \ $(am__tty_colors); \ if test -n "$$list"; then \ for tst in $$list; do \ if test -f ./$$tst; then dir=./; \ elif test -f $$tst; then dir=; \ else dir="$(srcdir)/"; fi; \ if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ all=`expr $$all + 1`; \ case " $(XFAIL_TESTS) " in \ *[\ \ ]$$tst[\ \ ]*) \ xpass=`expr $$xpass + 1`; \ failed=`expr $$failed + 1`; \ col=$$red; res=XPASS; \ ;; \ *) \ col=$$grn; res=PASS; \ ;; \ esac; \ elif test $$? -ne 77; then \ all=`expr $$all + 1`; \ case " $(XFAIL_TESTS) " in \ *[\ \ ]$$tst[\ \ ]*) \ xfail=`expr $$xfail + 1`; \ col=$$lgn; res=XFAIL; \ ;; \ *) \ failed=`expr $$failed + 1`; \ col=$$red; res=FAIL; \ ;; \ esac; \ else \ skip=`expr $$skip + 1`; \ col=$$blu; res=SKIP; \ fi; \ echo "$${col}$$res$${std}: $$tst"; \ done; \ if test "$$all" -eq 1; then \ tests="test"; \ All=""; \ else \ tests="tests"; \ All="All "; \ fi; \ if test "$$failed" -eq 0; then \ if test "$$xfail" -eq 0; then \ banner="$$All$$all $$tests passed"; \ else \ if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ fi; \ else \ if test "$$xpass" -eq 0; then \ banner="$$failed of $$all $$tests failed"; \ else \ if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ fi; \ fi; \ dashes="$$banner"; \ skipped=""; \ if test "$$skip" -ne 0; then \ if test "$$skip" -eq 1; then \ skipped="($$skip test was not run)"; \ else \ skipped="($$skip tests were not run)"; \ fi; \ test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ dashes="$$skipped"; \ fi; \ report=""; \ if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ report="Please report to $(PACKAGE_BUGREPORT)"; \ test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ dashes="$$report"; \ fi; \ dashes=`echo "$$dashes" | sed s/./=/g`; \ if test "$$failed" -eq 0; then \ echo "$$grn$$dashes"; \ else \ echo "$$red$$dashes"; \ fi; \ echo "$$banner"; \ test -z "$$skipped" || echo "$$skipped"; \ test -z "$$report" || echo "$$report"; \ echo "$$dashes$$std"; \ test "$$failed" -eq 0; \ else :; fi distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: check-am all-am: Makefile $(PROGRAMS) installdirs: install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ `test -z '$(STRIP)' || \ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install mostlyclean-generic: clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." clean: clean-am clean-am: clean-checkPROGRAMS clean-generic clean-libtool \ clean-noinstPROGRAMS mostlyclean-am distclean: distclean-am -rm -rf ./$(DEPDIR) -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -rf ./$(DEPDIR) -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: .MAKE: check-am install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \ clean-checkPROGRAMS clean-generic clean-libtool \ clean-noinstPROGRAMS ctags distclean distclean-compile \ distclean-generic distclean-libtool distclean-tags distdir dvi \ dvi-am html html-am info info-am install install-am \ install-data install-data-am install-dvi install-dvi-am \ install-exec install-exec-am install-html install-html-am \ install-info install-info-am install-man install-pdf \ install-pdf-am install-ps install-ps-am install-strip \ installcheck installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags uninstall uninstall-am # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: yaml-0.1.4/tests/example-reformatter.c0000644000175000017500000001251611570357736014713 00000000000000 #include #include #include int main(int argc, char *argv[]) { int help = 0; int canonical = 0; int unicode = 0; int k; int done = 0; yaml_parser_t parser; yaml_emitter_t emitter; yaml_event_t event; /* Clear the objects. */ memset(&parser, 0, sizeof(parser)); memset(&emitter, 0, sizeof(emitter)); memset(&event, 0, sizeof(event)); /* Analyze command line options. */ for (k = 1; k < argc; k ++) { if (strcmp(argv[k], "-h") == 0 || strcmp(argv[k], "--help") == 0) { help = 1; } else if (strcmp(argv[k], "-c") == 0 || strcmp(argv[k], "--canonical") == 0) { canonical = 1; } else if (strcmp(argv[k], "-u") == 0 || strcmp(argv[k], "--unicode") == 0) { unicode = 1; } else { fprintf(stderr, "Unrecognized option: %s\n" "Try `%s --help` for more information.\n", argv[k], argv[0]); return 1; } } /* Display the help string. */ if (help) { printf("%s [--canonical] [--unicode] output\n" "or\n%s -h | --help\nReformat a YAML stream\n\nOptions:\n" "-h, --help\t\tdisplay this help and exit\n" "-c, --canonical\t\toutput in the canonical YAML format\n" "-u, --unicode\t\toutput unescaped non-ASCII characters\n", argv[0], argv[0]); return 0; } /* Initialize the parser and emitter objects. */ if (!yaml_parser_initialize(&parser)) goto parser_error; if (!yaml_emitter_initialize(&emitter)) goto emitter_error; /* Set the parser parameters. */ yaml_parser_set_input_file(&parser, stdin); /* Set the emitter parameters. */ yaml_emitter_set_output_file(&emitter, stdout); yaml_emitter_set_canonical(&emitter, canonical); yaml_emitter_set_unicode(&emitter, unicode); /* The main loop. */ while (!done) { /* Get the next event. */ if (!yaml_parser_parse(&parser, &event)) goto parser_error; /* Check if this is the stream end. */ if (event.type == YAML_STREAM_END_EVENT) { done = 1; } /* Emit the event. */ if (!yaml_emitter_emit(&emitter, &event)) goto emitter_error; } yaml_parser_delete(&parser); yaml_emitter_delete(&emitter); return 0; parser_error: /* Display a parser error message. */ switch (parser.error) { case YAML_MEMORY_ERROR: fprintf(stderr, "Memory error: Not enough memory for parsing\n"); break; case YAML_READER_ERROR: if (parser.problem_value != -1) { fprintf(stderr, "Reader error: %s: #%X at %d\n", parser.problem, parser.problem_value, parser.problem_offset); } else { fprintf(stderr, "Reader error: %s at %d\n", parser.problem, parser.problem_offset); } break; case YAML_SCANNER_ERROR: if (parser.context) { fprintf(stderr, "Scanner error: %s at line %d, column %d\n" "%s at line %d, column %d\n", parser.context, parser.context_mark.line+1, parser.context_mark.column+1, parser.problem, parser.problem_mark.line+1, parser.problem_mark.column+1); } else { fprintf(stderr, "Scanner error: %s at line %d, column %d\n", parser.problem, parser.problem_mark.line+1, parser.problem_mark.column+1); } break; case YAML_PARSER_ERROR: if (parser.context) { fprintf(stderr, "Parser error: %s at line %d, column %d\n" "%s at line %d, column %d\n", parser.context, parser.context_mark.line+1, parser.context_mark.column+1, parser.problem, parser.problem_mark.line+1, parser.problem_mark.column+1); } else { fprintf(stderr, "Parser error: %s at line %d, column %d\n", parser.problem, parser.problem_mark.line+1, parser.problem_mark.column+1); } break; default: /* Couldn't happen. */ fprintf(stderr, "Internal error\n"); break; } yaml_parser_delete(&parser); yaml_emitter_delete(&emitter); return 1; emitter_error: /* Display an emitter error message. */ switch (emitter.error) { case YAML_MEMORY_ERROR: fprintf(stderr, "Memory error: Not enough memory for emitting\n"); break; case YAML_WRITER_ERROR: fprintf(stderr, "Writer error: %s\n", emitter.problem); break; case YAML_EMITTER_ERROR: fprintf(stderr, "Emitter error: %s\n", emitter.problem); break; default: /* Couldn't happen. */ fprintf(stderr, "Internal error\n"); break; } yaml_parser_delete(&parser); yaml_emitter_delete(&emitter); return 1; } yaml-0.1.4/tests/example-deconstructor-alt.c0000644000175000017500000010057611570357736016041 00000000000000 #include #include #include int main(int argc, char *argv[]) { int help = 0; int canonical = 0; int unicode = 0; int k; int done = 0; yaml_parser_t parser; yaml_emitter_t emitter; yaml_event_t input_event; yaml_document_t output_document; int root; /* Clear the objects. */ memset(&parser, 0, sizeof(parser)); memset(&emitter, 0, sizeof(emitter)); memset(&input_event, 0, sizeof(input_event)); memset(&output_document, 0, sizeof(output_document)); /* Analyze command line options. */ for (k = 1; k < argc; k ++) { if (strcmp(argv[k], "-h") == 0 || strcmp(argv[k], "--help") == 0) { help = 1; } else if (strcmp(argv[k], "-c") == 0 || strcmp(argv[k], "--canonical") == 0) { canonical = 1; } else if (strcmp(argv[k], "-u") == 0 || strcmp(argv[k], "--unicode") == 0) { unicode = 1; } else { fprintf(stderr, "Unrecognized option: %s\n" "Try `%s --help` for more information.\n", argv[k], argv[0]); return 1; } } /* Display the help string. */ if (help) { printf("%s . */ if (input_event.data.stream_start.encoding) { yaml_encoding_t encoding = input_event.data.stream_start.encoding; key = yaml_document_add_scalar(&output_document, NULL, "encoding", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, NULL, (encoding == YAML_UTF8_ENCODING ? "utf-8" : encoding == YAML_UTF16LE_ENCODING ? "utf-16-le" : encoding == YAML_UTF16BE_ENCODING ? "utf-16-be" : "unknown"), -1, YAML_PLAIN_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, properties, key, value)) goto document_error; } break; case YAML_STREAM_END_EVENT: /* Add 'type': 'STREAM-END'. */ key = yaml_document_add_scalar(&output_document, NULL, "type", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, NULL, "STREAM-END", -1, YAML_PLAIN_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, properties, key, value)) goto document_error; break; case YAML_DOCUMENT_START_EVENT: /* Add 'type': 'DOCUMENT-START'. */ key = yaml_document_add_scalar(&output_document, NULL, "type", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, NULL, "DOCUMENT-START", -1, YAML_PLAIN_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, properties, key, value)) goto document_error; /* Display the output_document version numbers. */ if (input_event.data.document_start.version_directive) { yaml_version_directive_t *version = input_event.data.document_start.version_directive; char number[64]; /* Add 'version': {}. */ key = yaml_document_add_scalar(&output_document, NULL, "version", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; map = yaml_document_add_mapping(&output_document, NULL, YAML_FLOW_MAPPING_STYLE); if (!map) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, properties, key, map)) goto document_error; /* Add 'major': . */ key = yaml_document_add_scalar(&output_document, NULL, "major", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; sprintf(number, "%d", version->major); value = yaml_document_add_scalar(&output_document, YAML_INT_TAG, number, -1, YAML_PLAIN_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, map, key, value)) goto document_error; /* Add 'minor': . */ key = yaml_document_add_scalar(&output_document, NULL, "minor", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; sprintf(number, "%d", version->minor); value = yaml_document_add_scalar(&output_document, YAML_INT_TAG, number, -1, YAML_PLAIN_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, map, key, value)) goto document_error; } /* Display the output_document tag directives. */ if (input_event.data.document_start.tag_directives.start != input_event.data.document_start.tag_directives.end) { yaml_tag_directive_t *tag; /* Add 'tags': []. */ key = yaml_document_add_scalar(&output_document, NULL, "tags", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; seq = yaml_document_add_sequence(&output_document, NULL, YAML_BLOCK_SEQUENCE_STYLE); if (!seq) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, properties, key, seq)) goto document_error; for (tag = input_event.data.document_start.tag_directives.start; tag != input_event.data.document_start.tag_directives.end; tag ++) { /* Add {}. */ map = yaml_document_add_mapping(&output_document, NULL, YAML_FLOW_MAPPING_STYLE); if (!map) goto document_error; if (!yaml_document_append_sequence_item(&output_document, seq, map)) goto document_error; /* Add 'handle': . */ key = yaml_document_add_scalar(&output_document, NULL, "handle", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, NULL, tag->handle, -1, YAML_DOUBLE_QUOTED_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, map, key, value)) goto document_error; /* Add 'prefix': . */ key = yaml_document_add_scalar(&output_document, NULL, "prefix", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, NULL, tag->prefix, -1, YAML_DOUBLE_QUOTED_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, map, key, value)) goto document_error; } } /* Add 'implicit': . */ key = yaml_document_add_scalar(&output_document, NULL, "implicit", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG, (input_event.data.document_start.implicit ? "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, properties, key, value)) goto document_error; break; case YAML_DOCUMENT_END_EVENT: /* Add 'type': 'DOCUMENT-END'. */ key = yaml_document_add_scalar(&output_document, NULL, "type", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, NULL, "DOCUMENT-END", -1, YAML_PLAIN_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, properties, key, value)) goto document_error; /* Add 'implicit': . */ key = yaml_document_add_scalar(&output_document, NULL, "implicit", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG, (input_event.data.document_end.implicit ? "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, properties, key, value)) goto document_error; break; case YAML_ALIAS_EVENT: /* Add 'type': 'ALIAS'. */ key = yaml_document_add_scalar(&output_document, NULL, "type", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, NULL, "ALIAS", -1, YAML_PLAIN_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, properties, key, value)) goto document_error; /* Add 'anchor': . */ key = yaml_document_add_scalar(&output_document, NULL, "anchor", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, NULL, input_event.data.alias.anchor, -1, YAML_DOUBLE_QUOTED_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, properties, key, value)) goto document_error; break; case YAML_SCALAR_EVENT: /* Add 'type': 'SCALAR'. */ key = yaml_document_add_scalar(&output_document, NULL, "type", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, NULL, "SCALAR", -1, YAML_PLAIN_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, properties, key, value)) goto document_error; /* Add 'anchor': . */ if (input_event.data.scalar.anchor) { key = yaml_document_add_scalar(&output_document, NULL, "anchor", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, NULL, input_event.data.scalar.anchor, -1, YAML_DOUBLE_QUOTED_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, properties, key, value)) goto document_error; } /* Add 'tag': . */ if (input_event.data.scalar.tag) { key = yaml_document_add_scalar(&output_document, NULL, "tag", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, NULL, input_event.data.scalar.tag, -1, YAML_DOUBLE_QUOTED_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, properties, key, value)) goto document_error; } /* Add 'value': . */ key = yaml_document_add_scalar(&output_document, NULL, "value", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, NULL, input_event.data.scalar.value, input_event.data.scalar.length, YAML_DOUBLE_QUOTED_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, properties, key, value)) goto document_error; /* Display if the scalar tag is implicit. */ /* Add 'implicit': {} */ key = yaml_document_add_scalar(&output_document, NULL, "version", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; map = yaml_document_add_mapping(&output_document, NULL, YAML_FLOW_MAPPING_STYLE); if (!map) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, properties, key, map)) goto document_error; /* Add 'plain': . */ key = yaml_document_add_scalar(&output_document, NULL, "plain", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG, (input_event.data.scalar.plain_implicit ? "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, map, key, value)) goto document_error; /* Add 'quoted': . */ key = yaml_document_add_scalar(&output_document, NULL, "quoted", -1, YAML_PLAIN_SCALAR_STYLE); if (!key) goto document_error; value = yaml_document_add_scalar(&output_document, YAML_BOOL_TAG, (input_event.data.scalar.quoted_implicit ? "true" : "false"), -1, YAML_PLAIN_SCALAR_STYLE); if (!value) goto document_error; if (!yaml_document_append_mapping_pair(&output_document, map, key, value)) goto document_error; /* Display the style information. */ if (input_event.data.scalar.style) { yaml_scalar_style_t style = input_event.data.scalar.style; /* Add 'style':