- 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 goto error; 740 value.handle = yaml_strdup(tag_directive->handle); 741 value.prefix = yaml_strdup(tag_directive->prefix); 742 if (!value.handle || !value.prefix) goto error; 743 if (!PUSH(&context, tag_directives_copy, value)) 744 goto error; 745 value.handle = NULL; 746 value.prefix = NULL; 1002 while (tag_directives->handle || tag_directives->prefix) { 1003 yaml_tag_directive_t value = *tag_directives; 1004 assert(value.handle); 1005 assert(value.prefix); 1006 if (!yaml_valid_utf8(value.handle, strlen((char *)value.handle))) 1007 goto error; 1008 if (!yaml_valid_utf8(value.prefix, strlen((char *)value.prefix))) 1009 goto error; 1010 if (!PUSH(&self, tag_directives_copy, value)) 1011 goto error; 1012 value.handle = yaml_strdup(value.handle); 1013 value.prefix = yaml_strdup(value.prefix); 1014 tag_directives_copy.list[tag_directives_copy.length-1] = value; 1015 if (!value.handle || !value.prefix) 1016 goto error; 747 1017 } 748 1018 } 749 1019 750 1020 DOCUMENT_START_EVENT_INIT(*event, version_directive_copy, 751 tag_directives_copy. start, tag_directives_copy.top,752 implicit, mark, mark);1021 tag_directives_copy.list, tag_directives_copy.length, 1022 tag_directives_copy.capacity, is_implicit, mark, mark); 753 1023 754 1024 return 1; … … 756 1026 error: 757 1027 yaml_free(version_directive_copy); 758 while (!STACK_EMPTY( context, tag_directives_copy)) {759 yaml_tag_directive_t value = POP( context, tag_directives_copy);1028 while (!STACK_EMPTY(&self, tag_directives_copy)) { 1029 yaml_tag_directive_t value = POP(&self, tag_directives_copy); 760 1030 yaml_free(value.handle); 761 1031 yaml_free(value.prefix); 762 1032 } 763 STACK_DEL(context, tag_directives_copy); 764 yaml_free(value.handle); 765 yaml_free(value.prefix); 1033 STACK_DEL(&self, tag_directives_copy); 766 1034 767 1035 return 0; … … 773 1041 774 1042 YAML_DECLARE(int) 775 yaml_ document_end_event_initialize(yaml_event_t *event, intimplicit)1043 yaml_event_create_document_end(yaml_event_t *event, int is_implicit) 776 1044 { 777 1045 yaml_mark_t mark = { 0, 0, 0 }; … … 779 1047 assert(event); /* Non-NULL emitter object is expected. */ 780 1048 781 DOCUMENT_END_EVENT_INIT(*event, i mplicit, mark, mark);1049 DOCUMENT_END_EVENT_INIT(*event, is_implicit, mark, mark); 782 1050 783 1051 return 1; … … 789 1057 790 1058 YAML_DECLARE(int) 791 yaml_ alias_event_initialize(yaml_event_t *event,yaml_char_t *anchor)1059 yaml_event_create_alias(yaml_event_t *event, const yaml_char_t *anchor) 792 1060 { 793 1061 yaml_mark_t mark = { 0, 0, 0 }; … … 797 1065 assert(anchor); /* Non-NULL anchor is expected. */ 798 1066 799 if (!yaml_ check_utf8(anchor, strlen((char *)anchor))) return 0;1067 if (!yaml_valid_utf8(anchor, strlen((char *)anchor))) return 0; 800 1068 801 1069 anchor_copy = yaml_strdup(anchor); … … 813 1081 814 1082 YAML_DECLARE(int) 815 yaml_ scalar_event_initialize(yaml_event_t *event,816 yaml_char_t *anchor,yaml_char_t *tag,817 yaml_char_t *value, int length,818 int plain_implicit, intquoted_implicit,1083 yaml_event_create_scalar(yaml_event_t *event, 1084 const yaml_char_t *anchor, const yaml_char_t *tag, 1085 const yaml_char_t *value, size_t length, 1086 int is_plain_implicit, int is_quoted_implicit, 819 1087 yaml_scalar_style_t style) 820 1088 { … … 828 1096 829 1097 if (anchor) { 830 if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error; 1098 if (!yaml_valid_utf8(anchor, strlen((char *)anchor))) 1099 goto error; 831 1100 anchor_copy = yaml_strdup(anchor); 832 if (!anchor_copy) goto error; 1101 if (!anchor_copy) 1102 goto error; 833 1103 } 834 1104 835 1105 if (tag) { 836 if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; 1106 if (!yaml_valid_utf8(tag, strlen((char *)tag))) 1107 goto error; 837 1108 tag_copy = yaml_strdup(tag); 838 if (!tag_copy) goto error; 1109 if (!tag_copy) 1110 goto error; 839 1111 } 840 1112 … … 843 1115 } 844 1116 845 if (!yaml_check_utf8(value, length)) goto error; 1117 if (!yaml_valid_utf8(value, length)) 1118 goto error; 846 1119 value_copy = yaml_malloc(length+1); 847 if (!value_copy) goto error; 1120 if (!value_copy) 1121 goto error; 848 1122 memcpy(value_copy, value, length); 849 1123 value_copy[length] = '\0'; 850 1124 851 1125 SCALAR_EVENT_INIT(*event, anchor_copy, tag_copy, value_copy, length, 852 plain_implicit,quoted_implicit, style, mark, mark);1126 is_plain_implicit, is_quoted_implicit, style, mark, mark); 853 1127 854 1128 return 1; … … 867 1141 868 1142 YAML_DECLARE(int) 869 yaml_ sequence_start_event_initialize(yaml_event_t *event,870 yaml_char_t *anchor, yaml_char_t *tag, int implicit,871 yaml_sequence_style_t style)1143 yaml_event_create_sequence_start(yaml_event_t *event, 1144 const yaml_char_t *anchor, const yaml_char_t *tag, 1145 int is_implicit, yaml_sequence_style_t style) 872 1146 { 873 1147 yaml_mark_t mark = { 0, 0, 0 }; … … 878 1152 879 1153 if (anchor) { 880 if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error; 1154 if (!yaml_valid_utf8(anchor, strlen((char *)anchor))) 1155 goto error; 881 1156 anchor_copy = yaml_strdup(anchor); 882 if (!anchor_copy) goto error; 1157 if (!anchor_copy) 1158 goto error; 883 1159 } 884 1160 885 1161 if (tag) { 886 if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; 1162 if (!yaml_valid_utf8(tag, strlen((char *)tag))) 1163 goto error; 887 1164 tag_copy = yaml_strdup(tag); 888 if (!tag_copy) goto error; 1165 if (!tag_copy) 1166 goto error; 889 1167 } 890 1168 891 1169 SEQUENCE_START_EVENT_INIT(*event, anchor_copy, tag_copy, 892 i mplicit, style, mark, mark);1170 is_implicit, style, mark, mark); 893 1171 894 1172 return 1; … … 906 1184 907 1185 YAML_DECLARE(int) 908 yaml_ sequence_end_event_initialize(yaml_event_t *event)1186 yaml_event_create_sequence_end(yaml_event_t *event) 909 1187 { 910 1188 yaml_mark_t mark = { 0, 0, 0 }; … … 922 1200 923 1201 YAML_DECLARE(int) 924 yaml_ mapping_start_event_initialize(yaml_event_t *event,925 yaml_char_t *anchor, yaml_char_t *tag, int implicit,926 yaml_mapping_style_t style)1202 yaml_event_create_mapping_start(yaml_event_t *event, 1203 const yaml_char_t *anchor, const yaml_char_t *tag, 1204 int is_implicit, yaml_mapping_style_t style) 927 1205 { 928 1206 yaml_mark_t mark = { 0, 0, 0 }; … … 933 1211 934 1212 if (anchor) { 935 if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error; 1213 if (!yaml_valid_utf8(anchor, strlen((char *)anchor))) 1214 goto error; 936 1215 anchor_copy = yaml_strdup(anchor); 937 if (!anchor_copy) goto error; 1216 if (!anchor_copy) 1217 goto error; 938 1218 } 939 1219 940 1220 if (tag) { 941 if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; 1221 if (!yaml_valid_utf8(tag, strlen((char *)tag))) 1222 goto error; 942 1223 tag_copy = yaml_strdup(tag); 943 if (!tag_copy) goto error; 1224 if (!tag_copy) 1225 goto error; 944 1226 } 945 1227 946 1228 MAPPING_START_EVENT_INIT(*event, anchor_copy, tag_copy, 947 i mplicit, style, mark, mark);1229 is_implicit, style, mark, mark); 948 1230 949 1231 return 1; … … 961 1243 962 1244 YAML_DECLARE(int) 963 yaml_ mapping_end_event_initialize(yaml_event_t *event)1245 yaml_event_create_mapping_end(yaml_event_t *event) 964 1246 { 965 1247 yaml_mark_t mark = { 0, 0, 0 }; … … 977 1259 978 1260 YAML_DECLARE(void) 979 yaml_event_delete(yaml_event_t *event) 980 { 981 yaml_tag_directive_t *tag_directive; 1261 yaml_event_destroy(yaml_event_t *event) 1262 { 1263 struct { 1264 yaml_error_t error; 1265 } self; 982 1266 983 1267 assert(event); /* Non-NULL event object expected. */ … … 987 1271 case YAML_DOCUMENT_START_EVENT: 988 1272 yaml_free(event->data.document_start.version_directive); 989 for (tag_directive = event->data.document_start.tag_directives.start;990 tag_directive != event->data.document_start.tag_directives.end;991 tag_directive++) {992 yaml_free( tag_directive->handle);993 yaml_free( tag_directive->prefix);1273 while (!STACK_EMPTY(&self, event->data.document_start.tag_directives)) { 1274 yaml_tag_directive_t value = POP(&self, 1275 event->data.document_start.tag_directives); 1276 yaml_free(value.handle); 1277 yaml_free(value.prefix); 994 1278 } 995 yaml_free(event->data.document_start.tag_directives.start);1279 STACK_DEL(&self, event->data.document_start.tag_directives); 996 1280 break; 997 1281 … … 1022 1306 memset(event, 0, sizeof(yaml_event_t)); 1023 1307 } 1308 1309 #if 0 1024 1310 1025 1311 /* … … 1073 1359 assert(tag_directive->handle); 1074 1360 assert(tag_directive->prefix); 1075 if (!yaml_ check_utf8(tag_directive->handle,1361 if (!yaml_valid_utf8(tag_directive->handle, 1076 1362 strlen((char *)tag_directive->handle))) 1077 1363 goto error; 1078 if (!yaml_ check_utf8(tag_directive->prefix,1364 if (!yaml_valid_utf8(tag_directive->prefix, 1079 1365 strlen((char *)tag_directive->prefix))) 1080 1366 goto error; … … 1211 1497 } 1212 1498 1213 if (!yaml_ check_utf8(tag, strlen((char *)tag))) goto error;1499 if (!yaml_valid_utf8(tag, strlen((char *)tag))) goto error; 1214 1500 tag_copy = yaml_strdup(tag); 1215 1501 if (!tag_copy) goto error; … … 1219 1505 } 1220 1506 1221 if (!yaml_ check_utf8(value, length)) goto error;1507 if (!yaml_valid_utf8(value, length)) goto error; 1222 1508 value_copy = yaml_malloc(length+1); 1223 1509 if (!value_copy) goto error; … … 1263 1549 } 1264 1550 1265 if (!yaml_ check_utf8(tag, strlen((char *)tag))) goto error;1551 if (!yaml_valid_utf8(tag, strlen((char *)tag))) goto error; 1266 1552 tag_copy = yaml_strdup(tag); 1267 1553 if (!tag_copy) goto error; … … 1308 1594 } 1309 1595 1310 if (!yaml_ check_utf8(tag, strlen((char *)tag))) goto error;1596 if (!yaml_valid_utf8(tag, strlen((char *)tag))) goto error; 1311 1597 tag_copy = yaml_strdup(tag); 1312 1598 if (!tag_copy) goto error; … … 1386 1672 } 1387 1673 1388 1674 #endif 1675 -
libyaml/trunk/src/yaml_private.h
r243 r261 26 26 27 27 /* 28 * Reader: Ensure that the buffer contains at least `length` characters. 29 */ 30 31 YAML_DECLARE(int) 32 yaml_parser_update_buffer(yaml_parser_t *parser, size_t length); 33 34 /* 35 * Scanner: Ensure that the token stack contains at least one token ready. 36 */ 37 38 YAML_DECLARE(int) 39 yaml_parser_fetch_more_tokens(yaml_parser_t *parser); 28 * Error management. 29 */ 30 31 #define MEMORY_ERROR_INIT(error) \ 32 (memset(&(error), 0, sizeof(error)), \ 33 (error).type = YAML_MEMORY_ERROR, \ 34 0) 35 36 #define READING_ERROR_INIT(error,error_type,error_problem,error_offset,error_value) \ 37 (memset(&(error), 0, sizeof(error)), \ 38 (error).type = (error_type), \ 39 (error).data.reading.problem = (error_problem), \ 40 (error).data.reading.offset = (error_offset), \ 41 (error).data.reading.value = (error_value), \ 42 0) 43 44 #define LOADING_ERROR_INIT(error,error_type,error_problem,error_problem_mark) \ 45 (memset(&(error), 0, sizeof(error)), \ 46 (error).type = (error_type), \ 47 (error).data.loading.context = NULL, \ 48 (error).data.loading.context_mark.index = 0, \ 49 (error).data.loading.context_mark.line = 0, \ 50 (error).data.loading.context_mark.column = 0, \ 51 (error).data.loading.problem = (error_problem), \ 52 (error).data.loading.problem_mark = (error_problem_mark), \ 53 0) 54 55 #define LOADING_ERROR_WITH_CONTEXT_INIT(error,error_type,error_context,error_context_mark,error_problem,error_problem_mark) \ 56 (memset(&(error), 0, sizeof(error)), \ 57 (error).type = (error_type), \ 58 (error).data.loading.context = (error_context), \ 59 (error).data.loading.context_mark = (error_context_mark), \ 60 (error).data.loading.problem = (error_problem), \ 61 (error).data.loading.problem_mark = (error_problem_mark), \ 62 0) 63 64 #define WRITING_ERROR_INIT(error,error_type,error_problem,error_offset) \ 65 (memset(&(error), 0, sizeof(error)), \ 66 (error).type = (error_type), \ 67 (error).data.writing.problem = (error_problem), \ 68 (error).data.writing.offset = (error_offset), \ 69 0) 70 71 #define DUMPING_ERROR_INIT(error,error_type,error_problem) \ 72 (memset(&(error), 0, sizeof(error)), \ 73 (error).type = (error_type), \ 74 (error).type.dumping.problem = (error_problem), \ 75 0) 76 77 #define READER_ERROR_INIT(error,problem,offset) \ 78 READING_ERROR_INIT(error,YAML_READER_ERROR,problem,offset,-1) 79 80 #define DECODER_ERROR_INIT(error,problem,offset,value) \ 81 READING_ERROR_INIT(error,YAML_DECODER_ERROR,problem,offset,value) 82 83 #define SCANNER_ERROR_INIT(error,problem,problem_mark) \ 84 LOADING_ERROR_INIT(error,YAML_SCANNER_ERROR,problem,problem_mark) 85 86 #define SCANNER_ERROR_WITH_CONTEXT_INIT(error,context,context_mark,problem,problem_mark) \ 87 LOADING_ERROR_WITH_CONTEXT_INIT(error,YAML_SCANNER_ERROR,context,context_mark,problem,problem_mark) 88 89 #define PARSER_ERROR_INIT(error,problem,problem_mark) \ 90 LOADING_ERROR_INIT(error,YAML_PARSER_ERROR,problem,problem_mark) 91 92 #define PARSER_ERROR_WITH_CONTEXT_INIT(error,context,context_mark,problem,problem_mark) \ 93 LOADING_ERROR_WITH_CONTEXT_INIT(error,YAML_PARSER_ERROR,context,context_mark,problem,problem_mark) 94 95 #define COMPOSER_ERROR_INIT(error,problem,problem_mark) \ 96 LOADING_ERROR_INIT(error,YAML_COMPOSER_ERROR,problem,problem_mark) 97 98 #define COMPOSER_ERROR_WITH_CONTEXT_INIT(error,context,context_mark,problem,problem_mark) \ 99 LOADING_ERROR_WITH_CONTEXT_INIT(error,YAML_COMPOSER_ERROR,context,context_mark,problem,problem_mark) 100 101 #define WRITER_ERROR_INIT(error,problem,offset) \ 102 WRITING_ERROR_INIT(error,YAML_WRITER_ERROR,problem,offset) 103 104 #define EMITTER_ERROR_INIT(error,context,problem) \ 105 DUMPING_ERROR_INIT(error,YAML_EMITTER_ERROR,problem) 106 107 #define SERIALIZER_ERROR_INIT(error,context) \ 108 DUMPING_ERROR_INIT(error,YAML_SERIALIZER_ERROR,problem) 40 109 41 110 /* … … 43 112 */ 44 113 45 #define INPUT_RAW_BUFFER_SIZE16384114 #define RAW_INPUT_BUFFER_CAPACITY 16384 46 115 47 116 /* 48 117 * The size of the input buffer. 49 118 * 50 * It should be possible to decode the whole raw buffer. 51 */ 52 53 #define INPUT_BUFFER_SIZE (INPUT_RAW_BUFFER_SIZE*3) 119 * The input buffer should be large enough to hold the content of the raw 120 * buffer after it is decoded. 121 */ 122 123 #define INPUT_BUFFER_CAPACITY (RAW_INPUT_BUFFER_CAPACITY*3) 54 124 55 125 /* … … 57 127 */ 58 128 59 #define OUTPUT_BUFFER_ SIZE16384129 #define OUTPUT_BUFFER_CAPACITY 16384 60 130 61 131 /* 62 132 * The size of the output raw buffer. 63 133 * 64 * It should be possible to encode the whole output buffer. 65 */ 66 67 #define OUTPUT_RAW_BUFFER_SIZE (OUTPUT_BUFFER_SIZE*2+2) 134 * The raw buffer should be able to hold the content of the output buffer 135 * after it is encoded. 136 */ 137 138 #define RAW_OUTPUT_BUFFER_CAPACITY (OUTPUT_BUFFER_CAPACITY*2+2) 68 139 69 140 /* … … 71 142 */ 72 143 73 #define INITIAL_STACK_ SIZE1674 #define INITIAL_QUEUE_ SIZE1675 #define INITIAL_STRING_ SIZE1676 77 /* 78 * Buffer management.79 */ 80 81 #define BUFFER_INIT(context,buffer,size)\82 ((( buffer).start = yaml_malloc(size)) ?\83 (( buffer).last = (buffer).pointer = (buffer).start,\84 (buffer). end = (buffer).start+(size),\144 #define INITIAL_STACK_CAPACITY 16 145 #define INITIAL_QUEUE_CAPACITY 16 146 #define INITIAL_STRING_CAPACITY 16 147 148 /* 149 * Input/output buffer management. 150 */ 151 152 #define STORAGE_INIT(self,storage,storage_capacity) \ 153 (((storage).buffer = yaml_malloc(storage_capacity)) ? \ 154 ((storage).pointer = (storage).length = 0, \ 155 (buffer).capacity = (storage_capacity) \ 85 156 1) : \ 86 (( context)->error = YAML_MEMORY_ERROR,\157 ((self)->error.type = YAML_MEMORY_ERROR, \ 87 158 0)) 88 159 89 #define BUFFER_DEL(context,buffer)\90 (yaml_free(( buffer).start),\91 ( buffer).start = (buffer).pointer = (buffer).end= 0)160 #define STORAGE_DEL(self,storage) \ 161 (yaml_free((storage).buffer), \ 162 (storage).pointer = (storage).length = (storage).capacity = 0) 92 163 93 164 /* … … 95 166 */ 96 167 97 typedef struct {98 yaml_char_t * start;99 yaml_char_t *end;100 yaml_char_t *pointer;168 typedef struct yaml_string_s { 169 yaml_char_t *buffer; 170 size_t pointer; 171 size_t capacity; 101 172 } yaml_string_t; 102 173 103 174 YAML_DECLARE(int) 104 yaml_string_extend(yaml_char_t **start, 105 yaml_char_t **pointer, yaml_char_t **end); 175 yaml_string_extend(yaml_char_t **buffer, size_t *capacity); 106 176 107 177 YAML_DECLARE(int) 108 178 yaml_string_join( 109 yaml_char_t ** a_start, yaml_char_t **a_pointer, yaml_char_t **a_end,110 yaml_char_t * *b_start, yaml_char_t **b_pointer, yaml_char_t **b_end);179 yaml_char_t **base_buffer, size_t *base_pointer, size_t *base_capacity, 180 yaml_char_t *adj_buffer, size_t adj_pointer, size_t adj_capacity); 111 181 112 182 #define NULL_STRING { NULL, NULL, NULL } 113 183 114 #define STRING(string, length) { (string), (string)+(length), (string) }115 116 #define STRING_INIT( context,string,size)\117 (((string). start = yaml_malloc(size)) ?\118 ((string).pointer = (string).start,\119 (string). end = (string).start+(size),\120 memset((string). start, 0, (size)),\184 #define STRING(string,capacity) { (string), 0, (capacity) } 185 186 #define STRING_INIT(self,string,string_capacity) \ 187 (((string).buffer = yaml_malloc(string_capacity)) ? \ 188 ((string).pointer = 0, \ 189 (string).capacity = (string_capacity), \ 190 memset((string).buffer, 0, (string_capacity)), \ 121 191 1) : \ 122 (( context)->error = YAML_MEMORY_ERROR,\192 ((self)->error.type = YAML_MEMORY_ERROR, \ 123 193 0)) 124 194 125 #define STRING_DEL(context,string) \ 126 (yaml_free((string).start), \ 127 (string).start = (string).pointer = (string).end = 0) 128 129 #define STRING_EXTEND(context,string) \ 130 (((string).pointer+5 < (string).end) \ 131 || yaml_string_extend(&(string).start, \ 132 &(string).pointer, &(string).end)) 133 134 #define CLEAR(context,string) \ 135 ((string).pointer = (string).start, \ 136 memset((string).start, 0, (string).end-(string).start)) 137 138 #define JOIN(context,string_a,string_b) \ 139 ((yaml_string_join(&(string_a).start, &(string_a).pointer, \ 140 &(string_a).end, &(string_b).start, \ 141 &(string_b).pointer, &(string_b).end)) ? \ 142 ((string_b).pointer = (string_b).start, \ 195 #define STRING_DEL(self,string) \ 196 (yaml_free((string).buffer), \ 197 (string).buffer = NULL, \ 198 ((string).pointer = (string).capacity = 0)) 199 200 #define STRING_EXTEND(self,string) \ 201 ((((string).pointer+5 < (string).capacity) \ 202 || yaml_string_extend(&(string).buffer, &(string).capacity)) ? \ 203 1 : \ 204 ((self)->error.type = YAML_MEMORY_ERROR, \ 205 0)) 206 207 #define CLEAR(self,string) \ 208 ((string).pointer = 0, \ 209 memset((string).buffer, 0, (string).capacity)) 210 211 #define JOIN(self,base_string,adj_string) \ 212 ((yaml_string_join(&(base_string).buffer, &(base_string).pointer, \ 213 &(base_string).capacity, (adj_string).buffer, \ 214 (adj_string).pointer, (adj_string).capacity)) ? \ 215 ((adj_string).pointer = 0, \ 143 216 1) : \ 144 (( context)->error = YAML_MEMORY_ERROR,\217 ((self)->error.type = YAML_MEMORY_ERROR, \ 145 218 0)) 146 219 … … 150 223 151 224 /* 225 * Get the octet at the specified position. 226 */ 227 228 #define OCTET_AT(string,offset) \ 229 ((string).buffer[(string).pointer+(offset)]) 230 231 /* 232 * Get the current offset. 233 */ 234 235 #define OCTET(string) OCTET_AT((string),0) 236 237 /* 152 238 * Check the octet at the specified position. 153 239 */ 154 240 155 241 #define CHECK_AT(string,octet,offset) \ 156 ( (string).pointer[offset]== (yaml_char_t)(octet))242 (OCTET_AT((string),(offset)) == (yaml_char_t)(octet)) 157 243 158 244 /* … … 168 254 169 255 #define IS_ALPHA_AT(string,offset) \ 170 (( (string).pointer[offset] >= (yaml_char_t) '0' &&\171 (string).pointer[offset] <= (yaml_char_t) '9') ||\172 ( (string).pointer[offset] >= (yaml_char_t) 'A' &&\173 (string).pointer[offset] <= (yaml_char_t) 'Z') ||\174 ( (string).pointer[offset] >= (yaml_char_t) 'a' &&\175 (string).pointer[offset] <= (yaml_char_t) 'z') ||\176 (string).pointer[offset] == '_' ||\177 (string).pointer[offset]== '-')256 ((OCTET_AT((string),(offset)) >= (yaml_char_t) '0' && \ 257 OCTET_AT((string),(offset)) <= (yaml_char_t) '9') || \ 258 (OCTET_AT((string),(offset)) >= (yaml_char_t) 'A' && \ 259 OCTET_AT((string),(offset)) <= (yaml_char_t) 'Z') || \ 260 (OCTET_AT((string),(offset)) >= (yaml_char_t) 'a' && \ 261 OCTET_AT((string),(offset)) <= (yaml_char_t) 'z') || \ 262 OCTET_AT((string),(offset)) == '_' || \ 263 OCTET_AT((string),(offset)) == '-') 178 264 179 265 #define IS_ALPHA(string) IS_ALPHA_AT((string),0) … … 184 270 185 271 #define IS_DIGIT_AT(string,offset) \ 186 (( (string).pointer[offset] >= (yaml_char_t) '0' &&\187 (string).pointer[offset]<= (yaml_char_t) '9'))272 ((OCTET_AT((string),(offset)) >= (yaml_char_t) '0' && \ 273 OCTET_AT((string),(offset)) <= (yaml_char_t) '9')) 188 274 189 275 #define IS_DIGIT(string) IS_DIGIT_AT((string),0) … … 194 280 195 281 #define AS_DIGIT_AT(string,offset) \ 196 ( (string).pointer[offset]- (yaml_char_t) '0')282 (OCTET_AT((string),(offset)) - (yaml_char_t) '0') 197 283 198 284 #define AS_DIGIT(string) AS_DIGIT_AT((string),0) … … 203 289 204 290 #define IS_HEX_AT(string,offset) \ 205 (( (string).pointer[offset] >= (yaml_char_t) '0' &&\206 (string).pointer[offset] <= (yaml_char_t) '9') ||\207 ( (string).pointer[offset] >= (yaml_char_t) 'A' &&\208 (string).pointer[offset] <= (yaml_char_t) 'F') ||\209 ( (string).pointer[offset] >= (yaml_char_t) 'a' &&\210 (string).pointer[offset]<= (yaml_char_t) 'f'))291 ((OCTET_AT((string),(offset)) >= (yaml_char_t) '0' && \ 292 OCTET_AT((string),(offset)) <= (yaml_char_t) '9') || \ 293 (OCTET_AT((string),(offset)) >= (yaml_char_t) 'A' && \ 294 OCTET_AT((string),(offset)) <= (yaml_char_t) 'F') || \ 295 (OCTET_AT((string),(offset)) >= (yaml_char_t) 'a' && \ 296 OCTET_AT((string),(offset)) <= (yaml_char_t) 'f')) 211 297 212 298 #define IS_HEX(string) IS_HEX_AT((string),0) … … 217 303 218 304 #define AS_HEX_AT(string,offset) \ 219 (( (string).pointer[offset] >= (yaml_char_t) 'A' &&\220 (string).pointer[offset] <= (yaml_char_t) 'F') ?\221 ( (string).pointer[offset] - (yaml_char_t) 'A' + 10) :\222 ( (string).pointer[offset] >= (yaml_char_t) 'a' &&\223 (string).pointer[offset] <= (yaml_char_t) 'f') ?\224 ( (string).pointer[offset] - (yaml_char_t) 'a' + 10) :\225 ( (string).pointer[offset]- (yaml_char_t) '0'))305 ((OCTET_AT((string),(offset)) >= (yaml_char_t) 'A' && \ 306 OCTET_AT((string),(offset)) <= (yaml_char_t) 'F') ? \ 307 (OCTET_AT((string),(offset)) - (yaml_char_t) 'A' + 10) : \ 308 (OCTET_AT((string),(offset)) >= (yaml_char_t) 'a' && \ 309 OCTET_AT((string),(offset)) <= (yaml_char_t) 'f') ? \ 310 (OCTET_AT((string),(offset)) - (yaml_char_t) 'a' + 10) : \ 311 (OCTET_AT((string),(offset)) - (yaml_char_t) '0')) 226 312 227 313 #define AS_HEX(string) AS_HEX_AT((string),0) … … 232 318 233 319 #define IS_ASCII_AT(string,offset) \ 234 ( (string).pointer[offset]<= (yaml_char_t) '\x7F')320 (OCTET_AT((string),(offset)) <= (yaml_char_t) '\x7F') 235 321 236 322 #define IS_ASCII(string) IS_ASCII_AT((string),0) … … 241 327 242 328 #define IS_PRINTABLE_AT(string,offset) \ 243 (( (string).pointer[offset] == 0x0A) /* . == #x0A */\244 || ( (string).pointer[offset] >= 0x20 /* #x20 <= . <= #x7E */\245 && (string).pointer[offset] <= 0x7E)\246 || ( (string).pointer[offset] == 0xC2 /* #0xA0 <= . <= #xD7FF */\247 && (string).pointer[offset+1] >= 0xA0)\248 || ( (string).pointer[offset] > 0xC2\249 && (string).pointer[offset] < 0xED)\250 || ( (string).pointer[offset] == 0xED\251 && (string).pointer[offset+1] < 0xA0)\252 || ( (string).pointer[offset] == 0xEE)\253 || ( (string).pointer[offset] == 0xEF /* #xE000 <= . <= #xFFFD */\254 && !( (string).pointer[offset+1] == 0xBB /* && . != #xFEFF */\255 && (string).pointer[offset+2] == 0xBF)\256 && !( (string).pointer[offset+1] == 0xBF\257 && ( (string).pointer[offset+2] == 0xBE\258 || (string).pointer[offset+2]== 0xBF))))329 ((OCTET_AT((string),(offset)) == 0x0A) /* . == #x0A */ \ 330 || (OCTET_AT((string),(offset)) >= 0x20 /* #x20 <= . <= #x7E */ \ 331 && OCTET_AT((string),(offset)) <= 0x7E) \ 332 || (OCTET_AT((string),(offset)) == 0xC2 /* #0xA0 <= . <= #xD7FF */ \ 333 && OCTET_AT((string),(offset)+1) >= 0xA0) \ 334 || (OCTET_AT((string),(offset)) > 0xC2 \ 335 && OCTET_AT((string),(offset)) < 0xED) \ 336 || (OCTET_AT((string),(offset)) == 0xED \ 337 && OCTET_AT((string),(offset)+1) < 0xA0) \ 338 || (OCTET_AT((string),(offset)) == 0xEE) \ 339 || (OCTET_AT((string),(offset)) == 0xEF /* #xE000 <= . <= #xFFFD */ \ 340 && !(OCTET_AT((string),(offset)+1) == 0xBB /* && . != #xFEFF */ \ 341 && OCTET_AT((string),(offset)+2) == 0xBF) \ 342 && !(OCTET_AT((string),(offset)+1) == 0xBF \ 343 && (OCTET_AT((string),(offset)+2) == 0xBE \ 344 || OCTET_AT((string),(offset)+2) == 0xBF)))) 259 345 260 346 #define IS_PRINTABLE(string) IS_PRINTABLE_AT((string),0) … … 359 445 360 446 #define WIDTH_AT(string,offset) \ 361 (( (string).pointer[offset] & 0x80) == 0x00 ? 1 :\362 ( (string).pointer[offset] & 0xE0) == 0xC0 ? 2 :\363 ( (string).pointer[offset] & 0xF0) == 0xE0 ? 3 :\364 ( (string).pointer[offset]& 0xF8) == 0xF0 ? 4 : 0)447 ((OCTET_AT((string),(offset)) & 0x80) == 0x00 ? 1 : \ 448 (OCTET_AT((string),(offset)) & 0xE0) == 0xC0 ? 2 : \ 449 (OCTET_AT((string),(offset)) & 0xF0) == 0xE0 ? 3 : \ 450 (OCTET_AT((string),(offset)) & 0xF8) == 0xF0 ? 4 : 0) 365 451 366 452 #define WIDTH(string) WIDTH_AT((string),0) … … 373 459 374 460 /* 461 * Copy a single octet and bump the pointers. 462 */ 463 464 #define COPY_OCTET(string_a,string_b) \ 465 ((string_a).buffer[(string_a).pointer++] \ 466 = (string_b).buffer[(string_b).pointer++]) 467 468 /* 375 469 * Copy a character and move the pointers of both strings. 376 470 */ 377 471 378 472 #define COPY(string_a,string_b) \ 379 (( *(string_b).pointer & 0x80) == 0x00 ?\380 (*((string_a).pointer++) = *((string_b).pointer++)) :\381 ( *(string_b).pointer & 0xE0) == 0xC0 ?\382 ( *((string_a).pointer++) = *((string_b).pointer++),\383 *((string_a).pointer++) = *((string_b).pointer++)) :\384 ( *(string_b).pointer & 0xF0) == 0xE0 ?\385 ( *((string_a).pointer++) = *((string_b).pointer++),\386 *((string_a).pointer++) = *((string_b).pointer++),\387 *((string_a).pointer++) = *((string_b).pointer++)) :\388 ( *(string_b).pointer & 0xF8) == 0xF0 ?\389 ( *((string_a).pointer++) = *((string_b).pointer++),\390 *((string_a).pointer++) = *((string_b).pointer++),\391 *((string_a).pointer++) = *((string_b).pointer++),\392 *((string_a).pointer++) = *((string_b).pointer++)) : 0)473 ((OCTET(string_b) & 0x80) == 0x00 ? \ 474 COPY_OCTET((string_a),(string_b)) : \ 475 (OCTET(string_b) & 0xE0) == 0xC0 ? \ 476 (COPY_OCTET((string_a),(string_b)), \ 477 COPY_OCTET((string_a),(string_b))) : \ 478 (OCTET(string_b) & 0xF0) == 0xE0 ? \ 479 (COPY_OCTET((string_a),(string_b)), \ 480 COPY_OCTET((string_a),(string_b)), \ 481 COPY_OCTET((string_a),(string_b))) : \ 482 (OCTET(string_b) & 0xF8) == 0xF0 ? \ 483 (COPY_OCTET((string_a),(string_b)), \ 484 COPY_OCTET((string_a),(string_b)), \ 485 COPY_OCTET((string_a),(string_b)), \ 486 COPY_OCTET((string_a),(string_b))) : 0) \ 393 487 394 488 /* … … 397 491 398 492 YAML_DECLARE(int) 399 yaml_stack_extend(void ** start, void **top, void **end);493 yaml_stack_extend(void **list, size_t size, size_t *length, size_t *capacity); 400 494 401 495 YAML_DECLARE(int) 402 yaml_queue_extend(void **start, void **head, void **tail, void **end); 403 404 #define STACK_INIT(context,stack,size) \ 405 (((stack).start = yaml_malloc((size)*sizeof(*(stack).start))) ? \ 406 ((stack).top = (stack).start, \ 407 (stack).end = (stack).start+(size), \ 496 yaml_queue_extend(void **list, size_t size, 497 size_t *head, size_t *tail, size_t *capacity); 498 499 #define STACK_INIT(self,stack,stack_capacity) \ 500 (((stack).list = yaml_malloc((stack_capacity)*sizeof(*(stack).list))) ? \ 501 ((stack).length = 0, \ 502 (stack).capacity = (stack_capacity), \ 408 503 1) : \ 409 (( context)->error = YAML_MEMORY_ERROR,\504 ((self)->error.type = YAML_MEMORY_ERROR, \ 410 505 0)) 411 506 412 #define STACK_DEL(context,stack) \ 413 (yaml_free((stack).start), \ 414 (stack).start = (stack).top = (stack).end = 0) 415 416 #define STACK_EMPTY(context,stack) \ 417 ((stack).start == (stack).top) 418 419 #define PUSH(context,stack,value) \ 420 (((stack).top != (stack).end \ 421 || yaml_stack_extend((void **)&(stack).start, \ 422 (void **)&(stack).top, (void **)&(stack).end)) ? \ 423 (*((stack).top++) = value, \ 507 #define STACK_DEL(self,stack) \ 508 (yaml_free((stack).list), \ 509 (stack).list = NULL, \ 510 (stack).length = (stack).capacity = 0) 511 512 #define STACK_EMPTY(self,stack) \ 513 ((stack).length == 0) 514 515 #define PUSH(self,stack,value) \ 516 (((stack).length < (stack).capacity \ 517 || yaml_stack_extend((void **)&(stack).list, sizeof(*(stack).list), \ 518 &(stack).length, &(stack).capacity)) ? \ 519 ((stack).list[(stack).length++] = (value), \ 424 520 1) : \ 425 (( context)->error = YAML_MEMORY_ERROR,\521 ((self)->error.type = YAML_MEMORY_ERROR, \ 426 522 0)) 427 523 428 #define POP( context,stack)\429 ( *(--(stack).top))430 431 #define QUEUE_INIT( context,queue,size)\432 (((queue). start = yaml_malloc((size)*sizeof(*(queue).start))) ?\433 ((queue).head = (queue).tail = (queue).start,\434 (queue). end = (queue).start+(size),\524 #define POP(self,stack) \ 525 ((stack).list[--(stack).length]) 526 527 #define QUEUE_INIT(self,queue,queue_capacity) \ 528 (((queue).list = yaml_malloc((queue_capacity)*sizeof(*(queue).list))) ? \ 529 ((queue).head = (queue).tail = 0, \ 530 (queue).capacity = (queue_capacity), \ 435 531 1) : \ 436 (( context)->error = YAML_MEMORY_ERROR,\532 ((self)->error.type = YAML_MEMORY_ERROR, \ 437 533 0)) 438 534 439 #define QUEUE_DEL(context,queue) \ 440 (yaml_free((queue).start), \ 441 (queue).start = (queue).head = (queue).tail = (queue).end = 0) 442 443 #define QUEUE_EMPTY(context,queue) \ 535 #define QUEUE_DEL(self,queue) \ 536 (yaml_free((queue).list), \ 537 (queue).list = NULL, \ 538 (queue).head = (queue).tail = (queue).capacity = 0) 539 540 #define QUEUE_EMPTY(self,queue) \ 444 541 ((queue).head == (queue).tail) 445 542 446 #define ENQUEUE( context,queue,value)\447 (((queue).tail != (queue). end\448 || yaml_queue_extend((void **)&(queue). start, (void **)&(queue).head,\449 (void **)&(queue).tail, (void **)&(queue).end)) ? \450 ( *((queue).tail++) = value,\543 #define ENQUEUE(self,queue,value) \ 544 (((queue).tail != (queue).capacity \ 545 || yaml_queue_extend((void **)&(queue).list, sizeof(*(queue).list), \ 546 &(queue).head, &(queue).tail, &(queue).capacity)) ? \ 547 ((queue).list[(queue).tail++] = (value), \ 451 548 1) : \ 452 (( context)->error = YAML_MEMORY_ERROR,\549 ((self)->error.type = YAML_MEMORY_ERROR, \ 453 550 0)) 454 551 455 #define DEQUEUE(context,queue) \ 456 (*((queue).head++)) 457 458 #define QUEUE_INSERT(context,queue,index,value) \ 459 (((queue).tail != (queue).end \ 460 || yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head, \ 461 (void **)&(queue).tail, (void **)&(queue).end)) ? \ 462 (memmove((queue).head+(index)+1,(queue).head+(index), \ 463 ((queue).tail-(queue).head-(index))*sizeof(*(queue).start)), \ 464 *((queue).head+(index)) = value, \ 552 #define DEQUEUE(self,queue) \ 553 ((queue).list[(queue).head++]) 554 555 #define QUEUE_INSERT(self,queue,index,value) \ 556 (((queue).tail != (queue).capacity \ 557 || yaml_queue_extend((void **)&(queue).list, sizeof(*(queue).list), \ 558 &(queue).head, &(queue).tail, &(queue).capacity)) ? \ 559 (memmove((queue).list+(queue).head+(index)+1, \ 560 (queue).list+(queue).head+(index), \ 561 ((queue).tail-(queue).head-(index))*sizeof(*(queue).list)), \ 562 (queue).list[(queue).head+(index)] = (value), \ 465 563 (queue).tail++, \ 466 564 1) : \ 467 (( context)->error = YAML_MEMORY_ERROR,\565 ((self)->error.type = YAML_MEMORY_ERROR, \ 468 566 0)) 469 567 … … 532 630 533 631 #define DOCUMENT_START_EVENT_INIT(event,event_version_directive, \ 534 event_tag_directives_start,event_tag_directives_end,event_implicit,start_mark,end_mark) \ 632 event_tag_directives_list,event_tag_directives_length, \ 633 event_tag_directives_capacity,event_is_implicit,start_mark,end_mark) \ 535 634 (EVENT_INIT((event),YAML_DOCUMENT_START_EVENT,(start_mark),(end_mark)), \ 536 635 (event).data.document_start.version_directive = (event_version_directive), \ 537 (event).data.document_start.tag_directives.start = (event_tag_directives_start), \ 538 (event).data.document_start.tag_directives.end = (event_tag_directives_end), \ 539 (event).data.document_start.implicit = (event_implicit)) 540 541 #define DOCUMENT_END_EVENT_INIT(event,event_implicit,start_mark,end_mark) \ 636 (event).data.document_start.tag_directives.list = (event_tag_directives_list), \ 637 (event).data.document_start.tag_directives.length = (event_tag_directives_length), \ 638 (event).data.document_start.tag_directives.capacity = (event_tag_directives_capacity), \ 639 (event).data.document_start.is_implicit = (event_is_implicit)) 640 641 #define DOCUMENT_END_EVENT_INIT(event,event_is_implicit,start_mark,end_mark) \ 542 642 (EVENT_INIT((event),YAML_DOCUMENT_END_EVENT,(start_mark),(end_mark)), \ 543 (event).data.document_end.i mplicit = (event_implicit))643 (event).data.document_end.is_implicit = (event_is_implicit)) 544 644 545 645 #define ALIAS_EVENT_INIT(event,event_anchor,start_mark,end_mark) \ … … 547 647 (event).data.alias.anchor = (event_anchor)) 548 648 549 #define SCALAR_EVENT_INIT(event,event_anchor,event_tag,event_value,event_length, \ 550 event_plain_implicit, event_quoted_implicit,event_style,start_mark,end_mark) \ 649 #define SCALAR_EVENT_INIT(event,event_anchor,event_tag,event_value, \ 650 event_length,event_is_plain_implicit,event_is_quoted_implicit, \ 651 event_style,start_mark,end_mark) \ 551 652 (EVENT_INIT((event),YAML_SCALAR_EVENT,(start_mark),(end_mark)), \ 552 653 (event).data.scalar.anchor = (event_anchor), \ … … 554 655 (event).data.scalar.value = (event_value), \ 555 656 (event).data.scalar.length = (event_length), \ 556 (event).data.scalar. plain_implicit = (event_plain_implicit),\557 (event).data.scalar. quoted_implicit = (event_quoted_implicit),\657 (event).data.scalar.is_plain_implicit = (event_is_plain_implicit), \ 658 (event).data.scalar.is_quoted_implicit = (event_is_quoted_implicit), \ 558 659 (event).data.scalar.style = (event_style)) 559 660 560 661 #define SEQUENCE_START_EVENT_INIT(event,event_anchor,event_tag, \ 561 event_i mplicit,event_style,start_mark,end_mark)\662 event_is_implicit,event_style,start_mark,end_mark) \ 562 663 (EVENT_INIT((event),YAML_SEQUENCE_START_EVENT,(start_mark),(end_mark)), \ 563 664 (event).data.sequence_start.anchor = (event_anchor), \ 564 665 (event).data.sequence_start.tag = (event_tag), \ 565 (event).data.sequence_start.i mplicit = (event_implicit),\666 (event).data.sequence_start.is_implicit = (event_is_implicit), \ 566 667 (event).data.sequence_start.style = (event_style)) 567 668 … … 570 671 571 672 #define MAPPING_START_EVENT_INIT(event,event_anchor,event_tag, \ 572 event_i mplicit,event_style,start_mark,end_mark)\673 event_is_implicit,event_style,start_mark,end_mark) \ 573 674 (EVENT_INIT((event),YAML_MAPPING_START_EVENT,(start_mark),(end_mark)), \ 574 675 (event).data.mapping_start.anchor = (event_anchor), \ 575 676 (event).data.mapping_start.tag = (event_tag), \ 576 (event).data.mapping_start.i mplicit = (event_implicit),\677 (event).data.mapping_start.is_implicit = (event_is_implicit), \ 577 678 (event).data.mapping_start.style = (event_style)) 578 679 … … 634 735 (node).data.mapping.style = (node_style)) 635 736 737 /* 738 * This structure holds information about a potential simple key. 739 */ 740 741 typedef struct yaml_simple_key_s { 742 /* Is a simple key possible? */ 743 int is_possible; 744 /* Is a simple key required? */ 745 int is_required; 746 /* The number of the token. */ 747 size_t token_number; 748 /* The position mark. */ 749 yaml_mark_t mark; 750 } yaml_simple_key_t; 751 752 /* 753 * The states of the parser. 754 */ 755 756 typedef enum yaml_parser_state_e { 757 /* Expect STREAM-START. */ 758 YAML_PARSE_STREAM_START_STATE, 759 /* Expect the beginning of an implicit document. */ 760 YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE, 761 /* Expect DOCUMENT-START. */ 762 YAML_PARSE_DOCUMENT_START_STATE, 763 /* Expect the content of a document. */ 764 YAML_PARSE_DOCUMENT_CONTENT_STATE, 765 /* Expect DOCUMENT-END. */ 766 YAML_PARSE_DOCUMENT_END_STATE, 767 /* Expect a block node. */ 768 YAML_PARSE_BLOCK_NODE_STATE, 769 /* Expect a block node or indentless sequence. */ 770 YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE, 771 /* Expect a flow node. */ 772 YAML_PARSE_FLOW_NODE_STATE, 773 /* Expect the first entry of a block sequence. */ 774 YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE, 775 /* Expect an entry of a block sequence. */ 776 YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE, 777 /* Expect an entry of an indentless sequence. */ 778 YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE, 779 /* Expect the first key of a block mapping. */ 780 YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE, 781 /* Expect a block mapping key. */ 782 YAML_PARSE_BLOCK_MAPPING_KEY_STATE, 783 /* Expect a block mapping value. */ 784 YAML_PARSE_BLOCK_MAPPING_VALUE_STATE, 785 /* Expect the first entry of a flow sequence. */ 786 YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE, 787 /* Expect an entry of a flow sequence. */ 788 YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE, 789 /* Expect a key of an ordered mapping. */ 790 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE, 791 /* Expect a value of an ordered mapping. */ 792 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE, 793 /* Expect the and of an ordered mapping entry. */ 794 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE, 795 /* Expect the first key of a flow mapping. */ 796 YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE, 797 /* Expect a key of a flow mapping. */ 798 YAML_PARSE_FLOW_MAPPING_KEY_STATE, 799 /* Expect a value of a flow mapping. */ 800 YAML_PARSE_FLOW_MAPPING_VALUE_STATE, 801 /* Expect an empty value of a flow mapping. */ 802 YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE, 803 /* Expect nothing. */ 804 YAML_PARSE_END_STATE 805 } yaml_parser_state_t; 806 807 /* 808 * This structure holds aliases data. 809 */ 810 811 typedef struct yaml_alias_data_s { 812 /* The anchor. */ 813 yaml_char_t *anchor; 814 /* The node id. */ 815 int index; 816 /* The anchor mark. */ 817 yaml_mark_t mark; 818 } yaml_alias_data_t; 819 820 /* 821 * The structure that holds data used by the file and string readers. 822 */ 823 824 typedef union yaml_standard_reader_data_u { 825 /* String input data. */ 826 yaml_string_t string; 827 /* File input data. */ 828 FILE *file; 829 } yaml_standard_reader_data_t; 830 831 /* 832 * The internal parser structure. 833 */ 834 835 struct yaml_parser_s { 836 837 /* 838 * Error stuff. 839 */ 840 841 yaml_error_t error; 842 843 /* 844 * Reader stuff. 845 */ 846 847 /* The read handler. */ 848 yaml_reader_t *reader; 849 850 /* The application data to be passed to the reader. */ 851 void *reader_data; 852 853 /* Standard (string or file) input data. */ 854 yaml_standard_reader_data_t standard_reader_data; 855 856 /* EOF flag. */ 857 int is_eof; 858 859 /* The working buffer. */ 860 struct { 861 yaml_char_t *buffer; 862 size_t pointer; 863 size_t length; 864 size_t capacity; 865 } input; 866 867 /* The number of unread characters in the buffer. */ 868 size_t unread; 869 870 /* The raw buffer. */ 871 struct { 872 unsigned char *buffer; 873 size_t pointer; 874 size_t length; 875 size_t capacity; 876 } raw_input; 877 878 /* The input encoding. */ 879 yaml_encoding_t encoding; 880 881 /* The offset of the current position (in bytes). */ 882 size_t offset; 883 884 /* The mark of the current position. */ 885 yaml_mark_t mark; 886 887 /* 888 * Scanner stuff. 889 */ 890 891 /* Have we started to scan the input stream? */ 892 int is_stream_start_produced; 893 894 /* Have we reached the end of the input stream? */ 895 int is_stream_end_produced; 896 897 /* The number of unclosed '[' and '{' indicators. */ 898 int flow_level; 899 900 /* The tokens queue. */ 901 struct { 902 yaml_token_t *list; 903 size_t head; 904 size_t tail; 905 size_t capacity; 906 } tokens; 907 908 /* The number of tokens fetched from the queue. */ 909 size_t tokens_parsed; 910 911 /* Does the tokens queue contain a token ready for dequeueing. */ 912 int is_token_available; 913 914 /* The indentation levels stack. */ 915 struct { 916 int *list; 917 size_t length; 918 size_t capacity; 919 } indents; 920 921 /* The current indentation level. */ 922 int indent; 923 924 /* May a simple key occur at the current position? */ 925 int is_simple_key_allowed; 926 927 /* The stack of simple keys. */ 928 struct { 929 yaml_simple_key_t *list; 930 size_t length; 931 size_t capacity; 932 } simple_keys; 933 934 /* 935 * Parser stuff. 936 */ 937 938 /* The parser states stack. */ 939 struct { 940 yaml_parser_state_t *list; 941 size_t length; 942 size_t capacity; 943 } states; 944 945 /* The current parser state. */ 946 yaml_parser_state_t state; 947 948 /* The stack of marks. */ 949 struct { 950 yaml_mark_t *list; 951 size_t length; 952 size_t capacity; 953 } marks; 954 955 /* The list of TAG directives. */ 956 struct { 957 yaml_tag_directive_t *list; 958 size_t length; 959 size_t capacity; 960 } tag_directives; 961 962 /* 963 * Dumper stuff. 964 */ 965 966 /* The resolve handler. */ 967 yaml_resolver_t *resolver; 968 969 /* The application data to be passed to the resolver. */ 970 void *resolver_data; 971 972 /* The alias data. */ 973 struct { 974 yaml_alias_data_t *list; 975 size_t length; 976 size_t capacity; 977 } aliases; 978 979 /* The currently parsed document. */ 980 yaml_document_t *document; 981 982 }; 983 984 /* 985 * The emitter states. 986 */ 987 988 typedef enum yaml_emitter_state_e { 989 /** Expect STREAM-START. */ 990 YAML_EMIT_STREAM_START_STATE, 991 /** Expect the first DOCUMENT-START or STREAM-END. */ 992 YAML_EMIT_FIRST_DOCUMENT_START_STATE, 993 /** Expect DOCUMENT-START or STREAM-END. */ 994 YAML_EMIT_DOCUMENT_START_STATE, 995 /** Expect the content of a document. */ 996 YAML_EMIT_DOCUMENT_CONTENT_STATE, 997 /** Expect DOCUMENT-END. */ 998 YAML_EMIT_DOCUMENT_END_STATE, 999 /** Expect the first item of a flow sequence. */ 1000 YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE, 1001 /** Expect an item of a flow sequence. */ 1002 YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE, 1003 /** Expect the first key of a flow mapping. */ 1004 YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE, 1005 /** Expect a key of a flow mapping. */ 1006 YAML_EMIT_FLOW_MAPPING_KEY_STATE, 1007 /** Expect a value for a simple key of a flow mapping. */ 1008 YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE, 1009 /** Expect a value of a flow mapping. */ 1010 YAML_EMIT_FLOW_MAPPING_VALUE_STATE, 1011 /** Expect the first item of a block sequence. */ 1012 YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE, 1013 /** Expect an item of a block sequence. */ 1014 YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE, 1015 /** Expect the first key of a block mapping. */ 1016 YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE, 1017 /** Expect the key of a block mapping. */ 1018 YAML_EMIT_BLOCK_MAPPING_KEY_STATE, 1019 /** Expect a value for a simple key of a block mapping. */ 1020 YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE, 1021 /** Expect a value of a block mapping. */ 1022 YAML_EMIT_BLOCK_MAPPING_VALUE_STATE, 1023 /** Expect nothing. */ 1024 YAML_EMIT_END_STATE 1025 } yaml_emitter_state_t; 1026 1027 /* 1028 * The structure that holds data used by the file and string readers. 1029 */ 1030 1031 typedef union yaml_standard_writer_data_u { 1032 /* String output data. */ 1033 yaml_string_t string; 1034 size_t *length; 1035 /* File output data. */ 1036 FILE *file; 1037 } yaml_standard_writer_data_t; 1038 1039 /* 1040 * The internals emitter structure. 1041 */ 1042 1043 struct yaml_emitter_s { 1044 1045 /* 1046 * Error stuff. 1047 */ 1048 1049 yaml_error_t error; 1050 1051 /* 1052 * Writer stuff. 1053 */ 1054 1055 /* Write handler. */ 1056 yaml_writer_t *writer; 1057 1058 /* A pointer for passing to the white handler. */ 1059 void *writer_data; 1060 1061 /* Standard (string or file) output data. */ 1062 yaml_standard_writer_data_t standard_writer_data; 1063 1064 /* The working buffer. */ 1065 struct { 1066 yaml_char_t *buffer; 1067 size_t pointer; 1068 size_t length; 1069 size_t capacity; 1070 } output; 1071 1072 /* The raw buffer. */ 1073 struct { 1074 yaml_char_t *buffer; 1075 size_t pointer; 1076 size_t length; 1077 size_t capacity; 1078 } raw_output; 1079 1080 /* The stream encoding. */ 1081 yaml_encoding_t encoding; 1082 1083 /* 1084 * Emitter stuff. 1085 */ 1086 1087 /* If the output is in the canonical style? */ 1088 int is_canonical; 1089 /* The number of indentation spaces. */ 1090 int best_indent; 1091 /* The preferred width of the output lines. */ 1092 int best_width; 1093 /* Allow unescaped non-ASCII characters? */ 1094 int is_unicode; 1095 /* The preferred line break. */ 1096 yaml_break_t line_break; 1097 1098 /* The stack of states. */ 1099 struct { 1100 yaml_emitter_state_t *list; 1101 size_t length; 1102 size_t capacity; 1103 } states; 1104 1105 /* The current emitter state. */ 1106 yaml_emitter_state_t state; 1107 1108 /* The event queue. */ 1109 struct { 1110 yaml_event_t *list; 1111 size_t head; 1112 size_t tail; 1113 size_t capacity; 1114 } events; 1115 1116 /* The stack of indentation levels. */ 1117 struct { 1118 int *list; 1119 size_t length; 1120 size_t capacity; 1121 } indents; 1122 1123 /* The list of tag directives. */ 1124 struct { 1125 yaml_tag_directive_t *list; 1126 size_t length; 1127 size_t capacity; 1128 } tag_directives; 1129 1130 /* The current indentation level. */ 1131 int indent; 1132 1133 /* The current flow level. */ 1134 int flow_level; 1135 1136 /* Is it the document root context? */ 1137 int is_root_context; 1138 /* Is it a sequence context? */ 1139 int is_sequence_context; 1140 /* Is it a mapping context? */ 1141 int is_mapping_context; 1142 /* Is it a simple mapping key context? */ 1143 int is_simple_key_context; 1144 1145 /* The current line. */ 1146 int line; 1147 /* The current column. */ 1148 int column; 1149 /* If the last character was a whitespace? */ 1150 int whitespace; 1151 /* If the last character was an indentation character (' ', '-', '?', ':')? */ 1152 int indention; 1153 1154 /* Anchor analysis. */ 1155 struct { 1156 /* The anchor value. */ 1157 yaml_char_t *anchor; 1158 /* The anchor length. */ 1159 size_t anchor_length; 1160 /* Is it an alias? */ 1161 int is_alias; 1162 } anchor_data; 1163 1164 /* Tag analysis. */ 1165 struct { 1166 /* The tag handle. */ 1167 yaml_char_t *handle; 1168 /* The tag handle length. */ 1169 size_t handle_length; 1170 /* The tag suffix. */ 1171 yaml_char_t *suffix; 1172 /* The tag suffix length. */ 1173 size_t suffix_length; 1174 } tag_data; 1175 1176 /* Scalar analysis. */ 1177 struct { 1178 /* The scalar value. */ 1179 yaml_char_t *value; 1180 /* The scalar length. */ 1181 size_t length; 1182 /* Does the scalar contain line breaks? */ 1183 int is_multiline; 1184 /* Can the scalar be expessed in the flow plain style? */ 1185 int is_flow_plain_allowed; 1186 /* Can the scalar be expressed in the block plain style? */ 1187 int is_block_plain_allowed; 1188 /* Can the scalar be expressed in the single quoted style? */ 1189 int is_single_quoted_allowed; 1190 /* Can the scalar be expressed in the literal or folded styles? */ 1191 int is_block_allowed; 1192 /* The output style. */ 1193 yaml_scalar_style_t style; 1194 } scalar_data; 1195 1196 /* 1197 * Dumper stuff. 1198 */ 1199 1200 /* If the stream was already opened? */ 1201 int is_opened; 1202 /* If the stream was already closed? */ 1203 int is_closed; 1204 1205 /* The information associated with the document nodes. */ 1206 struct { 1207 /* The number of references. */ 1208 size_t references; 1209 /* The anchor id. */ 1210 int anchor; 1211 /* If the node has been emitted? */ 1212 int is_serialized; 1213 } *anchors; 1214 1215 /* The last assigned anchor id. */ 1216 int last_anchor_id; 1217 1218 /* The currently emitted document. */ 1219 yaml_document_t *document; 1220 1221 }; 1222 1223 /* 1224 * Reader: Ensure that the buffer contains at least `length` characters. 1225 */ 1226 1227 YAML_DECLARE(int) 1228 yaml_parser_update_buffer(yaml_parser_t *parser, size_t length); 1229 1230 /* 1231 * Scanner: Ensure that the token stack contains at least one token ready. 1232 */ 1233 1234 YAML_DECLARE(int) 1235 yaml_parser_fetch_more_tokens(yaml_parser_t *parser); 1236
