summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjvoisin2017-12-21 14:14:41 +0100
committerjvoisin2017-12-21 14:14:41 +0100
commita3bcbfd610c513762a2a01dca3061960ffef16c0 (patch)
tree2d9f004648000933dfdbe7d35781303faecd30b9 /src
parent0d98f51e7dbde4a40c0039910d43ad378eaefa83 (diff)
Rename, again, some types
Diffstat (limited to 'src')
-rw-r--r--src/sp_var_parser.c58
-rw-r--r--src/sp_var_parser.h6
2 files changed, 32 insertions, 32 deletions
diff --git a/src/sp_var_parser.c b/src/sp_var_parser.c
index 6ec415a..2b4c544 100644
--- a/src/sp_var_parser.c
+++ b/src/sp_var_parser.c
@@ -1,17 +1,17 @@
1#include "php_snuffleupagus.h" 1#include "php_snuffleupagus.h"
2 2
3static int parse_str_tokens(const char *str, const sp_token_t token, 3static int parse_str_tokens(const char *str, const sp_conf_token token,
4 sp_list_node *tokens_list) { 4 sp_list_node *tokens_list) {
5 const char *cur_str = str; 5 const char *cur_str = str;
6 6
7 while ((cur_str = strchr(cur_str, token.token[0]))) { 7 while ((cur_str = strchr(cur_str, token.text_repr[0]))) {
8 if (0 == strncmp(cur_str, token.token, strlen(token.token))) { 8 if (0 == strncmp(cur_str, token.text_repr, strlen(token.text_repr))) {
9 sp_token_t *token_elm = pecalloc(sizeof(sp_token_t), 1, 1); 9 sp_conf_token *token_elm = pecalloc(sizeof(sp_conf_token), 1, 1);
10 token_elm->pos = cur_str - str; 10 token_elm->pos = cur_str - str;
11 token_elm->token = token.token; 11 token_elm->text_repr = token.text_repr;
12 token_elm->type = token.type; 12 token_elm->type = token.type;
13 sp_list_insert(tokens_list, token_elm); 13 sp_list_insert(tokens_list, token_elm);
14 cur_str += strlen(token.token); 14 cur_str += strlen(token.text_repr);
15 } else { 15 } else {
16 cur_str++; 16 cur_str++;
17 } 17 }
@@ -88,14 +88,14 @@ static int create_var(sp_tree *tree, const char *restrict value,
88} 88}
89 89
90int cmp_tokens(sp_list_node *list1, sp_list_node *list2) { 90int cmp_tokens(sp_list_node *list1, sp_list_node *list2) {
91 return (((sp_token_t *)list1->data)->pos 91 return (((sp_conf_token *)list1->data)->pos
92 - ((sp_token_t *)list2->data)->pos); 92 - ((sp_conf_token *)list2->data)->pos);
93} 93}
94 94
95static int is_next_token_empty(sp_token_t *token, sp_token_t *token_next, 95static int is_next_token_empty(sp_conf_token *token, sp_conf_token *token_next,
96 const char * restrict str) { 96 const char * restrict str) {
97 if ((token_next && token_next->pos == token->pos + strlen(token->token)) 97 if ((token_next && token_next->pos == token->pos + strlen(token->text_repr))
98 || (!token_next && token->pos == strlen(str) - strlen(token->token))) { 98 || (!token_next && token->pos == strlen(str) - strlen(token->text_repr))) {
99 return -1; 99 return -1;
100 } 100 }
101 return 0; 101 return 0;
@@ -104,11 +104,11 @@ static int is_next_token_empty(sp_token_t *token, sp_token_t *token_next,
104static int is_token_valid(sp_list_node *tokens_list, elem_type ignore, 104static int is_token_valid(sp_list_node *tokens_list, elem_type ignore,
105 int array_count, const char * restrict str, 105 int array_count, const char * restrict str,
106 size_t pos) { 106 size_t pos) {
107 sp_token_t *token = (sp_token_t *)tokens_list->data; 107 sp_conf_token *token = (sp_conf_token *)tokens_list->data;
108 sp_token_t *token_next = NULL; 108 sp_conf_token *token_next = NULL;
109 109
110 if (tokens_list->next) { 110 if (tokens_list->next) {
111 token_next = (sp_token_t *)tokens_list->next->data; 111 token_next = (sp_conf_token *)tokens_list->next->data;
112 } 112 }
113 switch (token->type) { 113 switch (token->type) {
114 case ESC_STRING_DELIMITER: 114 case ESC_STRING_DELIMITER:
@@ -132,7 +132,7 @@ static int is_token_valid(sp_list_node *tokens_list, elem_type ignore,
132 || token_next->type == ESC_STRING_DELIMITER) { 132 || token_next->type == ESC_STRING_DELIMITER) {
133 return -1; 133 return -1;
134 } 134 }
135 } else if (token->pos != strlen(str) - strlen(token->token)) { 135 } else if (token->pos != strlen(str) - strlen(token->text_repr)) {
136 return -1; 136 return -1;
137 } 137 }
138 } 138 }
@@ -164,22 +164,22 @@ static sp_tree *parse_tokens(const char * restrict str,
164 sp_tree *tree = sp_tree_new(); 164 sp_tree *tree = sp_tree_new();
165 165
166 for (; tokens_list && tokens_list->data; tokens_list = tokens_list->next) { 166 for (; tokens_list && tokens_list->data; tokens_list = tokens_list->next) {
167 sp_token_t *token = (sp_token_t *)tokens_list->data; 167 sp_conf_token *token = (sp_conf_token *)tokens_list->data;
168 size_t value_len; 168 size_t value_len;
169 char *idx = NULL; 169 char *idx = NULL;
170 170
171 if (-1 == is_token_valid(tokens_list, ignore, array_count, str, pos)) { 171 if (-1 == is_token_valid(tokens_list, ignore, array_count, str, pos)) {
172 sp_log_err("config", "Invalid `%s` position.", token->token); 172 sp_log_err("config", "Invalid `%s` position.", token->text_repr);
173 goto error; 173 goto error;
174 } 174 }
175 if (token->type == STRING_DELIMITER || token->type == ESC_STRING_DELIMITER) { 175 if (token->type == STRING_DELIMITER || token->type == ESC_STRING_DELIMITER) {
176 pos = (!ignore && !array_count) ? pos + strlen(token->token) : pos; 176 pos = (!ignore && !array_count) ? pos + strlen(token->text_repr) : pos;
177 ignore = (!ignore) ? token->type : (ignore == token->type) ? 0 : ignore; 177 ignore = (!ignore) ? token->type : (ignore == token->type) ? 0 : ignore;
178 token->type = STRING_DELIMITER; 178 token->type = STRING_DELIMITER;
179 } 179 }
180 if (ignore == 0) { 180 if (ignore == 0) {
181 if (token->type == ARRAY) { 181 if (token->type == ARRAY) {
182 pos_idx_start = (array_count) ? pos_idx_start : (int)(token->pos + strlen(token->token)); 182 pos_idx_start = (array_count) ? pos_idx_start : (int)(token->pos + strlen(token->text_repr));
183 array_count++; 183 array_count++;
184 } else if (token->type == ARRAY_END) { 184 } else if (token->type == ARRAY_END) {
185 array_count--; 185 array_count--;
@@ -188,7 +188,7 @@ static sp_tree *parse_tokens(const char * restrict str,
188 if (array_count == 0) { 188 if (array_count == 0) {
189 value_len = token->pos - pos; 189 value_len = token->pos - pos;
190 if (token->type == ARRAY) { 190 if (token->type == ARRAY) {
191 value_len -= strlen(token->token); 191 value_len -= strlen(token->text_repr);
192 } 192 }
193 if (pos_idx_start > 0) { 193 if (pos_idx_start > 0) {
194 idx = estrndup(&(str[pos_idx_start]), token->pos - pos_idx_start); 194 idx = estrndup(&(str[pos_idx_start]), token->pos - pos_idx_start);
@@ -198,7 +198,7 @@ static sp_tree *parse_tokens(const char * restrict str,
198 goto error; 198 goto error;
199 } 199 }
200 efree(idx); 200 efree(idx);
201 pos = token->pos + strlen(token->token); 201 pos = token->pos + strlen(token->text_repr);
202 pos_idx_start = -1; 202 pos_idx_start = -1;
203 } 203 }
204 } 204 }
@@ -219,13 +219,13 @@ error:
219sp_tree *parse_var(const char *line) { 219sp_tree *parse_var(const char *line) {
220 sp_list_node *tokens_list = NULL; 220 sp_list_node *tokens_list = NULL;
221 sp_tree *tree = NULL; 221 sp_tree *tree = NULL;
222 const sp_token_t delimiter_list[] = { 222 const sp_conf_token delimiter_list[] = {
223 {.type=OBJECT, .token=OBJECT_TOKEN}, 223 {.type=OBJECT, .text_repr=OBJECT_TOKEN},
224 {.type=ARRAY, .token=ARRAY_TOKEN}, 224 {.type=ARRAY, .text_repr=ARRAY_TOKEN},
225 {.type=ARRAY_END, .token=ARRAY_END_TOKEN}, 225 {.type=ARRAY_END, .text_repr=ARRAY_END_TOKEN},
226 {.type=STRING_DELIMITER, .token=STRING_TOKEN}, 226 {.type=STRING_DELIMITER, .text_repr=STRING_TOKEN},
227 {.type=ESC_STRING_DELIMITER, .token=ESC_STRING_TOKEN}, 227 {.type=ESC_STRING_DELIMITER, .text_repr=ESC_STRING_TOKEN},
228 {.type=CLASS, .token=CLASS_TOKEN} 228 {.type=CLASS, .text_repr=CLASS_TOKEN}
229 }; 229 };
230 230
231 231
@@ -233,7 +233,7 @@ sp_tree *parse_var(const char *line) {
233 return NULL; 233 return NULL;
234 } 234 }
235 tokens_list = sp_list_new(); 235 tokens_list = sp_list_new();
236 for (unsigned int i = 0; i < sizeof(delimiter_list) / sizeof(sp_token_t); i++) { 236 for (unsigned int i = 0; i < sizeof(delimiter_list) / sizeof(sp_conf_token); i++) {
237 parse_str_tokens(line, delimiter_list[i], tokens_list); 237 parse_str_tokens(line, delimiter_list[i], tokens_list);
238 } 238 }
239 tokens_list = sp_list_sort(tokens_list, cmp_tokens); 239 tokens_list = sp_list_sort(tokens_list, cmp_tokens);
diff --git a/src/sp_var_parser.h b/src/sp_var_parser.h
index eec77c9..4a26e58 100644
--- a/src/sp_var_parser.h
+++ b/src/sp_var_parser.h
@@ -4,9 +4,9 @@
4 4
5typedef struct sp_token_s { 5typedef struct sp_token_s {
6 elem_type type; 6 elem_type type;
7 char *token; 7 char *text_repr;
8 unsigned int pos; 8 size_t pos;
9} sp_token_t; 9} sp_conf_token;
10 10
11zval *get_value(zend_execute_data *, const sp_tree *, bool); 11zval *get_value(zend_execute_data *, const sp_tree *, bool);
12sp_tree *parse_var(const char *); 12sp_tree *parse_var(const char *);