use crate::externs::{strcmp, strlen, strncmp};
use crate::internal::{yaml_queue_extend, yaml_stack_extend};
use crate::memory::{yaml_free, yaml_strdup};
use crate::ops::{ForceAdd as _, ForceMul as _};
use crate::success::{Success, FAIL, OK};
use crate::yaml::{size_t, yaml_char_t, YamlStringT};
use crate::{
libc, yaml_emitter_flush, yaml_event_delete, PointerExt,
YamlAliasEvent, YamlAnyBreak, YamlAnyEncoding, YamlAnyScalarStyle,
YamlCrBreak, YamlCrlnBreak, YamlDocumentEndEvent,
YamlDocumentStartEvent, YamlDoubleQuotedScalarStyle,
YamlEmitBlockMappingFirstKeyState, YamlEmitBlockMappingKeyState,
YamlEmitBlockMappingSimpleValueState,
YamlEmitBlockMappingValueState,
YamlEmitBlockSequenceFirstItemState,
YamlEmitBlockSequenceItemState, YamlEmitDocumentContentState,
YamlEmitDocumentEndState, YamlEmitDocumentStartState,
YamlEmitEndState, YamlEmitFirstDocumentStartState,
YamlEmitFlowMappingFirstKeyState, YamlEmitFlowMappingKeyState,
YamlEmitFlowMappingSimpleValueState, YamlEmitFlowMappingValueState,
YamlEmitFlowSequenceFirstItemState, YamlEmitFlowSequenceItemState,
YamlEmitStreamStartState, YamlEmitterError, YamlEmitterT,
YamlEventT, YamlFlowMappingStyle, YamlFlowSequenceStyle,
YamlFoldedScalarStyle, YamlLiteralScalarStyle, YamlLnBreak,
YamlMappingEndEvent, YamlMappingStartEvent, YamlPlainScalarStyle,
YamlScalarEvent, YamlScalarStyleT, YamlSequenceEndEvent,
YamlSequenceStartEvent, YamlSingleQuotedScalarStyle,
YamlStreamEndEvent, YamlStreamStartEvent, YamlTagDirectiveT,
YamlUtf8Encoding, YamlVersionDirectiveT,
};
use core::ptr::{self, addr_of_mut};
unsafe fn flush(emitter: *mut YamlEmitterT) -> Success {
if (*emitter).buffer.pointer.wrapping_offset(5_isize)
< (*emitter).buffer.end
{
OK
} else {
yaml_emitter_flush(emitter)
}
}
unsafe fn put(emitter: *mut YamlEmitterT, value: u8) -> Success {
if flush(emitter).fail {
return FAIL;
}
let fresh40 = addr_of_mut!((*emitter).buffer.pointer);
let fresh41 = *fresh40;
*fresh40 = (*fresh40).wrapping_offset(1);
*fresh41 = value;
let fresh42 = addr_of_mut!((*emitter).column);
*fresh42 += 1;
OK
}
unsafe fn put_break(emitter: *mut YamlEmitterT) -> Success {
if flush(emitter).fail {
return FAIL;
}
if (*emitter).line_break == YamlCrBreak {
let fresh62 = addr_of_mut!((*emitter).buffer.pointer);
let fresh63 = *fresh62;
*fresh62 = (*fresh62).wrapping_offset(1);
*fresh63 = b'\r';
} else if (*emitter).line_break == YamlLnBreak {
let fresh64 = addr_of_mut!((*emitter).buffer.pointer);
let fresh65 = *fresh64;
*fresh64 = (*fresh64).wrapping_offset(1);
*fresh65 = b'\n';
} else if (*emitter).line_break == YamlCrlnBreak {
let fresh66 = addr_of_mut!((*emitter).buffer.pointer);
let fresh67 = *fresh66;
*fresh66 = (*fresh66).wrapping_offset(1);
*fresh67 = b'\r';
let fresh68 = addr_of_mut!((*emitter).buffer.pointer);
let fresh69 = *fresh68;
*fresh68 = (*fresh68).wrapping_offset(1);
*fresh69 = b'\n';
};
(*emitter).column = 0;
let fresh70 = addr_of_mut!((*emitter).line);
*fresh70 += 1;
OK
}
unsafe fn write(
emitter: *mut YamlEmitterT,
string: *mut YamlStringT,
) -> Success {
if flush(emitter).fail {
return FAIL;
}
copy!((*emitter).buffer, *string);
let fresh107 = addr_of_mut!((*emitter).column);
*fresh107 += 1;
OK
}
unsafe fn write_break(
emitter: *mut YamlEmitterT,
string: *mut YamlStringT,
) -> Success {
if flush(emitter).fail {
return FAIL;
}
if CHECK!(*string, b'\n') {
let _ = put_break(emitter);
(*string).pointer = (*string).pointer.wrapping_offset(1);
} else {
copy!((*emitter).buffer, *string);
(*emitter).column = 0;
let fresh300 = addr_of_mut!((*emitter).line);
*fresh300 += 1;
}
OK
}
macro_rules! write {
($emitter:expr, $string:expr) => {
write($emitter, addr_of_mut!($string))
};
}
macro_rules! write_break {
($emitter:expr, $string:expr) => {
write_break($emitter, addr_of_mut!($string))
};
}
unsafe fn yaml_emitter_set_emitter_error(
emitter: *mut YamlEmitterT,
problem: *const libc::c_char,
) -> Success {
(*emitter).error = YamlEmitterError;
let fresh0 = addr_of_mut!((*emitter).problem);
*fresh0 = problem;
FAIL
}
pub unsafe fn yaml_emitter_emit(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
) -> Success {
ENQUEUE!((*emitter).events, *event);
while yaml_emitter_need_more_events(emitter).fail {
if yaml_emitter_analyze_event(emitter, (*emitter).events.head)
.fail
{
return FAIL;
}
if yaml_emitter_state_machine(emitter, (*emitter).events.head)
.fail
{
return FAIL;
}
yaml_event_delete(addr_of_mut!(DEQUEUE!((*emitter).events)));
}
OK
}
unsafe fn yaml_emitter_need_more_events(
emitter: *mut YamlEmitterT,
) -> Success {
let mut level: libc::c_int = 0;
let mut event: *mut YamlEventT;
if QUEUE_EMPTY!((*emitter).events) {
return OK;
}
let accumulate = match (*(*emitter).events.head).type_ {
YamlDocumentStartEvent => 1,
YamlSequenceStartEvent => 2,
YamlMappingStartEvent => 3,
_ => return FAIL,
};
if (*emitter).events.tail.c_offset_from((*emitter).events.head)
as libc::c_long
> accumulate as libc::c_long
{
return FAIL;
}
event = (*emitter).events.head;
while event != (*emitter).events.tail {
match (*event).type_ {
YamlStreamStartEvent
| YamlDocumentStartEvent
| YamlSequenceStartEvent
| YamlMappingStartEvent => {
level += 1;
}
YamlStreamEndEvent | YamlDocumentEndEvent
| YamlSequenceEndEvent | YamlMappingEndEvent => {
level -= 1;
}
_ => {}
}
if level == 0 {
return FAIL;
}
event = event.wrapping_offset(1);
}
OK
}
unsafe fn yaml_emitter_append_tag_directive(
emitter: *mut YamlEmitterT,
value: YamlTagDirectiveT,
allow_duplicates: bool,
) -> Success {
let mut tag_directive: *mut YamlTagDirectiveT;
let mut copy = YamlTagDirectiveT {
handle: ptr::null_mut::<yaml_char_t>(),
prefix: ptr::null_mut::<yaml_char_t>(),
};
tag_directive = (*emitter).tag_directives.start;
while tag_directive != (*emitter).tag_directives.top {
if strcmp(
value.handle as *mut libc::c_char,
(*tag_directive).handle as *mut libc::c_char,
) == 0
{
if allow_duplicates {
return OK;
}
return yaml_emitter_set_emitter_error(
emitter,
b"duplicate %TAG directive\0" as *const u8
as *const libc::c_char,
);
}
tag_directive = tag_directive.wrapping_offset(1);
}
copy.handle = yaml_strdup(value.handle);
copy.prefix = yaml_strdup(value.prefix);
PUSH!((*emitter).tag_directives, copy);
OK
}
unsafe fn yaml_emitter_increase_indent(
emitter: *mut YamlEmitterT,
flow: bool,
indentless: bool,
) {
PUSH!((*emitter).indents, (*emitter).indent);
if (*emitter).indent < 0 {
(*emitter).indent =
if flow { (*emitter).best_indent } else { 0 };
} else if !indentless {
(*emitter).indent += (*emitter).best_indent;
}
}
unsafe fn yaml_emitter_state_machine(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
) -> Success {
match (*emitter).state {
YamlEmitStreamStartState => {
yaml_emitter_emit_stream_start(emitter, event)
}
YamlEmitFirstDocumentStartState => {
yaml_emitter_emit_document_start(emitter, event, true)
}
YamlEmitDocumentStartState => {
yaml_emitter_emit_document_start(emitter, event, false)
}
YamlEmitDocumentContentState => {
yaml_emitter_emit_document_content(emitter, event)
}
YamlEmitDocumentEndState => {
yaml_emitter_emit_document_end(emitter, event)
}
YamlEmitFlowSequenceFirstItemState => {
yaml_emitter_emit_flow_sequence_item(emitter, event, true)
}
YamlEmitFlowSequenceItemState => {
yaml_emitter_emit_flow_sequence_item(emitter, event, false)
}
YamlEmitFlowMappingFirstKeyState => {
yaml_emitter_emit_flow_mapping_key(emitter, event, true)
}
YamlEmitFlowMappingKeyState => {
yaml_emitter_emit_flow_mapping_key(emitter, event, false)
}
YamlEmitFlowMappingSimpleValueState => {
yaml_emitter_emit_flow_mapping_value(emitter, event, true)
}
YamlEmitFlowMappingValueState => {
yaml_emitter_emit_flow_mapping_value(emitter, event, false)
}
YamlEmitBlockSequenceFirstItemState => {
yaml_emitter_emit_block_sequence_item(emitter, event, true)
}
YamlEmitBlockSequenceItemState => {
yaml_emitter_emit_block_sequence_item(emitter, event, false)
}
YamlEmitBlockMappingFirstKeyState => {
yaml_emitter_emit_block_mapping_key(emitter, event, true)
}
YamlEmitBlockMappingKeyState => {
yaml_emitter_emit_block_mapping_key(emitter, event, false)
}
YamlEmitBlockMappingSimpleValueState => {
yaml_emitter_emit_block_mapping_value(emitter, event, true)
}
YamlEmitBlockMappingValueState => {
yaml_emitter_emit_block_mapping_value(emitter, event, false)
}
YamlEmitEndState => yaml_emitter_set_emitter_error(
emitter,
b"expected nothing after STREAM-END\0" as *const u8
as *const libc::c_char,
),
}
}
unsafe fn yaml_emitter_emit_stream_start(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
) -> Success {
(*emitter).open_ended = 0;
if (*event).type_ == YamlStreamStartEvent {
if (*emitter).encoding == YamlAnyEncoding {
(*emitter).encoding = (*event).data.stream_start.encoding;
}
if (*emitter).encoding == YamlAnyEncoding {
(*emitter).encoding = YamlUtf8Encoding;
}
if (*emitter).best_indent < 2 || (*emitter).best_indent > 9 {
(*emitter).best_indent = 2;
}
if (*emitter).best_width >= 0
&& (*emitter).best_width
<= (*emitter).best_indent.force_mul(2)
{
(*emitter).best_width = 80;
}
if (*emitter).best_width < 0 {
(*emitter).best_width = libc::c_int::MAX;
}
if (*emitter).line_break == YamlAnyBreak {
(*emitter).line_break = YamlLnBreak;
}
(*emitter).indent = -1;
(*emitter).line = 0;
(*emitter).column = 0;
(*emitter).whitespace = true;
(*emitter).indention = true;
if (*emitter).encoding != YamlUtf8Encoding
&& yaml_emitter_write_bom(emitter).fail
{
return FAIL;
}
(*emitter).state = YamlEmitFirstDocumentStartState;
return OK;
}
yaml_emitter_set_emitter_error(
emitter,
b"expected STREAM-START\0" as *const u8 as *const libc::c_char,
)
}
unsafe fn yaml_emitter_emit_document_start(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
first: bool,
) -> Success {
if (*event).type_ == YamlDocumentStartEvent {
let mut default_tag_directives: [YamlTagDirectiveT; 3] = [
YamlTagDirectiveT {
handle: b"!\0" as *const u8 as *const libc::c_char
as *mut yaml_char_t,
prefix: b"!\0" as *const u8 as *const libc::c_char
as *mut yaml_char_t,
},
YamlTagDirectiveT {
handle: b"!!\0" as *const u8 as *const libc::c_char
as *mut yaml_char_t,
prefix: b"tag:yaml.org,2002:\0" as *const u8
as *const libc::c_char
as *mut yaml_char_t,
},
YamlTagDirectiveT {
handle: ptr::null_mut::<yaml_char_t>(),
prefix: ptr::null_mut::<yaml_char_t>(),
},
];
let mut tag_directive: *mut YamlTagDirectiveT;
let mut implicit;
if !(*event).data.document_start.version_directive.is_null()
&& yaml_emitter_analyze_version_directive(
emitter,
*(*event).data.document_start.version_directive,
)
.fail
{
return FAIL;
}
tag_directive =
(*event).data.document_start.tag_directives.start;
while tag_directive
!= (*event).data.document_start.tag_directives.end
{
if yaml_emitter_analyze_tag_directive(
emitter,
*tag_directive,
)
.fail
{
return FAIL;
}
if yaml_emitter_append_tag_directive(
emitter,
*tag_directive,
false,
)
.fail
{
return FAIL;
}
tag_directive = tag_directive.wrapping_offset(1);
}
tag_directive = default_tag_directives.as_mut_ptr();
while !(*tag_directive).handle.is_null() {
if yaml_emitter_append_tag_directive(
emitter,
*tag_directive,
true,
)
.fail
{
return FAIL;
}
tag_directive = tag_directive.wrapping_offset(1);
}
implicit = (*event).data.document_start.implicit;
if !first || (*emitter).canonical {
implicit = false;
}
if (!(*event).data.document_start.version_directive.is_null()
|| (*event).data.document_start.tag_directives.start
!= (*event).data.document_start.tag_directives.end)
&& (*emitter).open_ended != 0
{
if yaml_emitter_write_indicator(
emitter,
b"...\0" as *const u8 as *const libc::c_char,
true,
false,
false,
)
.fail
{
return FAIL;
}
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
}
(*emitter).open_ended = 0;
if !(*event).data.document_start.version_directive.is_null() {
implicit = false;
if yaml_emitter_write_indicator(
emitter,
b"%YAML\0" as *const u8 as *const libc::c_char,
true,
false,
false,
)
.fail
{
return FAIL;
}
if (*(*event).data.document_start.version_directive).minor
== 1
{
if yaml_emitter_write_indicator(
emitter,
b"1.1\0" as *const u8 as *const libc::c_char,
true,
false,
false,
)
.fail
{
return FAIL;
}
} else if yaml_emitter_write_indicator(
emitter,
b"1.2\0" as *const u8 as *const libc::c_char,
true,
false,
false,
)
.fail
{
return FAIL;
}
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
}
if (*event).data.document_start.tag_directives.start
!= (*event).data.document_start.tag_directives.end
{
implicit = false;
tag_directive =
(*event).data.document_start.tag_directives.start;
while tag_directive
!= (*event).data.document_start.tag_directives.end
{
if yaml_emitter_write_indicator(
emitter,
b"%TAG\0" as *const u8 as *const libc::c_char,
true,
false,
false,
)
.fail
{
return FAIL;
}
if yaml_emitter_write_tag_handle(
emitter,
(*tag_directive).handle,
strlen(
(*tag_directive).handle as *mut libc::c_char,
),
)
.fail
{
return FAIL;
}
if yaml_emitter_write_tag_content(
emitter,
(*tag_directive).prefix,
strlen(
(*tag_directive).prefix as *mut libc::c_char,
),
true,
)
.fail
{
return FAIL;
}
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
tag_directive = tag_directive.wrapping_offset(1);
}
}
if yaml_emitter_check_empty_document(emitter) {
implicit = false;
}
if !implicit {
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
if yaml_emitter_write_indicator(
emitter,
b"---\0" as *const u8 as *const libc::c_char,
true,
false,
false,
)
.fail
{
return FAIL;
}
if (*emitter).canonical
&& yaml_emitter_write_indent(emitter).fail
{
return FAIL;
}
}
(*emitter).state = YamlEmitDocumentContentState;
(*emitter).open_ended = 0;
return OK;
} else if (*event).type_ == YamlStreamEndEvent {
if (*emitter).open_ended == 2 {
if yaml_emitter_write_indicator(
emitter,
b"...\0" as *const u8 as *const libc::c_char,
true,
false,
false,
)
.fail
{
return FAIL;
}
(*emitter).open_ended = 0;
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
}
if yaml_emitter_flush(emitter).fail {
return FAIL;
}
(*emitter).state = YamlEmitEndState;
return OK;
}
yaml_emitter_set_emitter_error(
emitter,
b"expected DOCUMENT-START or STREAM-END\0" as *const u8
as *const libc::c_char,
)
}
unsafe fn yaml_emitter_emit_document_content(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
) -> Success {
PUSH!((*emitter).states, YamlEmitDocumentEndState);
yaml_emitter_emit_node(emitter, event, true, false, false, false)
}
unsafe fn yaml_emitter_emit_document_end(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
) -> Success {
if (*event).type_ == YamlDocumentEndEvent {
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
if !(*event).data.document_end.implicit {
if yaml_emitter_write_indicator(
emitter,
b"...\0" as *const u8 as *const libc::c_char,
true,
false,
false,
)
.fail
{
return FAIL;
}
(*emitter).open_ended = 0;
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
} else if (*emitter).open_ended == 0 {
(*emitter).open_ended = 1;
}
if yaml_emitter_flush(emitter).fail {
return FAIL;
}
(*emitter).state = YamlEmitDocumentStartState;
while !STACK_EMPTY!((*emitter).tag_directives) {
let tag_directive = POP!((*emitter).tag_directives);
yaml_free(tag_directive.handle as *mut libc::c_void);
yaml_free(tag_directive.prefix as *mut libc::c_void);
}
return OK;
}
yaml_emitter_set_emitter_error(
emitter,
b"expected DOCUMENT-END\0" as *const u8 as *const libc::c_char,
)
}
unsafe fn yaml_emitter_emit_flow_sequence_item(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
first: bool,
) -> Success {
if first {
if yaml_emitter_write_indicator(
emitter,
b"[\0" as *const u8 as *const libc::c_char,
true,
true,
false,
)
.fail
{
return FAIL;
}
yaml_emitter_increase_indent(emitter, true, false);
let fresh12 = addr_of_mut!((*emitter).flow_level);
*fresh12 += 1;
}
if (*event).type_ == YamlSequenceEndEvent {
let fresh13 = addr_of_mut!((*emitter).flow_level);
*fresh13 -= 1;
(*emitter).indent = POP!((*emitter).indents);
if (*emitter).canonical && !first {
if yaml_emitter_write_indicator(
emitter,
b",\0" as *const u8 as *const libc::c_char,
false,
false,
false,
)
.fail
{
return FAIL;
}
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
}
if yaml_emitter_write_indicator(
emitter,
b"]\0" as *const u8 as *const libc::c_char,
false,
false,
false,
)
.fail
{
return FAIL;
}
(*emitter).state = POP!((*emitter).states);
return OK;
}
if !first
&& yaml_emitter_write_indicator(
emitter,
b",\0" as *const u8 as *const libc::c_char,
false,
false,
false,
)
.fail
{
return FAIL;
}
if ((*emitter).canonical
|| (*emitter).column > (*emitter).best_width)
&& yaml_emitter_write_indent(emitter).fail
{
return FAIL;
}
PUSH!((*emitter).states, YamlEmitFlowSequenceItemState);
yaml_emitter_emit_node(emitter, event, false, true, false, false)
}
unsafe fn yaml_emitter_emit_flow_mapping_key(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
first: bool,
) -> Success {
if first {
if yaml_emitter_write_indicator(
emitter,
b"{\0" as *const u8 as *const libc::c_char,
true,
true,
false,
)
.fail
{
return FAIL;
}
yaml_emitter_increase_indent(emitter, true, false);
let fresh18 = addr_of_mut!((*emitter).flow_level);
*fresh18 += 1;
}
if (*event).type_ == YamlMappingEndEvent {
if STACK_EMPTY!((*emitter).indents) {
return FAIL;
}
let fresh19 = addr_of_mut!((*emitter).flow_level);
*fresh19 -= 1;
(*emitter).indent = POP!((*emitter).indents);
if (*emitter).canonical && !first {
if yaml_emitter_write_indicator(
emitter,
b",\0" as *const u8 as *const libc::c_char,
false,
false,
false,
)
.fail
{
return FAIL;
}
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
}
if yaml_emitter_write_indicator(
emitter,
b"}\0" as *const u8 as *const libc::c_char,
false,
false,
false,
)
.fail
{
return FAIL;
}
(*emitter).state = POP!((*emitter).states);
return OK;
}
if !first
&& yaml_emitter_write_indicator(
emitter,
b",\0" as *const u8 as *const libc::c_char,
false,
false,
false,
)
.fail
{
return FAIL;
}
if ((*emitter).canonical
|| (*emitter).column > (*emitter).best_width)
&& yaml_emitter_write_indent(emitter).fail
{
return FAIL;
}
if !(*emitter).canonical && yaml_emitter_check_simple_key(emitter) {
PUSH!((*emitter).states, YamlEmitFlowMappingSimpleValueState);
yaml_emitter_emit_node(emitter, event, false, false, true, true)
} else {
if yaml_emitter_write_indicator(
emitter,
b"?\0" as *const u8 as *const libc::c_char,
true,
false,
false,
)
.fail
{
return FAIL;
}
PUSH!((*emitter).states, YamlEmitFlowMappingValueState);
yaml_emitter_emit_node(
emitter, event, false, false, true, false,
)
}
}
unsafe fn yaml_emitter_emit_flow_mapping_value(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
simple: bool,
) -> Success {
if simple {
if yaml_emitter_write_indicator(
emitter,
b":\0" as *const u8 as *const libc::c_char,
false,
false,
false,
)
.fail
{
return FAIL;
}
} else {
if ((*emitter).canonical
|| (*emitter).column > (*emitter).best_width)
&& yaml_emitter_write_indent(emitter).fail
{
return FAIL;
}
if yaml_emitter_write_indicator(
emitter,
b":\0" as *const u8 as *const libc::c_char,
true,
false,
false,
)
.fail
{
return FAIL;
}
}
PUSH!((*emitter).states, YamlEmitFlowMappingKeyState);
yaml_emitter_emit_node(emitter, event, false, false, true, false)
}
unsafe fn yaml_emitter_emit_block_sequence_item(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
first: bool,
) -> Success {
if first {
yaml_emitter_increase_indent(
emitter,
false,
(*emitter).mapping_context && !(*emitter).indention,
);
}
if (*event).type_ == YamlSequenceEndEvent {
(*emitter).indent = POP!((*emitter).indents);
(*emitter).state = POP!((*emitter).states);
return OK;
}
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
if yaml_emitter_write_indicator(
emitter,
b"-\0" as *const u8 as *const libc::c_char,
true,
false,
true,
)
.fail
{
return FAIL;
}
PUSH!((*emitter).states, YamlEmitBlockSequenceItemState);
yaml_emitter_emit_node(emitter, event, false, true, false, false)
}
unsafe fn yaml_emitter_emit_block_mapping_key(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
first: bool,
) -> Success {
if first {
yaml_emitter_increase_indent(emitter, false, false);
}
if (*event).type_ == YamlMappingEndEvent {
(*emitter).indent = POP!((*emitter).indents);
(*emitter).state = POP!((*emitter).states);
return OK;
}
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
if yaml_emitter_check_simple_key(emitter) {
PUSH!((*emitter).states, YamlEmitBlockMappingSimpleValueState);
yaml_emitter_emit_node(emitter, event, false, false, true, true)
} else {
if yaml_emitter_write_indicator(
emitter,
b"?\0" as *const u8 as *const libc::c_char,
true,
false,
true,
)
.fail
{
return FAIL;
}
PUSH!((*emitter).states, YamlEmitBlockMappingValueState);
yaml_emitter_emit_node(
emitter, event, false, false, true, false,
)
}
}
unsafe fn yaml_emitter_emit_block_mapping_value(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
simple: bool,
) -> Success {
if simple {
if yaml_emitter_write_indicator(
emitter,
b":\0" as *const u8 as *const libc::c_char,
false,
false,
false,
)
.fail
{
return FAIL;
}
} else {
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
if yaml_emitter_write_indicator(
emitter,
b":\0" as *const u8 as *const libc::c_char,
true,
false,
true,
)
.fail
{
return FAIL;
}
}
PUSH!((*emitter).states, YamlEmitBlockMappingKeyState);
yaml_emitter_emit_node(emitter, event, false, false, true, false)
}
unsafe fn yaml_emitter_emit_node(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
root: bool,
sequence: bool,
mapping: bool,
simple_key: bool,
) -> Success {
(*emitter).root_context = root;
(*emitter).sequence_context = sequence;
(*emitter).mapping_context = mapping;
(*emitter).simple_key_context = simple_key;
match (*event).type_ {
YamlAliasEvent => yaml_emitter_emit_alias(emitter, event),
YamlScalarEvent => yaml_emitter_emit_scalar(emitter, event),
YamlSequenceStartEvent => yaml_emitter_emit_sequence_start(emitter, event),
YamlMappingStartEvent => yaml_emitter_emit_mapping_start(emitter, event),
_ => yaml_emitter_set_emitter_error(
emitter,
b"expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS\0" as *const u8
as *const libc::c_char,
),
}
}
unsafe fn yaml_emitter_emit_alias(
emitter: *mut YamlEmitterT,
_event: *mut YamlEventT,
) -> Success {
if yaml_emitter_process_anchor(emitter).fail {
return FAIL;
}
if (*emitter).simple_key_context && put(emitter, b' ').fail {
return FAIL;
}
(*emitter).state = POP!((*emitter).states);
OK
}
unsafe fn yaml_emitter_emit_scalar(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
) -> Success {
if yaml_emitter_select_scalar_style(emitter, event).fail {
return FAIL;
}
if yaml_emitter_process_anchor(emitter).fail {
return FAIL;
}
if yaml_emitter_process_tag(emitter).fail {
return FAIL;
}
yaml_emitter_increase_indent(emitter, true, false);
if yaml_emitter_process_scalar(emitter).fail {
return FAIL;
}
(*emitter).indent = POP!((*emitter).indents);
(*emitter).state = POP!((*emitter).states);
OK
}
unsafe fn yaml_emitter_emit_sequence_start(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
) -> Success {
if yaml_emitter_process_anchor(emitter).fail {
return FAIL;
}
if yaml_emitter_process_tag(emitter).fail {
return FAIL;
}
if (*emitter).flow_level != 0
|| (*emitter).canonical
|| (*event).data.sequence_start.style == YamlFlowSequenceStyle
|| yaml_emitter_check_empty_sequence(emitter)
{
(*emitter).state = YamlEmitFlowSequenceFirstItemState;
} else {
(*emitter).state = YamlEmitBlockSequenceFirstItemState;
}
OK
}
unsafe fn yaml_emitter_emit_mapping_start(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
) -> Success {
if yaml_emitter_process_anchor(emitter).fail {
return FAIL;
}
if yaml_emitter_process_tag(emitter).fail {
return FAIL;
}
if (*emitter).flow_level != 0
|| (*emitter).canonical
|| (*event).data.mapping_start.style == YamlFlowMappingStyle
|| yaml_emitter_check_empty_mapping(emitter)
{
(*emitter).state = YamlEmitFlowMappingFirstKeyState;
} else {
(*emitter).state = YamlEmitBlockMappingFirstKeyState;
}
OK
}
unsafe fn yaml_emitter_check_empty_document(
_emitter: *mut YamlEmitterT,
) -> bool {
false
}
unsafe fn yaml_emitter_check_empty_sequence(
emitter: *mut YamlEmitterT,
) -> bool {
if ((*emitter).events.tail.c_offset_from((*emitter).events.head)
as libc::c_long)
< 2_i64
{
return false;
}
(*(*emitter).events.head).type_ == YamlSequenceStartEvent
&& (*(*emitter).events.head.wrapping_offset(1_isize)).type_
== YamlSequenceEndEvent
}
unsafe fn yaml_emitter_check_empty_mapping(
emitter: *mut YamlEmitterT,
) -> bool {
if ((*emitter).events.tail.c_offset_from((*emitter).events.head)
as libc::c_long)
< 2_i64
{
return false;
}
(*(*emitter).events.head).type_ == YamlMappingStartEvent
&& (*(*emitter).events.head.wrapping_offset(1_isize)).type_
== YamlMappingEndEvent
}
unsafe fn yaml_emitter_check_simple_key(
emitter: *mut YamlEmitterT,
) -> bool {
let event: *mut YamlEventT = (*emitter).events.head;
let mut length: size_t = 0_u64;
match (*event).type_ {
YamlAliasEvent => {
length =
length.force_add((*emitter).anchor_data.anchor_length);
}
YamlScalarEvent => {
if (*emitter).scalar_data.multiline {
return false;
}
length = length
.force_add((*emitter).anchor_data.anchor_length)
.force_add((*emitter).tag_data.handle_length)
.force_add((*emitter).tag_data.suffix_length)
.force_add((*emitter).scalar_data.length);
}
YamlSequenceStartEvent => {
if !yaml_emitter_check_empty_sequence(emitter) {
return false;
}
length = length
.force_add((*emitter).anchor_data.anchor_length)
.force_add((*emitter).tag_data.handle_length)
.force_add((*emitter).tag_data.suffix_length);
}
YamlMappingStartEvent => {
if !yaml_emitter_check_empty_mapping(emitter) {
return false;
}
length = length
.force_add((*emitter).anchor_data.anchor_length)
.force_add((*emitter).tag_data.handle_length)
.force_add((*emitter).tag_data.suffix_length);
}
_ => return false,
}
if length > 128_u64 {
return false;
}
true
}
unsafe fn yaml_emitter_select_scalar_style(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
) -> Success {
let mut style: YamlScalarStyleT = (*event).data.scalar.style;
let no_tag = (*emitter).tag_data.handle.is_null()
&& (*emitter).tag_data.suffix.is_null();
if no_tag
&& !(*event).data.scalar.plain_implicit
&& !(*event).data.scalar.quoted_implicit
{
return yaml_emitter_set_emitter_error(
emitter,
b"neither tag nor implicit flags are specified\0"
as *const u8 as *const libc::c_char,
);
}
if style == YamlAnyScalarStyle {
style = YamlPlainScalarStyle;
}
if (*emitter).canonical {
style = YamlDoubleQuotedScalarStyle;
}
if (*emitter).simple_key_context && (*emitter).scalar_data.multiline
{
style = YamlDoubleQuotedScalarStyle;
}
if style == YamlPlainScalarStyle {
if (*emitter).flow_level != 0
&& !(*emitter).scalar_data.flow_plain_allowed
|| (*emitter).flow_level == 0
&& !(*emitter).scalar_data.block_plain_allowed
{
style = YamlSingleQuotedScalarStyle;
}
if (*emitter).scalar_data.length == 0
&& ((*emitter).flow_level != 0
|| (*emitter).simple_key_context)
{
style = YamlSingleQuotedScalarStyle;
}
if no_tag && !(*event).data.scalar.plain_implicit {
style = YamlSingleQuotedScalarStyle;
}
}
if style == YamlSingleQuotedScalarStyle
&& !(*emitter).scalar_data.single_quoted_allowed
{
style = YamlDoubleQuotedScalarStyle;
}
if (style == YamlLiteralScalarStyle
|| style == YamlFoldedScalarStyle)
&& (!(*emitter).scalar_data.block_allowed
|| (*emitter).flow_level != 0
|| (*emitter).simple_key_context)
{
style = YamlDoubleQuotedScalarStyle;
}
if no_tag
&& !(*event).data.scalar.quoted_implicit
&& style != YamlPlainScalarStyle
{
let fresh46 = addr_of_mut!((*emitter).tag_data.handle);
*fresh46 = b"!\0" as *const u8 as *const libc::c_char
as *mut yaml_char_t;
(*emitter).tag_data.handle_length = 1_u64;
}
(*emitter).scalar_data.style = style;
OK
}
unsafe fn yaml_emitter_process_anchor(
emitter: *mut YamlEmitterT,
) -> Success {
if (*emitter).anchor_data.anchor.is_null() {
return OK;
}
if yaml_emitter_write_indicator(
emitter,
if (*emitter).anchor_data.alias {
b"*\0" as *const u8 as *const libc::c_char
} else {
b"&\0" as *const u8 as *const libc::c_char
},
true,
false,
false,
)
.fail
{
return FAIL;
}
yaml_emitter_write_anchor(
emitter,
(*emitter).anchor_data.anchor,
(*emitter).anchor_data.anchor_length,
)
}
unsafe fn yaml_emitter_process_tag(
emitter: *mut YamlEmitterT,
) -> Success {
if (*emitter).tag_data.handle.is_null()
&& (*emitter).tag_data.suffix.is_null()
{
return OK;
}
if !(*emitter).tag_data.handle.is_null() {
if yaml_emitter_write_tag_handle(
emitter,
(*emitter).tag_data.handle,
(*emitter).tag_data.handle_length,
)
.fail
{
return FAIL;
}
if !(*emitter).tag_data.suffix.is_null()
&& yaml_emitter_write_tag_content(
emitter,
(*emitter).tag_data.suffix,
(*emitter).tag_data.suffix_length,
false,
)
.fail
{
return FAIL;
}
} else {
if yaml_emitter_write_indicator(
emitter,
b"!<\0" as *const u8 as *const libc::c_char,
true,
false,
false,
)
.fail
{
return FAIL;
}
if yaml_emitter_write_tag_content(
emitter,
(*emitter).tag_data.suffix,
(*emitter).tag_data.suffix_length,
false,
)
.fail
{
return FAIL;
}
if yaml_emitter_write_indicator(
emitter,
b">\0" as *const u8 as *const libc::c_char,
false,
false,
false,
)
.fail
{
return FAIL;
}
}
OK
}
unsafe fn yaml_emitter_process_scalar(
emitter: *mut YamlEmitterT,
) -> Success {
match (*emitter).scalar_data.style {
YamlPlainScalarStyle => {
return yaml_emitter_write_plain_scalar(
emitter,
(*emitter).scalar_data.value,
(*emitter).scalar_data.length,
!(*emitter).simple_key_context,
);
}
YamlSingleQuotedScalarStyle => {
return yaml_emitter_write_single_quoted_scalar(
emitter,
(*emitter).scalar_data.value,
(*emitter).scalar_data.length,
!(*emitter).simple_key_context,
);
}
YamlDoubleQuotedScalarStyle => {
return yaml_emitter_write_double_quoted_scalar(
emitter,
(*emitter).scalar_data.value,
(*emitter).scalar_data.length,
!(*emitter).simple_key_context,
);
}
YamlLiteralScalarStyle => {
return yaml_emitter_write_literal_scalar(
emitter,
(*emitter).scalar_data.value,
(*emitter).scalar_data.length,
);
}
YamlFoldedScalarStyle => {
return yaml_emitter_write_folded_scalar(
emitter,
(*emitter).scalar_data.value,
(*emitter).scalar_data.length,
);
}
_ => {}
}
FAIL
}
unsafe fn yaml_emitter_analyze_version_directive(
emitter: *mut YamlEmitterT,
version_directive: YamlVersionDirectiveT,
) -> Success {
if version_directive.major != 1
|| version_directive.minor != 1 && version_directive.minor != 2
{
return yaml_emitter_set_emitter_error(
emitter,
b"incompatible %YAML directive\0" as *const u8
as *const libc::c_char,
);
}
OK
}
unsafe fn yaml_emitter_analyze_tag_directive(
emitter: *mut YamlEmitterT,
tag_directive: YamlTagDirectiveT,
) -> Success {
let handle_length: size_t =
strlen(tag_directive.handle as *mut libc::c_char);
let prefix_length: size_t =
strlen(tag_directive.prefix as *mut libc::c_char);
let mut handle =
STRING_ASSIGN!(tag_directive.handle, handle_length);
let prefix = STRING_ASSIGN!(tag_directive.prefix, prefix_length);
if handle.start == handle.end {
return yaml_emitter_set_emitter_error(
emitter,
b"tag handle must not be empty\0" as *const u8
as *const libc::c_char,
);
}
if *handle.start != b'!' {
return yaml_emitter_set_emitter_error(
emitter,
b"tag handle must start with '!'\0" as *const u8
as *const libc::c_char,
);
}
if *handle.end.wrapping_offset(-1_isize) != b'!' {
return yaml_emitter_set_emitter_error(
emitter,
b"tag handle must end with '!'\0" as *const u8
as *const libc::c_char,
);
}
handle.pointer = handle.pointer.wrapping_offset(1);
while handle.pointer < handle.end.wrapping_offset(-1_isize) {
if !IS_ALPHA!(handle) {
return yaml_emitter_set_emitter_error(
emitter,
b"tag handle must contain alphanumerical characters only\0" as *const u8
as *const libc::c_char,
);
}
MOVE!(handle);
}
if prefix.start == prefix.end {
return yaml_emitter_set_emitter_error(
emitter,
b"tag prefix must not be empty\0" as *const u8
as *const libc::c_char,
);
}
OK
}
unsafe fn yaml_emitter_analyze_anchor(
emitter: *mut YamlEmitterT,
anchor: *mut yaml_char_t,
alias: bool,
) -> Success {
let anchor_length: size_t = strlen(anchor as *mut libc::c_char);
let mut string = STRING_ASSIGN!(anchor, anchor_length);
if string.start == string.end {
return yaml_emitter_set_emitter_error(
emitter,
if alias {
b"alias value must not be empty\0" as *const u8
as *const libc::c_char
} else {
b"anchor value must not be empty\0" as *const u8
as *const libc::c_char
},
);
}
while string.pointer != string.end {
if !IS_ALPHA!(string) {
return yaml_emitter_set_emitter_error(
emitter,
if alias {
b"alias value must contain alphanumerical characters only\0" as *const u8
as *const libc::c_char
} else {
b"anchor value must contain alphanumerical characters only\0" as *const u8
as *const libc::c_char
},
);
}
MOVE!(string);
}
let fresh47 = addr_of_mut!((*emitter).anchor_data.anchor);
*fresh47 = string.start;
(*emitter).anchor_data.anchor_length =
string.end.c_offset_from(string.start) as size_t;
(*emitter).anchor_data.alias = alias;
OK
}
unsafe fn yaml_emitter_analyze_tag(
emitter: *mut YamlEmitterT,
tag: *mut yaml_char_t,
) -> Success {
let mut tag_directive: *mut YamlTagDirectiveT;
let tag_length: size_t = strlen(tag as *mut libc::c_char);
let string = STRING_ASSIGN!(tag, tag_length);
if string.start == string.end {
return yaml_emitter_set_emitter_error(
emitter,
b"tag value must not be empty\0" as *const u8
as *const libc::c_char,
);
}
tag_directive = (*emitter).tag_directives.start;
while tag_directive != (*emitter).tag_directives.top {
let prefix_length: size_t =
strlen((*tag_directive).prefix as *mut libc::c_char);
if prefix_length
< string.end.c_offset_from(string.start) as size_t
&& strncmp(
(*tag_directive).prefix as *mut libc::c_char,
string.start as *mut libc::c_char,
prefix_length,
) == 0
{
let fresh48 = addr_of_mut!((*emitter).tag_data.handle);
*fresh48 = (*tag_directive).handle;
(*emitter).tag_data.handle_length =
strlen((*tag_directive).handle as *mut libc::c_char);
let fresh49 = addr_of_mut!((*emitter).tag_data.suffix);
*fresh49 =
string.start.wrapping_offset(prefix_length as isize);
(*emitter).tag_data.suffix_length =
(string.end.c_offset_from(string.start)
as libc::c_ulong)
.wrapping_sub(prefix_length);
return OK;
}
tag_directive = tag_directive.wrapping_offset(1);
}
let fresh50 = addr_of_mut!((*emitter).tag_data.suffix);
*fresh50 = string.start;
(*emitter).tag_data.suffix_length =
string.end.c_offset_from(string.start) as size_t;
OK
}
unsafe fn yaml_emitter_analyze_scalar(
emitter: *mut YamlEmitterT,
value: *mut yaml_char_t,
length: size_t,
) -> Success {
let mut block_indicators = false;
let mut flow_indicators = false;
let mut line_breaks = false;
let mut special_characters = false;
let mut leading_space = false;
let mut leading_break = false;
let mut trailing_space = false;
let mut trailing_break = false;
let mut break_space = false;
let mut space_break = false;
let mut preceded_by_whitespace;
let mut followed_by_whitespace;
let mut previous_space = false;
let mut previous_break = false;
let mut string = STRING_ASSIGN!(value, length);
let fresh51 = addr_of_mut!((*emitter).scalar_data.value);
*fresh51 = value;
(*emitter).scalar_data.length = length;
if string.start == string.end {
(*emitter).scalar_data.multiline = false;
(*emitter).scalar_data.flow_plain_allowed = false;
(*emitter).scalar_data.block_plain_allowed = true;
(*emitter).scalar_data.single_quoted_allowed = true;
(*emitter).scalar_data.block_allowed = false;
return OK;
}
if CHECK_AT!(string, b'-', 0)
&& CHECK_AT!(string, b'-', 1)
&& CHECK_AT!(string, b'-', 2)
|| CHECK_AT!(string, b'.', 0)
&& CHECK_AT!(string, b'.', 1)
&& CHECK_AT!(string, b'.', 2)
{
block_indicators = true;
flow_indicators = true;
}
preceded_by_whitespace = true;
followed_by_whitespace = IS_BLANKZ_AT!(string, WIDTH!(string));
while string.pointer != string.end {
if string.start == string.pointer {
if CHECK!(string, b'#')
|| CHECK!(string, b',')
|| CHECK!(string, b'[')
|| CHECK!(string, b']')
|| CHECK!(string, b'{')
|| CHECK!(string, b'}')
|| CHECK!(string, b'&')
|| CHECK!(string, b'*')
|| CHECK!(string, b'!')
|| CHECK!(string, b'|')
|| CHECK!(string, b'>')
|| CHECK!(string, b'\'')
|| CHECK!(string, b'"')
|| CHECK!(string, b'%')
|| CHECK!(string, b'@')
|| CHECK!(string, b'`')
{
flow_indicators = true;
block_indicators = true;
}
if CHECK!(string, b'?') || CHECK!(string, b':') {
flow_indicators = true;
if followed_by_whitespace {
block_indicators = true;
}
}
if CHECK!(string, b'-') && followed_by_whitespace {
flow_indicators = true;
block_indicators = true;
}
} else {
if CHECK!(string, b',')
|| CHECK!(string, b'?')
|| CHECK!(string, b'[')
|| CHECK!(string, b']')
|| CHECK!(string, b'{')
|| CHECK!(string, b'}')
{
flow_indicators = true;
}
if CHECK!(string, b':') {
flow_indicators = true;
if followed_by_whitespace {
block_indicators = true;
}
}
if CHECK!(string, b'#') && preceded_by_whitespace {
flow_indicators = true;
block_indicators = true;
}
}
if !IS_PRINTABLE!(string)
|| !IS_ASCII!(string) && !(*emitter).unicode
{
special_characters = true;
}
if IS_BREAK!(string) {
line_breaks = true;
}
if IS_SPACE!(string) {
if string.start == string.pointer {
leading_space = true;
}
if string.pointer.wrapping_offset(WIDTH!(string) as isize)
== string.end
{
trailing_space = true;
}
if previous_break {
break_space = true;
}
previous_space = true;
previous_break = false;
} else if IS_BREAK!(string) {
if string.start == string.pointer {
leading_break = true;
}
if string.pointer.wrapping_offset(WIDTH!(string) as isize)
== string.end
{
trailing_break = true;
}
if previous_space {
space_break = true;
}
previous_space = false;
previous_break = true;
} else {
previous_space = false;
previous_break = false;
}
preceded_by_whitespace = IS_BLANKZ!(string);
MOVE!(string);
if string.pointer != string.end {
followed_by_whitespace =
IS_BLANKZ_AT!(string, WIDTH!(string));
}
}
(*emitter).scalar_data.multiline = line_breaks;
(*emitter).scalar_data.flow_plain_allowed = true;
(*emitter).scalar_data.block_plain_allowed = true;
(*emitter).scalar_data.single_quoted_allowed = true;
(*emitter).scalar_data.block_allowed = true;
if leading_space
|| leading_break
|| trailing_space
|| trailing_break
{
(*emitter).scalar_data.flow_plain_allowed = false;
(*emitter).scalar_data.block_plain_allowed = false;
}
if trailing_space {
(*emitter).scalar_data.block_allowed = false;
}
if break_space {
(*emitter).scalar_data.flow_plain_allowed = false;
(*emitter).scalar_data.block_plain_allowed = false;
(*emitter).scalar_data.single_quoted_allowed = false;
}
if space_break || special_characters {
(*emitter).scalar_data.flow_plain_allowed = false;
(*emitter).scalar_data.block_plain_allowed = false;
(*emitter).scalar_data.single_quoted_allowed = false;
(*emitter).scalar_data.block_allowed = false;
}
if line_breaks {
(*emitter).scalar_data.flow_plain_allowed = false;
(*emitter).scalar_data.block_plain_allowed = false;
}
if flow_indicators {
(*emitter).scalar_data.flow_plain_allowed = false;
}
if block_indicators {
(*emitter).scalar_data.block_plain_allowed = false;
}
OK
}
unsafe fn yaml_emitter_analyze_event(
emitter: *mut YamlEmitterT,
event: *mut YamlEventT,
) -> Success {
let fresh52 = addr_of_mut!((*emitter).anchor_data.anchor);
*fresh52 = ptr::null_mut::<yaml_char_t>();
(*emitter).anchor_data.anchor_length = 0_u64;
let fresh53 = addr_of_mut!((*emitter).tag_data.handle);
*fresh53 = ptr::null_mut::<yaml_char_t>();
(*emitter).tag_data.handle_length = 0_u64;
let fresh54 = addr_of_mut!((*emitter).tag_data.suffix);
*fresh54 = ptr::null_mut::<yaml_char_t>();
(*emitter).tag_data.suffix_length = 0_u64;
let fresh55 = addr_of_mut!((*emitter).scalar_data.value);
*fresh55 = ptr::null_mut::<yaml_char_t>();
(*emitter).scalar_data.length = 0_u64;
match (*event).type_ {
YamlAliasEvent => yaml_emitter_analyze_anchor(
emitter,
(*event).data.alias.anchor,
true,
),
YamlScalarEvent => {
if !(*event).data.scalar.anchor.is_null()
&& yaml_emitter_analyze_anchor(
emitter,
(*event).data.scalar.anchor,
false,
)
.fail
{
return FAIL;
}
if !(*event).data.scalar.tag.is_null()
&& ((*emitter).canonical
|| !(*event).data.scalar.plain_implicit
&& !(*event).data.scalar.quoted_implicit)
&& yaml_emitter_analyze_tag(
emitter,
(*event).data.scalar.tag,
)
.fail
{
return FAIL;
}
yaml_emitter_analyze_scalar(
emitter,
(*event).data.scalar.value,
(*event).data.scalar.length,
)
}
YamlSequenceStartEvent => {
if !(*event).data.sequence_start.anchor.is_null()
&& yaml_emitter_analyze_anchor(
emitter,
(*event).data.sequence_start.anchor,
false,
)
.fail
{
return FAIL;
}
if !(*event).data.sequence_start.tag.is_null()
&& ((*emitter).canonical
|| !(*event).data.sequence_start.implicit)
&& yaml_emitter_analyze_tag(
emitter,
(*event).data.sequence_start.tag,
)
.fail
{
return FAIL;
}
OK
}
YamlMappingStartEvent => {
if !(*event).data.mapping_start.anchor.is_null()
&& yaml_emitter_analyze_anchor(
emitter,
(*event).data.mapping_start.anchor,
false,
)
.fail
{
return FAIL;
}
if !(*event).data.mapping_start.tag.is_null()
&& ((*emitter).canonical
|| !(*event).data.mapping_start.implicit)
&& yaml_emitter_analyze_tag(
emitter,
(*event).data.mapping_start.tag,
)
.fail
{
return FAIL;
}
OK
}
_ => OK,
}
}
unsafe fn yaml_emitter_write_bom(
emitter: *mut YamlEmitterT,
) -> Success {
if flush(emitter).fail {
return FAIL;
}
let fresh56 = addr_of_mut!((*emitter).buffer.pointer);
let fresh57 = *fresh56;
*fresh56 = (*fresh56).wrapping_offset(1);
*fresh57 = b'\xEF';
let fresh58 = addr_of_mut!((*emitter).buffer.pointer);
let fresh59 = *fresh58;
*fresh58 = (*fresh58).wrapping_offset(1);
*fresh59 = b'\xBB';
let fresh60 = addr_of_mut!((*emitter).buffer.pointer);
let fresh61 = *fresh60;
*fresh60 = (*fresh60).wrapping_offset(1);
*fresh61 = b'\xBF';
OK
}
unsafe fn yaml_emitter_write_indent(
emitter: *mut YamlEmitterT,
) -> Success {
let indent: libc::c_int = if (*emitter).indent >= 0 {
(*emitter).indent
} else {
0
};
if (!(*emitter).indention
|| (*emitter).column > indent
|| (*emitter).column == indent && !(*emitter).whitespace)
&& put_break(emitter).fail
{
return FAIL;
}
if (*emitter).column < indent {
loop {
if put(emitter, b' ').fail {
return FAIL;
}
if (*emitter).column >= indent {
break;
}
}
}
(*emitter).whitespace = true;
(*emitter).indention = true;
OK
}
unsafe fn yaml_emitter_write_indicator(
emitter: *mut YamlEmitterT,
indicator: *const libc::c_char,
need_whitespace: bool,
is_whitespace: bool,
is_indention: bool,
) -> Success {
let indicator_length: size_t = strlen(indicator);
let mut string =
STRING_ASSIGN!(indicator as *mut yaml_char_t, indicator_length);
if need_whitespace
&& !(*emitter).whitespace
&& put(emitter, b' ').fail
{
return FAIL;
}
while string.pointer != string.end {
if write!(emitter, string).fail {
return FAIL;
}
}
(*emitter).whitespace = is_whitespace;
(*emitter).indention = (*emitter).indention && is_indention;
OK
}
unsafe fn yaml_emitter_write_anchor(
emitter: *mut YamlEmitterT,
value: *mut yaml_char_t,
length: size_t,
) -> Success {
let mut string = STRING_ASSIGN!(value, length);
while string.pointer != string.end {
if write!(emitter, string).fail {
return FAIL;
}
}
(*emitter).whitespace = false;
(*emitter).indention = false;
OK
}
unsafe fn yaml_emitter_write_tag_handle(
emitter: *mut YamlEmitterT,
value: *mut yaml_char_t,
length: size_t,
) -> Success {
let mut string = STRING_ASSIGN!(value, length);
if !(*emitter).whitespace && put(emitter, b' ').fail {
return FAIL;
}
while string.pointer != string.end {
if write!(emitter, string).fail {
return FAIL;
}
}
(*emitter).whitespace = false;
(*emitter).indention = false;
OK
}
unsafe fn yaml_emitter_write_tag_content(
emitter: *mut YamlEmitterT,
value: *mut yaml_char_t,
length: size_t,
need_whitespace: bool,
) -> Success {
let mut string = STRING_ASSIGN!(value, length);
if need_whitespace
&& !(*emitter).whitespace
&& put(emitter, b' ').fail
{
return FAIL;
}
while string.pointer != string.end {
if IS_ALPHA!(string)
|| CHECK!(string, b';')
|| CHECK!(string, b'/')
|| CHECK!(string, b'?')
|| CHECK!(string, b':')
|| CHECK!(string, b'@')
|| CHECK!(string, b'&')
|| CHECK!(string, b'=')
|| CHECK!(string, b'+')
|| CHECK!(string, b'$')
|| CHECK!(string, b',')
|| CHECK!(string, b'_')
|| CHECK!(string, b'.')
|| CHECK!(string, b'~')
|| CHECK!(string, b'*')
|| CHECK!(string, b'\'')
|| CHECK!(string, b'(')
|| CHECK!(string, b')')
|| CHECK!(string, b'[')
|| CHECK!(string, b']')
{
if write!(emitter, string).fail {
return FAIL;
}
} else {
let mut width = WIDTH!(string);
loop {
let fresh207 = width;
width -= 1;
if fresh207 == 0 {
break;
}
let fresh208 = string.pointer;
string.pointer = string.pointer.wrapping_offset(1);
let value = *fresh208;
if put(emitter, b'%').fail {
return FAIL;
}
if put(
emitter,
(value >> 4).force_add(if (value >> 4) < 10 {
b'0'
} else {
b'A' - 10
}),
)
.fail
{
return FAIL;
}
if put(
emitter,
(value & 0x0F).force_add(if (value & 0x0F) < 10 {
b'0'
} else {
b'A' - 10
}),
)
.fail
{
return FAIL;
}
}
}
}
(*emitter).whitespace = false;
(*emitter).indention = false;
OK
}
unsafe fn yaml_emitter_write_plain_scalar(
emitter: *mut YamlEmitterT,
value: *mut yaml_char_t,
length: size_t,
allow_breaks: bool,
) -> Success {
let mut spaces = false;
let mut breaks = false;
let mut string = STRING_ASSIGN!(value, length);
if !(*emitter).whitespace
&& (length != 0 || (*emitter).flow_level != 0)
&& put(emitter, b' ').fail
{
return FAIL;
}
while string.pointer != string.end {
if IS_SPACE!(string) {
if allow_breaks
&& !spaces
&& (*emitter).column > (*emitter).best_width
&& !IS_SPACE_AT!(string, 1)
{
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
MOVE!(string);
} else if write!(emitter, string).fail {
return FAIL;
}
spaces = true;
} else if IS_BREAK!(string) {
if !breaks
&& CHECK!(string, b'\n')
&& put_break(emitter).fail
{
return FAIL;
}
if write_break!(emitter, string).fail {
return FAIL;
}
(*emitter).indention = true;
breaks = true;
} else {
if breaks && yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
if write!(emitter, string).fail {
return FAIL;
}
(*emitter).indention = false;
spaces = false;
breaks = false;
}
}
(*emitter).whitespace = false;
(*emitter).indention = false;
OK
}
unsafe fn yaml_emitter_write_single_quoted_scalar(
emitter: *mut YamlEmitterT,
value: *mut yaml_char_t,
length: size_t,
allow_breaks: bool,
) -> Success {
let mut spaces = false;
let mut breaks = false;
let mut string = STRING_ASSIGN!(value, length);
if yaml_emitter_write_indicator(
emitter,
b"'\0" as *const u8 as *const libc::c_char,
true,
false,
false,
)
.fail
{
return FAIL;
}
while string.pointer != string.end {
if IS_SPACE!(string) {
if allow_breaks
&& !spaces
&& (*emitter).column > (*emitter).best_width
&& string.pointer != string.start
&& string.pointer
!= string.end.wrapping_offset(-1_isize)
&& !IS_SPACE_AT!(string, 1)
{
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
MOVE!(string);
} else if write!(emitter, string).fail {
return FAIL;
}
spaces = true;
} else if IS_BREAK!(string) {
if !breaks
&& CHECK!(string, b'\n')
&& put_break(emitter).fail
{
return FAIL;
}
if write_break!(emitter, string).fail {
return FAIL;
}
(*emitter).indention = true;
breaks = true;
} else {
if breaks && yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
if CHECK!(string, b'\'') && put(emitter, b'\'').fail {
return FAIL;
}
if write!(emitter, string).fail {
return FAIL;
}
(*emitter).indention = false;
spaces = false;
breaks = false;
}
}
if breaks && yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
if yaml_emitter_write_indicator(
emitter,
b"'\0" as *const u8 as *const libc::c_char,
false,
false,
false,
)
.fail
{
return FAIL;
}
(*emitter).whitespace = false;
(*emitter).indention = false;
OK
}
unsafe fn yaml_emitter_write_double_quoted_scalar(
emitter: *mut YamlEmitterT,
value: *mut yaml_char_t,
length: size_t,
allow_breaks: bool,
) -> Success {
let mut spaces = false;
let mut string = STRING_ASSIGN!(value, length);
if yaml_emitter_write_indicator(
emitter,
b"\"\0" as *const u8 as *const libc::c_char,
true,
false,
false,
)
.fail
{
return FAIL;
}
while string.pointer != string.end {
if !IS_PRINTABLE!(string)
|| !(*emitter).unicode && !IS_ASCII!(string)
|| IS_BOM!(string)
|| IS_BREAK!(string)
|| CHECK!(string, b'"')
|| CHECK!(string, b'\\')
{
let mut octet: libc::c_uchar;
let mut width: libc::c_uint;
let mut value_0: libc::c_uint;
let mut k: libc::c_int;
octet = *string.pointer;
width = if octet & 0x80 == 0x00 {
1
} else if octet & 0xE0 == 0xC0 {
2
} else if octet & 0xF0 == 0xE0 {
3
} else if octet & 0xF8 == 0xF0 {
4
} else {
0
};
value_0 = if octet & 0x80 == 0 {
octet & 0x7F
} else if octet & 0xE0 == 0xC0 {
octet & 0x1F
} else if octet & 0xF0 == 0xE0 {
octet & 0x0F
} else if octet & 0xF8 == 0xF0 {
octet & 0x07
} else {
0
} as libc::c_uint;
k = 1;
while k < width as libc::c_int {
octet = *string.pointer.wrapping_offset(k as isize);
value_0 = (value_0 << 6)
.force_add((octet & 0x3F) as libc::c_uint);
k += 1;
}
string.pointer =
string.pointer.wrapping_offset(width as isize);
if put(emitter, b'\\').fail {
return FAIL;
}
match value_0 {
0x00 => {
if put(emitter, b'0').fail {
return FAIL;
}
}
0x07 => {
if put(emitter, b'a').fail {
return FAIL;
}
}
0x08 => {
if put(emitter, b'b').fail {
return FAIL;
}
}
0x09 => {
if put(emitter, b't').fail {
return FAIL;
}
}
0x0A => {
if put(emitter, b'n').fail {
return FAIL;
}
}
0x0B => {
if put(emitter, b'v').fail {
return FAIL;
}
}
0x0C => {
if put(emitter, b'f').fail {
return FAIL;
}
}
0x0D => {
if put(emitter, b'r').fail {
return FAIL;
}
}
0x1B => {
if put(emitter, b'e').fail {
return FAIL;
}
}
0x22 => {
if put(emitter, b'"').fail {
return FAIL;
}
}
0x5C => {
if put(emitter, b'\\').fail {
return FAIL;
}
}
0x85 => {
if put(emitter, b'N').fail {
return FAIL;
}
}
0xA0 => {
if put(emitter, b'_').fail {
return FAIL;
}
}
0x2028 => {
if put(emitter, b'L').fail {
return FAIL;
}
}
0x2029 => {
if put(emitter, b'P').fail {
return FAIL;
}
}
_ => {
if value_0 <= 0xFF {
if put(emitter, b'x').fail {
return FAIL;
}
width = 2;
} else if value_0 <= 0xFFFF {
if put(emitter, b'u').fail {
return FAIL;
}
width = 4;
} else {
if put(emitter, b'U').fail {
return FAIL;
}
width = 8;
}
k = width.wrapping_sub(1).wrapping_mul(4)
as libc::c_int;
while k >= 0 {
let digit: libc::c_int =
(value_0 >> k & 0x0F) as libc::c_int;
if put(
emitter,
(digit
+ if digit < 10 {
b'0'
} else {
b'A' - 10
}
as i32)
as u8,
)
.fail
{
return FAIL;
}
k -= 4;
}
}
}
spaces = false;
} else if IS_SPACE!(string) {
if allow_breaks
&& !spaces
&& (*emitter).column > (*emitter).best_width
&& string.pointer != string.start
&& string.pointer
!= string.end.wrapping_offset(-1_isize)
{
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
if IS_SPACE_AT!(string, 1) && put(emitter, b'\\').fail {
return FAIL;
}
MOVE!(string);
} else if write!(emitter, string).fail {
return FAIL;
}
spaces = true;
} else {
if write!(emitter, string).fail {
return FAIL;
}
spaces = false;
}
}
if yaml_emitter_write_indicator(
emitter,
b"\"\0" as *const u8 as *const libc::c_char,
false,
false,
false,
)
.fail
{
return FAIL;
}
(*emitter).whitespace = false;
(*emitter).indention = false;
OK
}
unsafe fn yaml_emitter_write_block_scalar_hints(
emitter: *mut YamlEmitterT,
mut string: YamlStringT,
) -> Success {
let mut indent_hint: [libc::c_char; 2] = [0; 2];
let mut chomp_hint: *const libc::c_char =
ptr::null::<libc::c_char>();
if IS_SPACE!(string) || IS_BREAK!(string) {
indent_hint[0] = (b'0' as libc::c_int + (*emitter).best_indent)
as libc::c_char;
indent_hint[1] = '\0' as libc::c_char;
if yaml_emitter_write_indicator(
emitter,
indent_hint.as_mut_ptr(),
false,
false,
false,
)
.fail
{
return FAIL;
}
}
(*emitter).open_ended = 0;
string.pointer = string.end;
if string.start == string.pointer {
chomp_hint = b"-\0" as *const u8 as *const libc::c_char;
} else {
loop {
string.pointer = string.pointer.wrapping_offset(-1);
if *string.pointer & 0xC0 != 0x80 {
break;
}
}
if !IS_BREAK!(string) {
chomp_hint = b"-\0" as *const u8 as *const libc::c_char;
} else if string.start == string.pointer {
chomp_hint = b"+\0" as *const u8 as *const libc::c_char;
(*emitter).open_ended = 2;
} else {
loop {
string.pointer = string.pointer.wrapping_offset(-1);
if *string.pointer & 0xC0 != 0x80 {
break;
}
}
if IS_BREAK!(string) {
chomp_hint = b"+\0" as *const u8 as *const libc::c_char;
(*emitter).open_ended = 2;
}
}
}
if !chomp_hint.is_null()
&& yaml_emitter_write_indicator(
emitter, chomp_hint, false, false, false,
)
.fail
{
return FAIL;
}
OK
}
unsafe fn yaml_emitter_write_literal_scalar(
emitter: *mut YamlEmitterT,
value: *mut yaml_char_t,
length: size_t,
) -> Success {
let mut breaks = true;
let mut string = STRING_ASSIGN!(value, length);
if yaml_emitter_write_indicator(
emitter,
b"|\0" as *const u8 as *const libc::c_char,
true,
false,
false,
)
.fail
{
return FAIL;
}
if yaml_emitter_write_block_scalar_hints(emitter, string).fail {
return FAIL;
}
if put_break(emitter).fail {
return FAIL;
}
(*emitter).indention = true;
(*emitter).whitespace = true;
while string.pointer != string.end {
if IS_BREAK!(string) {
if write_break!(emitter, string).fail {
return FAIL;
}
(*emitter).indention = true;
breaks = true;
} else {
if breaks && yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
if write!(emitter, string).fail {
return FAIL;
}
(*emitter).indention = false;
breaks = false;
}
}
OK
}
unsafe fn yaml_emitter_write_folded_scalar(
emitter: *mut YamlEmitterT,
value: *mut yaml_char_t,
length: size_t,
) -> Success {
let mut breaks = true;
let mut leading_spaces = true;
let mut string = STRING_ASSIGN!(value, length);
if yaml_emitter_write_indicator(
emitter,
b">\0" as *const u8 as *const libc::c_char,
true,
false,
false,
)
.fail
{
return FAIL;
}
if yaml_emitter_write_block_scalar_hints(emitter, string).fail {
return FAIL;
}
if put_break(emitter).fail {
return FAIL;
}
(*emitter).indention = true;
(*emitter).whitespace = true;
while string.pointer != string.end {
if IS_BREAK!(string) {
if !breaks && !leading_spaces && CHECK!(string, b'\n') {
let mut k: libc::c_int = 0;
while IS_BREAK_AT!(string, k as isize) {
k += WIDTH_AT!(string, k as isize);
}
if !IS_BLANKZ_AT!(string, k as isize)
&& put_break(emitter).fail
{
return FAIL;
}
}
if write_break!(emitter, string).fail {
return FAIL;
}
(*emitter).indention = true;
breaks = true;
} else {
if breaks {
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
leading_spaces = IS_BLANK!(string);
}
if !breaks
&& IS_SPACE!(string)
&& !IS_SPACE_AT!(string, 1)
&& (*emitter).column > (*emitter).best_width
{
if yaml_emitter_write_indent(emitter).fail {
return FAIL;
}
MOVE!(string);
} else if write!(emitter, string).fail {
return FAIL;
}
(*emitter).indention = false;
breaks = false;
}
}
OK
}