myhtml_status_t myhtml_parse_fragment_single(myhtml_tree_t* tree, myhtml_encoding_t encoding, const char* html, size_t html_size, myhtml_tag_id_t tag_id, enum myhtml_namespace my_namespace) { if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { myhtml_tree_clean(tree); mythread_queue_clean(tree->queue); mythread_clean(tree->myhtml->thread); } if(tag_id == 0) tag_id = MyHTML_TAG_DIV; if(my_namespace == 0) my_namespace = MyHTML_NAMESPACE_HTML; tree->flags |= MyHTML_TREE_FLAGS_SINGLE_MODE; myhtml_tokenizer_fragment_init(tree, tag_id, my_namespace); myhtml_encoding_set(tree, encoding); myhtml_tokenizer_begin(tree, html, html_size); myhtml_tokenizer_end(tree); return MyHTML_STATUS_OK; }
myhtml_status_t myhtml_parse_chunk(myhtml_tree_t* tree, const char* html, size_t html_size) { if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { myhtml_tree_clean(tree); mythread_queue_clean(tree->queue); mythread_clean(tree->myhtml->thread); } myhtml_tokenizer_chunk(tree, html, html_size); return MyHTML_STATUS_OK; }
myhtml_status_t myhtml_parse(myhtml_tree_t* tree, myhtml_encoding_t encoding, const char* html, size_t html_size) { if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { myhtml_tree_clean(tree); mythread_queue_clean(tree->queue); mythread_clean(tree->myhtml->thread); } myhtml_encoding_set(tree, encoding); myhtml_tokenizer_begin(tree, html, html_size); myhtml_tokenizer_end(tree); return MyHTML_STATUS_OK; }
void mythread_queue_list_entry_clean(mythread_t *mythread, mythread_queue_list_entry_t *entry) { if(entry == NULL) return; mythread_queue_clean(entry->queue); size_t idx; for (idx = mythread->pth_list_root; idx < mythread->batch_first_id; idx++) { entry->thread_param[idx].use = 0; } for (idx = mythread->batch_first_id; idx < (mythread->batch_first_id + mythread->batch_count); idx++) { entry->thread_param[idx].use = mythread->pth_list[idx].data.t_count; } }
void mythread_clean(mythread_t *mythread) { mythread->sys_last_error = 0; if(mythread->queue) mythread_queue_clean(mythread->queue); size_t idx; for (idx = mythread->pth_list_root; idx < mythread->pth_list_length; idx++) { mythread->pth_list[idx].data.use = 0; } for (idx = 0; idx < mythread->batch_count; idx++) { mythread->pth_list[( mythread->batch_first_id + idx )].data.use = idx; } }
mythread_queue_t * mythread_queue_create(size_t size, myhtml_status_t *status) { if(status) *status = MyHTML_STATUS_OK; if(size < 4096) size = 4096; mythread_queue_t* queue = (mythread_queue_t*)mymalloc(sizeof(mythread_queue_t)); if(queue == NULL) { if(status) *status = MyHTML_STATUS_THREAD_ERROR_QUEUE_MALLOC; return NULL; } queue->nodes_pos_size = 512; queue->nodes_size = size; queue->nodes = (mythread_queue_node_t**)mycalloc(queue->nodes_pos_size, sizeof(mythread_queue_node_t*)); if(queue->nodes == NULL) { free(queue); if(status) *status = MyHTML_STATUS_THREAD_ERROR_QUEUE_NODES_MALLOC; return NULL; } mythread_queue_clean(queue); queue->nodes[queue->nodes_pos] = (mythread_queue_node_t*)mymalloc(sizeof(mythread_queue_node_t) * queue->nodes_size); if(queue->nodes[queue->nodes_pos] == NULL) { free(queue->nodes); free(queue); if(status) *status = MyHTML_STATUS_THREAD_ERROR_QUEUE_NODE_MALLOC; return NULL; } return queue; }
myhtml_status_t myhtml_parse_chunk_fragment(myhtml_tree_t* tree, const char* html, size_t html_size, myhtml_tag_id_t tag_id, enum myhtml_namespace my_namespace) { if(tree->flags & MyHTML_TREE_FLAGS_PARSE_END) { myhtml_tree_clean(tree); mythread_queue_clean(tree->queue); mythread_clean(tree->myhtml->thread); } if(tag_id == 0) tag_id = MyHTML_TAG_DIV; if(my_namespace == 0) my_namespace = MyHTML_NAMESPACE_HTML; myhtml_tokenizer_fragment_init(tree, tag_id, my_namespace); myhtml_tokenizer_chunk(tree, html, html_size); return MyHTML_STATUS_OK; }
void myhtml_clean(myhtml_t* myhtml) { mythread_queue_clean(myhtml->thread->queue); mythread_clean(myhtml->thread); mcobject_async_node_all_clean(myhtml->async_incoming_buf); }