1#![allow(non_camel_case_types)]
9
10use std::os::raw::c_int;
11
12#[repr(transparent)]
22#[derive(Clone, Copy, Debug, Eq, PartialEq)]
23pub struct FigStatus(pub c_int);
24
25#[allow(dead_code)]
26impl FigStatus {
27 pub const OK: c_int = 0;
28 pub const INVALID_ARGUMENT: c_int = 1;
29 pub const PARSE_ERROR: c_int = 2;
30 pub const OUT_OF_MEMORY: c_int = 3;
31 pub const UNSUPPORTED_FORMAT: c_int = 4;
32 pub const NOT_FOUND: c_int = 5;
33 pub const INTERNAL_ERROR: c_int = 255;
34}
35
36#[repr(C)]
37#[derive(Clone, Copy, Debug, Eq, PartialEq)]
38pub enum FigFormat {
39 Json = 1,
40 Jsonc = 2,
41 Yaml = 3,
42 Toml = 4,
43 Zon = 5,
44 Json5 = 7,
48 Fig = 8,
50}
51
52pub enum FigDocument {}
53
54pub type FigNodeId = u32;
55
56pub const FIG_NODE_NONE: FigNodeId = 0xFFFF_FFFF;
58
59#[repr(C)]
60#[derive(Clone, Copy, Debug, Eq, PartialEq)]
61#[allow(dead_code)]
62pub enum FigNodeKind {
63 Invalid = -1,
64 Null = 0,
65 Bool = 1,
66 Int = 2,
67 Float = 3,
68 String = 4,
69 Sequence = 5,
70 Mapping = 6,
71 Keyvalue = 7,
72 Alias = 8,
73}
74
75impl FigNodeKind {
76 pub fn from_c(raw: c_int) -> Self {
82 match raw {
83 0 => FigNodeKind::Null,
84 1 => FigNodeKind::Bool,
85 2 => FigNodeKind::Int,
86 3 => FigNodeKind::Float,
87 4 => FigNodeKind::String,
88 5 => FigNodeKind::Sequence,
89 6 => FigNodeKind::Mapping,
90 7 => FigNodeKind::Keyvalue,
91 8 => FigNodeKind::Alias,
92 _ => FigNodeKind::Invalid,
93 }
94 }
95}
96
97#[repr(C)]
104#[derive(Clone, Copy)]
105pub struct FigError {
106 pub size: u32,
107 pub code: c_int,
108 pub byte_offset: usize,
109 pub line: u32,
110 pub column: u32,
111 pub message_len: usize,
112 pub message: [u8; 256],
113}
114
115impl FigError {
116 pub fn new() -> Self {
118 FigError {
119 size: std::mem::size_of::<FigError>() as u32,
120 code: 0,
121 byte_offset: 0,
122 line: 0,
123 column: 0,
124 message_len: 0,
125 message: [0; 256],
126 }
127 }
128}
129
130unsafe extern "C" {
131 pub fn fig_version() -> u32;
132 pub fn fig_version_string() -> *const std::os::raw::c_char;
133 pub fn fig_format_capabilities(format: c_int) -> u32;
134
135 #[allow(dead_code)]
138 pub fn fig_parse(
139 input: *const u8,
140 input_len: usize,
141 format: c_int,
142 out_doc: *mut *mut FigDocument,
143 ) -> FigStatus;
144
145 pub fn fig_parse_ex(
146 input: *const u8,
147 input_len: usize,
148 format: c_int,
149 out_doc: *mut *mut FigDocument,
150 out_err: *mut FigError,
151 ) -> FigStatus;
152
153 pub fn fig_document_destroy(doc: *mut FigDocument);
154
155 pub fn fig_document_serialize(
156 doc: *mut FigDocument,
157 format: c_int,
158 options: *const FigSerializeOptions,
159 out_ptr: *mut *const u8,
160 out_len: *mut usize,
161 ) -> FigStatus;
162}
163
164unsafe extern "C" {
166 pub fn fig_document_root(doc: *const FigDocument) -> FigNodeId;
167 pub fn fig_node_kind(doc: *const FigDocument, node: FigNodeId) -> c_int;
171 pub fn fig_node_first_child(doc: *const FigDocument, node: FigNodeId) -> FigNodeId;
172 pub fn fig_node_next_sibling(doc: *const FigDocument, node: FigNodeId) -> FigNodeId;
173 pub fn fig_node_child_count(doc: *const FigDocument, node: FigNodeId) -> usize;
174 pub fn fig_keyvalue_key(doc: *const FigDocument, node: FigNodeId) -> FigNodeId;
175 pub fn fig_keyvalue_value(doc: *const FigDocument, node: FigNodeId) -> FigNodeId;
176
177 pub fn fig_node_bool(doc: *const FigDocument, node: FigNodeId, out: *mut bool) -> bool;
178 pub fn fig_node_number(
179 doc: *const FigDocument,
180 node: FigNodeId,
181 out_ptr: *mut *const u8,
182 out_len: *mut usize,
183 ) -> bool;
184 pub fn fig_node_string(
185 doc: *const FigDocument,
186 node: FigNodeId,
187 out_ptr: *mut *const u8,
188 out_len: *mut usize,
189 ) -> bool;
190 pub fn fig_node_extended(
191 doc: *const FigDocument,
192 node: FigNodeId,
193 out_kind: *mut c_int,
194 out_ptr: *mut *const u8,
195 out_len: *mut usize,
196 ) -> bool;
197}
198
199pub enum FigValue {}
202
203#[repr(C)]
205#[derive(Clone, Copy, Debug)]
206pub struct FigKeyValue {
207 pub key: FigNodeId,
208 pub value: FigNodeId,
209}
210
211#[repr(C)]
217#[derive(Clone, Copy, Debug)]
218pub struct FigSerializeOptions {
219 pub size: u32,
223 pub pretty: u8,
224 pub indent: u8,
225 pub strip_comments: u8,
226 pub lossless: u8,
227 pub width: u16,
228 pub flow: u8,
233}
234
235#[repr(C)]
242#[derive(Clone, Copy)]
243pub struct FigWarning {
244 pub size: u32,
245 pub code: c_int,
246 pub cause: c_int,
247 pub path: *const u8,
248 pub path_len: usize,
249 pub note: *const u8,
250 pub note_len: usize,
251}
252
253impl FigWarning {
254 pub fn new() -> Self {
256 FigWarning {
257 size: std::mem::size_of::<FigWarning>() as u32,
258 code: 0,
259 cause: 0,
260 path: std::ptr::null(),
261 path_len: 0,
262 note: std::ptr::null(),
263 note_len: 0,
264 }
265 }
266}
267
268unsafe extern "C" {
269 pub fn fig_value_create(out_value: *mut *mut FigValue) -> FigStatus;
270 pub fn fig_value_destroy(value: *mut FigValue);
271
272 pub fn fig_value_null(value: *mut FigValue, out_id: *mut FigNodeId) -> FigStatus;
273 pub fn fig_value_bool(value: *mut FigValue, b: bool, out_id: *mut FigNodeId) -> FigStatus;
274 pub fn fig_value_int(value: *mut FigValue, n: i64, out_id: *mut FigNodeId) -> FigStatus;
275 pub fn fig_value_uint(value: *mut FigValue, n: u64, out_id: *mut FigNodeId) -> FigStatus;
276 pub fn fig_value_number(
277 value: *mut FigValue,
278 raw: *const u8,
279 raw_len: usize,
280 is_float: bool,
281 out_id: *mut FigNodeId,
282 ) -> FigStatus;
283 pub fn fig_value_string(
284 value: *mut FigValue,
285 ptr: *const u8,
286 len: usize,
287 out_id: *mut FigNodeId,
288 ) -> FigStatus;
289 pub fn fig_value_extended(
290 value: *mut FigValue,
291 kind: c_int,
292 text: *const u8,
293 text_len: usize,
294 out_id: *mut FigNodeId,
295 ) -> FigStatus;
296 pub fn fig_value_seq(
297 value: *mut FigValue,
298 items: *const FigNodeId,
299 items_len: usize,
300 out_id: *mut FigNodeId,
301 ) -> FigStatus;
302 pub fn fig_value_map(
303 value: *mut FigValue,
304 entries: *const FigKeyValue,
305 entries_len: usize,
306 out_id: *mut FigNodeId,
307 ) -> FigStatus;
308 #[allow(dead_code)]
310 pub fn fig_value_serialize(
311 value: *mut FigValue,
312 root: FigNodeId,
313 format: c_int,
314 out_ptr: *mut *const u8,
315 out_len: *mut usize,
316 ) -> FigStatus;
317 pub fn fig_value_serialize_opts(
318 value: *mut FigValue,
319 root: FigNodeId,
320 format: c_int,
321 options: *const FigSerializeOptions,
322 out_ptr: *mut *const u8,
323 out_len: *mut usize,
324 ) -> FigStatus;
325}
326
327unsafe extern "C" {
330 pub fn fig_document_diagnose(
331 doc: *mut FigDocument,
332 format: c_int,
333 options: *const FigSerializeOptions,
334 out_count: *mut usize,
335 ) -> FigStatus;
336 pub fn fig_document_warning(
337 doc: *mut FigDocument,
338 index: usize,
339 out: *mut FigWarning,
340 ) -> FigStatus;
341 pub fn fig_value_diagnose(
342 value: *mut FigValue,
343 root: FigNodeId,
344 format: c_int,
345 options: *const FigSerializeOptions,
346 out_count: *mut usize,
347 ) -> FigStatus;
348 pub fn fig_value_warning(value: *mut FigValue, index: usize, out: *mut FigWarning)
349 -> FigStatus;
350}
351
352pub enum FigEditor {}
355pub enum FigEmbed {}
356
357#[repr(C)]
361#[derive(Clone, Copy, Debug)]
362pub struct FigPathSegment {
363 pub kind: i32,
364 pub key_ptr: *const u8,
365 pub key_len: usize,
366 pub index: usize,
367}
368
369#[repr(C)]
372#[derive(Clone, Copy, Debug)]
373pub struct FigStr {
374 pub ptr: *const u8,
375 pub len: usize,
376}
377
378#[repr(C)]
382#[derive(Clone, Copy, Debug, Default)]
383#[allow(dead_code)]
384pub struct FigSpan {
385 pub start: usize,
386 pub end: usize,
387}
388
389#[repr(C)]
390#[derive(Clone, Copy, Debug, Default)]
391#[allow(dead_code)]
392pub struct FigRegion {
393 pub size: u32,
398 pub open_fence: FigSpan,
399 pub content: FigSpan,
400 pub close_fence: FigSpan,
401 pub body: FigSpan,
402}
403
404#[repr(C)]
405#[derive(Clone, Copy, Debug, Eq, PartialEq)]
406#[allow(dead_code)]
407pub enum FigEmbedType {
408 FrontmatterYaml = 0,
409 FrontmatterJson = 1,
410 EndmatterYaml = 2,
411 FrontmatterFig = 3,
412 PlusToml = 4,
413 FencedYaml = 5,
414 FencedJson = 6,
415 FencedToml = 7,
416 MdFrontmatterJson = 8,
417 MdFrontmatterToml = 9,
418 MdFrontmatterFig = 10,
419 HtmlScriptFig = 11,
420 HtmlScriptYaml = 12,
421 HtmlScriptJson = 13,
422 HtmlScriptToml = 14,
423 HtmlCodeFig = 15,
424 HtmlCodeYaml = 16,
425 HtmlCodeJson = 17,
426 HtmlCodeToml = 18,
427}
428
429unsafe extern "C" {
430 pub fn fig_editor_create(
431 input: *const u8,
432 input_len: usize,
433 format: c_int,
434 out_editor: *mut *mut FigEditor,
435 ) -> FigStatus;
436 pub fn fig_editor_destroy(editor: *mut FigEditor);
437
438 pub fn fig_editor_replace_val(
439 editor: *mut FigEditor,
440 path: *const FigPathSegment,
441 path_len: usize,
442 repl: *const u8,
443 repl_len: usize,
444 ) -> FigStatus;
445 pub fn fig_editor_replace_key(
446 editor: *mut FigEditor,
447 path: *const FigPathSegment,
448 path_len: usize,
449 repl: *const u8,
450 repl_len: usize,
451 ) -> FigStatus;
452 pub fn fig_editor_set(
453 editor: *mut FigEditor,
454 path: *const FigPathSegment,
455 path_len: usize,
456 val: *const u8,
457 val_len: usize,
458 ) -> FigStatus;
459 pub fn fig_editor_add_leading_comment(
460 editor: *mut FigEditor,
461 path: *const FigPathSegment,
462 path_len: usize,
463 text: *const u8,
464 text_len: usize,
465 ) -> FigStatus;
466 pub fn fig_editor_set_trailing_comment(
467 editor: *mut FigEditor,
468 path: *const FigPathSegment,
469 path_len: usize,
470 text: *const u8,
471 text_len: usize,
472 ) -> FigStatus;
473 pub fn fig_editor_delete_leading_comments(
474 editor: *mut FigEditor,
475 path: *const FigPathSegment,
476 path_len: usize,
477 ) -> FigStatus;
478 pub fn fig_editor_delete_trailing_comment(
479 editor: *mut FigEditor,
480 path: *const FigPathSegment,
481 path_len: usize,
482 ) -> FigStatus;
483 pub fn fig_editor_get_leading_comment(
484 editor: *mut FigEditor,
485 path: *const FigPathSegment,
486 path_len: usize,
487 out_ptr: *mut *const u8,
488 out_len: *mut usize,
489 ) -> FigStatus;
490 pub fn fig_editor_get_trailing_comment(
491 editor: *mut FigEditor,
492 path: *const FigPathSegment,
493 path_len: usize,
494 out_ptr: *mut *const u8,
495 out_len: *mut usize,
496 ) -> FigStatus;
497 pub fn fig_editor_insert_key(
498 editor: *mut FigEditor,
499 path: *const FigPathSegment,
500 path_len: usize,
501 key: *const u8,
502 key_len: usize,
503 val: *const u8,
504 val_len: usize,
505 ) -> FigStatus;
506 pub fn fig_editor_delete_key(
507 editor: *mut FigEditor,
508 path: *const FigPathSegment,
509 path_len: usize,
510 ) -> FigStatus;
511 pub fn fig_editor_append_seq(
512 editor: *mut FigEditor,
513 path: *const FigPathSegment,
514 path_len: usize,
515 val: *const u8,
516 val_len: usize,
517 ) -> FigStatus;
518 pub fn fig_editor_prepend_seq(
519 editor: *mut FigEditor,
520 path: *const FigPathSegment,
521 path_len: usize,
522 val: *const u8,
523 val_len: usize,
524 ) -> FigStatus;
525 pub fn fig_editor_remove_seq_item(
526 editor: *mut FigEditor,
527 path: *const FigPathSegment,
528 path_len: usize,
529 index: usize,
530 ) -> FigStatus;
531 pub fn fig_editor_move_key(
532 editor: *mut FigEditor,
533 src_path: *const FigPathSegment,
534 src_path_len: usize,
535 dest_path: *const FigPathSegment,
536 dest_path_len: usize,
537 ) -> FigStatus;
538 pub fn fig_editor_reorder_keys(
539 editor: *mut FigEditor,
540 path: *const FigPathSegment,
541 path_len: usize,
542 keys: *const FigStr,
543 keys_len: usize,
544 ) -> FigStatus;
545 pub fn fig_editor_move_item(
546 editor: *mut FigEditor,
547 path: *const FigPathSegment,
548 path_len: usize,
549 from: usize,
550 to: usize,
551 ) -> FigStatus;
552 pub fn fig_editor_reorder_items(
553 editor: *mut FigEditor,
554 path: *const FigPathSegment,
555 path_len: usize,
556 indices: *const usize,
557 indices_len: usize,
558 ) -> FigStatus;
559 pub fn fig_editor_set_sequence(
560 editor: *mut FigEditor,
561 path: *const FigPathSegment,
562 path_len: usize,
563 items: *const FigStr,
564 items_len: usize,
565 ) -> FigStatus;
566 pub fn fig_editor_delete_container(
571 editor: *mut FigEditor,
572 path: *const FigPathSegment,
573 path_len: usize,
574 ) -> FigStatus;
575 pub fn fig_editor_insert_container(
576 editor: *mut FigEditor,
577 path: *const FigPathSegment,
578 path_len: usize,
579 body: *const u8,
580 body_len: usize,
581 ) -> FigStatus;
582 pub fn fig_editor_rename_container(
583 editor: *mut FigEditor,
584 path: *const FigPathSegment,
585 path_len: usize,
586 new_leaf: *const u8,
587 new_leaf_len: usize,
588 ) -> FigStatus;
589 pub fn fig_editor_move_container(
592 editor: *mut FigEditor,
593 src_path: *const FigPathSegment,
594 src_path_len: usize,
595 dest_path: *const FigPathSegment,
596 dest_path_len: usize,
597 ) -> FigStatus;
598 pub fn fig_editor_reorder_containers(
599 editor: *mut FigEditor,
600 order: *const FigStr,
601 order_len: usize,
602 ) -> FigStatus;
603 pub fn fig_editor_append_container_to_seq(
604 editor: *mut FigEditor,
605 path: *const FigPathSegment,
606 path_len: usize,
607 body: *const u8,
608 body_len: usize,
609 ) -> FigStatus;
610 pub fn fig_editor_source(
611 editor: *const FigEditor,
612 out_ptr: *mut *const u8,
613 out_len: *mut usize,
614 ) -> FigStatus;
615
616 pub fn fig_embed_extract(
617 input: *const u8,
618 input_len: usize,
619 embed_type: c_int,
620 out_region: *mut FigRegion,
621 ) -> FigStatus;
622
623 pub fn fig_embed_detect(
624 input: *const u8,
625 input_len: usize,
626 out_embed_type: *mut c_int,
627 ) -> FigStatus;
628
629 pub fn fig_embed_open(
630 input: *const u8,
631 input_len: usize,
632 embed_type: c_int,
633 out_embed: *mut *mut FigEmbed,
634 ) -> FigStatus;
635 pub fn fig_embed_open_or_init(
636 input: *const u8,
637 input_len: usize,
638 embed_type: c_int,
639 out_embed: *mut *mut FigEmbed,
640 ) -> FigStatus;
641 pub fn fig_embed_destroy(fm: *mut FigEmbed);
642
643 pub fn fig_embed_replace_val(
644 fm: *mut FigEmbed,
645 path: *const FigPathSegment,
646 path_len: usize,
647 repl: *const u8,
648 repl_len: usize,
649 ) -> FigStatus;
650 pub fn fig_embed_replace_key(
651 fm: *mut FigEmbed,
652 path: *const FigPathSegment,
653 path_len: usize,
654 repl: *const u8,
655 repl_len: usize,
656 ) -> FigStatus;
657 pub fn fig_embed_set(
658 fm: *mut FigEmbed,
659 path: *const FigPathSegment,
660 path_len: usize,
661 val: *const u8,
662 val_len: usize,
663 ) -> FigStatus;
664 pub fn fig_embed_add_leading_comment(
665 fm: *mut FigEmbed,
666 path: *const FigPathSegment,
667 path_len: usize,
668 text: *const u8,
669 text_len: usize,
670 ) -> FigStatus;
671 pub fn fig_embed_set_trailing_comment(
672 fm: *mut FigEmbed,
673 path: *const FigPathSegment,
674 path_len: usize,
675 text: *const u8,
676 text_len: usize,
677 ) -> FigStatus;
678 pub fn fig_embed_delete_leading_comments(
679 fm: *mut FigEmbed,
680 path: *const FigPathSegment,
681 path_len: usize,
682 ) -> FigStatus;
683 pub fn fig_embed_delete_trailing_comment(
684 fm: *mut FigEmbed,
685 path: *const FigPathSegment,
686 path_len: usize,
687 ) -> FigStatus;
688 pub fn fig_embed_get_leading_comment(
689 fm: *mut FigEmbed,
690 path: *const FigPathSegment,
691 path_len: usize,
692 out_ptr: *mut *const u8,
693 out_len: *mut usize,
694 ) -> FigStatus;
695 pub fn fig_embed_get_trailing_comment(
696 fm: *mut FigEmbed,
697 path: *const FigPathSegment,
698 path_len: usize,
699 out_ptr: *mut *const u8,
700 out_len: *mut usize,
701 ) -> FigStatus;
702 pub fn fig_embed_insert_key(
703 fm: *mut FigEmbed,
704 path: *const FigPathSegment,
705 path_len: usize,
706 key: *const u8,
707 key_len: usize,
708 val: *const u8,
709 val_len: usize,
710 ) -> FigStatus;
711 pub fn fig_embed_delete_key(
712 fm: *mut FigEmbed,
713 path: *const FigPathSegment,
714 path_len: usize,
715 ) -> FigStatus;
716 pub fn fig_embed_append_seq(
717 fm: *mut FigEmbed,
718 path: *const FigPathSegment,
719 path_len: usize,
720 val: *const u8,
721 val_len: usize,
722 ) -> FigStatus;
723 pub fn fig_embed_prepend_seq(
724 fm: *mut FigEmbed,
725 path: *const FigPathSegment,
726 path_len: usize,
727 val: *const u8,
728 val_len: usize,
729 ) -> FigStatus;
730 pub fn fig_embed_remove_seq_item(
731 fm: *mut FigEmbed,
732 path: *const FigPathSegment,
733 path_len: usize,
734 index: usize,
735 ) -> FigStatus;
736 pub fn fig_embed_move_key(
737 fm: *mut FigEmbed,
738 src_path: *const FigPathSegment,
739 src_path_len: usize,
740 dest_path: *const FigPathSegment,
741 dest_path_len: usize,
742 ) -> FigStatus;
743 pub fn fig_embed_reorder_keys(
744 fm: *mut FigEmbed,
745 path: *const FigPathSegment,
746 path_len: usize,
747 keys: *const FigStr,
748 keys_len: usize,
749 ) -> FigStatus;
750 pub fn fig_embed_move_item(
751 fm: *mut FigEmbed,
752 path: *const FigPathSegment,
753 path_len: usize,
754 from: usize,
755 to: usize,
756 ) -> FigStatus;
757 pub fn fig_embed_reorder_items(
758 fm: *mut FigEmbed,
759 path: *const FigPathSegment,
760 path_len: usize,
761 indices: *const usize,
762 indices_len: usize,
763 ) -> FigStatus;
764 pub fn fig_embed_set_sequence(
765 fm: *mut FigEmbed,
766 path: *const FigPathSegment,
767 path_len: usize,
768 items: *const FigStr,
769 items_len: usize,
770 ) -> FigStatus;
771 pub fn fig_embed_replace_body(fm: *mut FigEmbed, body: *const u8, body_len: usize)
772 -> FigStatus;
773 pub fn fig_embed_render(
774 fm: *mut FigEmbed,
775 out_ptr: *mut *const u8,
776 out_len: *mut usize,
777 ) -> FigStatus;
778}