[898] | 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 | |
---|
| 15 | YAML_DECLARE(void *) |
---|
| 16 | yaml_malloc(size_t size); |
---|
| 17 | |
---|
| 18 | YAML_DECLARE(void *) |
---|
| 19 | yaml_realloc(void *ptr, size_t size); |
---|
| 20 | |
---|
| 21 | YAML_DECLARE(void) |
---|
| 22 | yaml_free(void *ptr); |
---|
| 23 | |
---|
| 24 | YAML_DECLARE(yaml_char_t *) |
---|
| 25 | yaml_strdup(const yaml_char_t *); |
---|
| 26 | |
---|
| 27 | /* |
---|
| 28 | * Reader: Ensure that the buffer contains at least `length` characters. |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | YAML_DECLARE(int) |
---|
| 32 | yaml_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 | |
---|
| 38 | YAML_DECLARE(int) |
---|
| 39 | yaml_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 | |
---|
| 97 | typedef struct { |
---|
| 98 | yaml_char_t *start; |
---|
| 99 | yaml_char_t *end; |
---|
| 100 | yaml_char_t *pointer; |
---|
| 101 | } yaml_string_t; |
---|
| 102 | |
---|
| 103 | YAML_DECLARE(int) |
---|
| 104 | yaml_string_extend(yaml_char_t **start, |
---|
| 105 | yaml_char_t **pointer, yaml_char_t **end); |
---|
| 106 | |
---|
| 107 | YAML_DECLARE(int) |
---|
| 108 | yaml_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_INIT(context,string,size) \ |
---|
| 117 | (((string).start = yaml_malloc(size)) ? \ |
---|
| 118 | ((string).pointer = (string).start, \ |
---|
| 119 | (string).end = (string).start+(size), \ |
---|
| 120 | memset((string).start, 0, (size)), \ |
---|
| 121 | 1) : \ |
---|
| 122 | ((context)->error = YAML_MEMORY_ERROR, \ |
---|
| 123 | 0)) |
---|
| 124 | |
---|
| 125 | #define STRING_DEL(context,string) \ |
---|
| 126 | (yaml_free((string).start), \ |
---|
| 127 | (string).start = (string).pointer = (string).end = 0) |
---|
| 128 | |
---|
| 129 | #define STRING_EXTEND(context,string) \ |
---|
| 130 | (((string).pointer+5 < (string).end) \ |
---|
| 131 | || yaml_string_extend(&(string).start, \ |
---|
| 132 | &(string).pointer, &(string).end)) |
---|
| 133 | |
---|
| 134 | #define CLEAR(context,string) \ |
---|
| 135 | ((string).pointer = (string).start, \ |
---|
| 136 | memset((string).start, 0, (string).end-(string).start)) |
---|
| 137 | |
---|
| 138 | #define JOIN(context,string_a,string_b) \ |
---|
| 139 | ((yaml_string_join(&(string_a).start, &(string_a).pointer, \ |
---|
| 140 | &(string_a).end, &(string_b).start, \ |
---|
| 141 | &(string_b).pointer, &(string_b).end)) ? \ |
---|
| 142 | ((string_b).pointer = (string_b).start, \ |
---|
| 143 | 1) : \ |
---|
| 144 | ((context)->error = YAML_MEMORY_ERROR, \ |
---|
| 145 | 0)) |
---|
| 146 | |
---|
| 147 | /* |
---|
| 148 | * String check operations. |
---|
| 149 | */ |
---|
| 150 | |
---|
| 151 | /* |
---|
| 152 | * Check the octet at the specified position. |
---|
| 153 | */ |
---|
| 154 | |
---|
| 155 | #define CHECK_AT(string,octet,offset) \ |
---|
| 156 | ((string).pointer[offset] == (yaml_char_t)(octet)) |
---|
| 157 | |
---|
| 158 | /* |
---|
| 159 | * Check the current octet in the buffer. |
---|
| 160 | */ |
---|
| 161 | |
---|
| 162 | #define CHECK(string,octet) CHECK_AT((string),(octet),0) |
---|
| 163 | |
---|
| 164 | /* |
---|
| 165 | * Check if the character at the specified position is an alphabetical |
---|
| 166 | * character, a digit, '_', or '-'. |
---|
| 167 | */ |
---|
| 168 | |
---|
| 169 | #define IS_ALPHA_AT(string,offset) \ |
---|
| 170 | (((string).pointer[offset] >= (yaml_char_t) '0' && \ |
---|
| 171 | (string).pointer[offset] <= (yaml_char_t) '9') || \ |
---|
| 172 | ((string).pointer[offset] >= (yaml_char_t) 'A' && \ |
---|
| 173 | (string).pointer[offset] <= (yaml_char_t) 'Z') || \ |
---|
| 174 | ((string).pointer[offset] >= (yaml_char_t) 'a' && \ |
---|
| 175 | (string).pointer[offset] <= (yaml_char_t) 'z') || \ |
---|
| 176 | (string).pointer[offset] == '_' || \ |
---|
| 177 | (string).pointer[offset] == '-') |
---|
| 178 | |
---|
| 179 | #define IS_ALPHA(string) IS_ALPHA_AT((string),0) |
---|
| 180 | |
---|
| 181 | /* |
---|
| 182 | * Check if the character at the specified position is a digit. |
---|
| 183 | */ |
---|
| 184 | |
---|
| 185 | #define IS_DIGIT_AT(string,offset) \ |
---|
| 186 | (((string).pointer[offset] >= (yaml_char_t) '0' && \ |
---|
| 187 | (string).pointer[offset] <= (yaml_char_t) '9')) |
---|
| 188 | |
---|
| 189 | #define IS_DIGIT(string) IS_DIGIT_AT((string),0) |
---|
| 190 | |
---|
| 191 | /* |
---|
| 192 | * Get the value of a digit. |
---|
| 193 | */ |
---|
| 194 | |
---|
| 195 | #define AS_DIGIT_AT(string,offset) \ |
---|
| 196 | ((string).pointer[offset] - (yaml_char_t) '0') |
---|
| 197 | |
---|
| 198 | #define AS_DIGIT(string) AS_DIGIT_AT((string),0) |
---|
| 199 | |
---|
| 200 | /* |
---|
| 201 | * Check if the character at the specified position is a hex-digit. |
---|
| 202 | */ |
---|
| 203 | |
---|
| 204 | #define IS_HEX_AT(string,offset) \ |
---|
| 205 | (((string).pointer[offset] >= (yaml_char_t) '0' && \ |
---|
| 206 | (string).pointer[offset] <= (yaml_char_t) '9') || \ |
---|
| 207 | ((string).pointer[offset] >= (yaml_char_t) 'A' && \ |
---|
| 208 | (string).pointer[offset] <= (yaml_char_t) 'F') || \ |
---|
| 209 | ((string).pointer[offset] >= (yaml_char_t) 'a' && \ |
---|
| 210 | (string).pointer[offset] <= (yaml_char_t) 'f')) |
---|
| 211 | |
---|
| 212 | #define IS_HEX(string) IS_HEX_AT((string),0) |
---|
| 213 | |
---|
| 214 | /* |
---|
| 215 | * Get the value of a hex-digit. |
---|
| 216 | */ |
---|
| 217 | |
---|
| 218 | #define AS_HEX_AT(string,offset) \ |
---|
| 219 | (((string).pointer[offset] >= (yaml_char_t) 'A' && \ |
---|
| 220 | (string).pointer[offset] <= (yaml_char_t) 'F') ? \ |
---|
| 221 | ((string).pointer[offset] - (yaml_char_t) 'A' + 10) : \ |
---|
| 222 | ((string).pointer[offset] >= (yaml_char_t) 'a' && \ |
---|
| 223 | (string).pointer[offset] <= (yaml_char_t) 'f') ? \ |
---|
| 224 | ((string).pointer[offset] - (yaml_char_t) 'a' + 10) : \ |
---|
| 225 | ((string).pointer[offset] - (yaml_char_t) '0')) |
---|
| 226 | |
---|
| 227 | #define AS_HEX(string) AS_HEX_AT((string),0) |
---|
| 228 | |
---|
| 229 | /* |
---|
| 230 | * Check if the character is ASCII. |
---|
| 231 | */ |
---|
| 232 | |
---|
| 233 | #define IS_ASCII_AT(string,offset) \ |
---|
| 234 | ((string).pointer[offset] <= (yaml_char_t) '\x7F') |
---|
| 235 | |
---|
| 236 | #define IS_ASCII(string) IS_ASCII_AT((string),0) |
---|
| 237 | |
---|
| 238 | /* |
---|
| 239 | * Check if the character can be printed unescaped. |
---|
| 240 | */ |
---|
| 241 | |
---|
| 242 | #define IS_PRINTABLE_AT(string,offset) \ |
---|
| 243 | (((string).pointer[offset] == 0x0A) /* . == #x0A */ \ |
---|
| 244 | || ((string).pointer[offset] >= 0x20 /* #x20 <= . <= #x7E */ \ |
---|
| 245 | && (string).pointer[offset] <= 0x7E) \ |
---|
| 246 | || ((string).pointer[offset] == 0xC2 /* #0xA0 <= . <= #xD7FF */ \ |
---|
| 247 | && (string).pointer[offset+1] >= 0xA0) \ |
---|
| 248 | || ((string).pointer[offset] > 0xC2 \ |
---|
| 249 | && (string).pointer[offset] < 0xED) \ |
---|
| 250 | || ((string).pointer[offset] == 0xED \ |
---|
| 251 | && (string).pointer[offset+1] < 0xA0) \ |
---|
| 252 | || ((string).pointer[offset] == 0xEE) \ |
---|
| 253 | || ((string).pointer[offset] == 0xEF /* #xE000 <= . <= #xFFFD */ \ |
---|
| 254 | && !((string).pointer[offset+1] == 0xBB /* && . != #xFEFF */ \ |
---|
| 255 | && (string).pointer[offset+2] == 0xBF) \ |
---|
| 256 | && !((string).pointer[offset+1] == 0xBF \ |
---|
| 257 | && ((string).pointer[offset+2] == 0xBE \ |
---|
| 258 | || (string).pointer[offset+2] == 0xBF)))) |
---|
| 259 | |
---|
| 260 | #define IS_PRINTABLE(string) IS_PRINTABLE_AT((string),0) |
---|
| 261 | |
---|
| 262 | /* |
---|
| 263 | * Check if the character at the specified position is NUL. |
---|
| 264 | */ |
---|
| 265 | |
---|
| 266 | #define IS_Z_AT(string,offset) CHECK_AT((string),'\0',(offset)) |
---|
| 267 | |
---|
| 268 | #define IS_Z(string) IS_Z_AT((string),0) |
---|
| 269 | |
---|
| 270 | /* |
---|
| 271 | * Check if the character at the specified position is BOM. |
---|
| 272 | */ |
---|
| 273 | |
---|
| 274 | #define IS_BOM_AT(string,offset) \ |
---|
| 275 | (CHECK_AT((string),'\xEF',(offset)) \ |
---|
| 276 | && CHECK_AT((string),'\xBB',(offset)+1) \ |
---|
| 277 | && CHECK_AT((string),'\xBF',(offset)+2)) /* BOM (#xFEFF) */ |
---|
| 278 | |
---|
| 279 | #define IS_BOM(string) IS_BOM_AT(string,0) |
---|
| 280 | |
---|
| 281 | /* |
---|
| 282 | * Check if the character at the specified position is space. |
---|
| 283 | */ |
---|
| 284 | |
---|
| 285 | #define IS_SPACE_AT(string,offset) CHECK_AT((string),' ',(offset)) |
---|
| 286 | |
---|
| 287 | #define IS_SPACE(string) IS_SPACE_AT((string),0) |
---|
| 288 | |
---|
| 289 | /* |
---|
| 290 | * Check if the character at the specified position is tab. |
---|
| 291 | */ |
---|
| 292 | |
---|
| 293 | #define IS_TAB_AT(string,offset) CHECK_AT((string),'\t',(offset)) |
---|
| 294 | |
---|
| 295 | #define IS_TAB(string) IS_TAB_AT((string),0) |
---|
| 296 | |
---|
| 297 | /* |
---|
| 298 | * Check if the character at the specified position is blank (space or tab). |
---|
| 299 | */ |
---|
| 300 | |
---|
| 301 | #define IS_BLANK_AT(string,offset) \ |
---|
| 302 | (IS_SPACE_AT((string),(offset)) || IS_TAB_AT((string),(offset))) |
---|
| 303 | |
---|
| 304 | #define IS_BLANK(string) IS_BLANK_AT((string),0) |
---|
| 305 | |
---|
| 306 | /* |
---|
| 307 | * Check if the character at the specified position is a line break. |
---|
| 308 | */ |
---|
| 309 | |
---|
| 310 | #define IS_BREAK_AT(string,offset) \ |
---|
| 311 | (CHECK_AT((string),'\r',(offset)) /* CR (#xD)*/ \ |
---|
| 312 | || CHECK_AT((string),'\n',(offset)) /* LF (#xA) */ \ |
---|
| 313 | || (CHECK_AT((string),'\xC2',(offset)) \ |
---|
| 314 | && CHECK_AT((string),'\x85',(offset)+1)) /* NEL (#x85) */ \ |
---|
| 315 | || (CHECK_AT((string),'\xE2',(offset)) \ |
---|
| 316 | && CHECK_AT((string),'\x80',(offset)+1) \ |
---|
| 317 | && CHECK_AT((string),'\xA8',(offset)+2)) /* LS (#x2028) */ \ |
---|
| 318 | || (CHECK_AT((string),'\xE2',(offset)) \ |
---|
| 319 | && CHECK_AT((string),'\x80',(offset)+1) \ |
---|
| 320 | && CHECK_AT((string),'\xA9',(offset)+2))) /* PS (#x2029) */ |
---|
| 321 | |
---|
| 322 | #define IS_BREAK(string) IS_BREAK_AT((string),0) |
---|
| 323 | |
---|
| 324 | #define IS_CRLF_AT(string,offset) \ |
---|
| 325 | (CHECK_AT((string),'\r',(offset)) && CHECK_AT((string),'\n',(offset)+1)) |
---|
| 326 | |
---|
| 327 | #define IS_CRLF(string) IS_CRLF_AT((string),0) |
---|
| 328 | |
---|
| 329 | /* |
---|
| 330 | * Check if the character is a line break or NUL. |
---|
| 331 | */ |
---|
| 332 | |
---|
| 333 | #define IS_BREAKZ_AT(string,offset) \ |
---|
| 334 | (IS_BREAK_AT((string),(offset)) || IS_Z_AT((string),(offset))) |
---|
| 335 | |
---|
| 336 | #define IS_BREAKZ(string) IS_BREAKZ_AT((string),0) |
---|
| 337 | |
---|
| 338 | /* |
---|
| 339 | * Check if the character is a line break, space, or NUL. |
---|
| 340 | */ |
---|
| 341 | |
---|
| 342 | #define IS_SPACEZ_AT(string,offset) \ |
---|
| 343 | (IS_SPACE_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset))) |
---|
| 344 | |
---|
| 345 | #define IS_SPACEZ(string) IS_SPACEZ_AT((string),0) |
---|
| 346 | |
---|
| 347 | /* |
---|
| 348 | * Check if the character is a line break, space, tab, or NUL. |
---|
| 349 | */ |
---|
| 350 | |
---|
| 351 | #define IS_BLANKZ_AT(string,offset) \ |
---|
| 352 | (IS_BLANK_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset))) |
---|
| 353 | |
---|
| 354 | #define IS_BLANKZ(string) IS_BLANKZ_AT((string),0) |
---|
| 355 | |
---|
| 356 | /* |
---|
| 357 | * Determine the width of the character. |
---|
| 358 | */ |
---|
| 359 | |
---|
| 360 | #define WIDTH_AT(string,offset) \ |
---|
| 361 | (((string).pointer[offset] & 0x80) == 0x00 ? 1 : \ |
---|
| 362 | ((string).pointer[offset] & 0xE0) == 0xC0 ? 2 : \ |
---|
| 363 | ((string).pointer[offset] & 0xF0) == 0xE0 ? 3 : \ |
---|
| 364 | ((string).pointer[offset] & 0xF8) == 0xF0 ? 4 : 0) |
---|
| 365 | |
---|
| 366 | #define WIDTH(string) WIDTH_AT((string),0) |
---|
| 367 | |
---|
| 368 | /* |
---|
| 369 | * Move the string pointer to the next character. |
---|
| 370 | */ |
---|
| 371 | |
---|
| 372 | #define MOVE(string) ((string).pointer += WIDTH((string))) |
---|
| 373 | |
---|
| 374 | /* |
---|
| 375 | * Copy a character and move the pointers of both strings. |
---|
| 376 | */ |
---|
| 377 | |
---|
| 378 | #define COPY(string_a,string_b) \ |
---|
| 379 | ((*(string_b).pointer & 0x80) == 0x00 ? \ |
---|
| 380 | (*((string_a).pointer++) = *((string_b).pointer++)) : \ |
---|
| 381 | (*(string_b).pointer & 0xE0) == 0xC0 ? \ |
---|
| 382 | (*((string_a).pointer++) = *((string_b).pointer++), \ |
---|
| 383 | *((string_a).pointer++) = *((string_b).pointer++)) : \ |
---|
| 384 | (*(string_b).pointer & 0xF0) == 0xE0 ? \ |
---|
| 385 | (*((string_a).pointer++) = *((string_b).pointer++), \ |
---|
| 386 | *((string_a).pointer++) = *((string_b).pointer++), \ |
---|
| 387 | *((string_a).pointer++) = *((string_b).pointer++)) : \ |
---|
| 388 | (*(string_b).pointer & 0xF8) == 0xF0 ? \ |
---|
| 389 | (*((string_a).pointer++) = *((string_b).pointer++), \ |
---|
| 390 | *((string_a).pointer++) = *((string_b).pointer++), \ |
---|
| 391 | *((string_a).pointer++) = *((string_b).pointer++), \ |
---|
| 392 | *((string_a).pointer++) = *((string_b).pointer++)) : 0) |
---|
| 393 | |
---|
| 394 | /* |
---|
| 395 | * Stack and queue management. |
---|
| 396 | */ |
---|
| 397 | |
---|
| 398 | YAML_DECLARE(int) |
---|
| 399 | yaml_stack_extend(void **start, void **top, void **end); |
---|
| 400 | |
---|
| 401 | YAML_DECLARE(int) |
---|
| 402 | yaml_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 | |
---|