Skip to content

Commit e0ee626

Browse files
committed
Port input_ptr and cur_input variable
1 parent 7c474f7 commit e0ee626

File tree

7 files changed

+292
-256
lines changed

7 files changed

+292
-256
lines changed

crates/engine_xetex/src/c_api/engine.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{ptr, slice};
77
mod memory;
88

99
use crate::c_api::is_dir_sep;
10+
use crate::c_api::output::{rs_print, rs_print_ln, rs_print_nl_bytes};
1011
use crate::c_api::pool::{
1112
rs_make_string, rs_search_string, rs_slow_make_string, StringPool, EMPTY_STRING, TOO_BIG_CHAR,
1213
};
@@ -48,6 +49,8 @@ pub struct EngineCtx {
4849
pub(crate) texmf_log_name: StrNumber,
4950
pub(crate) log_opened: bool,
5051
pub(crate) input_stack: Vec<InputState>,
52+
pub(crate) input_ptr: usize,
53+
pub(crate) cur_input: InputState,
5154

5255
pub(crate) eqtb: Vec<MemoryWord>,
5356
pub(crate) prim: Box<[B32x2; PRIM_SIZE + 1]>,
@@ -103,6 +106,8 @@ impl EngineCtx {
103106
texmf_log_name: 0,
104107
log_opened: false,
105108
input_stack: Vec::new(),
109+
input_ptr: 0,
110+
cur_input: InputState::default(),
106111

107112
eqtb: Vec::new(),
108113
prim: Box::new([B32x2 { s0: 0, s1: 0 }; PRIM_SIZE + 1]),
@@ -471,6 +476,31 @@ pub extern "C" fn clear_input_stack() {
471476
ENGINE_CTX.with_borrow_mut(|engine| engine.input_stack.clear())
472477
}
473478

479+
#[no_mangle]
480+
pub extern "C" fn input_ptr() -> usize {
481+
ENGINE_CTX.with_borrow(|engine| engine.input_ptr)
482+
}
483+
484+
#[no_mangle]
485+
pub extern "C" fn set_input_ptr(val: usize) {
486+
ENGINE_CTX.with_borrow_mut(|engine| engine.input_ptr = val)
487+
}
488+
489+
#[no_mangle]
490+
pub extern "C" fn cur_input() -> InputState {
491+
ENGINE_CTX.with_borrow(|engine| engine.cur_input.clone())
492+
}
493+
494+
#[no_mangle]
495+
pub extern "C" fn cur_input_ptr() -> *mut InputState {
496+
ENGINE_CTX.with_borrow_mut(|engine| ptr::from_mut(&mut engine.cur_input))
497+
}
498+
499+
#[no_mangle]
500+
pub extern "C" fn set_cur_input(val: InputState) {
501+
ENGINE_CTX.with_borrow_mut(|engine| engine.cur_input = val)
502+
}
503+
474504
#[no_mangle]
475505
pub extern "C" fn eqtb(idx: usize) -> MemoryWord {
476506
ENGINE_CTX.with_borrow(|engine| engine.eqtb[idx])

crates/engine_xetex/src/c_api/output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct OutputCtx {
2727
term_offset: i32,
2828
file_offset: i32,
2929
rust_stdout: Option<OutputId>,
30-
log_file: Option<OutputId>,
30+
pub(crate) log_file: Option<OutputId>,
3131
write_file: Vec<Option<OutputId>>,
3232
doing_special: bool,
3333
digits: [u8; 23],

crates/engine_xetex/xetex/xetex-ini.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ eight_bits cur_cmd;
9999
int32_t cur_chr;
100100
int32_t cur_cs;
101101
int32_t cur_tok;
102-
int32_t input_ptr;
103102
int32_t max_in_stack;
104-
input_state_t cur_input;
105103
int32_t open_parens;
106104
UFILE **input_file;
107105
str_number *source_filename_stack;
@@ -2420,7 +2418,7 @@ load_fmt_file(void)
24202418
int32_t x;
24212419
rust_input_handle_t fmt_in;
24222420

2423-
j = cur_input.loc;
2421+
j = cur_input().loc;
24242422

24252423
/* This is where a first line starting with "&" used to
24262424
* trigger code that would change the format file. */
@@ -2431,7 +2429,7 @@ load_fmt_file(void)
24312429
if (fmt_in == INVALID_HANDLE)
24322430
_tt_abort("cannot open the format file \"%s\"", name_of_file());
24332431

2434-
cur_input.loc = j;
2432+
cur_input_ptr()->loc = j;
24352433

24362434
if (in_initex_mode) {
24372435
free(font_info);
@@ -2904,8 +2902,8 @@ final_cleanup(void)
29042902
if (job_name() == 0)
29052903
open_log_file();
29062904

2907-
while (input_ptr > 0)
2908-
if (cur_input.state == TOKEN_LIST)
2905+
while (input_ptr() > 0)
2906+
if (cur_input().state == TOKEN_LIST)
29092907
end_token_list();
29102908
else
29112909
end_file_reading();
@@ -3004,8 +3002,8 @@ init_io(void)
30043002

30053003
set_buffer(first, 0);
30063004
last = first;
3007-
cur_input.loc = first;
3008-
cur_input.limit = last;
3005+
cur_input_ptr()->loc = first;
3006+
cur_input_ptr()->limit = last;
30093007
first = last + 1;
30103008
}
30113009

@@ -3675,7 +3673,7 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d
36753673
else
36763674
output_file_extension = ".xdv";
36773675

3678-
input_ptr = 0;
3676+
set_input_ptr(0);
36793677
max_in_stack = 0;
36803678
source_filename_stack[0] = 0;
36813679
set_full_source_filename_stack(0, 0);
@@ -3695,11 +3693,11 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d
36953693
scanner_status = NORMAL;
36963694
warning_index = TEX_NULL;
36973695
first = 1;
3698-
cur_input.state = NEW_LINE;
3699-
cur_input.start = 1;
3700-
cur_input.index = 0;
3696+
cur_input_ptr()->state = NEW_LINE;
3697+
cur_input_ptr()->start = 1;
3698+
cur_input_ptr()->index = 0;
37013699
set_line(0);
3702-
cur_input.name = 0;
3700+
cur_input_ptr()->name = 0;
37033701
force_eof = false;
37043702
align_state = 1000000L;
37053703

@@ -3719,9 +3717,9 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d
37193717
}
37203718

37213719
if (INTPAR(end_line_char) < 0 || INTPAR(end_line_char) > BIGGEST_CHAR)
3722-
cur_input.limit--;
3720+
cur_input_ptr()->limit--;
37233721
else
3724-
set_buffer(cur_input.limit, INTPAR(end_line_char));
3722+
set_buffer(cur_input().limit, INTPAR(end_line_char));
37253723

37263724
if (in_initex_mode) {
37273725
/* TeX initializes with the real date and time, but for format file

crates/engine_xetex/xetex/xetex-synctex.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,10 @@ void synctex_start_input(void)
337337
* use the 16 other bits to store the column number */
338338
synctex_ctxt.synctex_tag_counter = 0;
339339
/* was this, but this looks like a bug */
340-
/* cur_input.synctex_tag = 0; */
340+
/* cur_input_ptr()->synctex_tag = 0; */
341341
return;
342342
}
343-
cur_input.synctex_tag = (int) synctex_ctxt.synctex_tag_counter; /* -> *TeX.web */
343+
cur_input_ptr()->synctex_tag = (int) synctex_ctxt.synctex_tag_counter; /* -> *TeX.web */
344344
if (synctex_ctxt.synctex_tag_counter == 1) {
345345
/* this is the first file TeX ever opens, in general \jobname.tex we
346346
* do not know yet if synchronization will ever be enabled so we have
@@ -357,7 +357,7 @@ void synctex_start_input(void)
357357
|| (INVALID_HANDLE != synctex_dot_open())) {
358358
char *tmp = get_current_name();
359359
/* Always record the input, even if INTPAR(synctex) is 0 */
360-
synctex_record_input(cur_input.synctex_tag, tmp);
360+
synctex_record_input(cur_input().synctex_tag, tmp);
361361
free(tmp);
362362
}
363363
return;

0 commit comments

Comments
 (0)