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