PageRenderTime 26ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/src/libyaml/yaml_private.h

https://code.google.com/
C++ Header | 635 lines | 372 code | 145 blank | 118 comment | 72 complexity | a12d0a899c8dd69536d4b0cb1e32ae65 MD5 | raw file
  1
  2#if HAVE_CONFIG_H
  3#include <config.h>
  4#endif
  5
  6#include <yaml.h>
  7
  8#include <assert.h>
  9#include <limits.h>
 10
 11/*
 12 * Memory management.
 13 */
 14
 15YAML_DECLARE(void *)
 16yaml_malloc(size_t size);
 17
 18YAML_DECLARE(void *)
 19yaml_realloc(void *ptr, size_t size);
 20
 21YAML_DECLARE(void)
 22yaml_free(void *ptr);
 23
 24YAML_DECLARE(yaml_char_t *)
 25yaml_strdup(const yaml_char_t *);
 26
 27/*
 28 * Reader: Ensure that the buffer contains at least `length` bytes.
 29 */
 30
 31YAML_DECLARE(int)
 32yaml_parser_update_buffer(yaml_parser_t *parser, size_t length);
 33
 34/*
 35 * Scanner: Ensure that the token stack contains at least one token ready.
 36 */
 37
 38YAML_DECLARE(int)
 39yaml_parser_fetch_more_tokens(yaml_parser_t *parser);
 40
 41/*
 42 * The size of the input raw buffer.
 43 */
 44
 45#define INPUT_RAW_BUFFER_SIZE   16384
 46
 47/*
 48 * The size of the input buffer.
 49 *
 50 * It should be possible to decode the whole raw buffer.
 51 */
 52
 53#define INPUT_BUFFER_SIZE       (INPUT_RAW_BUFFER_SIZE*3)
 54
 55/*
 56 * The size of the output buffer.
 57 */
 58
 59#define OUTPUT_BUFFER_SIZE      16384
 60
 61/*
 62 * The size of the output raw buffer.
 63 *
 64 * It should be possible to encode the whole output buffer.
 65 */
 66
 67#define OUTPUT_RAW_BUFFER_SIZE  (OUTPUT_BUFFER_SIZE*2+2)
 68
 69/*
 70 * The size of other stacks and queues.
 71 */
 72
 73#define INITIAL_STACK_SIZE  16
 74#define INITIAL_QUEUE_SIZE  16
 75#define INITIAL_STRING_SIZE 16
 76
 77/*
 78 * Buffer management.
 79 */
 80
 81#define BUFFER_INIT(context,buffer,size)                                        \
 82    (((buffer).start = yaml_malloc(size)) ?                                     \
 83        ((buffer).last = (buffer).pointer = (buffer).start,                     \
 84         (buffer).end = (buffer).start+(size),                                  \
 85         1) :                                                                   \
 86        ((context)->error = YAML_MEMORY_ERROR,                                  \
 87         0))
 88
 89#define BUFFER_DEL(context,buffer)                                              \
 90    (yaml_free((buffer).start),                                                 \
 91     (buffer).start = (buffer).pointer = (buffer).end = 0)
 92
 93/*
 94 * String management.
 95 */
 96
 97typedef struct {
 98    yaml_char_t *start;
 99    yaml_char_t *end;
100    yaml_char_t *pointer;
101} yaml_string_t;
102
103YAML_DECLARE(int)
104yaml_string_extend(yaml_char_t **start,
105        yaml_char_t **pointer, yaml_char_t **end);
106
107YAML_DECLARE(int)
108yaml_string_join(
109        yaml_char_t **a_start, yaml_char_t **a_pointer, yaml_char_t **a_end,
110        yaml_char_t **b_start, yaml_char_t **b_pointer, yaml_char_t **b_end);
111
112#define NULL_STRING { NULL, NULL, NULL }
113
114#define STRING(string,length)   { (string), (string)+(length), (string) }
115
116#define STRING_ASSIGN(value,string,length)                                      \
117    ((value).start = (string),                                                  \
118     (value).end = (string)+(length),                                           \
119     (value).pointer = (string))
120
121#define STRING_INIT(context,string,size)                                        \
122    (((string).start = yaml_malloc(size)) ?                                     \
123        ((string).pointer = (string).start,                                     \
124         (string).end = (string).start+(size),                                  \
125         memset((string).start, 0, (size)),                                     \
126         1) :                                                                   \
127        ((context)->error = YAML_MEMORY_ERROR,                                  \
128         0))
129
130#define STRING_DEL(context,string)                                              \
131    (yaml_free((string).start),                                                 \
132     (string).start = (string).pointer = (string).end = 0)
133
134#define STRING_EXTEND(context,string)                                           \
135    (((string).pointer+5 < (string).end)                                        \
136        || yaml_string_extend(&(string).start,                                  \
137            &(string).pointer, &(string).end))
138
139#define CLEAR(context,string)                                                   \
140    ((string).pointer = (string).start,                                         \
141     memset((string).start, 0, (string).end-(string).start))
142
143#define JOIN(context,string_a,string_b)                                         \
144    ((yaml_string_join(&(string_a).start, &(string_a).pointer,                  \
145                       &(string_a).end, &(string_b).start,                      \
146                       &(string_b).pointer, &(string_b).end)) ?                 \
147        ((string_b).pointer = (string_b).start,                                 \
148         1) :                                                                   \
149        ((context)->error = YAML_MEMORY_ERROR,                                  \
150         0))
151
152/*
153 * String check operations.
154 */
155
156/*
157 * Check the octet at the specified position.
158 */
159
160#define CHECK_AT(string,octet,offset)                                           \
161    ((string).pointer[offset] == (yaml_char_t)(octet))
162
163/*
164 * Check the current octet in the buffer.
165 */
166
167#define CHECK(string,octet) CHECK_AT((string),(octet),0)
168
169/*
170 * Check if the character at the specified position is an alphabetical
171 * character, a digit, '_', or '-'.
172 */
173
174#define IS_ALPHA_AT(string,offset)                                              \
175     (((string).pointer[offset] >= (yaml_char_t) '0' &&                         \
176       (string).pointer[offset] <= (yaml_char_t) '9') ||                        \
177      ((string).pointer[offset] >= (yaml_char_t) 'A' &&                         \
178       (string).pointer[offset] <= (yaml_char_t) 'Z') ||                        \
179      ((string).pointer[offset] >= (yaml_char_t) 'a' &&                         \
180       (string).pointer[offset] <= (yaml_char_t) 'z') ||                        \
181      (string).pointer[offset] == '_' ||                                        \
182      (string).pointer[offset] == '-')
183
184#define IS_ALPHA(string)    IS_ALPHA_AT((string),0)
185
186/*
187 * Check if the character at the specified position is a digit.
188 */
189
190#define IS_DIGIT_AT(string,offset)                                              \
191     (((string).pointer[offset] >= (yaml_char_t) '0' &&                         \
192       (string).pointer[offset] <= (yaml_char_t) '9'))
193
194#define IS_DIGIT(string)    IS_DIGIT_AT((string),0)
195
196/*
197 * Get the value of a digit.
198 */
199
200#define AS_DIGIT_AT(string,offset)                                              \
201     ((string).pointer[offset] - (yaml_char_t) '0')
202
203#define AS_DIGIT(string)    AS_DIGIT_AT((string),0)
204
205/*
206 * Check if the character at the specified position is a hex-digit.
207 */
208
209#define IS_HEX_AT(string,offset)                                                \
210     (((string).pointer[offset] >= (yaml_char_t) '0' &&                         \
211       (string).pointer[offset] <= (yaml_char_t) '9') ||                        \
212      ((string).pointer[offset] >= (yaml_char_t) 'A' &&                         \
213       (string).pointer[offset] <= (yaml_char_t) 'F') ||                        \
214      ((string).pointer[offset] >= (yaml_char_t) 'a' &&                         \
215       (string).pointer[offset] <= (yaml_char_t) 'f'))
216
217#define IS_HEX(string)    IS_HEX_AT((string),0)
218
219/*
220 * Get the value of a hex-digit.
221 */
222
223#define AS_HEX_AT(string,offset)                                                \
224      (((string).pointer[offset] >= (yaml_char_t) 'A' &&                        \
225        (string).pointer[offset] <= (yaml_char_t) 'F') ?                        \
226       ((string).pointer[offset] - (yaml_char_t) 'A' + 10) :                    \
227       ((string).pointer[offset] >= (yaml_char_t) 'a' &&                        \
228        (string).pointer[offset] <= (yaml_char_t) 'f') ?                        \
229       ((string).pointer[offset] - (yaml_char_t) 'a' + 10) :                    \
230       ((string).pointer[offset] - (yaml_char_t) '0'))
231 
232#define AS_HEX(string)  AS_HEX_AT((string),0)
233 
234/*
235 * Check if the character is ASCII.
236 */
237
238#define IS_ASCII_AT(string,offset)                                              \
239    ((string).pointer[offset] <= (yaml_char_t) '\x7F')
240
241#define IS_ASCII(string)    IS_ASCII_AT((string),0)
242
243/*
244 * Check if the character can be printed unescaped.
245 * Only correct if you know you are looking at valid UTF-8!
246 */
247
248#define IS_PRINTABLE_AT(string,offset)                                          \
249    (((string).pointer[offset] == 0x0A)         /* . == #x0A */                 \
250     || ((string).pointer[offset] >= 0x20       /* #x20 <= . <= #x7E */         \
251         && (string).pointer[offset] <= 0x7E)                                   \
252     || ((string).pointer[offset] == 0xC2       /* #0xA0 <= . <= #xD7FF */      \
253         && (string).pointer[offset+1] >= 0xA0)                                 \
254     || ((string).pointer[offset] > 0xC2                                        \
255         && (string).pointer[offset] < 0xED)                                    \
256     || ((string).pointer[offset] == 0xED                                       \
257         && (string).pointer[offset+1] < 0xA0)                                  \
258     || ((string).pointer[offset] == 0xEE)                                      \
259     || ((string).pointer[offset] == 0xEF      /* #xE000 <= . <= #xFFFD */      \
260         && !((string).pointer[offset+1] == 0xBB        /* && . != #xFEFF */    \
261             && (string).pointer[offset+2] == 0xBF)                             \
262         && !((string).pointer[offset+1] == 0xBF                                \
263             && ((string).pointer[offset+2] == 0xBE                             \
264                 || (string).pointer[offset+2] == 0xBF))))
265
266#define IS_PRINTABLE(string)    IS_PRINTABLE_AT((string),0)
267
268/*
269 * Check if the character at the specified position is NUL.
270 */
271
272#define IS_Z_AT(string,offset)    CHECK_AT((string),'\0',(offset))
273
274#define IS_Z(string)    IS_Z_AT((string),0)
275
276/*
277 * Check if the character at the specified position is BOM.
278 */
279
280#define IS_BOM_AT(string,offset)                                                \
281     (CHECK_AT((string),'\xEF',(offset))                                        \
282      && CHECK_AT((string),'\xBB',(offset)+1)                                   \
283      && CHECK_AT((string),'\xBF',(offset)+2))  /* BOM (#xFEFF) */
284
285#define IS_BOM(string)  IS_BOM_AT(string,0)
286
287/*
288 * Check if the character at the specified position is space.
289 */
290
291#define IS_SPACE_AT(string,offset)  CHECK_AT((string),' ',(offset))
292
293#define IS_SPACE(string)    IS_SPACE_AT((string),0)
294
295/*
296 * Check if the character at the specified position is tab.
297 */
298
299#define IS_TAB_AT(string,offset)    CHECK_AT((string),'\t',(offset))
300
301#define IS_TAB(string)  IS_TAB_AT((string),0)
302
303/*
304 * Check if the character at the specified position is blank (space or tab).
305 */
306
307#define IS_BLANK_AT(string,offset)                                              \
308    (IS_SPACE_AT((string),(offset)) || IS_TAB_AT((string),(offset)))
309
310#define IS_BLANK(string)    IS_BLANK_AT((string),0)
311
312/*
313 * Check if the character at the specified position is a line break.
314 */
315
316#define IS_BREAK_AT(string,offset)                                              \
317    (CHECK_AT((string),'\r',(offset))               /* CR (#xD)*/               \
318     || CHECK_AT((string),'\n',(offset))            /* LF (#xA) */              \
319     || (CHECK_AT((string),'\xC2',(offset))                                     \
320         && CHECK_AT((string),'\x85',(offset)+1))   /* NEL (#x85) */            \
321     || (CHECK_AT((string),'\xE2',(offset))                                     \
322         && CHECK_AT((string),'\x80',(offset)+1)                                \
323         && CHECK_AT((string),'\xA8',(offset)+2))   /* LS (#x2028) */           \
324     || (CHECK_AT((string),'\xE2',(offset))                                     \
325         && CHECK_AT((string),'\x80',(offset)+1)                                \
326         && CHECK_AT((string),'\xA9',(offset)+2)))  /* PS (#x2029) */
327
328#define IS_BREAK(string)    IS_BREAK_AT((string),0)
329
330#define IS_CRLF_AT(string,offset)                                               \
331     (CHECK_AT((string),'\r',(offset)) && CHECK_AT((string),'\n',(offset)+1))
332
333#define IS_CRLF(string) IS_CRLF_AT((string),0)
334
335/*
336 * Check if the character is a line break or NUL.
337 */
338
339#define IS_BREAKZ_AT(string,offset)                                             \
340    (IS_BREAK_AT((string),(offset)) || IS_Z_AT((string),(offset)))
341
342#define IS_BREAKZ(string)   IS_BREAKZ_AT((string),0)
343
344/*
345 * Check if the character is a line break, space, or NUL.
346 */
347
348#define IS_SPACEZ_AT(string,offset)                                             \
349    (IS_SPACE_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset)))
350
351#define IS_SPACEZ(string)   IS_SPACEZ_AT((string),0)
352
353/*
354 * Check if the character is a line break, space, tab, or NUL.
355 */
356
357#define IS_BLANKZ_AT(string,offset)                                             \
358    (IS_BLANK_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset)))
359
360#define IS_BLANKZ(string)   IS_BLANKZ_AT((string),0)
361
362/*
363 * Determine the width of the character.
364 * Only correct if you know you are looking at valid UTF-8!
365 */
366
367#define WIDTH_AT(string,offset)                                                 \
368     (((string).pointer[offset] & 0x80) == 0x00 ? 1 :                           \
369      ((string).pointer[offset] & 0xE0) == 0xC0 ? 2 :                           \
370      ((string).pointer[offset] & 0xF0) == 0xE0 ? 3 :                           \
371      ((string).pointer[offset] & 0xF8) == 0xF0 ? 4 : 0)
372
373#define WIDTH(string)   WIDTH_AT((string),0)
374
375/*
376 * Move the string pointer to the next byte.
377 */
378
379#define MOVE(string)    ((string).pointer++)
380
381#define MOVEN(string,n)  ((string).pointer += n)
382
383/*
384 * Copy a byte and move the pointers of both strings.
385 */
386
387#define COPY(string_a,string_b)                                                 \
388     (*((string_a).pointer++) = *((string_b).pointer++))
389
390#define COPYN(string_a,string_b,n)                                              \
391  (memcpy(string_a.pointer, string_b.pointer, n),                               \
392   string_a.pointer += n, string_b.pointer += n)
393
394/*
395 * Stack and queue management.
396 */
397
398YAML_DECLARE(int)
399yaml_stack_extend(void **start, void **top, void **end);
400
401YAML_DECLARE(int)
402yaml_queue_extend(void **start, void **head, void **tail, void **end);
403
404#define STACK_INIT(context,stack,size)                                          \
405    (((stack).start = yaml_malloc((size)*sizeof(*(stack).start))) ?             \
406        ((stack).top = (stack).start,                                           \
407         (stack).end = (stack).start+(size),                                    \
408         1) :                                                                   \
409        ((context)->error = YAML_MEMORY_ERROR,                                  \
410         0))
411
412#define STACK_DEL(context,stack)                                                \
413    (yaml_free((stack).start),                                                  \
414     (stack).start = (stack).top = (stack).end = 0)
415
416#define STACK_EMPTY(context,stack)                                              \
417    ((stack).start == (stack).top)
418
419#define PUSH(context,stack,value)                                               \
420    (((stack).top != (stack).end                                                \
421      || yaml_stack_extend((void **)&(stack).start,                             \
422              (void **)&(stack).top, (void **)&(stack).end)) ?                  \
423        (*((stack).top++) = value,                                              \
424         1) :                                                                   \
425        ((context)->error = YAML_MEMORY_ERROR,                                  \
426         0))
427
428#define POP(context,stack)                                                      \
429    (*(--(stack).top))
430
431#define QUEUE_INIT(context,queue,size)                                          \
432    (((queue).start = yaml_malloc((size)*sizeof(*(queue).start))) ?             \
433        ((queue).head = (queue).tail = (queue).start,                           \
434         (queue).end = (queue).start+(size),                                    \
435         1) :                                                                   \
436        ((context)->error = YAML_MEMORY_ERROR,                                  \
437         0))
438
439#define QUEUE_DEL(context,queue)                                                \
440    (yaml_free((queue).start),                                                  \
441     (queue).start = (queue).head = (queue).tail = (queue).end = 0)
442
443#define QUEUE_EMPTY(context,queue)                                              \
444    ((queue).head == (queue).tail)
445
446#define ENQUEUE(context,queue,value)                                            \
447    (((queue).tail != (queue).end                                               \
448      || yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head,     \
449            (void **)&(queue).tail, (void **)&(queue).end)) ?                   \
450        (*((queue).tail++) = value,                                             \
451         1) :                                                                   \
452        ((context)->error = YAML_MEMORY_ERROR,                                  \
453         0))
454
455#define DEQUEUE(context,queue)                                                  \
456    (*((queue).head++))
457
458#define QUEUE_INSERT(context,queue,index,value)                                 \
459    (((queue).tail != (queue).end                                               \
460      || yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head,     \
461            (void **)&(queue).tail, (void **)&(queue).end)) ?                   \
462        (memmove((queue).head+(index)+1,(queue).head+(index),                   \
463            ((queue).tail-(queue).head-(index))*sizeof(*(queue).start)),        \
464         *((queue).head+(index)) = value,                                       \
465         (queue).tail++,                                                        \
466         1) :                                                                   \
467        ((context)->error = YAML_MEMORY_ERROR,                                  \
468         0))
469
470/*
471 * Token initializers.
472 */
473
474#define TOKEN_INIT(token,token_type,token_start_mark,token_end_mark)            \
475    (memset(&(token), 0, sizeof(yaml_token_t)),                                 \
476     (token).type = (token_type),                                               \
477     (token).start_mark = (token_start_mark),                                   \
478     (token).end_mark = (token_end_mark))
479
480#define STREAM_START_TOKEN_INIT(token,token_encoding,start_mark,end_mark)       \
481    (TOKEN_INIT((token),YAML_STREAM_START_TOKEN,(start_mark),(end_mark)),       \
482     (token).data.stream_start.encoding = (token_encoding))
483
484#define STREAM_END_TOKEN_INIT(token,start_mark,end_mark)                        \
485    (TOKEN_INIT((token),YAML_STREAM_END_TOKEN,(start_mark),(end_mark)))
486
487#define ALIAS_TOKEN_INIT(token,token_value,start_mark,end_mark)                 \
488    (TOKEN_INIT((token),YAML_ALIAS_TOKEN,(start_mark),(end_mark)),              \
489     (token).data.alias.value = (token_value))
490
491#define ANCHOR_TOKEN_INIT(token,token_value,start_mark,end_mark)                \
492    (TOKEN_INIT((token),YAML_ANCHOR_TOKEN,(start_mark),(end_mark)),             \
493     (token).data.anchor.value = (token_value))
494
495#define TAG_TOKEN_INIT(token,token_handle,token_suffix,start_mark,end_mark)     \
496    (TOKEN_INIT((token),YAML_TAG_TOKEN,(start_mark),(end_mark)),                \
497     (token).data.tag.handle = (token_handle),                                  \
498     (token).data.tag.suffix = (token_suffix))
499
500#define SCALAR_TOKEN_INIT(token,token_value,token_length,token_style,start_mark,end_mark)   \
501    (TOKEN_INIT((token),YAML_SCALAR_TOKEN,(start_mark),(end_mark)),             \
502     (token).data.scalar.value = (token_value),                                 \
503     (token).data.scalar.length = (token_length),                               \
504     (token).data.scalar.style = (token_style))
505
506#define VERSION_DIRECTIVE_TOKEN_INIT(token,token_major,token_minor,start_mark,end_mark)     \
507    (TOKEN_INIT((token),YAML_VERSION_DIRECTIVE_TOKEN,(start_mark),(end_mark)),  \
508     (token).data.version_directive.major = (token_major),                      \
509     (token).data.version_directive.minor = (token_minor))
510
511#define TAG_DIRECTIVE_TOKEN_INIT(token,token_handle,token_prefix,start_mark,end_mark)       \
512    (TOKEN_INIT((token),YAML_TAG_DIRECTIVE_TOKEN,(start_mark),(end_mark)),      \
513     (token).data.tag_directive.handle = (token_handle),                        \
514     (token).data.tag_directive.prefix = (token_prefix))
515
516/*
517 * Event initializers.
518 */
519
520#define EVENT_INIT(event,event_type,event_start_mark,event_end_mark)            \
521    (memset(&(event), 0, sizeof(yaml_event_t)),                                 \
522     (event).type = (event_type),                                               \
523     (event).start_mark = (event_start_mark),                                   \
524     (event).end_mark = (event_end_mark))
525
526#define STREAM_START_EVENT_INIT(event,event_encoding,start_mark,end_mark)       \
527    (EVENT_INIT((event),YAML_STREAM_START_EVENT,(start_mark),(end_mark)),       \
528     (event).data.stream_start.encoding = (event_encoding))
529
530#define STREAM_END_EVENT_INIT(event,start_mark,end_mark)                        \
531    (EVENT_INIT((event),YAML_STREAM_END_EVENT,(start_mark),(end_mark)))
532
533#define DOCUMENT_START_EVENT_INIT(event,event_version_directive,                \
534        event_tag_directives_start,event_tag_directives_end,event_implicit,start_mark,end_mark) \
535    (EVENT_INIT((event),YAML_DOCUMENT_START_EVENT,(start_mark),(end_mark)),     \
536     (event).data.document_start.version_directive = (event_version_directive), \
537     (event).data.document_start.tag_directives.start = (event_tag_directives_start),   \
538     (event).data.document_start.tag_directives.end = (event_tag_directives_end),   \
539     (event).data.document_start.implicit = (event_implicit))
540
541#define DOCUMENT_END_EVENT_INIT(event,event_implicit,start_mark,end_mark)       \
542    (EVENT_INIT((event),YAML_DOCUMENT_END_EVENT,(start_mark),(end_mark)),       \
543     (event).data.document_end.implicit = (event_implicit))
544
545#define ALIAS_EVENT_INIT(event,event_anchor,start_mark,end_mark)                \
546    (EVENT_INIT((event),YAML_ALIAS_EVENT,(start_mark),(end_mark)),              \
547     (event).data.alias.anchor = (event_anchor))
548
549#define SCALAR_EVENT_INIT(event,event_anchor,event_tag,event_value,event_length,    \
550        event_plain_implicit, event_quoted_implicit,event_style,start_mark,end_mark)    \
551    (EVENT_INIT((event),YAML_SCALAR_EVENT,(start_mark),(end_mark)),             \
552     (event).data.scalar.anchor = (event_anchor),                               \
553     (event).data.scalar.tag = (event_tag),                                     \
554     (event).data.scalar.value = (event_value),                                 \
555     (event).data.scalar.length = (event_length),                               \
556     (event).data.scalar.plain_implicit = (event_plain_implicit),               \
557     (event).data.scalar.quoted_implicit = (event_quoted_implicit),             \
558     (event).data.scalar.style = (event_style))
559
560#define SEQUENCE_START_EVENT_INIT(event,event_anchor,event_tag,                 \
561        event_implicit,event_style,start_mark,end_mark)                         \
562    (EVENT_INIT((event),YAML_SEQUENCE_START_EVENT,(start_mark),(end_mark)),     \
563     (event).data.sequence_start.anchor = (event_anchor),                       \
564     (event).data.sequence_start.tag = (event_tag),                             \
565     (event).data.sequence_start.implicit = (event_implicit),                   \
566     (event).data.sequence_start.style = (event_style))
567
568#define SEQUENCE_END_EVENT_INIT(event,start_mark,end_mark)                      \
569    (EVENT_INIT((event),YAML_SEQUENCE_END_EVENT,(start_mark),(end_mark)))
570
571#define MAPPING_START_EVENT_INIT(event,event_anchor,event_tag,                  \
572        event_implicit,event_style,start_mark,end_mark)                         \
573    (EVENT_INIT((event),YAML_MAPPING_START_EVENT,(start_mark),(end_mark)),      \
574     (event).data.mapping_start.anchor = (event_anchor),                        \
575     (event).data.mapping_start.tag = (event_tag),                              \
576     (event).data.mapping_start.implicit = (event_implicit),                    \
577     (event).data.mapping_start.style = (event_style))
578
579#define MAPPING_END_EVENT_INIT(event,start_mark,end_mark)                       \
580    (EVENT_INIT((event),YAML_MAPPING_END_EVENT,(start_mark),(end_mark)))
581
582/*
583 * Document initializer.
584 */
585
586#define DOCUMENT_INIT(document,document_nodes_start,document_nodes_end,         \
587        document_version_directive,document_tag_directives_start,               \
588        document_tag_directives_end,document_start_implicit,                    \
589        document_end_implicit,document_start_mark,document_end_mark)            \
590    (memset(&(document), 0, sizeof(yaml_document_t)),                           \
591     (document).nodes.start = (document_nodes_start),                           \
592     (document).nodes.end = (document_nodes_end),                               \
593     (document).nodes.top = (document_nodes_start),                             \
594     (document).version_directive = (document_version_directive),               \
595     (document).tag_directives.start = (document_tag_directives_start),         \
596     (document).tag_directives.end = (document_tag_directives_end),             \
597     (document).start_implicit = (document_start_implicit),                     \
598     (document).end_implicit = (document_end_implicit),                         \
599     (document).start_mark = (document_start_mark),                             \
600     (document).end_mark = (document_end_mark))
601
602/*
603 * Node initializers.
604 */
605
606#define NODE_INIT(node,node_type,node_tag,node_start_mark,node_end_mark)        \
607    (memset(&(node), 0, sizeof(yaml_node_t)),                                   \
608     (node).type = (node_type),                                                 \
609     (node).tag = (node_tag),                                                   \
610     (node).start_mark = (node_start_mark),                                     \
611     (node).end_mark = (node_end_mark))
612
613#define SCALAR_NODE_INIT(node,node_tag,node_value,node_length,                  \
614        node_style,start_mark,end_mark)                                         \
615    (NODE_INIT((node),YAML_SCALAR_NODE,(node_tag),(start_mark),(end_mark)),     \
616     (node).data.scalar.value = (node_value),                                   \
617     (node).data.scalar.length = (node_length),                                 \
618     (node).data.scalar.style = (node_style))
619
620#define SEQUENCE_NODE_INIT(node,node_tag,node_items_start,node_items_end,       \
621        node_style,start_mark,end_mark)                                         \
622    (NODE_INIT((node),YAML_SEQUENCE_NODE,(node_tag),(start_mark),(end_mark)),   \
623     (node).data.sequence.items.start = (node_items_start),                     \
624     (node).data.sequence.items.end = (node_items_end),                         \
625     (node).data.sequence.items.top = (node_items_start),                       \
626     (node).data.sequence.style = (node_style))
627
628#define MAPPING_NODE_INIT(node,node_tag,node_pairs_start,node_pairs_end,        \
629        node_style,start_mark,end_mark)                                         \
630    (NODE_INIT((node),YAML_MAPPING_NODE,(node_tag),(start_mark),(end_mark)),    \
631     (node).data.mapping.pairs.start = (node_pairs_start),                      \
632     (node).data.mapping.pairs.end = (node_pairs_end),                          \
633     (node).data.mapping.pairs.top = (node_pairs_start),                        \
634     (node).data.mapping.style = (node_style))
635