Changeset 261 for libyaml/trunk/src/yaml_private.h
- Timestamp:
- 12/25/07 18:19:23 (5 years ago)
- File:
-
- 1 edited
-
libyaml/trunk/src/yaml_private.h (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libyaml/trunk/src/yaml_private.h
r243 r261 26 26 27 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); 28 * Error management. 29 */ 30 31 #define MEMORY_ERROR_INIT(error) \ 32 (memset(&(error), 0, sizeof(error)), \ 33 (error).type = YAML_MEMORY_ERROR, \ 34 0) 35 36 #define READING_ERROR_INIT(error,error_type,error_problem,error_offset,error_value) \ 37 (memset(&(error), 0, sizeof(error)), \ 38 (error).type = (error_type), \ 39 (error).data.reading.problem = (error_problem), \ 40 (error).data.reading.offset = (error_offset), \ 41 (error).data.reading.value = (error_value), \ 42 0) 43 44 #define LOADING_ERROR_INIT(error,error_type,error_problem,error_problem_mark) \ 45 (memset(&(error), 0, sizeof(error)), \ 46 (error).type = (error_type), \ 47 (error).data.loading.context = NULL, \ 48 (error).data.loading.context_mark.index = 0, \ 49 (error).data.loading.context_mark.line = 0, \ 50 (error).data.loading.context_mark.column = 0, \ 51 (error).data.loading.problem = (error_problem), \ 52 (error).data.loading.problem_mark = (error_problem_mark), \ 53 0) 54 55 #define LOADING_ERROR_WITH_CONTEXT_INIT(error,error_type,error_context,error_context_mark,error_problem,error_problem_mark) \ 56 (memset(&(error), 0, sizeof(error)), \ 57 (error).type = (error_type), \ 58 (error).data.loading.context = (error_context), \ 59 (error).data.loading.context_mark = (error_context_mark), \ 60 (error).data.loading.problem = (error_problem), \ 61 (error).data.loading.problem_mark = (error_problem_mark), \ 62 0) 63 64 #define WRITING_ERROR_INIT(error,error_type,error_problem,error_offset) \ 65 (memset(&(error), 0, sizeof(error)), \ 66 (error).type = (error_type), \ 67 (error).data.writing.problem = (error_problem), \ 68 (error).data.writing.offset = (error_offset), \ 69 0) 70 71 #define DUMPING_ERROR_INIT(error,error_type,error_problem) \ 72 (memset(&(error), 0, sizeof(error)), \ 73 (error).type = (error_type), \ 74 (error).type.dumping.problem = (error_problem), \ 75 0) 76 77 #define READER_ERROR_INIT(error,problem,offset) \ 78 READING_ERROR_INIT(error,YAML_READER_ERROR,problem,offset,-1) 79 80 #define DECODER_ERROR_INIT(error,problem,offset,value) \ 81 READING_ERROR_INIT(error,YAML_DECODER_ERROR,problem,offset,value) 82 83 #define SCANNER_ERROR_INIT(error,problem,problem_mark) \ 84 LOADING_ERROR_INIT(error,YAML_SCANNER_ERROR,problem,problem_mark) 85 86 #define SCANNER_ERROR_WITH_CONTEXT_INIT(error,context,context_mark,problem,problem_mark) \ 87 LOADING_ERROR_WITH_CONTEXT_INIT(error,YAML_SCANNER_ERROR,context,context_mark,problem,problem_mark) 88 89 #define PARSER_ERROR_INIT(error,problem,problem_mark) \ 90 LOADING_ERROR_INIT(error,YAML_PARSER_ERROR,problem,problem_mark) 91 92 #define PARSER_ERROR_WITH_CONTEXT_INIT(error,context,context_mark,problem,problem_mark) \ 93 LOADING_ERROR_WITH_CONTEXT_INIT(error,YAML_PARSER_ERROR,context,context_mark,problem,problem_mark) 94 95 #define COMPOSER_ERROR_INIT(error,problem,problem_mark) \ 96 LOADING_ERROR_INIT(error,YAML_COMPOSER_ERROR,problem,problem_mark) 97 98 #define COMPOSER_ERROR_WITH_CONTEXT_INIT(error,context,context_mark,problem,problem_mark) \ 99 LOADING_ERROR_WITH_CONTEXT_INIT(error,YAML_COMPOSER_ERROR,context,context_mark,problem,problem_mark) 100 101 #define WRITER_ERROR_INIT(error,problem,offset) \ 102 WRITING_ERROR_INIT(error,YAML_WRITER_ERROR,problem,offset) 103 104 #define EMITTER_ERROR_INIT(error,context,problem) \ 105 DUMPING_ERROR_INIT(error,YAML_EMITTER_ERROR,problem) 106 107 #define SERIALIZER_ERROR_INIT(error,context) \ 108 DUMPING_ERROR_INIT(error,YAML_SERIALIZER_ERROR,problem) 40 109 41 110 /* … … 43 112 */ 44 113 45 #define INPUT_RAW_BUFFER_SIZE16384114 #define RAW_INPUT_BUFFER_CAPACITY 16384 46 115 47 116 /* 48 117 * The size of the input buffer. 49 118 * 50 * It should be possible to decode the whole raw buffer. 51 */ 52 53 #define INPUT_BUFFER_SIZE (INPUT_RAW_BUFFER_SIZE*3) 119 * The input buffer should be large enough to hold the content of the raw 120 * buffer after it is decoded. 121 */ 122 123 #define INPUT_BUFFER_CAPACITY (RAW_INPUT_BUFFER_CAPACITY*3) 54 124 55 125 /* … … 57 127 */ 58 128 59 #define OUTPUT_BUFFER_ SIZE16384129 #define OUTPUT_BUFFER_CAPACITY 16384 60 130 61 131 /* 62 132 * The size of the output raw buffer. 63 133 * 64 * It should be possible to encode the whole output buffer. 65 */ 66 67 #define OUTPUT_RAW_BUFFER_SIZE (OUTPUT_BUFFER_SIZE*2+2) 134 * The raw buffer should be able to hold the content of the output buffer 135 * after it is encoded. 136 */ 137 138 #define RAW_OUTPUT_BUFFER_CAPACITY (OUTPUT_BUFFER_CAPACITY*2+2) 68 139 69 140 /* … … 71 142 */ 72 143 73 #define INITIAL_STACK_ SIZE1674 #define INITIAL_QUEUE_ SIZE1675 #define INITIAL_STRING_ SIZE1676 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),\144 #define INITIAL_STACK_CAPACITY 16 145 #define INITIAL_QUEUE_CAPACITY 16 146 #define INITIAL_STRING_CAPACITY 16 147 148 /* 149 * Input/output buffer management. 150 */ 151 152 #define STORAGE_INIT(self,storage,storage_capacity) \ 153 (((storage).buffer = yaml_malloc(storage_capacity)) ? \ 154 ((storage).pointer = (storage).length = 0, \ 155 (buffer).capacity = (storage_capacity) \ 85 156 1) : \ 86 (( context)->error = YAML_MEMORY_ERROR,\157 ((self)->error.type = YAML_MEMORY_ERROR, \ 87 158 0)) 88 159 89 #define BUFFER_DEL(context,buffer)\90 (yaml_free(( buffer).start),\91 ( buffer).start = (buffer).pointer = (buffer).end= 0)160 #define STORAGE_DEL(self,storage) \ 161 (yaml_free((storage).buffer), \ 162 (storage).pointer = (storage).length = (storage).capacity = 0) 92 163 93 164 /* … … 95 166 */ 96 167 97 typedef struct {98 yaml_char_t * start;99 yaml_char_t *end;100 yaml_char_t *pointer;168 typedef struct yaml_string_s { 169 yaml_char_t *buffer; 170 size_t pointer; 171 size_t capacity; 101 172 } yaml_string_t; 102 173 103 174 YAML_DECLARE(int) 104 yaml_string_extend(yaml_char_t **start, 105 yaml_char_t **pointer, yaml_char_t **end); 175 yaml_string_extend(yaml_char_t **buffer, size_t *capacity); 106 176 107 177 YAML_DECLARE(int) 108 178 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);179 yaml_char_t **base_buffer, size_t *base_pointer, size_t *base_capacity, 180 yaml_char_t *adj_buffer, size_t adj_pointer, size_t adj_capacity); 111 181 112 182 #define NULL_STRING { NULL, NULL, NULL } 113 183 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)),\184 #define STRING(string,capacity) { (string), 0, (capacity) } 185 186 #define STRING_INIT(self,string,string_capacity) \ 187 (((string).buffer = yaml_malloc(string_capacity)) ? \ 188 ((string).pointer = 0, \ 189 (string).capacity = (string_capacity), \ 190 memset((string).buffer, 0, (string_capacity)), \ 121 191 1) : \ 122 (( context)->error = YAML_MEMORY_ERROR,\192 ((self)->error.type = YAML_MEMORY_ERROR, \ 123 193 0)) 124 194 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, \ 195 #define STRING_DEL(self,string) \ 196 (yaml_free((string).buffer), \ 197 (string).buffer = NULL, \ 198 ((string).pointer = (string).capacity = 0)) 199 200 #define STRING_EXTEND(self,string) \ 201 ((((string).pointer+5 < (string).capacity) \ 202 || yaml_string_extend(&(string).buffer, &(string).capacity)) ? \ 203 1 : \ 204 ((self)->error.type = YAML_MEMORY_ERROR, \ 205 0)) 206 207 #define CLEAR(self,string) \ 208 ((string).pointer = 0, \ 209 memset((string).buffer, 0, (string).capacity)) 210 211 #define JOIN(self,base_string,adj_string) \ 212 ((yaml_string_join(&(base_string).buffer, &(base_string).pointer, \ 213 &(base_string).capacity, (adj_string).buffer, \ 214 (adj_string).pointer, (adj_string).capacity)) ? \ 215 ((adj_string).pointer = 0, \ 143 216 1) : \ 144 (( context)->error = YAML_MEMORY_ERROR,\217 ((self)->error.type = YAML_MEMORY_ERROR, \ 145 218 0)) 146 219 … … 150 223 151 224 /* 225 * Get the octet at the specified position. 226 */ 227 228 #define OCTET_AT(string,offset) \ 229 ((string).buffer[(string).pointer+(offset)]) 230 231 /* 232 * Get the current offset. 233 */ 234 235 #define OCTET(string) OCTET_AT((string),0) 236 237 /* 152 238 * Check the octet at the specified position. 153 239 */ 154 240 155 241 #define CHECK_AT(string,octet,offset) \ 156 ( (string).pointer[offset]== (yaml_char_t)(octet))242 (OCTET_AT((string),(offset)) == (yaml_char_t)(octet)) 157 243 158 244 /* … … 168 254 169 255 #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]== '-')256 ((OCTET_AT((string),(offset)) >= (yaml_char_t) '0' && \ 257 OCTET_AT((string),(offset)) <= (yaml_char_t) '9') || \ 258 (OCTET_AT((string),(offset)) >= (yaml_char_t) 'A' && \ 259 OCTET_AT((string),(offset)) <= (yaml_char_t) 'Z') || \ 260 (OCTET_AT((string),(offset)) >= (yaml_char_t) 'a' && \ 261 OCTET_AT((string),(offset)) <= (yaml_char_t) 'z') || \ 262 OCTET_AT((string),(offset)) == '_' || \ 263 OCTET_AT((string),(offset)) == '-') 178 264 179 265 #define IS_ALPHA(string) IS_ALPHA_AT((string),0) … … 184 270 185 271 #define IS_DIGIT_AT(string,offset) \ 186 (( (string).pointer[offset] >= (yaml_char_t) '0' &&\187 (string).pointer[offset]<= (yaml_char_t) '9'))272 ((OCTET_AT((string),(offset)) >= (yaml_char_t) '0' && \ 273 OCTET_AT((string),(offset)) <= (yaml_char_t) '9')) 188 274 189 275 #define IS_DIGIT(string) IS_DIGIT_AT((string),0) … … 194 280 195 281 #define AS_DIGIT_AT(string,offset) \ 196 ( (string).pointer[offset]- (yaml_char_t) '0')282 (OCTET_AT((string),(offset)) - (yaml_char_t) '0') 197 283 198 284 #define AS_DIGIT(string) AS_DIGIT_AT((string),0) … … 203 289 204 290 #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'))291 ((OCTET_AT((string),(offset)) >= (yaml_char_t) '0' && \ 292 OCTET_AT((string),(offset)) <= (yaml_char_t) '9') || \ 293 (OCTET_AT((string),(offset)) >= (yaml_char_t) 'A' && \ 294 OCTET_AT((string),(offset)) <= (yaml_char_t) 'F') || \ 295 (OCTET_AT((string),(offset)) >= (yaml_char_t) 'a' && \ 296 OCTET_AT((string),(offset)) <= (yaml_char_t) 'f')) 211 297 212 298 #define IS_HEX(string) IS_HEX_AT((string),0) … … 217 303 218 304 #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'))305 ((OCTET_AT((string),(offset)) >= (yaml_char_t) 'A' && \ 306 OCTET_AT((string),(offset)) <= (yaml_char_t) 'F') ? \ 307 (OCTET_AT((string),(offset)) - (yaml_char_t) 'A' + 10) : \ 308 (OCTET_AT((string),(offset)) >= (yaml_char_t) 'a' && \ 309 OCTET_AT((string),(offset)) <= (yaml_char_t) 'f') ? \ 310 (OCTET_AT((string),(offset)) - (yaml_char_t) 'a' + 10) : \ 311 (OCTET_AT((string),(offset)) - (yaml_char_t) '0')) 226 312 227 313 #define AS_HEX(string) AS_HEX_AT((string),0) … … 232 318 233 319 #define IS_ASCII_AT(string,offset) \ 234 ( (string).pointer[offset]<= (yaml_char_t) '\x7F')320 (OCTET_AT((string),(offset)) <= (yaml_char_t) '\x7F') 235 321 236 322 #define IS_ASCII(string) IS_ASCII_AT((string),0) … … 241 327 242 328 #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))))329 ((OCTET_AT((string),(offset)) == 0x0A) /* . == #x0A */ \ 330 || (OCTET_AT((string),(offset)) >= 0x20 /* #x20 <= . <= #x7E */ \ 331 && OCTET_AT((string),(offset)) <= 0x7E) \ 332 || (OCTET_AT((string),(offset)) == 0xC2 /* #0xA0 <= . <= #xD7FF */ \ 333 && OCTET_AT((string),(offset)+1) >= 0xA0) \ 334 || (OCTET_AT((string),(offset)) > 0xC2 \ 335 && OCTET_AT((string),(offset)) < 0xED) \ 336 || (OCTET_AT((string),(offset)) == 0xED \ 337 && OCTET_AT((string),(offset)+1) < 0xA0) \ 338 || (OCTET_AT((string),(offset)) == 0xEE) \ 339 || (OCTET_AT((string),(offset)) == 0xEF /* #xE000 <= . <= #xFFFD */ \ 340 && !(OCTET_AT((string),(offset)+1) == 0xBB /* && . != #xFEFF */ \ 341 && OCTET_AT((string),(offset)+2) == 0xBF) \ 342 && !(OCTET_AT((string),(offset)+1) == 0xBF \ 343 && (OCTET_AT((string),(offset)+2) == 0xBE \ 344 || OCTET_AT((string),(offset)+2) == 0xBF)))) 259 345 260 346 #define IS_PRINTABLE(string) IS_PRINTABLE_AT((string),0) … … 359 445 360 446 #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)447 ((OCTET_AT((string),(offset)) & 0x80) == 0x00 ? 1 : \ 448 (OCTET_AT((string),(offset)) & 0xE0) == 0xC0 ? 2 : \ 449 (OCTET_AT((string),(offset)) & 0xF0) == 0xE0 ? 3 : \ 450 (OCTET_AT((string),(offset)) & 0xF8) == 0xF0 ? 4 : 0) 365 451 366 452 #define WIDTH(string) WIDTH_AT((string),0) … … 373 459 374 460 /* 461 * Copy a single octet and bump the pointers. 462 */ 463 464 #define COPY_OCTET(string_a,string_b) \ 465 ((string_a).buffer[(string_a).pointer++] \ 466 = (string_b).buffer[(string_b).pointer++]) 467 468 /* 375 469 * Copy a character and move the pointers of both strings. 376 470 */ 377 471 378 472 #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)473 ((OCTET(string_b) & 0x80) == 0x00 ? \ 474 COPY_OCTET((string_a),(string_b)) : \ 475 (OCTET(string_b) & 0xE0) == 0xC0 ? \ 476 (COPY_OCTET((string_a),(string_b)), \ 477 COPY_OCTET((string_a),(string_b))) : \ 478 (OCTET(string_b) & 0xF0) == 0xE0 ? \ 479 (COPY_OCTET((string_a),(string_b)), \ 480 COPY_OCTET((string_a),(string_b)), \ 481 COPY_OCTET((string_a),(string_b))) : \ 482 (OCTET(string_b) & 0xF8) == 0xF0 ? \ 483 (COPY_OCTET((string_a),(string_b)), \ 484 COPY_OCTET((string_a),(string_b)), \ 485 COPY_OCTET((string_a),(string_b)), \ 486 COPY_OCTET((string_a),(string_b))) : 0) \ 393 487 394 488 /* … … 397 491 398 492 YAML_DECLARE(int) 399 yaml_stack_extend(void ** start, void **top, void **end);493 yaml_stack_extend(void **list, size_t size, size_t *length, size_t *capacity); 400 494 401 495 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), \ 496 yaml_queue_extend(void **list, size_t size, 497 size_t *head, size_t *tail, size_t *capacity); 498 499 #define STACK_INIT(self,stack,stack_capacity) \ 500 (((stack).list = yaml_malloc((stack_capacity)*sizeof(*(stack).list))) ? \ 501 ((stack).length = 0, \ 502 (stack).capacity = (stack_capacity), \ 408 503 1) : \ 409 (( context)->error = YAML_MEMORY_ERROR,\504 ((self)->error.type = YAML_MEMORY_ERROR, \ 410 505 0)) 411 506 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, \ 507 #define STACK_DEL(self,stack) \ 508 (yaml_free((stack).list), \ 509 (stack).list = NULL, \ 510 (stack).length = (stack).capacity = 0) 511 512 #define STACK_EMPTY(self,stack) \ 513 ((stack).length == 0) 514 515 #define PUSH(self,stack,value) \ 516 (((stack).length < (stack).capacity \ 517 || yaml_stack_extend((void **)&(stack).list, sizeof(*(stack).list), \ 518 &(stack).length, &(stack).capacity)) ? \ 519 ((stack).list[(stack).length++] = (value), \ 424 520 1) : \ 425 (( context)->error = YAML_MEMORY_ERROR,\521 ((self)->error.type = YAML_MEMORY_ERROR, \ 426 522 0)) 427 523 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),\524 #define POP(self,stack) \ 525 ((stack).list[--(stack).length]) 526 527 #define QUEUE_INIT(self,queue,queue_capacity) \ 528 (((queue).list = yaml_malloc((queue_capacity)*sizeof(*(queue).list))) ? \ 529 ((queue).head = (queue).tail = 0, \ 530 (queue).capacity = (queue_capacity), \ 435 531 1) : \ 436 (( context)->error = YAML_MEMORY_ERROR,\532 ((self)->error.type = YAML_MEMORY_ERROR, \ 437 533 0)) 438 534 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) \ 535 #define QUEUE_DEL(self,queue) \ 536 (yaml_free((queue).list), \ 537 (queue).list = NULL, \ 538 (queue).head = (queue).tail = (queue).capacity = 0) 539 540 #define QUEUE_EMPTY(self,queue) \ 444 541 ((queue).head == (queue).tail) 445 542 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,\543 #define ENQUEUE(self,queue,value) \ 544 (((queue).tail != (queue).capacity \ 545 || yaml_queue_extend((void **)&(queue).list, sizeof(*(queue).list), \ 546 &(queue).head, &(queue).tail, &(queue).capacity)) ? \ 547 ((queue).list[(queue).tail++] = (value), \ 451 548 1) : \ 452 (( context)->error = YAML_MEMORY_ERROR,\549 ((self)->error.type = YAML_MEMORY_ERROR, \ 453 550 0)) 454 551 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, \ 552 #define DEQUEUE(self,queue) \ 553 ((queue).list[(queue).head++]) 554 555 #define QUEUE_INSERT(self,queue,index,value) \ 556 (((queue).tail != (queue).capacity \ 557 || yaml_queue_extend((void **)&(queue).list, sizeof(*(queue).list), \ 558 &(queue).head, &(queue).tail, &(queue).capacity)) ? \ 559 (memmove((queue).list+(queue).head+(index)+1, \ 560 (queue).list+(queue).head+(index), \ 561 ((queue).tail-(queue).head-(index))*sizeof(*(queue).list)), \ 562 (queue).list[(queue).head+(index)] = (value), \ 465 563 (queue).tail++, \ 466 564 1) : \ 467 (( context)->error = YAML_MEMORY_ERROR,\565 ((self)->error.type = YAML_MEMORY_ERROR, \ 468 566 0)) 469 567 … … 532 630 533 631 #define DOCUMENT_START_EVENT_INIT(event,event_version_directive, \ 534 event_tag_directives_start,event_tag_directives_end,event_implicit,start_mark,end_mark) \ 632 event_tag_directives_list,event_tag_directives_length, \ 633 event_tag_directives_capacity,event_is_implicit,start_mark,end_mark) \ 535 634 (EVENT_INIT((event),YAML_DOCUMENT_START_EVENT,(start_mark),(end_mark)), \ 536 635 (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) \ 636 (event).data.document_start.tag_directives.list = (event_tag_directives_list), \ 637 (event).data.document_start.tag_directives.length = (event_tag_directives_length), \ 638 (event).data.document_start.tag_directives.capacity = (event_tag_directives_capacity), \ 639 (event).data.document_start.is_implicit = (event_is_implicit)) 640 641 #define DOCUMENT_END_EVENT_INIT(event,event_is_implicit,start_mark,end_mark) \ 542 642 (EVENT_INIT((event),YAML_DOCUMENT_END_EVENT,(start_mark),(end_mark)), \ 543 (event).data.document_end.i mplicit = (event_implicit))643 (event).data.document_end.is_implicit = (event_is_implicit)) 544 644 545 645 #define ALIAS_EVENT_INIT(event,event_anchor,start_mark,end_mark) \ … … 547 647 (event).data.alias.anchor = (event_anchor)) 548 648 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) \ 649 #define SCALAR_EVENT_INIT(event,event_anchor,event_tag,event_value, \ 650 event_length,event_is_plain_implicit,event_is_quoted_implicit, \ 651 event_style,start_mark,end_mark) \ 551 652 (EVENT_INIT((event),YAML_SCALAR_EVENT,(start_mark),(end_mark)), \ 552 653 (event).data.scalar.anchor = (event_anchor), \ … … 554 655 (event).data.scalar.value = (event_value), \ 555 656 (event).data.scalar.length = (event_length), \ 556 (event).data.scalar. plain_implicit = (event_plain_implicit),\557 (event).data.scalar. quoted_implicit = (event_quoted_implicit),\657 (event).data.scalar.is_plain_implicit = (event_is_plain_implicit), \ 658 (event).data.scalar.is_quoted_implicit = (event_is_quoted_implicit), \ 558 659 (event).data.scalar.style = (event_style)) 559 660 560 661 #define SEQUENCE_START_EVENT_INIT(event,event_anchor,event_tag, \ 561 event_i mplicit,event_style,start_mark,end_mark)\662 event_is_implicit,event_style,start_mark,end_mark) \ 562 663 (EVENT_INIT((event),YAML_SEQUENCE_START_EVENT,(start_mark),(end_mark)), \ 563 664 (event).data.sequence_start.anchor = (event_anchor), \ 564 665 (event).data.sequence_start.tag = (event_tag), \ 565 (event).data.sequence_start.i mplicit = (event_implicit),\666 (event).data.sequence_start.is_implicit = (event_is_implicit), \ 566 667 (event).data.sequence_start.style = (event_style)) 567 668 … … 570 671 571 672 #define MAPPING_START_EVENT_INIT(event,event_anchor,event_tag, \ 572 event_i mplicit,event_style,start_mark,end_mark)\673 event_is_implicit,event_style,start_mark,end_mark) \ 573 674 (EVENT_INIT((event),YAML_MAPPING_START_EVENT,(start_mark),(end_mark)), \ 574 675 (event).data.mapping_start.anchor = (event_anchor), \ 575 676 (event).data.mapping_start.tag = (event_tag), \ 576 (event).data.mapping_start.i mplicit = (event_implicit),\677 (event).data.mapping_start.is_implicit = (event_is_implicit), \ 577 678 (event).data.mapping_start.style = (event_style)) 578 679 … … 634 735 (node).data.mapping.style = (node_style)) 635 736 737 /* 738 * This structure holds information about a potential simple key. 739 */ 740 741 typedef struct yaml_simple_key_s { 742 /* Is a simple key possible? */ 743 int is_possible; 744 /* Is a simple key required? */ 745 int is_required; 746 /* The number of the token. */ 747 size_t token_number; 748 /* The position mark. */ 749 yaml_mark_t mark; 750 } yaml_simple_key_t; 751 752 /* 753 * The states of the parser. 754 */ 755 756 typedef enum yaml_parser_state_e { 757 /* Expect STREAM-START. */ 758 YAML_PARSE_STREAM_START_STATE, 759 /* Expect the beginning of an implicit document. */ 760 YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE, 761 /* Expect DOCUMENT-START. */ 762 YAML_PARSE_DOCUMENT_START_STATE, 763 /* Expect the content of a document. */ 764 YAML_PARSE_DOCUMENT_CONTENT_STATE, 765 /* Expect DOCUMENT-END. */ 766 YAML_PARSE_DOCUMENT_END_STATE, 767 /* Expect a block node. */ 768 YAML_PARSE_BLOCK_NODE_STATE, 769 /* Expect a block node or indentless sequence. */ 770 YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE, 771 /* Expect a flow node. */ 772 YAML_PARSE_FLOW_NODE_STATE, 773 /* Expect the first entry of a block sequence. */ 774 YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE, 775 /* Expect an entry of a block sequence. */ 776 YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE, 777 /* Expect an entry of an indentless sequence. */ 778 YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE, 779 /* Expect the first key of a block mapping. */ 780 YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE, 781 /* Expect a block mapping key. */ 782 YAML_PARSE_BLOCK_MAPPING_KEY_STATE, 783 /* Expect a block mapping value. */ 784 YAML_PARSE_BLOCK_MAPPING_VALUE_STATE, 785 /* Expect the first entry of a flow sequence. */ 786 YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE, 787 /* Expect an entry of a flow sequence. */ 788 YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE, 789 /* Expect a key of an ordered mapping. */ 790 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE, 791 /* Expect a value of an ordered mapping. */ 792 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE, 793 /* Expect the and of an ordered mapping entry. */ 794 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE, 795 /* Expect the first key of a flow mapping. */ 796 YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE, 797 /* Expect a key of a flow mapping. */ 798 YAML_PARSE_FLOW_MAPPING_KEY_STATE, 799 /* Expect a value of a flow mapping. */ 800 YAML_PARSE_FLOW_MAPPING_VALUE_STATE, 801 /* Expect an empty value of a flow mapping. */ 802 YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE, 803 /* Expect nothing. */ 804 YAML_PARSE_END_STATE 805 } yaml_parser_state_t; 806 807 /* 808 * This structure holds aliases data. 809 */ 810 811 typedef struct yaml_alias_data_s { 812 /* The anchor. */ 813 yaml_char_t *anchor; 814 /* The node id. */ 815 int index; 816 /* The anchor mark. */ 817 yaml_mark_t mark; 818 } yaml_alias_data_t; 819 820 /* 821 * The structure that holds data used by the file and string readers. 822 */ 823 824 typedef union yaml_standard_reader_data_u { 825 /* String input data. */ 826 yaml_string_t string; 827 /* File input data. */ 828 FILE *file; 829 } yaml_standard_reader_data_t; 830 831 /* 832 * The internal parser structure. 833 */ 834 835 struct yaml_parser_s { 836 837 /* 838 * Error stuff. 839 */ 840 841 yaml_error_t error; 842 843 /* 844 * Reader stuff. 845 */ 846 847 /* The read handler. */ 848 yaml_reader_t *reader; 849 850 /* The application data to be passed to the reader. */ 851 void *reader_data; 852 853 /* Standard (string or file) input data. */ 854 yaml_standard_reader_data_t standard_reader_data; 855 856 /* EOF flag. */ 857 int is_eof; 858 859 /* The working buffer. */ 860 struct { 861 yaml_char_t *buffer; 862 size_t pointer; 863 size_t length; 864 size_t capacity; 865 } input; 866 867 /* The number of unread characters in the buffer. */ 868 size_t unread; 869 870 /* The raw buffer. */ 871 struct { 872 unsigned char *buffer; 873 size_t pointer; 874 size_t length; 875 size_t capacity; 876 } raw_input; 877 878 /* The input encoding. */ 879 yaml_encoding_t encoding; 880 881 /* The offset of the current position (in bytes). */ 882 size_t offset; 883 884 /* The mark of the current position. */ 885 yaml_mark_t mark; 886 887 /* 888 * Scanner stuff. 889 */ 890 891 /* Have we started to scan the input stream? */ 892 int is_stream_start_produced; 893 894 /* Have we reached the end of the input stream? */ 895 int is_stream_end_produced; 896 897 /* The number of unclosed '[' and '{' indicators. */ 898 int flow_level; 899 900 /* The tokens queue. */ 901 struct { 902 yaml_token_t *list; 903 size_t head; 904 size_t tail; 905 size_t capacity; 906 } tokens; 907 908 /* The number of tokens fetched from the queue. */ 909 size_t tokens_parsed; 910 911 /* Does the tokens queue contain a token ready for dequeueing. */ 912 int is_token_available; 913 914 /* The indentation levels stack. */ 915 struct { 916 int *list; 917 size_t length; 918 size_t capacity; 919 } indents; 920 921 /* The current indentation level. */ 922 int indent; 923 924 /* May a simple key occur at the current position? */ 925 int is_simple_key_allowed; 926 927 /* The stack of simple keys. */ 928 struct { 929 yaml_simple_key_t *list; 930 size_t length; 931 size_t capacity; 932 } simple_keys; 933 934 /* 935 * Parser stuff. 936 */ 937 938 /* The parser states stack. */ 939 struct { 940 yaml_parser_state_t *list; 941 size_t length; 942 size_t capacity; 943 } states; 944 945 /* The current parser state. */ 946 yaml_parser_state_t state; 947 948 /* The stack of marks. */ 949 struct { 950 yaml_mark_t *list; 951 size_t length; 952 size_t capacity; 953 } marks; 954 955 /* The list of TAG directives. */ 956 struct { 957 yaml_tag_directive_t *list; 958 size_t length; 959 size_t capacity; 960 } tag_directives; 961 962 /* 963 * Dumper stuff. 964 */ 965 966 /* The resolve handler. */ 967 yaml_resolver_t *resolver; 968 969 /* The application data to be passed to the resolver. */ 970 void *resolver_data; 971 972 /* The alias data. */ 973 struct { 974 yaml_alias_data_t *list; 975 size_t length; 976 size_t capacity; 977 } aliases; 978 979 /* The currently parsed document. */ 980 yaml_document_t *document; 981 982 }; 983 984 /* 985 * The emitter states. 986 */ 987 988 typedef enum yaml_emitter_state_e { 989 /** Expect STREAM-START. */ 990 YAML_EMIT_STREAM_START_STATE, 991 /** Expect the first DOCUMENT-START or STREAM-END. */ 992 YAML_EMIT_FIRST_DOCUMENT_START_STATE, 993 /** Expect DOCUMENT-START or STREAM-END. */ 994 YAML_EMIT_DOCUMENT_START_STATE, 995 /** Expect the content of a document. */ 996 YAML_EMIT_DOCUMENT_CONTENT_STATE, 997 /** Expect DOCUMENT-END. */ 998 YAML_EMIT_DOCUMENT_END_STATE, 999 /** Expect the first item of a flow sequence. */ 1000 YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE, 1001 /** Expect an item of a flow sequence. */ 1002 YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE, 1003 /** Expect the first key of a flow mapping. */ 1004 YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE, 1005 /** Expect a key of a flow mapping. */ 1006 YAML_EMIT_FLOW_MAPPING_KEY_STATE, 1007 /** Expect a value for a simple key of a flow mapping. */ 1008 YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE, 1009 /** Expect a value of a flow mapping. */ 1010 YAML_EMIT_FLOW_MAPPING_VALUE_STATE, 1011 /** Expect the first item of a block sequence. */ 1012 YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE, 1013 /** Expect an item of a block sequence. */ 1014 YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE, 1015 /** Expect the first key of a block mapping. */ 1016 YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE, 1017 /** Expect the key of a block mapping. */ 1018 YAML_EMIT_BLOCK_MAPPING_KEY_STATE, 1019 /** Expect a value for a simple key of a block mapping. */ 1020 YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE, 1021 /** Expect a value of a block mapping. */ 1022 YAML_EMIT_BLOCK_MAPPING_VALUE_STATE, 1023 /** Expect nothing. */ 1024 YAML_EMIT_END_STATE 1025 } yaml_emitter_state_t; 1026 1027 /* 1028 * The structure that holds data used by the file and string readers. 1029 */ 1030 1031 typedef union yaml_standard_writer_data_u { 1032 /* String output data. */ 1033 yaml_string_t string; 1034 size_t *length; 1035 /* File output data. */ 1036 FILE *file; 1037 } yaml_standard_writer_data_t; 1038 1039 /* 1040 * The internals emitter structure. 1041 */ 1042 1043 struct yaml_emitter_s { 1044 1045 /* 1046 * Error stuff. 1047 */ 1048 1049 yaml_error_t error; 1050 1051 /* 1052 * Writer stuff. 1053 */ 1054 1055 /* Write handler. */ 1056 yaml_writer_t *writer; 1057 1058 /* A pointer for passing to the white handler. */ 1059 void *writer_data; 1060 1061 /* Standard (string or file) output data. */ 1062 yaml_standard_writer_data_t standard_writer_data; 1063 1064 /* The working buffer. */ 1065 struct { 1066 yaml_char_t *buffer; 1067 size_t pointer; 1068 size_t length; 1069 size_t capacity; 1070 } output; 1071 1072 /* The raw buffer. */ 1073 struct { 1074 yaml_char_t *buffer; 1075 size_t pointer; 1076 size_t length; 1077 size_t capacity; 1078 } raw_output; 1079 1080 /* The stream encoding. */ 1081 yaml_encoding_t encoding; 1082 1083 /* 1084 * Emitter stuff. 1085 */ 1086 1087 /* If the output is in the canonical style? */ 1088 int is_canonical; 1089 /* The number of indentation spaces. */ 1090 int best_indent; 1091 /* The preferred width of the output lines. */ 1092 int best_width; 1093 /* Allow unescaped non-ASCII characters? */ 1094 int is_unicode; 1095 /* The preferred line break. */ 1096 yaml_break_t line_break; 1097 1098 /* The stack of states. */ 1099 struct { 1100 yaml_emitter_state_t *list; 1101 size_t length; 1102 size_t capacity; 1103 } states; 1104 1105 /* The current emitter state. */ 1106 yaml_emitter_state_t state; 1107 1108 /* The event queue. */ 1109 struct { 1110 yaml_event_t *list; 1111 size_t head; 1112 size_t tail; 1113 size_t capacity; 1114 } events; 1115 1116 /* The stack of indentation levels. */ 1117 struct { 1118 int *list; 1119 size_t length; 1120 size_t capacity; 1121 } indents; 1122 1123 /* The list of tag directives. */ 1124 struct { 1125 yaml_tag_directive_t *list; 1126 size_t length; 1127 size_t capacity; 1128 } tag_directives; 1129 1130 /* The current indentation level. */ 1131 int indent; 1132 1133 /* The current flow level. */ 1134 int flow_level; 1135 1136 /* Is it the document root context? */ 1137 int is_root_context; 1138 /* Is it a sequence context? */ 1139 int is_sequence_context; 1140 /* Is it a mapping context? */ 1141 int is_mapping_context; 1142 /* Is it a simple mapping key context? */ 1143 int is_simple_key_context; 1144 1145 /* The current line. */ 1146 int line; 1147 /* The current column. */ 1148 int column; 1149 /* If the last character was a whitespace? */ 1150 int whitespace; 1151 /* If the last character was an indentation character (' ', '-', '?', ':')? */ 1152 int indention; 1153 1154 /* Anchor analysis. */ 1155 struct { 1156 /* The anchor value. */ 1157 yaml_char_t *anchor; 1158 /* The anchor length. */ 1159 size_t anchor_length; 1160 /* Is it an alias? */ 1161 int is_alias; 1162 } anchor_data; 1163 1164 /* Tag analysis. */ 1165 struct { 1166 /* The tag handle. */ 1167 yaml_char_t *handle; 1168 /* The tag handle length. */ 1169 size_t handle_length; 1170 /* The tag suffix. */ 1171 yaml_char_t *suffix; 1172 /* The tag suffix length. */ 1173 size_t suffix_length; 1174 } tag_data; 1175 1176 /* Scalar analysis. */ 1177 struct { 1178 /* The scalar value. */ 1179 yaml_char_t *value; 1180 /* The scalar length. */ 1181 size_t length; 1182 /* Does the scalar contain line breaks? */ 1183 int is_multiline; 1184 /* Can the scalar be expessed in the flow plain style? */ 1185 int is_flow_plain_allowed; 1186 /* Can the scalar be expressed in the block plain style? */ 1187 int is_block_plain_allowed; 1188 /* Can the scalar be expressed in the single quoted style? */ 1189 int is_single_quoted_allowed; 1190 /* Can the scalar be expressed in the literal or folded styles? */ 1191 int is_block_allowed; 1192 /* The output style. */ 1193 yaml_scalar_style_t style; 1194 } scalar_data; 1195 1196 /* 1197 * Dumper stuff. 1198 */ 1199 1200 /* If the stream was already opened? */ 1201 int is_opened; 1202 /* If the stream was already closed? */ 1203 int is_closed; 1204 1205 /* The information associated with the document nodes. */ 1206 struct { 1207 /* The number of references. */ 1208 size_t references; 1209 /* The anchor id. */ 1210 int anchor; 1211 /* If the node has been emitted? */ 1212 int is_serialized; 1213 } *anchors; 1214 1215 /* The last assigned anchor id. */ 1216 int last_anchor_id; 1217 1218 /* The currently emitted document. */ 1219 yaml_document_t *document; 1220 1221 }; 1222 1223 /* 1224 * Reader: Ensure that the buffer contains at least `length` characters. 1225 */ 1226 1227 YAML_DECLARE(int) 1228 yaml_parser_update_buffer(yaml_parser_t *parser, size_t length); 1229 1230 /* 1231 * Scanner: Ensure that the token stack contains at least one token ready. 1232 */ 1233 1234 YAML_DECLARE(int) 1235 yaml_parser_fetch_more_tokens(yaml_parser_t *parser); 1236
Note: See TracChangeset
for help on using the changeset viewer.
