diff --git a/engine/src/bibtex.rs b/engine/src/bibtex.rs index a3d599bac..90ceff74b 100644 --- a/engine/src/bibtex.rs +++ b/engine/src/bibtex.rs @@ -1,44 +1,20 @@ -#![allow(dead_code, - mutable_transmutes, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut)] +#![allow( + dead_code, + mutable_transmutes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] +use crate::core_memory::{xmalloc, xrealloc}; use crate::{ ttstub_input_close, ttstub_input_getc, ttstub_input_open, ttstub_output_close, ttstub_output_open, ttstub_output_open_stdout, ttstub_output_putc, ttstub_output_write, }; -use libc::free; +use libc::{free, snprintf, strcpy, strlen}; extern "C" { - /* tectonic/core-bridge.h: declarations of C/C++ => Rust bridge API - Copyright 2016-2018 the Tectonic Project - Licensed under the MIT License. - */ - /* Both XeTeX and bibtex use this enum: */ - /* The weird enum values are historical and could be rationalized. But it is - * good to write them explicitly since they must be kept in sync with - * `src/engines/mod.rs`. - */ - /* quasi-hack to get the primary input */ - /* Bridge API. Keep synchronized with src/engines/mod.rs. */ - /* These functions are not meant to be used in the C/C++ code. They define the - * API that we expose to the Rust side of things. */ - /* The internal, C/C++ interface: */ - /* Global symbols that route through the global API variable. Hopefully we - * will one day eliminate all of the global state and get rid of all of - * these. */ - #[no_mangle] - fn strlen(_: *const i8) -> u64; - #[no_mangle] - fn strcpy(_: *mut i8, _: *const i8) -> *mut i8; - #[no_mangle] - fn xmalloc(size: size_t) -> *mut libc::c_void; - #[no_mangle] - fn xrealloc(old_address: *mut libc::c_void, new_size: size_t) -> *mut libc::c_void; - #[no_mangle] - fn snprintf(_: *mut i8, _: u64, _: *const i8, _: ...) -> i32; #[no_mangle] fn vsnprintf(_: *mut i8, _: u64, _: *const i8, _: ::std::ffi::VaList) -> i32; #[no_mangle] @@ -456,47 +432,14 @@ unsafe extern "C" fn putc_log(c: i32) { ttstub_output_putc(standard_output, c); } unsafe extern "C" fn puts_log(mut s: *const i8) { - let mut len: size_t = strlen(s); - ttstub_output_write(log_file, s, len); - ttstub_output_write(standard_output, s, len); + let mut len = strlen(s); + ttstub_output_write(log_file, s, len as _); + ttstub_output_write(standard_output, s, len as _); } unsafe extern "C" fn ttstub_puts(mut handle: rust_output_handle_t, mut s: *const i8) { - ttstub_output_write(handle, s, strlen(s)); -} -static mut fmt_buf: [i8; 1024] = [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -]; + ttstub_output_write(handle, s, strlen(s) as _); +} +static mut fmt_buf: [i8; 1024] = [0; 1024]; unsafe extern "C" fn printf_log(mut fmt: *const i8, mut args: ...) { let mut ap: ::std::ffi::VaListImpl; ap = args.clone(); @@ -11131,9 +11074,9 @@ unsafe extern "C" fn execute_fn(mut ex_fn_loc: hash_loc) { unsafe extern "C" fn get_the_top_level_aux_file_name(mut aux_file_name: *const i8) -> i32 { name_of_file = xmalloc( strlen(aux_file_name) - .wrapping_add(1i32 as u64) - .wrapping_add(1i32 as u64) - .wrapping_mul(::std::mem::size_of::() as u64), + .wrapping_add(1) + .wrapping_add(1) + .wrapping_mul(::std::mem::size_of::()) as _, ) as *mut u8; strcpy(name_of_file as *mut i8, aux_file_name); aux_name_length = strlen(name_of_file as *mut i8) as i32; @@ -12572,11 +12515,11 @@ unsafe extern "C" fn bst_read_command() { let mut buf: [i8; 512] = [0; 512]; snprintf( buf.as_mut_ptr(), - (::std::mem::size_of::<[i8; 512]>() as u64).wrapping_sub(1i32 as u64), + (::std::mem::size_of::<[i8; 512]>()).wrapping_sub(1) as _, b"Database file #%ld: \x00" as *const u8 as *const i8, bib_ptr as i64 + 1i32 as i64, ); - ttstub_output_write(log_file, buf.as_mut_ptr(), strlen(buf.as_mut_ptr())); + ttstub_output_write(log_file, buf.as_mut_ptr(), strlen(buf.as_mut_ptr()) as _); log_pr_bib_name(); } bib_line_num = 0i32; @@ -13376,14 +13319,14 @@ pub unsafe extern "C" fn bibtex_main(mut aux_file_name: *const i8) -> TTHistory let mut buf: [i8; 512] = [0; 512]; snprintf( buf.as_mut_ptr(), - (::std::mem::size_of::<[i8; 512]>() as u64).wrapping_sub(1i32 as u64), + (::std::mem::size_of::<[i8; 512]>()).wrapping_sub(1), b"Capacity: max_strings=%ld, hash_size=%ld, hash_prime=%ld\n\x00" as *const u8 as *const i8, max_strings as i64, hash_size as i64, hash_prime as i64, ); - ttstub_output_write(log_file, buf.as_mut_ptr(), strlen(buf.as_mut_ptr())); + ttstub_output_write(log_file, buf.as_mut_ptr(), strlen(buf.as_mut_ptr()) as _); if verbose != 0 { puts_log(b"The top-level auxiliary file: \x00" as *const u8 as *const i8); print_aux_name(); diff --git a/engine/src/lib.rs b/engine/src/lib.rs index f11140b87..95e2d578e 100644 --- a/engine/src/lib.rs +++ b/engine/src/lib.rs @@ -137,6 +137,12 @@ mod core_memory { let mut new_string: *mut i8 = xmalloc(libc::strlen(s).wrapping_add(1) as size_t) as *mut i8; libc::strcpy(new_string, s) } + + #[inline] + pub(crate) unsafe extern "C" fn mfree(ptr: *mut libc::c_void) -> *mut libc::c_void { + libc::free(ptr); + std::ptr::null_mut() + } } mod bibtex; @@ -181,8 +187,4 @@ pub(crate) unsafe extern "C" fn streq_ptr(s1: *const i8, s2: *const i8) -> bool false } -#[inline] -pub(crate) unsafe extern "C" fn mfree(ptr: *mut libc::c_void) -> *mut libc::c_void { - libc::free(ptr); - std::ptr::null_mut() -} +mod xetex_layout_engine; diff --git a/engine/src/xetex_aatfont.rs b/engine/src/xetex_aatfont.rs index 7258f9e6f..66ee6d6e7 100644 --- a/engine/src/xetex_aatfont.rs +++ b/engine/src/xetex_aatfont.rs @@ -9,7 +9,7 @@ unused_mut )] -use super::xetex_ext::GlyphBBox; +use super::xetex_layout_engine::GlyphBBox; use self::cf_prelude::*; @@ -355,68 +355,15 @@ pub mod cf_prelude { } } -extern "C" { - #[no_mangle] - fn strcmp(_: *const libc::c_char, _: *const libc::c_char) -> libc::c_int; - #[no_mangle] - fn strlen(_: *const libc::c_char) -> usize; - #[no_mangle] - fn strncmp(_: *const libc::c_char, _: *const libc::c_char, _: usize) -> libc::c_int; - #[no_mangle] - fn strdup(_: *const libc::c_char) -> *mut libc::c_char; - #[no_mangle] - fn free(_: *mut libc::c_void); - /* The internal, C/C++ interface: */ - /* Macs provide Fixed and FixedPoint */ - /* Misc */ - /* gFreeTypeLibrary is defined in xetex-XeTeXFontInst_FT2.cpp, - * also used in xetex-XeTeXFontMgr_FC.cpp and xetex-ext.c. */ - #[no_mangle] - fn xmalloc(size: usize) -> *mut libc::c_void; - #[no_mangle] - fn xcalloc(n: usize, size: usize) -> *mut libc::c_void; - #[no_mangle] - fn print_chars(string: *const u16, len: i32); - #[no_mangle] - static mut name_of_file: *mut i8; - #[no_mangle] - static mut name_length: i32; - #[no_mangle] - static mut font_area: *mut str_number; - #[no_mangle] - static mut font_layout_engine: *mut *mut libc::c_void; - #[no_mangle] - static mut font_letter_space: *mut scaled_t; - #[no_mangle] - static mut loaded_font_flags: libc::c_char; - #[no_mangle] - static mut loaded_font_letter_space: scaled_t; - #[no_mangle] - static mut native_font_type_flag: int32_t; - #[no_mangle] - fn readCommonFeatures( - feat: *const libc::c_char, - end: *const libc::c_char, - extend: *mut libc::c_float, - slant: *mut libc::c_float, - embolden: *mut libc::c_float, - letterspace: *mut libc::c_float, - rgbValue: *mut u32, - ) -> libc::c_int; - #[no_mangle] - fn font_feature_warning( - featureNameP: *const libc::c_void, - featLen: int32_t, - settingNameP: *const libc::c_void, - setLen: int32_t, - ); - #[no_mangle] - fn read_double(s: *mut *const libc::c_char) -> libc::c_double; - #[no_mangle] - fn Fix2D(f: Fixed) -> libc::c_double; - #[no_mangle] - fn D2Fix(d: libc::c_double) -> Fixed; -} +use crate::core_memory::{xcalloc, xmalloc}; +use crate::xetex_ext::{print_chars, readCommonFeatures, read_double, D2Fix, Fix2D}; +use crate::xetex_ini::memory_word; +use crate::xetex_ini::{ + font_area, font_layout_engine, font_letter_space, loaded_font_flags, loaded_font_letter_space, + name_length, name_of_file, native_font_type_flag, +}; +use crate::xetex_xetex0::font_feature_warning; +use libc::{free, strcmp, strdup, strlen, strncmp}; type int32_t = libc::c_int; type uint16_t = libc::c_ushort; pub type Boolean = libc::c_uchar; @@ -433,62 +380,6 @@ struct FixedPoint { y: Fixed, } -/* The annoying `memory_word` type. We have to make sure the byte-swapping - * that the (un)dumping routines do suffices to put things in the right place - * in memory. - * - * This set of data used to be a huge mess (see comment after the - * definitions). It is now (IMO) a lot more reasonable, but there will no - * doubt be carryover weird terminology around the code. - * - * ## ENDIANNESS (cheat sheet because I'm lame) - * - * Intel is little-endian. Say that we have a 32-bit integer stored in memory - * with `p` being a `uint8` pointer to its location. In little-endian land, - * `p[0]` is least significant byte and `p[3]` is its most significant byte. - * - * Conversely, in big-endian land, `p[0]` is its most significant byte and - * `p[3]` is its least significant byte. - * - * ## MEMORY_WORD LAYOUT - * - * Little endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [lsb......s0.......msb] [lsb......s1.......msb] - * b16: [l..s0...m] [l..s1...m] [l..s2...m] [l..s3...m] - * - * Big endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [msb......s1.......lsb] [msb......s0.......lsb] - * b16: [m..s3...l] [m..s2...l] [m..s1...l] [m...s0..l] - * - */ -pub type b32x2 = b32x2_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b32x2_le_t { - pub s0: int32_t, - pub s1: int32_t, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub union memory_word { - pub b32: b32x2, - pub b16: b16x4, - pub gr: libc::c_double, - pub ptr: *mut libc::c_void, -} -pub type b16x4 = b16x4_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b16x4_le_t { - pub s0: uint16_t, - pub s1: uint16_t, - pub s2: uint16_t, - pub s3: uint16_t, -} pub type str_number = int32_t; /* tectonic/core-strutils.h: miscellaneous C string utilities Copyright 2016-2018 the Tectonic Project @@ -497,25 +388,7 @@ pub type str_number = int32_t; /* Note that we explicitly do *not* change this on Windows. For maximum * portability, we should probably accept *either* forward or backward slashes * as directory separators. */ -#[inline] -unsafe fn strstartswith( - mut s: *const libc::c_char, - mut prefix: *const libc::c_char, -) -> *const libc::c_char { - let mut length: usize = 0; - length = strlen(prefix); - if strncmp(s, prefix, length) == 0i32 { - return s.offset(length as isize); - } - ptr::null() -} -#[inline] -unsafe fn streq_ptr(mut s1: *const libc::c_char, mut s2: *const libc::c_char) -> bool { - if !s1.is_null() && !s2.is_null() { - return strcmp(s1, s2) == 0i32; - } - false -} +use crate::{streq_ptr, strstartswith}; /* ***************************************************************************\ Part of the XeTeX typesetting system Copyright (c) 1994-2008 by SIL International @@ -626,11 +499,11 @@ pub unsafe fn do_aat_layout(mut p: *mut libc::c_void, mut justify: libc::c_int) runCount = CFArrayGetCount(glyphRuns); totalGlyphCount = CTLineGetGlyphCount(line); if totalGlyphCount > 0i32 as libc::c_long { - glyph_info = xmalloc((totalGlyphCount * 10i32 as libc::c_long) as usize); + glyph_info = xmalloc((totalGlyphCount * 10i32 as libc::c_long) as _); locations = glyph_info as *mut FixedPoint; glyphIDs = locations.offset(totalGlyphCount as isize) as *mut UInt16; glyphAdvances = - xmalloc((totalGlyphCount as usize).wrapping_mul(::std::mem::size_of::())) + xmalloc((totalGlyphCount as usize).wrapping_mul(::std::mem::size_of::()) as _) as *mut Fixed; totalGlyphCount = 0i32 as CFIndex; width = 0i32 as CGFloat; @@ -645,13 +518,13 @@ pub unsafe fn do_aat_layout(mut p: *mut libc::c_void, mut justify: libc::c_int) ) as CFBooleanRef; // TODO(jjgod): Avoid unnecessary allocation with CTRunGetFoosPtr(). let mut glyphs: *mut CGGlyph = - xmalloc((count as usize).wrapping_mul(::std::mem::size_of::() as usize)) + xmalloc((count as usize).wrapping_mul(::std::mem::size_of::()) as _) as *mut CGGlyph; let mut positions: *mut CGPoint = - xmalloc((count as usize).wrapping_mul(::std::mem::size_of::())) + xmalloc((count as usize).wrapping_mul(::std::mem::size_of::()) as _) as *mut CGPoint; let mut advances: *mut CGSize = - xmalloc((count as usize).wrapping_mul(::std::mem::size_of::())) + xmalloc((count as usize).wrapping_mul(::std::mem::size_of::()) as _) as *mut CGSize; let mut runWidth: CGFloat = CTRunGetTypographicBounds( run, @@ -1029,7 +902,8 @@ pub unsafe extern "C" fn getFileNameFromCTFont( { use std::os::unix::ffi::OsStrExt; let bytes = osstr.as_bytes(); - ret = xcalloc(bytes.len() + 1, std::mem::size_of::()) as *mut i8; + ret = + xcalloc((bytes.len() + 1) as _, std::mem::size_of::() as _) as *mut i8; for i in 0..bytes.len() { *ret.offset(i as isize) = bytes[i] as i8; } @@ -1856,7 +1730,7 @@ pub unsafe fn aat_print_font_name( if !name.is_null() { let mut len: CFIndex = CFStringGetLength(name); let mut buf: *mut UniChar = - xcalloc(len as usize, ::std::mem::size_of::()) as *mut UniChar; + xcalloc(len as _, ::std::mem::size_of::() as _) as *mut UniChar; CFStringGetCharacters(name, CFRangeMake(0i32 as CFIndex, len), buf); print_chars(buf, len as libc::c_int); free(buf as *mut libc::c_void); diff --git a/engine/src/xetex_engine_interface.rs b/engine/src/xetex_engine_interface.rs index 06b332b07..ee08e99db 100644 --- a/engine/src/xetex_engine_interface.rs +++ b/engine/src/xetex_engine_interface.rs @@ -9,18 +9,10 @@ )] use crate::streq_ptr; -extern "C" { - #[no_mangle] - fn strcmp(_: *const i8, _: *const i8) -> i32; - #[no_mangle] - static mut in_initex_mode: bool; - #[no_mangle] - static mut halt_on_error_p: i32; - #[no_mangle] - static mut synctex_enabled: i32; - #[no_mangle] - static mut semantic_pagination_enabled: bool; -} +use crate::xetex_ini::{ + halt_on_error_p, in_initex_mode, semantic_pagination_enabled, synctex_enabled, +}; + /* tectonic/core-strutils.h: miscellaneous C string utilities Copyright 2016-2018 the Tectonic Project Licensed under the MIT License. diff --git a/engine/src/xetex_errors.rs b/engine/src/xetex_errors.rs index 0b13cd0bf..97c35c0c4 100644 --- a/engine/src/xetex_errors.rs +++ b/engine/src/xetex_errors.rs @@ -1,64 +1,23 @@ -#![allow(dead_code, - mutable_transmutes, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut)] +#![allow( + dead_code, + mutable_transmutes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] use crate::ttstub_output_flush; -use crate::xetex_ini::{history, selector}; -extern "C" { - /* The internal, C/C++ interface: */ - #[no_mangle] - fn _tt_abort(format: *const i8, _: ...) -> !; - #[no_mangle] - static mut file_line_error_style_p: i32; - #[no_mangle] - static mut halt_on_error_p: i32; - #[no_mangle] - static mut rust_stdout: rust_output_handle_t; - #[no_mangle] - static mut interaction: u8; - #[no_mangle] - static mut error_count: i8; - #[no_mangle] - static mut help_line: [*const i8; 6]; - #[no_mangle] - static mut help_ptr: u8; - #[no_mangle] - static mut use_err_help: bool; - #[no_mangle] - static mut job_name: str_number; - #[no_mangle] - static mut log_opened: bool; - #[no_mangle] - fn show_context(); - #[no_mangle] - fn open_log_file(); - #[no_mangle] - fn give_err_help(); - #[no_mangle] - fn close_files_and_terminate(); - #[no_mangle] - fn print_ln(); - #[no_mangle] - fn print_nl_cstr(s: *const i8); - #[no_mangle] - fn print_char(s: i32); - #[no_mangle] - fn print_cstr(s: *const i8); - #[no_mangle] - fn print_file_line(); - #[no_mangle] - fn print_int(n: i32); - #[no_mangle] - fn print(s: i32); -} -/* tectonic/core-bridge.h: declarations of C/C++ => Rust bridge API - Copyright 2016-2018 the Tectonic Project - Licensed under the MIT License. -*/ +use crate::xetex_ini::{ + error_count, file_line_error_style_p, halt_on_error_p, help_line, help_ptr, history, + interaction, job_name, log_opened, rust_stdout, selector, use_err_help, +}; +use crate::xetex_output::{ + print, print_char, print_cstr, print_file_line, print_int, print_ln, print_nl_cstr, +}; +use crate::xetex_xetex0::{close_files_and_terminate, give_err_help, open_log_file, show_context}; +use bridge::_tt_abort; use crate::TTHistory; diff --git a/engine/src/xetex_ext.rs b/engine/src/xetex_ext.rs index 2c9e4347c..1de0df703 100644 --- a/engine/src/xetex_ext.rs +++ b/engine/src/xetex_ext.rs @@ -8,7 +8,6 @@ unused_mut )] -use crate::mfree; use crate::stub_icu as icu; use crate::stub_teckit as teckit; use crate::xetex_xetexd::print_c_string; @@ -16,19 +15,6 @@ use crate::{streq_ptr, strstartswith}; use crate::{ttstub_input_close, ttstub_input_get_size, ttstub_input_open, ttstub_input_read}; use libc::free; -#[cfg(not(target_os = "macos"))] -extern "C" { - pub type _FcPattern; -} -#[cfg(not(target_os = "macos"))] -pub type FcPattern = _FcPattern; - -/// PlatformFontRef matches C++ -#[cfg(not(target_os = "macos"))] -pub type PlatformFontRef = *mut FcPattern; -#[cfg(target_os = "macos")] -pub type PlatformFontRef = CTFontDescriptorRef; - #[cfg(target_os = "macos")] use super::xetex_aatfont as aat; #[cfg(target_os = "macos")] @@ -39,286 +25,25 @@ use super::xetex_aatfont::cf_prelude::{ CGColorGetComponents, CGColorRef, CGFloat, CTFontDescriptorRef, CTFontGetMatrix, CTFontGetSize, CTFontRef, }; +use crate::core_memory::{mfree, xcalloc, xmalloc, xrealloc, xstrdup}; +use crate::xetex_ini::memory_word; +use crate::xetex_ini::{ + depth_base, font_area, font_flags, font_info, font_layout_engine, font_letter_space, + height_base, loaded_font_design_size, loaded_font_flags, loaded_font_letter_space, + loaded_font_mapping, mapped_text, name_length, name_of_file, native_font_type_flag, param_base, + xdv_buffer, +}; +use crate::xetex_output::{print_char, print_int, print_nl, print_raw_char}; +use crate::xetex_scaledmath::xn_over_d; +use crate::xetex_texmfmp::gettexstring; +use crate::xetex_xetex0::{ + begin_diagnostic, end_diagnostic, font_feature_warning, font_mapping_warning, + get_tracing_fonts_state, +}; +use bridge::_tt_abort; -extern "C" { - pub type XeTeXFont_rec; - pub type XeTeXLayoutEngine_rec; - #[no_mangle] - fn memcpy(_: *mut libc::c_void, _: *const libc::c_void, _: u64) -> *mut libc::c_void; - #[no_mangle] - fn strcpy(_: *mut i8, _: *const i8) -> *mut i8; - #[no_mangle] - fn strncpy(_: *mut i8, _: *const i8, _: u64) -> *mut i8; - #[no_mangle] - fn strcat(_: *mut i8, _: *const i8) -> *mut i8; - #[no_mangle] - fn strcmp(_: *const i8, _: *const i8) -> i32; - #[no_mangle] - fn strncmp(_: *const i8, _: *const i8, _: u64) -> i32; - #[no_mangle] - fn strdup(_: *const i8) -> *mut i8; - #[no_mangle] - fn strstr(_: *const i8, _: *const i8) -> *mut i8; - #[no_mangle] - fn strlen(_: *const i8) -> u64; - #[no_mangle] - fn strcasecmp(_: *const i8, _: *const i8) -> i32; - /* The internal, C/C++ interface: */ - #[no_mangle] - fn _tt_abort(format: *const i8, _: ...) -> !; - /* tectonic/core-memory.h: basic dynamic memory helpers - Copyright 2016-2018 the Tectonic Project - Licensed under the MIT License. - */ - #[no_mangle] - fn xstrdup(s: *const i8) -> *mut i8; - #[no_mangle] - fn xmalloc(size: size_t) -> *mut libc::c_void; - #[no_mangle] - fn xrealloc(old_address: *mut libc::c_void, new_size: size_t) -> *mut libc::c_void; - #[no_mangle] - pub fn xcalloc(nelem: size_t, elsize: size_t) -> *mut libc::c_void; - #[no_mangle] - fn hb_tag_from_string(str: *const i8, len: i32) -> hb_tag_t; - #[no_mangle] - fn getCachedGlyphBBox(fontID: u16, glyphID: u16, bbox: *mut GlyphBBox) -> i32; - #[no_mangle] - fn cacheGlyphBBox(fontID: u16, glyphID: u16, bbox: *const GlyphBBox); - #[no_mangle] - fn get_cp_code(fontNum: i32, code: u32, side: i32) -> i32; - #[no_mangle] - fn maketexstring(s: *const i8) -> i32; - #[no_mangle] - fn getDefaultDirection(engine: XeTeXLayoutEngine) -> i32; - #[no_mangle] - fn createFont(fontRef: PlatformFontRef, pointSize: Fixed) -> XeTeXFont; - #[no_mangle] - fn getAscentAndDescent(engine: XeTeXLayoutEngine, ascent: *mut f32, descent: *mut f32); - #[no_mangle] - fn setFontLayoutDir(font: XeTeXFont, vertical: i32); - #[no_mangle] - fn layoutChars( - engine: XeTeXLayoutEngine, - chars: *mut u16, - offset: i32, - count: i32, - max: i32, - rightToLeft: bool, - ) -> i32; - #[no_mangle] - fn getPointSize(engine: XeTeXLayoutEngine) -> f32; - #[no_mangle] - fn getGlyphPositions(engine: XeTeXLayoutEngine, positions: *mut FloatPoint); - #[no_mangle] - fn getGlyphAdvances(engine: XeTeXLayoutEngine, advances: *mut f32); - #[no_mangle] - fn getGlyphs(engine: XeTeXLayoutEngine, glyphs: *mut u32); - #[no_mangle] - fn findFontByName(name: *const i8, var: *mut i8, size: f64) -> PlatformFontRef; - #[no_mangle] - fn getReqEngine() -> i8; - #[no_mangle] - fn setReqEngine(reqEngine: i8); - #[no_mangle] - fn getFullName(fontRef: PlatformFontRef) -> *const i8; - #[no_mangle] - fn getFontFilename(engine: XeTeXLayoutEngine, index: *mut u32) -> *mut i8; - #[no_mangle] - fn getDesignSize(font: XeTeXFont) -> f64; - #[no_mangle] - fn deleteFont(font: XeTeXFont); - #[no_mangle] - fn getSlant(font: XeTeXFont) -> Fixed; - #[no_mangle] - fn getFontTablePtr(font: XeTeXFont, tableTag: u32) -> *mut libc::c_void; - #[no_mangle] - fn countScripts(font: XeTeXFont) -> u32; - #[no_mangle] - fn countLanguages(font: XeTeXFont, script: hb_tag_t) -> u32; - #[no_mangle] - fn countFeatures(font: XeTeXFont, script: hb_tag_t, language: hb_tag_t) -> u32; - #[no_mangle] - fn countGlyphs(font: XeTeXFont) -> u32; - #[no_mangle] - fn getIndScript(font: XeTeXFont, index: u32) -> hb_tag_t; - #[no_mangle] - fn getIndLanguage(font: XeTeXFont, script: hb_tag_t, index: u32) -> hb_tag_t; - #[no_mangle] - fn getIndFeature(font: XeTeXFont, script: hb_tag_t, language: hb_tag_t, index: u32) - -> hb_tag_t; - #[no_mangle] - fn getGlyphWidth(font: XeTeXFont, gid: u32) -> f32; - #[no_mangle] - fn createFontFromFile(filename: *const i8, index: i32, pointSize: Fixed) -> XeTeXFont; - #[no_mangle] - fn getCapAndXHeight(engine: XeTeXLayoutEngine, capheight: *mut f32, xheight: *mut f32); - #[no_mangle] - fn getEmboldenFactor(engine: XeTeXLayoutEngine) -> f32; - #[no_mangle] - fn getSlantFactor(engine: XeTeXLayoutEngine) -> f32; - #[no_mangle] - fn getExtendFactor(engine: XeTeXLayoutEngine) -> f32; - #[no_mangle] - fn getFontRef(engine: XeTeXLayoutEngine) -> PlatformFontRef; - #[no_mangle] - fn getFont(engine: XeTeXLayoutEngine) -> XeTeXFont; - #[no_mangle] - fn deleteLayoutEngine(engine: XeTeXLayoutEngine); - #[no_mangle] - fn createLayoutEngine( - fontRef: PlatformFontRef, - font: XeTeXFont, - script: hb_tag_t, - language: *mut i8, - features: *mut hb_feature_t, - nFeatures: i32, - shapers: *mut *mut i8, - rgbValue: u32, - extend: f32, - slant: f32, - embolden: f32, - ) -> XeTeXLayoutEngine; - /* graphite interface functions... */ - #[no_mangle] - fn findGraphiteFeature( - engine: XeTeXLayoutEngine, - s: *const i8, - e: *const i8, - f: *mut hb_tag_t, - v: *mut i32, - ) -> bool; - #[no_mangle] - fn findNextGraphiteBreak() -> i32; - #[no_mangle] - fn initGraphiteBreaking(engine: XeTeXLayoutEngine, txtPtr: *const u16, txtLen: i32) -> bool; - #[no_mangle] - fn getFontCharRange(engine: XeTeXLayoutEngine, reqFirst: i32) -> i32; - #[no_mangle] - fn getGlyphName(font: XeTeXFont, gid: u16, len: *mut i32) -> *const i8; - #[no_mangle] - fn mapGlyphToIndex(engine: XeTeXLayoutEngine, glyphName: *const i8) -> i32; - #[no_mangle] - fn mapCharToGlyph(engine: XeTeXLayoutEngine, charCode: u32) -> u32; - #[no_mangle] - fn getGlyphItalCorr(engine: XeTeXLayoutEngine, glyphID: u32) -> f32; - #[no_mangle] - fn getGlyphSidebearings(engine: XeTeXLayoutEngine, glyphID: u32, lsb: *mut f32, rsb: *mut f32); - #[no_mangle] - fn getGlyphHeightDepth( - engine: XeTeXLayoutEngine, - glyphID: u32, - height: *mut f32, - depth: *mut f32, - ); - #[no_mangle] - fn getGlyphWidthFromEngine(engine: XeTeXLayoutEngine, glyphID: u32) -> f32; - #[no_mangle] - fn getGlyphBounds(engine: XeTeXLayoutEngine, glyphID: u32, bbox: *mut GlyphBBox); - #[no_mangle] - fn getRgbValue(engine: XeTeXLayoutEngine) -> u32; - #[no_mangle] - fn countGraphiteFeatures(engine: XeTeXLayoutEngine) -> u32; - #[no_mangle] - fn getGraphiteFeatureCode(engine: XeTeXLayoutEngine, index: u32) -> u32; - #[no_mangle] - fn countGraphiteFeatureSettings(engine: XeTeXLayoutEngine, feature: u32) -> u32; - #[no_mangle] - fn getGraphiteFeatureSettingCode(engine: XeTeXLayoutEngine, feature: u32, index: u32) -> u32; - #[no_mangle] - fn getGraphiteFeatureDefaultSetting(engine: XeTeXLayoutEngine, feature: u32) -> u32; - #[no_mangle] - fn getGraphiteFeatureLabel(engine: XeTeXLayoutEngine, feature: u32) -> *mut i8; - #[no_mangle] - fn getGraphiteFeatureSettingLabel( - engine: XeTeXLayoutEngine, - feature: u32, - setting: u32, - ) -> *mut i8; - #[no_mangle] - fn findGraphiteFeatureNamed(engine: XeTeXLayoutEngine, name: *const i8, namelength: i32) - -> i64; - #[no_mangle] - fn findGraphiteFeatureSettingNamed( - engine: XeTeXLayoutEngine, - feature: u32, - name: *const i8, - namelength: i32, - ) -> i64; - /* not the MS compiler, so try Metrowerks' platform macros */ - /* this seems to be needed for a gcc-mingw32 build to work... */ - /* - Create a converter object from a compiled mapping - */ - #[no_mangle] - fn gr_label_destroy(label: *mut libc::c_void); - #[no_mangle] - fn gettexstring(_: str_number) -> *mut i8; - #[no_mangle] - pub static mut name_of_file: *mut i8; - #[no_mangle] - pub static mut name_length: i32; - #[no_mangle] - static mut font_info: *mut memory_word; - #[no_mangle] - static mut font_area: *mut str_number; - #[no_mangle] - static mut font_layout_engine: *mut *mut libc::c_void; - #[no_mangle] - static mut font_flags: *mut i8; - #[no_mangle] - static mut font_letter_space: *mut scaled_t; - #[no_mangle] - static mut loaded_font_mapping: *mut libc::c_void; - #[no_mangle] - static mut loaded_font_flags: i8; - #[no_mangle] - static mut loaded_font_letter_space: scaled_t; - #[no_mangle] - static mut loaded_font_design_size: scaled_t; - #[no_mangle] - static mut mapped_text: *mut UTF16_code; - #[no_mangle] - static mut xdv_buffer: *mut i8; - #[no_mangle] - static mut height_base: *mut i32; - #[no_mangle] - static mut depth_base: *mut i32; - #[no_mangle] - static mut param_base: *mut i32; - #[no_mangle] - static mut native_font_type_flag: i32; - #[no_mangle] - fn begin_diagnostic(); - #[no_mangle] - fn end_diagnostic(blank_line: bool); - #[no_mangle] - fn font_feature_warning( - featureNameP: *const libc::c_void, - featLen: i32, - settingNameP: *const libc::c_void, - setLen: i32, - ); - #[no_mangle] - fn font_mapping_warning( - mappingNameP: *const libc::c_void, - mappingNameLen: i32, - warningType: i32, - ); - #[no_mangle] - fn get_tracing_fonts_state() -> i32; - #[no_mangle] - fn print_raw_char(s: UTF16_code, incr_offset: bool); - #[no_mangle] - fn print_char(s: i32); - #[no_mangle] - fn print_nl(s: str_number); - #[no_mangle] - fn print_int(n: i32); - /* xetex-pagebuilder */ - /* xetex-scaledmath */ - #[no_mangle] - fn xn_over_d(x: scaled_t, n: i32, d: i32) -> scaled_t; -} +use crate::xetex_layout_engine::*; +use libc::{memcpy, strcasecmp, strcat, strcpy, strdup, strlen, strncpy, strstr}; pub type __ssize_t = i64; pub type size_t = u64; @@ -327,110 +52,15 @@ pub type ssize_t = __ssize_t; use crate::TTInputFormat; pub type rust_input_handle_t = *mut libc::c_void; -pub type hb_tag_t = u32; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct hb_feature_t { - pub tag: hb_tag_t, - pub value: u32, - pub start: u32, - pub end: u32, -} -pub type scaled_t = i32; -pub type SInt32 = i32; -#[cfg(not(target_os = "macos"))] -pub type Fixed = scaled_t; -#[cfg(target_os = "macos")] -pub type Fixed = SInt32; - -#[derive(Copy, Clone)] -#[cfg_attr(not(target_os = "macos"), repr(C))] -#[cfg_attr(target_os = "macos", repr(C, packed(2)))] -pub struct FixedPoint { - pub x: Fixed, - pub y: Fixed, -} pub type Boolean = libc::c_uchar; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct FloatPoint { - pub x: f32, - pub y: f32, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub struct GlyphBBox { - pub xMin: f32, - pub yMin: f32, - pub xMax: f32, - pub yMax: f32, -} -pub type XeTeXFont = *mut XeTeXFont_rec; -pub type XeTeXLayoutEngine = *mut XeTeXLayoutEngine_rec; pub type str_number = i32; pub type UTF16_code = u16; /* 16.16 version number */ -/* The annoying `memory_word` type. We have to make sure the byte-swapping - * that the (un)dumping routines do suffices to put things in the right place - * in memory. - * - * This set of data used to be a huge mess (see comment after the - * definitions). It is now (IMO) a lot more reasonable, but there will no - * doubt be carryover weird terminology around the code. - * - * ## ENDIANNESS (cheat sheet because I'm lame) - * - * Intel is little-endian. Say that we have a 32-bit integer stored in memory - * with `p` being a `uint8` pointer to its location. In little-endian land, - * `p[0]` is least significant byte and `p[3]` is its most significant byte. - * - * Conversely, in big-endian land, `p[0]` is its most significant byte and - * `p[3]` is its least significant byte. - * - * ## MEMORY_WORD LAYOUT - * - * Little endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [lsb......s0.......msb] [lsb......s1.......msb] - * b16: [l..s0...m] [l..s1...m] [l..s2...m] [l..s3...m] - * - * Big endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [msb......s1.......lsb] [msb......s0.......lsb] - * b16: [m..s3...l] [m..s2...l] [m..s1...l] [m...s0..l] - * - */ -pub type b32x2 = b32x2_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b32x2_le_t { - pub s0: i32, - pub s1: i32, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub union memory_word { - pub b32: b32x2, - pub b16: b16x4, - pub gr: f64, - pub ptr: *mut libc::c_void, -} -pub type b16x4 = b16x4_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b16x4_le_t { - pub s0: u16, - pub s1: u16, - pub s2: u16, - pub s3: u16, -} pub type UniChar = u16; /* tectonic/core-strutils.h: miscellaneous C string utilities @@ -691,7 +321,7 @@ unsafe extern "C" fn load_mapping_file( let mut buffer: *mut i8 = xmalloc((e.wrapping_offset_from(s) as i64 + 5i32 as i64) as size_t) as *mut i8; let mut map: rust_input_handle_t = 0 as *mut libc::c_void; - strncpy(buffer, s, e.wrapping_offset_from(s) as i64 as u64); + strncpy(buffer, s, e.wrapping_offset_from(s) as usize); *buffer.offset(e.wrapping_offset_from(s) as i64 as isize) = 0_i8; strcat(buffer, b".tec\x00" as *const u8 as *const i8); map = ttstub_input_open(buffer, TTInputFormat::MISCFONTS, 0i32); @@ -1144,7 +774,7 @@ unsafe extern "C" fn loadOTfont( memcpy( language as *mut libc::c_void, cp3 as *const libc::c_void, - cp2.wrapping_offset_from(cp3) as i64 as u64, + cp2.wrapping_offset_from(cp3) as usize, ); current_block = 13857423536159756434; } @@ -1417,18 +1047,14 @@ pub unsafe extern "C" fn find_native_font( splitFontName(name, &mut var, &mut feat, &mut end, &mut index); nameString = xmalloc((var.wrapping_offset_from(name) as i64 + 1i32 as i64) as size_t) as *mut i8; - strncpy( - nameString, - name, - var.wrapping_offset_from(name) as i64 as u64, - ); + strncpy(nameString, name, var.wrapping_offset_from(name) as usize); *nameString.offset(var.wrapping_offset_from(name) as i64 as isize) = 0_i8; if feat > var { varString = xmalloc(feat.wrapping_offset_from(var) as i64 as size_t) as *mut i8; strncpy( varString, var.offset(1), - (feat.wrapping_offset_from(var) as i64 - 1i32 as i64) as u64, + (feat.wrapping_offset_from(var) as i64 - 1i32 as i64) as usize, ); *varString.offset((feat.wrapping_offset_from(var) as i64 - 1i32 as i64) as isize) = 0_i8 } @@ -1437,7 +1063,7 @@ pub unsafe extern "C" fn find_native_font( strncpy( featString, feat.offset(1), - (end.wrapping_offset_from(feat) as i64 - 1i32 as i64) as u64, + (end.wrapping_offset_from(feat) as i64 - 1i32 as i64) as usize, ); *featString.offset((end.wrapping_offset_from(feat) as i64 - 1i32 as i64) as isize) = 0_i8 } @@ -1491,14 +1117,12 @@ pub unsafe extern "C" fn find_native_font( let mut fullName: *const i8 = getFullName(fontRef); name_length = strlen(fullName) as i32; if !featString.is_null() { - name_length = (name_length as u64) - .wrapping_add(strlen(featString).wrapping_add(1i32 as u64)) - as i32 as i32 + name_length = + (name_length as usize).wrapping_add(strlen(featString).wrapping_add(1)) as _ } if !varString.is_null() { - name_length = (name_length as u64) - .wrapping_add(strlen(varString).wrapping_add(1i32 as u64)) - as i32 as i32 + name_length = + (name_length as usize).wrapping_add(strlen(varString).wrapping_add(1)) as _ } free(name_of_file as *mut libc::c_void); name_of_file = xmalloc((name_length + 1i32) as size_t) as *mut i8; @@ -1995,7 +1619,7 @@ pub unsafe extern "C" fn make_font_def(mut f: i32) -> i32 { memcpy( cp as *mut libc::c_void, filename as *const libc::c_void, - filenameLen as u64, + filenameLen as _, ); cp = cp.offset(filenameLen as i32 as isize); *(cp as *mut u32) = SWAP32(index); diff --git a/engine/src/xetex_ini.rs b/engine/src/xetex_ini.rs index 619787c8c..b64ecd216 100644 --- a/engine/src/xetex_ini.rs +++ b/engine/src/xetex_ini.rs @@ -9,262 +9,42 @@ )] use super::xetex_texmfmp::get_date_and_time; -use crate::mfree; +use crate::core_memory::{mfree, xcalloc, xmalloc}; +use crate::xetex_errors::{confusion, error, overflow}; +use crate::xetex_ext::release_font_engine; +use crate::xetex_layout_engine::{destroy_font_manager, set_cp_code}; +use crate::xetex_math::initialize_math_variables; +use crate::xetex_output::{ + print, print_char, print_cstr, print_esc, print_esc_cstr, print_file_line, print_file_name, + print_int, print_ln, print_nl, print_nl_cstr, print_scaled, +}; +use crate::xetex_pagebuilder::initialize_pagebuilder_variables; +use crate::xetex_shipout::{deinitialize_shipout_variables, initialize_shipout_variables}; +use crate::xetex_stringpool::{length, load_pool_strings, make_string}; +use crate::xetex_synctex::synctex_init_command; +use crate::xetex_texmfmp::maketexstring; +use crate::xetex_xetex0::{ + alter_aux, alter_box_dimen, alter_integer, alter_page_so_far, alter_prev_graf, back_error, + back_input, begin_diagnostic, close_files_and_terminate, delete_glue_ref, delete_token_ref, + do_marks, do_register_command, end_diagnostic, end_file_reading, end_token_list, eq_define, + eq_word_define, find_font_dimen, find_sa_element, flush_list, flush_node_list, free_node, + geq_define, geq_word_define, get_avail, get_node, get_r_token, get_token, get_x_token, gsa_def, + id_lookup, main_control, make_name_string, max_hyphenatable_length, new_font, new_interaction, + open_log_file, pack_job_name, prim_lookup, print_cmd_chr, pseudo_close, read_toks, sa_def, + scan_box, scan_char_class, scan_char_class_not_ignored, scan_char_num, scan_dimen, + scan_fifteen_bit_int, scan_font_ident, scan_glue, scan_glyph_number, scan_int, scan_keyword, + scan_left_brace, scan_math_class_int, scan_math_fam_int, scan_optional_equals, + scan_register_num, scan_toks, scan_usv_num, scan_xetex_math_char_int, show_cur_cmd_chr, + show_save_groups, start_input, trap_zero_glue, +}; use crate::{ ttstub_input_close, ttstub_input_open, ttstub_input_read, ttstub_output_close, ttstub_output_flush, ttstub_output_open, ttstub_output_open_stdout, ttstub_output_write, }; -use libc::free; -extern "C" { - #[no_mangle] - fn memset(_: *mut libc::c_void, _: i32, _: u64) -> *mut libc::c_void; - #[no_mangle] - fn strcpy(_: *mut i8, _: *const i8) -> *mut i8; - #[no_mangle] - fn strlen(_: *const i8) -> u64; - /* The internal, C/C++ interface: */ - #[no_mangle] - fn _tt_abort(format: *const i8, _: ...) -> !; - #[no_mangle] - fn xmalloc(size: size_t) -> *mut libc::c_void; - #[no_mangle] - fn xcalloc(nelem: size_t, elsize: size_t) -> *mut libc::c_void; - #[no_mangle] - fn get_avail() -> i32; - #[no_mangle] - fn flush_list(p: i32); - #[no_mangle] - fn get_node(s: i32) -> i32; - #[no_mangle] - fn free_node(p: i32, s: i32); - #[no_mangle] - fn delete_token_ref(p: i32); - #[no_mangle] - fn delete_glue_ref(p: i32); - #[no_mangle] - fn flush_node_list(p: i32); - #[no_mangle] - fn begin_diagnostic(); - #[no_mangle] - fn end_diagnostic(blank_line: bool); - #[no_mangle] - fn print_cmd_chr(cmd: u16, chr_code: i32); - #[no_mangle] - fn id_lookup(j: i32, l: i32) -> i32; - #[no_mangle] - fn prim_lookup(s: str_number) -> i32; - #[no_mangle] - fn pseudo_close(); - #[no_mangle] - fn sa_def(p: i32, e: i32); - #[no_mangle] - fn gsa_def(p: i32, e: i32); - #[no_mangle] - fn eq_define(p: i32, t: u16, e: i32); - #[no_mangle] - fn alter_page_so_far(); - #[no_mangle] - fn load_pool_strings(spare_size: i32) -> i32; - #[no_mangle] - fn alter_prev_graf(); - #[no_mangle] - fn eq_word_define(p: i32, w: i32); - #[no_mangle] - fn geq_define(p: i32, t: u16, e: i32); - #[no_mangle] - fn geq_word_define(p: i32, w: i32); - #[no_mangle] - fn show_cur_cmd_chr(); - #[no_mangle] - fn end_token_list(); - #[no_mangle] - fn back_input(); - #[no_mangle] - fn back_error(); - #[no_mangle] - fn end_file_reading(); - #[no_mangle] - fn get_token(); - #[no_mangle] - fn find_sa_element(t: small_number, n: i32, w: bool); - #[no_mangle] - fn get_x_token(); - #[no_mangle] - fn scan_left_brace(); - #[no_mangle] - fn scan_optional_equals(); - #[no_mangle] - fn scan_keyword(s: *const i8) -> bool; - #[no_mangle] - fn scan_glyph_number(f: internal_font_number); - #[no_mangle] - fn scan_char_class(); - #[no_mangle] - fn scan_char_class_not_ignored(); - #[no_mangle] - fn scan_usv_num(); - #[no_mangle] - fn scan_char_num(); - #[no_mangle] - fn scan_xetex_math_char_int(); - #[no_mangle] - fn scan_math_class_int(); - #[no_mangle] - fn scan_math_fam_int(); - #[no_mangle] - fn scan_fifteen_bit_int(); - #[no_mangle] - fn scan_register_num(); - #[no_mangle] - fn scan_font_ident(); - #[no_mangle] - fn find_font_dimen(writing: bool); - #[no_mangle] - fn scan_int(); - #[no_mangle] - fn scan_dimen(mu: bool, inf: bool, shortcut: bool); - #[no_mangle] - fn scan_glue(level: small_number); - #[no_mangle] - fn scan_toks(macro_def: bool, xpand: bool) -> i32; - #[no_mangle] - fn read_toks(n: i32, r: i32, j: i32); - #[no_mangle] - fn make_name_string() -> str_number; - #[no_mangle] - fn pack_job_name(_: *const i8); - #[no_mangle] - fn open_log_file(); - #[no_mangle] - fn start_input(primary_input_name: *const i8); - #[no_mangle] - fn max_hyphenatable_length() -> i32; - #[no_mangle] - fn overflow(s: *const i8, n: i32) -> !; - #[no_mangle] - fn show_save_groups(); - #[no_mangle] - fn do_marks(a: small_number, l: small_number, q: i32) -> bool; - #[no_mangle] - fn scan_box(box_context: i32); - #[no_mangle] - fn get_r_token(); - #[no_mangle] - fn trap_zero_glue(); - #[no_mangle] - fn do_register_command(a: small_number); - #[no_mangle] - fn destroy_font_manager(); - #[no_mangle] - fn alter_integer(); - #[no_mangle] - fn alter_box_dimen(); - #[no_mangle] - fn new_font(a: small_number); - #[no_mangle] - fn new_interaction(); - #[no_mangle] - fn confusion(s: *const i8) -> !; - #[no_mangle] - fn error(); - #[no_mangle] - fn print_cstr(s: *const i8); - #[no_mangle] - fn print_esc_cstr(s: *const i8); - #[no_mangle] - fn print_nl_cstr(s: *const i8); - #[no_mangle] - fn print_file_line(); - #[no_mangle] - fn length(s: str_number) -> i32; - #[no_mangle] - fn make_string() -> str_number; - #[no_mangle] - fn alter_aux(); - #[no_mangle] - fn print_int(n: i32); - #[no_mangle] - fn print(s: i32); - #[no_mangle] - fn print_char(s: i32); - #[no_mangle] - fn main_control(); - #[no_mangle] - fn close_files_and_terminate(); - #[no_mangle] - fn initialize_math_variables(); - #[no_mangle] - fn print_ln(); - #[no_mangle] - fn print_nl(s: str_number); - #[no_mangle] - fn print_esc(s: str_number); - #[no_mangle] - fn print_file_name(n: i32, a: i32, e: i32); - #[no_mangle] - fn print_scaled(s: scaled_t); - #[no_mangle] - fn initialize_pagebuilder_variables(); - #[no_mangle] - fn initialize_shipout_variables(); - #[no_mangle] - fn deinitialize_shipout_variables(); - #[no_mangle] - fn release_font_engine(engine: *mut libc::c_void, type_flag: i32); - #[no_mangle] - fn maketexstring(s: *const i8) -> i32; - #[no_mangle] - fn set_cp_code(fontNum: i32, code: u32, side: i32, value: i32); - /* synctex.h - - Copyright (c) 2008, 2009 jerome DOT laurens AT u-bourgogne DOT fr - - This file is part of the SyncTeX package. - - Permission is hereby granted, free of charge, to any person - obtaining a copy of this software and associated documentation - files (the "Software"), to deal in the Software without - restriction, including without limitation the rights to use, - copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following - conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. +use bridge::_tt_abort; +use dpx::dpx_pdfobj::{pdf_files_close, pdf_files_init}; +use libc::{free, memset, strcpy, strlen}; - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - OTHER DEALINGS IN THE SOFTWARE - - Acknowledgments: - ---------------- - The author received useful remarks from the pdfTeX developers, especially Hahn The Thanh, - and significant help from XeTeX developer Jonathan Kew - - Nota Bene: - ---------- - If you include or use a significant part of the synctex package into a software, - I would appreciate to be listed as contributor and see "SyncTeX" highlighted. - - Version 1 - Latest Revision: Wed Jul 1 08:17:50 UTC 2009 - - */ - /* Send this message to init the synctex command value to the command line option. - * Sending this message too early will cause a bus error. */ - #[no_mangle] - fn synctex_init_command(); - #[no_mangle] - fn pdf_files_close(); - #[no_mangle] - fn pdf_files_init(); -} pub type __ssize_t = i64; pub type uintptr_t = u64; pub type size_t = u64; @@ -13981,8 +13761,8 @@ pub unsafe extern "C" fn tt_run_engine( * main() driver routines. */ /* Get our stdout handle */ rust_stdout = ttstub_output_open_stdout(); - let mut len: size_t = strlen(dump_name); - TEX_format_default = xmalloc(len.wrapping_add(1i32 as u64)) as *mut i8; + let len = strlen(dump_name); + TEX_format_default = xmalloc(len.wrapping_add(1) as _) as *mut i8; strcpy(TEX_format_default, dump_name); format_default_length = len as i32; /* Not sure why these get custom initializations. */ @@ -14263,7 +14043,7 @@ pub unsafe extern "C" fn tt_run_engine( memset( buffer as *mut libc::c_void, 0i32, - (buf_size as u64).wrapping_mul(::std::mem::size_of::() as u64), + (buf_size as usize).wrapping_mul(::std::mem::size_of::()), ); first = 0i32; scanner_status = 0_u8; diff --git a/engine/src/xetex_io.rs b/engine/src/xetex_io.rs index 851e81bcd..917d7a01e 100644 --- a/engine/src/xetex_io.rs +++ b/engine/src/xetex_io.rs @@ -8,105 +8,28 @@ unused_mut )] +use crate::core_memory::{xcalloc, xmalloc, xstrdup}; use crate::stub_errno as errno; use crate::stub_icu as icu; use crate::stub_teckit as teckit; +use crate::xetex_ini::{ + buf_size, buffer, cur_area, cur_chr, cur_ext, cur_name, cur_val, eqtb, first, last, + max_buf_stack, name_in_progress, name_length, name_length16, name_of_file, name_of_file16, + read_file, read_open, stop_at_space, +}; +use crate::xetex_output::{print_int, print_nl}; +use crate::xetex_texmfmp::gettexstring; +use crate::xetex_xetex0::{ + bad_utf8_warning, begin_diagnostic, begin_name, end_diagnostic, end_name, + get_input_normalization_state, more_name, pack_file_name, scan_file_name, scan_four_bit_int, + scan_optional_equals, +}; use crate::xetex_xetexd::print_c_string; use crate::{ ttstub_input_close, ttstub_input_getc, ttstub_input_open, ttstub_input_open_primary, ttstub_input_seek, ttstub_input_ungetc, }; -use libc::free; - -extern "C" { - #[no_mangle] - fn strlen(_: *const i8) -> u64; - /* The internal, C/C++ interface: */ - /* tectonic/core-memory.h: basic dynamic memory helpers - Copyright 2016-2018 the Tectonic Project - Licensed under the MIT License. - */ - #[no_mangle] - fn xstrdup(s: *const i8) -> *mut i8; - #[no_mangle] - fn xmalloc(size: size_t) -> *mut libc::c_void; - #[no_mangle] - fn xcalloc(nelem: size_t, elsize: size_t) -> *mut libc::c_void; - #[no_mangle] - fn gettexstring(_: str_number) -> *mut i8; - /* Needed here for UFILE */ - /* variables! */ - /* All the following variables are defined in xetexini.c */ - #[no_mangle] - static mut eqtb: *mut memory_word; - #[no_mangle] - static mut name_of_file: *mut i8; - #[no_mangle] - static mut name_of_file16: *mut UTF16_code; - #[no_mangle] - static mut name_length: i32; - #[no_mangle] - static mut name_length16: i32; - #[no_mangle] - static mut buffer: *mut UnicodeScalar; - #[no_mangle] - static mut first: i32; - #[no_mangle] - static mut last: i32; - #[no_mangle] - static mut max_buf_stack: i32; - #[no_mangle] - static mut buf_size: i32; - #[no_mangle] - static mut cur_chr: i32; - #[no_mangle] - static mut cur_val: i32; - #[no_mangle] - static mut read_file: [*mut UFILE; 16]; - #[no_mangle] - static mut read_open: [u8; 17]; - #[no_mangle] - static mut cur_name: str_number; - #[no_mangle] - static mut cur_area: str_number; - #[no_mangle] - static mut cur_ext: str_number; - #[no_mangle] - static mut name_in_progress: bool; - /* xetex-errors */ - /* xetex-math */ - /* xetex-output */ - #[no_mangle] - fn print_nl(s: str_number); - #[no_mangle] - fn get_input_normalization_state() -> i32; - #[no_mangle] - fn bad_utf8_warning(); - #[no_mangle] - fn begin_diagnostic(); - #[no_mangle] - fn print_int(n: i32); - #[no_mangle] - fn print_char(s: i32); - #[no_mangle] - fn end_diagnostic(blank_line: bool); - #[no_mangle] - static mut stop_at_space: bool; - #[no_mangle] - fn scan_optional_equals(); - #[no_mangle] - fn scan_four_bit_int(); - #[no_mangle] - fn begin_name(); - #[no_mangle] - fn more_name(c: UTF16_code) -> bool; - #[no_mangle] - fn end_name(); - #[no_mangle] - fn pack_file_name(n: str_number, a: str_number, e: str_number); - #[no_mangle] - fn scan_file_name(); -} +use libc::{free, strlen}; use crate::*; @@ -292,62 +215,6 @@ pub const U_USING_FALLBACK_WARNING: UErrorCode = -128; pub type UTF16_code = u16; pub type UnicodeScalar = i32; pub type str_number = i32; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b32x2_le_t { - pub s0: i32, - pub s1: i32, -} -/* The annoying `memory_word` type. We have to make sure the byte-swapping - * that the (un)dumping routines do suffices to put things in the right place - * in memory. - * - * This set of data used to be a huge mess (see comment after the - * definitions). It is now (IMO) a lot more reasonable, but there will no - * doubt be carryover weird terminology around the code. - * - * ## ENDIANNESS (cheat sheet because I'm lame) - * - * Intel is little-endian. Say that we have a 32-bit integer stored in memory - * with `p` being a `uint8` pointer to its location. In little-endian land, - * `p[0]` is least significant byte and `p[3]` is its most significant byte. - * - * Conversely, in big-endian land, `p[0]` is its most significant byte and - * `p[3]` is its least significant byte. - * - * ## MEMORY_WORD LAYOUT - * - * Little endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [lsb......s0.......msb] [lsb......s1.......msb] - * b16: [l..s0...m] [l..s1...m] [l..s2...m] [l..s3...m] - * - * Big endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [msb......s1.......lsb] [msb......s0.......lsb] - * b16: [m..s3...l] [m..s2...l] [m..s1...l] [m...s0..l] - * - */ -pub type b32x2 = b32x2_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b16x4_le_t { - pub s0: u16, - pub s1: u16, - pub s2: u16, - pub s3: u16, -} -pub type b16x4 = b16x4_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub union memory_word { - pub b32: b32x2, - pub b16: b16x4, - pub gr: f64, - pub ptr: *mut libc::c_void, -} #[derive(Copy, Clone)] #[repr(C)] diff --git a/engine/src/xetex_layout_engine.rs b/engine/src/xetex_layout_engine.rs new file mode 100644 index 000000000..17743ac22 --- /dev/null +++ b/engine/src/xetex_layout_engine.rs @@ -0,0 +1,310 @@ +pub type XeTeXLayoutEngine = *mut XeTeXLayoutEngine_rec; +/// PlatformFontRef matches C++ +#[cfg(not(target_os = "macos"))] +pub type PlatformFontRef = *mut FcPattern; +#[cfg(target_os = "macos")] +use crate::xetex_aatfont::cf_prelude::CTFontDescriptorRef; +#[cfg(target_os = "macos")] +pub type PlatformFontRef = CTFontDescriptorRef; +#[derive(Copy, Clone)] +#[repr(C)] +pub struct GlyphAssembly { + pub count: u32, + pub parts: *mut hb_ot_math_glyph_part_t, +} +pub type hb_tag_t = u32; +#[derive(Copy, Clone)] +#[repr(C)] +pub struct hb_feature_t { + pub tag: hb_tag_t, + pub value: u32, + pub start: u32, + pub end: u32, +} +pub type hb_codepoint_t = u32; +pub type hb_position_t = i32; +pub type hb_ot_math_glyph_part_flags_t = u32; +pub const HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER: hb_ot_math_glyph_part_flags_t = 1; +#[derive(Copy, Clone)] +#[repr(C)] +pub struct hb_ot_math_glyph_part_t { + pub glyph: hb_codepoint_t, + pub start_connector_length: hb_position_t, + pub end_connector_length: hb_position_t, + pub full_advance: hb_position_t, + pub flags: hb_ot_math_glyph_part_flags_t, +} +#[derive(Copy, Clone)] +#[repr(C)] +pub struct GlyphBBox { + pub xMin: f32, + pub yMin: f32, + pub xMax: f32, + pub yMax: f32, +} +extern "C" { + pub type XeTeXFont_rec; + pub type XeTeXLayoutEngine_rec; + #[no_mangle] + pub fn get_ot_math_constant(f: i32, n: i32) -> i32; + #[no_mangle] + pub fn set_cp_code(fontNum: i32, code: u32, side: i32, value: i32); + #[no_mangle] + pub fn get_cp_code(fontNum: i32, code: u32, side: i32) -> i32; + #[no_mangle] + pub fn isOpenTypeMathFont(engine: XeTeXLayoutEngine) -> bool; + #[no_mangle] + pub fn usingGraphite(engine: XeTeXLayoutEngine) -> bool; + #[no_mangle] + pub fn usingOpenType(engine: XeTeXLayoutEngine) -> bool; + #[no_mangle] + pub fn terminate_font_manager(); + #[no_mangle] + pub fn destroy_font_manager(); + #[no_mangle] + pub fn get_native_mathsy_param(f: i32, n: i32) -> i32; + #[no_mangle] + pub fn get_native_mathex_param(f: i32, n: i32) -> i32; + #[no_mangle] + pub fn get_ot_math_variant(f: i32, g: i32, v: i32, adv: *mut i32, horiz: i32) -> i32; + #[no_mangle] + pub fn get_ot_assembly_ptr(f: i32, g: i32, horiz: i32) -> *mut libc::c_void; + #[no_mangle] + pub fn free_ot_assembly(a: *mut GlyphAssembly); + #[no_mangle] + pub fn get_ot_math_ital_corr(f: i32, g: i32) -> i32; + #[no_mangle] + pub fn get_ot_math_accent_pos(f: i32, g: i32) -> i32; + #[no_mangle] + pub fn get_ot_math_kern(f: i32, g: i32, sf: i32, sg: i32, cmd: i32, shift: i32) -> i32; + #[no_mangle] + pub fn ot_part_count(a: *const GlyphAssembly) -> i32; + #[no_mangle] + pub fn ot_part_glyph(a: *const GlyphAssembly, i: i32) -> i32; + #[no_mangle] + pub fn ot_part_is_extender(a: *const GlyphAssembly, i: i32) -> bool; + #[no_mangle] + pub fn ot_part_start_connector(f: i32, a: *const GlyphAssembly, i: i32) -> i32; + #[no_mangle] + pub fn ot_part_end_connector(f: i32, a: *const GlyphAssembly, i: i32) -> i32; + #[no_mangle] + pub fn ot_part_full_advance(f: i32, a: *const GlyphAssembly, i: i32) -> i32; + #[no_mangle] + pub fn ot_min_connector_overlap(f: i32) -> i32; + #[no_mangle] + pub fn hb_tag_from_string(str: *const i8, len: i32) -> hb_tag_t; + #[no_mangle] + pub fn getCachedGlyphBBox(fontID: u16, glyphID: u16, bbox: *mut GlyphBBox) -> i32; + #[no_mangle] + pub fn cacheGlyphBBox(fontID: u16, glyphID: u16, bbox: *const GlyphBBox); + #[no_mangle] + pub fn maketexstring(s: *const i8) -> i32; + #[no_mangle] + pub fn getDefaultDirection(engine: XeTeXLayoutEngine) -> i32; + #[no_mangle] + pub fn createFont(fontRef: PlatformFontRef, pointSize: Fixed) -> XeTeXFont; + #[no_mangle] + pub fn getAscentAndDescent(engine: XeTeXLayoutEngine, ascent: *mut f32, descent: *mut f32); + #[no_mangle] + pub fn setFontLayoutDir(font: XeTeXFont, vertical: i32); + #[no_mangle] + pub fn layoutChars( + engine: XeTeXLayoutEngine, + chars: *mut u16, + offset: i32, + count: i32, + max: i32, + rightToLeft: bool, + ) -> i32; + #[no_mangle] + pub fn getPointSize(engine: XeTeXLayoutEngine) -> f32; + #[no_mangle] + pub fn getGlyphPositions(engine: XeTeXLayoutEngine, positions: *mut FloatPoint); + #[no_mangle] + pub fn getGlyphAdvances(engine: XeTeXLayoutEngine, advances: *mut f32); + #[no_mangle] + pub fn getGlyphs(engine: XeTeXLayoutEngine, glyphs: *mut u32); + #[no_mangle] + pub fn findFontByName(name: *const i8, var: *mut i8, size: f64) -> PlatformFontRef; + #[no_mangle] + pub fn getReqEngine() -> i8; + #[no_mangle] + pub fn setReqEngine(reqEngine: i8); + #[no_mangle] + pub fn getFullName(fontRef: PlatformFontRef) -> *const i8; + #[no_mangle] + pub fn getFontFilename(engine: XeTeXLayoutEngine, index: *mut u32) -> *mut i8; + #[no_mangle] + pub fn getDesignSize(font: XeTeXFont) -> f64; + #[no_mangle] + pub fn deleteFont(font: XeTeXFont); + #[no_mangle] + pub fn getSlant(font: XeTeXFont) -> Fixed; + #[no_mangle] + pub fn getFontTablePtr(font: XeTeXFont, tableTag: u32) -> *mut libc::c_void; + #[no_mangle] + pub fn countScripts(font: XeTeXFont) -> u32; + #[no_mangle] + pub fn countLanguages(font: XeTeXFont, script: hb_tag_t) -> u32; + #[no_mangle] + pub fn countFeatures(font: XeTeXFont, script: hb_tag_t, language: hb_tag_t) -> u32; + #[no_mangle] + pub fn countGlyphs(font: XeTeXFont) -> u32; + #[no_mangle] + pub fn getIndScript(font: XeTeXFont, index: u32) -> hb_tag_t; + #[no_mangle] + pub fn getIndLanguage(font: XeTeXFont, script: hb_tag_t, index: u32) -> hb_tag_t; + #[no_mangle] + pub fn getIndFeature( + font: XeTeXFont, + script: hb_tag_t, + language: hb_tag_t, + index: u32, + ) -> hb_tag_t; + #[no_mangle] + pub fn getGlyphWidth(font: XeTeXFont, gid: u32) -> f32; + #[no_mangle] + pub fn createFontFromFile(filename: *const i8, index: i32, pointSize: Fixed) -> XeTeXFont; + #[no_mangle] + pub fn getCapAndXHeight(engine: XeTeXLayoutEngine, capheight: *mut f32, xheight: *mut f32); + #[no_mangle] + pub fn getEmboldenFactor(engine: XeTeXLayoutEngine) -> f32; + #[no_mangle] + pub fn getSlantFactor(engine: XeTeXLayoutEngine) -> f32; + #[no_mangle] + pub fn getExtendFactor(engine: XeTeXLayoutEngine) -> f32; + #[no_mangle] + pub fn getFontRef(engine: XeTeXLayoutEngine) -> PlatformFontRef; + #[no_mangle] + pub fn getFont(engine: XeTeXLayoutEngine) -> XeTeXFont; + #[no_mangle] + pub fn deleteLayoutEngine(engine: XeTeXLayoutEngine); + #[no_mangle] + pub fn createLayoutEngine( + fontRef: PlatformFontRef, + font: XeTeXFont, + script: hb_tag_t, + language: *mut i8, + features: *mut hb_feature_t, + nFeatures: i32, + shapers: *mut *mut i8, + rgbValue: u32, + extend: f32, + slant: f32, + embolden: f32, + ) -> XeTeXLayoutEngine; + /* graphite interface functions... */ + #[no_mangle] + pub fn findGraphiteFeature( + engine: XeTeXLayoutEngine, + s: *const i8, + e: *const i8, + f: *mut hb_tag_t, + v: *mut i32, + ) -> bool; + #[no_mangle] + pub fn findNextGraphiteBreak() -> i32; + #[no_mangle] + pub fn initGraphiteBreaking(engine: XeTeXLayoutEngine, txtPtr: *const u16, txtLen: i32) + -> bool; + #[no_mangle] + pub fn getFontCharRange(engine: XeTeXLayoutEngine, reqFirst: i32) -> i32; + #[no_mangle] + pub fn getGlyphName(font: XeTeXFont, gid: u16, len: *mut i32) -> *const i8; + #[no_mangle] + pub fn mapGlyphToIndex(engine: XeTeXLayoutEngine, glyphName: *const i8) -> i32; + #[no_mangle] + pub fn mapCharToGlyph(engine: XeTeXLayoutEngine, charCode: u32) -> u32; + #[no_mangle] + pub fn getGlyphItalCorr(engine: XeTeXLayoutEngine, glyphID: u32) -> f32; + #[no_mangle] + pub fn getGlyphSidebearings( + engine: XeTeXLayoutEngine, + glyphID: u32, + lsb: *mut f32, + rsb: *mut f32, + ); + #[no_mangle] + pub fn getGlyphHeightDepth( + engine: XeTeXLayoutEngine, + glyphID: u32, + height: *mut f32, + depth: *mut f32, + ); + #[no_mangle] + pub fn getGlyphWidthFromEngine(engine: XeTeXLayoutEngine, glyphID: u32) -> f32; + #[no_mangle] + pub fn getGlyphBounds(engine: XeTeXLayoutEngine, glyphID: u32, bbox: *mut GlyphBBox); + #[no_mangle] + pub fn getRgbValue(engine: XeTeXLayoutEngine) -> u32; + #[no_mangle] + pub fn countGraphiteFeatures(engine: XeTeXLayoutEngine) -> u32; + #[no_mangle] + pub fn getGraphiteFeatureCode(engine: XeTeXLayoutEngine, index: u32) -> u32; + #[no_mangle] + pub fn countGraphiteFeatureSettings(engine: XeTeXLayoutEngine, feature: u32) -> u32; + #[no_mangle] + pub fn getGraphiteFeatureSettingCode( + engine: XeTeXLayoutEngine, + feature: u32, + index: u32, + ) -> u32; + #[no_mangle] + pub fn getGraphiteFeatureDefaultSetting(engine: XeTeXLayoutEngine, feature: u32) -> u32; + #[no_mangle] + pub fn getGraphiteFeatureLabel(engine: XeTeXLayoutEngine, feature: u32) -> *mut i8; + #[no_mangle] + pub fn getGraphiteFeatureSettingLabel( + engine: XeTeXLayoutEngine, + feature: u32, + setting: u32, + ) -> *mut i8; + #[no_mangle] + pub fn findGraphiteFeatureNamed( + engine: XeTeXLayoutEngine, + name: *const i8, + namelength: i32, + ) -> i64; + #[no_mangle] + pub fn findGraphiteFeatureSettingNamed( + engine: XeTeXLayoutEngine, + feature: u32, + name: *const i8, + namelength: i32, + ) -> i64; + /* not the MS compiler, so try Metrowerks' platform macros */ + /* this seems to be needed for a gcc-mingw32 build to work... */ + /* + Create a converter object from a compiled mapping + */ + #[no_mangle] + pub fn gr_label_destroy(label: *mut libc::c_void); +} +pub type XeTeXFont = *mut XeTeXFont_rec; +#[cfg(not(target_os = "macos"))] +pub type Fixed = scaled_t; +#[cfg(target_os = "macos")] +pub type Fixed = SInt32; + +#[derive(Copy, Clone)] +#[cfg_attr(not(target_os = "macos"), repr(C))] +#[cfg_attr(target_os = "macos", repr(C, packed(2)))] +pub struct FixedPoint { + pub x: Fixed, + pub y: Fixed, +} +pub type scaled_t = i32; +pub type SInt32 = i32; +#[derive(Copy, Clone)] +#[repr(C)] +pub struct FloatPoint { + pub x: f32, + pub y: f32, +} + +#[cfg(not(target_os = "macos"))] +extern "C" { + pub type _FcPattern; +} +#[cfg(not(target_os = "macos"))] +pub type FcPattern = _FcPattern; diff --git a/engine/src/xetex_linebreak.rs b/engine/src/xetex_linebreak.rs index 3d1b43360..eaec59465 100644 --- a/engine/src/xetex_linebreak.rs +++ b/engine/src/xetex_linebreak.rs @@ -8,209 +8,31 @@ unused_mut )] -use crate::xetex_ini::hi_mem_min; +use crate::xetex_errors::{confusion, error, pdf_error}; +use crate::xetex_ext::measure_native_node; +use crate::xetex_ini::{ + active_width, adjust_tail, arith_error, avail, bchar_label, char_base, cur_l, cur_lang, + cur_list, cur_q, cur_r, eqtb, file_line_error_style_p, first_p, font_bchar, + font_in_short_display, font_info, global_prev_p, hc, help_line, help_ptr, hf, hi_mem_min, + hlist_stack, hlist_stack_level, hu, hyf, hyf_distance, hyf_next, hyf_num, hyph_index, + hyph_link, hyph_list, hyph_start, hyph_word, hyphen_char, hyphen_passed, init_lft, init_lig, + init_list, init_trie, just_box, kern_base, last_leftmost_char, last_rightmost_char, lft_hit, + lig_kern_base, lig_stack, ligature_present, max_hyph_char, mem, op_start, pack_begin_line, + pre_adjust_tail, rt_hit, semantic_pagination_enabled, str_pool, str_start, temp_ptr, + trie_not_ready, trie_trc, trie_trl, trie_tro, width_base, xtx_ligature_present, +}; +use crate::xetex_ini::{b16x4, memory_word}; +use crate::xetex_output::{print_cstr, print_file_line, print_nl_cstr}; +use crate::xetex_stringpool::length; +use crate::xetex_xetex0::{ + append_to_vlist, badness, char_pw, delete_glue_ref, effective_char, flush_list, + flush_node_list, fract, free_node, get_avail, get_node, hpack, max_hyphenatable_length, + new_character, new_disc, new_kern, new_lig_item, new_ligature, new_margin_kern, new_math, + new_native_character, new_native_word_node, new_param_glue, new_penalty, new_spec, pop_nest, + prev_rightmost, +}; use crate::xetex_xetexd::{is_char_node, is_non_discardable_node}; -extern "C" { - #[no_mangle] - fn measure_native_node(node: *mut libc::c_void, use_glyph_metrics: i32); - #[no_mangle] - static mut eqtb: *mut memory_word; - #[no_mangle] - static mut file_line_error_style_p: i32; - #[no_mangle] - static mut str_pool: *mut packed_UTF16_code; - #[no_mangle] - static mut str_start: *mut pool_pointer; - #[no_mangle] - static mut help_line: [*const i8; 6]; - #[no_mangle] - static mut help_ptr: u8; - #[no_mangle] - static mut arith_error: bool; - #[no_mangle] - static mut temp_ptr: i32; - #[no_mangle] - static mut mem: *mut memory_word; - #[no_mangle] - static mut avail: i32; - #[no_mangle] - static mut last_leftmost_char: i32; - #[no_mangle] - static mut last_rightmost_char: i32; - #[no_mangle] - static mut hlist_stack: [i32; 513]; - #[no_mangle] - static mut hlist_stack_level: i16; - #[no_mangle] - static mut first_p: i32; - #[no_mangle] - static mut global_prev_p: i32; - #[no_mangle] - static mut font_in_short_display: i32; - #[no_mangle] - static mut cur_list: list_state_record; - #[no_mangle] - static mut font_info: *mut memory_word; - #[no_mangle] - static mut hyphen_char: *mut i32; - #[no_mangle] - static mut bchar_label: *mut font_index; - #[no_mangle] - static mut font_bchar: *mut nine_bits; - #[no_mangle] - static mut char_base: *mut i32; - #[no_mangle] - static mut width_base: *mut i32; - #[no_mangle] - static mut lig_kern_base: *mut i32; - #[no_mangle] - static mut kern_base: *mut i32; - #[no_mangle] - static mut adjust_tail: i32; - #[no_mangle] - static mut pre_adjust_tail: i32; - #[no_mangle] - static mut pack_begin_line: i32; - #[no_mangle] - static mut just_box: i32; - #[no_mangle] - static mut active_width: [scaled_t; 7]; - #[no_mangle] - static mut hc: [i32; 4099]; - #[no_mangle] - static mut hf: internal_font_number; - #[no_mangle] - static mut hu: [i32; 4097]; - #[no_mangle] - static mut cur_lang: u8; - #[no_mangle] - static mut max_hyph_char: i32; - #[no_mangle] - static mut hyf: [u8; 4097]; - #[no_mangle] - static mut init_list: i32; - #[no_mangle] - static mut init_lig: bool; - #[no_mangle] - static mut init_lft: bool; - #[no_mangle] - static mut hyphen_passed: small_number; - #[no_mangle] - static mut cur_l: i32; - #[no_mangle] - static mut cur_r: i32; - #[no_mangle] - static mut cur_q: i32; - #[no_mangle] - static mut lig_stack: i32; - #[no_mangle] - static mut ligature_present: bool; - #[no_mangle] - static mut lft_hit: bool; - #[no_mangle] - static mut rt_hit: bool; - #[no_mangle] - static mut trie_trl: *mut trie_pointer; - #[no_mangle] - static mut trie_tro: *mut trie_pointer; - #[no_mangle] - static mut trie_trc: *mut u16; - #[no_mangle] - static mut hyf_distance: [small_number; 35112]; - #[no_mangle] - static mut hyf_num: [small_number; 35112]; - #[no_mangle] - static mut hyf_next: [trie_opcode; 35112]; - #[no_mangle] - static mut op_start: [i32; 256]; - #[no_mangle] - static mut hyph_word: *mut str_number; - #[no_mangle] - static mut hyph_list: *mut i32; - #[no_mangle] - static mut hyph_link: *mut hyph_pointer; - #[no_mangle] - static mut trie_not_ready: bool; - #[no_mangle] - static mut hyph_start: trie_pointer; - #[no_mangle] - static mut hyph_index: trie_pointer; - #[no_mangle] - static mut xtx_ligature_present: bool; - #[no_mangle] - static mut semantic_pagination_enabled: bool; - #[no_mangle] - fn badness(t: scaled_t, s: scaled_t) -> i32; - #[no_mangle] - fn get_avail() -> i32; - #[no_mangle] - fn flush_list(p: i32); - #[no_mangle] - fn get_node(s: i32) -> i32; - #[no_mangle] - fn free_node(p: i32, s: i32); - #[no_mangle] - fn new_ligature(f: internal_font_number, c: u16, q: i32) -> i32; - #[no_mangle] - fn new_lig_item(c: u16) -> i32; - #[no_mangle] - fn new_disc() -> i32; - #[no_mangle] - fn new_math(w: scaled_t, s: small_number) -> i32; - #[no_mangle] - fn new_spec(p: i32) -> i32; - #[no_mangle] - fn new_param_glue(n: small_number) -> i32; - #[no_mangle] - fn new_kern(w: scaled_t) -> i32; - #[no_mangle] - fn new_penalty(m: i32) -> i32; - #[no_mangle] - fn prev_rightmost(s: i32, e: i32) -> i32; - #[no_mangle] - fn delete_glue_ref(p: i32); - #[no_mangle] - fn flush_node_list(p: i32); - #[no_mangle] - fn pop_nest(); - #[no_mangle] - fn length(s: str_number) -> i32; - #[no_mangle] - fn init_trie(); - #[no_mangle] - fn max_hyphenatable_length() -> i32; - #[no_mangle] - fn append_to_vlist(b: i32); - #[no_mangle] - fn hpack(p: i32, w: scaled_t, m: small_number) -> i32; - #[no_mangle] - fn new_margin_kern(w: scaled_t, p: i32, side: small_number) -> i32; - #[no_mangle] - fn char_pw(p: i32, side: small_number) -> scaled_t; - #[no_mangle] - fn new_character(f: internal_font_number, c: UTF16_code) -> i32; - #[no_mangle] - fn new_native_character(f: internal_font_number, c: UnicodeScalar) -> i32; - #[no_mangle] - fn new_native_word_node(f: internal_font_number, n: i32) -> i32; - #[no_mangle] - fn fract(x: i32, n: i32, d: i32, max_answer: i32) -> i32; - #[no_mangle] - fn effective_char(err_p: bool, f: internal_font_number, c: u16) -> i32; - #[no_mangle] - fn confusion(s: *const i8) -> !; - #[no_mangle] - fn print_nl_cstr(s: *const i8); - #[no_mangle] - fn error(); - #[no_mangle] - fn print_cstr(s: *const i8); - #[no_mangle] - fn pdf_error(t: *const i8, p: *const i8) -> !; - #[no_mangle] - fn print_file_line(); -} pub type scaled_t = i32; pub type UTF16_code = u16; pub type UnicodeScalar = i32; @@ -218,47 +40,12 @@ pub type pool_pointer = i32; pub type str_number = i32; pub type packed_UTF16_code = u16; pub type small_number = i16; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b32x2_le_t { - pub s0: i32, - pub s1: i32, -} -pub type b32x2 = b32x2_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b16x4_le_t { - pub s0: u16, - pub s1: u16, - pub s2: u16, - pub s3: u16, -} -pub type b16x4 = b16x4_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub union memory_word { - pub b32: b32x2, - pub b16: b16x4, - pub gr: f64, - pub ptr: *mut libc::c_void, -} pub type internal_font_number = i32; pub type font_index = i32; pub type nine_bits = i32; pub type trie_pointer = i32; pub type trie_opcode = u16; pub type hyph_pointer = u16; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct list_state_record { - pub mode: i16, - pub head: i32, - pub tail: i32, - pub eTeX_aux: i32, - pub prev_graf: i32, - pub mode_line: i32, - pub aux: memory_word, -} static mut passive: i32 = 0; static mut cur_active_width: [scaled_t; 7] = [0; 7]; static mut background: [scaled_t; 7] = [0; 7]; diff --git a/engine/src/xetex_math.rs b/engine/src/xetex_math.rs index 6e30dff5f..8bbc6d3e6 100644 --- a/engine/src/xetex_math.rs +++ b/engine/src/xetex_math.rs @@ -8,302 +8,39 @@ unused_mut )] +use crate::xetex_errors::{confusion, error}; +use crate::xetex_ext::{map_char_to_glyph, measure_native_glyph, real_get_native_glyph}; +use crate::xetex_ini::{ + adjust_tail, avail, char_base, cur_c, cur_chr, cur_cmd, cur_dir, cur_f, cur_group, cur_i, + cur_lang, cur_list, cur_val, cur_val1, depth_base, empty, eqtb, exten_base, + file_line_error_style_p, font_area, font_bc, font_ec, font_info, font_layout_engine, + font_params, height_base, help_line, help_ptr, insert_src_special_every_math, italic_base, + just_box, kern_base, lig_kern_base, mem, nest_ptr, null_character, param_base, pre_adjust_tail, + save_ptr, save_stack, skew_char, temp_ptr, tex_remainder, total_shrink, width_base, + xtx_ligature_present, LR_problems, LR_ptr, +}; +use crate::xetex_ini::{b16x4, b16x4_le_t, memory_word}; +use crate::xetex_layout_engine::*; +use crate::xetex_linebreak::line_break; +use crate::xetex_output::{ + print, print_char, print_cstr, print_esc_cstr, print_file_line, print_int, print_nl_cstr, + print_size, +}; +use crate::xetex_pagebuilder::build_page; +use crate::xetex_scaledmath::{half, mult_and_add, tex_round, x_over_n, xn_over_d}; +use crate::xetex_xetex0::{ + append_to_vlist, back_error, back_input, begin_token_list, char_warning, copy_node_list, + delete_glue_ref, effective_char, eq_word_define, flush_node_list, free_node, get_avail, + get_node, get_token, get_x_token, group_code, hpack, insert_src_special, internal_font_number, + just_copy, just_reverse, new_character, new_choice, new_glue, new_kern, new_math, + new_native_character, new_noad, new_null_box, new_param_glue, new_penalty, new_rule, + new_skip_param, new_spec, norm_min, off_save, pop_nest, push_math, push_nest, + scan_delimiter_int, scan_dimen, scan_fifteen_bit_int, scan_keyword, scan_left_brace, scan_math, + scan_math_class_int, scan_math_fam_int, scan_usv_num, unsave, vpackage, +}; use crate::xetex_xetexd::is_char_node; -extern "C" { - pub type XeTeXLayoutEngine_rec; - #[no_mangle] - static mut eqtb: *mut memory_word; - #[no_mangle] - static mut file_line_error_style_p: i32; - #[no_mangle] - static mut insert_src_special_every_math: bool; - #[no_mangle] - static mut help_line: [*const i8; 6]; - #[no_mangle] - static mut help_ptr: u8; - #[no_mangle] - static mut tex_remainder: scaled_t; - #[no_mangle] - static mut temp_ptr: i32; - #[no_mangle] - static mut mem: *mut memory_word; - #[no_mangle] - static mut avail: i32; - #[no_mangle] - static mut nest_ptr: i32; - #[no_mangle] - static mut cur_list: list_state_record; - #[no_mangle] - static mut save_stack: *mut memory_word; - #[no_mangle] - static mut save_ptr: i32; - #[no_mangle] - static mut cur_group: group_code; - #[no_mangle] - static mut cur_cmd: eight_bits; - #[no_mangle] - static mut cur_chr: i32; - #[no_mangle] - static mut cur_val: i32; - #[no_mangle] - static mut cur_val1: i32; - #[no_mangle] - static mut font_info: *mut memory_word; - #[no_mangle] - static mut font_params: *mut font_index; - #[no_mangle] - static mut font_area: *mut str_number; - #[no_mangle] - static mut font_bc: *mut UTF16_code; - #[no_mangle] - static mut font_ec: *mut UTF16_code; - #[no_mangle] - static mut skew_char: *mut i32; - #[no_mangle] - static mut font_layout_engine: *mut *mut libc::c_void; - #[no_mangle] - static mut char_base: *mut i32; - #[no_mangle] - static mut width_base: *mut i32; - #[no_mangle] - static mut height_base: *mut i32; - #[no_mangle] - static mut depth_base: *mut i32; - #[no_mangle] - static mut italic_base: *mut i32; - #[no_mangle] - static mut lig_kern_base: *mut i32; - #[no_mangle] - static mut kern_base: *mut i32; - #[no_mangle] - static mut exten_base: *mut i32; - #[no_mangle] - static mut param_base: *mut i32; - #[no_mangle] - static mut null_character: b16x4; - #[no_mangle] - static mut total_shrink: [scaled_t; 4]; - #[no_mangle] - static mut adjust_tail: i32; - #[no_mangle] - static mut pre_adjust_tail: i32; - #[no_mangle] - static mut empty: b32x2; - #[no_mangle] - static mut cur_f: internal_font_number; - #[no_mangle] - static mut cur_c: i32; - #[no_mangle] - static mut cur_i: b16x4; - #[no_mangle] - fn usingOpenType(engine: XeTeXLayoutEngine) -> bool; - #[no_mangle] - fn isOpenTypeMathFont(engine: XeTeXLayoutEngine) -> bool; - #[no_mangle] - fn measure_native_glyph(node: *mut libc::c_void, use_glyph_metrics: i32); - #[no_mangle] - fn map_char_to_glyph(font: i32, ch: i32) -> i32; - #[no_mangle] - fn real_get_native_glyph(pNode: *mut libc::c_void, index: u32) -> u16; - #[no_mangle] - fn get_native_mathsy_param(f: i32, n: i32) -> i32; - #[no_mangle] - fn get_native_mathex_param(f: i32, n: i32) -> i32; - #[no_mangle] - fn get_ot_math_constant(f: i32, n: i32) -> i32; - #[no_mangle] - fn get_ot_math_variant(f: i32, g: i32, v: i32, adv: *mut i32, horiz: i32) -> i32; - #[no_mangle] - fn get_ot_assembly_ptr(f: i32, g: i32, horiz: i32) -> *mut libc::c_void; - #[no_mangle] - fn free_ot_assembly(a: *mut GlyphAssembly); - #[no_mangle] - fn get_ot_math_ital_corr(f: i32, g: i32) -> i32; - #[no_mangle] - fn get_ot_math_accent_pos(f: i32, g: i32) -> i32; - #[no_mangle] - fn get_ot_math_kern(f: i32, g: i32, sf: i32, sg: i32, cmd: i32, shift: i32) -> i32; - #[no_mangle] - fn ot_part_count(a: *const GlyphAssembly) -> i32; - #[no_mangle] - fn ot_part_glyph(a: *const GlyphAssembly, i: i32) -> i32; - #[no_mangle] - fn ot_part_is_extender(a: *const GlyphAssembly, i: i32) -> bool; - #[no_mangle] - fn ot_part_start_connector(f: i32, a: *const GlyphAssembly, i: i32) -> i32; - #[no_mangle] - fn ot_part_end_connector(f: i32, a: *const GlyphAssembly, i: i32) -> i32; - #[no_mangle] - fn ot_part_full_advance(f: i32, a: *const GlyphAssembly, i: i32) -> i32; - #[no_mangle] - fn ot_min_connector_overlap(f: i32) -> i32; - /*:1683*/ - /* It looks like these arrays are set up so that they can be safely indexed - * with negative indices. The underlying arrays used to be named "zzzaa" and - * "zzzbb". */ - /* the former xetexcoerce.h: */ - #[no_mangle] - fn just_reverse(p: i32); - #[no_mangle] - fn get_token(); - #[no_mangle] - fn get_x_token(); - #[no_mangle] - fn scan_left_brace(); - #[no_mangle] - fn scan_keyword(s: *const i8) -> bool; - #[no_mangle] - fn scan_usv_num(); - #[no_mangle] - fn scan_math_class_int(); - #[no_mangle] - fn scan_math_fam_int(); - #[no_mangle] - fn scan_fifteen_bit_int(); - #[no_mangle] - fn scan_delimiter_int(); - #[no_mangle] - fn effective_char(err_p: bool, f: internal_font_number, c: u16) -> i32; - #[no_mangle] - fn scan_dimen(mu: bool, inf: bool, shortcut: bool); - #[no_mangle] - fn char_warning(f: internal_font_number, c: i32); - #[no_mangle] - fn new_native_character(f: internal_font_number, c: UnicodeScalar) -> i32; - #[no_mangle] - fn new_character(f: internal_font_number, c: UTF16_code) -> i32; - #[no_mangle] - fn hpack(p: i32, w: scaled_t, m: small_number) -> i32; - #[no_mangle] - fn vpackage(p: i32, h: scaled_t, m: small_number, l: scaled_t) -> i32; - #[no_mangle] - fn append_to_vlist(b: i32); - #[no_mangle] - fn new_noad() -> i32; - #[no_mangle] - fn new_choice() -> i32; - #[no_mangle] - fn line_break(d: bool); - #[no_mangle] - fn off_save(); - #[no_mangle] - fn norm_min(h: i32) -> small_number; - #[no_mangle] - fn push_math(c: group_code); - #[no_mangle] - fn just_copy(p: i32, h: i32, t: i32); - #[no_mangle] - fn back_error(); - #[no_mangle] - fn back_input(); - #[no_mangle] - fn begin_token_list(p: i32, t: u16); - #[no_mangle] - fn unsave(); - #[no_mangle] - fn eq_word_define(p: i32, w: i32); - #[no_mangle] - static mut just_box: i32; - #[no_mangle] - static mut cur_lang: u8; - #[no_mangle] - fn pop_nest(); - #[no_mangle] - fn push_nest(); - #[no_mangle] - fn copy_node_list(p: i32) -> i32; - #[no_mangle] - fn flush_node_list(p: i32); - #[no_mangle] - fn delete_glue_ref(p: i32); - #[no_mangle] - fn new_penalty(m: i32) -> i32; - #[no_mangle] - fn new_kern(w: scaled_t) -> i32; - #[no_mangle] - fn new_skip_param(n: small_number) -> i32; - #[no_mangle] - fn new_glue(q: i32) -> i32; - #[no_mangle] - fn new_param_glue(n: small_number) -> i32; - #[no_mangle] - fn new_spec(p: i32) -> i32; - #[no_mangle] - fn new_math(w: scaled_t, s: small_number) -> i32; - #[no_mangle] - fn new_rule() -> i32; - #[no_mangle] - fn new_null_box() -> i32; - #[no_mangle] - fn free_node(p: i32, s: i32); - #[no_mangle] - fn get_node(s: i32) -> i32; - #[no_mangle] - fn get_avail() -> i32; - #[no_mangle] - static mut xtx_ligature_present: bool; - #[no_mangle] - static mut cur_dir: small_number; - #[no_mangle] - static mut LR_problems: i32; - #[no_mangle] - static mut LR_ptr: i32; - /* xetex-errors */ - #[no_mangle] - fn confusion(s: *const i8) -> !; - #[no_mangle] - fn scan_math(p: i32); - #[no_mangle] - fn insert_src_special(); - #[no_mangle] - fn error(); - #[no_mangle] - fn print_esc_cstr(s: *const i8); - #[no_mangle] - fn print_size(s: i32); - #[no_mangle] - fn print_int(n: i32); - #[no_mangle] - fn print_cstr(s: *const i8); - #[no_mangle] - fn print(s: i32); - #[no_mangle] - fn print_char(s: i32); - #[no_mangle] - fn print_nl_cstr(s: *const i8); - /* xetex-pagebuilder */ - /* xetex-scaledmath */ - #[no_mangle] - fn x_over_n(x: scaled_t, n: i32) -> scaled_t; - #[no_mangle] - fn mult_and_add(n: i32, x: scaled_t, y: scaled_t, max_answer: scaled_t) -> scaled_t; - #[no_mangle] - fn print_file_line(); - #[no_mangle] - fn half(x: i32) -> i32; - #[no_mangle] - fn tex_round(_: f64) -> i32; - #[no_mangle] - fn build_page(); - #[no_mangle] - fn xn_over_d(x: scaled_t, n: i32, d: i32) -> scaled_t; -} -pub type hb_codepoint_t = u32; -pub type hb_position_t = i32; -pub type hb_ot_math_glyph_part_flags_t = u32; -pub const HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER: hb_ot_math_glyph_part_flags_t = 1; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct hb_ot_math_glyph_part_t { - pub glyph: hb_codepoint_t, - pub start_connector_length: hb_position_t, - pub end_connector_length: hb_position_t, - pub full_advance: hb_position_t, - pub flags: hb_ot_math_glyph_part_flags_t, -} pub type scaled_t = i32; -pub type XeTeXLayoutEngine = *mut XeTeXLayoutEngine_rec; /* ***************************************************************************\ Part of the XeTeX typesetting system Copyright (c) 1994-2008 by SIL International @@ -335,55 +72,11 @@ shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the copyright holders. \****************************************************************************/ -#[derive(Copy, Clone)] -#[repr(C)] -pub struct GlyphAssembly { - pub count: u32, - pub parts: *mut hb_ot_math_glyph_part_t, -} pub type UTF16_code = u16; pub type UnicodeScalar = i32; pub type eight_bits = u8; pub type str_number = i32; pub type small_number = i16; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b32x2_le_t { - pub s0: i32, - pub s1: i32, -} -pub type b32x2 = b32x2_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b16x4_le_t { - pub s0: u16, - pub s1: u16, - pub s2: u16, - pub s3: u16, -} -pub type b16x4 = b16x4_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub union memory_word { - pub b32: b32x2, - pub b16: b16x4, - pub gr: f64, - pub ptr: *mut libc::c_void, -} -pub type group_code = u8; -pub type internal_font_number = i32; -pub type font_index = i32; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct list_state_record { - pub mode: i16, - pub head: i32, - pub tail: i32, - pub eTeX_aux: i32, - pub prev_graf: i32, - pub mode_line: i32, - pub aux: memory_word, -} static mut null_delimiter: b16x4 = b16x4 { s0: 0, s1: 0, diff --git a/engine/src/xetex_output.rs b/engine/src/xetex_output.rs index 0a4534b8a..3caceb3f9 100644 --- a/engine/src/xetex_output.rs +++ b/engine/src/xetex_output.rs @@ -1,75 +1,26 @@ -#![allow(dead_code, - mutable_transmutes, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut)] +#![allow( + dead_code, + mutable_transmutes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] -use super::xetex_ini::selector; +use super::xetex_ini::{ + dig, doing_special, eqtb, eqtb_top, error_line, file_offset, full_source_filename_stack, hash, + in_open, line, line_stack, log_file, max_print_line, mem, pool_ptr, pool_size, rust_stdout, + selector, str_pool, str_ptr, str_start, tally, term_offset, trick_buf, trick_count, write_file, +}; +use super::xetex_ini::{memory_word, Selector}; use crate::ttstub_output_putc; -extern "C" { - #[no_mangle] - fn strlen(_: *const i8) -> u64; - /* Needed here for UFILE */ - /* variables! */ - /* All the following variables are defined in xetexini.c */ - #[no_mangle] - static mut eqtb: *mut memory_word; - #[no_mangle] - static mut error_line: i32; - #[no_mangle] - static mut max_print_line: i32; - #[no_mangle] - static mut pool_size: i32; - #[no_mangle] - static mut str_pool: *mut packed_UTF16_code; - #[no_mangle] - static mut str_start: *mut pool_pointer; - #[no_mangle] - static mut pool_ptr: pool_pointer; - #[no_mangle] - static mut str_ptr: str_number; - #[no_mangle] - static mut rust_stdout: rust_output_handle_t; - #[no_mangle] - static mut log_file: rust_output_handle_t; - #[no_mangle] - static mut dig: [u8; 23]; - #[no_mangle] - static mut tally: i32; - #[no_mangle] - static mut term_offset: i32; - #[no_mangle] - static mut file_offset: i32; - #[no_mangle] - static mut trick_buf: [UTF16_code; 256]; - #[no_mangle] - static mut trick_count: i32; - #[no_mangle] - static mut doing_special: bool; - #[no_mangle] - static mut mem: *mut memory_word; - #[no_mangle] - static mut hash: *mut b32x2; - #[no_mangle] - static mut eqtb_top: i32; - #[no_mangle] - static mut in_open: i32; - #[no_mangle] - static mut line: i32; - #[no_mangle] - static mut line_stack: *mut i32; - #[no_mangle] - static mut full_source_filename_stack: *mut str_number; - #[no_mangle] - static mut write_file: [rust_output_handle_t; 16]; -} + +use libc::strlen; + pub type rust_output_handle_t = *mut libc::c_void; pub type scaled_t = i32; -use super::xetex_ini::Selector; - /* tectonic/xetex-xetexd.h -- many, many XeTeX symbol definitions Copyright 2016-2018 The Tectonic Project Licensed under the MIT License. @@ -84,62 +35,6 @@ pub type pool_pointer = i32; pub type str_number = i32; pub type packed_UTF16_code = u16; pub type small_number = i16; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b32x2_le_t { - pub s0: i32, - pub s1: i32, -} -/* The annoying `memory_word` type. We have to make sure the byte-swapping - * that the (un)dumping routines do suffices to put things in the right place - * in memory. - * - * This set of data used to be a huge mess (see comment after the - * definitions). It is now (IMO) a lot more reasonable, but there will no - * doubt be carryover weird terminology around the code. - * - * ## ENDIANNESS (cheat sheet because I'm lame) - * - * Intel is little-endian. Say that we have a 32-bit integer stored in memory - * with `p` being a `uint8` pointer to its location. In little-endian land, - * `p[0]` is least significant byte and `p[3]` is its most significant byte. - * - * Conversely, in big-endian land, `p[0]` is its most significant byte and - * `p[3]` is its least significant byte. - * - * ## MEMORY_WORD LAYOUT - * - * Little endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [lsb......s0.......msb] [lsb......s1.......msb] - * b16: [l..s0...m] [l..s1...m] [l..s2...m] [l..s3...m] - * - * Big endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [msb......s1.......lsb] [msb......s0.......lsb] - * b16: [m..s3...l] [m..s2...l] [m..s1...l] [m...s0..l] - * - */ -pub type b32x2 = b32x2_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b16x4_le_t { - pub s0: u16, - pub s1: u16, - pub s2: u16, - pub s3: u16, -} -pub type b16x4 = b16x4_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub union memory_word { - pub b32: b32x2, - pub b16: b16x4, - pub gr: f64, - pub ptr: *mut libc::c_void, -} /* xetex-output */ /* tectonic/output.c -- functions related to outputting messages * Copyright 2016 the Tectonic Project @@ -480,10 +375,8 @@ pub unsafe extern "C" fn print(mut s: i32) { } #[no_mangle] pub unsafe extern "C" fn print_cstr(mut str: *const i8) { - let mut i: u32 = 0_u32; - while (i as u64) < strlen(str) { + for i in 0..strlen(str) { print_char(*str.offset(i as isize) as i32); - i = i.wrapping_add(1) } } #[no_mangle] diff --git a/engine/src/xetex_pagebuilder.rs b/engine/src/xetex_pagebuilder.rs index 692f46b33..00d710248 100644 --- a/engine/src/xetex_pagebuilder.rs +++ b/engine/src/xetex_pagebuilder.rs @@ -8,197 +8,27 @@ unused_mut )] +use crate::xetex_errors::{confusion, error}; +use crate::xetex_ini::{ + best_height_plus_depth, cur_list, cur_mark, cur_ptr, dead_cycles, disc_ptr, eqtb, + file_line_error_style_p, help_line, help_ptr, insert_penalties, last_glue, last_kern, + last_node_type, last_penalty, line, mem, nest, nest_ptr, output_active, page_contents, + page_so_far, page_tail, sa_root, semantic_pagination_enabled, temp_ptr, +}; +use crate::xetex_output::{print_cstr, print_esc_cstr, print_file_line, print_int, print_nl_cstr}; +use crate::xetex_scaledmath::x_over_n; +use crate::xetex_shipout::ship_out; +use crate::xetex_xetex0::{ + badness, begin_token_list, box_error, delete_glue_ref, delete_token_ref, do_marks, + find_sa_element, flush_node_list, free_node, geq_word_define, get_node, new_null_box, + new_save_level, new_skip_param, new_spec, normal_paragraph, prune_page_top, push_nest, + scan_left_brace, vert_break, vpackage, +}; use crate::xetex_xetexd::is_non_discardable_node; -extern "C" { - /* Needed here for UFILE */ - /* variables! */ - /* All the following variables are defined in xetexini.c */ - #[no_mangle] - static mut eqtb: *mut memory_word; - #[no_mangle] - static mut file_line_error_style_p: i32; - #[no_mangle] - static mut help_line: [*const i8; 6]; - #[no_mangle] - static mut help_ptr: u8; - #[no_mangle] - static mut temp_ptr: i32; - #[no_mangle] - static mut mem: *mut memory_word; - #[no_mangle] - static mut nest: *mut list_state_record; - #[no_mangle] - static mut nest_ptr: i32; - #[no_mangle] - static mut cur_list: list_state_record; - #[no_mangle] - static mut line: i32; - #[no_mangle] - static mut cur_mark: [i32; 5]; - #[no_mangle] - static mut dead_cycles: i32; - #[no_mangle] - static mut best_height_plus_depth: scaled_t; - #[no_mangle] - static mut page_tail: i32; - #[no_mangle] - static mut page_contents: u8; - #[no_mangle] - static mut page_so_far: [scaled_t; 8]; - #[no_mangle] - static mut last_glue: i32; - #[no_mangle] - static mut last_penalty: i32; - #[no_mangle] - static mut last_kern: scaled_t; - #[no_mangle] - static mut last_node_type: i32; - #[no_mangle] - static mut insert_penalties: i32; - #[no_mangle] - static mut output_active: bool; - #[no_mangle] - static mut sa_root: [i32; 8]; - #[no_mangle] - static mut cur_ptr: i32; - #[no_mangle] - static mut disc_ptr: [i32; 4]; - #[no_mangle] - static mut semantic_pagination_enabled: bool; - /* the former xetexcoerce.h: */ - #[no_mangle] - fn badness(t: scaled_t, s: scaled_t) -> i32; - #[no_mangle] - fn get_node(s: i32) -> i32; - #[no_mangle] - fn free_node(p: i32, s: i32); - #[no_mangle] - fn new_null_box() -> i32; - #[no_mangle] - fn new_spec(p: i32) -> i32; - #[no_mangle] - fn new_skip_param(n: small_number) -> i32; - #[no_mangle] - fn delete_token_ref(p: i32); - #[no_mangle] - fn delete_glue_ref(p: i32); - #[no_mangle] - fn flush_node_list(p: i32); - #[no_mangle] - fn push_nest(); - #[no_mangle] - fn new_save_level(c: group_code); - #[no_mangle] - fn geq_word_define(p: i32, w: i32); - #[no_mangle] - fn begin_token_list(p: i32, t: u16); - #[no_mangle] - fn find_sa_element(t: small_number, n: i32, w: bool); - #[no_mangle] - fn scan_left_brace(); - #[no_mangle] - fn vpackage(p: i32, h: scaled_t, m: small_number, l: scaled_t) -> i32; - #[no_mangle] - fn prune_page_top(p: i32, s: bool) -> i32; - #[no_mangle] - fn vert_break(p: i32, h: scaled_t, d: scaled_t) -> i32; - #[no_mangle] - fn do_marks(a: small_number, l: small_number, q: i32) -> bool; - #[no_mangle] - fn box_error(n: eight_bits); - #[no_mangle] - fn normal_paragraph(); - #[no_mangle] - fn error(); - #[no_mangle] - fn confusion(s: *const i8) -> !; - #[no_mangle] - fn print_cstr(s: *const i8); - #[no_mangle] - fn print_nl_cstr(s: *const i8); - #[no_mangle] - fn print_esc_cstr(s: *const i8); - #[no_mangle] - fn print_int(n: i32); - #[no_mangle] - fn print_file_line(); - #[no_mangle] - fn ship_out(p: i32); - #[no_mangle] - fn x_over_n(x: scaled_t, n: i32) -> scaled_t; -} + pub type scaled_t = i32; pub type eight_bits = u8; pub type small_number = i16; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b32x2_le_t { - pub s0: i32, - pub s1: i32, -} -/* The annoying `memory_word` type. We have to make sure the byte-swapping - * that the (un)dumping routines do suffices to put things in the right place - * in memory. - * - * This set of data used to be a huge mess (see comment after the - * definitions). It is now (IMO) a lot more reasonable, but there will no - * doubt be carryover weird terminology around the code. - * - * ## ENDIANNESS (cheat sheet because I'm lame) - * - * Intel is little-endian. Say that we have a 32-bit integer stored in memory - * with `p` being a `uint8` pointer to its location. In little-endian land, - * `p[0]` is least significant byte and `p[3]` is its most significant byte. - * - * Conversely, in big-endian land, `p[0]` is its most significant byte and - * `p[3]` is its least significant byte. - * - * ## MEMORY_WORD LAYOUT - * - * Little endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [lsb......s0.......msb] [lsb......s1.......msb] - * b16: [l..s0...m] [l..s1...m] [l..s2...m] [l..s3...m] - * - * Big endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [msb......s1.......lsb] [msb......s0.......lsb] - * b16: [m..s3...l] [m..s2...l] [m..s1...l] [m...s0..l] - * - */ -pub type b32x2 = b32x2_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b16x4_le_t { - pub s0: u16, - pub s1: u16, - pub s2: u16, - pub s3: u16, -} -pub type b16x4 = b16x4_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub union memory_word { - pub b32: b32x2, - pub b16: b16x4, - pub gr: f64, - pub ptr: *mut libc::c_void, -} -/* enum: normal .. filll */ -pub type group_code = u8; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct list_state_record { - pub mode: i16, - pub head: i32, - pub tail: i32, - pub eTeX_aux: i32, - pub prev_graf: i32, - pub mode_line: i32, - pub aux: memory_word, -} /* tectonic/xetex-pagebuilder.c: the page builder Copyright 2017-2018 The Tectonic Project Licensed under the MIT License. @@ -1182,7 +1012,7 @@ unsafe extern "C" fn fire_up(mut c: i32) { .s1, 7_u16, ); - new_save_level(8i32 as group_code); + new_save_level(8); normal_paragraph(); scan_left_brace(); return; diff --git a/engine/src/xetex_pic.rs b/engine/src/xetex_pic.rs index d5c659cb0..6a8616b44 100644 --- a/engine/src/xetex_pic.rs +++ b/engine/src/xetex_pic.rs @@ -1,227 +1,37 @@ -#![allow(dead_code, - mutable_transmutes, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut)] +#![allow( + dead_code, + mutable_transmutes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] +use crate::core_memory::xstrdup; +use crate::xetex_errors::error; +use crate::xetex_ext::{D2Fix, Fix2D}; +use crate::xetex_ini::memory_word; +use crate::xetex_ini::{ + cur_area, cur_ext, cur_list, cur_name, cur_val, file_line_error_style_p, help_line, help_ptr, + mem, name_of_file, +}; +use crate::xetex_output::{ + print, print_cstr, print_file_line, print_file_name, print_nl_cstr, print_scaled, +}; +use crate::xetex_xetex0::{ + new_whatsit, pack_file_name, scan_decimal, scan_dimen, scan_file_name, scan_int, scan_keyword, +}; +use crate::TTInputFormat; use crate::{ttstub_input_close, ttstub_input_open}; -use dpx::dpx_pdfdoc::pdf_doc_get_page; +use dpx::dpx_bmpimage::{bmp_get_bbox, check_for_bmp}; +use dpx::dpx_dpxutil::{max4, min4}; +use dpx::dpx_jpegimage::{check_for_jpeg, jpeg_get_bbox}; +use dpx::dpx_pdfdoc::{pdf_doc_get_page, pdf_doc_get_page_count}; use dpx::dpx_pdfdraw::pdf_dev_transform; use dpx::dpx_pdfobj::{pdf_close, pdf_file, pdf_obj, pdf_open, pdf_release_obj}; -use libc::free; -extern "C" { - #[no_mangle] - fn memcpy(_: *mut libc::c_void, _: *const libc::c_void, _: u64) -> *mut libc::c_void; - #[no_mangle] - fn strlen(_: *const i8) -> u64; - /* tectonic/core-memory.h: basic dynamic memory helpers - Copyright 2016-2018 the Tectonic Project - Licensed under the MIT License. - */ - #[no_mangle] - fn xstrdup(s: *const i8) -> *mut i8; - #[no_mangle] - static mut name_of_file: *mut i8; - #[no_mangle] - static mut file_line_error_style_p: i32; - #[no_mangle] - static mut help_line: [*const i8; 6]; - #[no_mangle] - static mut help_ptr: u8; - #[no_mangle] - static mut mem: *mut memory_word; - #[no_mangle] - static mut cur_list: list_state_record; - #[no_mangle] - static mut cur_val: i32; - #[no_mangle] - static mut cur_name: str_number; - #[no_mangle] - static mut cur_area: str_number; - #[no_mangle] - static mut cur_ext: str_number; - #[no_mangle] - fn scan_keyword(s: *const i8) -> bool; - #[no_mangle] - fn scan_int(); - #[no_mangle] - fn scan_dimen(mu: bool, inf: bool, shortcut: bool); - #[no_mangle] - fn scan_decimal(); - #[no_mangle] - fn pack_file_name(n: str_number, a: str_number, e: str_number); - #[no_mangle] - fn scan_file_name(); - #[no_mangle] - fn new_whatsit(s: small_number, w: small_number); - /* xetex-errors */ - #[no_mangle] - fn error(); - #[no_mangle] - fn print(s: i32); - #[no_mangle] - fn print_cstr(s: *const i8); - #[no_mangle] - fn print_nl_cstr(s: *const i8); - /* ***************************************************************************\ - Part of the XeTeX typesetting system - Copyright (c) 1994-2008 by SIL International - Copyright (c) 2009, 2011 by Jonathan Kew - Copyright (c) 2012, 2013 by Jiang Jiang - Copyright (c) 2012-2015 by Khaled Hosny - - SIL Author(s): Jonathan Kew - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE - FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - Except as contained in this notice, the name of the copyright holders - shall not be used in advertising or otherwise to promote the sale, - use or other dealings in this Software without prior written - authorization from the copyright holders. - \****************************************************************************/ - /* some typedefs that XeTeX uses - on Mac OS, we get these from Apple headers, - but otherwise we'll need these substitute definitions */ - /* command codes for XeTeX extension commands */ - /* accessing info in a native_word_node */ - /* info for each glyph is location (FixedPoint) + glyph ID (u16) */ - /* glyph ID field in a glyph_node */ - /* For Unicode encoding form interpretation... */ - /* single-purpose metrics accessors */ - #[no_mangle] - fn Fix2D(f: Fixed) -> f64; - #[no_mangle] - fn print_file_name(n: i32, a: i32, e: i32); - #[no_mangle] - fn print_file_line(); - #[no_mangle] - fn print_scaled(s: scaled_t); - #[no_mangle] - fn D2Fix(d: f64) -> Fixed; - /* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2002-2017 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team. - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - #[no_mangle] - fn min4(v1: f64, v2: f64, v3: f64, v4: f64) -> f64; - #[no_mangle] - fn max4(v1: f64, v2: f64, v3: f64, v4: f64) -> f64; - /* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2007-2017 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team. - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - /* PDF document metadata */ - /* They just return PDF dictionary object. - * Callers are completely responsible for doing right thing... - */ - #[no_mangle] - fn pdf_doc_get_page_count(pf: *mut pdf_file) -> i32; - #[no_mangle] - fn check_for_png(handle: rust_input_handle_t) -> i32; - #[no_mangle] - fn png_get_bbox( - handle: rust_input_handle_t, - width: *mut u32, - height: *mut u32, - xdensity: *mut f64, - ydensity: *mut f64, - ) -> i32; - /* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - - Copyright (C) 2002-2016 by Jin-Hwan Cho and Shunsaku Hirata, - the dvipdfmx project team. - - Copyright (C) 1998, 1999 by Mark A. Wicks - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - #[no_mangle] - fn check_for_jpeg(handle: rust_input_handle_t) -> i32; - #[no_mangle] - fn jpeg_get_bbox( - handle: rust_input_handle_t, - width: *mut u32, - height: *mut u32, - xdensity: *mut f64, - ydensity: *mut f64, - ) -> i32; - #[no_mangle] - fn check_for_bmp(handle: rust_input_handle_t) -> i32; - #[no_mangle] - fn bmp_get_bbox( - handle: rust_input_handle_t, - width: *mut u32, - height: *mut u32, - xdensity: *mut f64, - ydensity: *mut f64, - ) -> i32; -} - -use crate::TTInputFormat; +use dpx::dpx_pngimage::{check_for_png, png_get_bbox}; +use libc::{free, memcpy, strlen}; pub type rust_input_handle_t = *mut libc::c_void; pub type scaled_t = i32; @@ -230,74 +40,6 @@ pub type str_number = i32; pub type small_number = i16; #[derive(Copy, Clone)] #[repr(C)] -pub struct b32x2_le_t { - pub s0: i32, - pub s1: i32, -} -/* quasi-hack to get the primary input */ -/* The annoying `memory_word` type. We have to make sure the byte-swapping - * that the (un)dumping routines do suffices to put things in the right place - * in memory. - * - * This set of data used to be a huge mess (see comment after the - * definitions). It is now (IMO) a lot more reasonable, but there will no - * doubt be carryover weird terminology around the code. - * - * ## ENDIANNESS (cheat sheet because I'm lame) - * - * Intel is little-endian. Say that we have a 32-bit integer stored in memory - * with `p` being a `uint8` pointer to its location. In little-endian land, - * `p[0]` is least significant byte and `p[3]` is its most significant byte. - * - * Conversely, in big-endian land, `p[0]` is its most significant byte and - * `p[3]` is its least significant byte. - * - * ## MEMORY_WORD LAYOUT - * - * Little endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [lsb......s0.......msb] [lsb......s1.......msb] - * b16: [l..s0...m] [l..s1...m] [l..s2...m] [l..s3...m] - * - * Big endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [msb......s1.......lsb] [msb......s0.......lsb] - * b16: [m..s3...l] [m..s2...l] [m..s1...l] [m...s0..l] - * - */ -pub type b32x2 = b32x2_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b16x4_le_t { - pub s0: u16, - pub s1: u16, - pub s2: u16, - pub s3: u16, -} -pub type b16x4 = b16x4_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub union memory_word { - pub b32: b32x2, - pub b16: b16x4, - pub gr: f64, - pub ptr: *mut libc::c_void, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub struct list_state_record { - pub mode: i16, - pub head: i32, - pub tail: i32, - pub eTeX_aux: i32, - pub prev_graf: i32, - pub mode_line: i32, - pub aux: memory_word, -} -#[derive(Copy, Clone)] -#[repr(C)] pub struct transform_t { pub a: f64, pub b: f64, @@ -982,11 +724,11 @@ pub unsafe extern "C" fn load_picture(mut is_pdf: bool) { if result == 0i32 { new_whatsit( 43i32 as small_number, - (9i32 as u64).wrapping_add( + (9usize).wrapping_add( strlen(pic_path) - .wrapping_add(::std::mem::size_of::() as u64) - .wrapping_sub(1i32 as u64) - .wrapping_div(::std::mem::size_of::() as u64), + .wrapping_add(::std::mem::size_of::()) + .wrapping_sub(1) + .wrapping_div(::std::mem::size_of::()), ) as small_number, ); if is_pdf { diff --git a/engine/src/xetex_scaledmath.rs b/engine/src/xetex_scaledmath.rs index 8502aaf4c..2ccce5d10 100644 --- a/engine/src/xetex_scaledmath.rs +++ b/engine/src/xetex_scaledmath.rs @@ -1,17 +1,14 @@ -#![allow(dead_code, - mutable_transmutes, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut)] +#![allow( + dead_code, + mutable_transmutes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] -extern "C" { - #[no_mangle] - static mut arith_error: bool; - #[no_mangle] - static mut tex_remainder: scaled_t; -} +use crate::xetex_ini::{arith_error, tex_remainder}; pub type scaled_t = i32; /* tectonic/xetex-scaledmath.c: low-level math functions Copyright 2017 The Tectonic Project diff --git a/engine/src/xetex_shipout.rs b/engine/src/xetex_shipout.rs index 1a0eb4ef6..f4e50151b 100644 --- a/engine/src/xetex_shipout.rs +++ b/engine/src/xetex_shipout.rs @@ -8,313 +8,51 @@ unused_mut )] -use super::xetex_ini::selector; +use crate::core_memory::xmalloc; +use crate::xetex_errors::{confusion, error, fatal_error, overflow}; +use crate::xetex_ext::{ + apply_tfm_font_mapping, makeXDVGlyphArrayData, make_font_def, store_justified_native_glyphs, +}; +use crate::xetex_ini::{ + avail, char_base, cur_area, cur_cs, cur_dir, cur_ext, cur_h, cur_h_offset, cur_list, cur_name, + cur_page_height, cur_page_width, cur_tok, cur_v, cur_v_offset, dead_cycles, def_ref, + doing_leaders, doing_special, eqtb, file_line_error_style_p, file_offset, font_area, font_bc, + font_check, font_dsize, font_ec, font_glue, font_info, font_letter_space, font_mapping, + font_name, font_ptr, font_size, font_used, help_line, help_ptr, init_pool_ptr, job_name, + last_bop, log_opened, max_h, max_print_line, max_push, max_v, mem, name_of_file, + output_file_extension, pdf_last_x_pos, pdf_last_y_pos, pool_ptr, pool_size, rule_dp, rule_ht, + rule_wd, rust_stdout, selector, semantic_pagination_enabled, str_pool, str_ptr, str_start, + temp_ptr, term_offset, total_pages, width_base, write_file, write_loc, write_open, xdv_buffer, + xtx_ligature_present, LR_problems, LR_ptr, +}; +use crate::xetex_ini::{memory_word, Selector}; +use crate::xetex_output::{ + print, print_char, print_cstr, print_file_line, print_file_name, print_int, print_ln, + print_nl_cstr, print_raw_char, print_scaled, +}; +use crate::xetex_scaledmath::tex_round; +use crate::xetex_stringpool::length; +use crate::xetex_synctex::{ + synctex_current, synctex_hlist, synctex_horizontal_rule_or_glue, synctex_kern, synctex_math, + synctex_sheet, synctex_teehs, synctex_tsilh, synctex_tsilv, synctex_vlist, synctex_void_hlist, + synctex_void_vlist, +}; +use crate::xetex_texmfmp::maketexstring; +use crate::xetex_xetex0::{ + begin_diagnostic, begin_token_list, effective_char, end_diagnostic, end_token_list, flush_list, + flush_node_list, free_node, get_avail, get_node, get_token, make_name_string, new_kern, + new_math, new_native_word_node, open_log_file, pack_file_name, pack_job_name, prepare_mag, + scan_toks, show_box, show_token_list, token_show, +}; use crate::xetex_xetexd::{is_char_node, print_c_string}; use crate::{ttstub_output_close, ttstub_output_flush, ttstub_output_open, ttstub_output_write}; -use libc::free; +use bridge::_tt_abort; +use libc::{free, strerror, strlen}; -extern "C" { - #[no_mangle] - fn strlen(_: *const i8) -> u64; - #[no_mangle] - fn strerror(_: i32) -> *mut i8; - /* The internal, C/C++ interface: */ - #[no_mangle] - fn _tt_abort(format: *const i8, _: ...) -> !; - #[no_mangle] - fn xmalloc(size: size_t) -> *mut libc::c_void; - /* Needed here for UFILE */ - /* variables! */ - /* All the following variables are defined in xetexini.c */ - #[no_mangle] - static mut eqtb: *mut memory_word; - #[no_mangle] - static mut name_of_file: *mut i8; - #[no_mangle] - static mut max_print_line: i32; - #[no_mangle] - static mut pool_size: i32; - #[no_mangle] - static mut file_line_error_style_p: i32; - #[no_mangle] - static mut str_pool: *mut packed_UTF16_code; - #[no_mangle] - static mut str_start: *mut pool_pointer; - #[no_mangle] - static mut pool_ptr: pool_pointer; - #[no_mangle] - static mut str_ptr: str_number; - #[no_mangle] - static mut init_pool_ptr: pool_pointer; - #[no_mangle] - static mut rust_stdout: rust_output_handle_t; - #[no_mangle] - static mut term_offset: i32; - #[no_mangle] - static mut file_offset: i32; - #[no_mangle] - static mut doing_special: bool; - #[no_mangle] - static mut help_line: [*const i8; 6]; - #[no_mangle] - static mut help_ptr: u8; - #[no_mangle] - static mut temp_ptr: i32; - #[no_mangle] - static mut mem: *mut memory_word; - #[no_mangle] - static mut avail: i32; - #[no_mangle] - static mut cur_list: list_state_record; - #[no_mangle] - static mut cur_cs: i32; - #[no_mangle] - static mut cur_tok: i32; - #[no_mangle] - static mut def_ref: i32; - #[no_mangle] - static mut cur_name: str_number; - #[no_mangle] - static mut cur_area: str_number; - #[no_mangle] - static mut cur_ext: str_number; - #[no_mangle] - static mut job_name: str_number; - #[no_mangle] - static mut log_opened: bool; - #[no_mangle] - static mut output_file_extension: *const i8; - #[no_mangle] - static mut font_info: *mut memory_word; - #[no_mangle] - static mut font_ptr: internal_font_number; - #[no_mangle] - static mut font_check: *mut b16x4; - #[no_mangle] - static mut font_size: *mut scaled_t; - #[no_mangle] - static mut font_dsize: *mut scaled_t; - #[no_mangle] - static mut font_name: *mut str_number; - #[no_mangle] - static mut font_area: *mut str_number; - #[no_mangle] - static mut font_bc: *mut UTF16_code; - #[no_mangle] - static mut font_ec: *mut UTF16_code; - #[no_mangle] - static mut font_glue: *mut i32; - #[no_mangle] - static mut font_used: *mut bool; - #[no_mangle] - static mut font_mapping: *mut *mut libc::c_void; - #[no_mangle] - static mut font_letter_space: *mut scaled_t; - #[no_mangle] - static mut xdv_buffer: *mut i8; - #[no_mangle] - static mut char_base: *mut i32; - #[no_mangle] - static mut width_base: *mut i32; - #[no_mangle] - static mut total_pages: i32; - #[no_mangle] - static mut max_v: scaled_t; - #[no_mangle] - static mut max_h: scaled_t; - #[no_mangle] - static mut max_push: i32; - #[no_mangle] - static mut last_bop: i32; - #[no_mangle] - static mut dead_cycles: i32; - #[no_mangle] - static mut doing_leaders: bool; - #[no_mangle] - static mut rule_ht: scaled_t; - #[no_mangle] - static mut rule_dp: scaled_t; - #[no_mangle] - static mut rule_wd: scaled_t; - #[no_mangle] - static mut cur_h: scaled_t; - #[no_mangle] - static mut cur_v: scaled_t; - #[no_mangle] - static mut write_file: [rust_output_handle_t; 16]; - #[no_mangle] - static mut write_open: [bool; 18]; - #[no_mangle] - static mut write_loc: i32; - #[no_mangle] - static mut cur_page_width: scaled_t; - #[no_mangle] - static mut cur_page_height: scaled_t; - #[no_mangle] - static mut cur_h_offset: scaled_t; - #[no_mangle] - static mut cur_v_offset: scaled_t; - #[no_mangle] - static mut pdf_last_x_pos: i32; - #[no_mangle] - static mut pdf_last_y_pos: i32; - #[no_mangle] - static mut LR_ptr: i32; - #[no_mangle] - static mut LR_problems: i32; - #[no_mangle] - static mut cur_dir: small_number; - #[no_mangle] - static mut xtx_ligature_present: bool; - #[no_mangle] - static mut semantic_pagination_enabled: bool; - #[no_mangle] - fn show_token_list(p: i32, q: i32, l: i32); - #[no_mangle] - fn get_avail() -> i32; - #[no_mangle] - fn flush_list(p: i32); - #[no_mangle] - fn get_node(s: i32) -> i32; - #[no_mangle] - fn free_node(p: i32, s: i32); - #[no_mangle] - fn new_math(w: scaled_t, s: small_number) -> i32; - #[no_mangle] - fn new_kern(w: scaled_t) -> i32; - #[no_mangle] - fn show_box(p: i32); - #[no_mangle] - fn flush_node_list(p: i32); - #[no_mangle] - fn begin_diagnostic(); - #[no_mangle] - fn end_diagnostic(blank_line: bool); - #[no_mangle] - fn prepare_mag(); - #[no_mangle] - fn token_show(p: i32); - #[no_mangle] - fn begin_token_list(p: i32, t: u16); - #[no_mangle] - fn end_token_list(); - #[no_mangle] - fn get_token(); - #[no_mangle] - fn make_name_string() -> str_number; - #[no_mangle] - fn makeXDVGlyphArrayData(p: *mut libc::c_void) -> i32; - #[no_mangle] - fn make_font_def(f: i32) -> i32; - #[no_mangle] - fn store_justified_native_glyphs(node: *mut libc::c_void); - #[no_mangle] - fn maketexstring(s: *const i8) -> i32; - #[no_mangle] - fn apply_tfm_font_mapping(mapping: *mut libc::c_void, c: i32) -> i32; - #[no_mangle] - fn effective_char(err_p: bool, f: internal_font_number, c: u16) -> i32; - #[no_mangle] - fn scan_toks(macro_def: bool, xpand: bool) -> i32; - #[no_mangle] - fn pack_file_name(n: str_number, a: str_number, e: str_number); - #[no_mangle] - fn pack_job_name(_: *const i8); - #[no_mangle] - fn open_log_file(); - #[no_mangle] - fn new_native_word_node(f: internal_font_number, n: i32) -> i32; - #[no_mangle] - fn confusion(s: *const i8) -> !; - #[no_mangle] - fn fatal_error(s: *const i8) -> !; - #[no_mangle] - fn overflow(s: *const i8, n: i32) -> !; - #[no_mangle] - fn tex_round(_: f64) -> i32; - #[no_mangle] - fn print_scaled(s: scaled_t); - #[no_mangle] - fn print_ln(); - #[no_mangle] - fn print_nl_cstr(s: *const i8); - #[no_mangle] - fn print_cstr(s: *const i8); - #[no_mangle] - fn print_file_name(n: i32, a: i32, e: i32); - #[no_mangle] - fn print_int(n: i32); - #[no_mangle] - fn length(s: str_number) -> i32; - #[no_mangle] - fn print_char(s: i32); - #[no_mangle] - fn print(s: i32); - #[no_mangle] - fn error(); - #[no_mangle] - fn print_file_line(); - #[no_mangle] - fn print_raw_char(s: UTF16_code, incr_offset: bool); - /* Recording the "{..." line. In *tex.web, use synctex_sheet(pdf_output) at - * the very beginning of the ship_out procedure. - */ - #[no_mangle] - fn synctex_sheet(mag: i32); - /* Recording the "}..." line. In *tex.web, use synctex_teehs at - * the very end of the ship_out procedure. - */ - #[no_mangle] - fn synctex_teehs(); - /* This message is sent when a vlist will be shipped out, more precisely at - * the beginning of the vlist_out procedure in *TeX.web. It will be balanced - * by a synctex_tsilv, sent at the end of the vlist_out procedure. p is the - * address of the vlist We assume that p is really a vlist node! */ - #[no_mangle] - fn synctex_vlist(this_box: i32); - /* Recording a "}" line ending a vbox: this message is sent whenever a vlist - * has been shipped out. It is used to close the vlist nesting level. It is - * sent at the end of each vlist_out procedure in *TeX.web to balance a former - * synctex_vlist sent at the beginning of that procedure. */ - #[no_mangle] - fn synctex_tsilv(this_box: i32); - /* This message is sent when a void vlist will be shipped out. - * There is no need to balance a void vlist. */ - #[no_mangle] - fn synctex_void_vlist(p: i32, this_box: i32); - /* Send this message when an hlist will be shipped out, more precisely at - * the beginning of the hlist_out procedure in *TeX.web. It must be balanced - * by a synctex_tsilh, sent at the end of the hlist_out procedure. p is the - * address of the hlist. */ - #[no_mangle] - fn synctex_hlist(this_box: i32); - /* Send this message at the end of the various hlist_out procedure in *TeX.web - * to balance a former synctex_hlist. */ - #[no_mangle] - fn synctex_tsilh(this_box: i32); - /* This message is sent when a void hlist will be shipped out. - * There is no need to balance a void hlist. */ - #[no_mangle] - fn synctex_void_hlist(p: i32, this_box: i32); - /* Send this message whenever an inline math node will ship out. */ - #[no_mangle] - fn synctex_math(p: i32, this_box: i32); - /* Send this message whenever an horizontal rule or glue node will ship out. */ - #[no_mangle] - fn synctex_horizontal_rule_or_glue(p: i32, this_box: i32); - /* Send this message whenever a kern node will ship out. */ - #[no_mangle] - fn synctex_kern(p: i32, this_box: i32); - /* For debugging purpose only */ - #[no_mangle] - fn synctex_current(); -} pub type size_t = u64; pub type rust_output_handle_t = *mut libc::c_void; pub type scaled_t = i32; -use super::xetex_ini::Selector; - /* tectonic/xetex-xetexd.h -- many, many XeTeX symbol definitions Copyright 2016-2018 The Tectonic Project Licensed under the MIT License. @@ -329,153 +67,6 @@ pub type pool_pointer = i32; pub type str_number = i32; pub type packed_UTF16_code = u16; pub type small_number = i16; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b32x2_le_t { - pub s0: i32, - pub s1: i32, -} -/* The annoying `memory_word` type. We have to make sure the byte-swapping - * that the (un)dumping routines do suffices to put things in the right place - * in memory. - * - * This set of data used to be a huge mess (see comment after the - * definitions). It is now (IMO) a lot more reasonable, but there will no - * doubt be carryover weird terminology around the code. - * - * ## ENDIANNESS (cheat sheet because I'm lame) - * - * Intel is little-endian. Say that we have a 32-bit integer stored in memory - * with `p` being a `uint8` pointer to its location. In little-endian land, - * `p[0]` is least significant byte and `p[3]` is its most significant byte. - * - * Conversely, in big-endian land, `p[0]` is its most significant byte and - * `p[3]` is its least significant byte. - * - * ## MEMORY_WORD LAYOUT - * - * Little endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [lsb......s0.......msb] [lsb......s1.......msb] - * b16: [l..s0...m] [l..s1...m] [l..s2...m] [l..s3...m] - * - * Big endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [msb......s1.......lsb] [msb......s0.......lsb] - * b16: [m..s3...l] [m..s2...l] [m..s1...l] [m...s0..l] - * - */ -pub type b32x2 = b32x2_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b16x4_le_t { - pub s0: u16, - pub s1: u16, - pub s2: u16, - pub s3: u16, -} -pub type b16x4 = b16x4_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub union memory_word { - pub b32: b32x2, - pub b16: b16x4, - pub gr: f64, - pub ptr: *mut libc::c_void, -} -/* ## THE ORIGINAL SITUATION (archived for posterity) - * - * In XeTeX, a "quarterword" is 16 bits. Who knows why. A "halfword" is, - * sensibly, 32 bits. A "memory word" is a full word: either four quarters or - * two halves: i.e., 64 bits. The memory word union also has options for - * doubles (called `gr`), `integer` which is an i32 (called `cint`), and a - * pointer (`ptr`). - * - * Original struct definition, LITTLE ENDIAN (condensed): - * - * typedef union { - * struct { i32 LH, RH; } v; - * struct { short B1, B0; } u; - * } two_halves; - * - * typedef struct { - * struct { u16 B3, B2, B1, B0; } u; - * } four_quarters; - * - * typedef union { - * two_halves hh; - * - * struct { - * i32 junk; - * i32 CINT; - * } u; - * - * struct { - * four_quarters QQQQ; - * } v; - * } memory_word; - * - * # define cint u.CINT - * # define qqqq v.QQQQ - * - * Original memory layout, LITTLE ENDIAN: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * cint: [lsb...............msb] - * hh.u: [l..B1...m] [l..B0...m] - * hh.v: [lsb......LH.......msb] [lsb......RH.......msb] - * quarters: [l..B3...m] [l..B2...m] [l..B1...m] [l..B0...m] - * - * Original struct definition, BIG ENDIAN (condensed): - * - * typedef union { - * struct { i32 RH, LH; } v; - * struct { - * i32 junk; - * short B0, B1; - * } u; - * } two_halves; - * - * typedef struct { - * struct { u16 B0, B1, B2, B3; } u; - * } four_quarters; - * - * typedef union { - * two_halves hh; - * four_quarters qqqq; - * } memory_word; - * - * Original memory layout, BIG ENDIAN: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * cint: [msb...............lsb] - * hh.u: [m..B0...l] [m..B1...l] - * hh.v: [msb......RH.......lsb] [msb......LH.......lsb] - * quarters: [m..B0...l] [m..B1...l] [m..B2...l] [m...B3..l] - * - * Several things to note that apply to both endiannesses: - * - * 1. The different B0 and B1 instances do not line up. - * 2. `cint` is isomorphic to `hh.v.RH` - * 3. `hh.u.B0` is isomorphic to `qqqq.u.B2` - * 4. `hh.u.B1` is isomorphic to `qqqq.u.B3`. - * 5. The `four_quarters` field `u` serves no discernable purpose. - * - * CONVERTING TO THE NEW SYSTEM - * - * - `w.cint` => `w.b32.s1` - * - `w.qqqq.u.B` => `w.b16.s{{3 - }}` !!!!!!!!!!! - * - similar for `.u.B` => `.s{{3 - }}` !!! - * - `w.hh.u.B0` => `w.b16.s1` - * - `w.hh.u.B1` => `w.b16.s0` - * - `w.hh.v.RH` => `w.b32.s1` - * - `w.hh.v.LH` => `w.b32.s0` - * - `four_quarters` => `b16x4` - * - `two_halves` => `b32x2` - * - */ /* Symbolic accessors for various TeX data structures. I would loooove to turn these * into actual structs, but the path to doing that is not currently clear. Making * field references symbolic seems like a decent start. Sadly I don't see how to do @@ -553,17 +144,6 @@ pub union memory_word { /* \splitbotmarks */ pub type glue_ord = u8; pub type internal_font_number = i32; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct list_state_record { - pub mode: i16, - pub head: i32, - pub tail: i32, - pub eTeX_aux: i32, - pub prev_graf: i32, - pub mode_line: i32, - pub aux: memory_word, -} #[inline] unsafe extern "C" fn cur_length() -> pool_pointer { pool_ptr - *str_start.offset((str_ptr - 65536i32) as isize) diff --git a/engine/src/xetex_stringpool.rs b/engine/src/xetex_stringpool.rs index 2aa69f053..f7918d7c7 100644 --- a/engine/src/xetex_stringpool.rs +++ b/engine/src/xetex_stringpool.rs @@ -1,35 +1,21 @@ -#![allow(dead_code, - mutable_transmutes, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut)] +#![allow( + dead_code, + mutable_transmutes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] + +use libc::strlen; + +use crate::xetex_errors::overflow; +use crate::xetex_ini::{ + buffer, init_pool_ptr, init_str_ptr, max_strings, pool_ptr, pool_size, str_pool, str_ptr, + str_start, +}; -extern "C" { - #[no_mangle] - fn strlen(_: *const i8) -> u64; - #[no_mangle] - static mut buffer: *mut UnicodeScalar; - #[no_mangle] - static mut max_strings: i32; - #[no_mangle] - static mut pool_size: i32; - #[no_mangle] - static mut str_pool: *mut packed_UTF16_code; - #[no_mangle] - static mut str_start: *mut pool_pointer; - #[no_mangle] - static mut pool_ptr: pool_pointer; - #[no_mangle] - static mut str_ptr: str_number; - #[no_mangle] - static mut init_pool_ptr: pool_pointer; - #[no_mangle] - static mut init_str_ptr: str_number; - #[no_mangle] - fn overflow(s: *const i8, n: i32) -> !; -} pub type size_t = u64; pub type UnicodeScalar = i32; pub type pool_pointer = i32; @@ -48,7 +34,6 @@ static mut string_constants: [*const i8; 3] = [ pub unsafe extern "C" fn load_pool_strings(mut spare_size: i32) -> i32 { let mut s: *const i8 = 0 as *const i8; let mut i: i32 = 0i32; - let mut total_len: size_t = 0i32 as size_t; let mut g: str_number = 0i32; loop { let fresh0 = i; @@ -57,15 +42,15 @@ pub unsafe extern "C" fn load_pool_strings(mut spare_size: i32) -> i32 { if s.is_null() { break; } - let mut len: size_t = strlen(s); - total_len = (total_len as u64).wrapping_add(len) as size_t as size_t; - if total_len >= spare_size as u64 { + let mut len = strlen(s); + let total_len = len; + if total_len >= spare_size as usize { return 0i32; } loop { let fresh1 = len; len = len.wrapping_sub(1); - if !(fresh1 > 0i32 as u64) { + if !(fresh1 > 0) { break; } let fresh2 = s; diff --git a/engine/src/xetex_synctex.rs b/engine/src/xetex_synctex.rs index 5dcbdf2fd..cb26c36c6 100644 --- a/engine/src/xetex_synctex.rs +++ b/engine/src/xetex_synctex.rs @@ -8,135 +8,24 @@ unused_mut )] -use crate::mfree; +use crate::core_memory::{mfree, xmalloc, xrealloc, xstrdup}; +use crate::xetex_ini::{ + cur_h, cur_input, cur_v, eqtb, job_name, mem, rule_dp, rule_ht, rule_wd, synctex_enabled, + total_pages, +}; +use crate::xetex_io::name_of_input_file; +use crate::xetex_texmfmp::gettexstring; use crate::{ ttstub_fprintf, ttstub_issue_error, ttstub_issue_warning, ttstub_output_close, ttstub_output_open, }; -use libc::free; +use libc::{free, strcat, strcpy, strlen}; use std::ptr; -extern "C" { - #[no_mangle] - fn strcpy(_: *mut i8, _: *const i8) -> *mut i8; - #[no_mangle] - fn strcat(_: *mut i8, _: *const i8) -> *mut i8; - #[no_mangle] - fn strlen(_: *const i8) -> u64; - /* Global symbols that route through the global API variable. Hopefully we - * will one day eliminate all of the global state and get rid of all of - * these. */ - /* tectonic/core-memory.h: basic dynamic memory helpers - Copyright 2016-2018 the Tectonic Project - Licensed under the MIT License. - */ - #[no_mangle] - fn xstrdup(s: *const i8) -> *mut i8; - #[no_mangle] - fn xmalloc(size: size_t) -> *mut libc::c_void; - #[no_mangle] - fn xrealloc(old_address: *mut libc::c_void, new_size: size_t) -> *mut libc::c_void; - #[no_mangle] - fn gettexstring(_: str_number) -> *mut i8; - /* Needed here for UFILE */ - /* variables! */ - /* All the following variables are defined in xetexini.c */ - #[no_mangle] - static mut eqtb: *mut memory_word; - #[no_mangle] - static mut mem: *mut memory_word; - #[no_mangle] - static mut cur_input: input_state_t; - #[no_mangle] - static mut job_name: str_number; - #[no_mangle] - static mut total_pages: i32; - #[no_mangle] - static mut rule_ht: scaled_t; - #[no_mangle] - static mut rule_dp: scaled_t; - #[no_mangle] - static mut rule_wd: scaled_t; - #[no_mangle] - static mut cur_h: scaled_t; - #[no_mangle] - static mut cur_v: scaled_t; - #[no_mangle] - static mut synctex_enabled: i32; - #[no_mangle] - static mut name_of_input_file: *mut i8; -} pub type size_t = u64; pub type rust_output_handle_t = *mut libc::c_void; pub type scaled_t = i32; pub type str_number = i32; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b32x2_le_t { - pub s0: i32, - pub s1: i32, -} -/* The annoying `memory_word` type. We have to make sure the byte-swapping - * that the (un)dumping routines do suffices to put things in the right place - * in memory. - * - * This set of data used to be a huge mess (see comment after the - * definitions). It is now (IMO) a lot more reasonable, but there will no - * doubt be carryover weird terminology around the code. - * - * ## ENDIANNESS (cheat sheet because I'm lame) - * - * Intel is little-endian. Say that we have a 32-bit integer stored in memory - * with `p` being a `uint8` pointer to its location. In little-endian land, - * `p[0]` is least significant byte and `p[3]` is its most significant byte. - * - * Conversely, in big-endian land, `p[0]` is its most significant byte and - * `p[3]` is its least significant byte. - * - * ## MEMORY_WORD LAYOUT - * - * Little endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [lsb......s0.......msb] [lsb......s1.......msb] - * b16: [l..s0...m] [l..s1...m] [l..s2...m] [l..s3...m] - * - * Big endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [msb......s1.......lsb] [msb......s0.......lsb] - * b16: [m..s3...l] [m..s2...l] [m..s1...l] [m...s0..l] - * - */ -pub type b32x2 = b32x2_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b16x4_le_t { - pub s0: u16, - pub s1: u16, - pub s2: u16, - pub s3: u16, -} -pub type b16x4 = b16x4_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub union memory_word { - pub b32: b32x2, - pub b16: b16x4, - pub gr: f64, - pub ptr: *mut libc::c_void, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub struct input_state_t { - pub state: u16, - pub index: u16, - pub start: i32, - pub loc: i32, - pub limit: i32, - pub name: i32, - pub synctex_tag: i32, -} bitflags::bitflags! { #[repr(C)] pub struct Flags: u32 { @@ -359,7 +248,6 @@ static mut synctex_suffix_gz: *const i8 = b".gz\x00" as *const u8 as *const i8; unsafe extern "C" fn synctex_dot_open() -> rust_output_handle_t { let mut tmp: *mut i8 = 0 as *mut i8; let mut the_name: *mut i8 = 0 as *mut i8; - let mut len: size_t = 0; if synctex_ctxt.flags.contains(Flags::OFF) || (*eqtb.offset( (1i32 @@ -397,12 +285,12 @@ unsafe extern "C" fn synctex_dot_open() -> rust_output_handle_t { return synctex_ctxt.file; } tmp = gettexstring(job_name); - len = strlen(tmp); - if !(len <= 0i32 as u64) { + let len = strlen(tmp); + if !(len <= 0) { the_name = xmalloc( len.wrapping_add(strlen(synctex_suffix)) .wrapping_add(strlen(synctex_suffix_gz)) - .wrapping_add(1i32 as u64), + .wrapping_add(1) as _, ) as *mut i8; strcpy(the_name, tmp); strcat(the_name, synctex_suffix); @@ -498,7 +386,7 @@ pub unsafe extern "C" fn synctex_start_input() { if strlen(synctex_ctxt.root_name) == 0 { synctex_ctxt.root_name = xrealloc( synctex_ctxt.root_name as *mut libc::c_void, - strlen(b"texput\x00" as *const u8 as *const i8).wrapping_add(1i32 as u64), + strlen(b"texput\x00" as *const u8 as *const i8).wrapping_add(1) as _, ) as *mut i8; strcpy( synctex_ctxt.root_name, diff --git a/engine/src/xetex_texmfmp.rs b/engine/src/xetex_texmfmp.rs index 581c4165f..2bf10c788 100644 --- a/engine/src/xetex_texmfmp.rs +++ b/engine/src/xetex_texmfmp.rs @@ -1,68 +1,32 @@ -#![allow(dead_code, - mutable_transmutes, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - unused_assignments, - unused_mut)] +#![allow( + dead_code, + mutable_transmutes, + non_camel_case_types, + non_snake_case, + non_upper_case_globals, + unused_assignments, + unused_mut +)] +use crate::core_memory::xmalloc; +use crate::xetex_ini::{pool_ptr, pool_size, str_pool, str_start}; +use crate::xetex_io::{bytesFromUTF8, firstByteMark, offsetsFromUTF8}; +use crate::xetex_stringpool::make_string; use crate::{ttstub_get_data_md5, ttstub_get_file_md5}; -use libc::free; -extern "C" { - #[no_mangle] - fn strlen(_: *const i8) -> u64; - /* The internal, C/C++ interface: */ - #[no_mangle] - fn xmalloc(size: size_t) -> *mut libc::c_void; - #[no_mangle] - fn sprintf(_: *mut i8, _: *const i8, _: ...) -> i32; - #[no_mangle] - static mut pool_size: i32; - #[no_mangle] - static mut str_pool: *mut packed_UTF16_code; - #[no_mangle] - static mut str_start: *mut pool_pointer; - #[no_mangle] - static mut pool_ptr: pool_pointer; - #[no_mangle] - static firstByteMark: [u8; 7]; - #[no_mangle] - static offsetsFromUTF8: [u32; 6]; - #[no_mangle] - static bytesFromUTF8: [u8; 256]; - #[no_mangle] - fn make_string() -> str_number; -} -pub type __time_t = i64; +use libc::{free, sprintf, strlen}; + pub type size_t = u64; -pub type time_t = __time_t; pub type str_number = i32; pub type packed_UTF16_code = u16; pub type UInt32 = u32; pub type pool_pointer = i32; pub type UInt16 = u16; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct tm { - pub tm_sec: i32, - pub tm_min: i32, - pub tm_hour: i32, - pub tm_mday: i32, - pub tm_mon: i32, - pub tm_year: i32, - pub tm_wday: i32, - pub tm_yday: i32, - pub tm_isdst: i32, - pub tm_gmtoff: i64, - pub tm_zone: *const i8, -} /* texmfmp.c: Hand-coded routines for TeX or Metafont in C. Originally written by Tim Morgan, drawing from other Unix ports of TeX. This is a collection of miscellany, everything that's easier (or only possible) to do in C. This file is public domain. */ -/* For `struct tm'. Moved here for Visual Studio 2005. */ static mut last_source_name: *mut i8 = 0 as *const i8 as *mut i8; static mut last_lineno: i32 = 0; pub fn get_date_and_time() -> (i32, i32, i32, i32) { @@ -83,14 +47,13 @@ unsafe extern "C" fn checkpool_pointer(mut pool_ptr_0: pool_pointer, mut len: si } #[no_mangle] pub unsafe extern "C" fn maketexstring(mut s: *const i8) -> i32 { - let mut len: size_t = 0; let mut rval: UInt32 = 0; let mut cp: *const u8 = s as *const u8; if s.is_null() || *s as i32 == 0i32 { return (65536 + 1i32 as i64) as i32; } - len = strlen(s); - checkpool_pointer(pool_ptr, len); + let len = strlen(s); + checkpool_pointer(pool_ptr, len as _); loop { let fresh0 = cp; cp = cp.offset(1); @@ -346,10 +309,10 @@ pub unsafe extern "C" fn make_src_special( lineno, ); assert!( - !((pool_ptr as u64) + !((pool_ptr as usize) .wrapping_add(strlen(buf.as_mut_ptr())) .wrapping_add(strlen(filename)) - >= pool_size as size_t), + >= pool_size as usize), "string pool overflow" ); s = buf.as_mut_ptr(); @@ -406,7 +369,7 @@ pub unsafe extern "C" fn getmd5sum(mut s: str_number, mut file: bool) { if file { ret = ttstub_get_file_md5(xname, digest.as_mut_ptr()) } else { - ret = ttstub_get_data_md5(xname, strlen(xname), digest.as_mut_ptr()) + ret = ttstub_get_data_md5(xname, strlen(xname) as _, digest.as_mut_ptr()) } free(xname as *mut libc::c_void); if ret != 0 { diff --git a/engine/src/xetex_xetex0.rs b/engine/src/xetex_xetex0.rs index e7d1165a7..6ea85b574 100644 --- a/engine/src/xetex_xetex0.rs +++ b/engine/src/xetex_xetex0.rs @@ -8,872 +8,98 @@ unused_mut )] -use super::xetex_ini::{history, old_setting, selector}; -use super::xetex_io::{tt_xetex_open_input, u_open_in}; -use crate::mfree; -use crate::xetex_ini::hi_mem_min; -use crate::xetex_xetexd::print_c_string; -use crate::xetex_xetexd::{is_char_node, is_non_discardable_node}; +use super::xetex_io::{ + bytesFromUTF8, make_utf16_name, name_of_input_file, offsetsFromUTF8, tt_xetex_open_input, + u_open_in, +}; +use crate::core_memory::{mfree, xmalloc, xrealloc}; +#[cfg(target_os = "macos")] +use crate::xetex_aatfont as aat; +use crate::xetex_errors::{confusion, error, fatal_error, overflow, pdf_error}; +use crate::xetex_ext::{ + apply_mapping, apply_tfm_font_mapping, check_for_tfm_font_mapping, find_native_font, + get_encoding_mode_and_info, get_font_char_range, get_glyph_bounds, + get_native_char_height_depth, get_native_char_sidebearings, getnativechardp, getnativecharht, + getnativecharic, getnativecharwd, gr_font_get_named, gr_font_get_named_1, gr_print_font_name, + linebreak_next, linebreak_start, load_tfm_font_mapping, map_char_to_glyph, map_glyph_to_index, + measure_native_glyph, measure_native_node, ot_font_get, ot_font_get_1, ot_font_get_2, + ot_font_get_3, ot_get_font_metrics, print_glyph_name, print_utf8_str, + real_get_native_glyph_italic_correction, real_get_native_italic_correction, + real_get_native_word_cp, release_font_engine, +}; +use crate::xetex_ini::{ + _xeq_level_array, active_width, adjust_tail, after_token, align_ptr, align_state, + area_delimiter, arith_error, avail, base_ptr, bchar, bchar_label, best_height_plus_depth, + breadth_max, buf_size, buffer, cancel_boundary, char_base, cond_ptr, cur_align, cur_area, + cur_boundary, cur_box, cur_chr, cur_cmd, cur_cs, cur_dir, cur_ext, cur_group, cur_head, cur_if, + cur_input, cur_l, cur_lang, cur_level, cur_list, cur_loop, cur_mark, cur_name, cur_order, + cur_pre_head, cur_pre_tail, cur_ptr, cur_q, cur_r, cur_span, cur_tail, cur_tok, cur_val, + cur_val1, cur_val_level, dead_cycles, def_ref, deletions_allowed, depth_base, depth_threshold, + dig, disc_ptr, empty, eof_seen, eqtb, eqtb_top, error_count, error_line, expand_depth, + expand_depth_count, ext_delimiter, exten_base, false_bchar, file_line_error_style_p, + file_name_quote_char, file_offset, first, first_count, fmem_ptr, font_area, font_bc, + font_bchar, font_check, font_dsize, font_ec, font_false_bchar, font_flags, font_glue, + font_in_short_display, font_info, font_layout_engine, font_letter_space, font_mapping, + font_max, font_mem_size, font_name, font_params, font_ptr, font_size, font_used, force_eof, + full_source_filename_stack, gave_char_warning_help, grp_stack, half_error_line, hash, + hash_extra, hash_high, hash_used, height_base, help_line, help_ptr, hi_mem_min, history, + hyphen_char, if_limit, if_line, if_stack, in_open, init_pool_ptr, init_str_ptr, input_file, + input_ptr, input_stack, ins_disc, insert_penalties, insert_src_special_auto, + insert_src_special_every_par, insert_src_special_every_vbox, interaction, is_hyph, + is_in_csname, italic_base, job_name, kern_base, last, last_badness, last_glue, last_kern, + last_leftmost_char, last_node_type, last_penalty, last_rightmost_char, lft_hit, lig_kern_base, + lig_stack, ligature_present, line, line_stack, lo_mem_max, loaded_font_design_size, + loaded_font_flags, loaded_font_letter_space, loaded_font_mapping, log_file, log_opened, + long_help_seen, long_state, mag_set, main_f, main_h, main_i, main_j, main_k, main_p, main_pp, + main_ppp, main_s, mapped_text, max_buf_stack, max_in_open, max_in_stack, max_nest_stack, + max_param_stack, max_print_line, max_reg_help_line, max_reg_num, max_save_stack, max_strings, + mem, mem_end, name_in_progress, name_length, name_length16, name_of_file, name_of_file16, + native_font_type_flag, native_len, native_text, native_text_size, nest, nest_ptr, nest_size, + no_new_control_sequence, old_setting, open_parens, output_active, pack_begin_line, + page_contents, page_so_far, page_tail, par_loc, par_token, param_base, param_ptr, param_size, + param_stack, pdf_last_x_pos, pdf_last_y_pos, pool_ptr, pool_size, pre_adjust_tail, prev_class, + prim, prim_eqtb, prim_used, pseudo_files, pstack, quoted_filename, radix, read_file, read_open, + rover, rt_hit, rust_stdout, sa_chain, sa_level, sa_null, sa_root, save_native_len, save_ptr, + save_size, save_stack, scanner_status, selector, set_box_allowed, shown_mode, skew_char, + skip_line, source_filename_stack, space_class, stack_size, stop_at_space, str_pool, str_ptr, + str_start, tally, temp_ptr, term_offset, tex_remainder, texmf_log_name, total_shrink, + total_stretch, trick_buf, trick_count, use_err_help, used_tectonic_coda_tokens, warning_index, + width_base, write_file, write_open, xtx_ligature_present, LR_problems, LR_ptr, +}; +use crate::xetex_ini::{b16x4, b32x2, memory_word, prefixed_command}; +use crate::xetex_io::{input_line, open_or_close_in, set_input_file_encoding, u_close}; +use crate::xetex_layout_engine::*; +use crate::xetex_linebreak::line_break; +use crate::xetex_math::{ + after_math, append_choices, build_choices, fin_mlist, flush_math, init_math, math_ac, + math_fraction, math_left_right, math_limit_switch, math_radical, resume_after_display, + start_eq_no, sub_sup, +}; +use crate::xetex_output::{ + print, print_char, print_cs, print_cstr, print_current_string, print_esc, print_esc_cstr, + print_file_line, print_file_name, print_hex, print_int, print_ln, print_native_word, print_nl, + print_nl_cstr, print_raw_char, print_roman_int, print_sa_num, print_scaled, print_size, + print_write_whatsit, sprint_cs, +}; +use crate::xetex_pagebuilder::build_page; +use crate::xetex_pic::{count_pdf_file_pages, load_picture}; +use crate::xetex_scaledmath::{mult_and_add, round_xn_over_d, tex_round, x_over_n, xn_over_d}; +use crate::xetex_shipout::{finalize_dvi_file, new_edge, out_what, ship_out}; +use crate::xetex_stringpool::{ + append_str, length, make_string, search_string, slow_make_string, str_eq_buf, str_eq_str, +}; +use crate::xetex_synctex::{synctex_start_input, synctex_terminate}; +use crate::xetex_texmfmp::{ + getmd5sum, gettexstring, is_new_source, make_src_special, maketexstring, remember_source_info, +}; +use crate::xetex_xetexd::{is_char_node, is_non_discardable_node, print_c_string}; use crate::{ ttstub_input_close, ttstub_input_getc, ttstub_issue_warning, ttstub_output_close, ttstub_output_flush, ttstub_output_open, ttstub_output_putc, }; +use bridge::_tt_abort; +use libc::{free, memcpy, strcat, strcpy, strlen}; -#[cfg(target_os = "macos")] -use crate::xetex_aatfont as aat; - -use libc::free; -extern "C" { - pub type XeTeXLayoutEngine_rec; - #[no_mangle] - fn memcpy(_: *mut libc::c_void, _: *const libc::c_void, _: u64) -> *mut libc::c_void; - #[no_mangle] - fn strcpy(_: *mut i8, _: *const i8) -> *mut i8; - #[no_mangle] - fn strcat(_: *mut i8, _: *const i8) -> *mut i8; - #[no_mangle] - fn strlen(_: *const i8) -> u64; - /* The internal, C/C++ interface: */ - #[no_mangle] - fn _tt_abort(format: *const i8, _: ...) -> !; - /* Global symbols that route through the global API variable. Hopefully we - * will one day eliminate all of the global state and get rid of all of - * these. */ - #[no_mangle] - fn xmalloc(size: size_t) -> *mut libc::c_void; - #[no_mangle] - fn xrealloc(old_address: *mut libc::c_void, new_size: size_t) -> *mut libc::c_void; - /* Functions originating in texmfmp.c */ - #[no_mangle] - fn getmd5sum(s: i32, file: bool); - #[no_mangle] - fn gettexstring(_: str_number) -> *mut i8; - #[no_mangle] - fn is_new_source(_: str_number, _: i32) -> bool; - #[no_mangle] - fn make_src_special(_: str_number, _: i32) -> pool_pointer; - #[no_mangle] - fn remember_source_info(_: str_number, _: i32); - /* Needed here for UFILE */ - /* variables! */ - /* All the following variables are defined in xetexini.c */ - #[no_mangle] - static mut eqtb: *mut memory_word; - #[no_mangle] - static mut name_of_file: *mut i8; - #[no_mangle] - static mut name_of_file16: *mut UTF16_code; - #[no_mangle] - static mut name_length: i32; - #[no_mangle] - static mut name_length16: i32; - #[no_mangle] - static mut buffer: *mut UnicodeScalar; - #[no_mangle] - static mut first: i32; - #[no_mangle] - static mut last: i32; - #[no_mangle] - static mut max_buf_stack: i32; - #[no_mangle] - static mut error_line: i32; - #[no_mangle] - static mut half_error_line: i32; - #[no_mangle] - static mut max_print_line: i32; - #[no_mangle] - static mut max_strings: i32; - #[no_mangle] - static mut pool_size: i32; - #[no_mangle] - static mut font_mem_size: i32; - #[no_mangle] - static mut font_max: i32; - #[no_mangle] - static mut buf_size: i32; - #[no_mangle] - static mut stack_size: i32; - #[no_mangle] - static mut max_in_open: i32; - #[no_mangle] - static mut param_size: i32; - #[no_mangle] - static mut nest_size: i32; - #[no_mangle] - static mut save_size: i32; - #[no_mangle] - static mut expand_depth: i32; - #[no_mangle] - static mut file_line_error_style_p: i32; - #[no_mangle] - static mut quoted_filename: bool; - #[no_mangle] - static mut insert_src_special_auto: bool; - #[no_mangle] - static mut insert_src_special_every_par: bool; - #[no_mangle] - static mut insert_src_special_every_vbox: bool; - #[no_mangle] - static mut str_pool: *mut packed_UTF16_code; - #[no_mangle] - static mut str_start: *mut pool_pointer; - #[no_mangle] - static mut pool_ptr: pool_pointer; - #[no_mangle] - static mut str_ptr: str_number; - #[no_mangle] - static mut init_pool_ptr: pool_pointer; - #[no_mangle] - static mut init_str_ptr: str_number; - #[no_mangle] - static mut rust_stdout: rust_output_handle_t; - #[no_mangle] - static mut log_file: rust_output_handle_t; - #[no_mangle] - static mut dig: [u8; 23]; - #[no_mangle] - static mut tally: i32; - #[no_mangle] - static mut term_offset: i32; - #[no_mangle] - static mut file_offset: i32; - #[no_mangle] - static mut trick_buf: [UTF16_code; 256]; - #[no_mangle] - static mut trick_count: i32; - #[no_mangle] - static mut first_count: i32; - #[no_mangle] - static mut native_text: *mut UTF16_code; - #[no_mangle] - static mut native_text_size: i32; - #[no_mangle] - static mut native_len: i32; - #[no_mangle] - static mut save_native_len: i32; - #[no_mangle] - static mut interaction: u8; - #[no_mangle] - static mut deletions_allowed: bool; - #[no_mangle] - static mut set_box_allowed: bool; - #[no_mangle] - static mut error_count: i8; - #[no_mangle] - static mut help_line: [*const i8; 6]; - #[no_mangle] - static mut help_ptr: u8; - #[no_mangle] - static mut use_err_help: bool; - #[no_mangle] - static mut arith_error: bool; - #[no_mangle] - static mut tex_remainder: scaled_t; - #[no_mangle] - static mut temp_ptr: i32; - #[no_mangle] - static mut mem: *mut memory_word; - #[no_mangle] - static mut lo_mem_max: i32; - #[no_mangle] - static mut avail: i32; - #[no_mangle] - static mut mem_end: i32; - #[no_mangle] - static mut rover: i32; - #[no_mangle] - static mut last_leftmost_char: i32; - #[no_mangle] - static mut last_rightmost_char: i32; - #[no_mangle] - static mut font_in_short_display: i32; - #[no_mangle] - static mut depth_threshold: i32; - #[no_mangle] - static mut breadth_max: i32; - #[no_mangle] - static mut nest: *mut list_state_record; - #[no_mangle] - static mut nest_ptr: i32; - #[no_mangle] - static mut max_nest_stack: i32; - #[no_mangle] - static mut cur_list: list_state_record; - #[no_mangle] - static mut shown_mode: i16; - #[no_mangle] - static mut hash: *mut b32x2; - #[no_mangle] - static mut hash_used: i32; - #[no_mangle] - static mut hash_extra: i32; - #[no_mangle] - static mut eqtb_top: i32; - #[no_mangle] - static mut hash_high: i32; - #[no_mangle] - static mut no_new_control_sequence: bool; - #[no_mangle] - static mut prim: [b32x2; 501]; - #[no_mangle] - static mut prim_used: i32; - #[no_mangle] - static mut prim_eqtb: [memory_word; 501]; - #[no_mangle] - static mut save_stack: *mut memory_word; - #[no_mangle] - static mut save_ptr: i32; - #[no_mangle] - static mut max_save_stack: i32; - #[no_mangle] - static mut cur_level: u16; - #[no_mangle] - static mut cur_group: group_code; - #[no_mangle] - static mut cur_boundary: i32; - #[no_mangle] - static mut mag_set: i32; - #[no_mangle] - static mut cur_cmd: eight_bits; - #[no_mangle] - static mut cur_chr: i32; - #[no_mangle] - static mut cur_cs: i32; - #[no_mangle] - static mut cur_tok: i32; - #[no_mangle] - static mut input_stack: *mut input_state_t; - #[no_mangle] - static mut input_ptr: i32; - #[no_mangle] - static mut max_in_stack: i32; - #[no_mangle] - static mut cur_input: input_state_t; - #[no_mangle] - static mut in_open: i32; - #[no_mangle] - static mut open_parens: i32; - #[no_mangle] - static mut input_file: *mut *mut UFILE; - #[no_mangle] - static mut line: i32; - #[no_mangle] - static mut line_stack: *mut i32; - #[no_mangle] - static mut source_filename_stack: *mut str_number; - #[no_mangle] - static mut full_source_filename_stack: *mut str_number; - #[no_mangle] - static mut scanner_status: u8; - #[no_mangle] - static mut warning_index: i32; - #[no_mangle] - static mut def_ref: i32; - #[no_mangle] - static mut param_stack: *mut i32; - #[no_mangle] - static mut param_ptr: i32; - #[no_mangle] - static mut max_param_stack: i32; - #[no_mangle] - static mut align_state: i32; - #[no_mangle] - static mut base_ptr: i32; - #[no_mangle] - static mut par_loc: i32; - #[no_mangle] - static mut par_token: i32; - #[no_mangle] - static mut force_eof: bool; - #[no_mangle] - static mut expand_depth_count: i32; - #[no_mangle] - static mut is_in_csname: bool; - #[no_mangle] - static mut cur_mark: [i32; 5]; - #[no_mangle] - static mut long_state: u8; - #[no_mangle] - static mut pstack: [i32; 9]; - #[no_mangle] - static mut cur_val: i32; - #[no_mangle] - static mut cur_val1: i32; - #[no_mangle] - static mut cur_val_level: u8; - #[no_mangle] - static mut radix: small_number; - #[no_mangle] - static mut cur_order: glue_ord; - #[no_mangle] - static mut read_file: [*mut UFILE; 16]; - #[no_mangle] - static mut read_open: [u8; 17]; - #[no_mangle] - static mut cond_ptr: i32; - #[no_mangle] - static mut if_limit: u8; - #[no_mangle] - static mut cur_if: small_number; - #[no_mangle] - static mut if_line: i32; - #[no_mangle] - static mut skip_line: i32; - #[no_mangle] - static mut cur_name: str_number; - #[no_mangle] - static mut cur_area: str_number; - #[no_mangle] - static mut cur_ext: str_number; - #[no_mangle] - static mut area_delimiter: pool_pointer; - #[no_mangle] - static mut ext_delimiter: pool_pointer; - #[no_mangle] - static mut file_name_quote_char: UTF16_code; - #[no_mangle] - static mut name_in_progress: bool; - #[no_mangle] - static mut job_name: str_number; - #[no_mangle] - static mut log_opened: bool; - #[no_mangle] - static mut texmf_log_name: str_number; - #[no_mangle] - static mut font_info: *mut memory_word; - #[no_mangle] - static mut fmem_ptr: font_index; - #[no_mangle] - static mut font_ptr: internal_font_number; - #[no_mangle] - static mut font_check: *mut b16x4; - #[no_mangle] - static mut font_size: *mut scaled_t; - #[no_mangle] - static mut font_dsize: *mut scaled_t; - #[no_mangle] - static mut font_params: *mut font_index; - #[no_mangle] - static mut font_name: *mut str_number; - #[no_mangle] - static mut font_area: *mut str_number; - #[no_mangle] - static mut font_bc: *mut UTF16_code; - #[no_mangle] - static mut font_ec: *mut UTF16_code; - #[no_mangle] - static mut font_glue: *mut i32; - #[no_mangle] - static mut font_used: *mut bool; - #[no_mangle] - static mut hyphen_char: *mut i32; - #[no_mangle] - static mut skew_char: *mut i32; - #[no_mangle] - static mut bchar_label: *mut font_index; - #[no_mangle] - static mut font_bchar: *mut nine_bits; - #[no_mangle] - static mut font_false_bchar: *mut nine_bits; - #[no_mangle] - static mut font_layout_engine: *mut *mut libc::c_void; - #[no_mangle] - static mut font_mapping: *mut *mut libc::c_void; - #[no_mangle] - static mut font_flags: *mut i8; - #[no_mangle] - static mut font_letter_space: *mut scaled_t; - #[no_mangle] - static mut loaded_font_mapping: *mut libc::c_void; - #[no_mangle] - static mut loaded_font_flags: i8; - #[no_mangle] - static mut loaded_font_letter_space: scaled_t; - #[no_mangle] - static mut loaded_font_design_size: scaled_t; - #[no_mangle] - static mut mapped_text: *mut UTF16_code; - #[no_mangle] - static mut char_base: *mut i32; - #[no_mangle] - static mut width_base: *mut i32; - #[no_mangle] - static mut height_base: *mut i32; - #[no_mangle] - static mut depth_base: *mut i32; - #[no_mangle] - static mut italic_base: *mut i32; - #[no_mangle] - static mut lig_kern_base: *mut i32; - #[no_mangle] - static mut kern_base: *mut i32; - #[no_mangle] - static mut exten_base: *mut i32; - #[no_mangle] - static mut param_base: *mut i32; - #[no_mangle] - static mut dead_cycles: i32; - /* should be internal to shipout, but accessed by synctex */ - #[no_mangle] - static mut total_stretch: [scaled_t; 4]; - #[no_mangle] - static mut total_shrink: [scaled_t; 4]; - #[no_mangle] - static mut last_badness: i32; - #[no_mangle] - static mut adjust_tail: i32; - #[no_mangle] - static mut pre_adjust_tail: i32; - #[no_mangle] - static mut pack_begin_line: i32; - #[no_mangle] - static mut empty: b32x2; - #[no_mangle] - static mut cur_align: i32; - #[no_mangle] - static mut cur_span: i32; - #[no_mangle] - static mut cur_loop: i32; - #[no_mangle] - static mut align_ptr: i32; - /* tectonic/xetex-io.h: XeTeX-specific low-level I/O routines - Copyright 2016-2018 the Tectonic Project - Licensed under the MIT License. - */ - #[no_mangle] - fn make_utf16_name(); - #[no_mangle] - fn input_line(f: *mut UFILE) -> i32; - #[no_mangle] - fn u_close(f: *mut UFILE); - #[no_mangle] - fn set_input_file_encoding(f: *mut UFILE, mode: i32, encodingData: i32); - #[no_mangle] - static bytesFromUTF8: [u8; 256]; - #[no_mangle] - static offsetsFromUTF8: [u32; 6]; - #[no_mangle] - static mut name_of_input_file: *mut i8; - #[no_mangle] - fn get_ot_math_constant(f: i32, n: i32) -> i32; - /* ***************************************************************************\ - Part of the XeTeX typesetting system - Copyright (c) 1994-2008 by SIL International - Copyright (c) 2009, 2011 by Jonathan Kew - Copyright (c) 2012, 2013 by Jiang Jiang - Copyright (c) 2012-2015 by Khaled Hosny - - SIL Author(s): Jonathan Kew - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE - FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - Except as contained in this notice, the name of the copyright holders - shall not be used in advertising or otherwise to promote the sale, - use or other dealings in this Software without prior written - authorization from the copyright holders. - \****************************************************************************/ - /* some typedefs that XeTeX uses - on Mac OS, we get these from Apple headers, - but otherwise we'll need these substitute definitions */ - /* command codes for XeTeX extension commands */ - /* accessing info in a native_word_node */ - /* info for each glyph is location (FixedPoint) + glyph ID (u16) */ - /* glyph ID field in a glyph_node */ - /* For Unicode encoding form interpretation... */ - /* single-purpose metrics accessors */ - /* the metrics params here are really TeX 'scaled' (or MacOS 'Fixed') values, but that typedef isn't available every place this is included */ - #[no_mangle] - fn apply_tfm_font_mapping(mapping: *mut libc::c_void, c: i32) -> i32; - #[no_mangle] - fn load_tfm_font_mapping() -> *mut libc::c_void; - #[no_mangle] - fn check_for_tfm_font_mapping(); - #[no_mangle] - fn get_cp_code(fontNum: i32, code: u32, side: i32) -> i32; - #[no_mangle] - fn maketexstring(s: *const i8) -> i32; - #[no_mangle] - fn count_pdf_file_pages() -> i32; - #[no_mangle] - fn get_font_char_range(font: i32, first_0: i32) -> i32; - #[no_mangle] - fn gr_font_get_named_1(what: i32, pEngine: *mut libc::c_void, param: i32) -> i32; - #[no_mangle] - fn gr_font_get_named(what: i32, pEngine: *mut libc::c_void) -> i32; - #[no_mangle] - fn gr_print_font_name(what: i32, pEngine: *mut libc::c_void, param1: i32, param2: i32); - #[no_mangle] - fn print_glyph_name(font: i32, gid: i32); - #[no_mangle] - fn map_glyph_to_index(font: i32) -> i32; - #[no_mangle] - fn map_char_to_glyph(font: i32, ch: i32) -> i32; - #[no_mangle] - fn measure_native_glyph(node: *mut libc::c_void, use_glyph_metrics: i32); - #[no_mangle] - fn real_get_native_word_cp(node: *mut libc::c_void, side: i32) -> i32; - #[no_mangle] - fn real_get_native_glyph_italic_correction(node: *mut libc::c_void) -> Fixed; - #[no_mangle] - fn real_get_native_italic_correction(node: *mut libc::c_void) -> Fixed; - #[no_mangle] - fn measure_native_node(node: *mut libc::c_void, use_glyph_metrics: i32); - #[no_mangle] - fn apply_mapping(cnv: *mut libc::c_void, txtPtr: *mut u16, txtLen: i32) -> i32; - #[no_mangle] - fn ot_font_get_3( - what: i32, - engine: *mut libc::c_void, - param1: i32, - param2: i32, - param3: i32, - ) -> i32; - #[no_mangle] - fn ot_font_get_2(what: i32, engine: *mut libc::c_void, param1: i32, param2: i32) -> i32; - #[no_mangle] - fn ot_font_get_1(what: i32, engine: *mut libc::c_void, param: i32) -> i32; - #[no_mangle] - fn ot_font_get(what: i32, engine: *mut libc::c_void) -> i32; - #[no_mangle] - fn get_glyph_bounds(font: i32, edge: i32, gid: i32) -> scaled_t; - #[no_mangle] - fn getnativecharic(font: i32, ch: i32) -> scaled_t; - #[no_mangle] - fn getnativechardp(font: i32, ch: i32) -> scaled_t; - #[no_mangle] - fn getnativecharht(font: i32, ch: i32) -> scaled_t; - #[no_mangle] - fn getnativecharwd(font: i32, ch: i32) -> scaled_t; - #[no_mangle] - fn get_native_char_sidebearings(font: i32, ch: i32, lsb: *mut scaled_t, rsb: *mut scaled_t); - #[no_mangle] - fn get_native_char_height_depth( - font: i32, - ch: i32, - height: *mut scaled_t, - depth: *mut scaled_t, - ); - #[no_mangle] - fn ot_get_font_metrics( - engine: *mut libc::c_void, - ascent: *mut scaled_t, - descent: *mut scaled_t, - xheight: *mut scaled_t, - capheight: *mut scaled_t, - slant: *mut scaled_t, - ); - #[no_mangle] - fn release_font_engine(engine: *mut libc::c_void, type_flag: i32); - #[no_mangle] - fn find_native_font(name: *mut i8, scaled_size: i32) -> *mut libc::c_void; - #[no_mangle] - fn print_utf8_str(str: *const u8, len: i32); - #[no_mangle] - fn get_encoding_mode_and_info(info: *mut i32) -> i32; - #[no_mangle] - fn linebreak_next() -> i32; - #[no_mangle] - fn linebreak_start(f: i32, localeStrNum: i32, text: *mut u16, textLength: i32); - #[no_mangle] - fn isOpenTypeMathFont(engine: XeTeXLayoutEngine) -> bool; - #[no_mangle] - fn usingGraphite(engine: XeTeXLayoutEngine) -> bool; - #[no_mangle] - fn usingOpenType(engine: XeTeXLayoutEngine) -> bool; - #[no_mangle] - static mut cur_head: i32; - #[no_mangle] - static mut cur_tail: i32; - #[no_mangle] - static mut cur_pre_head: i32; - #[no_mangle] - static mut cur_pre_tail: i32; - #[no_mangle] - static mut active_width: [scaled_t; 7]; - #[no_mangle] - static mut cur_lang: u8; - #[no_mangle] - static mut cur_l: i32; - #[no_mangle] - static mut cur_r: i32; - #[no_mangle] - static mut cur_q: i32; - #[no_mangle] - static mut lig_stack: i32; - #[no_mangle] - static mut ligature_present: bool; - #[no_mangle] - static mut lft_hit: bool; - #[no_mangle] - static mut rt_hit: bool; - #[no_mangle] - static mut best_height_plus_depth: scaled_t; - #[no_mangle] - static mut page_tail: i32; - #[no_mangle] - static mut page_contents: u8; - #[no_mangle] - static mut page_so_far: [scaled_t; 8]; - #[no_mangle] - static mut last_glue: i32; - #[no_mangle] - static mut last_penalty: i32; - #[no_mangle] - static mut last_kern: scaled_t; - #[no_mangle] - static mut last_node_type: i32; - #[no_mangle] - static mut insert_penalties: i32; - #[no_mangle] - static mut output_active: bool; - #[no_mangle] - static mut main_f: internal_font_number; - #[no_mangle] - static mut main_i: b16x4; - #[no_mangle] - static mut main_j: b16x4; - #[no_mangle] - static mut main_k: font_index; - #[no_mangle] - static mut main_p: i32; - #[no_mangle] - static mut main_pp: i32; - #[no_mangle] - static mut main_ppp: i32; - #[no_mangle] - static mut main_h: i32; - #[no_mangle] - static mut is_hyph: bool; - #[no_mangle] - static mut space_class: i32; - #[no_mangle] - static mut prev_class: i32; - #[no_mangle] - static mut main_s: i32; - #[no_mangle] - static mut bchar: i32; - #[no_mangle] - static mut false_bchar: i32; - #[no_mangle] - static mut cancel_boundary: bool; - #[no_mangle] - static mut ins_disc: bool; - #[no_mangle] - static mut cur_box: i32; - #[no_mangle] - static mut after_token: i32; - #[no_mangle] - static mut long_help_seen: bool; - #[no_mangle] - static mut write_file: [rust_output_handle_t; 16]; - #[no_mangle] - static mut write_open: [bool; 18]; - #[no_mangle] - static mut pdf_last_x_pos: i32; - #[no_mangle] - static mut pdf_last_y_pos: i32; - #[no_mangle] - static mut eof_seen: *mut bool; - #[no_mangle] - static mut LR_ptr: i32; - #[no_mangle] - static mut LR_problems: i32; - #[no_mangle] - static mut cur_dir: small_number; - #[no_mangle] - static mut pseudo_files: i32; - #[no_mangle] - static mut grp_stack: *mut save_pointer; - #[no_mangle] - static mut if_stack: *mut i32; - #[no_mangle] - static mut max_reg_num: i32; - #[no_mangle] - static mut max_reg_help_line: *const i8; - #[no_mangle] - static mut sa_root: [i32; 8]; - #[no_mangle] - static mut cur_ptr: i32; - #[no_mangle] - static mut sa_null: memory_word; - #[no_mangle] - static mut sa_chain: i32; - #[no_mangle] - static mut sa_level: u16; - #[no_mangle] - static mut disc_ptr: [i32; 4]; - #[no_mangle] - static mut stop_at_space: bool; - #[no_mangle] - static mut native_font_type_flag: i32; - #[no_mangle] - static mut xtx_ligature_present: bool; - #[no_mangle] - static mut used_tectonic_coda_tokens: bool; - #[no_mangle] - static mut gave_char_warning_help: bool; - /*:1683*/ - /* It looks like these arrays are set up so that they can be safely indexed - * with negative indices. The underlying arrays used to be named "zzzaa" and - * "zzzbb". */ - #[no_mangle] - static mut _xeq_level_array: [u16; 1114732]; - /* xetex-errors */ - /* xetex-math */ - /* xetex-output */ - #[no_mangle] - fn print_esc_cstr(s: *const i8); - #[no_mangle] - fn print_cstr(s: *const i8); - #[no_mangle] - fn print_char(s: i32); - #[no_mangle] - fn print_cs(p: i32); - #[no_mangle] - fn print_ln(); - #[no_mangle] - fn print_nl_cstr(s: *const i8); - #[no_mangle] - fn overflow(s: *const i8, n: i32) -> !; - #[no_mangle] - fn terminate_font_manager(); - #[no_mangle] - fn round_xn_over_d(x: scaled_t, n: i32, d: i32) -> scaled_t; - #[no_mangle] - fn print_native_word(p: i32); - #[no_mangle] - fn print_esc(s: str_number); - #[no_mangle] - fn print(s: i32); - #[no_mangle] - fn print_scaled(s: scaled_t); - #[no_mangle] - fn print_int(n: i32); - #[no_mangle] - fn print_hex(n: i32); - #[no_mangle] - fn print_raw_char(s: UTF16_code, incr_offset: bool); - #[no_mangle] - fn print_write_whatsit(s: *const i8, p: i32); - #[no_mangle] - fn print_file_name(n: i32, a: i32, e: i32); - #[no_mangle] - fn tex_round(_: f64) -> i32; - #[no_mangle] - fn print_current_string(); - #[no_mangle] - fn confusion(s: *const i8) -> !; - #[no_mangle] - fn x_over_n(x: scaled_t, n: i32) -> scaled_t; - /* tectonic/xetex-stringpool.h: preloaded "string pool" constants - Copyright 2017 the Tectonic Project - Licensed under the MIT License. - */ - #[no_mangle] - fn length(s: str_number) -> i32; - #[no_mangle] - fn print_size(s: i32); - #[no_mangle] - fn print_sa_num(q: i32); - #[no_mangle] - fn error(); - #[no_mangle] - fn print_file_line(); - #[no_mangle] - fn make_string() -> str_number; - #[no_mangle] - fn str_eq_buf(s: str_number, k: i32) -> bool; - #[no_mangle] - fn str_eq_str(s: str_number, t: str_number) -> bool; - #[no_mangle] - fn print_nl(s: str_number); - #[no_mangle] - fn finalize_dvi_file(); - #[no_mangle] - fn init_math(); - #[no_mangle] - fn start_eq_no(); - #[no_mangle] - fn math_limit_switch(); - #[no_mangle] - fn math_radical(); - #[no_mangle] - fn math_ac(); - #[no_mangle] - fn append_choices(); - #[no_mangle] - fn sub_sup(); - #[no_mangle] - fn math_fraction(); - #[no_mangle] - fn math_left_right(); - #[no_mangle] - fn after_math(); - #[no_mangle] - fn build_choices(); - #[no_mangle] - fn fin_mlist(p: i32) -> i32; - #[no_mangle] - fn load_picture(is_pdf: bool); - #[no_mangle] - fn open_or_close_in(); - #[no_mangle] - fn append_str(s: str_number); - #[no_mangle] - fn ship_out(p: i32); - #[no_mangle] - fn line_break(d: bool); - #[no_mangle] - fn fatal_error(s: *const i8) -> !; - #[no_mangle] - fn flush_math(); - #[no_mangle] - fn prefixed_command(); - #[no_mangle] - fn resume_after_display(); - #[no_mangle] - fn build_page(); - #[no_mangle] - fn sprint_cs(p: i32); - #[no_mangle] - fn new_edge(s: small_number, w: scaled_t) -> i32; - #[no_mangle] - fn out_what(p: i32); - #[no_mangle] - fn slow_make_string() -> str_number; - #[no_mangle] - fn search_string(search: str_number) -> str_number; - #[no_mangle] - fn pdf_error(t: *const i8, p: *const i8) -> !; - #[no_mangle] - fn print_roman_int(n: i32); - #[no_mangle] - fn mult_and_add(n: i32, x: scaled_t, y: scaled_t, max_answer: scaled_t) -> scaled_t; - #[no_mangle] - fn xn_over_d(x: scaled_t, n: i32, d: i32) -> scaled_t; - /* Send this message to clean memory, and close the file. */ - #[no_mangle] - fn synctex_terminate(log_opened_0: bool); - /* Send this message when starting a new input. */ - #[no_mangle] - fn synctex_start_input(); -} pub type size_t = u64; /* tectonic/core-bridge.h: declarations of C/C++ => Rust bridge API Copyright 2016-2018 the Tectonic Project @@ -890,7 +116,6 @@ pub type CFDictionaryRef = *mut libc::c_void; use super::xetex_ini::Selector; -pub type XeTeXLayoutEngine = *mut XeTeXLayoutEngine_rec; pub type UInt16 = u16; pub type UInt32 = u32; /* quasi-hack to get the primary input */ @@ -910,153 +135,6 @@ pub type pool_pointer = i32; pub type str_number = i32; pub type packed_UTF16_code = u16; pub type small_number = i16; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b32x2_le_t { - pub s0: i32, - pub s1: i32, -} -/* The annoying `memory_word` type. We have to make sure the byte-swapping - * that the (un)dumping routines do suffices to put things in the right place - * in memory. - * - * This set of data used to be a huge mess (see comment after the - * definitions). It is now (IMO) a lot more reasonable, but there will no - * doubt be carryover weird terminology around the code. - * - * ## ENDIANNESS (cheat sheet because I'm lame) - * - * Intel is little-endian. Say that we have a 32-bit integer stored in memory - * with `p` being a `uint8` pointer to its location. In little-endian land, - * `p[0]` is least significant byte and `p[3]` is its most significant byte. - * - * Conversely, in big-endian land, `p[0]` is its most significant byte and - * `p[3]` is its least significant byte. - * - * ## MEMORY_WORD LAYOUT - * - * Little endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [lsb......s0.......msb] [lsb......s1.......msb] - * b16: [l..s0...m] [l..s1...m] [l..s2...m] [l..s3...m] - * - * Big endian: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * b32: [msb......s1.......lsb] [msb......s0.......lsb] - * b16: [m..s3...l] [m..s2...l] [m..s1...l] [m...s0..l] - * - */ -pub type b32x2 = b32x2_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct b16x4_le_t { - pub s0: u16, - pub s1: u16, - pub s2: u16, - pub s3: u16, -} -pub type b16x4 = b16x4_le_t; -#[derive(Copy, Clone)] -#[repr(C)] -pub union memory_word { - pub b32: b32x2, - pub b16: b16x4, - pub gr: f64, - pub ptr: *mut libc::c_void, -} -/* ## THE ORIGINAL SITUATION (archived for posterity) - * - * In XeTeX, a "quarterword" is 16 bits. Who knows why. A "halfword" is, - * sensibly, 32 bits. A "memory word" is a full word: either four quarters or - * two halves: i.e., 64 bits. The memory word union also has options for - * doubles (called `gr`), `integer` which is an i32 (called `cint`), and a - * pointer (`ptr`). - * - * Original struct definition, LITTLE ENDIAN (condensed): - * - * typedef union { - * struct { i32 LH, RH; } v; - * struct { short B1, B0; } u; - * } two_halves; - * - * typedef struct { - * struct { u16 B3, B2, B1, B0; } u; - * } four_quarters; - * - * typedef union { - * two_halves hh; - * - * struct { - * i32 junk; - * i32 CINT; - * } u; - * - * struct { - * four_quarters QQQQ; - * } v; - * } memory_word; - * - * # define cint u.CINT - * # define qqqq v.QQQQ - * - * Original memory layout, LITTLE ENDIAN: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * cint: [lsb...............msb] - * hh.u: [l..B1...m] [l..B0...m] - * hh.v: [lsb......LH.......msb] [lsb......RH.......msb] - * quarters: [l..B3...m] [l..B2...m] [l..B1...m] [l..B0...m] - * - * Original struct definition, BIG ENDIAN (condensed): - * - * typedef union { - * struct { i32 RH, LH; } v; - * struct { - * i32 junk; - * short B0, B1; - * } u; - * } two_halves; - * - * typedef struct { - * struct { u16 B0, B1, B2, B3; } u; - * } four_quarters; - * - * typedef union { - * two_halves hh; - * four_quarters qqqq; - * } memory_word; - * - * Original memory layout, BIG ENDIAN: - * - * bytes: --0-- --1-- --2-- --3-- --4-- --5-- --6-- --7-- - * cint: [msb...............lsb] - * hh.u: [m..B0...l] [m..B1...l] - * hh.v: [msb......RH.......lsb] [msb......LH.......lsb] - * quarters: [m..B0...l] [m..B1...l] [m..B2...l] [m...B3..l] - * - * Several things to note that apply to both endiannesses: - * - * 1. The different B0 and B1 instances do not line up. - * 2. `cint` is isomorphic to `hh.v.RH` - * 3. `hh.u.B0` is isomorphic to `qqqq.u.B2` - * 4. `hh.u.B1` is isomorphic to `qqqq.u.B3`. - * 5. The `four_quarters` field `u` serves no discernable purpose. - * - * CONVERTING TO THE NEW SYSTEM - * - * - `w.cint` => `w.b32.s1` - * - `w.qqqq.u.B` => `w.b16.s{{3 - }}` !!!!!!!!!!! - * - similar for `.u.B` => `.s{{3 - }}` !!! - * - `w.hh.u.B0` => `w.b16.s1` - * - `w.hh.u.B1` => `w.b16.s0` - * - `w.hh.v.RH` => `w.b32.s1` - * - `w.hh.v.LH` => `w.b32.s0` - * - `four_quarters` => `b16x4` - * - `two_halves` => `b32x2` - * - */ /* Symbolic accessors for various TeX data structures. I would loooove to turn these * into actual structs, but the path to doing that is not currently clear. Making * field references symbolic seems like a decent start. Sadly I don't see how to do @@ -1139,28 +217,6 @@ pub type internal_font_number = i32; pub type font_index = i32; pub type nine_bits = i32; pub type save_pointer = i32; -#[derive(Copy, Clone)] -#[repr(C)] -pub struct list_state_record { - pub mode: i16, - pub head: i32, - pub tail: i32, - pub eTeX_aux: i32, - pub prev_graf: i32, - pub mode_line: i32, - pub aux: memory_word, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub struct input_state_t { - pub state: u16, - pub index: u16, - pub start: i32, - pub loc: i32, - pub limit: i32, - pub name: i32, - pub synctex_tag: i32, -} pub use super::xetex_io::UFILE; @@ -1535,7 +591,7 @@ pub unsafe extern "C" fn copy_native_glyph_info(mut src: i32, mut dest: i32) { memcpy( (*mem.offset((dest + 5i32) as isize)).ptr, (*mem.offset((src + 5i32) as isize)).ptr, - (glyph_count * 10i32) as u64, + (glyph_count * 10i32) as usize, ); (*mem.offset((dest + 4i32) as isize)).b16.s0 = glyph_count as u16 }; @@ -9876,7 +8932,7 @@ pub unsafe extern "C" fn scan_keyword(mut s: *const i8) -> bool { let mut p: i32 = 4999999i32 - 13i32; let mut q: i32 = 0; (*mem.offset(p as isize)).b32.s1 = -0xfffffffi32; - if strlen(s) == 1i32 as u64 { + if strlen(s) == 1 { let mut c: i8 = *s.offset(0); loop { get_x_token(); @@ -9901,8 +8957,8 @@ pub unsafe extern "C" fn scan_keyword(mut s: *const i8) -> bool { } } } - let mut slen: size_t = strlen(s); - let mut i: size_t = 0i32 as size_t; + let slen = strlen(s); + let mut i = 0; while i < slen { get_x_token(); if cur_cs == 0i32 @@ -16186,8 +15242,8 @@ pub unsafe extern "C" fn start_input(mut primary_input_name: *const i8) { stop_at_space = false; let mut cp: *const u8 = primary_input_name as *const u8; assert!( - !((pool_ptr as u64).wrapping_add(strlen(primary_input_name).wrapping_mul(2i32 as u64)) - >= pool_size as u64), + !((pool_ptr as usize).wrapping_add(strlen(primary_input_name).wrapping_mul(2)) + >= pool_size as usize), "string pool overflow [{} bytes]", pool_size, );