summaryrefslogtreecommitdiffstats
path: root/contrib/libucl/ucl_emitter.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-08 18:26:58 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-08 18:26:58 +0000
commitff660e595fb04857e73e1f84d1e13d412fb980ef (patch)
tree89311f8e1131729d6216537c282925166408dd47 /contrib/libucl/ucl_emitter.c
parent40d4ca29664da075d9078161814b01070b6c0058 (diff)
downloadrspamd-ff660e595fb04857e73e1f84d1e13d412fb980ef.tar.gz
rspamd-ff660e595fb04857e73e1f84d1e13d412fb980ef.zip
Update libucl
Diffstat (limited to 'contrib/libucl/ucl_emitter.c')
-rw-r--r--contrib/libucl/ucl_emitter.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/contrib/libucl/ucl_emitter.c b/contrib/libucl/ucl_emitter.c
index 8bfbf09b8..84108e21d 100644
--- a/contrib/libucl/ucl_emitter.c
+++ b/contrib/libucl/ucl_emitter.c
@@ -362,6 +362,7 @@ ucl_emitter_common_elt (struct ucl_emitter_context *ctx,
const struct ucl_emitter_functions *func = ctx->func;
bool flag;
struct ucl_object_userdata *ud;
+ const ucl_object_t *comment = NULL, *cur_comment;
const char *ud_out = "";
if (ctx->id != UCL_EMIT_CONFIG && !first) {
@@ -379,6 +380,25 @@ ucl_emitter_common_elt (struct ucl_emitter_context *ctx,
ucl_add_tabs (func, ctx->indent, compact);
+ if (ctx->comments && ctx->id == UCL_EMIT_CONFIG) {
+ comment = ucl_object_find_keyl (ctx->comments, (const char *)&obj,
+ sizeof (void *));
+
+ if (comment) {
+ if (!(comment->flags & UCL_OBJECT_INHERITED)) {
+ DL_FOREACH (comment, cur_comment) {
+ func->ucl_emitter_append_len (cur_comment->value.sv,
+ cur_comment->len,
+ func->ud);
+ func->ucl_emitter_append_character ('\n', 1, func->ud);
+ ucl_add_tabs (func, ctx->indent, compact);
+ }
+
+ comment = NULL;
+ }
+ }
+ }
+
switch (obj->type) {
case UCL_INT:
ucl_emitter_print_key (print_key, ctx, obj, compact);
@@ -438,6 +458,19 @@ ucl_emitter_common_elt (struct ucl_emitter_context *ctx,
ucl_emitter_finish_object (ctx, obj, compact, !print_key);
break;
}
+
+ if (comment) {
+ DL_FOREACH (comment, cur_comment) {
+ func->ucl_emitter_append_len (cur_comment->value.sv,
+ cur_comment->len,
+ func->ud);
+ func->ucl_emitter_append_character ('\n', 1, func->ud);
+
+ if (cur_comment->next) {
+ ucl_add_tabs (func, ctx->indent, compact);
+ }
+ }
+ }
}
/*
@@ -605,10 +638,10 @@ ucl_object_emit_len (const ucl_object_t *obj, enum ucl_emitter emit_type,
}
func = ucl_object_emit_memory_funcs ((void **)&res);
- s = func->ud;
if (func != NULL) {
- ucl_object_emit_full (obj, emit_type, func);
+ s = func->ud;
+ ucl_object_emit_full (obj, emit_type, func, NULL);
if (outlen != NULL) {
*outlen = s->i;
@@ -622,7 +655,8 @@ ucl_object_emit_len (const ucl_object_t *obj, enum ucl_emitter emit_type,
bool
ucl_object_emit_full (const ucl_object_t *obj, enum ucl_emitter emit_type,
- struct ucl_emitter_functions *emitter)
+ struct ucl_emitter_functions *emitter,
+ const ucl_object_t *comments)
{
const struct ucl_emitter_context *ctx;
struct ucl_emitter_context my_ctx;
@@ -634,6 +668,7 @@ ucl_object_emit_full (const ucl_object_t *obj, enum ucl_emitter emit_type,
my_ctx.func = emitter;
my_ctx.indent = 0;
my_ctx.top = obj;
+ my_ctx.comments = comments;
my_ctx.ops->ucl_emitter_write_elt (&my_ctx, obj, true, false);
res = true;