Lines Matching +full:p +full:- +full:state

48 #define ucl_chunk_skipc(chunk, p)    \  argument
50 if (*(p) == '\n') { \
51 (chunk)->line ++; \
52 (chunk)->column = 0; \
54 else (chunk)->column ++; \
55 (p++); \
56 (chunk)->pos ++; \
57 (chunk)->remain --; \
64 struct ucl_chunk *chunk = parser->chunks; in ucl_set_err()
66 if (parser->cur_file) { in ucl_set_err()
67 filename = parser->cur_file; in ucl_set_err()
73 if (chunk->pos < chunk->end) { in ucl_set_err()
74 if (isgraph (*chunk->pos)) { in ucl_set_err()
76 "line: %d, column: %d - '%s', character: '%c'"; in ucl_set_err()
80 "line: %d, column: %d - '%s', character: '0x%02x'"; in ucl_set_err()
83 filename, chunk->line, chunk->column, in ucl_set_err()
84 str, *chunk->pos); in ucl_set_err()
91 parser->err_code = code; in ucl_set_err()
92 parser->state = UCL_STATE_ERROR; in ucl_set_err()
103 if (parser->last_comment) { in ucl_save_comment()
105 DL_APPEND (parser->last_comment, nobj); in ucl_save_comment()
108 parser->last_comment = nobj; in ucl_save_comment()
116 if (parser->last_comment) { in ucl_attach_comment()
117 ucl_object_insert_key (parser->comments, parser->last_comment, in ucl_attach_comment()
121 parser->last_comment->flags |= UCL_OBJECT_INHERITED; in ucl_attach_comment()
124 parser->last_comment = NULL; in ucl_attach_comment()
136 struct ucl_chunk *chunk = parser->chunks; in ucl_skip_comments()
137 const unsigned char *p, *beg = NULL; in ucl_skip_comments() local
141 p = chunk->pos; in ucl_skip_comments()
144 if (chunk->remain > 0 && *p == '#') { in ucl_skip_comments()
145 if (parser->state != UCL_STATE_SCOMMENT && in ucl_skip_comments()
146 parser->state != UCL_STATE_MCOMMENT) { in ucl_skip_comments()
147 beg = p; in ucl_skip_comments()
149 while (p < chunk->end) { in ucl_skip_comments()
150 if (*p == '\n') { in ucl_skip_comments()
151 if (parser->flags & UCL_PARSER_SAVE_COMMENTS) { in ucl_skip_comments()
152 ucl_save_comment (parser, beg, p - beg); in ucl_skip_comments()
156 ucl_chunk_skipc (chunk, p); in ucl_skip_comments()
160 ucl_chunk_skipc (chunk, p); in ucl_skip_comments()
164 else if (chunk->remain >= 2 && *p == '/') { in ucl_skip_comments()
165 if (p[1] == '*') { in ucl_skip_comments()
166 beg = p; in ucl_skip_comments()
167 ucl_chunk_skipc (chunk, p); in ucl_skip_comments()
169 ucl_chunk_skipc (chunk, p); in ucl_skip_comments()
171 while (p < chunk->end) { in ucl_skip_comments()
172 if (*p == '"' && *(p - 1) != '\\') { in ucl_skip_comments()
177 if (*p == '*') { in ucl_skip_comments()
178 ucl_chunk_skipc (chunk, p); in ucl_skip_comments()
179 if (*p == '/') { in ucl_skip_comments()
180 comments_nested --; in ucl_skip_comments()
182 if (parser->flags & UCL_PARSER_SAVE_COMMENTS) { in ucl_skip_comments()
183 ucl_save_comment (parser, beg, p - beg + 1); in ucl_skip_comments()
187 ucl_chunk_skipc (chunk, p); in ucl_skip_comments()
191 ucl_chunk_skipc (chunk, p); in ucl_skip_comments()
193 else if (p[0] == '/' && chunk->remain >= 2 && p[1] == '*') { in ucl_skip_comments()
195 ucl_chunk_skipc (chunk, p); in ucl_skip_comments()
196 ucl_chunk_skipc (chunk, p); in ucl_skip_comments()
201 ucl_chunk_skipc (chunk, p); in ucl_skip_comments()
205 "unfinished multiline comment", &parser->err); in ucl_skip_comments()
211 if (beg && p > beg && (parser->flags & UCL_PARSER_SAVE_COMMENTS)) { in ucl_skip_comments()
212 ucl_save_comment (parser, beg, p - beg); in ucl_skip_comments()
322 LL_FOREACH (parser->variables, var) { in ucl_check_variable_safe()
324 if (remain == var->var_len) { in ucl_check_variable_safe()
325 if (memcmp (ptr, var->var, var->var_len) == 0) { in ucl_check_variable_safe()
326 *out_len += var->value_len; in ucl_check_variable_safe()
328 return (ptr + var->var_len); in ucl_check_variable_safe()
333 if (remain >= var->var_len) { in ucl_check_variable_safe()
334 if (memcmp (ptr, var->var, var->var_len) == 0) { in ucl_check_variable_safe()
335 *out_len += var->value_len; in ucl_check_variable_safe()
337 return (ptr + var->var_len); in ucl_check_variable_safe()
344 if (!(*found) && parser->var_handler != NULL && strict) { in ucl_check_variable_safe()
346 if (parser->var_handler (ptr, remain, &dst, &dstlen, &need_free, in ucl_check_variable_safe()
347 parser->var_data)) { in ucl_check_variable_safe()
373 const char *p, *end, *ret = ptr; in ucl_check_variable() local
378 p = ptr + 1; in ucl_check_variable()
380 while (p < end) { in ucl_check_variable()
381 if (*p == '}') { in ucl_check_variable()
382 ret = ucl_check_variable_safe (parser, ptr + 1, p - ptr - 1, in ucl_check_variable()
396 p ++; in ucl_check_variable()
430 const char *p = ptr + 1, *ret; in ucl_expand_single_variable() local
438 remain --; in ucl_expand_single_variable()
440 if (*p == '$') { in ucl_expand_single_variable()
441 *d++ = *p++; in ucl_expand_single_variable()
443 return p; in ucl_expand_single_variable()
445 else if (*p == '{') { in ucl_expand_single_variable()
446 p ++; in ucl_expand_single_variable()
449 remain -= 2; in ucl_expand_single_variable()
452 LL_FOREACH (parser->variables, var) { in ucl_expand_single_variable()
453 if (remain >= var->var_len) { in ucl_expand_single_variable()
454 if (memcmp (p, var->var, var->var_len) == 0) { in ucl_expand_single_variable()
455 memcpy (d, var->value, var->value_len); in ucl_expand_single_variable()
456 ret += var->var_len; in ucl_expand_single_variable()
457 d += var->value_len; in ucl_expand_single_variable()
464 if (strict && parser->var_handler != NULL) { in ucl_expand_single_variable()
465 if (parser->var_handler (p, remain, &dst, &dstlen, &need_free, in ucl_expand_single_variable()
466 parser->var_data)) { in ucl_expand_single_variable()
483 ret --; in ucl_expand_single_variable()
508 const char *p, *end = src + in_len; in ucl_expand_variable() local
513 if (parser->flags & UCL_PARSER_DISABLE_MACRO) { in ucl_expand_variable()
518 p = src; in ucl_expand_variable()
519 while (p != end) { in ucl_expand_variable()
520 if (*p == '$') { in ucl_expand_variable()
521 p = ucl_check_variable (parser, p + 1, end - p - 1, &out_len, &vars_found); in ucl_expand_variable()
524 p ++; in ucl_expand_variable()
541 p = src; in ucl_expand_variable()
542 while (p != end) { in ucl_expand_variable()
543 if (*p == '$') { in ucl_expand_variable()
544 p = ucl_expand_single_variable (parser, p, end - p, &d); in ucl_expand_variable()
547 *d++ = *p++; in ucl_expand_variable()
576 ssize_t ret = -1, tret; in ucl_copy_or_store_ptr()
580 (need_expand && parser->variables != NULL) || in ucl_copy_or_store_ptr()
581 !(parser->flags & UCL_PARSER_ZEROCOPY)) { in ucl_copy_or_store_ptr()
586 &parser->err); in ucl_copy_or_store_ptr()
644 nobj = ucl_object_new_full (is_array ? UCL_ARRAY : UCL_OBJECT, parser->chunks->priority); in ucl_parser_add_container()
649 if (obj->type == (is_array ? UCL_OBJECT : UCL_ARRAY)) { in ucl_parser_add_container()
653 &parser->err); in ucl_parser_add_container()
658 nobj->type = is_array ? UCL_ARRAY : UCL_OBJECT; in ucl_parser_add_container()
662 if (nobj->value.ov == NULL) { in ucl_parser_add_container()
663 nobj->value.ov = ucl_hash_create (parser->flags & UCL_PARSER_KEY_LOWERCASE); in ucl_parser_add_container()
664 if (nobj->value.ov == NULL) { in ucl_parser_add_container()
668 parser->state = UCL_STATE_KEY; in ucl_parser_add_container()
670 parser->state = UCL_STATE_VALUE; in ucl_parser_add_container()
679 st->obj = nobj; in ucl_parser_add_container()
684 &parser->err); in ucl_parser_add_container()
693 st->e.params.level = level; in ucl_parser_add_container()
694 st->e.params.line = parser->chunks->line; in ucl_parser_add_container()
695 st->chunk = parser->chunks; in ucl_parser_add_container()
698 st->e.params.flags = UCL_STACK_HAS_OBRACE; in ucl_parser_add_container()
701 st->e.params.flags = 0; in ucl_parser_add_container()
704 LL_PREPEND (parser->stack, st); in ucl_parser_add_container()
705 parser->cur_obj = nobj; in ucl_parser_add_container()
713 &parser->err); in ucl_parser_add_container()
722 const char *p = start, *c = start; in ucl_maybe_parse_number() local
730 if (*p == '-') { in ucl_maybe_parse_number()
733 p ++; in ucl_maybe_parse_number()
735 while (p < end) { in ucl_maybe_parse_number()
736 if (is_hex && isxdigit (*p)) { in ucl_maybe_parse_number()
737 p ++; in ucl_maybe_parse_number()
739 else if (isdigit (*p)) { in ucl_maybe_parse_number()
741 p ++; in ucl_maybe_parse_number()
743 else if (!is_hex && (*p == 'x' || *p == 'X')) { in ucl_maybe_parse_number()
746 c = p + 1; in ucl_maybe_parse_number()
749 if (p == c) { in ucl_maybe_parse_number()
754 else if (*p == '.') { in ucl_maybe_parse_number()
763 p ++; in ucl_maybe_parse_number()
766 else if (*p == 'e' || *p == 'E') { in ucl_maybe_parse_number()
775 p ++; in ucl_maybe_parse_number()
776 if (p >= end) { in ucl_maybe_parse_number()
780 if (!isdigit (*p) && *p != '+' && *p != '-') { in ucl_maybe_parse_number()
786 p ++; in ucl_maybe_parse_number()
824 p = endptr; in ucl_maybe_parse_number()
829 p = endptr; in ucl_maybe_parse_number()
830 switch (*p) { in ucl_maybe_parse_number()
837 if (end - p >= 2) { in ucl_maybe_parse_number()
838 if (p[1] == 's' || p[1] == 'S') { in ucl_maybe_parse_number()
845 if (p[0] == 'm' || p[0] == 'M') { in ucl_maybe_parse_number()
849 dv *= ucl_lex_num_multiplier (*p, false); in ucl_maybe_parse_number()
851 p += 2; in ucl_maybe_parse_number()
854 else if (number_bytes || (p[1] == 'b' || p[1] == 'B')) { in ucl_maybe_parse_number()
860 lv *= ucl_lex_num_multiplier (*p, true); in ucl_maybe_parse_number()
861 p += 2; in ucl_maybe_parse_number()
864 else if (ucl_lex_is_atom_end (p[1])) { in ucl_maybe_parse_number()
866 dv *= ucl_lex_num_multiplier (*p, false); in ucl_maybe_parse_number()
869 lv *= ucl_lex_num_multiplier (*p, number_bytes); in ucl_maybe_parse_number()
871 p ++; in ucl_maybe_parse_number()
874 else if (allow_time && end - p >= 3) { in ucl_maybe_parse_number()
875 if (tolower (p[0]) == 'm' && in ucl_maybe_parse_number()
876 tolower (p[1]) == 'i' && in ucl_maybe_parse_number()
877 tolower (p[2]) == 'n') { in ucl_maybe_parse_number()
885 p += 3; in ucl_maybe_parse_number()
892 dv *= ucl_lex_num_multiplier (*p, false); in ucl_maybe_parse_number()
895 lv *= ucl_lex_num_multiplier (*p, number_bytes); in ucl_maybe_parse_number()
897 p ++; in ucl_maybe_parse_number()
904 (p == end - 1 || ucl_lex_is_atom_end (p[1]))) { in ucl_maybe_parse_number()
909 p ++; in ucl_maybe_parse_number()
923 (p == end - 1 || ucl_lex_is_atom_end (p[1]))) { in ucl_maybe_parse_number()
929 dv *= ucl_lex_time_multiplier (*p); in ucl_maybe_parse_number()
930 p ++; in ucl_maybe_parse_number()
936 while (p < end && ucl_test_character(*p, UCL_CHARACTER_WHITESPACE)) { in ucl_maybe_parse_number()
937 p++; in ucl_maybe_parse_number()
939 if (ucl_lex_is_atom_end(*p)) in ucl_maybe_parse_number()
946 p = endptr; in ucl_maybe_parse_number()
957 obj->type = UCL_FLOAT; in ucl_maybe_parse_number()
960 obj->type = UCL_TIME; in ucl_maybe_parse_number()
962 obj->value.dv = is_neg ? (-dv) : dv; in ucl_maybe_parse_number()
965 obj->type = UCL_INT; in ucl_maybe_parse_number()
966 obj->value.iv = is_neg ? (-lv) : lv; in ucl_maybe_parse_number()
969 *pos = p; in ucl_maybe_parse_number()
987 ret = ucl_maybe_parse_number (obj, chunk->pos, chunk->end, (const char **)&pos, in ucl_lex_number()
988 true, false, ((parser->flags & UCL_PARSER_NO_TIME) == 0)); in ucl_lex_number()
991 chunk->remain -= pos - chunk->pos; in ucl_lex_number()
992 chunk->column += pos - chunk->pos; in ucl_lex_number()
993 chunk->pos = pos; in ucl_lex_number()
998 &parser->err); in ucl_lex_number()
1020 const unsigned char *p = chunk->pos; in ucl_lex_json_string() local
1024 while (p < chunk->end) { in ucl_lex_json_string()
1025 c = *p; in ucl_lex_json_string()
1030 &parser->err); in ucl_lex_json_string()
1034 &parser->err); in ucl_lex_json_string()
1039 ucl_chunk_skipc (chunk, p); in ucl_lex_json_string()
1040 c = *p; in ucl_lex_json_string()
1041 if (p >= chunk->end) { in ucl_lex_json_string()
1043 &parser->err); in ucl_lex_json_string()
1048 ucl_chunk_skipc (chunk, p); in ucl_lex_json_string()
1049 for (i = 0; i < 4 && p < chunk->end; i ++) { in ucl_lex_json_string()
1050 if (!isxdigit (*p)) { in ucl_lex_json_string()
1052 &parser->err); in ucl_lex_json_string()
1055 ucl_chunk_skipc (chunk, p); in ucl_lex_json_string()
1057 if (p >= chunk->end) { in ucl_lex_json_string()
1060 &parser->err); in ucl_lex_json_string()
1065 ucl_chunk_skipc (chunk, p); in ucl_lex_json_string()
1073 ucl_chunk_skipc (chunk, p); in ucl_lex_json_string()
1082 ucl_chunk_skipc (chunk, p); in ucl_lex_json_string()
1087 &parser->err); in ucl_lex_json_string()
1102 const unsigned char *p = chunk->pos; in ucl_lex_squoted_string() local
1105 while (p < chunk->end) { in ucl_lex_squoted_string()
1106 c = *p; in ucl_lex_squoted_string()
1108 ucl_chunk_skipc (chunk, p); in ucl_lex_squoted_string()
1110 if (p >= chunk->end) { in ucl_lex_squoted_string()
1113 &parser->err); in ucl_lex_squoted_string()
1117 ucl_chunk_skipc (chunk, p); in ucl_lex_squoted_string()
1124 ucl_chunk_skipc (chunk, p); in ucl_lex_squoted_string()
1128 ucl_chunk_skipc (chunk, p); in ucl_lex_squoted_string()
1133 &parser->err); in ucl_lex_squoted_string()
1144 if ((parser->flags & UCL_PARSER_NO_IMPLICIT_ARRAYS) == 0) { in ucl_parser_append_elt()
1146 top->flags |= UCL_OBJECT_MULTIVALUE; in ucl_parser_append_elt()
1148 parser->stack->obj->len ++; in ucl_parser_append_elt()
1151 if ((top->flags & UCL_OBJECT_MULTIVALUE) != 0) { in ucl_parser_append_elt()
1158 nobj->key = top->key; in ucl_parser_append_elt()
1159 nobj->keylen = top->keylen; in ucl_parser_append_elt()
1160 nobj->flags |= UCL_OBJECT_MULTIVALUE; in ucl_parser_append_elt()
1175 container = parser->stack->obj->value.ov; in ucl_parser_process_object_element()
1177 DL_FOREACH (parser->stack->obj, cur) { in ucl_parser_process_object_element()
1178 tobj = __DECONST (ucl_object_t *, ucl_hash_search_obj (cur->value.ov, nobj)); in ucl_parser_process_object_element()
1188 parser->flags & UCL_PARSER_KEY_LOWERCASE); in ucl_parser_process_object_element()
1192 nobj->prev = nobj; in ucl_parser_process_object_element()
1193 nobj->next = NULL; in ucl_parser_process_object_element()
1194 parser->stack->obj->len ++; in ucl_parser_process_object_element()
1199 switch (parser->chunks->strategy) { in ucl_parser_process_object_element()
1205 * - if we have two objects with the same priority, then we form an in ucl_parser_process_object_element()
1207 * - if a new object has bigger priority, then we overwrite an old one in ucl_parser_process_object_element()
1208 * - if a new object has lower priority, then we ignore it in ucl_parser_process_object_element()
1211 if (tobj->flags & UCL_OBJECT_INHERITED) { in ucl_parser_process_object_element()
1224 DL_APPEND (parser->trash_objs, nobj); in ucl_parser_process_object_element()
1243 nobj->key); in ucl_parser_process_object_element()
1244 ucl_set_err (parser, UCL_EMERGE, errmsg, &parser->err); in ucl_parser_process_object_element()
1252 if (tobj->type == UCL_OBJECT || tobj->type == UCL_ARRAY) { in ucl_parser_process_object_element()
1265 DL_APPEND (parser->trash_objs, nobj); in ucl_parser_process_object_element()
1275 parser->stack->obj->value.ov = container; in ucl_parser_process_object_element()
1276 parser->cur_obj = nobj; in ucl_parser_process_object_element()
1294 const unsigned char *p, *c = NULL, *end, *t; in ucl_parse_key() local
1302 p = chunk->pos; in ucl_parse_key()
1304 if (*p == '.') { in ucl_parse_key()
1306 if (!(parser->flags & UCL_PARSER_DISABLE_MACRO)) { in ucl_parse_key()
1307 ucl_chunk_skipc (chunk, p); in ucl_parse_key()
1310 parser->prev_state = parser->state; in ucl_parse_key()
1311 parser->state = UCL_STATE_MACRO_NAME; in ucl_parse_key()
1315 while (p < chunk->end) { in ucl_parse_key()
1320 if (chunk->remain >= 2 && ucl_lex_is_comment (p[0], p[1])) { in ucl_parse_key()
1324 p = chunk->pos; in ucl_parse_key()
1326 else if (ucl_test_character (*p, UCL_CHARACTER_WHITESPACE_UNSAFE)) { in ucl_parse_key()
1327 ucl_chunk_skipc (chunk, p); in ucl_parse_key()
1329 else if (ucl_test_character (*p, UCL_CHARACTER_KEY_START)) { in ucl_parse_key()
1331 c = p; in ucl_parse_key()
1332 ucl_chunk_skipc (chunk, p); in ucl_parse_key()
1335 else if (*p == '"') { in ucl_parse_key()
1337 c = p + 1; in ucl_parse_key()
1340 ucl_chunk_skipc (chunk, p); in ucl_parse_key()
1342 else if (*p == '}') { in ucl_parse_key()
1347 else if (*p == '.') { in ucl_parse_key()
1348 ucl_chunk_skipc (chunk, p); in ucl_parse_key()
1349 parser->prev_state = parser->state; in ucl_parse_key()
1350 parser->state = UCL_STATE_MACRO_NAME; in ucl_parse_key()
1356 &parser->err); in ucl_parse_key()
1363 if (ucl_test_character (*p, UCL_CHARACTER_KEY)) { in ucl_parse_key()
1365 ucl_chunk_skipc (chunk, p); in ucl_parse_key()
1367 else if (ucl_test_character (*p, UCL_CHARACTER_KEY_SEP)) { in ucl_parse_key()
1368 end = p; in ucl_parse_key()
1373 &parser->err); in ucl_parse_key()
1383 end = chunk->pos - 1; in ucl_parse_key()
1384 p = chunk->pos; in ucl_parse_key()
1390 if (p >= chunk->end && got_content) { in ucl_parse_key()
1391 ucl_set_err (parser, UCL_ESYNTAX, "unfinished key", &parser->err); in ucl_parse_key()
1399 while (p < chunk->end) { in ucl_parse_key()
1400 if (ucl_test_character (*p, UCL_CHARACTER_WHITESPACE)) { in ucl_parse_key()
1401 ucl_chunk_skipc (chunk, p); in ucl_parse_key()
1403 else if (*p == '=') { in ucl_parse_key()
1405 ucl_chunk_skipc (chunk, p); in ucl_parse_key()
1410 &parser->err); in ucl_parse_key()
1414 else if (*p == ':') { in ucl_parse_key()
1416 ucl_chunk_skipc (chunk, p); in ucl_parse_key()
1421 &parser->err); in ucl_parse_key()
1425 else if (chunk->remain >= 2 && ucl_lex_is_comment (p[0], p[1])) { in ucl_parse_key()
1430 p = chunk->pos; in ucl_parse_key()
1438 if (p >= chunk->end && got_content) { in ucl_parse_key()
1439 ucl_set_err (parser, UCL_ESYNTAX, "unfinished key", &parser->err); in ucl_parse_key()
1449 * 1) key1 key2 ... keyN [:=] value <- we treat that as error in ucl_parse_key()
1450 * 2) key1 ... keyN {} or [] <- we treat that as nested objects in ucl_parse_key()
1451 * 3) key1 value[;,\n] <- we treat that as linear object in ucl_parse_key()
1453 t = p; in ucl_parse_key()
1458 /* Check first non-space character after a key */ in ucl_parse_key()
1460 while (t < chunk->end) { in ucl_parse_key()
1474 nobj = ucl_object_new_full (UCL_NULL, parser->chunks->priority); in ucl_parse_key()
1478 keylen = ucl_copy_or_store_ptr (parser, c, &nobj->trash_stack[UCL_TRASH_KEY], in ucl_parse_key()
1479 &key, end - c, need_unescape, parser->flags & UCL_PARSER_KEY_LOWERCASE, in ucl_parse_key()
1481 if (keylen == -1) { in ucl_parse_key()
1486 ucl_set_err (parser, UCL_ESYNTAX, "empty keys are not allowed", &parser->err); in ucl_parse_key()
1491 nobj->key = key; in ucl_parse_key()
1492 nobj->keylen = keylen; in ucl_parse_key()
1499 nobj->flags |= UCL_OBJECT_NEED_KEY_ESCAPE; in ucl_parse_key()
1518 const unsigned char *p; in ucl_parse_string_value() local
1526 p = chunk->pos; in ucl_parse_string_value()
1528 while (p < chunk->end) { in ucl_parse_string_value()
1531 if (*p == '{') { in ucl_parse_string_value()
1534 else if (*p == '}') { in ucl_parse_string_value()
1538 ucl_chunk_skipc (chunk, p); in ucl_parse_string_value()
1543 else if (*p == '[') { in ucl_parse_string_value()
1546 else if (*p == ']') { in ucl_parse_string_value()
1550 ucl_chunk_skipc (chunk, p); in ucl_parse_string_value()
1554 else if (*p == '$') { in ucl_parse_string_value()
1557 else if (*p == '\\') { in ucl_parse_string_value()
1559 ucl_chunk_skipc (chunk, p); in ucl_parse_string_value()
1560 if (p < chunk->end) { in ucl_parse_string_value()
1561 ucl_chunk_skipc (chunk, p); in ucl_parse_string_value()
1566 if (ucl_lex_is_atom_end (*p) || (chunk->remain >= 2 && ucl_lex_is_comment (p[0], p[1]))) { in ucl_parse_string_value()
1569 ucl_chunk_skipc (chunk, p); in ucl_parse_string_value()
1591 const unsigned char *p, *c, *tend; in ucl_parse_multiline_string() local
1595 p = chunk->pos; in ucl_parse_multiline_string()
1597 c = p; in ucl_parse_multiline_string()
1599 while (p < chunk->end) { in ucl_parse_multiline_string()
1601 if (chunk->end - p < term_len) { in ucl_parse_multiline_string()
1604 else if (memcmp (p, term, term_len) == 0) { in ucl_parse_multiline_string()
1605 tend = p + term_len; in ucl_parse_multiline_string()
1608 ucl_chunk_skipc (chunk, p); in ucl_parse_multiline_string()
1611 len = p - c; in ucl_parse_multiline_string()
1612 chunk->remain -= term_len; in ucl_parse_multiline_string()
1613 chunk->pos = p + term_len; in ucl_parse_multiline_string()
1614 chunk->column = term_len; in ucl_parse_multiline_string()
1619 if (*p == '\n') { in ucl_parse_multiline_string()
1623 if (*p == '$') { in ucl_parse_multiline_string()
1628 ucl_chunk_skipc (chunk, p); in ucl_parse_multiline_string()
1639 if (parser == NULL || parser->stack == NULL || parser->stack->obj == NULL) { in ucl_parser_get_container()
1643 if (parser->stack->obj->type == UCL_ARRAY) { in ucl_parser_get_container()
1645 obj = ucl_object_new_full (UCL_NULL, parser->chunks->priority); in ucl_parser_get_container()
1646 t = parser->stack->obj; in ucl_parser_get_container()
1653 parser->cur_obj = obj; in ucl_parser_get_container()
1658 obj = parser->cur_obj; in ucl_parser_get_container()
1673 const unsigned char *p, *c; in ucl_parse_value() local
1679 p = chunk->pos; in ucl_parse_value()
1682 if (ucl_test_character (*p, UCL_CHARACTER_WHITESPACE_UNSAFE) || in ucl_parse_value()
1683 (chunk->remain >= 2 && ucl_lex_is_comment (p[0], p[1]))) { in ucl_parse_value()
1684 while (p < chunk->end && ucl_test_character (*p, UCL_CHARACTER_WHITESPACE_UNSAFE)) { in ucl_parse_value()
1685 ucl_chunk_skipc (chunk, p); in ucl_parse_value()
1690 p = chunk->pos; in ucl_parse_value()
1693 while (p < chunk->end) { in ucl_parse_value()
1694 c = p; in ucl_parse_value()
1695 switch (*p) { in ucl_parse_value()
1697 ucl_chunk_skipc (chunk, p); in ucl_parse_value()
1709 str_len = chunk->pos - c - 2; in ucl_parse_value()
1710 obj->type = UCL_STRING; in ucl_parse_value()
1712 &obj->trash_stack[UCL_TRASH_VALUE], in ucl_parse_value()
1713 &obj->value.sv, str_len, need_unescape, false, in ucl_parse_value()
1714 var_expand, false)) == -1) { in ucl_parse_value()
1718 obj->len = str_len; in ucl_parse_value()
1719 parser->state = UCL_STATE_AFTER_VALUE; in ucl_parse_value()
1724 ucl_chunk_skipc (chunk, p); in ucl_parse_value()
1735 str_len = chunk->pos - c - 2; in ucl_parse_value()
1736 obj->type = UCL_STRING; in ucl_parse_value()
1737 obj->flags |= UCL_OBJECT_SQUOTED; in ucl_parse_value()
1740 &obj->trash_stack[UCL_TRASH_VALUE], in ucl_parse_value()
1741 &obj->value.sv, str_len, need_unescape, false, in ucl_parse_value()
1742 var_expand, true)) == -1) { in ucl_parse_value()
1746 obj->len = str_len; in ucl_parse_value()
1748 parser->state = UCL_STATE_AFTER_VALUE; in ucl_parse_value()
1758 if (parser->stack) { in ucl_parse_value()
1760 parser->stack->e.params.level, true); in ucl_parse_value()
1769 ucl_chunk_skipc (chunk, p); in ucl_parse_value()
1779 if (parser->stack) { in ucl_parse_value()
1781 parser->stack->e.params.level, true); in ucl_parse_value()
1791 ucl_chunk_skipc (chunk, p); in ucl_parse_value()
1797 if (parser->stack && parser->stack->obj->type == UCL_ARRAY) { in ucl_parse_value()
1798 parser->state = UCL_STATE_AFTER_VALUE; in ucl_parse_value()
1807 /* We have something like multiline value, which must be <<[A-Z]+\n */ in ucl_parse_value()
1808 if (chunk->end - p > 3) { in ucl_parse_value()
1809 if (memcmp (p, "<<", 2) == 0) { in ucl_parse_value()
1810 p += 2; in ucl_parse_value()
1812 while (p < chunk->end && *p >= 'A' && *p <= 'Z') { in ucl_parse_value()
1813 p ++; in ucl_parse_value()
1815 if (*p =='\n') { in ucl_parse_value()
1817 chunk->remain -= p - c + 1; in ucl_parse_value()
1819 chunk->pos = p + 1; in ucl_parse_value()
1820 chunk->column = 0; in ucl_parse_value()
1821 chunk->line ++; in ucl_parse_value()
1823 p - c, &c, &var_expand)) == 0) { in ucl_parse_value()
1825 "unterminated multiline value", &parser->err); in ucl_parse_value()
1829 obj->type = UCL_STRING; in ucl_parse_value()
1830 obj->flags |= UCL_OBJECT_MULTILINE; in ucl_parse_value()
1832 &obj->trash_stack[UCL_TRASH_VALUE], in ucl_parse_value()
1833 &obj->value.sv, str_len - 1, false, in ucl_parse_value()
1834 false, var_expand, false)) == -1) { in ucl_parse_value()
1837 obj->len = str_len; in ucl_parse_value()
1839 parser->state = UCL_STATE_AFTER_VALUE; in ucl_parse_value()
1854 if (ucl_test_character (*p, UCL_CHARACTER_VALUE_DIGIT_START)) { in ucl_parse_value()
1856 if (parser->state == UCL_STATE_ERROR) { in ucl_parse_value()
1861 parser->state = UCL_STATE_AFTER_VALUE; in ucl_parse_value()
1873 while (ucl_test_character (*(chunk->pos - 1 - stripped_spaces), in ucl_parse_value()
1877 str_len = chunk->pos - c - stripped_spaces; in ucl_parse_value()
1880 &parser->err); in ucl_parse_value()
1884 obj->len = 0; in ucl_parse_value()
1885 obj->type = UCL_NULL; in ucl_parse_value()
1888 obj->len = 0; in ucl_parse_value()
1889 obj->type = UCL_FLOAT; in ucl_parse_value()
1890 obj->value.dv = NAN; in ucl_parse_value()
1893 obj->len = 0; in ucl_parse_value()
1894 obj->type = UCL_FLOAT; in ucl_parse_value()
1895 obj->value.dv = INFINITY; in ucl_parse_value()
1898 obj->type = UCL_STRING; in ucl_parse_value()
1900 &obj->trash_stack[UCL_TRASH_VALUE], in ucl_parse_value()
1901 &obj->value.sv, str_len, need_unescape, in ucl_parse_value()
1902 false, var_expand, false)) == -1) { in ucl_parse_value()
1905 obj->len = str_len; in ucl_parse_value()
1908 parser->state = UCL_STATE_AFTER_VALUE; in ucl_parse_value()
1927 const unsigned char *p; in ucl_parse_after_value() local
1931 p = chunk->pos; in ucl_parse_after_value()
1933 while (p < chunk->end) { in ucl_parse_after_value()
1934 if (ucl_test_character (*p, UCL_CHARACTER_WHITESPACE)) { in ucl_parse_after_value()
1936 ucl_chunk_skipc (chunk, p); in ucl_parse_after_value()
1938 else if (chunk->remain >= 2 && ucl_lex_is_comment (p[0], p[1])) { in ucl_parse_after_value()
1945 p = chunk->pos; in ucl_parse_after_value()
1947 else if (ucl_test_character (*p, UCL_CHARACTER_VALUE_END)) { in ucl_parse_after_value()
1948 if (*p == '}' || *p == ']') { in ucl_parse_after_value()
1949 if (parser->stack == NULL) { in ucl_parse_after_value()
1952 &parser->err); in ucl_parse_after_value()
1955 if ((*p == '}' && parser->stack->obj->type == UCL_OBJECT) || in ucl_parse_after_value()
1956 (*p == ']' && parser->stack->obj->type == UCL_ARRAY)) { in ucl_parse_after_value()
1959 st = parser->stack; in ucl_parse_after_value()
1961 if (!(st->e.params.flags & UCL_STACK_HAS_OBRACE)) { in ucl_parse_after_value()
1962 parser->err_code = UCL_EUNPAIRED; in ucl_parse_after_value()
1963 ucl_create_err (&parser->err, in ucl_parse_after_value()
1965 chunk->fname ? chunk->fname : "memory", in ucl_parse_after_value()
1966 parser->chunks->line, st->e.params.line); in ucl_parse_after_value()
1971 parser->stack = st->next; in ucl_parse_after_value()
1974 if (parser->cur_obj) { in ucl_parse_after_value()
1975 ucl_attach_comment (parser, parser->cur_obj, true); in ucl_parse_after_value()
1978 while (parser->stack != NULL) { in ucl_parse_after_value()
1979 st = parser->stack; in ucl_parse_after_value()
1981 if (st->next == NULL) { in ucl_parse_after_value()
1984 else if (st->next->e.params.level == st->e.params.level) { in ucl_parse_after_value()
1989 parser->stack = st->next; in ucl_parse_after_value()
1990 parser->cur_obj = st->obj; in ucl_parse_after_value()
1997 &parser->err); in ucl_parse_after_value()
2001 if (parser->stack == NULL) { in ucl_parse_after_value()
2006 ucl_chunk_skipc (chunk, p); in ucl_parse_after_value()
2013 ucl_chunk_skipc (chunk, p); in ucl_parse_after_value()
2020 &parser->err); in ucl_parse_after_value()
2034 const unsigned char *p, *c; in ucl_skip_macro_as_comment() local
2043 } state = macro_skip_start, prev_state = macro_skip_start; in ucl_skip_macro_as_comment() local
2045 p = chunk->pos; in ucl_skip_macro_as_comment()
2046 c = chunk->pos; in ucl_skip_macro_as_comment()
2048 while (p < chunk->end) { in ucl_skip_macro_as_comment()
2049 switch (state) { in ucl_skip_macro_as_comment()
2051 if (!ucl_test_character (*p, UCL_CHARACTER_WHITESPACE)) { in ucl_skip_macro_as_comment()
2052 state = macro_has_symbols; in ucl_skip_macro_as_comment()
2054 else if (ucl_test_character (*p, UCL_CHARACTER_WHITESPACE_UNSAFE)) { in ucl_skip_macro_as_comment()
2055 state = macro_save; in ucl_skip_macro_as_comment()
2059 ucl_chunk_skipc (chunk, p); in ucl_skip_macro_as_comment()
2063 if (*p == '{') { in ucl_skip_macro_as_comment()
2064 state = macro_has_sqbrace; in ucl_skip_macro_as_comment()
2066 else if (*p == '(') { in ucl_skip_macro_as_comment()
2067 state = macro_has_obrace; in ucl_skip_macro_as_comment()
2069 else if (*p == '"') { in ucl_skip_macro_as_comment()
2070 state = macro_has_quote; in ucl_skip_macro_as_comment()
2072 else if (*p == '\n') { in ucl_skip_macro_as_comment()
2073 state = macro_save; in ucl_skip_macro_as_comment()
2077 ucl_chunk_skipc (chunk, p); in ucl_skip_macro_as_comment()
2081 if (*p == '\\') { in ucl_skip_macro_as_comment()
2082 prev_state = state; in ucl_skip_macro_as_comment()
2083 state = macro_has_backslash; in ucl_skip_macro_as_comment()
2085 else if (*p == ')') { in ucl_skip_macro_as_comment()
2086 state = macro_has_symbols; in ucl_skip_macro_as_comment()
2089 ucl_chunk_skipc (chunk, p); in ucl_skip_macro_as_comment()
2093 if (*p == '\\') { in ucl_skip_macro_as_comment()
2094 prev_state = state; in ucl_skip_macro_as_comment()
2095 state = macro_has_backslash; in ucl_skip_macro_as_comment()
2097 else if (*p == '}') { in ucl_skip_macro_as_comment()
2098 state = macro_save; in ucl_skip_macro_as_comment()
2101 ucl_chunk_skipc (chunk, p); in ucl_skip_macro_as_comment()
2105 if (*p == '\\') { in ucl_skip_macro_as_comment()
2106 prev_state = state; in ucl_skip_macro_as_comment()
2107 state = macro_has_backslash; in ucl_skip_macro_as_comment()
2109 else if (*p == '"') { in ucl_skip_macro_as_comment()
2110 state = macro_save; in ucl_skip_macro_as_comment()
2113 ucl_chunk_skipc (chunk, p); in ucl_skip_macro_as_comment()
2117 state = prev_state; in ucl_skip_macro_as_comment()
2118 ucl_chunk_skipc (chunk, p); in ucl_skip_macro_as_comment()
2122 if (parser->flags & UCL_PARSER_SAVE_COMMENTS) { in ucl_skip_macro_as_comment()
2123 ucl_save_comment (parser, c, p - c); in ucl_skip_macro_as_comment()
2147 const unsigned char *p, *c; in ucl_parse_macro_value() local
2150 p = chunk->pos; in ucl_parse_macro_value()
2152 switch (*p) { in ucl_parse_macro_value()
2155 c = p; in ucl_parse_macro_value()
2156 ucl_chunk_skipc (chunk, p); in ucl_parse_macro_value()
2162 *macro_len = chunk->pos - c - 2; in ucl_parse_macro_value()
2163 p = chunk->pos; in ucl_parse_macro_value()
2167 ucl_chunk_skipc (chunk, p); in ucl_parse_macro_value()
2169 while (p < chunk->end) { in ucl_parse_macro_value()
2170 if (ucl_test_character (*p, UCL_CHARACTER_WHITESPACE_UNSAFE)) { in ucl_parse_macro_value()
2171 ucl_chunk_skipc (chunk, p); in ucl_parse_macro_value()
2177 c = p; in ucl_parse_macro_value()
2178 while (p < chunk->end) { in ucl_parse_macro_value()
2179 if (*p == '}') { in ucl_parse_macro_value()
2182 ucl_chunk_skipc (chunk, p); in ucl_parse_macro_value()
2185 *macro_len = p - c; in ucl_parse_macro_value()
2186 ucl_chunk_skipc (chunk, p); in ucl_parse_macro_value()
2190 c = p; in ucl_parse_macro_value()
2191 while (p < chunk->end) { in ucl_parse_macro_value()
2192 if (ucl_lex_is_atom_end (*p)) { in ucl_parse_macro_value()
2195 ucl_chunk_skipc (chunk, p); in ucl_parse_macro_value()
2198 *macro_len = p - c; in ucl_parse_macro_value()
2203 /* Skip ';' and space characters and return to previous state */ in ucl_parse_macro_value()
2204 while (p < chunk->end) { in ucl_parse_macro_value()
2205 if (!ucl_test_character (*p, UCL_CHARACTER_WHITESPACE_UNSAFE) && *p != ';') { in ucl_parse_macro_value()
2208 ucl_chunk_skipc (chunk, p); in ucl_parse_macro_value()
2225 int obraces = 1, ebraces = 0, state = 0; in ucl_parse_macro_arguments() local
2226 const unsigned char *p, *c; in ucl_parse_macro_arguments() local
2230 saved.column = chunk->column; in ucl_parse_macro_arguments()
2231 saved.line = chunk->line; in ucl_parse_macro_arguments()
2232 saved.pos = chunk->pos; in ucl_parse_macro_arguments()
2233 saved.remain = chunk->remain; in ucl_parse_macro_arguments()
2234 p = chunk->pos; in ucl_parse_macro_arguments()
2236 if (*p != '(' || chunk->remain < 2) { in ucl_parse_macro_arguments()
2241 ucl_chunk_skipc (chunk, p); in ucl_parse_macro_arguments()
2242 c = p; in ucl_parse_macro_arguments()
2244 while ((p) < (chunk)->end) { in ucl_parse_macro_arguments()
2245 switch (state) { in ucl_parse_macro_arguments()
2248 if (*p == '(') { in ucl_parse_macro_arguments()
2251 else if (*p == ')') { in ucl_parse_macro_arguments()
2254 else if (*p == '"') { in ucl_parse_macro_arguments()
2255 state = 1; in ucl_parse_macro_arguments()
2259 state = 99; in ucl_parse_macro_arguments()
2265 if (chunk->remain == 0) { in ucl_parse_macro_arguments()
2268 ucl_chunk_skipc (chunk, p); in ucl_parse_macro_arguments()
2272 if (*p == '"' && *(p - 1) != '\\') { in ucl_parse_macro_arguments()
2273 state = 0; in ucl_parse_macro_arguments()
2275 if (chunk->remain == 0) { in ucl_parse_macro_arguments()
2279 ucl_chunk_skipc (chunk, p); in ucl_parse_macro_arguments()
2286 params_parser = ucl_parser_new (parser->flags); in ucl_parse_macro_arguments()
2289 &parser->err); in ucl_parse_macro_arguments()
2305 chunk->column = saved.column; in ucl_parse_macro_arguments()
2306 chunk->line = saved.line; in ucl_parse_macro_arguments()
2307 chunk->pos = saved.pos; in ucl_parse_macro_arguments()
2308 chunk->remain = saved.remain; in ucl_parse_macro_arguments()
2313 #define SKIP_SPACES_COMMENTS(parser, chunk, p) do { \ argument
2314 while ((p) < (chunk)->end) { \
2315 if (!ucl_test_character (*(p), UCL_CHARACTER_WHITESPACE_UNSAFE)) { \
2316 if ((chunk)->remain >= 2 && ucl_lex_is_comment ((p)[0], (p)[1])) { \
2320 p = (chunk)->pos; \
2324 ucl_chunk_skipc (chunk, p); \
2337 struct ucl_chunk *chunk = parser->chunks; in ucl_state_machine()
2338 const unsigned char *p, *c = NULL, *macro_start = NULL; in ucl_state_machine() local
2344 if (parser->top_obj == NULL) { in ucl_state_machine()
2345 parser->state = UCL_STATE_INIT; in ucl_state_machine()
2348 p = chunk->pos; in ucl_state_machine()
2349 while (chunk->pos < chunk->end) { in ucl_state_machine()
2350 switch (parser->state) { in ucl_state_machine()
2353 * At the init state we can either go to the parse array or object in ucl_state_machine()
2358 parser->prev_state = parser->state; in ucl_state_machine()
2359 parser->state = UCL_STATE_ERROR; in ucl_state_machine()
2366 while (p < chunk->end && ucl_test_character (*p, in ucl_state_machine()
2368 ucl_chunk_skipc (chunk, p); in ucl_state_machine()
2371 p = chunk->pos; in ucl_state_machine()
2373 if (p < chunk->end) { in ucl_state_machine()
2374 if (*p == '[') { in ucl_state_machine()
2375 parser->state = UCL_STATE_VALUE; in ucl_state_machine()
2376 ucl_chunk_skipc (chunk, p); in ucl_state_machine()
2381 if (*p == '{') { in ucl_state_machine()
2382 ucl_chunk_skipc (chunk, p); in ucl_state_machine()
2383 parser->state = UCL_STATE_KEY_OBRACE; in ucl_state_machine()
2387 parser->state = UCL_STATE_KEY; in ucl_state_machine()
2392 if (parser->top_obj == NULL) { in ucl_state_machine()
2393 if (parser->state == UCL_STATE_VALUE) { in ucl_state_machine()
2406 parser->top_obj = obj; in ucl_state_machine()
2407 parser->cur_obj = obj; in ucl_state_machine()
2415 while (p < chunk->end && ucl_test_character (*p, UCL_CHARACTER_WHITESPACE_UNSAFE)) { in ucl_state_machine()
2416 ucl_chunk_skipc (chunk, p); in ucl_state_machine()
2418 if (p == chunk->end || *p == '}') { in ucl_state_machine()
2420 parser->state = UCL_STATE_AFTER_VALUE; in ucl_state_machine()
2423 if (parser->stack == NULL) { in ucl_state_machine()
2426 "expects a key", &parser->err); in ucl_state_machine()
2427 parser->prev_state = parser->state; in ucl_state_machine()
2428 parser->state = UCL_STATE_ERROR; in ucl_state_machine()
2432 parser->prev_state = parser->state; in ucl_state_machine()
2433 parser->state = UCL_STATE_ERROR; in ucl_state_machine()
2438 p = chunk->pos; in ucl_state_machine()
2439 parser->state = UCL_STATE_AFTER_VALUE; in ucl_state_machine()
2442 else if (parser->state != UCL_STATE_MACRO_NAME) { in ucl_state_machine()
2443 if (next_key && parser->stack->obj->type == UCL_OBJECT) { in ucl_state_machine()
2445 obj = ucl_parser_add_container (parser->cur_obj, in ucl_state_machine()
2448 parser->stack->e.params.level + 1, in ucl_state_machine()
2449 parser->state == UCL_STATE_KEY_OBRACE); in ucl_state_machine()
2455 parser->state = UCL_STATE_VALUE; in ucl_state_machine()
2459 c = chunk->pos; in ucl_state_machine()
2461 p = chunk->pos; in ucl_state_machine()
2465 if (!parser->cur_obj || !ucl_parse_value (parser, chunk)) { in ucl_state_machine()
2466 parser->prev_state = parser->state; in ucl_state_machine()
2467 parser->state = UCL_STATE_ERROR; in ucl_state_machine()
2470 /* State is set in ucl_parse_value call */ in ucl_state_machine()
2471 p = chunk->pos; in ucl_state_machine()
2475 parser->prev_state = parser->state; in ucl_state_machine()
2476 parser->state = UCL_STATE_ERROR; in ucl_state_machine()
2480 if (parser->stack != NULL) { in ucl_state_machine()
2481 if (parser->stack->obj->type == UCL_OBJECT) { in ucl_state_machine()
2482 parser->state = UCL_STATE_KEY; in ucl_state_machine()
2486 parser->state = UCL_STATE_VALUE; in ucl_state_machine()
2494 p = chunk->pos; in ucl_state_machine()
2497 if (parser->flags & UCL_PARSER_DISABLE_MACRO) { in ucl_state_machine()
2500 ucl_create_err (&parser->err, in ucl_state_machine()
2502 chunk->fname ? chunk->fname : "memory", in ucl_state_machine()
2503 chunk->line, in ucl_state_machine()
2504 chunk->column); in ucl_state_machine()
2505 parser->state = UCL_STATE_ERROR; in ucl_state_machine()
2509 p = chunk->pos; in ucl_state_machine()
2510 parser->state = parser->prev_state; in ucl_state_machine()
2514 if (!ucl_test_character (*p, UCL_CHARACTER_WHITESPACE_UNSAFE) && in ucl_state_machine()
2515 *p != '(') { in ucl_state_machine()
2516 ucl_chunk_skipc (chunk, p); in ucl_state_machine()
2519 if (c != NULL && p - c > 0) { in ucl_state_machine()
2521 macro_len = (size_t) (p - c); in ucl_state_machine()
2522 HASH_FIND (hh, parser->macroes, c, macro_len, macro); in ucl_state_machine()
2524 ucl_create_err (&parser->err, in ucl_state_machine()
2527 chunk->fname ? chunk->fname : "memory", in ucl_state_machine()
2528 chunk->line, in ucl_state_machine()
2529 chunk->column, in ucl_state_machine()
2530 (int) (p - c), in ucl_state_machine()
2532 *chunk->pos); in ucl_state_machine()
2533 parser->state = UCL_STATE_ERROR; in ucl_state_machine()
2537 SKIP_SPACES_COMMENTS(parser, chunk, p); in ucl_state_machine()
2538 parser->state = UCL_STATE_MACRO; in ucl_state_machine()
2542 ucl_create_err (&parser->err, in ucl_state_machine()
2544 chunk->fname ? chunk->fname : "memory", in ucl_state_machine()
2545 chunk->line, in ucl_state_machine()
2546 chunk->column); in ucl_state_machine()
2547 parser->state = UCL_STATE_ERROR; in ucl_state_machine()
2554 if (*chunk->pos == '(') { in ucl_state_machine()
2556 p = chunk->pos; in ucl_state_machine()
2558 SKIP_SPACES_COMMENTS(parser, chunk, p); in ucl_state_machine()
2566 parser->prev_state = parser->state; in ucl_state_machine()
2567 parser->state = UCL_STATE_ERROR; in ucl_state_machine()
2572 parser->state = parser->prev_state; in ucl_state_machine()
2575 if (macro->is_context) { in ucl_state_machine()
2576 ret = macro->h.context_handler (macro_start, macro_len, in ucl_state_machine()
2578 parser->top_obj, in ucl_state_machine()
2579 macro->ud); in ucl_state_machine()
2582 ret = macro->h.handler (macro_start, macro_len, macro_args, in ucl_state_machine()
2583 macro->ud); in ucl_state_machine()
2587 if (macro->is_context) { in ucl_state_machine()
2588 ret = macro->h.context_handler (macro_escaped, macro_len, in ucl_state_machine()
2590 parser->top_obj, in ucl_state_machine()
2591 macro->ud); in ucl_state_machine()
2594 ret = macro->h.handler (macro_escaped, macro_len, macro_args, in ucl_state_machine()
2595 macro->ud); in ucl_state_machine()
2603 "internal error: parser has macro undefined", &parser->err); in ucl_state_machine()
2609 chunk = parser->chunks; in ucl_state_machine()
2610 p = chunk->pos; in ucl_state_machine()
2622 "internal error: parser is in an unknown state", &parser->err); in ucl_state_machine()
2623 parser->state = UCL_STATE_ERROR; in ucl_state_machine()
2628 if (parser->last_comment) { in ucl_state_machine()
2629 if (parser->cur_obj) { in ucl_state_machine()
2630 ucl_attach_comment (parser, parser->cur_obj, true); in ucl_state_machine()
2632 else if (parser->stack && parser->stack->obj) { in ucl_state_machine()
2633 ucl_attach_comment (parser, parser->stack->obj, true); in ucl_state_machine()
2635 else if (parser->top_obj) { in ucl_state_machine()
2636 ucl_attach_comment (parser, parser->top_obj, true); in ucl_state_machine()
2639 ucl_object_unref (parser->last_comment); in ucl_state_machine()
2643 if (parser->stack != NULL && parser->state != UCL_STATE_ERROR) { in ucl_state_machine()
2647 LL_FOREACH (parser->stack, st) { in ucl_state_machine()
2648 if (st->chunk != parser->chunks) { in ucl_state_machine()
2651 if (st->e.params.flags & UCL_STACK_HAS_OBRACE) { in ucl_state_machine()
2652 if (parser->err == NULL) { in ucl_state_machine()
2653 utstring_new (parser->err); in ucl_state_machine()
2656 utstring_printf (parser->err, "%s:%d unmatched open brace at %d; ", in ucl_state_machine()
2657 chunk->fname ? chunk->fname : "memory", in ucl_state_machine()
2658 parser->chunks->line, in ucl_state_machine()
2659 st->e.params.line); in ucl_state_machine()
2666 parser->err_code = UCL_EUNPAIRED; in ucl_state_machine()
2699 parser->flags = flags; in ucl_parser_new()
2700 parser->includepaths = NULL; in ucl_parser_new()
2703 parser->comments = ucl_object_typed_new (UCL_OBJECT); in ucl_parser_new()
2724 parser->default_priority = prio; in ucl_parser_set_default_priority()
2733 return -1; in ucl_parser_get_default_priority()
2736 return parser->default_priority; in ucl_parser_get_default_priority()
2755 new->h.handler = handler; in ucl_parser_register_macro()
2756 new->name = strdup (macro); in ucl_parser_register_macro()
2757 if (new->name == NULL) { in ucl_parser_register_macro()
2761 new->ud = ud; in ucl_parser_register_macro()
2762 HASH_ADD_KEYPTR (hh, parser->macroes, new->name, strlen (new->name), new); in ucl_parser_register_macro()
2782 new->h.context_handler = handler; in ucl_parser_register_context_macro()
2783 new->name = strdup (macro); in ucl_parser_register_context_macro()
2784 if (new->name == NULL) { in ucl_parser_register_context_macro()
2788 new->ud = ud; in ucl_parser_register_context_macro()
2789 new->is_context = true; in ucl_parser_register_context_macro()
2790 HASH_ADD_KEYPTR (hh, parser->macroes, new->name, strlen (new->name), new); in ucl_parser_register_context_macro()
2805 LL_FOREACH (parser->variables, cur) { in ucl_parser_register_variable()
2806 if (strcmp (cur->var, var) == 0) { in ucl_parser_register_variable()
2816 DL_DELETE (parser->variables, new); in ucl_parser_register_variable()
2817 free (new->var); in ucl_parser_register_variable()
2818 free (new->value); in ucl_parser_register_variable()
2833 new->var = strdup (var); in ucl_parser_register_variable()
2834 new->var_len = strlen (var); in ucl_parser_register_variable()
2835 new->value = strdup (value); in ucl_parser_register_variable()
2836 new->value_len = strlen (value); in ucl_parser_register_variable()
2838 DL_APPEND (parser->variables, new); in ucl_parser_register_variable()
2841 free (new->value); in ucl_parser_register_variable()
2842 new->value = strdup (value); in ucl_parser_register_variable()
2843 new->value_len = strlen (value); in ucl_parser_register_variable()
2852 parser->var_handler = handler; in ucl_parser_set_variables_handler()
2853 parser->var_data = ud; in ucl_parser_set_variables_handler()
2869 ucl_create_err (&parser->err, "invalid chunk added"); in ucl_parser_add_chunk_full()
2873 if (parser->state != UCL_STATE_ERROR) { in ucl_parser_add_chunk_full()
2876 ucl_create_err (&parser->err, "cannot allocate chunk structure"); in ucl_parser_add_chunk_full()
2883 LL_FOREACH (parser->special_handlers, special_handler) { in ucl_parser_add_chunk_full()
2884 if ((special_handler->flags & UCL_SPECIAL_HANDLER_PREPROCESS_ALL) || in ucl_parser_add_chunk_full()
2885 (len >= special_handler->magic_len && in ucl_parser_add_chunk_full()
2886 memcmp (data, special_handler->magic, special_handler->magic_len) == 0)) { in ucl_parser_add_chunk_full()
2890 if (!special_handler->handler (parser, data, len, &ndata, &nlen, in ucl_parser_add_chunk_full()
2891 special_handler->user_data)) { in ucl_parser_add_chunk_full()
2892 ucl_create_err (&parser->err, "call for external handler failed"); in ucl_parser_add_chunk_full()
2898 nchain->begin = ndata; in ucl_parser_add_chunk_full()
2899 nchain->len = nlen; in ucl_parser_add_chunk_full()
2900 nchain->special_handler = special_handler; in ucl_parser_add_chunk_full()
2903 LL_PREPEND (chunk->special_handlers, nchain); in ucl_parser_add_chunk_full()
2923 chunk->begin = data; in ucl_parser_add_chunk_full()
2924 chunk->remain = len; in ucl_parser_add_chunk_full()
2925 chunk->pos = chunk->begin; in ucl_parser_add_chunk_full()
2926 chunk->end = chunk->begin + len; in ucl_parser_add_chunk_full()
2927 chunk->line = 1; in ucl_parser_add_chunk_full()
2928 chunk->column = 0; in ucl_parser_add_chunk_full()
2929 chunk->priority = priority; in ucl_parser_add_chunk_full()
2930 chunk->strategy = strat; in ucl_parser_add_chunk_full()
2931 chunk->parse_type = parse_type; in ucl_parser_add_chunk_full()
2933 if (parser->cur_file) { in ucl_parser_add_chunk_full()
2934 chunk->fname = strdup (parser->cur_file); in ucl_parser_add_chunk_full()
2937 LL_PREPEND (parser->chunks, chunk); in ucl_parser_add_chunk_full()
2938 parser->recursion ++; in ucl_parser_add_chunk_full()
2940 if (parser->recursion > UCL_MAX_RECURSION) { in ucl_parser_add_chunk_full()
2941 ucl_create_err (&parser->err, "maximum include nesting limit is reached: %d", in ucl_parser_add_chunk_full()
2942 parser->recursion); in ucl_parser_add_chunk_full()
2960 if (parser->top_obj == NULL) { in ucl_parser_add_chunk_full()
2965 parser->top_obj = ucl_object_new_full (UCL_OBJECT, priority); in ucl_parser_add_chunk_full()
2972 ucl_create_err (&parser->err, "a parser is in an invalid state"); in ucl_parser_add_chunk_full()
2999 parser->default_priority, UCL_DUPLICATE_APPEND, UCL_PARSE_UCL); in ucl_parser_add_chunk()
3006 if (parser == NULL || parser->top_obj == NULL) { in ucl_parser_insert_chunk()
3013 int state = parser->state; in ucl_parser_insert_chunk() local
3014 parser->state = UCL_STATE_INIT; in ucl_parser_insert_chunk()
3017 if (parser->stack != NULL && parser->stack->next != NULL) { in ucl_parser_insert_chunk()
3018 parser->stack->e.params.level = parser->stack->next->e.params.level; in ucl_parser_insert_chunk()
3021 res = ucl_parser_add_chunk_full (parser, data, len, parser->chunks->priority, in ucl_parser_insert_chunk()
3022 parser->chunks->strategy, parser->chunks->parse_type); in ucl_parser_insert_chunk()
3025 chunk = parser->chunks; in ucl_parser_insert_chunk()
3027 parser->chunks = chunk->next; in ucl_parser_insert_chunk()
3029 parser->recursion --; in ucl_parser_insert_chunk()
3032 parser->state = state; in ucl_parser_insert_chunk()
3042 ucl_create_err (&parser->err, "invalid string added"); in ucl_parser_add_string_priority()
3062 (const unsigned char *)data, len, parser->default_priority); in ucl_parser_add_string()
3072 if (parser->includepaths == NULL) { in ucl_set_include_path()
3073 parser->includepaths = ucl_object_copy (paths); in ucl_set_include_path()
3076 ucl_object_unref (parser->includepaths); in ucl_set_include_path()
3077 parser->includepaths = ucl_object_copy (paths); in ucl_set_include_path()
3080 if (parser->includepaths == NULL) { in ucl_set_include_path()
3089 …if (parser == NULL || parser->chunks == NULL || parser->chunks->pos == NULL || parser->chunks->end… in ucl_parser_chunk_peek()
3090 parser->chunks->pos == parser->chunks->end) { in ucl_parser_chunk_peek()
3094 return( *parser->chunks->pos ); in ucl_parser_chunk_peek()
3099 …if (parser == NULL || parser->chunks == NULL || parser->chunks->pos == NULL || parser->chunks->end… in ucl_parser_chunk_skip()
3100 parser->chunks->pos == parser->chunks->end) { in ucl_parser_chunk_skip()
3104 const unsigned char *p = parser->chunks->pos; in ucl_parser_chunk_skip() local
3105 ucl_chunk_skipc( parser->chunks, p ); in ucl_parser_chunk_skip()
3106 if( parser->chunks->pos != NULL ) return true; in ucl_parser_chunk_skip()
3115 if (parser == NULL || parser->stack == NULL) { in ucl_parser_get_current_stack_object()
3119 struct ucl_stack *stack = parser->stack; in ucl_parser_get_current_stack_object()
3120 if(stack == NULL || stack->obj == NULL || ucl_object_type (stack->obj) != UCL_OBJECT) in ucl_parser_get_current_stack_object()
3127 stack = stack->next; in ucl_parser_get_current_stack_object()
3128 if(stack == NULL || stack->obj == NULL || ucl_object_type (stack->obj) != UCL_OBJECT) in ucl_parser_get_current_stack_object()
3134 obj = ucl_object_ref (stack->obj); in ucl_parser_get_current_stack_object()