diff options
author | bapt <bapt@FreeBSD.org> | 2014-07-18 06:58:01 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2014-07-18 06:58:01 +0000 |
commit | 2c479407e0afce2c05606d6d9c052858196fcea2 (patch) | |
tree | 96497f945ddb4dfe861d3b28b15907997f8d7e30 /contrib/libucl/include/ucl.h | |
parent | d8612e9432a6a6bdeb374817db86445640e36cd4 (diff) | |
parent | f900132171b58516e797b158ec4ae0f93501bed4 (diff) | |
download | FreeBSD-src-2c479407e0afce2c05606d6d9c052858196fcea2.zip FreeBSD-src-2c479407e0afce2c05606d6d9c052858196fcea2.tar.gz |
Update libucl to the 2014-07-16 snapshot
This update brings streamlined ucl emitter support
Diffstat (limited to 'contrib/libucl/include/ucl.h')
-rw-r--r-- | contrib/libucl/include/ucl.h | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/contrib/libucl/include/ucl.h b/contrib/libucl/include/ucl.h index 3eeea9a..b40f113 100644 --- a/contrib/libucl/include/ucl.h +++ b/contrib/libucl/include/ucl.h @@ -786,6 +786,7 @@ UCL_EXTERN bool ucl_parser_set_filevars (struct ucl_parser *parser, const char * * @{ */ +struct ucl_emitter_context; /** * Structure using for emitter callbacks */ @@ -798,10 +799,49 @@ struct ucl_emitter_functions { int (*ucl_emitter_append_int) (int64_t elt, void *ud); /** Append floating point element */ int (*ucl_emitter_append_double) (double elt, void *ud); + /** Free userdata */ + void (*ucl_emitter_free_func)(void *ud); /** Opaque userdata pointer */ void *ud; }; +struct ucl_emitter_operations { + /** Write a primitive element */ + void (*ucl_emitter_write_elt) (struct ucl_emitter_context *ctx, + const ucl_object_t *obj, bool first, bool print_key); + /** Start ucl object */ + void (*ucl_emitter_start_object) (struct ucl_emitter_context *ctx, + const ucl_object_t *obj, bool print_key); + /** End ucl object */ + void (*ucl_emitter_end_object) (struct ucl_emitter_context *ctx, + const ucl_object_t *obj); + /** Start ucl array */ + void (*ucl_emitter_start_array) (struct ucl_emitter_context *ctx, + const ucl_object_t *obj, bool print_key); + void (*ucl_emitter_end_array) (struct ucl_emitter_context *ctx, + const ucl_object_t *obj); +}; + +/** + * Structure that defines emitter functions + */ +struct ucl_emitter_context { + /** Name of emitter (e.g. json, compact_json) */ + const char *name; + /** Unique id (e.g. UCL_EMIT_JSON for standard emitters */ + int id; + /** A set of output functions */ + const struct ucl_emitter_functions *func; + /** A set of output operations */ + const struct ucl_emitter_operations *ops; + /** Current amount of indent tabs */ + unsigned int ident; + /** Top level object */ + const ucl_object_t *top; + /** The rest of context */ + unsigned char data[1]; +}; + /** * Emit object to a string * @param obj object @@ -817,11 +857,81 @@ UCL_EXTERN unsigned char *ucl_object_emit (const ucl_object_t *obj, * @param obj object * @param emit_type if type is #UCL_EMIT_JSON then emit json, if type is * #UCL_EMIT_CONFIG then emit config like object + * @param emitter a set of emitter functions * @return dump of an object (must be freed after using) or NULL in case of error */ UCL_EXTERN bool ucl_object_emit_full (const ucl_object_t *obj, enum ucl_emitter emit_type, struct ucl_emitter_functions *emitter); + +/** + * Start streamlined UCL object emitter + * @param obj top UCL object + * @param emit_type emit type + * @param emitter a set of emitter functions + * @return new streamlined context that should be freed by + * `ucl_object_emit_streamline_finish` + */ +UCL_EXTERN struct ucl_emitter_context* ucl_object_emit_streamline_new ( + const ucl_object_t *obj, enum ucl_emitter emit_type, + struct ucl_emitter_functions *emitter); + +/** + * Start object or array container for the streamlined output + * @param ctx streamlined context + * @param obj container object + */ +UCL_EXTERN void ucl_object_emit_streamline_start_container ( + struct ucl_emitter_context *ctx, const ucl_object_t *obj); +/** + * Add a complete UCL object to streamlined output + * @param ctx streamlined context + * @param obj object to output + */ +UCL_EXTERN void ucl_object_emit_streamline_add_object ( + struct ucl_emitter_context *ctx, const ucl_object_t *obj); +/** + * End previously added container + * @param ctx streamlined context + */ +UCL_EXTERN void ucl_object_emit_streamline_end_container ( + struct ucl_emitter_context *ctx); +/** + * Terminate streamlined container finishing all containers in it + * @param ctx streamlined context + */ +UCL_EXTERN void ucl_object_emit_streamline_finish ( + struct ucl_emitter_context *ctx); + +/** + * Returns functions to emit object to memory + * @param pmem target pointer (should be freed by caller) + * @return emitter functions structure + */ +UCL_EXTERN struct ucl_emitter_functions* ucl_object_emit_memory_funcs ( + void **pmem); + +/** + * Returns functions to emit object to FILE * + * @param fp FILE * object + * @return emitter functions structure + */ +UCL_EXTERN struct ucl_emitter_functions* ucl_object_emit_file_funcs ( + FILE *fp); +/** + * Returns functions to emit object to a file descriptor + * @param fd file descriptor + * @return emitter functions structure + */ +UCL_EXTERN struct ucl_emitter_functions* ucl_object_emit_fd_funcs ( + int fd); + +/** + * Free emitter functions + * @param f pointer to functions + */ +UCL_EXTERN void ucl_object_emit_funcs_free (struct ucl_emitter_functions *f); + /** @} */ /** |