Skip to content

Commit 981dfce

Browse files
committed
Port history variable
1 parent 34e0b40 commit 981dfce

File tree

6 files changed

+67
-23
lines changed

6 files changed

+67
-23
lines changed

crates/engine_xetex/src/c_api/engine.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub struct EngineCtx {
5252
pub(crate) input_ptr: usize,
5353
pub(crate) cur_input: InputState,
5454
pub(crate) interaction: InteractionMode,
55+
pub(crate) history: History,
5556

5657
pub(crate) eqtb: Vec<MemoryWord>,
5758
pub(crate) prim: Box<[B32x2; PRIM_SIZE + 1]>,
@@ -105,6 +106,29 @@ struct NodeError {
105106
subty: u16,
106107
}
107108

109+
#[derive(Copy, Clone, PartialEq, Eq)]
110+
#[repr(C)]
111+
pub enum History {
112+
Spotless = 0,
113+
WarningIssued = 1,
114+
ErrorIssued = 2,
115+
FatalError = 3,
116+
}
117+
118+
impl TryFrom<u8> for History {
119+
type Error = u8;
120+
121+
fn try_from(value: u8) -> Result<Self, Self::Error> {
122+
Ok(match value {
123+
0 => History::Spotless,
124+
1 => History::WarningIssued,
125+
2 => History::ErrorIssued,
126+
3 => History::FatalError,
127+
_ => return Err(value),
128+
})
129+
}
130+
}
131+
108132
impl EngineCtx {
109133
fn new() -> EngineCtx {
110134
EngineCtx {
@@ -132,6 +156,7 @@ impl EngineCtx {
132156
input_ptr: 0,
133157
cur_input: InputState::default(),
134158
interaction: InteractionMode::Batch,
159+
history: History::Spotless,
135160

136161
eqtb: Vec::new(),
137162
prim: Box::new([B32x2 { s0: 0, s1: 0 }; PRIM_SIZE + 1]),
@@ -536,6 +561,16 @@ pub extern "C" fn set_interaction(val: u8) {
536561
.with_borrow_mut(|engine| engine.interaction = InteractionMode::try_from(val).unwrap())
537562
}
538563

564+
#[no_mangle]
565+
pub extern "C" fn history() -> History {
566+
ENGINE_CTX.with_borrow(|engine| engine.history)
567+
}
568+
569+
#[no_mangle]
570+
pub extern "C" fn set_history(val: u8) {
571+
ENGINE_CTX.with_borrow_mut(|engine| engine.history = History::try_from(val).unwrap())
572+
}
573+
539574
#[no_mangle]
540575
pub extern "C" fn eqtb(idx: usize) -> MemoryWord {
541576
ENGINE_CTX.with_borrow(|engine| engine.eqtb[idx])

crates/engine_xetex/xetex/xetex-errors.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ post_error_message(int need_to_print_it)
2323
if (need_to_print_it && log_opened())
2424
error();
2525

26-
history = HISTORY_FATAL_ERROR;
26+
set_history(HISTORY_FATAL_ERROR);
2727
close_files_and_terminate();
2828
tt_cleanup();
2929
ttstub_output_flush(rust_stdout());
@@ -33,13 +33,13 @@ post_error_message(int need_to_print_it)
3333
void
3434
error(void)
3535
{
36-
if (history < HISTORY_ERROR_ISSUED)
37-
history = HISTORY_ERROR_ISSUED;
36+
if (history() < HISTORY_ERROR_ISSUED)
37+
set_history(HISTORY_ERROR_ISSUED);
3838

3939
print_char('.');
4040
show_context();
4141
if (halt_on_error_p) {
42-
history = HISTORY_FATAL_ERROR;
42+
set_history(HISTORY_FATAL_ERROR);
4343
post_error_message(0);
4444
_tt_abort("halted on potentially-recoverable error as specified");
4545
}
@@ -51,7 +51,7 @@ error(void)
5151
error_count++;
5252
if (error_count == 100) {
5353
print_nl_cstr("(That makes 100 errors; please try again.)");
54-
history = HISTORY_FATAL_ERROR;
54+
set_history(HISTORY_FATAL_ERROR);
5555
post_error_message(0);
5656
_tt_abort("halted after 100 potentially-recoverable errors");
5757
}
@@ -115,7 +115,7 @@ confusion(const char* s)
115115
{
116116
pre_error_message();
117117

118-
if (history < HISTORY_ERROR_ISSUED) {
118+
if (history() < HISTORY_ERROR_ISSUED) {
119119
print_cstr("This can't happen (");
120120
print_cstr(s);
121121
print_char(')');

crates/engine_xetex/xetex/xetex-ini.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ int32_t native_len;
5353
int32_t save_native_len;
5454
bool deletions_allowed;
5555
bool set_box_allowed;
56-
tt_history_t history;
5756
signed char error_count;
5857
const char* help_line[6];
5958
unsigned char help_ptr;
@@ -2057,7 +2056,7 @@ store_fmt_file(void)
20572056
if (log_opened())
20582057
error();
20592058

2060-
history = HISTORY_FATAL_ERROR;
2059+
set_history(HISTORY_FATAL_ERROR);
20612060
close_files_and_terminate();
20622061
ttstub_output_flush(rust_stdout());
20632062
_tt_abort("\\dump inside a group");
@@ -2937,8 +2936,8 @@ final_cleanup(void)
29372936
free_node(temp_ptr, IF_NODE_SIZE);
29382937
}
29392938

2940-
if (history != HISTORY_SPOTLESS) {
2941-
if ((history == HISTORY_WARNING_ISSUED || (interaction() < ERROR_STOP_MODE))) {
2939+
if (history() != HISTORY_SPOTLESS) {
2940+
if ((history() == HISTORY_WARNING_ISSUED || (interaction() < ERROR_STOP_MODE))) {
29422941

29432942
if (selector() == SELECTOR_TERM_AND_LOG) {
29442943
set_selector(SELECTOR_TERM_ONLY);
@@ -3602,7 +3601,7 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d
36023601

36033602
/* Sanity-check various invariants. */
36043603

3605-
history = HISTORY_FATAL_ERROR;
3604+
set_history(HISTORY_FATAL_ERROR);
36063605
bad = 0;
36073606

36083607
if (half_error_line < 30 || half_error_line > error_line() - 15)
@@ -3712,7 +3711,7 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d
37123711

37133712
if (!in_initex_mode) {
37143713
if (!load_fmt_file())
3715-
return history;
3714+
return history();
37163715
}
37173716

37183717
if (INTPAR(end_line_char) < 0 || INTPAR(end_line_char) > BIGGEST_CHAR)
@@ -3825,12 +3824,12 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d
38253824
pdf_files_init();
38263825
synctex_init_command();
38273826
start_input(input_file_name);
3828-
history = HISTORY_SPOTLESS;
3827+
set_history(HISTORY_SPOTLESS);
38293828
main_control();
38303829
final_cleanup();
38313830
close_files_and_terminate();
38323831

38333832
tt_cleanup();
38343833

3835-
return history;
3834+
return history();
38363835
}

crates/engine_xetex/xetex/xetex-xetex0.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,8 +2110,8 @@ void begin_diagnostic(void)
21102110

21112111
if (INTPAR(tracing_online) <= 0 && selector() == SELECTOR_TERM_AND_LOG) {
21122112
set_selector(selector()-1);
2113-
if (history == HISTORY_SPOTLESS)
2114-
history = HISTORY_WARNING_ISSUED;
2113+
if (history() == HISTORY_SPOTLESS)
2114+
set_history(HISTORY_WARNING_ISSUED);
21152115
}
21162116
}
21172117

@@ -4023,8 +4023,8 @@ void group_warning(void)
40234023

40244024
if (INTPAR(tracing_nesting) > 1)
40254025
show_context();
4026-
if (history == HISTORY_SPOTLESS)
4027-
history = HISTORY_WARNING_ISSUED;
4026+
if (history() == HISTORY_SPOTLESS)
4027+
set_history(HISTORY_WARNING_ISSUED);
40284028

40294029
capture_to_diagnostic(NULL);
40304030
}
@@ -4066,8 +4066,8 @@ void if_warning(void)
40664066
show_context();
40674067

40684068
capture_to_diagnostic(NULL);
4069-
if (history == HISTORY_SPOTLESS)
4070-
history = HISTORY_WARNING_ISSUED;
4069+
if (history() == HISTORY_SPOTLESS)
4070+
set_history(HISTORY_WARNING_ISSUED);
40714071
}
40724072
}
40734073

@@ -4131,8 +4131,8 @@ void file_warning(void)
41314131
show_context();
41324132
capture_to_diagnostic(NULL);
41334133
}
4134-
if (history == HISTORY_SPOTLESS)
4135-
history = HISTORY_WARNING_ISSUED;
4134+
if (history() == HISTORY_SPOTLESS)
4135+
set_history(HISTORY_WARNING_ISSUED);
41364136
}
41374137

41384138
void delete_sa_ref(int32_t q)

crates/engine_xetex/xetex/xetex-xetexd.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ extern int32_t native_len;
413413
extern int32_t save_native_len;
414414
extern bool deletions_allowed;
415415
extern bool set_box_allowed;
416-
extern tt_history_t history;
417416
extern signed char error_count;
418417
extern const char* help_line[6];
419418
extern unsigned char help_ptr;

crates/engine_xetex/xetex/xetex_bindings.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@
6464

6565
#define TOO_BIG_CHAR 65536
6666

67+
typedef enum {
68+
History_Spotless = 0,
69+
History_WarningIssued = 1,
70+
History_ErrorIssued = 2,
71+
History_FatalError = 3,
72+
} History;
73+
6774
typedef int32_t StrNumber;
6875

6976
typedef struct {
@@ -254,6 +261,10 @@ uint8_t interaction(void);
254261

255262
void set_interaction(uint8_t val);
256263

264+
History history(void);
265+
266+
void set_history(uint8_t val);
267+
257268
MemoryWord eqtb(uintptr_t idx);
258269

259270
void set_eqtb(uintptr_t idx, MemoryWord val);

0 commit comments

Comments
 (0)