/**1* @file yaml.h2* @brief Public interface for libyaml.3*4* Include the header file with the code:5* @code6* #include <yaml.h>7* @endcode8*/910#ifndef YAML_H11#define YAML_H1213#ifdef __cplusplus14extern "C" {15#endif1617#include <stdlib.h>18#include <stdio.h>19#include <string.h>2021/**22* @defgroup export Export Definitions23* @{24*/2526/** The public API declaration. */2728#if defined(__MINGW32__)29# define YAML_DECLARE(type) type30#elif defined(_WIN32)31# if defined(YAML_DECLARE_STATIC)32# define YAML_DECLARE(type) type33# elif defined(YAML_DECLARE_EXPORT)34# define YAML_DECLARE(type) __declspec(dllexport) type35# else36# define YAML_DECLARE(type) __declspec(dllimport) type37# endif38#else39# define YAML_DECLARE(type) type40#endif4142/** @} */4344/**45* @defgroup version Version Information46* @{47*/4849/**50* Get the library version as a string.51*52* @returns The function returns the pointer to a static string of the form53* @c "X.Y.Z", where @c X is the major version number, @c Y is a minor version54* number, and @c Z is the patch version number.55*/5657YAML_DECLARE(const char *)58yaml_get_version_string(void);5960/**61* Get the library version numbers.62*63* @param[out] major Major version number.64* @param[out] minor Minor version number.65* @param[out] patch Patch version number.66*/6768YAML_DECLARE(void)69yaml_get_version(int *major, int *minor, int *patch);7071/** @} */7273/**74* @defgroup basic Basic Types75* @{76*/7778/** The character type (UTF-8 octet). */79typedef unsigned char yaml_char_t;8081/** The version directive data. */82typedef struct yaml_version_directive_s {83/** The major version number. */84int major;85/** The minor version number. */86int minor;87} yaml_version_directive_t;8889/** The tag directive data. */90typedef struct yaml_tag_directive_s {91/** The tag handle. */92yaml_char_t *handle;93/** The tag prefix. */94yaml_char_t *prefix;95} yaml_tag_directive_t;9697/** The stream encoding. */98typedef enum yaml_encoding_e {99/** Let the parser choose the encoding. */100YAML_ANY_ENCODING,101/** The default UTF-8 encoding. */102YAML_UTF8_ENCODING,103/** The UTF-16-LE encoding with BOM. */104YAML_UTF16LE_ENCODING,105/** The UTF-16-BE encoding with BOM. */106YAML_UTF16BE_ENCODING107} yaml_encoding_t;108109/** Line break types. */110111typedef enum yaml_break_e {112/** Let the parser choose the break type. */113YAML_ANY_BREAK,114/** Use CR for line breaks (Mac style). */115YAML_CR_BREAK,116/** Use LN for line breaks (Unix style). */117YAML_LN_BREAK,118/** Use CR LN for line breaks (DOS style). */119YAML_CRLN_BREAK120} yaml_break_t;121122/** Many bad things could happen with the parser and emitter. */123typedef enum yaml_error_type_e {124/** No error is produced. */125YAML_NO_ERROR,126127/** Cannot allocate or reallocate a block of memory. */128YAML_MEMORY_ERROR,129130/** Cannot read or decode the input stream. */131YAML_READER_ERROR,132/** Cannot scan the input stream. */133YAML_SCANNER_ERROR,134/** Cannot parse the input stream. */135YAML_PARSER_ERROR,136/** Cannot compose a YAML document. */137YAML_COMPOSER_ERROR,138139/** Cannot write to the output stream. */140YAML_WRITER_ERROR,141/** Cannot emit a YAML stream. */142YAML_EMITTER_ERROR143} yaml_error_type_t;144145/** The pointer position. */146typedef struct yaml_mark_s {147/** The position index. */148size_t index;149150/** The position line. */151size_t line;152153/** The position column. */154size_t column;155} yaml_mark_t;156157/** @} */158159/**160* @defgroup styles Node Styles161* @{162*/163164/** Scalar styles. */165typedef enum yaml_scalar_style_e {166/** Let the emitter choose the style. */167YAML_ANY_SCALAR_STYLE,168169/** The plain scalar style. */170YAML_PLAIN_SCALAR_STYLE,171172/** The single-quoted scalar style. */173YAML_SINGLE_QUOTED_SCALAR_STYLE,174/** The double-quoted scalar style. */175YAML_DOUBLE_QUOTED_SCALAR_STYLE,176177/** The literal scalar style. */178YAML_LITERAL_SCALAR_STYLE,179/** The folded scalar style. */180YAML_FOLDED_SCALAR_STYLE181} yaml_scalar_style_t;182183/** Sequence styles. */184typedef enum yaml_sequence_style_e {185/** Let the emitter choose the style. */186YAML_ANY_SEQUENCE_STYLE,187188/** The block sequence style. */189YAML_BLOCK_SEQUENCE_STYLE,190/** The flow sequence style. */191YAML_FLOW_SEQUENCE_STYLE192} yaml_sequence_style_t;193194/** Mapping styles. */195typedef enum yaml_mapping_style_e {196/** Let the emitter choose the style. */197YAML_ANY_MAPPING_STYLE,198199/** The block mapping style. */200YAML_BLOCK_MAPPING_STYLE,201/** The flow mapping style. */202YAML_FLOW_MAPPING_STYLE203/* YAML_FLOW_SET_MAPPING_STYLE */204} yaml_mapping_style_t;205206/** @} */207208/**209* @defgroup tokens Tokens210* @{211*/212213/** Token types. */214typedef enum yaml_token_type_e {215/** An empty token. */216YAML_NO_TOKEN,217218/** A STREAM-START token. */219YAML_STREAM_START_TOKEN,220/** A STREAM-END token. */221YAML_STREAM_END_TOKEN,222223/** A VERSION-DIRECTIVE token. */224YAML_VERSION_DIRECTIVE_TOKEN,225/** A TAG-DIRECTIVE token. */226YAML_TAG_DIRECTIVE_TOKEN,227/** A DOCUMENT-START token. */228YAML_DOCUMENT_START_TOKEN,229/** A DOCUMENT-END token. */230YAML_DOCUMENT_END_TOKEN,231232/** A BLOCK-SEQUENCE-START token. */233YAML_BLOCK_SEQUENCE_START_TOKEN,234/** A BLOCK-MAPPING-START token. */235YAML_BLOCK_MAPPING_START_TOKEN,236/** A BLOCK-END token. */237YAML_BLOCK_END_TOKEN,238239/** A FLOW-SEQUENCE-START token. */240YAML_FLOW_SEQUENCE_START_TOKEN,241/** A FLOW-SEQUENCE-END token. */242YAML_FLOW_SEQUENCE_END_TOKEN,243/** A FLOW-MAPPING-START token. */244YAML_FLOW_MAPPING_START_TOKEN,245/** A FLOW-MAPPING-END token. */246YAML_FLOW_MAPPING_END_TOKEN,247248/** A BLOCK-ENTRY token. */249YAML_BLOCK_ENTRY_TOKEN,250/** A FLOW-ENTRY token. */251YAML_FLOW_ENTRY_TOKEN,252/** A KEY token. */253YAML_KEY_TOKEN,254/** A VALUE token. */255YAML_VALUE_TOKEN,256257/** An ALIAS token. */258YAML_ALIAS_TOKEN,259/** An ANCHOR token. */260YAML_ANCHOR_TOKEN,261/** A TAG token. */262YAML_TAG_TOKEN,263/** A SCALAR token. */264YAML_SCALAR_TOKEN265} yaml_token_type_t;266267/** The token structure. */268typedef struct yaml_token_s {269270/** The token type. */271yaml_token_type_t type;272273/** The token data. */274union {275276/** The stream start (for @c YAML_STREAM_START_TOKEN). */277struct {278/** The stream encoding. */279yaml_encoding_t encoding;280} stream_start;281282/** The alias (for @c YAML_ALIAS_TOKEN). */283struct {284/** The alias value. */285yaml_char_t *value;286} alias;287288/** The anchor (for @c YAML_ANCHOR_TOKEN). */289struct {290/** The anchor value. */291yaml_char_t *value;292} anchor;293294/** The tag (for @c YAML_TAG_TOKEN). */295struct {296/** The tag handle. */297yaml_char_t *handle;298/** The tag suffix. */299yaml_char_t *suffix;300} tag;301302/** The scalar value (for @c YAML_SCALAR_TOKEN). */303struct {304/** The scalar value. */305yaml_char_t *value;306/** The length of the scalar value. */307size_t length;308/** The scalar style. */309yaml_scalar_style_t style;310} scalar;311312/** The version directive (for @c YAML_VERSION_DIRECTIVE_TOKEN). */313struct {314/** The major version number. */315int major;316/** The minor version number. */317int minor;318} version_directive;319320/** The tag directive (for @c YAML_TAG_DIRECTIVE_TOKEN). */321struct {322/** The tag handle. */323yaml_char_t *handle;324/** The tag prefix. */325yaml_char_t *prefix;326} tag_directive;327328} data;329330/** The beginning of the token. */331yaml_mark_t start_mark;332/** The end of the token. */333yaml_mark_t end_mark;334335} yaml_token_t;336337/**338* Free any memory allocated for a token object.339*340* @param[in,out] token A token object.341*/342343YAML_DECLARE(void)344yaml_token_delete(yaml_token_t *token);345346/** @} */347348/**349* @defgroup events Events350* @{351*/352353/** Event types. */354typedef enum yaml_event_type_e {355/** An empty event. */356YAML_NO_EVENT,357358/** A STREAM-START event. */359YAML_STREAM_START_EVENT,360/** A STREAM-END event. */361YAML_STREAM_END_EVENT,362363/** A DOCUMENT-START event. */364YAML_DOCUMENT_START_EVENT,365/** A DOCUMENT-END event. */366YAML_DOCUMENT_END_EVENT,367368/** An ALIAS event. */369YAML_ALIAS_EVENT,370/** A SCALAR event. */371YAML_SCALAR_EVENT,372373/** A SEQUENCE-START event. */374YAML_SEQUENCE_START_EVENT,375/** A SEQUENCE-END event. */376YAML_SEQUENCE_END_EVENT,377378/** A MAPPING-START event. */379YAML_MAPPING_START_EVENT,380/** A MAPPING-END event. */381YAML_MAPPING_END_EVENT382} yaml_event_type_t;383384/** The event structure. */385typedef struct yaml_event_s {386387/** The event type. */388yaml_event_type_t type;389390/** The event data. */391union {392393/** The stream parameters (for @c YAML_STREAM_START_EVENT). */394struct {395/** The document encoding. */396yaml_encoding_t encoding;397} stream_start;398399/** The document parameters (for @c YAML_DOCUMENT_START_EVENT). */400struct {401/** The version directive. */402yaml_version_directive_t *version_directive;403404/** The list of tag directives. */405struct {406/** The beginning of the tag directives list. */407yaml_tag_directive_t *start;408/** The end of the tag directives list. */409yaml_tag_directive_t *end;410} tag_directives;411412/** Is the document indicator implicit? */413int implicit;414} document_start;415416/** The document end parameters (for @c YAML_DOCUMENT_END_EVENT). */417struct {418/** Is the document end indicator implicit? */419int implicit;420} document_end;421422/** The alias parameters (for @c YAML_ALIAS_EVENT). */423struct {424/** The anchor. */425yaml_char_t *anchor;426} alias;427428/** The scalar parameters (for @c YAML_SCALAR_EVENT). */429struct {430/** The anchor. */431yaml_char_t *anchor;432/** The tag. */433yaml_char_t *tag;434/** The scalar value. */435yaml_char_t *value;436/** The length of the scalar value. */437size_t length;438/** Is the tag optional for the plain style? */439int plain_implicit;440/** Is the tag optional for any non-plain style? */441int quoted_implicit;442/** The scalar style. */443yaml_scalar_style_t style;444} scalar;445446/** The sequence parameters (for @c YAML_SEQUENCE_START_EVENT). */447struct {448/** The anchor. */449yaml_char_t *anchor;450/** The tag. */451yaml_char_t *tag;452/** Is the tag optional? */453int implicit;454/** The sequence style. */455yaml_sequence_style_t style;456} sequence_start;457458/** The mapping parameters (for @c YAML_MAPPING_START_EVENT). */459struct {460/** The anchor. */461yaml_char_t *anchor;462/** The tag. */463yaml_char_t *tag;464/** Is the tag optional? */465int implicit;466/** The mapping style. */467yaml_mapping_style_t style;468} mapping_start;469470} data;471472/** The beginning of the event. */473yaml_mark_t start_mark;474/** The end of the event. */475yaml_mark_t end_mark;476477} yaml_event_t;478479/**480* Create the STREAM-START event.481*482* @param[out] event An empty event object.483* @param[in] encoding The stream encoding.484*485* @returns @c 1 if the function succeeded, @c 0 on error.486*/487488YAML_DECLARE(int)489yaml_stream_start_event_initialize(yaml_event_t *event,490yaml_encoding_t encoding);491492/**493* Create the STREAM-END event.494*495* @param[out] event An empty event object.496*497* @returns @c 1 if the function succeeded, @c 0 on error.498*/499500YAML_DECLARE(int)501yaml_stream_end_event_initialize(yaml_event_t *event);502503/**504* Create the DOCUMENT-START event.505*506* The @a implicit argument is considered as a stylistic parameter and may be507* ignored by the emitter.508*509* @param[out] event An empty event object.510* @param[in] version_directive The %YAML directive value or511* @c NULL.512* @param[in] tag_directives_start The beginning of the %TAG513* directives list.514* @param[in] tag_directives_end The end of the %TAG directives515* list.516* @param[in] implicit If the document start indicator is517* implicit.518*519* @returns @c 1 if the function succeeded, @c 0 on error.520*/521522YAML_DECLARE(int)523yaml_document_start_event_initialize(yaml_event_t *event,524yaml_version_directive_t *version_directive,525yaml_tag_directive_t *tag_directives_start,526yaml_tag_directive_t *tag_directives_end,527int implicit);528529/**530* Create the DOCUMENT-END event.531*532* The @a implicit argument is considered as a stylistic parameter and may be533* ignored by the emitter.534*535* @param[out] event An empty event object.536* @param[in] implicit If the document end indicator is implicit.537*538* @returns @c 1 if the function succeeded, @c 0 on error.539*/540541YAML_DECLARE(int)542yaml_document_end_event_initialize(yaml_event_t *event, int implicit);543544/**545* Create an ALIAS event.546*547* @param[out] event An empty event object.548* @param[in] anchor The anchor value.549*550* @returns @c 1 if the function succeeded, @c 0 on error.551*/552553YAML_DECLARE(int)554yaml_alias_event_initialize(yaml_event_t *event, const yaml_char_t *anchor);555556/**557* Create a SCALAR event.558*559* The @a style argument may be ignored by the emitter.560*561* Either the @a tag attribute or one of the @a plain_implicit and562* @a quoted_implicit flags must be set.563*564* @param[out] event An empty event object.565* @param[in] anchor The scalar anchor or @c NULL.566* @param[in] tag The scalar tag or @c NULL.567* @param[in] value The scalar value.568* @param[in] length The length of the scalar value.569* @param[in] plain_implicit If the tag may be omitted for the plain570* style.571* @param[in] quoted_implicit If the tag may be omitted for any572* non-plain style.573* @param[in] style The scalar style.574*575* @returns @c 1 if the function succeeded, @c 0 on error.576*/577578YAML_DECLARE(int)579yaml_scalar_event_initialize(yaml_event_t *event,580const yaml_char_t *anchor, const yaml_char_t *tag,581const yaml_char_t *value, int length,582int plain_implicit, int quoted_implicit,583yaml_scalar_style_t style);584585/**586* Create a SEQUENCE-START event.587*588* The @a style argument may be ignored by the emitter.589*590* Either the @a tag attribute or the @a implicit flag must be set.591*592* @param[out] event An empty event object.593* @param[in] anchor The sequence anchor or @c NULL.594* @param[in] tag The sequence tag or @c NULL.595* @param[in] implicit If the tag may be omitted.596* @param[in] style The sequence style.597*598* @returns @c 1 if the function succeeded, @c 0 on error.599*/600601YAML_DECLARE(int)602yaml_sequence_start_event_initialize(yaml_event_t *event,603const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,604yaml_sequence_style_t style);605606/**607* Create a SEQUENCE-END event.608*609* @param[out] event An empty event object.610*611* @returns @c 1 if the function succeeded, @c 0 on error.612*/613614YAML_DECLARE(int)615yaml_sequence_end_event_initialize(yaml_event_t *event);616617/**618* Create a MAPPING-START event.619*620* The @a style argument may be ignored by the emitter.621*622* Either the @a tag attribute or the @a implicit flag must be set.623*624* @param[out] event An empty event object.625* @param[in] anchor The mapping anchor or @c NULL.626* @param[in] tag The mapping tag or @c NULL.627* @param[in] implicit If the tag may be omitted.628* @param[in] style The mapping style.629*630* @returns @c 1 if the function succeeded, @c 0 on error.631*/632633YAML_DECLARE(int)634yaml_mapping_start_event_initialize(yaml_event_t *event,635const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,636yaml_mapping_style_t style);637638/**639* Create a MAPPING-END event.640*641* @param[out] event An empty event object.642*643* @returns @c 1 if the function succeeded, @c 0 on error.644*/645646YAML_DECLARE(int)647yaml_mapping_end_event_initialize(yaml_event_t *event);648649/**650* Free any memory allocated for an event object.651*652* @param[in,out] event An event object.653*/654655YAML_DECLARE(void)656yaml_event_delete(yaml_event_t *event);657658/** @} */659660/**661* @defgroup nodes Nodes662* @{663*/664665/** The tag @c !!null with the only possible value: @c null. */666#define YAML_NULL_TAG "tag:yaml.org,2002:null"667/** The tag @c !!bool with the values: @c true and @c false. */668#define YAML_BOOL_TAG "tag:yaml.org,2002:bool"669/** The tag @c !!str for string values. */670#define YAML_STR_TAG "tag:yaml.org,2002:str"671/** The tag @c !!int for integer values. */672#define YAML_INT_TAG "tag:yaml.org,2002:int"673/** The tag @c !!float for float values. */674#define YAML_FLOAT_TAG "tag:yaml.org,2002:float"675/** The tag @c !!timestamp for date and time values. */676#define YAML_TIMESTAMP_TAG "tag:yaml.org,2002:timestamp"677678/** The tag @c !!seq is used to denote sequences. */679#define YAML_SEQ_TAG "tag:yaml.org,2002:seq"680/** The tag @c !!map is used to denote mapping. */681#define YAML_MAP_TAG "tag:yaml.org,2002:map"682683/** The default scalar tag is @c !!str. */684#define YAML_DEFAULT_SCALAR_TAG YAML_STR_TAG685/** The default sequence tag is @c !!seq. */686#define YAML_DEFAULT_SEQUENCE_TAG YAML_SEQ_TAG687/** The default mapping tag is @c !!map. */688#define YAML_DEFAULT_MAPPING_TAG YAML_MAP_TAG689690/** Node types. */691typedef enum yaml_node_type_e {692/** An empty node. */693YAML_NO_NODE,694695/** A scalar node. */696YAML_SCALAR_NODE,697/** A sequence node. */698YAML_SEQUENCE_NODE,699/** A mapping node. */700YAML_MAPPING_NODE701} yaml_node_type_t;702703/** The forward definition of a document node structure. */704typedef struct yaml_node_s yaml_node_t;705706/** An element of a sequence node. */707typedef int yaml_node_item_t;708709/** An element of a mapping node. */710typedef struct yaml_node_pair_s {711/** The key of the element. */712int key;713/** The value of the element. */714int value;715} yaml_node_pair_t;716717/** The node structure. */718struct yaml_node_s {719720/** The node type. */721yaml_node_type_t type;722723/** The node tag. */724yaml_char_t *tag;725726/** The node data. */727union {728729/** The scalar parameters (for @c YAML_SCALAR_NODE). */730struct {731/** The scalar value. */732yaml_char_t *value;733/** The length of the scalar value. */734size_t length;735/** The scalar style. */736yaml_scalar_style_t style;737} scalar;738739/** The sequence parameters (for @c YAML_SEQUENCE_NODE). */740struct {741/** The stack of sequence items. */742struct {743/** The beginning of the stack. */744yaml_node_item_t *start;745/** The end of the stack. */746yaml_node_item_t *end;747/** The top of the stack. */748yaml_node_item_t *top;749} items;750/** The sequence style. */751yaml_sequence_style_t style;752} sequence;753754/** The mapping parameters (for @c YAML_MAPPING_NODE). */755struct {756/** The stack of mapping pairs (key, value). */757struct {758/** The beginning of the stack. */759yaml_node_pair_t *start;760/** The end of the stack. */761yaml_node_pair_t *end;762/** The top of the stack. */763yaml_node_pair_t *top;764} pairs;765/** The mapping style. */766yaml_mapping_style_t style;767} mapping;768769} data;770771/** The beginning of the node. */772yaml_mark_t start_mark;773/** The end of the node. */774yaml_mark_t end_mark;775776};777778/** The document structure. */779typedef struct yaml_document_s {780781/** The document nodes. */782struct {783/** The beginning of the stack. */784yaml_node_t *start;785/** The end of the stack. */786yaml_node_t *end;787/** The top of the stack. */788yaml_node_t *top;789} nodes;790791/** The version directive. */792yaml_version_directive_t *version_directive;793794/** The list of tag directives. */795struct {796/** The beginning of the tag directives list. */797yaml_tag_directive_t *start;798/** The end of the tag directives list. */799yaml_tag_directive_t *end;800} tag_directives;801802/** Is the document start indicator implicit? */803int start_implicit;804/** Is the document end indicator implicit? */805int end_implicit;806807/** The beginning of the document. */808yaml_mark_t start_mark;809/** The end of the document. */810yaml_mark_t end_mark;811812} yaml_document_t;813814/**815* Create a YAML document.816*817* @param[out] document An empty document object.818* @param[in] version_directive The %YAML directive value or819* @c NULL.820* @param[in] tag_directives_start The beginning of the %TAG821* directives list.822* @param[in] tag_directives_end The end of the %TAG directives823* list.824* @param[in] start_implicit If the document start indicator is825* implicit.826* @param[in] end_implicit If the document end indicator is827* implicit.828*829* @returns @c 1 if the function succeeded, @c 0 on error.830*/831832YAML_DECLARE(int)833yaml_document_initialize(yaml_document_t *document,834yaml_version_directive_t *version_directive,835yaml_tag_directive_t *tag_directives_start,836yaml_tag_directive_t *tag_directives_end,837int start_implicit, int end_implicit);838839/**840* Delete a YAML document and all its nodes.841*842* @param[in,out] document A document object.843*/844845YAML_DECLARE(void)846yaml_document_delete(yaml_document_t *document);847848/**849* Get a node of a YAML document.850*851* The pointer returned by this function is valid until any of the functions852* modifying the documents are called.853*854* @param[in] document A document object.855* @param[in] index The node id.856*857* @returns the node objct or @c NULL if @c node_id is out of range.858*/859860YAML_DECLARE(yaml_node_t *)861yaml_document_get_node(yaml_document_t *document, int index);862863/**864* Get the root of a YAML document node.865*866* The root object is the first object added to the document.867*868* The pointer returned by this function is valid until any of the functions869* modifying the documents are called.870*871* An empty document produced by the parser signifies the end of a YAML872* stream.873*874* @param[in] document A document object.875*876* @returns the node object or @c NULL if the document is empty.877*/878879YAML_DECLARE(yaml_node_t *)880yaml_document_get_root_node(yaml_document_t *document);881882/**883* Create a SCALAR node and attach it to the document.884*885* The @a style argument may be ignored by the emitter.886*887* @param[in,out] document A document object.888* @param[in] tag The scalar tag.889* @param[in] value The scalar value.890* @param[in] length The length of the scalar value.891* @param[in] style The scalar style.892*893* @returns the node id or @c 0 on error.894*/895896YAML_DECLARE(int)897yaml_document_add_scalar(yaml_document_t *document,898const yaml_char_t *tag, const yaml_char_t *value, int length,899yaml_scalar_style_t style);900901/**902* Create a SEQUENCE node and attach it to the document.903*904* The @a style argument may be ignored by the emitter.905*906* @param[in,out] document A document object.907* @param[in] tag The sequence tag.908* @param[in] style The sequence style.909*910* @returns the node id or @c 0 on error.911*/912913YAML_DECLARE(int)914yaml_document_add_sequence(yaml_document_t *document,915const yaml_char_t *tag, yaml_sequence_style_t style);916917/**918* Create a MAPPING node and attach it to the document.919*920* The @a style argument may be ignored by the emitter.921*922* @param[in,out] document A document object.923* @param[in] tag The sequence tag.924* @param[in] style The sequence style.925*926* @returns the node id or @c 0 on error.927*/928929YAML_DECLARE(int)930yaml_document_add_mapping(yaml_document_t *document,931const yaml_char_t *tag, yaml_mapping_style_t style);932933/**934* Add an item to a SEQUENCE node.935*936* @param[in,out] document A document object.937* @param[in] sequence The sequence node id.938* @param[in] item The item node id.939*940* @returns @c 1 if the function succeeded, @c 0 on error.941*/942943YAML_DECLARE(int)944yaml_document_append_sequence_item(yaml_document_t *document,945int sequence, int item);946947/**948* Add a pair of a key and a value to a MAPPING node.949*950* @param[in,out] document A document object.951* @param[in] mapping The mapping node id.952* @param[in] key The key node id.953* @param[in] value The value node id.954*955* @returns @c 1 if the function succeeded, @c 0 on error.956*/957958YAML_DECLARE(int)959yaml_document_append_mapping_pair(yaml_document_t *document,960int mapping, int key, int value);961962/** @} */963964/**965* @defgroup parser Parser Definitions966* @{967*/968969/**970* The prototype of a read handler.971*972* The read handler is called when the parser needs to read more bytes from the973* source. The handler should write not more than @a size bytes to the @a974* buffer. The number of written bytes should be set to the @a length variable.975*976* @param[in,out] data A pointer to an application data specified by977* yaml_parser_set_input().978* @param[out] buffer The buffer to write the data from the source.979* @param[in] size The size of the buffer.980* @param[out] size_read The actual number of bytes read from the source.981*982* @returns On success, the handler should return @c 1. If the handler failed,983* the returned value should be @c 0. On EOF, the handler should set the984* @a size_read to @c 0 and return @c 1.985*/986987typedef int yaml_read_handler_t(void *data, unsigned char *buffer, size_t size,988size_t *size_read);989990/**991* This structure holds information about a potential simple key.992*/993994typedef struct yaml_simple_key_s {995/** Is a simple key possible? */996int possible;997998/** Is a simple key required? */999int required;10001001/** The number of the token. */1002size_t token_number;10031004/** The position mark. */1005yaml_mark_t mark;1006} yaml_simple_key_t;10071008/**1009* The states of the parser.1010*/1011typedef enum yaml_parser_state_e {1012/** Expect STREAM-START. */1013YAML_PARSE_STREAM_START_STATE,1014/** Expect the beginning of an implicit document. */1015YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE,1016/** Expect DOCUMENT-START. */1017YAML_PARSE_DOCUMENT_START_STATE,1018/** Expect the content of a document. */1019YAML_PARSE_DOCUMENT_CONTENT_STATE,1020/** Expect DOCUMENT-END. */1021YAML_PARSE_DOCUMENT_END_STATE,10221023/** Expect a block node. */1024YAML_PARSE_BLOCK_NODE_STATE,1025/** Expect a block node or indentless sequence. */1026YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE,1027/** Expect a flow node. */1028YAML_PARSE_FLOW_NODE_STATE,1029/** Expect the first entry of a block sequence. */1030YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE,1031/** Expect an entry of a block sequence. */1032YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE,10331034/** Expect an entry of an indentless sequence. */1035YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE,1036/** Expect the first key of a block mapping. */1037YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE,1038/** Expect a block mapping key. */1039YAML_PARSE_BLOCK_MAPPING_KEY_STATE,1040/** Expect a block mapping value. */1041YAML_PARSE_BLOCK_MAPPING_VALUE_STATE,1042/** Expect the first entry of a flow sequence. */1043YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE,10441045/** Expect an entry of a flow sequence. */1046YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE,1047/** Expect a key of an ordered mapping. */1048YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE,1049/** Expect a value of an ordered mapping. */1050YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE,1051/** Expect the and of an ordered mapping entry. */1052YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE,1053/** Expect the first key of a flow mapping. */1054YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE,1055/** Expect a key of a flow mapping. */10561057YAML_PARSE_FLOW_MAPPING_KEY_STATE,1058/** Expect a value of a flow mapping. */1059YAML_PARSE_FLOW_MAPPING_VALUE_STATE,1060/** Expect an empty value of a flow mapping. */1061YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE,1062/** Expect nothing. */1063YAML_PARSE_END_STATE1064} yaml_parser_state_t;10651066/**1067* This structure holds aliases data.1068*/10691070typedef struct yaml_alias_data_s {1071/** The anchor. */1072yaml_char_t *anchor;1073/** The node id. */1074int index;1075/** The anchor mark. */1076yaml_mark_t mark;1077} yaml_alias_data_t;10781079/**1080* The parser structure.1081*1082* All members are internal. Manage the structure using the @c yaml_parser_1083* family of functions.1084*/10851086typedef struct yaml_parser_s {10871088/**1089* @name Error handling1090* @{1091*/10921093/** Error type. */1094yaml_error_type_t error;1095/** Error description. */1096const char *problem;1097/** The byte about which the problem occured. */1098size_t problem_offset;1099/** The problematic value (@c -1 is none). */1100int problem_value;1101/** The problem position. */1102yaml_mark_t problem_mark;1103/** The error context. */1104const char *context;1105/** The context position. */1106yaml_mark_t context_mark;11071108/**1109* @}1110*/11111112/**1113* @name Reader stuff1114* @{1115*/11161117/** Read handler. */1118yaml_read_handler_t *read_handler;11191120/** A pointer for passing to the read handler. */1121void *read_handler_data;11221123/** Standard (string or file) input data. */1124union {1125/** String input data. */1126struct {1127/** The string start pointer. */1128const unsigned char *start;1129/** The string end pointer. */1130const unsigned char *end;1131/** The string current position. */1132const unsigned char *current;1133} string;11341135/** File input data. */1136FILE *file;1137} input;11381139/** EOF flag */1140int eof;11411142/** The working buffer. */1143struct {1144/** The beginning of the buffer. */1145yaml_char_t *start;1146/** The end of the buffer. */1147yaml_char_t *end;1148/** The current position of the buffer. */1149yaml_char_t *pointer;1150/** The last filled position of the buffer. */1151yaml_char_t *last;1152} buffer;11531154/* The number of unread characters in the buffer. */1155size_t unread;11561157/** The raw buffer. */1158struct {1159/** The beginning of the buffer. */1160unsigned char *start;1161/** The end of the buffer. */1162unsigned char *end;1163/** The current position of the buffer. */1164unsigned char *pointer;1165/** The last filled position of the buffer. */1166unsigned char *last;1167} raw_buffer;11681169/** The input encoding. */1170yaml_encoding_t encoding;11711172/** The offset of the current position (in bytes). */1173size_t offset;11741175/** The mark of the current position. */1176yaml_mark_t mark;11771178/**1179* @}1180*/11811182/**1183* @name Scanner stuff1184* @{1185*/11861187/** Have we started to scan the input stream? */1188int stream_start_produced;11891190/** Have we reached the end of the input stream? */1191int stream_end_produced;11921193/** The number of unclosed '[' and '{' indicators. */1194int flow_level;11951196/** The tokens queue. */1197struct {1198/** The beginning of the tokens queue. */1199yaml_token_t *start;1200/** The end of the tokens queue. */1201yaml_token_t *end;1202/** The head of the tokens queue. */1203yaml_token_t *head;1204/** The tail of the tokens queue. */1205yaml_token_t *tail;1206} tokens;12071208/** The number of tokens fetched from the queue. */1209size_t tokens_parsed;12101211/** Does the tokens queue contain a token ready for dequeueing. */1212int token_available;12131214/** The indentation levels stack. */1215struct {1216/** The beginning of the stack. */1217int *start;1218/** The end of the stack. */1219int *end;1220/** The top of the stack. */1221int *top;1222} indents;12231224/** The current indentation level. */1225int indent;12261227/** May a simple key occur at the current position? */1228int simple_key_allowed;12291230/** The stack of simple keys. */1231struct {1232/** The beginning of the stack. */1233yaml_simple_key_t *start;1234/** The end of the stack. */1235yaml_simple_key_t *end;1236/** The top of the stack. */1237yaml_simple_key_t *top;1238} simple_keys;12391240/**1241* @}1242*/12431244/**1245* @name Parser stuff1246* @{1247*/12481249/** The parser states stack. */1250struct {1251/** The beginning of the stack. */1252yaml_parser_state_t *start;1253/** The end of the stack. */1254yaml_parser_state_t *end;1255/** The top of the stack. */1256yaml_parser_state_t *top;1257} states;12581259/** The current parser state. */1260yaml_parser_state_t state;12611262/** The stack of marks. */1263struct {1264/** The beginning of the stack. */1265yaml_mark_t *start;1266/** The end of the stack. */1267yaml_mark_t *end;1268/** The top of the stack. */1269yaml_mark_t *top;1270} marks;12711272/** The list of TAG directives. */1273struct {1274/** The beginning of the list. */1275yaml_tag_directive_t *start;1276/** The end of the list. */1277yaml_tag_directive_t *end;1278/** The top of the list. */1279yaml_tag_directive_t *top;1280} tag_directives;12811282/**1283* @}1284*/12851286/**1287* @name Dumper stuff1288* @{1289*/12901291/** The alias data. */1292struct {1293/** The beginning of the list. */1294yaml_alias_data_t *start;1295/** The end of the list. */1296yaml_alias_data_t *end;1297/** The top of the list. */1298yaml_alias_data_t *top;1299} aliases;13001301/** The currently parsed document. */1302yaml_document_t *document;13031304/**1305* @}1306*/13071308} yaml_parser_t;13091310/**1311* Initialize a parser.1312*1313* This function creates a new parser object. An application is responsible1314* for destroying the object using the yaml_parser_delete() function.1315*1316* @param[out] parser An empty parser object.1317*1318* @returns @c 1 if the function succeeded, @c 0 on error.1319*/13201321YAML_DECLARE(int)1322yaml_parser_initialize(yaml_parser_t *parser);13231324/**1325* Destroy a parser.1326*1327* @param[in,out] parser A parser object.1328*/13291330YAML_DECLARE(void)1331yaml_parser_delete(yaml_parser_t *parser);13321333/**1334* Set a string input.1335*1336* Note that the @a input pointer must be valid while the @a parser object1337* exists. The application is responsible for destroing @a input after1338* destroying the @a parser.1339*1340* @param[in,out] parser A parser object.1341* @param[in] input A source data.1342* @param[in] size The length of the source data in bytes.1343*/13441345YAML_DECLARE(void)1346yaml_parser_set_input_string(yaml_parser_t *parser,1347const unsigned char *input, size_t size);13481349/**1350* Set a file input.1351*1352* @a file should be a file object open for reading. The application is1353* responsible for closing the @a file.1354*1355* @param[in,out] parser A parser object.1356* @param[in] file An open file.1357*/13581359YAML_DECLARE(void)1360yaml_parser_set_input_file(yaml_parser_t *parser, FILE *file);13611362/**1363* Set a generic input handler.1364*1365* @param[in,out] parser A parser object.1366* @param[in] handler A read handler.1367* @param[in] data Any application data for passing to the read1368* handler.1369*/13701371YAML_DECLARE(void)1372yaml_parser_set_input(yaml_parser_t *parser,1373yaml_read_handler_t *handler, void *data);13741375/**1376* Set the source encoding.1377*1378* @param[in,out] parser A parser object.1379* @param[in] encoding The source encoding.1380*/13811382YAML_DECLARE(void)1383yaml_parser_set_encoding(yaml_parser_t *parser, yaml_encoding_t encoding);13841385/**1386* Scan the input stream and produce the next token.1387*1388* Call the function subsequently to produce a sequence of tokens corresponding1389* to the input stream. The initial token has the type1390* @c YAML_STREAM_START_TOKEN while the ending token has the type1391* @c YAML_STREAM_END_TOKEN.1392*1393* An application is responsible for freeing any buffers associated with the1394* produced token object using the @c yaml_token_delete function.1395*1396* An application must not alternate the calls of yaml_parser_scan() with the1397* calls of yaml_parser_parse() or yaml_parser_load(). Doing this will break1398* the parser.1399*1400* @param[in,out] parser A parser object.1401* @param[out] token An empty token object.1402*1403* @returns @c 1 if the function succeeded, @c 0 on error.1404*/14051406YAML_DECLARE(int)1407yaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token);14081409/**1410* Parse the input stream and produce the next parsing event.1411*1412* Call the function subsequently to produce a sequence of events corresponding1413* to the input stream. The initial event has the type1414* @c YAML_STREAM_START_EVENT while the ending event has the type1415* @c YAML_STREAM_END_EVENT.1416*1417* An application is responsible for freeing any buffers associated with the1418* produced event object using the yaml_event_delete() function.1419*1420* An application must not alternate the calls of yaml_parser_parse() with the1421* calls of yaml_parser_scan() or yaml_parser_load(). Doing this will break the1422* parser.1423*1424* @param[in,out] parser A parser object.1425* @param[out] event An empty event object.1426*1427* @returns @c 1 if the function succeeded, @c 0 on error.1428*/14291430YAML_DECLARE(int)1431yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event);14321433/**1434* Parse the input stream and produce the next YAML document.1435*1436* Call this function subsequently to produce a sequence of documents1437* constituting the input stream.1438*1439* If the produced document has no root node, it means that the document1440* end has been reached.1441*1442* An application is responsible for freeing any data associated with the1443* produced document object using the yaml_document_delete() function.1444*1445* An application must not alternate the calls of yaml_parser_load() with the1446* calls of yaml_parser_scan() or yaml_parser_parse(). Doing this will break1447* the parser.1448*1449* @param[in,out] parser A parser object.1450* @param[out] document An empty document object.1451*1452* @returns @c 1 if the function succeeded, @c 0 on error.1453*/14541455YAML_DECLARE(int)1456yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document);14571458/** @} */14591460/**1461* @defgroup emitter Emitter Definitions1462* @{1463*/14641465/**1466* The prototype of a write handler.1467*1468* The write handler is called when the emitter needs to flush the accumulated1469* characters to the output. The handler should write @a size bytes of the1470* @a buffer to the output.1471*1472* @param[in,out] data A pointer to an application data specified by1473* yaml_emitter_set_output().1474* @param[in] buffer The buffer with bytes to be written.1475* @param[in] size The size of the buffer.1476*1477* @returns On success, the handler should return @c 1. If the handler failed,1478* the returned value should be @c 0.1479*/14801481typedef int yaml_write_handler_t(void *data, unsigned char *buffer, size_t size);14821483/** The emitter states. */1484typedef enum yaml_emitter_state_e {1485/** Expect STREAM-START. */1486YAML_EMIT_STREAM_START_STATE,1487/** Expect the first DOCUMENT-START or STREAM-END. */1488YAML_EMIT_FIRST_DOCUMENT_START_STATE,1489/** Expect DOCUMENT-START or STREAM-END. */1490YAML_EMIT_DOCUMENT_START_STATE,1491/** Expect the content of a document. */1492YAML_EMIT_DOCUMENT_CONTENT_STATE,1493/** Expect DOCUMENT-END. */1494YAML_EMIT_DOCUMENT_END_STATE,14951496/** Expect the first item of a flow sequence. */1497YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE,1498/** Expect an item of a flow sequence. */1499YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE,1500/** Expect the first key of a flow mapping. */1501YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE,1502/** Expect a key of a flow mapping. */1503YAML_EMIT_FLOW_MAPPING_KEY_STATE,1504/** Expect a value for a simple key of a flow mapping. */1505YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE,15061507/** Expect a value of a flow mapping. */1508YAML_EMIT_FLOW_MAPPING_VALUE_STATE,1509/** Expect the first item of a block sequence. */1510YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE,1511/** Expect an item of a block sequence. */1512YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE,1513/** Expect the first key of a block mapping. */1514YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE,1515/** Expect the key of a block mapping. */1516YAML_EMIT_BLOCK_MAPPING_KEY_STATE,15171518/** Expect a value for a simple key of a block mapping. */1519YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE,1520/** Expect a value of a block mapping. */1521YAML_EMIT_BLOCK_MAPPING_VALUE_STATE,1522/** Expect nothing. */1523YAML_EMIT_END_STATE1524} yaml_emitter_state_t;152515261527/* This is needed for C++ */15281529typedef struct yaml_anchors_s {1530/** The number of references. */1531int references;1532/** The anchor id. */1533int anchor;1534/** If the node has been emitted? */1535int serialized;1536} yaml_anchors_t;15371538/**1539* The emitter structure.1540*1541* All members are internal. Manage the structure using the @c yaml_emitter_1542* family of functions.1543*/15441545typedef struct yaml_emitter_s {15461547/**1548* @name Error handling1549* @{1550*/15511552/** Error type. */1553yaml_error_type_t error;1554/** Error description. */1555const char *problem;15561557/**1558* @}1559*/15601561/**1562* @name Writer stuff1563* @{1564*/15651566/** Write handler. */1567yaml_write_handler_t *write_handler;15681569/** A pointer for passing to the write handler. */1570void *write_handler_data;15711572/** Standard (string or file) output data. */1573union {1574/** String output data. */1575struct {1576/** The buffer pointer. */1577unsigned char *buffer;1578/** The buffer size. */1579size_t size;1580/** The number of written bytes. */1581size_t *size_written;1582} string;15831584/** File output data. */1585FILE *file;1586} output;15871588/** The working buffer. */1589struct {1590/** The beginning of the buffer. */1591yaml_char_t *start;1592/** The end of the buffer. */1593yaml_char_t *end;1594/** The current position of the buffer. */1595yaml_char_t *pointer;1596/** The last filled position of the buffer. */1597yaml_char_t *last;1598} buffer;15991600/** The raw buffer. */1601struct {1602/** The beginning of the buffer. */1603unsigned char *start;1604/** The end of the buffer. */1605unsigned char *end;1606/** The current position of the buffer. */1607unsigned char *pointer;1608/** The last filled position of the buffer. */1609unsigned char *last;1610} raw_buffer;16111612/** The stream encoding. */1613yaml_encoding_t encoding;16141615/**1616* @}1617*/16181619/**1620* @name Emitter stuff1621* @{1622*/16231624/** If the output is in the canonical style? */1625int canonical;1626/** The number of indentation spaces. */1627int best_indent;1628/** The preferred width of the output lines. */1629int best_width;1630/** Allow unescaped non-ASCII characters? */1631int unicode;1632/** The preferred line break. */1633yaml_break_t line_break;16341635/** The stack of states. */1636struct {1637/** The beginning of the stack. */1638yaml_emitter_state_t *start;1639/** The end of the stack. */1640yaml_emitter_state_t *end;1641/** The top of the stack. */1642yaml_emitter_state_t *top;1643} states;16441645/** The current emitter state. */1646yaml_emitter_state_t state;16471648/** The event queue. */1649struct {1650/** The beginning of the event queue. */1651yaml_event_t *start;1652/** The end of the event queue. */1653yaml_event_t *end;1654/** The head of the event queue. */1655yaml_event_t *head;1656/** The tail of the event queue. */1657yaml_event_t *tail;1658} events;16591660/** The stack of indentation levels. */1661struct {1662/** The beginning of the stack. */1663int *start;1664/** The end of the stack. */1665int *end;1666/** The top of the stack. */1667int *top;1668} indents;16691670/** The list of tag directives. */1671struct {1672/** The beginning of the list. */1673yaml_tag_directive_t *start;1674/** The end of the list. */1675yaml_tag_directive_t *end;1676/** The top of the list. */1677yaml_tag_directive_t *top;1678} tag_directives;16791680/** The current indentation level. */1681int indent;16821683/** The current flow level. */1684int flow_level;16851686/** Is it the document root context? */1687int root_context;1688/** Is it a sequence context? */1689int sequence_context;1690/** Is it a mapping context? */1691int mapping_context;1692/** Is it a simple mapping key context? */1693int simple_key_context;16941695/** The current line. */1696int line;1697/** The current column. */1698int column;1699/** If the last character was a whitespace? */1700int whitespace;1701/** If the last character was an indentation character (' ', '-', '?', ':')? */1702int indention;1703/** If an explicit document end is required? */1704int open_ended;17051706/** Anchor analysis. */1707struct {1708/** The anchor value. */1709yaml_char_t *anchor;1710/** The anchor length. */1711size_t anchor_length;1712/** Is it an alias? */1713int alias;1714} anchor_data;17151716/** Tag analysis. */1717struct {1718/** The tag handle. */1719yaml_char_t *handle;1720/** The tag handle length. */1721size_t handle_length;1722/** The tag suffix. */1723yaml_char_t *suffix;1724/** The tag suffix length. */1725size_t suffix_length;1726} tag_data;17271728/** Scalar analysis. */1729struct {1730/** The scalar value. */1731yaml_char_t *value;1732/** The scalar length. */1733size_t length;1734/** Does the scalar contain line breaks? */1735int multiline;1736/** Can the scalar be expessed in the flow plain style? */1737int flow_plain_allowed;1738/** Can the scalar be expressed in the block plain style? */1739int block_plain_allowed;1740/** Can the scalar be expressed in the single quoted style? */1741int single_quoted_allowed;1742/** Can the scalar be expressed in the literal or folded styles? */1743int block_allowed;1744/** The output style. */1745yaml_scalar_style_t style;1746} scalar_data;17471748/**1749* @}1750*/17511752/**1753* @name Dumper stuff1754* @{1755*/17561757/** If the stream was already opened? */1758int opened;1759/** If the stream was already closed? */1760int closed;17611762/** The information associated with the document nodes. */1763yaml_anchors_t *anchors;17641765/** The last assigned anchor id. */1766int last_anchor_id;17671768/** The currently emitted document. */1769yaml_document_t *document;17701771/**1772* @}1773*/17741775} yaml_emitter_t;17761777/**1778* Initialize an emitter.1779*1780* This function creates a new emitter object. An application is responsible1781* for destroying the object using the yaml_emitter_delete() function.1782*1783* @param[out] emitter An empty parser object.1784*1785* @returns @c 1 if the function succeeded, @c 0 on error.1786*/17871788YAML_DECLARE(int)1789yaml_emitter_initialize(yaml_emitter_t *emitter);17901791/**1792* Destroy an emitter.1793*1794* @param[in,out] emitter An emitter object.1795*/17961797YAML_DECLARE(void)1798yaml_emitter_delete(yaml_emitter_t *emitter);17991800/**1801* Set a string output.1802*1803* The emitter will write the output characters to the @a output buffer of the1804* size @a size. The emitter will set @a size_written to the number of written1805* bytes. If the buffer is smaller than required, the emitter produces the1806* YAML_WRITE_ERROR error.1807*1808* @param[in,out] emitter An emitter object.1809* @param[in] output An output buffer.1810* @param[in] size The buffer size.1811* @param[in] size_written The pointer to save the number of written1812* bytes.1813*/18141815YAML_DECLARE(void)1816yaml_emitter_set_output_string(yaml_emitter_t *emitter,1817unsigned char *output, size_t size, size_t *size_written);18181819/**1820* Set a file output.1821*1822* @a file should be a file object open for writing. The application is1823* responsible for closing the @a file.1824*1825* @param[in,out] emitter An emitter object.1826* @param[in] file An open file.1827*/18281829YAML_DECLARE(void)1830yaml_emitter_set_output_file(yaml_emitter_t *emitter, FILE *file);18311832/**1833* Set a generic output handler.1834*1835* @param[in,out] emitter An emitter object.1836* @param[in] handler A write handler.1837* @param[in] data Any application data for passing to the write1838* handler.1839*/18401841YAML_DECLARE(void)1842yaml_emitter_set_output(yaml_emitter_t *emitter,1843yaml_write_handler_t *handler, void *data);18441845/**1846* Set the output encoding.1847*1848* @param[in,out] emitter An emitter object.1849* @param[in] encoding The output encoding.1850*/18511852YAML_DECLARE(void)1853yaml_emitter_set_encoding(yaml_emitter_t *emitter, yaml_encoding_t encoding);18541855/**1856* Set if the output should be in the "canonical" format as in the YAML1857* specification.1858*1859* @param[in,out] emitter An emitter object.1860* @param[in] canonical If the output is canonical.1861*/18621863YAML_DECLARE(void)1864yaml_emitter_set_canonical(yaml_emitter_t *emitter, int canonical);18651866/**1867* Set the indentation increment.1868*1869* @param[in,out] emitter An emitter object.1870* @param[in] indent The indentation increment (1 < . < 10).1871*/18721873YAML_DECLARE(void)1874yaml_emitter_set_indent(yaml_emitter_t *emitter, int indent);18751876/**1877* Set the preferred line width. @c -1 means unlimited.1878*1879* @param[in,out] emitter An emitter object.1880* @param[in] width The preferred line width.1881*/18821883YAML_DECLARE(void)1884yaml_emitter_set_width(yaml_emitter_t *emitter, int width);18851886/**1887* Set if unescaped non-ASCII characters are allowed.1888*1889* @param[in,out] emitter An emitter object.1890* @param[in] unicode If unescaped Unicode characters are allowed.1891*/18921893YAML_DECLARE(void)1894yaml_emitter_set_unicode(yaml_emitter_t *emitter, int unicode);18951896/**1897* Set the preferred line break.1898*1899* @param[in,out] emitter An emitter object.1900* @param[in] line_break The preferred line break.1901*/19021903YAML_DECLARE(void)1904yaml_emitter_set_break(yaml_emitter_t *emitter, yaml_break_t line_break);19051906/**1907* Emit an event.1908*1909* The event object may be generated using the yaml_parser_parse() function.1910* The emitter takes the responsibility for the event object and destroys its1911* content after it is emitted. The event object is destroyed even if the1912* function fails.1913*1914* @param[in,out] emitter An emitter object.1915* @param[in,out] event An event object.1916*1917* @returns @c 1 if the function succeeded, @c 0 on error.1918*/19191920YAML_DECLARE(int)1921yaml_emitter_emit(yaml_emitter_t *emitter, yaml_event_t *event);19221923/**1924* Start a YAML stream.1925*1926* This function should be used before yaml_emitter_dump() is called.1927*1928* @param[in,out] emitter An emitter object.1929*1930* @returns @c 1 if the function succeeded, @c 0 on error.1931*/19321933YAML_DECLARE(int)1934yaml_emitter_open(yaml_emitter_t *emitter);19351936/**1937* Finish a YAML stream.1938*1939* This function should be used after yaml_emitter_dump() is called.1940*1941* @param[in,out] emitter An emitter object.1942*1943* @returns @c 1 if the function succeeded, @c 0 on error.1944*/19451946YAML_DECLARE(int)1947yaml_emitter_close(yaml_emitter_t *emitter);19481949/**1950* Emit a YAML document.1951*1952* The documen object may be generated using the yaml_parser_load() function1953* or the yaml_document_initialize() function. The emitter takes the1954* responsibility for the document object and destroys its content after1955* it is emitted. The document object is destroyed even if the function fails.1956*1957* @param[in,out] emitter An emitter object.1958* @param[in,out] document A document object.1959*1960* @returns @c 1 if the function succeeded, @c 0 on error.1961*/19621963YAML_DECLARE(int)1964yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document);19651966/**1967* Flush the accumulated characters to the output.1968*1969* @param[in,out] emitter An emitter object.1970*1971* @returns @c 1 if the function succeeded, @c 0 on error.1972*/19731974YAML_DECLARE(int)1975yaml_emitter_flush(yaml_emitter_t *emitter);19761977/** @} */19781979#ifdef __cplusplus1980}1981#endif19821983#endif /* #ifndef YAML_H */1984198519861987