1use core::ptr::{self, addr_of_mut};
2
3use crate::{
4 PointerExt, YAML_ALIAS_EVENT, YAML_ANY_BREAK, YAML_ANY_ENCODING, YAML_ANY_SCALAR_STYLE, YAML_CR_BREAK,
5 YAML_CRLN_BREAK, YAML_DOCUMENT_END_EVENT, YAML_DOCUMENT_START_EVENT, YAML_DOUBLE_QUOTED_SCALAR_STYLE,
6 YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE, YAML_EMIT_BLOCK_MAPPING_KEY_STATE,
7 YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE, YAML_EMIT_BLOCK_MAPPING_VALUE_STATE,
8 YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE, YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE, YAML_EMIT_DOCUMENT_CONTENT_STATE,
9 YAML_EMIT_DOCUMENT_END_STATE, YAML_EMIT_DOCUMENT_START_STATE, YAML_EMIT_END_STATE,
10 YAML_EMIT_FIRST_DOCUMENT_START_STATE, YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE, YAML_EMIT_FLOW_MAPPING_KEY_STATE,
11 YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE, YAML_EMIT_FLOW_MAPPING_VALUE_STATE,
12 YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE, YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE, YAML_EMIT_STREAM_START_STATE,
13 YAML_EMITTER_ERROR, YAML_FLOW_MAPPING_STYLE, YAML_FLOW_SEQUENCE_STYLE, YAML_FOLDED_SCALAR_STYLE,
14 YAML_LITERAL_SCALAR_STYLE, YAML_LN_BREAK, YAML_MAPPING_END_EVENT, YAML_MAPPING_START_EVENT,
15 YAML_PLAIN_SCALAR_STYLE, YAML_SCALAR_EVENT, YAML_SEQUENCE_END_EVENT, YAML_SEQUENCE_START_EVENT,
16 YAML_SINGLE_QUOTED_SCALAR_STYLE, YAML_STREAM_END_EVENT, YAML_STREAM_START_EVENT, YAML_UTF8_ENCODING,
17 api::{yaml_free, yaml_queue_extend, yaml_stack_extend, yaml_strdup},
18 externs::{strcmp, strlen, strncmp},
19 libc,
20 ops::{ForceAdd as _, ForceMul as _},
21 success::{FAIL, OK, Success},
22 yaml::{size_t, yaml_char_t, yaml_string_t},
23 yaml_emitter_flush, yaml_emitter_t, yaml_event_delete, yaml_event_t, yaml_scalar_style_t, yaml_tag_directive_t,
24 yaml_version_directive_t,
25};
26
27unsafe fn FLUSH(emitter: *mut yaml_emitter_t) -> Success {
28 if (*emitter).buffer.pointer.wrapping_offset(5_isize) < (*emitter).buffer.end {
29 OK
30 } else {
31 yaml_emitter_flush(emitter)
32 }
33}
34
35unsafe fn PUT(emitter: *mut yaml_emitter_t, value: u8) -> Success {
36 if FLUSH(emitter).fail {
37 return FAIL;
38 }
39 let fresh40 = addr_of_mut!((*emitter).buffer.pointer);
40 let fresh41 = *fresh40;
41 *fresh40 = (*fresh40).wrapping_offset(1);
42 *fresh41 = value;
43 let fresh42 = addr_of_mut!((*emitter).column);
44 *fresh42 += 1;
45 OK
46}
47
48unsafe fn PUT_BREAK(emitter: *mut yaml_emitter_t) -> Success {
49 if FLUSH(emitter).fail {
50 return FAIL;
51 }
52 if (*emitter).line_break == YAML_CR_BREAK {
53 let fresh62 = addr_of_mut!((*emitter).buffer.pointer);
54 let fresh63 = *fresh62;
55 *fresh62 = (*fresh62).wrapping_offset(1);
56 *fresh63 = b'\r';
57 } else if (*emitter).line_break == YAML_LN_BREAK {
58 let fresh64 = addr_of_mut!((*emitter).buffer.pointer);
59 let fresh65 = *fresh64;
60 *fresh64 = (*fresh64).wrapping_offset(1);
61 *fresh65 = b'\n';
62 } else if (*emitter).line_break == YAML_CRLN_BREAK {
63 let fresh66 = addr_of_mut!((*emitter).buffer.pointer);
64 let fresh67 = *fresh66;
65 *fresh66 = (*fresh66).wrapping_offset(1);
66 *fresh67 = b'\r';
67 let fresh68 = addr_of_mut!((*emitter).buffer.pointer);
68 let fresh69 = *fresh68;
69 *fresh68 = (*fresh68).wrapping_offset(1);
70 *fresh69 = b'\n';
71 };
72 (*emitter).column = 0;
73 let fresh70 = addr_of_mut!((*emitter).line);
74 *fresh70 += 1;
75 OK
76}
77
78unsafe fn WRITE(emitter: *mut yaml_emitter_t, string: *mut yaml_string_t) -> Success {
79 if FLUSH(emitter).fail {
80 return FAIL;
81 }
82 COPY!((*emitter).buffer, *string);
83 let fresh107 = addr_of_mut!((*emitter).column);
84 *fresh107 += 1;
85 OK
86}
87
88unsafe fn WRITE_BREAK(emitter: *mut yaml_emitter_t, string: *mut yaml_string_t) -> Success {
89 if FLUSH(emitter).fail {
90 return FAIL;
91 }
92 if CHECK!(*string, b'\n') {
93 let _ = PUT_BREAK(emitter);
94 (*string).pointer = (*string).pointer.wrapping_offset(1);
95 } else {
96 COPY!((*emitter).buffer, *string);
97 (*emitter).column = 0;
98 let fresh300 = addr_of_mut!((*emitter).line);
99 *fresh300 += 1;
100 }
101 OK
102}
103
104macro_rules! WRITE {
105 ($emitter:expr, $string:expr) => {
106 WRITE($emitter, addr_of_mut!($string))
107 };
108}
109
110macro_rules! WRITE_BREAK {
111 ($emitter:expr, $string:expr) => {
112 WRITE_BREAK($emitter, addr_of_mut!($string))
113 };
114}
115
116unsafe fn yaml_emitter_set_emitter_error(emitter: *mut yaml_emitter_t, problem: *const libc::c_char) -> Success {
117 (*emitter).error = YAML_EMITTER_ERROR;
118 let fresh0 = addr_of_mut!((*emitter).problem);
119 *fresh0 = problem;
120 FAIL
121}
122
123pub unsafe fn yaml_emitter_emit(emitter: *mut yaml_emitter_t, event: *mut yaml_event_t) -> Success {
130 ENQUEUE!((*emitter).events, *event);
131 while yaml_emitter_need_more_events(emitter).fail {
132 if yaml_emitter_analyze_event(emitter, (*emitter).events.head).fail {
133 return FAIL;
134 }
135 if yaml_emitter_state_machine(emitter, (*emitter).events.head).fail {
136 return FAIL;
137 }
138 yaml_event_delete(addr_of_mut!(DEQUEUE!((*emitter).events)));
139 }
140 OK
141}
142
143unsafe fn yaml_emitter_need_more_events(emitter: *mut yaml_emitter_t) -> Success {
144 let mut level: libc::c_int = 0;
145 let mut event: *mut yaml_event_t;
146 if QUEUE_EMPTY!((*emitter).events) {
147 return OK;
148 }
149 let accumulate = match (*(*emitter).events.head).type_ {
150 YAML_DOCUMENT_START_EVENT => 1,
151 YAML_SEQUENCE_START_EVENT => 2,
152 YAML_MAPPING_START_EVENT => 3,
153 _ => return FAIL,
154 };
155 if (*emitter).events.tail.c_offset_from((*emitter).events.head) as libc::c_long > accumulate as libc::c_long {
156 return FAIL;
157 }
158 event = (*emitter).events.head;
159 while event != (*emitter).events.tail {
160 match (*event).type_ {
161 YAML_STREAM_START_EVENT
162 | YAML_DOCUMENT_START_EVENT
163 | YAML_SEQUENCE_START_EVENT
164 | YAML_MAPPING_START_EVENT => {
165 level += 1;
166 }
167 YAML_STREAM_END_EVENT | YAML_DOCUMENT_END_EVENT | YAML_SEQUENCE_END_EVENT | YAML_MAPPING_END_EVENT => {
168 level -= 1;
169 }
170 _ => {}
171 }
172 if level == 0 {
173 return FAIL;
174 }
175 event = event.wrapping_offset(1);
176 }
177 OK
178}
179
180unsafe fn yaml_emitter_append_tag_directive(
181 emitter: *mut yaml_emitter_t,
182 value: yaml_tag_directive_t,
183 allow_duplicates: bool,
184) -> Success {
185 let mut tag_directive: *mut yaml_tag_directive_t;
186 let mut copy = yaml_tag_directive_t {
187 handle: ptr::null_mut::<yaml_char_t>(),
188 prefix: ptr::null_mut::<yaml_char_t>(),
189 };
190 tag_directive = (*emitter).tag_directives.start;
191 while tag_directive != (*emitter).tag_directives.top {
192 if strcmp(value.handle as *mut libc::c_char, (*tag_directive).handle as *mut libc::c_char) == 0 {
193 if allow_duplicates {
194 return OK;
195 }
196 return yaml_emitter_set_emitter_error(
197 emitter,
198 b"duplicate %TAG directive\0" as *const u8 as *const libc::c_char,
199 );
200 }
201 tag_directive = tag_directive.wrapping_offset(1);
202 }
203 copy.handle = yaml_strdup(value.handle);
204 copy.prefix = yaml_strdup(value.prefix);
205 PUSH!((*emitter).tag_directives, copy);
206 OK
207}
208
209unsafe fn yaml_emitter_increase_indent(emitter: *mut yaml_emitter_t, flow: bool, indentless: bool) {
210 PUSH!((*emitter).indents, (*emitter).indent);
211 if (*emitter).indent < 0 {
212 (*emitter).indent = if flow { (*emitter).best_indent } else { 0 };
213 } else if !indentless {
214 (*emitter).indent += (*emitter).best_indent;
215 }
216}
217
218unsafe fn yaml_emitter_state_machine(emitter: *mut yaml_emitter_t, event: *mut yaml_event_t) -> Success {
219 match (*emitter).state {
220 YAML_EMIT_STREAM_START_STATE => yaml_emitter_emit_stream_start(emitter, event),
221 YAML_EMIT_FIRST_DOCUMENT_START_STATE => yaml_emitter_emit_document_start(emitter, event, true),
222 YAML_EMIT_DOCUMENT_START_STATE => yaml_emitter_emit_document_start(emitter, event, false),
223 YAML_EMIT_DOCUMENT_CONTENT_STATE => yaml_emitter_emit_document_content(emitter, event),
224 YAML_EMIT_DOCUMENT_END_STATE => yaml_emitter_emit_document_end(emitter, event),
225 YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE => yaml_emitter_emit_flow_sequence_item(emitter, event, true),
226 YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE => yaml_emitter_emit_flow_sequence_item(emitter, event, false),
227 YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE => yaml_emitter_emit_flow_mapping_key(emitter, event, true),
228 YAML_EMIT_FLOW_MAPPING_KEY_STATE => yaml_emitter_emit_flow_mapping_key(emitter, event, false),
229 YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE => yaml_emitter_emit_flow_mapping_value(emitter, event, true),
230 YAML_EMIT_FLOW_MAPPING_VALUE_STATE => yaml_emitter_emit_flow_mapping_value(emitter, event, false),
231 YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE => yaml_emitter_emit_block_sequence_item(emitter, event, true),
232 YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE => yaml_emitter_emit_block_sequence_item(emitter, event, false),
233 YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE => yaml_emitter_emit_block_mapping_key(emitter, event, true),
234 YAML_EMIT_BLOCK_MAPPING_KEY_STATE => yaml_emitter_emit_block_mapping_key(emitter, event, false),
235 YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE => yaml_emitter_emit_block_mapping_value(emitter, event, true),
236 YAML_EMIT_BLOCK_MAPPING_VALUE_STATE => yaml_emitter_emit_block_mapping_value(emitter, event, false),
237 YAML_EMIT_END_STATE => yaml_emitter_set_emitter_error(
238 emitter,
239 b"expected nothing after STREAM-END\0" as *const u8 as *const libc::c_char,
240 ),
241 }
242}
243
244unsafe fn yaml_emitter_emit_stream_start(emitter: *mut yaml_emitter_t, event: *mut yaml_event_t) -> Success {
245 (*emitter).open_ended = 0;
246 if (*event).type_ == YAML_STREAM_START_EVENT {
247 if (*emitter).encoding == YAML_ANY_ENCODING {
248 (*emitter).encoding = (*event).data.stream_start.encoding;
249 }
250 if (*emitter).encoding == YAML_ANY_ENCODING {
251 (*emitter).encoding = YAML_UTF8_ENCODING;
252 }
253 if (*emitter).best_indent < 2 || (*emitter).best_indent > 9 {
254 (*emitter).best_indent = 2;
255 }
256 if (*emitter).best_width >= 0 && (*emitter).best_width <= (*emitter).best_indent.force_mul(2) {
257 (*emitter).best_width = 80;
258 }
259 if (*emitter).best_width < 0 {
260 (*emitter).best_width = libc::c_int::MAX;
261 }
262 if (*emitter).line_break == YAML_ANY_BREAK {
263 (*emitter).line_break = YAML_LN_BREAK;
264 }
265 (*emitter).indent = -1;
266 (*emitter).line = 0;
267 (*emitter).column = 0;
268 (*emitter).whitespace = true;
269 (*emitter).indention = true;
270 if (*emitter).encoding != YAML_UTF8_ENCODING {
271 if yaml_emitter_write_bom(emitter).fail {
272 return FAIL;
273 }
274 }
275 (*emitter).state = YAML_EMIT_FIRST_DOCUMENT_START_STATE;
276 return OK;
277 }
278 yaml_emitter_set_emitter_error(emitter, b"expected STREAM-START\0" as *const u8 as *const libc::c_char)
279}
280
281unsafe fn yaml_emitter_emit_document_start(
282 emitter: *mut yaml_emitter_t,
283 event: *mut yaml_event_t,
284 first: bool,
285) -> Success {
286 if (*event).type_ == YAML_DOCUMENT_START_EVENT {
287 let mut default_tag_directives: [yaml_tag_directive_t; 3] = [
288 yaml_tag_directive_t {
289 handle: b"!\0" as *const u8 as *const libc::c_char as *mut yaml_char_t,
290 prefix: b"!\0" as *const u8 as *const libc::c_char as *mut yaml_char_t,
291 },
292 yaml_tag_directive_t {
293 handle: b"!!\0" as *const u8 as *const libc::c_char as *mut yaml_char_t,
294 prefix: b"tag:yaml.org,2002:\0" as *const u8 as *const libc::c_char as *mut yaml_char_t,
295 },
296 yaml_tag_directive_t {
297 handle: ptr::null_mut::<yaml_char_t>(),
298 prefix: ptr::null_mut::<yaml_char_t>(),
299 },
300 ];
301 let mut tag_directive: *mut yaml_tag_directive_t;
302 let mut implicit;
303 if !(*event).data.document_start.version_directive.is_null() {
304 if yaml_emitter_analyze_version_directive(emitter, *(*event).data.document_start.version_directive).fail {
305 return FAIL;
306 }
307 }
308 tag_directive = (*event).data.document_start.tag_directives.start;
309 while tag_directive != (*event).data.document_start.tag_directives.end {
310 if yaml_emitter_analyze_tag_directive(emitter, *tag_directive).fail {
311 return FAIL;
312 }
313 if yaml_emitter_append_tag_directive(emitter, *tag_directive, false).fail {
314 return FAIL;
315 }
316 tag_directive = tag_directive.wrapping_offset(1);
317 }
318 tag_directive = default_tag_directives.as_mut_ptr();
319 while !(*tag_directive).handle.is_null() {
320 if yaml_emitter_append_tag_directive(emitter, *tag_directive, true).fail {
321 return FAIL;
322 }
323 tag_directive = tag_directive.wrapping_offset(1);
324 }
325 implicit = (*event).data.document_start.implicit;
326 if !first || (*emitter).canonical {
327 implicit = false;
328 }
329 if (!(*event).data.document_start.version_directive.is_null()
330 || (*event).data.document_start.tag_directives.start != (*event).data.document_start.tag_directives.end)
331 && (*emitter).open_ended != 0
332 {
333 if yaml_emitter_write_indicator(emitter, b"...\0" as *const u8 as *const libc::c_char, true, false, false)
334 .fail
335 {
336 return FAIL;
337 }
338 if yaml_emitter_write_indent(emitter).fail {
339 return FAIL;
340 }
341 }
342 (*emitter).open_ended = 0;
343 if !(*event).data.document_start.version_directive.is_null() {
344 implicit = false;
345 if yaml_emitter_write_indicator(emitter, b"%YAML\0" as *const u8 as *const libc::c_char, true, false, false)
346 .fail
347 {
348 return FAIL;
349 }
350 if (*(*event).data.document_start.version_directive).minor == 1 {
351 if yaml_emitter_write_indicator(
352 emitter,
353 b"1.1\0" as *const u8 as *const libc::c_char,
354 true,
355 false,
356 false,
357 )
358 .fail
359 {
360 return FAIL;
361 }
362 } else if yaml_emitter_write_indicator(
363 emitter,
364 b"1.2\0" as *const u8 as *const libc::c_char,
365 true,
366 false,
367 false,
368 )
369 .fail
370 {
371 return FAIL;
372 }
373 if yaml_emitter_write_indent(emitter).fail {
374 return FAIL;
375 }
376 }
377 if (*event).data.document_start.tag_directives.start != (*event).data.document_start.tag_directives.end {
378 implicit = false;
379 tag_directive = (*event).data.document_start.tag_directives.start;
380 while tag_directive != (*event).data.document_start.tag_directives.end {
381 if yaml_emitter_write_indicator(
382 emitter,
383 b"%TAG\0" as *const u8 as *const libc::c_char,
384 true,
385 false,
386 false,
387 )
388 .fail
389 {
390 return FAIL;
391 }
392 if yaml_emitter_write_tag_handle(
393 emitter,
394 (*tag_directive).handle,
395 strlen((*tag_directive).handle as *mut libc::c_char),
396 )
397 .fail
398 {
399 return FAIL;
400 }
401 if yaml_emitter_write_tag_content(
402 emitter,
403 (*tag_directive).prefix,
404 strlen((*tag_directive).prefix as *mut libc::c_char),
405 true,
406 )
407 .fail
408 {
409 return FAIL;
410 }
411 if yaml_emitter_write_indent(emitter).fail {
412 return FAIL;
413 }
414 tag_directive = tag_directive.wrapping_offset(1);
415 }
416 }
417 if yaml_emitter_check_empty_document(emitter) {
418 implicit = false;
419 }
420 if !implicit {
421 if yaml_emitter_write_indent(emitter).fail {
422 return FAIL;
423 }
424 if yaml_emitter_write_indicator(emitter, b"---\0" as *const u8 as *const libc::c_char, true, false, false)
425 .fail
426 {
427 return FAIL;
428 }
429 if (*emitter).canonical {
430 if yaml_emitter_write_indent(emitter).fail {
431 return FAIL;
432 }
433 }
434 }
435 (*emitter).state = YAML_EMIT_DOCUMENT_CONTENT_STATE;
436 (*emitter).open_ended = 0;
437 return OK;
438 } else if (*event).type_ == YAML_STREAM_END_EVENT {
439 if (*emitter).open_ended == 2 {
440 if yaml_emitter_write_indicator(emitter, b"...\0" as *const u8 as *const libc::c_char, true, false, false)
441 .fail
442 {
443 return FAIL;
444 }
445 (*emitter).open_ended = 0;
446 if yaml_emitter_write_indent(emitter).fail {
447 return FAIL;
448 }
449 }
450 if yaml_emitter_flush(emitter).fail {
451 return FAIL;
452 }
453 (*emitter).state = YAML_EMIT_END_STATE;
454 return OK;
455 }
456 yaml_emitter_set_emitter_error(
457 emitter,
458 b"expected DOCUMENT-START or STREAM-END\0" as *const u8 as *const libc::c_char,
459 )
460}
461
462unsafe fn yaml_emitter_emit_document_content(emitter: *mut yaml_emitter_t, event: *mut yaml_event_t) -> Success {
463 PUSH!((*emitter).states, YAML_EMIT_DOCUMENT_END_STATE);
464 yaml_emitter_emit_node(emitter, event, true, false, false, false)
465}
466
467unsafe fn yaml_emitter_emit_document_end(emitter: *mut yaml_emitter_t, event: *mut yaml_event_t) -> Success {
468 if (*event).type_ == YAML_DOCUMENT_END_EVENT {
469 if yaml_emitter_write_indent(emitter).fail {
470 return FAIL;
471 }
472 if !(*event).data.document_end.implicit {
473 if yaml_emitter_write_indicator(emitter, b"...\0" as *const u8 as *const libc::c_char, true, false, false)
474 .fail
475 {
476 return FAIL;
477 }
478 (*emitter).open_ended = 0;
479 if yaml_emitter_write_indent(emitter).fail {
480 return FAIL;
481 }
482 } else if (*emitter).open_ended == 0 {
483 (*emitter).open_ended = 1;
484 }
485 if yaml_emitter_flush(emitter).fail {
486 return FAIL;
487 }
488 (*emitter).state = YAML_EMIT_DOCUMENT_START_STATE;
489 while !STACK_EMPTY!((*emitter).tag_directives) {
490 let tag_directive = POP!((*emitter).tag_directives);
491 yaml_free(tag_directive.handle as *mut libc::c_void);
492 yaml_free(tag_directive.prefix as *mut libc::c_void);
493 }
494 return OK;
495 }
496 yaml_emitter_set_emitter_error(emitter, b"expected DOCUMENT-END\0" as *const u8 as *const libc::c_char)
497}
498
499unsafe fn yaml_emitter_emit_flow_sequence_item(
500 emitter: *mut yaml_emitter_t,
501 event: *mut yaml_event_t,
502 first: bool,
503) -> Success {
504 if first {
505 if yaml_emitter_write_indicator(emitter, b"[\0" as *const u8 as *const libc::c_char, true, true, false).fail {
506 return FAIL;
507 }
508 yaml_emitter_increase_indent(emitter, true, false);
509 let fresh12 = addr_of_mut!((*emitter).flow_level);
510 *fresh12 += 1;
511 }
512 if (*event).type_ == YAML_SEQUENCE_END_EVENT {
513 let fresh13 = addr_of_mut!((*emitter).flow_level);
514 *fresh13 -= 1;
515 (*emitter).indent = POP!((*emitter).indents);
516 if (*emitter).canonical && !first {
517 if yaml_emitter_write_indicator(emitter, b",\0" as *const u8 as *const libc::c_char, false, false, false)
518 .fail
519 {
520 return FAIL;
521 }
522 if yaml_emitter_write_indent(emitter).fail {
523 return FAIL;
524 }
525 }
526 if yaml_emitter_write_indicator(emitter, b"]\0" as *const u8 as *const libc::c_char, false, false, false).fail {
527 return FAIL;
528 }
529 (*emitter).state = POP!((*emitter).states);
530 return OK;
531 }
532 if !first {
533 if yaml_emitter_write_indicator(emitter, b",\0" as *const u8 as *const libc::c_char, false, false, false).fail {
534 return FAIL;
535 }
536 }
537 if (*emitter).canonical || (*emitter).column > (*emitter).best_width {
538 if yaml_emitter_write_indent(emitter).fail {
539 return FAIL;
540 }
541 }
542 PUSH!((*emitter).states, YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE);
543 yaml_emitter_emit_node(emitter, event, false, true, false, false)
544}
545
546unsafe fn yaml_emitter_emit_flow_mapping_key(
547 emitter: *mut yaml_emitter_t,
548 event: *mut yaml_event_t,
549 first: bool,
550) -> Success {
551 if first {
552 if yaml_emitter_write_indicator(emitter, b"{\0" as *const u8 as *const libc::c_char, true, true, false).fail {
553 return FAIL;
554 }
555 yaml_emitter_increase_indent(emitter, true, false);
556 let fresh18 = addr_of_mut!((*emitter).flow_level);
557 *fresh18 += 1;
558 }
559 if (*event).type_ == YAML_MAPPING_END_EVENT {
560 if STACK_EMPTY!((*emitter).indents) {
561 return FAIL;
562 }
563 let fresh19 = addr_of_mut!((*emitter).flow_level);
564 *fresh19 -= 1;
565 (*emitter).indent = POP!((*emitter).indents);
566 if (*emitter).canonical && !first {
567 if yaml_emitter_write_indicator(emitter, b",\0" as *const u8 as *const libc::c_char, false, false, false)
568 .fail
569 {
570 return FAIL;
571 }
572 if yaml_emitter_write_indent(emitter).fail {
573 return FAIL;
574 }
575 }
576 if yaml_emitter_write_indicator(emitter, b"}\0" as *const u8 as *const libc::c_char, false, false, false).fail {
577 return FAIL;
578 }
579 (*emitter).state = POP!((*emitter).states);
580 return OK;
581 }
582 if !first {
583 if yaml_emitter_write_indicator(emitter, b",\0" as *const u8 as *const libc::c_char, false, false, false).fail {
584 return FAIL;
585 }
586 }
587 if (*emitter).canonical || (*emitter).column > (*emitter).best_width {
588 if yaml_emitter_write_indent(emitter).fail {
589 return FAIL;
590 }
591 }
592 if !(*emitter).canonical && yaml_emitter_check_simple_key(emitter) {
593 PUSH!((*emitter).states, YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE);
594 yaml_emitter_emit_node(emitter, event, false, false, true, true)
595 } else {
596 if yaml_emitter_write_indicator(emitter, b"?\0" as *const u8 as *const libc::c_char, true, false, false).fail {
597 return FAIL;
598 }
599 PUSH!((*emitter).states, YAML_EMIT_FLOW_MAPPING_VALUE_STATE);
600 yaml_emitter_emit_node(emitter, event, false, false, true, false)
601 }
602}
603
604unsafe fn yaml_emitter_emit_flow_mapping_value(
605 emitter: *mut yaml_emitter_t,
606 event: *mut yaml_event_t,
607 simple: bool,
608) -> Success {
609 if simple {
610 if yaml_emitter_write_indicator(emitter, b":\0" as *const u8 as *const libc::c_char, false, false, false).fail {
611 return FAIL;
612 }
613 } else {
614 if (*emitter).canonical || (*emitter).column > (*emitter).best_width {
615 if yaml_emitter_write_indent(emitter).fail {
616 return FAIL;
617 }
618 }
619 if yaml_emitter_write_indicator(emitter, b":\0" as *const u8 as *const libc::c_char, true, false, false).fail {
620 return FAIL;
621 }
622 }
623 PUSH!((*emitter).states, YAML_EMIT_FLOW_MAPPING_KEY_STATE);
624 yaml_emitter_emit_node(emitter, event, false, false, true, false)
625}
626
627unsafe fn yaml_emitter_emit_block_sequence_item(
628 emitter: *mut yaml_emitter_t,
629 event: *mut yaml_event_t,
630 first: bool,
631) -> Success {
632 if first {
633 yaml_emitter_increase_indent(emitter, false, (*emitter).mapping_context && !(*emitter).indention);
634 }
635 if (*event).type_ == YAML_SEQUENCE_END_EVENT {
636 (*emitter).indent = POP!((*emitter).indents);
637 (*emitter).state = POP!((*emitter).states);
638 return OK;
639 }
640 if yaml_emitter_write_indent(emitter).fail {
641 return FAIL;
642 }
643 if yaml_emitter_write_indicator(emitter, b"-\0" as *const u8 as *const libc::c_char, true, false, true).fail {
644 return FAIL;
645 }
646 PUSH!((*emitter).states, YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE);
647 yaml_emitter_emit_node(emitter, event, false, true, false, false)
648}
649
650unsafe fn yaml_emitter_emit_block_mapping_key(
651 emitter: *mut yaml_emitter_t,
652 event: *mut yaml_event_t,
653 first: bool,
654) -> Success {
655 if first {
656 yaml_emitter_increase_indent(emitter, false, false);
657 }
658 if (*event).type_ == YAML_MAPPING_END_EVENT {
659 (*emitter).indent = POP!((*emitter).indents);
660 (*emitter).state = POP!((*emitter).states);
661 return OK;
662 }
663 if yaml_emitter_write_indent(emitter).fail {
664 return FAIL;
665 }
666 if yaml_emitter_check_simple_key(emitter) {
667 PUSH!((*emitter).states, YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE);
668 yaml_emitter_emit_node(emitter, event, false, false, true, true)
669 } else {
670 if yaml_emitter_write_indicator(emitter, b"?\0" as *const u8 as *const libc::c_char, true, false, true).fail {
671 return FAIL;
672 }
673 PUSH!((*emitter).states, YAML_EMIT_BLOCK_MAPPING_VALUE_STATE);
674 yaml_emitter_emit_node(emitter, event, false, false, true, false)
675 }
676}
677
678unsafe fn yaml_emitter_emit_block_mapping_value(
679 emitter: *mut yaml_emitter_t,
680 event: *mut yaml_event_t,
681 simple: bool,
682) -> Success {
683 if simple {
684 if yaml_emitter_write_indicator(emitter, b":\0" as *const u8 as *const libc::c_char, false, false, false).fail {
685 return FAIL;
686 }
687 } else {
688 if yaml_emitter_write_indent(emitter).fail {
689 return FAIL;
690 }
691 if yaml_emitter_write_indicator(emitter, b":\0" as *const u8 as *const libc::c_char, true, false, true).fail {
692 return FAIL;
693 }
694 }
695 PUSH!((*emitter).states, YAML_EMIT_BLOCK_MAPPING_KEY_STATE);
696 yaml_emitter_emit_node(emitter, event, false, false, true, false)
697}
698
699unsafe fn yaml_emitter_emit_node(
700 emitter: *mut yaml_emitter_t,
701 event: *mut yaml_event_t,
702 root: bool,
703 sequence: bool,
704 mapping: bool,
705 simple_key: bool,
706) -> Success {
707 (*emitter).root_context = root;
708 (*emitter).sequence_context = sequence;
709 (*emitter).mapping_context = mapping;
710 (*emitter).simple_key_context = simple_key;
711 match (*event).type_ {
712 YAML_ALIAS_EVENT => yaml_emitter_emit_alias(emitter, event),
713 YAML_SCALAR_EVENT => yaml_emitter_emit_scalar(emitter, event),
714 YAML_SEQUENCE_START_EVENT => yaml_emitter_emit_sequence_start(emitter, event),
715 YAML_MAPPING_START_EVENT => yaml_emitter_emit_mapping_start(emitter, event),
716 _ => yaml_emitter_set_emitter_error(
717 emitter,
718 b"expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS\0" as *const u8 as *const libc::c_char,
719 ),
720 }
721}
722
723unsafe fn yaml_emitter_emit_alias(emitter: *mut yaml_emitter_t, _event: *mut yaml_event_t) -> Success {
724 if yaml_emitter_process_anchor(emitter).fail {
725 return FAIL;
726 }
727 if (*emitter).simple_key_context {
728 if PUT(emitter, b' ').fail {
729 return FAIL;
730 }
731 }
732 (*emitter).state = POP!((*emitter).states);
733 OK
734}
735
736unsafe fn yaml_emitter_emit_scalar(emitter: *mut yaml_emitter_t, event: *mut yaml_event_t) -> Success {
737 if yaml_emitter_select_scalar_style(emitter, event).fail {
738 return FAIL;
739 }
740 if yaml_emitter_process_anchor(emitter).fail {
741 return FAIL;
742 }
743 if yaml_emitter_process_tag(emitter).fail {
744 return FAIL;
745 }
746 yaml_emitter_increase_indent(emitter, true, false);
747 if yaml_emitter_process_scalar(emitter).fail {
748 return FAIL;
749 }
750 (*emitter).indent = POP!((*emitter).indents);
751 (*emitter).state = POP!((*emitter).states);
752 OK
753}
754
755unsafe fn yaml_emitter_emit_sequence_start(emitter: *mut yaml_emitter_t, event: *mut yaml_event_t) -> Success {
756 if yaml_emitter_process_anchor(emitter).fail {
757 return FAIL;
758 }
759 if yaml_emitter_process_tag(emitter).fail {
760 return FAIL;
761 }
762 if (*emitter).flow_level != 0
763 || (*emitter).canonical
764 || (*event).data.sequence_start.style == YAML_FLOW_SEQUENCE_STYLE
765 || yaml_emitter_check_empty_sequence(emitter)
766 {
767 (*emitter).state = YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE;
768 } else {
769 (*emitter).state = YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE;
770 }
771 OK
772}
773
774unsafe fn yaml_emitter_emit_mapping_start(emitter: *mut yaml_emitter_t, event: *mut yaml_event_t) -> Success {
775 if yaml_emitter_process_anchor(emitter).fail {
776 return FAIL;
777 }
778 if yaml_emitter_process_tag(emitter).fail {
779 return FAIL;
780 }
781 if (*emitter).flow_level != 0
782 || (*emitter).canonical
783 || (*event).data.mapping_start.style == YAML_FLOW_MAPPING_STYLE
784 || yaml_emitter_check_empty_mapping(emitter)
785 {
786 (*emitter).state = YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE;
787 } else {
788 (*emitter).state = YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE;
789 }
790 OK
791}
792
793unsafe fn yaml_emitter_check_empty_document(_emitter: *mut yaml_emitter_t) -> bool {
794 false
795}
796
797unsafe fn yaml_emitter_check_empty_sequence(emitter: *mut yaml_emitter_t) -> bool {
798 if ((*emitter).events.tail.c_offset_from((*emitter).events.head) as libc::c_long) < 2_i64 {
799 return false;
800 }
801 (*(*emitter).events.head).type_ == YAML_SEQUENCE_START_EVENT
802 && (*(*emitter).events.head.wrapping_offset(1_isize)).type_ == YAML_SEQUENCE_END_EVENT
803}
804
805unsafe fn yaml_emitter_check_empty_mapping(emitter: *mut yaml_emitter_t) -> bool {
806 if ((*emitter).events.tail.c_offset_from((*emitter).events.head) as libc::c_long) < 2_i64 {
807 return false;
808 }
809 (*(*emitter).events.head).type_ == YAML_MAPPING_START_EVENT
810 && (*(*emitter).events.head.wrapping_offset(1_isize)).type_ == YAML_MAPPING_END_EVENT
811}
812
813unsafe fn yaml_emitter_check_simple_key(emitter: *mut yaml_emitter_t) -> bool {
814 let event: *mut yaml_event_t = (*emitter).events.head;
815 let mut length: size_t = 0_u64;
816 match (*event).type_ {
817 YAML_ALIAS_EVENT => {
818 length = (length as libc::c_ulong).force_add((*emitter).anchor_data.anchor_length) as size_t;
819 }
820 YAML_SCALAR_EVENT => {
821 if (*emitter).scalar_data.multiline {
822 return false;
823 }
824 length = (length as libc::c_ulong)
825 .force_add((*emitter).anchor_data.anchor_length)
826 .force_add((*emitter).tag_data.handle_length)
827 .force_add((*emitter).tag_data.suffix_length)
828 .force_add((*emitter).scalar_data.length) as size_t;
829 }
830 YAML_SEQUENCE_START_EVENT => {
831 if !yaml_emitter_check_empty_sequence(emitter) {
832 return false;
833 }
834 length = (length as libc::c_ulong)
835 .force_add((*emitter).anchor_data.anchor_length)
836 .force_add((*emitter).tag_data.handle_length)
837 .force_add((*emitter).tag_data.suffix_length) as size_t;
838 }
839 YAML_MAPPING_START_EVENT => {
840 if !yaml_emitter_check_empty_mapping(emitter) {
841 return false;
842 }
843 length = (length as libc::c_ulong)
844 .force_add((*emitter).anchor_data.anchor_length)
845 .force_add((*emitter).tag_data.handle_length)
846 .force_add((*emitter).tag_data.suffix_length) as size_t;
847 }
848 _ => return false,
849 }
850 if length > 128_u64 {
851 return false;
852 }
853 true
854}
855
856unsafe fn yaml_emitter_select_scalar_style(emitter: *mut yaml_emitter_t, event: *mut yaml_event_t) -> Success {
857 let mut style: yaml_scalar_style_t = (*event).data.scalar.style;
858 let no_tag = (*emitter).tag_data.handle.is_null() && (*emitter).tag_data.suffix.is_null();
859 if no_tag && !(*event).data.scalar.plain_implicit && !(*event).data.scalar.quoted_implicit {
860 return yaml_emitter_set_emitter_error(
861 emitter,
862 b"neither tag nor implicit flags are specified\0" as *const u8 as *const libc::c_char,
863 );
864 }
865 if style == YAML_ANY_SCALAR_STYLE {
866 style = YAML_PLAIN_SCALAR_STYLE;
867 }
868 if (*emitter).canonical {
869 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE;
870 }
871 if (*emitter).simple_key_context && (*emitter).scalar_data.multiline {
872 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE;
873 }
874 if style == YAML_PLAIN_SCALAR_STYLE {
875 if (*emitter).flow_level != 0 && !(*emitter).scalar_data.flow_plain_allowed
876 || (*emitter).flow_level == 0 && !(*emitter).scalar_data.block_plain_allowed
877 {
878 style = YAML_SINGLE_QUOTED_SCALAR_STYLE;
879 }
880 if (*emitter).scalar_data.length == 0 && ((*emitter).flow_level != 0 || (*emitter).simple_key_context) {
881 style = YAML_SINGLE_QUOTED_SCALAR_STYLE;
882 }
883 if no_tag && !(*event).data.scalar.plain_implicit {
884 style = YAML_SINGLE_QUOTED_SCALAR_STYLE;
885 }
886 }
887 if style == YAML_SINGLE_QUOTED_SCALAR_STYLE {
888 if !(*emitter).scalar_data.single_quoted_allowed {
889 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE;
890 }
891 }
892 if style == YAML_LITERAL_SCALAR_STYLE || style == YAML_FOLDED_SCALAR_STYLE {
893 if !(*emitter).scalar_data.block_allowed || (*emitter).flow_level != 0 || (*emitter).simple_key_context {
894 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE;
895 }
896 }
897 if no_tag && !(*event).data.scalar.quoted_implicit && style != YAML_PLAIN_SCALAR_STYLE {
898 let fresh46 = addr_of_mut!((*emitter).tag_data.handle);
899 *fresh46 = b"!\0" as *const u8 as *const libc::c_char as *mut yaml_char_t;
900 (*emitter).tag_data.handle_length = 1_u64;
901 }
902 (*emitter).scalar_data.style = style;
903 OK
904}
905
906unsafe fn yaml_emitter_process_anchor(emitter: *mut yaml_emitter_t) -> Success {
907 if (*emitter).anchor_data.anchor.is_null() {
908 return OK;
909 }
910 if yaml_emitter_write_indicator(
911 emitter,
912 if (*emitter).anchor_data.alias {
913 b"*\0" as *const u8 as *const libc::c_char
914 } else {
915 b"&\0" as *const u8 as *const libc::c_char
916 },
917 true,
918 false,
919 false,
920 )
921 .fail
922 {
923 return FAIL;
924 }
925 yaml_emitter_write_anchor(emitter, (*emitter).anchor_data.anchor, (*emitter).anchor_data.anchor_length)
926}
927
928unsafe fn yaml_emitter_process_tag(emitter: *mut yaml_emitter_t) -> Success {
929 if (*emitter).tag_data.handle.is_null() && (*emitter).tag_data.suffix.is_null() {
930 return OK;
931 }
932 if !(*emitter).tag_data.handle.is_null() {
933 if yaml_emitter_write_tag_handle(emitter, (*emitter).tag_data.handle, (*emitter).tag_data.handle_length).fail {
934 return FAIL;
935 }
936 if !(*emitter).tag_data.suffix.is_null() {
937 if yaml_emitter_write_tag_content(
938 emitter,
939 (*emitter).tag_data.suffix,
940 (*emitter).tag_data.suffix_length,
941 false,
942 )
943 .fail
944 {
945 return FAIL;
946 }
947 }
948 } else {
949 if yaml_emitter_write_indicator(emitter, b"!<\0" as *const u8 as *const libc::c_char, true, false, false).fail {
950 return FAIL;
951 }
952 if yaml_emitter_write_tag_content(emitter, (*emitter).tag_data.suffix, (*emitter).tag_data.suffix_length, false)
953 .fail
954 {
955 return FAIL;
956 }
957 if yaml_emitter_write_indicator(emitter, b">\0" as *const u8 as *const libc::c_char, false, false, false).fail {
958 return FAIL;
959 }
960 }
961 OK
962}
963
964unsafe fn yaml_emitter_process_scalar(emitter: *mut yaml_emitter_t) -> Success {
965 match (*emitter).scalar_data.style {
966 YAML_PLAIN_SCALAR_STYLE => {
967 return yaml_emitter_write_plain_scalar(
968 emitter,
969 (*emitter).scalar_data.value,
970 (*emitter).scalar_data.length,
971 !(*emitter).simple_key_context,
972 );
973 }
974 YAML_SINGLE_QUOTED_SCALAR_STYLE => {
975 return yaml_emitter_write_single_quoted_scalar(
976 emitter,
977 (*emitter).scalar_data.value,
978 (*emitter).scalar_data.length,
979 !(*emitter).simple_key_context,
980 );
981 }
982 YAML_DOUBLE_QUOTED_SCALAR_STYLE => {
983 return yaml_emitter_write_double_quoted_scalar(
984 emitter,
985 (*emitter).scalar_data.value,
986 (*emitter).scalar_data.length,
987 !(*emitter).simple_key_context,
988 );
989 }
990 YAML_LITERAL_SCALAR_STYLE => {
991 return yaml_emitter_write_literal_scalar(
992 emitter,
993 (*emitter).scalar_data.value,
994 (*emitter).scalar_data.length,
995 );
996 }
997 YAML_FOLDED_SCALAR_STYLE => {
998 return yaml_emitter_write_folded_scalar(
999 emitter,
1000 (*emitter).scalar_data.value,
1001 (*emitter).scalar_data.length,
1002 );
1003 }
1004 _ => {}
1005 }
1006 FAIL
1007}
1008
1009unsafe fn yaml_emitter_analyze_version_directive(
1010 emitter: *mut yaml_emitter_t,
1011 version_directive: yaml_version_directive_t,
1012) -> Success {
1013 if version_directive.major != 1 || version_directive.minor != 1 && version_directive.minor != 2 {
1014 return yaml_emitter_set_emitter_error(
1015 emitter,
1016 b"incompatible %YAML directive\0" as *const u8 as *const libc::c_char,
1017 );
1018 }
1019 OK
1020}
1021
1022unsafe fn yaml_emitter_analyze_tag_directive(
1023 emitter: *mut yaml_emitter_t,
1024 tag_directive: yaml_tag_directive_t,
1025) -> Success {
1026 let handle_length: size_t = strlen(tag_directive.handle as *mut libc::c_char);
1027 let prefix_length: size_t = strlen(tag_directive.prefix as *mut libc::c_char);
1028 let mut handle = STRING_ASSIGN!(tag_directive.handle, handle_length);
1029 let prefix = STRING_ASSIGN!(tag_directive.prefix, prefix_length);
1030 if handle.start == handle.end {
1031 return yaml_emitter_set_emitter_error(
1032 emitter,
1033 b"tag handle must not be empty\0" as *const u8 as *const libc::c_char,
1034 );
1035 }
1036 if *handle.start != b'!' {
1037 return yaml_emitter_set_emitter_error(
1038 emitter,
1039 b"tag handle must start with '!'\0" as *const u8 as *const libc::c_char,
1040 );
1041 }
1042 if *handle.end.wrapping_offset(-1_isize) != b'!' {
1043 return yaml_emitter_set_emitter_error(
1044 emitter,
1045 b"tag handle must end with '!'\0" as *const u8 as *const libc::c_char,
1046 );
1047 }
1048 handle.pointer = handle.pointer.wrapping_offset(1);
1049 while handle.pointer < handle.end.wrapping_offset(-1_isize) {
1050 if !IS_ALPHA!(handle) {
1051 return yaml_emitter_set_emitter_error(
1052 emitter,
1053 b"tag handle must contain alphanumerical characters only\0" as *const u8 as *const libc::c_char,
1054 );
1055 }
1056 MOVE!(handle);
1057 }
1058 if prefix.start == prefix.end {
1059 return yaml_emitter_set_emitter_error(
1060 emitter,
1061 b"tag prefix must not be empty\0" as *const u8 as *const libc::c_char,
1062 );
1063 }
1064 OK
1065}
1066
1067unsafe fn yaml_emitter_analyze_anchor(emitter: *mut yaml_emitter_t, anchor: *mut yaml_char_t, alias: bool) -> Success {
1068 let anchor_length: size_t = strlen(anchor as *mut libc::c_char);
1069 let mut string = STRING_ASSIGN!(anchor, anchor_length);
1070 if string.start == string.end {
1071 return yaml_emitter_set_emitter_error(
1072 emitter,
1073 if alias {
1074 b"alias value must not be empty\0" as *const u8 as *const libc::c_char
1075 } else {
1076 b"anchor value must not be empty\0" as *const u8 as *const libc::c_char
1077 },
1078 );
1079 }
1080 while string.pointer != string.end {
1081 if !IS_ALPHA!(string) {
1082 return yaml_emitter_set_emitter_error(
1083 emitter,
1084 if alias {
1085 b"alias value must contain alphanumerical characters only\0" as *const u8 as *const libc::c_char
1086 } else {
1087 b"anchor value must contain alphanumerical characters only\0" as *const u8 as *const libc::c_char
1088 },
1089 );
1090 }
1091 MOVE!(string);
1092 }
1093 let fresh47 = addr_of_mut!((*emitter).anchor_data.anchor);
1094 *fresh47 = string.start;
1095 (*emitter).anchor_data.anchor_length = string.end.c_offset_from(string.start) as size_t;
1096 (*emitter).anchor_data.alias = alias;
1097 OK
1098}
1099
1100unsafe fn yaml_emitter_analyze_tag(emitter: *mut yaml_emitter_t, tag: *mut yaml_char_t) -> Success {
1101 let mut tag_directive: *mut yaml_tag_directive_t;
1102 let tag_length: size_t = strlen(tag as *mut libc::c_char);
1103 let string = STRING_ASSIGN!(tag, tag_length);
1104 if string.start == string.end {
1105 return yaml_emitter_set_emitter_error(
1106 emitter,
1107 b"tag value must not be empty\0" as *const u8 as *const libc::c_char,
1108 );
1109 }
1110 tag_directive = (*emitter).tag_directives.start;
1111 while tag_directive != (*emitter).tag_directives.top {
1112 let prefix_length: size_t = strlen((*tag_directive).prefix as *mut libc::c_char);
1113 if prefix_length < string.end.c_offset_from(string.start) as size_t
1114 && strncmp(
1115 (*tag_directive).prefix as *mut libc::c_char,
1116 string.start as *mut libc::c_char,
1117 prefix_length,
1118 ) == 0
1119 {
1120 let fresh48 = addr_of_mut!((*emitter).tag_data.handle);
1121 *fresh48 = (*tag_directive).handle;
1122 (*emitter).tag_data.handle_length = strlen((*tag_directive).handle as *mut libc::c_char);
1123 let fresh49 = addr_of_mut!((*emitter).tag_data.suffix);
1124 *fresh49 = string.start.wrapping_offset(prefix_length as isize);
1125 (*emitter).tag_data.suffix_length =
1126 (string.end.c_offset_from(string.start) as libc::c_ulong).wrapping_sub(prefix_length);
1127 return OK;
1128 }
1129 tag_directive = tag_directive.wrapping_offset(1);
1130 }
1131 let fresh50 = addr_of_mut!((*emitter).tag_data.suffix);
1132 *fresh50 = string.start;
1133 (*emitter).tag_data.suffix_length = string.end.c_offset_from(string.start) as size_t;
1134 OK
1135}
1136
1137unsafe fn yaml_emitter_analyze_scalar(
1138 emitter: *mut yaml_emitter_t,
1139 value: *mut yaml_char_t,
1140 length: size_t,
1141) -> Success {
1142 let mut block_indicators = false;
1143 let mut flow_indicators = false;
1144 let mut line_breaks = false;
1145 let mut special_characters = false;
1146 let mut leading_space = false;
1147 let mut leading_break = false;
1148 let mut trailing_space = false;
1149 let mut trailing_break = false;
1150 let mut break_space = false;
1151 let mut space_break = false;
1152 let mut preceded_by_whitespace;
1153 let mut followed_by_whitespace;
1154 let mut previous_space = false;
1155 let mut previous_break = false;
1156 let mut string = STRING_ASSIGN!(value, length);
1157 let fresh51 = addr_of_mut!((*emitter).scalar_data.value);
1158 *fresh51 = value;
1159 (*emitter).scalar_data.length = length;
1160 if string.start == string.end {
1161 (*emitter).scalar_data.multiline = false;
1162 (*emitter).scalar_data.flow_plain_allowed = false;
1163 (*emitter).scalar_data.block_plain_allowed = true;
1164 (*emitter).scalar_data.single_quoted_allowed = true;
1165 (*emitter).scalar_data.block_allowed = false;
1166 return OK;
1167 }
1168 if CHECK_AT!(string, b'-', 0) && CHECK_AT!(string, b'-', 1) && CHECK_AT!(string, b'-', 2)
1169 || CHECK_AT!(string, b'.', 0) && CHECK_AT!(string, b'.', 1) && CHECK_AT!(string, b'.', 2)
1170 {
1171 block_indicators = true;
1172 flow_indicators = true;
1173 }
1174 preceded_by_whitespace = true;
1175 followed_by_whitespace = IS_BLANKZ_AT!(string, WIDTH!(string));
1176 while string.pointer != string.end {
1177 if string.start == string.pointer {
1178 if CHECK!(string, b'#')
1179 || CHECK!(string, b',')
1180 || CHECK!(string, b'[')
1181 || CHECK!(string, b']')
1182 || CHECK!(string, b'{')
1183 || CHECK!(string, b'}')
1184 || CHECK!(string, b'&')
1185 || CHECK!(string, b'*')
1186 || CHECK!(string, b'!')
1187 || CHECK!(string, b'|')
1188 || CHECK!(string, b'>')
1189 || CHECK!(string, b'\'')
1190 || CHECK!(string, b'"')
1191 || CHECK!(string, b'%')
1192 || CHECK!(string, b'@')
1193 || CHECK!(string, b'`')
1194 {
1195 flow_indicators = true;
1196 block_indicators = true;
1197 }
1198 if CHECK!(string, b'?') || CHECK!(string, b':') {
1199 flow_indicators = true;
1200 if followed_by_whitespace {
1201 block_indicators = true;
1202 }
1203 }
1204 if CHECK!(string, b'-') && followed_by_whitespace {
1205 flow_indicators = true;
1206 block_indicators = true;
1207 }
1208 } else {
1209 if CHECK!(string, b',')
1210 || CHECK!(string, b'?')
1211 || CHECK!(string, b'[')
1212 || CHECK!(string, b']')
1213 || CHECK!(string, b'{')
1214 || CHECK!(string, b'}')
1215 {
1216 flow_indicators = true;
1217 }
1218 if CHECK!(string, b':') {
1219 flow_indicators = true;
1220 if followed_by_whitespace {
1221 block_indicators = true;
1222 }
1223 }
1224 if CHECK!(string, b'#') && preceded_by_whitespace {
1225 flow_indicators = true;
1226 block_indicators = true;
1227 }
1228 }
1229 if !IS_PRINTABLE!(string) || !IS_ASCII!(string) && !(*emitter).unicode {
1230 special_characters = true;
1231 }
1232 if IS_BREAK!(string) {
1233 line_breaks = true;
1234 }
1235 if IS_SPACE!(string) {
1236 if string.start == string.pointer {
1237 leading_space = true;
1238 }
1239 if string.pointer.wrapping_offset(WIDTH!(string) as isize) == string.end {
1240 trailing_space = true;
1241 }
1242 if previous_break {
1243 break_space = true;
1244 }
1245 previous_space = true;
1246 previous_break = false;
1247 } else if IS_BREAK!(string) {
1248 if string.start == string.pointer {
1249 leading_break = true;
1250 }
1251 if string.pointer.wrapping_offset(WIDTH!(string) as isize) == string.end {
1252 trailing_break = true;
1253 }
1254 if previous_space {
1255 space_break = true;
1256 }
1257 previous_space = false;
1258 previous_break = true;
1259 } else {
1260 previous_space = false;
1261 previous_break = false;
1262 }
1263 preceded_by_whitespace = IS_BLANKZ!(string);
1264 MOVE!(string);
1265 if string.pointer != string.end {
1266 followed_by_whitespace = IS_BLANKZ_AT!(string, WIDTH!(string));
1267 }
1268 }
1269 (*emitter).scalar_data.multiline = line_breaks;
1270 (*emitter).scalar_data.flow_plain_allowed = true;
1271 (*emitter).scalar_data.block_plain_allowed = true;
1272 (*emitter).scalar_data.single_quoted_allowed = true;
1273 (*emitter).scalar_data.block_allowed = true;
1274 if leading_space || leading_break || trailing_space || trailing_break {
1275 (*emitter).scalar_data.flow_plain_allowed = false;
1276 (*emitter).scalar_data.block_plain_allowed = false;
1277 }
1278 if trailing_space {
1279 (*emitter).scalar_data.block_allowed = false;
1280 }
1281 if break_space {
1282 (*emitter).scalar_data.flow_plain_allowed = false;
1283 (*emitter).scalar_data.block_plain_allowed = false;
1284 (*emitter).scalar_data.single_quoted_allowed = false;
1285 }
1286 if space_break || special_characters {
1287 (*emitter).scalar_data.flow_plain_allowed = false;
1288 (*emitter).scalar_data.block_plain_allowed = false;
1289 (*emitter).scalar_data.single_quoted_allowed = false;
1290 (*emitter).scalar_data.block_allowed = false;
1291 }
1292 if line_breaks {
1293 (*emitter).scalar_data.flow_plain_allowed = false;
1294 (*emitter).scalar_data.block_plain_allowed = false;
1295 }
1296 if flow_indicators {
1297 (*emitter).scalar_data.flow_plain_allowed = false;
1298 }
1299 if block_indicators {
1300 (*emitter).scalar_data.block_plain_allowed = false;
1301 }
1302 OK
1303}
1304
1305unsafe fn yaml_emitter_analyze_event(emitter: *mut yaml_emitter_t, event: *mut yaml_event_t) -> Success {
1306 let fresh52 = addr_of_mut!((*emitter).anchor_data.anchor);
1307 *fresh52 = ptr::null_mut::<yaml_char_t>();
1308 (*emitter).anchor_data.anchor_length = 0_u64;
1309 let fresh53 = addr_of_mut!((*emitter).tag_data.handle);
1310 *fresh53 = ptr::null_mut::<yaml_char_t>();
1311 (*emitter).tag_data.handle_length = 0_u64;
1312 let fresh54 = addr_of_mut!((*emitter).tag_data.suffix);
1313 *fresh54 = ptr::null_mut::<yaml_char_t>();
1314 (*emitter).tag_data.suffix_length = 0_u64;
1315 let fresh55 = addr_of_mut!((*emitter).scalar_data.value);
1316 *fresh55 = ptr::null_mut::<yaml_char_t>();
1317 (*emitter).scalar_data.length = 0_u64;
1318 match (*event).type_ {
1319 YAML_ALIAS_EVENT => yaml_emitter_analyze_anchor(emitter, (*event).data.alias.anchor, true),
1320 YAML_SCALAR_EVENT => {
1321 if !(*event).data.scalar.anchor.is_null() {
1322 if yaml_emitter_analyze_anchor(emitter, (*event).data.scalar.anchor, false).fail {
1323 return FAIL;
1324 }
1325 }
1326 if !(*event).data.scalar.tag.is_null()
1327 && ((*emitter).canonical
1328 || !(*event).data.scalar.plain_implicit && !(*event).data.scalar.quoted_implicit)
1329 {
1330 if yaml_emitter_analyze_tag(emitter, (*event).data.scalar.tag).fail {
1331 return FAIL;
1332 }
1333 }
1334 yaml_emitter_analyze_scalar(emitter, (*event).data.scalar.value, (*event).data.scalar.length)
1335 }
1336 YAML_SEQUENCE_START_EVENT => {
1337 if !(*event).data.sequence_start.anchor.is_null() {
1338 if yaml_emitter_analyze_anchor(emitter, (*event).data.sequence_start.anchor, false).fail {
1339 return FAIL;
1340 }
1341 }
1342 if !(*event).data.sequence_start.tag.is_null()
1343 && ((*emitter).canonical || !(*event).data.sequence_start.implicit)
1344 {
1345 if yaml_emitter_analyze_tag(emitter, (*event).data.sequence_start.tag).fail {
1346 return FAIL;
1347 }
1348 }
1349 OK
1350 }
1351 YAML_MAPPING_START_EVENT => {
1352 if !(*event).data.mapping_start.anchor.is_null() {
1353 if yaml_emitter_analyze_anchor(emitter, (*event).data.mapping_start.anchor, false).fail {
1354 return FAIL;
1355 }
1356 }
1357 if !(*event).data.mapping_start.tag.is_null()
1358 && ((*emitter).canonical || !(*event).data.mapping_start.implicit)
1359 {
1360 if yaml_emitter_analyze_tag(emitter, (*event).data.mapping_start.tag).fail {
1361 return FAIL;
1362 }
1363 }
1364 OK
1365 }
1366 _ => OK,
1367 }
1368}
1369
1370unsafe fn yaml_emitter_write_bom(emitter: *mut yaml_emitter_t) -> Success {
1371 if FLUSH(emitter).fail {
1372 return FAIL;
1373 }
1374 let fresh56 = addr_of_mut!((*emitter).buffer.pointer);
1375 let fresh57 = *fresh56;
1376 *fresh56 = (*fresh56).wrapping_offset(1);
1377 *fresh57 = b'\xEF';
1378 let fresh58 = addr_of_mut!((*emitter).buffer.pointer);
1379 let fresh59 = *fresh58;
1380 *fresh58 = (*fresh58).wrapping_offset(1);
1381 *fresh59 = b'\xBB';
1382 let fresh60 = addr_of_mut!((*emitter).buffer.pointer);
1383 let fresh61 = *fresh60;
1384 *fresh60 = (*fresh60).wrapping_offset(1);
1385 *fresh61 = b'\xBF';
1386 OK
1387}
1388
1389unsafe fn yaml_emitter_write_indent(emitter: *mut yaml_emitter_t) -> Success {
1390 let indent: libc::c_int = if (*emitter).indent >= 0 { (*emitter).indent } else { 0 };
1391 if !(*emitter).indention || (*emitter).column > indent || (*emitter).column == indent && !(*emitter).whitespace {
1392 if PUT_BREAK(emitter).fail {
1393 return FAIL;
1394 }
1395 }
1396 while (*emitter).column < indent {
1397 if PUT(emitter, b' ').fail {
1398 return FAIL;
1399 }
1400 }
1401 (*emitter).whitespace = true;
1402 (*emitter).indention = true;
1403 OK
1404}
1405
1406unsafe fn yaml_emitter_write_indicator(
1407 emitter: *mut yaml_emitter_t,
1408 indicator: *const libc::c_char,
1409 need_whitespace: bool,
1410 is_whitespace: bool,
1411 is_indention: bool,
1412) -> Success {
1413 let indicator_length: size_t = strlen(indicator);
1414 let mut string = STRING_ASSIGN!(indicator as *mut yaml_char_t, indicator_length);
1415 if need_whitespace && !(*emitter).whitespace {
1416 if PUT(emitter, b' ').fail {
1417 return FAIL;
1418 }
1419 }
1420 while string.pointer != string.end {
1421 if WRITE!(emitter, string).fail {
1422 return FAIL;
1423 }
1424 }
1425 (*emitter).whitespace = is_whitespace;
1426 (*emitter).indention = (*emitter).indention && is_indention;
1427 OK
1428}
1429
1430unsafe fn yaml_emitter_write_anchor(emitter: *mut yaml_emitter_t, value: *mut yaml_char_t, length: size_t) -> Success {
1431 let mut string = STRING_ASSIGN!(value, length);
1432 while string.pointer != string.end {
1433 if WRITE!(emitter, string).fail {
1434 return FAIL;
1435 }
1436 }
1437 (*emitter).whitespace = false;
1438 (*emitter).indention = false;
1439 OK
1440}
1441
1442unsafe fn yaml_emitter_write_tag_handle(
1443 emitter: *mut yaml_emitter_t,
1444 value: *mut yaml_char_t,
1445 length: size_t,
1446) -> Success {
1447 let mut string = STRING_ASSIGN!(value, length);
1448 if !(*emitter).whitespace {
1449 if PUT(emitter, b' ').fail {
1450 return FAIL;
1451 }
1452 }
1453 while string.pointer != string.end {
1454 if WRITE!(emitter, string).fail {
1455 return FAIL;
1456 }
1457 }
1458 (*emitter).whitespace = false;
1459 (*emitter).indention = false;
1460 OK
1461}
1462
1463unsafe fn yaml_emitter_write_tag_content(
1464 emitter: *mut yaml_emitter_t,
1465 value: *mut yaml_char_t,
1466 length: size_t,
1467 need_whitespace: bool,
1468) -> Success {
1469 let mut string = STRING_ASSIGN!(value, length);
1470 if need_whitespace && !(*emitter).whitespace {
1471 if PUT(emitter, b' ').fail {
1472 return FAIL;
1473 }
1474 }
1475 while string.pointer != string.end {
1476 if IS_ALPHA!(string)
1477 || CHECK!(string, b';')
1478 || CHECK!(string, b'/')
1479 || CHECK!(string, b'?')
1480 || CHECK!(string, b':')
1481 || CHECK!(string, b'@')
1482 || CHECK!(string, b'&')
1483 || CHECK!(string, b'=')
1484 || CHECK!(string, b'+')
1485 || CHECK!(string, b'$')
1486 || CHECK!(string, b',')
1487 || CHECK!(string, b'_')
1488 || CHECK!(string, b'.')
1489 || CHECK!(string, b'~')
1490 || CHECK!(string, b'*')
1491 || CHECK!(string, b'\'')
1492 || CHECK!(string, b'(')
1493 || CHECK!(string, b')')
1494 || CHECK!(string, b'[')
1495 || CHECK!(string, b']')
1496 {
1497 if WRITE!(emitter, string).fail {
1498 return FAIL;
1499 }
1500 } else {
1501 let mut width = WIDTH!(string);
1502 loop {
1503 let fresh207 = width;
1504 width -= 1;
1505 if !(fresh207 != 0) {
1506 break;
1507 }
1508 let fresh208 = string.pointer;
1509 string.pointer = string.pointer.wrapping_offset(1);
1510 let value = *fresh208;
1511 if PUT(emitter, b'%').fail {
1512 return FAIL;
1513 }
1514 if PUT(
1515 emitter,
1516 (value >> 4).force_add(if (value >> 4) < 10 { b'0' } else { b'A' - 10 }),
1517 )
1518 .fail
1519 {
1520 return FAIL;
1521 }
1522 if PUT(
1523 emitter,
1524 (value & 0x0F).force_add(if (value & 0x0F) < 10 { b'0' } else { b'A' - 10 }),
1525 )
1526 .fail
1527 {
1528 return FAIL;
1529 }
1530 }
1531 }
1532 }
1533 (*emitter).whitespace = false;
1534 (*emitter).indention = false;
1535 OK
1536}
1537
1538unsafe fn yaml_emitter_write_plain_scalar(
1539 emitter: *mut yaml_emitter_t,
1540 value: *mut yaml_char_t,
1541 length: size_t,
1542 allow_breaks: bool,
1543) -> Success {
1544 let mut spaces = false;
1545 let mut breaks = false;
1546 let mut string = STRING_ASSIGN!(value, length);
1547 if !(*emitter).whitespace && (length != 0 || (*emitter).flow_level != 0) {
1548 if PUT(emitter, b' ').fail {
1549 return FAIL;
1550 }
1551 }
1552 while string.pointer != string.end {
1553 if IS_SPACE!(string) {
1554 if allow_breaks && !spaces && (*emitter).column > (*emitter).best_width && !IS_SPACE_AT!(string, 1) {
1555 if yaml_emitter_write_indent(emitter).fail {
1556 return FAIL;
1557 }
1558 MOVE!(string);
1559 } else if WRITE!(emitter, string).fail {
1560 return FAIL;
1561 }
1562 spaces = true;
1563 } else if IS_BREAK!(string) {
1564 if !breaks && CHECK!(string, b'\n') {
1565 if PUT_BREAK(emitter).fail {
1566 return FAIL;
1567 }
1568 }
1569 if WRITE_BREAK!(emitter, string).fail {
1570 return FAIL;
1571 }
1572 (*emitter).indention = true;
1573 breaks = true;
1574 } else {
1575 if breaks {
1576 if yaml_emitter_write_indent(emitter).fail {
1577 return FAIL;
1578 }
1579 }
1580 if WRITE!(emitter, string).fail {
1581 return FAIL;
1582 }
1583 (*emitter).indention = false;
1584 spaces = false;
1585 breaks = false;
1586 }
1587 }
1588 (*emitter).whitespace = false;
1589 (*emitter).indention = false;
1590 OK
1591}
1592
1593unsafe fn yaml_emitter_write_single_quoted_scalar(
1594 emitter: *mut yaml_emitter_t,
1595 value: *mut yaml_char_t,
1596 length: size_t,
1597 allow_breaks: bool,
1598) -> Success {
1599 let mut spaces = false;
1600 let mut breaks = false;
1601 let mut string = STRING_ASSIGN!(value, length);
1602 if yaml_emitter_write_indicator(emitter, b"'\0" as *const u8 as *const libc::c_char, true, false, false).fail {
1603 return FAIL;
1604 }
1605 while string.pointer != string.end {
1606 if IS_SPACE!(string) {
1607 if allow_breaks
1608 && !spaces
1609 && (*emitter).column > (*emitter).best_width
1610 && string.pointer != string.start
1611 && string.pointer != string.end.wrapping_offset(-1_isize)
1612 && !IS_SPACE_AT!(string, 1)
1613 {
1614 if yaml_emitter_write_indent(emitter).fail {
1615 return FAIL;
1616 }
1617 MOVE!(string);
1618 } else if WRITE!(emitter, string).fail {
1619 return FAIL;
1620 }
1621 spaces = true;
1622 } else if IS_BREAK!(string) {
1623 if !breaks && CHECK!(string, b'\n') {
1624 if PUT_BREAK(emitter).fail {
1625 return FAIL;
1626 }
1627 }
1628 if WRITE_BREAK!(emitter, string).fail {
1629 return FAIL;
1630 }
1631 (*emitter).indention = true;
1632 breaks = true;
1633 } else {
1634 if breaks {
1635 if yaml_emitter_write_indent(emitter).fail {
1636 return FAIL;
1637 }
1638 }
1639 if CHECK!(string, b'\'') {
1640 if PUT(emitter, b'\'').fail {
1641 return FAIL;
1642 }
1643 }
1644 if WRITE!(emitter, string).fail {
1645 return FAIL;
1646 }
1647 (*emitter).indention = false;
1648 spaces = false;
1649 breaks = false;
1650 }
1651 }
1652 if breaks {
1653 if yaml_emitter_write_indent(emitter).fail {
1654 return FAIL;
1655 }
1656 }
1657 if yaml_emitter_write_indicator(emitter, b"'\0" as *const u8 as *const libc::c_char, false, false, false).fail {
1658 return FAIL;
1659 }
1660 (*emitter).whitespace = false;
1661 (*emitter).indention = false;
1662 OK
1663}
1664
1665unsafe fn yaml_emitter_write_double_quoted_scalar(
1666 emitter: *mut yaml_emitter_t,
1667 value: *mut yaml_char_t,
1668 length: size_t,
1669 allow_breaks: bool,
1670) -> Success {
1671 let mut spaces = false;
1672 let mut string = STRING_ASSIGN!(value, length);
1673 if yaml_emitter_write_indicator(emitter, b"\"\0" as *const u8 as *const libc::c_char, true, false, false).fail {
1674 return FAIL;
1675 }
1676 while string.pointer != string.end {
1677 if !IS_PRINTABLE!(string)
1678 || !(*emitter).unicode && !IS_ASCII!(string)
1679 || IS_BOM!(string)
1680 || IS_BREAK!(string)
1681 || CHECK!(string, b'"')
1682 || CHECK!(string, b'\\')
1683 {
1684 let mut octet: libc::c_uchar;
1685 let mut width: libc::c_uint;
1686 let mut value_0: libc::c_uint;
1687 let mut k: libc::c_int;
1688 octet = *string.pointer;
1689 width = if octet & 0x80 == 0x00 {
1690 1
1691 } else if octet & 0xE0 == 0xC0 {
1692 2
1693 } else if octet & 0xF0 == 0xE0 {
1694 3
1695 } else if octet & 0xF8 == 0xF0 {
1696 4
1697 } else {
1698 0
1699 };
1700 value_0 = if octet & 0x80 == 0 {
1701 octet & 0x7F
1702 } else if octet & 0xE0 == 0xC0 {
1703 octet & 0x1F
1704 } else if octet & 0xF0 == 0xE0 {
1705 octet & 0x0F
1706 } else if octet & 0xF8 == 0xF0 {
1707 octet & 0x07
1708 } else {
1709 0
1710 } as libc::c_uint;
1711 k = 1;
1712 while k < width as libc::c_int {
1713 octet = *string.pointer.wrapping_offset(k as isize);
1714 value_0 = (value_0 << 6).force_add((octet & 0x3F) as libc::c_uint);
1715 k += 1;
1716 }
1717 string.pointer = string.pointer.wrapping_offset(width as isize);
1718 if PUT(emitter, b'\\').fail {
1719 return FAIL;
1720 }
1721 match value_0 {
1722 0x00 => {
1723 if PUT(emitter, b'0').fail {
1724 return FAIL;
1725 }
1726 }
1727 0x07 => {
1728 if PUT(emitter, b'a').fail {
1729 return FAIL;
1730 }
1731 }
1732 0x08 => {
1733 if PUT(emitter, b'b').fail {
1734 return FAIL;
1735 }
1736 }
1737 0x09 => {
1738 if PUT(emitter, b't').fail {
1739 return FAIL;
1740 }
1741 }
1742 0x0A => {
1743 if PUT(emitter, b'n').fail {
1744 return FAIL;
1745 }
1746 }
1747 0x0B => {
1748 if PUT(emitter, b'v').fail {
1749 return FAIL;
1750 }
1751 }
1752 0x0C => {
1753 if PUT(emitter, b'f').fail {
1754 return FAIL;
1755 }
1756 }
1757 0x0D => {
1758 if PUT(emitter, b'r').fail {
1759 return FAIL;
1760 }
1761 }
1762 0x1B => {
1763 if PUT(emitter, b'e').fail {
1764 return FAIL;
1765 }
1766 }
1767 0x22 => {
1768 if PUT(emitter, b'"').fail {
1769 return FAIL;
1770 }
1771 }
1772 0x5C => {
1773 if PUT(emitter, b'\\').fail {
1774 return FAIL;
1775 }
1776 }
1777 0x85 => {
1778 if PUT(emitter, b'N').fail {
1779 return FAIL;
1780 }
1781 }
1782 0xA0 => {
1783 if PUT(emitter, b'_').fail {
1784 return FAIL;
1785 }
1786 }
1787 0x2028 => {
1788 if PUT(emitter, b'L').fail {
1789 return FAIL;
1790 }
1791 }
1792 0x2029 => {
1793 if PUT(emitter, b'P').fail {
1794 return FAIL;
1795 }
1796 }
1797 _ => {
1798 if value_0 <= 0xFF {
1799 if PUT(emitter, b'x').fail {
1800 return FAIL;
1801 }
1802 width = 2;
1803 } else if value_0 <= 0xFFFF {
1804 if PUT(emitter, b'u').fail {
1805 return FAIL;
1806 }
1807 width = 4;
1808 } else {
1809 if PUT(emitter, b'U').fail {
1810 return FAIL;
1811 }
1812 width = 8;
1813 }
1814 k = width.wrapping_sub(1).wrapping_mul(4) as libc::c_int;
1815 while k >= 0 {
1816 let digit: libc::c_int = (value_0 >> k & 0x0F) as libc::c_int;
1817 if PUT(emitter, (digit + if digit < 10 { b'0' } else { b'A' - 10 } as i32) as u8).fail {
1818 return FAIL;
1819 }
1820 k -= 4;
1821 }
1822 }
1823 }
1824 spaces = false;
1825 } else if IS_SPACE!(string) {
1826 if allow_breaks
1827 && !spaces
1828 && (*emitter).column > (*emitter).best_width
1829 && string.pointer != string.start
1830 && string.pointer != string.end.wrapping_offset(-1_isize)
1831 {
1832 if yaml_emitter_write_indent(emitter).fail {
1833 return FAIL;
1834 }
1835 if IS_SPACE_AT!(string, 1) {
1836 if PUT(emitter, b'\\').fail {
1837 return FAIL;
1838 }
1839 }
1840 MOVE!(string);
1841 } else if WRITE!(emitter, string).fail {
1842 return FAIL;
1843 }
1844 spaces = true;
1845 } else {
1846 if WRITE!(emitter, string).fail {
1847 return FAIL;
1848 }
1849 spaces = false;
1850 }
1851 }
1852 if yaml_emitter_write_indicator(emitter, b"\"\0" as *const u8 as *const libc::c_char, false, false, false).fail {
1853 return FAIL;
1854 }
1855 (*emitter).whitespace = false;
1856 (*emitter).indention = false;
1857 OK
1858}
1859
1860unsafe fn yaml_emitter_write_block_scalar_hints(emitter: *mut yaml_emitter_t, mut string: yaml_string_t) -> Success {
1861 let mut indent_hint: [libc::c_char; 2] = [0; 2];
1862 let mut chomp_hint: *const libc::c_char = ptr::null::<libc::c_char>();
1863 if IS_SPACE!(string) || IS_BREAK!(string) {
1864 indent_hint[0] = (b'0' as libc::c_int + (*emitter).best_indent) as libc::c_char;
1865 indent_hint[1] = '\0' as libc::c_char;
1866 if yaml_emitter_write_indicator(emitter, indent_hint.as_mut_ptr(), false, false, false).fail {
1867 return FAIL;
1868 }
1869 }
1870 (*emitter).open_ended = 0;
1871 string.pointer = string.end;
1872 if string.start == string.pointer {
1873 chomp_hint = b"-\0" as *const u8 as *const libc::c_char;
1874 } else {
1875 loop {
1876 string.pointer = string.pointer.wrapping_offset(-1);
1877 if !(*string.pointer & 0xC0 == 0x80) {
1878 break;
1879 }
1880 }
1881 if !IS_BREAK!(string) {
1882 chomp_hint = b"-\0" as *const u8 as *const libc::c_char;
1883 } else if string.start == string.pointer {
1884 chomp_hint = b"+\0" as *const u8 as *const libc::c_char;
1885 (*emitter).open_ended = 2;
1886 } else {
1887 loop {
1888 string.pointer = string.pointer.wrapping_offset(-1);
1889 if !(*string.pointer & 0xC0 == 0x80) {
1890 break;
1891 }
1892 }
1893 if IS_BREAK!(string) {
1894 chomp_hint = b"+\0" as *const u8 as *const libc::c_char;
1895 (*emitter).open_ended = 2;
1896 }
1897 }
1898 }
1899 if !chomp_hint.is_null() {
1900 if yaml_emitter_write_indicator(emitter, chomp_hint, false, false, false).fail {
1901 return FAIL;
1902 }
1903 }
1904 OK
1905}
1906
1907unsafe fn yaml_emitter_write_literal_scalar(
1908 emitter: *mut yaml_emitter_t,
1909 value: *mut yaml_char_t,
1910 length: size_t,
1911) -> Success {
1912 let mut breaks = true;
1913 let mut string = STRING_ASSIGN!(value, length);
1914 if yaml_emitter_write_indicator(emitter, b"|\0" as *const u8 as *const libc::c_char, true, false, false).fail {
1915 return FAIL;
1916 }
1917 if yaml_emitter_write_block_scalar_hints(emitter, string).fail {
1918 return FAIL;
1919 }
1920 if PUT_BREAK(emitter).fail {
1921 return FAIL;
1922 }
1923 (*emitter).indention = true;
1924 (*emitter).whitespace = true;
1925 while string.pointer != string.end {
1926 if IS_BREAK!(string) {
1927 if WRITE_BREAK!(emitter, string).fail {
1928 return FAIL;
1929 }
1930 (*emitter).indention = true;
1931 breaks = true;
1932 } else {
1933 if breaks {
1934 if yaml_emitter_write_indent(emitter).fail {
1935 return FAIL;
1936 }
1937 }
1938 if WRITE!(emitter, string).fail {
1939 return FAIL;
1940 }
1941 (*emitter).indention = false;
1942 breaks = false;
1943 }
1944 }
1945 OK
1946}
1947
1948unsafe fn yaml_emitter_write_folded_scalar(
1949 emitter: *mut yaml_emitter_t,
1950 value: *mut yaml_char_t,
1951 length: size_t,
1952) -> Success {
1953 let mut breaks = true;
1954 let mut leading_spaces = true;
1955 let mut string = STRING_ASSIGN!(value, length);
1956 if yaml_emitter_write_indicator(emitter, b">\0" as *const u8 as *const libc::c_char, true, false, false).fail {
1957 return FAIL;
1958 }
1959 if yaml_emitter_write_block_scalar_hints(emitter, string).fail {
1960 return FAIL;
1961 }
1962 if PUT_BREAK(emitter).fail {
1963 return FAIL;
1964 }
1965 (*emitter).indention = true;
1966 (*emitter).whitespace = true;
1967 while string.pointer != string.end {
1968 if IS_BREAK!(string) {
1969 if !breaks && !leading_spaces && CHECK!(string, b'\n') {
1970 let mut k: libc::c_int = 0;
1971 while IS_BREAK_AT!(string, k as isize) {
1972 k += WIDTH_AT!(string, k as isize);
1973 }
1974 if !IS_BLANKZ_AT!(string, k) {
1975 if PUT_BREAK(emitter).fail {
1976 return FAIL;
1977 }
1978 }
1979 }
1980 if WRITE_BREAK!(emitter, string).fail {
1981 return FAIL;
1982 }
1983 (*emitter).indention = true;
1984 breaks = true;
1985 } else {
1986 if breaks {
1987 if yaml_emitter_write_indent(emitter).fail {
1988 return FAIL;
1989 }
1990 leading_spaces = IS_BLANK!(string);
1991 }
1992 if !breaks && IS_SPACE!(string) && !IS_SPACE_AT!(string, 1) && (*emitter).column > (*emitter).best_width {
1993 if yaml_emitter_write_indent(emitter).fail {
1994 return FAIL;
1995 }
1996 MOVE!(string);
1997 } else if WRITE!(emitter, string).fail {
1998 return FAIL;
1999 }
2000 (*emitter).indention = false;
2001 breaks = false;
2002 }
2003 }
2004 OK
2005}