From 95b98ba9b588df2f28b0a0acca11a1133fb266f0 Mon Sep 17 00:00:00 2001 From: Kirill Simonov Date: Sat, 27 May 2006 17:19:07 +0000 Subject: Implementing Reader: first tries. --- include/yaml/yaml.h | 161 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 145 insertions(+), 16 deletions(-) (limited to 'include') diff --git a/include/yaml/yaml.h b/include/yaml/yaml.h index 40cd9af..c4bd0ba 100644 --- a/include/yaml/yaml.h +++ b/include/yaml/yaml.h @@ -16,6 +16,8 @@ extern "C" { #endif #include +#include +#include /** * @defgroup version Version Information @@ -62,10 +64,7 @@ typedef enum { YAML_UTF16BE_ENCODING } yaml_encoding_t; -/** @} */ - -/* - +/** Many bad things could happen with the parser and emitter. */ typedef enum { YAML_NO_ERROR, @@ -79,6 +78,10 @@ typedef enum { YAML_EMITTER_ERROR } yaml_error_type_t; +/** @} */ + +/* + typedef enum { YAML_ANY_SCALAR_STYLE, YAML_PLAIN_SCALAR_STYLE, @@ -249,19 +252,18 @@ typedef struct { * source. The handler should write not more than @a size bytes to the @a * buffer. The number of written bytes should be set to the @a length variable. * - * @param[in] ext A pointer to an application data specified by - * @c yaml_parser_set_read_handler. - * @param[out] buffer The buffer to write the data from the source. - * @param[in] size The size of the buffer. - * @param[out] length The actual number of bytes read from the source. + * @param[in] ext A pointer to an application data specified by + * @c yaml_parser_set_read_handler. + * @param[out] buffer The buffer to write the data from the source. + * @param[in] size The size of the buffer. + * @param[out] size_read The actual number of bytes read from the source. * * @returns On success, the handler should return @c 1. If the handler failed, * the returned value should be @c 0. On EOF, the handler should set the * @a length to @c 0 and return @c 1. */ -typedef int yaml_read_handler_t(void *ext, yaml_char_t *buffer, size_t size, - size_t *length); - +typedef int yaml_read_handler_t(void *ext, unsigned char *buffer, size_t size, + size_t *size_read); /** * The parser structure. @@ -272,16 +274,27 @@ typedef int yaml_read_handler_t(void *ext, yaml_char_t *buffer, size_t size, typedef struct { + /** + * @name Error handling + * @{ + */ + + error_type_t error; + + /** + * @} + */ + /** * @name Reader stuff * @{ */ /** Read handler */ - yaml_read_handler_t *reader; + yaml_read_handler_t *read_handler; /** A pointer for passing to the read handler. */ - void *reader_ext; + void *read_handler_data; /** EOF flag */ int eof; @@ -289,18 +302,39 @@ typedef struct { /** The pointer to the beginning of the working buffer. */ yaml_char_t *buffer; + /** The size of the buffer (in bytes). */ + size_t buffer_size; + /** The pointer to the current character in the working buffer. */ - yaml_char_t *pointer; + yaml_char_t *buffer_pointer; + + /** The number of unread characters in the buffer (in characters). */ + size_t buffer_length; /** The remaining undecoded characters. */ unsigned char *raw_buffer; - /** The size of the raw buffer. */ + /** The size of the raw buffer (in bytes). */ size_t raw_buffer_size; + /** Is the application responsible for freeing the raw buffer? */ + int raw_buffer_foreign; + /** The input encoding. */ yaml_encoding_t encoding; + /** The offset of the current position (in bytes). */ + size_t offset; + + /** The index of the current position (in characters). */ + size_t index; + + /** The line of the current position (starting from @c 0). */ + size_t line; + + /** The column of the current position (starting from @c 0). */ + size_t column; + /** * @} */ @@ -328,6 +362,57 @@ yaml_parser_new(void); void yaml_parser_delete(yaml_parser_t *parser); +/** + * Set a string input. + * + * Note that the @a input pointer must be valid while the @a parser object + * exists. The application is responsible for destroing @a input after + * destroying the @a parser. + * + * @param[in] parser A parser object. + * @param[in] input A source data. + * @param[in] length The length of the source data in bytes. + */ + +void +yaml_parser_set_input_string(yaml_parser_t *parser, + unsigned char *input, size_t size); + + +/** + * Set a file input. + * + * @a file should be a file object open for reading. The application is + * responsible for closing the @a file. + * + * @param[in] parser A parser object. + * @param[in] file An open file. + */ + +void +yaml_parser_set_input_file(yaml_parser_t *parser, FILE *file); + +/** + * Set a generic input handler. + * + * @param[in] parser A parser object. + * @param[in] handler A read handler. + * @param[in] data Any application data for passing to the read handler. + */ + +void +yaml_parser_set_input(yaml_parser_t *parser, + yaml_read_handler_t *handler, void *data); + +/** + * Set the source encoding. + * + * @param[in] encoding The source encoding. + */ + +void +yaml_parser_set_encoding(yaml_parser_t *parser, yaml_encoding_t encoding); + /** @} */ /* @@ -335,6 +420,50 @@ typedef struct { } yaml_emitter_t; */ +/** + * @defgroup internal Internal Definitions + * @{ + */ + +/** + * Allocate a dynamic memory block. + * + * @param[in] size Size of a memory block, \c 0 is valid. + * + * @returns @c yaml_malloc returns a pointer to a newly allocated memory block, + * or @c NULL if it failed. + */ + +void * +yaml_malloc(size_t size); + +/** + * Reallocate a dynamic memory block. + * + * @param[in] ptr A pointer to an existing memory block, \c NULL is + * valid. + * @param[in] size A size of a new block, \c 0 is valid. + * + * @returns @c yaml_realloc returns a pointer to a reallocated memory block, + * or @c NULL if it failed. + */ + +void * +yaml_realloc(void *ptr, size_t size); + +/** + * Free a dynamic memory block. + * + * @param[in] ptr A pointer to an existing memory block, \c NULL is + * valid. + */ + +void +yaml_free(void *ptr); + +/** @} */ + + #ifdef __cplusplus } #endif -- cgit v1.2.1