summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKirill Simonov <xi@resolvent.net>2006-05-27 17:19:07 +0000
committerKirill Simonov <xi@resolvent.net>2006-05-27 17:19:07 +0000
commit95b98ba9b588df2f28b0a0acca11a1133fb266f0 (patch)
tree57b669d90579bb58e5b88c21596e45b0f0283c35 /include
parenta51447c932b63bcf7cc0226dafd621c6cd8a347a (diff)
downloadlibyaml-git-95b98ba9b588df2f28b0a0acca11a1133fb266f0.tar.gz
Implementing Reader: first tries.
Diffstat (limited to 'include')
-rw-r--r--include/yaml/yaml.h161
1 files changed, 145 insertions, 16 deletions
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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
/**
* @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.
@@ -273,15 +275,26 @@ 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