| 1 | pub use type_size::*; |
| 2 | use libc::{c_char, c_uchar, c_int, c_void, size_t}; |
| 3 | use parser::YamlIoParser; |
| 4 | use emitter::YamlEmitter; |
| 5 | |
| 6 | #[allow(non_camel_case_types)] |
| 7 | pub type yaml_char_t = c_uchar; |
| 8 | |
| 9 | #[allow(non_camel_case_types)] |
| 10 | pub type yaml_read_handler_t = extern fn(data: *mut YamlIoParser, buffer: *mut u8, size: size_t, size_read: *mut size_t) -> c_int; |
| 11 | |
| 12 | #[allow(non_camel_case_types)] |
| 13 | pub type yaml_write_handler_t = extern fn(data: *mut YamlEmitter, buffer: *const u8, size: size_t) -> c_int; |
| 14 | |
| 15 | #[repr(C)] |
| 16 | #[allow(non_camel_case_types)] |
| 17 | #[derive(Debug, PartialEq, Clone, Copy)] |
| 18 | pub enum YamlErrorType { |
| 19 | /** No error is produced. */ |
| 20 | YAML_NO_ERROR, |
| 21 | |
| 22 | /** Cannot allocate or reallocate a block of memory. */ |
| 23 | YAML_MEMORY_ERROR, |
| 24 | |
| 25 | /** Cannot read or decode the input stream. */ |
| 26 | YAML_READER_ERROR, |
| 27 | /** Cannot scan the input stream. */ |
| 28 | YAML_SCANNER_ERROR, |
| 29 | /** Cannot parse the input stream. */ |
| 30 | YAML_PARSER_ERROR, |
| 31 | /** Cannot compose a YAML document. */ |
| 32 | YAML_COMPOSER_ERROR, |
| 33 | |
| 34 | /** Cannot write to the output stream. */ |
| 35 | YAML_WRITER_ERROR, |
| 36 | /** Cannot emit a YAML stream. */ |
| 37 | YAML_EMITTER_ERROR |
| 38 | } |
| 39 | |
| 40 | #[derive(Debug, PartialEq, Clone, Copy)] |
| 41 | #[repr(C)] |
| 42 | pub enum YamlSequenceStyle { |
| 43 | /** Let the emitter choose the style. */ |
| 44 | YamlAnySequenceStyle = 0, |
| 45 | |
| 46 | /** The block sequence style. */ |
| 47 | YamlBlockSequenceStyle, |
| 48 | /** The flow sequence style. */ |
| 49 | YamlFlowSequenceStyle |
| 50 | } |
| 51 | |
| 52 | #[derive(Debug, PartialEq, Clone, Copy)] |
| 53 | #[repr(C)] |
| 54 | pub enum YamlScalarStyle { |
| 55 | /** Let the emitter choose the style. */ |
| 56 | YamlAnyScalarStyle = 0, |
| 57 | |
| 58 | /** The plain scalar style. */ |
| 59 | YamlPlainScalarStyle, |
| 60 | |
| 61 | /** The single-quoted scalar style. */ |
| 62 | YamlSingleQuotedScalarStyle, |
| 63 | /** The double-quoted scalar style. */ |
| 64 | YamlDoubleQuotedScalarStyle, |
| 65 | |
| 66 | /** The literal scalar style. */ |
| 67 | YamlLiteralScalarStyle, |
| 68 | /** The folded scalar style. */ |
| 69 | YamlFoldedScalarStyle |
| 70 | } |
| 71 | |
| 72 | #[derive(Debug, PartialEq, Clone, Copy)] |
| 73 | #[repr(C)] |
| 74 | pub enum YamlEncoding { |
| 75 | /** Let the parser choose the encoding. */ |
| 76 | YamlAnyEncoding = 0, |
| 77 | /** The default UTF-8 encoding. */ |
| 78 | YamlUtf8Encoding, |
| 79 | /** The UTF-16-LE encoding with BOM. */ |
| 80 | YamlUtf16LeEncoding, |
| 81 | /** The UTF-16-BE encoding with BOM. */ |
| 82 | YamlUtf16BeEncoding |
| 83 | } |
| 84 | |
| 85 | #[derive(Clone, Copy)] |
| 86 | #[repr(C)] |
| 87 | #[allow(non_camel_case_types)] |
| 88 | pub struct yaml_mark_t { |
| 89 | pub index: size_t, |
| 90 | pub line: size_t, |
| 91 | pub column: size_t |
| 92 | } |
| 93 | |
| 94 | #[repr(C)] |
| 95 | #[allow(non_camel_case_types)] |
| 96 | pub struct yaml_buffer_t { |
| 97 | pub start: *const yaml_char_t, |
| 98 | pub end: *const yaml_char_t, |
| 99 | pub pointer: *const yaml_char_t, |
| 100 | pub last: *const yaml_char_t |
| 101 | } |
| 102 | |
| 103 | #[repr(C)] |
| 104 | #[allow(non_camel_case_types)] |
| 105 | pub struct yaml_queue_t { |
| 106 | pub start: *const c_void, |
| 107 | pub end: *const c_void, |
| 108 | pub head: *const c_void, |
| 109 | pub tail: *const c_void |
| 110 | } |
| 111 | |
| 112 | #[repr(C)] |
| 113 | #[allow(non_camel_case_types)] |
| 114 | pub struct yaml_stack_t { |
| 115 | pub start: *const c_void, |
| 116 | pub end: *const c_void, |
| 117 | pub top: *const c_void |
| 118 | } |
| 119 | |
| 120 | #[repr(C)] |
| 121 | #[allow(non_camel_case_types)] |
| 122 | #[derive(Clone, Copy)] |
| 123 | pub enum yaml_node_type_t { |
| 124 | /** An empty node. */ |
| 125 | YAML_NO_NODE = 0, |
| 126 | |
| 127 | /** A scalar node. */ |
| 128 | YAML_SCALAR_NODE, |
| 129 | /** A sequence node. */ |
| 130 | YAML_SEQUENCE_NODE, |
| 131 | /** A mapping node. */ |
| 132 | YAML_MAPPING_NODE |
| 133 | } |
| 134 | |
| 135 | #[repr(C)] |
| 136 | #[allow(non_camel_case_types)] |
| 137 | pub struct yaml_node_t { |
| 138 | pub node_type: yaml_node_type_t, |
| 139 | pub tag: *const yaml_char_t, |
| 140 | pub data: yaml_node_data_t, |
| 141 | pub start_mark: yaml_mark_t, |
| 142 | pub end_mark: yaml_mark_t, |
| 143 | } |
| 144 | |
| 145 | #[repr(C)] |
| 146 | #[allow(non_camel_case_types)] |
| 147 | pub struct yaml_scalar_node_t { |
| 148 | pub value: *const yaml_char_t, |
| 149 | pub length: size_t, |
| 150 | pub style: YamlScalarStyle |
| 151 | } |
| 152 | |
| 153 | #[repr(C)] |
| 154 | #[allow(non_camel_case_types)] |
| 155 | pub struct yaml_sequence_node_t { |
| 156 | pub items: yaml_stack_t, |
| 157 | pub style: YamlSequenceStyle |
| 158 | } |
| 159 | |
| 160 | #[derive(Clone, Copy)] |
| 161 | #[repr(C)] |
| 162 | #[allow(non_camel_case_types)] |
| 163 | pub struct yaml_node_pair_t { |
| 164 | pub key: c_int, |
| 165 | pub value: c_int |
| 166 | } |
| 167 | |
| 168 | #[repr(C)] |
| 169 | #[allow(non_camel_case_types)] |
| 170 | pub struct yaml_document_t { |
| 171 | pub nodes: yaml_stack_t, |
| 172 | |
| 173 | pub version_directive: *const yaml_version_directive_t, |
| 174 | pub tag_directives: yaml_tag_directive_list_t, |
| 175 | |
| 176 | pub start_implicit: c_int, |
| 177 | pub end_implicit: c_int, |
| 178 | |
| 179 | pub start_mark: yaml_mark_t, |
| 180 | pub end_mark: yaml_mark_t, |
| 181 | } |
| 182 | |
| 183 | #[repr(C)] |
| 184 | #[allow(non_camel_case_types)] |
| 185 | pub struct yaml_parser_t { |
| 186 | pub error: YamlErrorType, |
| 187 | pub problem: *const c_char, |
| 188 | pub problem_offset: size_t, |
| 189 | pub problem_value: c_int, |
| 190 | pub problem_mark: yaml_mark_t, |
| 191 | pub context: *const c_char, |
| 192 | pub context_mark: yaml_mark_t, |
| 193 | |
| 194 | pub read_handler: yaml_read_handler_t, |
| 195 | pub read_handler_data: *const c_void, |
| 196 | |
| 197 | pub input: yaml_parser_input_t, |
| 198 | pub eof: c_int, |
| 199 | pub buffer: yaml_buffer_t, |
| 200 | pub unread: size_t, |
| 201 | pub raw_buffer: yaml_buffer_t, |
| 202 | pub encoding: YamlEncoding, |
| 203 | pub offset: size_t, |
| 204 | pub mark: yaml_mark_t, |
| 205 | |
| 206 | pub stream_start_produced: c_int, |
| 207 | pub stream_end_produced: c_int, |
| 208 | pub flow_level: c_int, |
| 209 | pub tokens: yaml_queue_t, |
| 210 | pub tokens_parsed: size_t, |
| 211 | pub token_available: c_int, |
| 212 | |
| 213 | pub indents: yaml_stack_t, |
| 214 | pub indent: c_int, |
| 215 | pub simple_key_allowed: c_int, |
| 216 | pub simple_keys: yaml_stack_t, |
| 217 | |
| 218 | pub states: yaml_stack_t, |
| 219 | pub parser_state: c_int, |
| 220 | pub marks: yaml_stack_t, |
| 221 | pub tag_directives: yaml_stack_t, |
| 222 | pub aliases: yaml_stack_t, |
| 223 | |
| 224 | pub document: *const yaml_document_t, |
| 225 | } |
| 226 | |
| 227 | #[derive(Clone, Copy)] |
| 228 | #[repr(C)] |
| 229 | #[allow(non_camel_case_types)] |
| 230 | pub enum yaml_break_t { |
| 231 | /** Let the parser choose the break type. */ |
| 232 | YAML_ANY_BREAK, |
| 233 | /** Use CR for line breaks (Mac style). */ |
| 234 | YAML_CR_BREAK, |
| 235 | /** Use LN for line breaks (Unix style). */ |
| 236 | YAML_LN_BREAK, |
| 237 | /** Use CR LN for line breaks (DOS style). */ |
| 238 | YAML_CRLN_BREAK |
| 239 | } |
| 240 | |
| 241 | #[repr(C)] |
| 242 | #[allow(non_camel_case_types)] |
| 243 | pub struct yaml_emitter_t { |
| 244 | pub error: YamlErrorType, |
| 245 | pub problem: *const c_char, |
| 246 | |
| 247 | pub write_handler: yaml_write_handler_t, |
| 248 | pub write_handler_data: *const c_void, |
| 249 | |
| 250 | pub output: yaml_emitter_output_t, |
| 251 | pub buffer: yaml_buffer_t, |
| 252 | pub raw_buffer: yaml_buffer_t, |
| 253 | pub encoding: YamlEncoding, |
| 254 | |
| 255 | pub canonical: c_int, |
| 256 | pub best_indent: c_int, |
| 257 | pub best_width: c_int, |
| 258 | pub unicode: c_int, |
| 259 | pub line_break: yaml_break_t, |
| 260 | |
| 261 | pub states: yaml_stack_t, |
| 262 | pub state: c_int, |
| 263 | pub events: yaml_queue_t, |
| 264 | pub indents: yaml_stack_t, |
| 265 | pub tag_directives: yaml_stack_t, |
| 266 | |
| 267 | pub indent: c_int, |
| 268 | |
| 269 | pub flow_level: c_int, |
| 270 | |
| 271 | pub root_context: c_int, |
| 272 | pub sequence_context: c_int, |
| 273 | pub mapping_context: c_int, |
| 274 | pub simple_key_context: c_int, |
| 275 | |
| 276 | pub line: c_int, |
| 277 | pub column: c_int, |
| 278 | pub whitespace: c_int, |
| 279 | pub indention: c_int, |
| 280 | pub open_ended: c_int, |
| 281 | |
| 282 | pub anchor_data: yaml_emitter_anchor_data_t, |
| 283 | pub tag_data: yaml_emitter_tag_data_t, |
| 284 | pub scalar_data: yaml_emitter_scalar_data_t, |
| 285 | |
| 286 | pub opened: c_int, |
| 287 | pub closed: c_int, |
| 288 | |
| 289 | pub anchors: *const c_void, |
| 290 | |
| 291 | pub last_anchor_id: c_int, |
| 292 | |
| 293 | pub document: *const yaml_document_t |
| 294 | } |
| 295 | |
| 296 | #[repr(C)] |
| 297 | #[allow(non_camel_case_types)] |
| 298 | pub struct yaml_emitter_anchor_data_t { |
| 299 | pub anchor: *const yaml_char_t, |
| 300 | pub anchor_length: size_t, |
| 301 | pub alias: c_int |
| 302 | } |
| 303 | |
| 304 | #[repr(C)] |
| 305 | #[allow(non_camel_case_types)] |
| 306 | pub struct yaml_emitter_tag_data_t { |
| 307 | pub handle: *const yaml_char_t, |
| 308 | pub handle_length: size_t, |
| 309 | pub suffix: *const yaml_char_t, |
| 310 | pub suffix_length: size_t |
| 311 | } |
| 312 | |
| 313 | #[repr(C)] |
| 314 | #[allow(non_camel_case_types)] |
| 315 | pub struct yaml_emitter_scalar_data_t { |
| 316 | pub value: *const yaml_char_t, |
| 317 | pub length: size_t, |
| 318 | pub multiline: c_int, |
| 319 | pub flow_plain_allowed: c_int, |
| 320 | pub block_plain_allowed: c_int, |
| 321 | pub single_quoted_allowed: c_int, |
| 322 | pub block_allowed: c_int, |
| 323 | pub style: YamlScalarStyle, |
| 324 | } |
| 325 | |
| 326 | #[derive(Clone, Copy)] |
| 327 | #[repr(C)] |
| 328 | #[allow(non_camel_case_types)] |
| 329 | pub struct yaml_event_t { |
| 330 | pub event_type: yaml_event_type_t, |
| 331 | pub data: yaml_event_data_t, |
| 332 | pub start_mark: yaml_mark_t, |
| 333 | pub end_mark: yaml_mark_t |
| 334 | } |
| 335 | |
| 336 | #[derive(Clone, Copy)] |
| 337 | #[repr(C)] |
| 338 | #[allow(non_camel_case_types)] |
| 339 | pub struct yaml_stream_start_event_t { |
| 340 | pub encoding: YamlEncoding |
| 341 | } |
| 342 | |
| 343 | #[repr(C)] |
| 344 | #[allow(non_camel_case_types)] |
| 345 | pub struct yaml_tag_directive_list_t { |
| 346 | pub start: *const yaml_tag_directive_t, |
| 347 | pub end: *const yaml_tag_directive_t, |
| 348 | } |
| 349 | |
| 350 | #[repr(C)] |
| 351 | #[allow(non_camel_case_types)] |
| 352 | pub struct yaml_document_start_event_t { |
| 353 | pub version_directive: *const yaml_version_directive_t, |
| 354 | pub tag_directives: yaml_tag_directive_list_t, |
| 355 | pub implicit: c_int |
| 356 | } |
| 357 | |
| 358 | #[derive(Clone, Copy)] |
| 359 | #[repr(C)] |
| 360 | #[allow(non_camel_case_types)] |
| 361 | pub struct yaml_document_end_event_t { |
| 362 | pub implicit: c_int |
| 363 | } |
| 364 | |
| 365 | #[repr(C)] |
| 366 | #[allow(non_camel_case_types)] |
| 367 | pub struct yaml_alias_event_t { |
| 368 | pub anchor: *const yaml_char_t |
| 369 | } |
| 370 | |
| 371 | #[allow(non_camel_case_types)] |
| 372 | pub struct yaml_sequence_start_event_t { |
| 373 | pub anchor: *const yaml_char_t, |
| 374 | pub tag: *const yaml_char_t, |
| 375 | pub implicit: c_int, |
| 376 | pub style: YamlSequenceStyle |
| 377 | } |
| 378 | |
| 379 | #[repr(C)] |
| 380 | #[allow(non_camel_case_types)] |
| 381 | pub struct yaml_mapping_start_event_t { |
| 382 | pub anchor: *const yaml_char_t, |
| 383 | pub tag: *const yaml_char_t, |
| 384 | pub implicit: c_int, |
| 385 | pub style: YamlSequenceStyle |
| 386 | } |
| 387 | |
| 388 | #[repr(C)] |
| 389 | #[allow(non_camel_case_types)] |
| 390 | pub struct yaml_scalar_event_t { |
| 391 | pub anchor: *const yaml_char_t, |
| 392 | pub tag: *const yaml_char_t, |
| 393 | pub value: *const yaml_char_t, |
| 394 | pub length: size_t, |
| 395 | pub plain_implicit: c_int, |
| 396 | pub quoted_implicit: c_int, |
| 397 | pub style: YamlScalarStyle |
| 398 | } |
| 399 | |
| 400 | impl yaml_event_t { |
| 401 | pub unsafe fn delete(&mut self) { |
| 402 | yaml_event_delete(self); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | #[derive(Clone, Copy)] |
| 407 | #[repr(C)] |
| 408 | #[allow(non_camel_case_types)] |
| 409 | pub struct yaml_version_directive_t { |
| 410 | pub major: c_int, |
| 411 | pub minor: c_int |
| 412 | } |
| 413 | |
| 414 | #[repr(C)] |
| 415 | #[allow(non_camel_case_types)] |
| 416 | pub struct yaml_tag_directive_t { |
| 417 | pub handle: *const c_char, |
| 418 | pub prefix: *const c_char |
| 419 | } |
| 420 | |
| 421 | #[link(name = "yaml")] |
| 422 | #[allow(improper_ctypes)] |
| 423 | extern { |
| 424 | pub fn yaml_get_version_string() -> *const c_char; |
| 425 | pub fn yaml_get_version(major: *mut c_int, minor: *mut c_int, patch: *mut c_int) -> c_void; |
| 426 | pub fn yaml_event_delete(event: *mut yaml_event_t) -> c_void; |
| 427 | pub fn yaml_document_initialize(document: *mut yaml_document_t, |
| 428 | version_directive: *const yaml_version_directive_t, |
| 429 | tag_directives_start: *const yaml_tag_directive_t, |
| 430 | tag_directives_end: *const yaml_tag_directive_t, |
| 431 | start_implicit: c_int, end_implicit: c_int) -> c_int; |
| 432 | pub fn yaml_document_get_node(document: *const yaml_document_t, index: c_int) -> *const yaml_node_t; |
| 433 | pub fn yaml_document_get_root_node(document: *const yaml_document_t) -> *const yaml_node_t; |
| 434 | pub fn yaml_document_delete(document: *mut yaml_document_t) -> c_void; |
| 435 | pub fn yaml_document_add_scalar(document: *mut yaml_document_t, |
| 436 | tag: *const yaml_char_t, value: *const yaml_char_t, length: c_int, |
| 437 | style: YamlScalarStyle) -> c_int; |
| 438 | pub fn yaml_document_add_sequence(document: *mut yaml_document_t, |
| 439 | tag: *const yaml_char_t, style: YamlSequenceStyle) -> c_int; |
| 440 | pub fn yaml_document_add_mapping(document: *mut yaml_document_t, |
| 441 | tag: *const yaml_char_t, style: YamlSequenceStyle) -> c_int; |
| 442 | pub fn yaml_parser_initialize(parser: *mut yaml_parser_t) -> c_int; |
| 443 | pub fn yaml_parser_set_encoding(parser: *mut yaml_parser_t, encoding: YamlEncoding) -> c_void; |
| 444 | pub fn yaml_parser_delete(parser: *mut yaml_parser_t) -> c_void; |
| 445 | pub fn yaml_parser_set_input_string(parser: *mut yaml_parser_t, input: *const yaml_char_t, size: size_t) -> c_void; |
| 446 | pub fn yaml_parser_set_input(parser: *mut yaml_parser_t, handler: yaml_read_handler_t, data: *const c_void) -> c_void; |
| 447 | pub fn yaml_parser_parse(parser: *mut yaml_parser_t, event: *mut yaml_event_t) -> c_int; |
| 448 | pub fn yaml_parser_load(parser: *mut yaml_parser_t, document: *mut yaml_document_t) -> c_int; |
| 449 | pub fn yaml_emitter_initialize(emitter: *mut yaml_emitter_t) -> c_int; |
| 450 | pub fn yaml_emitter_emit(emitter: *mut yaml_emitter_t, event: *mut yaml_event_t) -> c_int; |
| 451 | pub fn yaml_emitter_delete(emitter: *mut yaml_emitter_t) -> c_void; |
| 452 | pub fn yaml_emitter_set_output(emitter: *mut yaml_emitter_t, handler: yaml_write_handler_t, data: *const c_void) -> c_void; |
| 453 | pub fn yaml_emitter_flush(emitter: *mut yaml_emitter_t) -> c_int; |
| 454 | pub fn yaml_stream_start_event_initialize(event: *mut yaml_event_t, encoding: YamlEncoding) -> c_int; |
| 455 | pub fn yaml_stream_end_event_initialize(event: *mut yaml_event_t) -> c_int; |
| 456 | pub fn yaml_document_start_event_initialize(event: *mut yaml_event_t, |
| 457 | version_directive: *const yaml_version_directive_t, |
| 458 | tag_directives_start: *const yaml_tag_directive_t, |
| 459 | tag_directies_end: *const yaml_tag_directive_t, |
| 460 | implicit: c_int) -> c_int; |
| 461 | pub fn yaml_document_end_event_initialize(event: *mut yaml_event_t, implicit: c_int) -> c_int; |
| 462 | pub fn yaml_alias_event_initialize(event: *mut yaml_event_t, anchor: *const yaml_char_t) -> c_int; |
| 463 | pub fn yaml_scalar_event_initialize(event: *mut yaml_event_t, |
| 464 | anchor: *const yaml_char_t, tag: *const yaml_char_t, |
| 465 | value: *const yaml_char_t, length: c_int, |
| 466 | plain_implicit: c_int, quoted_implicit: c_int, |
| 467 | style: YamlScalarStyle) -> c_int; |
| 468 | pub fn yaml_sequence_start_event_initialize(event: *mut yaml_event_t, |
| 469 | anchor: *const yaml_char_t, tag: *const yaml_char_t, implicit: c_int, |
| 470 | style: YamlSequenceStyle) -> c_int; |
| 471 | pub fn yaml_sequence_end_event_initialize(event: *mut yaml_event_t) -> c_int; |
| 472 | pub fn yaml_mapping_start_event_initialize(event: *mut yaml_event_t, |
| 473 | anchor: *const yaml_char_t, tag: *const yaml_char_t, implicit: c_int, |
| 474 | style: YamlSequenceStyle) -> c_int; |
| 475 | pub fn yaml_mapping_end_event_initialize(event: *mut yaml_event_t) -> c_int; |
| 476 | } |