Ruby  2.0.0p451(2014-02-24revision45167)
ext/psych/yaml/yaml_private.h
Go to the documentation of this file.
00001 #ifdef RUBY_EXTCONF_H
00002 #include RUBY_EXTCONF_H
00003 #endif
00004 
00005 #if HAVE_CONFIG_H
00006 #include <config.h>
00007 #endif
00008 
00009 #include <yaml.h>
00010 
00011 #include <assert.h>
00012 #include <limits.h>
00013 #include <stddef.h>
00014 
00015 #ifndef _MSC_VER
00016 #include <stdint.h>
00017 #else
00018 #ifdef _WIN64
00019 #define PTRDIFF_MAX _I64_MAX
00020 #else
00021 #define PTRDIFF_MAX INT_MAX
00022 #endif
00023 #endif
00024 
00025 /*
00026  * Memory management.
00027  */
00028 
00029 YAML_DECLARE(void *)
00030 yaml_malloc(size_t size);
00031 
00032 YAML_DECLARE(void *)
00033 yaml_realloc(void *ptr, size_t size);
00034 
00035 YAML_DECLARE(void)
00036 yaml_free(void *ptr);
00037 
00038 YAML_DECLARE(yaml_char_t *)
00039 yaml_strdup(const yaml_char_t *);
00040 
00041 /*
00042  * Reader: Ensure that the buffer contains at least `length` characters.
00043  */
00044 
00045 YAML_DECLARE(int)
00046 yaml_parser_update_buffer(yaml_parser_t *parser, size_t length);
00047 
00048 /*
00049  * Scanner: Ensure that the token stack contains at least one token ready.
00050  */
00051 
00052 YAML_DECLARE(int)
00053 yaml_parser_fetch_more_tokens(yaml_parser_t *parser);
00054 
00055 /*
00056  * The size of the input raw buffer.
00057  */
00058 
00059 #define INPUT_RAW_BUFFER_SIZE   16384
00060 
00061 /*
00062  * The size of the input buffer.
00063  *
00064  * It should be possible to decode the whole raw buffer.
00065  */
00066 
00067 #define INPUT_BUFFER_SIZE       (INPUT_RAW_BUFFER_SIZE*3)
00068 
00069 /*
00070  * The size of the output buffer.
00071  */
00072 
00073 #define OUTPUT_BUFFER_SIZE      16384
00074 
00075 /*
00076  * The size of the output raw buffer.
00077  *
00078  * It should be possible to encode the whole output buffer.
00079  */
00080 
00081 #define OUTPUT_RAW_BUFFER_SIZE  (OUTPUT_BUFFER_SIZE*2+2)
00082 
00083 /*
00084  * The size of other stacks and queues.
00085  */
00086 
00087 #define INITIAL_STACK_SIZE  16
00088 #define INITIAL_QUEUE_SIZE  16
00089 #define INITIAL_STRING_SIZE 16
00090 
00091 /*
00092  * Buffer management.
00093  */
00094 
00095 #define BUFFER_INIT(context,buffer,size)                                        \
00096     (((buffer).start = yaml_malloc(size)) ?                                     \
00097         ((buffer).last = (buffer).pointer = (buffer).start,                     \
00098          (buffer).end = (buffer).start+(size),                                  \
00099          1) :                                                                   \
00100         ((context)->error = YAML_MEMORY_ERROR,                                  \
00101          0))
00102 
00103 #define BUFFER_DEL(context,buffer)                                              \
00104     (yaml_free((buffer).start),                                                 \
00105      (buffer).start = (buffer).pointer = (buffer).end = 0)
00106 
00107 /*
00108  * String management.
00109  */
00110 
00111 typedef struct {
00112     yaml_char_t *start;
00113     yaml_char_t *end;
00114     yaml_char_t *pointer;
00115 } yaml_string_t;
00116 
00117 YAML_DECLARE(int)
00118 yaml_string_extend(yaml_char_t **start,
00119         yaml_char_t **pointer, yaml_char_t **end);
00120 
00121 YAML_DECLARE(int)
00122 yaml_string_join(
00123         yaml_char_t **a_start, yaml_char_t **a_pointer, yaml_char_t **a_end,
00124         yaml_char_t **b_start, yaml_char_t **b_pointer, yaml_char_t **b_end);
00125 
00126 #define NULL_STRING { NULL, NULL, NULL }
00127 
00128 #define STRING(string,length)   { (string), (string)+(length), (string) }
00129 
00130 #define STRING_ASSIGN(value,string,length)                                      \
00131     ((value).start = (string),                                                  \
00132      (value).end = (string)+(length),                                           \
00133      (value).pointer = (string))
00134 
00135 #define STRING_INIT(context,string,size)                                        \
00136     (((string).start = yaml_malloc(size)) ?                                     \
00137         ((string).pointer = (string).start,                                     \
00138          (string).end = (string).start+(size),                                  \
00139          memset((string).start, 0, (size)),                                     \
00140          1) :                                                                   \
00141         ((context)->error = YAML_MEMORY_ERROR,                                  \
00142          0))
00143 
00144 #define STRING_DEL(context,string)                                              \
00145     (yaml_free((string).start),                                                 \
00146      (string).start = (string).pointer = (string).end = 0)
00147 
00148 #define STRING_EXTEND(context,string)                                           \
00149     (((string).pointer+5 < (string).end)                                        \
00150         || yaml_string_extend(&(string).start,                                  \
00151             &(string).pointer, &(string).end))
00152 
00153 #define CLEAR(context,string)                                                   \
00154     ((string).pointer = (string).start,                                         \
00155      memset((string).start, 0, (string).end-(string).start))
00156 
00157 #define JOIN(context,string_a,string_b)                                         \
00158     ((yaml_string_join(&(string_a).start, &(string_a).pointer,                  \
00159                        &(string_a).end, &(string_b).start,                      \
00160                        &(string_b).pointer, &(string_b).end)) ?                 \
00161         ((string_b).pointer = (string_b).start,                                 \
00162          1) :                                                                   \
00163         ((context)->error = YAML_MEMORY_ERROR,                                  \
00164          0))
00165 
00166 /*
00167  * String check operations.
00168  */
00169 
00170 /*
00171  * Check the octet at the specified position.
00172  */
00173 
00174 #define CHECK_AT(string,octet,offset)                                           \
00175     ((string).pointer[offset] == (yaml_char_t)(octet))
00176 
00177 /*
00178  * Check the current octet in the buffer.
00179  */
00180 
00181 #define CHECK(string,octet) CHECK_AT((string),(octet),0)
00182 
00183 /*
00184  * Check if the character at the specified position is an alphabetical
00185  * character, a digit, '_', or '-'.
00186  */
00187 
00188 #define IS_ALPHA_AT(string,offset)                                              \
00189      (((string).pointer[offset] >= (yaml_char_t) '0' &&                         \
00190        (string).pointer[offset] <= (yaml_char_t) '9') ||                        \
00191       ((string).pointer[offset] >= (yaml_char_t) 'A' &&                         \
00192        (string).pointer[offset] <= (yaml_char_t) 'Z') ||                        \
00193       ((string).pointer[offset] >= (yaml_char_t) 'a' &&                         \
00194        (string).pointer[offset] <= (yaml_char_t) 'z') ||                        \
00195       (string).pointer[offset] == '_' ||                                        \
00196       (string).pointer[offset] == '-')
00197 
00198 #define IS_ALPHA(string)    IS_ALPHA_AT((string),0)
00199 
00200 /*
00201  * Check if the character at the specified position is a digit.
00202  */
00203 
00204 #define IS_DIGIT_AT(string,offset)                                              \
00205      (((string).pointer[offset] >= (yaml_char_t) '0' &&                         \
00206        (string).pointer[offset] <= (yaml_char_t) '9'))
00207 
00208 #define IS_DIGIT(string)    IS_DIGIT_AT((string),0)
00209 
00210 /*
00211  * Get the value of a digit.
00212  */
00213 
00214 #define AS_DIGIT_AT(string,offset)                                              \
00215      ((string).pointer[offset] - (yaml_char_t) '0')
00216 
00217 #define AS_DIGIT(string)    AS_DIGIT_AT((string),0)
00218 
00219 /*
00220  * Check if the character at the specified position is a hex-digit.
00221  */
00222 
00223 #define IS_HEX_AT(string,offset)                                                \
00224      (((string).pointer[offset] >= (yaml_char_t) '0' &&                         \
00225        (string).pointer[offset] <= (yaml_char_t) '9') ||                        \
00226       ((string).pointer[offset] >= (yaml_char_t) 'A' &&                         \
00227        (string).pointer[offset] <= (yaml_char_t) 'F') ||                        \
00228       ((string).pointer[offset] >= (yaml_char_t) 'a' &&                         \
00229        (string).pointer[offset] <= (yaml_char_t) 'f'))
00230 
00231 #define IS_HEX(string)    IS_HEX_AT((string),0)
00232 
00233 /*
00234  * Get the value of a hex-digit.
00235  */
00236 
00237 #define AS_HEX_AT(string,offset)                                                \
00238       (((string).pointer[offset] >= (yaml_char_t) 'A' &&                        \
00239         (string).pointer[offset] <= (yaml_char_t) 'F') ?                        \
00240        ((string).pointer[offset] - (yaml_char_t) 'A' + 10) :                    \
00241        ((string).pointer[offset] >= (yaml_char_t) 'a' &&                        \
00242         (string).pointer[offset] <= (yaml_char_t) 'f') ?                        \
00243        ((string).pointer[offset] - (yaml_char_t) 'a' + 10) :                    \
00244        ((string).pointer[offset] - (yaml_char_t) '0'))
00245 
00246 #define AS_HEX(string)  AS_HEX_AT((string),0)
00247 
00248 /*
00249  * Check if the character is ASCII.
00250  */
00251 
00252 #define IS_ASCII_AT(string,offset)                                              \
00253     ((string).pointer[offset] <= (yaml_char_t) '\x7F')
00254 
00255 #define IS_ASCII(string)    IS_ASCII_AT((string),0)
00256 
00257 /*
00258  * Check if the character can be printed unescaped.
00259  */
00260 
00261 #define IS_PRINTABLE_AT(string,offset)                                          \
00262     (((string).pointer[offset] == 0x0A)         /* . == #x0A */                 \
00263      || ((string).pointer[offset] >= 0x20       /* #x20 <= . <= #x7E */         \
00264          && (string).pointer[offset] <= 0x7E)                                   \
00265      || ((string).pointer[offset] == 0xC2       /* #0xA0 <= . <= #xD7FF */      \
00266          && (string).pointer[offset+1] >= 0xA0)                                 \
00267      || ((string).pointer[offset] > 0xC2                                        \
00268          && (string).pointer[offset] < 0xED)                                    \
00269      || ((string).pointer[offset] == 0xED                                       \
00270          && (string).pointer[offset+1] < 0xA0)                                  \
00271      || ((string).pointer[offset] == 0xEE)                                      \
00272      || ((string).pointer[offset] == 0xEF      /* #xE000 <= . <= #xFFFD */      \
00273          && !((string).pointer[offset+1] == 0xBB        /* && . != #xFEFF */    \
00274              && (string).pointer[offset+2] == 0xBF)                             \
00275          && !((string).pointer[offset+1] == 0xBF                                \
00276              && ((string).pointer[offset+2] == 0xBE                             \
00277                  || (string).pointer[offset+2] == 0xBF))))
00278 
00279 #define IS_PRINTABLE(string)    IS_PRINTABLE_AT((string),0)
00280 
00281 /*
00282  * Check if the character at the specified position is NUL.
00283  */
00284 
00285 #define IS_Z_AT(string,offset)    CHECK_AT((string),'\0',(offset))
00286 
00287 #define IS_Z(string)    IS_Z_AT((string),0)
00288 
00289 /*
00290  * Check if the character at the specified position is BOM.
00291  */
00292 
00293 #define IS_BOM_AT(string,offset)                                                \
00294      (CHECK_AT((string),'\xEF',(offset))                                        \
00295       && CHECK_AT((string),'\xBB',(offset)+1)                                   \
00296       && CHECK_AT((string),'\xBF',(offset)+2))  /* BOM (#xFEFF) */
00297 
00298 #define IS_BOM(string)  IS_BOM_AT(string,0)
00299 
00300 /*
00301  * Check if the character at the specified position is space.
00302  */
00303 
00304 #define IS_SPACE_AT(string,offset)  CHECK_AT((string),' ',(offset))
00305 
00306 #define IS_SPACE(string)    IS_SPACE_AT((string),0)
00307 
00308 /*
00309  * Check if the character at the specified position is tab.
00310  */
00311 
00312 #define IS_TAB_AT(string,offset)    CHECK_AT((string),'\t',(offset))
00313 
00314 #define IS_TAB(string)  IS_TAB_AT((string),0)
00315 
00316 /*
00317  * Check if the character at the specified position is blank (space or tab).
00318  */
00319 
00320 #define IS_BLANK_AT(string,offset)                                              \
00321     (IS_SPACE_AT((string),(offset)) || IS_TAB_AT((string),(offset)))
00322 
00323 #define IS_BLANK(string)    IS_BLANK_AT((string),0)
00324 
00325 /*
00326  * Check if the character at the specified position is a line break.
00327  */
00328 
00329 #define IS_BREAK_AT(string,offset)                                              \
00330     (CHECK_AT((string),'\r',(offset))               /* CR (#xD)*/               \
00331      || CHECK_AT((string),'\n',(offset))            /* LF (#xA) */              \
00332      || (CHECK_AT((string),'\xC2',(offset))                                     \
00333          && CHECK_AT((string),'\x85',(offset)+1))   /* NEL (#x85) */            \
00334      || (CHECK_AT((string),'\xE2',(offset))                                     \
00335          && CHECK_AT((string),'\x80',(offset)+1)                                \
00336          && CHECK_AT((string),'\xA8',(offset)+2))   /* LS (#x2028) */           \
00337      || (CHECK_AT((string),'\xE2',(offset))                                     \
00338          && CHECK_AT((string),'\x80',(offset)+1)                                \
00339          && CHECK_AT((string),'\xA9',(offset)+2)))  /* PS (#x2029) */
00340 
00341 #define IS_BREAK(string)    IS_BREAK_AT((string),0)
00342 
00343 #define IS_CRLF_AT(string,offset)                                               \
00344      (CHECK_AT((string),'\r',(offset)) && CHECK_AT((string),'\n',(offset)+1))
00345 
00346 #define IS_CRLF(string) IS_CRLF_AT((string),0)
00347 
00348 /*
00349  * Check if the character is a line break or NUL.
00350  */
00351 
00352 #define IS_BREAKZ_AT(string,offset)                                             \
00353     (IS_BREAK_AT((string),(offset)) || IS_Z_AT((string),(offset)))
00354 
00355 #define IS_BREAKZ(string)   IS_BREAKZ_AT((string),0)
00356 
00357 /*
00358  * Check if the character is a line break, space, or NUL.
00359  */
00360 
00361 #define IS_SPACEZ_AT(string,offset)                                             \
00362     (IS_SPACE_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset)))
00363 
00364 #define IS_SPACEZ(string)   IS_SPACEZ_AT((string),0)
00365 
00366 /*
00367  * Check if the character is a line break, space, tab, or NUL.
00368  */
00369 
00370 #define IS_BLANKZ_AT(string,offset)                                             \
00371     (IS_BLANK_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset)))
00372 
00373 #define IS_BLANKZ(string)   IS_BLANKZ_AT((string),0)
00374 
00375 /*
00376  * Determine the width of the character.
00377  */
00378 
00379 #define WIDTH_AT(string,offset)                                                 \
00380      (((string).pointer[offset] & 0x80) == 0x00 ? 1 :                           \
00381       ((string).pointer[offset] & 0xE0) == 0xC0 ? 2 :                           \
00382       ((string).pointer[offset] & 0xF0) == 0xE0 ? 3 :                           \
00383       ((string).pointer[offset] & 0xF8) == 0xF0 ? 4 : 0)
00384 
00385 #define WIDTH(string)   WIDTH_AT((string),0)
00386 
00387 /*
00388  * Move the string pointer to the next character.
00389  */
00390 
00391 #define MOVE(string)    ((string).pointer += WIDTH((string)))
00392 
00393 /*
00394  * Copy a character and move the pointers of both strings.
00395  */
00396 
00397 #define COPY(string_a,string_b)                                                 \
00398     ((*(string_b).pointer & 0x80) == 0x00 ?                                     \
00399      (*((string_a).pointer++) = *((string_b).pointer++)) :                      \
00400      (*(string_b).pointer & 0xE0) == 0xC0 ?                                     \
00401      (*((string_a).pointer++) = *((string_b).pointer++),                        \
00402       *((string_a).pointer++) = *((string_b).pointer++)) :                      \
00403      (*(string_b).pointer & 0xF0) == 0xE0 ?                                     \
00404      (*((string_a).pointer++) = *((string_b).pointer++),                        \
00405       *((string_a).pointer++) = *((string_b).pointer++),                        \
00406       *((string_a).pointer++) = *((string_b).pointer++)) :                      \
00407      (*(string_b).pointer & 0xF8) == 0xF0 ?                                     \
00408      (*((string_a).pointer++) = *((string_b).pointer++),                        \
00409       *((string_a).pointer++) = *((string_b).pointer++),                        \
00410       *((string_a).pointer++) = *((string_b).pointer++),                        \
00411       *((string_a).pointer++) = *((string_b).pointer++)) : 0)
00412 
00413 /*
00414  * Stack and queue management.
00415  */
00416 
00417 YAML_DECLARE(int)
00418 yaml_stack_extend(void **start, void **top, void **end);
00419 
00420 YAML_DECLARE(int)
00421 yaml_queue_extend(void **start, void **head, void **tail, void **end);
00422 
00423 #define STACK_INIT(context,stack,size)                                          \
00424     (((stack).start = yaml_malloc((size)*sizeof(*(stack).start))) ?             \
00425         ((stack).top = (stack).start,                                           \
00426          (stack).end = (stack).start+(size),                                    \
00427          1) :                                                                   \
00428         ((context)->error = YAML_MEMORY_ERROR,                                  \
00429          0))
00430 
00431 #define STACK_DEL(context,stack)                                                \
00432     (yaml_free((stack).start),                                                  \
00433      (stack).start = (stack).top = (stack).end = 0)
00434 
00435 #define STACK_EMPTY(context,stack)                                              \
00436     ((void)(context),                                                           \
00437      ((stack).start == (stack).top))
00438 
00439 #define STACK_LIMIT(context,stack,size)                                         \
00440     ((stack).top - (stack).start < (size) ?                                     \
00441         1 :                                                                     \
00442         ((context)->error = YAML_MEMORY_ERROR,                                  \
00443          0))
00444 
00445 #define PUSH(context,stack,value)                                               \
00446     (((stack).top != (stack).end                                                \
00447       || yaml_stack_extend((void **)&(stack).start,                             \
00448               (void **)&(stack).top, (void **)&(stack).end)) ?                  \
00449         (*((stack).top++) = value,                                              \
00450          1) :                                                                   \
00451         ((context)->error = YAML_MEMORY_ERROR,                                  \
00452          0))
00453 
00454 #define POP(context,stack)                                                      \
00455     (*(--(stack).top))
00456 
00457 #define QUEUE_INIT(context,queue,size)                                          \
00458     (((queue).start = yaml_malloc((size)*sizeof(*(queue).start))) ?             \
00459         ((queue).head = (queue).tail = (queue).start,                           \
00460          (queue).end = (queue).start+(size),                                    \
00461          1) :                                                                   \
00462         ((context)->error = YAML_MEMORY_ERROR,                                  \
00463          0))
00464 
00465 #define QUEUE_DEL(context,queue)                                                \
00466     (yaml_free((queue).start),                                                  \
00467      (queue).start = (queue).head = (queue).tail = (queue).end = 0)
00468 
00469 #define QUEUE_EMPTY(context,queue)                                              \
00470     ((queue).head == (queue).tail)
00471 
00472 #define ENQUEUE(context,queue,value)                                            \
00473     (((queue).tail != (queue).end                                               \
00474       || yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head,     \
00475             (void **)&(queue).tail, (void **)&(queue).end)) ?                   \
00476         (*((queue).tail++) = value,                                             \
00477          1) :                                                                   \
00478         ((context)->error = YAML_MEMORY_ERROR,                                  \
00479          0))
00480 
00481 #define DEQUEUE(context,queue)                                                  \
00482     (*((queue).head++))
00483 
00484 #define QUEUE_INSERT(context,queue,index,value)                                 \
00485     (((queue).tail != (queue).end                                               \
00486       || yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head,     \
00487             (void **)&(queue).tail, (void **)&(queue).end)) ?                   \
00488         (memmove((queue).head+(index)+1,(queue).head+(index),                   \
00489             ((queue).tail-(queue).head-(index))*sizeof(*(queue).start)),        \
00490          *((queue).head+(index)) = value,                                       \
00491          (queue).tail++,                                                        \
00492          1) :                                                                   \
00493         ((context)->error = YAML_MEMORY_ERROR,                                  \
00494          0))
00495 
00496 /*
00497  * Token initializers.
00498  */
00499 
00500 #define TOKEN_INIT(token,token_type,token_start_mark,token_end_mark)            \
00501     (memset(&(token), 0, sizeof(yaml_token_t)),                                 \
00502      (token).type = (token_type),                                               \
00503      (token).start_mark = (token_start_mark),                                   \
00504      (token).end_mark = (token_end_mark))
00505 
00506 #define STREAM_START_TOKEN_INIT(token,token_encoding,start_mark,end_mark)       \
00507     (TOKEN_INIT((token),YAML_STREAM_START_TOKEN,(start_mark),(end_mark)),       \
00508      (token).data.stream_start.encoding = (token_encoding))
00509 
00510 #define STREAM_END_TOKEN_INIT(token,start_mark,end_mark)                        \
00511     (TOKEN_INIT((token),YAML_STREAM_END_TOKEN,(start_mark),(end_mark)))
00512 
00513 #define ALIAS_TOKEN_INIT(token,token_value,start_mark,end_mark)                 \
00514     (TOKEN_INIT((token),YAML_ALIAS_TOKEN,(start_mark),(end_mark)),              \
00515      (token).data.alias.value = (token_value))
00516 
00517 #define ANCHOR_TOKEN_INIT(token,token_value,start_mark,end_mark)                \
00518     (TOKEN_INIT((token),YAML_ANCHOR_TOKEN,(start_mark),(end_mark)),             \
00519      (token).data.anchor.value = (token_value))
00520 
00521 #define TAG_TOKEN_INIT(token,token_handle,token_suffix,start_mark,end_mark)     \
00522     (TOKEN_INIT((token),YAML_TAG_TOKEN,(start_mark),(end_mark)),                \
00523      (token).data.tag.handle = (token_handle),                                  \
00524      (token).data.tag.suffix = (token_suffix))
00525 
00526 #define SCALAR_TOKEN_INIT(token,token_value,token_length,token_style,start_mark,end_mark)   \
00527     (TOKEN_INIT((token),YAML_SCALAR_TOKEN,(start_mark),(end_mark)),             \
00528      (token).data.scalar.value = (token_value),                                 \
00529      (token).data.scalar.length = (token_length),                               \
00530      (token).data.scalar.style = (token_style))
00531 
00532 #define VERSION_DIRECTIVE_TOKEN_INIT(token,token_major,token_minor,start_mark,end_mark)     \
00533     (TOKEN_INIT((token),YAML_VERSION_DIRECTIVE_TOKEN,(start_mark),(end_mark)),  \
00534      (token).data.version_directive.major = (token_major),                      \
00535      (token).data.version_directive.minor = (token_minor))
00536 
00537 #define TAG_DIRECTIVE_TOKEN_INIT(token,token_handle,token_prefix,start_mark,end_mark)       \
00538     (TOKEN_INIT((token),YAML_TAG_DIRECTIVE_TOKEN,(start_mark),(end_mark)),      \
00539      (token).data.tag_directive.handle = (token_handle),                        \
00540      (token).data.tag_directive.prefix = (token_prefix))
00541 
00542 /*
00543  * Event initializers.
00544  */
00545 
00546 #define EVENT_INIT(event,event_type,event_start_mark,event_end_mark)            \
00547     (memset(&(event), 0, sizeof(yaml_event_t)),                                 \
00548      (event).type = (event_type),                                               \
00549      (event).start_mark = (event_start_mark),                                   \
00550      (event).end_mark = (event_end_mark))
00551 
00552 #define STREAM_START_EVENT_INIT(event,event_encoding,start_mark,end_mark)       \
00553     (EVENT_INIT((event),YAML_STREAM_START_EVENT,(start_mark),(end_mark)),       \
00554      (event).data.stream_start.encoding = (event_encoding))
00555 
00556 #define STREAM_END_EVENT_INIT(event,start_mark,end_mark)                        \
00557     (EVENT_INIT((event),YAML_STREAM_END_EVENT,(start_mark),(end_mark)))
00558 
00559 #define DOCUMENT_START_EVENT_INIT(event,event_version_directive,                \
00560         event_tag_directives_start,event_tag_directives_end,event_implicit,start_mark,end_mark) \
00561     (EVENT_INIT((event),YAML_DOCUMENT_START_EVENT,(start_mark),(end_mark)),     \
00562      (event).data.document_start.version_directive = (event_version_directive), \
00563      (event).data.document_start.tag_directives.start = (event_tag_directives_start),   \
00564      (event).data.document_start.tag_directives.end = (event_tag_directives_end),   \
00565      (event).data.document_start.implicit = (event_implicit))
00566 
00567 #define DOCUMENT_END_EVENT_INIT(event,event_implicit,start_mark,end_mark)       \
00568     (EVENT_INIT((event),YAML_DOCUMENT_END_EVENT,(start_mark),(end_mark)),       \
00569      (event).data.document_end.implicit = (event_implicit))
00570 
00571 #define ALIAS_EVENT_INIT(event,event_anchor,start_mark,end_mark)                \
00572     (EVENT_INIT((event),YAML_ALIAS_EVENT,(start_mark),(end_mark)),              \
00573      (event).data.alias.anchor = (event_anchor))
00574 
00575 #define SCALAR_EVENT_INIT(event,event_anchor,event_tag,event_value,event_length,    \
00576         event_plain_implicit, event_quoted_implicit,event_style,start_mark,end_mark)    \
00577     (EVENT_INIT((event),YAML_SCALAR_EVENT,(start_mark),(end_mark)),             \
00578      (event).data.scalar.anchor = (event_anchor),                               \
00579      (event).data.scalar.tag = (event_tag),                                     \
00580      (event).data.scalar.value = (event_value),                                 \
00581      (event).data.scalar.length = (event_length),                               \
00582      (event).data.scalar.plain_implicit = (event_plain_implicit),               \
00583      (event).data.scalar.quoted_implicit = (event_quoted_implicit),             \
00584      (event).data.scalar.style = (event_style))
00585 
00586 #define SEQUENCE_START_EVENT_INIT(event,event_anchor,event_tag,                 \
00587         event_implicit,event_style,start_mark,end_mark)                         \
00588     (EVENT_INIT((event),YAML_SEQUENCE_START_EVENT,(start_mark),(end_mark)),     \
00589      (event).data.sequence_start.anchor = (event_anchor),                       \
00590      (event).data.sequence_start.tag = (event_tag),                             \
00591      (event).data.sequence_start.implicit = (event_implicit),                   \
00592      (event).data.sequence_start.style = (event_style))
00593 
00594 #define SEQUENCE_END_EVENT_INIT(event,start_mark,end_mark)                      \
00595     (EVENT_INIT((event),YAML_SEQUENCE_END_EVENT,(start_mark),(end_mark)))
00596 
00597 #define MAPPING_START_EVENT_INIT(event,event_anchor,event_tag,                  \
00598         event_implicit,event_style,start_mark,end_mark)                         \
00599     (EVENT_INIT((event),YAML_MAPPING_START_EVENT,(start_mark),(end_mark)),      \
00600      (event).data.mapping_start.anchor = (event_anchor),                        \
00601      (event).data.mapping_start.tag = (event_tag),                              \
00602      (event).data.mapping_start.implicit = (event_implicit),                    \
00603      (event).data.mapping_start.style = (event_style))
00604 
00605 #define MAPPING_END_EVENT_INIT(event,start_mark,end_mark)                       \
00606     (EVENT_INIT((event),YAML_MAPPING_END_EVENT,(start_mark),(end_mark)))
00607 
00608 /*
00609  * Document initializer.
00610  */
00611 
00612 #define DOCUMENT_INIT(document,document_nodes_start,document_nodes_end,         \
00613         document_version_directive,document_tag_directives_start,               \
00614         document_tag_directives_end,document_start_implicit,                    \
00615         document_end_implicit,document_start_mark,document_end_mark)            \
00616     (memset(&(document), 0, sizeof(yaml_document_t)),                           \
00617      (document).nodes.start = (document_nodes_start),                           \
00618      (document).nodes.end = (document_nodes_end),                               \
00619      (document).nodes.top = (document_nodes_start),                             \
00620      (document).version_directive = (document_version_directive),               \
00621      (document).tag_directives.start = (document_tag_directives_start),         \
00622      (document).tag_directives.end = (document_tag_directives_end),             \
00623      (document).start_implicit = (document_start_implicit),                     \
00624      (document).end_implicit = (document_end_implicit),                         \
00625      (document).start_mark = (document_start_mark),                             \
00626      (document).end_mark = (document_end_mark))
00627 
00628 /*
00629  * Node initializers.
00630  */
00631 
00632 #define NODE_INIT(node,node_type,node_tag,node_start_mark,node_end_mark)        \
00633     (memset(&(node), 0, sizeof(yaml_node_t)),                                   \
00634      (node).type = (node_type),                                                 \
00635      (node).tag = (node_tag),                                                   \
00636      (node).start_mark = (node_start_mark),                                     \
00637      (node).end_mark = (node_end_mark))
00638 
00639 #define SCALAR_NODE_INIT(node,node_tag,node_value,node_length,                  \
00640         node_style,start_mark,end_mark)                                         \
00641     (NODE_INIT((node),YAML_SCALAR_NODE,(node_tag),(start_mark),(end_mark)),     \
00642      (node).data.scalar.value = (node_value),                                   \
00643      (node).data.scalar.length = (node_length),                                 \
00644      (node).data.scalar.style = (node_style))
00645 
00646 #define SEQUENCE_NODE_INIT(node,node_tag,node_items_start,node_items_end,       \
00647         node_style,start_mark,end_mark)                                         \
00648     (NODE_INIT((node),YAML_SEQUENCE_NODE,(node_tag),(start_mark),(end_mark)),   \
00649      (node).data.sequence.items.start = (node_items_start),                     \
00650      (node).data.sequence.items.end = (node_items_end),                         \
00651      (node).data.sequence.items.top = (node_items_start),                       \
00652      (node).data.sequence.style = (node_style))
00653 
00654 #define MAPPING_NODE_INIT(node,node_tag,node_pairs_start,node_pairs_end,        \
00655         node_style,start_mark,end_mark)                                         \
00656     (NODE_INIT((node),YAML_MAPPING_NODE,(node_tag),(start_mark),(end_mark)),    \
00657      (node).data.mapping.pairs.start = (node_pairs_start),                      \
00658      (node).data.mapping.pairs.end = (node_pairs_end),                          \
00659      (node).data.mapping.pairs.top = (node_pairs_start),                        \
00660      (node).data.mapping.style = (node_style))
00661 
00662