Changeset 199
- Timestamp:
- 07/03/06 09:34:57 (2 years ago)
- Files:
-
- libyaml/trunk/include/yaml/yaml.h (modified) (4 diffs)
- libyaml/trunk/src/api.c (modified) (5 diffs)
- libyaml/trunk/src/reader.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libyaml/trunk/include/yaml/yaml.h
r185 r199 78 78 typedef unsigned char yaml_char_t; 79 79 80 /** The version directive data. */ 81 typedef struct { 82 /** The major version number. */ 83 int major; 84 /** The minor version number. */ 85 int minor; 86 } yaml_version_directive_t; 87 88 /** The tag directive data. */ 89 typedef struct { 90 /** The tag handle. */ 91 yaml_char_t *handle; 92 /** The tag prefix. */ 93 yaml_char_t *prefix; 94 } yaml_tag_directive_t; 95 80 96 /** The stream encoding. */ 81 97 typedef enum { … … 195 211 union { 196 212 197 /** The stream encoding (for @c YAML_STREAM_START_TOKEN). */ 198 yaml_encoding_t encoding; 199 200 /** The anchor (for @c YAML_ALIAS_TOKEN and @c YAML_ANCHOR_TOKEN). */ 201 yaml_char_t *anchor; 213 /** The stream start (for @c YAML_STREAM_START_TOKEN). */ 214 struct { 215 /** The stream encoding. */ 216 yaml_encoding_t encoding; 217 } stream_start; 218 219 /** The alias (for @c YAML_ALIAS_TOKEN). */ 220 struct { 221 /** The alias value. */ 222 yaml_char_t *value; 223 } alias; 224 225 /** The anchor (for @c YAML_ANCHOR_TOKEN). */ 226 struct { 227 /** The anchor value. */ 228 yaml_char_t *value; 229 } anchor; 202 230 203 231 /** The tag (for @c YAML_TAG_TOKEN). */ … … 420 448 /** @} */ 421 449 422 /* 423 450 /** 451 * @defgroup events Events 452 * @{ 453 */ 454 455 /** Event types. */ 424 456 typedef enum { 425 457 YAML_STREAM_START_EVENT, … … 439 471 } yaml_event_type_t; 440 472 473 /** The event structure. */ 441 474 typedef struct { 475 476 /** The event type. */ 442 477 yaml_event_type_t type; 478 479 /** The event data. */ 443 480 union { 444 struct { 481 482 /** The stream parameters (for @c YAML_STREAM_START_EVENT). */ 483 struct { 484 /** The document encoding. */ 445 485 yaml_encoding_t encoding; 446 486 } stream_start; 447 struct { 448 struct { 449 int major; 450 int minor; 451 } version; 452 struct { 453 char *handle; 454 char *prefix; 455 } **tag_pairs; 487 488 /** The document parameters (for @c YAML_DOCUMENT_START_EVENT). */ 489 struct { 490 /** The version directive. */ 491 yaml_version_directive_t *version_directive; 492 /** The list of tag directives. */ 493 yaml_tag_directive_t **tag_directives; 494 /** Is the document indicator implicit? */ 456 495 int implicit; 457 496 } document_start; 458 struct { 497 498 /** The document end parameters (for @c YAML_DOCUMENT_END_EVENT). */ 499 struct { 500 /** Is the document end indicator implicit? */ 459 501 int implicit; 460 502 } document_end; 461 struct { 462 char *anchor; 503 504 /** The alias parameters (for @c YAML_ALIAS_EVENT). */ 505 struct { 506 /** The anchor. */ 507 yaml_char_t *anchor; 463 508 } alias; 464 struct { 465 char *anchor; 466 char *tag; 467 char *value; 509 510 /** The scalar parameters (for @c YAML_SCALAR_EVENT). */ 511 struct { 512 /** The anchor. */ 513 yaml_char_t *anchor; 514 /** The tag. */ 515 yaml_char_t *tag; 516 /** The scalar value. */ 517 yaml_char_t *value; 518 /** The length of the scalar value. */ 468 519 size_t length; 520 /** Is the tag optional for the plain style? */ 469 521 int plain_implicit; 522 /** Is the tag optional for any non-plain style? */ 470 523 int quoted_implicit; 524 /** The scalar style. */ 471 525 yaml_scalar_style_t style; 472 526 } scalar; 473 struct { 474 char *anchor; 475 char *tag; 527 528 /** The sequence parameters (for @c YAML_SEQUENCE_START_EVENT). */ 529 struct { 530 /** The anchor. */ 531 yaml_char_t *anchor; 532 /** The tag. */ 533 yaml_char_t *tag; 534 /** Is the tag optional? */ 476 535 int implicit; 536 /** The sequence style. */ 477 537 yaml_sequence_style_t style; 478 538 } sequence_start; 479 struct { 480 char *anchor; 481 char *tag; 539 540 /** The mapping parameters (for @c YAML_MAPPING_START_EVENT). */ 541 struct { 542 /** The anchor. */ 543 yaml_char_t *anchor; 544 /** The tag. */ 545 yaml_char_t *tag; 546 /** Is the tag optional? */ 482 547 int implicit; 548 /** The mapping style. */ 483 549 yaml_mapping_style_t style; 484 550 } mapping_start; 551 485 552 } data; 553 554 /** The beginning of the token. */ 486 555 yaml_mark_t start_mark; 556 557 /** The end of the token. */ 487 558 yaml_mark_t end_mark; 488 559 } yaml_event_t; 489 560 490 */ 491 561 /** 562 * Create a new @c YAML_STREAM_START_EVENT event. 563 * 564 * @param[in] encoding The stream encoding. 565 * @param[in] start_mark The beginning of the event. 566 * @param[in] end_mark The end of the event. 567 * 568 * @returns A new event object, or @c NULL on error. 569 */ 570 571 YAML_DECLARE(yaml_event_t *) 572 yaml_stream_start_event_new(yaml_encoding_t encoding, 573 yaml_mark_t start_mark, yaml_mark_t end_mark); 574 575 /** 576 * Create a new @c YAML_STREAM_END_TOKEN event. 577 * 578 * @param[in] start_mark The beginning of the event. 579 * @param[in] end_mark The end of the event. 580 * 581 * @returns A new event object, or @c NULL on error. 582 */ 583 584 YAML_DECLARE(yaml_event_t *) 585 yaml_stream_end_event_new(yaml_mark_t start_mark, yaml_mark_t end_mark); 586 587 /** 588 * Create a new @c YAML_DOCUMENT_START_EVENT event. 589 * 590 * @param[in] version_directive The version directive or @c NULL. 591 * @param[in] tag_directives A list of tag directives or @c NULL. 592 * @param[in] implicit Is the document indicator present? 593 * @param[in] start_mark The beginning of the event. 594 * @param[in] end_mark The end of the event. 595 * 596 * @returns A new event object, or @c NULL on error. 597 */ 598 599 YAML_DECLARE(yaml_event_t *) 600 yaml_document_start_event_new(yaml_version_directive_t *version_directive, 601 yaml_tag_directive_t **tag_directives, int implicit, 602 yaml_mark_t start_mark, yaml_mark_t end_mark); 603 604 /** 605 * Create a new @c YAML_DOCUMENT_END_EVENT event. 606 * 607 * @param[in] implicit Is the document end indicator present? 608 * @param[in] start_mark The beginning of the event. 609 * @param[in] end_mark The end of the event. 610 * 611 * @returns A new event object, or @c NULL on error. 612 */ 613 614 YAML_DECLARE(yaml_event_t *) 615 yaml_document_end_event_new(int implicit, 616 yaml_mark_t start_mark, yaml_mark_t end_mark); 617 618 /** 619 * Create a new @c YAML_ALIAS_EVENT event. 620 * 621 * @param[in] anchor The anchor value. 622 * @param[in] start_mark The beginning of the event. 623 * @param[in] end_mark The end of the event. 624 * 625 * @returns A new event object, or @c NULL on error. 626 */ 627 628 YAML_DECLARE(yaml_event_t *) 629 yaml_alias_event_new(yaml_char_t *anchor, 630 yaml_mark_t start_mark, yaml_mark_t end_mark); 631 632 /** 633 * Create a new @c YAML_SCALAR_EVENT event. 634 * 635 * @param[in] anchor The anchor value or @c NULL. 636 * @param[in] tag The tag value or @c NULL. 637 * @param[in] value The scalar value. 638 * @param[in] length The length of the scalar value. 639 * @param[in] plain_implicit Is the tag optional for the plain style? 640 * @param[in] quoted_implicit Is the tag optional for any non-plain style? 641 * @param[in] style The scalar style. 642 * @param[in] start_mark The beginning of the event. 643 * @param[in] end_mark The end of the event. 644 * 645 * @returns A new event object, or @c NULL on error. 646 */ 647 648 YAML_DECLARE(yaml_event_t *) 649 yaml_scalar_event_new(yaml_char_t *anchor, yaml_char_t *tag, 650 yaml_char_t *value, size_t length, 651 int plain_implicit, int quoted_implicit, 652 yaml_scalar_style_t style, 653 yaml_mark_t start_mark, yaml_mark_t end_mark); 654 655 /** 656 * Create a new @c YAML_SEQUENCE_START_EVENT event. 657 * 658 * @param[in] anchor The anchor value or @c NULL. 659 * @param[in] tag The tag value or @c NULL. 660 * @param[in] implicit Is the tag optional? 661 * @param[in] style The sequence style. 662 * @param[in] start_mark The beginning of the event. 663 * @param[in] end_mark The end of the event. 664 * 665 * @returns A new event object, or @c NULL on error. 666 */ 667 668 YAML_DECLARE(yaml_event_t *) 669 yaml_sequence_start_new(yaml_char_t *anchor, yaml_char_t *tag, 670 int implicit, yaml_sequence_style_t style, 671 yaml_mark_t start_mark, yaml_mark_t end_mark); 672 673 /** 674 * Create a new @c YAML_SEQUENCE_END_EVENT event. 675 * 676 * @param[in] start_mark The beginning of the event. 677 * @param[in] end_mark The end of the event. 678 * 679 * @returns A new event object, or @c NULL on error. 680 */ 681 682 YAML_DECLARE(yaml_event_t *) 683 yaml_sequence_end_new(yaml_mark_t start_mark, yaml_mark_t end_mark); 684 685 /** 686 * Create a new @c YAML_MAPPING_START_EVENT event. 687 * 688 * @param[in] anchor The anchor value or @c NULL. 689 * @param[in] tag The tag value or @c NULL. 690 * @param[in] implicit Is the tag optional? 691 * @param[in] style The mapping style. 692 * @param[in] start_mark The beginning of the event. 693 * @param[in] end_mark The end of the event. 694 * 695 * @returns A new event object, or @c NULL on error. 696 */ 697 698 YAML_DECLARE(yaml_event_t *) 699 yaml_mapping_start_new(yaml_char_t *anchor, yaml_char_t *tag, 700 int implicit, yaml_mapping_style_t style, 701 yaml_mark_t start_mark, yaml_mark_t end_mark); 702 703 /** 704 * Create a new @c YAML_MAPPING_END_EVENT event. 705 * 706 * @param[in] start_mark The beginning of the event. 707 * @param[in] end_mark The end of the event. 708 * 709 * @returns A new event object, or @c NULL on error. 710 */ 711 712 YAML_DECLARE(yaml_event_t *) 713 yaml_mapping_end_new(yaml_mark_t start_mark, yaml_mark_t end_mark); 714 715 /** 716 * Destroy an event object. 717 * 718 * @param[in] event An event object. 719 */ 720 721 YAML_DECLARE(void) 722 yaml_event_delete(yaml_event_t *event); 723 724 /** @} */ 492 725 493 726 /** libyaml/trunk/src/api.c
r190 r199 277 277 if (!token) return NULL; 278 278 279 token->data. encoding = encoding;279 token->data.stream_start.encoding = encoding; 280 280 281 281 return token; … … 348 348 if (!token) return NULL; 349 349 350 token->data.a nchor= anchor;350 token->data.alias.value = anchor; 351 351 352 352 return token; … … 366 366 if (!token) return NULL; 367 367 368 token->data.anchor = anchor;368 token->data.anchor.value = anchor; 369 369 370 370 return token; … … 428 428 429 429 case YAML_ALIAS_TOKEN: 430 yaml_free(token->data.alias.value); 431 break; 432 430 433 case YAML_ANCHOR_TOKEN: 431 yaml_free(token->data.anchor );434 yaml_free(token->data.anchor.value); 432 435 break; 433 436 … … 447 450 } 448 451 452 /* 453 * Create an event. 454 */ 455 456 static yaml_event_t * 457 yaml_event_new(yaml_event_type_t type, 458 yaml_mark_t start_mark, yaml_mark_t end_mark) 459 { 460 yaml_event_t *event = yaml_malloc(sizeof(yaml_event_t)); 461 462 if (!event) return NULL; 463 464 memset(event, 0, sizeof(yaml_event_t)); 465 466 event->type = type; 467 event->start_mark = start_mark; 468 event->end_mark = end_mark; 469 470 return event; 471 } 472 473 /* 474 * Create a STREAM-START event. 475 */ 476 477 YAML_DECLARE(yaml_event_t *) 478 yaml_stream_start_event_new(yaml_encoding_t encoding, 479 yaml_mark_t start_mark, yaml_mark_t end_mark) 480 { 481 yaml_event_t *event = yaml_event_new(YAML_STREAM_START_EVENT, 482 start_mark, end_mark); 483 484 if (!event) return NULL; 485 486 event->data.stream_start.encoding = encoding; 487 488 return event; 489 } 490 491 /* 492 * Create a STREAM-END event. 493 */ 494 495 YAML_DECLARE(yaml_event_t *) 496 yaml_stream_end_event_new(yaml_mark_t start_mark, yaml_mark_t end_mark) 497 { 498 return yaml_event_new(YAML_STREAM_END_EVENT, start_mark, end_mark); 499 } 500 501 /* 502 * Create a DOCUMENT-START event. 503 */ 504 505 YAML_DECLARE(yaml_event_t *) 506 yaml_document_start_event_new(yaml_version_directive_t *version_directive, 507 yaml_tag_directive_t **tag_directives, int implicit, 508 yaml_mark_t start_mark, yaml_mark_t end_mark) 509 { 510 yaml_event_t *event = yaml_event_new(YAML_DOCUMENT_START_EVENT, 511 start_mark, end_mark); 512 513 if (!event) return NULL; 514 515 event->data.document_start.version_directive = version_directive; 516 event->data.document_start.tag_directives = tag_directives; 517 event->data.document_start.implicit = implicit; 518 519 return event; 520 } 521 522 /* 523 * Create a DOCUMENT-END event. 524 */ 525 526 YAML_DECLARE(yaml_event_t *) 527 yaml_document_end_event_new(int implicit, 528 yaml_mark_t start_mark, yaml_mark_t end_mark) 529 { 530 yaml_event_t *event = yaml_event_new(YAML_DOCUMENT_END_EVENT, 531 start_mark, end_mark); 532 533 if (!event) return NULL; 534 535 event->data.document_end.implicit = implicit; 536 537 return event; 538 } 539 540 /* 541 * Create an ALIAS event. 542 */ 543 544 YAML_DECLARE(yaml_event_t *) 545 yaml_alias_event_new(yaml_char_t *anchor, 546 yaml_mark_t start_mark, yaml_mark_t end_mark) 547 { 548 yaml_event_t *event = yaml_event_new(YAML_ALIAS_EVENT, 549 start_mark, end_mark); 550 551 if (!event) return NULL; 552 553 event->data.alias.anchor = anchor; 554 555 return event; 556 } 557 558 /* 559 * Create a SCALAR event. 560 */ 561 562 YAML_DECLARE(yaml_event_t *) 563 yaml_scalar_event_new(yaml_char_t *anchor, yaml_char_t *tag, 564 yaml_char_t *value, size_t length, 565 int plain_implicit, int quoted_implicit, 566 yaml_scalar_style_t style, 567 yaml_mark_t start_mark, yaml_mark_t end_mark) 568 { 569 yaml_event_t *event = yaml_event_new(YAML_SCALAR_EVENT, 570 start_mark, end_mark); 571 572 if (!event) return NULL; 573 574 event->data.scalar.anchor = anchor; 575 event->data.scalar.tag = tag; 576 event->data.scalar.value = value; 577 event->data.scalar.length = length; 578 event->data.scalar.plain_implicit = plain_implicit; 579 event->data.scalar.quoted_implicit = quoted_implicit; 580 event->data.scalar.style = style; 581 582 return event; 583 } 584 585 /* 586 * Create a SEQUENCE-START event. 587 */ 588 589 YAML_DECLARE(yaml_event_t *) 590 yaml_sequence_start_new(yaml_char_t *anchor, yaml_char_t *tag, 591 int implicit, yaml_sequence_style_t style, 592 yaml_mark_t start_mark, yaml_mark_t end_mark) 593 { 594 yaml_event_t *event = yaml_event_new(YAML_SEQUENCE_START_EVENT, 595 start_mark, end_mark); 596 597 if (!event) return NULL; 598 599 event->data.sequence_start.anchor = anchor; 600 event->data.sequence_start.tag = tag; 601 event->data.sequence_start.implicit = implicit; 602 event->data.sequence_start.style = style; 603 604 return event; 605 } 606 607 /* 608 * Create a SEQUENCE-END event. 609 */ 610 611 YAML_DECLARE(yaml_event_t *) 612 yaml_sequence_end_event_new(yaml_mark_t start_mark, yaml_mark_t end_mark) 613 { 614 return yaml_event_new(YAML_SEQUENCE_END_EVENT, start_mark, end_mark); 615 } 616 617 /* 618 * Create a MAPPING-START event. 619 */ 620 621 YAML_DECLARE(yaml_event_t *) 622 yaml_mapping_start_new(yaml_char_t *anchor, yaml_char_t *tag, 623 int implicit, yaml_mapping_style_t style, 624 yaml_mark_t start_mark, yaml_mark_t end_mark) 625 { 626 yaml_event_t *event = yaml_event_new(YAML_MAPPING_START_EVENT, 627 start_mark, end_mark); 628 629 if (!event) return NULL; 630 631 event->data.mapping_start.anchor = anchor; 632 event->data.mapping_start.tag = tag; 633 event->data.mapping_start.implicit = implicit; 634 event->data.mapping_start.style = style; 635 636 return event; 637 } 638 639 /* 640 * Create a MAPPING-END event. 641 */ 642 643 YAML_DECLARE(yaml_event_t *) 644 yaml_mapping_end_event_new(yaml_mark_t start_mark, yaml_mark_t end_mark) 645 { 646 return yaml_event_new(YAML_MAPPING_END_EVENT, start_mark, end_mark); 647 } 648 649 /* 650 * Destroy an event object. 651 */ 652 653 YAML_DECLARE(void) 654 yaml_event_delete(yaml_event_t *event) 655 { 656 assert(event); /* Non-NULL event object expected. */ 657 658 switch (event->type) 659 { 660 case YAML_DOCUMENT_START_EVENT: 661 yaml_free(event->data.document_start.version_directive); 662 if (event->data.document_start.tag_directives) { 663 yaml_tag_directive_t **tag_directive; 664 for (tag_directive = event->data.document_start.tag_directives; 665 *tag_directive; tag_directive++) { 666 yaml_free((*tag_directive)->handle); 667 yaml_free((*tag_directive)->prefix); 668 yaml_free(*tag_directive); 669 } 670 yaml_free(event->data.document_start.tag_directives); 671 } 672 break; 673 674 case YAML_ALIAS_EVENT: 675 yaml_free(event->data.alias.anchor); 676 break; 677 678 case YAML_SCALAR_EVENT: 679 yaml_free(event->data.scalar.anchor); 680 yaml_free(event->data.scalar.tag); 681 yaml_free(event->data.scalar.value); 682 break; 683 684 case YAML_SEQUENCE_START_EVENT: 685 yaml_free(event->data.sequence_start.anchor); 686 yaml_free(event->data.sequence_start.tag); 687 break; 688 689 case YAML_MAPPING_START_EVENT: 690 yaml_free(event->data.mapping_start.anchor); 691 yaml_free(event->data.mapping_start.tag); 692 break; 693 } 694 695 memset(event, 0, sizeof(yaml_event_t)); 696 697 yaml_free(event); 698 } 699 libyaml/trunk/src/reader.c
r183 r199 149 149 memmove(parser->buffer, parser->pointer, size); 150 150 parser->pointer = parser->buffer; 151 parser->buffer_end -=size;151 parser->buffer_end = parser->buffer + size; 152 152 } 153 153 else if (parser->pointer == parser->buffer_end) {
