]>
Commit | Line | Data |
---|---|---|
721c1923 KS |
1 | /** |
2 | * @file yaml.h | |
3 | * @brief Public interface for libyaml. | |
4 | * | |
a51447c9 | 5 | * Include the header file with the code: |
721c1923 KS |
6 | * @code |
7 | * #include <yaml/yaml.h> | |
8 | * @endcode | |
9 | */ | |
9e05b78c | 10 | |
cec6fc98 KS |
11 | #ifndef YAML_H |
12 | #define YAML_H | |
9e05b78c KS |
13 | |
14 | #ifdef __cplusplus | |
15 | extern "C" { | |
16 | #endif | |
17 | ||
cec6fc98 | 18 | #include <stdlib.h> |
95b98ba9 KS |
19 | #include <stdio.h> |
20 | #include <string.h> | |
cec6fc98 | 21 | |
f642fd11 KS |
22 | /** |
23 | * @defgroup Export Definitions | |
24 | * @{ | |
25 | */ | |
26 | ||
27 | /** The public API declaration. */ | |
28 | ||
29 | #ifdef WIN32 | |
30 | # if defined(YAML_DECLARE_STATIC) | |
31 | # define YAML_DECLARE(type) type | |
32 | # elif defined(YAML_DECLARE_EXPORT) | |
33 | # define YAML_DECLARE(type) __declspec(dllexport) type | |
34 | # else | |
35 | # define YAML_DECLARE(type) __declspec(dllimport) type | |
36 | # endif | |
37 | #else | |
38 | # define YAML_DECLARE(type) type | |
39 | #endif | |
40 | ||
41 | /** @} */ | |
42 | ||
a51447c9 KS |
43 | /** |
44 | * @defgroup version Version Information | |
45 | * @{ | |
46 | */ | |
47 | ||
48 | /** | |
49 | * Get the library version as a string. | |
50 | * | |
51 | * @returns The function returns the pointer to a static string of the form | |
52 | * @c "X.Y.Z", where @c X is the major version number, @c Y is a minor version | |
53 | * number, and @c Z is the patch version number. | |
54 | */ | |
55 | ||
f642fd11 | 56 | YAML_DECLARE(const char *) |
a51447c9 KS |
57 | yaml_get_version_string(void); |
58 | ||
59 | /** | |
60 | * Get the library version numbers. | |
61 | * | |
62 | * @param[out] major Major version number. | |
63 | * @param[out] minor Minor version number. | |
64 | * @param[out] patch Patch version number. | |
65 | */ | |
66 | ||
f642fd11 | 67 | YAML_DECLARE(void) |
a51447c9 KS |
68 | yaml_get_version(int *major, int *minor, int *patch); |
69 | ||
70 | /** @} */ | |
71 | ||
72 | /** | |
73 | * @defgroup basic Basic Types | |
74 | * @{ | |
75 | */ | |
76 | ||
f642fd11 | 77 | /** The character type (UTF-8 octet). */ |
a51447c9 | 78 | typedef unsigned char yaml_char_t; |
9e05b78c | 79 | |
a51447c9 | 80 | /** The stream encoding. */ |
9e05b78c | 81 | typedef enum { |
a51447c9 | 82 | YAML_ANY_ENCODING, |
9e05b78c KS |
83 | YAML_UTF8_ENCODING, |
84 | YAML_UTF16LE_ENCODING, | |
85 | YAML_UTF16BE_ENCODING | |
86 | } yaml_encoding_t; | |
87 | ||
95b98ba9 | 88 | /** Many bad things could happen with the parser and emitter. */ |
a51447c9 KS |
89 | typedef enum { |
90 | YAML_NO_ERROR, | |
91 | ||
92 | YAML_MEMORY_ERROR, | |
93 | ||
94 | YAML_READER_ERROR, | |
95 | YAML_SCANNER_ERROR, | |
96 | YAML_PARSER_ERROR, | |
97 | ||
98 | YAML_WRITER_ERROR, | |
99 | YAML_EMITTER_ERROR | |
100 | } yaml_error_type_t; | |
101 | ||
f642fd11 KS |
102 | /** The pointer position. */ |
103 | typedef struct { | |
104 | /** The position index. */ | |
105 | size_t index; | |
106 | ||
107 | /** The position line. */ | |
108 | size_t line; | |
109 | ||
110 | /** The position column. */ | |
111 | size_t column; | |
112 | } yaml_mark_t; | |
113 | ||
95b98ba9 KS |
114 | /** @} */ |
115 | ||
f642fd11 KS |
116 | /** |
117 | * @defgroup Node Styles | |
118 | * @{ | |
119 | */ | |
95b98ba9 | 120 | |
f642fd11 | 121 | /** Scalar styles. */ |
9e05b78c | 122 | typedef enum { |
cec6fc98 | 123 | YAML_ANY_SCALAR_STYLE, |
f642fd11 | 124 | |
9e05b78c | 125 | YAML_PLAIN_SCALAR_STYLE, |
f642fd11 | 126 | |
9e05b78c KS |
127 | YAML_SINGLE_QUOTED_SCALAR_STYLE, |
128 | YAML_DOUBLE_QUOTED_SCALAR_STYLE, | |
f642fd11 | 129 | |
9e05b78c KS |
130 | YAML_LITERAL_SCALAR_STYLE, |
131 | YAML_FOLDED_SCALAR_STYLE | |
132 | } yaml_scalar_style_t; | |
133 | ||
f642fd11 KS |
134 | |
135 | /** Sequence styles. */ | |
9e05b78c | 136 | typedef enum { |
cec6fc98 | 137 | YAML_ANY_SEQUENCE_STYLE, |
f642fd11 | 138 | |
9e05b78c KS |
139 | YAML_BLOCK_SEQUENCE_STYLE, |
140 | YAML_FLOW_SEQUENCE_STYLE | |
141 | } yaml_sequence_style_t; | |
142 | ||
f642fd11 | 143 | /** Mapping styles. */ |
9e05b78c | 144 | typedef enum { |
cec6fc98 | 145 | YAML_ANY_MAPPING_STYLE, |
f642fd11 | 146 | |
9e05b78c KS |
147 | YAML_BLOCK_MAPPING_STYLE, |
148 | YAML_FLOW_MAPPING_STYLE | |
149 | } yaml_mapping_style_t; | |
150 | ||
f642fd11 KS |
151 | /** @} */ |
152 | ||
153 | /** | |
154 | * @defgroup Tokens | |
155 | * @{ | |
156 | */ | |
157 | ||
158 | /** Token types. */ | |
9e05b78c KS |
159 | typedef enum { |
160 | YAML_STREAM_START_TOKEN, | |
161 | YAML_STREAM_END_TOKEN, | |
cec6fc98 | 162 | |
9e05b78c KS |
163 | YAML_VERSION_DIRECTIVE_TOKEN, |
164 | YAML_TAG_DIRECTIVE_TOKEN, | |
165 | YAML_DOCUMENT_START_TOKEN, | |
166 | YAML_DOCUMENT_END_TOKEN, | |
cec6fc98 | 167 | |
9e05b78c KS |
168 | YAML_BLOCK_SEQUENCE_START_TOKEN, |
169 | YAML_BLOCK_MAPPING_START_TOKEN, | |
170 | YAML_BLOCK_END_TOKEN, | |
cec6fc98 | 171 | |
9e05b78c KS |
172 | YAML_FLOW_SEQUENCE_START_TOKEN, |
173 | YAML_FLOW_SEQUENCE_END_TOKEN, | |
174 | YAML_FLOW_MAPPING_START_TOKEN, | |
175 | YAML_FLOW_MAPPING_END_TOKEN, | |
cec6fc98 | 176 | |
9e05b78c KS |
177 | YAML_BLOCK_ENTRY_TOKEN, |
178 | YAML_FLOW_ENTRY_TOKEN, | |
179 | YAML_KEY_TOKEN, | |
180 | YAML_VALUE_TOKEN, | |
cec6fc98 | 181 | |
9e05b78c KS |
182 | YAML_ALIAS_TOKEN, |
183 | YAML_ANCHOR_TOKEN, | |
184 | YAML_TAG_TOKEN, | |
185 | YAML_SCALAR_TOKEN | |
186 | } yaml_token_type_t; | |
187 | ||
f642fd11 KS |
188 | /** The token structure. */ |
189 | typedef struct { | |
cec6fc98 | 190 | |
f642fd11 KS |
191 | /** The token type. */ |
192 | yaml_token_type_t type; | |
cec6fc98 | 193 | |
f642fd11 KS |
194 | /** The token data. */ |
195 | union { | |
cec6fc98 | 196 | |
f642fd11 KS |
197 | /** The stream encoding (for @c YAML_STREAM_START_TOKEN). */ |
198 | yaml_encoding_t encoding; | |
cec6fc98 | 199 | |
f642fd11 KS |
200 | /** The anchor (for @c YAML_ALIAS_TOKEN and @c YAML_ANCHOR_TOKEN). */ |
201 | yaml_char_t *anchor; | |
9e05b78c | 202 | |
f642fd11 KS |
203 | /** The tag (for @c YAML_TAG_TOKEN). */ |
204 | struct { | |
205 | /** The tag handle. */ | |
206 | yaml_char_t *handle; | |
9e05b78c | 207 | |
f642fd11 KS |
208 | /** The tag suffix. */ |
209 | yaml_char_t *suffix; | |
210 | } tag; | |
9e05b78c | 211 | |
f642fd11 | 212 | /** The scalar value (for @c YAML_SCALAR_TOKEN). */ |
9e05b78c | 213 | struct { |
f642fd11 KS |
214 | |
215 | /** The scalar value. */ | |
216 | yaml_char_t *value; | |
217 | ||
218 | /** The length of the scalar value. */ | |
cec6fc98 | 219 | size_t length; |
f642fd11 KS |
220 | |
221 | /** The scalar style. */ | |
9e05b78c KS |
222 | yaml_scalar_style_t style; |
223 | } scalar; | |
f642fd11 KS |
224 | |
225 | /** The version directive (for @c YAML_VERSION_DIRECTIVE_TOKEN). */ | |
9e05b78c | 226 | struct { |
f642fd11 | 227 | /** The major version number. */ |
9e05b78c | 228 | int major; |
f642fd11 KS |
229 | |
230 | /** The minor version number. */ | |
9e05b78c | 231 | int minor; |
f642fd11 KS |
232 | } version_directive; |
233 | ||
234 | /** The tag directive (for @c YAML_TAG_DIRECTIVE_TOKEN). */ | |
9e05b78c | 235 | struct { |
f642fd11 KS |
236 | /** The tag handle. */ |
237 | yaml_char_t *handle; | |
238 | ||
239 | /** The tag prefix. */ | |
240 | yaml_char_t *prefix; | |
241 | } tag_directive; | |
9e05b78c | 242 | } data; |
f642fd11 KS |
243 | |
244 | /** The beginning of the token. */ | |
9e05b78c | 245 | yaml_mark_t start_mark; |
f642fd11 KS |
246 | |
247 | /** The end of the token. */ | |
9e05b78c | 248 | yaml_mark_t end_mark; |
f642fd11 | 249 | |
9e05b78c KS |
250 | } yaml_token_t; |
251 | ||
f642fd11 KS |
252 | /** |
253 | * Create a new token without assigning any data. | |
254 | * | |
255 | * This function can be used for constructing indicator tokens: | |
256 | * @c YAML_DOCUMENT_START, @c YAML_DOCUMENT_END, | |
257 | * @c YAML_BLOCK_SEQUENCE_START_TOKEN, @c YAML_BLOCK_MAPPING_START_TOKEN, | |
258 | * @c YAML_BLOCK_END_TOKEN, | |
259 | * @c YAML_FLOW_SEQUENCE_START_TOKEN, @c YAML_FLOW_SEQUENCE_END_TOKEN, | |
260 | * @c YAML_FLOW_MAPPING_START_TOKEN, @c YAML_FLOW_MAPPING_END_TOKEN, | |
261 | * @c YAML_BLOCK_ENTRY_TOKEN, @c YAML_FLOW_ENTRY_TOKEN, | |
262 | * @c YAML_KEY_TOKEN, @c YAML_VALUE_TOKEN. | |
263 | * | |
264 | * @param[in] type The token type. | |
265 | * @param[in] start_mark The beginning of the token. | |
266 | * @param[in] end_mark The end of the token. | |
267 | * | |
268 | * @returns A new token object, or @c NULL on error. | |
269 | */ | |
270 | ||
271 | YAML_DECLARE(yaml_token_t *) | |
272 | yaml_token_new(yaml_token_type_t type, | |
273 | yaml_mark_t start_mark, yaml_mark_t end_mark); | |
274 | ||
275 | /** | |
276 | * Create a new @c YAML_STREAM_START_TOKEN token with the specified encoding. | |
277 | * | |
278 | * @param[in] encoding The stream encoding. | |
279 | * @param[in] start_mark The beginning of the token. | |
280 | * @param[in] end_mark The end of the token. | |
281 | * | |
282 | * @returns A new token object, or @c NULL on error. | |
283 | */ | |
284 | ||
285 | YAML_DECLARE(yaml_token_t *) | |
286 | yaml_stream_start_token_new(yaml_encoding_t encoding, | |
287 | yaml_mark_t start_mark, yaml_mark_t end_mark); | |
288 | ||
289 | /** | |
290 | * Create a new @c YAML_STREAM_END_TOKEN token. | |
291 | * | |
292 | * @param[in] start_mark The beginning of the token. | |
293 | * @param[in] end_mark The end of the token. | |
294 | * | |
295 | * @returns A new token object, or @c NULL on error. | |
296 | */ | |
297 | ||
298 | YAML_DECLARE(yaml_token_t *) | |
299 | yaml_stream_end_token_new(yaml_mark_t start_mark, yaml_mark_t end_mark); | |
300 | ||
301 | /** | |
302 | * Create a new @c YAML_VERSION_DIRECTIVE_TOKEN token with the specified | |
303 | * version numbers. | |
304 | * | |
305 | * @param[in] major The major version number. | |
306 | * @param[in] minor The minor version number. | |
307 | * @param[in] start_mark The beginning of the token. | |
308 | * @param[in] end_mark The end of the token. | |
309 | * | |
310 | * @returns A new token object, or @c NULL on error. | |
311 | */ | |
312 | ||
313 | YAML_DECLARE(yaml_token_t *) | |
314 | yaml_version_directive_token_new(int major, int minor, | |
315 | yaml_mark_t start_mark, yaml_mark_t end_mark); | |
316 | ||
317 | /** | |
318 | * Create a new @c YAML_TAG_DIRECTIVE_TOKEN token with the specified tag | |
319 | * handle and prefix. | |
320 | * | |
321 | * Note that the @a handle and the @a prefix pointers will be freed by | |
322 | * the token descructor. | |
323 | * | |
324 | * @param[in] handle The tag handle. | |
325 | * @param[in] prefix The tag prefix. | |
326 | * @param[in] start_mark The beginning of the token. | |
327 | * @param[in] end_mark The end of the token. | |
328 | * | |
329 | * @returns A new token object, or @c NULL on error. | |
330 | */ | |
331 | ||
332 | YAML_DECLARE(yaml_token_t *) | |
333 | yaml_tag_directive_token_new(yaml_char_t *handle, yaml_char_t *prefix, | |
334 | yaml_mark_t start_mark, yaml_mark_t end_mark); | |
335 | ||
336 | /** | |
337 | * Create a new @c YAML_ALIAS_TOKEN token with the specified anchor. | |
338 | * | |
339 | * Note that the @a anchor pointer will be freed by the token descructor. | |
340 | * | |
341 | * @param[in] anchor The anchor. | |
342 | * @param[in] start_mark The beginning of the token. | |
343 | * @param[in] end_mark The end of the token. | |
344 | * | |
345 | * @returns A new token object, or @c NULL on error. | |
346 | */ | |
347 | ||
348 | YAML_DECLARE(yaml_token_t *) | |
349 | yaml_alias_token_new(yaml_char_t *anchor, | |
350 | yaml_mark_t start_mark, yaml_mark_t end_mark); | |
351 | ||
352 | /** | |
353 | * Create a new @c YAML_ANCHOR_TOKEN token with the specified anchor. | |
354 | * | |
355 | * Note that the @a anchor pointer will be freed by the token descructor. | |
356 | * | |
357 | * @param[in] anchor The anchor. | |
358 | * @param[in] start_mark The beginning of the token. | |
359 | * @param[in] end_mark The end of the token. | |
360 | * | |
361 | * @returns A new token object, or @c NULL on error. | |
362 | */ | |
363 | ||
364 | YAML_DECLARE(yaml_token_t *) | |
365 | yaml_anchor_token_new(yaml_char_t *anchor, | |
366 | yaml_mark_t start_mark, yaml_mark_t end_mark); | |
367 | ||
368 | /** | |
369 | * Create a new @c YAML_TAG_TOKEN token with the specified tag handle and | |
370 | * suffix. | |
371 | * | |
372 | * Note that the @a handle and the @a suffix pointers will be freed by | |
373 | * the token descructor. | |
374 | * | |
375 | * @param[in] handle The tag handle. | |
376 | * @param[in] suffix The tag suffix. | |
377 | * @param[in] start_mark The beginning of the token. | |
378 | * @param[in] end_mark The end of the token. | |
379 | * | |
380 | * @returns A new token object, or @c NULL on error. | |
381 | */ | |
382 | ||
383 | YAML_DECLARE(yaml_token_t *) | |
384 | yaml_tag_token_new(yaml_char_t *handle, yaml_char_t *suffix, | |
385 | yaml_mark_t start_mark, yaml_mark_t end_mark); | |
386 | ||
387 | /** | |
388 | * Create a new @c YAML_SCALAR_TOKEN token with the specified scalar value, | |
389 | * length, and style. | |
390 | * | |
391 | * Note that the scalar value may contain the @c NUL character, therefore | |
392 | * the value length is also required. The scalar value always ends with | |
393 | * @c NUL. | |
394 | * | |
395 | * Note that the @a value pointer will be freed by the token descructor. | |
396 | * | |
397 | * @param[in] value The scalar value. | |
398 | * @param[in] length The value length. | |
399 | * @param[in] style The scalar style. | |
400 | * @param[in] start_mark The beginning of the token. | |
401 | * @param[in] end_mark The end of the token. | |
402 | * | |
403 | * @returns A new token object, or @c NULL on error. | |
404 | */ | |
405 | ||
406 | YAML_DECLARE(yaml_token_t *) | |
407 | yaml_scalar_token_new(yaml_char_t *value, size_t length, | |
408 | yaml_scalar_style_t style, | |
409 | yaml_mark_t start_mark, yaml_mark_t end_mark); | |
410 | ||
411 | /** | |
412 | * Destroy a token object. | |
413 | * | |
414 | * @param[in] token A token object. | |
415 | */ | |
416 | ||
417 | YAML_DECLARE(void) | |
418 | yaml_token_delete(yaml_token_t *token); | |
419 | ||
420 | /** @} */ | |
421 | ||
422 | /* | |
423 | ||
424 | typedef enum { | |
425 | YAML_STREAM_START_EVENT, | |
426 | YAML_STREAM_END_EVENT, | |
427 | ||
428 | YAML_DOCUMENT_START_EVENT, | |
429 | YAML_DOCUMENT_END_EVENT, | |
430 | ||
431 | YAML_ALIAS_EVENT, | |
432 | YAML_SCALAR_EVENT, | |
433 | ||
434 | YAML_SEQUENCE_START_EVENT, | |
435 | YAML_SEQUENCE_END_EVENT, | |
436 | ||
437 | YAML_MAPPING_START_EVENT, | |
438 | YAML_MAPPING_END_EVENT | |
439 | } yaml_event_type_t; | |
440 | ||
9e05b78c KS |
441 | typedef struct { |
442 | yaml_event_type_t type; | |
443 | union { | |
444 | struct { | |
445 | yaml_encoding_t encoding; | |
446 | } stream_start; | |
447 | struct { | |
448 | struct { | |
449 | int major; | |
450 | int minor; | |
451 | } version; | |
452 | struct { | |
cec6fc98 KS |
453 | char *handle; |
454 | char *prefix; | |
9e05b78c KS |
455 | } **tag_pairs; |
456 | int implicit; | |
457 | } document_start; | |
458 | struct { | |
459 | int implicit; | |
460 | } document_end; | |
461 | struct { | |
cec6fc98 | 462 | char *anchor; |
9e05b78c KS |
463 | } alias; |
464 | struct { | |
cec6fc98 KS |
465 | char *anchor; |
466 | char *tag; | |
467 | char *value; | |
468 | size_t length; | |
9e05b78c KS |
469 | int plain_implicit; |
470 | int quoted_implicit; | |
471 | yaml_scalar_style_t style; | |
472 | } scalar; | |
473 | struct { | |
cec6fc98 KS |
474 | char *anchor; |
475 | char *tag; | |
9e05b78c KS |
476 | int implicit; |
477 | yaml_sequence_style_t style; | |
478 | } sequence_start; | |
479 | struct { | |
cec6fc98 KS |
480 | char *anchor; |
481 | char *tag; | |
9e05b78c KS |
482 | int implicit; |
483 | yaml_mapping_style_t style; | |
484 | } mapping_start; | |
485 | } data; | |
486 | yaml_mark_t start_mark; | |
487 | yaml_mark_t end_mark; | |
488 | } yaml_event_t; | |
489 | ||
a51447c9 KS |
490 | */ |
491 | ||
492 | ||
493 | /** | |
494 | * @defgroup parser Parser Definitions | |
495 | * @{ | |
496 | */ | |
497 | ||
498 | /** | |
499 | * The prototype of a read handler. | |
500 | * | |
501 | * The read handler is called when the parser needs to read more bytes from the | |
502 | * source. The handler should write not more than @a size bytes to the @a | |
503 | * buffer. The number of written bytes should be set to the @a length variable. | |
504 | * | |
6eb1ded4 | 505 | * @param[in] data A pointer to an application data specified by |
95b98ba9 KS |
506 | * @c yaml_parser_set_read_handler. |
507 | * @param[out] buffer The buffer to write the data from the source. | |
508 | * @param[in] size The size of the buffer. | |
509 | * @param[out] size_read The actual number of bytes read from the source. | |
a51447c9 KS |
510 | * |
511 | * @returns On success, the handler should return @c 1. If the handler failed, | |
512 | * the returned value should be @c 0. On EOF, the handler should set the | |
513 | * @a length to @c 0 and return @c 1. | |
514 | */ | |
6eb1ded4 KS |
515 | |
516 | typedef int yaml_read_handler_t(void *data, unsigned char *buffer, size_t size, | |
95b98ba9 | 517 | size_t *size_read); |
a51447c9 | 518 | |
6eb1ded4 KS |
519 | /** |
520 | * This structure holds a string input specified by | |
521 | * @c yaml_parser_set_input_string. | |
522 | */ | |
523 | ||
524 | typedef struct { | |
f642fd11 | 525 | /** The string start pointer. */ |
6eb1ded4 | 526 | unsigned char *start; |
f642fd11 KS |
527 | |
528 | /** The string end pointer. */ | |
6eb1ded4 | 529 | unsigned char *end; |
f642fd11 KS |
530 | |
531 | /** The string current position. */ | |
6eb1ded4 KS |
532 | unsigned char *current; |
533 | } yaml_string_input_t; | |
534 | ||
a51447c9 KS |
535 | /** |
536 | * The parser structure. | |
537 | * | |
538 | * All members are internal. Manage the structure using the @c yaml_parser_ | |
539 | * family of functions. | |
540 | */ | |
541 | ||
9e05b78c | 542 | typedef struct { |
a51447c9 | 543 | |
95b98ba9 KS |
544 | /** |
545 | * @name Error handling | |
546 | * @{ | |
547 | */ | |
548 | ||
3d790dfd | 549 | /** Error type. */ |
6eb1ded4 | 550 | yaml_error_type_t error; |
95b98ba9 | 551 | |
3d790dfd KS |
552 | /** Error description. */ |
553 | const char *problem; | |
554 | ||
555 | /** The byte about which the problem occured. */ | |
556 | size_t problem_offset; | |
557 | ||
2fa16060 KS |
558 | /** The problematic value (@c -1 is none). */ |
559 | int problem_value; | |
560 | ||
95b98ba9 KS |
561 | /** |
562 | * @} | |
563 | */ | |
564 | ||
a51447c9 KS |
565 | /** |
566 | * @name Reader stuff | |
567 | * @{ | |
568 | */ | |
569 | ||
3d790dfd | 570 | /** Read handler. */ |
95b98ba9 | 571 | yaml_read_handler_t *read_handler; |
a51447c9 KS |
572 | |
573 | /** A pointer for passing to the read handler. */ | |
95b98ba9 | 574 | void *read_handler_data; |
a51447c9 KS |
575 | |
576 | /** EOF flag */ | |
577 | int eof; | |
578 | ||
579 | /** The pointer to the beginning of the working buffer. */ | |
580 | yaml_char_t *buffer; | |
581 | ||
6eb1ded4 KS |
582 | /** The pointer to the end of the working buffer. */ |
583 | yaml_char_t *buffer_end; | |
95b98ba9 | 584 | |
a51447c9 | 585 | /** The pointer to the current character in the working buffer. */ |
6eb1ded4 | 586 | yaml_char_t *pointer; |
95b98ba9 | 587 | |
6eb1ded4 KS |
588 | /** The number of unread characters in the working buffer. */ |
589 | size_t unread; | |
a51447c9 | 590 | |
6eb1ded4 | 591 | /** The pointer to the beginning of the raw buffer. */ |
a51447c9 KS |
592 | unsigned char *raw_buffer; |
593 | ||
6eb1ded4 KS |
594 | /** The pointer to the current character in the raw buffer. */ |
595 | unsigned char *raw_pointer; | |
a51447c9 | 596 | |
6eb1ded4 KS |
597 | /** The number of unread bytes in the raw buffer. */ |
598 | size_t raw_unread; | |
95b98ba9 | 599 | |
a51447c9 KS |
600 | /** The input encoding. */ |
601 | yaml_encoding_t encoding; | |
602 | ||
95b98ba9 KS |
603 | /** The offset of the current position (in bytes). */ |
604 | size_t offset; | |
605 | ||
606 | /** The index of the current position (in characters). */ | |
607 | size_t index; | |
608 | ||
609 | /** The line of the current position (starting from @c 0). */ | |
610 | size_t line; | |
611 | ||
612 | /** The column of the current position (starting from @c 0). */ | |
613 | size_t column; | |
614 | ||
6eb1ded4 KS |
615 | /* String input structure. */ |
616 | yaml_string_input_t string_input; | |
617 | ||
a51447c9 KS |
618 | /** |
619 | * @} | |
620 | */ | |
621 | ||
9e05b78c KS |
622 | } yaml_parser_t; |
623 | ||
a51447c9 KS |
624 | /** |
625 | * Create a new parser. | |
626 | * | |
627 | * This function creates a new parser object. An application is responsible | |
628 | * for destroying the object using the @c yaml_parser_delete function. | |
629 | * | |
630 | * @returns A new parser object; @c NULL on error. | |
631 | */ | |
632 | ||
f642fd11 | 633 | YAML_DECLARE(yaml_parser_t *) |
a51447c9 KS |
634 | yaml_parser_new(void); |
635 | ||
636 | /** | |
637 | * Destroy a parser. | |
638 | * | |
639 | * @param[in] parser A parser object. | |
640 | */ | |
641 | ||
f642fd11 | 642 | YAML_DECLARE(void) |
a51447c9 KS |
643 | yaml_parser_delete(yaml_parser_t *parser); |
644 | ||
95b98ba9 KS |
645 | /** |
646 | * Set a string input. | |
647 | * | |
648 | * Note that the @a input pointer must be valid while the @a parser object | |
649 | * exists. The application is responsible for destroing @a input after | |
650 | * destroying the @a parser. | |
651 | * | |
652 | * @param[in] parser A parser object. | |
653 | * @param[in] input A source data. | |
f642fd11 | 654 | * @param[in] size The length of the source data in bytes. |
95b98ba9 KS |
655 | */ |
656 | ||
f642fd11 | 657 | YAML_DECLARE(void) |
95b98ba9 KS |
658 | yaml_parser_set_input_string(yaml_parser_t *parser, |
659 | unsigned char *input, size_t size); | |
660 | ||
661 | ||
662 | /** | |
663 | * Set a file input. | |
664 | * | |
665 | * @a file should be a file object open for reading. The application is | |
666 | * responsible for closing the @a file. | |
667 | * | |
668 | * @param[in] parser A parser object. | |
669 | * @param[in] file An open file. | |
670 | */ | |
671 | ||
f642fd11 | 672 | YAML_DECLARE(void) |
95b98ba9 KS |
673 | yaml_parser_set_input_file(yaml_parser_t *parser, FILE *file); |
674 | ||
675 | /** | |
676 | * Set a generic input handler. | |
677 | * | |
678 | * @param[in] parser A parser object. | |
679 | * @param[in] handler A read handler. | |
680 | * @param[in] data Any application data for passing to the read handler. | |
681 | */ | |
682 | ||
f642fd11 | 683 | YAML_DECLARE(void) |
95b98ba9 KS |
684 | yaml_parser_set_input(yaml_parser_t *parser, |
685 | yaml_read_handler_t *handler, void *data); | |
686 | ||
687 | /** | |
688 | * Set the source encoding. | |
689 | * | |
f642fd11 | 690 | * @param[in] parser A parser object. |
95b98ba9 KS |
691 | * @param[in] encoding The source encoding. |
692 | */ | |
693 | ||
f642fd11 | 694 | YAML_DECLARE(void) |
95b98ba9 KS |
695 | yaml_parser_set_encoding(yaml_parser_t *parser, yaml_encoding_t encoding); |
696 | ||
a51447c9 KS |
697 | /** @} */ |
698 | ||
699 | /* | |
9e05b78c KS |
700 | typedef struct { |
701 | } yaml_emitter_t; | |
cec6fc98 | 702 | */ |
9e05b78c | 703 | |
95b98ba9 KS |
704 | /** |
705 | * @defgroup internal Internal Definitions | |
706 | * @{ | |
707 | */ | |
708 | ||
709 | /** | |
710 | * Allocate a dynamic memory block. | |
711 | * | |
712 | * @param[in] size Size of a memory block, \c 0 is valid. | |
713 | * | |
714 | * @returns @c yaml_malloc returns a pointer to a newly allocated memory block, | |
715 | * or @c NULL if it failed. | |
716 | */ | |
717 | ||
f642fd11 | 718 | YAML_DECLARE(void *) |
95b98ba9 KS |
719 | yaml_malloc(size_t size); |
720 | ||
721 | /** | |
722 | * Reallocate a dynamic memory block. | |
723 | * | |
724 | * @param[in] ptr A pointer to an existing memory block, \c NULL is | |
725 | * valid. | |
726 | * @param[in] size A size of a new block, \c 0 is valid. | |
727 | * | |
728 | * @returns @c yaml_realloc returns a pointer to a reallocated memory block, | |
729 | * or @c NULL if it failed. | |
730 | */ | |
731 | ||
f642fd11 | 732 | YAML_DECLARE(void *) |
95b98ba9 KS |
733 | yaml_realloc(void *ptr, size_t size); |
734 | ||
735 | /** | |
736 | * Free a dynamic memory block. | |
737 | * | |
738 | * @param[in] ptr A pointer to an existing memory block, \c NULL is | |
739 | * valid. | |
740 | */ | |
741 | ||
f642fd11 | 742 | YAML_DECLARE(void) |
95b98ba9 KS |
743 | yaml_free(void *ptr); |
744 | ||
6eb1ded4 KS |
745 | /** The size of the raw buffer. */ |
746 | ||
747 | #define YAML_RAW_BUFFER_SIZE 16384 | |
748 | ||
749 | /** | |
750 | * The size of the buffer. | |
751 | * | |
752 | * We allocate enough space for decoding the whole raw buffer. | |
753 | */ | |
754 | ||
755 | #define YAML_BUFFER_SIZE (YAML_RAW_BUFFER_SIZE*3) | |
756 | ||
3d790dfd KS |
757 | /** |
758 | * Ensure that the buffer contains at least @a length characters. | |
759 | * | |
760 | * @param[in] parser A parser object. | |
761 | * @param[in] length The number of characters in the buffer. | |
762 | * | |
763 | * @returns @c 1 on success, @c 0 on error. | |
764 | */ | |
765 | ||
f642fd11 | 766 | YAML_DECLARE(int) |
3d790dfd KS |
767 | yaml_parser_update_buffer(yaml_parser_t *parser, size_t length); |
768 | ||
95b98ba9 KS |
769 | /** @} */ |
770 | ||
771 | ||
9e05b78c KS |
772 | #ifdef __cplusplus |
773 | } | |
774 | #endif | |
775 | ||
cec6fc98 | 776 | #endif /* #ifndef YAML_H */ |
9e05b78c | 777 |