@@ -45,11 +45,33 @@ pub struct EngineCtx {
45
45
pub ( crate ) name_in_progress : bool ,
46
46
pub ( crate ) stop_at_space : bool ,
47
47
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 > ,
48
51
49
52
pub ( crate ) eqtb : Vec < MemoryWord > ,
50
53
pub ( crate ) prim : Box < [ B32x2 ; PRIM_SIZE + 1 ] > ,
51
54
/// An arena of TeX nodes
52
55
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 ,
53
75
}
54
76
55
77
struct NodeError {
@@ -78,10 +100,14 @@ impl EngineCtx {
78
100
name_in_progress : false ,
79
101
stop_at_space : false ,
80
102
quoted_filename : false ,
103
+ texmf_log_name : 0 ,
104
+ log_opened : false ,
105
+ input_stack : Vec :: new ( ) ,
81
106
82
107
eqtb : Vec :: new ( ) ,
83
108
prim : Box :: new ( [ B32x2 { s0 : 0 , s1 : 0 } ; PRIM_SIZE + 1 ] ) ,
84
109
mem : Vec :: new ( ) ,
110
+ buffer : Vec :: new ( ) ,
85
111
}
86
112
}
87
113
@@ -405,6 +431,46 @@ pub extern "C" fn set_quoted_filename(val: bool) {
405
431
ENGINE_CTX . with_borrow_mut ( |engine| engine. quoted_filename = val)
406
432
}
407
433
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
+
408
474
#[ no_mangle]
409
475
pub extern "C" fn eqtb ( idx : usize ) -> MemoryWord {
410
476
ENGINE_CTX . with_borrow ( |engine| engine. eqtb [ idx] )
@@ -484,6 +550,33 @@ pub extern "C" fn prim_ptr(idx: usize) -> *mut B32x2 {
484
550
ENGINE_CTX . with_borrow_mut ( |engine| ptr:: from_mut ( & mut engine. prim [ idx] ) )
485
551
}
486
552
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
+
487
580
fn checkpool_pointer ( pool : & mut StringPool , pool_ptr : usize , len : usize ) {
488
581
if pool_ptr + len >= pool. pool_size {
489
582
panic ! ( "string pool overflow [{} bytes]" , pool. pool_size) ;
0 commit comments