Skip to content

Commit 34e0b40

Browse files
committed
Port interaction variable and pre_error_message
1 parent 5f522ad commit 34e0b40

File tree

8 files changed

+89
-37
lines changed

8 files changed

+89
-37
lines changed

crates/engine_xetex/src/c_api/engine.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub struct EngineCtx {
5151
pub(crate) input_stack: Vec<InputState>,
5252
pub(crate) input_ptr: usize,
5353
pub(crate) cur_input: InputState,
54+
pub(crate) interaction: InteractionMode,
5455

5556
pub(crate) eqtb: Vec<MemoryWord>,
5657
pub(crate) prim: Box<[B32x2; PRIM_SIZE + 1]>,
@@ -59,6 +60,28 @@ pub struct EngineCtx {
5960
pub(crate) buffer: Vec<char>,
6061
}
6162

63+
#[derive(Copy, Clone, PartialEq, Eq)]
64+
pub enum InteractionMode {
65+
Batch = 0,
66+
Nonstop,
67+
Scroll,
68+
ErrorStop,
69+
}
70+
71+
impl TryFrom<u8> for InteractionMode {
72+
type Error = u8;
73+
74+
fn try_from(value: u8) -> Result<Self, Self::Error> {
75+
Ok(match value {
76+
0 => InteractionMode::Batch,
77+
1 => InteractionMode::Nonstop,
78+
2 => InteractionMode::Scroll,
79+
3 => InteractionMode::ErrorStop,
80+
_ => return Err(value),
81+
})
82+
}
83+
}
84+
6285
#[derive(Clone, Default, PartialEq)]
6386
#[repr(C)]
6487
pub struct InputState {
@@ -108,6 +131,7 @@ impl EngineCtx {
108131
input_stack: Vec::new(),
109132
input_ptr: 0,
110133
cur_input: InputState::default(),
134+
interaction: InteractionMode::Batch,
111135

112136
eqtb: Vec::new(),
113137
prim: Box::new([B32x2 { s0: 0, s1: 0 }; PRIM_SIZE + 1]),
@@ -501,6 +525,17 @@ pub extern "C" fn set_cur_input(val: InputState) {
501525
ENGINE_CTX.with_borrow_mut(|engine| engine.cur_input = val)
502526
}
503527

528+
#[no_mangle]
529+
pub extern "C" fn interaction() -> u8 {
530+
ENGINE_CTX.with_borrow(|engine| engine.interaction as u8)
531+
}
532+
533+
#[no_mangle]
534+
pub extern "C" fn set_interaction(val: u8) {
535+
ENGINE_CTX
536+
.with_borrow_mut(|engine| engine.interaction = InteractionMode::try_from(val).unwrap())
537+
}
538+
504539
#[no_mangle]
505540
pub extern "C" fn eqtb(idx: usize) -> MemoryWord {
506541
ENGINE_CTX.with_borrow(|engine| engine.eqtb[idx])
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use crate::c_api::engine::{rs_open_log_file, InteractionMode, Selector};
2+
use crate::c_api::globals::Globals;
3+
use crate::c_api::output::rs_error_here_with_diagnostic;
4+
5+
pub fn rs_pre_error_message(globals: &mut Globals<'_, '_>) {
6+
if globals.engine.log_opened {
7+
globals.engine.selector = Selector::TermAndLog;
8+
} else {
9+
globals.engine.selector = Selector::TermOnly;
10+
}
11+
12+
if globals.engine.job_name == 0 {
13+
rs_open_log_file(globals);
14+
}
15+
16+
if globals.engine.interaction == InteractionMode::Batch {
17+
globals.engine.selector = match globals.engine.selector {
18+
Selector::TermAndLog => Selector::LogOnly,
19+
Selector::TermOnly => Selector::NoPrint,
20+
_ => panic!(),
21+
}
22+
}
23+
24+
rs_error_here_with_diagnostic(globals, b"");
25+
}
26+
27+
#[no_mangle]
28+
extern "C" fn pre_error_message() {
29+
Globals::with(|globals| rs_pre_error_message(globals))
30+
}

crates/engine_xetex/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ pub mod c_api {
237237
use tectonic_bridge_core::CoreBridgeState;
238238

239239
mod engine;
240+
mod errors;
240241
mod globals;
241242
mod hash;
242243
mod inputs;

crates/engine_xetex/xetex/xetex-errors.c

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,14 @@
1111

1212
/* WEBby error-handling code: */
1313

14-
static void
15-
pre_error_message (void)
16-
{
17-
/* FKA normalize_selector(): */
18-
19-
if (log_opened())
20-
set_selector(SELECTOR_TERM_AND_LOG);
21-
else
22-
set_selector(SELECTOR_TERM_ONLY);
23-
24-
if (job_name() == 0)
25-
open_log_file();
26-
27-
if (interaction == BATCH_MODE)
28-
set_selector(selector()-1);
29-
30-
error_here_with_diagnostic("");
31-
}
32-
33-
3414
/*82: */
3515
static void
3616
post_error_message(int need_to_print_it)
3717
{
3818
capture_to_diagnostic(NULL);
3919

40-
if (interaction == ERROR_STOP_MODE)
41-
interaction = SCROLL_MODE;
20+
if (interaction() == ERROR_STOP_MODE)
21+
set_interaction(SCROLL_MODE);
4222

4323
if (need_to_print_it && log_opened())
4424
error();
@@ -76,7 +56,7 @@ error(void)
7656
_tt_abort("halted after 100 potentially-recoverable errors");
7757
}
7858

79-
if (interaction > BATCH_MODE)
59+
if (interaction() > BATCH_MODE)
8060
set_selector(selector()-1);
8161

8262
if (use_err_help) {
@@ -90,7 +70,7 @@ error(void)
9070
}
9171

9272
print_ln();
93-
if (interaction > BATCH_MODE)
73+
if (interaction() > BATCH_MODE)
9474
set_selector(selector()+1);
9575
print_ln();
9676
}

crates/engine_xetex/xetex/xetex-ini.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ UTF16_code *native_text;
5151
int32_t native_text_size;
5252
int32_t native_len;
5353
int32_t save_native_len;
54-
unsigned char interaction;
5554
bool deletions_allowed;
5655
bool set_box_allowed;
5756
tt_history_t history;
@@ -2053,8 +2052,8 @@ store_fmt_file(void)
20532052
help_ptr = 1;
20542053
help_line[0] = "`{...\\dump}' is a no-no.";
20552054

2056-
if (interaction == ERROR_STOP_MODE)
2057-
interaction = SCROLL_MODE;
2055+
if (interaction() == ERROR_STOP_MODE)
2056+
set_interaction(SCROLL_MODE);
20582057
if (log_opened())
20592058
error();
20602059

@@ -2075,7 +2074,7 @@ store_fmt_file(void)
20752074
print_int(INTPAR(day));
20762075
print_char(')');
20772076

2078-
if (interaction == BATCH_MODE)
2077+
if (interaction() == BATCH_MODE)
20792078
set_selector(SELECTOR_LOG_ONLY);
20802079
else
20812080
set_selector(SELECTOR_TERM_AND_LOG);
@@ -2939,7 +2938,7 @@ final_cleanup(void)
29392938
}
29402939

29412940
if (history != HISTORY_SPOTLESS) {
2942-
if ((history == HISTORY_WARNING_ISSUED || (interaction < ERROR_STOP_MODE))) {
2941+
if ((history == HISTORY_WARNING_ISSUED || (interaction() < ERROR_STOP_MODE))) {
29432942

29442943
if (selector() == SELECTOR_TERM_AND_LOG) {
29452944
set_selector(SELECTOR_TERM_ONLY);
@@ -3018,7 +3017,7 @@ initialize_more_variables(void)
30183017
native_text_size = 128;
30193018
native_text = xmalloc(native_text_size * sizeof(UTF16_code));
30203019

3021-
interaction = ERROR_STOP_MODE;
3020+
set_interaction(ERROR_STOP_MODE);
30223021

30233022
deletions_allowed = true;
30243023
set_box_allowed = true;
@@ -3815,7 +3814,7 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d
38153814
random_seed = (microseconds * 1000) + (epochseconds % 1000000L);
38163815
init_randoms(random_seed);
38173816

3818-
if (interaction == BATCH_MODE)
3817+
if (interaction() == BATCH_MODE)
38193818
set_selector(SELECTOR_NO_PRINT);
38203819
else
38213820
set_selector(SELECTOR_TERM_ONLY); /*:79*/

crates/engine_xetex/xetex/xetex-xetex0.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7306,7 +7306,7 @@ scan_something_internal(small_number level, bool negative)
73067306
if (m == 0)
73077307
cur_val = dead_cycles;
73087308
else if (m == 2)
7309-
cur_val = interaction;
7309+
cur_val = interaction();
73107310
else
73117311
cur_val = insert_penalties;
73127312
cur_val_level = INT_VAL;
@@ -15928,8 +15928,8 @@ void new_font(small_number a)
1592815928
void new_interaction(void)
1592915929
{
1593015930
print_ln();
15931-
interaction = cur_chr;
15932-
if (interaction == BATCH_MODE)
15931+
set_interaction(cur_chr);
15932+
if (interaction() == BATCH_MODE)
1593315933
set_selector(SELECTOR_NO_PRINT);
1593415934
else
1593515935
set_selector(SELECTOR_TERM_ONLY);
@@ -15974,7 +15974,7 @@ void issue_message(void)
1597415974
help_line[0] = "(That was another \\errmessage.)";
1597515975
} else {
1597615976

15977-
if (interaction < ERROR_STOP_MODE)
15977+
if (interaction() < ERROR_STOP_MODE)
1597815978
long_help_seen = true;
1597915979
{
1598015980
help_ptr = 4;
@@ -16151,7 +16151,7 @@ void show_whatever(void)
1615116151

1615216152
common_ending:
1615316153
capture_to_diagnostic(NULL); // calling with null twice is fine
16154-
if (interaction < ERROR_STOP_MODE) {
16154+
if (interaction() < ERROR_STOP_MODE) {
1615516155
help_ptr = 0;
1615616156
error_count--;
1615716157
} else if (INTPAR(tracing_online) > 0) {

crates/engine_xetex/xetex/xetex-xetexd.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ extern UTF16_code *native_text;
411411
extern int32_t native_text_size;
412412
extern int32_t native_len;
413413
extern int32_t save_native_len;
414-
extern unsigned char interaction;
415414
extern bool deletions_allowed;
416415
extern bool set_box_allowed;
417416
extern tt_history_t history;

crates/engine_xetex/xetex/xetex_bindings.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ input_state_t *cur_input_ptr(void);
250250

251251
void set_cur_input(input_state_t val);
252252

253+
uint8_t interaction(void);
254+
255+
void set_interaction(uint8_t val);
256+
253257
MemoryWord eqtb(uintptr_t idx);
254258

255259
void set_eqtb(uintptr_t idx, MemoryWord val);
@@ -304,6 +308,10 @@ bool more_name(uint16_t c);
304308

305309
StrNumber make_name_string(void);
306310

311+
void open_log_file(void);
312+
313+
void pre_error_message(void);
314+
307315
void resize_hash(uintptr_t len);
308316

309317
B32x2 hash(uintptr_t idx);

0 commit comments

Comments
 (0)