ucl_parser.c (1709ccf9d38a5753192420ce5fccd93b04ce4d07) | ucl_parser.c (b04a7a0baf6523245034b8ccd06cd0176b8a18cf) |
---|---|
1/* Copyright (c) 2013, Vsevolod Stakhov 2 * All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above copyright --- 41 unchanged lines hidden (view full) --- 50 (chunk)->column = 0; \ 51 } \ 52 else (chunk)->column ++; \ 53 (p++); \ 54 (chunk)->pos ++; \ 55 (chunk)->remain --; \ 56 } while (0) 57 | 1/* Copyright (c) 2013, Vsevolod Stakhov 2 * All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above copyright --- 41 unchanged lines hidden (view full) --- 50 (chunk)->column = 0; \ 51 } \ 52 else (chunk)->column ++; \ 53 (p++); \ 54 (chunk)->pos ++; \ 55 (chunk)->remain --; \ 56 } while (0) 57 |
58/** 59 * Save parser state 60 * @param chunk 61 * @param s 62 */ | |
63static inline void | 58static inline void |
64ucl_chunk_save_state (struct ucl_chunk *chunk, struct ucl_parser_saved_state *s) 65{ 66 s->column = chunk->column; 67 s->pos = chunk->pos; 68 s->line = chunk->line; 69 s->remain = chunk->remain; 70} 71 72/** 73 * Restore parser state 74 * @param chunk 75 * @param s 76 */ 77static inline void 78ucl_chunk_restore_state (struct ucl_chunk *chunk, struct ucl_parser_saved_state *s) 79{ 80 chunk->column = s->column; 81 chunk->pos = s->pos; 82 chunk->line = s->line; 83 chunk->remain = s->remain; 84} 85 86static inline void | |
87ucl_set_err (struct ucl_chunk *chunk, int code, const char *str, UT_string **err) 88{ 89 if (chunk->pos < chunk->end) { 90 if (isgraph (*chunk->pos)) { 91 ucl_create_err (err, "error on line %d at column %d: '%s', character: '%c'", 92 chunk->line, chunk->column, str, *chunk->pos); 93 } 94 else { --- 986 unchanged lines hidden (view full) --- 1081 } 1082 } 1083 1084 /* Create a new object */ 1085 nobj = ucl_object_new (); 1086 keylen = ucl_copy_or_store_ptr (parser, c, &nobj->trash_stack[UCL_TRASH_KEY], 1087 &key, end - c, need_unescape, parser->flags & UCL_PARSER_KEY_LOWERCASE, false); 1088 if (keylen == -1) { | 59ucl_set_err (struct ucl_chunk *chunk, int code, const char *str, UT_string **err) 60{ 61 if (chunk->pos < chunk->end) { 62 if (isgraph (*chunk->pos)) { 63 ucl_create_err (err, "error on line %d at column %d: '%s', character: '%c'", 64 chunk->line, chunk->column, str, *chunk->pos); 65 } 66 else { --- 986 unchanged lines hidden (view full) --- 1053 } 1054 } 1055 1056 /* Create a new object */ 1057 nobj = ucl_object_new (); 1058 keylen = ucl_copy_or_store_ptr (parser, c, &nobj->trash_stack[UCL_TRASH_KEY], 1059 &key, end - c, need_unescape, parser->flags & UCL_PARSER_KEY_LOWERCASE, false); 1060 if (keylen == -1) { |
1089 ucl_object_free(nobj); | 1061 ucl_object_unref (nobj); |
1090 return false; 1091 } 1092 else if (keylen == 0) { 1093 ucl_set_err (chunk, UCL_ESYNTAX, "empty keys are not allowed", &parser->err); | 1062 return false; 1063 } 1064 else if (keylen == 0) { 1065 ucl_set_err (chunk, UCL_ESYNTAX, "empty keys are not allowed", &parser->err); |
1094 ucl_object_free(nobj); | 1066 ucl_object_unref (nobj); |
1095 return false; 1096 } 1097 1098 container = parser->stack->obj->value.ov; 1099 nobj->key = key; 1100 nobj->keylen = keylen; | 1067 return false; 1068 } 1069 1070 container = parser->stack->obj->value.ov; 1071 nobj->key = key; 1072 nobj->keylen = keylen; |
1101 tobj = ucl_hash_search_obj (container, nobj); | 1073 tobj = __DECONST (ucl_object_t *, ucl_hash_search_obj (container, nobj)); |
1102 if (tobj == NULL) { 1103 container = ucl_hash_insert_object (container, nobj); 1104 nobj->prev = nobj; 1105 nobj->next = NULL; 1106 parser->stack->obj->len ++; 1107 } 1108 else { 1109 DL_APPEND (tobj, nobj); --- 845 unchanged lines hidden --- | 1074 if (tobj == NULL) { 1075 container = ucl_hash_insert_object (container, nobj); 1076 nobj->prev = nobj; 1077 nobj->next = NULL; 1078 parser->stack->obj->len ++; 1079 } 1080 else { 1081 DL_APPEND (tobj, nobj); --- 845 unchanged lines hidden --- |