diff options
author | lexborisov <lex.borisov@gmail.com> | 2016-11-22 15:22:59 +0300 |
---|---|---|
committer | lexborisov <lex.borisov@gmail.com> | 2016-11-22 15:22:59 +0300 |
commit | 38264d95e80c886501541d377ba791773f18d228 (patch) | |
tree | eed272f4c1d012a557ca303767f360913501a0c8 /source/modest/finder | |
parent | a7621943de14c469ec2dff56c4e3e590d2fceba7 (diff) |
Changes for finder api; modest_finder_by_selectors_list
Diffstat (limited to 'source/modest/finder')
-rw-r--r-- | source/modest/finder/finder.c | 39 | ||||
-rw-r--r-- | source/modest/finder/finder.h | 9 | ||||
-rw-r--r-- | source/modest/finder/myosi.h | 3 | ||||
-rw-r--r-- | source/modest/finder/pseudo_class.c | 2 | ||||
-rw-r--r-- | source/modest/finder/thread.c | 5 | ||||
-rw-r--r-- | source/modest/finder/type.c | 34 |
6 files changed, 57 insertions, 35 deletions
diff --git a/source/modest/finder/finder.c b/source/modest/finder/finder.c index eb5e875..e7f69d4 100644 --- a/source/modest/finder/finder.c +++ b/source/modest/finder/finder.c @@ -26,10 +26,10 @@ modest_finder_t * modest_finder_create(void) return (modest_finder_t*)myhtml_calloc(1, sizeof(modest_finder_t)); } -modest_status_t modest_finder_init(modest_finder_t* finder, myhtml_tree_t* myhtml_tree, mycss_stylesheet_t *stylesheet) +modest_status_t modest_finder_init(modest_finder_t* finder) { - finder->tree = myhtml_tree; - finder->stylesheet = stylesheet; + //finder->tree = NULL; + //finder->stylesheet = NULL; return MODEST_STATUS_OK; } @@ -52,19 +52,29 @@ modest_finder_t * modest_finder_destroy(modest_finder_t* finder, bool self_destr return finder; } -modest_finder_t * modest_finder_create_simple(myhtml_tree_t* myhtml_tree, mycss_stylesheet_t *stylesheet) +modest_finder_t * modest_finder_create_simple(void) { modest_finder_t *finder = modest_finder_create(); if(finder == NULL) return NULL; - if(modest_finder_init(finder, myhtml_tree, stylesheet) != MODEST_STATUS_OK) + if(modest_finder_init(finder) != MODEST_STATUS_OK) return modest_finder_destroy(finder, true); return finder; } +myhtml_tree_t * modest_finder_html_tree(modest_finder_t* finder) +{ + return finder->html_tree; +} + +void modest_finder_html_tree_set(modest_finder_t* finder, myhtml_tree_t* myhtml_tree) +{ + finder->html_tree = myhtml_tree; +} + void modest_finder_callback_found_with_collection(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_list_t* selector_list, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec, void* ctx) { myhtml_collection_t* collection = (myhtml_collection_t*)ctx; @@ -119,7 +129,7 @@ modest_finder_t * modest_finder_by_stylesheet(myhtml_tree_t* myhtml_tree, mycss_ if(finder == NULL) return NULL; - modest_status_t status = modest_finder_init(finder, myhtml_tree, stylesheet); + modest_status_t status = modest_finder_init(finder); if(status != MODEST_STATUS_OK) { modest_finder_destroy(finder, true); @@ -152,6 +162,8 @@ modest_finder_t * modest_finder_by_stylesheet(myhtml_tree_t* myhtml_tree, mycss_ return finder; } + finder->html_tree = myhtml_tree; + while(selector_list) { for(size_t i = 0; i < selector_list->entries_list_length; i++) { mycss_selectors_specificity_t spec = selector_list->entries_list[i].specificity; @@ -165,10 +177,11 @@ modest_finder_t * modest_finder_by_stylesheet(myhtml_tree_t* myhtml_tree, mycss_ return finder; } -modest_status_t modest_finder_by_selectors_list(modest_finder_t* finder, mycss_selectors_list_t* selector_list, - myhtml_tree_node_t* scope_node, myhtml_collection_t** collection) +modest_status_t modest_finder_by_selectors_list(modest_finder_t* finder, + myhtml_tree_t* myhtml_tree, myhtml_tree_node_t* scope_node, + mycss_selectors_list_t* selector_list, myhtml_collection_t** collection) { - if(finder == NULL || selector_list == NULL || scope_node == NULL || collection == NULL) + if(finder == NULL || myhtml_tree == NULL || selector_list == NULL || scope_node == NULL || collection == NULL) return MODEST_STATUS_ERROR; if(*collection == NULL) { @@ -179,6 +192,8 @@ modest_status_t modest_finder_by_selectors_list(modest_finder_t* finder, mycss_s return MODEST_STATUS_ERROR_MEMORY_ALLOCATION; } + finder->html_tree = myhtml_tree; + for(size_t i = 0; i < selector_list->entries_list_length; i++) { mycss_selectors_specificity_t spec = selector_list->entries_list[i].specificity; @@ -189,12 +204,6 @@ modest_status_t modest_finder_by_selectors_list(modest_finder_t* finder, mycss_s return MODEST_STATUS_OK; } -void modest_finder_begin(modest_finder_t* finder, myhtml_tree_node_t* base_node, mycss_selectors_entry_t* selector) -{ - mycss_selectors_specificity_t spec = {0,0,0}; - modest_finder_node_combinator_begin(finder, base_node, NULL, selector, &spec, NULL, NULL); -} - myhtml_tree_node_t * modest_finder_node_combinator_begin(modest_finder_t* finder, myhtml_tree_node_t* base_node, mycss_selectors_list_t* selector_list, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec, modest_finder_callback_f callback_found, void* ctx) diff --git a/source/modest/finder/finder.h b/source/modest/finder/finder.h index d73c82c..51070c7 100644 --- a/source/modest/finder/finder.h +++ b/source/modest/finder/finder.h @@ -38,12 +38,12 @@ typedef myhtml_tree_node_t * (*modest_finder_selector_combinator_f)(modest_finde /* init */ modest_finder_t * modest_finder_create(void); -modest_status_t modest_finder_init(modest_finder_t* finder, myhtml_tree_t* myhtml_tree, mycss_stylesheet_t *stylesheet); +modest_status_t modest_finder_init(modest_finder_t* finder); void modest_finder_clean(modest_finder_t* finder); modest_finder_t * modest_finder_destroy(modest_finder_t* finder, bool self_destroy); /* simple api */ -modest_finder_t * modest_finder_create_simple(myhtml_tree_t* myhtml_tree, mycss_stylesheet_t *stylesheet); +modest_finder_t * modest_finder_create_simple(void); /* callbacks */ void modest_finder_callback_found_with_collection(modest_finder_t* finder, myhtml_tree_node_t* node, @@ -57,12 +57,11 @@ void modest_finder_callback_found_with_bool(modest_finder_t* finder, myhtml_tree void modest_finder_specificity_inc(mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec); /* base api */ -void modest_finder_begin(modest_finder_t* finder, myhtml_tree_node_t* base_node, mycss_selectors_entry_t* selector); modest_finder_t * modest_finder_by_stylesheet(myhtml_tree_t* myhtml_tree, mycss_stylesheet_t *stylesheet, myhtml_collection_t** collection, myhtml_tree_node_t* base_node, mycss_selectors_list_t* selector_list); -modest_status_t modest_finder_by_selectors_list(modest_finder_t* finder, mycss_selectors_list_t* selector_list, - myhtml_tree_node_t* scope_node, myhtml_collection_t** collection); +modest_status_t modest_finder_by_selectors_list(modest_finder_t* finder, myhtml_tree_t* myhtml_tree, myhtml_tree_node_t* scope_node, + mycss_selectors_list_t* selector_list, myhtml_collection_t** collection); /* process */ myhtml_tree_node_t * modest_finder_node_combinator_begin(modest_finder_t* finder, myhtml_tree_node_t* base_node, diff --git a/source/modest/finder/myosi.h b/source/modest/finder/myosi.h index 01de865..468f1a0 100644 --- a/source/modest/finder/myosi.h +++ b/source/modest/finder/myosi.h @@ -37,8 +37,7 @@ typedef void (*modest_finder_callback_f)(modest_finder_t* finder, myhtml_tree_no typedef bool (*modest_finder_match_f)(myhtml_token_attr_t* attr, const char* key, size_t key_len, const char* value, size_t value_len, bool case_sensitive); struct modest_finder { - myhtml_tree_t* tree; - mycss_stylesheet_t* stylesheet; + myhtml_tree_t* html_tree; }; typedef struct modest_finder_thread_declaration modest_finder_thread_declaration_t; diff --git a/source/modest/finder/pseudo_class.c b/source/modest/finder/pseudo_class.c index 7d0fa1c..5dcd8e7 100644 --- a/source/modest/finder/pseudo_class.c +++ b/source/modest/finder/pseudo_class.c @@ -759,7 +759,7 @@ bool modest_finder_selector_sub_type_pseudo_class_required(modest_finder_t* find bool modest_finder_selector_sub_type_pseudo_class_root(modest_finder_t* finder, myhtml_tree_node_t* base_node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec) { - if(finder->tree->node_html == base_node) + if(finder->html_tree && finder->html_tree->node_html == base_node) return true; return false; diff --git a/source/modest/finder/thread.c b/source/modest/finder/thread.c index 100e52f..87276e5 100644 --- a/source/modest/finder/thread.c +++ b/source/modest/finder/thread.c @@ -139,6 +139,11 @@ modest_status_t modest_finder_thread_process(modest_t* modest, modest_finder_thr finder_thread->base_node = scope_node; finder_thread->selector_list = selector_list; + if(finder_thread->finder == NULL) + return MODEST_STATUS_ERROR; + + finder_thread->finder->html_tree = myhtml_tree; + mythread_resume_all(finder_thread->thread); modest_finder_thread_wait_for_all_done(finder_thread); diff --git a/source/modest/finder/type.c b/source/modest/finder/type.c index e85a3e4..ec827f2 100644 --- a/source/modest/finder/type.c +++ b/source/modest/finder/type.c @@ -39,10 +39,12 @@ bool modest_finder_selector_type_element(modest_finder_t* finder, myhtml_tree_no if(str->length == 1 && *str->data == '*') return true; - myhtml_tag_id_t tag_id = myhtml_tag_id_by_name(finder->tree, str->data, str->length); - - if(tag_id == node->tag_id) - return true; + if(finder->html_tree) { + myhtml_tag_id_t tag_id = myhtml_tag_id_by_name(finder->html_tree, str->data, str->length); + + if(tag_id == node->tag_id) + return true; + } return false; } @@ -52,10 +54,14 @@ bool modest_finder_selector_type_id(modest_finder_t* finder, myhtml_tree_node_t* if(node->token == NULL) return false; - return modest_finder_match_attribute_eq(node->token->attr_first, - "id", 2, - selector->key->data, selector->key->length, - (finder->tree->compat_mode != MyHTML_TREE_COMPAT_MODE_QUIRKS)); + if(finder->html_tree) { + return modest_finder_match_attribute_eq(node->token->attr_first, + "id", 2, + selector->key->data, selector->key->length, + (finder->html_tree->compat_mode != MyHTML_TREE_COMPAT_MODE_QUIRKS)); + } + + return false; } bool modest_finder_selector_type_class(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec) @@ -63,10 +69,14 @@ bool modest_finder_selector_type_class(modest_finder_t* finder, myhtml_tree_node if(node->token == NULL) return false; - return modest_finder_match_attribute_ws(node->token->attr_first, - "class", 5, - selector->key->data, selector->key->length, - (finder->tree->compat_mode != MyHTML_TREE_COMPAT_MODE_QUIRKS)); + if(finder->html_tree) { + return modest_finder_match_attribute_ws(node->token->attr_first, + "class", 5, + selector->key->data, selector->key->length, + (finder->html_tree->compat_mode != MyHTML_TREE_COMPAT_MODE_QUIRKS)); + } + + return false; } bool modest_finder_selector_type_attribute(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec) |