Changeset 237
- Timestamp:
- 12/11/06 14:33:21 (7 years ago)
- Location:
- libyaml/trunk
- Files:
-
- 3 edited
-
include/yaml.h (modified) (4 diffs)
-
src/api.c (modified) (2 diffs)
-
src/yaml_private.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
libyaml/trunk/include/yaml.h
r220 r237 407 407 } data; 408 408 409 /** The beginning of the token. */409 /** The beginning of the event. */ 410 410 yaml_mark_t start_mark; 411 /** The end of the token. */411 /** The end of the event. */ 412 412 yaml_mark_t end_mark; 413 413 … … 586 586 YAML_DECLARE(void) 587 587 yaml_event_delete(yaml_event_t *event); 588 589 /** 590 * @defgroup nodes Nodes 591 * @{ 592 */ 593 594 #define YAML_NULL_TAG "tag:yaml.org,2002:null" 595 #define YAML_BOOL_TAG "tag:yaml.org,2002:bool" 596 #define YAML_STR_TAG "tag:yaml.org,2002:str" 597 #define YAML_INT_TAG "tag:yaml.org,2002:int" 598 #define YAML_FLOAT_TAG "tag:yaml.org,2002:float" 599 #define YAML_TIMESTAMP_TAG "tag:yaml.org,2002:timestamp" 600 601 #define YAML_SEQ_TAG "tag:yaml.org,2002:seq" 602 #define YAML_MAP_TAG "tag:yaml.org,2002:map" 603 604 #define YAML_DEFAULT_SCALAR_TAG YAML_STR_TAG 605 #define YAML_DEFAULT_SEQUENCE_TAG YAML_SEQ_TAG 606 #define YAML_DEFAULT_MAPPING_STYLE YAML_MAP_TAG 607 608 /** Node types. */ 609 typedef enum { 610 YAML_NO_NODE, 611 612 YAML_SCALAR_NODE, 613 YAML_SEQUENCE_NODE, 614 YAML_MAPPING_NODE 615 } yaml_node_type_t; 616 617 #if 0 618 619 typedef struct _yaml_node_t yaml_node_item_t; 620 621 typedef struct { 622 yaml_node_item_t key; 623 yaml_node_item_t value; 624 } yaml_node_pair_t; 625 626 /** The node structure. */ 627 typedef struct _yaml_node_t { 628 629 /** The node type. */ 630 yaml_node_type_t type; 631 632 /* The reference counter. */ 633 int references; 634 635 /** The node data. */ 636 union { 637 638 /** The scalar parameters (for @c YAML_SCALAR_NODE). */ 639 struct { 640 /** The tag. */ 641 yaml_char_t *tag; 642 /** The scalar value. */ 643 yaml_char_t *value; 644 /** The length of the scalar value. */ 645 size_t length; 646 /** The scalar style. */ 647 yaml_scalar_style_t style; 648 } scalar; 649 650 /** The sequence parameters (for @c YAML_SEQUENCE_NODE). */ 651 struct { 652 /** The tag. */ 653 yaml_char_t *tag; 654 /** The stack of sequence items. */ 655 struct { 656 /** The beginning of the stack. */ 657 struct yaml_node_item_t *start; 658 /** The end of the stack. */ 659 struct yaml_node_item_t *end; 660 /** The top of the stack. */ 661 struct yaml_node_item_t *top; 662 } items; 663 /** The sequence style. */ 664 yaml_sequence_style_t style; 665 } sequence; 666 667 /** The mapping parameters (for @c YAML_MAPPING_NODE). */ 668 struct { 669 /** The tag. */ 670 yaml_char_t *tag; 671 /** The stack of mapping pairs. */ 672 struct { 673 /** The beginning of the stack. */ 674 struct yaml_node_pair_t *start; 675 /** The end of the stack. */ 676 struct yaml_node_pair_t *end; 677 /** The top of the stack. */ 678 struct yaml_node_pair_t *top; 679 } pairs; 680 /** The mapping style. */ 681 yaml_mapping_style_t style; 682 } mapping; 683 684 } data; 685 686 /** The beginning of the node. */ 687 yaml_mark_t start_mark; 688 /** The end of the node. */ 689 yaml_mark_t end_mark; 690 691 } yaml_node_t; 692 693 /** 694 * Create a SCALAR node. 695 * 696 * The @a style argument may be ignored by the emitter. 697 * 698 * @param[out] node An empty node object. 699 * @param[in] tag The scalar tag. 700 * @param[in] value The scalar value. 701 * @param[in] length The length of the scalar value. 702 * @param[in] style The scalar style. 703 * 704 * @returns @c 1 if the function succeeded, @c 0 on error. 705 */ 706 707 YAML_DECLARE(int) 708 yaml_scalar_node_initialize(yaml_node_t *node, 709 yaml_char_t *tag, yaml_char_t *value, int length, 710 yaml_scalar_style_t style); 711 712 /** 713 * Create a SEQUENCE node. 714 * 715 * The @a style argument may be ignored by the emitter. 716 * 717 * @param[out] node An empty node object. 718 * @param[in] tag The sequence tag. 719 * @param[in] style The sequence style. 720 * 721 * @returns @c 1 if the function succeeded, @c 0 on error. 722 */ 723 724 YAML_DECLARE(int) 725 yaml_sequence_node_initialize(yaml_node_t *node, 726 yaml_char_t *tag, yaml_sequence_style_t style); 727 728 /** 729 * Add an item to a SEQUENCE node 730 * 731 * @param[out] node A sequence node. 732 * @param[in] item An item node. 733 * 734 * @returns @c 1 if the function succeeded, @c 0 on error. 735 */ 736 737 YAML_DECLARE(int) 738 yaml_sequence_node_add_item(yaml_node_t *node, yaml_node_t *item) 739 740 /** 741 * Create a SCALAR node and add it to a SEQUENCE node. 742 * 743 * @param[out] node A sequence node. 744 * @param[in] tag The scalar tag. 745 * @param[in] value The scalar value. 746 * @param[in] length The length of the scalar value. 747 * @param[in] style The scalar style. 748 * 749 * @returns @c 1 if the function succeeded, @c 0 on error. 750 */ 751 752 YAML_DECLARE(int) 753 yaml_sequence_node_add_scalar_item(yaml_node_t *node, 754 yaml_char_t *tag, yaml_char_t *value, int length, 755 yaml_scalar_style_t style); 756 757 /** 758 * Get the number of subnodes of a SEQUENCE node. 759 * 760 * @param[in] node A sequence node. 761 * 762 * @returns the number of subnodes. 763 */ 764 765 YAML_DECLARE(size_t) 766 yaml_sequence_node_get_length(yaml_node_t *node); 767 768 /** 769 * Get a subnode of a SEQUENCE node. 770 * 771 * @param[in] node A sequence node. 772 * @param[in] index The index of a subnode. 773 * @param[out] item A subnode. 774 */ 775 776 YAML_DECLARE(void) 777 yaml_sequence_node_get_item(yaml_node_t *node, size_t index, 778 yaml_node_t *item); 779 780 /** 781 * Create a MAPPING node. 782 * 783 * The @a style argument may be ignored by the emitter. 784 * 785 * @param[out] node An empty node object. 786 * @param[in] tag The mapping tag. 787 * @param[in] style The mapping style. 788 * 789 * @returns @c 1 if the function succeeded, @c 0 on error. 790 */ 791 792 YAML_DECLARE(int) 793 yaml_mapping_node_initialize(yaml_node_t *node, 794 yaml_char_t *tag, yaml_mapping_style_t style); 795 796 /** 797 * Add a key/value pair of nodes to a MAPPING node. 798 * 799 * @param[out] node A mapping node. 800 * @param[in] key A key node. 801 * @param[in] value A value node. 802 * 803 * @returns @c 1 if the function succeeded, @c 0 on error. 804 */ 805 806 YAML_DECLARE(int) 807 yaml_mapping_node_add_pair(yaml_node_t *node, 808 yaml_node_t *key, yaml_node_t *value) 809 810 /** 811 * Create a scalar key and add the key/value pair to a MAPPING node. 812 * 813 * @param[out] node A mapping node. 814 * @param[in] key_tag The key node tag. 815 * @param[in] key_value The key node value. 816 * @param[in] key_length The length of the key node value. 817 * @param[in] key_style The key node style. 818 * @param[in] value A value node. 819 * 820 * @returns @c 1 if the function succeeded, @c 0 on error. 821 */ 822 823 YAML_DECLARE(int) 824 yaml_sequence_node_add_scalar_key_pair(yaml_node_t *node, 825 yaml_char_t *key_tag, yaml_char_t *key_value, int key_length, 826 yaml_scalar_style_t key_style, 827 yaml_node_t *value); 828 829 /** 830 * Create a scalar key/value nodes and add the pair to a MAPPING node. 831 * 832 * @param[out] node A mapping node. 833 * @param[in] key_tag The key node tag. 834 * @param[in] key_value The key node value. 835 * @param[in] key_length The length of the key node value. 836 * @param[in] key_style The key node style. 837 * @param[in] value_tag The value node tag. 838 * @param[in] value_value The value node value. 839 * @param[in] value_length The length of the value node value. 840 * @param[in] value_style The value node style. 841 * 842 * @returns @c 1 if the function succeeded, @c 0 on error. 843 */ 844 845 YAML_DECLARE(int) 846 yaml_sequence_node_add_scalar_pair(yaml_node_t *node, 847 yaml_char_t *key_tag, yaml_char_t *key_value, int key_length, 848 yaml_scalar_style_t key_style, 849 yaml_char_t *value_tag, yaml_char_t *value_value, int value_length, 850 yaml_scalar_style_t value_style); 851 852 /** 853 * Get the number of subnode pairs of a MAPPING node. 854 * 855 * @param[in] node A mapping node. 856 * 857 * @returns the number of pairs. 858 */ 859 860 YAML_DECLARE(size_t) 861 yaml_mapping_node_get_length(yaml_node_t *node); 862 863 /** 864 * Get a subnode of a SEQUENCE node. 865 * 866 * @param[in] node A sequence node. 867 * @param[in] index The index of a subnode. 868 * @param[out] key The key subnode. 869 * @param[out] value The value subnode. 870 */ 871 872 YAML_DECLARE(void) 873 yaml_mapping_node_get_pair(yaml_node_t *node, size_t index, 874 yaml_node_t *key, yaml_node_t *value); 875 876 /** 877 * Delete a node and its subnodes. 878 * 879 * @param[out] node A node object. 880 */ 881 882 YAML_DECLARE(void) 883 yaml_node_delete(yaml_node_t *node); 884 885 #endif 588 886 589 887 /** @} */ … … 712 1010 struct { 713 1011 /** The string start pointer. */ 714 unsigned char *start;1012 const unsigned char *start; 715 1013 /** The string end pointer. */ 716 unsigned char *end;1014 const unsigned char *end; 717 1015 /** The string current position. */ 718 unsigned char *current;1016 const unsigned char *current; 719 1017 } string; 720 1018 … … 909 1207 YAML_DECLARE(void) 910 1208 yaml_parser_set_input_string(yaml_parser_t *parser, 911 unsigned char *input, size_t size);1209 const unsigned char *input, size_t size); 912 1210 913 1211 /** -
libyaml/trunk/src/api.c
r219 r237 280 280 YAML_DECLARE(void) 281 281 yaml_parser_set_input_string(yaml_parser_t *parser, 282 unsigned char *input, size_t size)282 const unsigned char *input, size_t size) 283 283 { 284 284 assert(parser); /* Non-NULL parser object expected. */ … … 1020 1020 } 1021 1021 1022 #if 0 1023 1024 /* 1025 * Create a SCALAR node. 1026 */ 1027 1028 YAML_DECLARE(int) 1029 yaml_scalar_node_initialize(yaml_node_t *node, 1030 yaml_char_t *tag, yaml_char_t *value, int length, 1031 yaml_scalar_style_t style) 1032 { 1033 yaml_mark_t mark = { 0, 0, 0 }; 1034 yaml_char_t *tag_copy = NULL; 1035 yaml_char_t *value_copy = NULL; 1036 1037 assert(node); /* Non-NULL node object is expected. */ 1038 assert(value); /* Non-NULL anchor is expected. */ 1039 1040 if (!tag) { 1041 tag = YAML_DEFAULT_SCALAR_TAG; 1042 } 1043 1044 if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; 1045 tag_copy = yaml_strdup(tag); 1046 if (!tag_copy) goto error; 1047 1048 if (length < 0) { 1049 length = strlen((char *)value); 1050 } 1051 1052 if (!yaml_check_utf8(value, length)) goto error; 1053 value_copy = yaml_malloc(length+1); 1054 if (!value_copy) goto error; 1055 memcpy(value_copy, value, length); 1056 value_copy[length] = '\0'; 1057 1058 SCALAR_NODE_INIT(*node, tag_copy, value_copy, length, style, mark, mark); 1059 1060 return 1; 1061 1062 error: 1063 yaml_free(tag_copy); 1064 yaml_free(value_copy); 1065 1066 return 0; 1067 } 1068 1069 /* 1070 * Create a SEQUENCE node. 1071 */ 1072 1073 YAML_DECLARE(int) 1074 yaml_sequence_node_initialize(yaml_node_t *node, 1075 yaml_char_t *tag, yaml_sequence_style_t style) 1076 { 1077 struct { 1078 yaml_error_type_t error; 1079 } context; 1080 yaml_mark_t mark = { 0, 0, 0 }; 1081 yaml_char_t *tag_copy = NULL; 1082 struct { 1083 yaml_node_item_t *start; 1084 yaml_node_item_t *end; 1085 yaml_node_item_t *top; 1086 } items = { NULL, NULL, NULL }; 1087 1088 assert(node); /* Non-NULL node object is expected. */ 1089 1090 if (!tag) { 1091 tag = YAML_DEFAULT_SEQUENCE_TAG; 1092 } 1093 1094 if (tag) { 1095 if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; 1096 tag_copy = yaml_strdup(tag); 1097 if (!tag_copy) goto error; 1098 } 1099 1100 if (!STACK_INIT(context, items, INITIAL_STACK_SIZE)) goto error; 1101 1102 SEQUENCE_NODE_INIT(*node, tag_copy, items.start, item.end, style, 1103 mark, mark); 1104 1105 return 1; 1106 1107 error: 1108 yaml_free(tag_copy); 1109 STACK_DEL(context, items); 1110 1111 return 0; 1112 } 1113 1114 /* 1115 * Create a MAPPING node. 1116 */ 1117 1118 YAML_DECLARE(int) 1119 yaml_mapping_node_initialize(yaml_node_t *node, 1120 yaml_char_t *tag, yaml_mapping_style_t style) 1121 { 1122 struct { 1123 yaml_error_type_t error; 1124 } context; 1125 yaml_mark_t mark = { 0, 0, 0 }; 1126 yaml_char_t *tag_copy = NULL; 1127 struct { 1128 yaml_node_pair_t *start; 1129 yaml_node_pair_t *end; 1130 yaml_node_pair_t *top; 1131 } pairs = { NULL, NULL, NULL }; 1132 1133 assert(node); /* Non-NULL node object is expected. */ 1134 1135 if (!tag) { 1136 tag = YAML_DEFAULT_MAPPING_TAG; 1137 } 1138 1139 if (tag) { 1140 if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; 1141 tag_copy = yaml_strdup(tag); 1142 if (!tag_copy) goto error; 1143 } 1144 1145 if (!STACK_INIT(context, pairs, INITIAL_STACK_SIZE)) goto error; 1146 1147 MAPPING_NODE_INIT(*node, tag_copy, pairs.start, pairs.end, style, 1148 mark, mark); 1149 1150 return 1; 1151 1152 error: 1153 yaml_free(tag_copy); 1154 STACK_DEL(context, pairs); 1155 1156 return 0; 1157 } 1158 1159 /* 1160 * Delete a node and its subnodes. 1161 */ 1162 1163 YAML_DECLARE(void) 1164 yaml_node_delete(yaml_node_t *node) 1165 { 1166 struct { 1167 yaml_error_type_t error; 1168 } context; 1169 struct { 1170 yaml_node_item_t *start; 1171 yaml_node_item_t *end; 1172 yaml_node_item_t *head; 1173 yaml_node_item_t *tail; 1174 } queue = { NULL, NULL, NULL, NULL }; 1175 1176 assert(node); /* Non-NULL node object is expected. */ 1177 1178 if (node->type == YAML_SCALAR_NODE) { 1179 yaml_free(node->data.scalar.tag); 1180 yaml_free(node->data.scalar.value); 1181 memset(node, 0, sizeof(yaml_node_t)); 1182 return; 1183 } 1184 1185 if (!QUEUE_INIT(context, queue, INITIAL_QUEUE_SIZE)) goto error; 1186 if (!ENQUEUE(context, queue, node)) goto error; 1187 1188 while (!QUEUE_EMPTY(context, queue)) { 1189 yaml_node_t node = DEQUEUE(context, queue); 1190 if (node.type == YAML_SCALAR_NODE) { 1191 if (!node->reference) 1192 } 1193 if (node->type == YAML_SEQUENCE_NODE) { 1194 while (!STACK_EMPTY(context, node->data.sequence.items)) { 1195 yaml_node_t *item = 1196 } 1197 } 1198 } 1199 } 1200 1201 #endif 1202 -
libyaml/trunk/src/yaml_private.h
r214 r237 580 580 (EVENT_INIT((event),YAML_MAPPING_END_EVENT,(start_mark),(end_mark))) 581 581 582 /* 583 * Node initializers. 584 */ 585 586 #define NODE_INIT(node,node_type,node_start_mark,node_end_mark) \ 587 (memset(&(node), 0, sizeof(yaml_node_t)), \ 588 (node).type = (node_type), \ 589 (node).start_mark = (node_start_mark), \ 590 (node).end_mark = (node_end_mark)) 591 592 #define SCALAR_NODE_INIT(node,node_tag,node_value,node_length, \ 593 node_style,start_mark,end_mark) \ 594 (EVENT_INIT((node),YAML_SCALAR_NODE,(start_mark),(end_mark)), \ 595 (node).data.scalar.tag = (node_tag), \ 596 (node).data.scalar.value = (node_value), \ 597 (node).data.scalar.length = (node_length), \ 598 (node).data.scalar.style = (node_style)) 599 600 #define SEQUENCE_NODE_INIT(node,node_tag,node_items_start,node_items_end, \ 601 node_style,start_mark,end_mark) \ 602 (NODE_INIT((node),YAML_SEQUENCE_NODE,(start_mark),(end_mark)), \ 603 (node).data.sequence.tag = (node_tag), \ 604 (node).data.sequence.items.start = (node_items_start), \ 605 (node).data.sequence.items.end = (node_items_end), \ 606 (node).data.sequence.items.top = (node_items_start), \ 607 (node).data.sequence.style = (node_style)) 608 609 #define MAPPING_NODE_INIT(node,node_tag,node_pairs_start,node_pairs_end, \ 610 node_style,start_mark,end_mark) \ 611 (NODE_INIT((node),YAML_MAPPING_NODE,(start_mark),(end_mark)), \ 612 (node).data.mapping.tag = (node_tag), \ 613 (node).data.mapping.pairs.start = (node_pairs_start), \ 614 (node).data.mapping.pairs.end = (node_pairs_end), \ 615 (node).data.mapping.pairs.top = (node_pairs_start), \ 616 (node).data.mapping.style = (node_style)) 617
Note: See TracChangeset
for help on using the changeset viewer.
