2 #include "yaml_private.h"
9 yaml_emitter_emit(yaml_emitter_t *emitter, yaml_event_t *event);
12 yaml_emitter_emit_stream_start(yaml_emitter_t *emitter,
13 yaml_encoding_t encoding);
16 yaml_emitter_emit_stream_end(yaml_emitter_t *emitter);
19 yaml_emitter_emit_document_start(yaml_emitter_t *emitter,
20 yaml_version_directive_t *version_directive,
21 yaml_tag_directive_t *tag_directives_start,
22 yaml_tag_directive_t *tag_directives_end,
26 yaml_emitter_emit_document_end(yaml_emitter_t *emitter, int implicit);
29 yaml_emitter_emit_alias(yaml_emitter_t *emitter, yaml_char_t *anchor);
32 yaml_emitter_emit_scalar(yaml_emitter_t *emitter,
33 yaml_char_t *anchor, yaml_char_t *tag,
34 yaml_char_t *value, size_t length,
35 int plain_implicit, int quoted_implicit,
36 yaml_scalar_style_t style);
39 yaml_emitter_emit_sequence_start(yaml_emitter_t *emitter,
40 yaml_char_t *anchor, yaml_char_t *tag, int implicit,
41 yaml_sequence_style_t style);
44 yaml_emitter_emit_sequence_end(yaml_emitter_t *emitter);
47 yaml_emitter_emit_mapping_start(yaml_emitter_t *emitter,
48 yaml_char_t *anchor, yaml_char_t *tag, int implicit,
49 yaml_mapping_style_t style);
52 yaml_emitter_emit_mapping_end(yaml_emitter_t *emitter);
59 yaml_emitter_emit_stream_start(yaml_emitter_t *emitter,
60 yaml_encoding_t encoding)
63 yaml_mark_t mark = { 0, 0, 0 };
65 assert(emitter); /* Non-NULL emitter object is expected. */
67 STREAM_START_EVENT_INIT(event, encoding, mark, mark);
69 return yaml_emitter_emit(emitter, &event);
77 yaml_emitter_emit_stream_end(yaml_emitter_t *emitter)
80 yaml_mark_t mark = { 0, 0, 0 };
82 assert(emitter); /* Non-NULL emitter object is expected. */
84 STREAM_END_EVENT_INIT(event, mark, mark);
86 return yaml_emitter_emit(emitter, &event);
90 * Emit DOCUMENT-START.
94 yaml_emitter_emit_document_start(yaml_emitter_t *emitter,
95 yaml_version_directive_t *version_directive,
96 yaml_tag_directive_t *tag_directives_start,
97 yaml_tag_directive_t *tag_directives_end,
101 yaml_mark_t mark = { 0, 0, 0 };
102 yaml_version_directive_t *version_directive_copy = NULL;
104 yaml_tag_directive_t *start;
105 yaml_tag_directive_t *end;
106 yaml_tag_directive_t *top;
107 } tag_directives_copy = { NULL, NULL, NULL };
108 yaml_tag_directive_t value = { NULL, NULL };
110 assert(emitter); /* Non-NULL emitter object is expected. */
111 assert((tag_directives_start && tag_directives_end) ||
112 (tag_directives_start == tag_directives_end));
113 /* Valid tag directives are expected. */
115 if (version_directive) {
116 version_directive_copy = yaml_malloc(sizeof(yaml_version_directive_t));
117 if (!version_directive_copy) {
118 emitter->error = YAML_MEMORY_ERROR;
121 version_directive_copy->major = version_directive->major;
122 version_directive_copy->minor = version_directive->minor;
125 if (tag_directives_start != tag_directives_end) {
126 yaml_tag_directive_t *tag_directive;
127 if (!STACK_INIT(emitter, tag_directives_copy, INITIAL_STACK_SIZE))
129 for (tag_directive = tag_directives_start;
130 tag_directive != tag_directives_end; tag_directive ++) {
131 value.handle = yaml_strdup(tag_directive->handle);
132 value.prefix = yaml_strdup(tag_directive->prefix);
133 if (!value.handle || !value.prefix) {
134 emitter->error = YAML_MEMORY_ERROR;
137 if (!PUSH(emitter, tag_directives_copy, value))
144 DOCUMENT_START_EVENT_INIT(event, version_directive_copy,
145 tag_directives_copy.start, tag_directives_copy.end,
146 implicit, mark, mark);
148 if (yaml_emitter_emit(emitter, &event)) {
153 yaml_free(version_directive_copy);
154 while (!STACK_EMPTY(emitter, tag_directives_copy)) {
155 yaml_tag_directive_t value = POP(emitter, tag_directives_copy);
156 yaml_free(value.handle);
157 yaml_free(value.prefix);
159 STACK_DEL(emitter, tag_directives_copy);
160 yaml_free(value.handle);
161 yaml_free(value.prefix);
171 yaml_emitter_emit_document_end(yaml_emitter_t *emitter, int implicit)
174 yaml_mark_t mark = { 0, 0, 0 };
176 assert(emitter); /* Non-NULL emitter object is expected. */
178 DOCUMENT_END_EVENT_INIT(event, implicit, mark, mark);
180 return yaml_emitter_emit(emitter, &event);
188 yaml_emitter_emit_alias(yaml_emitter_t *emitter, yaml_char_t *anchor)
191 yaml_mark_t mark = { 0, 0, 0 };
192 yaml_char_t *anchor_copy = NULL;
194 assert(emitter); /* Non-NULL emitter object is expected. */
195 assert(anchor); /* Non-NULL anchor is expected. */
197 anchor_copy = yaml_strdup(anchor);
199 emitter->error = YAML_MEMORY_ERROR;
203 ALIAS_EVENT_INIT(event, anchor_copy, mark, mark);
205 if (yaml_emitter_emit(emitter, &event)) {
209 yaml_free(anchor_copy);
219 yaml_emitter_emit_scalar(yaml_emitter_t *emitter,
220 yaml_char_t *anchor, yaml_char_t *tag,
221 yaml_char_t *value, size_t length,
222 int plain_implicit, int quoted_implicit,
223 yaml_scalar_style_t style)
226 yaml_mark_t mark = { 0, 0, 0 };
227 yaml_char_t *anchor_copy = NULL;
228 yaml_char_t *tag_copy = NULL;
229 yaml_char_t *value_copy = NULL;
231 assert(emitter); /* Non-NULL emitter object is expected. */
232 assert(value); /* Non-NULL anchor is expected. */
235 anchor_copy = yaml_strdup(anchor);
237 emitter->error = YAML_MEMORY_ERROR;
243 tag_copy = yaml_strdup(tag);
245 emitter->error = YAML_MEMORY_ERROR;
250 value_copy = yaml_malloc(length+1);
252 emitter->error = YAML_MEMORY_ERROR;
255 memcpy(value_copy, value, length);
256 value_copy[length] = '\0';
258 SCALAR_EVENT_INIT(event, anchor_copy, tag_copy, value_copy, length,
259 plain_implicit, quoted_implicit, style, mark, mark);
261 if (yaml_emitter_emit(emitter, &event)) {
266 yaml_free(anchor_copy);
268 yaml_free(value_copy);
274 * Emit SEQUENCE-START.
278 yaml_emitter_emit_sequence_start(yaml_emitter_t *emitter,
279 yaml_char_t *anchor, yaml_char_t *tag, int implicit,
280 yaml_sequence_style_t style)
283 yaml_mark_t mark = { 0, 0, 0 };
284 yaml_char_t *anchor_copy = NULL;
285 yaml_char_t *tag_copy = NULL;
287 assert(emitter); /* Non-NULL emitter object is expected. */
290 anchor_copy = yaml_strdup(anchor);
292 emitter->error = YAML_MEMORY_ERROR;
298 tag_copy = yaml_strdup(tag);
300 emitter->error = YAML_MEMORY_ERROR;
305 SEQUENCE_START_EVENT_INIT(event, anchor_copy, tag_copy,
306 implicit, style, mark, mark);
308 if (yaml_emitter_emit(emitter, &event)) {
313 yaml_free(anchor_copy);
324 yaml_emitter_emit_sequence_end(yaml_emitter_t *emitter)
327 yaml_mark_t mark = { 0, 0, 0 };
329 assert(emitter); /* Non-NULL emitter object is expected. */
331 SEQUENCE_END_EVENT_INIT(event, mark, mark);
333 return yaml_emitter_emit(emitter, &event);
337 * Emit MAPPING-START.
341 yaml_emitter_emit_mapping_start(yaml_emitter_t *emitter,
342 yaml_char_t *anchor, yaml_char_t *tag, int implicit,
343 yaml_mapping_style_t style)
346 yaml_mark_t mark = { 0, 0, 0 };
347 yaml_char_t *anchor_copy = NULL;
348 yaml_char_t *tag_copy = NULL;
350 assert(emitter); /* Non-NULL emitter object is expected. */
353 anchor_copy = yaml_strdup(anchor);
355 emitter->error = YAML_MEMORY_ERROR;
361 tag_copy = yaml_strdup(tag);
363 emitter->error = YAML_MEMORY_ERROR;
368 MAPPING_START_EVENT_INIT(event, anchor_copy, tag_copy,
369 implicit, style, mark, mark);
371 if (yaml_emitter_emit(emitter, &event)) {
376 yaml_free(anchor_copy);
387 yaml_emitter_emit_mapping_end(yaml_emitter_t *emitter)
390 yaml_mark_t mark = { 0, 0, 0 };
392 assert(emitter); /* Non-NULL emitter object is expected. */
394 MAPPING_END_EVENT_INIT(event, mark, mark);
396 return yaml_emitter_emit(emitter, &event);
404 yaml_emitter_emit(yaml_emitter_t *emitter, yaml_event_t *event)