Changeset 261

Show
Ignore:
Timestamp:
12/25/07 18:19:23 (4 years ago)
Author:
xi
Message:

API refactoring (Note: it breaks the build).

Location:
libyaml/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • libyaml/trunk/include/yaml.h

    r243 r261  
    7171 
    7272/** 
     73 * @defgroup styles Error Handling 
     74 * @{ 
     75 */ 
     76 
     77/** Many bad things could happen with the parser and the emitter. */ 
     78typedef 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. */ 
     107typedef 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. */ 
     119typedef 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/** 
    73181 * @defgroup basic Basic Types 
    74182 * @{ 
     
    107215 
    108216/** Line break types. */ 
    109  
    110217typedef enum yaml_break_e { 
    111218    /** Let the parser choose the break type. */ 
     
    119226} yaml_break_t; 
    120227 
    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_ERROR 
    142 } 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  
    156228/** @} */ 
    157229 
     
    279351        } stream_start; 
    280352 
     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 
    281369        /** The alias (for @c YAML_ALIAS_TOKEN). */ 
    282370        struct { 
     
    309397        } scalar; 
    310398 
    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  
    327399    } data; 
    328400 
     
    335407 
    336408/** 
     409 * Allocate a new empty token object. 
     410 * 
     411 * @returns a new token object or @c NULL on error. 
     412 */ 
     413 
     414YAML_DECLARE(yaml_token_t *) 
     415yaml_token_new(void); 
     416 
     417/** 
     418 * Delete and deallocate a token object. 
     419 * 
     420 * @param[in,out]   token   A token object. 
     421 */ 
     422 
     423YAML_DECLARE(void) 
     424yaml_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 
     435YAML_DECLARE(int) 
     436yaml_token_duplicate(yaml_token_t *token, yaml_token_t *model); 
     437 
     438/** 
    337439 * Free any memory allocated for a token object. 
    338440 * 
     
    341443 
    342444YAML_DECLARE(void) 
    343 yaml_token_delete(yaml_token_t *token); 
     445yaml_token_destroy(yaml_token_t *token); 
    344446 
    345447/** @} */ 
     
    403505            /** The list of tag directives. */ 
    404506            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; 
    409513            } tag_directives; 
    410514 
    411515            /** Is the document indicator implicit? */ 
    412             int implicit; 
     516            int is_implicit; 
    413517        } document_start; 
    414518 
     
    416520        struct { 
    417521            /** Is the document end indicator implicit? */ 
    418             int implicit; 
     522            int is_implicit; 
    419523        } document_end; 
    420524 
     
    436540            size_t length; 
    437541            /** Is the tag optional for the plain style? */ 
    438             int plain_implicit; 
     542            int is_plain_implicit; 
    439543            /** Is the tag optional for any non-plain style? */ 
    440             int quoted_implicit; 
     544            int is_quoted_implicit; 
    441545            /** The scalar style. */ 
    442546            yaml_scalar_style_t style; 
     
    450554            yaml_char_t *tag; 
    451555            /** Is the tag optional? */ 
    452             int implicit; 
     556            int is_implicit; 
    453557            /** The sequence style. */ 
    454558            yaml_sequence_style_t style; 
     
    462566            yaml_char_t *tag; 
    463567            /** Is the tag optional? */ 
    464             int implicit; 
     568            int is_implicit; 
    465569            /** The mapping style. */ 
    466570            yaml_mapping_style_t style; 
     
    477581 
    478582/** 
    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 
     588YAML_DECLARE(yaml_event_t *) 
     589yaml_event_new(void); 
     590 
     591/** 
     592 * Delete and deallocate an event object. 
     593 * 
     594 * @param[in,out]   event   An event object. 
     595 */ 
     596 
     597YAML_DECLARE(void) 
     598yaml_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 
     609YAML_DECLARE(int) 
     610yaml_event_duplicate(yaml_event_t *event, yaml_event_t *model); 
     611 
     612/** 
     613 * Create a STREAM-START event. 
     614 * 
     615 * This function never fails. 
    480616 * 
    481617 * @param[out]      event       An empty event object. 
     
    486622 
    487623YAML_DECLARE(int) 
    488 yaml_stream_start_event_initialize(yaml_event_t *event, 
     624yaml_event_create_stream_start(yaml_event_t *event, 
    489625        yaml_encoding_t encoding); 
    490626 
    491627/** 
    492  * Create the STREAM-END event. 
     628 * Create a STREAM-END event. 
     629 * 
     630 * This function never fails. 
    493631 * 
    494632 * @param[out]      event       An empty event object. 
     
    498636 
    499637YAML_DECLARE(int) 
    500 yaml_stream_end_event_initialize(yaml_event_t *event); 
     638yaml_event_create_stream_end(yaml_event_t *event); 
    501639 
    502640/** 
    503641 * Create the DOCUMENT-START event. 
    504  * 
    505  * The @a implicit argument is considered as a stylistic parameter and may be 
    506  * ignored by the emitter. 
    507642 * 
    508643 * @param[out]      event                   An empty event object. 
    509644 * @param[in]       version_directive       The %YAML directive value or 
    510645 *                                          @c NULL. 
    511  * @param[in]       tag_directives_start    The beginning of the %TAG 
    512  *                                          directives list. 
    513  * @param[in]       tag_directives_end      The end of the %TAG directives 
    514  *                                          list. 
    515  * @param[in]       implicit                If the document start indicator is 
    516  *                                          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 implicit); 
     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 
     657YAML_DECLARE(int) 
     658yaml_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); 
    527662 
    528663/** 
    529664 * Create the DOCUMENT-END event. 
    530665 * 
    531  * The @a implicit argument is considered as a stylistic parameter and may be 
    532  * ignored by the emitter. 
    533  * 
    534666 * @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 
     674YAML_DECLARE(int) 
     675yaml_event_create_document_end(yaml_event_t *event, int is_implicit); 
    542676 
    543677/** 
     
    551685 
    552686YAML_DECLARE(int) 
    553 yaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor); 
     687yaml_event_create_alias(yaml_event_t *event, const yaml_char_t *anchor); 
    554688 
    555689/** 
    556690 * Create a SCALAR event. 
    557691 * 
    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 and 
    561  * @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 plain 
    569  *                                  style. 
    570  * @param[in]       quoted_implicit If the tag may be omitted for any 
    571  *                                  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, int quoted_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 
     711YAML_DECLARE(int) 
     712yaml_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, 
    582716        yaml_scalar_style_t style); 
    583717 
    584718/** 
    585719 * 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. 
    590720 * 
    591721 * @param[out]      event       An empty event object. 
    592722 * @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 
     732YAML_DECLARE(int) 
     733yaml_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); 
    604736 
    605737/** 
     
    612744 
    613745YAML_DECLARE(int) 
    614 yaml_sequence_end_event_initialize(yaml_event_t *event); 
     746yaml_event_create_sequence_end(yaml_event_t *event); 
    615747 
    616748/** 
    617749 * 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. 
    622750 * 
    623751 * @param[out]      event       An empty event object. 
    624752 * @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. 
    627756 * @param[in]       style       The mapping style. 
    628757 * 
     
    631760 
    632761YAML_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); 
     762yaml_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); 
    636765 
    637766/** 
     
    644773 
    645774YAML_DECLARE(int) 
    646 yaml_mapping_end_event_initialize(yaml_event_t *event); 
     775yaml_event_create_mapping_end(yaml_event_t *event); 
    647776 
    648777/** 
     
    653782 
    654783YAML_DECLARE(void) 
    655 yaml_event_delete(yaml_event_t *event); 
     784yaml_event_destroy(yaml_event_t *event); 
    656785 
    657786/** @} */ 
     
    672801/** The tag @c !!float for float values. */ 
    673802#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" 
    676803 
    677804/** The tag @c !!seq is used to denote sequences. */ 
     
    700827} yaml_node_type_t; 
    701828 
     829/** Arc types. */ 
     830typedef 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 
    702842/** The forward definition of a document node structure. */ 
    703843typedef struct yaml_node_s yaml_node_t; 
     
    714854} yaml_node_pair_t; 
    715855 
     856/** An element of a path in a YAML document. */ 
     857typedef 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 
    716866/** The node structure. */ 
    717867struct yaml_node_s { 
     
    720870    yaml_node_type_t type; 
    721871 
     872    /** The node anchor. */ 
     873    yaml_char_t *anchor; 
    722874    /** The node tag. */ 
    723875    yaml_char_t *tag; 
     
    738890        /** The sequence parameters (for @c YAML_SEQUENCE_NODE). */ 
    739891        struct { 
    740             /** The stack of sequence items. */ 
     892            /** The list of sequence items. */ 
    741893            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; 
    748900            } items; 
    749901            /** The sequence style. */ 
     
    753905        /** The mapping parameters (for @c YAML_MAPPING_NODE). */ 
    754906        struct { 
    755             /** The stack of mapping pairs (key, value). */ 
     907            /** The list of mapping pairs (key, value). */ 
    756908            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; 
    763915            } pairs; 
    764916            /** The mapping style. */ 
     
    775927}; 
    776928 
     929/** The incomplete node structure. */ 
     930typedef 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 
    777965/** The document structure. */ 
    778966typedef struct yaml_document_s { 
     
    780968    /** The document nodes. */ 
    781969    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; 
    788976    } nodes; 
    789977 
     
    793981    /** The list of tag directives. */ 
    794982    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; 
    799989    } tag_directives; 
    800990 
    801991    /** Is the document start indicator implicit? */ 
    802     int start_implicit; 
     992    int is_start_implicit; 
    803993    /** Is the document end indicator implicit? */ 
    804     int end_implicit; 
     994    int is_end_implicit; 
    805995 
    806996    /** The beginning of the document. */ 
     
    8111001} yaml_document_t; 
    8121002 
     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 
     1011YAML_DECLARE(yaml_document_t *) 
     1012yaml_document_new(void); 
     1013 
     1014/** 
     1015 * Delete and deallocatge a document object. 
     1016 * 
     1017 * @param[in,out]   document    A document object. 
     1018 */ 
     1019 
     1020YAML_DECLARE(void) 
     1021yaml_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 
     1032YAML_DECLARE(int) 
     1033yaml_document_duplicate(yaml_document_t *document, yaml_document_t *model); 
     1034 
    8131035/** 
    8141036 * Create a YAML document. 
     
    8171039 * @param[in]       version_directive       The %YAML directive value or 
    8181040 *                                          @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 
    8241045 *                                          implicit. 
    825  * @param[in]       end_implicit            If the document end indicator is 
     1046 * @param[in]       is_end_implicit         If the document end indicator is 
    8261047 *                                          implicit. 
    8271048 * 
     
    8301051 
    8311052YAML_DECLARE(int) 
    832 yaml_document_initialize(yaml_document_t *document, 
     1053yaml_document_create(yaml_document_t *document, 
    8331054        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); 
    8371057 
    8381058/** 
     
    8431063 
    8441064YAML_DECLARE(void) 
    845 yaml_document_delete(yaml_document_t *document); 
     1065yaml_document_destroy(yaml_document_t *document); 
    8461066 
    8471067/** 
     
    8491069 * 
    8501070 * The pointer returned by this function is valid until any of the functions 
    851  * modifying the documents are called. 
     1071 * modifying the documents is called. 
    8521072 * 
    8531073 * @param[in]       document        A document object. 
     
    8661086 * 
    8671087 * The pointer returned by this function is valid until any of the functions 
    868  * modifying the documents are called. 
     1088 * modifying the documents is called. 
    8691089 * 
    8701090 * An empty document produced by the parser signifies the end of a YAML 
     
    8851105 * 
    8861106 * @param[in,out]   document        A document object. 
     1107 * @param[in]       anchor          A preferred anchor for the node or @c NULL. 
    8871108 * @param[in]       tag             The scalar tag. 
    8881109 * @param[in]       value           The scalar value. 
     
    8951116YAML_DECLARE(int) 
    8961117yaml_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); 
    8991120 
    9001121/** 
     
    9041125 * 
    9051126 * @param[in,out]   document    A document object. 
     1127 * @param[in]       anchor      A preferred anchor for the node or @c NULL. 
    9061128 * @param[in]       tag         The sequence tag. 
    9071129 * @param[in]       style       The sequence style. 
     
    9121134YAML_DECLARE(int) 
    9131135yaml_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); 
    9151137 
    9161138/** 
     
    9201142 * 
    9211143 * @param[in,out]   document    A document object. 
     1144 * @param[in]       anchor      A preferred anchor for the node or @c NULL. 
    9221145 * @param[in]       tag         The sequence tag. 
    9231146 * @param[in]       style       The sequence style. 
     
    9281151YAML_DECLARE(int) 
    9291152yaml_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); 
    9311154 
    9321155/** 
     
    9591182        int mapping, int key, int value); 
    9601183 
    961 /** @} */ 
    962  
    963 /** 
    964  * @defgroup parser Parser Definitions 
     1184#endif 
     1185 
     1186/** 
     1187 * @defgroup callbacks Callback Definitions 
    9651188 * @{ 
    9661189 */ 
     
    9701193 * 
    9711194 * 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. 
    9741199 * 
    9751200 * @param[in,out]   data        A pointer to an application data specified by 
    976  *                              yaml_parser_set_input(). 
     1201 *                              @c yaml_parser_set_reader(). 
    9771202 * @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_read   The 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. 
    9801205 * 
    9811206 * @returns On success, the handler should return @c 1.  If the handler failed, 
     
    9841209 */ 
    9851210 
    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. 
     1211typedef 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 
     1230typedef 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 
     1251typedef 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. */ 
     1262typedef struct yaml_parser_s yaml_parser_t; 
     1263 
     1264/** 
     1265 * Create a new parser object. 
    13071266 * 
    13081267 * 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 
     1273YAML_DECLARE(yaml_parser_t *) 
     1274yaml_parser_new(void); 
    13181275 
    13191276/** 
     
    13251282YAML_DECLARE(void) 
    13261283yaml_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 
     1292YAML_DECLARE(void) 
     1293yaml_parser_get_error(yaml_parser_t *parser, yaml_error_t *error); 
    13271294 
    13281295/** 
     
    13341301 * 
    13351302 * @param[in,out]   parser  A parser object. 
    1336  * @param[in]       input   A source data. 
    1337  * @param[in]       size    The 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 
     1307YAML_DECLARE(void) 
     1308yaml_parser_set_string_reader(yaml_parser_t *parser, 
     1309        const unsigned char *buffer, size_t length); 
    13431310 
    13441311/** 
     
    13531320 
    13541321YAML_DECLARE(void) 
    1355 yaml_parser_set_input_file(yaml_parser_t *parser, FILE *file); 
     1322yaml_parser_set_file_reader(yaml_parser_t *parser, FILE *file); 
    13561323 
    13571324/** 
     
    13591326 * 
    13601327 * @param[in,out]   parser  A parser object. 
    1361  * @param[in]       handler A read handler. 
     1328 * @param[in]       reader A read handler. 
    13621329 * @param[in]       data    Any application data for passing to the read 
    13631330 *                          handler. 
     
    13651332 
    13661333YAML_DECLARE(void) 
    1367 yaml_parser_set_input(yaml_parser_t *parser, 
    1368         yaml_read_handler_t *handler, void *data); 
     1334yaml_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 
     1348YAML_DECLARE(void) 
     1349yaml_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 
     1363YAML_DECLARE(void) 
     1364yaml_parser_set_resolver(yaml_parser_t *parser, 
     1365        yaml_resolver_t *resolver, void *data); 
     1366 
     1367#endif 
    13691368 
    13701369/** 
     
    13871386 * 
    13881387 * 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 the 
    1392  * calls of yaml_parser_parse() or yaml_parser_load(). Doing this will break 
    1393  * 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. 
    13941393 * 
    13951394 * @param[in,out]   parser      A parser object. 
     
    14111410 * 
    14121411 * 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 the 
    1416  * calls of yaml_parser_scan() or yaml_parser_load(). Doing this will break the 
    1417  * 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. 
    14181417 * 
    14191418 * @param[in,out]   parser      A parser object. 
     
    14261425yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event); 
    14271426 
     1427#if 0 
     1428 
    14281429/** 
    14291430 * Parse the input stream and produce the next YAML document. 
     
    14361437 * 
    14371438 * 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 the 
    1441  * calls of yaml_parser_scan() or yaml_parser_parse(). Doing this will break 
    1442  * 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. 
    14431444 * 
    14441445 * @param[in,out]   parser      A parser object. 
     
    14511452yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document); 
    14521453 
     1454#endif 
     1455 
    14531456/** @} */ 
    14541457 
     
    14581461 */ 
    14591462 
    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. */ 
     1464typedef struct yaml_emitter_s yaml_emitter_t; 
     1465 
     1466/** 
     1467 * Create a new emitter object. 
    17641468 * 
    17651469 * 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 
     1475YAML_DECLARE(yaml_emitter_t *) 
     1476yaml_emitter_new(void); 
    17751477 
    17761478/** 
     
    17821484YAML_DECLARE(void) 
    17831485yaml_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 
     1494YAML_DECLARE(void) 
     1495yaml_emitter_get_error(yaml_emitter_t *emitter, yaml_error_t *error); 
    17841496 
    17851497/** 
     
    17891501 * size @a size.  The emitter will set @a size_written to the number of written 
    17901502 * bytes.  If the buffer is smaller than required, the emitter produces the 
    1791  * YAML_WRITE_ERROR error. 
     1503 * @c YAML_WRITE_ERROR error. 
    17921504 * 
    17931505 * @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 
    17971508 *                                  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 
     1512YAML_DECLARE(void) 
     1513yaml_emitter_set_string_writer(yaml_emitter_t *emitter, 
     1514        unsigned char *buffer, size_t *length, size_t capacity); 
    18031515 
    18041516/** 
     
    18131525 
    18141526YAML_DECLARE(void) 
    1815 yaml_emitter_set_output_file(yaml_emitter_t *emitter, FILE *file); 
     1527yaml_emitter_set_file_writer(yaml_emitter_t *emitter, FILE *file); 
    18161528 
    18171529/** 
     
    18191531 * 
    18201532 * @param[in,out]   emitter     An emitter object. 
    1821  * @param[in]       handler     A write handler. 
     1533 * @param[in]       writer      A write handler. 
    18221534 * @param[in]       data        Any application data for passing to the write 
    18231535 *                              handler. 
     
    18251537 
    18261538YAML_DECLARE(void) 
    1827 yaml_emitter_set_output(yaml_emitter_t *emitter, 
    1828         yaml_write_handler_t *handler, void *data); 
     1539yaml_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 
     1553YAML_DECLARE(void) 
     1554yaml_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 
     1568YAML_DECLARE(void) 
     1569yaml_emitter_set_resolver(yaml_emitter_t *emitter, 
     1570        yaml_resolver_t *resolver, void *data); 
     1571 
     1572#endif 
    18291573 
    18301574/** 
     
    18421586 * specification. 
    18431587 * 
    1844  * @param[in,out]   emitter     An emitter object. 
    1845  * @param[in]       canonical   If 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 
     1592YAML_DECLARE(void) 
     1593yaml_emitter_set_canonical(yaml_emitter_t *emitter, int is_canonical); 
    18501594 
    18511595/** 
     
    18731617 * 
    18741618 * @param[in,out]   emitter     An emitter object. 
    1875  * @param[in]       unicode     If 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 
     1622YAML_DECLARE(void) 
     1623yaml_emitter_set_unicode(yaml_emitter_t *emitter, int is_unicode); 
    18801624 
    18811625/** 
     
    19061650yaml_emitter_emit(yaml_emitter_t *emitter, yaml_event_t *event); 
    19071651 
     1652#if 0 
     1653 
    19081654/** 
    19091655 * Start a YAML stream. 
    19101656 * 
    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. 
    19121659 * 
    19131660 * @param[in,out]   emitter     An emitter object. 
     
    19221669 * Finish a YAML stream. 
    19231670 * 
    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. 
    19251673 * 
    19261674 * @param[in,out]   emitter     An emitter object. 
     
    19351683 * Emit a YAML document. 
    19361684 * 
    1937  * The documen object may be generated using the yaml_parser_load() function 
    1938  * or the yaml_document_initialize() function.  The emitter takes the 
    1939  * responsibility for the document object and destoys its content after 
    1940  * it is emitted. The document object is destroyedeven 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. 
    19411689 * 
    19421690 * @param[in,out]   emitter     An emitter object. 
     
    19491697yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document); 
    19501698 
    1951 /** 
    1952  * Flush the accumulated characters to the output. 
     1699#endif 
     1700 
     1701/** 
     1702 * Flush the accumulated characters to the output stream. 
    19531703 * 
    19541704 * @param[in,out]   emitter     An emitter object. 
  • libyaml/trunk/src/api.c

    r243 r261  
    7272 
    7373YAML_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. 
     74yaml_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. 
    9290 */ 
    9391 
    9492YAML_DECLARE(int) 
    9593yaml_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) 
    10098        return 1; 
    10199 
    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)) 
    104102            return 0; 
    105103    } 
    106104 
    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; 
    109107 
    110108    return 1; 
     
    116114 
    117115YAML_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; 
     116yaml_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; 
    127124 
    128125    return 1; 
     
    134131 
    135132YAML_DECLARE(int) 
    136 yaml_queue_extend(void **start, void **head, void **tail, void **end) 
     133yaml_queue_extend(void **list, size_t size, 
     134        size_t *head, size_t *tail, size_t *capacity) 
    137135{ 
    138136    /* Check if we need to resize the queue. */ 
    139137 
    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; 
    150145    } 
    151146 
    152147    /* Check if we need to move the queue at the beginning of the buffer. */ 
    153148 
    154     if (*tail == *end) { 
     149    if (*tail == *capacity) { 
    155150        if (*head != *tail) { 
    156             memmove(*start, *head, (char *)*tail - (char *)*head); 
     151            memmove((char *)*list, (char *)*list + (*head)*size, 
     152                    (*tail-*head)*size); 
    157153        } 
    158         *tail = (char *)*tail - (char *)*head + (char *)*start; 
    159         *head = *start; 
     154        *tail -= *head; 
     155        *head = 0; 
    160156    } 
    161157 
     
    168164 */ 
    169165 
    170 YAML_DECLARE(int) 
    171 yaml_parser_initialize(yaml_parser_t *parser) 
    172 { 
    173     assert(parser);     /* Non-NULL parser object expected. */ 
     166YAML_DECLARE(yaml_parser_t *) 
     167yaml_parser_new(void) 
     168{ 
     169    yaml_parser_t *parser = yaml_malloc(sizeof(yaml_parser_t)); 
     170 
     171    if (!parser) 
     172        return NULL; 
    174173 
    175174    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)) 
    177176        goto error; 
    178     if (!BUFFER_INIT(parser, parser->buffer, INPUT_BUFFER_SIZE)) 
     177    if (!BUFFER_INIT(parser, parser->input, INPUT_BUFFER_CAPACITY)) 
    179178        goto error; 
    180     if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_SIZE)) 
     179    if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_CAPACITY)) 
    181180        goto error; 
    182     if (!STACK_INIT(parser, parser->indents, INITIAL_STACK_SIZE)) 
     181    if (!STACK_INIT(parser, parser->indents, INITIAL_STACK_CAPACITY)) 
    183182        goto error; 
    184     if (!STACK_INIT(parser, parser->simple_keys, INITIAL_STACK_SIZE)) 
     183    if (!STACK_INIT(parser, parser->simple_keys, INITIAL_STACK_CAPACITY)) 
    185184        goto error; 
    186     if (!STACK_INIT(parser, parser->states, INITIAL_STACK_SIZE)) 
     185    if (!STACK_INIT(parser, parser->states, INITIAL_STACK_CAPACITY)) 
    187186        goto error; 
    188     if (!STACK_INIT(parser, parser->marks, INITIAL_STACK_SIZE)) 
     187    if (!STACK_INIT(parser, parser->marks, INITIAL_STACK_CAPACITY)) 
    189188        goto error; 
    190     if (!STACK_INIT(parser, parser->tag_directives, INITIAL_STACK_SIZE)) 
     189    if (!STACK_INIT(parser, parser->tag_directives, INITIAL_STACK_CAPACITY)) 
    191190        goto error; 
    192191 
    193     return 1; 
     192    return parser; 
    194193 
    195194error: 
    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; 
    207198} 
    208199 
     
    216207    assert(parser); /* Non-NULL parser object expected. */ 
    217208 
    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); 
    220211    while (!QUEUE_EMPTY(parser, parser->tokens)) { 
    221         yaml_token_delete(&DEQUEUE(parser, parser->tokens)); 
     212        yaml_token_destroy(&DEQUEUE(parser, parser->tokens)); 
    222213    } 
    223214    QUEUE_DEL(parser, parser->tokens); 
     
    234225 
    235226    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 
     234YAML_DECLARE(void) 
     235yaml_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. 
    240244 */ 
    241245 
    242246static 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; 
     247yaml_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; 
    250254        return 1; 
    251255    } 
    252256 
    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. 
    266269 */ 
    267270 
    268271static 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); 
     272yaml_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); 
    276279} 
    277280 
     
    281284 
    282285YAML_DECLARE(void) 
    283 yaml_parser_set_input_string(yaml_parser_t *parser, 
    284         const unsigned char *input, size_t size) 
     286yaml_parser_set_string_reader(yaml_parser_t *parser, 
     287        const unsigned char *buffer, size_t length) 
    285288{ 
    286289    assert(parser); /* Non-NULL parser object expected. */ 
    287     assert(!parser->read_handler);  /* You can set the source only 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; 
    296299} 
    297300 
     
    301304 
    302305YAML_DECLARE(void) 
    303 yaml_parser_set_input_file(yaml_parser_t *parser, FILE *file) 
     306yaml_parser_set_file_reader(yaml_parser_t *parser, FILE *file) 
    304307{ 
    305308    assert(parser); /* Non-NULL parser object expected. */ 
    306     assert(!parser->read_handler);  /* You can set the source only once. */ 
     309    assert(!parser->reader);    /* You can set the input handler only once. */ 
    307310    assert(file);   /* Non-NULL file object expected. */ 
    308311 
    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; 
    313316} 
    314317 
     
    318321 
    319322YAML_DECLARE(void) 
    320 yaml_parser_set_input(yaml_parser_t *parser, 
    321         yaml_read_handler_t *handler, void *data) 
     323yaml_parser_set_reader(yaml_parser_t *parser, 
     324        yaml_reader_t *reader, void *data) 
    322325{ 
    323326    assert(parser); /* Non-NULL parser object expected. */ 
    324     assert(!parser->read_handler);  /* You can set the source only 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; 
    329332} 
    330333 
     
    337340{ 
    338341    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. */ 
    340343 
    341344    parser->encoding = encoding; 
     
    346349 */ 
    347350 
    348 YAML_DECLARE(int) 
    349 yaml_emitter_initialize(yaml_emitter_t *emitter) 
     351YAML_DECLARE(yaml_emitter_t *) 
     352yaml_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 
     375error: 
     376    yaml_emitter_delete(emitter); 
     377 
     378    return NULL; 
     379} 
     380 
     381/* 
     382 * Destroy an emitter object. 
     383 */ 
     384 
     385YAML_DECLARE(void) 
     386yaml_emitter_delete(yaml_emitter_t *emitter) 
    350387{ 
    351388    assert(emitter);    /* Non-NULL emitter object expected. */ 
    352389 
    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); 
    392392    STACK_DEL(emitter, emitter->states); 
    393393    while (!QUEUE_EMPTY(emitter, emitter->events)) { 
     
    405405 
    406406    memset(emitter, 0, sizeof(yaml_emitter_t)); 
     407    yaml_free(emitter); 
     408} 
     409 
     410/* 
     411 * Get the current emitter error. 
     412 */ 
     413 
     414YAML_DECLARE(void) 
     415yaml_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; 
    407420} 
    408421 
     
    412425 
    413426static 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; 
     427yaml_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; 
    433442} 
    434443 
     
    438447 
    439448static 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); 
     449yaml_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); 
    445454} 
    446455/* 
     
    449458 
    450459YAML_DECLARE(void) 
    451 yaml_emitter_set_output_string(yaml_emitter_t *emitter, 
    452         unsigned char *output, size_t size, size_t *size_written) 
     460yaml_emitter_set_string_writer(yaml_emitter_t *emitter, 
     461        unsigned char *buffer, size_t *length, size_t capacity) 
    453462{ 
    454463    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; 
    465476} 
    466477 
     
    470481 
    471482YAML_DECLARE(void) 
    472 yaml_emitter_set_output_file(yaml_emitter_t *emitter, FILE *file) 
     483yaml_emitter_set_file_writer(yaml_emitter_t *emitter, FILE *file) 
    473484{ 
    474485    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. */ 
    476487    assert(file);       /* Non-NULL file object expected. */ 
    477488 
    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; 
    482493} 
    483494 
     
    487498 
    488499YAML_DECLARE(void) 
    489 yaml_emitter_set_output(yaml_emitter_t *emitter, 
    490         yaml_write_handler_t *handler, void *data) 
     500yaml_emitter_set_writer(yaml_emitter_t *emitter, 
     501        yaml_writer_t *writer, void *data) 
    491502{ 
    492503    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; 
    498509} 
    499510 
     
    516527 
    517528YAML_DECLARE(void) 
    518 yaml_emitter_set_canonical(yaml_emitter_t *emitter, int canonical) 
     529yaml_emitter_set_canonical(yaml_emitter_t *emitter, int is_canonical) 
    519530{ 
    520531    assert(emitter);    /* Non-NULL emitter object expected. */ 
    521532 
    522     emitter->canonical = (canonical != 0); 
     533    emitter->is_canonical = (is_canonical != 0); 
    523534} 
    524535 
     
    552563 
    553564YAML_DECLARE(void) 
    554 yaml_emitter_set_unicode(yaml_emitter_t *emitter, int unicode) 
     565yaml_emitter_set_unicode(yaml_emitter_t *emitter, int is_unicode) 
    555566{ 
    556567    assert(emitter);    /* Non-NULL emitter object expected. */ 
    557568 
    558     emitter->unicode = (unicode != 0); 
     569    emitter->is_unicode = (is_unicode != 0); 
    559570} 
    560571 
     
    572583 
    573584/* 
     585 * Allocate a token object. 
     586 */ 
     587 
     588YAML_DECLARE(yaml_token_t *) 
     589yaml_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 
     605YAML_DECLARE(void) 
     606yaml_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 
     618YAML_DECLARE(int) 
     619yaml_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 
     687error: 
     688    yaml_token_destroy(token); 
     689 
     690    return 0; 
     691} 
     692 
     693/* 
    574694 * Destroy a token object. 
    575695 */ 
    576696 
    577697YAML_DECLARE(void) 
    578 yaml_token_delete(yaml_token_t *token) 
     698yaml_token_destroy(yaml_token_t *token) 
    579699{ 
    580700    assert(token);  /* Non-NULL token object expected. */ 
     
    618738 
    619739static 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) { 
     740yaml_valid_utf8(const yaml_char_t *buffer, size_t length) 
     741{ 
     742    size_t pointer = 0; 
     743 
     744    while (pointer < length) { 
    626745        unsigned char octet; 
    627746        unsigned int width; 
     
    629748        size_t k; 
    630749 
    631         octet = pointer[0]; 
     750        octet = buffer[pointer]; 
    632751        width = (octet & 0x80) == 0x00 ? 1 : 
    633752                (octet & 0xE0) == 0xC0 ? 2 : 
     
    639758                (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; 
    640759        if (!width) return 0; 
    641         if (pointer+width > end) return 0; 
     760        if (pointer+width > length) return 0; 
    642761        for (k = 1; k < width; k ++) { 
    643             octet = pointer[k]; 
     762            octet = buffer[pointer+k]; 
    644763            if ((octet & 0xC0) != 0x80) return 0; 
    645764            value = (value << 6) + (octet & 0x3F); 
     
    657776 
    658777/* 
     778 * Allocate an event object. 
     779 */ 
     780 
     781YAML_DECLARE(yaml_event_t *) 
     782yaml_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 
     798YAML_DECLARE(void) 
     799yaml_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 
     811YAML_DECLARE(int) 
     812yaml_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 
     931error: 
     932    yaml_event_destroy(event); 
     933 
     934    return 0; 
     935} 
     936 
     937/* 
    659938 * Create STREAM-START. 
    660939 */ 
    661940 
    662941YAML_DECLARE(int) 
    663 yaml_stream_start_event_initialize(yaml_event_t *event, 
     942yaml_event_create_stream_start(yaml_event_t *event, 
    664943        yaml_encoding_t encoding) 
    665944{ 
     
    678957 
    679958YAML_DECLARE(int) 
    680 yaml_stream_end_event_initialize(yaml_event_t *event) 
     959yaml_event_create_stream_end(yaml_event_t *event) 
    681960{ 
    682961    yaml_mark_t mark = { 0, 0, 0 }; 
     
    694973 
    695974YAML_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) 
     975yaml_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) 
    701979{ 
    702980    struct { 
    703         yaml_error_type_t error; 
    704     } context; 
     981        yaml_error_t error; 
     982    } self; 
    705983    yaml_mark_t mark = { 0, 0, 0 }; 
    706984    yaml_version_directive_t *version_directive_copy = NULL; 
    707985    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 }; 
    713990 
    714991    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. */ 
    718992 
    719993    if (version_directive) { 
    720994        version_directive_copy = yaml_malloc(sizeof(yaml_version_directive_t)); 
    721995        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)) 
    7291001            goto error; 
    730         for (tag_directive = tag_directives_start; 
    731                 tag_directive != tag_directives_end; tag_directive ++) { 
    732             assert(tag_directive->handle); 
    733             assert(tag_directive->prefix); 
    734             if (!yaml_check_utf8(tag_directive->handle, 
    735                         strlen((char *)tag_directive->handle))) 
    736                 goto error; 
    737             if (!yaml_check_utf8(tag_directive->prefix, 
    738                         strlen((char *)tag_directive->prefix))) 
    739               &nb