From a3bcbfd610c513762a2a01dca3061960ffef16c0 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 21 Dec 2017 14:14:41 +0100 Subject: Rename, again, some types --- src/sp_var_parser.c | 58 ++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'src/sp_var_parser.c') 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 @@ #include "php_snuffleupagus.h" -static int parse_str_tokens(const char *str, const sp_token_t token, +static int parse_str_tokens(const char *str, const sp_conf_token token, sp_list_node *tokens_list) { const char *cur_str = str; - while ((cur_str = strchr(cur_str, token.token[0]))) { - if (0 == strncmp(cur_str, token.token, strlen(token.token))) { - sp_token_t *token_elm = pecalloc(sizeof(sp_token_t), 1, 1); + while ((cur_str = strchr(cur_str, token.text_repr[0]))) { + if (0 == strncmp(cur_str, token.text_repr, strlen(token.text_repr))) { + sp_conf_token *token_elm = pecalloc(sizeof(sp_conf_token), 1, 1); token_elm->pos = cur_str - str; - token_elm->token = token.token; + token_elm->text_repr = token.text_repr; token_elm->type = token.type; sp_list_insert(tokens_list, token_elm); - cur_str += strlen(token.token); + cur_str += strlen(token.text_repr); } else { cur_str++; } @@ -88,14 +88,14 @@ static int create_var(sp_tree *tree, const char *restrict value, } int cmp_tokens(sp_list_node *list1, sp_list_node *list2) { - return (((sp_token_t *)list1->data)->pos - - ((sp_token_t *)list2->data)->pos); + return (((sp_conf_token *)list1->data)->pos + - ((sp_conf_token *)list2->data)->pos); } -static int is_next_token_empty(sp_token_t *token, sp_token_t *token_next, +static int is_next_token_empty(sp_conf_token *token, sp_conf_token *token_next, const char * restrict str) { - if ((token_next && token_next->pos == token->pos + strlen(token->token)) - || (!token_next && token->pos == strlen(str) - strlen(token->token))) { + if ((token_next && token_next->pos == token->pos + strlen(token->text_repr)) + || (!token_next && token->pos == strlen(str) - strlen(token->text_repr))) { return -1; } return 0; @@ -104,11 +104,11 @@ static int is_next_token_empty(sp_token_t *token, sp_token_t *token_next, static int is_token_valid(sp_list_node *tokens_list, elem_type ignore, int array_count, const char * restrict str, size_t pos) { - sp_token_t *token = (sp_token_t *)tokens_list->data; - sp_token_t *token_next = NULL; + sp_conf_token *token = (sp_conf_token *)tokens_list->data; + sp_conf_token *token_next = NULL; if (tokens_list->next) { - token_next = (sp_token_t *)tokens_list->next->data; + token_next = (sp_conf_token *)tokens_list->next->data; } switch (token->type) { case ESC_STRING_DELIMITER: @@ -132,7 +132,7 @@ static int is_token_valid(sp_list_node *tokens_list, elem_type ignore, || token_next->type == ESC_STRING_DELIMITER) { return -1; } - } else if (token->pos != strlen(str) - strlen(token->token)) { + } else if (token->pos != strlen(str) - strlen(token->text_repr)) { return -1; } } @@ -164,22 +164,22 @@ static sp_tree *parse_tokens(const char * restrict str, sp_tree *tree = sp_tree_new(); for (; tokens_list && tokens_list->data; tokens_list = tokens_list->next) { - sp_token_t *token = (sp_token_t *)tokens_list->data; + sp_conf_token *token = (sp_conf_token *)tokens_list->data; size_t value_len; char *idx = NULL; if (-1 == is_token_valid(tokens_list, ignore, array_count, str, pos)) { - sp_log_err("config", "Invalid `%s` position.", token->token); + sp_log_err("config", "Invalid `%s` position.", token->text_repr); goto error; } if (token->type == STRING_DELIMITER || token->type == ESC_STRING_DELIMITER) { - pos = (!ignore && !array_count) ? pos + strlen(token->token) : pos; + pos = (!ignore && !array_count) ? pos + strlen(token->text_repr) : pos; ignore = (!ignore) ? token->type : (ignore == token->type) ? 0 : ignore; token->type = STRING_DELIMITER; } if (ignore == 0) { if (token->type == ARRAY) { - pos_idx_start = (array_count) ? pos_idx_start : (int)(token->pos + strlen(token->token)); + pos_idx_start = (array_count) ? pos_idx_start : (int)(token->pos + strlen(token->text_repr)); array_count++; } else if (token->type == ARRAY_END) { array_count--; @@ -188,7 +188,7 @@ static sp_tree *parse_tokens(const char * restrict str, if (array_count == 0) { value_len = token->pos - pos; if (token->type == ARRAY) { - value_len -= strlen(token->token); + value_len -= strlen(token->text_repr); } if (pos_idx_start > 0) { idx = estrndup(&(str[pos_idx_start]), token->pos - pos_idx_start); @@ -198,7 +198,7 @@ static sp_tree *parse_tokens(const char * restrict str, goto error; } efree(idx); - pos = token->pos + strlen(token->token); + pos = token->pos + strlen(token->text_repr); pos_idx_start = -1; } } @@ -219,13 +219,13 @@ error: sp_tree *parse_var(const char *line) { sp_list_node *tokens_list = NULL; sp_tree *tree = NULL; - const sp_token_t delimiter_list[] = { - {.type=OBJECT, .token=OBJECT_TOKEN}, - {.type=ARRAY, .token=ARRAY_TOKEN}, - {.type=ARRAY_END, .token=ARRAY_END_TOKEN}, - {.type=STRING_DELIMITER, .token=STRING_TOKEN}, - {.type=ESC_STRING_DELIMITER, .token=ESC_STRING_TOKEN}, - {.type=CLASS, .token=CLASS_TOKEN} + const sp_conf_token delimiter_list[] = { + {.type=OBJECT, .text_repr=OBJECT_TOKEN}, + {.type=ARRAY, .text_repr=ARRAY_TOKEN}, + {.type=ARRAY_END, .text_repr=ARRAY_END_TOKEN}, + {.type=STRING_DELIMITER, .text_repr=STRING_TOKEN}, + {.type=ESC_STRING_DELIMITER, .text_repr=ESC_STRING_TOKEN}, + {.type=CLASS, .text_repr=CLASS_TOKEN} }; @@ -233,7 +233,7 @@ sp_tree *parse_var(const char *line) { return NULL; } tokens_list = sp_list_new(); - for (unsigned int i = 0; i < sizeof(delimiter_list) / sizeof(sp_token_t); i++) { + for (unsigned int i = 0; i < sizeof(delimiter_list) / sizeof(sp_conf_token); i++) { parse_str_tokens(line, delimiter_list[i], tokens_list); } tokens_list = sp_list_sort(tokens_list, cmp_tokens); -- cgit v1.3