Changeset 237 for libyaml/trunk/src/api.c
- Timestamp:
- 12/11/06 14:33:21 (7 years ago)
- File:
-
- 1 edited
-
libyaml/trunk/src/api.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.
