Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/yaml.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /**
0002  * @file yaml.h
0003  * @brief Public interface for libyaml.
0004  * 
0005  * Include the header file with the code:
0006  * @code
0007  * #include <yaml.h>
0008  * @endcode
0009  */
0010 
0011 #ifndef YAML_H
0012 #define YAML_H
0013 
0014 #ifdef __cplusplus
0015 extern "C" {
0016 #endif
0017 
0018 #include <stdlib.h>
0019 #include <stdio.h>
0020 #include <string.h>
0021 
0022 /**
0023  * @defgroup export Export Definitions
0024  * @{
0025  */
0026 
0027 /** The public API declaration. */
0028 
0029 #if defined(__MINGW32__)
0030 #   define  YAML_DECLARE(type)  type
0031 #elif defined(_WIN32)
0032 #   if defined(YAML_DECLARE_STATIC)
0033 #       define  YAML_DECLARE(type)  type
0034 #   elif defined(YAML_DECLARE_EXPORT)
0035 #       define  YAML_DECLARE(type)  __declspec(dllexport) type
0036 #   else
0037 #       define  YAML_DECLARE(type)  __declspec(dllimport) type
0038 #   endif
0039 #else
0040 #   define  YAML_DECLARE(type)  type
0041 #endif
0042 
0043 /** @} */
0044 
0045 /**
0046  * @defgroup version Version Information
0047  * @{
0048  */
0049 
0050 /**
0051  * Get the library version as a string.
0052  *
0053  * @returns The function returns the pointer to a static string of the form
0054  * @c "X.Y.Z", where @c X is the major version number, @c Y is a minor version
0055  * number, and @c Z is the patch version number.
0056  */
0057 
0058 YAML_DECLARE(const char *)
0059 yaml_get_version_string(void);
0060 
0061 /**
0062  * Get the library version numbers.
0063  *
0064  * @param[out]      major   Major version number.
0065  * @param[out]      minor   Minor version number.
0066  * @param[out]      patch   Patch version number.
0067  */
0068 
0069 YAML_DECLARE(void)
0070 yaml_get_version(int *major, int *minor, int *patch);
0071 
0072 /** @} */
0073 
0074 /**
0075  * @defgroup basic Basic Types
0076  * @{
0077  */
0078 
0079 /** The character type (UTF-8 octet). */
0080 typedef unsigned char yaml_char_t;
0081 
0082 /** The version directive data. */
0083 typedef struct yaml_version_directive_s {
0084     /** The major version number. */
0085     int major;
0086     /** The minor version number. */
0087     int minor;
0088 } yaml_version_directive_t;
0089 
0090 /** The tag directive data. */
0091 typedef struct yaml_tag_directive_s {
0092     /** The tag handle. */
0093     yaml_char_t *handle;
0094     /** The tag prefix. */
0095     yaml_char_t *prefix;
0096 } yaml_tag_directive_t;
0097 
0098 /** The stream encoding. */
0099 typedef enum yaml_encoding_e {
0100     /** Let the parser choose the encoding. */
0101     YAML_ANY_ENCODING,
0102     /** The default UTF-8 encoding. */
0103     YAML_UTF8_ENCODING,
0104     /** The UTF-16-LE encoding with BOM. */
0105     YAML_UTF16LE_ENCODING,
0106     /** The UTF-16-BE encoding with BOM. */
0107     YAML_UTF16BE_ENCODING
0108 } yaml_encoding_t;
0109 
0110 /** Line break types. */
0111 
0112 typedef enum yaml_break_e {
0113     /** Let the parser choose the break type. */
0114     YAML_ANY_BREAK,
0115     /** Use CR for line breaks (Mac style). */
0116     YAML_CR_BREAK,
0117     /** Use LN for line breaks (Unix style). */
0118     YAML_LN_BREAK,
0119     /** Use CR LN for line breaks (DOS style). */
0120     YAML_CRLN_BREAK
0121 } yaml_break_t;
0122 
0123 /** Many bad things could happen with the parser and emitter. */
0124 typedef enum yaml_error_type_e {
0125     /** No error is produced. */
0126     YAML_NO_ERROR,
0127 
0128     /** Cannot allocate or reallocate a block of memory. */
0129     YAML_MEMORY_ERROR,
0130 
0131     /** Cannot read or decode the input stream. */
0132     YAML_READER_ERROR,
0133     /** Cannot scan the input stream. */
0134     YAML_SCANNER_ERROR,
0135     /** Cannot parse the input stream. */
0136     YAML_PARSER_ERROR,
0137     /** Cannot compose a YAML document. */
0138     YAML_COMPOSER_ERROR,
0139 
0140     /** Cannot write to the output stream. */
0141     YAML_WRITER_ERROR,
0142     /** Cannot emit a YAML stream. */
0143     YAML_EMITTER_ERROR
0144 } yaml_error_type_t;
0145 
0146 /** The pointer position. */
0147 typedef struct yaml_mark_s {
0148     /** The position index. */
0149     size_t index;
0150 
0151     /** The position line. */
0152     size_t line;
0153 
0154     /** The position column. */
0155     size_t column;
0156 } yaml_mark_t;
0157 
0158 /** @} */
0159 
0160 /**
0161  * @defgroup styles Node Styles
0162  * @{
0163  */
0164 
0165 /** Scalar styles. */
0166 typedef enum yaml_scalar_style_e {
0167     /** Let the emitter choose the style. */
0168     YAML_ANY_SCALAR_STYLE,
0169 
0170     /** The plain scalar style. */
0171     YAML_PLAIN_SCALAR_STYLE,
0172 
0173     /** The single-quoted scalar style. */
0174     YAML_SINGLE_QUOTED_SCALAR_STYLE,
0175     /** The double-quoted scalar style. */
0176     YAML_DOUBLE_QUOTED_SCALAR_STYLE,
0177 
0178     /** The literal scalar style. */
0179     YAML_LITERAL_SCALAR_STYLE,
0180     /** The folded scalar style. */
0181     YAML_FOLDED_SCALAR_STYLE
0182 } yaml_scalar_style_t;
0183 
0184 /** Sequence styles. */
0185 typedef enum yaml_sequence_style_e {
0186     /** Let the emitter choose the style. */
0187     YAML_ANY_SEQUENCE_STYLE,
0188 
0189     /** The block sequence style. */
0190     YAML_BLOCK_SEQUENCE_STYLE,
0191     /** The flow sequence style. */
0192     YAML_FLOW_SEQUENCE_STYLE
0193 } yaml_sequence_style_t;
0194 
0195 /** Mapping styles. */
0196 typedef enum yaml_mapping_style_e {
0197     /** Let the emitter choose the style. */
0198     YAML_ANY_MAPPING_STYLE,
0199 
0200     /** The block mapping style. */
0201     YAML_BLOCK_MAPPING_STYLE,
0202     /** The flow mapping style. */
0203     YAML_FLOW_MAPPING_STYLE
0204 /*    YAML_FLOW_SET_MAPPING_STYLE   */
0205 } yaml_mapping_style_t;
0206 
0207 /** @} */
0208 
0209 /**
0210  * @defgroup tokens Tokens
0211  * @{
0212  */
0213 
0214 /** Token types. */
0215 typedef enum yaml_token_type_e {
0216     /** An empty token. */
0217     YAML_NO_TOKEN,
0218 
0219     /** A STREAM-START token. */
0220     YAML_STREAM_START_TOKEN,
0221     /** A STREAM-END token. */
0222     YAML_STREAM_END_TOKEN,
0223 
0224     /** A VERSION-DIRECTIVE token. */
0225     YAML_VERSION_DIRECTIVE_TOKEN,
0226     /** A TAG-DIRECTIVE token. */
0227     YAML_TAG_DIRECTIVE_TOKEN,
0228     /** A DOCUMENT-START token. */
0229     YAML_DOCUMENT_START_TOKEN,
0230     /** A DOCUMENT-END token. */
0231     YAML_DOCUMENT_END_TOKEN,
0232 
0233     /** A BLOCK-SEQUENCE-START token. */
0234     YAML_BLOCK_SEQUENCE_START_TOKEN,
0235     /** A BLOCK-MAPPING-START token. */
0236     YAML_BLOCK_MAPPING_START_TOKEN,
0237     /** A BLOCK-END token. */
0238     YAML_BLOCK_END_TOKEN,
0239 
0240     /** A FLOW-SEQUENCE-START token. */
0241     YAML_FLOW_SEQUENCE_START_TOKEN,
0242     /** A FLOW-SEQUENCE-END token. */
0243     YAML_FLOW_SEQUENCE_END_TOKEN,
0244     /** A FLOW-MAPPING-START token. */
0245     YAML_FLOW_MAPPING_START_TOKEN,
0246     /** A FLOW-MAPPING-END token. */
0247     YAML_FLOW_MAPPING_END_TOKEN,
0248 
0249     /** A BLOCK-ENTRY token. */
0250     YAML_BLOCK_ENTRY_TOKEN,
0251     /** A FLOW-ENTRY token. */
0252     YAML_FLOW_ENTRY_TOKEN,
0253     /** A KEY token. */
0254     YAML_KEY_TOKEN,
0255     /** A VALUE token. */
0256     YAML_VALUE_TOKEN,
0257 
0258     /** An ALIAS token. */
0259     YAML_ALIAS_TOKEN,
0260     /** An ANCHOR token. */
0261     YAML_ANCHOR_TOKEN,
0262     /** A TAG token. */
0263     YAML_TAG_TOKEN,
0264     /** A SCALAR token. */
0265     YAML_SCALAR_TOKEN
0266 } yaml_token_type_t;
0267 
0268 /** The token structure. */
0269 typedef struct yaml_token_s {
0270 
0271     /** The token type. */
0272     yaml_token_type_t type;
0273 
0274     /** The token data. */
0275     union {
0276 
0277         /** The stream start (for @c YAML_STREAM_START_TOKEN). */
0278         struct {
0279             /** The stream encoding. */
0280             yaml_encoding_t encoding;
0281         } stream_start;
0282 
0283         /** The alias (for @c YAML_ALIAS_TOKEN). */
0284         struct {
0285             /** The alias value. */
0286             yaml_char_t *value;
0287         } alias;
0288 
0289         /** The anchor (for @c YAML_ANCHOR_TOKEN). */
0290         struct {
0291             /** The anchor value. */
0292             yaml_char_t *value;
0293         } anchor;
0294 
0295         /** The tag (for @c YAML_TAG_TOKEN). */
0296         struct {
0297             /** The tag handle. */
0298             yaml_char_t *handle;
0299             /** The tag suffix. */
0300             yaml_char_t *suffix;
0301         } tag;
0302 
0303         /** The scalar value (for @c YAML_SCALAR_TOKEN). */
0304         struct {
0305             /** The scalar value. */
0306             yaml_char_t *value;
0307             /** The length of the scalar value. */
0308             size_t length;
0309             /** The scalar style. */
0310             yaml_scalar_style_t style;
0311         } scalar;
0312 
0313         /** The version directive (for @c YAML_VERSION_DIRECTIVE_TOKEN). */
0314         struct {
0315             /** The major version number. */
0316             int major;
0317             /** The minor version number. */
0318             int minor;
0319         } version_directive;
0320 
0321         /** The tag directive (for @c YAML_TAG_DIRECTIVE_TOKEN). */
0322         struct {
0323             /** The tag handle. */
0324             yaml_char_t *handle;
0325             /** The tag prefix. */
0326             yaml_char_t *prefix;
0327         } tag_directive;
0328 
0329     } data;
0330 
0331     /** The beginning of the token. */
0332     yaml_mark_t start_mark;
0333     /** The end of the token. */
0334     yaml_mark_t end_mark;
0335 
0336 } yaml_token_t;
0337 
0338 /**
0339  * Free any memory allocated for a token object.
0340  *
0341  * @param[in,out]   token   A token object.
0342  */
0343 
0344 YAML_DECLARE(void)
0345 yaml_token_delete(yaml_token_t *token);
0346 
0347 /** @} */
0348 
0349 /**
0350  * @defgroup events Events
0351  * @{
0352  */
0353 
0354 /** Event types. */
0355 typedef enum yaml_event_type_e {
0356     /** An empty event. */
0357     YAML_NO_EVENT,
0358 
0359     /** A STREAM-START event. */
0360     YAML_STREAM_START_EVENT,
0361     /** A STREAM-END event. */
0362     YAML_STREAM_END_EVENT,
0363 
0364     /** A DOCUMENT-START event. */
0365     YAML_DOCUMENT_START_EVENT,
0366     /** A DOCUMENT-END event. */
0367     YAML_DOCUMENT_END_EVENT,
0368 
0369     /** An ALIAS event. */
0370     YAML_ALIAS_EVENT,
0371     /** A SCALAR event. */
0372     YAML_SCALAR_EVENT,
0373 
0374     /** A SEQUENCE-START event. */
0375     YAML_SEQUENCE_START_EVENT,
0376     /** A SEQUENCE-END event. */
0377     YAML_SEQUENCE_END_EVENT,
0378 
0379     /** A MAPPING-START event. */
0380     YAML_MAPPING_START_EVENT,
0381     /** A MAPPING-END event. */
0382     YAML_MAPPING_END_EVENT
0383 } yaml_event_type_t;
0384 
0385 /** The event structure. */
0386 typedef struct yaml_event_s {
0387 
0388     /** The event type. */
0389     yaml_event_type_t type;
0390 
0391     /** The event data. */
0392     union {
0393         
0394         /** The stream parameters (for @c YAML_STREAM_START_EVENT). */
0395         struct {
0396             /** The document encoding. */
0397             yaml_encoding_t encoding;
0398         } stream_start;
0399 
0400         /** The document parameters (for @c YAML_DOCUMENT_START_EVENT). */
0401         struct {
0402             /** The version directive. */
0403             yaml_version_directive_t *version_directive;
0404 
0405             /** The list of tag directives. */
0406             struct {
0407                 /** The beginning of the tag directives list. */
0408                 yaml_tag_directive_t *start;
0409                 /** The end of the tag directives list. */
0410                 yaml_tag_directive_t *end;
0411             } tag_directives;
0412 
0413             /** Is the document indicator implicit? */
0414             int implicit;
0415         } document_start;
0416 
0417         /** The document end parameters (for @c YAML_DOCUMENT_END_EVENT). */
0418         struct {
0419             /** Is the document end indicator implicit? */
0420             int implicit;
0421         } document_end;
0422 
0423         /** The alias parameters (for @c YAML_ALIAS_EVENT). */
0424         struct {
0425             /** The anchor. */
0426             yaml_char_t *anchor;
0427         } alias;
0428 
0429         /** The scalar parameters (for @c YAML_SCALAR_EVENT). */
0430         struct {
0431             /** The anchor. */
0432             yaml_char_t *anchor;
0433             /** The tag. */
0434             yaml_char_t *tag;
0435             /** The scalar value. */
0436             yaml_char_t *value;
0437             /** The length of the scalar value. */
0438             size_t length;
0439             /** Is the tag optional for the plain style? */
0440             int plain_implicit;
0441             /** Is the tag optional for any non-plain style? */
0442             int quoted_implicit;
0443             /** The scalar style. */
0444             yaml_scalar_style_t style;
0445         } scalar;
0446 
0447         /** The sequence parameters (for @c YAML_SEQUENCE_START_EVENT). */
0448         struct {
0449             /** The anchor. */
0450             yaml_char_t *anchor;
0451             /** The tag. */
0452             yaml_char_t *tag;
0453             /** Is the tag optional? */
0454             int implicit;
0455             /** The sequence style. */
0456             yaml_sequence_style_t style;
0457         } sequence_start;
0458 
0459         /** The mapping parameters (for @c YAML_MAPPING_START_EVENT). */
0460         struct {
0461             /** The anchor. */
0462             yaml_char_t *anchor;
0463             /** The tag. */
0464             yaml_char_t *tag;
0465             /** Is the tag optional? */
0466             int implicit;
0467             /** The mapping style. */
0468             yaml_mapping_style_t style;
0469         } mapping_start;
0470 
0471     } data;
0472 
0473     /** The beginning of the event. */
0474     yaml_mark_t start_mark;
0475     /** The end of the event. */
0476     yaml_mark_t end_mark;
0477 
0478 } yaml_event_t;
0479 
0480 /**
0481  * Create the STREAM-START event.
0482  *
0483  * @param[out]      event       An empty event object.
0484  * @param[in]       encoding    The stream encoding.
0485  *
0486  * @returns @c 1 if the function succeeded, @c 0 on error.
0487  */
0488 
0489 YAML_DECLARE(int)
0490 yaml_stream_start_event_initialize(yaml_event_t *event,
0491         yaml_encoding_t encoding);
0492 
0493 /**
0494  * Create the STREAM-END event.
0495  *
0496  * @param[out]      event       An empty event object.
0497  *
0498  * @returns @c 1 if the function succeeded, @c 0 on error.
0499  */
0500 
0501 YAML_DECLARE(int)
0502 yaml_stream_end_event_initialize(yaml_event_t *event);
0503 
0504 /**
0505  * Create the DOCUMENT-START event.
0506  *
0507  * The @a implicit argument is considered as a stylistic parameter and may be
0508  * ignored by the emitter.
0509  *
0510  * @param[out]      event                   An empty event object.
0511  * @param[in]       version_directive       The %YAML directive value or
0512  *                                          @c NULL.
0513  * @param[in]       tag_directives_start    The beginning of the %TAG
0514  *                                          directives list.
0515  * @param[in]       tag_directives_end      The end of the %TAG directives
0516  *                                          list.
0517  * @param[in]       implicit                If the document start indicator is
0518  *                                          implicit.
0519  *
0520  * @returns @c 1 if the function succeeded, @c 0 on error.
0521  */
0522 
0523 YAML_DECLARE(int)
0524 yaml_document_start_event_initialize(yaml_event_t *event,
0525         yaml_version_directive_t *version_directive,
0526         yaml_tag_directive_t *tag_directives_start,
0527         yaml_tag_directive_t *tag_directives_end,
0528         int implicit);
0529 
0530 /**
0531  * Create the DOCUMENT-END event.
0532  *
0533  * The @a implicit argument is considered as a stylistic parameter and may be
0534  * ignored by the emitter.
0535  *
0536  * @param[out]      event       An empty event object.
0537  * @param[in]       implicit    If the document end indicator is implicit.
0538  *
0539  * @returns @c 1 if the function succeeded, @c 0 on error.
0540  */
0541 
0542 YAML_DECLARE(int)
0543 yaml_document_end_event_initialize(yaml_event_t *event, int implicit);
0544 
0545 /**
0546  * Create an ALIAS event.
0547  *
0548  * @param[out]      event       An empty event object.
0549  * @param[in]       anchor      The anchor value.
0550  *
0551  * @returns @c 1 if the function succeeded, @c 0 on error.
0552  */
0553 
0554 YAML_DECLARE(int)
0555 yaml_alias_event_initialize(yaml_event_t *event, const yaml_char_t *anchor);
0556 
0557 /**
0558  * Create a SCALAR event.
0559  *
0560  * The @a style argument may be ignored by the emitter.
0561  *
0562  * Either the @a tag attribute or one of the @a plain_implicit and
0563  * @a quoted_implicit flags must be set.
0564  *
0565  * @param[out]      event           An empty event object.
0566  * @param[in]       anchor          The scalar anchor or @c NULL.
0567  * @param[in]       tag             The scalar tag or @c NULL.
0568  * @param[in]       value           The scalar value.
0569  * @param[in]       length          The length of the scalar value.
0570  * @param[in]       plain_implicit  If the tag may be omitted for the plain
0571  *                                  style.
0572  * @param[in]       quoted_implicit If the tag may be omitted for any
0573  *                                  non-plain style.
0574  * @param[in]       style           The scalar style.
0575  *
0576  * @returns @c 1 if the function succeeded, @c 0 on error.
0577  */
0578 
0579 YAML_DECLARE(int)
0580 yaml_scalar_event_initialize(yaml_event_t *event,
0581         const yaml_char_t *anchor, const yaml_char_t *tag,
0582         const yaml_char_t *value, int length,
0583         int plain_implicit, int quoted_implicit,
0584         yaml_scalar_style_t style);
0585 
0586 /**
0587  * Create a SEQUENCE-START event.
0588  *
0589  * The @a style argument may be ignored by the emitter.
0590  *
0591  * Either the @a tag attribute or the @a implicit flag must be set.
0592  *
0593  * @param[out]      event       An empty event object.
0594  * @param[in]       anchor      The sequence anchor or @c NULL.
0595  * @param[in]       tag         The sequence tag or @c NULL.
0596  * @param[in]       implicit    If the tag may be omitted.
0597  * @param[in]       style       The sequence style.
0598  *
0599  * @returns @c 1 if the function succeeded, @c 0 on error.
0600  */
0601 
0602 YAML_DECLARE(int)
0603 yaml_sequence_start_event_initialize(yaml_event_t *event,
0604         const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
0605         yaml_sequence_style_t style);
0606 
0607 /**
0608  * Create a SEQUENCE-END event.
0609  *
0610  * @param[out]      event       An empty event object.
0611  *
0612  * @returns @c 1 if the function succeeded, @c 0 on error.
0613  */
0614 
0615 YAML_DECLARE(int)
0616 yaml_sequence_end_event_initialize(yaml_event_t *event);
0617 
0618 /**
0619  * Create a MAPPING-START event.
0620  *
0621  * The @a style argument may be ignored by the emitter.
0622  *
0623  * Either the @a tag attribute or the @a implicit flag must be set.
0624  *
0625  * @param[out]      event       An empty event object.
0626  * @param[in]       anchor      The mapping anchor or @c NULL.
0627  * @param[in]       tag         The mapping tag or @c NULL.
0628  * @param[in]       implicit    If the tag may be omitted.
0629  * @param[in]       style       The mapping style.
0630  *
0631  * @returns @c 1 if the function succeeded, @c 0 on error.
0632  */
0633 
0634 YAML_DECLARE(int)
0635 yaml_mapping_start_event_initialize(yaml_event_t *event,
0636         const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
0637         yaml_mapping_style_t style);
0638 
0639 /**
0640  * Create a MAPPING-END event.
0641  *
0642  * @param[out]      event       An empty event object.
0643  *
0644  * @returns @c 1 if the function succeeded, @c 0 on error.
0645  */
0646 
0647 YAML_DECLARE(int)
0648 yaml_mapping_end_event_initialize(yaml_event_t *event);
0649 
0650 /**
0651  * Free any memory allocated for an event object.
0652  *
0653  * @param[in,out]   event   An event object.
0654  */
0655 
0656 YAML_DECLARE(void)
0657 yaml_event_delete(yaml_event_t *event);
0658 
0659 /** @} */
0660 
0661 /**
0662  * @defgroup nodes Nodes
0663  * @{
0664  */
0665 
0666 /** The tag @c !!null with the only possible value: @c null. */
0667 #define YAML_NULL_TAG       "tag:yaml.org,2002:null"
0668 /** The tag @c !!bool with the values: @c true and @c false. */
0669 #define YAML_BOOL_TAG       "tag:yaml.org,2002:bool"
0670 /** The tag @c !!str for string values. */
0671 #define YAML_STR_TAG        "tag:yaml.org,2002:str"
0672 /** The tag @c !!int for integer values. */
0673 #define YAML_INT_TAG        "tag:yaml.org,2002:int"
0674 /** The tag @c !!float for float values. */
0675 #define YAML_FLOAT_TAG      "tag:yaml.org,2002:float"
0676 /** The tag @c !!timestamp for date and time values. */
0677 #define YAML_TIMESTAMP_TAG  "tag:yaml.org,2002:timestamp"
0678 
0679 /** The tag @c !!seq is used to denote sequences. */
0680 #define YAML_SEQ_TAG        "tag:yaml.org,2002:seq"
0681 /** The tag @c !!map is used to denote mapping. */
0682 #define YAML_MAP_TAG        "tag:yaml.org,2002:map"
0683 
0684 /** The default scalar tag is @c !!str. */
0685 #define YAML_DEFAULT_SCALAR_TAG     YAML_STR_TAG
0686 /** The default sequence tag is @c !!seq. */
0687 #define YAML_DEFAULT_SEQUENCE_TAG   YAML_SEQ_TAG
0688 /** The default mapping tag is @c !!map. */
0689 #define YAML_DEFAULT_MAPPING_TAG    YAML_MAP_TAG
0690 
0691 /** Node types. */
0692 typedef enum yaml_node_type_e {
0693     /** An empty node. */
0694     YAML_NO_NODE,
0695 
0696     /** A scalar node. */
0697     YAML_SCALAR_NODE,
0698     /** A sequence node. */
0699     YAML_SEQUENCE_NODE,
0700     /** A mapping node. */
0701     YAML_MAPPING_NODE
0702 } yaml_node_type_t;
0703 
0704 /** The forward definition of a document node structure. */
0705 typedef struct yaml_node_s yaml_node_t;
0706 
0707 /** An element of a sequence node. */
0708 typedef int yaml_node_item_t;
0709 
0710 /** An element of a mapping node. */
0711 typedef struct yaml_node_pair_s {
0712     /** The key of the element. */
0713     int key;
0714     /** The value of the element. */
0715     int value;
0716 } yaml_node_pair_t;
0717 
0718 /** The node structure. */
0719 struct yaml_node_s {
0720 
0721     /** The node type. */
0722     yaml_node_type_t type;
0723 
0724     /** The node tag. */
0725     yaml_char_t *tag;
0726 
0727     /** The node data. */
0728     union {
0729         
0730         /** The scalar parameters (for @c YAML_SCALAR_NODE). */
0731         struct {
0732             /** The scalar value. */
0733             yaml_char_t *value;
0734             /** The length of the scalar value. */
0735             size_t length;
0736             /** The scalar style. */
0737             yaml_scalar_style_t style;
0738         } scalar;
0739 
0740         /** The sequence parameters (for @c YAML_SEQUENCE_NODE). */
0741         struct {
0742             /** The stack of sequence items. */
0743             struct {
0744                 /** The beginning of the stack. */
0745                 yaml_node_item_t *start;
0746                 /** The end of the stack. */
0747                 yaml_node_item_t *end;
0748                 /** The top of the stack. */
0749                 yaml_node_item_t *top;
0750             } items;
0751             /** The sequence style. */
0752             yaml_sequence_style_t style;
0753         } sequence;
0754 
0755         /** The mapping parameters (for @c YAML_MAPPING_NODE). */
0756         struct {
0757             /** The stack of mapping pairs (key, value). */
0758             struct {
0759                 /** The beginning of the stack. */
0760                 yaml_node_pair_t *start;
0761                 /** The end of the stack. */
0762                 yaml_node_pair_t *end;
0763                 /** The top of the stack. */
0764                 yaml_node_pair_t *top;
0765             } pairs;
0766             /** The mapping style. */
0767             yaml_mapping_style_t style;
0768         } mapping;
0769 
0770     } data;
0771 
0772     /** The beginning of the node. */
0773     yaml_mark_t start_mark;
0774     /** The end of the node. */
0775     yaml_mark_t end_mark;
0776 
0777 };
0778 
0779 /** The document structure. */
0780 typedef struct yaml_document_s {
0781 
0782     /** The document nodes. */
0783     struct {
0784         /** The beginning of the stack. */
0785         yaml_node_t *start;
0786         /** The end of the stack. */
0787         yaml_node_t *end;
0788         /** The top of the stack. */
0789         yaml_node_t *top;
0790     } nodes;
0791 
0792     /** The version directive. */
0793     yaml_version_directive_t *version_directive;
0794 
0795     /** The list of tag directives. */
0796     struct {
0797         /** The beginning of the tag directives list. */
0798         yaml_tag_directive_t *start;
0799         /** The end of the tag directives list. */
0800         yaml_tag_directive_t *end;
0801     } tag_directives;
0802 
0803     /** Is the document start indicator implicit? */
0804     int start_implicit;
0805     /** Is the document end indicator implicit? */
0806     int end_implicit;
0807 
0808     /** The beginning of the document. */
0809     yaml_mark_t start_mark;
0810     /** The end of the document. */
0811     yaml_mark_t end_mark;
0812 
0813 } yaml_document_t;
0814 
0815 /**
0816  * Create a YAML document.
0817  *
0818  * @param[out]      document                An empty document object.
0819  * @param[in]       version_directive       The %YAML directive value or
0820  *                                          @c NULL.
0821  * @param[in]       tag_directives_start    The beginning of the %TAG
0822  *                                          directives list.
0823  * @param[in]       tag_directives_end      The end of the %TAG directives
0824  *                                          list.
0825  * @param[in]       start_implicit          If the document start indicator is
0826  *                                          implicit.
0827  * @param[in]       end_implicit            If the document end indicator is
0828  *                                          implicit.
0829  *
0830  * @returns @c 1 if the function succeeded, @c 0 on error.
0831  */
0832 
0833 YAML_DECLARE(int)
0834 yaml_document_initialize(yaml_document_t *document,
0835         yaml_version_directive_t *version_directive,
0836         yaml_tag_directive_t *tag_directives_start,
0837         yaml_tag_directive_t *tag_directives_end,
0838         int start_implicit, int end_implicit);
0839 
0840 /**
0841  * Delete a YAML document and all its nodes.
0842  *
0843  * @param[in,out]   document        A document object.
0844  */
0845 
0846 YAML_DECLARE(void)
0847 yaml_document_delete(yaml_document_t *document);
0848 
0849 /**
0850  * Get a node of a YAML document.
0851  *
0852  * The pointer returned by this function is valid until any of the functions
0853  * modifying the documents are called.
0854  *
0855  * @param[in]       document        A document object.
0856  * @param[in]       index           The node id.
0857  *
0858  * @returns the node objct or @c NULL if @c node_id is out of range.
0859  */
0860 
0861 YAML_DECLARE(yaml_node_t *)
0862 yaml_document_get_node(yaml_document_t *document, int index);
0863 
0864 /**
0865  * Get the root of a YAML document node.
0866  *
0867  * The root object is the first object added to the document.
0868  *
0869  * The pointer returned by this function is valid until any of the functions
0870  * modifying the documents are called.
0871  *
0872  * An empty document produced by the parser signifies the end of a YAML
0873  * stream.
0874  *
0875  * @param[in]       document        A document object.
0876  *
0877  * @returns the node object or @c NULL if the document is empty.
0878  */
0879 
0880 YAML_DECLARE(yaml_node_t *)
0881 yaml_document_get_root_node(yaml_document_t *document);
0882 
0883 /**
0884  * Create a SCALAR node and attach it to the document.
0885  *
0886  * The @a style argument may be ignored by the emitter.
0887  *
0888  * @param[in,out]   document        A document object.
0889  * @param[in]       tag             The scalar tag.
0890  * @param[in]       value           The scalar value.
0891  * @param[in]       length          The length of the scalar value.
0892  * @param[in]       style           The scalar style.
0893  *
0894  * @returns the node id or @c 0 on error.
0895  */
0896 
0897 YAML_DECLARE(int)
0898 yaml_document_add_scalar(yaml_document_t *document,
0899         const yaml_char_t *tag, const yaml_char_t *value, int length,
0900         yaml_scalar_style_t style);
0901 
0902 /**
0903  * Create a SEQUENCE node and attach it to the document.
0904  *
0905  * The @a style argument may be ignored by the emitter.
0906  *
0907  * @param[in,out]   document    A document object.
0908  * @param[in]       tag         The sequence tag.
0909  * @param[in]       style       The sequence style.
0910  *
0911  * @returns the node id or @c 0 on error.
0912  */
0913 
0914 YAML_DECLARE(int)
0915 yaml_document_add_sequence(yaml_document_t *document,
0916         const yaml_char_t *tag, yaml_sequence_style_t style);
0917 
0918 /**
0919  * Create a MAPPING node and attach it to the document.
0920  *
0921  * The @a style argument may be ignored by the emitter.
0922  *
0923  * @param[in,out]   document    A document object.
0924  * @param[in]       tag         The sequence tag.
0925  * @param[in]       style       The sequence style.
0926  *
0927  * @returns the node id or @c 0 on error.
0928  */
0929 
0930 YAML_DECLARE(int)
0931 yaml_document_add_mapping(yaml_document_t *document,
0932         const yaml_char_t *tag, yaml_mapping_style_t style);
0933 
0934 /**
0935  * Add an item to a SEQUENCE node.
0936  *
0937  * @param[in,out]   document    A document object.
0938  * @param[in]       sequence    The sequence node id.
0939  * @param[in]       item        The item node id.
0940  *
0941  * @returns @c 1 if the function succeeded, @c 0 on error.
0942  */
0943 
0944 YAML_DECLARE(int)
0945 yaml_document_append_sequence_item(yaml_document_t *document,
0946         int sequence, int item);
0947 
0948 /**
0949  * Add a pair of a key and a value to a MAPPING node.
0950  *
0951  * @param[in,out]   document    A document object.
0952  * @param[in]       mapping     The mapping node id.
0953  * @param[in]       key         The key node id.
0954  * @param[in]       value       The value node id.
0955  *
0956  * @returns @c 1 if the function succeeded, @c 0 on error.
0957  */
0958 
0959 YAML_DECLARE(int)
0960 yaml_document_append_mapping_pair(yaml_document_t *document,
0961         int mapping, int key, int value);
0962 
0963 /** @} */
0964 
0965 /**
0966  * @defgroup parser Parser Definitions
0967  * @{
0968  */
0969 
0970 /**
0971  * The prototype of a read handler.
0972  *
0973  * The read handler is called when the parser needs to read more bytes from the
0974  * source.  The handler should write not more than @a size bytes to the @a
0975  * buffer.  The number of written bytes should be set to the @a length variable.
0976  *
0977  * @param[in,out]   data        A pointer to an application data specified by
0978  *                              yaml_parser_set_input().
0979  * @param[out]      buffer      The buffer to write the data from the source.
0980  * @param[in]       size        The size of the buffer.
0981  * @param[out]      size_read   The actual number of bytes read from the source.
0982  *
0983  * @returns On success, the handler should return @c 1.  If the handler failed,
0984  * the returned value should be @c 0.  On EOF, the handler should set the
0985  * @a size_read to @c 0 and return @c 1.
0986  */
0987 
0988 typedef int yaml_read_handler_t(void *data, unsigned char *buffer, size_t size,
0989         size_t *size_read);
0990 
0991 /**
0992  * This structure holds information about a potential simple key.
0993  */
0994 
0995 typedef struct yaml_simple_key_s {
0996     /** Is a simple key possible? */
0997     int possible;
0998 
0999     /** Is a simple key required? */
1000     int required;
1001 
1002     /** The number of the token. */
1003     size_t token_number;
1004 
1005     /** The position mark. */
1006     yaml_mark_t mark;
1007 } yaml_simple_key_t;
1008 
1009 /**
1010  * The states of the parser.
1011  */
1012 typedef enum yaml_parser_state_e {
1013     /** Expect STREAM-START. */
1014     YAML_PARSE_STREAM_START_STATE,
1015     /** Expect the beginning of an implicit document. */
1016     YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE,
1017     /** Expect DOCUMENT-START. */
1018     YAML_PARSE_DOCUMENT_START_STATE,
1019     /** Expect the content of a document. */
1020     YAML_PARSE_DOCUMENT_CONTENT_STATE,
1021     /** Expect DOCUMENT-END. */
1022     YAML_PARSE_DOCUMENT_END_STATE,
1023 
1024     /** Expect a block node. */
1025     YAML_PARSE_BLOCK_NODE_STATE,
1026     /** Expect a block node or indentless sequence. */
1027     YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE,
1028     /** Expect a flow node. */
1029     YAML_PARSE_FLOW_NODE_STATE,
1030     /** Expect the first entry of a block sequence. */
1031     YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE,
1032     /** Expect an entry of a block sequence. */
1033     YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE,
1034 
1035     /** Expect an entry of an indentless sequence. */
1036     YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE,
1037     /** Expect the first key of a block mapping. */
1038     YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE,
1039     /** Expect a block mapping key. */
1040     YAML_PARSE_BLOCK_MAPPING_KEY_STATE,
1041     /** Expect a block mapping value. */
1042     YAML_PARSE_BLOCK_MAPPING_VALUE_STATE,
1043     /** Expect the first entry of a flow sequence. */
1044     YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE,
1045 
1046     /** Expect an entry of a flow sequence. */
1047     YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE,
1048     /** Expect a key of an ordered mapping. */
1049     YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE,
1050     /** Expect a value of an ordered mapping. */
1051     YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE,
1052     /** Expect the and of an ordered mapping entry. */
1053     YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE,
1054     /** Expect the first key of a flow mapping. */
1055     YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE,
1056     /** Expect a key of a flow mapping. */
1057 
1058     YAML_PARSE_FLOW_MAPPING_KEY_STATE,
1059     /** Expect a value of a flow mapping. */
1060     YAML_PARSE_FLOW_MAPPING_VALUE_STATE,
1061     /** Expect an empty value of a flow mapping. */
1062     YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE,
1063     /** Expect nothing. */
1064     YAML_PARSE_END_STATE
1065 } yaml_parser_state_t;
1066 
1067 /**
1068  * This structure holds aliases data.
1069  */
1070 
1071 typedef struct yaml_alias_data_s {
1072     /** The anchor. */
1073     yaml_char_t *anchor;
1074     /** The node id. */
1075     int index;
1076     /** The anchor mark. */
1077     yaml_mark_t mark;
1078 } yaml_alias_data_t;
1079 
1080 /**
1081  * The parser structure.
1082  *
1083  * All members are internal.  Manage the structure using the @c yaml_parser_
1084  * family of functions.
1085  */
1086 
1087 typedef struct yaml_parser_s {
1088 
1089     /**
1090      * @name Error handling
1091      * @{
1092      */
1093 
1094     /** Error type. */
1095     yaml_error_type_t error;
1096     /** Error description. */
1097     const char *problem;
1098     /** The byte about which the problem occured. */
1099     size_t problem_offset;
1100     /** The problematic value (@c -1 is none). */
1101     int problem_value;
1102     /** The problem position. */
1103     yaml_mark_t problem_mark;
1104     /** The error context. */
1105     const char *context;
1106     /** The context position. */
1107     yaml_mark_t context_mark;
1108 
1109     /**
1110      * @}
1111      */
1112 
1113     /**
1114      * @name Reader stuff
1115      * @{
1116      */
1117 
1118     /** Read handler. */
1119     yaml_read_handler_t *read_handler;
1120 
1121     /** A pointer for passing to the read handler. */
1122     void *read_handler_data;
1123 
1124     /** Standard (string or file) input data. */
1125     union {
1126         /** String input data. */
1127         struct {
1128             /** The string start pointer. */
1129             const unsigned char *start;
1130             /** The string end pointer. */
1131             const unsigned char *end;
1132             /** The string current position. */
1133             const unsigned char *current;
1134         } string;
1135 
1136         /** File input data. */
1137         FILE *file;
1138     } input;
1139 
1140     /** EOF flag */
1141     int eof;
1142 
1143     /** The working buffer. */
1144     struct {
1145         /** The beginning of the buffer. */
1146         yaml_char_t *start;
1147         /** The end of the buffer. */
1148         yaml_char_t *end;
1149         /** The current position of the buffer. */
1150         yaml_char_t *pointer;
1151         /** The last filled position of the buffer. */
1152         yaml_char_t *last;
1153     } buffer;
1154 
1155     /* The number of unread characters in the buffer. */
1156     size_t unread;
1157 
1158     /** The raw buffer. */
1159     struct {
1160         /** The beginning of the buffer. */
1161         unsigned char *start;
1162         /** The end of the buffer. */
1163         unsigned char *end;
1164         /** The current position of the buffer. */
1165         unsigned char *pointer;
1166         /** The last filled position of the buffer. */
1167         unsigned char *last;
1168     } raw_buffer;
1169 
1170     /** The input encoding. */
1171     yaml_encoding_t encoding;
1172 
1173     /** The offset of the current position (in bytes). */
1174     size_t offset;
1175 
1176     /** The mark of the current position. */
1177     yaml_mark_t mark;
1178 
1179     /**
1180      * @}
1181      */
1182 
1183     /**
1184      * @name Scanner stuff
1185      * @{
1186      */
1187 
1188     /** Have we started to scan the input stream? */
1189     int stream_start_produced;
1190 
1191     /** Have we reached the end of the input stream? */
1192     int stream_end_produced;
1193 
1194     /** The number of unclosed '[' and '{' indicators. */
1195     int flow_level;
1196 
1197     /** The tokens queue. */
1198     struct {
1199         /** The beginning of the tokens queue. */
1200         yaml_token_t *start;
1201         /** The end of the tokens queue. */
1202         yaml_token_t *end;
1203         /** The head of the tokens queue. */
1204         yaml_token_t *head;
1205         /** The tail of the tokens queue. */
1206         yaml_token_t *tail;
1207     } tokens;
1208 
1209     /** The number of tokens fetched from the queue. */
1210     size_t tokens_parsed;
1211 
1212     /** Does the tokens queue contain a token ready for dequeueing. */
1213     int token_available;
1214 
1215     /** The indentation levels stack. */
1216     struct {
1217         /** The beginning of the stack. */
1218         int *start;
1219         /** The end of the stack. */
1220         int *end;
1221         /** The top of the stack. */
1222         int *top;
1223     } indents;
1224 
1225     /** The current indentation level. */
1226     int indent;
1227 
1228     /** May a simple key occur at the current position? */
1229     int simple_key_allowed;
1230 
1231     /** The stack of simple keys. */
1232     struct {
1233         /** The beginning of the stack. */
1234         yaml_simple_key_t *start;
1235         /** The end of the stack. */
1236         yaml_simple_key_t *end;
1237         /** The top of the stack. */
1238         yaml_simple_key_t *top;
1239     } simple_keys;
1240 
1241     /**
1242      * @}
1243      */
1244 
1245     /**
1246      * @name Parser stuff
1247      * @{
1248      */
1249 
1250     /** The parser states stack. */
1251     struct {
1252         /** The beginning of the stack. */
1253         yaml_parser_state_t *start;
1254         /** The end of the stack. */
1255         yaml_parser_state_t *end;
1256         /** The top of the stack. */
1257         yaml_parser_state_t *top;
1258     } states;
1259 
1260     /** The current parser state. */
1261     yaml_parser_state_t state;
1262 
1263     /** The stack of marks. */
1264     struct {
1265         /** The beginning of the stack. */
1266         yaml_mark_t *start;
1267         /** The end of the stack. */
1268         yaml_mark_t *end;
1269         /** The top of the stack. */
1270         yaml_mark_t *top;
1271     } marks;
1272 
1273     /** The list of TAG directives. */
1274     struct {
1275         /** The beginning of the list. */
1276         yaml_tag_directive_t *start;
1277         /** The end of the list. */
1278         yaml_tag_directive_t *end;
1279         /** The top of the list. */
1280         yaml_tag_directive_t *top;
1281     } tag_directives;
1282 
1283     /**
1284      * @}
1285      */
1286 
1287     /**
1288      * @name Dumper stuff
1289      * @{
1290      */
1291 
1292     /** The alias data. */
1293     struct {
1294         /** The beginning of the list. */
1295         yaml_alias_data_t *start;
1296         /** The end of the list. */
1297         yaml_alias_data_t *end;
1298         /** The top of the list. */
1299         yaml_alias_data_t *top;
1300     } aliases;
1301 
1302     /** The currently parsed document. */
1303     yaml_document_t *document;
1304 
1305     /**
1306      * @}
1307      */
1308 
1309 } yaml_parser_t;
1310 
1311 /**
1312  * Initialize a parser.
1313  *
1314  * This function creates a new parser object.  An application is responsible
1315  * for destroying the object using the yaml_parser_delete() function.
1316  *
1317  * @param[out]      parser  An empty parser object.
1318  *
1319  * @returns @c 1 if the function succeeded, @c 0 on error.
1320  */
1321 
1322 YAML_DECLARE(int)
1323 yaml_parser_initialize(yaml_parser_t *parser);
1324 
1325 /**
1326  * Destroy a parser.
1327  *
1328  * @param[in,out]   parser  A parser object.
1329  */
1330 
1331 YAML_DECLARE(void)
1332 yaml_parser_delete(yaml_parser_t *parser);
1333 
1334 /**
1335  * Set a string input.
1336  *
1337  * Note that the @a input pointer must be valid while the @a parser object
1338  * exists.  The application is responsible for destroing @a input after
1339  * destroying the @a parser.
1340  *
1341  * @param[in,out]   parser  A parser object.
1342  * @param[in]       input   A source data.
1343  * @param[in]       size    The length of the source data in bytes.
1344  */
1345 
1346 YAML_DECLARE(void)
1347 yaml_parser_set_input_string(yaml_parser_t *parser,
1348         const unsigned char *input, size_t size);
1349 
1350 /**
1351  * Set a file input.
1352  *
1353  * @a file should be a file object open for reading.  The application is
1354  * responsible for closing the @a file.
1355  *
1356  * @param[in,out]   parser  A parser object.
1357  * @param[in]       file    An open file.
1358  */
1359 
1360 YAML_DECLARE(void)
1361 yaml_parser_set_input_file(yaml_parser_t *parser, FILE *file);
1362 
1363 /**
1364  * Set a generic input handler.
1365  *
1366  * @param[in,out]   parser  A parser object.
1367  * @param[in]       handler A read handler.
1368  * @param[in]       data    Any application data for passing to the read
1369  *                          handler.
1370  */
1371 
1372 YAML_DECLARE(void)
1373 yaml_parser_set_input(yaml_parser_t *parser,
1374         yaml_read_handler_t *handler, void *data);
1375 
1376 /**
1377  * Set the source encoding.
1378  *
1379  * @param[in,out]   parser      A parser object.
1380  * @param[in]       encoding    The source encoding.
1381  */
1382 
1383 YAML_DECLARE(void)
1384 yaml_parser_set_encoding(yaml_parser_t *parser, yaml_encoding_t encoding);
1385 
1386 /**
1387  * Scan the input stream and produce the next token.
1388  *
1389  * Call the function subsequently to produce a sequence of tokens corresponding
1390  * to the input stream.  The initial token has the type
1391  * @c YAML_STREAM_START_TOKEN while the ending token has the type
1392  * @c YAML_STREAM_END_TOKEN.
1393  *
1394  * An application is responsible for freeing any buffers associated with the
1395  * produced token object using the @c yaml_token_delete function.
1396  *
1397  * An application must not alternate the calls of yaml_parser_scan() with the
1398  * calls of yaml_parser_parse() or yaml_parser_load(). Doing this will break
1399  * the parser.
1400  *
1401  * @param[in,out]   parser      A parser object.
1402  * @param[out]      token       An empty token object.
1403  *
1404  * @returns @c 1 if the function succeeded, @c 0 on error.
1405  */
1406 
1407 YAML_DECLARE(int)
1408 yaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token);
1409 
1410 /**
1411  * Parse the input stream and produce the next parsing event.
1412  *
1413  * Call the function subsequently to produce a sequence of events corresponding
1414  * to the input stream.  The initial event has the type
1415  * @c YAML_STREAM_START_EVENT while the ending event has the type
1416  * @c YAML_STREAM_END_EVENT.
1417  *
1418  * An application is responsible for freeing any buffers associated with the
1419  * produced event object using the yaml_event_delete() function.
1420  *
1421  * An application must not alternate the calls of yaml_parser_parse() with the
1422  * calls of yaml_parser_scan() or yaml_parser_load(). Doing this will break the
1423  * parser.
1424  *
1425  * @param[in,out]   parser      A parser object.
1426  * @param[out]      event       An empty event object.
1427  *
1428  * @returns @c 1 if the function succeeded, @c 0 on error.
1429  */
1430 
1431 YAML_DECLARE(int)
1432 yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event);
1433 
1434 /**
1435  * Parse the input stream and produce the next YAML document.
1436  *
1437  * Call this function subsequently to produce a sequence of documents
1438  * constituting the input stream.
1439  *
1440  * If the produced document has no root node, it means that the document
1441  * end has been reached.
1442  *
1443  * An application is responsible for freeing any data associated with the
1444  * produced document object using the yaml_document_delete() function.
1445  *
1446  * An application must not alternate the calls of yaml_parser_load() with the
1447  * calls of yaml_parser_scan() or yaml_parser_parse(). Doing this will break
1448  * the parser.
1449  *
1450  * @param[in,out]   parser      A parser object.
1451  * @param[out]      document    An empty document object.
1452  *
1453  * @returns @c 1 if the function succeeded, @c 0 on error.
1454  */
1455 
1456 YAML_DECLARE(int)
1457 yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document);
1458 
1459 /** @} */
1460 
1461 /**
1462  * @defgroup emitter Emitter Definitions
1463  * @{
1464  */
1465 
1466 /**
1467  * The prototype of a write handler.
1468  *
1469  * The write handler is called when the emitter needs to flush the accumulated
1470  * characters to the output.  The handler should write @a size bytes of the
1471  * @a buffer to the output.
1472  *
1473  * @param[in,out]   data        A pointer to an application data specified by
1474  *                              yaml_emitter_set_output().
1475  * @param[in]       buffer      The buffer with bytes to be written.
1476  * @param[in]       size        The size of the buffer.
1477  *
1478  * @returns On success, the handler should return @c 1.  If the handler failed,
1479  * the returned value should be @c 0.
1480  */
1481 
1482 typedef int yaml_write_handler_t(void *data, unsigned char *buffer, size_t size);
1483 
1484 /** The emitter states. */
1485 typedef enum yaml_emitter_state_e {
1486     /** Expect STREAM-START. */
1487     YAML_EMIT_STREAM_START_STATE,
1488     /** Expect the first DOCUMENT-START or STREAM-END. */
1489     YAML_EMIT_FIRST_DOCUMENT_START_STATE,
1490     /** Expect DOCUMENT-START or STREAM-END. */
1491     YAML_EMIT_DOCUMENT_START_STATE,
1492     /** Expect the content of a document. */
1493     YAML_EMIT_DOCUMENT_CONTENT_STATE,
1494     /** Expect DOCUMENT-END. */
1495     YAML_EMIT_DOCUMENT_END_STATE,
1496 
1497     /** Expect the first item of a flow sequence. */
1498     YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE,
1499     /** Expect an item of a flow sequence. */
1500     YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE,
1501     /** Expect the first key of a flow mapping. */
1502     YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE,
1503     /** Expect a key of a flow mapping. */
1504     YAML_EMIT_FLOW_MAPPING_KEY_STATE,
1505     /** Expect a value for a simple key of a flow mapping. */
1506     YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE,
1507 
1508     /** Expect a value of a flow mapping. */
1509     YAML_EMIT_FLOW_MAPPING_VALUE_STATE,
1510     /** Expect the first item of a block sequence. */
1511     YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE,
1512     /** Expect an item of a block sequence. */
1513     YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE,
1514     /** Expect the first key of a block mapping. */
1515     YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE,
1516     /** Expect the key of a block mapping. */
1517     YAML_EMIT_BLOCK_MAPPING_KEY_STATE,
1518 
1519     /** Expect a value for a simple key of a block mapping. */
1520     YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE,
1521     /** Expect a value of a block mapping. */
1522     YAML_EMIT_BLOCK_MAPPING_VALUE_STATE,
1523     /** Expect nothing. */
1524     YAML_EMIT_END_STATE
1525 } yaml_emitter_state_t;
1526 
1527 
1528 /* This is needed for C++ */
1529 
1530 typedef struct yaml_anchors_s {
1531     /** The number of references. */
1532     int references;
1533     /** The anchor id. */
1534     int anchor;
1535     /** If the node has been emitted? */
1536     int serialized;
1537 } yaml_anchors_t;
1538 
1539 /**
1540  * The emitter structure.
1541  *
1542  * All members are internal.  Manage the structure using the @c yaml_emitter_
1543  * family of functions.
1544  */
1545 
1546 typedef struct yaml_emitter_s {
1547 
1548     /**
1549      * @name Error handling
1550      * @{
1551      */
1552 
1553     /** Error type. */
1554     yaml_error_type_t error;
1555     /** Error description. */
1556     const char *problem;
1557 
1558     /**
1559      * @}
1560      */
1561 
1562     /**
1563      * @name Writer stuff
1564      * @{
1565      */
1566 
1567     /** Write handler. */
1568     yaml_write_handler_t *write_handler;
1569 
1570     /** A pointer for passing to the write handler. */
1571     void *write_handler_data;
1572 
1573     /** Standard (string or file) output data. */
1574     union {
1575         /** String output data. */
1576         struct {
1577             /** The buffer pointer. */
1578             unsigned char *buffer;
1579             /** The buffer size. */
1580             size_t size;
1581             /** The number of written bytes. */
1582             size_t *size_written;
1583         } string;
1584 
1585         /** File output data. */
1586         FILE *file;
1587     } output;
1588 
1589     /** The working buffer. */
1590     struct {
1591         /** The beginning of the buffer. */
1592         yaml_char_t *start;
1593         /** The end of the buffer. */
1594         yaml_char_t *end;
1595         /** The current position of the buffer. */
1596         yaml_char_t *pointer;
1597         /** The last filled position of the buffer. */
1598         yaml_char_t *last;
1599     } buffer;
1600 
1601     /** The raw buffer. */
1602     struct {
1603         /** The beginning of the buffer. */
1604         unsigned char *start;
1605         /** The end of the buffer. */
1606         unsigned char *end;
1607         /** The current position of the buffer. */
1608         unsigned char *pointer;
1609         /** The last filled position of the buffer. */
1610         unsigned char *last;
1611     } raw_buffer;
1612 
1613     /** The stream encoding. */
1614     yaml_encoding_t encoding;
1615 
1616     /**
1617      * @}
1618      */
1619 
1620     /**
1621      * @name Emitter stuff
1622      * @{
1623      */
1624 
1625     /** If the output is in the canonical style? */
1626     int canonical;
1627     /** The number of indentation spaces. */
1628     int best_indent;
1629     /** The preferred width of the output lines. */
1630     int best_width;
1631     /** Allow unescaped non-ASCII characters? */
1632     int unicode;
1633     /** The preferred line break. */
1634     yaml_break_t line_break;
1635 
1636     /** The stack of states. */
1637     struct {
1638         /** The beginning of the stack. */
1639         yaml_emitter_state_t *start;
1640         /** The end of the stack. */
1641         yaml_emitter_state_t *end;
1642         /** The top of the stack. */
1643         yaml_emitter_state_t *top;
1644     } states;
1645 
1646     /** The current emitter state. */
1647     yaml_emitter_state_t state;
1648 
1649     /** The event queue. */
1650     struct {
1651         /** The beginning of the event queue. */
1652         yaml_event_t *start;
1653         /** The end of the event queue. */
1654         yaml_event_t *end;
1655         /** The head of the event queue. */
1656         yaml_event_t *head;
1657         /** The tail of the event queue. */
1658         yaml_event_t *tail;
1659     } events;
1660 
1661     /** The stack of indentation levels. */
1662     struct {
1663         /** The beginning of the stack. */
1664         int *start;
1665         /** The end of the stack. */
1666         int *end;
1667         /** The top of the stack. */
1668         int *top;
1669     } indents;
1670 
1671     /** The list of tag directives. */
1672     struct {
1673         /** The beginning of the list. */
1674         yaml_tag_directive_t *start;
1675         /** The end of the list. */
1676         yaml_tag_directive_t *end;
1677         /** The top of the list. */
1678         yaml_tag_directive_t *top;
1679     } tag_directives;
1680 
1681     /** The current indentation level. */
1682     int indent;
1683 
1684     /** The current flow level. */
1685     int flow_level;
1686 
1687     /** Is it the document root context? */
1688     int root_context;
1689     /** Is it a sequence context? */
1690     int sequence_context;
1691     /** Is it a mapping context? */
1692     int mapping_context;
1693     /** Is it a simple mapping key context? */
1694     int simple_key_context;
1695 
1696     /** The current line. */
1697     int line;
1698     /** The current column. */
1699     int column;
1700     /** If the last character was a whitespace? */
1701     int whitespace;
1702     /** If the last character was an indentation character (' ', '-', '?', ':')? */
1703     int indention;
1704     /** If an explicit document end is required? */
1705     int open_ended;
1706 
1707     /** Anchor analysis. */
1708     struct {
1709         /** The anchor value. */
1710         yaml_char_t *anchor;
1711         /** The anchor length. */
1712         size_t anchor_length;
1713         /** Is it an alias? */
1714         int alias;
1715     } anchor_data;
1716 
1717     /** Tag analysis. */
1718     struct {
1719         /** The tag handle. */
1720         yaml_char_t *handle;
1721         /** The tag handle length. */
1722         size_t handle_length;
1723         /** The tag suffix. */
1724         yaml_char_t *suffix;
1725         /** The tag suffix length. */
1726         size_t suffix_length;
1727     } tag_data;
1728 
1729     /** Scalar analysis. */
1730     struct {
1731         /** The scalar value. */
1732         yaml_char_t *value;
1733         /** The scalar length. */
1734         size_t length;
1735         /** Does the scalar contain line breaks? */
1736         int multiline;
1737         /** Can the scalar be expessed in the flow plain style? */
1738         int flow_plain_allowed;
1739         /** Can the scalar be expressed in the block plain style? */
1740         int block_plain_allowed;
1741         /** Can the scalar be expressed in the single quoted style? */
1742         int single_quoted_allowed;
1743         /** Can the scalar be expressed in the literal or folded styles? */
1744         int block_allowed;
1745         /** The output style. */
1746         yaml_scalar_style_t style;
1747     } scalar_data;
1748 
1749     /**
1750      * @}
1751      */
1752 
1753     /**
1754      * @name Dumper stuff
1755      * @{
1756      */
1757 
1758     /** If the stream was already opened? */
1759     int opened;
1760     /** If the stream was already closed? */
1761     int closed;
1762 
1763     /** The information associated with the document nodes. */
1764     yaml_anchors_t *anchors;
1765 
1766     /** The last assigned anchor id. */
1767     int last_anchor_id;
1768 
1769     /** The currently emitted document. */
1770     yaml_document_t *document;
1771 
1772     /**
1773      * @}
1774      */
1775 
1776 } yaml_emitter_t;
1777 
1778 /**
1779  * Initialize an emitter.
1780  *
1781  * This function creates a new emitter object.  An application is responsible
1782  * for destroying the object using the yaml_emitter_delete() function.
1783  *
1784  * @param[out]      emitter     An empty parser object.
1785  *
1786  * @returns @c 1 if the function succeeded, @c 0 on error.
1787  */
1788 
1789 YAML_DECLARE(int)
1790 yaml_emitter_initialize(yaml_emitter_t *emitter);
1791 
1792 /**
1793  * Destroy an emitter.
1794  *
1795  * @param[in,out]   emitter     An emitter object.
1796  */
1797 
1798 YAML_DECLARE(void)
1799 yaml_emitter_delete(yaml_emitter_t *emitter);
1800 
1801 /**
1802  * Set a string output.
1803  *
1804  * The emitter will write the output characters to the @a output buffer of the
1805  * size @a size.  The emitter will set @a size_written to the number of written
1806  * bytes.  If the buffer is smaller than required, the emitter produces the
1807  * YAML_WRITE_ERROR error.
1808  *
1809  * @param[in,out]   emitter         An emitter object.
1810  * @param[in]       output          An output buffer.
1811  * @param[in]       size            The buffer size.
1812  * @param[in]       size_written    The pointer to save the number of written
1813  *                                  bytes.
1814  */
1815 
1816 YAML_DECLARE(void)
1817 yaml_emitter_set_output_string(yaml_emitter_t *emitter,
1818         unsigned char *output, size_t size, size_t *size_written);
1819 
1820 /**
1821  * Set a file output.
1822  *
1823  * @a file should be a file object open for writing.  The application is
1824  * responsible for closing the @a file.
1825  *
1826  * @param[in,out]   emitter     An emitter object.
1827  * @param[in]       file        An open file.
1828  */
1829 
1830 YAML_DECLARE(void)
1831 yaml_emitter_set_output_file(yaml_emitter_t *emitter, FILE *file);
1832 
1833 /**
1834  * Set a generic output handler.
1835  *
1836  * @param[in,out]   emitter     An emitter object.
1837  * @param[in]       handler     A write handler.
1838  * @param[in]       data        Any application data for passing to the write
1839  *                              handler.
1840  */
1841 
1842 YAML_DECLARE(void)
1843 yaml_emitter_set_output(yaml_emitter_t *emitter,
1844         yaml_write_handler_t *handler, void *data);
1845 
1846 /**
1847  * Set the output encoding.
1848  *
1849  * @param[in,out]   emitter     An emitter object.
1850  * @param[in]       encoding    The output encoding.
1851  */
1852 
1853 YAML_DECLARE(void)
1854 yaml_emitter_set_encoding(yaml_emitter_t *emitter, yaml_encoding_t encoding);
1855 
1856 /**
1857  * Set if the output should be in the "canonical" format as in the YAML
1858  * specification.
1859  *
1860  * @param[in,out]   emitter     An emitter object.
1861  * @param[in]       canonical   If the output is canonical.
1862  */
1863 
1864 YAML_DECLARE(void)
1865 yaml_emitter_set_canonical(yaml_emitter_t *emitter, int canonical);
1866 
1867 /**
1868  * Set the indentation increment.
1869  *
1870  * @param[in,out]   emitter     An emitter object.
1871  * @param[in]       indent      The indentation increment (1 < . < 10).
1872  */
1873 
1874 YAML_DECLARE(void)
1875 yaml_emitter_set_indent(yaml_emitter_t *emitter, int indent);
1876 
1877 /**
1878  * Set the preferred line width. @c -1 means unlimited.
1879  *
1880  * @param[in,out]   emitter     An emitter object.
1881  * @param[in]       width       The preferred line width.
1882  */
1883 
1884 YAML_DECLARE(void)
1885 yaml_emitter_set_width(yaml_emitter_t *emitter, int width);
1886 
1887 /**
1888  * Set if unescaped non-ASCII characters are allowed.
1889  *
1890  * @param[in,out]   emitter     An emitter object.
1891  * @param[in]       unicode     If unescaped Unicode characters are allowed.
1892  */
1893 
1894 YAML_DECLARE(void)
1895 yaml_emitter_set_unicode(yaml_emitter_t *emitter, int unicode);
1896 
1897 /**
1898  * Set the preferred line break.
1899  *
1900  * @param[in,out]   emitter     An emitter object.
1901  * @param[in]       line_break  The preferred line break.
1902  */
1903 
1904 YAML_DECLARE(void)
1905 yaml_emitter_set_break(yaml_emitter_t *emitter, yaml_break_t line_break);
1906 
1907 /**
1908  * Emit an event.
1909  *
1910  * The event object may be generated using the yaml_parser_parse() function.
1911  * The emitter takes the responsibility for the event object and destroys its
1912  * content after it is emitted. The event object is destroyed even if the
1913  * function fails.
1914  *
1915  * @param[in,out]   emitter     An emitter object.
1916  * @param[in,out]   event       An event object.
1917  *
1918  * @returns @c 1 if the function succeeded, @c 0 on error.
1919  */
1920 
1921 YAML_DECLARE(int)
1922 yaml_emitter_emit(yaml_emitter_t *emitter, yaml_event_t *event);
1923 
1924 /**
1925  * Start a YAML stream.
1926  *
1927  * This function should be used before yaml_emitter_dump() is called.
1928  *
1929  * @param[in,out]   emitter     An emitter object.
1930  *
1931  * @returns @c 1 if the function succeeded, @c 0 on error.
1932  */
1933 
1934 YAML_DECLARE(int)
1935 yaml_emitter_open(yaml_emitter_t *emitter);
1936 
1937 /**
1938  * Finish a YAML stream.
1939  *
1940  * This function should be used after yaml_emitter_dump() is called.
1941  *
1942  * @param[in,out]   emitter     An emitter object.
1943  *
1944  * @returns @c 1 if the function succeeded, @c 0 on error.
1945  */
1946 
1947 YAML_DECLARE(int)
1948 yaml_emitter_close(yaml_emitter_t *emitter);
1949 
1950 /**
1951  * Emit a YAML document.
1952  *
1953  * The documen object may be generated using the yaml_parser_load() function
1954  * or the yaml_document_initialize() function.  The emitter takes the
1955  * responsibility for the document object and destroys its content after
1956  * it is emitted. The document object is destroyed even if the function fails.
1957  *
1958  * @param[in,out]   emitter     An emitter object.
1959  * @param[in,out]   document    A document object.
1960  *
1961  * @returns @c 1 if the function succeeded, @c 0 on error.
1962  */
1963 
1964 YAML_DECLARE(int)
1965 yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document);
1966 
1967 /**
1968  * Flush the accumulated characters to the output.
1969  *
1970  * @param[in,out]   emitter     An emitter object.
1971  *
1972  * @returns @c 1 if the function succeeded, @c 0 on error.
1973  */
1974 
1975 YAML_DECLARE(int)
1976 yaml_emitter_flush(yaml_emitter_t *emitter);
1977 
1978 /** @} */
1979 
1980 #ifdef __cplusplus
1981 }
1982 #endif
1983 
1984 #endif /* #ifndef YAML_H */
1985