api.c

filter: Statementstmt 48.7% 319 / 655 Branchbran 30.1% 146 / 484 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 40.8% 465 / 1139 SCAR 0
CC
0
Cov
0%
CRAP 0
« scanner.c ↑ Summary emitter.c »
1  
2 #include "yaml_private.h"
3  
4 /*
5 * Get the library version.
6 */
7  
8 YAML_DECLARE(const char *)
9 1 yaml_get_version_string(void)
10 {
11 1 return YAML_VERSION_STRING;
12 }
13  
14 /*
15 * Get the library version numbers.
16 */
17  
18 YAML_DECLARE(void)
19 0 yaml_get_version(int *major, int *minor, int *patch)
20 {
21 0 *major = YAML_VERSION_MAJOR;
22 0 *minor = YAML_VERSION_MINOR;
23 0 *patch = YAML_VERSION_PATCH;
24 0 }
25  
26 /*
27 * Allocate a dynamic memory block.
28 */
29  
30 YAML_DECLARE(void *)
31 3459 yaml_malloc(size_t size)
32 {
33 3459 ▶ return malloc(size ? size : 1);
Branch: 1 branch
BranchTrueFalseTotal
return malloc(size ? size : 1); 3459 0 3459
34 }
35  
36 /*
37 * Reallocate a dynamic memory block.
38 */
39  
40 YAML_DECLARE(void *)
41 66 yaml_realloc(void *ptr, size_t size)
42 {
43 66 ▶ return ptr ? realloc(ptr, size ? size : 1) : malloc(size ? size : 1);
Branch: 3 branches
BranchTrueFalseTotal
return ptr ? realloc(ptr, size ? size : 1) : malloc(size ? size : 1); 66 0 66
return ptr ? realloc(ptr, size ? size : 1) : malloc(size ? size : 1); 66 0 66
return ptr ? realloc(ptr, size ? size : 1) : malloc(size ? size : 1); 0 0 0
44 }
45  
46 /*
47 * Free a dynamic memory block.
48 */
49  
50 YAML_DECLARE(void)
51 6897 yaml_free(void *ptr)
52 {
53 6897 ▶ if (ptr) free(ptr);
Branch: 1 branch
BranchTrueFalseTotal
if (ptr) free(ptr); 4678 2219 6897
54 6897 }
55  
56 /*
57 * Duplicate a string.
58 */
59  
60 YAML_DECLARE(yaml_char_t *)
61 1229 yaml_strdup(const yaml_char_t *str)
62 {
63 1229 ▶ if (!str)
Branch: 1 branch
BranchTrueFalseTotal
if (!str) 0 1229 1229
64 0 return NULL;
65  
66 1229 return (yaml_char_t *)strdup((char *)str);
67 }
68  
69 /*
70 * Extend a string.
71 */
72  
73 YAML_DECLARE(int)
74 66 yaml_string_extend(yaml_char_t **start,
75 yaml_char_t **pointer, yaml_char_t **end)
76 {
77 yaml_char_t *new_start;
78  
79 66 ▶ if ((char *)*end - (char *)*start >= INT_MAX / 2)
Branch: 1 branch
BranchTrueFalseTotal
if ((char *)*end - (char *)*start >= INT_MAX / 2) 0 66 66
80 0 return 0;
81  
82 66 new_start = (yaml_char_t *)yaml_realloc((void*)*start, (*end - *start)*2);
83 66 ▶ if (!new_start) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!new_start) return 0; 0 66 66
84  
85 66 memset(new_start + (*end - *start), 0, *end - *start);
86  
87 66 *pointer = new_start + (*pointer - *start);
88 66 *end = new_start + (*end - *start)*2;
89 66 *start = new_start;
90  
91 66 return 1;
92 }
93  
94 /*
95 * Append a string B to a string A.
96 */
97  
98 YAML_DECLARE(int)
99 85 yaml_string_join(
100 yaml_char_t **a_start, yaml_char_t **a_pointer, yaml_char_t **a_end,
101 yaml_char_t **b_start, yaml_char_t **b_pointer, SHIM(yaml_char_t **b_end))
102 {
103 UNUSED_PARAM(b_end)
104 85 ▶ if (*b_start == *b_pointer)
Branch: 1 branch
BranchTrueFalseTotal
if (*b_start == *b_pointer) 24 61 85
105 24 return 1;
106  
107 61 ▶ while (*a_end - *a_pointer <= *b_pointer - *b_start) {
Branch: 1 branch
BranchTrueFalseTotal
while (*a_end - *a_pointer <= *b_pointer - *b_start) { 0 61 61
108 0 ▶ if (!yaml_string_extend(a_start, a_pointer, a_end))
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_string_extend(a_start, a_pointer, a_end)) 0 0 0
109 0 return 0;
110 }
111  
112 61 memcpy(*a_pointer, *b_start, *b_pointer - *b_start);
113 61 *a_pointer += *b_pointer - *b_start;
114  
115 61 return 1;
116 }
117  
118 /*
119 * Extend a stack.
120 */
121  
122 YAML_DECLARE(int)
123 0 yaml_stack_extend(void **start, void **top, void **end)
124 {
125 void *new_start;
126  
127 0 ▶ if ((char *)*end - (char *)*start >= INT_MAX / 2)
Branch: 1 branch
BranchTrueFalseTotal
if ((char *)*end - (char *)*start >= INT_MAX / 2) 0 0 0
128 0 return 0;
129  
130 0 new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2);
131 0 ▶ if (!new_start) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!new_start) return 0; 0 0 0
132  
133 0 *top = (char *)new_start + ((char *)*top - (char *)*start);
134 0 *end = (char *)new_start + ((char *)*end - (char *)*start)*2;
135 0 *start = new_start;
136  
137 0 return 1;
138 }
139  
140 /*
141 * Extend or move a queue.
142 */
143  
144 YAML_DECLARE(int)
145 48 yaml_queue_extend(void **start, void **head, void **tail, void **end)
146 {
147 /* Check if we need to resize the queue. */
148  
149 48 ▶ if (*start == *head && *tail == *end) {
Branch: 2 branches
BranchTrueFalseTotal
if (*start == *head && *tail == *end) { 0 48 48
if (*start == *head && *tail == *end) { 0 0 0
150 0 void *new_start = yaml_realloc(*start,
151 0 ((char *)*end - (char *)*start)*2);
152  
153 0 ▶ if (!new_start) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!new_start) return 0; 0 0 0
154  
155 0 *head = (char *)new_start + ((char *)*head - (char *)*start);
156 0 *tail = (char *)new_start + ((char *)*tail - (char *)*start);
157 0 *end = (char *)new_start + ((char *)*end - (char *)*start)*2;
158 0 *start = new_start;
159 }
160  
161 /* Check if we need to move the queue at the beginning of the buffer. */
162  
163 48 ▶ if (*tail == *end) {
Branch: 1 branch
BranchTrueFalseTotal
if (*tail == *end) { 48 0 48
164 48 ▶ if (*head != *tail) {
Branch: 1 branch
BranchTrueFalseTotal
if (*head != *tail) { 26 22 48
165 26 memmove(*start, *head, (char *)*tail - (char *)*head);
166 }
167 48 *tail = (char *)*tail - (char *)*head + (char *)*start;
168 48 *head = *start;
169 }
170  
171 48 return 1;
172 }
173  
174  
175 /*
176 * Create a new parser object.
177 */
178  
179 YAML_DECLARE(int)
180 110 yaml_parser_initialize(yaml_parser_t *parser)
181 {
182 110 ▶ assert(parser); /* Non-NULL parser object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(parser); /* Non-NULL parser object expected. */ 0 110 110
183  
184 110 memset(parser, 0, sizeof(yaml_parser_t));
185 110 ▶ if (!BUFFER_INIT(parser, parser->raw_buffer, INPUT_RAW_BUFFER_SIZE))
Branch: 2 branches
BranchTrueFalseTotal
if (!BUFFER_INIT(parser, parser->raw_buffer, INPUT_RAW_BUFFER_SIZE)) 110 0 110
if (!BUFFER_INIT(parser, parser->raw_buffer, INPUT_RAW_BUFFER_SIZE)) 0 110 110
186 0 goto error;
187 110 ▶ if (!BUFFER_INIT(parser, parser->buffer, INPUT_BUFFER_SIZE))
Branch: 2 branches
BranchTrueFalseTotal
if (!BUFFER_INIT(parser, parser->buffer, INPUT_BUFFER_SIZE)) 110 0 110
if (!BUFFER_INIT(parser, parser->buffer, INPUT_BUFFER_SIZE)) 0 110 110
188 0 goto error;
189 110 ▶ if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_SIZE, yaml_token_t*))
Branch: 2 branches
BranchTrueFalseTotal
if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_SIZE, yaml_token_t*)) 110 0 110
if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_SIZE, yaml_token_t*)) 0 110 110
190 0 goto error;
191 110 ▶ if (!STACK_INIT(parser, parser->indents, int*))
Branch: 2 branches
BranchTrueFalseTotal
if (!STACK_INIT(parser, parser->indents, int*)) 110 0 110
if (!STACK_INIT(parser, parser->indents, int*)) 0 110 110
192 0 goto error;
193 110 ▶ if (!STACK_INIT(parser, parser->simple_keys, yaml_simple_key_t*))
Branch: 2 branches
BranchTrueFalseTotal
if (!STACK_INIT(parser, parser->simple_keys, yaml_simple_key_t*)) 110 0 110
if (!STACK_INIT(parser, parser->simple_keys, yaml_simple_key_t*)) 0 110 110
194 0 goto error;
195 110 ▶ if (!STACK_INIT(parser, parser->states, yaml_parser_state_t*))
Branch: 2 branches
BranchTrueFalseTotal
if (!STACK_INIT(parser, parser->states, yaml_parser_state_t*)) 110 0 110
if (!STACK_INIT(parser, parser->states, yaml_parser_state_t*)) 0 110 110
196 0 goto error;
197 110 ▶ if (!STACK_INIT(parser, parser->marks, yaml_mark_t*))
Branch: 2 branches
BranchTrueFalseTotal
if (!STACK_INIT(parser, parser->marks, yaml_mark_t*)) 110 0 110
if (!STACK_INIT(parser, parser->marks, yaml_mark_t*)) 0 110 110
198 0 goto error;
199 110 ▶ if (!STACK_INIT(parser, parser->tag_directives, yaml_tag_directive_t*))
Branch: 2 branches
BranchTrueFalseTotal
if (!STACK_INIT(parser, parser->tag_directives, yaml_tag_directive_t*)) 110 0 110
if (!STACK_INIT(parser, parser->tag_directives, yaml_tag_directive_t*)) 0 110 110
200 0 goto error;
201  
202 110 return 1;
203  
204 0 error:
205  
206 0 BUFFER_DEL(parser, parser->raw_buffer);
207 0 BUFFER_DEL(parser, parser->buffer);
208 0 QUEUE_DEL(parser, parser->tokens);
209 0 STACK_DEL(parser, parser->indents);
210 0 STACK_DEL(parser, parser->simple_keys);
211 0 STACK_DEL(parser, parser->states);
212 0 STACK_DEL(parser, parser->marks);
213 0 STACK_DEL(parser, parser->tag_directives);
214  
215 0 return 0;
216 }
217  
218 /*
219 * Destroy a parser object.
220 */
221  
222 YAML_DECLARE(void)
223 132 yaml_parser_delete(yaml_parser_t *parser)
224 {
225 132 ▶ assert(parser); /* Non-NULL parser object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(parser); /* Non-NULL parser object expected. */ 0 132 132
226  
227 132 BUFFER_DEL(parser, parser->raw_buffer);
228 132 BUFFER_DEL(parser, parser->buffer);
229 133 ▶ while (!QUEUE_EMPTY(parser, parser->tokens)) {
Branch: 1 branch
BranchTrueFalseTotal
while (!QUEUE_EMPTY(parser, parser->tokens)) { 1 132 133
230 1 yaml_token_delete(&DEQUEUE(parser, parser->tokens));
231 }
232 132 QUEUE_DEL(parser, parser->tokens);
233 132 STACK_DEL(parser, parser->indents);
234 132 STACK_DEL(parser, parser->simple_keys);
235 132 STACK_DEL(parser, parser->states);
236 132 STACK_DEL(parser, parser->marks);
237 144 ▶ while (!STACK_EMPTY(parser, parser->tag_directives)) {
Branch: 1 branch
BranchTrueFalseTotal
while (!STACK_EMPTY(parser, parser->tag_directives)) { 12 132 144
238 12 yaml_tag_directive_t tag_directive = POP(parser, parser->tag_directives);
239 12 yaml_free(tag_directive.handle);
240 12 yaml_free(tag_directive.prefix);
241 }
242 132 STACK_DEL(parser, parser->tag_directives);
243  
244 132 memset(parser, 0, sizeof(yaml_parser_t));
245 132 }
246  
247 /*
248 * String read handler.
249 */
250  
251 static int
252 202 yaml_string_read_handler(void *data, unsigned char *buffer, size_t size,
253 size_t *size_read)
254 {
255 202 yaml_parser_t *parser = (yaml_parser_t *)data;
256  
257 202 ▶ if (parser->input.string.current == parser->input.string.end) {
Branch: 1 branch
BranchTrueFalseTotal
if (parser->input.string.current == parser->input.string.end) { 99 103 202
258 99 *size_read = 0;
259 99 return 1;
260 }
261  
262 103 if (size > (size_t)(parser->input.string.end
263 103 ▶ - parser->input.string.current)) {
Branch: 1 branch
BranchTrueFalseTotal
- parser->input.string.current)) { 103 0 103
264 103 size = parser->input.string.end - parser->input.string.current;
265 }
266  
267 103 memcpy(buffer, parser->input.string.current, size);
268 103 parser->input.string.current += size;
269 103 *size_read = size;
270 103 return 1;
271 }
272  
273 /*
274 * File read handler.
275 */
276  
277 static int
278 7 yaml_file_read_handler(void *data, unsigned char *buffer, size_t size,
279 size_t *size_read)
280 {
281 7 yaml_parser_t *parser = (yaml_parser_t *)data;
282  
283 7 *size_read = fread(buffer, 1, size, parser->input.file);
284 7 return !ferror(parser->input.file);
285 }
286  
287 /*
288 * Set a string input.
289 */
290  
291 YAML_DECLARE(void)
292 104 yaml_parser_set_input_string(yaml_parser_t *parser,
293 const unsigned char *input, size_t size)
294 {
295 104 ▶ assert(parser); /* Non-NULL parser object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(parser); /* Non-NULL parser object expected. */ 0 104 104
296 104 ▶ assert(!parser->read_handler); /* You can set the source only once. */
Branch: 1 branch
BranchTrueFalseTotal
assert(!parser->read_handler); /* You can set the source only once. */ 0 104 104
297 104 ▶ assert(input); /* Non-NULL input string expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(input); /* Non-NULL input string expected. */ 0 104 104
298  
299 104 parser->read_handler = yaml_string_read_handler;
300 104 parser->read_handler_data = parser;
301  
302 104 parser->input.string.start = input;
303 104 parser->input.string.current = input;
304 104 parser->input.string.end = input+size;
305 104 }
306  
307 /*
308 * Set a file input.
309 */
310  
311 YAML_DECLARE(void)
312 4 yaml_parser_set_input_file(yaml_parser_t *parser, FILE *file)
313 {
314 4 ▶ assert(parser); /* Non-NULL parser object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(parser); /* Non-NULL parser object expected. */ 0 4 4
315 4 ▶ assert(!parser->read_handler); /* You can set the source only once. */
Branch: 1 branch
BranchTrueFalseTotal
assert(!parser->read_handler); /* You can set the source only once. */ 0 4 4
316 4 ▶ assert(file); /* Non-NULL file object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(file); /* Non-NULL file object expected. */ 0 4 4
317  
318 4 parser->read_handler = yaml_file_read_handler;
319 4 parser->read_handler_data = parser;
320  
321 4 parser->input.file = file;
322 4 }
323  
324 /*
325 * Set a generic input.
326 */
327  
328 YAML_DECLARE(void)
329 2 yaml_parser_set_input(yaml_parser_t *parser,
330 yaml_read_handler_t *handler, void *data)
331 {
332 2 ▶ assert(parser); /* Non-NULL parser object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(parser); /* Non-NULL parser object expected. */ 0 2 2
333 2 ▶ assert(!parser->read_handler); /* You can set the source only once. */
Branch: 1 branch
BranchTrueFalseTotal
assert(!parser->read_handler); /* You can set the source only once. */ 0 2 2
334 2 ▶ assert(handler); /* Non-NULL read handler expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(handler); /* Non-NULL read handler expected. */ 0 2 2
335  
336 2 parser->read_handler = handler;
337 2 parser->read_handler_data = data;
338 2 }
339  
340 /*
341 * Set the source encoding.
342 */
343  
344 YAML_DECLARE(void)
345 0 yaml_parser_set_encoding(yaml_parser_t *parser, yaml_encoding_t encoding)
346 {
347 0 ▶ assert(parser); /* Non-NULL parser object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(parser); /* Non-NULL parser object expected. */ 0 0 0
348 0 ▶ assert(!parser->encoding); /* Encoding is already set or detected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(!parser->encoding); /* Encoding is already set or detected. */ 0 0 0
349  
350 0 parser->encoding = encoding;
351 0 }
352  
353 /*
354 * Create a new emitter object.
355 */
356  
357 YAML_DECLARE(int)
358 88 yaml_emitter_initialize(yaml_emitter_t *emitter)
359 {
360 88 ▶ assert(emitter); /* Non-NULL emitter object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(emitter); /* Non-NULL emitter object expected. */ 0 88 88
361  
362 88 memset(emitter, 0, sizeof(yaml_emitter_t));
363 88 ▶ if (!BUFFER_INIT(emitter, emitter->buffer, OUTPUT_BUFFER_SIZE))
Branch: 2 branches
BranchTrueFalseTotal
if (!BUFFER_INIT(emitter, emitter->buffer, OUTPUT_BUFFER_SIZE)) 88 0 88
if (!BUFFER_INIT(emitter, emitter->buffer, OUTPUT_BUFFER_SIZE)) 0 88 88
364 0 goto error;
365 88 ▶ if (!BUFFER_INIT(emitter, emitter->raw_buffer, OUTPUT_RAW_BUFFER_SIZE))
Branch: 2 branches
BranchTrueFalseTotal
if (!BUFFER_INIT(emitter, emitter->raw_buffer, OUTPUT_RAW_BUFFER_SIZE)) 88 0 88
if (!BUFFER_INIT(emitter, emitter->raw_buffer, OUTPUT_RAW_BUFFER_SIZE)) 0 88 88
366 0 goto error;
367 88 ▶ if (!STACK_INIT(emitter, emitter->states, yaml_emitter_state_t*))
Branch: 2 branches
BranchTrueFalseTotal
if (!STACK_INIT(emitter, emitter->states, yaml_emitter_state_t*)) 88 0 88
if (!STACK_INIT(emitter, emitter->states, yaml_emitter_state_t*)) 0 88 88
368 0 goto error;
369 88 ▶ if (!QUEUE_INIT(emitter, emitter->events, INITIAL_QUEUE_SIZE, yaml_event_t*))
Branch: 2 branches
BranchTrueFalseTotal
if (!QUEUE_INIT(emitter, emitter->events, INITIAL_QUEUE_SIZE, yaml_event_t*)) 88 0 88
if (!QUEUE_INIT(emitter, emitter->events, INITIAL_QUEUE_SIZE, yaml_event_t*)) 0 88 88
370 0 goto error;
371 88 ▶ if (!STACK_INIT(emitter, emitter->indents, int*))
Branch: 2 branches
BranchTrueFalseTotal
if (!STACK_INIT(emitter, emitter->indents, int*)) 88 0 88
if (!STACK_INIT(emitter, emitter->indents, int*)) 0 88 88
372 0 goto error;
373 88 ▶ if (!STACK_INIT(emitter, emitter->tag_directives, yaml_tag_directive_t*))
Branch: 2 branches
BranchTrueFalseTotal
if (!STACK_INIT(emitter, emitter->tag_directives, yaml_tag_directive_t*)) 88 0 88
if (!STACK_INIT(emitter, emitter->tag_directives, yaml_tag_directive_t*)) 0 88 88
374 0 goto error;
375  
376 88 return 1;
377  
378 0 error:
379  
380 0 BUFFER_DEL(emitter, emitter->buffer);
381 0 BUFFER_DEL(emitter, emitter->raw_buffer);
382 0 STACK_DEL(emitter, emitter->states);
383 0 QUEUE_DEL(emitter, emitter->events);
384 0 STACK_DEL(emitter, emitter->indents);
385 0 STACK_DEL(emitter, emitter->tag_directives);
386  
387 0 return 0;
388 }
389  
390 /*
391 * Destroy an emitter object.
392 */
393  
394 YAML_DECLARE(void)
395 111 yaml_emitter_delete(yaml_emitter_t *emitter)
396 {
397 111 ▶ assert(emitter); /* Non-NULL emitter object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(emitter); /* Non-NULL emitter object expected. */ 0 111 111
398  
399 111 BUFFER_DEL(emitter, emitter->buffer);
400 111 BUFFER_DEL(emitter, emitter->raw_buffer);
401 111 STACK_DEL(emitter, emitter->states);
402 111 ▶ while (!QUEUE_EMPTY(emitter, emitter->events)) {
Branch: 1 branch
BranchTrueFalseTotal
while (!QUEUE_EMPTY(emitter, emitter->events)) { 0 111 111
403 0 yaml_event_delete(&DEQUEUE(emitter, emitter->events));
404 }
405 111 QUEUE_DEL(emitter, emitter->events);
406 111 STACK_DEL(emitter, emitter->indents);
407 111 ▶ while (!STACK_EMPTY(empty, emitter->tag_directives)) {
Branch: 1 branch
BranchTrueFalseTotal
while (!STACK_EMPTY(empty, emitter->tag_directives)) { 0 111 111
408 0 yaml_tag_directive_t tag_directive = POP(emitter, emitter->tag_directives);
409 0 yaml_free(tag_directive.handle);
410 0 yaml_free(tag_directive.prefix);
411 }
412 111 STACK_DEL(emitter, emitter->tag_directives);
413 111 yaml_free(emitter->anchors);
414  
415 111 memset(emitter, 0, sizeof(yaml_emitter_t));
416 111 }
417  
418 /*
419 * String write handler.
420 */
421  
422 static int
423 0 yaml_string_write_handler(void *data, unsigned char *buffer, size_t size)
424 {
425 0 yaml_emitter_t *emitter = (yaml_emitter_t *)data;
426  
427 0 ▶ if (emitter->output.string.size - *emitter->output.string.size_written
Branch: 1 branch
BranchTrueFalseTotal
if (emitter->output.string.size - *emitter->output.string.size_written 0 0 0
428 < size) {
429 0 memcpy(emitter->output.string.buffer
430 0 + *emitter->output.string.size_written,
431 buffer,
432 0 emitter->output.string.size
433 0 - *emitter->output.string.size_written);
434 0 *emitter->output.string.size_written = emitter->output.string.size;
435 0 return 0;
436 }
437  
438 0 memcpy(emitter->output.string.buffer
439 0 + *emitter->output.string.size_written, buffer, size);
440 0 *emitter->output.string.size_written += size;
441 0 return 1;
442 }
443  
444 /*
445 * File write handler.
446 */
447  
448 static int
449 5 yaml_file_write_handler(void *data, unsigned char *buffer, size_t size)
450 {
451 5 yaml_emitter_t *emitter = (yaml_emitter_t *)data;
452  
453 5 return (fwrite(buffer, 1, size, emitter->output.file) == size);
454 }
455 /*
456 * Set a string output.
457 */
458  
459 YAML_DECLARE(void)
460 0 yaml_emitter_set_output_string(yaml_emitter_t *emitter,
461 unsigned char *output, size_t size, size_t *size_written)
462 {
463 0 ▶ assert(emitter); /* Non-NULL emitter object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(emitter); /* Non-NULL emitter object expected. */ 0 0 0
464 0 ▶ assert(!emitter->write_handler); /* You can set the output only once. */
Branch: 1 branch
BranchTrueFalseTotal
assert(!emitter->write_handler); /* You can set the output only once. */ 0 0 0
465 0 ▶ assert(output); /* Non-NULL output string expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(output); /* Non-NULL output string expected. */ 0 0 0
466  
467 0 emitter->write_handler = yaml_string_write_handler;
468 0 emitter->write_handler_data = emitter;
469  
470 0 emitter->output.string.buffer = output;
471 0 emitter->output.string.size = size;
472 0 emitter->output.string.size_written = size_written;
473 0 *size_written = 0;
474 0 }
475  
476 /*
477 * Set a file output.
478 */
479  
480 YAML_DECLARE(void)
481 3 yaml_emitter_set_output_file(yaml_emitter_t *emitter, FILE *file)
482 {
483 3 ▶ assert(emitter); /* Non-NULL emitter object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(emitter); /* Non-NULL emitter object expected. */ 0 3 3
484 3 ▶ assert(!emitter->write_handler); /* You can set the output only once. */
Branch: 1 branch
BranchTrueFalseTotal
assert(!emitter->write_handler); /* You can set the output only once. */ 0 3 3
485 3 ▶ assert(file); /* Non-NULL file object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(file); /* Non-NULL file object expected. */ 0 3 3
486  
487 3 emitter->write_handler = yaml_file_write_handler;
488 3 emitter->write_handler_data = emitter;
489  
490 3 emitter->output.file = file;
491 3 }
492  
493 /*
494 * Set a generic output handler.
495 */
496  
497 YAML_DECLARE(void)
498 85 yaml_emitter_set_output(yaml_emitter_t *emitter,
499 yaml_write_handler_t *handler, void *data)
500 {
501 85 ▶ assert(emitter); /* Non-NULL emitter object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(emitter); /* Non-NULL emitter object expected. */ 0 85 85
502 85 ▶ assert(!emitter->write_handler); /* You can set the output only once. */
Branch: 1 branch
BranchTrueFalseTotal
assert(!emitter->write_handler); /* You can set the output only once. */ 0 85 85
503 85 ▶ assert(handler); /* Non-NULL handler object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(handler); /* Non-NULL handler object expected. */ 0 85 85
504  
505 85 emitter->write_handler = handler;
506 85 emitter->write_handler_data = data;
507 85 }
508  
509 /*
510 * Set the output encoding.
511 */
512  
513 YAML_DECLARE(void)
514 0 yaml_emitter_set_encoding(yaml_emitter_t *emitter, yaml_encoding_t encoding)
515 {
516 0 ▶ assert(emitter); /* Non-NULL emitter object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(emitter); /* Non-NULL emitter object expected. */ 0 0 0
517 0 ▶ assert(!emitter->encoding); /* You can set encoding only once. */
Branch: 1 branch
BranchTrueFalseTotal
assert(!emitter->encoding); /* You can set encoding only once. */ 0 0 0
518  
519 0 emitter->encoding = encoding;
520 0 }
521  
522 /*
523 * Set the canonical output style.
524 */
525  
526 YAML_DECLARE(void)
527 88 yaml_emitter_set_canonical(yaml_emitter_t *emitter, int canonical)
528 {
529 88 ▶ assert(emitter); /* Non-NULL emitter object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(emitter); /* Non-NULL emitter object expected. */ 0 88 88
530  
531 88 emitter->canonical = (canonical != 0);
532 88 }
533  
534 /*
535 * Set the indentation increment.
536 */
537  
538 YAML_DECLARE(void)
539 88 yaml_emitter_set_indent(yaml_emitter_t *emitter, int indent)
540 {
541 88 ▶ assert(emitter); /* Non-NULL emitter object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(emitter); /* Non-NULL emitter object expected. */ 0 88 88
542  
543 88 ▶ emitter->best_indent = (1 < indent && indent < 10) ? indent : 2;
Branch: 2 branches
BranchTrueFalseTotal
emitter->best_indent = (1 < indent && indent < 10) ? indent : 2; 88 0 88
emitter->best_indent = (1 < indent && indent < 10) ? indent : 2; 88 0 88
544 88 }
545  
546 /*
547 * Set the preferred line width.
548 */
549  
550 YAML_DECLARE(void)
551 88 yaml_emitter_set_width(yaml_emitter_t *emitter, int width)
552 {
553 88 ▶ assert(emitter); /* Non-NULL emitter object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(emitter); /* Non-NULL emitter object expected. */ 0 88 88
554  
555 88 emitter->best_width = (width >= 0) ? width : -1;
556 88 }
557  
558 /*
559 * Set if unescaped non-ASCII characters are allowed.
560 */
561  
562 YAML_DECLARE(void)
563 88 yaml_emitter_set_unicode(yaml_emitter_t *emitter, int unicode)
564 {
565 88 ▶ assert(emitter); /* Non-NULL emitter object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(emitter); /* Non-NULL emitter object expected. */ 0 88 88
566  
567 88 emitter->unicode = (unicode != 0);
568 88 }
569  
570 /*
571 * Set the preferred line break character.
572 */
573  
574 YAML_DECLARE(void)
575 0 yaml_emitter_set_break(yaml_emitter_t *emitter, yaml_break_t line_break)
576 {
577 0 ▶ assert(emitter); /* Non-NULL emitter object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(emitter); /* Non-NULL emitter object expected. */ 0 0 0
578  
579 0 emitter->line_break = line_break;
580 0 }
581  
582 /*
583 * Destroy a token object.
584 */
585  
586 YAML_DECLARE(void)
587 1 yaml_token_delete(yaml_token_t *token)
588 {
589 1 ▶ assert(token); /* Non-NULL token object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(token); /* Non-NULL token object expected. */ 0 1 1
590  
591 1 switch (token->type)
592 {
593 0 case YAML_TAG_DIRECTIVE_TOKEN:
594 0 yaml_free(token->data.tag_directive.handle);
595 0 yaml_free(token->data.tag_directive.prefix);
596 0 break;
597  
598 0 case YAML_ALIAS_TOKEN:
599 0 yaml_free(token->data.alias.value);
600 0 break;
601  
602 0 case YAML_ANCHOR_TOKEN:
603 0 yaml_free(token->data.anchor.value);
604 0 break;
605  
606 0 case YAML_TAG_TOKEN:
607 0 yaml_free(token->data.tag.handle);
608 0 yaml_free(token->data.tag.suffix);
609 0 break;
610  
611 1 case YAML_SCALAR_TOKEN:
612 1 yaml_free(token->data.scalar.value);
613 1 break;
614  
615 0 default:
616 0 break;
617 }
618  
619 1 memset(token, 0, sizeof(yaml_token_t));
620 1 }
621  
622 /*
623 * Check if a string is a valid UTF-8 sequence.
624 *
625 * Check 'reader.c' for more details on UTF-8 encoding.
626 */
627  
628 static int
629 630 yaml_check_utf8(const yaml_char_t *start, size_t length)
630 {
631 630 const yaml_char_t *end = start + length;
632 630 const yaml_char_t *pointer = start;
633  
634 10148 ▶ while (pointer < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (pointer < end) { 9518 630 10148
635 unsigned char octet;
636 unsigned int width;
637 unsigned int value;
638 size_t k;
639  
640 9518 octet = pointer[0];
641 9591 ▶ width = (octet & 0x80) == 0x00 ? 1 :
Branch: 1 branch
BranchTrueFalseTotal
width = (octet & 0x80) == 0x00 ? 1 : 73 9445 9518
642 73 ▶ (octet & 0xE0) == 0xC0 ? 2 :
Branch: 1 branch
BranchTrueFalseTotal
(octet & 0xE0) == 0xC0 ? 2 : 57 16 73
643 57 ▶ (octet & 0xF0) == 0xE0 ? 3 :
Branch: 1 branch
BranchTrueFalseTotal
(octet & 0xF0) == 0xE0 ? 3 : 0 57 57
644 0 ▶ (octet & 0xF8) == 0xF0 ? 4 : 0;
Branch: 1 branch
BranchTrueFalseTotal
(octet & 0xF8) == 0xF0 ? 4 : 0; 0 0 0
645 9591 ▶ value = (octet & 0x80) == 0x00 ? octet & 0x7F :
Branch: 1 branch
BranchTrueFalseTotal
value = (octet & 0x80) == 0x00 ? octet & 0x7F : 9445 73 9518
646 73 ▶ (octet & 0xE0) == 0xC0 ? octet & 0x1F :
Branch: 1 branch
BranchTrueFalseTotal
(octet & 0xE0) == 0xC0 ? octet & 0x1F : 16 57 73
647 57 ▶ (octet & 0xF0) == 0xE0 ? octet & 0x0F :
Branch: 1 branch
BranchTrueFalseTotal
(octet & 0xF0) == 0xE0 ? octet & 0x0F : 57 0 57
648 0 ▶ (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0;
Branch: 1 branch
BranchTrueFalseTotal
(octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; 0 0 0
649 9518 ▶ if (!width) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!width) return 0; 0 9518 9518
650 9518 ▶ if (pointer+width > end) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (pointer+width > end) return 0; 0 9518 9518
651 9648 ▶ for (k = 1; k < width; k ++) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 1; k < width; k ++) { 130 9518 9648
652 130 octet = pointer[k];
653 130 ▶ if ((octet & 0xC0) != 0x80) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if ((octet & 0xC0) != 0x80) return 0; 0 130 130
654 130 value = (value << 6) + (octet & 0x3F);
655 }
656 9518 ▶ if (!((width == 1) ||
Branch: 3 branches
BranchTrueFalseTotal
if (!((width == 1) || 73 9445 9518
if (!((width == 1) || 16 57 73
if (!((width == 1) || 0 0 0
657 73 ▶ (width == 2 && value >= 0x80) ||
Branch: 2 branches
BranchTrueFalseTotal
(width == 2 && value >= 0x80) || 0 16 16
(width == 2 && value >= 0x80) || 57 0 57
658 57 ▶ (width == 3 && value >= 0x800) ||
Branch: 1 branch
BranchTrueFalseTotal
(width == 3 && value >= 0x800) || 0 57 57
659 0 ▶ (width == 4 && value >= 0x10000))) return 0;
Branch: 1 branch
BranchTrueFalseTotal
(width == 4 && value >= 0x10000))) return 0; 0 0 0
660  
661 9518 pointer += width;
662 }
663  
664 630 return 1;
665 }
666  
667 /*
668 * Create STREAM-START.
669 */
670  
671 YAML_DECLARE(int)
672 88 yaml_stream_start_event_initialize(yaml_event_t *event,
673 yaml_encoding_t encoding)
674 {
675 88 yaml_mark_t mark = { 0, 0, 0 };
676  
677 88 ▶ assert(event); /* Non-NULL event object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(event); /* Non-NULL event object is expected. */ 0 88 88
678  
679 88 STREAM_START_EVENT_INIT(*event, encoding, mark, mark);
680  
681 88 return 1;
682 }
683  
684 /*
685 * Create STREAM-END.
686 */
687  
688 YAML_DECLARE(int)
689 88 yaml_stream_end_event_initialize(yaml_event_t *event)
690 {
691 88 yaml_mark_t mark = { 0, 0, 0 };
692  
693 88 ▶ assert(event); /* Non-NULL event object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(event); /* Non-NULL event object is expected. */ 0 88 88
694  
695 88 STREAM_END_EVENT_INIT(*event, mark, mark);
696  
697 88 return 1;
698 }
699  
700 /*
701 * Create DOCUMENT-START.
702 */
703  
704 YAML_DECLARE(int)
705 110 yaml_document_start_event_initialize(yaml_event_t *event,
706 yaml_version_directive_t *version_directive,
707 yaml_tag_directive_t *tag_directives_start,
708 yaml_tag_directive_t *tag_directives_end,
709 int implicit)
710 {
711 struct {
712 yaml_error_type_t error;
713 } context;
714 110 yaml_mark_t mark = { 0, 0, 0 };
715 110 yaml_version_directive_t *version_directive_copy = NULL;
716 struct {
717 yaml_tag_directive_t *start;
718 yaml_tag_directive_t *end;
719 yaml_tag_directive_t *top;
720 110 } tag_directives_copy = { NULL, NULL, NULL };
721 110 yaml_tag_directive_t value = { NULL, NULL };
722  
723 110 ▶ assert(event); /* Non-NULL event object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(event); /* Non-NULL event object is expected. */ 0 110 110
724 110 ▶ assert((tag_directives_start && tag_directives_end) ||
Branch: 3 branches
BranchTrueFalseTotal
assert((tag_directives_start && tag_directives_end) || 0 110 110
assert((tag_directives_start && tag_directives_end) || 0 0 0
assert((tag_directives_start && tag_directives_end) || 0 110 110
725 (tag_directives_start == tag_directives_end));
726 /* Valid tag directives are expected. */
727  
728 110 ▶ if (version_directive) {
Branch: 1 branch
BranchTrueFalseTotal
if (version_directive) { 0 110 110
729 0 version_directive_copy = YAML_MALLOC_STATIC(yaml_version_directive_t);
730 0 ▶ if (!version_directive_copy) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!version_directive_copy) goto error; 0 0 0
731 0 version_directive_copy->major = version_directive->major;
732 0 version_directive_copy->minor = version_directive->minor;
733 }
734  
735 110 ▶ if (tag_directives_start != tag_directives_end) {
Branch: 1 branch
BranchTrueFalseTotal
if (tag_directives_start != tag_directives_end) { 0 110 110
736 yaml_tag_directive_t *tag_directive;
737 0 ▶ if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*))
Branch: 2 branches
BranchTrueFalseTotal
if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*)) 0 0 0
if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*)) 0 0 0
738 0 goto error;
739 0 for (tag_directive = tag_directives_start;
740 0 ▶ tag_directive != tag_directives_end; tag_directive ++) {
Branch: 1 branch
BranchTrueFalseTotal
tag_directive != tag_directives_end; tag_directive ++) { 0 0 0
741 0 ▶ assert(tag_directive->handle);
Branch: 1 branch
BranchTrueFalseTotal
assert(tag_directive->handle); 0 0 0
742 0 ▶ assert(tag_directive->prefix);
Branch: 1 branch
BranchTrueFalseTotal
assert(tag_directive->prefix); 0 0 0
743 0 ▶ if (!yaml_check_utf8(tag_directive->handle,
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(tag_directive->handle, 0 0 0
744 0 strlen((char *)tag_directive->handle)))
745 0 goto error;
746 0 ▶ if (!yaml_check_utf8(tag_directive->prefix,
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(tag_directive->prefix, 0 0 0
747 0 strlen((char *)tag_directive->prefix)))
748 0 goto error;
749 0 value.handle = yaml_strdup(tag_directive->handle);
750 0 value.prefix = yaml_strdup(tag_directive->prefix);
751 0 ▶ if (!value.handle || !value.prefix) goto error;
Branch: 2 branches
BranchTrueFalseTotal
if (!value.handle || !value.prefix) goto error; 0 0 0
if (!value.handle || !value.prefix) goto error; 0 0 0
752 0 ▶ if (!PUSH(&context, tag_directives_copy, value))
Branch: 3 branches
BranchTrueFalseTotal
if (!PUSH(&context, tag_directives_copy, value)) 0 0 0
if (!PUSH(&context, tag_directives_copy, value)) 0 0 0
if (!PUSH(&context, tag_directives_copy, value)) 0 0 0
753 0 goto error;
754 0 value.handle = NULL;
755 0 value.prefix = NULL;
756 }
757 }
758  
759 110 DOCUMENT_START_EVENT_INIT(*event, version_directive_copy,
760 tag_directives_copy.start, tag_directives_copy.top,
761 implicit, mark, mark);
762  
763 110 return 1;
764  
765 0 error:
766 0 yaml_free(version_directive_copy);
767 0 ▶ while (!STACK_EMPTY(context, tag_directives_copy)) {
Branch: 1 branch
BranchTrueFalseTotal
while (!STACK_EMPTY(context, tag_directives_copy)) { 0 0 0
768 0 value = POP(context, tag_directives_copy);
769 0 yaml_free(value.handle);
770 0 yaml_free(value.prefix);
771 }
772 0 STACK_DEL(context, tag_directives_copy);
773 0 yaml_free(value.handle);
774 0 yaml_free(value.prefix);
775  
776 0 return 0;
777 }
778  
779 /*
780 * Create DOCUMENT-END.
781 */
782  
783 YAML_DECLARE(int)
784 110 yaml_document_end_event_initialize(yaml_event_t *event, int implicit)
785 {
786 110 yaml_mark_t mark = { 0, 0, 0 };
787  
788 110 ▶ assert(event); /* Non-NULL emitter object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(event); /* Non-NULL emitter object is expected. */ 0 110 110
789  
790 110 DOCUMENT_END_EVENT_INIT(*event, implicit, mark, mark);
791  
792 110 return 1;
793 }
794  
795 /*
796 * Create ALIAS.
797 */
798  
799 YAML_DECLARE(int)
800 17 yaml_alias_event_initialize(yaml_event_t *event, const yaml_char_t *anchor)
801 {
802 17 yaml_mark_t mark = { 0, 0, 0 };
803 17 yaml_char_t *anchor_copy = NULL;
804  
805 17 ▶ assert(event); /* Non-NULL event object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(event); /* Non-NULL event object is expected. */ 0 17 17
806 17 ▶ assert(anchor); /* Non-NULL anchor is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(anchor); /* Non-NULL anchor is expected. */ 0 17 17
807  
808 17 ▶ if (!yaml_check_utf8(anchor, strlen((char *)anchor))) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(anchor, strlen((char *)anchor))) return 0; 0 17 17
809  
810 17 anchor_copy = yaml_strdup(anchor);
811 17 ▶ if (!anchor_copy)
Branch: 1 branch
BranchTrueFalseTotal
if (!anchor_copy) 0 17 17
812 0 return 0;
813  
814 17 ALIAS_EVENT_INIT(*event, anchor_copy, mark, mark);
815  
816 17 return 1;
817 }
818  
819 /*
820 * Create SCALAR.
821 */
822  
823 YAML_DECLARE(int)
824 293 yaml_scalar_event_initialize(yaml_event_t *event,
825 const yaml_char_t *anchor, const yaml_char_t *tag,
826 const yaml_char_t *value, int length,
827 int plain_implicit, int quoted_implicit,
828 yaml_scalar_style_t style)
829 {
830 293 yaml_mark_t mark = { 0, 0, 0 };
831 293 yaml_char_t *anchor_copy = NULL;
832 293 yaml_char_t *tag_copy = NULL;
833 293 yaml_char_t *value_copy = NULL;
834  
835 293 ▶ assert(event); /* Non-NULL event object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(event); /* Non-NULL event object is expected. */ 0 293 293
836 293 ▶ assert(value); /* Non-NULL anchor is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(value); /* Non-NULL anchor is expected. */ 0 293 293
837  
838 293 ▶ if (anchor) {
Branch: 1 branch
BranchTrueFalseTotal
if (anchor) { 0 293 293
839 0 ▶ if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error; 0 0 0
840 0 anchor_copy = yaml_strdup(anchor);
841 0 ▶ if (!anchor_copy) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!anchor_copy) goto error; 0 0 0
842 }
843  
844 293 ▶ if (tag) {
Branch: 1 branch
BranchTrueFalseTotal
if (tag) { 274 19 293
845 274 ▶ if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; 0 274 274
846 274 tag_copy = yaml_strdup(tag);
847 274 ▶ if (!tag_copy) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!tag_copy) goto error; 0 274 274
848 }
849  
850 293 ▶ if (length < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length < 0) { 0 293 293
851 0 length = strlen((char *)value);
852 }
853  
854 293 ▶ if (!yaml_check_utf8(value, length)) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(value, length)) goto error; 0 293 293
855 293 value_copy = YAML_MALLOC(length+1);
856 293 ▶ if (!value_copy) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!value_copy) goto error; 0 293 293
857 293 memcpy(value_copy, value, length);
858 293 value_copy[length] = '\0';
859  
860 293 SCALAR_EVENT_INIT(*event, anchor_copy, tag_copy, value_copy, length,
861 plain_implicit, quoted_implicit, style, mark, mark);
862  
863 293 return 1;
864  
865 0 error:
866 0 yaml_free(anchor_copy);
867 0 yaml_free(tag_copy);
868 0 yaml_free(value_copy);
869  
870 0 return 0;
871 }
872  
873 /*
874 * Create SEQUENCE-START.
875 */
876  
877 YAML_DECLARE(int)
878 44 yaml_sequence_start_event_initialize(yaml_event_t *event,
879 const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
880 yaml_sequence_style_t style)
881 {
882 44 yaml_mark_t mark = { 0, 0, 0 };
883 44 yaml_char_t *anchor_copy = NULL;
884 44 yaml_char_t *tag_copy = NULL;
885  
886 44 ▶ assert(event); /* Non-NULL event object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(event); /* Non-NULL event object is expected. */ 0 44 44
887  
888 44 ▶ if (anchor) {
Branch: 1 branch
BranchTrueFalseTotal
if (anchor) { 6 38 44
889 6 ▶ if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error; 0 6 6
890 6 anchor_copy = yaml_strdup(anchor);
891 6 ▶ if (!anchor_copy) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!anchor_copy) goto error; 0 6 6
892 }
893  
894 44 ▶ if (tag) {
Branch: 1 branch
BranchTrueFalseTotal
if (tag) { 3 41 44
895 3 ▶ if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; 0 3 3
896 3 tag_copy = yaml_strdup(tag);
897 3 ▶ if (!tag_copy) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!tag_copy) goto error; 0 3 3
898 }
899  
900 44 SEQUENCE_START_EVENT_INIT(*event, anchor_copy, tag_copy,
901 implicit, style, mark, mark);
902  
903 44 return 1;
904  
905 0 error:
906 0 yaml_free(anchor_copy);
907 0 yaml_free(tag_copy);
908  
909 0 return 0;
910 }
911  
912 /*
913 * Create SEQUENCE-END.
914 */
915  
916 YAML_DECLARE(int)
917 44 yaml_sequence_end_event_initialize(yaml_event_t *event)
918 {
919 44 yaml_mark_t mark = { 0, 0, 0 };
920  
921 44 ▶ assert(event); /* Non-NULL event object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(event); /* Non-NULL event object is expected. */ 0 44 44
922  
923 44 SEQUENCE_END_EVENT_INIT(*event, mark, mark);
924  
925 44 return 1;
926 }
927  
928 /*
929 * Create MAPPING-START.
930 */
931  
932 YAML_DECLARE(int)
933 67 yaml_mapping_start_event_initialize(yaml_event_t *event,
934 const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
935 yaml_mapping_style_t style)
936 {
937 67 yaml_mark_t mark = { 0, 0, 0 };
938 67 yaml_char_t *anchor_copy = NULL;
939 67 yaml_char_t *tag_copy = NULL;
940  
941 67 ▶ assert(event); /* Non-NULL event object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(event); /* Non-NULL event object is expected. */ 0 67 67
942  
943 67 ▶ if (anchor) {
Branch: 1 branch
BranchTrueFalseTotal
if (anchor) { 10 57 67
944 10 ▶ if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error; 0 10 10
945 10 anchor_copy = yaml_strdup(anchor);
946 10 ▶ if (!anchor_copy) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!anchor_copy) goto error; 0 10 10
947 }
948  
949 67 ▶ if (tag) {
Branch: 1 branch
BranchTrueFalseTotal
if (tag) { 27 40 67
950 27 ▶ if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; 0 27 27
951 27 tag_copy = yaml_strdup(tag);
952 27 ▶ if (!tag_copy) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!tag_copy) goto error; 0 27 27
953 }
954  
955 67 MAPPING_START_EVENT_INIT(*event, anchor_copy, tag_copy,
956 implicit, style, mark, mark);
957  
958 67 return 1;
959  
960 0 error:
961 0 yaml_free(anchor_copy);
962 0 yaml_free(tag_copy);
963  
964 0 return 0;
965 }
966  
967 /*
968 * Create MAPPING-END.
969 */
970  
971 YAML_DECLARE(int)
972 67 yaml_mapping_end_event_initialize(yaml_event_t *event)
973 {
974 67 yaml_mark_t mark = { 0, 0, 0 };
975  
976 67 ▶ assert(event); /* Non-NULL event object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(event); /* Non-NULL event object is expected. */ 0 67 67
977  
978 67 MAPPING_END_EVENT_INIT(*event, mark, mark);
979  
980 67 return 1;
981 }
982  
983 /*
984 * Destroy an event object.
985 */
986  
987 YAML_DECLARE(void)
988 1763 yaml_event_delete(yaml_event_t *event)
989 {
990 yaml_tag_directive_t *tag_directive;
991  
992 1763 ▶ assert(event); /* Non-NULL event object expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(event); /* Non-NULL event object expected. */ 0 1763 1763
993  
994 1763 switch (event->type)
995 {
996 217 case YAML_DOCUMENT_START_EVENT:
997 217 yaml_free(event->data.document_start.version_directive);
998 217 for (tag_directive = event->data.document_start.tag_directives.start;
999 217 ▶ tag_directive != event->data.document_start.tag_directives.end;
Branch: 1 branch
BranchTrueFalseTotal
tag_directive != event->data.document_start.tag_directives.end; 0 217 217
1000 0 tag_directive++) {
1001 0 yaml_free(tag_directive->handle);
1002 0 yaml_free(tag_directive->prefix);
1003 }
1004 217 yaml_free(event->data.document_start.tag_directives.start);
1005 217 break;
1006  
1007 33 case YAML_ALIAS_EVENT:
1008 33 yaml_free(event->data.alias.anchor);
1009 33 break;
1010  
1011 641 case YAML_SCALAR_EVENT:
1012 641 yaml_free(event->data.scalar.anchor);
1013 641 yaml_free(event->data.scalar.tag);
1014 641 yaml_free(event->data.scalar.value);
1015 641 break;
1016  
1017 95 case YAML_SEQUENCE_START_EVENT:
1018 95 yaml_free(event->data.sequence_start.anchor);
1019 95 yaml_free(event->data.sequence_start.tag);
1020 95 break;
1021  
1022 141 case YAML_MAPPING_START_EVENT:
1023 141 yaml_free(event->data.mapping_start.anchor);
1024 141 yaml_free(event->data.mapping_start.tag);
1025 141 break;
1026  
1027 636 default:
1028 636 break;
1029 }
1030  
1031 1763 memset(event, 0, sizeof(yaml_event_t));
1032 1763 }
1033  
1034 /*
1035 * Create a document object.
1036 */
1037  
1038 YAML_DECLARE(int)
1039 0 yaml_document_initialize(yaml_document_t *document,
1040 yaml_version_directive_t *version_directive,
1041 yaml_tag_directive_t *tag_directives_start,
1042 yaml_tag_directive_t *tag_directives_end,
1043 int start_implicit, int end_implicit)
1044 {
1045 struct {
1046 yaml_error_type_t error;
1047 } context;
1048 struct {
1049 yaml_node_t *start;
1050 yaml_node_t *end;
1051 yaml_node_t *top;
1052 0 } nodes = { NULL, NULL, NULL };
1053 0 yaml_version_directive_t *version_directive_copy = NULL;
1054 struct {
1055 yaml_tag_directive_t *start;
1056 yaml_tag_directive_t *end;
1057 yaml_tag_directive_t *top;
1058 0 } tag_directives_copy = { NULL, NULL, NULL };
1059 0 yaml_tag_directive_t value = { NULL, NULL };
1060 0 yaml_mark_t mark = { 0, 0, 0 };
1061  
1062 0 ▶ assert(document); /* Non-NULL document object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(document); /* Non-NULL document object is expected. */ 0 0 0
1063 0 ▶ assert((tag_directives_start && tag_directives_end) ||
Branch: 3 branches
BranchTrueFalseTotal
assert((tag_directives_start && tag_directives_end) || 0 0 0
assert((tag_directives_start && tag_directives_end) || 0 0 0
assert((tag_directives_start && tag_directives_end) || 0 0 0
1064 (tag_directives_start == tag_directives_end));
1065 /* Valid tag directives are expected. */
1066  
1067 0 ▶ if (!STACK_INIT(&context, nodes, yaml_node_t*)) goto error;
Branch: 2 branches
BranchTrueFalseTotal
if (!STACK_INIT(&context, nodes, yaml_node_t*)) goto error; 0 0 0
if (!STACK_INIT(&context, nodes, yaml_node_t*)) goto error; 0 0 0
1068  
1069 0 ▶ if (version_directive) {
Branch: 1 branch
BranchTrueFalseTotal
if (version_directive) { 0 0 0
1070 0 version_directive_copy = YAML_MALLOC_STATIC(yaml_version_directive_t);
1071 0 ▶ if (!version_directive_copy) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!version_directive_copy) goto error; 0 0 0
1072 0 version_directive_copy->major = version_directive->major;
1073 0 version_directive_copy->minor = version_directive->minor;
1074 }
1075  
1076 0 ▶ if (tag_directives_start != tag_directives_end) {
Branch: 1 branch
BranchTrueFalseTotal
if (tag_directives_start != tag_directives_end) { 0 0 0
1077 yaml_tag_directive_t *tag_directive;
1078 0 ▶ if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*))
Branch: 2 branches
BranchTrueFalseTotal
if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*)) 0 0 0
if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*)) 0 0 0
1079 0 goto error;
1080 0 for (tag_directive = tag_directives_start;
1081 0 ▶ tag_directive != tag_directives_end; tag_directive ++) {
Branch: 1 branch
BranchTrueFalseTotal
tag_directive != tag_directives_end; tag_directive ++) { 0 0 0
1082 0 ▶ assert(tag_directive->handle);
Branch: 1 branch
BranchTrueFalseTotal
assert(tag_directive->handle); 0 0 0
1083 0 ▶ assert(tag_directive->prefix);
Branch: 1 branch
BranchTrueFalseTotal
assert(tag_directive->prefix); 0 0 0
1084 0 ▶ if (!yaml_check_utf8(tag_directive->handle,
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(tag_directive->handle, 0 0 0
1085 0 strlen((char *)tag_directive->handle)))
1086 0 goto error;
1087 0 ▶ if (!yaml_check_utf8(tag_directive->prefix,
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(tag_directive->prefix, 0 0 0
1088 0 strlen((char *)tag_directive->prefix)))
1089 0 goto error;
1090 0 value.handle = yaml_strdup(tag_directive->handle);
1091 0 value.prefix = yaml_strdup(tag_directive->prefix);
1092 0 ▶ if (!value.handle || !value.prefix) goto error;
Branch: 2 branches
BranchTrueFalseTotal
if (!value.handle || !value.prefix) goto error; 0 0 0
if (!value.handle || !value.prefix) goto error; 0 0 0
1093 0 ▶ if (!PUSH(&context, tag_directives_copy, value))
Branch: 3 branches
BranchTrueFalseTotal
if (!PUSH(&context, tag_directives_copy, value)) 0 0 0
if (!PUSH(&context, tag_directives_copy, value)) 0 0 0
if (!PUSH(&context, tag_directives_copy, value)) 0 0 0
1094 0 goto error;
1095 0 value.handle = NULL;
1096 0 value.prefix = NULL;
1097 }
1098 }
1099  
1100 0 DOCUMENT_INIT(*document, nodes.start, nodes.end, version_directive_copy,
1101 tag_directives_copy.start, tag_directives_copy.top,
1102 start_implicit, end_implicit, mark, mark);
1103  
1104 0 return 1;
1105  
1106 0 error:
1107 0 STACK_DEL(&context, nodes);
1108 0 yaml_free(version_directive_copy);
1109 0 ▶ while (!STACK_EMPTY(&context, tag_directives_copy)) {
Branch: 1 branch
BranchTrueFalseTotal
while (!STACK_EMPTY(&context, tag_directives_copy)) { 0 0 0
1110 0 value = POP(&context, tag_directives_copy);
1111 0 yaml_free(value.handle);
1112 0 yaml_free(value.prefix);
1113 }
1114 0 STACK_DEL(&context, tag_directives_copy);
1115 0 yaml_free(value.handle);
1116 0 yaml_free(value.prefix);
1117  
1118 0 return 0;
1119 }
1120  
1121 /*
1122 * Destroy a document object.
1123 */
1124  
1125 YAML_DECLARE(void)
1126 0 yaml_document_delete(yaml_document_t *document)
1127 {
1128 yaml_tag_directive_t *tag_directive;
1129  
1130 0 ▶ assert(document); /* Non-NULL document object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(document); /* Non-NULL document object is expected. */ 0 0 0
1131  
1132 0 ▶ while (!STACK_EMPTY(&context, document->nodes)) {
Branch: 1 branch
BranchTrueFalseTotal
while (!STACK_EMPTY(&context, document->nodes)) { 0 0 0
1133 0 yaml_node_t node = POP(&context, document->nodes);
1134 0 yaml_free(node.tag);
1135 0 switch (node.type) {
1136 0 case YAML_SCALAR_NODE:
1137 0 yaml_free(node.data.scalar.value);
1138 0 break;
1139 0 case YAML_SEQUENCE_NODE:
1140 0 STACK_DEL(&context, node.data.sequence.items);
1141 0 break;
1142 0 case YAML_MAPPING_NODE:
1143 0 STACK_DEL(&context, node.data.mapping.pairs);
1144 0 break;
1145 0 default:
1146 0 assert(0); /* Should not happen. */
1147 }
1148 }
1149 0 STACK_DEL(&context, document->nodes);
1150  
1151 0 yaml_free(document->version_directive);
1152 0 for (tag_directive = document->tag_directives.start;
1153 0 ▶ tag_directive != document->tag_directives.end;
Branch: 1 branch
BranchTrueFalseTotal
tag_directive != document->tag_directives.end; 0 0 0
1154 0 tag_directive++) {
1155 0 yaml_free(tag_directive->handle);
1156 0 yaml_free(tag_directive->prefix);
1157 }
1158 0 yaml_free(document->tag_directives.start);
1159  
1160 0 memset(document, 0, sizeof(yaml_document_t));
1161 0 }
1162  
1163 /**
1164 * Get a document node.
1165 */
1166  
1167 YAML_DECLARE(yaml_node_t *)
1168 0 yaml_document_get_node(yaml_document_t *document, int index)
1169 {
1170 0 ▶ assert(document); /* Non-NULL document object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(document); /* Non-NULL document object is expected. */ 0 0 0
1171  
1172 0 ▶ if (index > 0 && document->nodes.start + index <= document->nodes.top) {
Branch: 2 branches
BranchTrueFalseTotal
if (index > 0 && document->nodes.start + index <= document->nodes.top) { 0 0 0
if (index > 0 && document->nodes.start + index <= document->nodes.top) { 0 0 0
1173 0 return document->nodes.start + index - 1;
1174 }
1175 0 return NULL;
1176 }
1177  
1178 /**
1179 * Get the root object.
1180 */
1181  
1182 YAML_DECLARE(yaml_node_t *)
1183 0 yaml_document_get_root_node(yaml_document_t *document)
1184 {
1185 0 ▶ assert(document); /* Non-NULL document object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(document); /* Non-NULL document object is expected. */ 0 0 0
1186  
1187 0 ▶ if (document->nodes.top != document->nodes.start) {
Branch: 1 branch
BranchTrueFalseTotal
if (document->nodes.top != document->nodes.start) { 0 0 0
1188 0 return document->nodes.start;
1189 }
1190 0 return NULL;
1191 }
1192  
1193 /*
1194 * Add a scalar node to a document.
1195 */
1196  
1197 YAML_DECLARE(int)
1198 0 yaml_document_add_scalar(yaml_document_t *document,
1199 const yaml_char_t *tag, const yaml_char_t *value, int length,
1200 yaml_scalar_style_t style)
1201 {
1202 struct {
1203 yaml_error_type_t error;
1204 } context;
1205 0 yaml_mark_t mark = { 0, 0, 0 };
1206 0 yaml_char_t *tag_copy = NULL;
1207 0 yaml_char_t *value_copy = NULL;
1208 yaml_node_t node;
1209  
1210 0 ▶ assert(document); /* Non-NULL document object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(document); /* Non-NULL document object is expected. */ 0 0 0
1211 0 ▶ assert(value); /* Non-NULL value is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(value); /* Non-NULL value is expected. */ 0 0 0
1212  
1213 0 ▶ if (!tag) {
Branch: 1 branch
BranchTrueFalseTotal
if (!tag) { 0 0 0
1214 0 tag = (yaml_char_t *)YAML_DEFAULT_SCALAR_TAG;
1215 }
1216  
1217 0 ▶ if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; 0 0 0
1218 0 tag_copy = yaml_strdup(tag);
1219 0 ▶ if (!tag_copy) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!tag_copy) goto error; 0 0 0
1220  
1221 0 ▶ if (length < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length < 0) { 0 0 0
1222 0 length = strlen((char *)value);
1223 }
1224  
1225 0 ▶ if (!yaml_check_utf8(value, length)) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(value, length)) goto error; 0 0 0
1226 0 value_copy = YAML_MALLOC(length+1);
1227 0 ▶ if (!value_copy) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!value_copy) goto error; 0 0 0
1228 0 memcpy(value_copy, value, length);
1229 0 value_copy[length] = '\0';
1230  
1231 0 SCALAR_NODE_INIT(node, tag_copy, value_copy, length, style, mark, mark);
1232 0 ▶ if (!PUSH(&context, document->nodes, node)) goto error;
Branch: 3 branches
BranchTrueFalseTotal
if (!PUSH(&context, document->nodes, node)) goto error; 0 0 0
if (!PUSH(&context, document->nodes, node)) goto error; 0 0 0
if (!PUSH(&context, document->nodes, node)) goto error; 0 0 0
1233  
1234 0 return document->nodes.top - document->nodes.start;
1235  
1236 0 error:
1237 0 yaml_free(tag_copy);
1238 0 yaml_free(value_copy);
1239  
1240 0 return 0;
1241 }
1242  
1243 /*
1244 * Add a sequence node to a document.
1245 */
1246  
1247 YAML_DECLARE(int)
1248 0 yaml_document_add_sequence(yaml_document_t *document,
1249 const yaml_char_t *tag, yaml_sequence_style_t style)
1250 {
1251 struct {
1252 yaml_error_type_t error;
1253 } context;
1254 0 yaml_mark_t mark = { 0, 0, 0 };
1255 0 yaml_char_t *tag_copy = NULL;
1256 struct {
1257 yaml_node_item_t *start;
1258 yaml_node_item_t *end;
1259 yaml_node_item_t *top;
1260 0 } items = { NULL, NULL, NULL };
1261 yaml_node_t node;
1262  
1263 0 ▶ assert(document); /* Non-NULL document object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(document); /* Non-NULL document object is expected. */ 0 0 0
1264  
1265 0 ▶ if (!tag) {
Branch: 1 branch
BranchTrueFalseTotal
if (!tag) { 0 0 0
1266 0 tag = (yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG;
1267 }
1268  
1269 0 ▶ if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; 0 0 0
1270 0 tag_copy = yaml_strdup(tag);
1271 0 ▶ if (!tag_copy) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!tag_copy) goto error; 0 0 0
1272  
1273 0 ▶ if (!STACK_INIT(&context, items, yaml_node_item_t*)) goto error;
Branch: 2 branches
BranchTrueFalseTotal
if (!STACK_INIT(&context, items, yaml_node_item_t*)) goto error; 0 0 0
if (!STACK_INIT(&context, items, yaml_node_item_t*)) goto error; 0 0 0
1274  
1275 0 SEQUENCE_NODE_INIT(node, tag_copy, items.start, items.end,
1276 style, mark, mark);
1277 0 ▶ if (!PUSH(&context, document->nodes, node)) goto error;
Branch: 3 branches
BranchTrueFalseTotal
if (!PUSH(&context, document->nodes, node)) goto error; 0 0 0
if (!PUSH(&context, document->nodes, node)) goto error; 0 0 0
if (!PUSH(&context, document->nodes, node)) goto error; 0 0 0
1278  
1279 0 return document->nodes.top - document->nodes.start;
1280  
1281 0 error:
1282 0 STACK_DEL(&context, items);
1283 0 yaml_free(tag_copy);
1284  
1285 0 return 0;
1286 }
1287  
1288 /*
1289 * Add a mapping node to a document.
1290 */
1291  
1292 YAML_DECLARE(int)
1293 0 yaml_document_add_mapping(yaml_document_t *document,
1294 const yaml_char_t *tag, yaml_mapping_style_t style)
1295 {
1296 struct {
1297 yaml_error_type_t error;
1298 } context;
1299 0 yaml_mark_t mark = { 0, 0, 0 };
1300 0 yaml_char_t *tag_copy = NULL;
1301 struct {
1302 yaml_node_pair_t *start;
1303 yaml_node_pair_t *end;
1304 yaml_node_pair_t *top;
1305 0 } pairs = { NULL, NULL, NULL };
1306 yaml_node_t node;
1307  
1308 0 ▶ assert(document); /* Non-NULL document object is expected. */
Branch: 1 branch
BranchTrueFalseTotal
assert(document); /* Non-NULL document object is expected. */ 0 0 0
1309  
1310 0 ▶ if (!tag) {
Branch: 1 branch
BranchTrueFalseTotal
if (!tag) { 0 0 0
1311 0 tag = (yaml_char_t *)YAML_DEFAULT_MAPPING_TAG;
1312 }
1313  
1314 0 ▶ if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; 0 0 0
1315 0 tag_copy = yaml_strdup(tag);
1316 0 ▶ if (!tag_copy) goto error;
Branch: 1 branch
BranchTrueFalseTotal
if (!tag_copy) goto error; 0 0 0
1317  
1318 0 ▶ if (!STACK_INIT(&context, pairs, yaml_node_pair_t*)) goto error;
Branch: 2 branches
BranchTrueFalseTotal
if (!STACK_INIT(&context, pairs, yaml_node_pair_t*)) goto error; 0 0 0
if (!STACK_INIT(&context, pairs, yaml_node_pair_t*)) goto error; 0 0 0
1319  
1320 0 MAPPING_NODE_INIT(node, tag_copy, pairs.start, pairs.end,
1321 style, mark, mark);
1322 0 ▶ if (!PUSH(&context, document->nodes, node)) goto error;
Branch: 3 branches
BranchTrueFalseTotal
if (!PUSH(&context, document->nodes, node)) goto error; 0 0 0
if (!PUSH(&context, document->nodes, node)) goto error; 0 0 0
if (!PUSH(&context, document->nodes, node)) goto error; 0 0 0
1323  
1324 0 return document->nodes.top - document->nodes.start;
1325  
1326 0 error:
1327 0 STACK_DEL(&context, pairs);
1328 0 yaml_free(tag_copy);
1329  
1330 0 return 0;
1331 }
1332  
1333 /*
1334 * Append an item to a sequence node.
1335 */
1336  
1337 YAML_DECLARE(int)
1338 0 yaml_document_append_sequence_item(yaml_document_t *document,
1339 int sequence, int item)
1340 {
1341 struct {
1342 yaml_error_type_t error;
1343 } context;
1344  
1345 0 ▶ assert(document); /* Non-NULL document is required. */
Branch: 1 branch
BranchTrueFalseTotal
assert(document); /* Non-NULL document is required. */ 0 0 0
1346 0 ▶ assert(sequence > 0
Branch: 2 branches
BranchTrueFalseTotal
assert(sequence > 0 0 0 0
assert(sequence > 0 0 0 0
1347 && document->nodes.start + sequence <= document->nodes.top);
1348 /* Valid sequence id is required. */
1349 0 ▶ assert(document->nodes.start[sequence-1].type == YAML_SEQUENCE_NODE);
Branch: 1 branch
BranchTrueFalseTotal
assert(document->nodes.start[sequence-1].type == YAML_SEQUENCE_NODE); 0 0 0
1350 /* A sequence node is required. */
1351 0 ▶ assert(item > 0 && document->nodes.start + item <= document->nodes.top);
Branch: 2 branches
BranchTrueFalseTotal
assert(item > 0 && document->nodes.start + item <= document->nodes.top); 0 0 0
assert(item > 0 && document->nodes.start + item <= document->nodes.top); 0 0 0
1352 /* Valid item id is required. */
1353  
1354 0 ▶ if (!PUSH(&context,
Branch: 3 branches
BranchTrueFalseTotal
if (!PUSH(&context, 0 0 0
if (!PUSH(&context, 0 0 0
if (!PUSH(&context, 0 0 0
1355 document->nodes.start[sequence-1].data.sequence.items, item))
1356 0 return 0;
1357  
1358 0 return 1;
1359 }
1360  
1361 /*
1362 * Append a pair of a key and a value to a mapping node.
1363 */
1364  
1365 YAML_DECLARE(int)
1366 0 yaml_document_append_mapping_pair(yaml_document_t *document,
1367 int mapping, int key, int value)
1368 {
1369 struct {
1370 yaml_error_type_t error;
1371 } context;
1372  
1373 yaml_node_pair_t pair;
1374  
1375 0 ▶ assert(document); /* Non-NULL document is required. */
Branch: 1 branch
BranchTrueFalseTotal
assert(document); /* Non-NULL document is required. */ 0 0 0
1376 0 ▶ assert(mapping > 0
Branch: 2 branches
BranchTrueFalseTotal
assert(mapping > 0 0 0 0
assert(mapping > 0 0 0 0
1377 && document->nodes.start + mapping <= document->nodes.top);
1378 /* Valid mapping id is required. */
1379 0 ▶ assert(document->nodes.start[mapping-1].type == YAML_MAPPING_NODE);
Branch: 1 branch
BranchTrueFalseTotal
assert(document->nodes.start[mapping-1].type == YAML_MAPPING_NODE); 0 0 0
1380 /* A mapping node is required. */
1381 0 ▶ assert(key > 0 && document->nodes.start + key <= document->nodes.top);
Branch: 2 branches
BranchTrueFalseTotal
assert(key > 0 && document->nodes.start + key <= document->nodes.top); 0 0 0
assert(key > 0 && document->nodes.start + key <= document->nodes.top); 0 0 0
1382 /* Valid key id is required. */
1383 0 ▶ assert(value > 0 && document->nodes.start + value <= document->nodes.top);
Branch: 2 branches
BranchTrueFalseTotal
assert(value > 0 && document->nodes.start + value <= document->nodes.top); 0 0 0
assert(value > 0 && document->nodes.start + value <= document->nodes.top); 0 0 0
1384 /* Valid value id is required. */
1385  
1386 0 pair.key = key;
1387 0 pair.value = value;
1388  
1389 0 ▶ if (!PUSH(&context,
Branch: 3 branches
BranchTrueFalseTotal
if (!PUSH(&context, 0 0 0
if (!PUSH(&context, 0 0 0
if (!PUSH(&context, 0 0 0
1390 document->nodes.start[mapping-1].data.mapping.pairs, pair))
1391 0 return 0;
1392  
1393 0 return 1;
1394 }
1395  
1396  
« scanner.c ↑ Summary emitter.c »