Changeset 263
- Timestamp:
- 12/27/07 07:05:17 (5 years ago)
- Location:
- libyaml/trunk
- Files:
-
- 10 edited
-
src/api.c (modified) (4 diffs)
-
src/dumper.c (modified) (2 diffs)
-
src/emitter.c (modified) (91 diffs)
-
src/loader.c (modified) (2 diffs)
-
src/parser.c (modified) (30 diffs)
-
src/reader.c (modified) (18 diffs)
-
src/scanner.c (modified) (131 diffs)
-
src/writer.c (modified) (9 diffs)
-
src/yaml_private.h (modified) (10 diffs)
-
tests/run-scanner.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libyaml/trunk/src/api.c
r261 r263 173 173 174 174 memset(parser, 0, sizeof(yaml_parser_t)); 175 if (! BUFFER_INIT(parser, parser->raw_input, RAW_INPUT_BUFFER_CAPACITY))175 if (!STRING_INIT(parser, parser->raw_input, RAW_INPUT_BUFFER_CAPACITY)) 176 176 goto error; 177 if (! BUFFER_INIT(parser, parser->input, INPUT_BUFFER_CAPACITY))177 if (!STRING_INIT(parser, parser->input, INPUT_BUFFER_CAPACITY)) 178 178 goto error; 179 179 if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_CAPACITY)) … … 207 207 assert(parser); /* Non-NULL parser object expected. */ 208 208 209 BUFFER_DEL(parser, parser->raw_input);210 BUFFER_DEL(parser, parser->input);209 STRING_DEL(parser, parser->raw_input); 210 STRING_DEL(parser, parser->input); 211 211 while (!QUEUE_EMPTY(parser, parser->tokens)) { 212 212 yaml_token_destroy(&DEQUEUE(parser, parser->tokens)); … … 358 358 359 359 memset(emitter, 0, sizeof(yaml_emitter_t)); 360 if (! BUFFER_INIT(emitter, emitter->output, OUTPUT_BUFFER_CAPACITY))360 if (!STRING_INIT(emitter, emitter->output, OUTPUT_BUFFER_CAPACITY)) 361 361 goto error; 362 if (! BUFFER_INIT(emitter, emitter->raw_output, RAW_OUTPUT_BUFFER_CAPACITY))362 if (!STRING_INIT(emitter, emitter->raw_output, RAW_OUTPUT_BUFFER_CAPACITY)) 363 363 goto error; 364 364 if (!STACK_INIT(emitter, emitter->states, INITIAL_STACK_CAPACITY)) … … 388 388 assert(emitter); /* Non-NULL emitter object expected. */ 389 389 390 BUFFER_DEL(emitter, emitter->output);391 BUFFER_DEL(emitter, emitter->raw_output);390 STRING_DEL(emitter, emitter->output); 391 STRING_DEL(emitter, emitter->raw_output); 392 392 STACK_DEL(emitter, emitter->states); 393 393 while (!QUEUE_EMPTY(emitter, emitter->events)) { -
libyaml/trunk/src/dumper.c
r238 r263 1 1 2 2 #include "yaml_private.h" 3 4 #if 0 3 5 4 6 /* … … 393 395 } 394 396 397 #endif 398 -
libyaml/trunk/src/emitter.c
r241 r263 7 7 8 8 #define FLUSH(emitter) \ 9 ((emitter-> buffer.pointer+5 < emitter->buffer.end)\9 ((emitter->output.pointer+5 < emitter->output.capacity) \ 10 10 || yaml_emitter_flush(emitter)) 11 11 … … 16 16 #define PUT(emitter,value) \ 17 17 (FLUSH(emitter) \ 18 && ( *(emitter->buffer.pointer++) = (yaml_char_t)(value),\18 && (JOIN_OCTET(emitter->output,(yaml_char_t)(value)), \ 19 19 emitter->column ++, \ 20 20 1)) … … 27 27 (FLUSH(emitter) \ 28 28 && ((emitter->line_break == YAML_CR_BREAK ? \ 29 (*(emitter->buffer.pointer++) = (yaml_char_t) '\r') :\29 JOIN_OCTET(emitter->output, (yaml_char_t) '\r') : \ 30 30 emitter->line_break == YAML_LN_BREAK ? \ 31 (*(emitter->buffer.pointer++) = (yaml_char_t) '\n') :\31 JOIN_OCTET(emitter->output, (yaml_char_t) '\n') : \ 32 32 emitter->line_break == YAML_CRLN_BREAK ? \ 33 ( *(emitter->buffer.pointer++) = (yaml_char_t) '\r',\34 *(emitter->buffer.pointer++) = (yaml_char_t) '\n') : 0),\33 (JOIN_OCTET(emitter->output, (yaml_char_t) '\r'), \ 34 JOIN_OCTET(emitter->output, (yaml_char_t) '\n')) : 0), \ 35 35 emitter->column = 0, \ 36 36 emitter->line ++, \ … … 43 43 #define WRITE(emitter,string) \ 44 44 (FLUSH(emitter) \ 45 && (COPY(emitter-> buffer,string), \45 && (COPY(emitter->output,string), \ 46 46 emitter->column ++, \ 47 47 1)) … … 57 57 string.pointer ++, \ 58 58 1) : \ 59 (COPY(emitter-> buffer,string), \59 (COPY(emitter->output,string), \ 60 60 emitter->column = 0, \ 61 61 emitter->line ++, \ … … 74 74 75 75 static int 76 yaml_emitter_set_emitter_error(yaml_emitter_t *emitter, const char *problem);77 78 static int79 76 yaml_emitter_need_more_events(yaml_emitter_t *emitter); 80 77 … … 136 133 static int 137 134 yaml_emitter_emit_node(yaml_emitter_t *emitter, yaml_event_t *event, 138 int root, int sequence, int mapping, intsimple_key);135 int is_root, int is_sequence, int is_mapping, int is_simple_key); 139 136 140 137 static int … … 262 259 263 260 /* 264 * Set an emitter error and return 0.265 */266 267 static int268 yaml_emitter_set_emitter_error(yaml_emitter_t *emitter, const char *problem)269 {270 emitter->error = YAML_EMITTER_ERROR;271 emitter->problem = problem;272 273 return 0;274 }275 276 /*277 261 * Emit an event. 278 262 */ … … 287 271 288 272 while (!yaml_emitter_need_more_events(emitter)) { 289 if (!yaml_emitter_analyze_event(emitter, emitter->events.head)) 290 return 0; 291 if (!yaml_emitter_state_machine(emitter, emitter->events.head)) 273 if (!yaml_emitter_analyze_event(emitter, 274 emitter->events.list + emitter->events.head)) 275 return 0; 276 if (!yaml_emitter_state_machine(emitter, 277 emitter->events.list + emitter->events.head)) 292 278 return 0; 293 279 yaml_event_delete(&DEQUEUE(emitter, emitter->events)); … … 311 297 int level = 0; 312 298 int accumulate = 0; 313 yaml_event_t *event;299 size_t idx; 314 300 315 301 if (QUEUE_EMPTY(emitter, emitter->events)) 316 302 return 1; 317 303 318 switch (emitter->events. head->type) {304 switch (emitter->events.list[emitter->events.head].type) { 319 305 case YAML_DOCUMENT_START_EVENT: 320 306 accumulate = 1; … … 333 319 return 0; 334 320 335 for (event = emitter->events.head; event != emitter->events.tail; event ++) { 321 for (idx = emitter->events.head; idx < emitter->events.tail; idx ++) { 322 yaml_event_t *event = emitter->events.list+idx; 336 323 switch (event->type) { 337 324 case YAML_STREAM_START_EVENT: … … 365 352 yaml_tag_directive_t value, int allow_duplicates) 366 353 { 367 yaml_tag_directive_t *tag_directive;354 int idx; 368 355 yaml_tag_directive_t copy = { NULL, NULL }; 369 356 370 for ( tag_directive = emitter->tag_directives.start;371 tag_directive != emitter->tag_directives.top; tag_directive ++) {357 for (idx = 0; idx < emitter->tag_directives.length; idx ++) { 358 yaml_tag_directive_t *tag_directive = emitter->tag_directives.list+idx; 372 359 if (strcmp((char *)value.handle, (char *)tag_directive->handle) == 0) { 373 360 if (allow_duplicates) 374 361 return 1; 375 return yaml_emitter_set_emitter_error(emitter, 376 "duplicate %TAG directive"); 362 return EMITTER_ERROR_INIT(emitter, "duplicate %TAG directive"); 377 363 } 378 364 } … … 381 367 copy.prefix = yaml_strdup(value.prefix); 382 368 if (!copy.handle || !copy.prefix) { 383 emitter->error = YAML_MEMORY_ERROR;369 MEMORY_ERROR_INIT(emitter); 384 370 goto error; 385 371 } … … 478 464 479 465 case YAML_EMIT_END_STATE: 480 return yaml_emitter_set_emitter_error(emitter,466 return EMITTER_ERROR_INIT(emitter, 481 467 "expected nothing after STREAM-END"); 482 468 … … 527 513 emitter->line = 0; 528 514 emitter->column = 0; 529 emitter-> whitespace = 1;530 emitter->i ndention = 1;515 emitter->is_whitespace = 1; 516 emitter->is_indention = 1; 531 517 532 518 if (emitter->encoding != YAML_UTF8_ENCODING) { … … 540 526 } 541 527 542 return yaml_emitter_set_emitter_error(emitter, 543 "expected STREAM-START"); 528 return EMITTER_ERROR_INIT(emitter, "expected STREAM-START"); 544 529 } 545 530 … … 560 545 }; 561 546 yaml_tag_directive_t *tag_directive; 562 int implicit; 547 int is_implicit; 548 int idx; 563 549 564 550 if (event->data.document_start.version_directive) { … … 568 554 } 569 555 570 for (tag_directive = event->data.document_start.tag_directives.start; 571 tag_directive != event->data.document_start.tag_directives.end; 572 tag_directive ++) { 556 for (idx = 0; idx < event->data.document_start.tag_directives.length; idx++) { 557 tag_directive = event->data.document_start.tag_directives.list+idx; 573 558 if (!yaml_emitter_analyze_tag_directive(emitter, *tag_directive)) 574 559 return 0; … … 583 568 } 584 569 585 i mplicit = event->data.document_start.implicit;586 if (!first || emitter-> canonical) {587 i mplicit = 0;570 is_implicit = event->data.document_start.is_implicit; 571 if (!first || emitter->is_canonical) { 572 is_implicit = 0; 588 573 } 589 574 590 575 if (event->data.document_start.version_directive) { 591 i mplicit = 0;576 is_implicit = 0; 592 577 if (!yaml_emitter_write_indicator(emitter, "%YAML", 1, 0, 0)) 593 578 return 0; … … 598 583 } 599 584 600 if (event->data.document_start.tag_directives.start 601 != event->data.document_start.tag_directives.end) { 602 implicit = 0; 603 for (tag_directive = event->data.document_start.tag_directives.start; 604 tag_directive != event->data.document_start.tag_directives.end; 605 tag_directive ++) { 585 if (event->data.document_start.tag_directives.length) { 586 is_implicit = 0; 587 for (idx = 0; idx < event->data.document_start.tag_directives.length; 588 idx++) { 589 tag_directive = event->data.document_start.tag_directives.list+idx; 606 590 if (!yaml_emitter_write_indicator(emitter, "%TAG", 1, 0, 0)) 607 591 return 0; … … 618 602 619 603 if (yaml_emitter_check_empty_document(emitter)) { 620 i mplicit = 0;621 } 622 623 if (!i mplicit) {604 is_implicit = 0; 605 } 606 607 if (!is_implicit) { 624 608 if (!yaml_emitter_write_indent(emitter)) 625 609 return 0; 626 610 if (!yaml_emitter_write_indicator(emitter, "---", 1, 0, 0)) 627 611 return 0; 628 if (emitter-> canonical) {612 if (emitter->is_canonical) { 629 613 if (!yaml_emitter_write_indent(emitter)) 630 614 return 0; … … 647 631 } 648 632 649 return yaml_emitter_set_emitter_error(emitter, 650 "expected DOCUMENT-START or STREAM-END"); 633 return EMITTER_ERROR_INIT(emitter, "expected DOCUMENT-START or STREAM-END"); 651 634 } 652 635 … … 677 660 if (!yaml_emitter_write_indent(emitter)) 678 661 return 0; 679 if (!event->data.document_end.i mplicit) {662 if (!event->data.document_end.is_implicit) { 680 663 if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0)) 681 664 return 0; … … 698 681 } 699 682 700 return yaml_emitter_set_emitter_error(emitter, 701 "expected DOCUMENT-END"); 683 return EMITTER_ERROR_INIT(emitter, "expected DOCUMENT-END"); 702 684 } 703 685 … … 724 706 emitter->flow_level --; 725 707 emitter->indent = POP(emitter, emitter->indents); 726 if (emitter-> canonical && !first) {708 if (emitter->is_canonical && !first) { 727 709 if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0)) 728 710 return 0; … … 742 724 } 743 725 744 if (emitter-> canonical || emitter->column > emitter->best_width) {726 if (emitter->is_canonical || emitter->column > emitter->best_width) { 745 727 if (!yaml_emitter_write_indent(emitter)) 746 728 return 0; … … 773 755 emitter->flow_level --; 774 756 emitter->indent = POP(emitter, emitter->indents); 775 if (emitter-> canonical && !first) {757 if (emitter->is_canonical && !first) { 776 758 if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0)) 777 759 return 0; … … 790 772 return 0; 791 773 } 792 if (emitter-> canonical || emitter->column > emitter->best_width) {774 if (emitter->is_canonical || emitter->column > emitter->best_width) { 793 775 if (!yaml_emitter_write_indent(emitter)) 794 776 return 0; 795 777 } 796 778 797 if (!emitter-> canonical && yaml_emitter_check_simple_key(emitter))779 if (!emitter->is_canonical && yaml_emitter_check_simple_key(emitter)) 798 780 { 799 781 if (!PUSH(emitter, emitter->states, … … 828 810 } 829 811 else { 830 if (emitter-> canonical || emitter->column > emitter->best_width) {812 if (emitter->is_canonical || emitter->column > emitter->best_width) { 831 813 if (!yaml_emitter_write_indent(emitter)) 832 814 return 0; … … 851 833 { 852 834 if (!yaml_emitter_increase_indent(emitter, 0, 853 (emitter-> mapping_context && !emitter->indention)))835 (emitter->is_mapping_context && !emitter->is_indention))) 854 836 return 0; 855 837 } … … 950 932 static int 951 933 yaml_emitter_emit_node(yaml_emitter_t *emitter, yaml_event_t *event, 952 int root, int sequence, int mapping, intsimple_key)953 { 954 emitter-> root_context =root;955 emitter-> sequence_context =sequence;956 emitter-> mapping_context =mapping;957 emitter-> simple_key_context =simple_key;934 int is_root, int is_sequence, int is_mapping, int is_simple_key) 935 { 936 emitter->is_root_context = is_root; 937 emitter->is_sequence_context = is_sequence; 938 emitter->is_mapping_context = is_mapping; 939 emitter->is_simple_key_context = is_simple_key; 958 940 959 941 switch (event->type) … … 972 954 973 955 default: 974 return yaml_emitter_set_emitter_error(emitter,956 return EMITTER_ERROR_INIT(emitter, 975 957 "expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS"); 976 958 } … … 1028 1010 return 0; 1029 1011 1030 if (emitter->flow_level || emitter-> canonical1012 if (emitter->flow_level || emitter->is_canonical 1031 1013 || event->data.sequence_start.style == YAML_FLOW_SEQUENCE_STYLE 1032 1014 || yaml_emitter_check_empty_sequence(emitter)) { … … 1052 1034 return 0; 1053 1035 1054 if (emitter->flow_level || emitter-> canonical1036 if (emitter->flow_level || emitter->is_canonical 1055 1037 || event->data.mapping_start.style == YAML_FLOW_MAPPING_STYLE 1056 1038 || yaml_emitter_check_empty_mapping(emitter)) { … … 1084 1066 return 0; 1085 1067 1086 return (emitter->events.head[0].type == YAML_SEQUENCE_START_EVENT 1087 && emitter->events.head[1].type == YAML_SEQUENCE_END_EVENT); 1068 return (emitter->events.list[emitter->events.head].type 1069 == YAML_SEQUENCE_START_EVENT && 1070 emitter->events.list[emitter->events.head+1].type 1071 == YAML_SEQUENCE_END_EVENT); 1088 1072 } 1089 1073 … … 1098 1082 return 0; 1099 1083 1100 return (emitter->events.head[0].type == YAML_MAPPING_START_EVENT 1101 && emitter->events.head[1].type == YAML_MAPPING_END_EVENT); 1084 return (emitter->events.list[emitter->events.head].type 1085 == YAML_MAPPING_START_EVENT && 1086 emitter->events.list[emitter->events.head+1].type 1087 == YAML_MAPPING_END_EVENT); 1102 1088 } 1103 1089 … … 1109 1095 yaml_emitter_check_simple_key(yaml_emitter_t *emitter) 1110 1096 { 1111 yaml_event_t *event = emitter->events. head;1097 yaml_event_t *event = emitter->events.list + emitter->events.head; 1112 1098 size_t length = 0; 1113 1099 … … 1119 1105 1120 1106 case YAML_SCALAR_EVENT: 1121 if (emitter->scalar_data. multiline)1107 if (emitter->scalar_data.is_multiline) 1122 1108 return 0; 1123 1109 length += emitter->anchor_data.anchor_length … … 1163 1149 int no_tag = (!emitter->tag_data.handle && !emitter->tag_data.suffix); 1164 1150 1165 if (no_tag && !event->data.scalar. plain_implicit1166 && !event->data.scalar. quoted_implicit) {1167 return yaml_emitter_set_emitter_error(emitter,1151 if (no_tag && !event->data.scalar.is_plain_implicit 1152 && !event->data.scalar.is_quoted_implicit) { 1153 return EMITTER_ERROR_INIT(emitter, 1168 1154 "neither tag nor implicit flags are specified"); 1169 1155 } … … 1172 1158 style = YAML_PLAIN_SCALAR_STYLE; 1173 1159 1174 if (emitter-> canonical)1160 if (emitter->is_canonical) 1175 1161 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1176 1162 1177 if (emitter-> simple_key_context && emitter->scalar_data.multiline)1163 if (emitter->is_simple_key_context && emitter->scalar_data.is_multiline) 1178 1164 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1179 1165 1180 1166 if (style == YAML_PLAIN_SCALAR_STYLE) 1181 1167 { 1182 if ((emitter->flow_level && !emitter->scalar_data. flow_plain_allowed)1183 || (!emitter->flow_level && !emitter->scalar_data. block_plain_allowed))1168 if ((emitter->flow_level && !emitter->scalar_data.is_flow_plain_allowed) 1169 || (!emitter->flow_level && !emitter->scalar_data.is_block_plain_allowed)) 1184 1170 style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 1185 1171 if (!emitter->scalar_data.length 1186 && (emitter->flow_level || emitter-> simple_key_context))1172 && (emitter->flow_level || emitter->is_simple_key_context)) 1187 1173 style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 1188 if (no_tag && !event->data.scalar. plain_implicit)1174 if (no_tag && !event->data.scalar.is_plain_implicit) 1189 1175 style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 1190 1176 } … … 1192 1178 if (style == YAML_SINGLE_QUOTED_SCALAR_STYLE) 1193 1179 { 1194 if (!emitter->scalar_data. single_quoted_allowed)1180 if (!emitter->scalar_data.is_single_quoted_allowed) 1195 1181 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1196 1182 } … … 1198 1184 if (style == YAML_LITERAL_SCALAR_STYLE || style == YAML_FOLDED_SCALAR_STYLE) 1199 1185 { 1200 if (!emitter->scalar_data. block_allowed1201 || emitter->flow_level || emitter-> simple_key_context)1186 if (!emitter->scalar_data.is_block_allowed 1187 || emitter->flow_level || emitter->is_simple_key_context) 1202 1188 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1203 1189 } 1204 1190 1205 if (no_tag && !event->data.scalar. quoted_implicit1191 if (no_tag && !event->data.scalar.is_quoted_implicit 1206 1192 && style != YAML_PLAIN_SCALAR_STYLE) 1207 1193 { … … 1226 1212 1227 1213 if (!yaml_emitter_write_indicator(emitter, 1228 (emitter->anchor_data. alias ? "*" : "&"), 1, 0, 0))1214 (emitter->anchor_data.is_alias ? "*" : "&"), 1, 0, 0)) 1229 1215 return 0; 1230 1216 … … 1280 1266 return yaml_emitter_write_plain_scalar(emitter, 1281 1267 emitter->scalar_data.value, emitter->scalar_data.length, 1282 !emitter-> simple_key_context);1268 !emitter->is_simple_key_context); 1283 1269 1284 1270 case YAML_SINGLE_QUOTED_SCALAR_STYLE: 1285 1271 return yaml_emitter_write_single_quoted_scalar(emitter, 1286 1272 emitter->scalar_data.value, emitter->scalar_data.length, 1287 !emitter-> simple_key_context);1273 !emitter->is_simple_key_context); 1288 1274 1289 1275 case YAML_DOUBLE_QUOTED_SCALAR_STYLE: 1290 1276 return yaml_emitter_write_double_quoted_scalar(emitter, 1291 1277 emitter->scalar_data.value, emitter->scalar_data.length, 1292 !emitter-> simple_key_context);1278 !emitter->is_simple_key_context); 1293 1279 1294 1280 case YAML_LITERAL_SCALAR_STYLE: … … 1316 1302 { 1317 1303 if (version_directive.major != 1 || version_directive.minor != 1) { 1318 return yaml_emitter_set_emitter_error(emitter, 1319 "incompatible %YAML directive"); 1304 return EMITTER_ERROR_INIT(emitter, "incompatible %YAML directive"); 1320 1305 } 1321 1306 … … 1336 1321 strlen((char *)tag_directive.prefix)); 1337 1322 1338 if (handle.start == handle.end) { 1339 return yaml_emitter_set_emitter_error(emitter, 1340 "tag handle must not be empty"); 1341 } 1342 1343 if (handle.start[0] != '!') { 1344 return yaml_emitter_set_emitter_error(emitter, 1345 "tag handle must start with '!'"); 1346 } 1347 1348 if (handle.end[-1] != '!') { 1349 return yaml_emitter_set_emitter_error(emitter, 1350 "tag handle must end with '!'"); 1323 if (!handle.capacity) { 1324 return EMITTER_ERROR_INIT(emitter, "tag handle must not be empty"); 1325 } 1326 1327 if (handle.buffer[0] != '!') { 1328 return EMITTER_ERROR_INIT(emitter, "tag handle must start with '!'"); 1329 } 1330 1331 if (handle.buffer[handle.capacity-1] != '!') { 1332 return EMITTER_ERROR_INIT(emitter, "tag handle must end with '!'"); 1351 1333 } 1352 1334 1353 1335 handle.pointer ++; 1354 1336 1355 while (handle.pointer < handle. end-1) {1337 while (handle.pointer < handle.capacity-1) { 1356 1338 if (!IS_ALPHA(handle)) { 1357 return yaml_emitter_set_emitter_error(emitter,1339 return EMITTER_ERROR_INIT(emitter, 1358 1340 "tag handle must contain alphanumerical characters only"); 1359 1341 } … … 1361 1343 } 1362 1344 1363 if (prefix.start == prefix.end) { 1364 return yaml_emitter_set_emitter_error(emitter, 1365 "tag prefix must not be empty"); 1345 if (!prefix.capacity) { 1346 return EMITTER_ERROR_INIT(emitter, "tag prefix must not be empty"); 1366 1347 } 1367 1348 … … 1375 1356 static int 1376 1357 yaml_emitter_analyze_anchor(yaml_emitter_t *emitter, 1377 yaml_char_t *anchor, int alias)1358 yaml_char_t *anchor, int is_alias) 1378 1359 { 1379 1360 yaml_string_t string = STRING(anchor, strlen((char *)anchor)); 1380 1361 1381 if ( string.start == string.end) {1382 return yaml_emitter_set_emitter_error(emitter,alias ?1362 if (!string.capacity) { 1363 return EMITTER_ERROR_INIT(emitter, is_alias ? 1383 1364 "alias value must not be empty" : 1384 1365 "anchor value must not be empty"); 1385 1366 } 1386 1367 1387 while (string.pointer != string.end) {1368 while (string.pointer < string.capacity) { 1388 1369 if (!IS_ALPHA(string)) { 1389 return yaml_emitter_set_emitter_error(emitter,alias ?1370 return EMITTER_ERROR_INIT(emitter, is_alias ? 1390 1371 "alias value must contain alphanumerical characters only" : 1391 1372 "anchor value must contain alphanumerical characters only"); … … 1394 1375 } 1395 1376 1396 emitter->anchor_data.anchor = string. start;1397 emitter->anchor_data.anchor_length = string. end - string.start;1398 emitter->anchor_data. alias =alias;1377 emitter->anchor_data.anchor = string.buffer; 1378 emitter->anchor_data.anchor_length = string.capacity; 1379 emitter->anchor_data.is_alias = is_alias; 1399 1380 1400 1381 return 1; … … 1410 1391 { 1411 1392 yaml_string_t string = STRING(tag, strlen((char *)tag)); 1412 yaml_tag_directive_t *tag_directive; 1413 1414 if (string.start == string.end) { 1415 return yaml_emitter_set_emitter_error(emitter, 1416 "tag value must not be empty"); 1417 } 1418 1419 for (tag_directive = emitter->tag_directives.start; 1420 tag_directive != emitter->tag_directives.top; tag_directive ++) { 1393 size_t idx; 1394 1395 if (!string.capacity) { 1396 return EMITTER_ERROR_INIT(emitter, "tag value must not be empty"); 1397 } 1398 1399 for (idx = 0; idx < emitter->tag_directives.length; idx ++) { 1400 yaml_tag_directive_t *tag_directive = emitter->tag_directives.list+idx; 1421 1401 size_t prefix_length = strlen((char *)tag_directive->prefix); 1422 if (prefix_length < (size_t)(string.end - string.start)1423 && strncmp((char *)tag_directive->prefix, (char *)string. start,1402 if (prefix_length < string.capacity 1403 && strncmp((char *)tag_directive->prefix, (char *)string.buffer, 1424 1404 prefix_length) == 0) 1425 1405 { … … 1427 1407 emitter->tag_data.handle_length = 1428 1408 strlen((char *)tag_directive->handle); 1429 emitter->tag_data.suffix = string.start + prefix_length; 1430 emitter->tag_data.suffix_length = 1431 (string.end - string.start) - prefix_length; 1409 emitter->tag_data.suffix = string.buffer + prefix_length; 1410 emitter->tag_data.suffix_length = string.capacity - prefix_length; 1432 1411 return 1; 1433 1412 } 1434 1413 } 1435 1414 1436 emitter->tag_data.suffix = string. start;1437 emitter->tag_data.suffix_length = string. end - string.start;1415 emitter->tag_data.suffix = string.buffer; 1416 emitter->tag_data.suffix_length = string.capacity; 1438 1417 1439 1418 return 1; … … 1474 1453 emitter->scalar_data.length = length; 1475 1454 1476 if ( string.start == string.end)1477 { 1478 emitter->scalar_data. multiline = 0;1479 emitter->scalar_data. flow_plain_allowed = 0;1480 emitter->scalar_data. block_plain_allowed = 1;1481 emitter->scalar_data. single_quoted_allowed = 1;1482 emitter->scalar_data. block_allowed = 0;1455 if (!string.capacity) 1456 { 1457 emitter->scalar_data.is_multiline = 0; 1458 emitter->scalar_data.is_flow_plain_allowed = 0; 1459 emitter->scalar_data.is_block_plain_allowed = 1; 1460 emitter->scalar_data.is_single_quoted_allowed = 1; 1461 emitter->scalar_data.is_block_allowed = 0; 1483 1462 1484 1463 return 1; … … 1498 1477 followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 1499 1478 1500 while (string.pointer != string.end)1501 { 1502 if ( string.start ==string.pointer)1479 while (string.pointer < string.capacity) 1480 { 1481 if (!string.pointer) 1503 1482 { 1504 1483 if (CHECK(string, '#') || CHECK(string, ',') … … 1548 1527 1549 1528 if (!IS_PRINTABLE(string) 1550 || (!IS_ASCII(string) && !emitter-> unicode)) {1529 || (!IS_ASCII(string) && !emitter->is_unicode)) { 1551 1530 special_characters = 1; 1552 1531 } … … 1559 1538 { 1560 1539 spaces = 1; 1561 if ( string.start ==string.pointer) {1540 if (!string.pointer) { 1562 1541 leading = 1; 1563 1542 } … … 1570 1549 } 1571 1550 breaks = 1; 1572 if ( string.start ==string.pointer) {1551 if (!string.pointer) { 1573 1552 leading = 1; 1574 1553 } … … 1605 1584 } 1606 1585 1607 if ((spaces || breaks) && string.pointer == string. end-1)1586 if ((spaces || breaks) && string.pointer == string.capacity-1) 1608 1587 { 1609 1588 if (spaces && breaks) { … … 1626 1605 preceeded_by_space = IS_BLANKZ(string); 1627 1606 MOVE(string); 1628 if (string.pointer != string.end) {1607 if (string.pointer < string.capacity) { 1629 1608 followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 1630 1609 } 1631 1610 } 1632 1611 1633 emitter->scalar_data. multiline = line_breaks;1634 1635 emitter->scalar_data. flow_plain_allowed = 1;1636 emitter->scalar_data. block_plain_allowed = 1;1637 emitter->scalar_data. single_quoted_allowed = 1;1638 emitter->scalar_data. block_allowed = 1;1612 emitter->scalar_data.is_multiline = line_breaks; 1613 1614 emitter->scalar_data.is_flow_plain_allowed = 1; 1615 emitter->scalar_data.is_block_plain_allowed = 1; 1616 emitter->scalar_data.is_single_quoted_allowed = 1; 1617 emitter->scalar_data.is_block_allowed = 1; 1639 1618 1640 1619 if (leading_spaces || leading_breaks || trailing_spaces) { 1641 emitter->scalar_data. flow_plain_allowed = 0;1642 emitter->scalar_data. block_plain_allowed = 0;1643 emitter->scalar_data. block_allowed = 0;1620 emitter->scalar_data.is_flow_plain_allowed = 0; 1621 emitter->scalar_data.is_block_plain_allowed = 0; 1622 emitter->scalar_data.is_block_allowed = 0; 1644 1623 } 1645 1624 1646 1625 if (trailing_breaks) { 1647 emitter->scalar_data. flow_plain_allowed = 0;1648 emitter->scalar_data. block_plain_allowed = 0;1626 emitter->scalar_data.is_flow_plain_allowed = 0; 1627 emitter->scalar_data.is_block_plain_allowed = 0; 1649 1628 } 1650 1629 1651 1630 if (inline_breaks_spaces) { 1652 emitter->scalar_data. flow_plain_allowed = 0;1653 emitter->scalar_data. block_plain_allowed = 0;1654 emitter->scalar_data. single_quoted_allowed = 0;1631 emitter->scalar_data.is_flow_plain_allowed = 0; 1632 emitter->scalar_data.is_block_plain_allowed = 0; 1633 emitter->scalar_data.is_single_quoted_allowed = 0; 1655 1634 } 1656 1635 1657 1636 if (mixed_breaks_spaces || special_characters) { 1658 emitter->scalar_data. flow_plain_allowed = 0;1659 emitter->scalar_data. block_plain_allowed = 0;1660 emitter->scalar_data. single_quoted_allowed = 0;1661 emitter->scalar_data. block_allowed = 0;1637 emitter->scalar_data.is_flow_plain_allowed = 0; 1638 emitter->scalar_data.is_block_plain_allowed = 0; 1639 emitter->scalar_data.is_single_quoted_allowed = 0; 1640 emitter->scalar_data.is_block_allowed = 0; 1662 1641 } 1663 1642 1664 1643 if (line_breaks) { 1665 emitter->scalar_data. flow_plain_allowed = 0;1666 emitter->scalar_data. block_plain_allowed = 0;1644 emitter->scalar_data.is_flow_plain_allowed = 0; 1645 emitter->scalar_data.is_block_plain_allowed = 0; 1667 1646 } 1668 1647 1669 1648 if (flow_indicators) { 1670 emitter->scalar_data. flow_plain_allowed = 0;1649 emitter->scalar_data.is_flow_plain_allowed = 0; 1671 1650 } 1672 1651 1673 1652 if (block_indicators) { 1674 emitter->scalar_data. block_plain_allowed = 0;1653 emitter->scalar_data.is_block_plain_allowed = 0; 1675 1654 } 1676 1655 … … 1709 1688 return 0; 1710 1689 } 1711 if (event->data.scalar.tag && (emitter-> canonical ||1712 (!event->data.scalar. plain_implicit1713 && !event->data.scalar. quoted_implicit))) {1690 if (event->data.scalar.tag && (emitter->is_canonical || 1691 (!event->data.scalar.is_plain_implicit 1692 && !event->data.scalar.is_quoted_implicit))) { 1714 1693 if (!yaml_emitter_analyze_tag(emitter, event->data.scalar.tag)) 1715 1694 return 0; … … 1726 1705 return 0; 1727 1706 } 1728 if (event->data.sequence_start.tag && (emitter-> canonical ||1729 !event->data.sequence_start.i mplicit)) {1707 if (event->data.sequence_start.tag && (emitter->is_canonical || 1708 !event->data.sequence_start.is_implicit)) { 1730 1709 if (!yaml_emitter_analyze_tag(emitter, 1731 1710 event->data.sequence_start.tag)) … … 1740 1719 return 0; 1741 1720 } 1742 if (event->data.mapping_start.tag && (emitter-> canonical ||1743 !event->data.mapping_start.i mplicit)) {1721 if (event->data.mapping_start.tag && (emitter->is_canonical || 1722 !event->data.mapping_start.is_implicit)) { 1744 1723 if (!yaml_emitter_analyze_tag(emitter, 1745 1724 event->data.mapping_start.tag)) … … 1762 1741 if (!FLUSH(emitter)) return 0; 1763 1742 1764 *(emitter->buffer.pointer++) = (yaml_char_t) '\xEF';1765 *(emitter->buffer.pointer++) = (yaml_char_t) '\xBB';1766 *(emitter->buffer.pointer++) = (yaml_char_t) '\xBF';1743 JOIN_OCTET(emitter->output, (yaml_char_t) '\xEF'); 1744 JOIN_OCTET(emitter->output, (yaml_char_t) '\xBB'); 1745 JOIN_OCTET(emitter->output, (yaml_char_t) '\xBF'); 1767 1746 1768 1747 return 1; … … 1774 1753 int indent = (emitter->indent >= 0) ? emitter->indent : 0; 1775 1754 1776 if (!emitter->i ndention || emitter->column > indent1777 || (emitter->column == indent && !emitter-> whitespace)) {1755 if (!emitter->is_indention || emitter->column > indent 1756 || (emitter->column == indent && !emitter->is_whitespace)) { 1778 1757 if (!PUT_BREAK(emitter)) return 0; 1779 1758 } … … 1783 1762 } 1784 1763 1785 emitter-> whitespace = 1;1786 emitter->i ndention = 1;1764 emitter->is_whitespace = 1; 1765 emitter->is_indention = 1; 1787 1766 1788 1767 return 1; … … 1796 1775 yaml_string_t string = STRING((yaml_char_t *)indicator, strlen(indicator)); 1797 1776 1798 if (need_whitespace && !emitter-> whitespace) {1777 if (need_whitespace && !emitter->is_whitespace) { 1799 1778 if (!PUT(emitter, ' ')) return 0; 1800 1779 } 1801 1780 1802 while (string.pointer != string.end) {1781 while (string.pointer < string.capacity) { 1803 1782 if (!WRITE(emitter, string)) return 0; 1804 1783 } 1805 1784 1806 emitter-> whitespace = is_whitespace;1807 emitter->i ndention = (emitter->indention && is_indention);1785 emitter->is_whitespace = is_whitespace; 1786 emitter->is_indention = (emitter->is_indention && is_indention); 1808 1787 1809 1788 return 1; … … 1816 1795 yaml_string_t string = STRING(value, length); 1817 1796 1818 while (string.pointer != string.end) {1797 while (string.pointer < string.capacity) { 1819 1798 if (!WRITE(emitter, string)) return 0; 1820 1799 } 1821 1800 1822 emitter-> whitespace = 0;1823 emitter->i ndention = 0;1801 emitter->is_whitespace = 0; 1802 emitter->is_indention = 0; 1824 1803 1825 1804 return 1; … … 1832 1811 yaml_string_t string = STRING(value, length); 1833 1812 1834 if (!emitter-> whitespace) {1813 if (!emitter->is_whitespace) { 1835 1814 if (!PUT(emitter, ' ')) return 0; 1836 1815 } 1837 1816 1838 while (string.pointer != string.end) {1817 while (string.pointer < string.capacity) { 1839 1818 if (!WRITE(emitter, string)) return 0; 1840 1819 } 1841 1820 1842 emitter-> whitespace = 0;1843 emitter->i ndention = 0;1821 emitter->is_whitespace = 0; 1822 emitter->is_indention = 0; 1844 1823 1845 1824 return 1; … … 1853 1832 yaml_string_t string = STRING(value, length); 1854 1833 1855 if (need_whitespace && !emitter-> whitespace) {1834 if (need_whitespace && !emitter->is_whitespace) { 1856 1835 if (!PUT(emitter, ' ')) return 0; 1857 1836 } 1858 1837 1859 while (string.pointer != string.end) {1838 while (string.pointer < string.capacity) { 1860 1839 if (IS_ALPHA(string) 1861 1840 || CHECK(string, ';') || CHECK(string, '/') … … 1875 1854 unsigned int value; 1876 1855 while (width --) { 1877 value = *(string.pointer++); 1856 value = OCTET(string); 1857 string.pointer ++; 1878 1858 if (!PUT(emitter, '%')) return 0; 1879 1859 if (!PUT(emitter, (value >> 4) … … 1887 1867 } 1888 1868 1889 emitter-> whitespace = 0;1890 emitter->i ndention = 0;1869 emitter->is_whitespace = 0; 1870 emitter->is_indention = 0; 1891 1871 1892 1872 return 1; … … 1901 1881 int breaks = 0; 1902 1882 1903 if (!emitter-> whitespace) {1883 if (!emitter->is_whitespace) { 1904 1884 if (!PUT(emitter, ' ')) return 0; 1905 1885 } 1906 1886 1907 while (string.pointer != string.end)1887 while (string.pointer < string.capacity) 1908 1888 { 1909 1889 if (IS_SPACE(string)) … … 1926 1906 } 1927 1907 if (!WRITE_BREAK(emitter, string)) return 0; 1928 emitter->i ndention = 1;1908 emitter->is_indention = 1; 1929 1909 breaks = 1; 1930 1910 } … … 1935 1915 } 1936 1916 if (!WRITE(emitter, string)) return 0; 1937 emitter->i ndention = 0;1917 emitter->is_indention = 0; 1938 1918 spaces = 0; 1939 1919 breaks = 0; … … 1941 1921 } 1942 1922 1943 emitter-> whitespace = 0;1944 emitter->i ndention = 0;1923 emitter->is_whitespace = 0; 1924 emitter->is_indention = 0; 1945 1925 1946 1926 return 1; … … 1958 1938 return 0; 1959 1939 1960 while (string.pointer != string.end)1940 while (string.pointer < string.capacity) 1961 1941 { 1962 1942 if (IS_SPACE(string)) … … 1964 1944 if (allow_breaks && !spaces 1965 1945 && emitter->column > emitter->best_width 1966 && string.pointer != string.start1967 && string.pointer != string. end- 11946 && string.pointer != 0 1947 && string.pointer != string.capacity - 1 1968 1948 && !IS_SPACE_AT(string, 1)) { 1969 1949 if (!yaml_emitter_write_indent(emitter)) return 0; … … 1981 1961 } 1982 1962 if (!WRITE_BREAK(emitter, string)) return 0; 1983 emitter->i ndention = 1;1963 emitter->is_indention = 1; 1984 1964 breaks = 1; 1985 1965 } … … 1993 1973 } 1994 1974 if (!WRITE(emitter, string)) return 0; 1995 emitter->i ndention = 0;1975 emitter->is_indention = 0; 1996 1976 spaces = 0; 1997 1977 breaks = 0; … … 2002 1982 return 0; 2003 1983 2004 emitter-> whitespace = 0;2005 emitter->i ndention = 0;1984 emitter->is_whitespace = 0; 1985 emitter->is_indention = 0; 2006 1986 2007 1987 return 1; … … 2018 1998 return 0; 2019 1999 2020 while (string.pointer != string.end)2021 { 2022 if (!IS_PRINTABLE(string) || (!emitter-> unicode && !IS_ASCII(string))2000 while (string.pointer < string.capacity) 2001 { 2002 if (!IS_PRINTABLE(string) || (!emitter->is_unicode && !IS_ASCII(string)) 2023 2003 || IS_BOM(string) || IS_BREAK(string) 2024 2004 || CHECK(string, '"') || CHECK(string, '\\')) … … 2027 2007 unsigned int width; 2028 2008 unsigned int value; 2029 int k;2030 2031 octet = string.pointer[0];2009 int idx; 2010 2011 octet = OCTET(string); 2032 2012 width = (octet & 0x80) == 0x00 ? 1 : 2033 2013 (octet & 0xE0) == 0xC0 ? 2 : … … 2038 2018 (octet & 0xF0) == 0xE0 ? octet & 0x0F : 2039 2019 (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; 2040 for ( k = 1; k < (int)width; k++) {2041 octet = string.pointer[k];2020 for (idx = 1; idx < width; idx ++) { 2021 octet = OCTET_AT(string, idx); 2042 2022 value = (value << 6) + (octet & 0x3F); 2043 2023 } … … 2121 2101 width = 8; 2122 2102 } 2123 for ( k = (width-1)*4; k >= 0; k-= 4) {2124 int digit = (value >> k) & 0x0F;2103 for (idx = (width-1)*4; idx >= 0; idx -= 4) { 2104 int digit = (value >> idx) & 0x0F; 2125 2105 if (!PUT(emitter, digit + (digit < 10 ? '0' : 'A'-10))) 2126 2106 return 0; … … 2133 2113 if (allow_breaks && !spaces 2134 2114 && emitter->column > emitter->best_width 2135 && string.pointer != string.start2136 && string.pointer != string. end- 1) {2115 && string.pointer != 0 2116 && string.pointer != string.capacity - 1) { 2137 2117 if (!yaml_emitter_write_indent(emitter)) return 0; 2138 2118 if (IS_SPACE_AT(string, 1)) { … … 2156 2136 return 0; 2157 2137 2158 emitter-> whitespace = 0;2159 emitter->i ndention = 0;2138 emitter->is_whitespace = 0; 2139 emitter->is_indention = 0; 2160 2140 2161 2141 return 1; … … 2166 2146 yaml_string_t string) 2167 2147 { 2168 string.pointer = string. end;2169 if ( string.start ==string.pointer)2148 string.pointer = string.capacity; 2149 if (!string.pointer) 2170 2150 return -1; 2171 2151 do { 2172 2152 string.pointer --; 2173 } while (( *string.pointer& 0xC0) == 0x80);2153 } while ((OCTET(string) & 0xC0) == 0x80); 2174 2154 if (!IS_BREAK(string)) 2175 2155 return -1; 2176 if ( string.start ==string.pointer)2156 if (!string.pointer) 2177 2157 return 0; 2178 2158 do { 2179 2159 string.pointer --; 2180 } while (( *string.pointer& 0xC0) == 0x80);2160 } while ((OCTET(string) & 0xC0) == 0x80); 2181 2161 if (!IS_BREAK(string)) 2182 2162 return 0; … … 2199 2179 return 0; 2200 2180 2201 while (string.pointer != string.end)2181 while (string.pointer < string.capacity) 2202 2182 { 2203 2183 if (IS_BREAK(string)) 2204 2184 { 2205 2185 if (!WRITE_BREAK(emitter, string)) return 0; 2206 emitter->i ndention = 1;2186 emitter->is_indention = 1; 2207 2187 breaks = 1; 2208 2188 } … … 2213 2193 } 2214 2194 if (!WRITE(emitter, string)) return 0; 2215 emitter->i ndention = 0;2195 emitter->is_indention = 0; 2216 2196 breaks = 0; 2217 2197 } … … 2236 2216 return 0; 2237 2217 2238 while (string.pointer != string.end)2218 while (string.pointer < string.capacity) 2239 2219 { 2240 2220 if (IS_BREAK(string)) … … 2250 2230 } 2251 2231 if (!WRITE_BREAK(emitter, string)) return 0; 2252 emitter->i ndention = 1;2232 emitter->is_indention = 1; 2253 2233 breaks = 1; 2254 2234 } … … 2267 2247 if (!WRITE(emitter, string)) return 0; 2268 2248 } 2269 emitter->i ndention = 0;2249 emitter->is_indention = 0; 2270 2250 breaks = 0; 2271 2251 } -
libyaml/trunk/src/loader.c
r243 r263 1 1 2 2 #include "yaml_private.h" 3 4 #if 0 3 5 4 6 /* … … 429 431 } 430 432 433 #endif 434 -
libyaml/trunk/src/parser.c
r250 r263 47 47 48 48 #define PEEK_TOKEN(parser) \ 49 ((parser-> token_available || yaml_parser_fetch_more_tokens(parser)) ?\50 parser->tokens. head : NULL)49 ((parser->is_token_available || yaml_parser_fetch_more_tokens(parser)) ? \ 50 parser->tokens.list + parser->tokens.head : NULL) 51 51 52 52 /* … … 55 55 56 56 #define SKIP_TOKEN(parser) \ 57 (parser-> token_available = 0,\57 (parser->is_token_available = 0, \ 58 58 parser->tokens_parsed ++, \ 59 parser-> stream_end_produced =\60 (parser->tokens. head->type == YAML_STREAM_END_TOKEN),\59 parser->is_stream_end_produced = \ 60 (parser->tokens.list[parser->tokens.head].type == YAML_STREAM_END_TOKEN), \ 61 61 parser->tokens.head ++) 62 62 … … 69 69 70 70 /* 71 * Error handling.72 */73 74 static int75 yaml_parser_set_parser_error(yaml_parser_t *parser,76 const char *problem, yaml_mark_t problem_mark);77 78 static int79 yaml_parser_set_parser_error_context(yaml_parser_t *parser,80 const char *context, yaml_mark_t context_mark,81 const char *problem, yaml_mark_t problem_mark);82 83 /*84 71 * State functions. 85 72 */ … … 156 143 yaml_parser_process_directives(yaml_parser_t *parser, 157 144 yaml_version_directive_t **version_directive_ref, 158 yaml_tag_directive_t **tag_directives_start_ref, 159 yaml_tag_directive_t **tag_directives_end_ref); 145 yaml_tag_directive_t **tag_directives_list_ref, 146 size_t *tag_directives_length_ref, 147 size_t *tag_directives_capacity_ref); 160 148 161 149 static int … … 179 167 /* No events after the end of the stream or error. */ 180 168 181 if (parser-> stream_end_produced || parser->error ||182 parser->state == YAML_PARSE_END_STATE) {169 if (parser->is_stream_end_produced || parser->error.type 170 || parser->state == YAML_PARSE_END_STATE) { 183 171 return 1; 184 172 } … … 188 176 return yaml_parser_state_machine(parser, event); 189 177 } 190 191 /*192 * Set parser error.193 */194 195 static int196 yaml_parser_set_parser_error(yaml_parser_t *parser,197 const char *problem, yaml_mark_t problem_mark)198 {199 parser->error = YAML_PARSER_ERROR;200 parser->problem = problem;201 parser->problem_mark = problem_mark;202 203 return 0;204 }205 206 static int207 yaml_parser_set_parser_error_context(yaml_parser_t *parser,208 const char *context, yaml_mark_t context_mark,209 const char *problem, yaml_mark_t problem_mark)210 {211 parser->error = YAML_PARSER_ERROR;212 parser->context = context;213 parser->context_mark = context_mark;214 parser->problem = problem;215 parser->problem_mark = problem_mark;216 217 return 0;218 }219 220 178 221 179 /* … … 319 277 320 278 if (token->type != YAML_STREAM_START_TOKEN) { 321 return yaml_parser_set_parser_error(parser,279 return PARSER_ERROR_INIT(parser, 322 280 "did not found expected <stream-start>", token->start_mark); 323 281 } … … 346 304 yaml_version_directive_t *version_directive = NULL; 347 305 struct { 348 yaml_tag_directive_t *start; 349 yaml_tag_directive_t *end; 350 } tag_directives = { NULL, NULL }; 306 yaml_tag_directive_t *list; 307 size_t length; 308 size_t capacity; 309 } tag_directives = { NULL, 0, 0 }; 351 310 352 311 token = PEEK_TOKEN(parser); … … 371 330 token->type != YAML_STREAM_END_TOKEN) 372 331 { 373 if (!yaml_parser_process_directives(parser, NULL, NULL, NULL ))332 if (!yaml_parser_process_directives(parser, NULL, NULL, NULL, NULL)) 374 333 return 0; 375 334 if (!PUSH(parser, parser->states, YAML_PARSE_DOCUMENT_END_STATE)) 376 335 return 0; 377 336 parser->state = YAML_PARSE_BLOCK_NODE_STATE; 378 DOCUMENT_START_EVENT_INIT(*event, NULL, NULL, NULL, 1,337 DOCUMENT_START_EVENT_INIT(*event, NULL, NULL, 0, 0, 1, 379 338 token->start_mark, token->start_mark); 380 339 return 1; … … 388 347 start_mark = token->start_mark; 389 348 if (!yaml_parser_process_directives(parser, &version_directive, 390 &tag_directives.start, &tag_directives.end)) 349 &tag_directives.list, &tag_directives.length, 350 &tag_directives.capacity)) 391 351 return 0; 392 352 token = PEEK_TOKEN(parser); 393 353 if (!token) goto error; 394 354 if (token->type != YAML_DOCUMENT_START_TOKEN) { 395 yaml_parser_set_parser_error(parser,355 PARSER_ERROR_INIT(parser, 396 356 "did not found expected <document start>", token->start_mark); 397 357 goto error; … … 402 362 end_mark = token->end_mark; 403 363 DOCUMENT_START_EVENT_INIT(*event, version_directive, 404 tag_directives.start, tag_directives.end, 0, 364 tag_directives.list, tag_directives.length, 365 tag_directives.capacity, 0, 405 366 start_mark, end_mark); 406 367 SKIP_TOKEN(parser); 407 368 version_directive = NULL; 408 tag_directives.start = tag_directives.end = NULL; 369 tag_directives.list = NULL; 370 tag_directives.length = tag_directives.capacity = 0; 409 371 return 1; 410 372 } … … 422 384 error: 423 385 yaml_free(version_directive); 424 while ( tag_directives.start != tag_directives.end) {425 yaml_ free(tag_directives.end[-1].handle);426 yaml_free(tag_directive s.end[-1].prefix);427 tag_directives.end --;428 } 429 yaml_free(tag_directives.start);386 while (!STACK_EMPTY(parser, tag_directives)) { 387 yaml_tag_directive_t tag_directive = POP(parser, tag_directives); 388 yaml_free(tag_directive.handle); 389 yaml_free(tag_directive.prefix); 390 } 391 STACK_DEL(parser, tag_directives); 430 392 return 0; 431 393 } … … 599 561 } 600 562 else { 601 yaml_tag_directive_t *tag_directive; 602 for (tag_directive = parser->tag_directives.start; 603 tag_directive != parser->tag_directives.top; 604 tag_directive ++) { 563 int idx; 564 for (idx = 0; idx < parser->tag_directives.length; idx++) { 565 yaml_tag_directive_t *tag_directive = parser->tag_directives.list + idx; 605 566 if (strcmp((char *)tag_directive->handle, (char *)tag_handle) == 0) { 606 567 size_t prefix_len = strlen((char *)tag_directive->prefix); … … 608 569 tag = yaml_malloc(prefix_len+suffix_len+1); 609 570 if (!tag) { 610 parser->error = YAML_MEMORY_ERROR;571 MEMORY_ERROR_INIT(parser); 611 572 goto error; 612 573 } … … 621 582 } 622 583 if (!tag) { 623 yaml_parser_set_parser_error_context(parser,584 PARSER_ERROR_WITH_CONTEXT_INIT(parser, 624 585 "while parsing a node", start_mark, 625 586 "found undefined tag handle", tag_mark); … … 688 649 yaml_char_t *value = yaml_malloc(1); 689 650 if (!value) { 690 parser->error = YAML_MEMORY_ERROR;651 MEMORY_ERROR_INIT(parser); 691 652 goto error; 692 653 } … … 699 660 } 700 661 else { 701 yaml_parser_set_parser_error_context(parser,662 PARSER_ERROR_WITH_CONTEXT_INIT(parser, 702 663 (block ? "while parsing a block node" 703 664 : "while parsing a flow node"), start_mark, … … 770 731 else 771 732 { 772 return yaml_parser_set_parser_error_context(parser,733 return PARSER_ERROR_WITH_CONTEXT_INIT(parser, 773 734 "while parsing a block collection", POP(parser, parser->marks), 774 735 "did not found expected '-' indicator", token->start_mark); … … 880 841 else 881 842 { 882 return yaml_parser_set_parser_error_context(parser,843 return PARSER_ERROR_WITH_CONTEXT_INIT(parser, 883 844 "while parsing a block mapping", POP(parser, parser->marks), 884 845 "did not found expected key", token->start_mark); … … 974 935 } 975 936 else { 976 return yaml_parser_set_parser_error_context(parser,937 return PARSER_ERROR_WITH_CONTEXT_INIT(parser, 977 938 "while parsing a flow sequence", POP(parser, parser->marks), 978 939 "did not found expected ',' or ']'", token->start_mark); … … 1126 1087 } 1127 1088 else { 1128 return yaml_parser_set_parser_error_context(parser,1089 return PARSER_ERROR_WITH_CONTEXT_INIT(parser, 1129 1090 "while parsing a flow mapping", POP(parser, parser->marks), 1130 1091 "did not found expected ',' or '}'", token->start_mark); … … 1215 1176 value = yaml_malloc(1); 1216 1177 if (!value) { 1217 parser->error = YAML_MEMORY_ERROR; 1218 return 0; 1178 return MEMORY_ERROR_INIT(parser); 1219 1179 } 1220 1180 value[0] = '\0'; … … 1233 1193 yaml_parser_process_directives(yaml_parser_t *parser, 1234 1194 yaml_version_directive_t **version_directive_ref, 1235 yaml_tag_directive_t **tag_directives_start_ref, 1236 yaml_tag_directive_t **tag_directives_end_ref) 1195 yaml_tag_directive_t **tag_directives_list_ref, 1196 size_t *tag_directives_length_ref, 1197 size_t *tag_directives_capacity_ref) 1237 1198 { 1238 1199 yaml_tag_directive_t default_tag_directives[] = { … … 1244 1205 yaml_version_directive_t *version_directive = NULL; 1245 1206 struct { 1246 yaml_tag_directive_t * start;1247 yaml_tag_directive_t *end;1248 yaml_tag_directive_t *top;1249 } tag_directives = { NULL, NULL, NULL};1250 yaml_token_t *token; 1251 1252 if (!STACK_INIT(parser, tag_directives, INITIAL_STACK_ SIZE))1207 yaml_tag_directive_t *list; 1208 size_t length; 1209 size_t capacity; 1210 } tag_directives = { NULL, 0, 0 }; 1211 yaml_token_t *token; 1212 1213 if (!STACK_INIT(parser, tag_directives, INITIAL_STACK_CAPACITY)) 1253 1214 goto error; 1254 1215 … … 1261 1222 if (token->type == YAML_VERSION_DIRECTIVE_TOKEN) { 1262 1223 if (version_directive) { 1263 yaml_parser_set_parser_error(parser,1224 PARSER_ERROR_INIT(parser, 1264 1225 "found duplicate %YAML directive", token->start_mark); 1265 1226 goto error; … … 1267 1228 if (token->data.version_directive.major != 1 1268 1229 || token->data.version_directive.minor != 1) { 1269 yaml_parser_set_parser_error(parser,1230 PARSER_ERROR_INIT(parser, 1270 1231 "found incompatible YAML document", token->start_mark); 1271 1232 goto error; … … 1273 1234 version_directive = yaml_malloc(sizeof(yaml_version_directive_t)); 1274 1235 if (!version_directive) { 1275 parser->error = YAML_MEMORY_ERROR;1236 MEMORY_ERROR_INIT(parser); 1276 1237 goto error; 1277 1238 } … … 1307 1268 *version_directive_ref = version_directive; 1308 1269 } 1309 if (tag_directives_ start_ref) {1270 if (tag_directives_list_ref) { 1310 1271 if (STACK_EMPTY(parser, tag_directives)) { 1311 *tag_directives_start_ref = *tag_directives_end_ref = NULL; 1272 *tag_directives_list_ref = NULL; 1273 *tag_directives_length_ref = 0; 1274 *tag_directives_capacity_ref = 0; 1312 1275 STACK_DEL(parser, tag_directives); 1313 1276 } 1314 1277 else { 1315 *tag_directives_start_ref = tag_directives.start; 1316 *tag_directives_end_ref = tag_directives.top; 1278 *tag_directives_list_ref = tag_directives.list; 1279 *tag_directives_length_ref = tag_directives.length; 1280 *tag_directives_capacity_ref = tag_directives.capacity; 1317 1281 } 1318 1282 } … … 1344 1308 yaml_tag_directive_t *tag_directive; 1345 1309 yaml_tag_directive_t copy = { NULL, NULL }; 1346 1347 for (tag_directive = parser->tag_directives.start; 1348 tag_directive != parser->tag_directives.top; tag_directive ++) { 1310 int idx; 1311 1312 for (idx = 0; idx < parser->tag_directives.length; idx++) { 1313 yaml_tag_directive_t *tag_directive = parser->tag_directives.list + idx; 1349 1314 if (strcmp((char *)value.handle, (char *)tag_directive->handle) == 0) { 1350 1315 if (allow_duplicates) 1351 1316 return 1; 1352 return yaml_parser_set_parser_error(parser,1317 return PARSER_ERROR_INIT(parser, 1353 1318 "found duplicate %TAG directive", mark); 1354 1319 } … … 1358 1323 copy.prefix = yaml_strdup(value.prefix); 1359 1324 if (!copy.handle || !copy.prefix) { 1360 parser->error = YAML_MEMORY_ERROR;1325 MEMORY_ERROR_INIT(parser); 1361 1326 goto error; 1362 1327 } -
libyaml/trunk/src/reader.c
r262 r263 36 36 /* Ensure that we had enough bytes in the raw buffer. */ 37 37 38 while (!parser->is_eof && parser->raw_input. length< 3) {38 while (!parser->is_eof && parser->raw_input.capacity < 3) { 39 39 if (!yaml_parser_update_raw_buffer(parser)) { 40 40 return 0; … … 44 44 /* Determine the encoding. */ 45 45 46 if (parser->raw_input. length>= 246 if (parser->raw_input.capacity >= 2 47 47 && !memcmp(parser->raw_input.buffer, BOM_UTF16LE, 2)) { 48 48 parser->encoding = YAML_UTF16LE_ENCODING; … … 50 50 parser->offset = 2; 51 51 } 52 else if (parser->raw_input. length>= 252 else if (parser->raw_input.capacity >= 2 53 53 && !memcmp(parser->raw_input.buffer, BOM_UTF16BE, 2)) { 54 54 parser->encoding = YAML_UTF16BE_ENCODING; … … 56 56 parser->offset = 2; 57 57 } 58 else if (parser->raw_input. length>= 358 else if (parser->raw_input.capacity >= 3 59 59 && !memcmp(parser->raw_input.buffer, BOM_UTF8, 3)) { 60 60 parser->encoding = YAML_UTF8_ENCODING; … … 81 81 82 82 if (parser->raw_input.pointer == 0 && 83 parser->raw_input. length == parser->raw_input.capacity)83 parser->raw_input.capacity == RAW_INPUT_BUFFER_CAPACITY) 84 84 return 1; 85 85 … … 92 92 93 93 if (parser->raw_input.pointer > 0 && 94 parser->raw_input.pointer < parser->raw_input. length) {94 parser->raw_input.pointer < parser->raw_input.capacity) { 95 95 memmove(parser->raw_input.buffer, 96 96 parser->raw_input.buffer + parser->raw_input.pointer, 97 parser->raw_input.length - parser->raw_input.pointer); 98 } 97 parser->raw_input.capacity - parser->raw_input.pointer); 98 } 99 parser->raw_input.capacity -= parser->raw_input.pointer; 99 100 parser->raw_input.pointer = 0; 100 101 … … 102 103 103 104 if (!parser->reader(parser->reader_data, 104 parser->raw_input.buffer + parser->raw_input. length,105 parser->raw_input.capacity - parser->raw_input.length,105 parser->raw_input.buffer + parser->raw_input.capacity, 106 RAW_INPUT_BUFFER_CAPACITY - parser->raw_input.capacity, 106 107 &length)) { 107 108 return READER_ERROR_INIT(parser, "Input error", parser->offset); 108 109 } 109 parser->raw_input. length+= length;110 parser->raw_input.capacity += length; 110 111 if (!length) { 111 112 parser->is_eof = 1; … … 125 126 yaml_parser_update_buffer(yaml_parser_t *parser, size_t length) 126 127 { 128 size_t old_capacity; 129 127 130 assert(parser->reader); /* Read handler must be set. */ 128 131 129 132 /* If the EOF flag is set and the raw buffer is empty, do nothing. */ 130 133 131 if (parser->is_eof && parser->raw_input.pointer == parser->raw_input. length)134 if (parser->is_eof && parser->raw_input.pointer == parser->raw_input.capacity) 132 135 return 1; 133 136 … … 147 150 148 151 if (parser->input.pointer > 0 && 149 parser->input.pointer < parser->input. length) {152 parser->input.pointer < parser->input.capacity) { 150 153 memmove(parser->input.buffer, 151 154 parser->input.buffer + parser->input.pointer, 152 parser->input.length - parser->input.pointer); 153 parser->input.length -= parser->input.pointer; 154 parser->input.pointer = 0; 155 } 156 else if (parser->input.pointer == parser->input.length) { 157 parser->input.pointer = parser->input.length = 0; 158 } 155 parser->input.capacity - parser->input.pointer); 156 parser->input.capacity -= parser->input.pointer; 157 } 158 else if (parser->input.pointer == parser->input.capacity) { 159 parser->input.capacity = 0; 160 } 161 162 /* Set the pointer to the end of the buffer. */ 163 164 parser->input.pointer = parser->input.capacity; 159 165 160 166 /* Fill the buffer until it has enough characters. */ … … 168 174 /* Decode the raw buffer. */ 169 175 170 while (parser->raw_input.pointer != parser->raw_input. length)176 while (parser->raw_input.pointer != parser->raw_input.capacity) 171 177 { 172 unsigned char *raw_buffer =173 parser->raw_input.buffer + parser->raw_input.pointer;174 178 size_t raw_unread = 175 parser->raw_input. length- parser->raw_input.pointer;179 parser->raw_input.capacity - parser->raw_input.pointer; 176 180 unsigned int value = 0, value2 = 0; 177 181 int is_incomplete = 0; … … 179 183 unsigned int width = 0; 180 184 int low, high; 181 size_t k;185 size_t idx; 182 186 183 187 /* Decode the next character. */ … … 209 213 /* Determine the length of the UTF-8 sequence. */ 210 214 211 octet = *raw_buffer;215 octet = OCTET(parser->raw_input); 212 216 width = (octet & 0x80) == 0x00 ? 1 : 213 217 (octet & 0xE0) == 0xC0 ? 2 : … … 243 247 /* Check and decode the trailing octets. */ 244 248 245 for ( k = 1; k < width; k++)249 for (idx = 1; idx < width; idx ++) 246 250 { 247 octet = raw_buffer[k];251 octet = OCTET_AT(parser->raw_input, idx); 248 252 249 253 /* Check if the octet is valid. */ … … 252 256 return DECODER_ERROR_INIT(parser, 253 257 "Invalid trailing UTF-8 octet", 254 parser->offset+ k, octet);258 parser->offset+idx, octet); 255 259 256 260 /* Decode the octet. */ … … 324 328 /* Get the character. */ 325 329 326 value = raw_buffer[low] + (raw_buffer[high] << 8); 330 value = OCTET_AT(parser->raw_input, low) 331 + (OCTET_AT(parser->raw_input, high) << 8); 327 332 328 333 /* Check for unexpected low surrogate area. */ … … 353 358 /* Get the next character. */ 354 359 355 value2 = raw_buffer[low+2] + (raw_buffer[high+2] << 8); 360 value2 = OCTET_AT(parser->raw_input, low+2) 361 + (OCTET_AT(parser->raw_input, high+2) << 8); 356 362 357 363 /* Check for a low surrogate area. */ … … 407 413 /* 0000 0000-0000 007F -> 0xxxxxxx */ 408 414 if (value <= 0x7F) { 409 parser->input.buffer[parser->input.length++] = value;415 JOIN_OCTET(parser->input, value); 410 416 } 411 417 /* 0000 0080-0000 07FF -> 110xxxxx 10xxxxxx */ 412 418 else if (value <= 0x7FF) { 413 parser->input.buffer[parser->input.length++] = 0xC0 + (value >> 6);414 parser->input.buffer[parser->input.length++] = 0x80 + (value & 0x3F);419 JOIN_OCTET(parser->input, 0xC0 + (value >> 6)); 420 JOIN_OCTET(parser->input, 0x80 + (value & 0x3F)); 415 421 } 416 422 /* 0000 0800-0000 FFFF -> 1110xxxx 10xxxxxx 10xxxxxx */ 417 423 else if (value <= 0xFFFF) { 418 parser->input.buffer[parser->input.length++] = 0xE0 + (value >> 12);419 parser->input.buffer[parser->input.length++] = 0x80 + ((value >> 6) & 0x3F);420 parser->input.buffer[parser->input.length++] = 0x80 + (value & 0x3F);424 JOIN_OCTET(parser->input, 0xE0 + (value >> 12)); 425 JOIN_OCTET(parser->input, 0x80 + ((value >> 6) & 0x3F)); 426 JOIN_OCTET(parser->input, 0x80 + (value & 0x3F)); 421 427 } 422 428 /* 0001 0000-0010 FFFF -> 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ 423 429 else { 424 parser->input.buffer[parser->input.length++] = 0xF0 + (value >> 18);425 parser->input.buffer[parser->input.length++] = 0x80 + ((value >> 12) & 0x3F);426 parser->input.buffer[parser->input.length++] = 0x80 + ((value >> 6) & 0x3F);427 parser->input.buffer[parser->input.length++] = 0x80 + (value & 0x3F);430 JOIN_OCTET(parser->input, 0xF0 + (value >> 18)); 431 JOIN_OCTET(parser->input, 0x80 + ((value >> 12) & 0x3F)); 432 JOIN_OCTET(parser->input, 0x80 + ((value >> 6) & 0x3F)); 433 JOIN_OCTET(parser->input, 0x80 + (value & 0x3F)); 428 434 } 429 435 … … 431 437 } 432 438 433 /* On EOF, put NUL into the buffer and return. */439 /* On EOF, put NUL into the buffer and stop. */ 434 440 435 441 if (parser->is_eof) { 436 parser->input.buffer[parser->input.length++] = '\0';442 JOIN_OCTET(parser->input, '\0'); 437 443 parser->unread ++; 438 return 1;444 break; 439 445 } 440 446 441 447 } 448 /* Swap the pointer with the end of the buffer. */ 449 450 old_capacity = parser->input.capacity; 451 parser->input.capacity = parser->input.pointer; 452 parser->input.pointer = old_capacity; 442 453 443 454 return 1; -
libyaml/trunk/src/scanner.c
r243 r263 496 496 parser->mark.column ++, \ 497 497 parser->unread --, \ 498 parser-> buffer.pointer += WIDTH(parser->buffer))498 parser->input.pointer += WIDTH(parser->input)) 499 499 500 500 #define SKIP_LINE(parser) \ 501 (IS_CRLF(parser-> buffer) ?\501 (IS_CRLF(parser->input) ? \ 502 502 (parser->mark.index += 2, \ 503 503 parser->mark.column = 0, \ 504 504 parser->mark.line ++, \ 505 505 parser->unread -= 2, \ 506 parser-> buffer.pointer += 2) :\507 IS_BREAK(parser-> buffer) ?\506 parser->input.pointer += 2) : \ 507 IS_BREAK(parser->input) ? \ 508 508 (parser->mark.index ++, \ 509 509 parser->mark.column = 0, \ 510 510 parser->mark.line ++, \ 511 511 parser->unread --, \ 512 parser-> buffer.pointer += WIDTH(parser->buffer)) : 0)512 parser->input.pointer += WIDTH(parser->input)) : 0) 513 513 514 514 /* … … 518 518 #define READ(parser,string) \ 519 519 (STRING_EXTEND(parser,string) ? \ 520 (COPY(string,parser-> buffer),\520 (COPY(string,parser->input), \ 521 521 parser->mark.index ++, \ 522 522 parser->mark.column ++, \ … … 530 530 #define READ_LINE(parser,string) \ 531 531 (STRING_EXTEND(parser,string) ? \ 532 (((CHECK_AT(parser-> buffer,'\r',0)\533 && CHECK_AT(parser-> buffer,'\n',1)) ?/* CR LF -> LF */ \534 ( *((string).pointer++) = (yaml_char_t) '\n',\535 parser-> buffer.pointer += 2,\532 (((CHECK_AT(parser->input,'\r',0) \ 533 && CHECK_AT(parser->input,'\n',1)) ? /* CR LF -> LF */ \ 534 (JOIN_OCTET(string, (yaml_char_t) '\n'), \ 535 parser->input.pointer += 2, \ 536 536 parser->mark.index += 2, \ 537 537 parser->mark.column = 0, \ 538 538 parser->mark.line ++, \ 539 539 parser->unread -= 2) : \ 540 (CHECK_AT(parser-> buffer,'\r',0)\541 || CHECK_AT(parser-> buffer,'\n',0)) ?/* CR|LF -> LF */ \542 ( *((string).pointer++) = (yaml_char_t) '\n',\543 parser-> buffer.pointer ++,\540 (CHECK_AT(parser->input,'\r',0) \ 541 || CHECK_AT(parser->input,'\n',0)) ? /* CR|LF -> LF */ \ 542 (JOIN_OCTET(string,(yaml_char_t) '\n'), \ 543 parser->input.pointer ++, \ 544 544 parser->mark.index ++, \ 545 545 parser->mark.column = 0, \ 546 546 parser->mark.line ++, \ 547 547 parser->unread --) : \ 548 (CHECK_AT(parser-> buffer,'\xC2',0)\549 && CHECK_AT(parser-> buffer,'\x85',1)) ?/* NEL -> LF */ \550 ( *((string).pointer++) = (yaml_char_t) '\n',\551 parser-> buffer.pointer += 2,\548 (CHECK_AT(parser->input,'\xC2',0) \ 549 && CHECK_AT(parser->input,'\x85',1)) ? /* NEL -> LF */ \ 550 (JOIN_OCTET(string,(yaml_char_t) '\n'), \ 551 parser->input.pointer += 2, \ 552 552 parser->mark.index ++, \ 553 553 parser->mark.column = 0, \ 554 554 parser->mark.line ++, \ 555 555 parser->unread --) : \ 556 (CHECK_AT(parser-> buffer,'\xE2',0) &&\557 CHECK_AT(parser-> buffer,'\x80',1) &&\558 (CHECK_AT(parser-> buffer,'\xA8',2) ||\559 CHECK_AT(parser-> buffer,'\xA9',2))) ?/* LS|PS -> LS|PS */ \560 ( *((string).pointer++) = *(parser->buffer.pointer++),\561 *((string).pointer++) = *(parser->buffer.pointer++),\562 *((string).pointer++) = *(parser->buffer.pointer++),\556 (CHECK_AT(parser->input,'\xE2',0) && \ 557 CHECK_AT(parser->input,'\x80',1) && \ 558 (CHECK_AT(parser->input,'\xA8',2) || \ 559 CHECK_AT(parser->input,'\xA9',2))) ? /* LS|PS -> LS|PS */ \ 560 (COPY_OCTET(string,parser->input), \ 561 COPY_OCTET(string,parser->input), \ 562 COPY_OCTET(string,parser->input), \ 563 563 parser->mark.index ++, \ 564 564 parser->mark.column = 0, \ … … 575 575 576 576 /* 577 * Error handling.578 */579 580 static int581 yaml_parser_set_scanner_error(yaml_parser_t *parser, const char *context,582 yaml_mark_t context_mark, const char *problem);583 584 /*585 577 * High-level token API. 586 578 */ … … 751 743 /* No tokens after STREAM-END or error. */ 752 744 753 if (parser-> stream_end_produced || parser->error) {745 if (parser->is_stream_end_produced || parser->error.type) { 754 746 return 1; 755 747 } … … 757 749 /* Ensure that the tokens queue contains enough tokens. */ 758 750 759 if (!parser-> token_available) {751 if (!parser->is_token_available) { 760 752 if (!yaml_parser_fetch_more_tokens(parser)) 761 753 return 0; … … 765 757 766 758 *token = DEQUEUE(parser, parser->tokens); 767 parser-> token_available = 0;759 parser->is_token_available = 0; 768 760 parser->tokens_parsed ++; 769 761 770 762 if (token->type == YAML_STREAM_END_TOKEN) { 771 parser->stream_end_produced = 1; 772 } 773 774 return 1; 775 } 776 777 /* 778 * Set the scanner error and return 0. 779 */ 780 781 static int 782 yaml_parser_set_scanner_error(yaml_parser_t *parser, const char *context, 783 yaml_mark_t context_mark, const char *problem) 784 { 785 parser->error = YAML_SCANNER_ERROR; 786 parser->context = context; 787 parser->context_mark = context_mark; 788 parser->problem = problem; 789 parser->problem_mark = parser->mark; 790 791 return 0; 763 parser->is_stream_end_produced = 1; 764 } 765 766 return 1; 792 767 } 793 768 … … 820 795 else 821 796 { 822 yaml_simple_key_t *simple_key;797 size_t idx; 823 798 824 799 /* Check if any potential simple key may occupy the head position. */ … … 827 802 return 0; 828 803 829 for ( simple_key = parser->simple_keys.start;830 simple_key != parser->simple_keys.top; simple_key++) {831 if (simple_key-> possible804 for (idx = 0; idx < parser->simple_keys.length; idx++) { 805 yaml_simple_key_t *simple_key = parser->simple_keys.list + idx; 806 if (simple_key->is_possible 832 807 && simple_key->token_number == parser->tokens_parsed) { 833 808 need_more_tokens = 1; … … 848 823 } 849 824 850 parser-> token_available = 1;825 parser->is_token_available = 1; 851 826 852 827 return 1; … … 860 835 yaml_parser_fetch_next_token(yaml_parser_t *parser) 861 836 { 837 yaml_mark_t start_mark = parser->mark; 838 862 839 /* Ensure that the buffer is initialized. */ 863 840 … … 867 844 /* Check if we just started scanning. Fetch STREAM-START then. */ 868 845 869 if (!parser-> stream_start_produced)846 if (!parser->is_stream_start_produced) 870 847 return yaml_parser_fetch_stream_start(parser); 871 848 … … 895 872 /* Is it the end of the stream? */ 896 873 897 if (IS_Z(parser-> buffer))874 if (IS_Z(parser->input)) 898 875 return yaml_parser_fetch_stream_end(parser); 899 876 900 877 /* Is it a directive? */ 901 878 902 if (parser->mark.column == 0 && CHECK(parser-> buffer, '%'))879 if (parser->mark.column == 0 && CHECK(parser->input, '%')) 903 880 return yaml_parser_fetch_directive(parser); 904 881 … … 906 883 907 884 if (parser->mark.column == 0 908 && CHECK_AT(parser-> buffer, '-', 0)909 && CHECK_AT(parser-> buffer, '-', 1)910 && CHECK_AT(parser-> buffer, '-', 2)911 && IS_BLANKZ_AT(parser-> buffer, 3))885 && CHECK_AT(parser->input, '-', 0) 886 && CHECK_AT(parser->input, '-', 1) 887 && CHECK_AT(parser->input, '-', 2) 888 && IS_BLANKZ_AT(parser->input, 3)) 912 889 return yaml_parser_fetch_document_indicator(parser, 913 890 YAML_DOCUMENT_START_TOKEN); … … 916 893 917 894 if (parser->mark.column == 0 918 && CHECK_AT(parser-> buffer, '.', 0)919 && CHECK_AT(parser-> buffer, '.', 1)920 && CHECK_AT(parser-> buffer, '.', 2)921 && IS_BLANKZ_AT(parser-> buffer, 3))895 && CHECK_AT(parser->input, '.', 0) 896 && CHECK_AT(parser->input, '.', 1) 897 && CHECK_AT(parser->input, '.', 2) 898 && IS_BLANKZ_AT(parser->input, 3)) 922 899 return yaml_parser_fetch_document_indicator(parser, 923 900 YAML_DOCUMENT_END_TOKEN); … … 925 902 /* Is it the flow sequence start indicator? */ 926 903 927 if (CHECK(parser-> buffer, '['))904 if (CHECK(parser->input, '[')) 928 905 return yaml_parser_fetch_flow_collection_start(parser, 929 906 YAML_FLOW_SEQUENCE_START_TOKEN); … … 931 908 /* Is it the flow mapping start indicator? */ 932 909 933 if (CHECK(parser-> buffer, '{'))910 if (CHECK(parser->input, '{')) 934 911 return yaml_parser_fetch_flow_collection_start(parser, 935 912 YAML_FLOW_MAPPING_START_TOKEN); … … 937 914 /* Is it the flow sequence end indicator? */ 938 915 939 if (CHECK(parser-> buffer, ']'))916 if (CHECK(parser->input, ']')) 940 917 return yaml_parser_fetch_flow_collection_end(parser, 941 918 YAML_FLOW_SEQUENCE_END_TOKEN); … … 943 920 /* Is it the flow mapping end indicator? */ 944 921 945 if (CHECK(parser-> buffer, '}'))922 if (CHECK(parser->input, '}')) 946 923 return yaml_parser_fetch_flow_collection_end(parser, 947 924 YAML_FLOW_MAPPING_END_TOKEN); … … 949 926 /* Is it the flow entry indicator? */ 950 927 951 if (CHECK(parser-> buffer, ','))928 if (CHECK(parser->input, ',')) 952 929 return yaml_parser_fetch_flow_entry(parser); 953 930 954 931 /* Is it the block entry indicator? */ 955 932 956 if (CHECK(parser-> buffer, '-') && IS_BLANKZ_AT(parser->buffer, 1))933 if (CHECK(parser->input, '-') && IS_BLANKZ_AT(parser->input, 1)) 957 934 return yaml_parser_fetch_block_entry(parser); 958 935 959 936 /* Is it the key indicator? */ 960 937 961 if (CHECK(parser-> buffer, '?')962 && (parser->flow_level || IS_BLANKZ_AT(parser-> buffer, 1)))938 if (CHECK(parser->input, '?') 939 && (parser->flow_level || IS_BLANKZ_AT(parser->input, 1))) 963 940 return yaml_parser_fetch_key(parser); 964 941 965 942 /* Is it the value indicator? */ 966 943 967 if (CHECK(parser-> buffer, ':')968 && (parser->flow_level || IS_BLANKZ_AT(parser-> buffer, 1)))944 if (CHECK(parser->input, ':') 945 && (parser->flow_level || IS_BLANKZ_AT(parser->input, 1))) 969 946 return yaml_parser_fetch_value(parser); 970 947 971 948 /* Is it an alias? */ 972 949 973 if (CHECK(parser-> buffer, '*'))950 if (CHECK(parser->input, '*')) 974 951 return yaml_parser_fetch_anchor(parser, YAML_ALIAS_TOKEN); 975 952 976 953 /* Is it an anchor? */ 977 954 978 if (CHECK(parser-> buffer, '&'))955 if (CHECK(parser->input, '&')) 979 956 return yaml_parser_fetch_anchor(parser, YAML_ANCHOR_TOKEN); 980 957 981 958 /* Is it a tag? */ 982 959 983 if (CHECK(parser-> buffer, '!'))960 if (CHECK(parser->input, '!')) 984 961 return yaml_parser_fetch_tag(parser); 985 962 986 963 /* Is it a literal scalar? */ 987 964 988 if (CHECK(parser-> buffer, '|') && !parser->flow_level)965 if (CHECK(parser->input, '|') && !parser->flow_level) 989 966 return yaml_parser_fetch_block_scalar(parser, 1); 990 967 991 968 /* Is it a folded scalar? */ 992 969 993 if (CHECK(parser-> buffer, '>') && !parser->flow_level)970 if (CHECK(parser->input, '>') && !parser->flow_level) 994 971 return yaml_parser_fetch_block_scalar(parser, 0); 995 972 996 973 /* Is it a single-quoted scalar? */ 997 974 998 if (CHECK(parser-> buffer, '\''))975 if (CHECK(parser->input, '\'')) 999 976 return yaml_parser_fetch_flow_scalar(parser, 1); 1000 977 1001 978 /* Is it a double-quoted scalar? */ 1002 979 1003 if (CHECK(parser-> buffer, '"'))980 if (CHECK(parser->input, '"')) 1004 981 return yaml_parser_fetch_flow_scalar(parser, 0); 1005 982 … … 1023 1000 */ 1024 1001 1025 if (!(IS_BLANKZ(parser-> buffer) || CHECK(parser->buffer, '-')1026 || CHECK(parser-> buffer, '?') || CHECK(parser->buffer, ':')1027 || CHECK(parser-> buffer, ',') || CHECK(parser->buffer, '[')1028 || CHECK(parser-> buffer, ']') || CHECK(parser->buffer, '{')1029 || CHECK(parser-> buffer, '}') || CHECK(parser->buffer, '#')1030 || CHECK(parser-> buffer, '&') || CHECK(parser->buffer, '*')1031 || CHECK(parser-> buffer, '!') || CHECK(parser->buffer, '|')1032 || CHECK(parser-> buffer, '>') || CHECK(parser->buffer, '\'')1033 || CHECK(parser-> buffer, '"') || CHECK(parser->buffer, '%')1034 || CHECK(parser-> buffer, '@') || CHECK(parser->buffer, '`')) ||1035 (CHECK(parser-> buffer, '-') && !IS_BLANK_AT(parser->buffer, 1)) ||1002 if (!(IS_BLANKZ(parser->input) || CHECK(parser->input, '-') 1003 || CHECK(parser->input, '?') || CHECK(parser->input, ':') 1004 || CHECK(parser->input, ',') || CHECK(parser->input, '[') 1005 || CHECK(parser->input, ']') || CHECK(parser->input, '{') 1006 || CHECK(parser->input, '}') || CHECK(parser->input, '#') 1007 || CHECK(parser->input, '&') || CHECK(parser->input, '*') 1008 || CHECK(parser->input, '!') || CHECK(parser->input, '|') 1009 || CHECK(parser->input, '>') || CHECK(parser->input, '\'') 1010 || CHECK(parser->input, '"') || CHECK(parser->input, '%') 1011 || CHECK(parser->input, '@') || CHECK(parser->input, '`')) || 1012 (CHECK(parser->input, '-') && !IS_BLANK_AT(parser->input, 1)) || 1036 1013 (!parser->flow_level && 1037 (CHECK(parser-> buffer, '?') || CHECK(parser->buffer, ':'))1038 && !IS_BLANKZ_AT(parser-> buffer, 1)))1014 (CHECK(parser->input, '?') || CHECK(parser->input, ':')) 1015 && !IS_BLANKZ_AT(parser->input, 1))) 1039 1016 return yaml_parser_fetch_plain_scalar(parser); 1040 1017 … … 1043 1020 */ 1044 1021 1045 return yaml_parser_set_scanner_error(parser,1046 "while scanning for the next token", parser->mark,1047 "found character that cannot start any token" );1022 return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 1023 "while scanning for the next token", start_mark, 1024 "found character that cannot start any token", parser->mark); 1048 1025 } 1049 1026 … … 1056 1033 yaml_parser_stale_simple_keys(yaml_parser_t *parser) 1057 1034 { 1058 yaml_simple_key_t *simple_key;1035 size_t idx; 1059 1036 1060 1037 /* Check for a potential simple key for each flow level. */ 1061 1038 1062 for (simple_key = parser->simple_keys.start; 1063 simple_key != parser->simple_keys.top; simple_key ++) 1039 for (idx = 0; idx < parser->simple_keys.length; idx ++) 1064 1040 { 1041 yaml_simple_key_t *simple_key = parser->simple_keys.list + idx; 1042 1065 1043 /* 1066 1044 * The specification requires that a simple key … … 1070 1048 */ 1071 1049 1072 if (simple_key-> possible1050 if (simple_key->is_possible 1073 1051 && (simple_key->mark.line < parser->mark.line 1074 1052 || simple_key->mark.index+1024 < parser->mark.index)) { … … 1076 1054 /* Check if the potential simple key to be removed is required. */ 1077 1055 1078 if (simple_key-> required) {1079 return yaml_parser_set_scanner_error(parser,1056 if (simple_key->is_required) { 1057 return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 1080 1058 "while scanning a simple key", simple_key->mark, 1081 "could not found expected ':'" );1059 "could not found expected ':'", parser->mark); 1082 1060 } 1083 1061 1084 simple_key-> possible = 0;1062 simple_key->is_possible = 0; 1085 1063 } 1086 1064 } … … 1103 1081 */ 1104 1082 1105 int required = (!parser->flow_level1083 int is_required = (!parser->flow_level 1106 1084 && parser->indent == (int)parser->mark.column); 1107 1085 … … 1111 1089 */ 1112 1090 1113 assert(parser-> simple_key_allowed || !required);/* Impossible. */1091 assert(parser->is_simple_key_allowed || !is_required); /* Impossible. */ 1114 1092 1115 1093 /* … … 1117 1095 */ 1118 1096 1119 if (parser-> simple_key_allowed)1097 if (parser->is_simple_key_allowed) 1120 1098 { 1121 yaml_simple_key_t simple_key = { 1, required,1099 yaml_simple_key_t simple_key = { 1, is_required, 1122 1100 parser->tokens_parsed + parser->tokens.tail - parser->tokens.head, 1123 1101 { 0, 0, 0 } }; … … 1126 1104 if (!yaml_parser_remove_simple_key(parser)) return 0; 1127 1105 1128 *(parser->simple_keys.top-1)= simple_key;1106 parser->simple_keys.list[parser->simple_keys.length-1] = simple_key; 1129 1107 } 1130 1108 … … 1139 1117 yaml_parser_remove_simple_key(yaml_parser_t *parser) 1140 1118 { 1141 yaml_simple_key_t *simple_key = parser->simple_keys.top-1; 1142 1143 if (simple_key->possible) 1119 yaml_simple_key_t *simple_key = 1120 parser->simple_keys.list + parser->simple_keys.length - 1; 1121 1122 if (simple_key->is_possible) 1144 1123 { 1145 1124 /* If the key is required, it is an error. */ 1146 1125 1147 if (simple_key-> required) {1148 return yaml_parser_set_scanner_error(parser,1126 if (simple_key->is_required) { 1127 return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 1149 1128 "while scanning a simple key", simple_key->mark, 1150 "could not found expected ':'" );1129 "could not found expected ':'", parser->mark); 1151 1130 } 1152 1131 } … … 1154 1133 /* Remove the key from the stack. */ 1155 1134 1156 simple_key-> possible = 0;1135 simple_key->is_possible = 0; 1157 1136 1158 1137 return 1; … … 1302 1281 /* A simple key is allowed at the beginning of the stream. */ 1303 1282 1304 parser-> simple_key_allowed = 1;1283 parser->is_simple_key_allowed = 1; 1305 1284 1306 1285 /* We have started. */ 1307 1286 1308 parser-> stream_start_produced = 1;1287 parser->is_stream_start_produced = 1; 1309 1288 1310 1289 /* Create the STREAM-START token and append it to the queue. */ … … 1345 1324 return 0; 1346 1325 1347 parser-> simple_key_allowed = 0;1326 parser->is_simple_key_allowed = 0; 1348 1327 1349 1328 /* Create the STREAM-END token and append it to the queue. */ … … 1376 1355 return 0; 1377 1356 1378 parser-> simple_key_allowed = 0;1357 parser->is_simple_key_allowed = 0; 1379 1358 1380 1359 /* Create the YAML-DIRECTIVE or TAG-DIRECTIVE token. */ … … 1414 1393 return 0; 1415 1394 1416 parser-> simple_key_allowed = 0;1395 parser->is_simple_key_allowed = 0; 1417 1396 1418 1397 /* Consume the token. */ … … 1461 1440 /* A simple key may follow the indicators '[' and '{'. */ 1462 1441 1463 parser-> simple_key_allowed = 1;1442 parser->is_simple_key_allowed = 1; 1464 1443 1465 1444 /* Consume the token. */ … … 1504 1483 /* No simple keys after the indicators ']' and '}'. */ 1505 1484 1506 parser-> simple_key_allowed = 0;1485 parser->is_simple_key_allowed = 0; 1507 1486 1508 1487 /* Consume the token. */ … … 1541 1520 /* Simple keys are allowed after ','. */ 1542 1521 1543 parser-> simple_key_allowed = 1;1522 parser->is_simple_key_allowed = 1; 1544 1523 1545 1524 /* Consume the token. */ … … 1575 1554 /* Check if we are allowed to start a new entry. */ 1576 1555 1577 if (!parser->simple_key_allowed) { 1578 return yaml_parser_set_scanner_error(parser, NULL, parser->mark, 1579 "block sequence entries are not allowed in this context"); 1556 if (!parser->is_simple_key_allowed) { 1557 return SCANNER_ERROR_INIT(parser, 1558 "block sequence entries are not allowed in this context", 1559 parser->mark); 1580 1560 } 1581 1561 … … 1602 1582 /* Simple keys are allowed after '-'. */ 1603 1583 1604 parser-> simple_key_allowed = 1;1584 parser->is_simple_key_allowed = 1; 1605 1585 1606 1586 /* Consume the token. */ … … 1636 1616 /* Check if we are allowed to start a new key (not nessesary simple). */ 1637 1617 1638 if (!parser-> simple_key_allowed) {1639 return yaml_parser_set_scanner_error(parser, NULL, parser->mark,1640 "mapping keys are not allowed in this context" );1618 if (!parser->is_simple_key_allowed) { 1619 return SCANNER_ERROR_INIT(parser, 1620 "mapping keys are not allowed in this context", parser->mark); 1641 1621 } 1642 1622 … … 1655 1635 /* Simple keys are allowed after '?' in the block context. */ 1656 1636 1657 parser-> simple_key_allowed = (!parser->flow_level);1637 parser->is_simple_key_allowed = (!parser->flow_level); 1658 1638 1659 1639 /* Consume the token. */ … … 1682 1662 yaml_mark_t start_mark, end_mark; 1683 1663 yaml_token_t token; 1684 yaml_simple_key_t *simple_key = parser->simple_keys.top-1; 1664 yaml_simple_key_t *simple_key = 1665 parser->simple_keys.list + parser->simple_keys.length - 1; 1685 1666 1686 1667 /* Have we found a simple key? */ 1687 1668 1688 if (simple_key-> possible)1669 if (simple_key->is_possible) 1689 1670 { 1690 1671 … … 1706 1687 /* Remove the simple key. */ 1707 1688 1708 simple_key-> possible = 0;1689 simple_key->is_possible = 0; 1709 1690 1710 1691 /* A simple key cannot follow another simple key. */ 1711 1692 1712 parser-> simple_key_allowed = 0;1693 parser->is_simple_key_allowed = 0; 1713 1694 } 1714 1695 else … … 1722 1703 /* Check if we are allowed to start a complex value. */ 1723 1704 1724 if (!parser->simple_key_allowed) { 1725 return yaml_parser_set_scanner_error(parser, NULL, parser->mark, 1726 "mapping values are not allowed in this context"); 1705 if (!parser->is_simple_key_allowed) { 1706 return SCANNER_ERROR_INIT(parser, 1707 "mapping values are not allowed in this context", 1708 parser->mark); 1727 1709 } 1728 1710 … … 1736 1718 /* Simple keys after ':' are allowed in the block context. */ 1737 1719 1738 parser-> simple_key_allowed = (!parser->flow_level);1720 parser->is_simple_key_allowed = (!parser->flow_level); 1739 1721 } 1740 1722 … … 1771 1753 /* A simple key cannot follow an anchor or an alias. */ 1772 1754 1773 parser-> simple_key_allowed = 0;1755 parser->is_simple_key_allowed = 0; 1774 1756 1775 1757 /* Create the ALIAS or ANCHOR token and append it to the queue. */ … … 1801 1783 /* A simple key cannot follow a tag. */ 1802 1784 1803 parser-> simple_key_allowed = 0;1785 parser->is_simple_key_allowed = 0; 1804 1786 1805 1787 /* Create the TAG token and append it to the queue. */ … … 1832 1814 /* A simple key may follow a block scalar. */ 1833 1815 1834 parser-> simple_key_allowed = 1;1816 parser->is_simple_key_allowed = 1; 1835 1817 1836 1818 /* Create the SCALAR token and append it to the queue. */ … … 1863 1845 /* A simple key cannot follow a flow scalar. */ 1864 1846 1865 parser-> simple_key_allowed = 0;1847 parser->is_simple_key_allowed = 0; 1866 1848 1867 1849 /* Create the SCALAR token and append it to the queue. */ … … 1894 1876 /* A simple key cannot follow a flow scalar. */ 1895 1877 1896 parser-> simple_key_allowed = 0;1878 parser->is_simple_key_allowed = 0; 1897 1879 1898 1880 /* Create the SCALAR token and append it to the queue. */ … … 1924 1906 if (!CACHE(parser, 1)) return 0; 1925 1907 1926 if (parser->mark.column == 0 && IS_BOM(parser-> buffer))1908 if (parser->mark.column == 0 && IS_BOM(parser->input)) 1927 1909 SKIP(parser); 1928 1910 … … 1939 1921 if (!CACHE(parser, 1)) return 0; 1940 1922 1941 while (CHECK(parser-> buffer,' ') ||1942 ((parser->flow_level || !parser-> simple_key_allowed) &&1943 CHECK(parser-> buffer, '\t'))) {1923 while (CHECK(parser->input,' ') || 1924 ((parser->flow_level || !parser->is_simple_key_allowed) && 1925 CHECK(parser->input, '\t'))) { 1944 1926 SKIP(parser); 1945 1927 if (!CACHE(parser, 1)) return 0; … … 1948 1930 /* Eat a comment until a line break. */ 1949 1931 1950 if (CHECK(parser-> buffer, '#')) {1951 while (!IS_BREAKZ(parser-> buffer)) {1932 if (CHECK(parser->input, '#')) { 1933 while (!IS_BREAKZ(parser->input)) { 1952 1934 SKIP(parser); 1953 1935 if (!CACHE(parser, 1)) return 0; … … 1957 1939 /* If it is a line break, eat it. */ 1958 1940 1959 if (IS_BREAK(parser-> buffer))1941 if (IS_BREAK(parser->input)) 1960 1942 { 1961 1943 if (!CACHE(parser, 2)) return 0; … … 1965 1947 1966 1948 if (!parser->flow_level) { 1967 parser-> simple_key_allowed = 1;1949 parser->is_simple_key_allowed = 1; 1968 1950 } 1969 1951 } … … 2048 2030 else 2049 2031 { 2050 yaml_parser_set_scanner_error(parser, "while scanning a directive", 2051 start_mark, "found uknown directive name"); 2032 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2033 "while scanning a directive", start_mark, 2034 "found uknown directive name", parser->mark); 2052 2035 goto error; 2053 2036 } … … 2057 2040 if (!CACHE(parser, 1)) goto error; 2058 2041 2059 while (IS_BLANK(parser-> buffer)) {2042 while (IS_BLANK(parser->input)) { 2060 2043 SKIP(parser); 2061 2044 if (!CACHE(parser, 1)) goto error; 2062 2045 } 2063 2046 2064 if (CHECK(parser-> buffer, '#')) {2065 while (!IS_BREAKZ(parser-> buffer)) {2047 if (CHECK(parser->input, '#')) { 2048 while (!IS_BREAKZ(parser->input)) { 2066 2049 SKIP(parser); 2067 2050 if (!CACHE(parser, 1)) goto error; … … 2071 2054 /* Check if we are at the end of the line. */ 2072 2055 2073 if (!IS_BREAKZ(parser->buffer)) { 2074 yaml_parser_set_scanner_error(parser, "while scanning a directive", 2075 start_mark, "did not found expected comment or line break"); 2056 if (!IS_BREAKZ(parser->input)) { 2057 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2058 "while scanning a directive", start_mark, 2059 "did not found expected comment or line break", parser->mark); 2076 2060 goto error; 2077 2061 } … … 2079 2063 /* Eat a line break. */ 2080 2064 2081 if (IS_BREAK(parser-> buffer)) {2065 if (IS_BREAK(parser->input)) { 2082 2066 if (!CACHE(parser, 2)) goto error; 2083 2067 SKIP_LINE(parser); … … 2111 2095 yaml_string_t string = NULL_STRING; 2112 2096 2113 if (!STRING_INIT(parser, string, INITIAL_STRING_SIZE)) goto error; 2097 if (!STRING_INIT(parser, string, INITIAL_STRING_CAPACITY)) 2098 goto error; 2114 2099 2115 2100 /* Consume the directive name. */ … … 2117 2102 if (!CACHE(parser, 1)) goto error; 2118 2103 2119 while (IS_ALPHA(parser-> buffer))2104 while (IS_ALPHA(parser->input)) 2120 2105 { 2121 2106 if (!READ(parser, string)) goto error; … … 2125 2110 /* Check if the name is empty. */ 2126 2111 2127 if (string.start == string.pointer) { 2128 yaml_parser_set_scanner_error(parser, "while scanning a directive", 2129 start_mark, "cannot found expected directive name"); 2112 if (!string.pointer) { 2113 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2114 "while scanning a directive", start_mark, 2115 "cannot found expected directive name", parser->mark); 2130 2116 goto error; 2131 2117 } … … 2133 2119 /* Check for an blank character after the name. */ 2134 2120 2135 if (!IS_BLANKZ(parser->buffer)) { 2136 yaml_parser_set_scanner_error(parser, "while scanning a directive", 2137 start_mark, "found unexpected non-alphabetical character"); 2121 if (!IS_BLANKZ(parser->input)) { 2122 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2123 "while scanning a directive", start_mark, 2124 "found unexpected non-alphabetical character", parser->mark); 2138 2125 goto error; 2139 2126 } 2140 2127 2141 *name = string. start;2128 *name = string.buffer; 2142 2129 2143 2130 return 1; … … 2164 2151 if (!CACHE(parser, 1)) return 0; 2165 2152 2166 while (IS_BLANK(parser-> buffer)) {2153 while (IS_BLANK(parser->input)) { 2167 2154 SKIP(parser); 2168 2155 if (!CACHE(parser, 1)) return 0; … … 2176 2163 /* Eat '.'. */ 2177 2164 2178 if (!CHECK(parser->buffer, '.')) { 2179 return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", 2180 start_mark, "did not find expected digit or '.' character"); 2165 if (!CHECK(parser->input, '.')) { 2166 return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2167 "while scanning a %YAML directive", start_mark, 2168 "did not find expected digit or '.' character", parser->mark); 2181 2169 } 2182 2170 … … 2214 2202 if (!CACHE(parser, 1)) return 0; 2215 2203 2216 while (IS_DIGIT(parser-> buffer))2204 while (IS_DIGIT(parser->input)) 2217 2205 { 2218 2206 /* Check if the number is too long. */ 2219 2207 2220 2208 if (++length > MAX_NUMBER_LENGTH) { 2221 return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", 2222 start_mark, "found extremely long version number"); 2223 } 2224 2225 value = value*10 + AS_DIGIT(parser->buffer); 2209 return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2210 "while scanning a %YAML directive", start_mark, 2211 "found extremely long version number", parser->mark); 2212 } 2213 2214 value = value*10 + AS_DIGIT(parser->input); 2226 2215 2227 2216 SKIP(parser); … … 2233 2222 2234 2223 if (!length) { 2235 return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", 2236 start_mark, "did not find expected version number"); 2224 return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2225 "while scanning a %YAML directive", start_mark, 2226 "did not find expected version number", parser->mark); 2237 2227 } 2238 2228 … … 2261 2251 if (!CACHE(parser, 1)) goto error; 2262 2252 2263 while (IS_BLANK(parser-> buffer)) {2253 while (IS_BLANK(parser->input)) { 2264 2254 SKIP(parser); 2265 2255 if (!CACHE(parser, 1)) goto error; … … 2275 2265 if (!CACHE(parser, 1)) goto error; 2276 2266 2277 if (!IS_BLANK(parser->buffer)) { 2278 yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive", 2279 start_mark, "did not find expected whitespace"); 2267 if (!IS_BLANK(parser->input)) { 2268 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2269 "while scanning a %TAG directive", start_mark, 2270 "did not find expected whitespace", parser->mark); 2280 2271 goto error; 2281 2272 } … … 2283 2274 /* Eat whitespaces. */ 2284 2275 2285 while (IS_BLANK(parser-> buffer)) {2276 while (IS_BLANK(parser->input)) { 2286 2277 SKIP(parser); 2287 2278 if (!CACHE(parser, 1)) goto error; … … 2297 2288 if (!CACHE(parser, 1)) goto error; 2298 2289 2299 if (!IS_BLANKZ(parser->buffer)) { 2300 yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive", 2301 start_mark, "did not find expected whitespace or line break"); 2290 if (!IS_BLANKZ(parser->input)) { 2291 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2292 "while scanning a %TAG directive", start_mark, 2293 "did not find expected whitespace or line break", parser->mark); 2302 2294 goto error; 2303 2295 } … … 2322 2314 yaml_string_t string = NULL_STRING; 2323 2315 2324 if (!STRING_INIT(parser, string, INITIAL_STRING_SIZE)) goto error; 2316 if (!STRING_INIT(parser, string, INITIAL_STRING_CAPACITY)) 2317 goto error; 2325 2318 2326 2319 /* Eat the indicator character. */ … … 2334 2327 if (!CACHE(parser, 1)) goto error; 2335 2328 2336 while (IS_ALPHA(parser-> buffer)) {2329 while (IS_ALPHA(parser->input)) { 2337 2330 if (!READ(parser, string)) goto error; 2338 2331 if (!CACHE(parser, 1)) goto error; … … 2349 2342 */ 2350 2343 2351 if (!length || !(IS_BLANKZ(parser->buffer) || CHECK(parser->buffer, '?') 2352 || CHECK(parser->buffer, ':') || CHECK(parser->buffer, ',') 2353 || CHECK(parser->buffer, ']') || CHECK(parser->buffer, '}') 2354 || CHECK(parser->buffer, '%') || CHECK(parser->buffer, '@') 2355 || CHECK(parser->buffer, '`'))) { 2356 yaml_parser_set_scanner_error(parser, type == YAML_ANCHOR_TOKEN ? 2357 "while scanning an anchor" : "while scanning an alias", start_mark, 2358 "did not find expected alphabetic or numeric character"); 2344 if (!length || !(IS_BLANKZ(parser->input) || CHECK(parser->input, '?') 2345 || CHECK(parser->input, ':') || CHECK(parser->input, ',') 2346 || CHECK(parser->input, ']') || CHECK(parser->input, '}') 2347 || CHECK(parser->input, '%') || CHECK(parser->input, '@') 2348 || CHECK(parser->input, '`'))) { 2349 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, type == YAML_ANCHOR_TOKEN ? 2350 "while scanning an anchor" : "while scanning an alias", 2351 start_mark, 2352 "did not find expected alphabetic or numeric character", 2353 parser->mark); 2359 2354 goto error; 2360 2355 } … … 2363 2358 2364 2359 if (type == YAML_ANCHOR_TOKEN) { 2365 ANCHOR_TOKEN_INIT(*token, string. start, start_mark, end_mark);2360 ANCHOR_TOKEN_INIT(*token, string.buffer, start_mark, end_mark); 2366 2361 } 2367 2362 else { 2368 ALIAS_TOKEN_INIT(*token, string. start, start_mark, end_mark);2363 ALIAS_TOKEN_INIT(*token, string.buffer, start_mark, end_mark); 2369 2364 } 2370 2365 … … 2393 2388 if (!CACHE(parser, 2)) goto error; 2394 2389 2395 if (CHECK_AT(parser-> buffer, '<', 1))2390 if (CHECK_AT(parser->input, '<', 1)) 2396 2391 { 2397 2392 /* Set the handle to '' */ … … 2413 2408 /* Check for '>' and eat it. */ 2414 2409 2415 if (!CHECK(parser->buffer, '>')) { 2416 yaml_parser_set_scanner_error(parser, "while scanning a tag", 2417 start_mark, "did not find the expected '>'"); 2410 if (!CHECK(parser->input, '>')) { 2411 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2412 "while scanning a tag", start_mark, 2413 "did not find the expected '>'", parser->mark); 2418 2414 goto error; 2419 2415 } … … 2471 2467 if (!CACHE(parser, 1)) goto error; 2472 2468 2473 if (!IS_BLANKZ(parser->buffer)) { 2474 yaml_parser_set_scanner_error(parser, "while scanning a tag", 2475 start_mark, "did not found expected whitespace or line break"); 2469 if (!IS_BLANKZ(parser->input)) { 2470 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2471 "while scanning a tag", start_mark, 2472 "did not found expected whitespace or line break", parser->mark); 2476 2473 goto error; 2477 2474 } … … 2501 2498 yaml_string_t string = NULL_STRING; 2502 2499 2503 if (!STRING_INIT(parser, string, INITIAL_STRING_SIZE)) goto error; 2500 if (!STRING_INIT(parser, string, INITIAL_STRING_CAPACITY)) 2501 goto error; 2504 2502 2505 2503 /* Check the initial '!' character. */ … … 2507 2505 if (!CACHE(parser, 1)) goto error; 2508 2506 2509 if (!CHECK(parser-> buffer, '!')) {2510 yaml_parser_set_scanner_error(parser, directive ?2507 if (!CHECK(parser->input, '!')) { 2508 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, directive ? 2511 2509 "while scanning a tag directive" : "while scanning a tag", 2512 start_mark, "did not find expected '!'" );2510 start_mark, "did not find expected '!'", parser->mark); 2513 2511 goto error; 2514 2512 } … … 2522 2520 if (!CACHE(parser, 1)) goto error; 2523 2521 2524 while (IS_ALPHA(parser-> buffer))2522 while (IS_ALPHA(parser->input)) 2525 2523 { 2526 2524 if (!READ(parser, string)) goto error; … … 2530 2528 /* Check if the trailing character is '!' and copy it. */ 2531 2529 2532 if (CHECK(parser-> buffer, '!'))2530 if (CHECK(parser->input, '!')) 2533 2531 { 2534 2532 if (!READ(parser, string)) goto error; … … 2542 2540 */ 2543 2541 2544 if (directive && !(string.start[0] == '!' && string.start[1] == '\0')) { 2545 yaml_parser_set_scanner_error(parser, "while parsing a tag directive", 2546 start_mark, "did not find expected '!'"); 2542 if (directive && 2543 !(string.buffer[0] == '!' && string.buffer[1] == '\0')) { 2544 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2545 "while parsing a tag directive", start_mark, 2546 "did not find expected '!'", parser->mark); 2547 2547 goto error; 2548 2548 } 2549 2549 } 2550 2550 2551 *handle = string. start;2551 *handle = string.buffer; 2552 2552 2553 2553 return 1; … … 2569 2569 yaml_string_t string = NULL_STRING; 2570 2570 2571 if (!STRING_INIT(parser, string, INITIAL_STRING_SIZE)) goto error; 2571 if (!STRING_INIT(parser, string, INITIAL_STRING_CAPACITY)) 2572 goto error; 2572 2573 2573 2574 /* Resize the string to include the head. */ 2574 2575 2575 while (string. end - string.start <= (int)length) {2576 if (!yaml_string_extend(&string. start, &string.pointer, &string.end)) {2577 parser->error = YAML_MEMORY_ERROR;2576 while (string.capacity <= length) { 2577 if (!yaml_string_extend(&string.buffer, &string.capacity)) { 2578 MEMORY_ERROR_INIT(parser); 2578 2579 goto error; 2579 2580 } … … 2587 2588 2588 2589 if (length > 1) { 2589 memcpy(string. start, head+1, length-1);2590 memcpy(string.buffer, head+1, length-1); 2590 2591 string.pointer += length-1; 2591 2592 } … … 2603 2604 */ 2604 2605 2605 while (IS_ALPHA(parser-> buffer) || CHECK(parser->buffer, ';')2606 || CHECK(parser-> buffer, '/') || CHECK(parser->buffer, '?')2607 || CHECK(parser-> buffer, ':') || CHECK(parser->buffer, '@')2608 || CHECK(parser-> buffer, '&') || CHECK(parser->buffer, '=')2609 || CHECK(parser-> buffer, '+') || CHECK(parser->buffer, '$')2610 || CHECK(parser-> buffer, ',') || CHECK(parser->buffer, '.')2611 || CHECK(parser-> buffer, '!') || CHECK(parser->buffer, '~')2612 || CHECK(parser-> buffer, '*') || CHECK(parser->buffer, '\'')2613 || CHECK(parser-> buffer, '(') || CHECK(parser->buffer, ')')2614 || CHECK(parser-> buffer, '[') || CHECK(parser->buffer, ']')2615 || CHECK(parser-> buffer, '%'))2606 while (IS_ALPHA(parser->input) || CHECK(parser->input, ';') 2607 || CHECK(parser->input, '/') || CHECK(parser->input, '?') 2608 || CHECK(parser->input, ':') || CHECK(parser->input, '@') 2609 || CHECK(parser->input, '&') || CHECK(parser->input, '=') 2610 || CHECK(parser->input, '+') || CHECK(parser->input, '$') 2611 || CHECK(parser->input, ',') || CHECK(parser->input, '.') 2612 || CHECK(parser->input, '!') || CHECK(parser->input, '~') 2613 || CHECK(parser->input, '*') || CHECK(parser->input, '\'') 2614 || CHECK(parser->input, '(') || CHECK(parser->input, ')') 2615 || CHECK(parser->input, '[') || CHECK(parser->input, ']') 2616 || CHECK(parser->input, '%')) 2616 2617 { 2617 2618 /* Check if it is a URI-escape sequence. */ 2618 2619 2619 if (CHECK(parser-> buffer, '%')) {2620 if (CHECK(parser->input, '%')) { 2620 2621 if (!yaml_parser_scan_uri_escapes(parser, 2621 2622 directive, start_mark, &string)) goto error; … … 2635 2636 goto error; 2636 2637 2637 yaml_parser_set_scanner_error(parser, directive ?2638 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, directive ? 2638 2639 "while parsing a %TAG directive" : "while parsing a tag", 2639 start_mark, "did not find expected tag URI" );2640 start_mark, "did not find expected tag URI", parser->mark); 2640 2641 goto error; 2641 2642 } 2642 2643 2643 *uri = string. start;2644 *uri = string.buffer; 2644 2645 2645 2646 return 1; … … 2663 2664 2664 2665 do { 2665 2666 2666 unsigned char octet = 0; 2667 2667 … … 2670 2670 if (!CACHE(parser, 3)) return 0; 2671 2671 2672 if (!(CHECK(parser-> buffer, '%')2673 && IS_HEX_AT(parser-> buffer, 1)2674 && IS_HEX_AT(parser-> buffer, 2))) {2675 return yaml_parser_set_scanner_error(parser, directive ?2672 if (!(CHECK(parser->input, '%') 2673 && IS_HEX_AT(parser->input, 1) 2674 && IS_HEX_AT(parser->input, 2))) { 2675 return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, directive ? 2676 2676 "while parsing a %TAG directive" : "while parsing a tag", 2677 start_mark, "did not find URI escaped octet" );2677 start_mark, "did not find URI escaped octet", parser->mark); 2678 2678 } 2679 2679 2680 2680 /* Get the octet. */ 2681 2681 2682 octet = (AS_HEX_AT(parser-> buffer, 1) << 4) + AS_HEX_AT(parser->buffer, 2);2682 octet = (AS_HEX_AT(parser->input, 1) << 4) + AS_HEX_AT(parser->input, 2); 2683 2683 2684 2684 /* If it is the leading octet, determine the length of the UTF-8 sequence. */ … … 2691 2691 (octet & 0xF8) == 0xF0 ? 4 : 0; 2692 2692 if (!width) { 2693 return yaml_parser_set_scanner_error(parser, directive ?2693 return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, directive ? 2694 2694 "while parsing a %TAG directive" : "while parsing a tag", 2695 start_mark, "found an incorrect leading UTF-8 octet"); 2695 start_mark, "found an incorrect leading UTF-8 octet", 2696 parser->mark); 2696 2697 } 2697 2698 } … … 2701 2702 2702 2703 if ((octet & 0xC0) != 0x80) { 2703 return yaml_parser_set_scanner_error(parser, directive ?2704 return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, directive ? 2704 2705 "while parsing a %TAG directive" : "while parsing a tag", 2705 start_mark, "found an incorrect trailing UTF-8 octet"); 2706 start_mark, "found an incorrect trailing UTF-8 octet", 2707 parser->mark); 2706 2708 } 2707 2709 } … … 2709 2711 /* Copy the octet and move the pointers. */ 2710 2712 2711 *(string->pointer++) = octet;2713 JOIN_OCTET(*string, octet); 2712 2714 SKIP(parser); 2713 2715 SKIP(parser); … … 2738 2740 int trailing_blank = 0; 2739 2741 2740 if (!STRING_INIT(parser, string, INITIAL_STRING_SIZE)) goto error; 2741 if (!STRING_INIT(parser, leading_break, INITIAL_STRING_SIZE)) goto error; 2742 if (!STRING_INIT(parser, trailing_breaks, INITIAL_STRING_SIZE)) goto error; 2742 if (!STRING_INIT(parser, string, INITIAL_STRING_CAPACITY)) 2743 goto error; 2744 if (!STRING_INIT(parser, leading_break, INITIAL_STRING_CAPACITY)) 2745 goto error; 2746 if (!STRING_INIT(parser, trailing_breaks, INITIAL_STRING_CAPACITY)) 2747 goto error; 2743 2748 2744 2749 /* Eat the indicator '|' or '>'. */ … … 2754 2759 /* Check for a chomping indicator. */ 2755 2760 2756 if (CHECK(parser-> buffer, '+') || CHECK(parser->buffer, '-'))2761 if (CHECK(parser->input, '+') || CHECK(parser->input, '-')) 2757 2762 { 2758 2763 /* Set the chomping method and eat the indicator. */ 2759 2764 2760 chomping = CHECK(parser-> buffer, '+') ? +1 : -1;2765 chomping = CHECK(parser->input, '+') ? +1 : -1; 2761 2766 2762 2767 SKIP(parser); … … 2766 2771 if (!CACHE(parser, 1)) goto error; 2767 2772 2768 if (IS_DIGIT(parser-> buffer))2773 if (IS_DIGIT(parser->input)) 2769 2774 { 2770 2775 /* Check that the intendation is greater than 0. */ 2771 2776 2772 if (CHECK(parser->buffer, '0')) { 2773 yaml_parser_set_scanner_error(parser, "while scanning a block scalar", 2774 start_mark, "found an intendation indicator equal to 0"); 2777 if (CHECK(parser->input, '0')) { 2778 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2779 "while scanning a block scalar", start_mark, 2780 "found an intendation indicator equal to 0", parser->mark); 2775 2781 goto error; 2776 2782 } … … 2778 2784 /* Get the intendation level and eat the indicator. */ 2779 2785 2780 increment = AS_DIGIT(parser-> buffer);2786 increment = AS_DIGIT(parser->input); 2781 2787 2782 2788 SKIP(parser); … … 2786 2792 /* Do the same as above, but in the opposite order. */ 2787 2793 2788 else if (IS_DIGIT(parser-> buffer))2794 else if (IS_DIGIT(parser->input)) 2789 2795 { 2790 if (CHECK(parser->buffer, '0')) { 2791 yaml_parser_set_scanner_error(parser, "while scanning a block scalar", 2792 start_mark, "found an intendation indicator equal to 0"); 2796 if (CHECK(parser->input, '0')) { 2797 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2798 "while scanning a block scalar", start_mark, 2799 "found an intendation indicator equal to 0", parser->mark); 2793 2800 goto error; 2794 2801 } 2795 2802 2796 increment = AS_DIGIT(parser-> buffer);2803 increment = AS_DIGIT(parser->input); 2797 2804 2798 2805 SKIP(parser); … … 2800 2807 if (!CACHE(parser, 1)) goto error; 2801 2808 2802 if (CHECK(parser-> buffer, '+') || CHECK(parser->buffer, '-')) {2803 chomping = CHECK(parser-> buffer, '+') ? +1 : -1;2809 if (CHECK(parser->input, '+') || CHECK(parser->input, '-')) { 2810 chomping = CHECK(parser->input, '+') ? +1 : -1; 2804 2811 2805 2812 SKIP(parser); … … 2811 2818 if (!CACHE(parser, 1)) goto error; 2812 2819 2813 while (IS_BLANK(parser-> buffer)) {2820 while (IS_BLANK(parser->input)) { 2814 2821 SKIP(parser); 2815 2822 if (!CACHE(parser, 1)) goto error; 2816 2823 } 2817 2824 2818 if (CHECK(parser-> buffer, '#')) {2819 while (!IS_BREAKZ(parser-> buffer)) {2825 if (CHECK(parser->input, '#')) { 2826 while (!IS_BREAKZ(parser->input)) { 2820 2827 SKIP(parser); 2821 2828 if (!CACHE(parser, 1)) goto error; … … 2825 2832 /* Check if we are at the end of the line. */ 2826 2833 2827 if (!IS_BREAKZ(parser->buffer)) { 2828 yaml_parser_set_scanner_error(parser, "while scanning a block scalar", 2829 start_mark, "did not found expected comment or line break"); 2834 if (!IS_BREAKZ(parser->input)) { 2835 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2836 "while scanning a block scalar", start_mark, 2837 "did not found expected comment or line break", parser->mark); 2830 2838 goto error; 2831 2839 } … … 2833 2841 /* Eat a line break. */ 2834 2842 2835 if (IS_BREAK(parser-> buffer)) {2843 if (IS_BREAK(parser->input)) { 2836 2844 if (!CACHE(parser, 2)) goto error; 2837 2845 SKIP_LINE(parser); … … 2855 2863 if (!CACHE(parser, 1)) goto error; 2856 2864 2857 while ((int)parser->mark.column == indent && !IS_Z(parser-> buffer))2865 while ((int)parser->mark.column == indent && !IS_Z(parser->input)) 2858 2866 { 2859 2867 /* … … 2863 2871 /* Is it a trailing whitespace? */ 2864 2872 2865 trailing_blank = IS_BLANK(parser-> buffer);2873 trailing_blank = IS_BLANK(parser->input); 2866 2874 2867 2875 /* Check if we need to fold the leading line break. */ 2868 2876 2869 if (!literal && (*leading_break. start== '\n')2877 if (!literal && (*leading_break.buffer == '\n') 2870 2878 && !leading_blank && !trailing_blank) 2871 2879 { 2872 2880 /* Do we need to join the lines by space? */ 2873 2881 2874 if (*trailing_breaks. start== '\0') {2882 if (*trailing_breaks.buffer == '\0') { 2875 2883 if (!STRING_EXTEND(parser, string)) goto error; 2876 *(string.pointer ++) = ' ';2884 JOIN_OCTET(string, ' '); 2877 2885 } 2878 2886 … … 2891 2899 /* Is it a leading whitespace? */ 2892 2900 2893 leading_blank = IS_BLANK(parser-> buffer);2901 leading_blank = IS_BLANK(parser->input); 2894 2902 2895 2903 /* Consume the current line. */ 2896 2904 2897 while (!IS_BREAKZ(parser-> buffer)) {2905 while (!IS_BREAKZ(parser->input)) { 2898 2906 if (!READ(parser, string)) goto error; 2899 2907 if (!CACHE(parser, 1)) goto error; … … 2923 2931 /* Create a token. */ 2924 2932 2925 SCALAR_TOKEN_INIT(*token, string. start, string.pointer-string.start,2933 SCALAR_TOKEN_INIT(*token, string.buffer, string.pointer, 2926 2934 literal ? YAML_LITERAL_SCALAR_STYLE : YAML_FOLDED_SCALAR_STYLE, 2927 2935 start_mark, end_mark); … … 2963 2971 2964 2972 while ((!*indent || (int)parser->mark.column < *indent) 2965 && IS_SPACE(parser-> buffer)) {2973 && IS_SPACE(parser->input)) { 2966 2974 SKIP(parser); 2967 2975 if (!CACHE(parser, 1)) return 0; … … 2974 2982 2975 2983 if ((!*indent || (int)parser->mark.column < *indent) 2976 && IS_TAB(parser->buffer)) { 2977 return yaml_parser_set_scanner_error(parser, "while scanning a block scalar", 2978 start_mark, "found a tab character where an intendation space is expected"); 2984 && IS_TAB(parser->input)) { 2985 return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 2986 "while scanning a block scalar", start_mark, 2987 "found a tab character where an intendation space is expected", 2988 parser->mark); 2979 2989 } 2980 2990 2981 2991 /* Have we found a non-empty line? */ 2982 2992 2983 if (!IS_BREAK(parser-> buffer)) break;2993 if (!IS_BREAK(parser->input)) break; 2984 2994 2985 2995 /* Consume the line break. */ … … 3019 3029 int leading_blanks; 3020 3030 3021 if (!STRING_INIT(parser, string, INITIAL_STRING_SIZE)) goto error; 3022 if (!STRING_INIT(parser, leading_break, INITIAL_STRING_SIZE)) goto error; 3023 if (!STRING_INIT(parser, trailing_breaks, INITIAL_STRING_SIZE)) goto error; 3024 if (!STRING_INIT(parser, whitespaces, INITIAL_STRING_SIZE)) goto error; 3031 if (!STRING_INIT(parser, string, INITIAL_STRING_CAPACITY)) 3032 goto error; 3033 if (!STRING_INIT(parser, leading_break, INITIAL_STRING_CAPACITY)) 3034 goto error; 3035 if (!STRING_INIT(parser, trailing_breaks, INITIAL_STRING_CAPACITY)) 3036 goto error; 3037 if (!STRING_INIT(parser, whitespaces, INITIAL_STRING_CAPACITY)) 3038 goto error; 3025 3039 3026 3040 /* Eat the left quote. */ … … 3039 3053 3040 3054 if (parser->mark.column == 0 && 3041 ((CHECK_AT(parser-> buffer, '-', 0) &&3042 CHECK_AT(parser-> buffer, '-', 1) &&3043 CHECK_AT(parser-> buffer, '-', 2)) ||3044 (CHECK_AT(parser-> buffer, '.', 0) &&3045 CHECK_AT(parser-> buffer, '.', 1) &&3046 CHECK_AT(parser-> buffer, '.', 2))) &&3047 IS_BLANKZ_AT(parser-> buffer, 3))3055 ((CHECK_AT(parser->input, '-', 0) && 3056 CHECK_AT(parser->input, '-', 1) && 3057 CHECK_AT(parser->input, '-', 2)) || 3058 (CHECK_AT(parser->input, '.', 0) && 3059 CHECK_AT(parser->input, '.', 1) && 3060 CHECK_AT(parser->input, '.', 2))) && 3061 IS_BLANKZ_AT(parser->input, 3)) 3048 3062 { 3049 yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar", 3050 start_mark, "found unexpected document indicator"); 3063 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 3064 "while scanning a quoted scalar", start_mark, 3065 "found unexpected document indicator", parser->mark); 3051 3066 goto error; 3052 3067 } … … 3054 3069 /* Check for EOF. */ 3055 3070 3056 if (IS_Z(parser->buffer)) { 3057 yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar", 3058 start_mark, "found unexpected end of stream"); 3071 if (IS_Z(parser->input)) { 3072 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 3073 "while scanning a quoted scalar", start_mark, 3074 "found unexpected end of stream", parser->mark); 3059 3075 goto error; 3060 3076 } … … 3066 3082 leading_blanks = 0; 3067 3083 3068 while (!IS_BLANKZ(parser-> buffer))3084 while (!IS_BLANKZ(parser->input)) 3069 3085 { 3070 3086 /* Check for an escaped single quote. */ 3071 3087 3072 if (single && CHECK_AT(parser-> buffer, '\'', 0)3073 && CHECK_AT(parser-> buffer, '\'', 1))3088 if (single && CHECK_AT(parser->input, '\'', 0) 3089 && CHECK_AT(parser->input, '\'', 1)) 3074 3090 { 3075 3091 if (!STRING_EXTEND(parser, string)) goto error; 3076 *(string.pointer++) = '\'';3092 JOIN_OCTET(string, '\''); 3077 3093 SKIP(parser); 3078 3094 SKIP(parser); … … 3081 3097 /* Check for the right quote. */ 3082 3098 3083 else if (CHECK(parser-> buffer, single ? '\'' : '"'))3099 else if (CHECK(parser->input, single ? '\'' : '"')) 3084 3100 { 3085 3101 break; … … 3088 3104 /* Check for an escaped line break. */ 3089 3105 3090 else if (!single && CHECK(parser-> buffer, '\\')3091 && IS_BREAK_AT(parser-> buffer, 1))3106 else if (!single && CHECK(parser->input, '\\') 3107 && IS_BREAK_AT(parser->input, 1)) 3092 3108 { 3093 3109 if (!CACHE(parser, 3)) goto error; … … 3100 3116 /* Check for an escape sequence. */ 3101 3117 3102 else if (!single && CHECK(parser-> buffer, '\\'))3118 else if (!single && CHECK(parser->input, '\\')) 3103 3119 { 3104 3120 size_t code_length = 0; … … 3108 3124 /* Check the escape character. */ 3109 3125 3110 switch ( parser->buffer.pointer[1])3126 switch (OCTET_AT(parser->input, 1)) 3111 3127 { 3112 3128 case '0': 3113 *(string.pointer++) = '\0';3129 JOIN_OCTET(string, '\0'); 3114 3130 break; 3115 3131 3116 3132 case 'a': 3117 *(string.pointer++) = '\x07';3133 JOIN_OCTET(string, '\x07'); 3118 3134 break; 3119 3135 3120 3136 case 'b': 3121 *(string.pointer++) = '\x08';3137 JOIN_OCTET(string, '\x08'); 3122 3138 break; 3123 3139 3124 3140 case 't': 3125 3141 case '\t': 3126 *(string.pointer++) = '\x09';3142 JOIN_OCTET(string, '\x09'); 3127 3143 break; 3128 3144 3129 3145 case 'n': 3130 *(string.pointer++) = '\x0A';3146 JOIN_OCTET(string, '\x0A'); 3131 3147 break; 3132 3148 3133 3149 case 'v': 3134 *(string.pointer++) = '\x0B';3150 JOIN_OCTET(string, '\x0B'); 3135 3151 break; 3136 3152 3137 3153 case 'f': 3138 *(string.pointer++) = '\x0C';3154 JOIN_OCTET(string, '\x0C'); 3139 3155 break; 3140 3156 3141 3157 case 'r': 3142 *(string.pointer++) = '\x0D';3158 JOIN_OCTET(string, '\x0D'); 3143 3159 break; 3144 3160 3145 3161 case 'e': 3146 *(string.pointer++) = '\x1B';3162 JOIN_OCTET(string, '\x1B'); 3147 3163 break; 3148 3164 3149 3165 case ' ': 3150 *(string.pointer++) = '\x20';3166 JOIN_OCTET(string, '\x20'); 3151 3167 break; 3152 3168 3153 3169 case '"': 3154 *(string.pointer++) = '"';3170 JOIN_OCTET(string, '"'); 3155 3171 break; 3156 3172 3157 3173 case '\'': 3158 *(string.pointer++) = '\'';3174 JOIN_OCTET(string, '\''); 3159 3175 break; 3160 3176 3161 3177 case '\\': 3162 *(string.pointer++) = '\\';3178 JOIN_OCTET(string, '\\'); 3163 3179 break; 3164 3180 3165 3181 case 'N': /* NEL (#x85) */ 3166 *(string.pointer++) = '\xC2';3167 *(string.pointer++) = '\x85';3182 JOIN_OCTET(string, '\xC2'); 3183 JOIN_OCTET(string, '\x85'); 3168 3184 break; 3169 3185 3170 3186 case '_': /* #xA0 */ 3171 *(string.pointer++) = '\xC2';3172 *(string.pointer++) = '\xA0';3187 JOIN_OCTET(string, '\xC2'); 3188 JOIN_OCTET(string, '\xA0'); 3173 3189 break; 3174 3190 3175 3191 case 'L': /* LS (#x2028) */ 3176 *(string.pointer++) = '\xE2';3177 *(string.pointer++) = '\x80';3178 *(string.pointer++) = '\xA8';3192 JOIN_OCTET(string, '\xE2'); 3193 JOIN_OCTET(string, '\x80'); 3194 JOIN_OCTET(string, '\xA8'); 3179 3195 break; 3180 3196 3181 3197 case 'P': /* PS (#x2029) */ 3182 *(string.pointer++) = '\xE2';3183 *(string.pointer++) = '\x80';3184 *(string.pointer++) = '\xA9';3198 JOIN_OCTET(string, '\xE2'); 3199 JOIN_OCTET(string, '\x80'); 3200 JOIN_OCTET(string, '\xA9'); 3185 3201 break; 3186 3202 … … 3198 3214 3199 3215 default: 3200 yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", 3201 start_mark, "found unknown escape character"); 3216 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 3217 "while parsing a quoted scalar", start_mark, 3218 "found unknown escape character", parser->mark); 3202 3219 goto error; 3203 3220 } … … 3211 3228 { 3212 3229 unsigned int value = 0; 3213 size_t k;3230 size_t idx; 3214 3231 3215 3232 /* Scan the character value. */ … … 3217 3234 if (!CACHE(parser, code_length)) goto error; 3218 3235 3219 for (k = 0; k < code_length; k ++) { 3220 if (!IS_HEX_AT(parser->buffer, k)) { 3221 yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", 3222 start_mark, "did not find expected hexdecimal number"); 3236 for (idx = 0; idx < code_length; idx ++) { 3237 if (!IS_HEX_AT(parser->input, idx)) { 3238 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 3239 "while parsing a quoted scalar", start_mark, 3240 "did not find expected hexdecimal number", 3241 parser->mark); 3223 3242 goto error; 3224 3243 } 3225 value = (value << 4) + AS_HEX_AT(parser-> buffer, k);3244 value = (value << 4) + AS_HEX_AT(parser->input, idx); 3226 3245 } 3227 3246 … … 3229 3248 3230 3249 if ((value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF) { 3231 yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", 3232 start_mark, "found invalid Unicode character escape code"); 3250 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 3251 "while parsing a quoted scalar", start_mark, 3252 "found invalid Unicode character escape code", 3253 parser->mark); 3233 3254 goto error; 3234 3255 } 3235 3256 3236 3257 if (value <= 0x7F) { 3237 *(string.pointer++) = value;3258 JOIN_OCTET(string, value); 3238 3259 } 3239 3260 else if (value <= 0x7FF) { 3240 *(string.pointer++) = 0xC0 + (value >> 6);3241 *(string.pointer++) = 0x80 + (value & 0x3F);3261 JOIN_OCTET(string, 0xC0 + (value >> 6)); 3262 JOIN_OCTET(string, 0x80 + (value & 0x3F)); 3242 3263 } 3243 3264 else if (value <= 0xFFFF) { 3244 *(string.pointer++) = 0xE0 + (value >> 12);3245 *(string.pointer++) = 0x80 + ((value >> 6) & 0x3F);3246 *(string.pointer++) = 0x80 + (value & 0x3F);3265 JOIN_OCTET(string, 0xE0 + (value >> 12)); 3266 JOIN_OCTET(string, 0x80 + ((value >> 6) & 0x3F)); 3267 JOIN_OCTET(string, 0x80 + (value & 0x3F)); 3247 3268 } 3248 3269 else { 3249 *(string.pointer++) = 0xF0 + (value >> 18);3250 *(string.pointer++) = 0x80 + ((value >> 12) & 0x3F);3251 *(string.pointer++) = 0x80 + ((value >> 6) & 0x3F);3252 *(string.pointer++) = 0x80 + (value & 0x3F);3270 JOIN_OCTET(string, 0xF0 + (value >> 18)); 3271 JOIN_OCTET(string, 0x80 + ((value >> 12) & 0x3F)); 3272 JOIN_OCTET(string, 0x80 + ((value >> 6) & 0x3F)); 3273 JOIN_OCTET(string, 0x80 + (value & 0x3F)); 3253 3274 } 3254 3275 3255 3276 /* Advance the pointer. */ 3256 3277 3257 for ( k = 0; k < code_length; k++) {3278 for (idx = 0; idx < code_length; idx ++) { 3258 3279 SKIP(parser); 3259 3280 } … … 3273 3294 /* Check if we are at the end of the scalar. */ 3274 3295 3275 if (CHECK(parser-> buffer, single ? '\'' : '"'))3296 if (CHECK(parser->input, single ? '\'' : '"')) 3276 3297 break; 3277 3298 … … 3280 3301 if (!CACHE(parser, 1)) goto error; 3281 3302 3282 while (IS_BLANK(parser-> buffer) || IS_BREAK(parser->buffer))3303 while (IS_BLANK(parser->input) || IS_BREAK(parser->input)) 3283 3304 { 3284 if (IS_BLANK(parser-> buffer))3305 if (IS_BLANK(parser->input)) 3285 3306 { 3286 3307 /* Consume a space or a tab character. */ … … 3319 3340 /* Do we need to fold line breaks? */ 3320 3341 3321 if (leading_break. start[0] == '\n') {3322 if (trailing_breaks. start[0] == '\0') {3342 if (leading_break.buffer[0] == '\n') { 3343 if (trailing_breaks.buffer[0] == '\0') { 3323 3344 if (!STRING_EXTEND(parser, string)) goto error; 3324 *(string.pointer++) = ' ';3345 JOIN_OCTET(string, ' '); 3325 3346 } 3326 3347 else { … … 3352 3373 /* Create a token. */ 3353 3374 3354 SCALAR_TOKEN_INIT(*token, string. start, string.pointer-string.start,3375 SCALAR_TOKEN_INIT(*token, string.buffer, string.pointer, 3355 3376 single ? YAML_SINGLE_QUOTED_SCALAR_STYLE : YAML_DOUBLE_QUOTED_SCALAR_STYLE, 3356 3377 start_mark, end_mark); … … 3387 3408 int indent = parser->indent+1; 3388 3409 3389 if (!STRING_INIT(parser, string, INITIAL_STRING_SIZE)) goto error; 3390 if (!STRING_INIT(parser, leading_break, INITIAL_STRING_SIZE)) goto error; 3391 if (!STRING_INIT(parser, trailing_breaks, INITIAL_STRING_SIZE)) goto error; 3392 if (!STRING_INIT(parser, whitespaces, INITIAL_STRING_SIZE)) goto error; 3410 if (!STRING_INIT(parser, string, INITIAL_STRING_CAPACITY)) 3411 goto error; 3412 if (!STRING_INIT(parser, leading_break, INITIAL_STRING_CAPACITY)) 3413 goto error; 3414 if (!STRING_INIT(parser, trailing_breaks, INITIAL_STRING_CAPACITY)) 3415 goto error; 3416 if (!STRING_INIT(parser, whitespaces, INITIAL_STRING_CAPACITY)) 3417 goto error; 3393 3418 3394 3419 start_mark = end_mark = parser->mark; … … 3403 3428 3404 3429 if (parser->mark.column == 0 && 3405 ((CHECK_AT(parser-> buffer, '-', 0) &&3406 CHECK_AT(parser-> buffer, '-', 1) &&3407 CHECK_AT(parser-> buffer, '-', 2)) ||3408 (CHECK_AT(parser-> buffer, '.', 0) &&3409 CHECK_AT(parser-> buffer, '.', 1) &&3410 CHECK_AT(parser-> buffer, '.', 2))) &&3411 IS_BLANKZ_AT(parser-> buffer, 3)) break;3430 ((CHECK_AT(parser->input, '-', 0) && 3431 CHECK_AT(parser->input, '-', 1) && 3432 CHECK_AT(parser->input, '-', 2)) || 3433 (CHECK_AT(parser->input, '.', 0) && 3434 CHECK_AT(parser->input, '.', 1) && 3435 CHECK_AT(parser->input, '.', 2))) && 3436 IS_BLANKZ_AT(parser->input, 3)) break; 3412 3437 3413 3438 /* Check for a comment. */ 3414 3439 3415 if (CHECK(parser-> buffer, '#'))3440 if (CHECK(parser->input, '#')) 3416 3441 break; 3417 3442 3418 3443 /* Consume non-blank characters. */ 3419 3444 3420 while (!IS_BLANKZ(parser-> buffer))3445 while (!IS_BLANKZ(parser->input)) 3421 3446 { 3422 3447 /* Check for 'x:x' in the flow context. TODO: Fix the test "spec-08-13". */ 3423 3448 3424 3449 if (parser->flow_level 3425 && CHECK(parser->buffer, ':') 3426 && !IS_BLANKZ_AT(parser->buffer, 1)) { 3427 yaml_parser_set_scanner_error(parser, "while scanning a plain scalar", 3428 start_mark, "found unexpected ':'"); 3450 && CHECK(parser->input, ':') 3451 && !IS_BLANKZ_AT(parser->input, 1)) { 3452 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 3453 "while scanning a plain scalar", start_mark, 3454 "found unexpected ':'", parser->mark); 3429 3455 goto error; 3430 3456 } … … 3432 3458 /* Check for indicators that may end a plain scalar. */ 3433 3459 3434 if ((CHECK(parser-> buffer, ':') && IS_BLANKZ_AT(parser->buffer, 1))3460 if ((CHECK(parser->input, ':') && IS_BLANKZ_AT(parser->input, 1)) 3435 3461 || (parser->flow_level && 3436 (CHECK(parser-> buffer, ',') || CHECK(parser->buffer, ':')3437 || CHECK(parser-> buffer, '?') || CHECK(parser->buffer, '[')3438 || CHECK(parser-> buffer, ']') || CHECK(parser->buffer, '{')3439 || CHECK(parser-> buffer, '}'))))3462 (CHECK(parser->input, ',') || CHECK(parser->input, ':') 3463 || CHECK(parser->input, '?') || CHECK(parser->input, '[') 3464 || CHECK(parser->input, ']') || CHECK(parser->input, '{') 3465 || CHECK(parser->input, '}')))) 3440 3466 break; 3441 3467 3442 3468 /* Check if we need to join whitespaces and breaks. */ 3443 3469 3444 if (leading_blanks || whitespaces. start != whitespaces.pointer)3470 if (leading_blanks || whitespaces.pointer > 0) 3445 3471 { 3446 3472 if (leading_blanks) … … 3448 3474 /* Do we need to fold line breaks? */ 3449 3475 3450 if (leading_break. start[0] == '\n') {3451 if (trailing_breaks. start[0] == '\0') {3476 if (leading_break.buffer[0] == '\n') { 3477 if (trailing_breaks.buffer[0] == '\0') { 3452 3478 if (!STRING_EXTEND(parser, string)) goto error; 3453 *(string.pointer++) = ' ';3479 JOIN_OCTET(string, ' '); 3454 3480 } 3455 3481 else { … … 3486 3512 /* Is it the end? */ 3487 3513 3488 if (!(IS_BLANK(parser-> buffer) || IS_BREAK(parser->buffer)))3514 if (!(IS_BLANK(parser->input) || IS_BREAK(parser->input))) 3489 3515 break; 3490 3516 … … 3493 3519 if (!CACHE(parser, 1)) goto error; 3494 3520 3495 while (IS_BLANK(parser-> buffer) || IS_BREAK(parser->buffer))3521 while (IS_BLANK(parser->input) || IS_BREAK(parser->input)) 3496 3522 { 3497 if (IS_BLANK(parser-> buffer))3523 if (IS_BLANK(parser->input)) 3498 3524 { 3499 3525 /* Check for tab character that abuse intendation. */ 3500 3526 3501 3527 if (leading_blanks && (int)parser->mark.column < indent 3502 && IS_TAB(parser->buffer)) { 3503 yaml_parser_set_scanner_error(parser, "while scanning a plain scalar", 3504 start_mark, "found a tab character that violate intendation"); 3528 && IS_TAB(parser->input)) { 3529 SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 3530 "while scanning a plain scalar", start_mark, 3531 "found a tab character that violate intendation", 3532 parser->mark); 3505 3533 goto error; 3506 3534 } … … 3543 3571 /* Create a token. */ 3544 3572 3545 SCALAR_TOKEN_INIT(*token, string. start, string.pointer-string.start,3573 SCALAR_TOKEN_INIT(*token, string.buffer, string.pointer, 3546 3574 YAML_PLAIN_SCALAR_STYLE, start_mark, end_mark); 3547 3575 3548 /* Note that we change the ' simple_key_allowed' flag. */3576 /* Note that we change the 'is_simple_key_allowed' flag. */ 3549 3577 3550 3578 if (leading_blanks) { 3551 parser-> simple_key_allowed = 1;3579 parser->is_simple_key_allowed = 1; 3552 3580 } 3553 3581 -
libyaml/trunk/src/writer.c
r239 r263 6 6 */ 7 7 8 static int9 yaml_emitter_set_writer_error(yaml_emitter_t *emitter, const char *problem);10 11 8 YAML_DECLARE(int) 12 9 yaml_emitter_flush(yaml_emitter_t *emitter); 13 14 /*15 * Set the writer error and return 0.16 */17 18 static int19 yaml_emitter_set_writer_error(yaml_emitter_t *emitter, const char *problem)20 {21 emitter->error = YAML_WRITER_ERROR;22 emitter->problem = problem;23 24 return 0;25 }26 10 27 11 /* … … 35 19 36 20 assert(emitter); /* Non-NULL emitter object is expected. */ 37 assert(emitter->write _handler);/* Write handler must be set. */21 assert(emitter->writer); /* Write handler must be set. */ 38 22 assert(emitter->encoding); /* Output encoding must be set. */ 39 40 emitter->buffer.last = emitter->buffer.pointer;41 emitter->buffer.pointer = emitter->buffer.start;42 23 43 24 /* Check if the buffer is empty. */ 44 25 45 if ( emitter->buffer.start == emitter->buffer.last) {26 if (!emitter->output.pointer) { 46 27 return 1; 47 28 } 29 30 /* Switch the pointer to the beginning of the buffer. */ 31 32 emitter->output.capacity = emitter->output.pointer; 33 emitter->output.pointer = 0; 48 34 49 35 /* If the output encoding is UTF-8, we don't need to recode the buffer. */ … … 51 37 if (emitter->encoding == YAML_UTF8_ENCODING) 52 38 { 53 if (emitter->write_handler(emitter->write_handler_data, 54 emitter->buffer.start, 55 emitter->buffer.last - emitter->buffer.start)) { 56 emitter->buffer.last = emitter->buffer.start; 57 emitter->buffer.pointer = emitter->buffer.start; 39 if (emitter->writer(emitter->writer_data, 40 emitter->output.buffer, emitter->output.capacity)) { 41 emitter->offset += emitter->output.capacity; 42 emitter->output.capacity = OUTPUT_BUFFER_CAPACITY; 58 43 return 1; 59 44 } 60 45 else { 61 return yaml_emitter_set_writer_error(emitter, "Write error");46 return WRITER_ERROR_INIT(emitter, "Write error", emitter->offset); 62 47 } 63 48 } … … 68 53 high = (emitter->encoding == YAML_UTF16LE_ENCODING ? 1 : 0); 69 54 70 while (emitter-> buffer.pointer != emitter->buffer.last)55 while (emitter->output.pointer != emitter->output.capacity) 71 56 { 72 57 unsigned char octet; 73 58 unsigned int width; 74 59 unsigned int value; 75 size_t k;60 size_t idx; 76 61 77 62 /* … … 82 67 /* Read the next UTF-8 character. */ 83 68 84 octet = emitter->buffer.pointer[0];69 octet = OCTET(emitter->output); 85 70 86 71 width = (octet & 0x80) == 0x00 ? 1 : … … 94 79 (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; 95 80 96 for ( k = 1; k < width; k++) {97 octet = emitter->buffer.pointer[k];81 for (idx = 1; idx < width; idx ++) { 82 octet = OCTET_AT(emitter->output, idx); 98 83 value = (value << 6) + (octet & 0x3F); 99 84 } 100 85 101 emitter-> buffer.pointer += width;86 emitter->output.pointer += width; 102 87 103 88 /* Write the character. */ … … 105 90 if (value < 0x10000) 106 91 { 107 emitter->raw_buffer.last[high]= value >> 8;108 emitter->raw_buffer.last[low]= value & 0xFF;92 OCTET_AT(emitter->raw_output, high) = value >> 8; 93 OCTET_AT(emitter->raw_output, low) = value & 0xFF; 109 94 110 emitter->raw_ buffer.last+= 2;95 emitter->raw_output.pointer += 2; 111 96 } 112 97 else … … 115 100 116 101 value -= 0x10000; 117 emitter->raw_buffer.last[high]= 0xD8 + (value >> 18);118 emitter->raw_buffer.last[low]= (value >> 10) & 0xFF;119 emitter->raw_buffer.last[high+2]= 0xDC + ((value >> 8) & 0xFF);120 emitter->raw_buffer.last[low+2]= value & 0xFF;102 OCTET_AT(emitter->raw_output, high) = 0xD8 + (value >> 18); 103 OCTET_AT(emitter->raw_output, low) = (value >> 10) & 0xFF; 104 OCTET_AT(emitter->raw_output, high+2) = 0xDC + ((value >> 8) & 0xFF); 105 OCTET_AT(emitter->raw_output, low+2) = value & 0xFF; 121 106 122 emitter->raw_ buffer.last+= 4;107 emitter->raw_output.pointer += 4; 123 108 } 124 109 } … … 126 111 /* Write the raw buffer. */ 127 112 128 if (emitter->write_handler(emitter->write_handler_data, 129 emitter->raw_buffer.start, 130 emitter->raw_buffer.last - emitter->raw_buffer.start)) { 131 emitter->buffer.last = emitter->buffer.start; 132 emitter->buffer.pointer = emitter->buffer.start; 133 emitter->raw_buffer.last = emitter->raw_buffer.start; 134 emitter->raw_buffer.pointer = emitter->raw_buffer.start; 113 if (emitter->writer(emitter->writer_data, 114 emitter->raw_output.buffer, emitter->raw_output.pointer)) { 115 emitter->output.pointer = 0; 116 emitter->output.capacity = OUTPUT_BUFFER_CAPACITY; 117 emitter->offset += emitter->raw_output.pointer; 118 emitter->raw_output.pointer = 0; 135 119 return 1; 136 120 } 137 121 else { 138 return yaml_emitter_set_writer_error(emitter, "Write error");122 return WRITER_ERROR_INIT(emitter, "Write error", emitter->offset); 139 123 } 140 124 } -
libyaml/trunk/src/yaml_private.h
r262 r263 72 72 (memset(&(error), 0, sizeof(error)), \ 73 73 (error).type = (error_type), \ 74 (error). type.dumping.problem = (error_problem), \74 (error).data.dumping.problem = (error_problem), \ 75 75 0) 76 76 … … 105 105 WRITING_ERROR_INIT((self)->error,YAML_WRITER_ERROR,problem,offset) 106 106 107 #define EMITTER_ERROR_INIT(self, context,problem)\107 #define EMITTER_ERROR_INIT(self,problem) \ 108 108 DUMPING_ERROR_INIT((self)->error,YAML_EMITTER_ERROR,problem) 109 109 … … 148 148 #define INITIAL_QUEUE_CAPACITY 16 149 149 #define INITIAL_STRING_CAPACITY 16 150 151 /*152 * Input/output buffer management.153 */154 155 #define STORAGE_INIT(self,storage,storage_capacity) \156 (((storage).buffer = yaml_malloc(storage_capacity)) ? \157 ((storage).pointer = (storage).length = 0, \158 (buffer).capacity = (storage_capacity) \159 1) : \160 ((self)->error.type = YAML_MEMORY_ERROR, \161 0))162 163 #define STORAGE_DEL(self,storage) \164 (yaml_free((storage).buffer), \165 (storage).pointer = (storage).length = (storage).capacity = 0)166 150 167 151 /* … … 183 167 yaml_char_t *adj_buffer, size_t adj_pointer, size_t adj_capacity); 184 168 185 #define NULL_STRING { NULL, NULL, NULL}169 #define NULL_STRING { NULL, 0, 0 } 186 170 187 171 #define STRING(string,capacity) { (string), 0, (capacity) } … … 460 444 461 445 #define MOVE(string) ((string).pointer += WIDTH((string))) 446 447 /* 448 * Write a single octet and bump the pointer. 449 */ 450 451 #define JOIN_OCTET(string,octet) \ 452 ((string).buffer[(string).pointer++] = (octet)) 462 453 463 454 /* … … 864 855 yaml_char_t *buffer; 865 856 size_t pointer; 866 size_t length;867 857 size_t capacity; 868 858 } input; … … 875 865 unsigned char *buffer; 876 866 size_t pointer; 877 size_t length;878 867 size_t capacity; 879 868 } raw_input; … … 1069 1058 yaml_char_t *buffer; 1070 1059 size_t pointer; 1071 size_t length;1072 1060 size_t capacity; 1073 1061 } output; … … 1077 1065 yaml_char_t *buffer; 1078 1066 size_t pointer; 1079 size_t length;1080 1067 size_t capacity; 1081 1068 } raw_output; 1069 1070 /* The offset of the current position (in bytes). */ 1071 size_t offset; 1082 1072 1083 1073 /* The stream encoding. */ … … 1151 1141 int column; 1152 1142 /* If the last character was a whitespace? */ 1153 int whitespace;1143 int is_whitespace; 1154 1144 /* If the last character was an indentation character (' ', '-', '?', ':')? */ 1155 int i ndention;1145 int is_indention; 1156 1146 1157 1147 /* Anchor analysis. */ -
libyaml/trunk/tests/run-scanner.c
r242 r263 22 22 { 23 23 FILE *file; 24 yaml_parser_t parser;24 yaml_parser_t *parser; 25 25 yaml_token_t token; 26 26 int done = 0; … … 34 34 assert(file); 35 35 36 assert( yaml_parser_initialize(&parser));36 assert((parser = yaml_parser_new())); 37 37 38 yaml_parser_set_ input_file(&parser, file);38 yaml_parser_set_file_reader(parser, file); 39 39 40 40 while (!done) 41 41 { 42 if (!yaml_parser_scan( &parser, &token)) {42 if (!yaml_parser_scan(parser, &token)) { 43 43 error = 1; 44 44 break; … … 47 47 done = (token.type == YAML_STREAM_END_TOKEN); 48 48 49 yaml_token_de lete(&token);49 yaml_token_destroy(&token); 50 50 51 51 count ++; 52 52 } 53 53 54 yaml_parser_delete( &parser);54 yaml_parser_delete(parser); 55 55 56 56 assert(!fclose(file));
Note: See TracChangeset
for help on using the changeset viewer.
