diff options
| author | Ben Fuhrmannek | 2021-02-16 11:16:59 +0100 |
|---|---|---|
| committer | Ben Fuhrmannek | 2021-02-16 11:16:59 +0100 |
| commit | 5484bcb5eb2714e7438927e2566c86a74d7c51af (patch) | |
| tree | b78326d2999397be4c08e06b23209981f82a4ea9 /src/sp_var_parser.c | |
| parent | 7ac1e3866ef4f146c6c93a5ca13b9aebb14e936a (diff) | |
| parent | cecfdd808da67be908dbe7144cc8c74dfb3f855e (diff) | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src/sp_var_parser.c')
| -rw-r--r-- | src/sp_var_parser.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/sp_var_parser.c b/src/sp_var_parser.c index 72cbc12..b066b84 100644 --- a/src/sp_var_parser.c +++ b/src/sp_var_parser.c | |||
| @@ -85,7 +85,8 @@ static int create_var(sp_tree *tree, const char *restrict value, | |||
| 85 | return 0; | 85 | return 0; |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | int cmp_tokens(sp_list_node *list1, sp_list_node *list2) { | 88 | int cmp_tokens(sp_list_node const *const list1, |
| 89 | sp_list_node const *const list2) { | ||
| 89 | return (((sp_conf_token *)list1->data)->pos - | 90 | return (((sp_conf_token *)list1->data)->pos - |
| 90 | ((sp_conf_token *)list2->data)->pos); | 91 | ((sp_conf_token *)list2->data)->pos); |
| 91 | } | 92 | } |
| @@ -123,7 +124,7 @@ static int is_token_valid(sp_list_node *tokens_list, elem_type quote, | |||
| 123 | } | 124 | } |
| 124 | break; | 125 | break; |
| 125 | case ARRAY_END: | 126 | case ARRAY_END: |
| 126 | if (!quote) { | 127 | if (UNDEFINED == quote) { |
| 127 | if (array_count < 1) { | 128 | if (array_count < 1) { |
| 128 | return -1; | 129 | return -1; |
| 129 | } else if (token_next) { | 130 | } else if (token_next) { |
| @@ -137,7 +138,8 @@ static int is_token_valid(sp_list_node *tokens_list, elem_type quote, | |||
| 137 | } | 138 | } |
| 138 | break; | 139 | break; |
| 139 | case OBJECT: | 140 | case OBJECT: |
| 140 | if (!quote && -1 == is_next_token_empty(token, token_next, str)) { | 141 | if (UNDEFINED == quote && |
| 142 | -1 == is_next_token_empty(token, token_next, str)) { | ||
| 141 | return -1; | 143 | return -1; |
| 142 | } | 144 | } |
| 143 | if (pos == 0 && *str != VARIABLE_TOKEN) { | 145 | if (pos == 0 && *str != VARIABLE_TOKEN) { |
| @@ -145,7 +147,8 @@ static int is_token_valid(sp_list_node *tokens_list, elem_type quote, | |||
| 145 | } | 147 | } |
| 146 | break; | 148 | break; |
| 147 | case CLASS: | 149 | case CLASS: |
| 148 | if (!quote && -1 == is_next_token_empty(token, token_next, str)) { | 150 | if (UNDEFINED == quote && |
| 151 | -1 == is_next_token_empty(token, token_next, str)) { | ||
| 149 | return -1; | 152 | return -1; |
| 150 | } | 153 | } |
| 151 | break; | 154 | break; |
| @@ -159,7 +162,7 @@ static sp_tree *parse_tokens(const char *restrict str, | |||
| 159 | sp_list_node *tokens_list) { | 162 | sp_list_node *tokens_list) { |
| 160 | size_t pos = 0; | 163 | size_t pos = 0; |
| 161 | int array_count = 0, pos_idx_start = -1; | 164 | int array_count = 0, pos_idx_start = -1; |
| 162 | elem_type quote = 0; | 165 | elem_type quote = UNDEFINED; |
| 163 | sp_tree *tree = sp_tree_new(); | 166 | sp_tree *tree = sp_tree_new(); |
| 164 | 167 | ||
| 165 | for (; tokens_list && tokens_list->data; tokens_list = tokens_list->next) { | 168 | for (; tokens_list && tokens_list->data; tokens_list = tokens_list->next) { |
| @@ -172,11 +175,15 @@ static sp_tree *parse_tokens(const char *restrict str, | |||
| 172 | goto error; | 175 | goto error; |
| 173 | } | 176 | } |
| 174 | if (token->type == INTERPRETED_STRING || token->type == LITERAL_STRING) { | 177 | if (token->type == INTERPRETED_STRING || token->type == LITERAL_STRING) { |
| 175 | pos = (!quote && !array_count) ? pos + strlen(token->text_repr) : pos; | 178 | pos = (UNDEFINED == quote && !array_count) |
| 176 | quote = (!quote) ? token->type : (quote == token->type) ? 0 : quote; | 179 | ? pos + strlen(token->text_repr) |
| 180 | : pos; | ||
| 181 | quote = (UNDEFINED == quote) ? token->type | ||
| 182 | : (quote == token->type) ? 0 | ||
| 183 | : quote; | ||
| 177 | token->type = INTERPRETED_STRING; | 184 | token->type = INTERPRETED_STRING; |
| 178 | } | 185 | } |
| 179 | if (quote == 0) { | 186 | if (UNDEFINED == quote) { |
| 180 | if (token->type == ARRAY) { | 187 | if (token->type == ARRAY) { |
| 181 | pos_idx_start = (array_count) | 188 | pos_idx_start = (array_count) |
| 182 | ? pos_idx_start | 189 | ? pos_idx_start |
| @@ -209,7 +216,7 @@ static sp_tree *parse_tokens(const char *restrict str, | |||
| 209 | sp_log_err("config", "You forgot to close a bracket."); | 216 | sp_log_err("config", "You forgot to close a bracket."); |
| 210 | goto error; | 217 | goto error; |
| 211 | } | 218 | } |
| 212 | if (quote != 0) { | 219 | if (quote != UNDEFINED) { |
| 213 | sp_log_err("config", "Missing a closing quote."); | 220 | sp_log_err("config", "Missing a closing quote."); |
| 214 | error: | 221 | error: |
| 215 | sp_tree_free(tree); | 222 | sp_tree_free(tree); |
