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

API refactoring (Note: it breaks the build).

File:
1 edited

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. 
Note: See TracChangeset for help on using the changeset viewer.