Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
d8991f7
Port everything from scaledmath except m_log due to diagnostic depend…
CraftSpider Aug 8, 2025
440eb2b
Begin work on output, including moving some file context to Rust
CraftSpider Aug 8, 2025
bcdcb8a
Port capture_to_diagnostic
CraftSpider Aug 8, 2025
3dbba00
Clippy scaled_math
CraftSpider Aug 10, 2025
29c3ca4
Clippy rest
CraftSpider Aug 10, 2025
03508c9
Port warn_char
CraftSpider Aug 10, 2025
0fc9ad2
Port diagnostic_begin_capture_warning_here
CraftSpider Aug 10, 2025
b327601
Port selector variable
CraftSpider Aug 11, 2025
ac23c7b
Port term_offset and file_offset and variable
CraftSpider Aug 11, 2025
04baec8
Port rust_stdout and log_file variables
CraftSpider Aug 11, 2025
970fc31
Port print_ln fn and write_file variable
CraftSpider Aug 11, 2025
89c70f3
Fix file error
CraftSpider Aug 11, 2025
1964647
Port string pool variables to Rust
CraftSpider Aug 11, 2025
f4a0f8b
Port pool_size variable
CraftSpider Aug 11, 2025
670796a
Port tally variable
CraftSpider Aug 11, 2025
cf845dd
Port error_line and trick_count variable
CraftSpider Aug 11, 2025
6aafdae
Port trick_buf variable to Rust
CraftSpider Aug 12, 2025
71e3144
Port print_raw_char
CraftSpider Aug 12, 2025
2f44e45
Port doing_special variable
CraftSpider Aug 12, 2025
9f4e141
Port eqtb variable
CraftSpider Aug 12, 2025
81ada72
Port print_char
CraftSpider Aug 12, 2025
215e45b
Port print_*cstr functions
CraftSpider Aug 12, 2025
c7e4909
Fix print_char
CraftSpider Aug 14, 2025
7c9384b
Port dig variable
CraftSpider Aug 14, 2025
52586bf
Port print_the_digs
CraftSpider Aug 14, 2025
e1bd284
Port print, print_nl, and print_esc
CraftSpider Aug 14, 2025
8c46851
Port gettexstring, shift to using single globals context
CraftSpider Aug 14, 2025
46b2b10
Port print_int
CraftSpider Aug 14, 2025
70e9e07
Port print_file_line
CraftSpider Aug 14, 2025
f12ceb3
Port error_here_with_diagnostic
CraftSpider Aug 14, 2025
6959c1d
Port hash variables to Rust
CraftSpider Aug 15, 2025
6088a81
Port prim variable
CraftSpider Aug 18, 2025
d089bbc
Port print_cs
CraftSpider Aug 18, 2025
9ab6638
Port sprint_cs
CraftSpider Aug 18, 2025
b502e0a
Port print_file_name
CraftSpider Aug 18, 2025
0bb6661
Port print_size
CraftSpider Aug 18, 2025
0894324
Port mem variable
CraftSpider Aug 19, 2025
4290774
Port print_native_word, begin converting mem to use node structs inst…
CraftSpider Aug 19, 2025
6e9ef79
Port print_sa_num
CraftSpider Aug 20, 2025
1380683
Port print_two, print_hex, print_scaled, print_ucs_code
CraftSpider Aug 20, 2025
775bf85
Port print_current_string
CraftSpider Aug 20, 2025
c350f4a
Port print_roman_int
CraftSpider Aug 20, 2025
8cc9a67
Port make_string
CraftSpider Aug 20, 2025
4a3534a
Port maketexstring
CraftSpider Aug 22, 2025
88b7f26
Port pack_file_name
CraftSpider Aug 22, 2025
6ea364a
Port cur_name, cur_area, cur_ext, and job_name
CraftSpider Aug 22, 2025
049b5f4
Port pack_job_name
CraftSpider Aug 22, 2025
d0e6d82
Port name_of_file16 and name_length16
CraftSpider Aug 25, 2025
5b689e3
Port make_utf16_name
CraftSpider Aug 25, 2025
4c58cd0
Port area_delimiter, ext_delimiter, name_in_progress, and stop_at_spa…
CraftSpider Aug 25, 2025
993501c
Port file_name_quote_char and quoted_filename
CraftSpider Aug 25, 2025
04d5878
Port length, str_eq_str, and search_string
CraftSpider Aug 25, 2025
6d3e76a
Port slow_make_string
CraftSpider Aug 25, 2025
3f809e4
Port begin_name and end_name
CraftSpider Aug 26, 2025
4b50d75
Port more_name and make_name_string
CraftSpider Aug 26, 2025
270cc6a
Port texmf_log_name, log_opened, input_stack, and buffer variables
CraftSpider Aug 26, 2025
d817ea8
Port input_ptr and cur_input variable
CraftSpider Aug 26, 2025
5f522ad
Port open_log_file
CraftSpider Aug 26, 2025
34e0b40
Port interaction variable and pre_error_message
CraftSpider Aug 26, 2025
981dfce
Port history variable
CraftSpider Oct 24, 2025
64795a7
Port dvi_* variables
CraftSpider Oct 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 38 additions & 11 deletions crates/bridge_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,12 @@ impl<'a> CoreBridgeState<'a> {
true
}
}

/// Finish and emit a diagnostic
pub fn finish_diagnostic(&mut self, diag: Diagnostic) {
self.status
.report(diag.kind, format_args!("{}", diag.message), None);
}
}

/// A type for storing settings about potentially insecure engine features.
Expand Down Expand Up @@ -1250,23 +1256,45 @@ pub struct Diagnostic {
kind: MessageKind,
}

impl Diagnostic {
/// Create a new diagnostic that will be reported as an error.
pub fn error() -> Diagnostic {
Diagnostic {
message: String::new(),
kind: MessageKind::Error,
}
}

/// Create a new diagnostic that will be reported as a warning.
pub fn warning() -> Diagnostic {
Diagnostic {
message: String::new(),
kind: MessageKind::Warning,
}
}

/// Append text to a diagnostic.
pub fn append(&mut self, msg: impl AsRef<str>) {
self.message.push_str(msg.as_ref());
}

/// Append a single character to a diagnostic
pub fn append_char(&mut self, c: char) {
self.message.push(c);
}
}

/// Create a new diagnostic that will be reported as a warning.
#[no_mangle]
pub extern "C" fn ttbc_diag_begin_warning() -> *mut Diagnostic {
let warning = Box::new(Diagnostic {
message: String::new(),
kind: MessageKind::Warning,
});
let warning = Box::new(Diagnostic::error());
Box::into_raw(warning)
}

/// Create a new diagnostic that will be reported as an error.
#[no_mangle]
pub extern "C" fn ttbc_diag_begin_error() -> *mut Diagnostic {
let warning = Box::new(Diagnostic {
message: String::new(),
kind: MessageKind::Error,
});
let warning = Box::new(Diagnostic::error());
Box::into_raw(warning)
}

Expand All @@ -1278,7 +1306,7 @@ pub extern "C" fn ttbc_diag_begin_error() -> *mut Diagnostic {
#[no_mangle]
pub unsafe extern "C" fn ttbc_diag_append(diag: &mut Diagnostic, text: *const libc::c_char) {
let rtext = CStr::from_ptr(text);
diag.message.push_str(&rtext.to_string_lossy());
diag.append(rtext.to_string_lossy());
}

/// "Finish" a diagnostic: report it to the driver and free the diagnostic object.
Expand All @@ -1290,8 +1318,7 @@ pub unsafe extern "C" fn ttbc_diag_append(diag: &mut Diagnostic, text: *const li
pub unsafe extern "C" fn ttbc_diag_finish(es: &mut CoreBridgeState, diag: *mut Diagnostic) {
// By creating the box, we will free the diagnostic when this function exits.
let rdiag = Box::from_raw(diag);
es.status
.report(rdiag.kind, format_args!("{}", rdiag.message), None);
es.finish_diagnostic(*rdiag);
}

/// Run a shell command
Expand Down
1 change: 0 additions & 1 deletion crates/engine_xetex/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ const C_FILES: &[&str] = &[
"xetex/xetex-io.c",
"xetex/xetex-linebreak.c",
"xetex/xetex-math.c",
"xetex/xetex-output.c",
"xetex/xetex-pagebuilder.c",
"xetex/xetex-pic.c",
"xetex/xetex-scaledmath.c",
Expand Down
10 changes: 10 additions & 0 deletions crates/engine_xetex/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ include_guard = "TECTONIC_ENGINE_XETEX_BINDGEN_H"

[export.rename]
"CoreBridgeState" = "ttbc_state_t"
"Diagnostic" = "ttbc_diagnostic_t"
"FileFormat" = "ttbc_file_format"
"OutputId" = "rust_output_handle_t"
"InputState" = "input_state_t"

[export]
exclude = ["Option_OutputId", "Option_InputId"]

[defines]
"target_endian = big" = "WORDS_BIGENDIAN"

[enum]
prefix_with_name = true
104 changes: 104 additions & 0 deletions crates/engine_xetex/src/c_api/dvi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
use std::cell::RefCell;
use std::ptr;
use tectonic_bridge_core::OutputId;

thread_local! {
pub static DVI_CTX: RefCell<DviCtx> = const { RefCell::new(DviCtx::new()) }
}

pub struct DviCtx {
file: Option<OutputId>,
limit: i32,
ptr: i32,
offset: i32,
gone: i32,
buf: Vec<u8>,
}

impl DviCtx {
const fn new() -> DviCtx {
DviCtx {
file: None,
limit: 0,
ptr: 0,
offset: 0,
gone: 0,
buf: Vec::new(),
}
}
}

#[no_mangle]
pub extern "C" fn dvi_file() -> OutputId {
DVI_CTX.with_borrow(|dvi| dvi.file.unwrap())
}

#[no_mangle]
pub extern "C" fn set_dvi_file(file: OutputId) {
DVI_CTX.with_borrow_mut(|dvi| dvi.file = Some(file))
}

#[no_mangle]
pub extern "C" fn dvi_limit() -> i32 {
DVI_CTX.with_borrow(|dvi| dvi.limit)
}

#[no_mangle]
pub extern "C" fn set_dvi_limit(val: i32) {
DVI_CTX.with_borrow_mut(|dvi| dvi.limit = val)
}

#[no_mangle]
pub extern "C" fn dvi_ptr() -> i32 {
DVI_CTX.with_borrow(|dvi| dvi.ptr)
}

#[no_mangle]
pub extern "C" fn set_dvi_ptr(val: i32) {
DVI_CTX.with_borrow_mut(|dvi| dvi.ptr = val)
}

#[no_mangle]
pub extern "C" fn dvi_offset() -> i32 {
DVI_CTX.with_borrow(|dvi| dvi.offset)
}

#[no_mangle]
pub extern "C" fn set_dvi_offset(val: i32) {
DVI_CTX.with_borrow_mut(|dvi| dvi.offset = val)
}

#[no_mangle]
pub extern "C" fn dvi_gone() -> i32 {
DVI_CTX.with_borrow(|dvi| dvi.gone)
}

#[no_mangle]
pub extern "C" fn set_dvi_gone(val: i32) {
DVI_CTX.with_borrow_mut(|dvi| dvi.gone = val)
}

#[no_mangle]
pub extern "C" fn dvi_buf(idx: usize) -> u8 {
DVI_CTX.with_borrow(|engine| engine.buf[idx])
}

#[no_mangle]
pub extern "C" fn set_dvi_buf(idx: usize, val: u8) {
DVI_CTX.with_borrow_mut(|engine| engine.buf[idx] = val)
}

#[no_mangle]
pub extern "C" fn dvi_buf_ptr(idx: usize) -> *mut u8 {
DVI_CTX.with_borrow_mut(|engine| ptr::from_mut(&mut engine.buf[idx]))
}

#[no_mangle]
pub extern "C" fn resize_dvi_buf(len: usize) {
DVI_CTX.with_borrow_mut(|engine| engine.buf.resize(len, 0))
}

#[no_mangle]
pub extern "C" fn clear_dvi_buf() {
DVI_CTX.with_borrow_mut(|engine| engine.buf.clear())
}
Loading
Loading