@@ -45,11 +45,33 @@ pub struct EngineCtx {
4545 pub ( crate ) name_in_progress : bool ,
4646 pub ( crate ) stop_at_space : bool ,
4747 pub ( crate ) quoted_filename : bool ,
48+ pub ( crate ) texmf_log_name : StrNumber ,
49+ pub ( crate ) log_opened : bool ,
50+ pub ( crate ) input_stack : Vec < InputState > ,
4851
4952 pub ( crate ) eqtb : Vec < MemoryWord > ,
5053 pub ( crate ) prim : Box < [ B32x2 ; PRIM_SIZE + 1 ] > ,
5154 /// An arena of TeX nodes
5255 pub ( crate ) mem : Vec < MemoryWord > ,
56+ pub ( crate ) buffer : Vec < char > ,
57+ }
58+
59+ #[ derive( Clone , Default , PartialEq ) ]
60+ #[ repr( C ) ]
61+ pub struct InputState {
62+ /// tokenizer state: mid_line, skip_blanks, new_line
63+ state : u16 ,
64+ /// index of this level of input in input_file array
65+ index : u16 ,
66+ /// position of beginning of current line in `buffer`
67+ start : i32 ,
68+ /// position of next character to read in `buffer`
69+ loc : i32 ,
70+ /// position of end of line in `buffer`
71+ limit : i32 ,
72+ /// name of current file or magic value for terminal, etc.
73+ name : StrNumber ,
74+ synctex_tag : i32 ,
5375}
5476
5577struct NodeError {
@@ -78,10 +100,14 @@ impl EngineCtx {
78100 name_in_progress : false ,
79101 stop_at_space : false ,
80102 quoted_filename : false ,
103+ texmf_log_name : 0 ,
104+ log_opened : false ,
105+ input_stack : Vec :: new ( ) ,
81106
82107 eqtb : Vec :: new ( ) ,
83108 prim : Box :: new ( [ B32x2 { s0 : 0 , s1 : 0 } ; PRIM_SIZE + 1 ] ) ,
84109 mem : Vec :: new ( ) ,
110+ buffer : Vec :: new ( ) ,
85111 }
86112 }
87113
@@ -405,6 +431,46 @@ pub extern "C" fn set_quoted_filename(val: bool) {
405431 ENGINE_CTX . with_borrow_mut ( |engine| engine. quoted_filename = val)
406432}
407433
434+ #[ no_mangle]
435+ pub extern "C" fn texmf_log_name ( ) -> StrNumber {
436+ ENGINE_CTX . with_borrow ( |engine| engine. texmf_log_name )
437+ }
438+
439+ #[ no_mangle]
440+ pub extern "C" fn set_texmf_log_name ( val : StrNumber ) {
441+ ENGINE_CTX . with_borrow_mut ( |engine| engine. texmf_log_name = val)
442+ }
443+
444+ #[ no_mangle]
445+ pub extern "C" fn log_opened ( ) -> bool {
446+ ENGINE_CTX . with_borrow ( |engine| engine. log_opened )
447+ }
448+
449+ #[ no_mangle]
450+ pub extern "C" fn set_log_opened ( val : bool ) {
451+ ENGINE_CTX . with_borrow_mut ( |engine| engine. log_opened = val)
452+ }
453+
454+ #[ no_mangle]
455+ pub extern "C" fn resize_input_stack ( len : usize ) {
456+ ENGINE_CTX . with_borrow_mut ( |engine| engine. input_stack . resize ( len, InputState :: default ( ) ) )
457+ }
458+
459+ #[ no_mangle]
460+ pub extern "C" fn input_stack ( idx : usize ) -> InputState {
461+ ENGINE_CTX . with_borrow ( |engine| engine. input_stack [ idx] . clone ( ) )
462+ }
463+
464+ #[ no_mangle]
465+ pub extern "C" fn set_input_stack ( idx : usize , state : InputState ) {
466+ ENGINE_CTX . with_borrow_mut ( |engine| engine. input_stack [ idx] = state)
467+ }
468+
469+ #[ no_mangle]
470+ pub extern "C" fn clear_input_stack ( ) {
471+ ENGINE_CTX . with_borrow_mut ( |engine| engine. input_stack . clear ( ) )
472+ }
473+
408474#[ no_mangle]
409475pub extern "C" fn eqtb ( idx : usize ) -> MemoryWord {
410476 ENGINE_CTX . with_borrow ( |engine| engine. eqtb [ idx] )
@@ -484,6 +550,33 @@ pub extern "C" fn prim_ptr(idx: usize) -> *mut B32x2 {
484550 ENGINE_CTX . with_borrow_mut ( |engine| ptr:: from_mut ( & mut engine. prim [ idx] ) )
485551}
486552
553+ #[ no_mangle]
554+ pub extern "C" fn resize_buffer ( len : usize ) {
555+ ENGINE_CTX . with_borrow_mut ( |engine| engine. buffer . resize ( len, '\0' ) )
556+ }
557+
558+ #[ no_mangle]
559+ pub extern "C" fn buffer_ptr ( ) -> * mut char {
560+ ENGINE_CTX . with_borrow_mut ( |engine| engine. buffer . as_mut_ptr ( ) )
561+ }
562+
563+ #[ no_mangle]
564+ pub extern "C" fn buffer ( idx : usize ) -> char {
565+ ENGINE_CTX . with_borrow ( |engine| engine. buffer [ idx] )
566+ }
567+
568+ #[ no_mangle]
569+ pub extern "C" fn set_buffer ( idx : usize , val : u32 ) {
570+ ENGINE_CTX . with_borrow_mut ( |engine| {
571+ engine. buffer [ idx] = char:: from_u32 ( val) . unwrap_or ( char:: REPLACEMENT_CHARACTER )
572+ } )
573+ }
574+
575+ #[ no_mangle]
576+ pub extern "C" fn clear_buffer ( ) {
577+ ENGINE_CTX . with_borrow_mut ( |engine| engine. buffer . clear ( ) )
578+ }
579+
487580fn checkpool_pointer ( pool : & mut StringPool , pool_ptr : usize , len : usize ) {
488581 if pool_ptr + len >= pool. pool_size {
489582 panic ! ( "string pool overflow [{} bytes]" , pool. pool_size) ;
0 commit comments