Prepared for serialization...

This commit is contained in:
frank 2018-03-24 13:13:22 +01:00
parent bfc525605c
commit aed3e3d105
30 changed files with 110 additions and 92 deletions

View File

@ -41,6 +41,7 @@ static const modest_finder_selector_type_f modest_finder_static_selector_sub_typ
{
modest_finder_selector_sub_type_pseudo_class_function_undef, /* UNDEF */
modest_finder_selector_sub_type_pseudo_class_function_undef, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_UNKNOWN */
modest_finder_selector_sub_type_pseudo_class_function_contains, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS */
modest_finder_selector_sub_type_pseudo_class_function_current, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CURRENT */
modest_finder_selector_sub_type_pseudo_class_function_dir, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_DIR */
modest_finder_selector_sub_type_pseudo_class_function_drop, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_DROP */
@ -54,7 +55,6 @@ static const modest_finder_selector_type_f modest_finder_static_selector_sub_typ
modest_finder_selector_sub_type_pseudo_class_function_nth_last_column, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_LAST_COLUMN */
modest_finder_selector_sub_type_pseudo_class_function_nth_last_of_type, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_LAST_OF_TYPE */
modest_finder_selector_sub_type_pseudo_class_function_nth_of_type /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_OF_TYPE */
modest_finder_selector_sub_type_pseudo_class_function_contains /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS */
};
/* see enum mycss_selectors_sub_type (mycss_selectors_sub_type_t) on mycss/selectors/myosi.h */

BIN
lib/libmodest-0.0.6.so Executable file

Binary file not shown.

1
lib/libmodest-0.0.so Symbolic link
View File

@ -0,0 +1 @@
libmodest-0.0.6.so

1
lib/libmodest-0.so Symbolic link
View File

@ -0,0 +1 @@
libmodest-0.0.6.so

1
lib/libmodest.so Symbolic link
View File

@ -0,0 +1 @@
libmodest-0.0.6.so

BIN
lib/libmodest_static.a Normal file

Binary file not shown.

View File

@ -162,6 +162,10 @@ mystatus_t modest_finder_by_selectors_list(modest_finder_t* finder, myhtml_tree_
return MODEST_STATUS_ERROR_MEMORY_ALLOCATION;
}
// FRANK
printf("\nmodest_finder_by_selectors_list()\n");
printf("\tselector_list->entries_list_length = %d\n", (int)selector_list->entries_list_length);
for(size_t i = 0; i < selector_list->entries_list_length; i++) {
mycss_selectors_specificity_t spec = selector_list->entries_list[i].specificity;
@ -179,19 +183,28 @@ myhtml_tree_node_t * modest_finder_node_combinator_begin(modest_finder_t* finder
if(selector == NULL)
return NULL;
myhtml_tree_node_t *node = base_node;
// FRANK
printf("\nmodest_finder_node_combinator_begin()\n\t%s\n", (node)?"has node":"no node");
while(node) {
if(node->tag_id != MyHTML_TAG__TEXT && node->tag_id != MyHTML_TAG__COMMENT &&
modest_finder_static_selector_type_map[selector->type](finder, node, selector, spec))
{
printf("\t%s\n", (selector->next != NULL)?"has next":"no next");
if(selector->next == NULL) {
printf("\t%s\n", (callback_found)?"callback_found":"no callback_found");
if(callback_found)
callback_found(finder, node, selector_list, selector, spec, ctx);
}
else {
myhtml_tree_node_t *find_node = modest_finder_static_selector_combinator_map[selector->next->combinator](finder, node, selector_list, selector->next, spec, callback_found, ctx);
printf("\tselector->next->combinator = %d\n", (int)selector->next->combinator);
myhtml_tree_node_t *find_node = modest_finder_static_selector_combinator_map[selector->next->combinator](finder, node, selector_list, selector->next, spec, callback_found, ctx);
printf("\t%s\n", (find_node)?"find_node":"no find_node");
if(find_node == NULL) {
while(node != base_node && node->next == NULL)
node = node->parent;
@ -217,7 +230,7 @@ myhtml_tree_node_t * modest_finder_node_combinator_begin(modest_finder_t* finder
node = node->next;
}
}
return NULL;
}
@ -229,6 +242,10 @@ myhtml_tree_node_t * modest_finder_node_combinator_undef(modest_finder_t* finder
if(selector == NULL)
return NULL;
// FRANK
printf("\nmodest_finder_node_combinator_undef()\n");
printf("\tselector->type = %d\n", (int)selector->type);
mycss_selectors_specificity_t match_spec = *spec;
if(base_node->tag_id != MyHTML_TAG__TEXT && base_node->tag_id != MyHTML_TAG__COMMENT &&

View File

@ -80,23 +80,25 @@ bool modest_finder_selector_sub_type_pseudo_class_function_has(modest_finder_t*
bool modest_finder_selector_sub_type_pseudo_class_function_contains(modest_finder_t* finder, myhtml_tree_node_t* base_node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
{
// FRANK
mycss_selectors_list_t *list = selector->value;
bool i_found;
// TODO: implemenet
printf("\nmodest_finder_selector_sub_type_pseudo_class_function_contains()\n");
// mycss_selectors_list_t *list = selector->value;
// bool i_found;
for(size_t i = 0; i < list->entries_list_length; i++)
{
i_found = false;
// for(size_t i = 0; i < list->entries_list_length; i++)
// {
// i_found = false;
mycss_selectors_entry_t *sel_entry = list->entries_list[i].entry;
// mycss_selectors_entry_t *sel_entry = list->entries_list[i].entry;
if(sel_entry->combinator == MyCSS_SELECTORS_COMBINATOR_UNDEF)
modest_finder_node_combinator_descendant(finder, base_node, NULL, sel_entry, spec, modest_finder_callback_found_with_bool, &i_found);
else
modest_finder_static_selector_combinator_map[sel_entry->combinator](finder, base_node, NULL, sel_entry, spec, modest_finder_callback_found_with_bool, &i_found);
// if(sel_entry->combinator == MyCSS_SELECTORS_COMBINATOR_UNDEF)
// modest_finder_node_combinator_descendant(finder, base_node, NULL, sel_entry, spec, modest_finder_callback_found_with_bool, &i_found);
// else
// modest_finder_static_selector_combinator_map[sel_entry->combinator](finder, base_node, NULL, sel_entry, spec, modest_finder_callback_found_with_bool, &i_found);
if(i_found == true)
return true;
}
// if(i_found == true)
// return true;
// }
return false;
}

View File

@ -41,6 +41,7 @@ static const modest_finder_selector_type_f modest_finder_static_selector_sub_typ
{
modest_finder_selector_sub_type_pseudo_class_function_undef, /* UNDEF */
modest_finder_selector_sub_type_pseudo_class_function_undef, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_UNKNOWN */
modest_finder_selector_sub_type_pseudo_class_function_contains, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS */
modest_finder_selector_sub_type_pseudo_class_function_current, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CURRENT */
modest_finder_selector_sub_type_pseudo_class_function_dir, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_DIR */
modest_finder_selector_sub_type_pseudo_class_function_drop, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_DROP */
@ -53,8 +54,7 @@ static const modest_finder_selector_type_f modest_finder_static_selector_sub_typ
modest_finder_selector_sub_type_pseudo_class_function_nth_last_child, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_LAST_CHILD */
modest_finder_selector_sub_type_pseudo_class_function_nth_last_column, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_LAST_COLUMN */
modest_finder_selector_sub_type_pseudo_class_function_nth_last_of_type, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_LAST_OF_TYPE */
modest_finder_selector_sub_type_pseudo_class_function_nth_of_type, /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_OF_TYPE */
modest_finder_selector_sub_type_pseudo_class_function_contains /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS */
modest_finder_selector_sub_type_pseudo_class_function_nth_of_type /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NTH_OF_TYPE */
};

View File

@ -112,6 +112,9 @@ bool modest_finder_selector_type_attribute(modest_finder_t* finder, myhtml_tree_
bool modest_finder_selector_type_pseudo_class_function(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
{
// FRANK
printf("\nmodest_finder_selector_type_pseudo_class_function()\n\tselector->sub_type = %d\n", (int)selector->sub_type);
if(selector->sub_type < MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_LAST_ENTRY)
return modest_finder_static_selector_sub_type_pseudo_class_function_map[selector->sub_type](finder, node, selector, spec);

View File

@ -112,22 +112,15 @@ void mycss_selectors_function_begin_has(mycss_entry_t* entry, mycss_selectors_en
void mycss_selectors_function_begin_contains(mycss_entry_t* entry, mycss_selectors_entry_t* selector)
{
// FRANK
selector->sub_type = MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS;
selector->value = NULL;
entry->parser = mycss_selectors_function_parser_contains;
mycss_selectors_t *selectors = entry->selectors;
mycss_selectors_list_t **new_list = (mycss_selectors_list_t**)(&selectors->entry_last->value);
mycss_selectors_list_t *current_list = selectors->list_last;
// FRANK
// TODO: implement
printf("\nmycss_selectors_function_begin_contains()\n");
printf("\tselector->sub_type = %d\n", (int)selector->sub_type);
selectors->list = new_list;
selectors->list_last = NULL;
selectors->ending_token = entry->parser_ending_token;
mycss_selectors_state_relative_selector_list(entry, NULL, true);
(*new_list)->parent = current_list;
mycss_entry_parser_list_push(entry, mycss_selectors_function_parser_contains, entry->parser_switch, entry->parser_ending_token, false);
}
void mycss_selectors_function_begin_nth_last_child(mycss_entry_t* entry, mycss_selectors_entry_t* selector)

View File

@ -227,63 +227,38 @@ bool mycss_selectors_function_parser_has(mycss_entry_t* entry, mycss_token_t* to
////// CONTAINS
//////
///////////////////////////////////////////////////////////
void mycss_selectors_function_parser_contains_find_bad_selector(mycss_selectors_list_t* selectors_list)
{
// FRANK
for(size_t i = 0; i < selectors_list->entries_list_length; i++) {
mycss_selectors_entry_t* selector = selectors_list->entries_list[i].entry;
while(selector) {
if(selector->type == MyCSS_SELECTORS_TYPE_PSEUDO_ELEMENT) {
if((selectors_list->flags & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD) == 0)
selectors_list->flags |= MyCSS_SELECTORS_FLAGS_SELECTOR_BAD;
return;
}
selector = selector->next;
}
}
}
// void mycss_selectors_function_parser_contains_find_bad_selector(mycss_selectors_list_t* selectors_list)
// {
// // TODO: implement
// // FRANK
// printf("\nmycss_selectors_function_parser_contains_find_bad_selector()\n");
// }
bool mycss_selectors_function_parser_contains(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
{
// TODO: implement
// FRANK
mycss_selectors_t *selectors = entry->selectors;
mycss_selectors_list_t *selectors_list = selectors->list_last;
mycss_selectors_list_t *parent_list = selectors->list_last->parent;
printf("\nmycss_selectors_function_parser_contains()\n");
// printf("\ttoken->type = %d\n\tentry->parser_ending_token = %d\n\tlast_response = %d\n", (int)token->type, entry->parser_ending_token, (int)last_response);
selectors->entry_last = mycss_selectors_list_last_entry(parent_list);
selectors->list_last = parent_list;
selectors->specificity = &parent_list->entries_list[ (parent_list->entries_list_length - 1) ].specificity;
mycss_selectors_function_parser_contains_find_bad_selector(selectors_list);
selectors_list = mycss_selectors_parser_check_selector_list(selectors, selectors_list);
if(selectors_list == NULL) {
if(selectors->entry_last) {
selectors->entry_last->value = NULL;
selectors->entry_last->flags |= MyCSS_SELECTORS_FLAGS_SELECTOR_BAD;
// mycss_selectors_t *selectors = entry->selectors;
// mycss_selectors_entry_t *selector = selectors->entry_last;
// printf("\t%s\n", (selector->value) ? "selector->value exists" : "selector->value does not exist");
if(token){
// printf("%.*s", (int)size, buffer);
printf("\ttoken from %d -> %d, type = %d\n", (int)token->begin, (int)token->length, (int)token->type);
printf("\tdata = \"%.*s\"\n", (int)token->length, (char*)token->data);
if(token->type == entry->parser_ending_token) {
printf("\ttype is entry->parser_ending_token\n");
mycss_entry_parser_list_pop(entry);
return false;
}
}
else if((selectors_list->flags & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD) && selectors->entry_last) {
selectors->entry_last->flags |= MyCSS_SELECTORS_FLAGS_SELECTOR_BAD;
}
if(token->type == entry->parser_ending_token) {
mycss_entry_parser_list_pop(entry);
return false;
}
if(selectors_list)
selectors_list->flags |= MyCSS_SELECTORS_FLAGS_SELECTOR_BAD;
if(selectors->entry_last)
selectors->entry_last->flags |= MyCSS_SELECTORS_FLAGS_SELECTOR_BAD;
entry->parser = mycss_selectors_function_parser_state_drop_component_value;
return false;
return true;
}
///////////////////////////////////////////////////////////

View File

@ -128,6 +128,7 @@ mycss_selectors_list_t * mycss_selectors_parse_by_function(mycss_selectors_t* se
mycss_selectors_list_t *list = NULL;
selectors->list = &list;
/* parsing */
mycss_encoding_set(entry, encoding);
@ -141,12 +142,16 @@ mycss_selectors_list_t * mycss_selectors_parse_by_function(mycss_selectors_t* se
status = mycss_tokenizer_end(entry);
printf("\nmycss_selectors_parse_by_function()\n\tstatus = %d %s\n", (int)status, ((int)status == MyHTML_STATUS_OK)?"MyHTML_STATUS_OK":"not OK");
if(out_status)
*out_status = status;
if(list)
return list;
printf("\n\tmissing list, return NULL\n");
return NULL;
}

View File

@ -274,7 +274,7 @@ void mycss_selectors_parser_selector_pseudo_class_function(mycss_entry_t* entry,
mycss_selectors_function_begin_f to_func = mycss_function_begin_by_name(str->data, str->length);
// FRANK
printf("mycss_selectors_parser_selector_pseudo_class_function: '%s' %s\n", str->data, (to_func) ? "exists" : "does not exist");
printf("\nmycss_selectors_parser_selector_pseudo_class_function()\n\tbegin_by_name = '%s'\n\t%s\n", str->data, (to_func) ? "exists" : "does not exist");
if(to_func) {
to_func(entry, selector);

View File

@ -48,8 +48,9 @@ void mycss_selectors_serialization_chain(mycss_selectors_t* selectors, mycss_sel
bool mycss_selectors_serialization_contains(mycss_selectors_t* selectors, void *value,
mycore_callback_serialize_f callback, void* context)
{
// TODO: implement
// FRANK
printf("mycss_selectors_serialization_contains() '%s'\n", (char*)value);
printf("\nmycss_selectors_serialization_contains()\n");
return true;
}
@ -57,6 +58,11 @@ bool mycss_selectors_serialization_list(mycss_selectors_t* selectors, mycss_sele
mycore_callback_serialize_f callback, void* context)
{
while(selectors_list) {
// FRANK
printf("\nmycss_selectors_serialization_list()\n");
printf("\tselectors_list->entries_list_length = %d\n", (int)selectors_list->entries_list_length);
for(size_t i = 0; i < selectors_list->entries_list_length; i++)
{
mycss_selectors_entries_list_t *entries = &selectors_list->entries_list[i];
@ -159,15 +165,20 @@ bool mycss_selectors_serialization_selector(mycss_selectors_t* selectors, mycss_
callback("(", 1, context);
// FRANK
printf("mycss_selectors_serialization_selector() selector->sub_type = %d\n", (int)selector->sub_type);
printf("\nmycss_selectors_serialization_selector()\n\tselector->sub_type = %d\n", (int)selector->sub_type);
switch (selector->sub_type) {
// case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS:
case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS:
// TODO: implement
// FRANK
printf("\tMyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS\n");
printf("\t%s\n", (selector->value) ? "selector value exists" : "selector value does not exist");
// if(selector->value)
// mycss_selectors_serialization_contains(selectors, selector->value, callback, context);
// break;
break;
case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS:
// case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS:
case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_HAS:
case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_NOT:
case MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_MATCHES:

View File

@ -149,8 +149,10 @@ void * mycss_selectors_value_pseudo_class_function_has_create(mycss_entry_t* ent
void * mycss_selectors_value_pseudo_class_function_contains_create(mycss_entry_t* entry, bool set_clean)
{
// TODO: implement
// FRANK
return mycss_selectors_list_create(entry->selectors);
printf("\nmycss_selectors_value_pseudo_class_function_contains_create()\n");
return NULL;
}
void * mycss_selectors_value_pseudo_class_function_lang_create(mycss_entry_t* entry, bool set_clean)
@ -373,6 +375,10 @@ void * mycss_selectors_value_pseudo_class_function_nth_of_type_destroy(mycss_ent
void * mycss_selectors_value_pseudo_class_function_contains_destroy(mycss_entry_t* entry, void* value, bool self_destroy)
{
// FRANK
// TODO: implement
printf("\nmycss_selectors_value_pseudo_class_function_contains_destroy()\n");
if(value == NULL)
return NULL;

View File

@ -83,7 +83,6 @@ void * mycss_selectors_value_pseudo_class_function_nth_last_child_create(mycss_e
void * mycss_selectors_value_pseudo_class_function_nth_last_column_create(mycss_entry_t* entry, bool set_clean);
void * mycss_selectors_value_pseudo_class_function_nth_last_of_type_create(mycss_entry_t* entry, bool set_clean);
void * mycss_selectors_value_pseudo_class_function_nth_of_type_create(mycss_entry_t* entry, bool set_clean);
// FRANK
void * mycss_selectors_value_pseudo_class_function_contains_create(mycss_entry_t* entry, bool set_clean);
/* pseudo class function destroy */
@ -101,7 +100,6 @@ void * mycss_selectors_value_pseudo_class_function_nth_last_child_destroy(mycss_
void * mycss_selectors_value_pseudo_class_function_nth_last_column_destroy(mycss_entry_t* entry, void* value, bool self_destroy);
void * mycss_selectors_value_pseudo_class_function_nth_last_of_type_destroy(mycss_entry_t* entry, void* value, bool self_destroy);
void * mycss_selectors_value_pseudo_class_function_nth_of_type_destroy(mycss_entry_t* entry, void* value, bool self_destroy);
// FRANK
void * mycss_selectors_value_pseudo_class_function_contains_destroy(mycss_entry_t* entry, void* value, bool self_destroy);
#ifdef __cplusplus

BIN
test/mycore/utils/avl_tree Executable file

Binary file not shown.

BIN
test/mycss/declaration Executable file

Binary file not shown.

Binary file not shown.

BIN
test/myhtml/commoncrawl Executable file

Binary file not shown.

BIN
test/myhtml/pseudo_class_contains Executable file

Binary file not shown.

View File

@ -86,6 +86,9 @@ mycss_selectors_list_t * prepare_selector(mycss_entry_t *css_entry, const char*
MyENCODING_UTF_8,
selector, selector_size,
&out_status);
printf("\nprepare_selector()\n\t%s\n", (list != NULL)?"has list":"no list");
printf("\tlist->flags = %d\n", (int)list->flags);
/* check parsing errors */
if(list == NULL || (list->flags & MyCSS_SELECTORS_FLAGS_SELECTOR_BAD)) {
fprintf(stderr, "Bad CSS Selectors\n");
@ -99,6 +102,7 @@ mycss_selectors_list_t * prepare_selector(mycss_entry_t *css_entry, const char*
exit(EXIT_FAILURE);
}
printf("\treturn list\n");
return list;
}
@ -119,8 +123,9 @@ void print_found_result(myhtml_tree_t* html_tree, myhtml_collection_t *collectio
int main(int argc, const char * argv[])
{
const char *html = "<div><p id=p1><p id=p2><p id=p3><a>link</a><p id=p4><p id=p5><p id=p6></div>";
const char *selector = ":contains('link')";
const char *html = "<div>Another <p>Hello World</p></div>";
// const char *selector = ":has(p)";
const char *selector = "p:contains(Hello World)";
/* init MyHTML and parse HTML */
myhtml_tree_t *html_tree = parse_html(html, strlen(html));

BIN
test/myurl/url Executable file

Binary file not shown.

BIN
test_suite/mycore/utils/avl_tree Executable file

Binary file not shown.

BIN
test_suite/mycss/declaration Executable file

Binary file not shown.

Binary file not shown.

BIN
test_suite/myhtml/commoncrawl Executable file

Binary file not shown.

Binary file not shown.

BIN
test_suite/myurl/url Executable file

Binary file not shown.