File Coverage

third_party/modest/source/mycss/property/parser_image.c
Criterion Covered Total %
statement 0 265 0.0
branch 0 64 0.0
condition n/a
subroutine n/a
pod n/a
total 0 329 0.0


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/property/parser.h"
22              
23 0           mycss_values_image_image_set_option_t * mycss_property_parser_image_function_get_next_option(mycss_entry_t* entry, mycss_values_image_image_set_t *ii_set)
24             {
25 0 0         if(ii_set->options == NULL) {
26 0           ii_set->options = mycss_values_create(entry, sizeof(mycss_values_image_image_set_option_t));
27 0           ii_set->options_length = 0;
28             }
29             else {
30 0           ii_set->options = mycss_values_realloc(entry, ii_set->options,
31 0           ii_set->options_length * sizeof(mycss_values_image_image_set_option_t),
32             sizeof(mycss_values_image_image_set_option_t));
33             }
34            
35 0           mycss_values_image_image_set_option_t *ii_entry = &ii_set->options[ ii_set->options_length ];
36 0           ii_set->options_length++;
37            
38 0           return ii_entry;
39             }
40              
41 0           static void mycss_values_parser_image_switch(mycss_entry_t* entry)
42             {
43 0           mycss_stack_entry_t *stack_entry = mycss_stack_pop(entry->declaration->stack);
44            
45 0 0         if(stack_entry->value)
46 0           entry->declaration->entry_last->value = stack_entry->value;
47            
48 0           entry->parser = stack_entry->parser;
49 0           }
50              
51             /*
52             * Image
53             */
54 0           bool mycss_property_parser_image_function_image(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
55             {
56 0 0         if(token->type == MyCSS_TOKEN_TYPE_WHITESPACE)
57 0           return true;
58            
59 0           mycore_string_t str = {0};
60 0           mycss_declaration_entry_t* declr_entry = entry->declaration->entry_last;
61            
62 0           mycss_values_image_t *image = (mycss_values_image_t*)declr_entry->value;
63 0           mycss_values_image_image_t *image_image = image->value.ii;
64            
65 0           void *value = NULL;
66 0           unsigned int value_type = 0;
67 0           bool parser_changed = false;
68            
69 0 0         if(mycss_property_shared_image(entry, token, &value, &value_type, &str, &parser_changed)) {
70 0           image_image->image = value;
71            
72 0 0         if(parser_changed) {
73 0           mycss_stack_push(entry->declaration->stack, declr_entry->value, mycss_property_parser_image_function_image_wait_comma);
74 0           declr_entry->value = value;
75            
76 0           return mycss_property_parser_destroy_string(&str, true);
77             }
78            
79 0           entry->parser = mycss_property_parser_image_function_image_end;
80 0           return mycss_property_parser_destroy_string(&str, true);
81             }
82            
83 0 0         if(token->type == MyCSS_TOKEN_TYPE_STRING)
84             {
85 0           mycore_string_t *ns_str = mycss_values_create(entry, sizeof(mycore_string_t));
86 0           mycss_token_data_to_string(entry, token, ns_str, true, false);
87            
88 0           image_image->str = ns_str;
89            
90 0           entry->parser = mycss_property_parser_image_function_image_wait_comma;
91 0           return mycss_property_parser_destroy_string(&str, true);
92             }
93            
94 0 0         if(mycss_property_shared_color(entry, token, &value, &value_type, &str, &parser_changed)) {
95 0           image_image->color = value;
96            
97 0 0         if(parser_changed) {
98 0           mycss_stack_push(entry->declaration->stack, declr_entry->value, mycss_property_parser_image_function_image_end);
99 0           declr_entry->value = value;
100            
101 0           return mycss_property_parser_destroy_string(&str, true);
102             }
103            
104 0           entry->parser = mycss_property_parser_image_function_image_end;
105 0           return mycss_property_parser_destroy_string(&str, true);
106             }
107            
108 0           mycss_values_parser_image_switch(entry);
109 0           return mycss_property_parser_destroy_string(&str, false);
110             }
111              
112 0           bool mycss_property_parser_image_function_image_wait_comma(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
113             {
114 0           switch (token->type) {
115             case MyCSS_TOKEN_TYPE_WHITESPACE:
116 0           return true;
117            
118             case MyCSS_TOKEN_TYPE_RIGHT_PARENTHESIS:
119 0           mycss_values_parser_image_switch(entry);
120 0           return true;
121            
122             case MyCSS_TOKEN_TYPE_COMMA:
123 0           entry->parser = mycss_property_parser_image_function_image_color;
124 0           return true;
125            
126             default:
127 0           mycss_values_parser_image_switch(entry);
128 0           return false;
129             }
130             }
131              
132 0           bool mycss_property_parser_image_function_image_color(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
133             {
134 0 0         if(token->type == MyCSS_TOKEN_TYPE_WHITESPACE)
135 0           return true;
136            
137 0           mycore_string_t str = {0};
138 0           mycss_declaration_entry_t* declr_entry = entry->declaration->entry_last;
139            
140 0           mycss_values_image_t *image = (mycss_values_image_t*)declr_entry->value;
141 0           mycss_values_image_image_t *image_image = image->value.ii;
142            
143 0           void *value = NULL;
144 0           unsigned int value_type = 0;
145 0           bool parser_changed = false;
146            
147 0 0         if(mycss_property_shared_color(entry, token, &value, &value_type, &str, &parser_changed)) {
148 0           image_image->color = value;
149            
150 0 0         if(parser_changed) {
151 0           mycss_stack_push(entry->declaration->stack, declr_entry->value, mycss_property_parser_image_function_image_end);
152 0           declr_entry->value = value;
153            
154 0           return mycss_property_parser_destroy_string(&str, true);
155             }
156            
157 0           entry->parser = mycss_property_parser_image_function_image_end;
158 0           return mycss_property_parser_destroy_string(&str, true);
159             }
160            
161 0           mycss_values_parser_image_switch(entry);
162 0           return mycss_property_parser_destroy_string(&str, false);
163             }
164              
165 0           bool mycss_property_parser_image_function_image_end(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
166             {
167 0           switch (token->type) {
168             case MyCSS_TOKEN_TYPE_WHITESPACE:
169 0           return true;
170            
171             case MyCSS_TOKEN_TYPE_RIGHT_PARENTHESIS:
172 0           mycss_values_parser_image_switch(entry);
173 0           return true;
174            
175             default:
176 0           mycss_values_parser_image_switch(entry);
177 0           return false;
178             }
179             }
180              
181             /*
182             * Image-Set
183             */
184 0           bool mycss_property_parser_image_function_image_set(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
185             {
186 0 0         if(token->type == MyCSS_TOKEN_TYPE_WHITESPACE)
187 0           return true;
188            
189 0           mycore_string_t str = {0};
190 0           mycss_declaration_entry_t* declr_entry = entry->declaration->entry_last;
191            
192 0           mycss_values_image_t *image = (mycss_values_image_t*)declr_entry->value;
193 0           mycss_values_image_image_set_t *ii_set = image->value.ii_set;
194            
195 0           void *value = NULL;
196 0           unsigned int value_type = 0;
197 0           bool parser_changed = false;
198            
199 0 0         if(mycss_property_shared_image(entry, token, &value, &value_type, &str, &parser_changed))
200             {
201 0           mycss_values_image_image_set_option_t *ii_entry = mycss_property_parser_image_function_get_next_option(entry, ii_set);
202 0           ii_entry->image = value;
203            
204 0 0         if(parser_changed) {
205 0           mycss_stack_push(entry->declaration->stack, declr_entry->value, mycss_property_parser_image_function_image_set_resolution);
206 0           declr_entry->value = value;
207            
208 0           return mycss_property_parser_destroy_string(&str, true);
209             }
210            
211 0           entry->parser = mycss_property_parser_image_function_image_set_resolution;
212 0           return mycss_property_parser_destroy_string(&str, true);
213             }
214            
215 0 0         if(token->type == MyCSS_TOKEN_TYPE_STRING)
216             {
217 0           mycore_string_t *ns_str = mycss_values_create(entry, sizeof(mycore_string_t));
218 0           mycss_token_data_to_string(entry, token, ns_str, true, false);
219            
220 0           mycss_values_image_image_set_option_t *ii_entry = mycss_property_parser_image_function_get_next_option(entry, ii_set);
221 0           ii_entry->str = ns_str;
222            
223 0           entry->parser = mycss_property_parser_image_function_image_set_resolution;
224 0           return mycss_property_parser_destroy_string(&str, true);
225             }
226            
227 0           mycss_values_parser_image_switch(entry);
228 0           return mycss_property_parser_destroy_string(&str, false);
229             }
230              
231 0           bool mycss_property_parser_image_function_image_set_resolution(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
232             {
233 0 0         if(token->type == MyCSS_TOKEN_TYPE_WHITESPACE)
234 0           return true;
235            
236 0           mycore_string_t str = {0};
237 0           mycss_declaration_entry_t* declr_entry = entry->declaration->entry_last;
238            
239 0           mycss_values_image_t *image = (mycss_values_image_t*)declr_entry->value;
240 0           mycss_values_image_image_set_t *ii_set = image->value.ii_set;
241            
242 0           void *value = NULL;
243 0           unsigned int value_type = 0;
244            
245 0 0         if(mycss_property_shared_resolution(entry, token, &value, &value_type, &str))
246             {
247 0           mycss_values_image_image_set_option_t *ii_entry = mycss_property_parser_image_function_get_next_option(entry, ii_set);
248 0           ii_entry->resolution = value;
249            
250 0           entry->parser = mycss_property_parser_image_function_image_set_resolution_wait_end;
251 0           return mycss_property_parser_destroy_string(&str, true);
252             }
253            
254 0           mycss_values_parser_image_switch(entry);
255 0           return mycss_property_parser_destroy_string(&str, false);
256             }
257              
258 0           bool mycss_property_parser_image_function_image_set_resolution_wait_end(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
259             {
260 0           switch (token->type) {
261             case MyCSS_TOKEN_TYPE_WHITESPACE:
262 0           return true;
263            
264             case MyCSS_TOKEN_TYPE_RIGHT_PARENTHESIS:
265 0           mycss_values_parser_image_switch(entry);
266 0           return true;
267            
268             default:
269 0           entry->parser = mycss_property_parser_image_function_image_set;
270 0           return false;
271             }
272             }
273              
274             /*
275             * Element
276             */
277 0           bool mycss_property_parser_image_function_string(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
278             {
279 0 0         if(token->type == MyCSS_TOKEN_TYPE_WHITESPACE)
280 0           return true;
281            
282 0           mycss_declaration_entry_t* declr_entry = entry->declaration->entry_last;
283            
284 0           mycss_values_image_t *image = (mycss_values_image_t*)declr_entry->value;
285 0           mycss_values_element_t *element = image->value.element;
286            
287 0           void *value = &element->custom_ident;
288            
289 0 0         if(mycss_property_shared_custom_ident(entry, token, &value, NULL)) {
290 0           entry->parser = mycss_property_parser_image_function_string_wait_comma;
291 0           return true;
292             }
293            
294 0           mycss_values_parser_image_switch(entry);
295 0           return false;
296             }
297              
298 0           bool mycss_property_parser_image_function_string_wait_comma(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
299             {
300 0           switch (token->type) {
301             case MyCSS_TOKEN_TYPE_WHITESPACE:
302 0           return true;
303            
304             case MyCSS_TOKEN_TYPE_COMMA:
305 0           entry->parser = mycss_property_parser_image_function_string_wait_ident;
306 0           return true;
307            
308             case MyCSS_TOKEN_TYPE_RIGHT_PARENTHESIS:
309 0           mycss_values_parser_image_switch(entry);
310 0           return true;
311            
312             default:
313 0           mycss_values_parser_image_switch(entry);
314 0           return false;
315             }
316             }
317              
318 0           bool mycss_property_parser_image_function_string_wait_ident(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
319             {
320 0           switch (token->type) {
321             case MyCSS_TOKEN_TYPE_WHITESPACE:
322 0           return true;
323            
324             case MyCSS_TOKEN_TYPE_RIGHT_PARENTHESIS:
325 0           mycss_values_parser_image_switch(entry);
326 0           return true;
327            
328             case MyCSS_TOKEN_TYPE_IDENT:
329 0           break;
330            
331             default:
332 0           mycss_values_parser_image_switch(entry);
333 0           return false;
334             }
335            
336 0           mycss_declaration_entry_t* declr_entry = entry->declaration->entry_last;
337            
338 0           mycss_values_image_t *image = (mycss_values_image_t*)declr_entry->value;
339 0           mycss_values_element_t *element = image->value.element;
340            
341 0           mycore_string_t str = {0};
342 0           mycss_token_data_to_string(entry, token, &str, true, false);
343            
344 0           element->type = mycss_property_value_type_by_name(str.data, str.length);
345            
346 0 0         switch (element->type) {
347             case MyCSS_PROPERTY_VALUE_FIRST:
348             case MyCSS_PROPERTY_VALUE_START:
349             case MyCSS_PROPERTY_VALUE_LAST:
350             case MyCSS_PROPERTY_VALUE_FIRST_EXCEPT:
351 0           return mycss_property_parser_destroy_string(&str, true);
352            
353             default:
354 0           element->type = MyCSS_PROPERTY_VALUE_UNDEF;
355 0           break;
356             }
357            
358 0           mycss_values_parser_image_switch(entry);
359 0           return mycss_property_parser_destroy_string(&str, false);
360             }
361              
362             /*
363             * Cross Fade
364             */
365 0           bool mycss_property_parser_image_function_cross_fade(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
366             {
367 0 0         if(token->type == MyCSS_TOKEN_TYPE_WHITESPACE)
368 0           return true;
369            
370 0           mycss_declaration_entry_t* declr_entry = entry->declaration->entry_last;
371            
372 0           mycss_values_image_t *image = (mycss_values_image_t*)declr_entry->value;
373 0           mycss_values_cross_fade_t *cross_fade = image->value.cross_fade;
374            
375 0           mycore_string_t str = {0};
376            
377 0           void *value = NULL;
378 0           unsigned int value_type = 0;
379 0           bool parser_changed = false;
380            
381 0 0         if(mycss_property_shared_percentage(entry, token, &value, &value_type, &str)) {
382 0           cross_fade->mixing_image.percentage = value;
383            
384 0           entry->parser = mycss_property_parser_image_function_cross_fade_mixing_after_percentage;
385 0           return mycss_property_parser_destroy_string(&str, true);
386             }
387            
388 0 0         if(mycss_property_shared_image(entry, token, &value, &value_type, &str, &parser_changed)) {
389 0           cross_fade->mixing_image.image = value;
390            
391 0 0         if(parser_changed) {
392 0           mycss_stack_push(entry->declaration->stack, declr_entry->value, mycss_property_parser_image_function_cross_fade_mixing_after);
393 0           declr_entry->value = value;
394            
395 0           return mycss_property_parser_destroy_string(&str, true);
396             }
397            
398 0           entry->parser = mycss_property_parser_image_function_cross_fade_mixing_after;
399 0           return mycss_property_parser_destroy_string(&str, true);
400             }
401            
402 0           mycss_values_parser_image_switch(entry);
403 0           return mycss_property_parser_destroy_string(&str, false);
404             }
405              
406 0           bool mycss_property_parser_image_function_cross_fade_mixing_after_percentage(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
407             {
408 0 0         if(token->type == MyCSS_TOKEN_TYPE_WHITESPACE)
409 0           return true;
410            
411 0           mycss_declaration_entry_t* declr_entry = entry->declaration->entry_last;
412            
413 0           mycss_values_image_t *image = (mycss_values_image_t*)declr_entry->value;
414 0           mycss_values_cross_fade_t *cross_fade = image->value.cross_fade;
415            
416 0           mycore_string_t str = {0};
417            
418 0           void *value = NULL;
419 0           unsigned int value_type = 0;
420 0           bool parser_changed = false;
421            
422 0 0         if(mycss_property_shared_image(entry, token, &value, &value_type, &str, &parser_changed)) {
423 0           cross_fade->mixing_image.image = value;
424            
425 0 0         if(parser_changed) {
426 0           mycss_stack_push(entry->declaration->stack, declr_entry->value, mycss_property_parser_image_function_cross_fade_mixing_after);
427 0           declr_entry->value = value;
428            
429 0           return mycss_property_parser_destroy_string(&str, true);
430             }
431            
432 0           entry->parser_switch = mycss_property_parser_image_function_cross_fade_mixing_after;
433 0           return mycss_property_parser_destroy_string(&str, true);
434             }
435            
436 0           mycss_values_parser_image_switch(entry);
437 0           return mycss_property_parser_destroy_string(&str, false);
438             }
439              
440 0           bool mycss_property_parser_image_function_cross_fade_mixing_after(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
441             {
442 0           switch (token->type) {
443             case MyCSS_TOKEN_TYPE_WHITESPACE:
444 0           return true;
445            
446             case MyCSS_TOKEN_TYPE_COMMA:
447 0           entry->parser = mycss_property_parser_image_function_cross_fade_final;
448 0           return true;
449            
450             case MyCSS_TOKEN_TYPE_RIGHT_PARENTHESIS:
451 0           mycss_values_parser_image_switch(entry);
452 0           return true;
453            
454             default:
455 0           mycss_values_parser_image_switch(entry);
456 0           return false;
457             }
458             }
459              
460 0           bool mycss_property_parser_image_function_cross_fade_final(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
461             {
462 0 0         if(token->type == MyCSS_TOKEN_TYPE_WHITESPACE)
463 0           return true;
464            
465 0           mycss_declaration_entry_t* declr_entry = entry->declaration->entry_last;
466            
467 0           mycss_values_image_t *image = (mycss_values_image_t*)declr_entry->value;
468 0           mycss_values_cross_fade_t *cross_fade = image->value.cross_fade;
469            
470 0           mycore_string_t str = {0};
471            
472 0           void *value = NULL;
473 0           unsigned int value_type = 0;
474 0           bool parser_changed = false;
475            
476 0 0         if(mycss_property_shared_image(entry, token, &value, &value_type, &str, &parser_changed)) {
477 0           cross_fade->final_image.image = value;
478            
479 0 0         if(parser_changed) {
480 0           mycss_stack_push(entry->declaration->stack, declr_entry->value, mycss_property_parser_image_function_cross_fade_end);
481 0           declr_entry->value = value;
482            
483 0           return mycss_property_parser_destroy_string(&str, true);
484             }
485            
486 0           entry->parser = mycss_property_parser_image_function_cross_fade_end;
487 0           return mycss_property_parser_destroy_string(&str, true);
488             }
489            
490 0 0         if(mycss_property_shared_color(entry, token, &value, &value_type, &str, &parser_changed)) {
491 0           cross_fade->final_image.color = value;
492            
493 0 0         if(parser_changed) {
494 0           mycss_stack_push(entry->declaration->stack, declr_entry->value, mycss_property_parser_image_function_cross_fade_end);
495 0           declr_entry->value = value;
496            
497 0           return mycss_property_parser_destroy_string(&str, true);
498             }
499            
500 0           entry->parser = mycss_property_parser_image_function_cross_fade_end;
501 0           return mycss_property_parser_destroy_string(&str, true);
502             }
503            
504 0           mycss_values_parser_image_switch(entry);
505 0           return mycss_property_parser_destroy_string(&str, false);
506             }
507              
508 0           bool mycss_property_parser_image_function_cross_fade_end(mycss_entry_t* entry, mycss_token_t* token, bool last_response)
509             {
510 0           switch (token->type) {
511             case MyCSS_TOKEN_TYPE_WHITESPACE:
512 0           return true;
513            
514             case MyCSS_TOKEN_TYPE_RIGHT_PARENTHESIS:
515 0           mycss_values_parser_image_switch(entry);
516 0           return true;
517            
518             default:
519 0           mycss_values_parser_image_switch(entry);
520 0           return false;
521             }
522             }
523              
524