| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
#include "yaml_private.h" |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
/* |
|
5
|
|
|
|
|
|
|
* Get the library version. |
|
6
|
|
|
|
|
|
|
*/ |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
YAML_DECLARE(const char *) |
|
9
|
1
|
|
|
|
|
|
yaml_get_version_string(void) |
|
10
|
|
|
|
|
|
|
{ |
|
11
|
1
|
|
|
|
|
|
return YAML_VERSION_STRING; |
|
12
|
|
|
|
|
|
|
} |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
/* |
|
15
|
|
|
|
|
|
|
* Get the library version numbers. |
|
16
|
|
|
|
|
|
|
*/ |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
19
|
0
|
|
|
|
|
|
yaml_get_version(int *major, int *minor, int *patch) |
|
20
|
|
|
|
|
|
|
{ |
|
21
|
0
|
|
|
|
|
|
*major = YAML_VERSION_MAJOR; |
|
22
|
0
|
|
|
|
|
|
*minor = YAML_VERSION_MINOR; |
|
23
|
0
|
|
|
|
|
|
*patch = YAML_VERSION_PATCH; |
|
24
|
0
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
/* |
|
27
|
|
|
|
|
|
|
* Allocate a dynamic memory block. |
|
28
|
|
|
|
|
|
|
*/ |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
YAML_DECLARE(void *) |
|
31
|
3434
|
|
|
|
|
|
yaml_malloc(size_t size) |
|
32
|
|
|
|
|
|
|
{ |
|
33
|
3434
|
50
|
|
|
|
|
return malloc(size ? size : 1); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
/* |
|
37
|
|
|
|
|
|
|
* Reallocate a dynamic memory block. |
|
38
|
|
|
|
|
|
|
*/ |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
YAML_DECLARE(void *) |
|
41
|
66
|
|
|
|
|
|
yaml_realloc(void *ptr, size_t size) |
|
42
|
|
|
|
|
|
|
{ |
|
43
|
66
|
50
|
|
|
|
|
return ptr ? realloc(ptr, size ? size : 1) : malloc(size ? size : 1); |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
/* |
|
47
|
|
|
|
|
|
|
* Free a dynamic memory block. |
|
48
|
|
|
|
|
|
|
*/ |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
51
|
6847
|
|
|
|
|
|
yaml_free(void *ptr) |
|
52
|
|
|
|
|
|
|
{ |
|
53
|
6847
|
100
|
|
|
|
|
if (ptr) free(ptr); |
|
54
|
6847
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
/* |
|
57
|
|
|
|
|
|
|
* Duplicate a string. |
|
58
|
|
|
|
|
|
|
*/ |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
YAML_DECLARE(yaml_char_t *) |
|
61
|
1219
|
|
|
|
|
|
yaml_strdup(const yaml_char_t *str) |
|
62
|
|
|
|
|
|
|
{ |
|
63
|
1219
|
50
|
|
|
|
|
if (!str) |
|
64
|
0
|
|
|
|
|
|
return NULL; |
|
65
|
|
|
|
|
|
|
|
|
66
|
1219
|
|
|
|
|
|
return (yaml_char_t *)strdup((char *)str); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
/* |
|
70
|
|
|
|
|
|
|
* Extend a string. |
|
71
|
|
|
|
|
|
|
*/ |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
74
|
66
|
|
|
|
|
|
yaml_string_extend(yaml_char_t **start, |
|
75
|
|
|
|
|
|
|
yaml_char_t **pointer, yaml_char_t **end) |
|
76
|
|
|
|
|
|
|
{ |
|
77
|
|
|
|
|
|
|
yaml_char_t *new_start; |
|
78
|
|
|
|
|
|
|
|
|
79
|
66
|
50
|
|
|
|
|
if ((char *)*end - (char *)*start >= INT_MAX / 2) |
|
80
|
0
|
|
|
|
|
|
return 0; |
|
81
|
|
|
|
|
|
|
|
|
82
|
66
|
|
|
|
|
|
new_start = (yaml_char_t *)yaml_realloc((void*)*start, (*end - *start)*2); |
|
83
|
66
|
50
|
|
|
|
|
if (!new_start) return 0; |
|
84
|
|
|
|
|
|
|
|
|
85
|
66
|
|
|
|
|
|
memset(new_start + (*end - *start), 0, *end - *start); |
|
86
|
|
|
|
|
|
|
|
|
87
|
66
|
|
|
|
|
|
*pointer = new_start + (*pointer - *start); |
|
88
|
66
|
|
|
|
|
|
*end = new_start + (*end - *start)*2; |
|
89
|
66
|
|
|
|
|
|
*start = new_start; |
|
90
|
|
|
|
|
|
|
|
|
91
|
66
|
|
|
|
|
|
return 1; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
/* |
|
95
|
|
|
|
|
|
|
* Append a string B to a string A. |
|
96
|
|
|
|
|
|
|
*/ |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
99
|
170
|
|
|
|
|
|
yaml_string_join( |
|
100
|
|
|
|
|
|
|
yaml_char_t **a_start, yaml_char_t **a_pointer, yaml_char_t **a_end, |
|
101
|
|
|
|
|
|
|
yaml_char_t **b_start, yaml_char_t **b_pointer, SHIM(yaml_char_t **b_end)) |
|
102
|
|
|
|
|
|
|
{ |
|
103
|
|
|
|
|
|
|
UNUSED_PARAM(b_end) |
|
104
|
85
|
100
|
|
|
|
|
if (*b_start == *b_pointer) |
|
105
|
24
|
|
|
|
|
|
return 1; |
|
106
|
|
|
|
|
|
|
|
|
107
|
61
|
50
|
|
|
|
|
while (*a_end - *a_pointer <= *b_pointer - *b_start) { |
|
108
|
0
|
0
|
|
|
|
|
if (!yaml_string_extend(a_start, a_pointer, a_end)) |
|
109
|
0
|
|
|
|
|
|
return 0; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
61
|
|
|
|
|
|
memcpy(*a_pointer, *b_start, *b_pointer - *b_start); |
|
113
|
61
|
|
|
|
|
|
*a_pointer += *b_pointer - *b_start; |
|
114
|
|
|
|
|
|
|
|
|
115
|
61
|
|
|
|
|
|
return 1; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
/* |
|
119
|
|
|
|
|
|
|
* Extend a stack. |
|
120
|
|
|
|
|
|
|
*/ |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
123
|
0
|
|
|
|
|
|
yaml_stack_extend(void **start, void **top, void **end) |
|
124
|
|
|
|
|
|
|
{ |
|
125
|
|
|
|
|
|
|
void *new_start; |
|
126
|
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
|
if ((char *)*end - (char *)*start >= INT_MAX / 2) |
|
128
|
0
|
|
|
|
|
|
return 0; |
|
129
|
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2); |
|
131
|
0
|
0
|
|
|
|
|
if (!new_start) return 0; |
|
132
|
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
*top = (char *)new_start + ((char *)*top - (char *)*start); |
|
134
|
0
|
|
|
|
|
|
*end = (char *)new_start + ((char *)*end - (char *)*start)*2; |
|
135
|
0
|
|
|
|
|
|
*start = new_start; |
|
136
|
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
return 1; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
/* |
|
141
|
|
|
|
|
|
|
* Extend or move a queue. |
|
142
|
|
|
|
|
|
|
*/ |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
145
|
48
|
|
|
|
|
|
yaml_queue_extend(void **start, void **head, void **tail, void **end) |
|
146
|
|
|
|
|
|
|
{ |
|
147
|
|
|
|
|
|
|
/* Check if we need to resize the queue. */ |
|
148
|
|
|
|
|
|
|
|
|
149
|
48
|
50
|
|
|
|
|
if (*start == *head && *tail == *end) { |
|
|
|
0
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
void *new_start = yaml_realloc(*start, |
|
151
|
0
|
|
|
|
|
|
((char *)*end - (char *)*start)*2); |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
|
if (!new_start) return 0; |
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
*head = (char *)new_start + ((char *)*head - (char *)*start); |
|
156
|
0
|
|
|
|
|
|
*tail = (char *)new_start + ((char *)*tail - (char *)*start); |
|
157
|
0
|
|
|
|
|
|
*end = (char *)new_start + ((char *)*end - (char *)*start)*2; |
|
158
|
0
|
|
|
|
|
|
*start = new_start; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
/* Check if we need to move the queue at the beginning of the buffer. */ |
|
162
|
|
|
|
|
|
|
|
|
163
|
48
|
50
|
|
|
|
|
if (*tail == *end) { |
|
164
|
48
|
100
|
|
|
|
|
if (*head != *tail) { |
|
165
|
26
|
|
|
|
|
|
memmove(*start, *head, (char *)*tail - (char *)*head); |
|
166
|
|
|
|
|
|
|
} |
|
167
|
48
|
|
|
|
|
|
*tail = (char *)*tail - (char *)*head + (char *)*start; |
|
168
|
48
|
|
|
|
|
|
*head = *start; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
|
|
171
|
48
|
|
|
|
|
|
return 1; |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
/* |
|
176
|
|
|
|
|
|
|
* Create a new parser object. |
|
177
|
|
|
|
|
|
|
*/ |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
180
|
109
|
|
|
|
|
|
yaml_parser_initialize(yaml_parser_t *parser) |
|
181
|
|
|
|
|
|
|
{ |
|
182
|
109
|
50
|
|
|
|
|
assert(parser); /* Non-NULL parser object expected. */ |
|
183
|
|
|
|
|
|
|
|
|
184
|
109
|
|
|
|
|
|
memset(parser, 0, sizeof(yaml_parser_t)); |
|
185
|
109
|
50
|
|
|
|
|
if (!BUFFER_INIT(parser, parser->raw_buffer, INPUT_RAW_BUFFER_SIZE)) |
|
|
|
50
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
goto error; |
|
187
|
109
|
50
|
|
|
|
|
if (!BUFFER_INIT(parser, parser->buffer, INPUT_BUFFER_SIZE)) |
|
|
|
50
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
goto error; |
|
189
|
109
|
50
|
|
|
|
|
if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_SIZE, yaml_token_t*)) |
|
|
|
50
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
|
goto error; |
|
191
|
109
|
50
|
|
|
|
|
if (!STACK_INIT(parser, parser->indents, int*)) |
|
|
|
50
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
goto error; |
|
193
|
109
|
50
|
|
|
|
|
if (!STACK_INIT(parser, parser->simple_keys, yaml_simple_key_t*)) |
|
|
|
50
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
|
goto error; |
|
195
|
109
|
50
|
|
|
|
|
if (!STACK_INIT(parser, parser->states, yaml_parser_state_t*)) |
|
|
|
50
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
goto error; |
|
197
|
109
|
50
|
|
|
|
|
if (!STACK_INIT(parser, parser->marks, yaml_mark_t*)) |
|
|
|
50
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
goto error; |
|
199
|
109
|
50
|
|
|
|
|
if (!STACK_INIT(parser, parser->tag_directives, yaml_tag_directive_t*)) |
|
|
|
50
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
goto error; |
|
201
|
|
|
|
|
|
|
|
|
202
|
109
|
|
|
|
|
|
return 1; |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
error: |
|
205
|
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
BUFFER_DEL(parser, parser->raw_buffer); |
|
207
|
0
|
|
|
|
|
|
BUFFER_DEL(parser, parser->buffer); |
|
208
|
0
|
|
|
|
|
|
QUEUE_DEL(parser, parser->tokens); |
|
209
|
0
|
|
|
|
|
|
STACK_DEL(parser, parser->indents); |
|
210
|
0
|
|
|
|
|
|
STACK_DEL(parser, parser->simple_keys); |
|
211
|
0
|
|
|
|
|
|
STACK_DEL(parser, parser->states); |
|
212
|
0
|
|
|
|
|
|
STACK_DEL(parser, parser->marks); |
|
213
|
0
|
|
|
|
|
|
STACK_DEL(parser, parser->tag_directives); |
|
214
|
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
return 0; |
|
216
|
|
|
|
|
|
|
} |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
/* |
|
219
|
|
|
|
|
|
|
* Destroy a parser object. |
|
220
|
|
|
|
|
|
|
*/ |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
223
|
131
|
|
|
|
|
|
yaml_parser_delete(yaml_parser_t *parser) |
|
224
|
|
|
|
|
|
|
{ |
|
225
|
131
|
50
|
|
|
|
|
assert(parser); /* Non-NULL parser object expected. */ |
|
226
|
|
|
|
|
|
|
|
|
227
|
131
|
|
|
|
|
|
BUFFER_DEL(parser, parser->raw_buffer); |
|
228
|
131
|
|
|
|
|
|
BUFFER_DEL(parser, parser->buffer); |
|
229
|
132
|
100
|
|
|
|
|
while (!QUEUE_EMPTY(parser, parser->tokens)) { |
|
230
|
1
|
|
|
|
|
|
yaml_token_delete(&DEQUEUE(parser, parser->tokens)); |
|
231
|
|
|
|
|
|
|
} |
|
232
|
131
|
|
|
|
|
|
QUEUE_DEL(parser, parser->tokens); |
|
233
|
131
|
|
|
|
|
|
STACK_DEL(parser, parser->indents); |
|
234
|
131
|
|
|
|
|
|
STACK_DEL(parser, parser->simple_keys); |
|
235
|
131
|
|
|
|
|
|
STACK_DEL(parser, parser->states); |
|
236
|
131
|
|
|
|
|
|
STACK_DEL(parser, parser->marks); |
|
237
|
143
|
100
|
|
|
|
|
while (!STACK_EMPTY(parser, parser->tag_directives)) { |
|
238
|
12
|
|
|
|
|
|
yaml_tag_directive_t tag_directive = POP(parser, parser->tag_directives); |
|
239
|
12
|
|
|
|
|
|
yaml_free(tag_directive.handle); |
|
240
|
12
|
|
|
|
|
|
yaml_free(tag_directive.prefix); |
|
241
|
|
|
|
|
|
|
} |
|
242
|
131
|
|
|
|
|
|
STACK_DEL(parser, parser->tag_directives); |
|
243
|
|
|
|
|
|
|
|
|
244
|
131
|
|
|
|
|
|
memset(parser, 0, sizeof(yaml_parser_t)); |
|
245
|
131
|
|
|
|
|
|
} |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
/* |
|
248
|
|
|
|
|
|
|
* String read handler. |
|
249
|
|
|
|
|
|
|
*/ |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
static int |
|
252
|
202
|
|
|
|
|
|
yaml_string_read_handler(void *data, unsigned char *buffer, size_t size, |
|
253
|
|
|
|
|
|
|
size_t *size_read) |
|
254
|
|
|
|
|
|
|
{ |
|
255
|
202
|
|
|
|
|
|
yaml_parser_t *parser = (yaml_parser_t *)data; |
|
256
|
|
|
|
|
|
|
|
|
257
|
202
|
100
|
|
|
|
|
if (parser->input.string.current == parser->input.string.end) { |
|
258
|
99
|
|
|
|
|
|
*size_read = 0; |
|
259
|
99
|
|
|
|
|
|
return 1; |
|
260
|
|
|
|
|
|
|
} |
|
261
|
|
|
|
|
|
|
|
|
262
|
103
|
50
|
|
|
|
|
if (size > (size_t)(parser->input.string.end |
|
263
|
103
|
|
|
|
|
|
- parser->input.string.current)) { |
|
264
|
103
|
|
|
|
|
|
size = parser->input.string.end - parser->input.string.current; |
|
265
|
|
|
|
|
|
|
} |
|
266
|
|
|
|
|
|
|
|
|
267
|
103
|
|
|
|
|
|
memcpy(buffer, parser->input.string.current, size); |
|
268
|
103
|
|
|
|
|
|
parser->input.string.current += size; |
|
269
|
103
|
|
|
|
|
|
*size_read = size; |
|
270
|
103
|
|
|
|
|
|
return 1; |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
/* |
|
274
|
|
|
|
|
|
|
* File read handler. |
|
275
|
|
|
|
|
|
|
*/ |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
static int |
|
278
|
5
|
|
|
|
|
|
yaml_file_read_handler(void *data, unsigned char *buffer, size_t size, |
|
279
|
|
|
|
|
|
|
size_t *size_read) |
|
280
|
|
|
|
|
|
|
{ |
|
281
|
5
|
|
|
|
|
|
yaml_parser_t *parser = (yaml_parser_t *)data; |
|
282
|
|
|
|
|
|
|
|
|
283
|
5
|
|
|
|
|
|
*size_read = fread(buffer, 1, size, parser->input.file); |
|
284
|
5
|
|
|
|
|
|
return !ferror(parser->input.file); |
|
285
|
|
|
|
|
|
|
} |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
/* |
|
288
|
|
|
|
|
|
|
* Set a string input. |
|
289
|
|
|
|
|
|
|
*/ |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
292
|
104
|
|
|
|
|
|
yaml_parser_set_input_string(yaml_parser_t *parser, |
|
293
|
|
|
|
|
|
|
const unsigned char *input, size_t size) |
|
294
|
|
|
|
|
|
|
{ |
|
295
|
104
|
50
|
|
|
|
|
assert(parser); /* Non-NULL parser object expected. */ |
|
296
|
104
|
50
|
|
|
|
|
assert(!parser->read_handler); /* You can set the source only once. */ |
|
297
|
104
|
50
|
|
|
|
|
assert(input); /* Non-NULL input string expected. */ |
|
298
|
|
|
|
|
|
|
|
|
299
|
104
|
|
|
|
|
|
parser->read_handler = yaml_string_read_handler; |
|
300
|
104
|
|
|
|
|
|
parser->read_handler_data = parser; |
|
301
|
|
|
|
|
|
|
|
|
302
|
104
|
|
|
|
|
|
parser->input.string.start = input; |
|
303
|
104
|
|
|
|
|
|
parser->input.string.current = input; |
|
304
|
104
|
|
|
|
|
|
parser->input.string.end = input+size; |
|
305
|
104
|
|
|
|
|
|
} |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
/* |
|
308
|
|
|
|
|
|
|
* Set a file input. |
|
309
|
|
|
|
|
|
|
*/ |
|
310
|
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
312
|
3
|
|
|
|
|
|
yaml_parser_set_input_file(yaml_parser_t *parser, FILE *file) |
|
313
|
|
|
|
|
|
|
{ |
|
314
|
3
|
50
|
|
|
|
|
assert(parser); /* Non-NULL parser object expected. */ |
|
315
|
3
|
50
|
|
|
|
|
assert(!parser->read_handler); /* You can set the source only once. */ |
|
316
|
3
|
50
|
|
|
|
|
assert(file); /* Non-NULL file object expected. */ |
|
317
|
|
|
|
|
|
|
|
|
318
|
3
|
|
|
|
|
|
parser->read_handler = yaml_file_read_handler; |
|
319
|
3
|
|
|
|
|
|
parser->read_handler_data = parser; |
|
320
|
|
|
|
|
|
|
|
|
321
|
3
|
|
|
|
|
|
parser->input.file = file; |
|
322
|
3
|
|
|
|
|
|
} |
|
323
|
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
/* |
|
325
|
|
|
|
|
|
|
* Set a generic input. |
|
326
|
|
|
|
|
|
|
*/ |
|
327
|
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
329
|
2
|
|
|
|
|
|
yaml_parser_set_input(yaml_parser_t *parser, |
|
330
|
|
|
|
|
|
|
yaml_read_handler_t *handler, void *data) |
|
331
|
|
|
|
|
|
|
{ |
|
332
|
2
|
50
|
|
|
|
|
assert(parser); /* Non-NULL parser object expected. */ |
|
333
|
2
|
50
|
|
|
|
|
assert(!parser->read_handler); /* You can set the source only once. */ |
|
334
|
2
|
50
|
|
|
|
|
assert(handler); /* Non-NULL read handler expected. */ |
|
335
|
|
|
|
|
|
|
|
|
336
|
2
|
|
|
|
|
|
parser->read_handler = handler; |
|
337
|
2
|
|
|
|
|
|
parser->read_handler_data = data; |
|
338
|
2
|
|
|
|
|
|
} |
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
/* |
|
341
|
|
|
|
|
|
|
* Set the source encoding. |
|
342
|
|
|
|
|
|
|
*/ |
|
343
|
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
345
|
0
|
|
|
|
|
|
yaml_parser_set_encoding(yaml_parser_t *parser, yaml_encoding_t encoding) |
|
346
|
|
|
|
|
|
|
{ |
|
347
|
0
|
0
|
|
|
|
|
assert(parser); /* Non-NULL parser object expected. */ |
|
348
|
0
|
0
|
|
|
|
|
assert(!parser->encoding); /* Encoding is already set or detected. */ |
|
349
|
|
|
|
|
|
|
|
|
350
|
0
|
|
|
|
|
|
parser->encoding = encoding; |
|
351
|
0
|
|
|
|
|
|
} |
|
352
|
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
/* |
|
354
|
|
|
|
|
|
|
* Create a new emitter object. |
|
355
|
|
|
|
|
|
|
*/ |
|
356
|
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
358
|
87
|
|
|
|
|
|
yaml_emitter_initialize(yaml_emitter_t *emitter) |
|
359
|
|
|
|
|
|
|
{ |
|
360
|
87
|
50
|
|
|
|
|
assert(emitter); /* Non-NULL emitter object expected. */ |
|
361
|
|
|
|
|
|
|
|
|
362
|
87
|
|
|
|
|
|
memset(emitter, 0, sizeof(yaml_emitter_t)); |
|
363
|
87
|
50
|
|
|
|
|
if (!BUFFER_INIT(emitter, emitter->buffer, OUTPUT_BUFFER_SIZE)) |
|
|
|
50
|
|
|
|
|
|
|
364
|
0
|
|
|
|
|
|
goto error; |
|
365
|
87
|
50
|
|
|
|
|
if (!BUFFER_INIT(emitter, emitter->raw_buffer, OUTPUT_RAW_BUFFER_SIZE)) |
|
|
|
50
|
|
|
|
|
|
|
366
|
0
|
|
|
|
|
|
goto error; |
|
367
|
87
|
50
|
|
|
|
|
if (!STACK_INIT(emitter, emitter->states, yaml_emitter_state_t*)) |
|
|
|
50
|
|
|
|
|
|
|
368
|
0
|
|
|
|
|
|
goto error; |
|
369
|
87
|
50
|
|
|
|
|
if (!QUEUE_INIT(emitter, emitter->events, INITIAL_QUEUE_SIZE, yaml_event_t*)) |
|
|
|
50
|
|
|
|
|
|
|
370
|
0
|
|
|
|
|
|
goto error; |
|
371
|
87
|
50
|
|
|
|
|
if (!STACK_INIT(emitter, emitter->indents, int*)) |
|
|
|
50
|
|
|
|
|
|
|
372
|
0
|
|
|
|
|
|
goto error; |
|
373
|
87
|
50
|
|
|
|
|
if (!STACK_INIT(emitter, emitter->tag_directives, yaml_tag_directive_t*)) |
|
|
|
50
|
|
|
|
|
|
|
374
|
0
|
|
|
|
|
|
goto error; |
|
375
|
|
|
|
|
|
|
|
|
376
|
87
|
|
|
|
|
|
return 1; |
|
377
|
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
error: |
|
379
|
|
|
|
|
|
|
|
|
380
|
0
|
|
|
|
|
|
BUFFER_DEL(emitter, emitter->buffer); |
|
381
|
0
|
|
|
|
|
|
BUFFER_DEL(emitter, emitter->raw_buffer); |
|
382
|
0
|
|
|
|
|
|
STACK_DEL(emitter, emitter->states); |
|
383
|
0
|
|
|
|
|
|
QUEUE_DEL(emitter, emitter->events); |
|
384
|
0
|
|
|
|
|
|
STACK_DEL(emitter, emitter->indents); |
|
385
|
0
|
|
|
|
|
|
STACK_DEL(emitter, emitter->tag_directives); |
|
386
|
|
|
|
|
|
|
|
|
387
|
0
|
|
|
|
|
|
return 0; |
|
388
|
|
|
|
|
|
|
} |
|
389
|
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
/* |
|
391
|
|
|
|
|
|
|
* Destroy an emitter object. |
|
392
|
|
|
|
|
|
|
*/ |
|
393
|
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
395
|
110
|
|
|
|
|
|
yaml_emitter_delete(yaml_emitter_t *emitter) |
|
396
|
|
|
|
|
|
|
{ |
|
397
|
110
|
50
|
|
|
|
|
assert(emitter); /* Non-NULL emitter object expected. */ |
|
398
|
|
|
|
|
|
|
|
|
399
|
110
|
|
|
|
|
|
BUFFER_DEL(emitter, emitter->buffer); |
|
400
|
110
|
|
|
|
|
|
BUFFER_DEL(emitter, emitter->raw_buffer); |
|
401
|
110
|
|
|
|
|
|
STACK_DEL(emitter, emitter->states); |
|
402
|
110
|
50
|
|
|
|
|
while (!QUEUE_EMPTY(emitter, emitter->events)) { |
|
403
|
0
|
|
|
|
|
|
yaml_event_delete(&DEQUEUE(emitter, emitter->events)); |
|
404
|
|
|
|
|
|
|
} |
|
405
|
110
|
|
|
|
|
|
QUEUE_DEL(emitter, emitter->events); |
|
406
|
110
|
|
|
|
|
|
STACK_DEL(emitter, emitter->indents); |
|
407
|
110
|
50
|
|
|
|
|
while (!STACK_EMPTY(empty, emitter->tag_directives)) { |
|
408
|
0
|
|
|
|
|
|
yaml_tag_directive_t tag_directive = POP(emitter, emitter->tag_directives); |
|
409
|
0
|
|
|
|
|
|
yaml_free(tag_directive.handle); |
|
410
|
0
|
|
|
|
|
|
yaml_free(tag_directive.prefix); |
|
411
|
|
|
|
|
|
|
} |
|
412
|
110
|
|
|
|
|
|
STACK_DEL(emitter, emitter->tag_directives); |
|
413
|
110
|
|
|
|
|
|
yaml_free(emitter->anchors); |
|
414
|
|
|
|
|
|
|
|
|
415
|
110
|
|
|
|
|
|
memset(emitter, 0, sizeof(yaml_emitter_t)); |
|
416
|
110
|
|
|
|
|
|
} |
|
417
|
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
/* |
|
419
|
|
|
|
|
|
|
* String write handler. |
|
420
|
|
|
|
|
|
|
*/ |
|
421
|
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
static int |
|
423
|
0
|
|
|
|
|
|
yaml_string_write_handler(void *data, unsigned char *buffer, size_t size) |
|
424
|
|
|
|
|
|
|
{ |
|
425
|
0
|
|
|
|
|
|
yaml_emitter_t *emitter = (yaml_emitter_t *)data; |
|
426
|
|
|
|
|
|
|
|
|
427
|
0
|
0
|
|
|
|
|
if (emitter->output.string.size - *emitter->output.string.size_written |
|
428
|
|
|
|
|
|
|
< size) { |
|
429
|
0
|
|
|
|
|
|
memcpy(emitter->output.string.buffer |
|
430
|
0
|
|
|
|
|
|
+ *emitter->output.string.size_written, |
|
431
|
|
|
|
|
|
|
buffer, |
|
432
|
0
|
|
|
|
|
|
emitter->output.string.size |
|
433
|
0
|
|
|
|
|
|
- *emitter->output.string.size_written); |
|
434
|
0
|
|
|
|
|
|
*emitter->output.string.size_written = emitter->output.string.size; |
|
435
|
0
|
|
|
|
|
|
return 0; |
|
436
|
|
|
|
|
|
|
} |
|
437
|
|
|
|
|
|
|
|
|
438
|
0
|
|
|
|
|
|
memcpy(emitter->output.string.buffer |
|
439
|
0
|
|
|
|
|
|
+ *emitter->output.string.size_written, buffer, size); |
|
440
|
0
|
|
|
|
|
|
*emitter->output.string.size_written += size; |
|
441
|
0
|
|
|
|
|
|
return 1; |
|
442
|
|
|
|
|
|
|
} |
|
443
|
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
/* |
|
445
|
|
|
|
|
|
|
* File write handler. |
|
446
|
|
|
|
|
|
|
*/ |
|
447
|
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
static int |
|
449
|
4
|
|
|
|
|
|
yaml_file_write_handler(void *data, unsigned char *buffer, size_t size) |
|
450
|
|
|
|
|
|
|
{ |
|
451
|
4
|
|
|
|
|
|
yaml_emitter_t *emitter = (yaml_emitter_t *)data; |
|
452
|
|
|
|
|
|
|
|
|
453
|
4
|
|
|
|
|
|
return (fwrite(buffer, 1, size, emitter->output.file) == size); |
|
454
|
|
|
|
|
|
|
} |
|
455
|
|
|
|
|
|
|
/* |
|
456
|
|
|
|
|
|
|
* Set a string output. |
|
457
|
|
|
|
|
|
|
*/ |
|
458
|
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
460
|
0
|
|
|
|
|
|
yaml_emitter_set_output_string(yaml_emitter_t *emitter, |
|
461
|
|
|
|
|
|
|
unsigned char *output, size_t size, size_t *size_written) |
|
462
|
|
|
|
|
|
|
{ |
|
463
|
0
|
0
|
|
|
|
|
assert(emitter); /* Non-NULL emitter object expected. */ |
|
464
|
0
|
0
|
|
|
|
|
assert(!emitter->write_handler); /* You can set the output only once. */ |
|
465
|
0
|
0
|
|
|
|
|
assert(output); /* Non-NULL output string expected. */ |
|
466
|
|
|
|
|
|
|
|
|
467
|
0
|
|
|
|
|
|
emitter->write_handler = yaml_string_write_handler; |
|
468
|
0
|
|
|
|
|
|
emitter->write_handler_data = emitter; |
|
469
|
|
|
|
|
|
|
|
|
470
|
0
|
|
|
|
|
|
emitter->output.string.buffer = output; |
|
471
|
0
|
|
|
|
|
|
emitter->output.string.size = size; |
|
472
|
0
|
|
|
|
|
|
emitter->output.string.size_written = size_written; |
|
473
|
0
|
|
|
|
|
|
*size_written = 0; |
|
474
|
0
|
|
|
|
|
|
} |
|
475
|
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
/* |
|
477
|
|
|
|
|
|
|
* Set a file output. |
|
478
|
|
|
|
|
|
|
*/ |
|
479
|
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
481
|
2
|
|
|
|
|
|
yaml_emitter_set_output_file(yaml_emitter_t *emitter, FILE *file) |
|
482
|
|
|
|
|
|
|
{ |
|
483
|
2
|
50
|
|
|
|
|
assert(emitter); /* Non-NULL emitter object expected. */ |
|
484
|
2
|
50
|
|
|
|
|
assert(!emitter->write_handler); /* You can set the output only once. */ |
|
485
|
2
|
50
|
|
|
|
|
assert(file); /* Non-NULL file object expected. */ |
|
486
|
|
|
|
|
|
|
|
|
487
|
2
|
|
|
|
|
|
emitter->write_handler = yaml_file_write_handler; |
|
488
|
2
|
|
|
|
|
|
emitter->write_handler_data = emitter; |
|
489
|
|
|
|
|
|
|
|
|
490
|
2
|
|
|
|
|
|
emitter->output.file = file; |
|
491
|
2
|
|
|
|
|
|
} |
|
492
|
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
/* |
|
494
|
|
|
|
|
|
|
* Set a generic output handler. |
|
495
|
|
|
|
|
|
|
*/ |
|
496
|
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
498
|
85
|
|
|
|
|
|
yaml_emitter_set_output(yaml_emitter_t *emitter, |
|
499
|
|
|
|
|
|
|
yaml_write_handler_t *handler, void *data) |
|
500
|
|
|
|
|
|
|
{ |
|
501
|
85
|
50
|
|
|
|
|
assert(emitter); /* Non-NULL emitter object expected. */ |
|
502
|
85
|
50
|
|
|
|
|
assert(!emitter->write_handler); /* You can set the output only once. */ |
|
503
|
85
|
50
|
|
|
|
|
assert(handler); /* Non-NULL handler object expected. */ |
|
504
|
|
|
|
|
|
|
|
|
505
|
85
|
|
|
|
|
|
emitter->write_handler = handler; |
|
506
|
85
|
|
|
|
|
|
emitter->write_handler_data = data; |
|
507
|
85
|
|
|
|
|
|
} |
|
508
|
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
/* |
|
510
|
|
|
|
|
|
|
* Set the output encoding. |
|
511
|
|
|
|
|
|
|
*/ |
|
512
|
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
514
|
0
|
|
|
|
|
|
yaml_emitter_set_encoding(yaml_emitter_t *emitter, yaml_encoding_t encoding) |
|
515
|
|
|
|
|
|
|
{ |
|
516
|
0
|
0
|
|
|
|
|
assert(emitter); /* Non-NULL emitter object expected. */ |
|
517
|
0
|
0
|
|
|
|
|
assert(!emitter->encoding); /* You can set encoding only once. */ |
|
518
|
|
|
|
|
|
|
|
|
519
|
0
|
|
|
|
|
|
emitter->encoding = encoding; |
|
520
|
0
|
|
|
|
|
|
} |
|
521
|
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
/* |
|
523
|
|
|
|
|
|
|
* Set the canonical output style. |
|
524
|
|
|
|
|
|
|
*/ |
|
525
|
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
527
|
87
|
|
|
|
|
|
yaml_emitter_set_canonical(yaml_emitter_t *emitter, int canonical) |
|
528
|
|
|
|
|
|
|
{ |
|
529
|
87
|
50
|
|
|
|
|
assert(emitter); /* Non-NULL emitter object expected. */ |
|
530
|
|
|
|
|
|
|
|
|
531
|
87
|
|
|
|
|
|
emitter->canonical = (canonical != 0); |
|
532
|
87
|
|
|
|
|
|
} |
|
533
|
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
/* |
|
535
|
|
|
|
|
|
|
* Set the indentation increment. |
|
536
|
|
|
|
|
|
|
*/ |
|
537
|
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
539
|
87
|
|
|
|
|
|
yaml_emitter_set_indent(yaml_emitter_t *emitter, int indent) |
|
540
|
|
|
|
|
|
|
{ |
|
541
|
87
|
50
|
|
|
|
|
assert(emitter); /* Non-NULL emitter object expected. */ |
|
542
|
|
|
|
|
|
|
|
|
543
|
87
|
50
|
|
|
|
|
emitter->best_indent = (1 < indent && indent < 10) ? indent : 2; |
|
|
|
50
|
|
|
|
|
|
|
544
|
87
|
|
|
|
|
|
} |
|
545
|
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
/* |
|
547
|
|
|
|
|
|
|
* Set the preferred line width. |
|
548
|
|
|
|
|
|
|
*/ |
|
549
|
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
551
|
87
|
|
|
|
|
|
yaml_emitter_set_width(yaml_emitter_t *emitter, int width) |
|
552
|
|
|
|
|
|
|
{ |
|
553
|
87
|
50
|
|
|
|
|
assert(emitter); /* Non-NULL emitter object expected. */ |
|
554
|
|
|
|
|
|
|
|
|
555
|
87
|
|
|
|
|
|
emitter->best_width = (width >= 0) ? width : -1; |
|
556
|
87
|
|
|
|
|
|
} |
|
557
|
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
/* |
|
559
|
|
|
|
|
|
|
* Set if unescaped non-ASCII characters are allowed. |
|
560
|
|
|
|
|
|
|
*/ |
|
561
|
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
563
|
87
|
|
|
|
|
|
yaml_emitter_set_unicode(yaml_emitter_t *emitter, int unicode) |
|
564
|
|
|
|
|
|
|
{ |
|
565
|
87
|
50
|
|
|
|
|
assert(emitter); /* Non-NULL emitter object expected. */ |
|
566
|
|
|
|
|
|
|
|
|
567
|
87
|
|
|
|
|
|
emitter->unicode = (unicode != 0); |
|
568
|
87
|
|
|
|
|
|
} |
|
569
|
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
/* |
|
571
|
|
|
|
|
|
|
* Set the preferred line break character. |
|
572
|
|
|
|
|
|
|
*/ |
|
573
|
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
575
|
0
|
|
|
|
|
|
yaml_emitter_set_break(yaml_emitter_t *emitter, yaml_break_t line_break) |
|
576
|
|
|
|
|
|
|
{ |
|
577
|
0
|
0
|
|
|
|
|
assert(emitter); /* Non-NULL emitter object expected. */ |
|
578
|
|
|
|
|
|
|
|
|
579
|
0
|
|
|
|
|
|
emitter->line_break = line_break; |
|
580
|
0
|
|
|
|
|
|
} |
|
581
|
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
/* |
|
583
|
|
|
|
|
|
|
* Destroy a token object. |
|
584
|
|
|
|
|
|
|
*/ |
|
585
|
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
587
|
1
|
|
|
|
|
|
yaml_token_delete(yaml_token_t *token) |
|
588
|
|
|
|
|
|
|
{ |
|
589
|
1
|
50
|
|
|
|
|
assert(token); /* Non-NULL token object expected. */ |
|
590
|
|
|
|
|
|
|
|
|
591
|
1
|
|
|
|
|
|
switch (token->type) |
|
592
|
|
|
|
|
|
|
{ |
|
593
|
|
|
|
|
|
|
case YAML_TAG_DIRECTIVE_TOKEN: |
|
594
|
0
|
|
|
|
|
|
yaml_free(token->data.tag_directive.handle); |
|
595
|
0
|
|
|
|
|
|
yaml_free(token->data.tag_directive.prefix); |
|
596
|
0
|
|
|
|
|
|
break; |
|
597
|
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
case YAML_ALIAS_TOKEN: |
|
599
|
0
|
|
|
|
|
|
yaml_free(token->data.alias.value); |
|
600
|
0
|
|
|
|
|
|
break; |
|
601
|
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
case YAML_ANCHOR_TOKEN: |
|
603
|
0
|
|
|
|
|
|
yaml_free(token->data.anchor.value); |
|
604
|
0
|
|
|
|
|
|
break; |
|
605
|
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
case YAML_TAG_TOKEN: |
|
607
|
0
|
|
|
|
|
|
yaml_free(token->data.tag.handle); |
|
608
|
0
|
|
|
|
|
|
yaml_free(token->data.tag.suffix); |
|
609
|
0
|
|
|
|
|
|
break; |
|
610
|
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
case YAML_SCALAR_TOKEN: |
|
612
|
1
|
|
|
|
|
|
yaml_free(token->data.scalar.value); |
|
613
|
1
|
|
|
|
|
|
break; |
|
614
|
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
default: |
|
616
|
0
|
|
|
|
|
|
break; |
|
617
|
|
|
|
|
|
|
} |
|
618
|
|
|
|
|
|
|
|
|
619
|
1
|
|
|
|
|
|
memset(token, 0, sizeof(yaml_token_t)); |
|
620
|
1
|
|
|
|
|
|
} |
|
621
|
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
/* |
|
623
|
|
|
|
|
|
|
* Check if a string is a valid UTF-8 sequence. |
|
624
|
|
|
|
|
|
|
* |
|
625
|
|
|
|
|
|
|
* Check 'reader.c' for more details on UTF-8 encoding. |
|
626
|
|
|
|
|
|
|
*/ |
|
627
|
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
static int |
|
629
|
626
|
|
|
|
|
|
yaml_check_utf8(const yaml_char_t *start, size_t length) |
|
630
|
|
|
|
|
|
|
{ |
|
631
|
626
|
|
|
|
|
|
const yaml_char_t *end = start + length; |
|
632
|
626
|
|
|
|
|
|
const yaml_char_t *pointer = start; |
|
633
|
|
|
|
|
|
|
|
|
634
|
10086
|
100
|
|
|
|
|
while (pointer < end) { |
|
635
|
|
|
|
|
|
|
unsigned char octet; |
|
636
|
|
|
|
|
|
|
unsigned int width; |
|
637
|
|
|
|
|
|
|
unsigned int value; |
|
638
|
|
|
|
|
|
|
size_t k; |
|
639
|
|
|
|
|
|
|
|
|
640
|
9460
|
|
|
|
|
|
octet = pointer[0]; |
|
641
|
9460
|
100
|
|
|
|
|
width = (octet & 0x80) == 0x00 ? 1 : |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
642
|
73
|
|
|
|
|
|
(octet & 0xE0) == 0xC0 ? 2 : |
|
643
|
57
|
|
|
|
|
|
(octet & 0xF0) == 0xE0 ? 3 : |
|
644
|
0
|
|
|
|
|
|
(octet & 0xF8) == 0xF0 ? 4 : 0; |
|
645
|
9460
|
100
|
|
|
|
|
value = (octet & 0x80) == 0x00 ? octet & 0x7F : |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
646
|
73
|
|
|
|
|
|
(octet & 0xE0) == 0xC0 ? octet & 0x1F : |
|
647
|
57
|
|
|
|
|
|
(octet & 0xF0) == 0xE0 ? octet & 0x0F : |
|
648
|
0
|
|
|
|
|
|
(octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; |
|
649
|
9460
|
50
|
|
|
|
|
if (!width) return 0; |
|
650
|
9460
|
50
|
|
|
|
|
if (pointer+width > end) return 0; |
|
651
|
9590
|
100
|
|
|
|
|
for (k = 1; k < width; k ++) { |
|
652
|
130
|
|
|
|
|
|
octet = pointer[k]; |
|
653
|
130
|
50
|
|
|
|
|
if ((octet & 0xC0) != 0x80) return 0; |
|
654
|
130
|
|
|
|
|
|
value = (value << 6) + (octet & 0x3F); |
|
655
|
|
|
|
|
|
|
} |
|
656
|
9460
|
100
|
|
|
|
|
if (!((width == 1) || |
|
|
|
100
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
657
|
73
|
50
|
|
|
|
|
(width == 2 && value >= 0x80) || |
|
|
|
50
|
|
|
|
|
|
|
658
|
57
|
50
|
|
|
|
|
(width == 3 && value >= 0x800) || |
|
659
|
0
|
0
|
|
|
|
|
(width == 4 && value >= 0x10000))) return 0; |
|
660
|
|
|
|
|
|
|
|
|
661
|
9460
|
|
|
|
|
|
pointer += width; |
|
662
|
|
|
|
|
|
|
} |
|
663
|
|
|
|
|
|
|
|
|
664
|
626
|
|
|
|
|
|
return 1; |
|
665
|
|
|
|
|
|
|
} |
|
666
|
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
/* |
|
668
|
|
|
|
|
|
|
* Create STREAM-START. |
|
669
|
|
|
|
|
|
|
*/ |
|
670
|
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
672
|
87
|
|
|
|
|
|
yaml_stream_start_event_initialize(yaml_event_t *event, |
|
673
|
|
|
|
|
|
|
yaml_encoding_t encoding) |
|
674
|
|
|
|
|
|
|
{ |
|
675
|
87
|
|
|
|
|
|
yaml_mark_t mark = { 0, 0, 0 }; |
|
676
|
|
|
|
|
|
|
|
|
677
|
87
|
50
|
|
|
|
|
assert(event); /* Non-NULL event object is expected. */ |
|
678
|
|
|
|
|
|
|
|
|
679
|
87
|
|
|
|
|
|
STREAM_START_EVENT_INIT(*event, encoding, mark, mark); |
|
680
|
|
|
|
|
|
|
|
|
681
|
87
|
|
|
|
|
|
return 1; |
|
682
|
|
|
|
|
|
|
} |
|
683
|
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
/* |
|
685
|
|
|
|
|
|
|
* Create STREAM-END. |
|
686
|
|
|
|
|
|
|
*/ |
|
687
|
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
689
|
87
|
|
|
|
|
|
yaml_stream_end_event_initialize(yaml_event_t *event) |
|
690
|
|
|
|
|
|
|
{ |
|
691
|
87
|
|
|
|
|
|
yaml_mark_t mark = { 0, 0, 0 }; |
|
692
|
|
|
|
|
|
|
|
|
693
|
87
|
50
|
|
|
|
|
assert(event); /* Non-NULL event object is expected. */ |
|
694
|
|
|
|
|
|
|
|
|
695
|
87
|
|
|
|
|
|
STREAM_END_EVENT_INIT(*event, mark, mark); |
|
696
|
|
|
|
|
|
|
|
|
697
|
87
|
|
|
|
|
|
return 1; |
|
698
|
|
|
|
|
|
|
} |
|
699
|
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
/* |
|
701
|
|
|
|
|
|
|
* Create DOCUMENT-START. |
|
702
|
|
|
|
|
|
|
*/ |
|
703
|
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
705
|
109
|
|
|
|
|
|
yaml_document_start_event_initialize(yaml_event_t *event, |
|
706
|
|
|
|
|
|
|
yaml_version_directive_t *version_directive, |
|
707
|
|
|
|
|
|
|
yaml_tag_directive_t *tag_directives_start, |
|
708
|
|
|
|
|
|
|
yaml_tag_directive_t *tag_directives_end, |
|
709
|
|
|
|
|
|
|
int implicit) |
|
710
|
|
|
|
|
|
|
{ |
|
711
|
|
|
|
|
|
|
struct { |
|
712
|
|
|
|
|
|
|
yaml_error_type_t error; |
|
713
|
|
|
|
|
|
|
} context; |
|
714
|
109
|
|
|
|
|
|
yaml_mark_t mark = { 0, 0, 0 }; |
|
715
|
109
|
|
|
|
|
|
yaml_version_directive_t *version_directive_copy = NULL; |
|
716
|
|
|
|
|
|
|
struct { |
|
717
|
|
|
|
|
|
|
yaml_tag_directive_t *start; |
|
718
|
|
|
|
|
|
|
yaml_tag_directive_t *end; |
|
719
|
|
|
|
|
|
|
yaml_tag_directive_t *top; |
|
720
|
109
|
|
|
|
|
|
} tag_directives_copy = { NULL, NULL, NULL }; |
|
721
|
109
|
|
|
|
|
|
yaml_tag_directive_t value = { NULL, NULL }; |
|
722
|
|
|
|
|
|
|
|
|
723
|
109
|
50
|
|
|
|
|
assert(event); /* Non-NULL event object is expected. */ |
|
724
|
109
|
50
|
|
|
|
|
assert((tag_directives_start && tag_directives_end) || |
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
(tag_directives_start == tag_directives_end)); |
|
726
|
|
|
|
|
|
|
/* Valid tag directives are expected. */ |
|
727
|
|
|
|
|
|
|
|
|
728
|
109
|
50
|
|
|
|
|
if (version_directive) { |
|
729
|
0
|
|
|
|
|
|
version_directive_copy = YAML_MALLOC_STATIC(yaml_version_directive_t); |
|
730
|
0
|
0
|
|
|
|
|
if (!version_directive_copy) goto error; |
|
731
|
0
|
|
|
|
|
|
version_directive_copy->major = version_directive->major; |
|
732
|
0
|
|
|
|
|
|
version_directive_copy->minor = version_directive->minor; |
|
733
|
|
|
|
|
|
|
} |
|
734
|
|
|
|
|
|
|
|
|
735
|
109
|
50
|
|
|
|
|
if (tag_directives_start != tag_directives_end) { |
|
736
|
|
|
|
|
|
|
yaml_tag_directive_t *tag_directive; |
|
737
|
0
|
0
|
|
|
|
|
if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*)) |
|
|
|
0
|
|
|
|
|
|
|
738
|
0
|
|
|
|
|
|
goto error; |
|
739
|
0
|
0
|
|
|
|
|
for (tag_directive = tag_directives_start; |
|
740
|
0
|
|
|
|
|
|
tag_directive != tag_directives_end; tag_directive ++) { |
|
741
|
0
|
0
|
|
|
|
|
assert(tag_directive->handle); |
|
742
|
0
|
0
|
|
|
|
|
assert(tag_directive->prefix); |
|
743
|
0
|
0
|
|
|
|
|
if (!yaml_check_utf8(tag_directive->handle, |
|
744
|
0
|
|
|
|
|
|
strlen((char *)tag_directive->handle))) |
|
745
|
0
|
|
|
|
|
|
goto error; |
|
746
|
0
|
0
|
|
|
|
|
if (!yaml_check_utf8(tag_directive->prefix, |
|
747
|
0
|
|
|
|
|
|
strlen((char *)tag_directive->prefix))) |
|
748
|
0
|
|
|
|
|
|
goto error; |
|
749
|
0
|
|
|
|
|
|
value.handle = yaml_strdup(tag_directive->handle); |
|
750
|
0
|
|
|
|
|
|
value.prefix = yaml_strdup(tag_directive->prefix); |
|
751
|
0
|
0
|
|
|
|
|
if (!value.handle || !value.prefix) goto error; |
|
|
|
0
|
|
|
|
|
|
|
752
|
0
|
0
|
|
|
|
|
if (!PUSH(&context, tag_directives_copy, value)) |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
753
|
0
|
|
|
|
|
|
goto error; |
|
754
|
0
|
|
|
|
|
|
value.handle = NULL; |
|
755
|
0
|
|
|
|
|
|
value.prefix = NULL; |
|
756
|
|
|
|
|
|
|
} |
|
757
|
|
|
|
|
|
|
} |
|
758
|
|
|
|
|
|
|
|
|
759
|
109
|
|
|
|
|
|
DOCUMENT_START_EVENT_INIT(*event, version_directive_copy, |
|
760
|
|
|
|
|
|
|
tag_directives_copy.start, tag_directives_copy.top, |
|
761
|
|
|
|
|
|
|
implicit, mark, mark); |
|
762
|
|
|
|
|
|
|
|
|
763
|
109
|
|
|
|
|
|
return 1; |
|
764
|
|
|
|
|
|
|
|
|
765
|
|
|
|
|
|
|
error: |
|
766
|
0
|
|
|
|
|
|
yaml_free(version_directive_copy); |
|
767
|
0
|
0
|
|
|
|
|
while (!STACK_EMPTY(context, tag_directives_copy)) { |
|
768
|
0
|
|
|
|
|
|
value = POP(context, tag_directives_copy); |
|
769
|
0
|
|
|
|
|
|
yaml_free(value.handle); |
|
770
|
0
|
|
|
|
|
|
yaml_free(value.prefix); |
|
771
|
|
|
|
|
|
|
} |
|
772
|
0
|
|
|
|
|
|
STACK_DEL(context, tag_directives_copy); |
|
773
|
0
|
|
|
|
|
|
yaml_free(value.handle); |
|
774
|
0
|
|
|
|
|
|
yaml_free(value.prefix); |
|
775
|
|
|
|
|
|
|
|
|
776
|
109
|
|
|
|
|
|
return 0; |
|
777
|
|
|
|
|
|
|
} |
|
778
|
|
|
|
|
|
|
|
|
779
|
|
|
|
|
|
|
/* |
|
780
|
|
|
|
|
|
|
* Create DOCUMENT-END. |
|
781
|
|
|
|
|
|
|
*/ |
|
782
|
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
784
|
109
|
|
|
|
|
|
yaml_document_end_event_initialize(yaml_event_t *event, int implicit) |
|
785
|
|
|
|
|
|
|
{ |
|
786
|
109
|
|
|
|
|
|
yaml_mark_t mark = { 0, 0, 0 }; |
|
787
|
|
|
|
|
|
|
|
|
788
|
109
|
50
|
|
|
|
|
assert(event); /* Non-NULL emitter object is expected. */ |
|
789
|
|
|
|
|
|
|
|
|
790
|
109
|
|
|
|
|
|
DOCUMENT_END_EVENT_INIT(*event, implicit, mark, mark); |
|
791
|
|
|
|
|
|
|
|
|
792
|
109
|
|
|
|
|
|
return 1; |
|
793
|
|
|
|
|
|
|
} |
|
794
|
|
|
|
|
|
|
|
|
795
|
|
|
|
|
|
|
/* |
|
796
|
|
|
|
|
|
|
* Create ALIAS. |
|
797
|
|
|
|
|
|
|
*/ |
|
798
|
|
|
|
|
|
|
|
|
799
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
800
|
17
|
|
|
|
|
|
yaml_alias_event_initialize(yaml_event_t *event, const yaml_char_t *anchor) |
|
801
|
|
|
|
|
|
|
{ |
|
802
|
17
|
|
|
|
|
|
yaml_mark_t mark = { 0, 0, 0 }; |
|
803
|
17
|
|
|
|
|
|
yaml_char_t *anchor_copy = NULL; |
|
804
|
|
|
|
|
|
|
|
|
805
|
17
|
50
|
|
|
|
|
assert(event); /* Non-NULL event object is expected. */ |
|
806
|
17
|
50
|
|
|
|
|
assert(anchor); /* Non-NULL anchor is expected. */ |
|
807
|
|
|
|
|
|
|
|
|
808
|
17
|
50
|
|
|
|
|
if (!yaml_check_utf8(anchor, strlen((char *)anchor))) return 0; |
|
809
|
|
|
|
|
|
|
|
|
810
|
17
|
|
|
|
|
|
anchor_copy = yaml_strdup(anchor); |
|
811
|
17
|
50
|
|
|
|
|
if (!anchor_copy) |
|
812
|
0
|
|
|
|
|
|
return 0; |
|
813
|
|
|
|
|
|
|
|
|
814
|
17
|
|
|
|
|
|
ALIAS_EVENT_INIT(*event, anchor_copy, mark, mark); |
|
815
|
|
|
|
|
|
|
|
|
816
|
17
|
|
|
|
|
|
return 1; |
|
817
|
|
|
|
|
|
|
} |
|
818
|
|
|
|
|
|
|
|
|
819
|
|
|
|
|
|
|
/* |
|
820
|
|
|
|
|
|
|
* Create SCALAR. |
|
821
|
|
|
|
|
|
|
*/ |
|
822
|
|
|
|
|
|
|
|
|
823
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
824
|
291
|
|
|
|
|
|
yaml_scalar_event_initialize(yaml_event_t *event, |
|
825
|
|
|
|
|
|
|
const yaml_char_t *anchor, const yaml_char_t *tag, |
|
826
|
|
|
|
|
|
|
const yaml_char_t *value, int length, |
|
827
|
|
|
|
|
|
|
int plain_implicit, int quoted_implicit, |
|
828
|
|
|
|
|
|
|
yaml_scalar_style_t style) |
|
829
|
|
|
|
|
|
|
{ |
|
830
|
291
|
|
|
|
|
|
yaml_mark_t mark = { 0, 0, 0 }; |
|
831
|
291
|
|
|
|
|
|
yaml_char_t *anchor_copy = NULL; |
|
832
|
291
|
|
|
|
|
|
yaml_char_t *tag_copy = NULL; |
|
833
|
291
|
|
|
|
|
|
yaml_char_t *value_copy = NULL; |
|
834
|
|
|
|
|
|
|
|
|
835
|
291
|
50
|
|
|
|
|
assert(event); /* Non-NULL event object is expected. */ |
|
836
|
291
|
50
|
|
|
|
|
assert(value); /* Non-NULL anchor is expected. */ |
|
837
|
|
|
|
|
|
|
|
|
838
|
291
|
50
|
|
|
|
|
if (anchor) { |
|
839
|
0
|
0
|
|
|
|
|
if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error; |
|
840
|
0
|
|
|
|
|
|
anchor_copy = yaml_strdup(anchor); |
|
841
|
0
|
0
|
|
|
|
|
if (!anchor_copy) goto error; |
|
842
|
|
|
|
|
|
|
} |
|
843
|
|
|
|
|
|
|
|
|
844
|
291
|
100
|
|
|
|
|
if (tag) { |
|
845
|
272
|
50
|
|
|
|
|
if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; |
|
846
|
272
|
|
|
|
|
|
tag_copy = yaml_strdup(tag); |
|
847
|
272
|
50
|
|
|
|
|
if (!tag_copy) goto error; |
|
848
|
|
|
|
|
|
|
} |
|
849
|
|
|
|
|
|
|
|
|
850
|
291
|
50
|
|
|
|
|
if (length < 0) { |
|
851
|
0
|
|
|
|
|
|
length = strlen((char *)value); |
|
852
|
|
|
|
|
|
|
} |
|
853
|
|
|
|
|
|
|
|
|
854
|
291
|
50
|
|
|
|
|
if (!yaml_check_utf8(value, length)) goto error; |
|
855
|
291
|
|
|
|
|
|
value_copy = YAML_MALLOC(length+1); |
|
856
|
291
|
50
|
|
|
|
|
if (!value_copy) goto error; |
|
857
|
291
|
|
|
|
|
|
memcpy(value_copy, value, length); |
|
858
|
291
|
|
|
|
|
|
value_copy[length] = '\0'; |
|
859
|
|
|
|
|
|
|
|
|
860
|
291
|
|
|
|
|
|
SCALAR_EVENT_INIT(*event, anchor_copy, tag_copy, value_copy, length, |
|
861
|
|
|
|
|
|
|
plain_implicit, quoted_implicit, style, mark, mark); |
|
862
|
|
|
|
|
|
|
|
|
863
|
291
|
|
|
|
|
|
return 1; |
|
864
|
|
|
|
|
|
|
|
|
865
|
|
|
|
|
|
|
error: |
|
866
|
0
|
|
|
|
|
|
yaml_free(anchor_copy); |
|
867
|
0
|
|
|
|
|
|
yaml_free(tag_copy); |
|
868
|
0
|
|
|
|
|
|
yaml_free(value_copy); |
|
869
|
|
|
|
|
|
|
|
|
870
|
291
|
|
|
|
|
|
return 0; |
|
871
|
|
|
|
|
|
|
} |
|
872
|
|
|
|
|
|
|
|
|
873
|
|
|
|
|
|
|
/* |
|
874
|
|
|
|
|
|
|
* Create SEQUENCE-START. |
|
875
|
|
|
|
|
|
|
*/ |
|
876
|
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
878
|
44
|
|
|
|
|
|
yaml_sequence_start_event_initialize(yaml_event_t *event, |
|
879
|
|
|
|
|
|
|
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit, |
|
880
|
|
|
|
|
|
|
yaml_sequence_style_t style) |
|
881
|
|
|
|
|
|
|
{ |
|
882
|
44
|
|
|
|
|
|
yaml_mark_t mark = { 0, 0, 0 }; |
|
883
|
44
|
|
|
|
|
|
yaml_char_t *anchor_copy = NULL; |
|
884
|
44
|
|
|
|
|
|
yaml_char_t *tag_copy = NULL; |
|
885
|
|
|
|
|
|
|
|
|
886
|
44
|
50
|
|
|
|
|
assert(event); /* Non-NULL event object is expected. */ |
|
887
|
|
|
|
|
|
|
|
|
888
|
44
|
100
|
|
|
|
|
if (anchor) { |
|
889
|
6
|
50
|
|
|
|
|
if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error; |
|
890
|
6
|
|
|
|
|
|
anchor_copy = yaml_strdup(anchor); |
|
891
|
6
|
50
|
|
|
|
|
if (!anchor_copy) goto error; |
|
892
|
|
|
|
|
|
|
} |
|
893
|
|
|
|
|
|
|
|
|
894
|
44
|
100
|
|
|
|
|
if (tag) { |
|
895
|
3
|
50
|
|
|
|
|
if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; |
|
896
|
3
|
|
|
|
|
|
tag_copy = yaml_strdup(tag); |
|
897
|
3
|
50
|
|
|
|
|
if (!tag_copy) goto error; |
|
898
|
|
|
|
|
|
|
} |
|
899
|
|
|
|
|
|
|
|
|
900
|
44
|
|
|
|
|
|
SEQUENCE_START_EVENT_INIT(*event, anchor_copy, tag_copy, |
|
901
|
|
|
|
|
|
|
implicit, style, mark, mark); |
|
902
|
|
|
|
|
|
|
|
|
903
|
44
|
|
|
|
|
|
return 1; |
|
904
|
|
|
|
|
|
|
|
|
905
|
|
|
|
|
|
|
error: |
|
906
|
0
|
|
|
|
|
|
yaml_free(anchor_copy); |
|
907
|
0
|
|
|
|
|
|
yaml_free(tag_copy); |
|
908
|
|
|
|
|
|
|
|
|
909
|
44
|
|
|
|
|
|
return 0; |
|
910
|
|
|
|
|
|
|
} |
|
911
|
|
|
|
|
|
|
|
|
912
|
|
|
|
|
|
|
/* |
|
913
|
|
|
|
|
|
|
* Create SEQUENCE-END. |
|
914
|
|
|
|
|
|
|
*/ |
|
915
|
|
|
|
|
|
|
|
|
916
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
917
|
44
|
|
|
|
|
|
yaml_sequence_end_event_initialize(yaml_event_t *event) |
|
918
|
|
|
|
|
|
|
{ |
|
919
|
44
|
|
|
|
|
|
yaml_mark_t mark = { 0, 0, 0 }; |
|
920
|
|
|
|
|
|
|
|
|
921
|
44
|
50
|
|
|
|
|
assert(event); /* Non-NULL event object is expected. */ |
|
922
|
|
|
|
|
|
|
|
|
923
|
44
|
|
|
|
|
|
SEQUENCE_END_EVENT_INIT(*event, mark, mark); |
|
924
|
|
|
|
|
|
|
|
|
925
|
44
|
|
|
|
|
|
return 1; |
|
926
|
|
|
|
|
|
|
} |
|
927
|
|
|
|
|
|
|
|
|
928
|
|
|
|
|
|
|
/* |
|
929
|
|
|
|
|
|
|
* Create MAPPING-START. |
|
930
|
|
|
|
|
|
|
*/ |
|
931
|
|
|
|
|
|
|
|
|
932
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
933
|
66
|
|
|
|
|
|
yaml_mapping_start_event_initialize(yaml_event_t *event, |
|
934
|
|
|
|
|
|
|
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit, |
|
935
|
|
|
|
|
|
|
yaml_mapping_style_t style) |
|
936
|
|
|
|
|
|
|
{ |
|
937
|
66
|
|
|
|
|
|
yaml_mark_t mark = { 0, 0, 0 }; |
|
938
|
66
|
|
|
|
|
|
yaml_char_t *anchor_copy = NULL; |
|
939
|
66
|
|
|
|
|
|
yaml_char_t *tag_copy = NULL; |
|
940
|
|
|
|
|
|
|
|
|
941
|
66
|
50
|
|
|
|
|
assert(event); /* Non-NULL event object is expected. */ |
|
942
|
|
|
|
|
|
|
|
|
943
|
66
|
100
|
|
|
|
|
if (anchor) { |
|
944
|
10
|
50
|
|
|
|
|
if (!yaml_check_utf8(anchor, strlen((char *)anchor))) goto error; |
|
945
|
10
|
|
|
|
|
|
anchor_copy = yaml_strdup(anchor); |
|
946
|
10
|
50
|
|
|
|
|
if (!anchor_copy) goto error; |
|
947
|
|
|
|
|
|
|
} |
|
948
|
|
|
|
|
|
|
|
|
949
|
66
|
100
|
|
|
|
|
if (tag) { |
|
950
|
27
|
50
|
|
|
|
|
if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; |
|
951
|
27
|
|
|
|
|
|
tag_copy = yaml_strdup(tag); |
|
952
|
27
|
50
|
|
|
|
|
if (!tag_copy) goto error; |
|
953
|
|
|
|
|
|
|
} |
|
954
|
|
|
|
|
|
|
|
|
955
|
66
|
|
|
|
|
|
MAPPING_START_EVENT_INIT(*event, anchor_copy, tag_copy, |
|
956
|
|
|
|
|
|
|
implicit, style, mark, mark); |
|
957
|
|
|
|
|
|
|
|
|
958
|
66
|
|
|
|
|
|
return 1; |
|
959
|
|
|
|
|
|
|
|
|
960
|
|
|
|
|
|
|
error: |
|
961
|
0
|
|
|
|
|
|
yaml_free(anchor_copy); |
|
962
|
0
|
|
|
|
|
|
yaml_free(tag_copy); |
|
963
|
|
|
|
|
|
|
|
|
964
|
66
|
|
|
|
|
|
return 0; |
|
965
|
|
|
|
|
|
|
} |
|
966
|
|
|
|
|
|
|
|
|
967
|
|
|
|
|
|
|
/* |
|
968
|
|
|
|
|
|
|
* Create MAPPING-END. |
|
969
|
|
|
|
|
|
|
*/ |
|
970
|
|
|
|
|
|
|
|
|
971
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
972
|
66
|
|
|
|
|
|
yaml_mapping_end_event_initialize(yaml_event_t *event) |
|
973
|
|
|
|
|
|
|
{ |
|
974
|
66
|
|
|
|
|
|
yaml_mark_t mark = { 0, 0, 0 }; |
|
975
|
|
|
|
|
|
|
|
|
976
|
66
|
50
|
|
|
|
|
assert(event); /* Non-NULL event object is expected. */ |
|
977
|
|
|
|
|
|
|
|
|
978
|
66
|
|
|
|
|
|
MAPPING_END_EVENT_INIT(*event, mark, mark); |
|
979
|
|
|
|
|
|
|
|
|
980
|
66
|
|
|
|
|
|
return 1; |
|
981
|
|
|
|
|
|
|
} |
|
982
|
|
|
|
|
|
|
|
|
983
|
|
|
|
|
|
|
/* |
|
984
|
|
|
|
|
|
|
* Destroy an event object. |
|
985
|
|
|
|
|
|
|
*/ |
|
986
|
|
|
|
|
|
|
|
|
987
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
988
|
1749
|
|
|
|
|
|
yaml_event_delete(yaml_event_t *event) |
|
989
|
|
|
|
|
|
|
{ |
|
990
|
|
|
|
|
|
|
yaml_tag_directive_t *tag_directive; |
|
991
|
|
|
|
|
|
|
|
|
992
|
1749
|
50
|
|
|
|
|
assert(event); /* Non-NULL event object expected. */ |
|
993
|
|
|
|
|
|
|
|
|
994
|
1749
|
|
|
|
|
|
switch (event->type) |
|
995
|
|
|
|
|
|
|
{ |
|
996
|
|
|
|
|
|
|
case YAML_DOCUMENT_START_EVENT: |
|
997
|
215
|
|
|
|
|
|
yaml_free(event->data.document_start.version_directive); |
|
998
|
215
|
50
|
|
|
|
|
for (tag_directive = event->data.document_start.tag_directives.start; |
|
999
|
215
|
|
|
|
|
|
tag_directive != event->data.document_start.tag_directives.end; |
|
1000
|
0
|
|
|
|
|
|
tag_directive++) { |
|
1001
|
0
|
|
|
|
|
|
yaml_free(tag_directive->handle); |
|
1002
|
0
|
|
|
|
|
|
yaml_free(tag_directive->prefix); |
|
1003
|
|
|
|
|
|
|
} |
|
1004
|
215
|
|
|
|
|
|
yaml_free(event->data.document_start.tag_directives.start); |
|
1005
|
215
|
|
|
|
|
|
break; |
|
1006
|
|
|
|
|
|
|
|
|
1007
|
|
|
|
|
|
|
case YAML_ALIAS_EVENT: |
|
1008
|
33
|
|
|
|
|
|
yaml_free(event->data.alias.anchor); |
|
1009
|
33
|
|
|
|
|
|
break; |
|
1010
|
|
|
|
|
|
|
|
|
1011
|
|
|
|
|
|
|
case YAML_SCALAR_EVENT: |
|
1012
|
637
|
|
|
|
|
|
yaml_free(event->data.scalar.anchor); |
|
1013
|
637
|
|
|
|
|
|
yaml_free(event->data.scalar.tag); |
|
1014
|
637
|
|
|
|
|
|
yaml_free(event->data.scalar.value); |
|
1015
|
637
|
|
|
|
|
|
break; |
|
1016
|
|
|
|
|
|
|
|
|
1017
|
|
|
|
|
|
|
case YAML_SEQUENCE_START_EVENT: |
|
1018
|
95
|
|
|
|
|
|
yaml_free(event->data.sequence_start.anchor); |
|
1019
|
95
|
|
|
|
|
|
yaml_free(event->data.sequence_start.tag); |
|
1020
|
95
|
|
|
|
|
|
break; |
|
1021
|
|
|
|
|
|
|
|
|
1022
|
|
|
|
|
|
|
case YAML_MAPPING_START_EVENT: |
|
1023
|
139
|
|
|
|
|
|
yaml_free(event->data.mapping_start.anchor); |
|
1024
|
139
|
|
|
|
|
|
yaml_free(event->data.mapping_start.tag); |
|
1025
|
139
|
|
|
|
|
|
break; |
|
1026
|
|
|
|
|
|
|
|
|
1027
|
|
|
|
|
|
|
default: |
|
1028
|
630
|
|
|
|
|
|
break; |
|
1029
|
|
|
|
|
|
|
} |
|
1030
|
|
|
|
|
|
|
|
|
1031
|
1749
|
|
|
|
|
|
memset(event, 0, sizeof(yaml_event_t)); |
|
1032
|
1749
|
|
|
|
|
|
} |
|
1033
|
|
|
|
|
|
|
|
|
1034
|
|
|
|
|
|
|
/* |
|
1035
|
|
|
|
|
|
|
* Create a document object. |
|
1036
|
|
|
|
|
|
|
*/ |
|
1037
|
|
|
|
|
|
|
|
|
1038
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
1039
|
0
|
|
|
|
|
|
yaml_document_initialize(yaml_document_t *document, |
|
1040
|
|
|
|
|
|
|
yaml_version_directive_t *version_directive, |
|
1041
|
|
|
|
|
|
|
yaml_tag_directive_t *tag_directives_start, |
|
1042
|
|
|
|
|
|
|
yaml_tag_directive_t *tag_directives_end, |
|
1043
|
|
|
|
|
|
|
int start_implicit, int end_implicit) |
|
1044
|
|
|
|
|
|
|
{ |
|
1045
|
|
|
|
|
|
|
struct { |
|
1046
|
|
|
|
|
|
|
yaml_error_type_t error; |
|
1047
|
|
|
|
|
|
|
} context; |
|
1048
|
|
|
|
|
|
|
struct { |
|
1049
|
|
|
|
|
|
|
yaml_node_t *start; |
|
1050
|
|
|
|
|
|
|
yaml_node_t *end; |
|
1051
|
|
|
|
|
|
|
yaml_node_t *top; |
|
1052
|
0
|
|
|
|
|
|
} nodes = { NULL, NULL, NULL }; |
|
1053
|
0
|
|
|
|
|
|
yaml_version_directive_t *version_directive_copy = NULL; |
|
1054
|
|
|
|
|
|
|
struct { |
|
1055
|
|
|
|
|
|
|
yaml_tag_directive_t *start; |
|
1056
|
|
|
|
|
|
|
yaml_tag_directive_t *end; |
|
1057
|
|
|
|
|
|
|
yaml_tag_directive_t *top; |
|
1058
|
0
|
|
|
|
|
|
} tag_directives_copy = { NULL, NULL, NULL }; |
|
1059
|
0
|
|
|
|
|
|
yaml_tag_directive_t value = { NULL, NULL }; |
|
1060
|
0
|
|
|
|
|
|
yaml_mark_t mark = { 0, 0, 0 }; |
|
1061
|
|
|
|
|
|
|
|
|
1062
|
0
|
0
|
|
|
|
|
assert(document); /* Non-NULL document object is expected. */ |
|
1063
|
0
|
0
|
|
|
|
|
assert((tag_directives_start && tag_directives_end) || |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
1064
|
|
|
|
|
|
|
(tag_directives_start == tag_directives_end)); |
|
1065
|
|
|
|
|
|
|
/* Valid tag directives are expected. */ |
|
1066
|
|
|
|
|
|
|
|
|
1067
|
0
|
0
|
|
|
|
|
if (!STACK_INIT(&context, nodes, yaml_node_t*)) goto error; |
|
|
|
0
|
|
|
|
|
|
|
1068
|
|
|
|
|
|
|
|
|
1069
|
0
|
0
|
|
|
|
|
if (version_directive) { |
|
1070
|
0
|
|
|
|
|
|
version_directive_copy = YAML_MALLOC_STATIC(yaml_version_directive_t); |
|
1071
|
0
|
0
|
|
|
|
|
if (!version_directive_copy) goto error; |
|
1072
|
0
|
|
|
|
|
|
version_directive_copy->major = version_directive->major; |
|
1073
|
0
|
|
|
|
|
|
version_directive_copy->minor = version_directive->minor; |
|
1074
|
|
|
|
|
|
|
} |
|
1075
|
|
|
|
|
|
|
|
|
1076
|
0
|
0
|
|
|
|
|
if (tag_directives_start != tag_directives_end) { |
|
1077
|
|
|
|
|
|
|
yaml_tag_directive_t *tag_directive; |
|
1078
|
0
|
0
|
|
|
|
|
if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*)) |
|
|
|
0
|
|
|
|
|
|
|
1079
|
0
|
|
|
|
|
|
goto error; |
|
1080
|
0
|
0
|
|
|
|
|
for (tag_directive = tag_directives_start; |
|
1081
|
0
|
|
|
|
|
|
tag_directive != tag_directives_end; tag_directive ++) { |
|
1082
|
0
|
0
|
|
|
|
|
assert(tag_directive->handle); |
|
1083
|
0
|
0
|
|
|
|
|
assert(tag_directive->prefix); |
|
1084
|
0
|
0
|
|
|
|
|
if (!yaml_check_utf8(tag_directive->handle, |
|
1085
|
0
|
|
|
|
|
|
strlen((char *)tag_directive->handle))) |
|
1086
|
0
|
|
|
|
|
|
goto error; |
|
1087
|
0
|
0
|
|
|
|
|
if (!yaml_check_utf8(tag_directive->prefix, |
|
1088
|
0
|
|
|
|
|
|
strlen((char *)tag_directive->prefix))) |
|
1089
|
0
|
|
|
|
|
|
goto error; |
|
1090
|
0
|
|
|
|
|
|
value.handle = yaml_strdup(tag_directive->handle); |
|
1091
|
0
|
|
|
|
|
|
value.prefix = yaml_strdup(tag_directive->prefix); |
|
1092
|
0
|
0
|
|
|
|
|
if (!value.handle || !value.prefix) goto error; |
|
|
|
0
|
|
|
|
|
|
|
1093
|
0
|
0
|
|
|
|
|
if (!PUSH(&context, tag_directives_copy, value)) |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
1094
|
0
|
|
|
|
|
|
goto error; |
|
1095
|
0
|
|
|
|
|
|
value.handle = NULL; |
|
1096
|
0
|
|
|
|
|
|
value.prefix = NULL; |
|
1097
|
|
|
|
|
|
|
} |
|
1098
|
|
|
|
|
|
|
} |
|
1099
|
|
|
|
|
|
|
|
|
1100
|
0
|
|
|
|
|
|
DOCUMENT_INIT(*document, nodes.start, nodes.end, version_directive_copy, |
|
1101
|
|
|
|
|
|
|
tag_directives_copy.start, tag_directives_copy.top, |
|
1102
|
|
|
|
|
|
|
start_implicit, end_implicit, mark, mark); |
|
1103
|
|
|
|
|
|
|
|
|
1104
|
0
|
|
|
|
|
|
return 1; |
|
1105
|
|
|
|
|
|
|
|
|
1106
|
|
|
|
|
|
|
error: |
|
1107
|
0
|
|
|
|
|
|
STACK_DEL(&context, nodes); |
|
1108
|
0
|
|
|
|
|
|
yaml_free(version_directive_copy); |
|
1109
|
0
|
0
|
|
|
|
|
while (!STACK_EMPTY(&context, tag_directives_copy)) { |
|
1110
|
0
|
|
|
|
|
|
value = POP(&context, tag_directives_copy); |
|
1111
|
0
|
|
|
|
|
|
yaml_free(value.handle); |
|
1112
|
0
|
|
|
|
|
|
yaml_free(value.prefix); |
|
1113
|
|
|
|
|
|
|
} |
|
1114
|
0
|
|
|
|
|
|
STACK_DEL(&context, tag_directives_copy); |
|
1115
|
0
|
|
|
|
|
|
yaml_free(value.handle); |
|
1116
|
0
|
|
|
|
|
|
yaml_free(value.prefix); |
|
1117
|
|
|
|
|
|
|
|
|
1118
|
0
|
|
|
|
|
|
return 0; |
|
1119
|
|
|
|
|
|
|
} |
|
1120
|
|
|
|
|
|
|
|
|
1121
|
|
|
|
|
|
|
/* |
|
1122
|
|
|
|
|
|
|
* Destroy a document object. |
|
1123
|
|
|
|
|
|
|
*/ |
|
1124
|
|
|
|
|
|
|
|
|
1125
|
|
|
|
|
|
|
YAML_DECLARE(void) |
|
1126
|
0
|
|
|
|
|
|
yaml_document_delete(yaml_document_t *document) |
|
1127
|
|
|
|
|
|
|
{ |
|
1128
|
|
|
|
|
|
|
yaml_tag_directive_t *tag_directive; |
|
1129
|
|
|
|
|
|
|
|
|
1130
|
0
|
0
|
|
|
|
|
assert(document); /* Non-NULL document object is expected. */ |
|
1131
|
|
|
|
|
|
|
|
|
1132
|
0
|
0
|
|
|
|
|
while (!STACK_EMPTY(&context, document->nodes)) { |
|
1133
|
0
|
|
|
|
|
|
yaml_node_t node = POP(&context, document->nodes); |
|
1134
|
0
|
|
|
|
|
|
yaml_free(node.tag); |
|
1135
|
0
|
|
|
|
|
|
switch (node.type) { |
|
1136
|
|
|
|
|
|
|
case YAML_SCALAR_NODE: |
|
1137
|
0
|
|
|
|
|
|
yaml_free(node.data.scalar.value); |
|
1138
|
0
|
|
|
|
|
|
break; |
|
1139
|
|
|
|
|
|
|
case YAML_SEQUENCE_NODE: |
|
1140
|
0
|
|
|
|
|
|
STACK_DEL(&context, node.data.sequence.items); |
|
1141
|
0
|
|
|
|
|
|
break; |
|
1142
|
|
|
|
|
|
|
case YAML_MAPPING_NODE: |
|
1143
|
0
|
|
|
|
|
|
STACK_DEL(&context, node.data.mapping.pairs); |
|
1144
|
0
|
|
|
|
|
|
break; |
|
1145
|
|
|
|
|
|
|
default: |
|
1146
|
0
|
|
|
|
|
|
assert(0); /* Should not happen. */ |
|
1147
|
|
|
|
|
|
|
} |
|
1148
|
|
|
|
|
|
|
} |
|
1149
|
0
|
|
|
|
|
|
STACK_DEL(&context, document->nodes); |
|
1150
|
|
|
|
|
|
|
|
|
1151
|
0
|
|
|
|
|
|
yaml_free(document->version_directive); |
|
1152
|
0
|
0
|
|
|
|
|
for (tag_directive = document->tag_directives.start; |
|
1153
|
0
|
|
|
|
|
|
tag_directive != document->tag_directives.end; |
|
1154
|
0
|
|
|
|
|
|
tag_directive++) { |
|
1155
|
0
|
|
|
|
|
|
yaml_free(tag_directive->handle); |
|
1156
|
0
|
|
|
|
|
|
yaml_free(tag_directive->prefix); |
|
1157
|
|
|
|
|
|
|
} |
|
1158
|
0
|
|
|
|
|
|
yaml_free(document->tag_directives.start); |
|
1159
|
|
|
|
|
|
|
|
|
1160
|
0
|
|
|
|
|
|
memset(document, 0, sizeof(yaml_document_t)); |
|
1161
|
0
|
|
|
|
|
|
} |
|
1162
|
|
|
|
|
|
|
|
|
1163
|
|
|
|
|
|
|
/** |
|
1164
|
|
|
|
|
|
|
* Get a document node. |
|
1165
|
|
|
|
|
|
|
*/ |
|
1166
|
|
|
|
|
|
|
|
|
1167
|
|
|
|
|
|
|
YAML_DECLARE(yaml_node_t *) |
|
1168
|
0
|
|
|
|
|
|
yaml_document_get_node(yaml_document_t *document, int index) |
|
1169
|
|
|
|
|
|
|
{ |
|
1170
|
0
|
0
|
|
|
|
|
assert(document); /* Non-NULL document object is expected. */ |
|
1171
|
|
|
|
|
|
|
|
|
1172
|
0
|
0
|
|
|
|
|
if (index > 0 && document->nodes.start + index <= document->nodes.top) { |
|
|
|
0
|
|
|
|
|
|
|
1173
|
0
|
|
|
|
|
|
return document->nodes.start + index - 1; |
|
1174
|
|
|
|
|
|
|
} |
|
1175
|
0
|
|
|
|
|
|
return NULL; |
|
1176
|
|
|
|
|
|
|
} |
|
1177
|
|
|
|
|
|
|
|
|
1178
|
|
|
|
|
|
|
/** |
|
1179
|
|
|
|
|
|
|
* Get the root object. |
|
1180
|
|
|
|
|
|
|
*/ |
|
1181
|
|
|
|
|
|
|
|
|
1182
|
|
|
|
|
|
|
YAML_DECLARE(yaml_node_t *) |
|
1183
|
0
|
|
|
|
|
|
yaml_document_get_root_node(yaml_document_t *document) |
|
1184
|
|
|
|
|
|
|
{ |
|
1185
|
0
|
0
|
|
|
|
|
assert(document); /* Non-NULL document object is expected. */ |
|
1186
|
|
|
|
|
|
|
|
|
1187
|
0
|
0
|
|
|
|
|
if (document->nodes.top != document->nodes.start) { |
|
1188
|
0
|
|
|
|
|
|
return document->nodes.start; |
|
1189
|
|
|
|
|
|
|
} |
|
1190
|
0
|
|
|
|
|
|
return NULL; |
|
1191
|
|
|
|
|
|
|
} |
|
1192
|
|
|
|
|
|
|
|
|
1193
|
|
|
|
|
|
|
/* |
|
1194
|
|
|
|
|
|
|
* Add a scalar node to a document. |
|
1195
|
|
|
|
|
|
|
*/ |
|
1196
|
|
|
|
|
|
|
|
|
1197
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
1198
|
0
|
|
|
|
|
|
yaml_document_add_scalar(yaml_document_t *document, |
|
1199
|
|
|
|
|
|
|
const yaml_char_t *tag, const yaml_char_t *value, int length, |
|
1200
|
|
|
|
|
|
|
yaml_scalar_style_t style) |
|
1201
|
|
|
|
|
|
|
{ |
|
1202
|
|
|
|
|
|
|
struct { |
|
1203
|
|
|
|
|
|
|
yaml_error_type_t error; |
|
1204
|
|
|
|
|
|
|
} context; |
|
1205
|
0
|
|
|
|
|
|
yaml_mark_t mark = { 0, 0, 0 }; |
|
1206
|
0
|
|
|
|
|
|
yaml_char_t *tag_copy = NULL; |
|
1207
|
0
|
|
|
|
|
|
yaml_char_t *value_copy = NULL; |
|
1208
|
|
|
|
|
|
|
yaml_node_t node; |
|
1209
|
|
|
|
|
|
|
|
|
1210
|
0
|
0
|
|
|
|
|
assert(document); /* Non-NULL document object is expected. */ |
|
1211
|
0
|
0
|
|
|
|
|
assert(value); /* Non-NULL value is expected. */ |
|
1212
|
|
|
|
|
|
|
|
|
1213
|
0
|
0
|
|
|
|
|
if (!tag) { |
|
1214
|
0
|
|
|
|
|
|
tag = (yaml_char_t *)YAML_DEFAULT_SCALAR_TAG; |
|
1215
|
|
|
|
|
|
|
} |
|
1216
|
|
|
|
|
|
|
|
|
1217
|
0
|
0
|
|
|
|
|
if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; |
|
1218
|
0
|
|
|
|
|
|
tag_copy = yaml_strdup(tag); |
|
1219
|
0
|
0
|
|
|
|
|
if (!tag_copy) goto error; |
|
1220
|
|
|
|
|
|
|
|
|
1221
|
0
|
0
|
|
|
|
|
if (length < 0) { |
|
1222
|
0
|
|
|
|
|
|
length = strlen((char *)value); |
|
1223
|
|
|
|
|
|
|
} |
|
1224
|
|
|
|
|
|
|
|
|
1225
|
0
|
0
|
|
|
|
|
if (!yaml_check_utf8(value, length)) goto error; |
|
1226
|
0
|
|
|
|
|
|
value_copy = YAML_MALLOC(length+1); |
|
1227
|
0
|
0
|
|
|
|
|
if (!value_copy) goto error; |
|
1228
|
0
|
|
|
|
|
|
memcpy(value_copy, value, length); |
|
1229
|
0
|
|
|
|
|
|
value_copy[length] = '\0'; |
|
1230
|
|
|
|
|
|
|
|
|
1231
|
0
|
|
|
|
|
|
SCALAR_NODE_INIT(node, tag_copy, value_copy, length, style, mark, mark); |
|
1232
|
0
|
0
|
|
|
|
|
if (!PUSH(&context, document->nodes, node)) goto error; |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
1233
|
|
|
|
|
|
|
|
|
1234
|
0
|
|
|
|
|
|
return document->nodes.top - document->nodes.start; |
|
1235
|
|
|
|
|
|
|
|
|
1236
|
|
|
|
|
|
|
error: |
|
1237
|
0
|
|
|
|
|
|
yaml_free(tag_copy); |
|
1238
|
0
|
|
|
|
|
|
yaml_free(value_copy); |
|
1239
|
|
|
|
|
|
|
|
|
1240
|
0
|
|
|
|
|
|
return 0; |
|
1241
|
|
|
|
|
|
|
} |
|
1242
|
|
|
|
|
|
|
|
|
1243
|
|
|
|
|
|
|
/* |
|
1244
|
|
|
|
|
|
|
* Add a sequence node to a document. |
|
1245
|
|
|
|
|
|
|
*/ |
|
1246
|
|
|
|
|
|
|
|
|
1247
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
1248
|
0
|
|
|
|
|
|
yaml_document_add_sequence(yaml_document_t *document, |
|
1249
|
|
|
|
|
|
|
const yaml_char_t *tag, yaml_sequence_style_t style) |
|
1250
|
|
|
|
|
|
|
{ |
|
1251
|
|
|
|
|
|
|
struct { |
|
1252
|
|
|
|
|
|
|
yaml_error_type_t error; |
|
1253
|
|
|
|
|
|
|
} context; |
|
1254
|
0
|
|
|
|
|
|
yaml_mark_t mark = { 0, 0, 0 }; |
|
1255
|
0
|
|
|
|
|
|
yaml_char_t *tag_copy = NULL; |
|
1256
|
|
|
|
|
|
|
struct { |
|
1257
|
|
|
|
|
|
|
yaml_node_item_t *start; |
|
1258
|
|
|
|
|
|
|
yaml_node_item_t *end; |
|
1259
|
|
|
|
|
|
|
yaml_node_item_t *top; |
|
1260
|
0
|
|
|
|
|
|
} items = { NULL, NULL, NULL }; |
|
1261
|
|
|
|
|
|
|
yaml_node_t node; |
|
1262
|
|
|
|
|
|
|
|
|
1263
|
0
|
0
|
|
|
|
|
assert(document); /* Non-NULL document object is expected. */ |
|
1264
|
|
|
|
|
|
|
|
|
1265
|
0
|
0
|
|
|
|
|
if (!tag) { |
|
1266
|
0
|
|
|
|
|
|
tag = (yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG; |
|
1267
|
|
|
|
|
|
|
} |
|
1268
|
|
|
|
|
|
|
|
|
1269
|
0
|
0
|
|
|
|
|
if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; |
|
1270
|
0
|
|
|
|
|
|
tag_copy = yaml_strdup(tag); |
|
1271
|
0
|
0
|
|
|
|
|
if (!tag_copy) goto error; |
|
1272
|
|
|
|
|
|
|
|
|
1273
|
0
|
0
|
|
|
|
|
if (!STACK_INIT(&context, items, yaml_node_item_t*)) goto error; |
|
|
|
0
|
|
|
|
|
|
|
1274
|
|
|
|
|
|
|
|
|
1275
|
0
|
|
|
|
|
|
SEQUENCE_NODE_INIT(node, tag_copy, items.start, items.end, |
|
1276
|
|
|
|
|
|
|
style, mark, mark); |
|
1277
|
0
|
0
|
|
|
|
|
if (!PUSH(&context, document->nodes, node)) goto error; |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
1278
|
|
|
|
|
|
|
|
|
1279
|
0
|
|
|
|
|
|
return document->nodes.top - document->nodes.start; |
|
1280
|
|
|
|
|
|
|
|
|
1281
|
|
|
|
|
|
|
error: |
|
1282
|
0
|
|
|
|
|
|
STACK_DEL(&context, items); |
|
1283
|
0
|
|
|
|
|
|
yaml_free(tag_copy); |
|
1284
|
|
|
|
|
|
|
|
|
1285
|
0
|
|
|
|
|
|
return 0; |
|
1286
|
|
|
|
|
|
|
} |
|
1287
|
|
|
|
|
|
|
|
|
1288
|
|
|
|
|
|
|
/* |
|
1289
|
|
|
|
|
|
|
* Add a mapping node to a document. |
|
1290
|
|
|
|
|
|
|
*/ |
|
1291
|
|
|
|
|
|
|
|
|
1292
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
1293
|
0
|
|
|
|
|
|
yaml_document_add_mapping(yaml_document_t *document, |
|
1294
|
|
|
|
|
|
|
const yaml_char_t *tag, yaml_mapping_style_t style) |
|
1295
|
|
|
|
|
|
|
{ |
|
1296
|
|
|
|
|
|
|
struct { |
|
1297
|
|
|
|
|
|
|
yaml_error_type_t error; |
|
1298
|
|
|
|
|
|
|
} context; |
|
1299
|
0
|
|
|
|
|
|
yaml_mark_t mark = { 0, 0, 0 }; |
|
1300
|
0
|
|
|
|
|
|
yaml_char_t *tag_copy = NULL; |
|
1301
|
|
|
|
|
|
|
struct { |
|
1302
|
|
|
|
|
|
|
yaml_node_pair_t *start; |
|
1303
|
|
|
|
|
|
|
yaml_node_pair_t *end; |
|
1304
|
|
|
|
|
|
|
yaml_node_pair_t *top; |
|
1305
|
0
|
|
|
|
|
|
} pairs = { NULL, NULL, NULL }; |
|
1306
|
|
|
|
|
|
|
yaml_node_t node; |
|
1307
|
|
|
|
|
|
|
|
|
1308
|
0
|
0
|
|
|
|
|
assert(document); /* Non-NULL document object is expected. */ |
|
1309
|
|
|
|
|
|
|
|
|
1310
|
0
|
0
|
|
|
|
|
if (!tag) { |
|
1311
|
0
|
|
|
|
|
|
tag = (yaml_char_t *)YAML_DEFAULT_MAPPING_TAG; |
|
1312
|
|
|
|
|
|
|
} |
|
1313
|
|
|
|
|
|
|
|
|
1314
|
0
|
0
|
|
|
|
|
if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; |
|
1315
|
0
|
|
|
|
|
|
tag_copy = yaml_strdup(tag); |
|
1316
|
0
|
0
|
|
|
|
|
if (!tag_copy) goto error; |
|
1317
|
|
|
|
|
|
|
|
|
1318
|
0
|
0
|
|
|
|
|
if (!STACK_INIT(&context, pairs, yaml_node_pair_t*)) goto error; |
|
|
|
0
|
|
|
|
|
|
|
1319
|
|
|
|
|
|
|
|
|
1320
|
0
|
|
|
|
|
|
MAPPING_NODE_INIT(node, tag_copy, pairs.start, pairs.end, |
|
1321
|
|
|
|
|
|
|
style, mark, mark); |
|
1322
|
0
|
0
|
|
|
|
|
if (!PUSH(&context, document->nodes, node)) goto error; |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
1323
|
|
|
|
|
|
|
|
|
1324
|
0
|
|
|
|
|
|
return document->nodes.top - document->nodes.start; |
|
1325
|
|
|
|
|
|
|
|
|
1326
|
|
|
|
|
|
|
error: |
|
1327
|
0
|
|
|
|
|
|
STACK_DEL(&context, pairs); |
|
1328
|
0
|
|
|
|
|
|
yaml_free(tag_copy); |
|
1329
|
|
|
|
|
|
|
|
|
1330
|
0
|
|
|
|
|
|
return 0; |
|
1331
|
|
|
|
|
|
|
} |
|
1332
|
|
|
|
|
|
|
|
|
1333
|
|
|
|
|
|
|
/* |
|
1334
|
|
|
|
|
|
|
* Append an item to a sequence node. |
|
1335
|
|
|
|
|
|
|
*/ |
|
1336
|
|
|
|
|
|
|
|
|
1337
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
1338
|
0
|
|
|
|
|
|
yaml_document_append_sequence_item(yaml_document_t *document, |
|
1339
|
|
|
|
|
|
|
int sequence, int item) |
|
1340
|
|
|
|
|
|
|
{ |
|
1341
|
|
|
|
|
|
|
struct { |
|
1342
|
|
|
|
|
|
|
yaml_error_type_t error; |
|
1343
|
|
|
|
|
|
|
} context; |
|
1344
|
|
|
|
|
|
|
|
|
1345
|
0
|
0
|
|
|
|
|
assert(document); /* Non-NULL document is required. */ |
|
1346
|
0
|
0
|
|
|
|
|
assert(sequence > 0 |
|
|
|
0
|
|
|
|
|
|
|
1347
|
|
|
|
|
|
|
&& document->nodes.start + sequence <= document->nodes.top); |
|
1348
|
|
|
|
|
|
|
/* Valid sequence id is required. */ |
|
1349
|
0
|
0
|
|
|
|
|
assert(document->nodes.start[sequence-1].type == YAML_SEQUENCE_NODE); |
|
1350
|
|
|
|
|
|
|
/* A sequence node is required. */ |
|
1351
|
0
|
0
|
|
|
|
|
assert(item > 0 && document->nodes.start + item <= document->nodes.top); |
|
|
|
0
|
|
|
|
|
|
|
1352
|
|
|
|
|
|
|
/* Valid item id is required. */ |
|
1353
|
|
|
|
|
|
|
|
|
1354
|
0
|
0
|
|
|
|
|
if (!PUSH(&context, |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
1355
|
|
|
|
|
|
|
document->nodes.start[sequence-1].data.sequence.items, item)) |
|
1356
|
0
|
|
|
|
|
|
return 0; |
|
1357
|
|
|
|
|
|
|
|
|
1358
|
0
|
|
|
|
|
|
return 1; |
|
1359
|
|
|
|
|
|
|
} |
|
1360
|
|
|
|
|
|
|
|
|
1361
|
|
|
|
|
|
|
/* |
|
1362
|
|
|
|
|
|
|
* Append a pair of a key and a value to a mapping node. |
|
1363
|
|
|
|
|
|
|
*/ |
|
1364
|
|
|
|
|
|
|
|
|
1365
|
|
|
|
|
|
|
YAML_DECLARE(int) |
|
1366
|
0
|
|
|
|
|
|
yaml_document_append_mapping_pair(yaml_document_t *document, |
|
1367
|
|
|
|
|
|
|
int mapping, int key, int value) |
|
1368
|
|
|
|
|
|
|
{ |
|
1369
|
|
|
|
|
|
|
struct { |
|
1370
|
|
|
|
|
|
|
yaml_error_type_t error; |
|
1371
|
|
|
|
|
|
|
} context; |
|
1372
|
|
|
|
|
|
|
|
|
1373
|
|
|
|
|
|
|
yaml_node_pair_t pair; |
|
1374
|
|
|
|
|
|
|
|
|
1375
|
0
|
0
|
|
|
|
|
assert(document); /* Non-NULL document is required. */ |
|
1376
|
0
|
0
|
|
|
|
|
assert(mapping > 0 |
|
|
|
0
|
|
|
|
|
|
|
1377
|
|
|
|
|
|
|
&& document->nodes.start + mapping <= document->nodes.top); |
|
1378
|
|
|
|
|
|
|
/* Valid mapping id is required. */ |
|
1379
|
0
|
0
|
|
|
|
|
assert(document->nodes.start[mapping-1].type == YAML_MAPPING_NODE); |
|
1380
|
|
|
|
|
|
|
/* A mapping node is required. */ |
|
1381
|
0
|
0
|
|
|
|
|
assert(key > 0 && document->nodes.start + key <= document->nodes.top); |
|
|
|
0
|
|
|
|
|
|
|
1382
|
|
|
|
|
|
|
/* Valid key id is required. */ |
|
1383
|
0
|
0
|
|
|
|
|
assert(value > 0 && document->nodes.start + value <= document->nodes.top); |
|
|
|
0
|
|
|
|
|
|
|
1384
|
|
|
|
|
|
|
/* Valid value id is required. */ |
|
1385
|
|
|
|
|
|
|
|
|
1386
|
0
|
|
|
|
|
|
pair.key = key; |
|
1387
|
0
|
|
|
|
|
|
pair.value = value; |
|
1388
|
|
|
|
|
|
|
|
|
1389
|
0
|
0
|
|
|
|
|
if (!PUSH(&context, |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
1390
|
|
|
|
|
|
|
document->nodes.start[mapping-1].data.mapping.pairs, pair)) |
|
1391
|
0
|
|
|
|
|
|
return 0; |
|
1392
|
|
|
|
|
|
|
|
|
1393
|
0
|
|
|
|
|
|
return 1; |
|
1394
|
|
|
|
|
|
|
} |
|
1395
|
|
|
|
|
|
|
|
|
1396
|
|
|
|
|
|
|
|