File Coverage

third_party/modest/source/mycss/selectors/list.c
Criterion Covered Total %
statement 36 75 48.0
branch 10 34 29.4
condition n/a
subroutine n/a
pod n/a
total 46 109 42.2


line stmt bran cond sub pod time code
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 128           mycss_selectors_list_t * mycss_selectors_list_create(mycss_selectors_t* selectors)
25             {
26 128           mycss_selectors_list_t* selectors_list = mcobject_malloc(selectors->mcobject_list_entries, NULL);
27 128           mycss_selectors_list_clean(selectors_list);
28 128           return selectors_list;
29             }
30              
31 128           void mycss_selectors_list_clean(mycss_selectors_list_t* selectors_list)
32             {
33 128           memset(selectors_list, 0, sizeof(mycss_selectors_list_t));
34 128           }
35              
36 128           mycss_selectors_list_t * mycss_selectors_list_destroy(mycss_selectors_t* selectors, mycss_selectors_list_t* selectors_list, bool self_destroy)
37             {
38 128 50         if(selectors_list == NULL)
39 0           return NULL;
40            
41 128           mycss_entry_t *entry = selectors->ref_entry;
42            
43 128 50         if(selectors_list->entries_list)
44             {
45 260 100         for(size_t i = 0; i < selectors_list->entries_list_length; i++) {
46 132           mycss_selectors_entry_t *sel_entry = selectors_list->entries_list[i].entry;
47            
48 285 100         while(sel_entry) {
49 153           mycss_selectors_entry_t *sel_entry_next = sel_entry->next;
50 153           mycss_selectors_entry_destroy(entry->selectors, sel_entry, true);
51            
52 153           sel_entry = sel_entry_next;
53             }
54             }
55            
56 128           mycss_selectors_entries_list_destroy(entry->selectors, selectors_list->entries_list);
57             }
58            
59 128 50         if(self_destroy) {
60 128           mcobject_free(selectors->mcobject_list_entries, selectors_list);
61 128           return NULL;
62             }
63            
64 0           return selectors_list;
65             }
66              
67 132           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 132 100         if(current_list->entries_list == NULL) {
70 128           current_list->entries_list = mycss_selectors_entries_list_create(selectors);
71             }
72             else {
73 4           current_list->entries_list = mycss_selectors_entries_list_add_one(selectors, current_list->entries_list, current_list->entries_list_length);
74             }
75            
76 132           mycss_selectors_entries_list_t *entries_list = ¤t_list->entries_list[current_list->entries_list_length];
77 132           memset(entries_list, 0, sizeof(mycss_selectors_entries_list_t));
78            
79 132           selectors->specificity = &entries_list->specificity;
80            
81 132           entries_list->entry = selector;
82 132           current_list->entries_list_length++;
83            
84 132           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 0         while(i) {
92 0           i--;
93            
94 0           mycss_selectors_entry_t *entry = list->entries_list[i].entry;
95            
96 0 0         while(entry) {
97 0 0         if(entry->next == NULL)
98 0           return entry;
99            
100 0           entry = entry->next;
101             }
102             }
103            
104 0           return NULL;
105             }
106              
107 128           void mycss_selectors_list_append_to_current(mycss_selectors_t* selectors, mycss_selectors_list_t* current_list)
108             {
109 128 50         if(selectors->list_last) {
110 0           selectors->list_last->next = current_list;
111 0           current_list->prev = selectors->list_last;
112             }
113             else {
114 128           (*selectors->list) = current_list;
115             }
116            
117 128           selectors->list_last = current_list;
118 128           }
119              
120 0           mycss_selectors_entry_t ** mycss_selectors_list_current_chain(mycss_selectors_list_t* list)
121             {
122 0 0         if(list->entries_list_length)
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 0         if(list->entries_list_length == 0)
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 0         if(entry == NULL) {
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 0         while(entry) {
145 0 0         if(entry->next == NULL) {
146 0 0         if(entry->key == NULL)
147             {
148 0 0         if(entry->prev)
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