« third_party/modest/source/myhtml/tokenizer_script.c
↑ Summary
third_party/modest/source/myport/posix/mycore/io.c »
| 1 | /* | ||||||||||||||||||
| 2 | Copyright (C) 2015-2017 Alexander Borisov | ||||||||||||||||||
| 3 | |||||||||||||||||||
| 4 | This library is free software; you can redistribute it and/or | ||||||||||||||||||
| 5 | modify it under the terms of the GNU Lesser General Public | ||||||||||||||||||
| 6 | License as published by the Free Software Foundation; either | ||||||||||||||||||
| 7 | version 2.1 of the License, or (at your option) any later version. | ||||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | This library is distributed in the hope that it will be useful, | ||||||||||||||||||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||||||||||||||||
| 12 | Lesser General Public License for more details. | ||||||||||||||||||
| 13 | |||||||||||||||||||
| 14 | You should have received a copy of the GNU Lesser General Public | ||||||||||||||||||
| 15 | License along with this library; if not, write to the Free Software | ||||||||||||||||||
| 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||||||||||||||||
| 17 | |||||||||||||||||||
| 18 | Author: lex.borisov@gmail.com (Alexander Borisov) | ||||||||||||||||||
| 19 | */ | ||||||||||||||||||
| 20 | |||||||||||||||||||
| 21 | #include "myhtml/tree.h" | ||||||||||||||||||
| 22 | |||||||||||||||||||
| 23 | 0 | myhtml_tree_t * myhtml_tree_create(void) | |||||||||||||||||
| 24 | { | ||||||||||||||||||
| 25 | 0 | return (myhtml_tree_t*)mycore_calloc(1, sizeof(myhtml_tree_t)); | |||||||||||||||||
| 26 | } | ||||||||||||||||||
| 27 | |||||||||||||||||||
| 28 | 0 | mystatus_t myhtml_tree_init(myhtml_tree_t* tree, myhtml_t* myhtml) | |||||||||||||||||
| 29 | { | ||||||||||||||||||
| 30 | 0 | mystatus_t status = MyHTML_STATUS_OK; | |||||||||||||||||
| 31 | |||||||||||||||||||
| 32 | 0 | tree->myhtml = myhtml; | |||||||||||||||||
| 33 | 0 | tree->token = myhtml_token_create(tree, 512); | |||||||||||||||||
| 34 | |||||||||||||||||||
| 35 | 0 | ▶ | if(tree->token == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 36 | 0 | return MyHTML_STATUS_TOKENIZER_ERROR_MEMORY_ALLOCATION; | |||||||||||||||||
| 37 | |||||||||||||||||||
| 38 | 0 | tree->temp_tag_name.data = NULL; | |||||||||||||||||
| 39 | 0 | tree->stream_buffer = NULL; | |||||||||||||||||
| 40 | 0 | tree->parse_flags = MyHTML_TREE_PARSE_FLAGS_CLEAN; | |||||||||||||||||
| 41 | 0 | tree->context = NULL; | |||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | 0 | tree->callback_before_token = NULL; | |||||||||||||||||
| 44 | 0 | tree->callback_after_token = NULL; | |||||||||||||||||
| 45 | 0 | tree->callback_before_token_ctx = NULL; | |||||||||||||||||
| 46 | 0 | tree->callback_after_token_ctx = NULL; | |||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | 0 | tree->callback_tree_node_insert = NULL; | |||||||||||||||||
| 49 | 0 | tree->callback_tree_node_remove = NULL; | |||||||||||||||||
| 50 | 0 | tree->callback_tree_node_insert_ctx = NULL; | |||||||||||||||||
| 51 | 0 | tree->callback_tree_node_remove_ctx = NULL; | |||||||||||||||||
| 52 | |||||||||||||||||||
| 53 | 0 | ▶ | if(status) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 54 | 0 | return status; | |||||||||||||||||
| 55 | |||||||||||||||||||
| 56 | /* Thread Queue */ | ||||||||||||||||||
| 57 | 0 | tree->queue = mythread_queue_create(); | |||||||||||||||||
| 58 | 0 | ▶ | if(tree->queue == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 59 | 0 | return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION; | |||||||||||||||||
| 60 | |||||||||||||||||||
| 61 | 0 | status = mythread_queue_init(tree->queue, 9182); | |||||||||||||||||
| 62 | 0 | ▶ | if(status) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 63 | 0 | return status; | |||||||||||||||||
| 64 | |||||||||||||||||||
| 65 | /* Init Incoming Buffer objects */ | ||||||||||||||||||
| 66 | 0 | tree->mcobject_incoming_buf = mcobject_create(); | |||||||||||||||||
| 67 | 0 | ▶ | if(tree->mcobject_incoming_buf == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 68 | 0 | return MyHTML_STATUS_TREE_ERROR_INCOMING_BUFFER_CREATE; | |||||||||||||||||
| 69 | |||||||||||||||||||
| 70 | 0 | status = mcobject_init(tree->mcobject_incoming_buf, 256, sizeof(mycore_incoming_buffer_t)); | |||||||||||||||||
| 71 | 0 | ▶ | if(status) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 72 | 0 | return status; | |||||||||||||||||
| 73 | |||||||||||||||||||
| 74 | /* init Tree Node objects */ | ||||||||||||||||||
| 75 | 0 | tree->tree_obj = mcobject_async_create(); | |||||||||||||||||
| 76 | 0 | ▶ | if(tree->tree_obj == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 77 | 0 | return MyHTML_STATUS_TREE_ERROR_MCOBJECT_CREATE; | |||||||||||||||||
| 78 | |||||||||||||||||||
| 79 | 0 | mcobject_async_status_t mcstatus = mcobject_async_init(tree->tree_obj, 128, 1024, sizeof(myhtml_tree_node_t)); | |||||||||||||||||
| 80 | 0 | ▶ | if(mcstatus) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 81 | 0 | return MyHTML_STATUS_TREE_ERROR_MCOBJECT_INIT; | |||||||||||||||||
| 82 | |||||||||||||||||||
| 83 | 0 | tree->mchar = mchar_async_create(); | |||||||||||||||||
| 84 | 0 | tree->active_formatting = myhtml_tree_active_formatting_init(tree); | |||||||||||||||||
| 85 | 0 | tree->open_elements = myhtml_tree_open_elements_init(tree); | |||||||||||||||||
| 86 | 0 | tree->other_elements = myhtml_tree_list_init(); | |||||||||||||||||
| 87 | 0 | tree->token_list = myhtml_tree_token_list_init(); | |||||||||||||||||
| 88 | 0 | tree->template_insertion = myhtml_tree_template_insertion_init(tree); | |||||||||||||||||
| 89 | |||||||||||||||||||
| 90 | 0 | ▶ | if(tree->mchar == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 91 | 0 | return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION; | |||||||||||||||||
| 92 | |||||||||||||||||||
| 93 | 0 | ▶ | if((status = mchar_async_init(tree->mchar, 128, (4096 * 5)))) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 94 | 0 | return status; | |||||||||||||||||
| 95 | |||||||||||||||||||
| 96 | 0 | tree->mcasync_tree_id = mcobject_async_node_add(tree->tree_obj, &mcstatus); | |||||||||||||||||
| 97 | 0 | ▶ | if(mcstatus) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 98 | 0 | return MyHTML_STATUS_TREE_ERROR_MCOBJECT_CREATE_NODE; | |||||||||||||||||
| 99 | |||||||||||||||||||
| 100 | 0 | tree->mcasync_rules_token_id = mcobject_async_node_add(tree->token->nodes_obj, &mcstatus); | |||||||||||||||||
| 101 | 0 | ▶ | if(mcstatus) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 102 | 0 | return MyHTML_STATUS_TREE_ERROR_MCOBJECT_CREATE_NODE; | |||||||||||||||||
| 103 | |||||||||||||||||||
| 104 | 0 | tree->mcasync_rules_attr_id = mcobject_async_node_add(tree->token->attr_obj, &mcstatus); | |||||||||||||||||
| 105 | 0 | ▶ | if(mcstatus) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 106 | 0 | return MyHTML_STATUS_TREE_ERROR_MCOBJECT_CREATE_NODE; | |||||||||||||||||
| 107 | |||||||||||||||||||
| 108 | #ifndef MyCORE_BUILD_WITHOUT_THREADS | ||||||||||||||||||
| 109 | 0 | tree->async_args = (myhtml_async_args_t*)mycore_calloc(myhtml->thread_total, sizeof(myhtml_async_args_t)); | |||||||||||||||||
| 110 | 0 | ▶ | if(tree->async_args == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 111 | 0 | return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION; | |||||||||||||||||
| 112 | |||||||||||||||||||
| 113 | // for batch thread | ||||||||||||||||||
| 114 | 0 | ▶ | for(size_t i = 0; i < myhtml->thread_total; i++) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 115 | 0 | tree->async_args[i].mchar_node_id = mchar_async_node_add(tree->mchar, &status); | |||||||||||||||||
| 116 | |||||||||||||||||||
| 117 | 0 | ▶ | if(status) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 118 | 0 | return status; | |||||||||||||||||
| 119 | } | ||||||||||||||||||
| 120 | #else /* MyCORE_BUILD_WITHOUT_THREADS */ | ||||||||||||||||||
| 121 | tree->async_args = (myhtml_async_args_t*)mycore_calloc(1, sizeof(myhtml_async_args_t)); | ||||||||||||||||||
| 122 | |||||||||||||||||||
| 123 | if(tree->async_args == NULL) | ||||||||||||||||||
| 124 | return MyHTML_STATUS_TREE_ERROR_MEMORY_ALLOCATION; | ||||||||||||||||||
| 125 | |||||||||||||||||||
| 126 | tree->async_args->mchar_node_id = mchar_async_node_add(tree->mchar, &status); | ||||||||||||||||||
| 127 | |||||||||||||||||||
| 128 | if(status) | ||||||||||||||||||
| 129 | return status; | ||||||||||||||||||
| 130 | |||||||||||||||||||
| 131 | #endif /* MyCORE_BUILD_WITHOUT_THREADS */ | ||||||||||||||||||
| 132 | |||||||||||||||||||
| 133 | /* for main thread only after parsing */ | ||||||||||||||||||
| 134 | 0 | tree->mchar_node_id = tree->async_args->mchar_node_id; | |||||||||||||||||
| 135 | |||||||||||||||||||
| 136 | 0 | tree->sync = mcsync_create(); | |||||||||||||||||
| 137 | 0 | ▶ | if(tree->sync == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 138 | 0 | return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION; | |||||||||||||||||
| 139 | |||||||||||||||||||
| 140 | 0 | ▶ | if(mcsync_init(tree->sync)) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 141 | 0 | return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION; | |||||||||||||||||
| 142 | |||||||||||||||||||
| 143 | /* init Tags after create and init mchar */ | ||||||||||||||||||
| 144 | 0 | tree->tags = myhtml_tag_create(); | |||||||||||||||||
| 145 | 0 | status = myhtml_tag_init(tree, tree->tags); | |||||||||||||||||
| 146 | |||||||||||||||||||
| 147 | 0 | myhtml_tree_clean(tree); | |||||||||||||||||
| 148 | |||||||||||||||||||
| 149 | 0 | return status; | |||||||||||||||||
| 150 | } | ||||||||||||||||||
| 151 | |||||||||||||||||||
| 152 | 0 | void myhtml_tree_clean(myhtml_tree_t* tree) | |||||||||||||||||
| 153 | { | ||||||||||||||||||
| 154 | #ifndef MyCORE_BUILD_WITHOUT_THREADS | ||||||||||||||||||
| 155 | 0 | myhtml_t* myhtml = tree->myhtml; | |||||||||||||||||
| 156 | |||||||||||||||||||
| 157 | 0 | ▶ | for(size_t i = 0; i < myhtml->thread_total; i++) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 158 | 0 | mchar_async_node_clean(tree->mchar, tree->async_args[i].mchar_node_id); | |||||||||||||||||
| 159 | } | ||||||||||||||||||
| 160 | #else | ||||||||||||||||||
| 161 | mchar_async_node_clean(tree->mchar, tree->mchar_node_id); | ||||||||||||||||||
| 162 | #endif | ||||||||||||||||||
| 163 | |||||||||||||||||||
| 164 | 0 | mcobject_async_node_clean(tree->tree_obj, tree->mcasync_tree_id); | |||||||||||||||||
| 165 | 0 | mcobject_async_node_clean(tree->token->nodes_obj, tree->mcasync_rules_token_id); | |||||||||||||||||
| 166 | 0 | mcobject_async_node_clean(tree->token->attr_obj, tree->mcasync_rules_attr_id); | |||||||||||||||||
| 167 | |||||||||||||||||||
| 168 | #ifndef MyCORE_BUILD_WITHOUT_THREADS | ||||||||||||||||||
| 169 | 0 | mythread_queue_list_entry_clean(tree->queue_entry); | |||||||||||||||||
| 170 | 0 | mythread_queue_list_entry_make_batch(tree->myhtml->thread_batch, tree->queue_entry); | |||||||||||||||||
| 171 | 0 | mythread_queue_list_entry_make_stream(tree->myhtml->thread_stream, tree->queue_entry); | |||||||||||||||||
| 172 | #endif /* MyCORE_BUILD_WITHOUT_THREADS */ | ||||||||||||||||||
| 173 | |||||||||||||||||||
| 174 | 0 | myhtml_token_clean(tree->token); | |||||||||||||||||
| 175 | |||||||||||||||||||
| 176 | // null root | ||||||||||||||||||
| 177 | 0 | myhtml_tree_node_create(tree); | |||||||||||||||||
| 178 | |||||||||||||||||||
| 179 | 0 | tree->document = myhtml_tree_node_create(tree); | |||||||||||||||||
| 180 | 0 | tree->fragment = NULL; | |||||||||||||||||
| 181 | |||||||||||||||||||
| 182 | 0 | tree->doctype.is_html = false; | |||||||||||||||||
| 183 | 0 | tree->doctype.attr_name = NULL; | |||||||||||||||||
| 184 | 0 | tree->doctype.attr_public = NULL; | |||||||||||||||||
| 185 | 0 | tree->doctype.attr_system = NULL; | |||||||||||||||||
| 186 | |||||||||||||||||||
| 187 | 0 | tree->node_html = 0; | |||||||||||||||||
| 188 | 0 | tree->node_body = 0; | |||||||||||||||||
| 189 | 0 | tree->node_head = 0; | |||||||||||||||||
| 190 | 0 | tree->node_form = 0; | |||||||||||||||||
| 191 | |||||||||||||||||||
| 192 | 0 | tree->state = MyHTML_TOKENIZER_STATE_DATA; | |||||||||||||||||
| 193 | 0 | tree->state_of_builder = MyHTML_TOKENIZER_STATE_DATA; | |||||||||||||||||
| 194 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_INITIAL; | |||||||||||||||||
| 195 | 0 | tree->orig_insert_mode = MyHTML_INSERTION_MODE_INITIAL; | |||||||||||||||||
| 196 | 0 | tree->compat_mode = MyHTML_TREE_COMPAT_MODE_NO_QUIRKS; | |||||||||||||||||
| 197 | 0 | tree->tmp_tag_id = MyHTML_TAG__UNDEF; | |||||||||||||||||
| 198 | 0 | tree->flags = MyHTML_TREE_FLAGS_CLEAN|MyHTML_TREE_FLAGS_FRAMESET_OK; | |||||||||||||||||
| 199 | 0 | tree->foster_parenting = false; | |||||||||||||||||
| 200 | 0 | tree->token_namespace = NULL; | |||||||||||||||||
| 201 | 0 | tree->incoming_buf = NULL; | |||||||||||||||||
| 202 | 0 | tree->incoming_buf_first = NULL; | |||||||||||||||||
| 203 | 0 | tree->global_offset = 0; | |||||||||||||||||
| 204 | 0 | tree->current_qnode = NULL; | |||||||||||||||||
| 205 | 0 | tree->token_last_done = NULL; | |||||||||||||||||
| 206 | 0 | tree->tokenizer_status = MyHTML_STATUS_OK; | |||||||||||||||||
| 207 | |||||||||||||||||||
| 208 | 0 | tree->encoding = MyENCODING_UTF_8; | |||||||||||||||||
| 209 | 0 | tree->encoding_usereq = MyENCODING_DEFAULT; | |||||||||||||||||
| 210 | |||||||||||||||||||
| 211 | 0 | myhtml_stream_buffer_clean(tree->stream_buffer); | |||||||||||||||||
| 212 | |||||||||||||||||||
| 213 | 0 | myhtml_tree_active_formatting_clean(tree); | |||||||||||||||||
| 214 | 0 | myhtml_tree_open_elements_clean(tree); | |||||||||||||||||
| 215 | 0 | myhtml_tree_list_clean(tree->other_elements); | |||||||||||||||||
| 216 | 0 | myhtml_tree_token_list_clean(tree->token_list); | |||||||||||||||||
| 217 | 0 | myhtml_tree_template_insertion_clean(tree); | |||||||||||||||||
| 218 | 0 | mcobject_clean(tree->mcobject_incoming_buf); | |||||||||||||||||
| 219 | 0 | myhtml_tag_clean(tree->tags); | |||||||||||||||||
| 220 | 0 | mythread_queue_clean(tree->queue); | |||||||||||||||||
| 221 | |||||||||||||||||||
| 222 | 0 | tree->attr_current = myhtml_token_attr_create(tree->token, tree->token->mcasync_attr_id); | |||||||||||||||||
| 223 | 0 | } | |||||||||||||||||
| 224 | |||||||||||||||||||
| 225 | 0 | void myhtml_tree_clean_all(myhtml_tree_t* tree) | |||||||||||||||||
| 226 | { | ||||||||||||||||||
| 227 | 0 | mcobject_async_clean(tree->tree_obj); | |||||||||||||||||
| 228 | 0 | myhtml_token_clean(tree->token); | |||||||||||||||||
| 229 | 0 | mchar_async_clean(tree->mchar); | |||||||||||||||||
| 230 | |||||||||||||||||||
| 231 | // null root | ||||||||||||||||||
| 232 | 0 | myhtml_tree_node_create(tree); | |||||||||||||||||
| 233 | |||||||||||||||||||
| 234 | 0 | tree->document = myhtml_tree_node_create(tree); | |||||||||||||||||
| 235 | 0 | tree->fragment = NULL; | |||||||||||||||||
| 236 | |||||||||||||||||||
| 237 | 0 | tree->doctype.is_html = false; | |||||||||||||||||
| 238 | 0 | tree->doctype.attr_name = NULL; | |||||||||||||||||
| 239 | 0 | tree->doctype.attr_public = NULL; | |||||||||||||||||
| 240 | 0 | tree->doctype.attr_system = NULL; | |||||||||||||||||
| 241 | |||||||||||||||||||
| 242 | 0 | tree->node_html = 0; | |||||||||||||||||
| 243 | 0 | tree->node_body = 0; | |||||||||||||||||
| 244 | 0 | tree->node_head = 0; | |||||||||||||||||
| 245 | 0 | tree->node_form = 0; | |||||||||||||||||
| 246 | |||||||||||||||||||
| 247 | 0 | tree->state = MyHTML_TOKENIZER_STATE_DATA; | |||||||||||||||||
| 248 | 0 | tree->state_of_builder = MyHTML_TOKENIZER_STATE_DATA; | |||||||||||||||||
| 249 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_INITIAL; | |||||||||||||||||
| 250 | 0 | tree->orig_insert_mode = MyHTML_INSERTION_MODE_INITIAL; | |||||||||||||||||
| 251 | 0 | tree->compat_mode = MyHTML_TREE_COMPAT_MODE_NO_QUIRKS; | |||||||||||||||||
| 252 | 0 | tree->tmp_tag_id = MyHTML_TAG__UNDEF; | |||||||||||||||||
| 253 | 0 | tree->flags = MyHTML_TREE_FLAGS_CLEAN|MyHTML_TREE_FLAGS_FRAMESET_OK; | |||||||||||||||||
| 254 | 0 | tree->foster_parenting = false; | |||||||||||||||||
| 255 | 0 | tree->token_namespace = NULL; | |||||||||||||||||
| 256 | 0 | tree->incoming_buf = NULL; | |||||||||||||||||
| 257 | 0 | tree->incoming_buf_first = NULL; | |||||||||||||||||
| 258 | 0 | tree->global_offset = 0; | |||||||||||||||||
| 259 | 0 | tree->current_qnode = NULL; | |||||||||||||||||
| 260 | 0 | tree->token_last_done = NULL; | |||||||||||||||||
| 261 | 0 | tree->tokenizer_status = MyHTML_STATUS_OK; | |||||||||||||||||
| 262 | |||||||||||||||||||
| 263 | 0 | tree->encoding = MyENCODING_UTF_8; | |||||||||||||||||
| 264 | 0 | tree->encoding_usereq = MyENCODING_DEFAULT; | |||||||||||||||||
| 265 | |||||||||||||||||||
| 266 | 0 | myhtml_stream_buffer_clean(tree->stream_buffer); | |||||||||||||||||
| 267 | |||||||||||||||||||
| 268 | 0 | myhtml_tree_active_formatting_clean(tree); | |||||||||||||||||
| 269 | 0 | myhtml_tree_open_elements_clean(tree); | |||||||||||||||||
| 270 | 0 | myhtml_tree_list_clean(tree->other_elements); | |||||||||||||||||
| 271 | 0 | myhtml_tree_token_list_clean(tree->token_list); | |||||||||||||||||
| 272 | 0 | myhtml_tree_template_insertion_clean(tree); | |||||||||||||||||
| 273 | 0 | mcobject_clean(tree->mcobject_incoming_buf); | |||||||||||||||||
| 274 | 0 | myhtml_tag_clean(tree->tags); | |||||||||||||||||
| 275 | |||||||||||||||||||
| 276 | #ifndef MyCORE_BUILD_WITHOUT_THREADS | ||||||||||||||||||
| 277 | 0 | mythread_queue_list_entry_clean(tree->queue_entry); | |||||||||||||||||
| 278 | 0 | mythread_queue_list_entry_make_batch(tree->myhtml->thread_batch, tree->queue_entry); | |||||||||||||||||
| 279 | 0 | mythread_queue_list_entry_make_stream(tree->myhtml->thread_stream, tree->queue_entry); | |||||||||||||||||
| 280 | #endif | ||||||||||||||||||
| 281 | |||||||||||||||||||
| 282 | 0 | tree->attr_current = myhtml_token_attr_create(tree->token, tree->token->mcasync_attr_id); | |||||||||||||||||
| 283 | 0 | } | |||||||||||||||||
| 284 | |||||||||||||||||||
| 285 | 0 | myhtml_tree_t * myhtml_tree_destroy(myhtml_tree_t* tree) | |||||||||||||||||
| 286 | { | ||||||||||||||||||
| 287 | 0 | ▶ | if(tree == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 288 | 0 | return NULL; | |||||||||||||||||
| 289 | |||||||||||||||||||
| 290 | /* destroy tags before other objects */ | ||||||||||||||||||
| 291 | 0 | tree->tags = myhtml_tag_destroy(tree->tags); | |||||||||||||||||
| 292 | 0 | tree->active_formatting = myhtml_tree_active_formatting_destroy(tree); | |||||||||||||||||
| 293 | 0 | tree->open_elements = myhtml_tree_open_elements_destroy(tree); | |||||||||||||||||
| 294 | 0 | tree->other_elements = myhtml_tree_list_destroy(tree->other_elements, true); | |||||||||||||||||
| 295 | 0 | tree->token_list = myhtml_tree_token_list_destroy(tree->token_list, true); | |||||||||||||||||
| 296 | 0 | tree->template_insertion = myhtml_tree_template_insertion_destroy(tree); | |||||||||||||||||
| 297 | 0 | tree->sync = mcsync_destroy(tree->sync, true); | |||||||||||||||||
| 298 | 0 | tree->tree_obj = mcobject_async_destroy(tree->tree_obj, true); | |||||||||||||||||
| 299 | 0 | tree->token = myhtml_token_destroy(tree->token); | |||||||||||||||||
| 300 | 0 | tree->mchar = mchar_async_destroy(tree->mchar, 1); | |||||||||||||||||
| 301 | 0 | tree->stream_buffer = myhtml_stream_buffer_destroy(tree->stream_buffer, true); | |||||||||||||||||
| 302 | 0 | tree->queue = mythread_queue_destroy(tree->queue); | |||||||||||||||||
| 303 | 0 | tree->mcobject_incoming_buf = mcobject_destroy(tree->mcobject_incoming_buf, true); | |||||||||||||||||
| 304 | |||||||||||||||||||
| 305 | 0 | myhtml_tree_temp_tag_name_destroy(&tree->temp_tag_name, false); | |||||||||||||||||
| 306 | |||||||||||||||||||
| 307 | 0 | mycore_free(tree->async_args); | |||||||||||||||||
| 308 | 0 | mycore_free(tree); | |||||||||||||||||
| 309 | |||||||||||||||||||
| 310 | 0 | return NULL; | |||||||||||||||||
| 311 | } | ||||||||||||||||||
| 312 | |||||||||||||||||||
| 313 | 0 | void myhtml_tree_node_clean(myhtml_tree_node_t* tree_node) | |||||||||||||||||
| 314 | { | ||||||||||||||||||
| 315 | 0 | memset(tree_node, 0, sizeof(myhtml_tree_node_t)); | |||||||||||||||||
| 316 | 0 | tree_node->ns = MyHTML_NAMESPACE_HTML; | |||||||||||||||||
| 317 | 0 | } | |||||||||||||||||
| 318 | |||||||||||||||||||
| 319 | /* parse flags */ | ||||||||||||||||||
| 320 | 0 | myhtml_tree_parse_flags_t myhtml_tree_parse_flags(myhtml_tree_t* tree) | |||||||||||||||||
| 321 | { | ||||||||||||||||||
| 322 | 0 | return tree->parse_flags; | |||||||||||||||||
| 323 | } | ||||||||||||||||||
| 324 | |||||||||||||||||||
| 325 | 0 | void myhtml_tree_parse_flags_set(myhtml_tree_t* tree, myhtml_tree_parse_flags_t flags) | |||||||||||||||||
| 326 | { | ||||||||||||||||||
| 327 | 0 | tree->parse_flags = flags; | |||||||||||||||||
| 328 | 0 | } | |||||||||||||||||
| 329 | |||||||||||||||||||
| 330 | 0 | myhtml_t * myhtml_tree_get_myhtml(myhtml_tree_t* tree) | |||||||||||||||||
| 331 | { | ||||||||||||||||||
| 332 | 0 | ▶ | if(tree) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 333 | 0 | return tree->myhtml; | |||||||||||||||||
| 334 | |||||||||||||||||||
| 335 | 0 | return NULL; | |||||||||||||||||
| 336 | } | ||||||||||||||||||
| 337 | |||||||||||||||||||
| 338 | 0 | myhtml_tag_t * myhtml_tree_get_tag(myhtml_tree_t* tree) | |||||||||||||||||
| 339 | { | ||||||||||||||||||
| 340 | 0 | ▶ | if(tree) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 341 | 0 | return tree->tags; | |||||||||||||||||
| 342 | |||||||||||||||||||
| 343 | 0 | return NULL; | |||||||||||||||||
| 344 | } | ||||||||||||||||||
| 345 | |||||||||||||||||||
| 346 | 0 | myhtml_tree_node_t * myhtml_tree_get_document(myhtml_tree_t* tree) | |||||||||||||||||
| 347 | { | ||||||||||||||||||
| 348 | 0 | return tree->document; | |||||||||||||||||
| 349 | } | ||||||||||||||||||
| 350 | |||||||||||||||||||
| 351 | 0 | myhtml_tree_node_t * myhtml_tree_get_node_html(myhtml_tree_t* tree) | |||||||||||||||||
| 352 | { | ||||||||||||||||||
| 353 | 0 | return tree->node_html; | |||||||||||||||||
| 354 | } | ||||||||||||||||||
| 355 | |||||||||||||||||||
| 356 | 0 | myhtml_tree_node_t * myhtml_tree_get_node_body(myhtml_tree_t* tree) | |||||||||||||||||
| 357 | { | ||||||||||||||||||
| 358 | 0 | return tree->node_body; | |||||||||||||||||
| 359 | } | ||||||||||||||||||
| 360 | |||||||||||||||||||
| 361 | 0 | myhtml_tree_node_t * myhtml_tree_get_node_head(myhtml_tree_t* tree) | |||||||||||||||||
| 362 | { | ||||||||||||||||||
| 363 | 0 | return tree->node_head; | |||||||||||||||||
| 364 | } | ||||||||||||||||||
| 365 | |||||||||||||||||||
| 366 | 0 | mchar_async_t * myhtml_tree_get_mchar(myhtml_tree_t* tree) | |||||||||||||||||
| 367 | { | ||||||||||||||||||
| 368 | 0 | return tree->mchar; | |||||||||||||||||
| 369 | } | ||||||||||||||||||
| 370 | |||||||||||||||||||
| 371 | 0 | size_t myhtml_tree_get_mchar_node_id(myhtml_tree_t* tree) | |||||||||||||||||
| 372 | { | ||||||||||||||||||
| 373 | 0 | return tree->mchar_node_id; | |||||||||||||||||
| 374 | } | ||||||||||||||||||
| 375 | |||||||||||||||||||
| 376 | 0 | myhtml_tree_node_t * myhtml_tree_node_create(myhtml_tree_t* tree) | |||||||||||||||||
| 377 | { | ||||||||||||||||||
| 378 | 0 | myhtml_tree_node_t* node = (myhtml_tree_node_t*)mcobject_async_malloc(tree->tree_obj, tree->mcasync_tree_id, NULL); | |||||||||||||||||
| 379 | 0 | myhtml_tree_node_clean(node); | |||||||||||||||||
| 380 | |||||||||||||||||||
| 381 | 0 | node->tree = tree; | |||||||||||||||||
| 382 | |||||||||||||||||||
| 383 | 0 | return node; | |||||||||||||||||
| 384 | } | ||||||||||||||||||
| 385 | |||||||||||||||||||
| 386 | 0 | void myhtml_tree_node_add_child(myhtml_tree_node_t* root, myhtml_tree_node_t* node) | |||||||||||||||||
| 387 | { | ||||||||||||||||||
| 388 | 0 | ▶ | if(root->last_child) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 389 | 0 | root->last_child->next = node; | |||||||||||||||||
| 390 | 0 | node->prev = root->last_child; | |||||||||||||||||
| 391 | } | ||||||||||||||||||
| 392 | else { | ||||||||||||||||||
| 393 | 0 | root->child = node; | |||||||||||||||||
| 394 | } | ||||||||||||||||||
| 395 | |||||||||||||||||||
| 396 | 0 | node->parent = root; | |||||||||||||||||
| 397 | 0 | root->last_child = node; | |||||||||||||||||
| 398 | |||||||||||||||||||
| 399 | 0 | ▶ | myhtml_tree_node_callback_insert(node->tree, node); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 400 | 0 | } | |||||||||||||||||
| 401 | |||||||||||||||||||
| 402 | 0 | void myhtml_tree_node_insert_before(myhtml_tree_node_t* root, myhtml_tree_node_t* node) | |||||||||||||||||
| 403 | { | ||||||||||||||||||
| 404 | 0 | ▶ | if(root->prev) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 405 | 0 | root->prev->next = node; | |||||||||||||||||
| 406 | 0 | node->prev = root->prev; | |||||||||||||||||
| 407 | } | ||||||||||||||||||
| 408 | else { | ||||||||||||||||||
| 409 | 0 | root->parent->child = node; | |||||||||||||||||
| 410 | } | ||||||||||||||||||
| 411 | |||||||||||||||||||
| 412 | 0 | node->parent = root->parent; | |||||||||||||||||
| 413 | 0 | node->next = root; | |||||||||||||||||
| 414 | 0 | root->prev = node; | |||||||||||||||||
| 415 | |||||||||||||||||||
| 416 | 0 | ▶ | myhtml_tree_node_callback_insert(node->tree, node); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 417 | 0 | } | |||||||||||||||||
| 418 | |||||||||||||||||||
| 419 | 0 | void myhtml_tree_node_insert_after(myhtml_tree_node_t* root, myhtml_tree_node_t* node) | |||||||||||||||||
| 420 | { | ||||||||||||||||||
| 421 | 0 | ▶ | if(root->next) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 422 | 0 | root->next->prev = node; | |||||||||||||||||
| 423 | 0 | node->next = root->next; | |||||||||||||||||
| 424 | } | ||||||||||||||||||
| 425 | else { | ||||||||||||||||||
| 426 | 0 | root->parent->last_child = node; | |||||||||||||||||
| 427 | } | ||||||||||||||||||
| 428 | |||||||||||||||||||
| 429 | 0 | node->parent = root->parent; | |||||||||||||||||
| 430 | 0 | node->prev = root; | |||||||||||||||||
| 431 | 0 | root->next = node; | |||||||||||||||||
| 432 | |||||||||||||||||||
| 433 | 0 | ▶ | myhtml_tree_node_callback_insert(node->tree, node); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 434 | 0 | } | |||||||||||||||||
| 435 | |||||||||||||||||||
| 436 | 0 | myhtml_tree_node_t * myhtml_tree_node_find_parent_by_tag_id(myhtml_tree_node_t* node, myhtml_tag_id_t tag_id) | |||||||||||||||||
| 437 | { | ||||||||||||||||||
| 438 | 0 | node = node->parent; | |||||||||||||||||
| 439 | |||||||||||||||||||
| 440 | 0 | ▶ | while (node && node->tag_id != tag_id) { | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 441 | 0 | node = node->parent; | |||||||||||||||||
| 442 | } | ||||||||||||||||||
| 443 | |||||||||||||||||||
| 444 | 0 | return node; | |||||||||||||||||
| 445 | } | ||||||||||||||||||
| 446 | |||||||||||||||||||
| 447 | 0 | myhtml_tree_node_t * myhtml_tree_node_remove(myhtml_tree_node_t* node) | |||||||||||||||||
| 448 | { | ||||||||||||||||||
| 449 | 0 | ▶ | if(node->next) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 450 | 0 | node->next->prev = node->prev; | |||||||||||||||||
| 451 | 0 | ▶ | else if(node->parent) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 452 | 0 | node->parent->last_child = node->prev; | |||||||||||||||||
| 453 | |||||||||||||||||||
| 454 | 0 | ▶ | if(node->prev) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 455 | 0 | node->prev->next = node->next; | |||||||||||||||||
| 456 | 0 | node->prev = NULL; | |||||||||||||||||
| 457 | 0 | ▶ | } else if(node->parent) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 458 | 0 | node->parent->child = node->next; | |||||||||||||||||
| 459 | |||||||||||||||||||
| 460 | 0 | node->parent = NULL; | |||||||||||||||||
| 461 | |||||||||||||||||||
| 462 | 0 | ▶ | if(node->next) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 463 | 0 | node->next = NULL; | |||||||||||||||||
| 464 | |||||||||||||||||||
| 465 | 0 | ▶ | myhtml_tree_node_callback_remove(node->tree, node); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 466 | |||||||||||||||||||
| 467 | 0 | return node; | |||||||||||||||||
| 468 | } | ||||||||||||||||||
| 469 | |||||||||||||||||||
| 470 | 0 | void myhtml_tree_node_free(myhtml_tree_node_t* node) | |||||||||||||||||
| 471 | { | ||||||||||||||||||
| 472 | 0 | ▶ | if(node == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 473 | 0 | return; | |||||||||||||||||
| 474 | |||||||||||||||||||
| 475 | 0 | ▶ | if(node->token) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 476 | 0 | myhtml_token_attr_delete_all(node->tree->token, node->token); | |||||||||||||||||
| 477 | 0 | myhtml_token_delete(node->tree->token, node->token); | |||||||||||||||||
| 478 | } | ||||||||||||||||||
| 479 | |||||||||||||||||||
| 480 | 0 | mcobject_async_free(node->tree->tree_obj, node); | |||||||||||||||||
| 481 | } | ||||||||||||||||||
| 482 | |||||||||||||||||||
| 483 | 0 | void myhtml_tree_node_delete(myhtml_tree_node_t* node) | |||||||||||||||||
| 484 | { | ||||||||||||||||||
| 485 | 0 | ▶ | if(node == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 486 | 0 | return; | |||||||||||||||||
| 487 | |||||||||||||||||||
| 488 | 0 | myhtml_tree_node_remove(node); | |||||||||||||||||
| 489 | 0 | myhtml_tree_node_free(node); | |||||||||||||||||
| 490 | } | ||||||||||||||||||
| 491 | |||||||||||||||||||
| 492 | 0 | static void _myhtml_tree_node_delete_recursive(myhtml_tree_node_t* node) | |||||||||||||||||
| 493 | { | ||||||||||||||||||
| 494 | 0 | ▶ | while(node) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 495 | { | ||||||||||||||||||
| 496 | 0 | ▶ | if(node->child) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 497 | 0 | _myhtml_tree_node_delete_recursive(node->child); | |||||||||||||||||
| 498 | |||||||||||||||||||
| 499 | 0 | node = node->next; | |||||||||||||||||
| 500 | 0 | myhtml_tree_node_delete(node); | |||||||||||||||||
| 501 | } | ||||||||||||||||||
| 502 | 0 | } | |||||||||||||||||
| 503 | |||||||||||||||||||
| 504 | 0 | void myhtml_tree_node_delete_recursive(myhtml_tree_node_t* node) | |||||||||||||||||
| 505 | { | ||||||||||||||||||
| 506 | 0 | ▶ | if(node == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 507 | 0 | return; | |||||||||||||||||
| 508 | |||||||||||||||||||
| 509 | 0 | ▶ | if(node->child) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 510 | 0 | _myhtml_tree_node_delete_recursive(node->child); | |||||||||||||||||
| 511 | |||||||||||||||||||
| 512 | 0 | myhtml_tree_node_delete(node); | |||||||||||||||||
| 513 | } | ||||||||||||||||||
| 514 | |||||||||||||||||||
| 515 | 0 | myhtml_tree_node_t * myhtml_tree_node_clone(myhtml_tree_node_t* node) | |||||||||||||||||
| 516 | { | ||||||||||||||||||
| 517 | 0 | myhtml_tree_node_t* new_node = myhtml_tree_node_create(node->tree); | |||||||||||||||||
| 518 | |||||||||||||||||||
| 519 | 0 | ▶ | if(node->token) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 520 | 0 | myhtml_token_node_wait_for_done(node->tree->token, node->token); | |||||||||||||||||
| 521 | |||||||||||||||||||
| 522 | 0 | new_node->token = myhtml_token_node_clone(node->tree->token, node->token, | |||||||||||||||||
| 523 | 0 | node->tree->mcasync_rules_token_id, | |||||||||||||||||
| 524 | 0 | node->tree->mcasync_rules_attr_id); | |||||||||||||||||
| 525 | 0 | new_node->tag_id = node->tag_id; | |||||||||||||||||
| 526 | 0 | new_node->ns = node->ns; | |||||||||||||||||
| 527 | |||||||||||||||||||
| 528 | 0 | ▶ | if(new_node->token) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 529 | 0 | new_node->token->type |= MyHTML_TOKEN_TYPE_DONE; | |||||||||||||||||
| 530 | |||||||||||||||||||
| 531 | 0 | return new_node; | |||||||||||||||||
| 532 | } | ||||||||||||||||||
| 533 | |||||||||||||||||||
| 534 | 0 | void myhtml_tree_node_insert_by_mode(myhtml_tree_node_t* adjusted_location, | |||||||||||||||||
| 535 | myhtml_tree_node_t* node, enum myhtml_tree_insertion_mode mode) | ||||||||||||||||||
| 536 | { | ||||||||||||||||||
| 537 | 0 | ▶ | if(mode == MyHTML_TREE_INSERTION_MODE_DEFAULT) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 538 | 0 | myhtml_tree_node_add_child(adjusted_location, node); | |||||||||||||||||
| 539 | 0 | ▶ | else if(mode == MyHTML_TREE_INSERTION_MODE_BEFORE) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 540 | 0 | myhtml_tree_node_insert_before(adjusted_location, node); | |||||||||||||||||
| 541 | else | ||||||||||||||||||
| 542 | 0 | myhtml_tree_node_insert_after(adjusted_location, node); | |||||||||||||||||
| 543 | 0 | } | |||||||||||||||||
| 544 | |||||||||||||||||||
| 545 | 0 | myhtml_tree_node_t * myhtml_tree_node_insert_by_token(myhtml_tree_t* tree, myhtml_token_node_t* token, myhtml_namespace_t ns) | |||||||||||||||||
| 546 | { | ||||||||||||||||||
| 547 | 0 | myhtml_tree_node_t* node = myhtml_tree_node_create(tree); | |||||||||||||||||
| 548 | |||||||||||||||||||
| 549 | 0 | node->tag_id = token->tag_id; | |||||||||||||||||
| 550 | 0 | node->token = token; | |||||||||||||||||
| 551 | 0 | node->ns = ns; | |||||||||||||||||
| 552 | |||||||||||||||||||
| 553 | enum myhtml_tree_insertion_mode mode; | ||||||||||||||||||
| 554 | 0 | myhtml_tree_node_t* adjusted_location = myhtml_tree_appropriate_place_inserting(tree, NULL, &mode); | |||||||||||||||||
| 555 | 0 | myhtml_tree_node_insert_by_mode(adjusted_location, node, mode); | |||||||||||||||||
| 556 | |||||||||||||||||||
| 557 | 0 | myhtml_tree_open_elements_append(tree, node); | |||||||||||||||||
| 558 | 0 | return node; | |||||||||||||||||
| 559 | } | ||||||||||||||||||
| 560 | |||||||||||||||||||
| 561 | 0 | myhtml_tree_node_t * myhtml_tree_node_insert(myhtml_tree_t* tree, myhtml_tag_id_t tag_idx, myhtml_namespace_t ns) | |||||||||||||||||
| 562 | { | ||||||||||||||||||
| 563 | 0 | myhtml_tree_node_t* node = myhtml_tree_node_create(tree); | |||||||||||||||||
| 564 | |||||||||||||||||||
| 565 | 0 | node->token = NULL; | |||||||||||||||||
| 566 | 0 | node->tag_id = tag_idx; | |||||||||||||||||
| 567 | 0 | node->ns = ns; | |||||||||||||||||
| 568 | |||||||||||||||||||
| 569 | enum myhtml_tree_insertion_mode mode; | ||||||||||||||||||
| 570 | 0 | myhtml_tree_node_t* adjusted_location = myhtml_tree_appropriate_place_inserting(tree, NULL, &mode); | |||||||||||||||||
| 571 | 0 | myhtml_tree_node_insert_by_mode(adjusted_location, node, mode); | |||||||||||||||||
| 572 | |||||||||||||||||||
| 573 | 0 | myhtml_tree_open_elements_append(tree, node); | |||||||||||||||||
| 574 | 0 | return node; | |||||||||||||||||
| 575 | } | ||||||||||||||||||
| 576 | |||||||||||||||||||
| 577 | 0 | myhtml_tree_node_t * myhtml_tree_node_insert_comment(myhtml_tree_t* tree, myhtml_token_node_t* token, myhtml_tree_node_t* parent) | |||||||||||||||||
| 578 | { | ||||||||||||||||||
| 579 | 0 | myhtml_tree_node_t* node = myhtml_tree_node_create(tree); | |||||||||||||||||
| 580 | |||||||||||||||||||
| 581 | 0 | node->token = token; | |||||||||||||||||
| 582 | 0 | node->tag_id = MyHTML_TAG__COMMENT; | |||||||||||||||||
| 583 | |||||||||||||||||||
| 584 | 0 | enum myhtml_tree_insertion_mode mode = 0; | |||||||||||||||||
| 585 | 0 | ▶ | if(parent == NULL) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 586 | 0 | parent = myhtml_tree_appropriate_place_inserting(tree, NULL, &mode); | |||||||||||||||||
| 587 | } | ||||||||||||||||||
| 588 | |||||||||||||||||||
| 589 | 0 | myhtml_tree_node_insert_by_mode(parent, node, mode); | |||||||||||||||||
| 590 | 0 | node->ns = parent->ns; | |||||||||||||||||
| 591 | |||||||||||||||||||
| 592 | 0 | return node; | |||||||||||||||||
| 593 | } | ||||||||||||||||||
| 594 | |||||||||||||||||||
| 595 | 0 | myhtml_tree_node_t * myhtml_tree_node_insert_doctype(myhtml_tree_t* tree, myhtml_token_node_t* token) | |||||||||||||||||
| 596 | { | ||||||||||||||||||
| 597 | 0 | myhtml_tree_node_t* node = myhtml_tree_node_create(tree); | |||||||||||||||||
| 598 | |||||||||||||||||||
| 599 | 0 | node->token = token; | |||||||||||||||||
| 600 | 0 | node->ns = MyHTML_NAMESPACE_HTML; | |||||||||||||||||
| 601 | 0 | node->tag_id = MyHTML_TAG__DOCTYPE; | |||||||||||||||||
| 602 | |||||||||||||||||||
| 603 | 0 | myhtml_tree_node_add_child(tree->document, node); | |||||||||||||||||
| 604 | 0 | return node; | |||||||||||||||||
| 605 | } | ||||||||||||||||||
| 606 | |||||||||||||||||||
| 607 | 0 | myhtml_tree_node_t * myhtml_tree_node_insert_root(myhtml_tree_t* tree, myhtml_token_node_t* token, enum myhtml_namespace ns) | |||||||||||||||||
| 608 | { | ||||||||||||||||||
| 609 | 0 | myhtml_tree_node_t* node = myhtml_tree_node_create(tree); | |||||||||||||||||
| 610 | |||||||||||||||||||
| 611 | 0 | ▶ | if(token) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 612 | 0 | node->tag_id = token->tag_id; | |||||||||||||||||
| 613 | else | ||||||||||||||||||
| 614 | 0 | node->tag_id = MyHTML_TAG_HTML; | |||||||||||||||||
| 615 | |||||||||||||||||||
| 616 | 0 | node->token = token; | |||||||||||||||||
| 617 | 0 | node->ns = ns; | |||||||||||||||||
| 618 | |||||||||||||||||||
| 619 | 0 | myhtml_tree_node_add_child(tree->document, node); | |||||||||||||||||
| 620 | 0 | myhtml_tree_open_elements_append(tree, node); | |||||||||||||||||
| 621 | |||||||||||||||||||
| 622 | 0 | tree->node_html = node; | |||||||||||||||||
| 623 | 0 | return node; | |||||||||||||||||
| 624 | } | ||||||||||||||||||
| 625 | |||||||||||||||||||
| 626 | 0 | myhtml_tree_node_t * myhtml_tree_node_insert_text(myhtml_tree_t* tree, myhtml_token_node_t* token) | |||||||||||||||||
| 627 | { | ||||||||||||||||||
| 628 | enum myhtml_tree_insertion_mode mode; | ||||||||||||||||||
| 629 | 0 | myhtml_tree_node_t* adjusted_location = myhtml_tree_appropriate_place_inserting(tree, NULL, &mode); | |||||||||||||||||
| 630 | |||||||||||||||||||
| 631 | 0 | ▶ | if(adjusted_location == tree->document) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 632 | 0 | return NULL; | |||||||||||||||||
| 633 | |||||||||||||||||||
| 634 | 0 | ▶ | if(mode == MyHTML_TREE_INSERTION_MODE_AFTER) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 635 | 0 | ▶ | if(adjusted_location->tag_id == MyHTML_TAG__TEXT && adjusted_location->token) | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 636 | { | ||||||||||||||||||
| 637 | 0 | myhtml_token_merged_two_token_string(tree, adjusted_location->token, token, false); | |||||||||||||||||
| 638 | 0 | return adjusted_location; | |||||||||||||||||
| 639 | } | ||||||||||||||||||
| 640 | } | ||||||||||||||||||
| 641 | 0 | ▶ | else if(mode == MyHTML_TREE_INSERTION_MODE_BEFORE) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 642 | 0 | ▶ | if(adjusted_location->tag_id == MyHTML_TAG__TEXT && adjusted_location->token) { | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 643 | 0 | myhtml_token_merged_two_token_string(tree, token, adjusted_location->token, true); | |||||||||||||||||
| 644 | 0 | return adjusted_location; | |||||||||||||||||
| 645 | } | ||||||||||||||||||
| 646 | } | ||||||||||||||||||
| 647 | else { | ||||||||||||||||||
| 648 | 0 | ▶ | if(adjusted_location->last_child && adjusted_location->last_child->tag_id == MyHTML_TAG__TEXT && | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 649 | 0 | ▶ | adjusted_location->last_child->token) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 650 | { | ||||||||||||||||||
| 651 | 0 | myhtml_token_merged_two_token_string(tree, adjusted_location->last_child->token, token, false); | |||||||||||||||||
| 652 | 0 | return adjusted_location->last_child; | |||||||||||||||||
| 653 | } | ||||||||||||||||||
| 654 | } | ||||||||||||||||||
| 655 | |||||||||||||||||||
| 656 | 0 | myhtml_tree_node_t* node = myhtml_tree_node_create(tree); | |||||||||||||||||
| 657 | |||||||||||||||||||
| 658 | 0 | node->tag_id = MyHTML_TAG__TEXT; | |||||||||||||||||
| 659 | 0 | node->token = token; | |||||||||||||||||
| 660 | 0 | node->ns = adjusted_location->ns; | |||||||||||||||||
| 661 | |||||||||||||||||||
| 662 | 0 | myhtml_tree_node_insert_by_mode(adjusted_location, node, mode); | |||||||||||||||||
| 663 | 0 | return node; | |||||||||||||||||
| 664 | } | ||||||||||||||||||
| 665 | |||||||||||||||||||
| 666 | 0 | myhtml_tree_node_t * myhtml_tree_node_insert_by_node(myhtml_tree_t* tree, myhtml_tree_node_t* node) | |||||||||||||||||
| 667 | { | ||||||||||||||||||
| 668 | enum myhtml_tree_insertion_mode mode; | ||||||||||||||||||
| 669 | 0 | myhtml_tree_node_t* adjusted_location = myhtml_tree_appropriate_place_inserting(tree, NULL, &mode); | |||||||||||||||||
| 670 | 0 | myhtml_tree_node_insert_by_mode(adjusted_location, node, mode); | |||||||||||||||||
| 671 | |||||||||||||||||||
| 672 | 0 | myhtml_tree_open_elements_append(tree, node); | |||||||||||||||||
| 673 | 0 | return node; | |||||||||||||||||
| 674 | } | ||||||||||||||||||
| 675 | |||||||||||||||||||
| 676 | 0 | myhtml_tree_node_t * myhtml_tree_node_insert_foreign_element(myhtml_tree_t* tree, myhtml_token_node_t* token) | |||||||||||||||||
| 677 | { | ||||||||||||||||||
| 678 | enum myhtml_tree_insertion_mode mode; | ||||||||||||||||||
| 679 | 0 | myhtml_tree_node_t* adjusted_location = myhtml_tree_appropriate_place_inserting(tree, NULL, &mode); | |||||||||||||||||
| 680 | |||||||||||||||||||
| 681 | 0 | myhtml_tree_node_t* node = myhtml_tree_node_create(tree); | |||||||||||||||||
| 682 | |||||||||||||||||||
| 683 | 0 | node->tag_id = token->tag_id; | |||||||||||||||||
| 684 | 0 | node->token = token; | |||||||||||||||||
| 685 | 0 | node->ns = adjusted_location->ns; | |||||||||||||||||
| 686 | |||||||||||||||||||
| 687 | 0 | myhtml_tree_node_insert_by_mode(adjusted_location, node, mode); | |||||||||||||||||
| 688 | 0 | myhtml_tree_open_elements_append(tree, node); | |||||||||||||||||
| 689 | 0 | return node; | |||||||||||||||||
| 690 | } | ||||||||||||||||||
| 691 | |||||||||||||||||||
| 692 | 0 | myhtml_tree_node_t * myhtml_tree_node_insert_html_element(myhtml_tree_t* tree, myhtml_token_node_t* token) | |||||||||||||||||
| 693 | { | ||||||||||||||||||
| 694 | enum myhtml_tree_insertion_mode mode; | ||||||||||||||||||
| 695 | 0 | myhtml_tree_node_t* adjusted_location = myhtml_tree_appropriate_place_inserting(tree, NULL, &mode); | |||||||||||||||||
| 696 | |||||||||||||||||||
| 697 | 0 | myhtml_tree_node_t* node = myhtml_tree_node_create(tree); | |||||||||||||||||
| 698 | |||||||||||||||||||
| 699 | 0 | node->tag_id = token->tag_id; | |||||||||||||||||
| 700 | 0 | node->token = token; | |||||||||||||||||
| 701 | 0 | node->ns = MyHTML_NAMESPACE_HTML; | |||||||||||||||||
| 702 | |||||||||||||||||||
| 703 | 0 | myhtml_tree_node_insert_by_mode(adjusted_location, node, mode); | |||||||||||||||||
| 704 | 0 | myhtml_tree_open_elements_append(tree, node); | |||||||||||||||||
| 705 | 0 | return node; | |||||||||||||||||
| 706 | } | ||||||||||||||||||
| 707 | |||||||||||||||||||
| 708 | 0 | myhtml_tree_node_t * myhtml_tree_element_in_scope(myhtml_tree_t* tree, myhtml_tag_id_t tag_idx, | |||||||||||||||||
| 709 | myhtml_namespace_t mynamespace, enum myhtml_tag_categories category) | ||||||||||||||||||
| 710 | { | ||||||||||||||||||
| 711 | 0 | myhtml_tree_node_t** list = tree->open_elements->list; | |||||||||||||||||
| 712 | |||||||||||||||||||
| 713 | const myhtml_tag_context_t *tag_ctx; | ||||||||||||||||||
| 714 | 0 | size_t i = tree->open_elements->length; | |||||||||||||||||
| 715 | |||||||||||||||||||
| 716 | 0 | ▶ | while(i) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 717 | 0 | i--; | |||||||||||||||||
| 718 | |||||||||||||||||||
| 719 | 0 | tag_ctx = myhtml_tag_get_by_id(tree->tags, list[i]->tag_id); | |||||||||||||||||
| 720 | |||||||||||||||||||
| 721 | 0 | ▶ | if(list[i]->tag_id == tag_idx && | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 722 | 0 | ▶ | (mynamespace == MyHTML_NAMESPACE_UNDEF || list[i]->ns == mynamespace)) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 723 | 0 | return list[i]; | |||||||||||||||||
| 724 | 0 | ▶ | else if(category == MyHTML_TAG_CATEGORIES_SCOPE_SELECT) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 725 | 0 | ▶ | if((tag_ctx->cats[list[i]->ns] & category) == 0) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 726 | 0 | break; | |||||||||||||||||
| 727 | } | ||||||||||||||||||
| 728 | 0 | ▶ | else if(tag_ctx->cats[list[i]->ns] & category) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 729 | 0 | break; | |||||||||||||||||
| 730 | } | ||||||||||||||||||
| 731 | |||||||||||||||||||
| 732 | 0 | return NULL; | |||||||||||||||||
| 733 | } | ||||||||||||||||||
| 734 | |||||||||||||||||||
| 735 | 0 | bool myhtml_tree_element_in_scope_by_node(myhtml_tree_node_t* node, enum myhtml_tag_categories category) | |||||||||||||||||
| 736 | { | ||||||||||||||||||
| 737 | 0 | myhtml_tree_t* tree = node->tree; | |||||||||||||||||
| 738 | 0 | myhtml_tree_node_t** list = tree->open_elements->list; | |||||||||||||||||
| 739 | |||||||||||||||||||
| 740 | const myhtml_tag_context_t *tag_ctx; | ||||||||||||||||||
| 741 | 0 | size_t i = tree->open_elements->length; | |||||||||||||||||
| 742 | |||||||||||||||||||
| 743 | 0 | ▶ | while(i) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 744 | 0 | i--; | |||||||||||||||||
| 745 | |||||||||||||||||||
| 746 | 0 | tag_ctx = myhtml_tag_get_by_id(tree->tags, list[i]->tag_id); | |||||||||||||||||
| 747 | |||||||||||||||||||
| 748 | 0 | ▶ | if(list[i] == node) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 749 | 0 | return true; | |||||||||||||||||
| 750 | 0 | ▶ | else if(category == MyHTML_TAG_CATEGORIES_SCOPE_SELECT) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 751 | 0 | ▶ | if((tag_ctx->cats[list[i]->ns] & category) == 0) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 752 | 0 | break; | |||||||||||||||||
| 753 | } | ||||||||||||||||||
| 754 | 0 | ▶ | else if(tag_ctx->cats[list[i]->ns] & category) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 755 | 0 | break; | |||||||||||||||||
| 756 | } | ||||||||||||||||||
| 757 | |||||||||||||||||||
| 758 | 0 | return false; | |||||||||||||||||
| 759 | } | ||||||||||||||||||
| 760 | |||||||||||||||||||
| 761 | // list | ||||||||||||||||||
| 762 | 0 | myhtml_tree_list_t * myhtml_tree_list_init(void) | |||||||||||||||||
| 763 | { | ||||||||||||||||||
| 764 | 0 | myhtml_tree_list_t* list = mycore_malloc(sizeof(myhtml_tree_list_t)); | |||||||||||||||||
| 765 | |||||||||||||||||||
| 766 | 0 | list->length = 0; | |||||||||||||||||
| 767 | 0 | list->size = 4096; | |||||||||||||||||
| 768 | 0 | list->list = (myhtml_tree_node_t**)mycore_malloc(sizeof(myhtml_tree_node_t*) * list->size); | |||||||||||||||||
| 769 | |||||||||||||||||||
| 770 | 0 | return list; | |||||||||||||||||
| 771 | } | ||||||||||||||||||
| 772 | |||||||||||||||||||
| 773 | 0 | void myhtml_tree_list_clean(myhtml_tree_list_t* list) | |||||||||||||||||
| 774 | { | ||||||||||||||||||
| 775 | 0 | list->length = 0; | |||||||||||||||||
| 776 | 0 | } | |||||||||||||||||
| 777 | |||||||||||||||||||
| 778 | 0 | myhtml_tree_list_t * myhtml_tree_list_destroy(myhtml_tree_list_t* list, bool destroy_self) | |||||||||||||||||
| 779 | { | ||||||||||||||||||
| 780 | 0 | ▶ | if(list == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 781 | 0 | return NULL; | |||||||||||||||||
| 782 | |||||||||||||||||||
| 783 | 0 | ▶ | if(list->list) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 784 | 0 | mycore_free(list->list); | |||||||||||||||||
| 785 | |||||||||||||||||||
| 786 | 0 | ▶ | if(destroy_self && list) { | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 787 | 0 | mycore_free(list); | |||||||||||||||||
| 788 | 0 | return NULL; | |||||||||||||||||
| 789 | } | ||||||||||||||||||
| 790 | |||||||||||||||||||
| 791 | 0 | return list; | |||||||||||||||||
| 792 | } | ||||||||||||||||||
| 793 | |||||||||||||||||||
| 794 | 0 | void myhtml_tree_list_append(myhtml_tree_list_t* list, myhtml_tree_node_t* node) | |||||||||||||||||
| 795 | { | ||||||||||||||||||
| 796 | 0 | ▶ | if(list->length >= list->size) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 797 | 0 | list->size <<= 1; | |||||||||||||||||
| 798 | |||||||||||||||||||
| 799 | 0 | myhtml_tree_node_t** tmp = (myhtml_tree_node_t**)mycore_realloc(list->list, sizeof(myhtml_tree_node_t*) * list->size); | |||||||||||||||||
| 800 | |||||||||||||||||||
| 801 | 0 | ▶ | if(tmp) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 802 | 0 | list->list = tmp; | |||||||||||||||||
| 803 | } | ||||||||||||||||||
| 804 | |||||||||||||||||||
| 805 | 0 | list->list[list->length] = node; | |||||||||||||||||
| 806 | 0 | list->length++; | |||||||||||||||||
| 807 | 0 | } | |||||||||||||||||
| 808 | |||||||||||||||||||
| 809 | 0 | void myhtml_tree_list_append_after_index(myhtml_tree_list_t* list, myhtml_tree_node_t* node, size_t index) | |||||||||||||||||
| 810 | { | ||||||||||||||||||
| 811 | 0 | myhtml_tree_list_insert_by_index(list, node, (index + 1)); | |||||||||||||||||
| 812 | 0 | } | |||||||||||||||||
| 813 | |||||||||||||||||||
| 814 | 0 | void myhtml_tree_list_insert_by_index(myhtml_tree_list_t* list, myhtml_tree_node_t* node, size_t index) | |||||||||||||||||
| 815 | { | ||||||||||||||||||
| 816 | 0 | ▶ | if(list->length >= list->size) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 817 | 0 | list->size <<= 1; | |||||||||||||||||
| 818 | |||||||||||||||||||
| 819 | 0 | myhtml_tree_node_t** tmp = (myhtml_tree_node_t**)mycore_realloc(list->list, sizeof(myhtml_tree_node_t*) * list->size); | |||||||||||||||||
| 820 | |||||||||||||||||||
| 821 | 0 | ▶ | if(tmp) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 822 | 0 | list->list = tmp; | |||||||||||||||||
| 823 | } | ||||||||||||||||||
| 824 | |||||||||||||||||||
| 825 | 0 | myhtml_tree_node_t** node_list = list->list; | |||||||||||||||||
| 826 | |||||||||||||||||||
| 827 | 0 | memmove(&node_list[(index + 1)], &node_list[index], sizeof(myhtml_tree_node_t*) * (list->length - index)); | |||||||||||||||||
| 828 | |||||||||||||||||||
| 829 | 0 | list->list[index] = node; | |||||||||||||||||
| 830 | 0 | list->length++; | |||||||||||||||||
| 831 | 0 | } | |||||||||||||||||
| 832 | |||||||||||||||||||
| 833 | 0 | myhtml_tree_node_t * myhtml_tree_list_current_node(myhtml_tree_list_t* list) | |||||||||||||||||
| 834 | { | ||||||||||||||||||
| 835 | 0 | ▶ | if(list->length == 0) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 836 | 0 | return 0; | |||||||||||||||||
| 837 | |||||||||||||||||||
| 838 | 0 | return list->list[ list->length - 1 ]; | |||||||||||||||||
| 839 | } | ||||||||||||||||||
| 840 | |||||||||||||||||||
| 841 | // stack of open elements | ||||||||||||||||||
| 842 | 0 | myhtml_tree_list_t * myhtml_tree_open_elements_init(myhtml_tree_t* tree) | |||||||||||||||||
| 843 | { | ||||||||||||||||||
| 844 | 0 | return myhtml_tree_list_init(); | |||||||||||||||||
| 845 | } | ||||||||||||||||||
| 846 | |||||||||||||||||||
| 847 | 0 | void myhtml_tree_open_elements_clean(myhtml_tree_t* tree) | |||||||||||||||||
| 848 | { | ||||||||||||||||||
| 849 | 0 | tree->open_elements->length = 0; | |||||||||||||||||
| 850 | 0 | } | |||||||||||||||||
| 851 | |||||||||||||||||||
| 852 | 0 | myhtml_tree_list_t * myhtml_tree_open_elements_destroy(myhtml_tree_t* tree) | |||||||||||||||||
| 853 | { | ||||||||||||||||||
| 854 | 0 | return myhtml_tree_list_destroy(tree->open_elements, true); | |||||||||||||||||
| 855 | } | ||||||||||||||||||
| 856 | |||||||||||||||||||
| 857 | 0 | myhtml_tree_node_t * myhtml_tree_current_node(myhtml_tree_t* tree) | |||||||||||||||||
| 858 | { | ||||||||||||||||||
| 859 | 0 | ▶ | if(tree->open_elements->length == 0) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 860 | MyCORE_DEBUG("Current node; Open elements is 0"); | ||||||||||||||||||
| 861 | 0 | return 0; | |||||||||||||||||
| 862 | } | ||||||||||||||||||
| 863 | |||||||||||||||||||
| 864 | 0 | return tree->open_elements->list[ tree->open_elements->length - 1 ]; | |||||||||||||||||
| 865 | } | ||||||||||||||||||
| 866 | |||||||||||||||||||
| 867 | 0 | myhtml_tree_node_t * myhtml_tree_adjusted_current_node(myhtml_tree_t* tree) | |||||||||||||||||
| 868 | { | ||||||||||||||||||
| 869 | 0 | ▶ | if(tree->open_elements->length == 1 && tree->fragment) | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 870 | 0 | return tree->fragment; | |||||||||||||||||
| 871 | |||||||||||||||||||
| 872 | 0 | return myhtml_tree_current_node(tree); | |||||||||||||||||
| 873 | } | ||||||||||||||||||
| 874 | |||||||||||||||||||
| 875 | 0 | void myhtml_tree_open_elements_append(myhtml_tree_t* tree, myhtml_tree_node_t* node) | |||||||||||||||||
| 876 | { | ||||||||||||||||||
| 877 | 0 | myhtml_tree_list_append(tree->open_elements, node); | |||||||||||||||||
| 878 | 0 | } | |||||||||||||||||
| 879 | |||||||||||||||||||
| 880 | 0 | void myhtml_tree_open_elements_append_after_index(myhtml_tree_t* tree, myhtml_tree_node_t* node, size_t index) | |||||||||||||||||
| 881 | { | ||||||||||||||||||
| 882 | 0 | myhtml_tree_list_append_after_index(tree->open_elements, node, index); | |||||||||||||||||
| 883 | 0 | } | |||||||||||||||||
| 884 | |||||||||||||||||||
| 885 | 0 | void myhtml_tree_open_elements_pop(myhtml_tree_t* tree) | |||||||||||||||||
| 886 | { | ||||||||||||||||||
| 887 | 0 | ▶ | if(tree->open_elements->length) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 888 | 0 | tree->open_elements->length--; | |||||||||||||||||
| 889 | |||||||||||||||||||
| 890 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 891 | if(tree->open_elements->length == 0) { | ||||||||||||||||||
| 892 | MyCORE_DEBUG("Pop open elements; Now, Open Elements set 0; Good, if the end of parsing, otherwise is very bad"); | ||||||||||||||||||
| 893 | } | ||||||||||||||||||
| 894 | #endif | ||||||||||||||||||
| 895 | 0 | } | |||||||||||||||||
| 896 | |||||||||||||||||||
| 897 | 0 | void myhtml_tree_open_elements_remove(myhtml_tree_t* tree, myhtml_tree_node_t* node) | |||||||||||||||||
| 898 | { | ||||||||||||||||||
| 899 | 0 | myhtml_tree_node_t** list = tree->open_elements->list; | |||||||||||||||||
| 900 | |||||||||||||||||||
| 901 | 0 | size_t el_idx = tree->open_elements->length; | |||||||||||||||||
| 902 | 0 | ▶ | while(el_idx) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 903 | { | ||||||||||||||||||
| 904 | 0 | el_idx--; | |||||||||||||||||
| 905 | |||||||||||||||||||
| 906 | 0 | ▶ | if(list[el_idx] == node) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 907 | { | ||||||||||||||||||
| 908 | 0 | memmove(&list[el_idx], &list[el_idx + 1], sizeof(myhtml_tree_node_t*) * (tree->open_elements->length - el_idx)); | |||||||||||||||||
| 909 | 0 | tree->open_elements->length--; | |||||||||||||||||
| 910 | |||||||||||||||||||
| 911 | 0 | break; | |||||||||||||||||
| 912 | } | ||||||||||||||||||
| 913 | } | ||||||||||||||||||
| 914 | |||||||||||||||||||
| 915 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 916 | if(tree->open_elements->length == 0) { | ||||||||||||||||||
| 917 | MyCORE_DEBUG("Remove open elements; Now, Open Elements set 0; Good, if the end of parsing, otherwise is very bad"); | ||||||||||||||||||
| 918 | } | ||||||||||||||||||
| 919 | #endif | ||||||||||||||||||
| 920 | 0 | } | |||||||||||||||||
| 921 | |||||||||||||||||||
| 922 | 0 | void myhtml_tree_open_elements_pop_until(myhtml_tree_t* tree, myhtml_tag_id_t tag_idx, myhtml_namespace_t mynamespace, bool is_exclude) | |||||||||||||||||
| 923 | { | ||||||||||||||||||
| 924 | 0 | myhtml_tree_node_t** list = tree->open_elements->list; | |||||||||||||||||
| 925 | |||||||||||||||||||
| 926 | 0 | ▶ | while(tree->open_elements->length) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 927 | { | ||||||||||||||||||
| 928 | 0 | tree->open_elements->length--; | |||||||||||||||||
| 929 | |||||||||||||||||||
| 930 | 0 | ▶ | if(list[ tree->open_elements->length ]->tag_id == tag_idx && | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 931 | // check namespace if set | ||||||||||||||||||
| 932 | 0 | (mynamespace == MyHTML_NAMESPACE_UNDEF || | |||||||||||||||||
| 933 | 0 | ▶ | list[ tree->open_elements->length ]->ns == mynamespace)) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 934 | { | ||||||||||||||||||
| 935 | 0 | ▶ | if(is_exclude) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 936 | 0 | tree->open_elements->length++; | |||||||||||||||||
| 937 | |||||||||||||||||||
| 938 | 0 | break; | |||||||||||||||||
| 939 | } | ||||||||||||||||||
| 940 | } | ||||||||||||||||||
| 941 | |||||||||||||||||||
| 942 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 943 | if(tree->open_elements->length == 0) { | ||||||||||||||||||
| 944 | MyCORE_DEBUG("Until open elements; Now, Open Elements set 0; Good, if the end of parsing, otherwise is very bad"); | ||||||||||||||||||
| 945 | } | ||||||||||||||||||
| 946 | #endif | ||||||||||||||||||
| 947 | 0 | } | |||||||||||||||||
| 948 | |||||||||||||||||||
| 949 | 0 | void myhtml_tree_open_elements_pop_until_by_node(myhtml_tree_t* tree, myhtml_tree_node_t* node, bool is_exclude) | |||||||||||||||||
| 950 | { | ||||||||||||||||||
| 951 | 0 | myhtml_tree_node_t** list = tree->open_elements->list; | |||||||||||||||||
| 952 | |||||||||||||||||||
| 953 | 0 | ▶ | while(tree->open_elements->length) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 954 | { | ||||||||||||||||||
| 955 | 0 | tree->open_elements->length--; | |||||||||||||||||
| 956 | |||||||||||||||||||
| 957 | 0 | ▶ | if(list[ tree->open_elements->length ] == node) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 958 | 0 | ▶ | if(is_exclude) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 959 | 0 | tree->open_elements->length++; | |||||||||||||||||
| 960 | |||||||||||||||||||
| 961 | 0 | break; | |||||||||||||||||
| 962 | } | ||||||||||||||||||
| 963 | } | ||||||||||||||||||
| 964 | |||||||||||||||||||
| 965 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 966 | if(tree->open_elements->length == 0) { | ||||||||||||||||||
| 967 | MyCORE_DEBUG("Until by node open elements; Now, Open Elements set 0; Good, if the end of parsing, otherwise is very bad"); | ||||||||||||||||||
| 968 | } | ||||||||||||||||||
| 969 | #endif | ||||||||||||||||||
| 970 | 0 | } | |||||||||||||||||
| 971 | |||||||||||||||||||
| 972 | 0 | void myhtml_tree_open_elements_pop_until_by_index(myhtml_tree_t* tree, size_t idx, bool is_exclude) | |||||||||||||||||
| 973 | { | ||||||||||||||||||
| 974 | 0 | ▶ | while(tree->open_elements->length) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 975 | { | ||||||||||||||||||
| 976 | 0 | tree->open_elements->length--; | |||||||||||||||||
| 977 | |||||||||||||||||||
| 978 | 0 | ▶ | if(tree->open_elements->length == idx) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 979 | 0 | ▶ | if(is_exclude) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 980 | 0 | tree->open_elements->length++; | |||||||||||||||||
| 981 | |||||||||||||||||||
| 982 | 0 | break; | |||||||||||||||||
| 983 | } | ||||||||||||||||||
| 984 | } | ||||||||||||||||||
| 985 | |||||||||||||||||||
| 986 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 987 | if(tree->open_elements->length == 0) { | ||||||||||||||||||
| 988 | MyCORE_DEBUG("Until by index open elements; Now, Open Elements set 0; Good, if the end of parsing, otherwise is very bad"); | ||||||||||||||||||
| 989 | } | ||||||||||||||||||
| 990 | #endif | ||||||||||||||||||
| 991 | 0 | } | |||||||||||||||||
| 992 | |||||||||||||||||||
| 993 | 0 | bool myhtml_tree_open_elements_find_reverse(myhtml_tree_t* tree, myhtml_tree_node_t* idx, size_t* pos) | |||||||||||||||||
| 994 | { | ||||||||||||||||||
| 995 | 0 | myhtml_tree_node_t** list = tree->open_elements->list; | |||||||||||||||||
| 996 | |||||||||||||||||||
| 997 | 0 | size_t i = tree->open_elements->length; | |||||||||||||||||
| 998 | 0 | ▶ | while(i) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 999 | { | ||||||||||||||||||
| 1000 | 0 | i--; | |||||||||||||||||
| 1001 | |||||||||||||||||||
| 1002 | 0 | ▶ | if(list[i] == idx) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1003 | 0 | ▶ | if(pos) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1004 | 0 | *pos = i; | |||||||||||||||||
| 1005 | |||||||||||||||||||
| 1006 | 0 | return true; | |||||||||||||||||
| 1007 | } | ||||||||||||||||||
| 1008 | } | ||||||||||||||||||
| 1009 | |||||||||||||||||||
| 1010 | 0 | return false; | |||||||||||||||||
| 1011 | } | ||||||||||||||||||
| 1012 | |||||||||||||||||||
| 1013 | 0 | bool myhtml_tree_open_elements_find(myhtml_tree_t* tree, myhtml_tree_node_t* node, size_t* pos) | |||||||||||||||||
| 1014 | { | ||||||||||||||||||
| 1015 | 0 | myhtml_tree_node_t** list = tree->open_elements->list; | |||||||||||||||||
| 1016 | |||||||||||||||||||
| 1017 | 0 | ▶ | for (size_t i = 0; i < tree->open_elements->length; i++) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1018 | { | ||||||||||||||||||
| 1019 | 0 | ▶ | if(list[i] == node) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1020 | 0 | ▶ | if(pos) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1021 | 0 | *pos = i; | |||||||||||||||||
| 1022 | |||||||||||||||||||
| 1023 | 0 | return true; | |||||||||||||||||
| 1024 | } | ||||||||||||||||||
| 1025 | } | ||||||||||||||||||
| 1026 | |||||||||||||||||||
| 1027 | 0 | return false; | |||||||||||||||||
| 1028 | } | ||||||||||||||||||
| 1029 | |||||||||||||||||||
| 1030 | 0 | myhtml_tree_node_t * myhtml_tree_open_elements_find_by_tag_idx_reverse(myhtml_tree_t* tree, myhtml_tag_id_t tag_idx, myhtml_namespace_t mynamespace, size_t* return_index) | |||||||||||||||||
| 1031 | { | ||||||||||||||||||
| 1032 | 0 | myhtml_tree_node_t** list = tree->open_elements->list; | |||||||||||||||||
| 1033 | |||||||||||||||||||
| 1034 | 0 | size_t i = tree->open_elements->length; | |||||||||||||||||
| 1035 | 0 | ▶ | while(i) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1036 | { | ||||||||||||||||||
| 1037 | 0 | i--; | |||||||||||||||||
| 1038 | |||||||||||||||||||
| 1039 | 0 | ▶ | if(list[i]->tag_id == tag_idx && | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 1040 | 0 | ▶ | (mynamespace == MyHTML_NAMESPACE_UNDEF || list[i]->ns == mynamespace)) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1041 | { | ||||||||||||||||||
| 1042 | 0 | ▶ | if(return_index) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1043 | 0 | *return_index = i; | |||||||||||||||||
| 1044 | |||||||||||||||||||
| 1045 | 0 | return list[i]; | |||||||||||||||||
| 1046 | } | ||||||||||||||||||
| 1047 | } | ||||||||||||||||||
| 1048 | |||||||||||||||||||
| 1049 | 0 | return NULL; | |||||||||||||||||
| 1050 | } | ||||||||||||||||||
| 1051 | |||||||||||||||||||
| 1052 | 0 | myhtml_tree_node_t * myhtml_tree_open_elements_find_by_tag_idx(myhtml_tree_t* tree, myhtml_tag_id_t tag_idx, myhtml_namespace_t mynamespace, size_t* return_index) | |||||||||||||||||
| 1053 | { | ||||||||||||||||||
| 1054 | 0 | myhtml_tree_node_t** list = tree->open_elements->list; | |||||||||||||||||
| 1055 | |||||||||||||||||||
| 1056 | 0 | ▶ | for (size_t i = 0; i < tree->open_elements->length; i++) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1057 | { | ||||||||||||||||||
| 1058 | 0 | ▶ | if(list[i]->tag_id == tag_idx && | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 1059 | 0 | ▶ | (mynamespace == MyHTML_NAMESPACE_UNDEF || list[i]->ns == mynamespace)) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1060 | { | ||||||||||||||||||
| 1061 | 0 | ▶ | if(return_index) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1062 | 0 | *return_index = i; | |||||||||||||||||
| 1063 | |||||||||||||||||||
| 1064 | 0 | return list[i]; | |||||||||||||||||
| 1065 | } | ||||||||||||||||||
| 1066 | } | ||||||||||||||||||
| 1067 | |||||||||||||||||||
| 1068 | 0 | return NULL; | |||||||||||||||||
| 1069 | } | ||||||||||||||||||
| 1070 | |||||||||||||||||||
| 1071 | 0 | void myhtml_tree_generate_implied_end_tags(myhtml_tree_t* tree, myhtml_tag_id_t exclude_tag_idx, myhtml_namespace_t mynamespace) | |||||||||||||||||
| 1072 | { | ||||||||||||||||||
| 1073 | 0 | ▶ | if(tree->open_elements->length == 0) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1074 | MyCORE_DEBUG("Generate implied end tags; Open elements is 0"); | ||||||||||||||||||
| 1075 | 0 | return; | |||||||||||||||||
| 1076 | } | ||||||||||||||||||
| 1077 | |||||||||||||||||||
| 1078 | 0 | ▶ | while(tree->open_elements->length > 0) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1079 | { | ||||||||||||||||||
| 1080 | 0 | myhtml_tree_node_t* current_node = myhtml_tree_current_node(tree); | |||||||||||||||||
| 1081 | |||||||||||||||||||
| 1082 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1083 | if(current_node == NULL) { | ||||||||||||||||||
| 1084 | MyCORE_DEBUG_ERROR("Generate implied end tags; Current node is NULL! This is very bad"); | ||||||||||||||||||
| 1085 | } | ||||||||||||||||||
| 1086 | #endif | ||||||||||||||||||
| 1087 | |||||||||||||||||||
| 1088 | 0 | ▶ | switch (current_node->tag_id) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1089 | 0 | case MyHTML_TAG_DD: | |||||||||||||||||
| 1090 | case MyHTML_TAG_DT: | ||||||||||||||||||
| 1091 | case MyHTML_TAG_LI: | ||||||||||||||||||
| 1092 | case MyHTML_TAG_MENUITEM: | ||||||||||||||||||
| 1093 | case MyHTML_TAG_OPTGROUP: | ||||||||||||||||||
| 1094 | case MyHTML_TAG_OPTION: | ||||||||||||||||||
| 1095 | case MyHTML_TAG_P: | ||||||||||||||||||
| 1096 | case MyHTML_TAG_RB: | ||||||||||||||||||
| 1097 | case MyHTML_TAG_RP: | ||||||||||||||||||
| 1098 | case MyHTML_TAG_RT: | ||||||||||||||||||
| 1099 | case MyHTML_TAG_RTC: | ||||||||||||||||||
| 1100 | 0 | ▶ | if(exclude_tag_idx == current_node->tag_id && | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 1101 | 0 | ▶ | (mynamespace == MyHTML_NAMESPACE_UNDEF || current_node->ns == mynamespace)) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1102 | 0 | return; | |||||||||||||||||
| 1103 | |||||||||||||||||||
| 1104 | 0 | myhtml_tree_open_elements_pop(tree); | |||||||||||||||||
| 1105 | 0 | continue; | |||||||||||||||||
| 1106 | |||||||||||||||||||
| 1107 | 0 | default: | |||||||||||||||||
| 1108 | 0 | return; | |||||||||||||||||
| 1109 | } | ||||||||||||||||||
| 1110 | } | ||||||||||||||||||
| 1111 | } | ||||||||||||||||||
| 1112 | |||||||||||||||||||
| 1113 | 0 | void myhtml_tree_generate_all_implied_end_tags(myhtml_tree_t* tree, myhtml_tag_id_t exclude_tag_idx, myhtml_namespace_t mynamespace) | |||||||||||||||||
| 1114 | { | ||||||||||||||||||
| 1115 | 0 | ▶ | if(tree->open_elements->length == 0) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1116 | MyCORE_DEBUG("Generate all implied end tags; Open elements is 0"); | ||||||||||||||||||
| 1117 | 0 | return; | |||||||||||||||||
| 1118 | } | ||||||||||||||||||
| 1119 | |||||||||||||||||||
| 1120 | 0 | ▶ | while(tree->open_elements->length > 0) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1121 | { | ||||||||||||||||||
| 1122 | 0 | myhtml_tree_node_t* current_node = myhtml_tree_current_node(tree); | |||||||||||||||||
| 1123 | |||||||||||||||||||
| 1124 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1125 | if(current_node == NULL) { | ||||||||||||||||||
| 1126 | MyCORE_DEBUG_ERROR("Generate all implied end tags; Current node is NULL! This is very bad"); | ||||||||||||||||||
| 1127 | } | ||||||||||||||||||
| 1128 | #endif | ||||||||||||||||||
| 1129 | |||||||||||||||||||
| 1130 | 0 | ▶ | switch (current_node->tag_id) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1131 | 0 | case MyHTML_TAG_CAPTION: | |||||||||||||||||
| 1132 | case MyHTML_TAG_COLGROUP: | ||||||||||||||||||
| 1133 | case MyHTML_TAG_DD: | ||||||||||||||||||
| 1134 | case MyHTML_TAG_DT: | ||||||||||||||||||
| 1135 | case MyHTML_TAG_LI: | ||||||||||||||||||
| 1136 | case MyHTML_TAG_OPTGROUP: | ||||||||||||||||||
| 1137 | case MyHTML_TAG_OPTION: | ||||||||||||||||||
| 1138 | case MyHTML_TAG_P: | ||||||||||||||||||
| 1139 | case MyHTML_TAG_RB: | ||||||||||||||||||
| 1140 | case MyHTML_TAG_RP: | ||||||||||||||||||
| 1141 | case MyHTML_TAG_RT: | ||||||||||||||||||
| 1142 | case MyHTML_TAG_RTC: | ||||||||||||||||||
| 1143 | case MyHTML_TAG_TBODY: | ||||||||||||||||||
| 1144 | case MyHTML_TAG_TD: | ||||||||||||||||||
| 1145 | case MyHTML_TAG_TFOOT: | ||||||||||||||||||
| 1146 | case MyHTML_TAG_TH: | ||||||||||||||||||
| 1147 | case MyHTML_TAG_THEAD: | ||||||||||||||||||
| 1148 | case MyHTML_TAG_TR: | ||||||||||||||||||
| 1149 | 0 | ▶ | if(exclude_tag_idx == current_node->tag_id && | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 1150 | 0 | ▶ | (mynamespace == MyHTML_NAMESPACE_UNDEF || current_node->ns == mynamespace)) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1151 | 0 | return; | |||||||||||||||||
| 1152 | |||||||||||||||||||
| 1153 | 0 | myhtml_tree_open_elements_pop(tree); | |||||||||||||||||
| 1154 | 0 | continue; | |||||||||||||||||
| 1155 | |||||||||||||||||||
| 1156 | 0 | default: | |||||||||||||||||
| 1157 | 0 | return; | |||||||||||||||||
| 1158 | } | ||||||||||||||||||
| 1159 | } | ||||||||||||||||||
| 1160 | } | ||||||||||||||||||
| 1161 | |||||||||||||||||||
| 1162 | 0 | void myhtml_tree_reset_insertion_mode_appropriately(myhtml_tree_t* tree) | |||||||||||||||||
| 1163 | { | ||||||||||||||||||
| 1164 | 0 | ▶ | if(tree->open_elements->length == 0) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1165 | MyCORE_DEBUG("Reset insertion mode appropriately; Open elements is 0"); | ||||||||||||||||||
| 1166 | 0 | return; | |||||||||||||||||
| 1167 | } | ||||||||||||||||||
| 1168 | |||||||||||||||||||
| 1169 | 0 | size_t i = tree->open_elements->length; | |||||||||||||||||
| 1170 | |||||||||||||||||||
| 1171 | // step 1 | ||||||||||||||||||
| 1172 | 0 | bool last = false; | |||||||||||||||||
| 1173 | 0 | myhtml_tree_node_t** list = tree->open_elements->list; | |||||||||||||||||
| 1174 | |||||||||||||||||||
| 1175 | // step 3 | ||||||||||||||||||
| 1176 | 0 | ▶ | while(i) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1177 | { | ||||||||||||||||||
| 1178 | 0 | i--; | |||||||||||||||||
| 1179 | |||||||||||||||||||
| 1180 | // step 2 | ||||||||||||||||||
| 1181 | 0 | myhtml_tree_node_t* node = list[i]; | |||||||||||||||||
| 1182 | |||||||||||||||||||
| 1183 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1184 | if(node == NULL) { | ||||||||||||||||||
| 1185 | MyCORE_DEBUG_ERROR("Reset insertion mode appropriately; node is NULL! This is very bad"); | ||||||||||||||||||
| 1186 | } | ||||||||||||||||||
| 1187 | #endif | ||||||||||||||||||
| 1188 | |||||||||||||||||||
| 1189 | 0 | ▶ | if(i == 0) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1190 | 0 | last = true; | |||||||||||||||||
| 1191 | |||||||||||||||||||
| 1192 | 0 | ▶ | if(tree->fragment) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1193 | 0 | node = tree->fragment; | |||||||||||||||||
| 1194 | } | ||||||||||||||||||
| 1195 | } | ||||||||||||||||||
| 1196 | |||||||||||||||||||
| 1197 | 0 | ▶ | if(node->ns != MyHTML_NAMESPACE_HTML) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1198 | 0 | ▶ | if(last) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1199 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_BODY; | |||||||||||||||||
| 1200 | 0 | return; | |||||||||||||||||
| 1201 | } | ||||||||||||||||||
| 1202 | |||||||||||||||||||
| 1203 | 0 | continue; | |||||||||||||||||
| 1204 | } | ||||||||||||||||||
| 1205 | |||||||||||||||||||
| 1206 | // step 4 | ||||||||||||||||||
| 1207 | 0 | ▶ | if(node->tag_id == MyHTML_TAG_SELECT) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1208 | { | ||||||||||||||||||
| 1209 | // step 4.1 | ||||||||||||||||||
| 1210 | 0 | ▶ | if(last) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1211 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_SELECT; | |||||||||||||||||
| 1212 | 0 | return; | |||||||||||||||||
| 1213 | } | ||||||||||||||||||
| 1214 | |||||||||||||||||||
| 1215 | // step 4.2 | ||||||||||||||||||
| 1216 | 0 | size_t ancestor = i; | |||||||||||||||||
| 1217 | |||||||||||||||||||
| 1218 | while(1) | ||||||||||||||||||
| 1219 | { | ||||||||||||||||||
| 1220 | // step 4.3 | ||||||||||||||||||
| 1221 | 0 | ▶ | if(ancestor == 0) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1222 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_SELECT; | |||||||||||||||||
| 1223 | 0 | return; | |||||||||||||||||
| 1224 | } | ||||||||||||||||||
| 1225 | |||||||||||||||||||
| 1226 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1227 | if(ancestor == 0) { | ||||||||||||||||||
| 1228 | MyCORE_DEBUG_ERROR("Reset insertion mode appropriately; Ancestor is 0! This is very, very bad"); | ||||||||||||||||||
| 1229 | } | ||||||||||||||||||
| 1230 | #endif | ||||||||||||||||||
| 1231 | |||||||||||||||||||
| 1232 | // step 4.4 | ||||||||||||||||||
| 1233 | 0 | ancestor--; | |||||||||||||||||
| 1234 | |||||||||||||||||||
| 1235 | // step 4.5 | ||||||||||||||||||
| 1236 | 0 | ▶ | if(list[ancestor]->tag_id == MyHTML_TAG_TEMPLATE) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1237 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_SELECT; | |||||||||||||||||
| 1238 | 0 | return; | |||||||||||||||||
| 1239 | } | ||||||||||||||||||
| 1240 | // step 4.6 | ||||||||||||||||||
| 1241 | 0 | ▶ | else if(list[ancestor]->tag_id == MyHTML_TAG_TABLE) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1242 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_SELECT_IN_TABLE; | |||||||||||||||||
| 1243 | 0 | return; | |||||||||||||||||
| 1244 | } | ||||||||||||||||||
| 1245 | } | ||||||||||||||||||
| 1246 | } | ||||||||||||||||||
| 1247 | |||||||||||||||||||
| 1248 | // step 5-15 | ||||||||||||||||||
| 1249 | 0 | switch (node->tag_id) { | |||||||||||||||||
| 1250 | 0 | case MyHTML_TAG_TD: | |||||||||||||||||
| 1251 | case MyHTML_TAG_TH: | ||||||||||||||||||
| 1252 | 0 | ▶ | if(last == false) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1253 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_CELL; | |||||||||||||||||
| 1254 | 0 | return; | |||||||||||||||||
| 1255 | } | ||||||||||||||||||
| 1256 | 0 | break; | |||||||||||||||||
| 1257 | |||||||||||||||||||
| 1258 | 0 | case MyHTML_TAG_TR: | |||||||||||||||||
| 1259 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_ROW; | |||||||||||||||||
| 1260 | 0 | return; | |||||||||||||||||
| 1261 | |||||||||||||||||||
| 1262 | 0 | case MyHTML_TAG_TBODY: | |||||||||||||||||
| 1263 | case MyHTML_TAG_TFOOT: | ||||||||||||||||||
| 1264 | case MyHTML_TAG_THEAD: | ||||||||||||||||||
| 1265 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_TABLE_BODY; | |||||||||||||||||
| 1266 | 0 | return; | |||||||||||||||||
| 1267 | |||||||||||||||||||
| 1268 | 0 | case MyHTML_TAG_CAPTION: | |||||||||||||||||
| 1269 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_CAPTION; | |||||||||||||||||
| 1270 | 0 | return; | |||||||||||||||||
| 1271 | |||||||||||||||||||
| 1272 | 0 | case MyHTML_TAG_COLGROUP: | |||||||||||||||||
| 1273 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_COLUMN_GROUP; | |||||||||||||||||
| 1274 | 0 | return; | |||||||||||||||||
| 1275 | |||||||||||||||||||
| 1276 | 0 | case MyHTML_TAG_TABLE: | |||||||||||||||||
| 1277 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_TABLE; | |||||||||||||||||
| 1278 | 0 | return; | |||||||||||||||||
| 1279 | |||||||||||||||||||
| 1280 | 0 | case MyHTML_TAG_TEMPLATE: | |||||||||||||||||
| 1281 | 0 | tree->insert_mode = tree->template_insertion->list[(tree->template_insertion->length - 1)]; | |||||||||||||||||
| 1282 | 0 | return; | |||||||||||||||||
| 1283 | |||||||||||||||||||
| 1284 | 0 | case MyHTML_TAG_HEAD: | |||||||||||||||||
| 1285 | 0 | ▶ | if(last == false) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1286 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_HEAD; | |||||||||||||||||
| 1287 | 0 | return; | |||||||||||||||||
| 1288 | } | ||||||||||||||||||
| 1289 | 0 | break; | |||||||||||||||||
| 1290 | |||||||||||||||||||
| 1291 | 0 | case MyHTML_TAG_BODY: | |||||||||||||||||
| 1292 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_BODY; | |||||||||||||||||
| 1293 | 0 | return; | |||||||||||||||||
| 1294 | |||||||||||||||||||
| 1295 | 0 | case MyHTML_TAG_FRAMESET: | |||||||||||||||||
| 1296 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_FRAMESET; | |||||||||||||||||
| 1297 | 0 | return; | |||||||||||||||||
| 1298 | |||||||||||||||||||
| 1299 | 0 | case MyHTML_TAG_HTML: | |||||||||||||||||
| 1300 | { | ||||||||||||||||||
| 1301 | 0 | ▶ | if(tree->node_head) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1302 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_AFTER_HEAD; | |||||||||||||||||
| 1303 | 0 | return; | |||||||||||||||||
| 1304 | } | ||||||||||||||||||
| 1305 | |||||||||||||||||||
| 1306 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_BEFORE_HEAD; | |||||||||||||||||
| 1307 | 0 | return; | |||||||||||||||||
| 1308 | } | ||||||||||||||||||
| 1309 | |||||||||||||||||||
| 1310 | 0 | default: | |||||||||||||||||
| 1311 | 0 | break; | |||||||||||||||||
| 1312 | } | ||||||||||||||||||
| 1313 | |||||||||||||||||||
| 1314 | // step 16 | ||||||||||||||||||
| 1315 | 0 | ▶ | if(last) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1316 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_BODY; | |||||||||||||||||
| 1317 | 0 | return; | |||||||||||||||||
| 1318 | } | ||||||||||||||||||
| 1319 | |||||||||||||||||||
| 1320 | // step 17 | ||||||||||||||||||
| 1321 | } | ||||||||||||||||||
| 1322 | |||||||||||||||||||
| 1323 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_INITIAL; | |||||||||||||||||
| 1324 | } | ||||||||||||||||||
| 1325 | |||||||||||||||||||
| 1326 | // stack of active formatting elements | ||||||||||||||||||
| 1327 | 0 | myhtml_tree_list_t * myhtml_tree_active_formatting_init(myhtml_tree_t* tree) | |||||||||||||||||
| 1328 | { | ||||||||||||||||||
| 1329 | 0 | return myhtml_tree_list_init(); | |||||||||||||||||
| 1330 | } | ||||||||||||||||||
| 1331 | |||||||||||||||||||
| 1332 | 0 | void myhtml_tree_active_formatting_clean(myhtml_tree_t* tree) | |||||||||||||||||
| 1333 | { | ||||||||||||||||||
| 1334 | 0 | tree->active_formatting->length = 0; | |||||||||||||||||
| 1335 | 0 | } | |||||||||||||||||
| 1336 | |||||||||||||||||||
| 1337 | 0 | myhtml_tree_list_t * myhtml_tree_active_formatting_destroy(myhtml_tree_t* tree) | |||||||||||||||||
| 1338 | { | ||||||||||||||||||
| 1339 | 0 | return myhtml_tree_list_destroy(tree->active_formatting, true); | |||||||||||||||||
| 1340 | } | ||||||||||||||||||
| 1341 | |||||||||||||||||||
| 1342 | 0 | bool myhtml_tree_active_formatting_is_marker(myhtml_tree_t* tree, myhtml_tree_node_t* node) | |||||||||||||||||
| 1343 | { | ||||||||||||||||||
| 1344 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1345 | if(node == NULL) { | ||||||||||||||||||
| 1346 | MyCORE_DEBUG_ERROR("Active formatting is marker; node is NULL!"); | ||||||||||||||||||
| 1347 | } | ||||||||||||||||||
| 1348 | #endif | ||||||||||||||||||
| 1349 | |||||||||||||||||||
| 1350 | 0 | ▶ | if(tree->myhtml->marker == node) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1351 | 0 | return true; | |||||||||||||||||
| 1352 | |||||||||||||||||||
| 1353 | 0 | ▶ | switch (node->tag_id) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1354 | 0 | case MyHTML_TAG_APPLET: | |||||||||||||||||
| 1355 | case MyHTML_TAG_BUTTON: | ||||||||||||||||||
| 1356 | case MyHTML_TAG_OBJECT: | ||||||||||||||||||
| 1357 | case MyHTML_TAG_MARQUEE: | ||||||||||||||||||
| 1358 | case MyHTML_TAG_TD: | ||||||||||||||||||
| 1359 | case MyHTML_TAG_TH: | ||||||||||||||||||
| 1360 | case MyHTML_TAG_CAPTION: | ||||||||||||||||||
| 1361 | 0 | return true; | |||||||||||||||||
| 1362 | |||||||||||||||||||
| 1363 | 0 | default: | |||||||||||||||||
| 1364 | 0 | break; | |||||||||||||||||
| 1365 | } | ||||||||||||||||||
| 1366 | |||||||||||||||||||
| 1367 | 0 | return false; | |||||||||||||||||
| 1368 | } | ||||||||||||||||||
| 1369 | |||||||||||||||||||
| 1370 | 0 | void myhtml_tree_active_formatting_append(myhtml_tree_t* tree, myhtml_tree_node_t* node) | |||||||||||||||||
| 1371 | { | ||||||||||||||||||
| 1372 | 0 | myhtml_tree_list_append( tree->active_formatting, node); | |||||||||||||||||
| 1373 | 0 | } | |||||||||||||||||
| 1374 | |||||||||||||||||||
| 1375 | 0 | void myhtml_tree_active_formatting_pop(myhtml_tree_t* tree) | |||||||||||||||||
| 1376 | { | ||||||||||||||||||
| 1377 | 0 | ▶ | if(tree->active_formatting->length) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1378 | 0 | tree->active_formatting->length--; | |||||||||||||||||
| 1379 | |||||||||||||||||||
| 1380 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1381 | if(tree->active_formatting->length == 0) { | ||||||||||||||||||
| 1382 | MyCORE_DEBUG("Pop active formatting; length is 0"); | ||||||||||||||||||
| 1383 | } | ||||||||||||||||||
| 1384 | #endif | ||||||||||||||||||
| 1385 | 0 | } | |||||||||||||||||
| 1386 | |||||||||||||||||||
| 1387 | 0 | void myhtml_tree_active_formatting_remove(myhtml_tree_t* tree, myhtml_tree_node_t* node) | |||||||||||||||||
| 1388 | { | ||||||||||||||||||
| 1389 | 0 | myhtml_tree_node_t** list = tree->active_formatting->list; | |||||||||||||||||
| 1390 | |||||||||||||||||||
| 1391 | 0 | size_t el_idx = tree->active_formatting->length; | |||||||||||||||||
| 1392 | 0 | ▶ | while(el_idx) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1393 | { | ||||||||||||||||||
| 1394 | 0 | el_idx--; | |||||||||||||||||
| 1395 | |||||||||||||||||||
| 1396 | 0 | ▶ | if(list[el_idx] == node) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1397 | { | ||||||||||||||||||
| 1398 | 0 | memmove(&list[el_idx], &list[el_idx + 1], sizeof(myhtml_tree_node_t*) * (tree->active_formatting->length - el_idx)); | |||||||||||||||||
| 1399 | 0 | tree->active_formatting->length--; | |||||||||||||||||
| 1400 | |||||||||||||||||||
| 1401 | 0 | break; | |||||||||||||||||
| 1402 | } | ||||||||||||||||||
| 1403 | } | ||||||||||||||||||
| 1404 | |||||||||||||||||||
| 1405 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1406 | if(tree->active_formatting->length == 0) { | ||||||||||||||||||
| 1407 | // MyCORE_DEBUG("Remove active formatting; length is 0"); | ||||||||||||||||||
| 1408 | } | ||||||||||||||||||
| 1409 | #endif | ||||||||||||||||||
| 1410 | 0 | } | |||||||||||||||||
| 1411 | |||||||||||||||||||
| 1412 | 0 | void myhtml_tree_active_formatting_remove_by_index(myhtml_tree_t* tree, size_t idx) | |||||||||||||||||
| 1413 | { | ||||||||||||||||||
| 1414 | 0 | myhtml_tree_node_t** list = tree->active_formatting->list; | |||||||||||||||||
| 1415 | |||||||||||||||||||
| 1416 | 0 | memmove(&list[idx], &list[idx + 1], sizeof(myhtml_tree_node_t*) * (tree->active_formatting->length - idx)); | |||||||||||||||||
| 1417 | 0 | tree->active_formatting->length--; | |||||||||||||||||
| 1418 | |||||||||||||||||||
| 1419 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1420 | if(tree->active_formatting->length == 0) { | ||||||||||||||||||
| 1421 | MyCORE_DEBUG("Remove active formatting by index; length is 0"); | ||||||||||||||||||
| 1422 | } | ||||||||||||||||||
| 1423 | #endif | ||||||||||||||||||
| 1424 | 0 | } | |||||||||||||||||
| 1425 | |||||||||||||||||||
| 1426 | 0 | void myhtml_tree_active_formatting_append_with_check(myhtml_tree_t* tree, myhtml_tree_node_t* node) | |||||||||||||||||
| 1427 | { | ||||||||||||||||||
| 1428 | // if(myhtml_tree_active_formatting_is_marker(tree, node)) { | ||||||||||||||||||
| 1429 | // myhtml_tree_active_formatting_append(tree, node); | ||||||||||||||||||
| 1430 | // return; | ||||||||||||||||||
| 1431 | // } | ||||||||||||||||||
| 1432 | |||||||||||||||||||
| 1433 | 0 | myhtml_tree_node_t** list = tree->active_formatting->list; | |||||||||||||||||
| 1434 | 0 | size_t i = tree->active_formatting->length; | |||||||||||||||||
| 1435 | 0 | ▶ | size_t earliest_idx = (i ? (i - 1) : 0); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1436 | 0 | size_t count = 0; | |||||||||||||||||
| 1437 | |||||||||||||||||||
| 1438 | 0 | ▶ | while(i) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1439 | { | ||||||||||||||||||
| 1440 | 0 | i--; | |||||||||||||||||
| 1441 | |||||||||||||||||||
| 1442 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1443 | if(list[i] == NULL) { | ||||||||||||||||||
| 1444 | MyCORE_DEBUG("Appen active formatting with check; list[" MyCORE_FORMAT_Z "] is NULL", i); | ||||||||||||||||||
| 1445 | } | ||||||||||||||||||
| 1446 | #endif | ||||||||||||||||||
| 1447 | |||||||||||||||||||
| 1448 | 0 | ▶ | if(myhtml_tree_active_formatting_is_marker(tree, list[i])) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1449 | 0 | break; | |||||||||||||||||
| 1450 | |||||||||||||||||||
| 1451 | 0 | ▶ | if(list[i]->token && node->token) | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 1452 | { | ||||||||||||||||||
| 1453 | 0 | myhtml_token_node_wait_for_done(tree->token, list[i]->token); | |||||||||||||||||
| 1454 | 0 | myhtml_token_node_wait_for_done(tree->token, node->token); | |||||||||||||||||
| 1455 | |||||||||||||||||||
| 1456 | 0 | ▶ | if(list[i]->ns == node->ns && | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1457 | 0 | list[i]->tag_id == node->tag_id && | |||||||||||||||||
| 1458 | 0 | myhtml_token_attr_compare(list[i]->token, node->token)) | |||||||||||||||||
| 1459 | { | ||||||||||||||||||
| 1460 | 0 | count++; | |||||||||||||||||
| 1461 | 0 | earliest_idx = i; | |||||||||||||||||
| 1462 | } | ||||||||||||||||||
| 1463 | } | ||||||||||||||||||
| 1464 | } | ||||||||||||||||||
| 1465 | |||||||||||||||||||
| 1466 | 0 | ▶ | if(count >= 3) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1467 | 0 | myhtml_tree_active_formatting_remove_by_index(tree, earliest_idx); | |||||||||||||||||
| 1468 | |||||||||||||||||||
| 1469 | 0 | myhtml_tree_active_formatting_append(tree, node); | |||||||||||||||||
| 1470 | 0 | } | |||||||||||||||||
| 1471 | |||||||||||||||||||
| 1472 | 0 | myhtml_tree_node_t * myhtml_tree_active_formatting_current_node(myhtml_tree_t* tree) | |||||||||||||||||
| 1473 | { | ||||||||||||||||||
| 1474 | 0 | ▶ | if(tree->active_formatting->length == 0) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1475 | MyCORE_DEBUG("Current node active formatting; length is 0"); | ||||||||||||||||||
| 1476 | 0 | return 0; | |||||||||||||||||
| 1477 | } | ||||||||||||||||||
| 1478 | |||||||||||||||||||
| 1479 | 0 | return tree->active_formatting->list[ tree->active_formatting->length - 1 ]; | |||||||||||||||||
| 1480 | } | ||||||||||||||||||
| 1481 | |||||||||||||||||||
| 1482 | 0 | bool myhtml_tree_active_formatting_find(myhtml_tree_t* tree, myhtml_tree_node_t* node, size_t* return_idx) | |||||||||||||||||
| 1483 | { | ||||||||||||||||||
| 1484 | 0 | myhtml_tree_node_t** list = tree->active_formatting->list; | |||||||||||||||||
| 1485 | |||||||||||||||||||
| 1486 | 0 | size_t i = tree->active_formatting->length; | |||||||||||||||||
| 1487 | 0 | ▶ | while(i) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1488 | { | ||||||||||||||||||
| 1489 | 0 | i--; | |||||||||||||||||
| 1490 | |||||||||||||||||||
| 1491 | 0 | ▶ | if(list[i] == node) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1492 | 0 | ▶ | if(return_idx) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1493 | 0 | *return_idx = i; | |||||||||||||||||
| 1494 | |||||||||||||||||||
| 1495 | 0 | return true; | |||||||||||||||||
| 1496 | } | ||||||||||||||||||
| 1497 | } | ||||||||||||||||||
| 1498 | |||||||||||||||||||
| 1499 | 0 | return false; | |||||||||||||||||
| 1500 | } | ||||||||||||||||||
| 1501 | |||||||||||||||||||
| 1502 | 0 | void myhtml_tree_active_formatting_up_to_last_marker(myhtml_tree_t* tree) | |||||||||||||||||
| 1503 | { | ||||||||||||||||||
| 1504 | // Step 1: Let entry be the last (most recently added) entry in the list of active formatting elements. | ||||||||||||||||||
| 1505 | 0 | myhtml_tree_node_t** list = tree->active_formatting->list; | |||||||||||||||||
| 1506 | |||||||||||||||||||
| 1507 | // Step 2: Remove entry from the list of active formatting elements. | ||||||||||||||||||
| 1508 | 0 | ▶ | if(tree->active_formatting->length == 0) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1509 | 0 | return; | |||||||||||||||||
| 1510 | |||||||||||||||||||
| 1511 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1512 | if(list[ tree->active_formatting->length ] == NULL) { | ||||||||||||||||||
| 1513 | MyCORE_DEBUG("Up to last marker active formatting; list[" MyCORE_FORMAT_Z "] is NULL", tree->active_formatting->length); | ||||||||||||||||||
| 1514 | } | ||||||||||||||||||
| 1515 | #endif | ||||||||||||||||||
| 1516 | |||||||||||||||||||
| 1517 | 0 | ▶ | while(tree->active_formatting->length) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1518 | { | ||||||||||||||||||
| 1519 | 0 | tree->active_formatting->length--; | |||||||||||||||||
| 1520 | |||||||||||||||||||
| 1521 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1522 | if(list[ tree->active_formatting->length ] == NULL) { | ||||||||||||||||||
| 1523 | MyCORE_DEBUG("Up to last marker active formatting; list[" MyCORE_FORMAT_Z "] is NULL", tree->active_formatting->length); | ||||||||||||||||||
| 1524 | } | ||||||||||||||||||
| 1525 | #endif | ||||||||||||||||||
| 1526 | |||||||||||||||||||
| 1527 | 0 | ▶ | if(myhtml_tree_active_formatting_is_marker(tree, list[ tree->active_formatting->length ])) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1528 | // include marker | ||||||||||||||||||
| 1529 | //tree->active_formatting->length++; | ||||||||||||||||||
| 1530 | 0 | break; | |||||||||||||||||
| 1531 | } | ||||||||||||||||||
| 1532 | } | ||||||||||||||||||
| 1533 | } | ||||||||||||||||||
| 1534 | |||||||||||||||||||
| 1535 | 0 | myhtml_tree_node_t * myhtml_tree_active_formatting_between_last_marker(myhtml_tree_t* tree, myhtml_tag_id_t tag_idx, size_t* return_idx) | |||||||||||||||||
| 1536 | { | ||||||||||||||||||
| 1537 | 0 | myhtml_tree_node_t** list = tree->active_formatting->list; | |||||||||||||||||
| 1538 | |||||||||||||||||||
| 1539 | 0 | size_t i = tree->active_formatting->length; | |||||||||||||||||
| 1540 | 0 | ▶ | while(i) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1541 | { | ||||||||||||||||||
| 1542 | 0 | i--; | |||||||||||||||||
| 1543 | |||||||||||||||||||
| 1544 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1545 | if(list[i] == NULL) { | ||||||||||||||||||
| 1546 | MyCORE_DEBUG("Between last marker active formatting; list[" MyCORE_FORMAT_Z "] is NULL", i); | ||||||||||||||||||
| 1547 | } | ||||||||||||||||||
| 1548 | #endif | ||||||||||||||||||
| 1549 | |||||||||||||||||||
| 1550 | 0 | ▶ | if(myhtml_tree_active_formatting_is_marker(tree, list[i])) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1551 | 0 | break; | |||||||||||||||||
| 1552 | 0 | ▶ | else if(list[i]->tag_id == tag_idx && list[i]->ns == MyHTML_NAMESPACE_HTML) { | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 1553 | 0 | ▶ | if(return_idx) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1554 | 0 | *return_idx = i; | |||||||||||||||||
| 1555 | 0 | return list[i]; | |||||||||||||||||
| 1556 | } | ||||||||||||||||||
| 1557 | } | ||||||||||||||||||
| 1558 | |||||||||||||||||||
| 1559 | 0 | return NULL; | |||||||||||||||||
| 1560 | } | ||||||||||||||||||
| 1561 | |||||||||||||||||||
| 1562 | 0 | void myhtml_tree_active_formatting_reconstruction(myhtml_tree_t* tree) | |||||||||||||||||
| 1563 | { | ||||||||||||||||||
| 1564 | 0 | myhtml_tree_list_t* af = tree->active_formatting; | |||||||||||||||||
| 1565 | 0 | myhtml_tree_node_t** list = af->list; | |||||||||||||||||
| 1566 | |||||||||||||||||||
| 1567 | // step 1 | ||||||||||||||||||
| 1568 | 0 | ▶ | if(af->length == 0) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1569 | 0 | return; | |||||||||||||||||
| 1570 | |||||||||||||||||||
| 1571 | // step 2--3 | ||||||||||||||||||
| 1572 | 0 | size_t af_idx = af->length - 1; | |||||||||||||||||
| 1573 | |||||||||||||||||||
| 1574 | 0 | if(myhtml_tree_active_formatting_is_marker(tree, list[af_idx]) || | |||||||||||||||||
| 1575 | 0 | myhtml_tree_open_elements_find(tree, list[af_idx], NULL)) | |||||||||||||||||
| 1576 | 0 | return; | |||||||||||||||||
| 1577 | |||||||||||||||||||
| 1578 | // step 4--6 | ||||||||||||||||||
| 1579 | 0 | ▶ | while (af_idx) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1580 | { | ||||||||||||||||||
| 1581 | 0 | af_idx--; | |||||||||||||||||
| 1582 | |||||||||||||||||||
| 1583 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1584 | if(list[af_idx] == NULL) { | ||||||||||||||||||
| 1585 | MyCORE_DEBUG("Formatting reconstruction; Step 4--6; list[" MyCORE_FORMAT_Z "] is NULL", af_idx); | ||||||||||||||||||
| 1586 | } | ||||||||||||||||||
| 1587 | #endif | ||||||||||||||||||
| 1588 | |||||||||||||||||||
| 1589 | 0 | if(myhtml_tree_active_formatting_is_marker(tree, list[af_idx]) || | |||||||||||||||||
| 1590 | 0 | myhtml_tree_open_elements_find(tree, list[af_idx], NULL)) | |||||||||||||||||
| 1591 | { | ||||||||||||||||||
| 1592 | 0 | af_idx++; // need if 0 | |||||||||||||||||
| 1593 | 0 | break; | |||||||||||||||||
| 1594 | } | ||||||||||||||||||
| 1595 | } | ||||||||||||||||||
| 1596 | |||||||||||||||||||
| 1597 | 0 | ▶ | while (af_idx < af->length) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1598 | { | ||||||||||||||||||
| 1599 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1600 | if(list[af_idx] == NULL) { | ||||||||||||||||||
| 1601 | MyCORE_DEBUG("Formatting reconstruction; Next steps; list[" MyCORE_FORMAT_Z "] is NULL", af_idx); | ||||||||||||||||||
| 1602 | } | ||||||||||||||||||
| 1603 | #endif | ||||||||||||||||||
| 1604 | |||||||||||||||||||
| 1605 | 0 | myhtml_tree_node_t* node = myhtml_tree_node_clone(list[af_idx]); | |||||||||||||||||
| 1606 | 0 | myhtml_tree_node_insert_by_node(tree, node); | |||||||||||||||||
| 1607 | |||||||||||||||||||
| 1608 | 0 | list[af_idx] = node; | |||||||||||||||||
| 1609 | |||||||||||||||||||
| 1610 | 0 | af_idx++; | |||||||||||||||||
| 1611 | } | ||||||||||||||||||
| 1612 | } | ||||||||||||||||||
| 1613 | |||||||||||||||||||
| 1614 | 0 | bool myhtml_tree_adoption_agency_algorithm(myhtml_tree_t* tree, myhtml_token_node_t* token, myhtml_tag_id_t subject_tag_idx) | |||||||||||||||||
| 1615 | { | ||||||||||||||||||
| 1616 | 0 | ▶ | if(tree->open_elements->length == 0) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1617 | 0 | return false; | |||||||||||||||||
| 1618 | |||||||||||||||||||
| 1619 | 0 | size_t oel_curr_index = tree->open_elements->length - 1; | |||||||||||||||||
| 1620 | |||||||||||||||||||
| 1621 | 0 | myhtml_tree_node_t** oel_list = tree->open_elements->list; | |||||||||||||||||
| 1622 | 0 | myhtml_tree_node_t** afe_list = tree->active_formatting->list; | |||||||||||||||||
| 1623 | 0 | myhtml_tree_node_t* current_node = oel_list[oel_curr_index]; | |||||||||||||||||
| 1624 | |||||||||||||||||||
| 1625 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1626 | if(current_node == NULL) { | ||||||||||||||||||
| 1627 | MyCORE_DEBUG_ERROR("Adoption agency algorithm; Current node is NULL"); | ||||||||||||||||||
| 1628 | } | ||||||||||||||||||
| 1629 | #endif | ||||||||||||||||||
| 1630 | |||||||||||||||||||
| 1631 | // step 1 | ||||||||||||||||||
| 1632 | 0 | ▶ | if(current_node->ns == MyHTML_NAMESPACE_HTML && current_node->tag_id == subject_tag_idx && | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 1633 | 0 | ▶ | myhtml_tree_active_formatting_find(tree, current_node, NULL) == false) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1634 | { | ||||||||||||||||||
| 1635 | 0 | myhtml_tree_open_elements_pop(tree); | |||||||||||||||||
| 1636 | 0 | return false; | |||||||||||||||||
| 1637 | } | ||||||||||||||||||
| 1638 | |||||||||||||||||||
| 1639 | // step 2, 3 | ||||||||||||||||||
| 1640 | 0 | int loop = 0; | |||||||||||||||||
| 1641 | |||||||||||||||||||
| 1642 | 0 | ▶ | while (loop < 8) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1643 | { | ||||||||||||||||||
| 1644 | // step 4 | ||||||||||||||||||
| 1645 | 0 | loop++; | |||||||||||||||||
| 1646 | |||||||||||||||||||
| 1647 | // step 5 | ||||||||||||||||||
| 1648 | 0 | size_t afe_index = 0; | |||||||||||||||||
| 1649 | 0 | myhtml_tree_node_t* formatting_element = NULL; | |||||||||||||||||
| 1650 | { | ||||||||||||||||||
| 1651 | 0 | myhtml_tree_node_t** list = tree->active_formatting->list; | |||||||||||||||||
| 1652 | |||||||||||||||||||
| 1653 | 0 | size_t i = tree->active_formatting->length; | |||||||||||||||||
| 1654 | 0 | ▶ | while(i) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1655 | { | ||||||||||||||||||
| 1656 | 0 | i--; | |||||||||||||||||
| 1657 | |||||||||||||||||||
| 1658 | 0 | ▶ | if(myhtml_tree_active_formatting_is_marker(tree, list[i])) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1659 | 0 | return false; | |||||||||||||||||
| 1660 | 0 | ▶ | else if(list[i]->tag_id == subject_tag_idx) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1661 | 0 | afe_index = i; | |||||||||||||||||
| 1662 | 0 | formatting_element = list[i]; | |||||||||||||||||
| 1663 | 0 | break; | |||||||||||||||||
| 1664 | } | ||||||||||||||||||
| 1665 | } | ||||||||||||||||||
| 1666 | } | ||||||||||||||||||
| 1667 | |||||||||||||||||||
| 1668 | //myhtml_tree_node_t* formatting_element = myhtml_tree_active_formatting_between_last_marker(tree, subject_tag_idx, &afe_index); | ||||||||||||||||||
| 1669 | |||||||||||||||||||
| 1670 | // If there is no such element, then abort these steps and instead act as described in the | ||||||||||||||||||
| 1671 | // ===> "any other end tag" entry above. | ||||||||||||||||||
| 1672 | 0 | ▶ | if(formatting_element == NULL) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1673 | 0 | return true; | |||||||||||||||||
| 1674 | } | ||||||||||||||||||
| 1675 | |||||||||||||||||||
| 1676 | // step 6 | ||||||||||||||||||
| 1677 | size_t oel_format_el_idx; | ||||||||||||||||||
| 1678 | 0 | ▶ | if(myhtml_tree_open_elements_find(tree, formatting_element, &oel_format_el_idx) == false) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1679 | 0 | myhtml_tree_active_formatting_remove(tree, formatting_element); | |||||||||||||||||
| 1680 | 0 | return false; | |||||||||||||||||
| 1681 | } | ||||||||||||||||||
| 1682 | |||||||||||||||||||
| 1683 | // step 7 | ||||||||||||||||||
| 1684 | 0 | ▶ | if(myhtml_tree_element_in_scope_by_node(formatting_element, MyHTML_TAG_CATEGORIES_SCOPE) == false) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1685 | /* %EXTERNAL% VALIDATOR:RULES TOKEN STATUS:AAA_FORMATTING_ELEMENT_NOT_FOUND LEVEL:ERROR NODE:formatting_element */ | ||||||||||||||||||
| 1686 | 0 | return false; | |||||||||||||||||
| 1687 | } | ||||||||||||||||||
| 1688 | |||||||||||||||||||
| 1689 | // step 8 | ||||||||||||||||||
| 1690 | //if(afe_last != list[i]) | ||||||||||||||||||
| 1691 | // fprintf(stderr, "oh"); | ||||||||||||||||||
| 1692 | |||||||||||||||||||
| 1693 | // step 9 | ||||||||||||||||||
| 1694 | 0 | myhtml_tree_node_t* current_node = myhtml_tree_current_node(tree); | |||||||||||||||||
| 1695 | 0 | ▶ | if(current_node->ns != formatting_element->ns || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1696 | 0 | current_node->tag_id != formatting_element->tag_id) { | |||||||||||||||||
| 1697 | // parse error | ||||||||||||||||||
| 1698 | /* %EXTERNAL% VALIDATOR:RULES HAVE_NEED STATUS:ELEMENT_NO_EXPECTED LEVEL:ERROR */ | ||||||||||||||||||
| 1699 | /* %EXTERNAL% VALIDATOR:RULES HAVE_NEED_ADD HAVE:current_node->token NEED:formatting_element->token HAVE_TAG_ID:current_node->tag_id HAVE_NS:current_node->ns NEED_TAG_ID:formatting_element->tag_id NEED_NS:formatting_element->ns */ | ||||||||||||||||||
| 1700 | } | ||||||||||||||||||
| 1701 | |||||||||||||||||||
| 1702 | // 10 | ||||||||||||||||||
| 1703 | // Let furthest block be the topmost node in the stack of open elements | ||||||||||||||||||
| 1704 | // that is lower in the stack than formatting element, and is an element in the special category. T | ||||||||||||||||||
| 1705 | // here might not be one. | ||||||||||||||||||
| 1706 | 0 | myhtml_tree_node_t* furthest_block = NULL; | |||||||||||||||||
| 1707 | 0 | size_t idx_furthest_block = 0; | |||||||||||||||||
| 1708 | 0 | ▶ | for (idx_furthest_block = oel_format_el_idx; idx_furthest_block < tree->open_elements->length; idx_furthest_block++) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1709 | { | ||||||||||||||||||
| 1710 | 0 | const myhtml_tag_context_t *tag_ctx = myhtml_tag_get_by_id(tree->tags, oel_list[idx_furthest_block]->tag_id); | |||||||||||||||||
| 1711 | |||||||||||||||||||
| 1712 | 0 | ▶ | if(tag_ctx->cats[oel_list[idx_furthest_block]->ns] & MyHTML_TAG_CATEGORIES_SPECIAL) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1713 | 0 | furthest_block = oel_list[idx_furthest_block]; | |||||||||||||||||
| 1714 | 0 | break; | |||||||||||||||||
| 1715 | } | ||||||||||||||||||
| 1716 | } | ||||||||||||||||||
| 1717 | |||||||||||||||||||
| 1718 | // step 11 | ||||||||||||||||||
| 1719 | // If there is no furthest block, then the UA must first pop all the nodes from the bottom | ||||||||||||||||||
| 1720 | // of the stack of open elements, from the current node up to and including formatting element, | ||||||||||||||||||
| 1721 | // then remove formatting element from the list of active formatting elements, and finally abort these steps. | ||||||||||||||||||
| 1722 | 0 | ▶ | if(furthest_block == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1723 | { | ||||||||||||||||||
| 1724 | 0 | ▶ | while(myhtml_tree_current_node(tree) != formatting_element) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1725 | 0 | myhtml_tree_open_elements_pop(tree); | |||||||||||||||||
| 1726 | } | ||||||||||||||||||
| 1727 | |||||||||||||||||||
| 1728 | 0 | myhtml_tree_open_elements_pop(tree); // and including formatting element | |||||||||||||||||
| 1729 | 0 | myhtml_tree_active_formatting_remove(tree, formatting_element); | |||||||||||||||||
| 1730 | |||||||||||||||||||
| 1731 | 0 | return false; | |||||||||||||||||
| 1732 | } | ||||||||||||||||||
| 1733 | |||||||||||||||||||
| 1734 | /* %EXTERNAL% VALIDATOR:RULES TOKEN STATUS:AAA_BEGIN LEVEL:INFO */ | ||||||||||||||||||
| 1735 | |||||||||||||||||||
| 1736 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1737 | if(oel_format_el_idx == 0) { | ||||||||||||||||||
| 1738 | MyCORE_DEBUG_ERROR("Adoption agency algorithm; Step 11; oel_format_el_idx is 0; Bad!"); | ||||||||||||||||||
| 1739 | } | ||||||||||||||||||
| 1740 | #endif | ||||||||||||||||||
| 1741 | |||||||||||||||||||
| 1742 | // step 12 | ||||||||||||||||||
| 1743 | 0 | myhtml_tree_node_t* common_ancestor = oel_list[oel_format_el_idx - 1]; | |||||||||||||||||
| 1744 | |||||||||||||||||||
| 1745 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1746 | if(common_ancestor == NULL) { | ||||||||||||||||||
| 1747 | MyCORE_DEBUG_ERROR("Adoption agency algorithm; Step 11; common_ancestor is NULL"); | ||||||||||||||||||
| 1748 | } | ||||||||||||||||||
| 1749 | #endif | ||||||||||||||||||
| 1750 | |||||||||||||||||||
| 1751 | // step 13 | ||||||||||||||||||
| 1752 | 0 | size_t bookmark = afe_index + 1; | |||||||||||||||||
| 1753 | |||||||||||||||||||
| 1754 | // step 14 | ||||||||||||||||||
| 1755 | 0 | myhtml_tree_node_t *node = furthest_block, *last = furthest_block; | |||||||||||||||||
| 1756 | 0 | size_t index_oel_node = idx_furthest_block; | |||||||||||||||||
| 1757 | |||||||||||||||||||
| 1758 | // step 14.1 | ||||||||||||||||||
| 1759 | 0 | for(int inner_loop = 0;;) | |||||||||||||||||
| 1760 | 0 | { | |||||||||||||||||
| 1761 | // step 14.2 | ||||||||||||||||||
| 1762 | 0 | inner_loop++; | |||||||||||||||||
| 1763 | |||||||||||||||||||
| 1764 | // step 14.3 | ||||||||||||||||||
| 1765 | size_t node_index; | ||||||||||||||||||
| 1766 | 0 | ▶ | if(myhtml_tree_open_elements_find(tree, node, &node_index) == false) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1767 | 0 | node_index = index_oel_node; | |||||||||||||||||
| 1768 | } | ||||||||||||||||||
| 1769 | |||||||||||||||||||
| 1770 | 0 | ▶ | if(node_index > 0) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1771 | 0 | node_index--; | |||||||||||||||||
| 1772 | else { | ||||||||||||||||||
| 1773 | MyCORE_DEBUG_ERROR("Adoption agency algorithm; decrement node_index, node_index is null"); | ||||||||||||||||||
| 1774 | 0 | return false; | |||||||||||||||||
| 1775 | } | ||||||||||||||||||
| 1776 | |||||||||||||||||||
| 1777 | 0 | index_oel_node = node_index; | |||||||||||||||||
| 1778 | |||||||||||||||||||
| 1779 | 0 | node = oel_list[node_index]; | |||||||||||||||||
| 1780 | |||||||||||||||||||
| 1781 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1782 | if(node == NULL) { | ||||||||||||||||||
| 1783 | MyCORE_DEBUG_ERROR("Adoption agency algorithm; Step 13.3; node is NULL"); | ||||||||||||||||||
| 1784 | } | ||||||||||||||||||
| 1785 | #endif | ||||||||||||||||||
| 1786 | // step 14.4 | ||||||||||||||||||
| 1787 | 0 | ▶ | if(node == formatting_element) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1788 | 0 | break; | |||||||||||||||||
| 1789 | |||||||||||||||||||
| 1790 | // step 14.5 | ||||||||||||||||||
| 1791 | size_t afe_node_index; | ||||||||||||||||||
| 1792 | 0 | bool is_exists = myhtml_tree_active_formatting_find(tree, node, &afe_node_index); | |||||||||||||||||
| 1793 | 0 | ▶ | if(inner_loop > 3 && is_exists) { | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 1794 | 0 | myhtml_tree_active_formatting_remove_by_index(tree, afe_node_index); | |||||||||||||||||
| 1795 | |||||||||||||||||||
| 1796 | 0 | ▶ | if(afe_node_index < bookmark) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1797 | 0 | bookmark--; | |||||||||||||||||
| 1798 | |||||||||||||||||||
| 1799 | // If inner loop counter is greater than three and node is in the list of active formatting elements, | ||||||||||||||||||
| 1800 | // then remove node from the list of active formatting elements. | ||||||||||||||||||
| 1801 | 0 | continue; | |||||||||||||||||
| 1802 | } | ||||||||||||||||||
| 1803 | |||||||||||||||||||
| 1804 | // step 14.6 | ||||||||||||||||||
| 1805 | 0 | ▶ | if(is_exists == false) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1806 | 0 | myhtml_tree_open_elements_remove(tree, node); | |||||||||||||||||
| 1807 | 0 | continue; | |||||||||||||||||
| 1808 | } | ||||||||||||||||||
| 1809 | |||||||||||||||||||
| 1810 | // step 14.7 | ||||||||||||||||||
| 1811 | 0 | myhtml_tree_node_t* clone = myhtml_tree_node_clone(node); | |||||||||||||||||
| 1812 | |||||||||||||||||||
| 1813 | 0 | clone->ns = MyHTML_NAMESPACE_HTML; | |||||||||||||||||
| 1814 | |||||||||||||||||||
| 1815 | 0 | afe_list[afe_node_index] = clone; | |||||||||||||||||
| 1816 | 0 | oel_list[node_index] = clone; | |||||||||||||||||
| 1817 | |||||||||||||||||||
| 1818 | 0 | node = clone; | |||||||||||||||||
| 1819 | |||||||||||||||||||
| 1820 | // step 14.8 | ||||||||||||||||||
| 1821 | 0 | ▶ | if(last == furthest_block) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1822 | 0 | bookmark = afe_node_index + 1; | |||||||||||||||||
| 1823 | |||||||||||||||||||
| 1824 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1825 | if(bookmark >= tree->active_formatting->length) { | ||||||||||||||||||
| 1826 | MyCORE_DEBUG_ERROR("Adoption agency algorithm; Step 13.8; bookmark >= open_elements length"); | ||||||||||||||||||
| 1827 | } | ||||||||||||||||||
| 1828 | #endif | ||||||||||||||||||
| 1829 | } | ||||||||||||||||||
| 1830 | |||||||||||||||||||
| 1831 | // step 14.9 | ||||||||||||||||||
| 1832 | 0 | ▶ | if(last->parent) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1833 | 0 | myhtml_tree_node_remove(last); | |||||||||||||||||
| 1834 | |||||||||||||||||||
| 1835 | 0 | myhtml_tree_node_add_child(node, last); | |||||||||||||||||
| 1836 | |||||||||||||||||||
| 1837 | // step 14.10 | ||||||||||||||||||
| 1838 | 0 | last = node; | |||||||||||||||||
| 1839 | } | ||||||||||||||||||
| 1840 | |||||||||||||||||||
| 1841 | 0 | ▶ | if(last->parent) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1842 | 0 | myhtml_tree_node_remove(last); | |||||||||||||||||
| 1843 | |||||||||||||||||||
| 1844 | // step 15 | ||||||||||||||||||
| 1845 | enum myhtml_tree_insertion_mode insert_mode; | ||||||||||||||||||
| 1846 | 0 | common_ancestor = myhtml_tree_appropriate_place_inserting(tree, common_ancestor, &insert_mode); | |||||||||||||||||
| 1847 | 0 | myhtml_tree_node_insert_by_mode(common_ancestor, last, insert_mode); | |||||||||||||||||
| 1848 | |||||||||||||||||||
| 1849 | // step 16 | ||||||||||||||||||
| 1850 | 0 | myhtml_tree_node_t* new_formatting_element = myhtml_tree_node_clone(formatting_element); | |||||||||||||||||
| 1851 | |||||||||||||||||||
| 1852 | 0 | new_formatting_element->ns = MyHTML_NAMESPACE_HTML; | |||||||||||||||||
| 1853 | |||||||||||||||||||
| 1854 | // step 17 | ||||||||||||||||||
| 1855 | 0 | myhtml_tree_node_t * furthest_block_child = furthest_block->child; | |||||||||||||||||
| 1856 | |||||||||||||||||||
| 1857 | 0 | ▶ | while (furthest_block_child) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1858 | 0 | myhtml_tree_node_t *next = furthest_block_child->next; | |||||||||||||||||
| 1859 | 0 | myhtml_tree_node_remove(furthest_block_child); | |||||||||||||||||
| 1860 | |||||||||||||||||||
| 1861 | 0 | myhtml_tree_node_add_child(new_formatting_element, furthest_block_child); | |||||||||||||||||
| 1862 | 0 | furthest_block_child = next; | |||||||||||||||||
| 1863 | } | ||||||||||||||||||
| 1864 | |||||||||||||||||||
| 1865 | // step 18 | ||||||||||||||||||
| 1866 | 0 | myhtml_tree_node_add_child(furthest_block, new_formatting_element); | |||||||||||||||||
| 1867 | |||||||||||||||||||
| 1868 | // step 19 | ||||||||||||||||||
| 1869 | 0 | ▶ | if(myhtml_tree_active_formatting_find(tree, formatting_element, &afe_index) == false) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1870 | 0 | return false; | |||||||||||||||||
| 1871 | |||||||||||||||||||
| 1872 | 0 | ▶ | if(afe_index < bookmark) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1873 | 0 | bookmark--; | |||||||||||||||||
| 1874 | |||||||||||||||||||
| 1875 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1876 | if(bookmark >= tree->active_formatting->length) { | ||||||||||||||||||
| 1877 | MyCORE_DEBUG_ERROR("Adoption agency algorithm; Before Step 18; bookmark (" MyCORE_FORMAT_Z ") >= open_elements length", bookmark); | ||||||||||||||||||
| 1878 | } | ||||||||||||||||||
| 1879 | #endif | ||||||||||||||||||
| 1880 | |||||||||||||||||||
| 1881 | 0 | myhtml_tree_active_formatting_remove_by_index(tree, afe_index); | |||||||||||||||||
| 1882 | 0 | myhtml_tree_list_insert_by_index(tree->active_formatting, new_formatting_element, bookmark); | |||||||||||||||||
| 1883 | |||||||||||||||||||
| 1884 | // step 20 | ||||||||||||||||||
| 1885 | 0 | myhtml_tree_open_elements_remove(tree, formatting_element); | |||||||||||||||||
| 1886 | |||||||||||||||||||
| 1887 | 0 | ▶ | if(myhtml_tree_open_elements_find(tree, furthest_block, &idx_furthest_block)) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1888 | 0 | myhtml_tree_list_insert_by_index(tree->open_elements, new_formatting_element, idx_furthest_block + 1); | |||||||||||||||||
| 1889 | } | ||||||||||||||||||
| 1890 | else { | ||||||||||||||||||
| 1891 | MyCORE_DEBUG_ERROR("Adoption agency algorithm; Step 19; can't find furthest_block in open elements"); | ||||||||||||||||||
| 1892 | } | ||||||||||||||||||
| 1893 | } | ||||||||||||||||||
| 1894 | |||||||||||||||||||
| 1895 | 0 | return false; | |||||||||||||||||
| 1896 | } | ||||||||||||||||||
| 1897 | |||||||||||||||||||
| 1898 | 0 | myhtml_tree_node_t * myhtml_tree_appropriate_place_inserting(myhtml_tree_t* tree, myhtml_tree_node_t* override_target, | |||||||||||||||||
| 1899 | enum myhtml_tree_insertion_mode* mode) | ||||||||||||||||||
| 1900 | { | ||||||||||||||||||
| 1901 | 0 | *mode = MyHTML_TREE_INSERTION_MODE_DEFAULT; | |||||||||||||||||
| 1902 | |||||||||||||||||||
| 1903 | // step 1 | ||||||||||||||||||
| 1904 | 0 | ▶ | myhtml_tree_node_t* target = override_target ? override_target : myhtml_tree_current_node(tree); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1905 | |||||||||||||||||||
| 1906 | // step 2 | ||||||||||||||||||
| 1907 | myhtml_tree_node_t* adjusted_location; | ||||||||||||||||||
| 1908 | |||||||||||||||||||
| 1909 | 0 | ▶ | if(tree->foster_parenting) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1910 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1911 | if(target == NULL) { | ||||||||||||||||||
| 1912 | MyCORE_DEBUG_ERROR("Appropriate place inserting; Step 2; target is NULL in return value! This IS very bad"); | ||||||||||||||||||
| 1913 | } | ||||||||||||||||||
| 1914 | #endif | ||||||||||||||||||
| 1915 | 0 | ▶ | if(target->ns != MyHTML_NAMESPACE_HTML) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1916 | 0 | return target; | |||||||||||||||||
| 1917 | |||||||||||||||||||
| 1918 | 0 | ▶ | switch (target->tag_id) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1919 | 0 | case MyHTML_TAG_TABLE: | |||||||||||||||||
| 1920 | case MyHTML_TAG_TBODY: | ||||||||||||||||||
| 1921 | case MyHTML_TAG_TFOOT: | ||||||||||||||||||
| 1922 | case MyHTML_TAG_THEAD: | ||||||||||||||||||
| 1923 | case MyHTML_TAG_TR: | ||||||||||||||||||
| 1924 | { | ||||||||||||||||||
| 1925 | size_t idx_template, idx_table; | ||||||||||||||||||
| 1926 | |||||||||||||||||||
| 1927 | // step 2.1-2 | ||||||||||||||||||
| 1928 | 0 | myhtml_tree_node_t* last_template = myhtml_tree_open_elements_find_by_tag_idx_reverse(tree, MyHTML_TAG_TEMPLATE, MyHTML_NAMESPACE_HTML, &idx_template); | |||||||||||||||||
| 1929 | 0 | myhtml_tree_node_t* last_table = myhtml_tree_open_elements_find_by_tag_idx_reverse(tree, MyHTML_TAG_TABLE, MyHTML_NAMESPACE_HTML, &idx_table); | |||||||||||||||||
| 1930 | |||||||||||||||||||
| 1931 | // step 2.3 | ||||||||||||||||||
| 1932 | 0 | ▶ | if(last_template && (last_table == NULL || idx_template > idx_table)) | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 1933 | { | ||||||||||||||||||
| 1934 | 0 | return last_template; | |||||||||||||||||
| 1935 | } | ||||||||||||||||||
| 1936 | |||||||||||||||||||
| 1937 | // step 2.4 | ||||||||||||||||||
| 1938 | 0 | ▶ | else if(last_table == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1939 | { | ||||||||||||||||||
| 1940 | 0 | adjusted_location = tree->open_elements->list[0]; | |||||||||||||||||
| 1941 | 0 | break; | |||||||||||||||||
| 1942 | } | ||||||||||||||||||
| 1943 | |||||||||||||||||||
| 1944 | // step 2.5 | ||||||||||||||||||
| 1945 | 0 | ▶ | else if(last_table->parent) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1946 | { | ||||||||||||||||||
| 1947 | //adjusted_location = last_table->parent; | ||||||||||||||||||
| 1948 | |||||||||||||||||||
| 1949 | 0 | ▶ | if(last_table->prev) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 1950 | 0 | adjusted_location = last_table->prev; | |||||||||||||||||
| 1951 | 0 | *mode = MyHTML_TREE_INSERTION_MODE_AFTER; | |||||||||||||||||
| 1952 | } | ||||||||||||||||||
| 1953 | else { | ||||||||||||||||||
| 1954 | 0 | adjusted_location = last_table; | |||||||||||||||||
| 1955 | 0 | *mode = MyHTML_TREE_INSERTION_MODE_BEFORE; | |||||||||||||||||
| 1956 | } | ||||||||||||||||||
| 1957 | |||||||||||||||||||
| 1958 | 0 | break; | |||||||||||||||||
| 1959 | } | ||||||||||||||||||
| 1960 | |||||||||||||||||||
| 1961 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1962 | if(idx_table == 0) { | ||||||||||||||||||
| 1963 | MyCORE_DEBUG_ERROR("Appropriate place inserting; Step 2.5; idx_table is 0"); | ||||||||||||||||||
| 1964 | } | ||||||||||||||||||
| 1965 | #endif | ||||||||||||||||||
| 1966 | |||||||||||||||||||
| 1967 | // step 2.6-7 | ||||||||||||||||||
| 1968 | 0 | adjusted_location = tree->open_elements->list[idx_table - 1]; | |||||||||||||||||
| 1969 | |||||||||||||||||||
| 1970 | 0 | break; | |||||||||||||||||
| 1971 | } | ||||||||||||||||||
| 1972 | |||||||||||||||||||
| 1973 | 0 | default: | |||||||||||||||||
| 1974 | 0 | adjusted_location = target; | |||||||||||||||||
| 1975 | 0 | break; | |||||||||||||||||
| 1976 | } | ||||||||||||||||||
| 1977 | } | ||||||||||||||||||
| 1978 | else { | ||||||||||||||||||
| 1979 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 1980 | if(target == NULL) { | ||||||||||||||||||
| 1981 | MyCORE_DEBUG_ERROR("Appropriate place inserting; Step 3-5; target is NULL in return value! This IS very bad"); | ||||||||||||||||||
| 1982 | } | ||||||||||||||||||
| 1983 | #endif | ||||||||||||||||||
| 1984 | |||||||||||||||||||
| 1985 | // step 3-4 | ||||||||||||||||||
| 1986 | 0 | return target; | |||||||||||||||||
| 1987 | } | ||||||||||||||||||
| 1988 | |||||||||||||||||||
| 1989 | // step 3-4 | ||||||||||||||||||
| 1990 | 0 | return adjusted_location; | |||||||||||||||||
| 1991 | } | ||||||||||||||||||
| 1992 | |||||||||||||||||||
| 1993 | 0 | myhtml_tree_node_t * myhtml_tree_appropriate_place_inserting_in_tree(myhtml_tree_node_t* target, enum myhtml_tree_insertion_mode* mode) | |||||||||||||||||
| 1994 | { | ||||||||||||||||||
| 1995 | 0 | *mode = MyHTML_TREE_INSERTION_MODE_BEFORE; | |||||||||||||||||
| 1996 | |||||||||||||||||||
| 1997 | // step 2 | ||||||||||||||||||
| 1998 | myhtml_tree_node_t* adjusted_location; | ||||||||||||||||||
| 1999 | |||||||||||||||||||
| 2000 | 0 | ▶ | if(target->tree->foster_parenting) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2001 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 2002 | if(target == NULL) { | ||||||||||||||||||
| 2003 | MyCORE_DEBUG_ERROR("Appropriate place inserting; Step 2; target is NULL in return value! This IS very bad"); | ||||||||||||||||||
| 2004 | } | ||||||||||||||||||
| 2005 | #endif | ||||||||||||||||||
| 2006 | |||||||||||||||||||
| 2007 | 0 | ▶ | if(target->ns != MyHTML_NAMESPACE_HTML) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2008 | 0 | return target; | |||||||||||||||||
| 2009 | |||||||||||||||||||
| 2010 | 0 | ▶ | switch (target->tag_id) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2011 | 0 | case MyHTML_TAG_TABLE: | |||||||||||||||||
| 2012 | case MyHTML_TAG_TBODY: | ||||||||||||||||||
| 2013 | case MyHTML_TAG_TFOOT: | ||||||||||||||||||
| 2014 | case MyHTML_TAG_THEAD: | ||||||||||||||||||
| 2015 | case MyHTML_TAG_TR: | ||||||||||||||||||
| 2016 | { | ||||||||||||||||||
| 2017 | // step 2.1-2 | ||||||||||||||||||
| 2018 | 0 | myhtml_tree_node_t* last_template = myhtml_tree_node_find_parent_by_tag_id(target, MyHTML_TAG_TEMPLATE); | |||||||||||||||||
| 2019 | 0 | myhtml_tree_node_t* last_table = myhtml_tree_node_find_parent_by_tag_id(target, MyHTML_TAG_TABLE); | |||||||||||||||||
| 2020 | 0 | myhtml_tree_node_t* last_table_in_template = NULL; | |||||||||||||||||
| 2021 | |||||||||||||||||||
| 2022 | 0 | ▶ | if(last_template) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2023 | 0 | last_table_in_template = myhtml_tree_node_find_parent_by_tag_id(last_template, MyHTML_TAG_TABLE); | |||||||||||||||||
| 2024 | } | ||||||||||||||||||
| 2025 | |||||||||||||||||||
| 2026 | // step 2.3 | ||||||||||||||||||
| 2027 | 0 | ▶ | if(last_template && (last_table == NULL || last_table != last_table_in_template)) | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 2028 | { | ||||||||||||||||||
| 2029 | 0 | *mode = MyHTML_TREE_INSERTION_MODE_DEFAULT; | |||||||||||||||||
| 2030 | 0 | adjusted_location = last_template; | |||||||||||||||||
| 2031 | 0 | break; | |||||||||||||||||
| 2032 | } | ||||||||||||||||||
| 2033 | |||||||||||||||||||
| 2034 | // step 2.4 | ||||||||||||||||||
| 2035 | 0 | ▶ | else if(last_table == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2036 | { | ||||||||||||||||||
| 2037 | 0 | adjusted_location = target; | |||||||||||||||||
| 2038 | 0 | break; | |||||||||||||||||
| 2039 | } | ||||||||||||||||||
| 2040 | |||||||||||||||||||
| 2041 | // step 2.5 | ||||||||||||||||||
| 2042 | 0 | ▶ | else if(last_table->parent) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2043 | { | ||||||||||||||||||
| 2044 | //adjusted_location = last_table->parent; | ||||||||||||||||||
| 2045 | |||||||||||||||||||
| 2046 | 0 | ▶ | if(last_table->prev) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2047 | 0 | adjusted_location = last_table->prev; | |||||||||||||||||
| 2048 | 0 | *mode = MyHTML_TREE_INSERTION_MODE_AFTER; | |||||||||||||||||
| 2049 | } | ||||||||||||||||||
| 2050 | else { | ||||||||||||||||||
| 2051 | 0 | adjusted_location = last_table; | |||||||||||||||||
| 2052 | } | ||||||||||||||||||
| 2053 | |||||||||||||||||||
| 2054 | 0 | break; | |||||||||||||||||
| 2055 | } | ||||||||||||||||||
| 2056 | |||||||||||||||||||
| 2057 | // step 2.6-7 | ||||||||||||||||||
| 2058 | 0 | adjusted_location = target; | |||||||||||||||||
| 2059 | |||||||||||||||||||
| 2060 | 0 | break; | |||||||||||||||||
| 2061 | } | ||||||||||||||||||
| 2062 | |||||||||||||||||||
| 2063 | 0 | default: | |||||||||||||||||
| 2064 | 0 | *mode = MyHTML_TREE_INSERTION_MODE_DEFAULT; | |||||||||||||||||
| 2065 | 0 | adjusted_location = target; | |||||||||||||||||
| 2066 | 0 | break; | |||||||||||||||||
| 2067 | } | ||||||||||||||||||
| 2068 | } | ||||||||||||||||||
| 2069 | else { | ||||||||||||||||||
| 2070 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 2071 | if(target == NULL) { | ||||||||||||||||||
| 2072 | MyCORE_DEBUG_ERROR("Appropriate place inserting; Step 3-5; target is NULL in return value! This IS very bad"); | ||||||||||||||||||
| 2073 | } | ||||||||||||||||||
| 2074 | #endif | ||||||||||||||||||
| 2075 | |||||||||||||||||||
| 2076 | 0 | *mode = MyHTML_TREE_INSERTION_MODE_DEFAULT; | |||||||||||||||||
| 2077 | // step 3-4 | ||||||||||||||||||
| 2078 | 0 | return target; | |||||||||||||||||
| 2079 | } | ||||||||||||||||||
| 2080 | |||||||||||||||||||
| 2081 | // step 3-4 | ||||||||||||||||||
| 2082 | 0 | return adjusted_location; | |||||||||||||||||
| 2083 | } | ||||||||||||||||||
| 2084 | |||||||||||||||||||
| 2085 | |||||||||||||||||||
| 2086 | // stack of template insertion modes | ||||||||||||||||||
| 2087 | 0 | myhtml_tree_insertion_list_t * myhtml_tree_template_insertion_init(myhtml_tree_t* tree) | |||||||||||||||||
| 2088 | { | ||||||||||||||||||
| 2089 | 0 | myhtml_tree_insertion_list_t* list = mycore_malloc(sizeof(myhtml_tree_insertion_list_t)); | |||||||||||||||||
| 2090 | |||||||||||||||||||
| 2091 | 0 | list->length = 0; | |||||||||||||||||
| 2092 | 0 | list->size = 1024; | |||||||||||||||||
| 2093 | 0 | list->list = (enum myhtml_insertion_mode*)mycore_malloc(sizeof(enum myhtml_insertion_mode) * list->size); | |||||||||||||||||
| 2094 | |||||||||||||||||||
| 2095 | 0 | tree->template_insertion = list; | |||||||||||||||||
| 2096 | |||||||||||||||||||
| 2097 | 0 | return list; | |||||||||||||||||
| 2098 | } | ||||||||||||||||||
| 2099 | |||||||||||||||||||
| 2100 | 0 | void myhtml_tree_template_insertion_clean(myhtml_tree_t* tree) | |||||||||||||||||
| 2101 | { | ||||||||||||||||||
| 2102 | 0 | tree->template_insertion->length = 0; | |||||||||||||||||
| 2103 | 0 | } | |||||||||||||||||
| 2104 | |||||||||||||||||||
| 2105 | 0 | myhtml_tree_insertion_list_t * myhtml_tree_template_insertion_destroy(myhtml_tree_t* tree) | |||||||||||||||||
| 2106 | { | ||||||||||||||||||
| 2107 | 0 | ▶ | if(tree->template_insertion == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2108 | 0 | return NULL; | |||||||||||||||||
| 2109 | |||||||||||||||||||
| 2110 | 0 | ▶ | if(tree->template_insertion->list) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2111 | 0 | mycore_free(tree->template_insertion->list); | |||||||||||||||||
| 2112 | |||||||||||||||||||
| 2113 | 0 | ▶ | if(tree->template_insertion) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2114 | 0 | mycore_free(tree->template_insertion); | |||||||||||||||||
| 2115 | |||||||||||||||||||
| 2116 | 0 | return NULL; | |||||||||||||||||
| 2117 | } | ||||||||||||||||||
| 2118 | |||||||||||||||||||
| 2119 | 0 | void myhtml_tree_template_insertion_append(myhtml_tree_t* tree, enum myhtml_insertion_mode insert_mode) | |||||||||||||||||
| 2120 | { | ||||||||||||||||||
| 2121 | 0 | myhtml_tree_insertion_list_t* list = tree->template_insertion; | |||||||||||||||||
| 2122 | |||||||||||||||||||
| 2123 | 0 | ▶ | if(list->length >= list->size) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2124 | 0 | list->size <<= 1; | |||||||||||||||||
| 2125 | |||||||||||||||||||
| 2126 | 0 | enum myhtml_insertion_mode* tmp = (enum myhtml_insertion_mode*)mycore_realloc(list->list, | |||||||||||||||||
| 2127 | 0 | sizeof(enum myhtml_insertion_mode) * list->size); | |||||||||||||||||
| 2128 | |||||||||||||||||||
| 2129 | 0 | ▶ | if(tmp) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2130 | 0 | list->list = tmp; | |||||||||||||||||
| 2131 | } | ||||||||||||||||||
| 2132 | |||||||||||||||||||
| 2133 | 0 | list->list[list->length] = insert_mode; | |||||||||||||||||
| 2134 | 0 | list->length++; | |||||||||||||||||
| 2135 | 0 | } | |||||||||||||||||
| 2136 | |||||||||||||||||||
| 2137 | 0 | void myhtml_tree_template_insertion_pop(myhtml_tree_t* tree) | |||||||||||||||||
| 2138 | { | ||||||||||||||||||
| 2139 | 0 | ▶ | if(tree->template_insertion->length) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2140 | 0 | tree->template_insertion->length--; | |||||||||||||||||
| 2141 | |||||||||||||||||||
| 2142 | #ifdef MyCORE_BUILD_DEBUG | ||||||||||||||||||
| 2143 | if(tree->template_insertion->length == 0) { | ||||||||||||||||||
| 2144 | MyCORE_DEBUG("Pop template insertion; length is 0"); | ||||||||||||||||||
| 2145 | } | ||||||||||||||||||
| 2146 | #endif | ||||||||||||||||||
| 2147 | 0 | } | |||||||||||||||||
| 2148 | |||||||||||||||||||
| 2149 | 0 | size_t myhtml_tree_template_insertion_length(myhtml_tree_t* tree) | |||||||||||||||||
| 2150 | { | ||||||||||||||||||
| 2151 | 0 | return tree->template_insertion->length; | |||||||||||||||||
| 2152 | } | ||||||||||||||||||
| 2153 | |||||||||||||||||||
| 2154 | // token list | ||||||||||||||||||
| 2155 | 0 | myhtml_tree_token_list_t * myhtml_tree_token_list_init(void) | |||||||||||||||||
| 2156 | { | ||||||||||||||||||
| 2157 | 0 | myhtml_tree_token_list_t* list = mycore_malloc(sizeof(myhtml_tree_token_list_t)); | |||||||||||||||||
| 2158 | |||||||||||||||||||
| 2159 | 0 | list->length = 0; | |||||||||||||||||
| 2160 | 0 | list->size = 4096; | |||||||||||||||||
| 2161 | 0 | list->list = (myhtml_token_node_t**)mycore_malloc(sizeof(myhtml_token_node_t*) * list->size); | |||||||||||||||||
| 2162 | |||||||||||||||||||
| 2163 | 0 | return list; | |||||||||||||||||
| 2164 | } | ||||||||||||||||||
| 2165 | |||||||||||||||||||
| 2166 | 0 | void myhtml_tree_token_list_clean(myhtml_tree_token_list_t* list) | |||||||||||||||||
| 2167 | { | ||||||||||||||||||
| 2168 | 0 | list->length = 0; | |||||||||||||||||
| 2169 | 0 | } | |||||||||||||||||
| 2170 | |||||||||||||||||||
| 2171 | 0 | myhtml_tree_token_list_t * myhtml_tree_token_list_destroy(myhtml_tree_token_list_t* list, bool destroy_self) | |||||||||||||||||
| 2172 | { | ||||||||||||||||||
| 2173 | 0 | ▶ | if(list == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2174 | 0 | return NULL; | |||||||||||||||||
| 2175 | |||||||||||||||||||
| 2176 | 0 | ▶ | if(list->list) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2177 | 0 | mycore_free(list->list); | |||||||||||||||||
| 2178 | |||||||||||||||||||
| 2179 | 0 | ▶ | if(destroy_self && list) { | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 2180 | 0 | mycore_free(list); | |||||||||||||||||
| 2181 | 0 | return NULL; | |||||||||||||||||
| 2182 | } | ||||||||||||||||||
| 2183 | |||||||||||||||||||
| 2184 | 0 | return list; | |||||||||||||||||
| 2185 | } | ||||||||||||||||||
| 2186 | |||||||||||||||||||
| 2187 | 0 | void myhtml_tree_token_list_append(myhtml_tree_token_list_t* list, myhtml_token_node_t* token) | |||||||||||||||||
| 2188 | { | ||||||||||||||||||
| 2189 | 0 | ▶ | if(list->length >= list->size) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2190 | 0 | list->size <<= 1; | |||||||||||||||||
| 2191 | |||||||||||||||||||
| 2192 | 0 | myhtml_token_node_t** tmp = (myhtml_token_node_t**)mycore_realloc(list->list, sizeof(myhtml_token_node_t*) * list->size); | |||||||||||||||||
| 2193 | |||||||||||||||||||
| 2194 | 0 | ▶ | if(tmp) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2195 | 0 | list->list = tmp; | |||||||||||||||||
| 2196 | } | ||||||||||||||||||
| 2197 | |||||||||||||||||||
| 2198 | 0 | list->list[list->length] = token; | |||||||||||||||||
| 2199 | 0 | list->length++; | |||||||||||||||||
| 2200 | 0 | } | |||||||||||||||||
| 2201 | |||||||||||||||||||
| 2202 | 0 | void myhtml_tree_token_list_append_after_index(myhtml_tree_token_list_t* list, myhtml_token_node_t* token, size_t index) | |||||||||||||||||
| 2203 | { | ||||||||||||||||||
| 2204 | 0 | ▶ | if(list->length >= list->size) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2205 | 0 | list->size <<= 1; | |||||||||||||||||
| 2206 | |||||||||||||||||||
| 2207 | 0 | myhtml_token_node_t** tmp = (myhtml_token_node_t**)mycore_realloc(list->list, sizeof(myhtml_token_node_t*) * list->size); | |||||||||||||||||
| 2208 | |||||||||||||||||||
| 2209 | 0 | ▶ | if(tmp) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2210 | 0 | list->list = tmp; | |||||||||||||||||
| 2211 | } | ||||||||||||||||||
| 2212 | |||||||||||||||||||
| 2213 | 0 | myhtml_token_node_t** node_list = list->list; | |||||||||||||||||
| 2214 | 0 | size_t el_idx = index; | |||||||||||||||||
| 2215 | |||||||||||||||||||
| 2216 | 0 | ▶ | while(el_idx > list->length) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2217 | 0 | node_list[(el_idx + 1)] = node_list[el_idx]; | |||||||||||||||||
| 2218 | 0 | el_idx++; | |||||||||||||||||
| 2219 | } | ||||||||||||||||||
| 2220 | |||||||||||||||||||
| 2221 | 0 | list->list[(index + 1)] = token; | |||||||||||||||||
| 2222 | 0 | list->length++; | |||||||||||||||||
| 2223 | 0 | } | |||||||||||||||||
| 2224 | |||||||||||||||||||
| 2225 | 0 | myhtml_token_node_t * myhtml_tree_token_list_current_node(myhtml_tree_token_list_t* list) | |||||||||||||||||
| 2226 | { | ||||||||||||||||||
| 2227 | 0 | ▶ | if(list->length == 0) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2228 | MyCORE_DEBUG("Token list current node; length is 0"); | ||||||||||||||||||
| 2229 | 0 | return NULL; | |||||||||||||||||
| 2230 | } | ||||||||||||||||||
| 2231 | |||||||||||||||||||
| 2232 | 0 | return list->list[ list->length - 1 ]; | |||||||||||||||||
| 2233 | } | ||||||||||||||||||
| 2234 | |||||||||||||||||||
| 2235 | // other | ||||||||||||||||||
| 2236 | 0 | void myhtml_tree_tags_close_p(myhtml_tree_t* tree, myhtml_token_node_t* token) | |||||||||||||||||
| 2237 | { | ||||||||||||||||||
| 2238 | 0 | myhtml_tree_generate_implied_end_tags(tree, MyHTML_TAG_P, MyHTML_NAMESPACE_HTML); | |||||||||||||||||
| 2239 | |||||||||||||||||||
| 2240 | 0 | myhtml_tree_node_t* current_node = myhtml_tree_current_node(tree); | |||||||||||||||||
| 2241 | 0 | if(myhtml_is_html_node(current_node, MyHTML_TAG_P) == false) { | |||||||||||||||||
| 2242 | // parse error | ||||||||||||||||||
| 2243 | /* %EXTERNAL% VALIDATOR:RULES HAVE_NEED STATUS:ELEMENT_NO_EXPECTED LEVEL:ERROR */ | ||||||||||||||||||
| 2244 | /* %EXTERNAL% VALIDATOR:RULES HAVE_NEED_ADD HAVE:current_node->token NEED:NULL HAVE_TAG_ID:current_node->tag_id HAVE_NS:current_node->ns NEED_TAG_ID:MyHTML_TAG_P NEED_NS:MyHTML_NAMESPACE_HTML */ | ||||||||||||||||||
| 2245 | } | ||||||||||||||||||
| 2246 | |||||||||||||||||||
| 2247 | 0 | myhtml_tree_open_elements_pop_until(tree, MyHTML_TAG_P, MyHTML_NAMESPACE_HTML, false); | |||||||||||||||||
| 2248 | 0 | } | |||||||||||||||||
| 2249 | |||||||||||||||||||
| 2250 | 0 | myhtml_tree_node_t * myhtml_tree_generic_raw_text_element_parsing_algorithm(myhtml_tree_t* tree, myhtml_token_node_t* token_node) | |||||||||||||||||
| 2251 | { | ||||||||||||||||||
| 2252 | 0 | myhtml_tree_node_t* node = myhtml_tree_node_insert_by_token(tree, token_node, MyHTML_NAMESPACE_HTML); | |||||||||||||||||
| 2253 | |||||||||||||||||||
| 2254 | 0 | tree->orig_insert_mode = tree->insert_mode; | |||||||||||||||||
| 2255 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_TEXT; | |||||||||||||||||
| 2256 | |||||||||||||||||||
| 2257 | 0 | return node; | |||||||||||||||||
| 2258 | } | ||||||||||||||||||
| 2259 | |||||||||||||||||||
| 2260 | 0 | void myhtml_tree_clear_stack_back_table_context(myhtml_tree_t* tree) | |||||||||||||||||
| 2261 | { | ||||||||||||||||||
| 2262 | 0 | myhtml_tree_node_t* current_node = myhtml_tree_current_node(tree); | |||||||||||||||||
| 2263 | |||||||||||||||||||
| 2264 | 0 | ▶ | while(!((current_node->tag_id == MyHTML_TAG_TABLE || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2265 | 0 | ▶ | current_node->tag_id == MyHTML_TAG_TEMPLATE || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2266 | 0 | ▶ | current_node->tag_id == MyHTML_TAG_HTML) && | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2267 | 0 | ▶ | current_node->ns == MyHTML_NAMESPACE_HTML)) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2268 | { | ||||||||||||||||||
| 2269 | 0 | myhtml_tree_open_elements_pop(tree); | |||||||||||||||||
| 2270 | 0 | current_node = myhtml_tree_current_node(tree); | |||||||||||||||||
| 2271 | } | ||||||||||||||||||
| 2272 | 0 | } | |||||||||||||||||
| 2273 | |||||||||||||||||||
| 2274 | 0 | void myhtml_tree_clear_stack_back_table_body_context(myhtml_tree_t* tree) | |||||||||||||||||
| 2275 | { | ||||||||||||||||||
| 2276 | 0 | myhtml_tree_node_t* current_node = myhtml_tree_current_node(tree); | |||||||||||||||||
| 2277 | |||||||||||||||||||
| 2278 | 0 | ▶ | while(!((current_node->tag_id == MyHTML_TAG_TBODY || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2279 | 0 | ▶ | current_node->tag_id == MyHTML_TAG_TFOOT || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2280 | 0 | ▶ | current_node->tag_id == MyHTML_TAG_THEAD || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2281 | 0 | ▶ | current_node->tag_id == MyHTML_TAG_TEMPLATE || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2282 | 0 | ▶ | current_node->tag_id == MyHTML_TAG_HTML) && | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2283 | 0 | ▶ | current_node->ns == MyHTML_NAMESPACE_HTML)) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2284 | { | ||||||||||||||||||
| 2285 | 0 | myhtml_tree_open_elements_pop(tree); | |||||||||||||||||
| 2286 | 0 | current_node = myhtml_tree_current_node(tree); | |||||||||||||||||
| 2287 | } | ||||||||||||||||||
| 2288 | 0 | } | |||||||||||||||||
| 2289 | |||||||||||||||||||
| 2290 | 0 | void myhtml_tree_clear_stack_back_table_row_context(myhtml_tree_t* tree) | |||||||||||||||||
| 2291 | { | ||||||||||||||||||
| 2292 | 0 | myhtml_tree_node_t* current_node = myhtml_tree_current_node(tree); | |||||||||||||||||
| 2293 | |||||||||||||||||||
| 2294 | 0 | ▶ | while(!((current_node->tag_id == MyHTML_TAG_TR || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2295 | 0 | ▶ | current_node->tag_id == MyHTML_TAG_TEMPLATE || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2296 | 0 | ▶ | current_node->tag_id == MyHTML_TAG_HTML) && | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2297 | 0 | ▶ | current_node->ns == MyHTML_NAMESPACE_HTML)) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2298 | { | ||||||||||||||||||
| 2299 | 0 | myhtml_tree_open_elements_pop(tree); | |||||||||||||||||
| 2300 | 0 | current_node = myhtml_tree_current_node(tree); | |||||||||||||||||
| 2301 | } | ||||||||||||||||||
| 2302 | 0 | } | |||||||||||||||||
| 2303 | |||||||||||||||||||
| 2304 | 0 | void myhtml_tree_close_cell(myhtml_tree_t* tree, myhtml_tree_node_t* tr_or_th_node, myhtml_token_node_t* token) | |||||||||||||||||
| 2305 | { | ||||||||||||||||||
| 2306 | // step 1 | ||||||||||||||||||
| 2307 | 0 | myhtml_tree_generate_implied_end_tags(tree, 0, MyHTML_NAMESPACE_UNDEF); | |||||||||||||||||
| 2308 | |||||||||||||||||||
| 2309 | // step 2 | ||||||||||||||||||
| 2310 | 0 | myhtml_tree_node_t* current_node = myhtml_tree_current_node(tree); | |||||||||||||||||
| 2311 | 0 | ▶ | if(!((current_node->tag_id == MyHTML_TAG_TD || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2312 | 0 | current_node->tag_id == MyHTML_TAG_TH) && | |||||||||||||||||
| 2313 | current_node->ns == MyHTML_NAMESPACE_HTML)) | ||||||||||||||||||
| 2314 | { | ||||||||||||||||||
| 2315 | // parse error | ||||||||||||||||||
| 2316 | /* %EXTERNAL% VALIDATOR:RULES HAVE_NEED STATUS:ELEMENT_OPEN_NOT_FOUND LEVEL:ERROR */ | ||||||||||||||||||
| 2317 | /* %EXTERNAL% VALIDATOR:RULES HAVE_NEED_ADD HAVE:NULL NEED:NULL HAVE_TAG_ID:MyHTML_TAG__UNDEF HAVE_NS:MyHTML_NAMESPACE_UNDEF NEED_TAG_ID:MyHTML_TAG_TD NEED_NS:MyHTML_NAMESPACE_HTML */ | ||||||||||||||||||
| 2318 | /* %EXTERNAL% VALIDATOR:RULES HAVE_NEED_ADD HAVE:NULL NEED:NULL HAVE_TAG_ID:MyHTML_TAG__UNDEF HAVE_NS:MyHTML_NAMESPACE_UNDEF NEED_TAG_ID:MyHTML_TAG_TH NEED_NS:MyHTML_NAMESPACE_HTML */ | ||||||||||||||||||
| 2319 | } | ||||||||||||||||||
| 2320 | |||||||||||||||||||
| 2321 | // step 3 | ||||||||||||||||||
| 2322 | 0 | myhtml_tree_open_elements_pop_until(tree, tr_or_th_node->tag_id, tr_or_th_node->ns, false); | |||||||||||||||||
| 2323 | |||||||||||||||||||
| 2324 | // step 4 | ||||||||||||||||||
| 2325 | 0 | myhtml_tree_active_formatting_up_to_last_marker(tree); | |||||||||||||||||
| 2326 | |||||||||||||||||||
| 2327 | // step 5 | ||||||||||||||||||
| 2328 | 0 | tree->insert_mode = MyHTML_INSERTION_MODE_IN_ROW; | |||||||||||||||||
| 2329 | 0 | } | |||||||||||||||||
| 2330 | |||||||||||||||||||
| 2331 | 0 | bool myhtml_tree_is_mathml_integration_point(myhtml_tree_t* tree, myhtml_tree_node_t* node) | |||||||||||||||||
| 2332 | { | ||||||||||||||||||
| 2333 | 0 | ▶ | if(node->ns == MyHTML_NAMESPACE_MATHML && | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2334 | 0 | ▶ | (node->tag_id == MyHTML_TAG_MI || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2335 | 0 | ▶ | node->tag_id == MyHTML_TAG_MO || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2336 | 0 | ▶ | node->tag_id == MyHTML_TAG_MN || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2337 | 0 | ▶ | node->tag_id == MyHTML_TAG_MS || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2338 | 0 | ▶ | node->tag_id == MyHTML_TAG_MTEXT) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2339 | ) | ||||||||||||||||||
| 2340 | 0 | return true; | |||||||||||||||||
| 2341 | |||||||||||||||||||
| 2342 | 0 | return false; | |||||||||||||||||
| 2343 | } | ||||||||||||||||||
| 2344 | |||||||||||||||||||
| 2345 | 0 | bool myhtml_tree_is_html_integration_point(myhtml_tree_t* tree, myhtml_tree_node_t* node) | |||||||||||||||||
| 2346 | { | ||||||||||||||||||
| 2347 | 0 | ▶ | if(node->ns == MyHTML_NAMESPACE_SVG && | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2348 | 0 | ▶ | (node->tag_id == MyHTML_TAG_FOREIGNOBJECT || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2349 | 0 | ▶ | node->tag_id == MyHTML_TAG_DESC || | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2350 | 0 | ▶ | node->tag_id == MyHTML_TAG_TITLE) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2351 | ) | ||||||||||||||||||
| 2352 | 0 | return true; | |||||||||||||||||
| 2353 | |||||||||||||||||||
| 2354 | 0 | ▶ | if(node->ns == MyHTML_NAMESPACE_MATHML && | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2355 | 0 | ▶ | node->tag_id == MyHTML_TAG_ANNOTATION_XML && node->token && | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 2356 | 0 | ▶ | (node->token->type & MyHTML_TOKEN_TYPE_CLOSE) == 0) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2357 | { | ||||||||||||||||||
| 2358 | 0 | myhtml_token_node_wait_for_done(tree->token, node->token); | |||||||||||||||||
| 2359 | |||||||||||||||||||
| 2360 | 0 | myhtml_token_attr_t* attr = myhtml_token_attr_match_case(tree->token, node->token, | |||||||||||||||||
| 2361 | "encoding", 8, "text/html", 9); | ||||||||||||||||||
| 2362 | 0 | ▶ | if(attr) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2363 | 0 | return true; | |||||||||||||||||
| 2364 | |||||||||||||||||||
| 2365 | 0 | attr = myhtml_token_attr_match_case(tree->token, node->token, | |||||||||||||||||
| 2366 | "encoding", 8, "application/xhtml+xml", 21); | ||||||||||||||||||
| 2367 | 0 | ▶ | if(attr) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2368 | 0 | return true; | |||||||||||||||||
| 2369 | } | ||||||||||||||||||
| 2370 | |||||||||||||||||||
| 2371 | 0 | return false; | |||||||||||||||||
| 2372 | } | ||||||||||||||||||
| 2373 | |||||||||||||||||||
| 2374 | // temp tag name | ||||||||||||||||||
| 2375 | 0 | mystatus_t myhtml_tree_temp_tag_name_init(myhtml_tree_temp_tag_name_t* temp_tag_name) | |||||||||||||||||
| 2376 | { | ||||||||||||||||||
| 2377 | 0 | temp_tag_name->size = 1024; | |||||||||||||||||
| 2378 | 0 | temp_tag_name->length = 0; | |||||||||||||||||
| 2379 | 0 | temp_tag_name->data = (char *)mycore_malloc(temp_tag_name->size * sizeof(char)); | |||||||||||||||||
| 2380 | |||||||||||||||||||
| 2381 | 0 | ▶ | if(temp_tag_name->data == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2382 | 0 | return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION; | |||||||||||||||||
| 2383 | |||||||||||||||||||
| 2384 | 0 | return MyHTML_STATUS_OK; | |||||||||||||||||
| 2385 | } | ||||||||||||||||||
| 2386 | |||||||||||||||||||
| 2387 | 0 | void myhtml_tree_temp_tag_name_clean(myhtml_tree_temp_tag_name_t* temp_tag_name) | |||||||||||||||||
| 2388 | { | ||||||||||||||||||
| 2389 | 0 | temp_tag_name->length = 0; | |||||||||||||||||
| 2390 | 0 | } | |||||||||||||||||
| 2391 | |||||||||||||||||||
| 2392 | 0 | myhtml_tree_temp_tag_name_t * myhtml_tree_temp_tag_name_destroy(myhtml_tree_temp_tag_name_t* temp_tag_name, bool self_destroy) | |||||||||||||||||
| 2393 | { | ||||||||||||||||||
| 2394 | 0 | ▶ | if(temp_tag_name == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2395 | 0 | return NULL; | |||||||||||||||||
| 2396 | |||||||||||||||||||
| 2397 | 0 | ▶ | if(temp_tag_name->data) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2398 | 0 | mycore_free(temp_tag_name->data); | |||||||||||||||||
| 2399 | 0 | temp_tag_name->data = NULL; | |||||||||||||||||
| 2400 | } | ||||||||||||||||||
| 2401 | |||||||||||||||||||
| 2402 | 0 | ▶ | if(self_destroy) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2403 | 0 | mycore_free(temp_tag_name); | |||||||||||||||||
| 2404 | 0 | return NULL; | |||||||||||||||||
| 2405 | } | ||||||||||||||||||
| 2406 | |||||||||||||||||||
| 2407 | 0 | return temp_tag_name; | |||||||||||||||||
| 2408 | } | ||||||||||||||||||
| 2409 | |||||||||||||||||||
| 2410 | 0 | mystatus_t myhtml_tree_temp_tag_name_append_one(myhtml_tree_temp_tag_name_t* temp_tag_name, const char name) | |||||||||||||||||
| 2411 | { | ||||||||||||||||||
| 2412 | 0 | ▶ | if(temp_tag_name->length >= temp_tag_name->size) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2413 | 0 | size_t nsize = temp_tag_name->size << 1; | |||||||||||||||||
| 2414 | 0 | char *tmp = (char *)mycore_realloc(temp_tag_name->data, nsize * sizeof(char)); | |||||||||||||||||
| 2415 | |||||||||||||||||||
| 2416 | 0 | ▶ | if(tmp) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2417 | 0 | temp_tag_name->size = nsize; | |||||||||||||||||
| 2418 | 0 | temp_tag_name->data = tmp; | |||||||||||||||||
| 2419 | } | ||||||||||||||||||
| 2420 | else | ||||||||||||||||||
| 2421 | 0 | return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION; | |||||||||||||||||
| 2422 | } | ||||||||||||||||||
| 2423 | |||||||||||||||||||
| 2424 | 0 | temp_tag_name->data[temp_tag_name->length] = name; | |||||||||||||||||
| 2425 | |||||||||||||||||||
| 2426 | 0 | temp_tag_name->length++; | |||||||||||||||||
| 2427 | 0 | return MyHTML_STATUS_OK; | |||||||||||||||||
| 2428 | } | ||||||||||||||||||
| 2429 | |||||||||||||||||||
| 2430 | 0 | mystatus_t myhtml_tree_temp_tag_name_append(myhtml_tree_temp_tag_name_t* temp_tag_name, const char* name, size_t name_len) | |||||||||||||||||
| 2431 | { | ||||||||||||||||||
| 2432 | 0 | ▶ | if(temp_tag_name->data == NULL || name_len == 0) | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 2433 | 0 | return MyHTML_STATUS_OK; | |||||||||||||||||
| 2434 | |||||||||||||||||||
| 2435 | 0 | ▶ | if((temp_tag_name->length + name_len) >= temp_tag_name->size) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2436 | 0 | size_t nsize = (temp_tag_name->size << 1) + name_len; | |||||||||||||||||
| 2437 | 0 | char *tmp = (char *)mycore_realloc(temp_tag_name->data, nsize * sizeof(char)); | |||||||||||||||||
| 2438 | |||||||||||||||||||
| 2439 | 0 | ▶ | if(tmp) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2440 | 0 | temp_tag_name->size = nsize; | |||||||||||||||||
| 2441 | 0 | temp_tag_name->data = tmp; | |||||||||||||||||
| 2442 | } | ||||||||||||||||||
| 2443 | else | ||||||||||||||||||
| 2444 | 0 | return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION; | |||||||||||||||||
| 2445 | } | ||||||||||||||||||
| 2446 | |||||||||||||||||||
| 2447 | 0 | memcpy(&temp_tag_name->data[temp_tag_name->length], name, name_len); | |||||||||||||||||
| 2448 | |||||||||||||||||||
| 2449 | 0 | temp_tag_name->length += name_len; | |||||||||||||||||
| 2450 | 0 | return MyHTML_STATUS_OK; | |||||||||||||||||
| 2451 | } | ||||||||||||||||||
| 2452 | |||||||||||||||||||
| 2453 | 0 | void myhtml_tree_wait_for_last_done_token(myhtml_tree_t* tree, myhtml_token_node_t* token_for_wait) | |||||||||||||||||
| 2454 | { | ||||||||||||||||||
| 2455 | #ifndef MyCORE_BUILD_WITHOUT_THREADS | ||||||||||||||||||
| 2456 | |||||||||||||||||||
| 2457 | 0 | ▶ | while(tree->token_last_done != token_for_wait) {mythread_nanosleep_sleep(tree->myhtml->thread_stream->timespec);} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2458 | |||||||||||||||||||
| 2459 | #endif | ||||||||||||||||||
| 2460 | 0 | } | |||||||||||||||||
| 2461 | |||||||||||||||||||
| 2462 | /* special tonek list */ | ||||||||||||||||||
| 2463 | 0 | mystatus_t myhtml_tree_special_list_init(myhtml_tree_special_token_list_t* special) | |||||||||||||||||
| 2464 | { | ||||||||||||||||||
| 2465 | 0 | special->size = 1024; | |||||||||||||||||
| 2466 | 0 | special->length = 0; | |||||||||||||||||
| 2467 | 0 | special->list = (myhtml_tree_special_token_t *)mycore_malloc(special->size * sizeof(myhtml_tree_special_token_t)); | |||||||||||||||||
| 2468 | |||||||||||||||||||
| 2469 | 0 | ▶ | if(special->list == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2470 | 0 | return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION; | |||||||||||||||||
| 2471 | |||||||||||||||||||
| 2472 | 0 | return MyHTML_STATUS_OK; | |||||||||||||||||
| 2473 | } | ||||||||||||||||||
| 2474 | |||||||||||||||||||
| 2475 | 0 | void myhtml_tree_special_list_clean(myhtml_tree_temp_tag_name_t* temp_tag_name) | |||||||||||||||||
| 2476 | { | ||||||||||||||||||
| 2477 | 0 | temp_tag_name->length = 0; | |||||||||||||||||
| 2478 | 0 | } | |||||||||||||||||
| 2479 | |||||||||||||||||||
| 2480 | 0 | myhtml_tree_special_token_list_t * myhtml_tree_special_list_destroy(myhtml_tree_special_token_list_t* special, bool self_destroy) | |||||||||||||||||
| 2481 | { | ||||||||||||||||||
| 2482 | 0 | ▶ | if(special == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2483 | 0 | return NULL; | |||||||||||||||||
| 2484 | |||||||||||||||||||
| 2485 | 0 | ▶ | if(special->list) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2486 | 0 | mycore_free(special->list); | |||||||||||||||||
| 2487 | 0 | special->list = NULL; | |||||||||||||||||
| 2488 | } | ||||||||||||||||||
| 2489 | |||||||||||||||||||
| 2490 | 0 | ▶ | if(self_destroy) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2491 | 0 | mycore_free(special); | |||||||||||||||||
| 2492 | 0 | return NULL; | |||||||||||||||||
| 2493 | } | ||||||||||||||||||
| 2494 | |||||||||||||||||||
| 2495 | 0 | return special; | |||||||||||||||||
| 2496 | } | ||||||||||||||||||
| 2497 | |||||||||||||||||||
| 2498 | 0 | mystatus_t myhtml_tree_special_list_append(myhtml_tree_special_token_list_t* special, myhtml_token_node_t *token, myhtml_namespace_t ns) | |||||||||||||||||
| 2499 | { | ||||||||||||||||||
| 2500 | 0 | ▶ | if(special->length >= special->size) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2501 | 0 | size_t nsize = special->size << 1; | |||||||||||||||||
| 2502 | 0 | myhtml_tree_special_token_t *tmp = (myhtml_tree_special_token_t *)mycore_realloc(special->list, nsize * sizeof(myhtml_tree_special_token_t)); | |||||||||||||||||
| 2503 | |||||||||||||||||||
| 2504 | 0 | ▶ | if(tmp) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2505 | 0 | special->size = nsize; | |||||||||||||||||
| 2506 | 0 | special->list = tmp; | |||||||||||||||||
| 2507 | } | ||||||||||||||||||
| 2508 | else | ||||||||||||||||||
| 2509 | 0 | return MyHTML_STATUS_ERROR_MEMORY_ALLOCATION; | |||||||||||||||||
| 2510 | } | ||||||||||||||||||
| 2511 | |||||||||||||||||||
| 2512 | 0 | special->list[special->length].ns = ns; | |||||||||||||||||
| 2513 | 0 | special->list[special->length].token = token; | |||||||||||||||||
| 2514 | |||||||||||||||||||
| 2515 | 0 | special->length++; | |||||||||||||||||
| 2516 | 0 | return MyHTML_STATUS_OK; | |||||||||||||||||
| 2517 | } | ||||||||||||||||||
| 2518 | |||||||||||||||||||
| 2519 | 0 | size_t myhtml_tree_special_list_length(myhtml_tree_special_token_list_t* special) | |||||||||||||||||
| 2520 | { | ||||||||||||||||||
| 2521 | 0 | return special->length; | |||||||||||||||||
| 2522 | } | ||||||||||||||||||
| 2523 | |||||||||||||||||||
| 2524 | 0 | size_t myhtml_tree_special_list_pop(myhtml_tree_special_token_list_t* special) | |||||||||||||||||
| 2525 | { | ||||||||||||||||||
| 2526 | 0 | ▶ | if(special->length) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2527 | 0 | special->length--; | |||||||||||||||||
| 2528 | |||||||||||||||||||
| 2529 | 0 | return special->length; | |||||||||||||||||
| 2530 | } | ||||||||||||||||||
| 2531 | |||||||||||||||||||
| 2532 | |||||||||||||||||||
| 2533 | 0 | myhtml_tree_special_token_t * myhtml_tree_special_list_get_last(myhtml_tree_special_token_list_t* special) | |||||||||||||||||
| 2534 | { | ||||||||||||||||||
| 2535 | 0 | ▶ | if(special->length == 0) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2536 | 0 | return NULL; | |||||||||||||||||
| 2537 | |||||||||||||||||||
| 2538 | 0 | return &special->list[special->length]; | |||||||||||||||||
| 2539 | } | ||||||||||||||||||
| 2540 | |||||||||||||||||||
| 2541 | /* incoming buffer */ | ||||||||||||||||||
| 2542 | 0 | mycore_incoming_buffer_t * myhtml_tree_incoming_buffer_first(myhtml_tree_t *tree) | |||||||||||||||||
| 2543 | { | ||||||||||||||||||
| 2544 | 0 | return tree->incoming_buf_first; | |||||||||||||||||
| 2545 | } | ||||||||||||||||||
| 2546 | |||||||||||||||||||
| 2547 | 0 | const char * myhtml_tree_incomming_buffer_make_data(myhtml_tree_t *tree, size_t begin, size_t length) | |||||||||||||||||
| 2548 | { | ||||||||||||||||||
| 2549 | 0 | mycore_incoming_buffer_t *buffer = mycore_incoming_buffer_find_by_position(tree->incoming_buf_first, begin); | |||||||||||||||||
| 2550 | 0 | size_t relative_begin = begin - buffer->offset; | |||||||||||||||||
| 2551 | |||||||||||||||||||
| 2552 | 0 | ▶ | if((relative_begin + length) <= buffer->size) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2553 | 0 | return &buffer->data[ relative_begin ]; | |||||||||||||||||
| 2554 | } | ||||||||||||||||||
| 2555 | |||||||||||||||||||
| 2556 | 0 | ▶ | if(tree->temp_tag_name.data == NULL) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2557 | 0 | myhtml_tree_temp_tag_name_init(&tree->temp_tag_name); | |||||||||||||||||
| 2558 | else | ||||||||||||||||||
| 2559 | 0 | myhtml_tree_temp_tag_name_clean(&tree->temp_tag_name); | |||||||||||||||||
| 2560 | |||||||||||||||||||
| 2561 | 0 | ▶ | while(buffer) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2562 | 0 | ▶ | if((relative_begin + length) > buffer->size) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 2563 | { | ||||||||||||||||||
| 2564 | 0 | size_t relative_end = (buffer->size - relative_begin); | |||||||||||||||||
| 2565 | 0 | length -= relative_end; | |||||||||||||||||
| 2566 | |||||||||||||||||||
| 2567 | 0 | myhtml_tree_temp_tag_name_append(&tree->temp_tag_name, &buffer->data[relative_begin], relative_end); | |||||||||||||||||
| 2568 | |||||||||||||||||||
| 2569 | 0 | relative_begin = 0; | |||||||||||||||||
| 2570 | 0 | buffer = buffer->next; | |||||||||||||||||
| 2571 | } | ||||||||||||||||||
| 2572 | else { | ||||||||||||||||||
| 2573 | 0 | myhtml_tree_temp_tag_name_append(&tree->temp_tag_name, &buffer->data[relative_begin], length); | |||||||||||||||||
| 2574 | 0 | break; | |||||||||||||||||
| 2575 | } | ||||||||||||||||||
| 2576 | } | ||||||||||||||||||
| 2577 | |||||||||||||||||||
| 2578 | 0 | return tree->temp_tag_name.data; | |||||||||||||||||
| 2579 | } | ||||||||||||||||||
| 2580 | |||||||||||||||||||
| 2581 | |||||||||||||||||||