Changeset 261 for libyaml/trunk/include/yaml.h
- Timestamp:
- 12/25/07 18:19:23 (5 years ago)
- File:
-
- 1 edited
-
libyaml/trunk/include/yaml.h (modified) (66 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.
Note: See TracChangeset
for help on using the changeset viewer.
