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/stack.h" |
22
|
|
|
|
|
|
|
|
23
|
74
|
|
|
|
|
|
mycss_stack_t * mycss_stack_create(void) |
24
|
|
|
|
|
|
|
{ |
25
|
74
|
|
|
|
|
|
return mycore_calloc(1, sizeof(mycss_stack_t)); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
74
|
|
|
|
|
|
mystatus_t mycss_stack_init(mycss_stack_t *stack, size_t size) |
29
|
|
|
|
|
|
|
{ |
30
|
74
|
|
|
|
|
|
stack->entries_size = size; |
31
|
74
|
|
|
|
|
|
stack->entries_length = 0; |
32
|
74
|
|
|
|
|
|
stack->entries = (mycss_stack_entry_t*)mycore_calloc(stack->entries_size, sizeof(mycss_stack_entry_t)); |
33
|
|
|
|
|
|
|
|
34
|
74
|
50
|
|
|
|
|
if(stack->entries == NULL) |
35
|
0
|
|
|
|
|
|
return MyCSS_STATUS_ERROR_MEMORY_ALLOCATION; |
36
|
|
|
|
|
|
|
|
37
|
74
|
|
|
|
|
|
return MyCSS_STATUS_OK; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
129
|
|
|
|
|
|
void mycss_stack_clean(mycss_stack_t *stack) |
41
|
|
|
|
|
|
|
{ |
42
|
129
|
|
|
|
|
|
stack->entries_length = 0; |
43
|
129
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
74
|
|
|
|
|
|
mycss_stack_t * mycss_stack_destroy(mycss_stack_t *stack, bool self_destroy) |
46
|
|
|
|
|
|
|
{ |
47
|
74
|
50
|
|
|
|
|
if(stack == NULL) |
48
|
0
|
|
|
|
|
|
return NULL; |
49
|
|
|
|
|
|
|
|
50
|
74
|
50
|
|
|
|
|
if(stack->entries) { |
51
|
74
|
|
|
|
|
|
mycore_free(stack->entries); |
52
|
74
|
|
|
|
|
|
stack->entries = NULL; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
74
|
50
|
|
|
|
|
if(self_destroy) { |
56
|
74
|
|
|
|
|
|
mycore_free(stack); |
57
|
74
|
|
|
|
|
|
return NULL; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return stack; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
mystatus_t mycss_stack_push(mycss_stack_t *stack, void* value, mycss_parser_token_f parser) |
64
|
|
|
|
|
|
|
{ |
65
|
0
|
0
|
|
|
|
|
if(stack->entries_length >= stack->entries_size) { |
66
|
0
|
|
|
|
|
|
size_t new_size = stack->entries_length << 1; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
mycss_stack_entry_t *entries = (mycss_stack_entry_t*)mycore_realloc(stack->entries, |
69
|
|
|
|
|
|
|
sizeof(mycss_stack_entry_t) * new_size); |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
if(entries) { |
72
|
0
|
|
|
|
|
|
stack->entries = entries; |
73
|
0
|
|
|
|
|
|
stack->entries_size = new_size; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
else |
76
|
0
|
|
|
|
|
|
return MyCSS_STATUS_ERROR_MEMORY_ALLOCATION; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
stack->entries[ stack->entries_length ].value = value; |
80
|
0
|
|
|
|
|
|
stack->entries[ stack->entries_length ].parser = parser; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
stack->entries_length++; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
return MyCSS_STATUS_OK; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
mycss_stack_entry_t * mycss_stack_pop(mycss_stack_t *stack) |
88
|
|
|
|
|
|
|
{ |
89
|
0
|
|
|
|
|
|
stack->entries_length--; |
90
|
0
|
|
|
|
|
|
return &stack->entries[ stack->entries_length ]; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
mycss_stack_entry_t * mycss_stack_current(mycss_stack_t *stack) |
94
|
|
|
|
|
|
|
{ |
95
|
0
|
0
|
|
|
|
|
if(stack->entries_length == 0) |
96
|
0
|
|
|
|
|
|
return NULL; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return &stack->entries[ (stack->entries_length - 1) ]; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|