Changeset 261
- Timestamp:
- 12/25/07 18:19:23 (4 years ago)
- Location:
- libyaml/trunk
- Files:
-
- 3 modified
-
include/yaml.h (modified) (66 diffs)
-
src/api.c (modified) (49 diffs)
-
src/yaml_private.h (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libyaml/trunk/include/yaml.h
r243 r261 71 71 72 72 /** 73 * @defgroup styles Error Handling 74 * @{ 75 */ 76 77 /** Many bad things could happen with the parser and the emitter. */ 78 typedef enum yaml_error_type_e { 79 /** No error is produced. */ 80 YAML_NO_ERROR, 81 82 /** Cannot allocate or reallocate a block of memory. */ 83 YAML_MEMORY_ERROR, 84 85 /** Cannot read from the input stream. */ 86 YAML_READER_ERROR, 87 /** Cannot decode the input stream. */ 88 YAML_DECODER_ERROR, 89 90 /** Cannot scan a YAML token. */ 91 YAML_SCANNER_ERROR, 92 /** Cannot parse a YAML production. */ 93 YAML_PARSER_ERROR, 94 /** Cannot compose a YAML document. */ 95 YAML_COMPOSER_ERROR, 96 97 /** Cannot write into the output stream. */ 98 YAML_WRITER_ERROR, 99 100 /** Cannot emit a YAML event. */ 101 YAML_EMITTER_ERROR, 102 /** Cannot serialize a YAML document. */ 103 YAML_SERIALIZER_ERROR 104 } yaml_error_type_t; 105 106 /** The pointer position. */ 107 typedef struct yaml_mark_s { 108 /** The character number (starting from zero). */ 109 size_t index; 110 111 /** The mark line (starting from zero). */ 112 size_t line; 113 114 /** The mark column (starting from zero). */ 115 size_t column; 116 } yaml_mark_t; 117 118 /** The error details. */ 119 typedef struct yaml_error_s { 120 121 /** The error type. */ 122 yaml_error_type_t type; 123 124 /** The detailed error information. */ 125 union { 126 127 /** 128 * A problem while reading the stream (@c YAML_READER_ERROR or 129 * @c YAML_DECODER_ERROR). 130 */ 131 struct { 132 /** The problem description. */ 133 const char *problem; 134 /** The stream offset. */ 135 size_t offset; 136 /** The problematic octet or character (@c -1 if not applicable). */ 137 int value; 138 } reading; 139 140 /** 141 * A problem while loading the stream (@c YAML_SCANNER_ERROR, 142 * @c YAML_PARSER_ERROR, or @c YAML_COMPOSER_ERROR). 143 */ 144 struct { 145 /** The problem description. */ 146 const char *problem; 147 /** The problem mark. */ 148 yaml_mark_t problem_mark; 149 /** The context in which the problem occured 150 * (@c NULL if not applicable). 151 */ 152 const char *context; 153 /** The context mark (if @c problem_mark is not @c NULL). **/ 154 yaml_mark_t context_mark; 155 } loading; 156 157 /** A problem while writing into the stream (@c YAML_WRITER_ERROR). */ 158 struct { 159 /** The problem description. */ 160 const char *problem; 161 /** The stream offset. */ 162 size_t offset; 163 } writing; 164 165 /** A problem while dumping into the stream (@c YAML_EMITTER_ERROR and 166 * @c YAML_SERIALIZER_ERROR). 167 */ 168 struct { 169 /** The problem description. */ 170 const char *problem; 171 } dumping; 172 173 } data; 174 175 } yaml_error_t; 176 177 178 /** @} */ 179 180 /** 73 181 * @defgroup basic Basic Types 74 182 * @{ … … 107 215 108 216 /** Line break types. */ 109 110 217 typedef enum yaml_break_e { 111 218 /** Let the parser choose the break type. */ … … 119 226 } yaml_break_t; 120 227 121 /** Many bad things could happen with the parser and emitter. */122 typedef enum yaml_error_type_e {123 /** No error is produced. */124 YAML_NO_ERROR,125 126 /** Cannot allocate or reallocate a block of memory. */127 YAML_MEMORY_ERROR,128 129 /** Cannot read or decode the input stream. */130 YAML_READER_ERROR,131 /** Cannot scan the input stream. */132 YAML_SCANNER_ERROR,133 /** Cannot parse the input stream. */134 YAML_PARSER_ERROR,135 /** Cannot compose a YAML document. */136 YAML_COMPOSER_ERROR,137 138 /** Cannot write to the output stream. */139 YAML_WRITER_ERROR,140 /** Cannot emit a YAML stream. */141 YAML_EMITTER_ERROR142 } yaml_error_type_t;143 144 /** The pointer position. */145 typedef struct yaml_mark_s {146 /** The position index. */147 size_t index;148 149 /** The position line. */150 size_t line;151 152 /** The position column. */153 size_t column;154 } yaml_mark_t;155 156 228 /** @} */ 157 229 … … 279 351 } stream_start; 280 352 353 /** The version directive (for @c YAML_VERSION_DIRECTIVE_TOKEN). */ 354 struct { 355 /** The major version number. */ 356 int major; 357 /** The minor version number. */ 358 int minor; 359 } version_directive; 360 361 /** The tag directive (for @c YAML_TAG_DIRECTIVE_TOKEN). */ 362 struct { 363 /** The tag handle. */ 364 yaml_char_t *handle; 365 /** The tag prefix. */ 366 yaml_char_t *prefix; 367 } tag_directive; 368 281 369 /** The alias (for @c YAML_ALIAS_TOKEN). */ 282 370 struct { … … 309 397 } scalar; 310 398 311 /** The version directive (for @c YAML_VERSION_DIRECTIVE_TOKEN). */312 struct {313 /** The major version number. */314 int major;315 /** The minor version number. */316 int minor;317 } version_directive;318 319 /** The tag directive (for @c YAML_TAG_DIRECTIVE_TOKEN). */320 struct {321 /** The tag handle. */322 yaml_char_t *handle;323 /** The tag prefix. */324 yaml_char_t *prefix;325 } tag_directive;326 327 399 } data; 328 400 … … 335 407 336 408 /** 409 * Allocate a new empty token object. 410 * 411 * @returns a new token object or @c NULL on error. 412 */ 413 414 YAML_DECLARE(yaml_token_t *) 415 yaml_token_new(void); 416 417 /** 418 * Delete and deallocate a token object. 419 * 420 * @param[in,out] token A token object. 421 */ 422 423 YAML_DECLARE(void) 424 yaml_token_delete(yaml_token_t *token); 425 426 /** 427 * Duplicate a token object. 428 * 429 * @param[in,out] token An empty token object. 430 * @param[in] model A token to copy. 431 * 432 * @returns @c 1 if the function succeeded, @c 0 on error. 433 */ 434 435 YAML_DECLARE(int) 436 yaml_token_duplicate(yaml_token_t *token, yaml_token_t *model); 437 438 /** 337 439 * Free any memory allocated for a token object. 338 440 * … … 341 443 342 444 YAML_DECLARE(void) 343 yaml_token_de lete(yaml_token_t *token);445 yaml_token_destroy(yaml_token_t *token); 344 446 345 447 /** @} */ … … 403 505 /** The list of tag directives. */ 404 506 struct { 405 /** The beginning of the tag directives list. */ 406 yaml_tag_directive_t *start; 407 /** The end of the tag directives list. */ 408 yaml_tag_directive_t *end; 507 /** The beginning of the list. */ 508 yaml_tag_directive_t *list; 509 /** The length of the list. */ 510 size_t length; 511 /** The capacity of the list. */ 512 size_t capacity; 409 513 } tag_directives; 410 514 411 515 /** Is the document indicator implicit? */ 412 int i mplicit;516 int is_implicit; 413 517 } document_start; 414 518 … … 416 520 struct { 417 521 /** Is the document end indicator implicit? */ 418 int i mplicit;522 int is_implicit; 419 523 } document_end; 420 524 … … 436 540 size_t length; 437 541 /** Is the tag optional for the plain style? */ 438 int plain_implicit;542 int is_plain_implicit; 439 543 /** Is the tag optional for any non-plain style? */ 440 int quoted_implicit;544 int is_quoted_implicit; 441 545 /** The scalar style. */ 442 546 yaml_scalar_style_t style; … … 450 554 yaml_char_t *tag; 451 555 /** Is the tag optional? */ 452 int i mplicit;556 int is_implicit; 453 557 /** The sequence style. */ 454 558 yaml_sequence_style_t style; … … 462 566 yaml_char_t *tag; 463 567 /** Is the tag optional? */ 464 int i mplicit;568 int is_implicit; 465 569 /** The mapping style. */ 466 570 yaml_mapping_style_t style; … … 477 581 478 582 /** 479 * Create the STREAM-START event. 583 * Allocate a new empty event object. 584 * 585 * @returns a new event object or @c NULL on error. 586 */ 587 588 YAML_DECLARE(yaml_event_t *) 589 yaml_event_new(void); 590 591 /** 592 * Delete and deallocate an event object. 593 * 594 * @param[in,out] event An event object. 595 */ 596 597 YAML_DECLARE(void) 598 yaml_event_delete(yaml_event_t *event); 599 600 /** 601 * Duplicate a event object. 602 * 603 * @param[in,out] event An empty event object. 604 * @param[in] model An event to copy. 605 * 606 * @returns @c 1 if the function succeeded, @c 0 on error. 607 */ 608 609 YAML_DECLARE(int) 610 yaml_event_duplicate(yaml_event_t *event, yaml_event_t *model); 611 612 /** 613 * Create a STREAM-START event. 614 * 615 * This function never fails. 480 616 * 481 617 * @param[out] event An empty event object. … … 486 622 487 623 YAML_DECLARE(int) 488 yaml_ stream_start_event_initialize(yaml_event_t *event,624 yaml_event_create_stream_start(yaml_event_t *event, 489 625 yaml_encoding_t encoding); 490 626 491 627 /** 492 * Create the STREAM-END event. 628 * Create a STREAM-END event. 629 * 630 * This function never fails. 493 631 * 494 632 * @param[out] event An empty event object. … … 498 636 499 637 YAML_DECLARE(int) 500 yaml_ stream_end_event_initialize(yaml_event_t *event);638 yaml_event_create_stream_end(yaml_event_t *event); 501 639 502 640 /** 503 641 * Create the DOCUMENT-START event. 504 *505 * The @a implicit argument is considered as a stylistic parameter and may be506 * ignored by the emitter.507 642 * 508 643 * @param[out] event An empty event object. 509 644 * @param[in] version_directive The %YAML directive value or 510 645 * @c NULL. 511 * @param[in] tag_directives_ startThe beginning of the %TAG512 * directives list .513 * @param[in] tag_directives_end The end of the %TAG directives514 * list.515 * @param[in] implicit If the document start indicatoris516 * implicit.517 * 518 * @returns @c 1 if the function succeeded, @c 0 on error.519 * /520 521 YAML_DECLARE(int) 522 yaml_document_start_event_initialize(yaml_event_t *event, 523 yaml_version_directive_t *version_directive,524 yaml_tag_directive_t *tag_directives_start,525 yaml_tag_directive_t *tag_directives_end,526 int i mplicit);646 * @param[in] tag_directives_list The beginning of the %TAG 647 * directives list or @c NULL. The 648 * list ends with @c (NULL,NULL). 649 * @param[in] is_implicit Set if the document start 650 * indicator is optional. This 651 * parameter is stylistic and may be 652 * ignored by the parser. 653 * 654 * @returns @c 1 if the function succeeded, @c 0 on error. 655 */ 656 657 YAML_DECLARE(int) 658 yaml_event_create_document_start(yaml_event_t *event, 659 const yaml_version_directive_t *version_directive, 660 const yaml_tag_directive_t *tag_directives, 661 int is_implicit); 527 662 528 663 /** 529 664 * Create the DOCUMENT-END event. 530 665 * 531 * The @a implicit argument is considered as a stylistic parameter and may be532 * ignored by the emitter.533 *534 666 * @param[out] event An empty event object. 535 * @param[in] implicit If the document end indicator is implicit. 536 * 537 * @returns @c 1 if the function succeeded, @c 0 on error. 538 */ 539 540 YAML_DECLARE(int) 541 yaml_document_end_event_initialize(yaml_event_t *event, int implicit); 667 * @param[in] is_implicit Set if the document end indicator is optional. 668 * This parameter is stylistic and may be ignored 669 * by the parser. 670 * 671 * @returns @c 1 if the function succeeded, @c 0 on error. 672 */ 673 674 YAML_DECLARE(int) 675 yaml_event_create_document_end(yaml_event_t *event, int is_implicit); 542 676 543 677 /** … … 551 685 552 686 YAML_DECLARE(int) 553 yaml_ alias_event_initialize(yaml_event_t *event,yaml_char_t *anchor);687 yaml_event_create_alias(yaml_event_t *event, const yaml_char_t *anchor); 554 688 555 689 /** 556 690 * Create a SCALAR event. 557 691 * 558 * The @a style argument may be ignored by the emitter.559 * 560 * Either the @a tag attribute or one of the @a plain_implicit and561 * @a quoted_implicit flags must be set.562 * 563 * @param[out] event An empty event object.564 * @param[in] anchor The scalar anchor or @c NULL.565 * @param[in] tag The scalar tag or @c NULL.566 * @param[in] value The scalar value.567 * @param[in] length The length of the scalar value.568 * @param[in] plain_implicit If the tag may be omitted for the plain569 * style.570 * @param[in] quoted_implicit If the tag may be omitted for any571 * non-plain style.572 * @param[in] style The scalar style.573 * 574 * @returns @c 1 if the function succeeded, @c 0 on error. 575 */ 576 577 YAML_DECLARE(int) 578 yaml_ scalar_event_initialize(yaml_event_t *event,579 yaml_char_t *anchor,yaml_char_t *tag,580 yaml_char_t *value, int length,581 int plain_implicit, intquoted_implicit,692 * @param[out] event An empty event object. 693 * @param[in] anchor The scalar anchor or @c NULL. 694 * @param[in] tag The scalar tag or @c NULL. If 695 * latter, one of the 696 * @a is_plain_implicit and 697 * @a is_quoted_implicit flags must 698 * be set. 699 * @param[in] value The scalar value. 700 * @param[in] length The length of the scalar value. 701 * @param[in] is_plain_implicit Set if the tag may be omitted for 702 * the plain style. 703 * @param[in] is_quoted_implicit Set if the tag may be omitted for 704 * any non-plain style. 705 * @param[in] style The scalar style. This attribute 706 * may be ignored by the emitter. 707 * 708 * @returns @c 1 if the function succeeded, @c 0 on error. 709 */ 710 711 YAML_DECLARE(int) 712 yaml_event_create_scalar(yaml_event_t *event, 713 const yaml_char_t *anchor, const yaml_char_t *tag, 714 const yaml_char_t *value, size_t length, 715 int is_plain_implicit, int is_quoted_implicit, 582 716 yaml_scalar_style_t style); 583 717 584 718 /** 585 719 * Create a SEQUENCE-START event. 586 *587 * The @a style argument may be ignored by the emitter.588 *589 * Either the @a tag attribute or the @a implicit flag must be set.590 720 * 591 721 * @param[out] event An empty event object. 592 722 * @param[in] anchor The sequence anchor or @c NULL. 593 * @param[in] tag The sequence tag or @c NULL. 594 * @param[in] implicit If the tag may be omitted. 595 * @param[in] style The sequence style. 596 * 597 * @returns @c 1 if the function succeeded, @c 0 on error. 598 */ 599 600 YAML_DECLARE(int) 601 yaml_sequence_start_event_initialize(yaml_event_t *event, 602 yaml_char_t *anchor, yaml_char_t *tag, int implicit, 603 yaml_sequence_style_t style); 723 * @param[in] tag The sequence tag or @c NULL. If latter, the 724 * @a is_implicit flag must be set. 725 * @param[in] is_implicit Set if the tag may be omitted. 726 * @param[in] style The sequence style. This attribute may be 727 * ignored by the parser. 728 * 729 * @returns @c 1 if the function succeeded, @c 0 on error. 730 */ 731 732 YAML_DECLARE(int) 733 yaml_event_create_sequence_start(yaml_event_t *event, 734 const yaml_char_t *anchor, const yaml_char_t *tag, 735 int is_implicit, yaml_sequence_style_t style); 604 736 605 737 /** … … 612 744 613 745 YAML_DECLARE(int) 614 yaml_ sequence_end_event_initialize(yaml_event_t *event);746 yaml_event_create_sequence_end(yaml_event_t *event); 615 747 616 748 /** 617 749 * Create a MAPPING-START event. 618 *619 * The @a style argument may be ignored by the emitter.620 *621 * Either the @a tag attribute or the @a implicit flag must be set.622 750 * 623 751 * @param[out] event An empty event object. 624 752 * @param[in] anchor The mapping anchor or @c NULL. 625 * @param[in] tag The mapping tag or @c NULL. 626 * @param[in] implicit If the tag may be omitted. 753 * @param[in] tag The mapping tag or @c NULL. If latter, the 754 * @a is_implicit flag must be set. 755 * @param[in] is_implicit Set if the tag may be omitted. 627 756 * @param[in] style The mapping style. 628 757 * … … 631 760 632 761 YAML_DECLARE(int) 633 yaml_ mapping_start_event_initialize(yaml_event_t *event,634 yaml_char_t *anchor, yaml_char_t *tag, int implicit,635 yaml_mapping_style_t style);762 yaml_event_create_mapping_start(yaml_event_t *event, 763 const yaml_char_t *anchor, const yaml_char_t *tag, 764 int is_implicit, yaml_mapping_style_t style); 636 765 637 766 /** … … 644 773 645 774 YAML_DECLARE(int) 646 yaml_ mapping_end_event_initialize(yaml_event_t *event);775 yaml_event_create_mapping_end(yaml_event_t *event); 647 776 648 777 /** … … 653 782 654 783 YAML_DECLARE(void) 655 yaml_event_de lete(yaml_event_t *event);784 yaml_event_destroy(yaml_event_t *event); 656 785 657 786 /** @} */ … … 672 801 /** The tag @c !!float for float values. */ 673 802 #define YAML_FLOAT_TAG "tag:yaml.org,2002:float" 674 /** The tag @c !!timestamp for date and time values. */675 #define YAML_TIMESTAMP_TAG "tag:yaml.org,2002:timestamp"676 803 677 804 /** The tag @c !!seq is used to denote sequences. */ … … 700 827 } yaml_node_type_t; 701 828 829 /** Arc types. */ 830 typedef enum yaml_arc_type_e { 831 /** An empty arc. */ 832 YAML_NO_ARC, 833 834 /** An item of a sequence. */ 835 YAML_SEQUENCE_ITEM_ARC, 836 /** A key of a mapping. */ 837 YAML_MAPPING_KEY_ARC, 838 /** A value of a mapping. */ 839 YAML_MAPPING_VALUE_ARC 840 } yaml_arc_type_t; 841 702 842 /** The forward definition of a document node structure. */ 703 843 typedef struct yaml_node_s yaml_node_t; … … 714 854 } yaml_node_pair_t; 715 855 856 /** An element of a path in a YAML document. */ 857 typedef struct yaml_arc_s { 858 /** The arc type. */ 859 yaml_arc_type_t type; 860 /** The collection node. */ 861 int node; 862 /** A pointer in the collection node. */ 863 int item; 864 } yaml_arc_t; 865 716 866 /** The node structure. */ 717 867 struct yaml_node_s { … … 720 870 yaml_node_type_t type; 721 871 872 /** The node anchor. */ 873 yaml_char_t *anchor; 722 874 /** The node tag. */ 723 875 yaml_char_t *tag; … … 738 890 /** The sequence parameters (for @c YAML_SEQUENCE_NODE). */ 739 891 struct { 740 /** The stackof sequence items. */892 /** The list of sequence items. */ 741 893 struct { 742 /** The beginning of the stack. */743 yaml_node_item_t * start;744 /** The end of the stack. */745 yaml_node_item_t *end;746 /** The top of the stack. */747 yaml_node_item_t *top;894 /** The beginning of the list. */ 895 yaml_node_item_t *list; 896 /** The length of the list. */ 897 size_t length; 898 /** The capacity of the list. */ 899 size_t capacity; 748 900 } items; 749 901 /** The sequence style. */ … … 753 905 /** The mapping parameters (for @c YAML_MAPPING_NODE). */ 754 906 struct { 755 /** The stackof mapping pairs (key, value). */907 /** The list of mapping pairs (key, value). */ 756 908 struct { 757 /** The beginning of the stack. */758 yaml_node_pair_t * start;759 /** The end of the stack. */760 yaml_node_pair_t *end;761 /** The top of the stack. */762 yaml_node_pair_t *top;909 /** The beginning of the list. */ 910 yaml_node_pair_t *list; 911 /** The length of the list. */ 912 size_t length; 913 /** The capacity of the list. */ 914 size_t capacity; 763 915 } pairs; 764 916 /** The mapping style. */ … … 775 927 }; 776 928 929 /** The incomplete node structure. */ 930 typedef struct yaml_incomplete_node_s { 931 932 /** The node type. */ 933 yaml_node_type_t type; 934 935 /** The path to the new node. */ 936 struct { 937 /** The beginning of the list. */ 938 yaml_arc_t *list; 939 /** The length of the list. */ 940 size_t length; 941 /** The capacity of the list. */ 942 size_t capacity; 943 } path; 944 945 /** The node data. */ 946 union { 947 948 /** The scalar parameters (for @c YAML_SCALAR_NODE). */ 949 struct { 950 /** The scalar value. */ 951 yaml_char_t *value; 952 /** The length of the scalar value. */ 953 size_t length; 954 /** Set if the scalar is plain. */ 955 int is_plain; 956 } scalar; 957 958 } data; 959 960 /** The position of the node. */ 961 yaml_mark_t mark; 962 963 } yaml_incomplete_node_t; 964 777 965 /** The document structure. */ 778 966 typedef struct yaml_document_s { … … 780 968 /** The document nodes. */ 781 969 struct { 782 /** The beginning of the stack. */783 yaml_node_t * start;784 /** The end of the stack. */785 yaml_node_t *end;786 /** The top of the stack. */787 yaml_node_t *top;970 /** The beginning of the list. */ 971 yaml_node_t *list; 972 /** The length of the list. */ 973 size_t length; 974 /** The capacity of the list. */ 975 size_t capacity; 788 976 } nodes; 789 977 … … 793 981 /** The list of tag directives. */ 794 982 struct { 795 /** The beginning of the tag directives list. */ 796 yaml_tag_directive_t *start; 797 /** The end of the tag directives list. */ 798 yaml_tag_directive_t *end; 983 /** The beginning of the tag directive list. */ 984 yaml_tag_directive_t *list; 985 /** The length of the tag directive list. */ 986 size_t length; 987 /** The capacity of the tag directive list. */ 988 size_t capacity; 799 989 } tag_directives; 800 990 801 991 /** Is the document start indicator implicit? */ 802 int start_implicit;992 int is_start_implicit; 803 993 /** Is the document end indicator implicit? */ 804 int end_implicit;994 int is_end_implicit; 805 995 806 996 /** The beginning of the document. */ … … 811 1001 } yaml_document_t; 812 1002 1003 #if 0 1004 1005 /** 1006 * Allocate a new empty document object. 1007 * 1008 * @returns a new document object or @c NULL on error. 1009 */ 1010 1011 YAML_DECLARE(yaml_document_t *) 1012 yaml_document_new(void); 1013 1014 /** 1015 * Delete and deallocatge a document object. 1016 * 1017 * @param[in,out] document A document object. 1018 */ 1019 1020 YAML_DECLARE(void) 1021 yaml_document_delete(yaml_document_t *document); 1022 1023 /** 1024 * Duplicate a document object. 1025 * 1026 * @param[in,out] document An empty document object. 1027 * @param[in] model A document to copy. 1028 * 1029 * @returns @c 1 if the function succeeded, @c 0 on error. 1030 */ 1031 1032 YAML_DECLARE(int) 1033 yaml_document_duplicate(yaml_document_t *document, yaml_document_t *model); 1034 813 1035 /** 814 1036 * Create a YAML document. … … 817 1039 * @param[in] version_directive The %YAML directive value or 818 1040 * @c NULL. 819 * @param[in] tag_directives_start The beginning of the %TAG 820 * directives list. 821 * @param[in] tag_directives_end The end of the %TAG directives 822 * list. 823 * @param[in] start_implicit If the document start indicator is 1041 * @param[in] tag_directives The list of the %TAG directives or 1042 * @c NULL. The list must end with 1043 * the pair @c (NULL,NULL). 1044 * @param[in] is_start_implicit If the document start indicator is 824 1045 * implicit. 825 * @param[in] end_implicitIf the document end indicator is1046 * @param[in] is_end_implicit If the document end indicator is 826 1047 * implicit. 827 1048 * … … 830 1051 831 1052 YAML_DECLARE(int) 832 yaml_document_ initialize(yaml_document_t *document,1053 yaml_document_create(yaml_document_t *document, 833 1054 yaml_version_directive_t *version_directive, 834 yaml_tag_directive_t *tag_directives_start, 835 yaml_tag_directive_t *tag_directives_end, 836 int start_implicit, int end_implicit); 1055 yaml_tag_directive_t *tag_directives, 1056 int is_start_implicit, int is_end_implicit); 837 1057 838 1058 /** … … 843 1063 844 1064 YAML_DECLARE(void) 845 yaml_document_de lete(yaml_document_t *document);1065 yaml_document_destroy(yaml_document_t *document); 846 1066 847 1067 /** … … 849 1069 * 850 1070 * The pointer returned by this function is valid until any of the functions 851 * modifying the documents arecalled.1071 * modifying the documents is called. 852 1072 * 853 1073 * @param[in] document A document object. … … 866 1086 * 867 1087 * The pointer returned by this function is valid until any of the functions 868 * modifying the documents arecalled.1088 * modifying the documents is called. 869 1089 * 870 1090 * An empty document produced by the parser signifies the end of a YAML … … 885 1105 * 886 1106 * @param[in,out] document A document object. 1107 * @param[in] anchor A preferred anchor for the node or @c NULL. 887 1108 * @param[in] tag The scalar tag. 888 1109 * @param[in] value The scalar value. … … 895 1116 YAML_DECLARE(int) 896 1117 yaml_document_add_scalar(yaml_document_t *document, 897 yaml_char_t * tag, yaml_char_t *value, int length,898 yaml_scalar_style_t style);1118 yaml_char_t *anchor, yaml_char_t *tag, yaml_char_t *value, 1119 size_t length, yaml_scalar_style_t style); 899 1120 900 1121 /** … … 904 1125 * 905 1126 * @param[in,out] document A document object. 1127 * @param[in] anchor A preferred anchor for the node or @c NULL. 906 1128 * @param[in] tag The sequence tag. 907 1129 * @param[in] style The sequence style. … … 912 1134 YAML_DECLARE(int) 913 1135 yaml_document_add_sequence(yaml_document_t *document, 914 yaml_char_t * tag, yaml_sequence_style_t style);1136 yaml_char_t *anchor, yaml_char_t *tag, yaml_sequence_style_t style); 915 1137 916 1138 /** … … 920 1142 * 921 1143 * @param[in,out] document A document object. 1144 * @param[in] anchor A preferred anchor for the node or @c NULL. 922 1145 * @param[in] tag The sequence tag. 923 1146 * @param[in] style The sequence style. … … 928 1151 YAML_DECLARE(int) 929 1152 yaml_document_add_mapping(yaml_document_t *document, 930 yaml_char_t * tag, yaml_mapping_style_t style);1153 yaml_char_t *anchor, yaml_char_t *tag, yaml_mapping_style_t style); 931 1154 932 1155 /** … … 959 1182 int mapping, int key, int value); 960 1183 961 /** @} */ 962 963 /** 964 * @defgroup parser ParserDefinitions1184 #endif 1185 1186 /** 1187 * @defgroup callbacks Callback Definitions 965 1188 * @{ 966 1189 */ … … 970 1193 * 971 1194 * The read handler is called when the parser needs to read more bytes from the 972 * source. The handler should write not more than @a size bytes to the @a 973 * buffer. The number of written bytes should be set to the @a length variable. 1195 * source. The handler should read no more than @a size bytes and write them 1196 * to the @a buffer. The number of the read bytes should be returned using the 1197 * @a size_read variable. If the handler reaches the stream end, @a size_read 1198 * must be set to @c 0. 974 1199 * 975 1200 * @param[in,out] data A pointer to an application data specified by 976 * yaml_parser_set_input().1201 * @c yaml_parser_set_reader(). 977 1202 * @param[out] buffer The buffer to write the data from the source. 978 * @param[in] size The size of the buffer.979 * @param[out] size_readThe actual number of bytes read from the source.1203 * @param[in] capacity The maximum number of bytes the buffer can hold. 1204 * @param[out] length The actual number of bytes read from the source. 980 1205 * 981 1206 * @returns On success, the handler should return @c 1. If the handler failed, … … 984 1209 */ 985 1210 986 typedef int yaml_read_handler_t(void *data, unsigned char *buffer, size_t size, 987 size_t *size_read); 988 989 /** 990 * This structure holds information about a potential simple key. 991 */ 992 993 typedef struct yaml_simple_key_s { 994 /** Is a simple key possible? */ 995 int possible; 996 997 /** Is a simple key required? */ 998 int required; 999 1000 /** The number of the token. */ 1001 size_t token_number; 1002 1003 /** The position mark. */ 1004 yaml_mark_t mark; 1005 } yaml_simple_key_t; 1006 1007 /** 1008 * The states of the parser. 1009 */ 1010 typedef enum yaml_parser_state_e { 1011 /** Expect STREAM-START. */ 1012 YAML_PARSE_STREAM_START_STATE, 1013 /** Expect the beginning of an implicit document. */ 1014 YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE, 1015 /** Expect DOCUMENT-START. */ 1016 YAML_PARSE_DOCUMENT_START_STATE, 1017 /** Expect the content of a document. */ 1018 YAML_PARSE_DOCUMENT_CONTENT_STATE, 1019 /** Expect DOCUMENT-END. */ 1020 YAML_PARSE_DOCUMENT_END_STATE, 1021 /** Expect a block node. */ 1022 YAML_PARSE_BLOCK_NODE_STATE, 1023 /** Expect a block node or indentless sequence. */ 1024 YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE, 1025 /** Expect a flow node. */ 1026 YAML_PARSE_FLOW_NODE_STATE, 1027 /** Expect the first entry of a block sequence. */ 1028 YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE, 1029 /** Expect an entry of a block sequence. */ 1030 YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE, 1031 /** Expect an entry of an indentless sequence. */ 1032 YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE, 1033 /** Expect the first key of a block mapping. */ 1034 YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE, 1035 /** Expect a block mapping key. */ 1036 YAML_PARSE_BLOCK_MAPPING_KEY_STATE, 1037 /** Expect a block mapping value. */ 1038 YAML_PARSE_BLOCK_MAPPING_VALUE_STATE, 1039 /** Expect the first entry of a flow sequence. */ 1040 YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE, 1041 /** Expect an entry of a flow sequence. */ 1042 YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE, 1043 /** Expect a key of an ordered mapping. */ 1044 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE, 1045 /** Expect a value of an ordered mapping. */ 1046 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE, 1047 /** Expect the and of an ordered mapping entry. */ 1048 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE, 1049 /** Expect the first key of a flow mapping. */ 1050 YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE, 1051 /** Expect a key of a flow mapping. */ 1052 YAML_PARSE_FLOW_MAPPING_KEY_STATE, 1053 /** Expect a value of a flow mapping. */ 1054 YAML_PARSE_FLOW_MAPPING_VALUE_STATE, 1055 /** Expect an empty value of a flow mapping. */ 1056 YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE, 1057 /** Expect nothing. */ 1058 YAML_PARSE_END_STATE 1059 } yaml_parser_state_t; 1060 1061 /** 1062 * This structure holds aliases data. 1063 */ 1064 1065 typedef struct yaml_alias_data_s { 1066 /** The anchor. */ 1067 yaml_char_t *anchor; 1068 /** The node id. */ 1069 int index; 1070 /** The anchor mark. */ 1071 yaml_mark_t mark; 1072 } yaml_alias_data_t; 1073 1074 /** 1075 * The parser structure. 1076 * 1077 * All members are internal. Manage the structure using the @c yaml_parser_ 1078 * family of functions. 1079 */ 1080 1081 typedef struct yaml_parser_s { 1082 1083 /** 1084 * @name Error handling 1085 * @{ 1086 */ 1087 1088 /** Error type. */ 1089 yaml_error_type_t error; 1090 /** Error description. */ 1091 const char *problem; 1092 /** The byte about which the problem occured. */ 1093 size_t problem_offset; 1094 /** The problematic value (@c -1 is none). */ 1095 int problem_value; 1096 /** The problem position. */ 1097 yaml_mark_t problem_mark; 1098 /** The error context. */ 1099 const char *context; 1100 /** The context position. */ 1101 yaml_mark_t context_mark; 1102 1103 /** 1104 * @} 1105 */ 1106 1107 /** 1108 * @name Reader stuff 1109 * @{ 1110 */ 1111 1112 /** Read handler. */ 1113 yaml_read_handler_t *read_handler; 1114 1115 /** A pointer for passing to the read handler. */ 1116 void *read_handler_data; 1117 1118 /** Standard (string or file) input data. */ 1119 union { 1120 /** String input data. */ 1121 struct { 1122 /** The string start pointer. */ 1123 const unsigned char *start; 1124 /** The string end pointer. */ 1125 const unsigned char *end; 1126 /** The string current position. */ 1127 const unsigned char *current; 1128 } string; 1129 1130 /** File input data. */ 1131 FILE *file; 1132 } input; 1133 1134 /** EOF flag */ 1135 int eof; 1136 1137 /** The working buffer. */ 1138 struct { 1139 /** The beginning of the buffer. */ 1140 yaml_char_t *start; 1141 /** The end of the buffer. */ 1142 yaml_char_t *end; 1143 /** The current position of the buffer. */ 1144 yaml_char_t *pointer; 1145 /** The last filled position of the buffer. */ 1146 yaml_char_t *last; 1147 } buffer; 1148 1149 /* The number of unread characters in the buffer. */ 1150 size_t unread; 1151 1152 /** The raw buffer. */ 1153 struct { 1154 /** The beginning of the buffer. */ 1155 unsigned char *start; 1156 /** The end of the buffer. */ 1157 unsigned char *end; 1158 /** The current position of the buffer. */ 1159 unsigned char *pointer; 1160 /** The last filled position of the buffer. */ 1161 unsigned char *last; 1162 } raw_buffer; 1163 1164 /** The input encoding. */ 1165 yaml_encoding_t encoding; 1166 1167 /** The offset of the current position (in bytes). */ 1168 size_t offset; 1169 1170 /** The mark of the current position. */ 1171 yaml_mark_t mark; 1172 1173 /** 1174 * @} 1175 */ 1176 1177 /** 1178 * @name Scanner stuff 1179 * @{ 1180 */ 1181 1182 /** Have we started to scan the input stream? */ 1183 int stream_start_produced; 1184 1185 /** Have we reached the end of the input stream? */ 1186 int stream_end_produced; 1187 1188 /** The number of unclosed '[' and '{' indicators. */ 1189 int flow_level; 1190 1191 /** The tokens queue. */ 1192 struct { 1193 /** The beginning of the tokens queue. */ 1194 yaml_token_t *start; 1195 /** The end of the tokens queue. */ 1196 yaml_token_t *end; 1197 /** The head of the tokens queue. */ 1198 yaml_token_t *head; 1199 /** The tail of the tokens queue. */ 1200 yaml_token_t *tail; 1201 } tokens; 1202 1203 /** The number of tokens fetched from the queue. */ 1204 size_t tokens_parsed; 1205 1206 /* Does the tokens queue contain a token ready for dequeueing. */ 1207 int token_available; 1208 1209 /** The indentation levels stack. */ 1210 struct { 1211 /** The beginning of the stack. */ 1212 int *start; 1213 /** The end of the stack. */ 1214 int *end; 1215 /** The top of the stack. */ 1216 int *top; 1217 } indents; 1218 1219 /** The current indentation level. */ 1220 int indent; 1221 1222 /** May a simple key occur at the current position? */ 1223 int simple_key_allowed; 1224 1225 /** The stack of simple keys. */ 1226 struct { 1227 /** The beginning of the stack. */ 1228 yaml_simple_key_t *start; 1229 /** The end of the stack. */ 1230 yaml_simple_key_t *end; 1231 /** The top of the stack. */ 1232 yaml_simple_key_t *top; 1233 } simple_keys; 1234 1235 /** 1236 * @} 1237 */ 1238 1239 /** 1240 * @name Parser stuff 1241 * @{ 1242 */ 1243 1244 /** The parser states stack. */ 1245 struct { 1246 /** The beginning of the stack. */ 1247 yaml_parser_state_t *start; 1248 /** The end of the stack. */ 1249 yaml_parser_state_t *end; 1250 /** The top of the stack. */ 1251 yaml_parser_state_t *top; 1252 } states; 1253 1254 /** The current parser state. */ 1255 yaml_parser_state_t state; 1256 1257 /** The stack of marks. */ 1258 struct { 1259 /** The beginning of the stack. */ 1260 yaml_mark_t *start; 1261 /** The end of the stack. */ 1262 yaml_mark_t *end; 1263 /** The top of the stack. */ 1264 yaml_mark_t *top; 1265 } marks; 1266 1267 /** The list of TAG directives. */ 1268 struct { 1269 /** The beginning of the list. */ 1270 yaml_tag_directive_t *start; 1271 /** The end of the list. */ 1272 yaml_tag_directive_t *end; 1273 /** The top of the list. */ 1274 yaml_tag_directive_t *top; 1275 } tag_directives; 1276 1277 /** 1278 * @} 1279 */ 1280 1281 /** 1282 * @name Dumper stuff 1283 * @{ 1284 */ 1285 1286 /** The alias data. */ 1287 struct { 1288 /** The beginning of the list. */ 1289 yaml_alias_data_t *start; 1290 /** The end of the list. */ 1291 yaml_alias_data_t *end; 1292 /** The top of the list. */ 1293 yaml_alias_data_t *top; 1294 } aliases; 1295 1296 /** The currently parsed document. */ 1297 yaml_document_t *document; 1298 1299 /** 1300 * @} 1301 */ 1302 1303 } yaml_parser_t; 1304 1305 /** 1306 * Initialize a parser. 1211 typedef int yaml_reader_t(void *data, unsigned char *buffer, size_t capacity, 1212 size_t *length); 1213 1214 /** 1215 * The prototype of a write handler. 1216 * 1217 * The write handler is called when the emitter needs to flush the accumulated 1218 * characters to the output. The handler should write @a size bytes of the 1219 * @a buffer to the output. 1220 * 1221 * @param[in,out] data A pointer to an application data specified by 1222 * @c yaml_emitter_set_writer(). 1223 * @param[in] buffer The buffer with bytes to be written. 1224 * @param[in] length The number of bytes to be written. 1225 * 1226 * @returns On success, the handler should return @c 1. If the handler failed, 1227 * it should return @c 0. 1228 */ 1229 1230 typedef int yaml_writer_t(void *data, unsigned char *buffer, size_t length); 1231 1232 /** 1233 * The prototype of a tag resolver. 1234 * 1235 * The resolve handler is called when the parser encounters a new node without 1236 * an explicit tag. The handler should determine the correct tag of the node 1237 * basing on the node kind, the path to the node from the document root and, 1238 * in the case of the scalar node, the node value. The handler is also called 1239 * by the emitter to determine whether the node tag could be omitted. 1240 * 1241 * @param[in,out] data A pointer to an application data specified by 1242 * @c yaml_parser_set_writter() or 1243 * @c yaml_emitter_set_writer(). 1244 * @param[in] node Information about the new node. 1245 * @param[out] tag The guessed node tag. 1246 * 1247 * @returns On success, the handler should return @c 1. If the handler failed, 1248 * it should return @c 0. 1249 */ 1250 1251 typedef int yaml_resolver_t(void *data, yaml_incomplete_node_t *node, 1252 yaml_char_t **tag); 1253 1254 /** @} */ 1255 1256 /** 1257 * @defgroup parser Parser Definitions 1258 * @{ 1259 */ 1260 1261 /** The parser object. */ 1262 typedef struct yaml_parser_s yaml_parser_t; 1263 1264 /** 1265 * Create a new parser object. 1307 1266 * 1308 1267 * This function creates a new parser object. An application is responsible 1309 * for destroying the object using the yaml_parser_delete() function. 1310 * 1311 * @param[out] parser An empty parser object. 1312 * 1313 * @returns @c 1 if the function succeeded, @c 0 on error. 1314 */ 1315 1316 YAML_DECLARE(int) 1317 yaml_parser_initialize(yaml_parser_t *parser); 1268 * for destroying the object using the @c yaml_parser_delete() function. 1269 * 1270 * @returns a new parser object or @c NULL on error. 1271 */ 1272 1273 YAML_DECLARE(yaml_parser_t *) 1274 yaml_parser_new(void); 1318 1275 1319 1276 /** … … 1325 1282 YAML_DECLARE(void) 1326 1283 yaml_parser_delete(yaml_parser_t *parser); 1284 1285 /** 1286 * Get a parser error. 1287 * 1288 * @param[in] parser A parser object. 1289 * @param[out] error An error object. 1290 */ 1291 1292 YAML_DECLARE(void) 1293 yaml_parser_get_error(yaml_parser_t *parser, yaml_error_t *error); 1327 1294 1328 1295 /** … … 1334 1301 * 1335 1302 * @param[in,out] parser A parser object. 1336 * @param[in] inputA source data.1337 * @param[in] sizeThe length of the source data in bytes.1338 */ 1339 1340 YAML_DECLARE(void) 1341 yaml_parser_set_ input_string(yaml_parser_t *parser,1342 const unsigned char * input, size_t size);1303 * @param[in] buffer A source data. 1304 * @param[in] length The length of the source data in bytes. 1305 */ 1306 1307 YAML_DECLARE(void) 1308 yaml_parser_set_string_reader(yaml_parser_t *parser, 1309 const unsigned char *buffer, size_t length); 1343 1310 1344 1311 /** … … 1353 1320 1354 1321 YAML_DECLARE(void) 1355 yaml_parser_set_ input_file(yaml_parser_t *parser, FILE *file);1322 yaml_parser_set_file_reader(yaml_parser_t *parser, FILE *file); 1356 1323 1357 1324 /** … … 1359 1326 * 1360 1327 * @param[in,out] parser A parser object. 1361 * @param[in] handlerA read handler.1328 * @param[in] reader A read handler. 1362 1329 * @param[in] data Any application data for passing to the read 1363 1330 * handler. … … 1365 1332 1366 1333 YAML_DECLARE(void) 1367 yaml_parser_set_input(yaml_parser_t *parser, 1368 yaml_read_handler_t *handler, void *data); 1334 yaml_parser_set_reader(yaml_parser_t *parser, 1335 yaml_reader_t *reader, void *data); 1336 1337 #if 0 1338 1339 /** 1340 * Set the standard resolve handler. 1341 * 1342 * The standard resolver recognize the following scalar kinds: !!null, !!bool, 1343 * !!str, !!int and !!float. 1344 * 1345 * @param[in,out] parser A parser object. 1346 */ 1347 1348 YAML_DECLARE(void) 1349 yaml_parser_set_standard_resolver(yaml_parser_t *parser); 1350 1351 /** 1352 * Set the resolve handler. 1353 * 1354 * The standard resolver recognize the following scalar kinds: !!null, !!bool, 1355 * !!str, !!int and !!float. 1356 * 1357 * @param[in,out] parser A parser object. 1358 * @param[in] resolver A resolve handler. 1359 * @param[in] data Any application data for passing to the resolve 1360 * handler. 1361 */ 1362 1363 YAML_DECLARE(void) 1364 yaml_parser_set_resolver(yaml_parser_t *parser, 1365 yaml_resolver_t *resolver, void *data); 1366 1367 #endif 1369 1368 1370 1369 /** … … 1387 1386 * 1388 1387 * An application is responsible for freeing any buffers associated with the 1389 * produced token object using the @c yaml_token_delete function.1390 * 1391 * An application must not alternate the calls of yaml_parser_scan() with the1392 * calls of yaml_parser_parse() or yaml_parser_load(). Doing this will break1393 * the parser.1388 * produced token object using the @c yaml_token_delete() function. 1389 * 1390 * An application must not alternate the calls of @c yaml_parser_scan() with 1391 * the calls of @c yaml_parser_parse() or @c yaml_parser_load(). Doing this 1392 * will break the parser. 1394 1393 * 1395 1394 * @param[in,out] parser A parser object. … … 1411 1410 * 1412 1411 * An application is responsible for freeing any buffers associated with the 1413 * produced event object using the yaml_event_delete() function.1414 * 1415 * An application must not alternate the calls of yaml_parser_parse() with the1416 * calls of yaml_parser_scan() or yaml_parser_load(). Doing this will break the1417 * parser.1412 * produced event object using the @c yaml_event_delete() function. 1413 * 1414 * An application must not alternate the calls of @c yaml_parser_parse() with 1415 * the calls of @c yaml_parser_scan() or @c yaml_parser_load(). Doing this will 1416 * break the parser. 1418 1417 * 1419 1418 * @param[in,out] parser A parser object. … … 1426 1425 yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event); 1427 1426 1427 #if 0 1428 1428 1429 /** 1429 1430 * Parse the input stream and produce the next YAML document. … … 1436 1437 * 1437 1438 * An application is responsible for freeing any data associated with the 1438 * produced document object using the yaml_document_delete() function.1439 * 1440 * An application must not alternate the calls of yaml_parser_load() with the1441 * calls of yaml_parser_scan() or yaml_parser_parse(). Doing this will break1442 * the parser.1439 * produced document object using the @c yaml_document_delete() function. 1440 * 1441 * An application must not alternate the calls of @c yaml_parser_load() with 1442 * the calls of @c yaml_parser_scan() or @c yaml_parser_parse(). Doing this 1443 * will break the parser. 1443 1444 * 1444 1445 * @param[in,out] parser A parser object. … … 1451 1452 yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document); 1452 1453 1454 #endif 1455 1453 1456 /** @} */ 1454 1457 … … 1458 1461 */ 1459 1462 1460 /** 1461 * The prototype of a write handler. 1462 * 1463 * The write handler is called when the emitter needs to flush the accumulated 1464 * characters to the output. The handler should write @a size bytes of the 1465 * @a buffer to the output. 1466 * 1467 * @param[in,out] data A pointer to an application data specified by 1468 * yaml_emitter_set_output(). 1469 * @param[in] buffer The buffer with bytes to be written. 1470 * @param[in] size The size of the buffer. 1471 * 1472 * @returns On success, the handler should return @c 1. If the handler failed, 1473 * the returned value should be @c 0. 1474 */ 1475 1476 typedef int yaml_write_handler_t(void *data, unsigned char *buffer, size_t size); 1477 1478 /** The emitter states. */ 1479 typedef enum yaml_emitter_state_e { 1480 /** Expect STREAM-START. */ 1481 YAML_EMIT_STREAM_START_STATE, 1482 /** Expect the first DOCUMENT-START or STREAM-END. */ 1483 YAML_EMIT_FIRST_DOCUMENT_START_STATE, 1484 /** Expect DOCUMENT-START or STREAM-END. */ 1485 YAML_EMIT_DOCUMENT_START_STATE, 1486 /** Expect the content of a document. */ 1487 YAML_EMIT_DOCUMENT_CONTENT_STATE, 1488 /** Expect DOCUMENT-END. */ 1489 YAML_EMIT_DOCUMENT_END_STATE, 1490 /** Expect the first item of a flow sequence. */ 1491 YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE, 1492 /** Expect an item of a flow sequence. */ 1493 YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE, 1494 /** Expect the first key of a flow mapping. */ 1495 YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE, 1496 /** Expect a key of a flow mapping. */ 1497 YAML_EMIT_FLOW_MAPPING_KEY_STATE, 1498 /** Expect a value for a simple key of a flow mapping. */ 1499 YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE, 1500 /** Expect a value of a flow mapping. */ 1501 YAML_EMIT_FLOW_MAPPING_VALUE_STATE, 1502 /** Expect the first item of a block sequence. */ 1503 YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE, 1504 /** Expect an item of a block sequence. */ 1505 YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE, 1506 /** Expect the first key of a block mapping. */ 1507 YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE, 1508 /** Expect the key of a block mapping. */ 1509 YAML_EMIT_BLOCK_MAPPING_KEY_STATE, 1510 /** Expect a value for a simple key of a block mapping. */ 1511 YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE, 1512 /** Expect a value of a block mapping. */ 1513 YAML_EMIT_BLOCK_MAPPING_VALUE_STATE, 1514 /** Expect nothing. */ 1515 YAML_EMIT_END_STATE 1516 } yaml_emitter_state_t; 1517 1518 /** 1519 * The emitter structure. 1520 * 1521 * All members are internal. Manage the structure using the @c yaml_emitter_ 1522 * family of functions. 1523 */ 1524 1525 typedef struct yaml_emitter_s { 1526 1527 /** 1528 * @name Error handling 1529 * @{ 1530 */ 1531 1532 /** Error type. */ 1533 yaml_error_type_t error; 1534 /** Error description. */ 1535 const char *problem; 1536 1537 /** 1538 * @} 1539 */ 1540 1541 /** 1542 * @name Writer stuff 1543 * @{ 1544 */ 1545 1546 /** Write handler. */ 1547 yaml_write_handler_t *write_handler; 1548 1549 /** A pointer for passing to the white handler. */ 1550 void *write_handler_data; 1551 1552 /** Standard (string or file) output data. */ 1553 union { 1554 /** String output data. */ 1555 struct { 1556 /** The buffer pointer. */ 1557 unsigned char *buffer; 1558 /** The buffer size. */ 1559 size_t size; 1560 /** The number of written bytes. */ 1561 size_t *size_written; 1562 } string; 1563 1564 /** File output data. */ 1565 FILE *file; 1566 } output; 1567 1568 /** The working buffer. */ 1569 struct { 1570 /** The beginning of the buffer. */ 1571 yaml_char_t *start; 1572 /** The end of the buffer. */ 1573 yaml_char_t *end; 1574 /** The current position of the buffer. */ 1575 yaml_char_t *pointer; 1576 /** The last filled position of the buffer. */ 1577 yaml_char_t *last; 1578 } buffer; 1579 1580 /** The raw buffer. */ 1581 struct { 1582 /** The beginning of the buffer. */ 1583 unsigned char *start; 1584 /** The end of the buffer. */ 1585 unsigned char *end; 1586 /** The current position of the buffer. */ 1587 unsigned char *pointer; 1588 /** The last filled position of the buffer. */ 1589 unsigned char *last; 1590 } raw_buffer; 1591 1592 /** The stream encoding. */ 1593 yaml_encoding_t encoding; 1594 1595 /** 1596 * @} 1597 */ 1598 1599 /** 1600 * @name Emitter stuff 1601 * @{ 1602 */ 1603 1604 /** If the output is in the canonical style? */ 1605 int canonical; 1606 /** The number of indentation spaces. */ 1607 int best_indent; 1608 /** The preferred width of the output lines. */ 1609 int best_width; 1610 /** Allow unescaped non-ASCII characters? */ 1611 int unicode; 1612 /** The preferred line break. */ 1613 yaml_break_t line_break; 1614 1615 /** The stack of states. */ 1616 struct { 1617 /** The beginning of the stack. */ 1618 yaml_emitter_state_t *start; 1619 /** The end of the stack. */ 1620 yaml_emitter_state_t *end; 1621 /** The top of the stack. */ 1622 yaml_emitter_state_t *top; 1623 } states; 1624 1625 /** The current emitter state. */ 1626 yaml_emitter_state_t state; 1627 1628 /** The event queue. */ 1629 struct { 1630 /** The beginning of the event queue. */ 1631 yaml_event_t *start; 1632 /** The end of the event queue. */ 1633 yaml_event_t *end; 1634 /** The head of the event queue. */ 1635 yaml_event_t *head; 1636 /** The tail of the event queue. */ 1637 yaml_event_t *tail; 1638 } events; 1639 1640 /** The stack of indentation levels. */ 1641 struct { 1642 /** The beginning of the stack. */ 1643 int *start; 1644 /** The end of the stack. */ 1645 int *end; 1646 /** The top of the stack. */ 1647 int *top; 1648 } indents; 1649 1650 /** The list of tag directives. */ 1651 struct { 1652 /** The beginning of the list. */ 1653 yaml_tag_directive_t *start; 1654 /** The end of the list. */ 1655 yaml_tag_directive_t *end; 1656 /** The top of the list. */ 1657 yaml_tag_directive_t *top; 1658 } tag_directives; 1659 1660 /** The current indentation level. */ 1661 int indent; 1662 1663 /** The current flow level. */ 1664 int flow_level; 1665 1666 /** Is it the document root context? */ 1667 int root_context; 1668 /** Is it a sequence context? */ 1669 int sequence_context; 1670 /** Is it a mapping context? */ 1671 int mapping_context; 1672 /** Is it a simple mapping key context? */ 1673 int simple_key_context; 1674 1675 /** The current line. */ 1676 int line; 1677 /** The current column. */ 1678 int column; 1679 /** If the last character was a whitespace? */ 1680 int whitespace; 1681 /** If the last character was an indentation character (' ', '-', '?', ':')? */ 1682 int indention; 1683 1684 /** Anchor analysis. */ 1685 struct { 1686 /** The anchor value. */ 1687 yaml_char_t *anchor; 1688 /** The anchor length. */ 1689 size_t anchor_length; 1690 /** Is it an alias? */ 1691 int alias; 1692 } anchor_data; 1693 1694 /** Tag analysis. */ 1695 struct { 1696 /** The tag handle. */ 1697 yaml_char_t *handle; 1698 /** The tag handle length. */ 1699 size_t handle_length; 1700 /** The tag suffix. */ 1701 yaml_char_t *suffix; 1702 /** The tag suffix length. */ 1703 size_t suffix_length; 1704 } tag_data; 1705 1706 /** Scalar analysis. */ 1707 struct { 1708 /** The scalar value. */ 1709 yaml_char_t *value; 1710 /** The scalar length. */ 1711 size_t length; 1712 /** Does the scalar contain line breaks? */ 1713 int multiline; 1714 /** Can the scalar be expessed in the flow plain style? */ 1715 int flow_plain_allowed; 1716 /** Can the scalar be expressed in the block plain style? */ 1717 int block_plain_allowed; 1718 /** Can the scalar be expressed in the single quoted style? */ 1719 int single_quoted_allowed; 1720 /** Can the scalar be expressed in the literal or folded styles? */ 1721 int block_allowed; 1722 /** The output style. */ 1723 yaml_scalar_style_t style; 1724 } scalar_data; 1725 1726 /** 1727 * @} 1728 */ 1729 1730 /** 1731 * @name Dumper stuff 1732 * @{ 1733 */ 1734 1735 /** If the stream was already opened? */ 1736 int opened; 1737 /** If the stream was already closed? */ 1738 int closed; 1739 1740 /** The information associated with the document nodes. */ 1741 struct { 1742 /** The number of references. */ 1743 int references; 1744 /** The anchor id. */ 1745 int anchor; 1746 /** If the node has been emitted? */ 1747 int serialized; 1748 } *anchors; 1749 1750 /** The last assigned anchor id. */ 1751 int last_anchor_id; 1752 1753 /** The currently emitted document. */ 1754 yaml_document_t *document; 1755 1756 /** 1757 * @} 1758 */ 1759 1760 } yaml_emitter_t; 1761 1762 /** 1763 * Initialize an emitter. 1463 /** The emitter object. */ 1464 typedef struct yaml_emitter_s yaml_emitter_t; 1465 1466 /** 1467 * Create a new emitter object. 1764 1468 * 1765 1469 * This function creates a new emitter object. An application is responsible 1766 * for destroying the object using the yaml_emitter_delete() function. 1767 * 1768 * @param[out] emitter An empty parser object. 1769 * 1770 * @returns @c 1 if the function succeeded, @c 0 on error. 1771 */ 1772 1773 YAML_DECLARE(int) 1774 yaml_emitter_initialize(yaml_emitter_t *emitter); 1470 * for destroying the object using the @c yaml_emitter_delete() function. 1471 * 1472 * @returns a new emitter object or @c NULL on error. 1473 */ 1474 1475 YAML_DECLARE(yaml_emitter_t *) 1476 yaml_emitter_new(void); 1775 1477 1776 1478 /** … … 1782 1484 YAML_DECLARE(void) 1783 1485 yaml_emitter_delete(yaml_emitter_t *emitter); 1486 1487 /** 1488 * Get an emitter error. 1489 * 1490 * @param[in] emitter An emitter object. 1491 * @param[out] error An error object. 1492 */ 1493 1494 YAML_DECLARE(void) 1495 yaml_emitter_get_error(yaml_emitter_t *emitter, yaml_error_t *error); 1784 1496 1785 1497 /** … … 1789 1501 * size @a size. The emitter will set @a size_written to the number of written 1790 1502 * bytes. If the buffer is smaller than required, the emitter produces the 1791 * YAML_WRITE_ERROR error.1503 * @c YAML_WRITE_ERROR error. 1792 1504 * 1793 1505 * @param[in,out] emitter An emitter object. 1794 * @param[in] output An output buffer. 1795 * @param[in] size The buffer size. 1796 * @param[in] size_written The pointer to save the number of written 1506 * @param[in] buffer An output buffer. 1507 * @param[in] length The pointer to save the number of written 1797 1508 * bytes. 1798 */ 1799 1800 YAML_DECLARE(void) 1801 yaml_emitter_set_output_string(yaml_emitter_t *emitter, 1802 unsigned char *output, size_t size, size_t *size_written); 1509 * @param[in] capacity The buffer size. 1510 */ 1511 1512 YAML_DECLARE(void) 1513 yaml_emitter_set_string_writer(yaml_emitter_t *emitter, 1514 unsigned char *buffer, size_t *length, size_t capacity); 1803 1515 1804 1516 /** … … 1813 1525 1814 1526 YAML_DECLARE(void) 1815 yaml_emitter_set_ output_file(yaml_emitter_t *emitter, FILE *file);1527 yaml_emitter_set_file_writer(yaml_emitter_t *emitter, FILE *file); 1816 1528 1817 1529 /** … … 1819 1531 * 1820 1532 * @param[in,out] emitter An emitter object. 1821 * @param[in] handlerA write handler.1533 * @param[in] writer A write handler. 1822 1534 * @param[in] data Any application data for passing to the write 1823 1535 * handler. … … 1825 1537 1826 1538 YAML_DECLARE(void) 1827 yaml_emitter_set_output(yaml_emitter_t *emitter, 1828 yaml_write_handler_t *handler, void *data); 1539 yaml_emitter_set_writer(yaml_emitter_t *emitter, 1540 yaml_writer_t *writer, void *data); 1541 1542 #if 0 1543 1544 /** 1545 * Set the standard resolve handler. 1546 * 1547 * The standard resolver recognize the following scalar kinds: !!null, !!bool, 1548 * !!str, !!int and !!float. 1549 * 1550 * @param[in,out] emitter An emitter object. 1551 */ 1552 1553 YAML_DECLARE(void) 1554 yaml_emitter_set_standard_resolver(yaml_emitter_t *emitter); 1555 1556 /** 1557 * Set the resolve handler. 1558 * 1559 * The standard resolver recognize the following scalar kinds: !!null, !!bool, 1560 * !!str, !!int and !!float. 1561 * 1562 * @param[in,out] emitter An emitter object. 1563 * @param[in] resolver A resolve handler. 1564 * @param[in] data Any application data for passing to the resolve 1565 * handler. 1566 */ 1567 1568 YAML_DECLARE(void) 1569 yaml_emitter_set_resolver(yaml_emitter_t *emitter, 1570 yaml_resolver_t *resolver, void *data); 1571 1572 #endif 1829 1573 1830 1574 /** … … 1842 1586 * specification. 1843 1587 * 1844 * @param[in,out] emitter An emitter object.1845 * @param[in] canonicalIf the output is canonical.1846 */ 1847 1848 YAML_DECLARE(void) 1849 yaml_emitter_set_canonical(yaml_emitter_t *emitter, int canonical);1588 * @param[in,out] emitter An emitter object. 1589 * @param[in] is_canonical If the output is canonical. 1590 */ 1591 1592 YAML_DECLARE(void) 1593 yaml_emitter_set_canonical(yaml_emitter_t *emitter, int is_canonical); 1850 1594 1851 1595 /** … … 1873 1617 * 1874 1618 * @param[in,out] emitter An emitter object. 1875 * @param[in] unicodeIf unescaped Unicode characters are allowed.1876 */ 1877 1878 YAML_DECLARE(void) 1879 yaml_emitter_set_unicode(yaml_emitter_t *emitter, int unicode);1619 * @param[in] is_unicode If unescaped Unicode characters are allowed. 1620 */ 1621 1622 YAML_DECLARE(void) 1623 yaml_emitter_set_unicode(yaml_emitter_t *emitter, int is_unicode); 1880 1624 1881 1625 /** … … 1906 1650 yaml_emitter_emit(yaml_emitter_t *emitter, yaml_event_t *event); 1907 1651 1652 #if 0 1653 1908 1654 /** 1909 1655 * Start a YAML stream. 1910 1656 * 1911 * This function should be used before yaml_emitter_dump() is called. 1657 * This function should be used before the first @c yaml_emitter_dump() is 1658 * called. 1912 1659 * 1913 1660 * @param[in,out] emitter An emitter object. … … 1922 1669 * Finish a YAML stream. 1923 1670 * 1924 * This function should be used after yaml_emitter_dump() is called. 1671 * This function should be used after the last @c yaml_emitter_dump() is 1672 * called. 1925 1673 * 1926 1674 * @param[in,out] emitter An emitter object. … … 1935 1683 * Emit a YAML document. 1936 1684 * 1937 * The documen object may be generated using the yaml_parser_load() function1938 * or the yaml_document_initialize() function. The emitter takes the1939 * responsibility for the document object and destoys its content after1940 * it is emitted. The document object is destroyed even if the function fails.1685 * The document object may be generated using the @c yaml_parser_load() 1686 * function or the @c yaml_document_initialize() function. The emitter takes 1687 * the responsibility for the document object and destoys its content after 1688 * it is emitted. The document object is destroyed even if the function fails. 1941 1689 * 1942 1690 * @param[in,out] emitter An emitter object. … … 1949 1697 yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document); 1950 1698 1951 /** 1952 * Flush the accumulated characters to the output. 1699 #endif 1700 1701 /** 1702 * Flush the accumulated characters to the output stream. 1953 1703 * 1954 1704 * @param[in,out] emitter An emitter object. -
libyaml/trunk/src/api.c
r243 r261 72 72 73 73 YAML_DECLARE(int) 74 yaml_string_extend(yaml_char_t **start, 75 yaml_char_t **pointer, yaml_char_t **end) 76 { 77 yaml_char_t *new_start = yaml_realloc(*start, (*end - *start)*2); 78 79 if (!new_start) return 0; 80 81 memset(new_start + (*end - *start), 0, *end - *start); 82 83 *pointer = new_start + (*pointer - *start); 84 *end = new_start + (*end - *start)*2; 85 *start = new_start; 86 87 return 1; 88 } 89 90 /* 91 * Append a string B to a string A. 74 yaml_string_extend(yaml_char_t **buffer, size_t *capacity) 75 { 76 yaml_char_t *new_buffer = yaml_realloc(*buffer, (*capacity)*2); 77 78 if (!new_buffer) return 0; 79 80 memset(new_buffer + *capacity, 0, *capacity); 81 82 *buffer = new_buffer; 83 *capacity *= 2; 84 85 return 1; 86 } 87 88 /* 89 * Append an adjunct string to a base string. 92 90 */ 93 91 94 92 YAML_DECLARE(int) 95 93 yaml_string_join( 96 yaml_char_t ** a_start, yaml_char_t **a_pointer, yaml_char_t **a_end,97 yaml_char_t * *b_start, yaml_char_t **b_pointer, yaml_char_t **b_end)98 { 99 if ( *b_start == *b_pointer)94 yaml_char_t **base_buffer, size_t *base_pointer, size_t *base_capacity, 95 yaml_char_t *adj_buffer, size_t adj_pointer, size_t adj_capacity) 96 { 97 if (!adj_pointer) 100 98 return 1; 101 99 102 while (* a_end - *a_pointer <= *b_pointer - *b_start) {103 if (!yaml_string_extend( a_start, a_pointer, a_end))100 while (*base_capacity - *base_pointer <= adj_pointer) { 101 if (!yaml_string_extend(base_buffer, base_capacity)) 104 102 return 0; 105 103 } 106 104 107 memcpy(* a_pointer, *b_start, *b_pointer - *b_start);108 * a_pointer += *b_pointer - *b_start;105 memcpy(*base_buffer+*base_pointer, adj_buffer, adj_pointer); 106 *base_pointer += adj_pointer; 109 107 110 108 return 1; … … 116 114 117 115 YAML_DECLARE(int) 118 yaml_stack_extend(void **start, void **top, void **end) 119 { 120 void *new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2); 121 122 if (!new_start) return 0; 123 124 *top = (char *)new_start + ((char *)*top - (char *)*start); 125 *end = (char *)new_start + ((char *)*end - (char *)*start)*2; 126 *start = new_start; 116 yaml_stack_extend(void **list, size_t size, size_t *length, size_t *capacity) 117 { 118 void *new_list = yaml_realloc(*list, (*capacity)*size*2); 119 120 if (!new_list) return 0; 121 122 *list = new_list; 123 *capacity *= 2; 127 124 128 125 return 1; … … 134 131 135 132 YAML_DECLARE(int) 136 yaml_queue_extend(void **start, void **head, void **tail, void **end) 133 yaml_queue_extend(void **list, size_t size, 134 size_t *head, size_t *tail, size_t *capacity) 137 135 { 138 136 /* Check if we need to resize the queue. */ 139 137 140 if (*start == *head && *tail == *end) { 141 void *new_start = yaml_realloc(*start, 142 ((char *)*end - (char *)*start)*2); 143 144 if (!new_start) return 0; 145 146 *head = (char *)new_start + ((char *)*head - (char *)*start); 147 *tail = (char *)new_start + ((char *)*tail - (char *)*start); 148 *end = (char *)new_start + ((char *)*end - (char *)*start)*2; 149 *start = new_start; 138 if (*head == 0 && *tail == *capacity) { 139 void *new_list = yaml_realloc(*list, (*capacity)*size*2); 140 141 if (!new_list) return 0; 142 143 *list = new_list; 144 *capacity *= 2; 150 145 } 151 146 152 147 /* Check if we need to move the queue at the beginning of the buffer. */ 153 148 154 if (*tail == * end) {149 if (*tail == *capacity) { 155 150 if (*head != *tail) { 156 memmove(*start, *head, (char *)*tail - (char *)*head); 151 memmove((char *)*list, (char *)*list + (*head)*size, 152 (*tail-*head)*size); 157 153 } 158 *tail = (char *)*tail - (char *)*head + (char *)*start;159 *head = *start;154 *tail -= *head; 155 *head = 0; 160 156 } 161 157 … … 168 164 */ 169 165 170 YAML_DECLARE(int) 171 yaml_parser_initialize(yaml_parser_t *parser) 172 { 173 assert(parser); /* Non-NULL parser object expected. */ 166 YAML_DECLARE(yaml_parser_t *) 167 yaml_parser_new(void) 168 { 169 yaml_parser_t *parser = yaml_malloc(sizeof(yaml_parser_t)); 170 171 if (!parser) 172 return NULL; 174 173 175 174 memset(parser, 0, sizeof(yaml_parser_t)); 176 if (!BUFFER_INIT(parser, parser->raw_ buffer, INPUT_RAW_BUFFER_SIZE))175 if (!BUFFER_INIT(parser, parser->raw_input, RAW_INPUT_BUFFER_CAPACITY)) 177 176 goto error; 178 if (!BUFFER_INIT(parser, parser-> buffer, INPUT_BUFFER_SIZE))177 if (!BUFFER_INIT(parser, parser->input, INPUT_BUFFER_CAPACITY)) 179 178 goto error; 180 if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_ SIZE))179 if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_CAPACITY)) 181 180 goto error; 182 if (!STACK_INIT(parser, parser->indents, INITIAL_STACK_ SIZE))181 if (!STACK_INIT(parser, parser->indents, INITIAL_STACK_CAPACITY)) 183 182 goto error; 184 if (!STACK_INIT(parser, parser->simple_keys, INITIAL_STACK_ SIZE))183 if (!STACK_INIT(parser, parser->simple_keys, INITIAL_STACK_CAPACITY)) 185 184 goto error; 186 if (!STACK_INIT(parser, parser->states, INITIAL_STACK_ SIZE))185 if (!STACK_INIT(parser, parser->states, INITIAL_STACK_CAPACITY)) 187 186 goto error; 188 if (!STACK_INIT(parser, parser->marks, INITIAL_STACK_ SIZE))187 if (!STACK_INIT(parser, parser->marks, INITIAL_STACK_CAPACITY)) 189 188 goto error; 190 if (!STACK_INIT(parser, parser->tag_directives, INITIAL_STACK_ SIZE))189 if (!STACK_INIT(parser, parser->tag_directives, INITIAL_STACK_CAPACITY)) 191 190 goto error; 192 191 193 return 1;192 return parser; 194 193 195 194 error: 196 197 BUFFER_DEL(parser, parser->raw_buffer); 198 BUFFER_DEL(parser, parser->buffer); 199 QUEUE_DEL(parser, parser->tokens); 200 STACK_DEL(parser, parser->indents); 201 STACK_DEL(parser, parser->simple_keys); 202 STACK_DEL(parser, parser->states); 203 STACK_DEL(parser, parser->marks); 204 STACK_DEL(parser, parser->tag_directives); 205 206 return 0; 195 yaml_parser_delete(parser); 196 197 return NULL; 207 198 } 208 199 … … 216 207 assert(parser); /* Non-NULL parser object expected. */ 217 208 218 BUFFER_DEL(parser, parser->raw_ buffer);219 BUFFER_DEL(parser, parser-> buffer);209 BUFFER_DEL(parser, parser->raw_input); 210 BUFFER_DEL(parser, parser->input); 220 211 while (!QUEUE_EMPTY(parser, parser->tokens)) { 221 yaml_token_de lete(&DEQUEUE(parser, parser->tokens));212 yaml_token_destroy(&DEQUEUE(parser, parser->tokens)); 222 213 } 223 214 QUEUE_DEL(parser, parser->tokens); … … 234 225 235 226 memset(parser, 0, sizeof(yaml_parser_t)); 236 } 237 238 /* 239 * String read handler. 227 yaml_free(parser); 228 } 229 230 /* 231 * Get the current parser error. 232 */ 233 234 YAML_DECLARE(void) 235 yaml_parser_get_error(yaml_parser_t *parser, yaml_error_t *error) 236 { 237 assert(parser); /* Non-NULL parser object expected. */ 238 239 *error = parser->error; 240 } 241 242 /* 243 * Standard string read handler. 240 244 */ 241 245 242 246 static int 243 yaml_string_read _handler(void *data, unsigned char *buffer, size_t size,244 size_t * size_read)245 { 246 yaml_ parser_t *parser =data;247 248 if ( parser->input.string.current == parser->input.string.end) {249 * size_read= 0;247 yaml_string_reader(void *untyped_data, unsigned char *buffer, size_t capacity, 248 size_t *length) 249 { 250 yaml_standard_reader_data_t *data = untyped_data; 251 252 if (data->string.pointer == data->string.capacity) { 253 *length = 0; 250 254 return 1; 251 255 } 252 256 253 if (size > (size_t)(parser->input.string.end 254 - parser->input.string.current)) { 255 size = parser->input.string.end - parser->input.string.current; 256 } 257 258 memcpy(buffer, parser->input.string.current, size); 259 parser->input.string.current += size; 260 *size_read = size; 261 return 1; 262 } 263 264 /* 265 * File read handler. 257 if (capacity > (size_t)(data->string.capacity - data->string.pointer)) { 258 capacity = data->string.capacity - data->string.pointer; 259 } 260 261 memcpy(buffer, data->string.buffer + data->string.pointer, capacity); 262 data->string.pointer += capacity; 263 *length = capacity; 264 return 1; 265 } 266 267 /* 268 * Standard file read handler. 266 269 */ 267 270 268 271 static int 269 yaml_file_read _handler(void *data, unsigned char *buffer, size_t size,270 size_t * size_read)271 { 272 yaml_ parser_t *parser =data;273 274 * size_read = fread(buffer, 1, size, parser->input.file);275 return !ferror( parser->input.file);272 yaml_file_reader(void *untyped_data, unsigned char *buffer, size_t capacity, 273 size_t *length) 274 { 275 yaml_standard_reader_data_t *data = untyped_data; 276 277 *length = fread(buffer, 1, capacity, data->file); 278 return !ferror(data->file); 276 279 } 277 280 … … 281 284 282 285 YAML_DECLARE(void) 283 yaml_parser_set_ input_string(yaml_parser_t *parser,284 const unsigned char * input, size_t size)286 yaml_parser_set_string_reader(yaml_parser_t *parser, 287 const unsigned char *buffer, size_t length) 285 288 { 286 289 assert(parser); /* Non-NULL parser object expected. */ 287 assert(!parser->read _handler); /* You can set the sourceonly once. */288 assert( input);/* Non-NULL input string expected. */289 290 parser->read _handler = yaml_string_read_handler;291 parser->read _handler_data = parser;292 293 parser-> input.string.start = input;294 parser-> input.string.current = input;295 parser-> input.string.end = input+size;290 assert(!parser->reader); /* You can set the input handler only once. */ 291 assert(buffer); /* Non-NULL input string expected. */ 292 293 parser->reader = yaml_string_reader; 294 parser->reader_data = &(parser->standard_reader_data); 295 296 parser->standard_reader_data.string.buffer = (unsigned char *)buffer; 297 parser->standard_reader_data.string.pointer = 0; 298 parser->standard_reader_data.string.capacity = length; 296 299 } 297 300 … … 301 304 302 305 YAML_DECLARE(void) 303 yaml_parser_set_ input_file(yaml_parser_t *parser, FILE *file)306 yaml_parser_set_file_reader(yaml_parser_t *parser, FILE *file) 304 307 { 305 308 assert(parser); /* Non-NULL parser object expected. */ 306 assert(!parser->read _handler); /* You can set the sourceonly once. */309 assert(!parser->reader); /* You can set the input handler only once. */ 307 310 assert(file); /* Non-NULL file object expected. */ 308 311 309 parser->read _handler = yaml_file_read_handler;310 parser->read _handler_data = parser;311 312 parser-> input.file = file;312 parser->reader = yaml_file_reader; 313 parser->reader_data = &(parser->standard_reader_data); 314 315 parser->standard_reader_data.file = file; 313 316 } 314 317 … … 318 321 319 322 YAML_DECLARE(void) 320 yaml_parser_set_ input(yaml_parser_t *parser,321 yaml_read _handler_t *handler, void *data)323 yaml_parser_set_reader(yaml_parser_t *parser, 324 yaml_reader_t *reader, void *data) 322 325 { 323 326 assert(parser); /* Non-NULL parser object expected. */ 324 assert(!parser->read _handler); /* You can set the sourceonly once. */325 assert( handler);/* Non-NULL read handler expected. */326 327 parser->read _handler = handler;328 parser->read _handler_data = data;327 assert(!parser->reader); /* You can set the input handler only once. */ 328 assert(reader); /* Non-NULL read handler expected. */ 329 330 parser->reader = reader; 331 parser->reader_data = data; 329 332 } 330 333 … … 337 340 { 338 341 assert(parser); /* Non-NULL parser object expected. */ 339 assert(!parser->encoding); /* Encoding is already set or detected. */342 assert(!parser->encoding); /* Encoding is already set or detected. */ 340 343 341 344 parser->encoding = encoding; … … 346 349 */ 347 350 348 YAML_DECLARE(int) 349 yaml_emitter_initialize(yaml_emitter_t *emitter) 351 YAML_DECLARE(yaml_emitter_t *) 352 yaml_emitter_new(void) 353 { 354 yaml_emitter_t *emitter = yaml_malloc(sizeof(yaml_emitter_t)); 355 356 if (!emitter) 357 return NULL; 358 359 memset(emitter, 0, sizeof(yaml_emitter_t)); 360 if (!BUFFER_INIT(emitter, emitter->output, OUTPUT_BUFFER_CAPACITY)) 361 goto error; 362 if (!BUFFER_INIT(emitter, emitter->raw_output, RAW_OUTPUT_BUFFER_CAPACITY)) 363 goto error; 364 if (!STACK_INIT(emitter, emitter->states, INITIAL_STACK_CAPACITY)) 365 goto error; 366 if (!QUEUE_INIT(emitter, emitter->events, INITIAL_QUEUE_CAPACITY)) 367 goto error; 368 if (!STACK_INIT(emitter, emitter->indents, INITIAL_STACK_CAPACITY)) 369 goto error; 370 if (!STACK_INIT(emitter, emitter->tag_directives, INITIAL_STACK_CAPACITY)) 371 goto error; 372 373 return emitter; 374 375 error: 376 yaml_emitter_delete(emitter); 377 378 return NULL; 379 } 380 381 /* 382 * Destroy an emitter object. 383 */ 384 385 YAML_DECLARE(void) 386 yaml_emitter_delete(yaml_emitter_t *emitter) 350 387 { 351 388 assert(emitter); /* Non-NULL emitter object expected. */ 352 389 353 memset(emitter, 0, sizeof(yaml_emitter_t)); 354 if (!BUFFER_INIT(emitter, emitter->buffer, OUTPUT_BUFFER_SIZE)) 355 goto error; 356 if (!BUFFER_INIT(emitter, emitter->raw_buffer, OUTPUT_RAW_BUFFER_SIZE)) 357 goto error; 358 if (!STACK_INIT(emitter, emitter->states, INITIAL_STACK_SIZE)) 359 goto error; 360 if (!QUEUE_INIT(emitter, emitter->events, INITIAL_QUEUE_SIZE)) 361 goto error; 362 if (!STACK_INIT(emitter, emitter->indents, INITIAL_STACK_SIZE)) 363 goto error; 364 if (!STACK_INIT(emitter, emitter->tag_directives, INITIAL_STACK_SIZE)) 365 goto error; 366 367 return 1; 368 369 error: 370 371 BUFFER_DEL(emitter, emitter->buffer); 372 BUFFER_DEL(emitter, emitter->raw_buffer); 373 STACK_DEL(emitter, emitter->states); 374 QUEUE_DEL(emitter, emitter->events); 375 STACK_DEL(emitter, emitter->indents); 376 STACK_DEL(emitter, emitter->tag_directives); 377 378 return 0; 379 } 380 381 /* 382 * Destroy an emitter object. 383 */ 384 385 YAML_DECLARE(void) 386 yaml_emitter_delete(yaml_emitter_t *emitter) 387 { 388 assert(emitter); /* Non-NULL emitter object expected. */ 389 390 BUFFER_DEL(emitter, emitter->buffer); 391 BUFFER_DEL(emitter, emitter->raw_buffer); 390 BUFFER_DEL(emitter, emitter->output); 391 BUFFER_DEL(emitter, emitter->raw_output); 392 392 STACK_DEL(emitter, emitter->states); 393 393 while (!QUEUE_EMPTY(emitter, emitter->events)) { … … 405 405 406 406 memset(emitter, 0, sizeof(yaml_emitter_t)); 407 yaml_free(emitter); 408 } 409 410 /* 411 * Get the current emitter error. 412 */ 413 414 YAML_DECLARE(void) 415 yaml_emitter_get_error(yaml_emitter_t *emitter, yaml_error_t *error) 416 { 417 assert(emitter); /* Non-NULL emitter object expected. */ 418 419 *error = emitter->error; 407 420 } 408 421 … … 412 425 413 426 static int 414 yaml_string_write_handler(void *data, unsigned char *buffer, size_t size) 415 { 416 yaml_emitter_t *emitter = data; 417 418 if (emitter->output.string.size + *emitter->output.string.size_written 419 < size) { 420 memcpy(emitter->output.string.buffer 421 + *emitter->output.string.size_written, 422 buffer, 423 emitter->output.string.size 424 - *emitter->output.string.size_written); 425 *emitter->output.string.size_written = emitter->output.string.size; 426 return 0; 427 } 428 429 memcpy(emitter->output.string.buffer 430 + *emitter->output.string.size_written, buffer, size); 431 *emitter->output.string.size_written += size; 432 return 1; 427 yaml_string_writer(void *untyped_data, unsigned char *buffer, size_t length) 428 { 429 yaml_standard_writer_data_t *data = untyped_data; 430 int result = 1; 431 432 if (data->string.capacity - data->string.pointer < length) { 433 length = data->string.capacity - data->string.pointer; 434 result = 0; 435 } 436 437 memcpy(data->string.buffer + data->string.pointer, buffer, length); 438 data->string.pointer += length; 439 *data->length += length; 440 441 return result; 433 442 } 434 443 … … 438 447 439 448 static int 440 yaml_file_write _handler(void *data, unsigned char *buffer, size_t size)441 { 442 yaml_ emitter_t *emitter =data;443 444 return (fwrite(buffer, 1, size, emitter->output.file) == size);449 yaml_file_writer(void *untyped_data, unsigned char *buffer, size_t length) 450 { 451 yaml_standard_writer_data_t *data = untyped_data; 452 453 return (fwrite(buffer, 1, length, data->file) == length); 445 454 } 446 455 /* … … 449 458 450 459 YAML_DECLARE(void) 451 yaml_emitter_set_ output_string(yaml_emitter_t *emitter,452 unsigned char * output, size_t size, size_t *size_written)460 yaml_emitter_set_string_writer(yaml_emitter_t *emitter, 461 unsigned char *buffer, size_t *length, size_t capacity) 453 462 { 454 463 assert(emitter); /* Non-NULL emitter object expected. */ 455 assert(!emitter->write_handler); /* You can set the output only once. */ 456 assert(output); /* Non-NULL output string expected. */ 457 458 emitter->write_handler = yaml_string_write_handler; 459 emitter->write_handler_data = emitter; 460 461 emitter->output.string.buffer = output; 462 emitter->output.string.size = size; 463 emitter->output.string.size_written = size_written; 464 *size_written = 0; 464 assert(!emitter->writer); /* You can set the output only once. */ 465 assert(buffer); /* Non-NULL output string expected. */ 466 467 emitter->writer = yaml_string_writer; 468 emitter->writer_data = &(emitter->standard_writer_data); 469 470 emitter->standard_writer_data.string.buffer = buffer; 471 emitter->standard_writer_data.string.pointer = 0; 472 emitter->standard_writer_data.string.capacity = capacity; 473 emitter->standard_writer_data.length = length; 474 475 *length = 0; 465 476 } 466 477 … … 470 481 471 482 YAML_DECLARE(void) 472 yaml_emitter_set_ output_file(yaml_emitter_t *emitter, FILE *file)483 yaml_emitter_set_file_writer(yaml_emitter_t *emitter, FILE *file) 473 484 { 474 485 assert(emitter); /* Non-NULL emitter object expected. */ 475 assert(!emitter->write _handler);/* You can set the output only once. */486 assert(!emitter->writer); /* You can set the output only once. */ 476 487 assert(file); /* Non-NULL file object expected. */ 477 488 478 emitter->write _handler = yaml_file_write_handler;479 emitter->write _handler_data = emitter;480 481 emitter-> output.file = file;489 emitter->writer = yaml_string_writer; 490 emitter->writer_data = &(emitter->standard_writer_data); 491 492 emitter->standard_writer_data.file = file; 482 493 } 483 494 … … 487 498 488 499 YAML_DECLARE(void) 489 yaml_emitter_set_ output(yaml_emitter_t *emitter,490 yaml_write _handler_t *handler, void *data)500 yaml_emitter_set_writer(yaml_emitter_t *emitter, 501 yaml_writer_t *writer, void *data) 491 502 { 492 503 assert(emitter); /* Non-NULL emitter object expected. */ 493 assert(!emitter->write _handler);/* You can set the output only once. */494 assert( handler);/* Non-NULL handler object expected. */495 496 emitter->write _handler = handler;497 emitter->write _handler_data = data;504 assert(!emitter->writer); /* You can set the output only once. */ 505 assert(writer); /* Non-NULL handler object expected. */ 506 507 emitter->writer = writer; 508 emitter->writer_data = data; 498 509 } 499 510 … … 516 527 517 528 YAML_DECLARE(void) 518 yaml_emitter_set_canonical(yaml_emitter_t *emitter, int canonical)529 yaml_emitter_set_canonical(yaml_emitter_t *emitter, int is_canonical) 519 530 { 520 531 assert(emitter); /* Non-NULL emitter object expected. */ 521 532 522 emitter-> canonical = (canonical != 0);533 emitter->is_canonical = (is_canonical != 0); 523 534 } 524 535 … … 552 563 553 564 YAML_DECLARE(void) 554 yaml_emitter_set_unicode(yaml_emitter_t *emitter, int unicode)565 yaml_emitter_set_unicode(yaml_emitter_t *emitter, int is_unicode) 555 566 { 556 567 assert(emitter); /* Non-NULL emitter object expected. */ 557 568 558 emitter-> unicode = (unicode != 0);569 emitter->is_unicode = (is_unicode != 0); 559 570 } 560 571 … … 572 583 573 584 /* 585 * Allocate a token object. 586 */ 587 588 YAML_DECLARE(yaml_token_t *) 589 yaml_token_new(void) 590 { 591 yaml_token_t *token = yaml_malloc(sizeof(yaml_token_t)); 592 593 if (!token) 594 return NULL; 595 596 memset(token, 0, sizeof(yaml_token_t)); 597 598 return token; 599 } 600 601 /* 602 * Deallocate a token object. 603 */ 604 605 YAML_DECLARE(void) 606 yaml_token_delete(yaml_token_t *token) 607 { 608 assert(token); /* Non-NULL token object expected. */ 609 610 yaml_token_destroy(token); 611 yaml_free(token); 612 } 613 614 /* 615 * Duplicate a token object. 616 */ 617 618 YAML_DECLARE(int) 619 yaml_token_duplicate(yaml_token_t *token, yaml_token_t *model) 620 { 621 assert(token); /* Non-NULL token object is expected. */ 622 assert(model); /* Non-NULL model token object is expected. */ 623 624 memset(token, 0, sizeof(yaml_token_t)); 625 626 token->type = model->type; 627 token->start_mark = model->start_mark; 628 token->end_mark = model->end_mark; 629 630 switch (token->type) 631 { 632 case YAML_STREAM_START_TOKEN: 633 token->data.stream_start.encoding = 634 model->data.stream_start.encoding; 635 break; 636 637 case YAML_VERSION_DIRECTIVE_TOKEN: 638 token->data.version_directive.major = 639 model->data.version_directive.major; 640 token->data.version_directive.minor = 641 model->data.version_directive.minor; 642 break; 643 644 case YAML_TAG_DIRECTIVE_TOKEN: 645 if (!(token->data.tag_directive.handle = 646 yaml_strdup(model->data.tag_directive.handle))) 647 goto error; 648 if (!(token->data.tag_directive.prefix = 649 yaml_strdup(model->data.tag_directive.prefix))) 650 goto error; 651 break; 652 653 case YAML_ALIAS_TOKEN: 654 if (!(token->data.alias.value = 655 yaml_strdup(model->data.alias.value))) 656 goto error; 657 break; 658 659 case YAML_ANCHOR_TOKEN: 660 if (!(token->data.anchor.value = 661 yaml_strdup(model->data.anchor.value))) 662 goto error; 663 break; 664 665 case YAML_TAG_TOKEN: 666 if (!(token->data.tag.handle = yaml_strdup(model->data.tag.handle))) 667 goto error; 668 if (!(token->data.tag.suffix = yaml_strdup(model->data.tag.suffix))) 669 goto error; 670 break; 671 672 case YAML_SCALAR_TOKEN: 673 if (!(token->data.scalar.value = 674 yaml_malloc(model->data.scalar.length+1))) 675 goto error; 676 memcpy(token->data.scalar.value, model->data.scalar.value, 677 model->data.scalar.length+1); 678 token->data.scalar.length = model->data.scalar.length; 679 break; 680 681 default: 682 break; 683 } 684 685 return 1; 686 687 error: 688 yaml_token_destroy(token); 689 690 return 0; 691 } 692 693 /* 574 694 * Destroy a token object. 575 695 */ 576 696 577 697 YAML_DECLARE(void) 578 yaml_token_de lete(yaml_token_t *token)698 yaml_token_destroy(yaml_token_t *token) 579 699 { 580 700 assert(token); /* Non-NULL token object expected. */ … … 618 738 619 739 static int 620 yaml_check_utf8(yaml_char_t *start, size_t length) 621 { 622 yaml_char_t *end = start+length; 623 yaml_char_t *pointer = start; 624 625 while (pointer < end) { 740 yaml_valid_utf8(const yaml_char_t *buffer, size_t length) 741 { 742 size_t pointer = 0; 743 744 while (pointer < length) { 626 745 unsigned char octet; 627 746 unsigned int width; … … 629 748 size_t k; 630 749 631 octet = pointer[0];750 octet = buffer[pointer]; 632 751 width = (octet & 0x80) == 0x00 ? 1 : 633 752 (octet & 0xE0) == 0xC0 ? 2 : … … 639 758 (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; 640 759 if (!width) return 0; 641 if (pointer+width > end) return 0;760 if (pointer+width > length) return 0; 642 761 for (k = 1; k < width; k ++) { 643 octet = pointer[k];762 octet = buffer[pointer+k]; 644 763 if ((octet & 0xC0) != 0x80) return 0; 645 764 value = (value << 6) + (octet & 0x3F); … … 657 776 658 777 /* 778 * Allocate an event object. 779 */ 780 781 YAML_DECLARE(yaml_event_t *) 782 yaml_event_new(void) 783 { 784 yaml_event_t *event = yaml_malloc(sizeof(yaml_event_t)); 785 786 if (!event) 787 return NULL; 788 789 memset(event, 0, sizeof(yaml_event_t)); 790 791 return event; 792 } 793 794 /* 795 * Deallocate an event object. 796 */ 797 798 YAML_DECLARE(void) 799 yaml_event_delete(yaml_event_t *event) 800 { 801 assert(event); /* Non-NULL event object expected. */ 802 803 yaml_event_destroy(event); 804 yaml_free(event); 805 } 806 807 /* 808 * Duplicate an event object. 809 */ 810 811 YAML_DECLARE(int) 812 yaml_event_duplicate(yaml_event_t *event, yaml_event_t *model) 813 { 814 struct { 815 yaml_error_t error; 816 } self; 817 818 assert(event); /* Non-NULL event object is expected. */ 819 assert(model); /* Non-NULL model event object is expected. */ 820 821 memset(event, 0, sizeof(yaml_event_t)); 822 823 event->type = model->type; 824 event->start_mark = model->start_mark; 825 event->end_mark = model->end_mark; 826 827 switch (event->type) 828 { 829 case YAML_STREAM_START_EVENT: 830 event->data.stream_start.encoding = 831 model->data.stream_start.encoding; 832 break; 833 834 case YAML_DOCUMENT_START_EVENT: 835 if (model->data.document_start.version_directive) { 836 if (!(event->data.document_start.version_directive = 837 yaml_malloc(sizeof(yaml_version_directive_t)))) 838 goto error; 839 *event->data.document_start.version_directive = 840 *model->data.document_start.version_directive; 841 } 842 if (model->data.document_start.tag_directives.length) { 843 yaml_tag_directive_t *tag_directives = 844 model->data.document_start.tag_directives.list; 845 if (!STACK_INIT(&self, event->data.document_start.tag_directives, 846 model->data.document_start.tag_directives.capacity)) 847 goto error; 848 while (event->data.document_start.tag_directives.length != 849 model->data.document_start.tag_directives.length) { 850 yaml_tag_directive_t value; 851 value.handle = yaml_strdup(tag_directives->handle); 852 value.prefix = yaml_strdup(tag_directives->prefix); 853 PUSH(&self, event->data.document_start.tag_directives, value); 854 if (!value.handle || !value.prefix) 855 goto error; 856 tag_directives ++; 857 } 858 } 859 event->data.document_start.is_implicit = 860 model->data.document_start.is_implicit; 861 break; 862 863 case YAML_DOCUMENT_END_EVENT: 864 event->data.document_end.is_implicit = 865 model->data.document_end.is_implicit; 866 867 case YAML_ALIAS_EVENT: 868 if (!(event->data.alias.anchor = 869 yaml_strdup(model->data.alias.anchor))) 870 goto error; 871 break; 872 873 case YAML_SCALAR_EVENT: 874 if (model->data.scalar.anchor && 875 !(event->data.scalar.anchor = 876 yaml_strdup(model->data.scalar.anchor))) 877 goto error; 878 if (event->data.scalar.tag && 879 !(event->data.scalar.tag = 880 yaml_strdup(model->data.scalar.tag))) 881 goto error; 882 if (!(event->data.scalar.value = 883 yaml_malloc(model->data.scalar.length+1))) 884 goto error; 885 memcpy(event->data.scalar.value, model->data.scalar.value, 886 model->data.scalar.length+1); 887 event->data.scalar.length = model->data.scalar.length; 888 event->data.scalar.is_plain_implicit = 889 model->data.scalar.is_plain_implicit; 890 event->data.scalar.is_quoted_implicit = 891 model->data.scalar.is_quoted_implicit; 892 event->data.scalar.style = model->data.scalar.style; 893 break; 894 895 case YAML_SEQUENCE_START_EVENT: 896 if (model->data.sequence_start.anchor && 897 !(event->data.sequence_start.anchor = 898 yaml_strdup(model->data.sequence_start.anchor))) 899 goto error; 900 if (event->data.sequence_start.tag && 901 !(event->data.sequence_start.tag = 902 yaml_strdup(model->data.sequence_start.tag))) 903 goto error; 904 event->data.sequence_start.is_implicit = 905 model->data.sequence_start.is_implicit; 906 event->data.sequence_start.style = 907 model->data.sequence_start.style; 908 break; 909 910 case YAML_MAPPING_START_EVENT: 911 if (model->data.mapping_start.anchor && 912 !(event->data.mapping_start.anchor = 913 yaml_strdup(model->data.mapping_start.anchor))) 914 goto error; 915 if (event->data.mapping_start.tag && 916 !(event->data.mapping_start.tag = 917 yaml_strdup(model->data.mapping_start.tag))) 918 goto error; 919 event->data.mapping_start.is_implicit = 920 model->data.mapping_start.is_implicit; 921 event->data.mapping_start.style = 922 model->data.mapping_start.style; 923 break; 924 925 default: 926 break; 927 } 928 929 return 1; 930 931 error: 932 yaml_event_destroy(event); 933 934 return 0; 935 } 936 937 /* 659 938 * Create STREAM-START. 660 939 */ 661 940 662 941 YAML_DECLARE(int) 663 yaml_ stream_start_event_initialize(yaml_event_t *event,942 yaml_event_create_stream_start(yaml_event_t *event, 664 943 yaml_encoding_t encoding) 665 944 { … … 678 957 679 958 YAML_DECLARE(int) 680 yaml_ stream_end_event_initialize(yaml_event_t *event)959 yaml_event_create_stream_end(yaml_event_t *event) 681 960 { 682 961 yaml_mark_t mark = { 0, 0, 0 }; … … 694 973 695 974 YAML_DECLARE(int) 696 yaml_document_start_event_initialize(yaml_event_t *event, 697 yaml_version_directive_t *version_directive, 698 yaml_tag_directive_t *tag_directives_start, 699 yaml_tag_directive_t *tag_directives_end, 700 int implicit) 975 yaml_event_create_document_start(yaml_event_t *event, 976 const yaml_version_directive_t *version_directive, 977 const yaml_tag_directive_t *tag_directives, 978 int is_implicit) 701 979 { 702 980 struct { 703 yaml_error_t ype_terror;704 } context;981 yaml_error_t error; 982 } self; 705 983 yaml_mark_t mark = { 0, 0, 0 }; 706 984 yaml_version_directive_t *version_directive_copy = NULL; 707 985 struct { 708 yaml_tag_directive_t *start; 709 yaml_tag_directive_t *end; 710 yaml_tag_directive_t *top; 711 } tag_directives_copy = { NULL, NULL, NULL }; 712 yaml_tag_directive_t value = { NULL, NULL }; 986 yaml_tag_directive_t *list; 987 size_t length; 988 size_t capacity; 989 } tag_directives_copy = { NULL, 0, 0 }; 713 990 714 991 assert(event); /* Non-NULL event object is expected. */ 715 assert((tag_directives_start && tag_directives_end) ||716 (tag_directives_start == tag_directives_end));717 /* Valid tag directives are expected. */718 992 719 993 if (version_directive) { 720 994 version_directive_copy = yaml_malloc(sizeof(yaml_version_directive_t)); 721 995 if (!version_directive_copy) goto error; 722 version_directive_copy->major = version_directive->major; 723 version_directive_copy->minor = version_directive->minor; 724 } 725 726 if (tag_directives_start != tag_directives_end) { 727 yaml_tag_directive_t *tag_directive; 728 if (!STACK_INIT(&context, tag_directives_copy, INITIAL_STACK_SIZE)) 996 *version_directive_copy = *version_directive; 997 } 998 999 if (tag_directives && (tag_directives->handle || tag_directives->prefix)) { 1000 if (!STACK_INIT(&self, tag_directives_copy, INITIAL_STACK_CAPACITY)) 729 1001 goto error; 730 for (tag_directive = tag_directives_start; 731 tag_directive != tag_directives_end; tag_directive ++) { 732 assert(tag_directive->handle); 733 assert(tag_directive->prefix); 734 if (!yaml_check_utf8(tag_directive->handle, 735 strlen((char *)tag_directive->handle))) 736 goto error; 737 if (!yaml_check_utf8(tag_directive->prefix, 738 strlen((char *)tag_directive->prefix))) 739 &nb
