« third_party/modest/source/mycss/selectors/function_parser.c
↑ Summary
third_party/modest/source/mycss/selectors/pseudo.c »
| 1 | /* | ||||||||||
| 2 | Copyright (C) 2016-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 "mycss/selectors/list.h" | ||||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | 0 | mycss_selectors_list_t * mycss_selectors_list_create(mycss_selectors_t* selectors) | |||||||||
| 25 | { | ||||||||||
| 26 | 0 | mycss_selectors_list_t* selectors_list = mcobject_malloc(selectors->mcobject_list_entries, NULL); | |||||||||
| 27 | 0 | mycss_selectors_list_clean(selectors_list); | |||||||||
| 28 | 0 | return selectors_list; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 0 | void mycss_selectors_list_clean(mycss_selectors_list_t* selectors_list) | |||||||||
| 32 | { | ||||||||||
| 33 | 0 | memset(selectors_list, 0, sizeof(mycss_selectors_list_t)); | |||||||||
| 34 | 0 | } | |||||||||
| 35 | |||||||||||
| 36 | 0 | mycss_selectors_list_t * mycss_selectors_list_destroy(mycss_selectors_t* selectors, mycss_selectors_list_t* selectors_list, bool self_destroy) | |||||||||
| 37 | { | ||||||||||
| 38 | 0 | ▶ | if(selectors_list == NULL) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 0 | return NULL; | |||||||||
| 40 | |||||||||||
| 41 | 0 | mycss_entry_t *entry = selectors->ref_entry; | |||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | if(selectors_list->entries_list) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | { | ||||||||||
| 45 | 0 | ▶ | for(size_t i = 0; i < selectors_list->entries_list_length; i++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | mycss_selectors_entry_t *sel_entry = selectors_list->entries_list[i].entry; | |||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | while(sel_entry) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | mycss_selectors_entry_t *sel_entry_next = sel_entry->next; | |||||||||
| 50 | 0 | mycss_selectors_entry_destroy(entry->selectors, sel_entry, true); | |||||||||
| 51 | |||||||||||
| 52 | 0 | sel_entry = sel_entry_next; | |||||||||
| 53 | } | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 0 | mycss_selectors_entries_list_destroy(entry->selectors, selectors_list->entries_list); | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | if(self_destroy) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | mcobject_free(selectors->mcobject_list_entries, selectors_list); | |||||||||
| 61 | 0 | return NULL; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 0 | return selectors_list; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 0 | mycss_selectors_list_t * mycss_selectors_list_append_selector(mycss_selectors_t* selectors, mycss_selectors_list_t* current_list, mycss_selectors_entry_t* selector) | |||||||||
| 68 | { | ||||||||||
| 69 | 0 | ▶ | if(current_list->entries_list == NULL) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | current_list->entries_list = mycss_selectors_entries_list_create(selectors); | |||||||||
| 71 | } | ||||||||||
| 72 | else { | ||||||||||
| 73 | 0 | current_list->entries_list = mycss_selectors_entries_list_add_one(selectors, current_list->entries_list, current_list->entries_list_length); | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 0 | mycss_selectors_entries_list_t *entries_list = ¤t_list->entries_list[current_list->entries_list_length]; | |||||||||
| 77 | 0 | memset(entries_list, 0, sizeof(mycss_selectors_entries_list_t)); | |||||||||
| 78 | |||||||||||
| 79 | 0 | selectors->specificity = &entries_list->specificity; | |||||||||
| 80 | |||||||||||
| 81 | 0 | entries_list->entry = selector; | |||||||||
| 82 | 0 | current_list->entries_list_length++; | |||||||||
| 83 | |||||||||||
| 84 | 0 | return current_list; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 0 | mycss_selectors_entry_t * mycss_selectors_list_last_entry(mycss_selectors_list_t* list) | |||||||||
| 88 | { | ||||||||||
| 89 | 0 | size_t i = list->entries_list_length; | |||||||||
| 90 | |||||||||||
| 91 | 0 | ▶ | while(i) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 0 | i--; | |||||||||
| 93 | |||||||||||
| 94 | 0 | mycss_selectors_entry_t *entry = list->entries_list[i].entry; | |||||||||
| 95 | |||||||||||
| 96 | 0 | ▶ | while(entry) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 0 | ▶ | if(entry->next == NULL) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 0 | return entry; | |||||||||
| 99 | |||||||||||
| 100 | 0 | entry = entry->next; | |||||||||
| 101 | } | ||||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 0 | return NULL; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 0 | void mycss_selectors_list_append_to_current(mycss_selectors_t* selectors, mycss_selectors_list_t* current_list) | |||||||||
| 108 | { | ||||||||||
| 109 | 0 | ▶ | if(selectors->list_last) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | 0 | selectors->list_last->next = current_list; | |||||||||
| 111 | 0 | current_list->prev = selectors->list_last; | |||||||||
| 112 | } | ||||||||||
| 113 | else { | ||||||||||
| 114 | 0 | (*selectors->list) = current_list; | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | 0 | selectors->list_last = current_list; | |||||||||
| 118 | 0 | } | |||||||||
| 119 | |||||||||||
| 120 | 0 | mycss_selectors_entry_t ** mycss_selectors_list_current_chain(mycss_selectors_list_t* list) | |||||||||
| 121 | { | ||||||||||
| 122 | 0 | ▶ | if(list->entries_list_length) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | 0 | return NULL; | |||||||||
| 124 | |||||||||||
| 125 | 0 | return &list->entries_list[ list->entries_list_length - 1 ].entry; | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | 0 | bool mycss_selectors_list_destroy_last_empty_selector(mycss_selectors_t* selectors, mycss_selectors_list_t* list, bool destroy_found) | |||||||||
| 129 | { | ||||||||||
| 130 | 0 | ▶ | if(list->entries_list_length == 0) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 131 | 0 | return false; | |||||||||
| 132 | |||||||||||
| 133 | 0 | size_t idx = list->entries_list_length - 1; | |||||||||
| 134 | |||||||||||
| 135 | 0 | mycss_selectors_entry_t *entry = list->entries_list[idx].entry; | |||||||||
| 136 | |||||||||||
| 137 | 0 | ▶ | if(entry == NULL) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 138 | 0 | mycss_selectors_entry_destroy(selectors, entry, destroy_found); | |||||||||
| 139 | 0 | list->entries_list_length--; | |||||||||
| 140 | |||||||||||
| 141 | 0 | return true; | |||||||||
| 142 | } | ||||||||||
| 143 | |||||||||||
| 144 | 0 | ▶ | while(entry) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 145 | 0 | ▶ | if(entry->next == NULL) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 146 | 0 | ▶ | if(entry->key == NULL) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 147 | { | ||||||||||
| 148 | 0 | ▶ | if(entry->prev) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 149 | 0 | entry->prev->next = NULL; | |||||||||
| 150 | else { | ||||||||||
| 151 | 0 | list->entries_list[idx].entry = NULL; | |||||||||
| 152 | 0 | list->entries_list_length--; | |||||||||
| 153 | } | ||||||||||
| 154 | |||||||||||
| 155 | 0 | mycss_selectors_entry_destroy(selectors, entry, destroy_found); | |||||||||
| 156 | |||||||||||
| 157 | 0 | return true; | |||||||||
| 158 | } | ||||||||||
| 159 | |||||||||||
| 160 | 0 | return false; | |||||||||
| 161 | } | ||||||||||
| 162 | |||||||||||
| 163 | 0 | entry = entry->next; | |||||||||
| 164 | } | ||||||||||
| 165 | |||||||||||
| 166 | 0 | return false; | |||||||||
| 167 | } | ||||||||||
| 168 | |||||||||||