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