| 1 | /* The public interface declaration */ |
|---|
| 2 | |
|---|
| 3 | /** |
|---|
| 4 | * A copy constructor for any YAML event. |
|---|
| 5 | * |
|---|
| 6 | * An application is responsible for freeing any buffers associated with the |
|---|
| 7 | * produced event object using the yaml_event_delete() function. |
|---|
| 8 | * |
|---|
| 9 | * @param[in] in The event object to be copied. |
|---|
| 10 | * @param[out] out An empty event object. |
|---|
| 11 | * |
|---|
| 12 | * @returns @c 1 if the function succeeded, @c 0 on error. |
|---|
| 13 | */ |
|---|
| 14 | |
|---|
| 15 | YAML_DECLARE(int) |
|---|
| 16 | yaml_event_initialize(yaml_event_t *out, yaml_event_t *in); |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | /* The source file code, I believe it would belong in api.c */ |
|---|
| 20 | |
|---|
| 21 | YAML_DECLARE(int) |
|---|
| 22 | yaml_event_initialize(yaml_event_t *out, yaml_event_t *in) { |
|---|
| 23 | switch((*in).type) { |
|---|
| 24 | case YAML_STREAM_START_EVENT: |
|---|
| 25 | if(!yaml_stream_start_event_initialize(&(*out), |
|---|
| 26 | (*in).data.stream_start.encoding)) |
|---|
| 27 | goto error; |
|---|
| 28 | break; |
|---|
| 29 | case YAML_STREAM_END_EVENT: |
|---|
| 30 | if(!yaml_stream_end_event_initialize(&(*out))) |
|---|
| 31 | goto error; |
|---|
| 32 | break; |
|---|
| 33 | case YAML_DOCUMENT_START_EVENT: |
|---|
| 34 | if(!yaml_document_start_event_initialize(&(*out), |
|---|
| 35 | (*in).data.document_start.version_directive, |
|---|
| 36 | (*in).data.document_start.tag_directives.start, |
|---|
| 37 | (*in).data.document_start.tag_directives.end, |
|---|
| 38 | (*in).data.document_start.implicit)) |
|---|
| 39 | goto error; |
|---|
| 40 | break; |
|---|
| 41 | case YAML_DOCUMENT_END_EVENT: |
|---|
| 42 | if(!yaml_document_end_event_initialize(&(*out), |
|---|
| 43 | (*in).data.document_end.implicit)) |
|---|
| 44 | goto error; |
|---|
| 45 | break; |
|---|
| 46 | case YAML_ALIAS_EVENT: |
|---|
| 47 | if(!yaml_alias_event_initialize(&(*out), |
|---|
| 48 | (*in).data.alias.anchor)) |
|---|
| 49 | goto error; |
|---|
| 50 | break; |
|---|
| 51 | case YAML_SCALAR_EVENT: |
|---|
| 52 | if(!yaml_scalar_event_initialize(&(*out), |
|---|
| 53 | (*in).data.scalar.anchor, (*in).data.scalar.tag, |
|---|
| 54 | (*in).data.scalar.value, (*in).data.scalar.length, |
|---|
| 55 | (*in).data.scalar.plain_implicit, |
|---|
| 56 | (*in).data.scalar.quoted_implicit, |
|---|
| 57 | (*in).data.scalar.style)) |
|---|
| 58 | goto error; |
|---|
| 59 | break; |
|---|
| 60 | case YAML_SEQUENCE_START_EVENT: |
|---|
| 61 | if(!yaml_sequence_start_event_initialize(&(*out), |
|---|
| 62 | (*in).data.sequence_start.anchor, |
|---|
| 63 | (*in).data.sequence_start.tag, |
|---|
| 64 | (*in).data.sequence_start.implicit, |
|---|
| 65 | (*in).data.sequence_start.style)) |
|---|
| 66 | goto error; |
|---|
| 67 | break; |
|---|
| 68 | case YAML_SEQUENCE_END_EVENT: |
|---|
| 69 | if(!yaml_sequence_end_event_initialize(&(*out))) |
|---|
| 70 | goto error; |
|---|
| 71 | break; |
|---|
| 72 | case YAML_MAPPING_START_EVENT: |
|---|
| 73 | if(!yaml_mapping_start_event_initialize(&(*out), |
|---|
| 74 | (*in).data.mapping_start.anchor, |
|---|
| 75 | (*in).data.mapping_start.tag, |
|---|
| 76 | (*in).data.mapping_start.implicit, |
|---|
| 77 | (*in).data.mapping_start.style)) |
|---|
| 78 | goto error; |
|---|
| 79 | break; |
|---|
| 80 | case YAML_MAPPING_END_EVENT: |
|---|
| 81 | if(!yaml_mapping_end_event_initialize(&(*out))) |
|---|
| 82 | goto error; |
|---|
| 83 | break; |
|---|
| 84 | default: goto error; break; |
|---|
| 85 | } |
|---|
| 86 | return 1; |
|---|
| 87 | |
|---|
| 88 | error: |
|---|
| 89 | return 0; |
|---|
| 90 | } |
|---|