Source

libyaml / include / yaml / yaml.h

Diff from to

File include/yaml/yaml.h

 #endif
 
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 /**
  * @defgroup version Version Information
     YAML_UTF16BE_ENCODING
 } yaml_encoding_t;
 
-/** @} */
-
-/*
-
+/** Many bad things could happen with the parser and emitter. */
 typedef enum {
     YAML_NO_ERROR,
 
     YAML_EMITTER_ERROR
 } yaml_error_type_t;
 
+/** @} */
+
+/*
+
 typedef enum {
     YAML_ANY_SCALAR_STYLE,
     YAML_PLAIN_SCALAR_STYLE,
  * 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.
 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;
     /** 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;
+
     /**
      * @}
      */
 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);
+
 /** @} */
 
 /*
 } 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