diff --git a/crates/bridge_core/src/lib.rs b/crates/bridge_core/src/lib.rs index 124815303..99400e444 100644 --- a/crates/bridge_core/src/lib.rs +++ b/crates/bridge_core/src/lib.rs @@ -746,6 +746,12 @@ impl<'a> CoreBridgeState<'a> { true } } + + /// Finish and emit a diagnostic + pub fn finish_diagnostic(&mut self, diag: Diagnostic) { + self.status + .report(diag.kind, format_args!("{}", diag.message), None); + } } /// A type for storing settings about potentially insecure engine features. @@ -1250,23 +1256,45 @@ pub struct Diagnostic { kind: MessageKind, } +impl Diagnostic { + /// Create a new diagnostic that will be reported as an error. + pub fn error() -> Diagnostic { + Diagnostic { + message: String::new(), + kind: MessageKind::Error, + } + } + + /// Create a new diagnostic that will be reported as a warning. + pub fn warning() -> Diagnostic { + Diagnostic { + message: String::new(), + kind: MessageKind::Warning, + } + } + + /// Append text to a diagnostic. + pub fn append(&mut self, msg: impl AsRef) { + self.message.push_str(msg.as_ref()); + } + + /// Append a single character to a diagnostic + pub fn append_char(&mut self, c: char) { + self.message.push(c); + } +} + /// Create a new diagnostic that will be reported as a warning. #[no_mangle] pub extern "C" fn ttbc_diag_begin_warning() -> *mut Diagnostic { - let warning = Box::new(Diagnostic { - message: String::new(), - kind: MessageKind::Warning, - }); + let warning = Box::new(Diagnostic::error()); Box::into_raw(warning) } /// Create a new diagnostic that will be reported as an error. #[no_mangle] pub extern "C" fn ttbc_diag_begin_error() -> *mut Diagnostic { - let warning = Box::new(Diagnostic { - message: String::new(), - kind: MessageKind::Error, - }); + let warning = Box::new(Diagnostic::error()); Box::into_raw(warning) } @@ -1278,7 +1306,7 @@ pub extern "C" fn ttbc_diag_begin_error() -> *mut Diagnostic { #[no_mangle] pub unsafe extern "C" fn ttbc_diag_append(diag: &mut Diagnostic, text: *const libc::c_char) { let rtext = CStr::from_ptr(text); - diag.message.push_str(&rtext.to_string_lossy()); + diag.append(rtext.to_string_lossy()); } /// "Finish" a diagnostic: report it to the driver and free the diagnostic object. @@ -1290,8 +1318,7 @@ pub unsafe extern "C" fn ttbc_diag_append(diag: &mut Diagnostic, text: *const li pub unsafe extern "C" fn ttbc_diag_finish(es: &mut CoreBridgeState, diag: *mut Diagnostic) { // By creating the box, we will free the diagnostic when this function exits. let rdiag = Box::from_raw(diag); - es.status - .report(rdiag.kind, format_args!("{}", rdiag.message), None); + es.finish_diagnostic(*rdiag); } /// Run a shell command diff --git a/crates/engine_xetex/build.rs b/crates/engine_xetex/build.rs index 9243a4480..a9593ba7c 100644 --- a/crates/engine_xetex/build.rs +++ b/crates/engine_xetex/build.rs @@ -196,7 +196,6 @@ const C_FILES: &[&str] = &[ "xetex/xetex-io.c", "xetex/xetex-linebreak.c", "xetex/xetex-math.c", - "xetex/xetex-output.c", "xetex/xetex-pagebuilder.c", "xetex/xetex-pic.c", "xetex/xetex-scaledmath.c", diff --git a/crates/engine_xetex/cbindgen.toml b/crates/engine_xetex/cbindgen.toml index 61fa905ef..0dff1e811 100644 --- a/crates/engine_xetex/cbindgen.toml +++ b/crates/engine_xetex/cbindgen.toml @@ -5,6 +5,16 @@ include_guard = "TECTONIC_ENGINE_XETEX_BINDGEN_H" [export.rename] "CoreBridgeState" = "ttbc_state_t" +"Diagnostic" = "ttbc_diagnostic_t" +"FileFormat" = "ttbc_file_format" +"OutputId" = "rust_output_handle_t" +"InputState" = "input_state_t" + +[export] +exclude = ["Option_OutputId", "Option_InputId"] + +[defines] +"target_endian = big" = "WORDS_BIGENDIAN" [enum] prefix_with_name = true diff --git a/crates/engine_xetex/src/c_api/dvi.rs b/crates/engine_xetex/src/c_api/dvi.rs new file mode 100644 index 000000000..834eea839 --- /dev/null +++ b/crates/engine_xetex/src/c_api/dvi.rs @@ -0,0 +1,104 @@ +use std::cell::RefCell; +use std::ptr; +use tectonic_bridge_core::OutputId; + +thread_local! { + pub static DVI_CTX: RefCell = const { RefCell::new(DviCtx::new()) } +} + +pub struct DviCtx { + file: Option, + limit: i32, + ptr: i32, + offset: i32, + gone: i32, + buf: Vec, +} + +impl DviCtx { + const fn new() -> DviCtx { + DviCtx { + file: None, + limit: 0, + ptr: 0, + offset: 0, + gone: 0, + buf: Vec::new(), + } + } +} + +#[no_mangle] +pub extern "C" fn dvi_file() -> OutputId { + DVI_CTX.with_borrow(|dvi| dvi.file.unwrap()) +} + +#[no_mangle] +pub extern "C" fn set_dvi_file(file: OutputId) { + DVI_CTX.with_borrow_mut(|dvi| dvi.file = Some(file)) +} + +#[no_mangle] +pub extern "C" fn dvi_limit() -> i32 { + DVI_CTX.with_borrow(|dvi| dvi.limit) +} + +#[no_mangle] +pub extern "C" fn set_dvi_limit(val: i32) { + DVI_CTX.with_borrow_mut(|dvi| dvi.limit = val) +} + +#[no_mangle] +pub extern "C" fn dvi_ptr() -> i32 { + DVI_CTX.with_borrow(|dvi| dvi.ptr) +} + +#[no_mangle] +pub extern "C" fn set_dvi_ptr(val: i32) { + DVI_CTX.with_borrow_mut(|dvi| dvi.ptr = val) +} + +#[no_mangle] +pub extern "C" fn dvi_offset() -> i32 { + DVI_CTX.with_borrow(|dvi| dvi.offset) +} + +#[no_mangle] +pub extern "C" fn set_dvi_offset(val: i32) { + DVI_CTX.with_borrow_mut(|dvi| dvi.offset = val) +} + +#[no_mangle] +pub extern "C" fn dvi_gone() -> i32 { + DVI_CTX.with_borrow(|dvi| dvi.gone) +} + +#[no_mangle] +pub extern "C" fn set_dvi_gone(val: i32) { + DVI_CTX.with_borrow_mut(|dvi| dvi.gone = val) +} + +#[no_mangle] +pub extern "C" fn dvi_buf(idx: usize) -> u8 { + DVI_CTX.with_borrow(|engine| engine.buf[idx]) +} + +#[no_mangle] +pub extern "C" fn set_dvi_buf(idx: usize, val: u8) { + DVI_CTX.with_borrow_mut(|engine| engine.buf[idx] = val) +} + +#[no_mangle] +pub extern "C" fn dvi_buf_ptr(idx: usize) -> *mut u8 { + DVI_CTX.with_borrow_mut(|engine| ptr::from_mut(&mut engine.buf[idx])) +} + +#[no_mangle] +pub extern "C" fn resize_dvi_buf(len: usize) { + DVI_CTX.with_borrow_mut(|engine| engine.buf.resize(len, 0)) +} + +#[no_mangle] +pub extern "C" fn clear_dvi_buf() { + DVI_CTX.with_borrow_mut(|engine| engine.buf.clear()) +} diff --git a/crates/engine_xetex/src/c_api/engine.rs b/crates/engine_xetex/src/c_api/engine.rs new file mode 100644 index 000000000..0db5bb364 --- /dev/null +++ b/crates/engine_xetex/src/c_api/engine.rs @@ -0,0 +1,1021 @@ +use crate::c_api::globals::Globals; +use crate::ty::StrNumber; +use std::cell::RefCell; +use std::ffi::{CStr, CString}; +use std::{ptr, slice}; + +mod memory; + +use crate::c_api::is_dir_sep; +use crate::c_api::output::{rs_print, rs_print_ln, rs_print_nl_bytes}; +use crate::c_api::pool::{ + rs_make_string, rs_search_string, rs_slow_make_string, StringPool, EMPTY_STRING, TOO_BIG_CHAR, +}; +pub use memory::*; + +pub const NULL_CS: usize = 0x220001; +pub const PRIM_SIZE: usize = 2100; +pub const UNDEFINED_CONTROL_SEQUENCE: usize = 0x226603; +pub const FROZEN_NULL_FONT: usize = 0x2242da; +pub const DIMEN_VAL_LIMIT: usize = 128; + +pub const TEXT_SIZE: usize = 0; +pub const SCRIPT_SIZE: usize = 256; +pub const SCRIPT_SCRIPT_SIZE: usize = 512; + +thread_local! { + pub static ENGINE_CTX: RefCell = RefCell::new(EngineCtx::new()) +} + +pub struct EngineCtx { + pub(crate) selector: Selector, + pub(crate) tally: i32, + pub(crate) error_line: i32, + pub(crate) trick_count: i32, + pub(crate) trick_buf: [u16; 256], + pub(crate) eqtb_top: i32, + pub(crate) name_of_file: Option, + pub(crate) name_of_file_utf16: Option>, + pub(crate) file_name_quote_char: u16, + pub(crate) cur_name: StrNumber, + pub(crate) cur_area: StrNumber, + pub(crate) cur_ext: StrNumber, + pub(crate) job_name: StrNumber, + pub(crate) area_delimiter: usize, + pub(crate) ext_delimiter: usize, + pub(crate) name_in_progress: bool, + pub(crate) stop_at_space: bool, + pub(crate) quoted_filename: bool, + pub(crate) texmf_log_name: StrNumber, + pub(crate) log_opened: bool, + pub(crate) input_stack: Vec, + pub(crate) input_ptr: usize, + pub(crate) cur_input: InputState, + pub(crate) interaction: InteractionMode, + pub(crate) history: History, + + pub(crate) eqtb: Vec, + pub(crate) prim: Box<[B32x2; PRIM_SIZE + 1]>, + /// An arena of TeX nodes + pub(crate) mem: Vec, + pub(crate) buffer: Vec, +} + +#[derive(Copy, Clone, PartialEq, Eq)] +pub enum InteractionMode { + Batch = 0, + Nonstop, + Scroll, + ErrorStop, +} + +impl TryFrom for InteractionMode { + type Error = u8; + + fn try_from(value: u8) -> Result { + Ok(match value { + 0 => InteractionMode::Batch, + 1 => InteractionMode::Nonstop, + 2 => InteractionMode::Scroll, + 3 => InteractionMode::ErrorStop, + _ => return Err(value), + }) + } +} + +#[derive(Clone, Default, PartialEq)] +#[repr(C)] +pub struct InputState { + /// tokenizer state: mid_line, skip_blanks, new_line + state: u16, + /// index of this level of input in input_file array + index: u16, + /// position of beginning of current line in `buffer` + start: i32, + /// position of next character to read in `buffer` + loc: i32, + /// position of end of line in `buffer` + limit: i32, + /// name of current file or magic value for terminal, etc. + name: StrNumber, + synctex_tag: i32, +} + +struct NodeError { + ty: u16, + subty: u16, +} + +#[derive(Copy, Clone, PartialEq, Eq)] +#[repr(C)] +pub enum History { + Spotless = 0, + WarningIssued = 1, + ErrorIssued = 2, + FatalError = 3, +} + +impl TryFrom for History { + type Error = u8; + + fn try_from(value: u8) -> Result { + Ok(match value { + 0 => History::Spotless, + 1 => History::WarningIssued, + 2 => History::ErrorIssued, + 3 => History::FatalError, + _ => return Err(value), + }) + } +} + +impl EngineCtx { + fn new() -> EngineCtx { + EngineCtx { + selector: Selector::File(0), + tally: 0, + error_line: 0, + trick_count: 0, + trick_buf: [0; 256], + eqtb_top: 0, + name_of_file: None, + name_of_file_utf16: None, + file_name_quote_char: 0, + cur_area: 0, + cur_ext: 0, + cur_name: 0, + job_name: 0, + area_delimiter: 0, + ext_delimiter: 0, + name_in_progress: false, + stop_at_space: false, + quoted_filename: false, + texmf_log_name: 0, + log_opened: false, + input_stack: Vec::new(), + input_ptr: 0, + cur_input: InputState::default(), + interaction: InteractionMode::Batch, + history: History::Spotless, + + eqtb: Vec::new(), + prim: Box::new([B32x2 { s0: 0, s1: 0 }; PRIM_SIZE + 1]), + mem: Vec::new(), + buffer: Vec::new(), + } + } + + pub fn raw_mem(&self, idx: usize) -> MemoryWord { + self.mem[idx] + } + + pub fn try_node(&self, idx: usize) -> Result<&T, NodeError> { + let ptr = self.mem.as_ptr().wrapping_add(idx); + let base = unsafe { &*NodeBase::from_ptr(ptr) }; + + if T::ty() != base.ty() || T::subty().is_some_and(|subty| subty != base.subty()) { + return Err(NodeError { + ty: base.ty(), + subty: base.subty(), + }); + } + + let ptr = unsafe { T::from_ptr(ptr) }; + Ok(unsafe { &*ptr }) + } + + pub fn base_node(&self, idx: usize) -> &NodeBase { + let ptr = self.mem.as_ptr().wrapping_add(idx); + let ptr = NodeBase::from_ptr(ptr); + unsafe { &*ptr } + } + + pub fn node(&self, idx: usize) -> &T { + match self.try_node::(idx) { + Ok(node) => node, + Err(e) => { + panic!( + "Invalid node type. expected {}:{:?}, found {}:{}", + T::ty(), + T::subty(), + e.ty, + e.subty, + ); + } + } + } + + pub fn int_par(&self, par: IntPar) -> i32 { + unsafe { self.eqtb[INT_BASE + par as usize].b32.s1 } + } + + pub fn set_int_par(&mut self, par: IntPar, val: i32) { + self.eqtb[INT_BASE + par as usize].b32.s1 = val + } + + pub fn cat_code(&self, p: usize) -> Result { + let val = unsafe { self.eqtb[CAT_CODE_BASE + p].b32.s1 }; + CatCode::try_from(val) + } +} + +#[derive(Copy, Clone, PartialEq)] +pub enum Selector { + File(u8), + NoPrint, + TermOnly, + LogOnly, + TermAndLog, + Pseudo, + NewString, +} + +impl From for u32 { + fn from(value: Selector) -> Self { + match value { + Selector::File(val) => val as u32, + Selector::NoPrint => 16, + Selector::TermOnly => 17, + Selector::LogOnly => 18, + Selector::TermAndLog => 19, + Selector::Pseudo => 20, + Selector::NewString => 21, + } + } +} + +impl TryFrom for Selector { + type Error = (); + + fn try_from(value: u32) -> Result { + match value { + val @ 0..16 => Ok(Selector::File(val as u8)), + 16 => Ok(Selector::NoPrint), + 17 => Ok(Selector::TermOnly), + 18 => Ok(Selector::LogOnly), + 19 => Ok(Selector::TermAndLog), + 20 => Ok(Selector::Pseudo), + 21 => Ok(Selector::NewString), + _ => Err(()), + } + } +} + +#[no_mangle] +pub extern "C" fn selector() -> u32 { + ENGINE_CTX.with_borrow(|engine| engine.selector.into()) +} + +#[no_mangle] +pub extern "C" fn set_selector(val: u32) { + ENGINE_CTX.with_borrow_mut(|engine| engine.selector = Selector::try_from(val).unwrap()); +} + +#[no_mangle] +pub extern "C" fn tally() -> i32 { + ENGINE_CTX.with_borrow(|engine| engine.tally) +} + +#[no_mangle] +pub extern "C" fn set_tally(val: i32) { + ENGINE_CTX.with_borrow_mut(|engine| engine.tally = val) +} + +#[no_mangle] +pub extern "C" fn error_line() -> i32 { + ENGINE_CTX.with_borrow(|engine| engine.error_line) +} + +#[no_mangle] +pub extern "C" fn set_error_line(val: i32) { + ENGINE_CTX.with_borrow_mut(|engine| engine.error_line = val) +} + +#[no_mangle] +pub extern "C" fn trick_count() -> i32 { + ENGINE_CTX.with_borrow(|engine| engine.trick_count) +} + +#[no_mangle] +pub extern "C" fn set_trick_count(val: i32) { + ENGINE_CTX.with_borrow_mut(|engine| engine.trick_count = val) +} + +#[no_mangle] +pub extern "C" fn trick_buf(idx: usize) -> u16 { + ENGINE_CTX.with_borrow(|engine| engine.trick_buf[idx]) +} + +#[no_mangle] +pub extern "C" fn set_trick_buf(idx: usize, val: u16) { + ENGINE_CTX.with_borrow_mut(|engine| engine.trick_buf[idx] = val) +} + +#[no_mangle] +pub extern "C" fn eqtb_top() -> i32 { + ENGINE_CTX.with_borrow(|engine| engine.eqtb_top) +} + +#[no_mangle] +pub extern "C" fn set_eqtb_top(val: i32) { + ENGINE_CTX.with_borrow_mut(|engine| engine.eqtb_top = val) +} + +#[no_mangle] +pub extern "C" fn name_length() -> usize { + ENGINE_CTX.with_borrow(|engine| { + engine + .name_of_file + .as_ref() + .map(|s| s.count_bytes()) + .unwrap_or(0) + }) +} + +#[no_mangle] +pub extern "C" fn name_of_file() -> *const libc::c_char { + ENGINE_CTX.with_borrow(|engine| { + engine + .name_of_file + .as_ref() + .map(|s| s.as_ptr()) + .unwrap_or(ptr::null()) + }) +} + +#[no_mangle] +pub extern "C" fn set_name_of_file(val: *const libc::c_char) { + let s = if val.is_null() { + None + } else { + Some(unsafe { CStr::from_ptr(val) }) + }; + ENGINE_CTX.with_borrow_mut(|engine| engine.name_of_file = s.map(CStr::to_owned)) +} + +#[no_mangle] +pub extern "C" fn name_length16() -> usize { + ENGINE_CTX.with_borrow(|engine| { + engine + .name_of_file_utf16 + .as_ref() + .map(|s| s.len()) + .unwrap_or(0) + }) +} + +#[no_mangle] +pub extern "C" fn name_of_file16() -> *const u16 { + ENGINE_CTX.with_borrow(|engine| { + engine + .name_of_file_utf16 + .as_ref() + .map(|s| s.as_ptr()) + .unwrap_or(ptr::null()) + }) +} + +#[no_mangle] +pub extern "C" fn set_name_of_file16(val: *const u16, len: usize) { + let s = if val.is_null() { + None + } else { + Some(unsafe { slice::from_raw_parts(val, len) }) + }; + ENGINE_CTX.with_borrow_mut(|engine| engine.name_of_file_utf16 = s.map(<[u16]>::to_owned)) +} + +#[no_mangle] +pub extern "C" fn cur_name() -> StrNumber { + ENGINE_CTX.with_borrow(|engine| engine.cur_name) +} + +#[no_mangle] +pub extern "C" fn set_cur_name(val: StrNumber) { + ENGINE_CTX.with_borrow_mut(|engine| engine.cur_name = val) +} + +#[no_mangle] +pub extern "C" fn cur_area() -> StrNumber { + ENGINE_CTX.with_borrow(|engine| engine.cur_area) +} + +#[no_mangle] +pub extern "C" fn set_cur_area(val: StrNumber) { + ENGINE_CTX.with_borrow_mut(|engine| engine.cur_area = val) +} + +#[no_mangle] +pub extern "C" fn cur_ext() -> StrNumber { + ENGINE_CTX.with_borrow(|engine| engine.cur_ext) +} + +#[no_mangle] +pub extern "C" fn set_cur_ext(val: StrNumber) { + ENGINE_CTX.with_borrow_mut(|engine| engine.cur_ext = val) +} + +#[no_mangle] +pub extern "C" fn job_name() -> StrNumber { + ENGINE_CTX.with_borrow(|engine| engine.job_name) +} + +#[no_mangle] +pub extern "C" fn set_job_name(val: StrNumber) { + ENGINE_CTX.with_borrow_mut(|engine| engine.job_name = val) +} + +#[no_mangle] +pub extern "C" fn area_delimiter() -> usize { + ENGINE_CTX.with_borrow(|engine| engine.area_delimiter) +} + +#[no_mangle] +pub extern "C" fn set_area_delimiter(val: usize) { + ENGINE_CTX.with_borrow_mut(|engine| engine.area_delimiter = val) +} + +#[no_mangle] +pub extern "C" fn ext_delimiter() -> usize { + ENGINE_CTX.with_borrow(|engine| engine.ext_delimiter) +} + +#[no_mangle] +pub extern "C" fn set_ext_delimiter(val: usize) { + ENGINE_CTX.with_borrow_mut(|engine| engine.ext_delimiter = val) +} + +#[no_mangle] +pub extern "C" fn name_in_progress() -> bool { + ENGINE_CTX.with_borrow(|engine| engine.name_in_progress) +} + +#[no_mangle] +pub extern "C" fn set_name_in_progress(val: bool) { + ENGINE_CTX.with_borrow_mut(|engine| engine.name_in_progress = val) +} + +#[no_mangle] +pub extern "C" fn stop_at_space() -> bool { + ENGINE_CTX.with_borrow(|engine| engine.stop_at_space) +} + +#[no_mangle] +pub extern "C" fn set_stop_at_space(val: bool) { + ENGINE_CTX.with_borrow_mut(|engine| engine.stop_at_space = val) +} + +#[no_mangle] +pub extern "C" fn file_name_quote_char() -> u16 { + ENGINE_CTX.with_borrow(|engine| engine.file_name_quote_char) +} + +#[no_mangle] +pub extern "C" fn set_file_name_quote_char(val: u16) { + ENGINE_CTX.with_borrow_mut(|engine| engine.file_name_quote_char = val) +} + +#[no_mangle] +pub extern "C" fn quoted_filename() -> bool { + ENGINE_CTX.with_borrow(|engine| engine.quoted_filename) +} + +#[no_mangle] +pub extern "C" fn set_quoted_filename(val: bool) { + ENGINE_CTX.with_borrow_mut(|engine| engine.quoted_filename = val) +} + +#[no_mangle] +pub extern "C" fn texmf_log_name() -> StrNumber { + ENGINE_CTX.with_borrow(|engine| engine.texmf_log_name) +} + +#[no_mangle] +pub extern "C" fn set_texmf_log_name(val: StrNumber) { + ENGINE_CTX.with_borrow_mut(|engine| engine.texmf_log_name = val) +} + +#[no_mangle] +pub extern "C" fn log_opened() -> bool { + ENGINE_CTX.with_borrow(|engine| engine.log_opened) +} + +#[no_mangle] +pub extern "C" fn set_log_opened(val: bool) { + ENGINE_CTX.with_borrow_mut(|engine| engine.log_opened = val) +} + +#[no_mangle] +pub extern "C" fn resize_input_stack(len: usize) { + ENGINE_CTX.with_borrow_mut(|engine| engine.input_stack.resize(len, InputState::default())) +} + +#[no_mangle] +pub extern "C" fn input_stack(idx: usize) -> InputState { + ENGINE_CTX.with_borrow(|engine| engine.input_stack[idx].clone()) +} + +#[no_mangle] +pub extern "C" fn set_input_stack(idx: usize, state: InputState) { + ENGINE_CTX.with_borrow_mut(|engine| engine.input_stack[idx] = state) +} + +#[no_mangle] +pub extern "C" fn clear_input_stack() { + ENGINE_CTX.with_borrow_mut(|engine| engine.input_stack.clear()) +} + +#[no_mangle] +pub extern "C" fn input_ptr() -> usize { + ENGINE_CTX.with_borrow(|engine| engine.input_ptr) +} + +#[no_mangle] +pub extern "C" fn set_input_ptr(val: usize) { + ENGINE_CTX.with_borrow_mut(|engine| engine.input_ptr = val) +} + +#[no_mangle] +pub extern "C" fn cur_input() -> InputState { + ENGINE_CTX.with_borrow(|engine| engine.cur_input.clone()) +} + +#[no_mangle] +pub extern "C" fn cur_input_ptr() -> *mut InputState { + ENGINE_CTX.with_borrow_mut(|engine| ptr::from_mut(&mut engine.cur_input)) +} + +#[no_mangle] +pub extern "C" fn set_cur_input(val: InputState) { + ENGINE_CTX.with_borrow_mut(|engine| engine.cur_input = val) +} + +#[no_mangle] +pub extern "C" fn interaction() -> u8 { + ENGINE_CTX.with_borrow(|engine| engine.interaction as u8) +} + +#[no_mangle] +pub extern "C" fn set_interaction(val: u8) { + ENGINE_CTX + .with_borrow_mut(|engine| engine.interaction = InteractionMode::try_from(val).unwrap()) +} + +#[no_mangle] +pub extern "C" fn history() -> History { + ENGINE_CTX.with_borrow(|engine| engine.history) +} + +#[no_mangle] +pub extern "C" fn set_history(val: u8) { + ENGINE_CTX.with_borrow_mut(|engine| engine.history = History::try_from(val).unwrap()) +} + +#[no_mangle] +pub extern "C" fn eqtb(idx: usize) -> MemoryWord { + ENGINE_CTX.with_borrow(|engine| engine.eqtb[idx]) +} + +#[no_mangle] +pub extern "C" fn set_eqtb(idx: usize, val: MemoryWord) { + ENGINE_CTX.with_borrow_mut(|engine| engine.eqtb[idx] = val) +} + +#[no_mangle] +pub extern "C" fn eqtb_ptr(idx: usize) -> *mut MemoryWord { + ENGINE_CTX.with_borrow_mut(|engine| ptr::from_mut(&mut engine.eqtb[idx])) +} + +#[no_mangle] +pub extern "C" fn resize_eqtb(len: usize) { + ENGINE_CTX.with_borrow_mut(|engine| { + engine.eqtb.resize( + len, + MemoryWord { + ptr: ptr::null_mut(), + }, + ) + }) +} + +#[no_mangle] +pub extern "C" fn clear_eqtb() { + ENGINE_CTX.with_borrow_mut(|engine| engine.eqtb.clear()) +} + +#[no_mangle] +pub extern "C" fn mem(idx: usize) -> MemoryWord { + ENGINE_CTX.with_borrow(|engine| engine.mem[idx]) +} + +#[no_mangle] +pub extern "C" fn set_mem(idx: usize, val: MemoryWord) { + ENGINE_CTX.with_borrow_mut(|engine| engine.mem[idx] = val) +} + +#[no_mangle] +pub extern "C" fn mem_ptr(idx: usize) -> *mut MemoryWord { + ENGINE_CTX.with_borrow_mut(|engine| ptr::from_mut(&mut engine.mem[idx])) +} + +#[no_mangle] +pub extern "C" fn resize_mem(len: usize) { + ENGINE_CTX.with_borrow_mut(|engine| { + engine.mem.resize( + len, + MemoryWord { + ptr: ptr::null_mut(), + }, + ) + }) +} + +#[no_mangle] +pub extern "C" fn clear_mem() { + ENGINE_CTX.with_borrow_mut(|engine| engine.mem.clear()) +} + +#[no_mangle] +pub extern "C" fn prim(idx: usize) -> B32x2 { + ENGINE_CTX.with_borrow(|engine| engine.prim[idx]) +} + +#[no_mangle] +pub extern "C" fn set_prim(idx: usize, val: B32x2) { + ENGINE_CTX.with_borrow_mut(|engine| engine.prim[idx] = val) +} + +#[no_mangle] +pub extern "C" fn prim_ptr(idx: usize) -> *mut B32x2 { + ENGINE_CTX.with_borrow_mut(|engine| ptr::from_mut(&mut engine.prim[idx])) +} + +#[no_mangle] +pub extern "C" fn resize_buffer(len: usize) { + ENGINE_CTX.with_borrow_mut(|engine| engine.buffer.resize(len, '\0')) +} + +#[no_mangle] +pub extern "C" fn buffer_ptr() -> *mut char { + ENGINE_CTX.with_borrow_mut(|engine| engine.buffer.as_mut_ptr()) +} + +#[no_mangle] +pub extern "C" fn buffer(idx: usize) -> char { + ENGINE_CTX.with_borrow(|engine| engine.buffer[idx]) +} + +#[no_mangle] +pub extern "C" fn set_buffer(idx: usize, val: u32) { + ENGINE_CTX.with_borrow_mut(|engine| { + engine.buffer[idx] = char::from_u32(val).unwrap_or(char::REPLACEMENT_CHARACTER) + }) +} + +#[no_mangle] +pub extern "C" fn clear_buffer() { + ENGINE_CTX.with_borrow_mut(|engine| engine.buffer.clear()) +} + +fn checkpool_pointer(pool: &mut StringPool, pool_ptr: usize, len: usize) { + if pool_ptr + len >= pool.pool_size { + panic!("string pool overflow [{} bytes]", pool.pool_size); + } +} + +pub fn rs_maketexstring(globals: &mut Globals<'_, '_>, str: &str) -> StrNumber { + if str.len() == 0 { + return EMPTY_STRING; + } + + checkpool_pointer(globals.strings, globals.strings.pool_ptr, str.len()); + + for b in str.encode_utf16() { + globals.strings.str_pool[globals.strings.pool_ptr] = b; + globals.strings.pool_ptr += 1; + } + + rs_make_string(globals.strings) +} + +pub fn rs_gettexstring(globals: &mut Globals<'_, '_>, s: StrNumber) -> String { + if s < 0x10000 { + return String::new(); + } + + let str = globals.strings.str(s - 0x10000); + + String::from_utf16_lossy(str) +} + +pub fn rs_pack_file_name(globals: &mut Globals<'_, '_>, n: StrNumber, a: StrNumber, e: StrNumber) { + let n = globals.strings.tex_str(n); + let a = globals.strings.tex_str(a); + let e = globals.strings.tex_str(e); + let mut buffer = String::with_capacity(n.len() + a.len() + e.len()); + + let iter = a.iter().chain(n).chain(e).copied(); + for c in char::decode_utf16(iter) { + let c = c.unwrap_or(char::REPLACEMENT_CHARACTER); + buffer.push(c); + } + + globals.engine.name_of_file = Some(CString::new(buffer).unwrap()); +} + +pub fn rs_pack_job_name(globals: &mut Globals<'_, '_>, s: &str) { + globals.engine.cur_area = EMPTY_STRING; + globals.engine.cur_ext = rs_maketexstring(globals, s); + globals.engine.cur_name = globals.engine.job_name; + rs_pack_file_name( + globals, + globals.engine.cur_name, + globals.engine.cur_area, + globals.engine.cur_ext, + ); +} + +pub fn rs_make_utf16_name(engine: &mut EngineCtx) { + engine.name_of_file_utf16 = engine + .name_of_file + .as_ref() + .and_then(|name| name.to_str().ok()) + .map(|s| s.encode_utf16().collect()); +} + +pub fn rs_begin_name(globals: &mut Globals<'_, '_>) { + globals.engine.area_delimiter = 0; + globals.engine.ext_delimiter = 0; + globals.engine.quoted_filename = false; + globals.engine.file_name_quote_char = 0; +} + +pub fn rs_end_name(globals: &mut Globals<'_, '_>) { + if globals.strings.str_ptr + 3 > globals.strings.max_strings { + todo!("overflow(\"number of strings\", max_strings() - init_str_ptr)"); + } + + /* area_delimiter is the length from the start of the filename to the + * directory seperator "/", which we use to construct the stringpool + * string `cur_area`. If there was already a string in the stringpool for + * the area, reuse it. */ + + if globals.engine.area_delimiter == 0 { + globals.engine.cur_area = EMPTY_STRING; + } else { + globals.engine.cur_area = globals.strings.str_ptr as StrNumber; + globals.strings.str_start[globals.strings.str_ptr + 1 - 0x10000] = + globals.strings.str_start[globals.strings.str_ptr - TOO_BIG_CHAR] + + globals.engine.area_delimiter as u32; + globals.strings.str_ptr += 1; + + let temp_str = rs_search_string(globals.strings, globals.engine.cur_area); + + if temp_str > 0 { + globals.engine.cur_area = temp_str; + globals.strings.str_ptr -= 1; + + for j in (globals.strings.str_start[globals.strings.str_ptr + 1 - 0x10000] as usize) + ..globals.strings.pool_ptr + { + globals.strings.str_pool[j - globals.engine.area_delimiter] = + globals.strings.str_pool[j]; + } + + globals.strings.pool_ptr -= globals.engine.area_delimiter; + } + } + + /* ext_delimiter is the length from the start of the filename to the + * extension '.' delimiter, which we use to construct the stringpool + * strings `cur_ext` and `cur_name`. */ + + if globals.engine.ext_delimiter == 0 { + globals.engine.cur_ext = EMPTY_STRING; + globals.engine.cur_name = rs_slow_make_string(globals.strings); + } else { + globals.engine.cur_name = globals.strings.str_ptr as StrNumber; + globals.strings.str_start[globals.strings.str_ptr + 1 - 0x10000] = + globals.strings.str_start[globals.strings.str_ptr - TOO_BIG_CHAR] + + globals.engine.ext_delimiter as u32 + - globals.engine.area_delimiter as u32 + - 1; + globals.strings.str_ptr += 1; + + globals.engine.cur_ext = rs_make_string(globals.strings); + globals.strings.str_ptr -= 1; + + let temp_str = rs_search_string(globals.strings, globals.engine.cur_name); + + if temp_str > 0 { + globals.engine.cur_name = temp_str; + globals.strings.str_ptr -= 1; + + for j in (globals.strings.str_start[globals.strings.str_ptr + 1 - 0x10000] as usize) + ..globals.strings.pool_ptr + { + globals.strings.str_pool + [j - globals.engine.ext_delimiter + globals.engine.area_delimiter + 1] = + globals.strings.str_pool[j]; + } + + globals.strings.pool_ptr -= + globals.engine.ext_delimiter - globals.engine.area_delimiter - 1; + } + } + + globals.engine.cur_ext = rs_slow_make_string(globals.strings); +} + +pub fn rs_more_name(globals: &mut Globals<'_, '_>, c: u16) -> bool { + if globals.engine.stop_at_space && globals.engine.file_name_quote_char == 0 && c == ' ' as u16 { + return false; + } + + if globals.engine.stop_at_space + && globals.engine.file_name_quote_char != 0 + && c == globals.engine.file_name_quote_char + { + globals.engine.file_name_quote_char = 0; + return true; + } + + if globals.engine.stop_at_space + && globals.engine.file_name_quote_char == 0 + && (c == '"' as u16 || c == '\'' as u16) + { + globals.engine.file_name_quote_char = c; + globals.engine.quoted_filename = true; + return true; + } + + if globals.strings.pool_ptr + 1 > globals.strings.pool_size { + todo!("overflow(\"pool size\", pool_size() - init_pool_ptr)"); + } + + globals.strings.str_pool[globals.strings.pool_ptr as usize] = c; + globals.strings.pool_ptr += 1; + + if is_dir_sep(char::from_u32(c as u32).unwrap_or(char::REPLACEMENT_CHARACTER)) { + globals.engine.area_delimiter = globals.strings.cur_length(); + globals.engine.ext_delimiter = 0; + } else if c == '.' as u16 { + globals.engine.ext_delimiter = globals.strings.cur_length(); + } + + true +} + +pub fn rs_make_name_string(globals: &mut Globals<'_, '_>) -> StrNumber { + if globals.strings.pool_ptr + + globals + .engine + .name_of_file + .as_ref() + .map(|n| n.count_bytes()) + .unwrap_or(0) + > globals.strings.pool_size + || globals.strings.str_ptr == globals.strings.max_strings + { + return '?' as StrNumber; + } + + rs_make_utf16_name(globals.engine); + + // TODO: Don't allocate and set name_of_file, just use encode_utf16 + if let Some(s) = globals.engine.name_of_file_utf16.as_deref() { + for &c in s { + globals.strings.str_pool[globals.strings.pool_ptr] = c; + globals.strings.pool_ptr += 1; + } + } + + let res = rs_make_string(globals.strings); + + let save = ( + globals.engine.area_delimiter, + globals.engine.ext_delimiter, + globals.engine.name_in_progress, + globals.engine.stop_at_space, + ); + globals.engine.name_in_progress = true; + rs_begin_name(globals); + globals.engine.stop_at_space = false; + + let name = globals.engine.name_of_file_utf16.take(); + // Needed for side-effects + name.as_deref() + .and_then(|s| s.iter().find(|&c| !rs_more_name(globals, *c))); + globals.engine.name_of_file_utf16 = name; + + globals.engine.stop_at_space = save.3; + rs_end_name(globals); + globals.engine.name_in_progress = save.2; + globals.engine.ext_delimiter = save.1; + globals.engine.area_delimiter = save.0; + + res +} + +#[no_mangle] +pub unsafe extern "C" fn maketexstring(str: *const libc::c_char) -> StrNumber { + if str.is_null() { + return EMPTY_STRING; + } + let str = unsafe { CStr::from_ptr(str) }.to_string_lossy(); + Globals::with(|globals| rs_maketexstring(globals, &str)) +} + +#[no_mangle] +pub unsafe extern "C" fn gettexstring(s: StrNumber) -> *mut libc::c_char { + let str = Globals::with(|globals| rs_gettexstring(globals, s)); + let out = unsafe { libc::malloc(str.len() + 1) }.cast::(); + unsafe { ptr::copy_nonoverlapping(str.as_ptr().cast(), out, str.len()) }; + unsafe { out.add(str.len()).write(0) }; + out +} + +#[no_mangle] +pub extern "C" fn pack_file_name(n: StrNumber, a: StrNumber, e: StrNumber) { + Globals::with(|globals| rs_pack_file_name(globals, n, a, e)) +} + +#[no_mangle] +pub extern "C" fn pack_job_name(s: *const libc::c_char) { + let s = unsafe { CStr::from_ptr(s) }.to_str().unwrap(); + Globals::with(|globals| rs_pack_job_name(globals, s)) +} + +#[no_mangle] +pub extern "C" fn make_utf16_name() { + ENGINE_CTX.with_borrow_mut(|engine| rs_make_utf16_name(engine)) +} + +#[no_mangle] +pub extern "C" fn begin_name() { + Globals::with(|globals| rs_begin_name(globals)) +} + +#[no_mangle] +pub extern "C" fn end_name() { + Globals::with(|globals| rs_end_name(globals)) +} + +#[no_mangle] +pub extern "C" fn more_name(c: u16) -> bool { + Globals::with(|globals| rs_more_name(globals, c)) +} + +#[no_mangle] +pub extern "C" fn make_name_string() -> StrNumber { + Globals::with(|globals| rs_make_name_string(globals)) +} + +pub fn rs_open_log_file(globals: &mut Globals<'_, '_>) { + let old = globals.engine.selector; + + if globals.engine.job_name == 0 { + globals.engine.job_name = rs_maketexstring(globals, "texput"); + } + + rs_pack_job_name(globals, ".log"); + + let file_name = globals + .engine + .name_of_file + .as_ref() + .unwrap() + .to_string_lossy(); + match globals.state.output_open(&file_name, false) { + Some(file) => globals.out.log_file = Some(file), + None => panic!("cannot open log file output \"{}\"", file_name), + } + + globals.engine.texmf_log_name = rs_make_name_string(globals); + globals.engine.selector = Selector::LogOnly; + globals.engine.log_opened = true; + + globals.engine.input_stack[globals.engine.input_ptr] = globals.engine.cur_input.clone(); + + rs_print_nl_bytes(globals, b"**"); + let mut l = globals.engine.input_stack[0].limit as usize; + if globals.engine.buffer[l] as i32 == globals.engine.int_par(IntPar::EndLineChar) { + l -= 1; + } + + for k in 1..=l { + rs_print(globals, globals.engine.buffer[k] as i32) + } + + rs_print_ln(globals); + globals.engine.selector = match old { + Selector::NoPrint => Selector::LogOnly, + Selector::TermOnly => Selector::TermAndLog, + _ => panic!(), + }; +} + +#[no_mangle] +pub extern "C" fn open_log_file() { + Globals::with(|globals| rs_open_log_file(globals)) +} diff --git a/crates/engine_xetex/src/c_api/engine/memory.rs b/crates/engine_xetex/src/c_api/engine/memory.rs new file mode 100644 index 000000000..594910b65 --- /dev/null +++ b/crates/engine_xetex/src/c_api/engine/memory.rs @@ -0,0 +1,433 @@ +/* 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] + * + */ + +use std::{fmt, ptr}; + +#[cfg(target_endian = "big")] +mod data { + #[derive(Copy, Clone)] + #[repr(C)] + pub struct B32x2 { + s1: i32, + s0: i32, + } + + #[derive(Copy, Clone)] + #[repr(C)] + pub struct B16x4 { + s3: u16, + s2: u16, + s1: u16, + s0: u16, + } +} + +#[cfg(not(target_endian = "big"))] +mod data { + #[derive(Copy, Clone)] + #[repr(C)] + pub struct B32x2 { + pub(crate) s0: i32, + pub(crate) s1: i32, + } + + #[derive(Copy, Clone)] + #[repr(C)] + pub struct B16x4 { + pub(crate) s0: u16, + pub(crate) s1: u16, + pub(crate) s2: u16, + pub(crate) s3: u16, + } +} + +pub use data::*; + +#[derive(Copy, Clone)] +#[repr(C)] +pub union MemoryWord { + pub(crate) b32: B32x2, + pub(crate) b16: B16x4, + pub(crate) gr: f64, + pub(crate) ptr: *mut (), +} + +impl MemoryWord { + pub fn i32_0(&self) -> i32 { + unsafe { self.b32.s0 } + } + + pub fn i32_1(&self) -> i32 { + unsafe { self.b32.s1 } + } + + pub fn u16_0(&self) -> u16 { + unsafe { self.b16.s0 } + } + + pub fn u16_1(&self) -> u16 { + unsafe { self.b16.s1 } + } + + pub fn u16_2(&self) -> u16 { + unsafe { self.b16.s2 } + } + + pub fn u16_3(&self) -> u16 { + unsafe { self.b16.s3 } + } + + pub fn f64(&self) -> f64 { + unsafe { self.gr } + } + + pub fn ptr(&self) -> *mut () { + unsafe { self.ptr } + } +} + +/* ## 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 int32_t (called `cint`), and a + * pointer (`ptr`). + * + * Original struct definition, LITTLE ENDIAN (condensed): + * + * typedef union { + * struct { int32_t LH, RH; } v; + * struct { short B1, B0; } u; + * } two_halves; + * + * typedef struct { + * struct { uint16_t B3, B2, B1, B0; } u; + * } four_quarters; + * + * typedef union { + * two_halves hh; + * + * struct { + * int32_t junk; + * int32_t 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 { int32_t RH, LH; } v; + * struct { + * int32_t junk; + * short B0, B1; + * } u; + * } two_halves; + * + * typedef struct { + * struct { uint16_t 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` + * + */ + +/* Types of nodes that can occur in general lists. */ +pub const WHATSIT_NODE: u16 = 8; + +/* Subtypes for whatsit nodes. */ +pub const NATIVE_WORD_NODE: u16 = 40; + +pub trait Node { + /// Type of this node. `None` indicates types which are valid for all nodes. + fn ty() -> u16; + /// Subtype of this node. `None` indicates types which are valid for all subtypes. + fn subty() -> Option; + + unsafe fn from_ptr(ptr: *const MemoryWord) -> *const Self; + unsafe fn from_ptr_mut(ptr: *mut MemoryWord) -> *mut Self; +} + +#[repr(C)] +pub struct NodeBase(MemoryWord); + +impl NodeBase { + pub(super) fn from_ptr(ptr: *const MemoryWord) -> *const NodeBase { + ptr.cast() + } + + pub fn ty(&self) -> u16 { + unsafe { self.0.b16.s1 } + } + + pub fn subty(&self) -> u16 { + unsafe { self.0.b16.s0 } + } + + pub fn next(&self) -> usize { + unsafe { self.0.b32.s1 as usize } + } +} + +impl fmt::Debug for NodeBase { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("NodeBase") + .field("ty", &self.ty()) + .field("subty", &self.subty()) + .finish() + } +} + +#[repr(C)] +pub struct NativeWordNode { + // p + node: NodeBase, + // p + 1..p + 3 + _priv: [MemoryWord; 3], + // p + 4 - most data is here + data: B16x4, + // p + 5 - glyph_info pointer + glyph_info: *mut (), + // p+6.. - text in this node + text: [u16], +} + +impl Node for NativeWordNode { + fn ty() -> u16 { + WHATSIT_NODE + } + + fn subty() -> Option { + Some(NATIVE_WORD_NODE) + } + + unsafe fn from_ptr(ptr: *const MemoryWord) -> *const Self { + let this = ptr::slice_from_raw_parts(ptr, 0) as *const Self; + let len = (*this).len(); + ptr::slice_from_raw_parts(ptr, len) as *const Self + } + + unsafe fn from_ptr_mut(ptr: *mut MemoryWord) -> *mut Self { + let this = ptr::slice_from_raw_parts_mut(ptr, 0) as *mut Self; + let len = (*this).len(); + ptr::slice_from_raw_parts_mut(ptr, len) as *mut Self + } +} + +impl NativeWordNode { + pub fn base(&self) -> &NodeBase { + &self.node + } + + pub fn len(&self) -> usize { + self.data.s1 as usize + } + + pub fn text(&self) -> &[u16] { + &self.text + } +} + +pub const EQTB_SIZE: usize = 0x886f92; + +pub const ACTIVE_BASE: usize = 0x1; +pub const SINGLE_BASE: usize = 0x110001; +pub const PRIM_EQTB_BASE: usize = 0x223aa6; +pub const CAT_CODE_BASE: usize = 0x226d29; +pub const INT_BASE: usize = 0x776d29; +pub const INT_PARS: usize = 83; + +#[derive(Copy, Clone, PartialEq)] +pub enum CatCode { + Escape = 0, + CarRet = 5, + Ignore = 9, + Spacer = 10, + Letter = 11, + OtherChar = 12, + Comment = 14, + InvalidChar = 15, + Data = 122, +} + +impl TryFrom for CatCode { + type Error = i32; + + fn try_from(value: i32) -> Result { + Ok(match value { + 0 => CatCode::Escape, + 5 => CatCode::CarRet, + 9 => CatCode::Ignore, + 10 => CatCode::Spacer, + 11 => CatCode::Letter, + 12 => CatCode::OtherChar, + 14 => CatCode::Comment, + 15 => CatCode::InvalidChar, + 122 => CatCode::Data, + _ => return Err(value), + }) + } +} + +/// Integer parameters +pub enum IntPar { + PreTolerance = 0, + Tolerance, + LinePenalty, + HyphenPenalty, + ExHyphenPenalty, + ClubPenalty, + WidowPenalty, + DisplayWidowPenalty, + BrokenPenalty, + BinOpPenalty, + RelPenalty, + PreDisplayPenalty, + PostDisplayPenalty, + InterLinePenalty, + DoubleHyphenDemerits, + FinalHyphenDemerits, + AdjDemerits, + Mag, + DelimiterFactor, + Looseness, + Time, + Day, + Month, + Year, + ShowBoxBreadth, + ShowBoxDepth, + HBadness, + VBadness, + Pausing, + TracingOnline, + TracingMacros, + TracingStats, + TracingParagraphs, + TracingPages, + TracingOutput, + TracingLostChars, + TracingCommands, + TracingRestores, + UcHyph, + OutputPenalty, + MaxDeadCycles, + HangAfter, + FloatingPenalty, + GlobalDefs, + CurFam, + EscapeChar, + DefaultHyphenChar, + DefaultSkewChar, + EndLineChar, + NewLineChar, + Language, + LeftHyphenMin, + RightHyphenMin, + HoldingInserts, + ErrorContextLines, + TracingStackLevels, + TracingAssigns, + TracingGroups, + TracingIfs, + TracingScanTokens, + TracingNesting, + PreDisplayDirection, + LastLineFit, + SavingVDiscards, + SavingHyphCodes, + SuppressFontNotFoundError, + XetexLinebreakLocale, + XetexLinebreakPenalty, + XetexProtrudeChars, + Texxet, + XetexDashBreak, + XetexUpwards, + XetexUseGlyphMetrics, + XetexInterCharTokens, + XetexInputNormalization, + XetexDefaultInputMode, + XetexDefaultInputEncoding, + XetexTracingFonts, + XetexInterwordSpaceShaping, + XetexGenerateActualText, + XetexHyphenatableLength, + Synctex, + PdfOutput, +} diff --git a/crates/engine_xetex/src/c_api/errors.rs b/crates/engine_xetex/src/c_api/errors.rs new file mode 100644 index 000000000..b062ac381 --- /dev/null +++ b/crates/engine_xetex/src/c_api/errors.rs @@ -0,0 +1,30 @@ +use crate::c_api::engine::{rs_open_log_file, InteractionMode, Selector}; +use crate::c_api::globals::Globals; +use crate::c_api::output::rs_error_here_with_diagnostic; + +pub fn rs_pre_error_message(globals: &mut Globals<'_, '_>) { + if globals.engine.log_opened { + globals.engine.selector = Selector::TermAndLog; + } else { + globals.engine.selector = Selector::TermOnly; + } + + if globals.engine.job_name == 0 { + rs_open_log_file(globals); + } + + if globals.engine.interaction == InteractionMode::Batch { + globals.engine.selector = match globals.engine.selector { + Selector::TermAndLog => Selector::LogOnly, + Selector::TermOnly => Selector::NoPrint, + _ => panic!(), + } + } + + rs_error_here_with_diagnostic(globals, b""); +} + +#[no_mangle] +extern "C" fn pre_error_message() { + Globals::with(|globals| rs_pre_error_message(globals)) +} diff --git a/crates/engine_xetex/src/c_api/globals.rs b/crates/engine_xetex/src/c_api/globals.rs new file mode 100644 index 000000000..4fdedc60f --- /dev/null +++ b/crates/engine_xetex/src/c_api/globals.rs @@ -0,0 +1,47 @@ +use crate::c_api::dvi::{DviCtx, DVI_CTX}; +use crate::c_api::engine::{EngineCtx, ENGINE_CTX}; +use crate::c_api::hash::{HashCtx, HASH_CTX}; +use crate::c_api::inputs::{FileCtx, FILE_CTX}; +use crate::c_api::output::{OutputCtx, OUTPUT_CTX}; +use crate::c_api::pool::{StringPool, STRING_POOL}; +use tectonic_bridge_core::CoreBridgeState; + +#[non_exhaustive] +pub struct Globals<'a, 'b> { + pub state: &'a mut CoreBridgeState<'b>, + pub engine: &'a mut EngineCtx, + pub strings: &'a mut StringPool, + pub hash: &'a mut HashCtx, + pub files: &'a mut FileCtx, + pub out: &'a mut OutputCtx, + pub dvi: &'a mut DviCtx, +} + +impl Globals<'_, '_> { + pub fn with(f: impl for<'a, 'b> FnOnce(&mut Globals<'a, 'b>) -> T) -> T { + CoreBridgeState::with_global_state(|state| { + ENGINE_CTX.with_borrow_mut(|engine| { + STRING_POOL.with_borrow_mut(|strings| { + HASH_CTX.with_borrow_mut(|hash| { + FILE_CTX.with_borrow_mut(|files| { + OUTPUT_CTX.with_borrow_mut(|out| { + DVI_CTX.with_borrow_mut(|dvi| { + let mut globals = Globals { + state, + engine, + strings, + hash, + files, + out, + dvi, + }; + f(&mut globals) + }) + }) + }) + }) + }) + }) + }) + } +} diff --git a/crates/engine_xetex/src/c_api/hash.rs b/crates/engine_xetex/src/c_api/hash.rs new file mode 100644 index 000000000..bb58e2d2c --- /dev/null +++ b/crates/engine_xetex/src/c_api/hash.rs @@ -0,0 +1,87 @@ +use crate::c_api::engine::B32x2; +use std::cell::RefCell; +use std::ptr; + +pub const HASH_OFFSET: usize = 514; +pub const HASH_BASE: usize = 0x220002; + +thread_local! { + pub static HASH_CTX: RefCell = const { RefCell::new(HashCtx::new()) }; +} + +pub struct HashCtx { + hash: Vec, + hash_used: i32, + hash_extra: i32, + hash_top: i32, +} + +impl HashCtx { + const fn new() -> HashCtx { + HashCtx { + hash: Vec::new(), + hash_used: 0, + hash_extra: 0, + hash_top: 0, + } + } + + pub fn hash(&self, idx: usize) -> B32x2 { + self.hash[idx - HASH_BASE] + } +} + +#[no_mangle] +pub extern "C" fn resize_hash(len: usize) { + HASH_CTX.with_borrow_mut(|hash| hash.hash.resize(len, B32x2 { s0: 0, s1: 0 })); +} + +#[no_mangle] +pub extern "C" fn hash(idx: usize) -> B32x2 { + HASH_CTX.with_borrow(|hash| hash.hash[idx - HASH_BASE]) +} + +#[no_mangle] +pub extern "C" fn set_hash(idx: usize, val: B32x2) { + HASH_CTX.with_borrow_mut(|hash| hash.hash[idx - HASH_BASE] = val) +} + +#[no_mangle] +pub extern "C" fn hash_ptr(idx: usize) -> *mut B32x2 { + HASH_CTX.with_borrow_mut(|hash| ptr::from_mut(&mut hash.hash[idx - HASH_BASE])) +} + +#[no_mangle] +pub extern "C" fn clear_hash() { + HASH_CTX.with_borrow_mut(|hash| hash.hash.clear()); +} + +#[no_mangle] +pub extern "C" fn hash_used() -> i32 { + HASH_CTX.with_borrow(|hash| hash.hash_used) +} + +#[no_mangle] +pub extern "C" fn set_hash_used(val: i32) { + HASH_CTX.with_borrow_mut(|hash| hash.hash_used = val) +} + +#[no_mangle] +pub extern "C" fn hash_extra() -> i32 { + HASH_CTX.with_borrow(|hash| hash.hash_extra) +} + +#[no_mangle] +pub extern "C" fn set_hash_extra(val: i32) { + HASH_CTX.with_borrow_mut(|hash| hash.hash_extra = val) +} + +#[no_mangle] +pub extern "C" fn hash_top() -> i32 { + HASH_CTX.with_borrow(|hash| hash.hash_top) +} + +#[no_mangle] +pub extern "C" fn set_hash_top(val: i32) { + HASH_CTX.with_borrow_mut(|hash| hash.hash_top = val) +} diff --git a/crates/engine_xetex/src/c_api/inputs.rs b/crates/engine_xetex/src/c_api/inputs.rs new file mode 100644 index 000000000..e673b49ac --- /dev/null +++ b/crates/engine_xetex/src/c_api/inputs.rs @@ -0,0 +1,86 @@ +use crate::ty::StrNumber; +use std::cell::RefCell; + +// pub const MAX_IN_OPEN: usize = 15; + +thread_local! { + pub static FILE_CTX: RefCell = const { RefCell::new(FileCtx::new()) }; +} + +pub struct FileCtx { + pub(crate) in_open: i32, + pub(crate) full_source_filename_stack: Vec, + pub(crate) line: i32, + pub(crate) line_stack: Vec, +} + +impl FileCtx { + const fn new() -> FileCtx { + FileCtx { + in_open: 0, + full_source_filename_stack: Vec::new(), + line: 0, + line_stack: Vec::new(), + } + } +} + +#[no_mangle] +pub extern "C" fn in_open() -> i32 { + FILE_CTX.with_borrow(|files| files.in_open) +} + +#[no_mangle] +pub extern "C" fn set_in_open(val: i32) { + FILE_CTX.with_borrow_mut(|files| files.in_open = val) +} + +#[no_mangle] +pub extern "C" fn full_source_filename_stack(idx: usize) -> StrNumber { + FILE_CTX.with_borrow(|files| files.full_source_filename_stack[idx]) +} + +#[no_mangle] +pub extern "C" fn set_full_source_filename_stack(idx: usize, val: StrNumber) { + FILE_CTX.with_borrow_mut(|files| { + if files.full_source_filename_stack.len() < idx + 1 { + files.full_source_filename_stack.resize(idx + 1, 0); + } + files.full_source_filename_stack[idx] = val + }) +} + +#[no_mangle] +pub extern "C" fn clear_full_source_filename_stack() { + FILE_CTX.with_borrow_mut(|files| files.full_source_filename_stack.clear()) +} + +#[no_mangle] +pub extern "C" fn line() -> i32 { + FILE_CTX.with_borrow(|files| files.line) +} + +#[no_mangle] +pub extern "C" fn set_line(val: i32) { + FILE_CTX.with_borrow_mut(|files| files.line = val) +} + +#[no_mangle] +pub extern "C" fn line_stack(idx: usize) -> i32 { + FILE_CTX.with_borrow(|files| files.line_stack[idx]) +} + +#[no_mangle] +pub extern "C" fn set_line_stack(idx: usize, val: i32) { + FILE_CTX.with_borrow_mut(|files| { + if files.line_stack.len() < idx + 1 { + files.line_stack.resize(idx + 1, 0); + } + files.line_stack[idx] = val; + }) +} + +#[no_mangle] +pub extern "C" fn clear_line_stack() { + FILE_CTX.with_borrow_mut(|files| files.line_stack.clear()) +} diff --git a/crates/engine_xetex/src/c_api/output.rs b/crates/engine_xetex/src/c_api/output.rs new file mode 100644 index 000000000..03ca47fbd --- /dev/null +++ b/crates/engine_xetex/src/c_api/output.rs @@ -0,0 +1,1069 @@ +use crate::c_api::engine::{ + rs_gettexstring, CatCode, IntPar, NativeWordNode, Selector, ACTIVE_BASE, DIMEN_VAL_LIMIT, + EQTB_SIZE, FROZEN_NULL_FONT, NULL_CS, PRIM_EQTB_BASE, SCRIPT_SIZE, SINGLE_BASE, TEXT_SIZE, + UNDEFINED_CONTROL_SEQUENCE, +}; +use crate::c_api::globals::Globals; +use crate::c_api::hash::HASH_BASE; +use crate::ty::{Scaled, StrNumber}; +use std::cell::RefCell; +use std::ffi::CStr; +use std::io::Write; +use std::ptr; +use std::ptr::NonNull; +use tectonic_bridge_core::{Diagnostic, OutputId}; + +pub const MAX_PRINT_LINE: usize = 79; +pub const BIGGEST_CHAR: i32 = 0xFFFF; +pub const BIGGEST_USV: i32 = 0x10FFFF; + +thread_local! { + pub static OUTPUT_CTX: RefCell = const { RefCell::new(OutputCtx::new()) } +} + +pub struct OutputCtx { + current_diagnostic: Option>, + file_line_error_style_p: i32, + term_offset: i32, + file_offset: i32, + rust_stdout: Option, + pub(crate) log_file: Option, + write_file: Vec>, + doing_special: bool, + digits: [u8; 23], +} + +impl OutputCtx { + const fn new() -> OutputCtx { + OutputCtx { + current_diagnostic: None, + file_line_error_style_p: 0, + term_offset: 0, + file_offset: 0, + rust_stdout: None, + log_file: None, + write_file: Vec::new(), + doing_special: false, + digits: [0; 23], + } + } +} + +#[no_mangle] +pub extern "C" fn file_line_error_style_p() -> i32 { + OUTPUT_CTX.with_borrow(|out| out.file_line_error_style_p) +} + +#[no_mangle] +pub extern "C" fn set_file_line_error_style_p(val: i32) { + OUTPUT_CTX.with_borrow_mut(|out| out.file_line_error_style_p = val) +} + +#[no_mangle] +pub extern "C" fn current_diagnostic() -> *mut Diagnostic { + OUTPUT_CTX.with_borrow_mut(|out| { + out.current_diagnostic + .as_mut() + .map(|b| ptr::from_mut(&mut **b)) + .unwrap_or(ptr::null_mut()) + }) +} + +#[no_mangle] +pub extern "C" fn term_offset() -> i32 { + OUTPUT_CTX.with_borrow(|out| out.term_offset) +} + +#[no_mangle] +pub extern "C" fn set_term_offset(val: i32) { + OUTPUT_CTX.with_borrow_mut(|out| out.term_offset = val) +} + +#[no_mangle] +pub extern "C" fn file_offset() -> i32 { + OUTPUT_CTX.with_borrow(|out| out.file_offset) +} + +#[no_mangle] +pub extern "C" fn set_file_offset(val: i32) { + OUTPUT_CTX.with_borrow_mut(|out| out.file_offset = val) +} + +#[no_mangle] +pub extern "C" fn rust_stdout() -> Option { + OUTPUT_CTX.with_borrow(|out| out.rust_stdout) +} + +#[no_mangle] +pub extern "C" fn set_rust_stdout(val: Option) { + OUTPUT_CTX.with_borrow_mut(|out| out.rust_stdout = val) +} + +#[no_mangle] +pub extern "C" fn log_file() -> Option { + OUTPUT_CTX.with_borrow(|out| out.log_file) +} + +#[no_mangle] +pub extern "C" fn set_log_file(val: Option) { + OUTPUT_CTX.with_borrow_mut(|out| out.log_file = val) +} + +#[no_mangle] +pub extern "C" fn write_file(idx: usize) -> Option { + OUTPUT_CTX.with_borrow(|out| out.write_file[idx]) +} + +#[no_mangle] +pub extern "C" fn set_write_file(idx: usize, val: Option) { + OUTPUT_CTX.with_borrow_mut(|out| { + if out.write_file.len() < idx + 1 { + out.write_file.resize(idx + 1, None); + } + out.write_file[idx] = val; + }) +} + +#[no_mangle] +pub extern "C" fn doing_special() -> bool { + OUTPUT_CTX.with_borrow(|out| out.doing_special) +} + +#[no_mangle] +pub extern "C" fn set_doing_special(val: bool) { + OUTPUT_CTX.with_borrow_mut(|out| out.doing_special = val) +} + +#[no_mangle] +pub extern "C" fn dig(idx: usize) -> u8 { + OUTPUT_CTX.with_borrow(|out| out.digits[idx]) +} + +#[no_mangle] +pub extern "C" fn set_dig(idx: usize, val: u8) { + OUTPUT_CTX.with_borrow_mut(|out| out.digits[idx] = val) +} + +fn rs_capture_to_diagnostic(globals: &mut Globals<'_, '_>, diagnostic: Option>) { + if let Some(diag) = globals.out.current_diagnostic.take() { + globals.state.finish_diagnostic(*diag); + } + globals.out.current_diagnostic = diagnostic; +} + +/// A lower-level API to begin or end the capture of messages into the diagnostic +/// buffer. You can start capture by obtaining a diagnostic_t and passing it to +/// this function -- however, the other functions in this API generally do this +/// for you. Complete capture by passing NULL. Either way, if a capture is in +/// progress when this function is called, it will be completed and reported. +#[no_mangle] +pub unsafe extern "C" fn capture_to_diagnostic(diagnostic: Option>) { + Globals::with(|globals| { + rs_capture_to_diagnostic(globals, diagnostic.map(|ptr| Box::from_raw(ptr.as_ptr()))) + }) +} + +pub fn rs_diagnostic_print_file_line(globals: &mut Globals<'_, '_>, diag: &mut Diagnostic) { + let mut level = globals.files.in_open as usize; + while level > 0 && globals.files.full_source_filename_stack[level] == 0 { + level -= 1; + } + + if level == 0 { + diag.append("!"); + } else { + let mut source_line = globals.files.line; + if level != globals.files.in_open as usize { + source_line = globals.files.line_stack[level + 1]; + } + + let filename = rs_gettexstring(globals, globals.files.full_source_filename_stack[level]); + diag.append(format!("{}:{}", filename, source_line)); + } +} + +#[no_mangle] +pub unsafe extern "C" fn diagnostic_print_file_line(diagnostic: *mut Diagnostic) { + Globals::with(|globals| rs_diagnostic_print_file_line(globals, &mut *diagnostic)) +} + +/// Duplicate messages printed to log/terminal into a warning diagnostic buffer, +/// until a call capture_to_diagnostic(0). A standard usage of this is +/// ```c +/// ttbc_diagnostic_t *warning = diagnostic_begin_capture_warning_here(); +/// +/// // ... XeTeX prints some errors using print_* functions ... +/// +/// capture_to_diagnostic(NULL); +/// ``` +/// +/// The current file and line number information are prefixed to the captured +/// output. +/// +/// NOTE: the only reason there isn't also an _error_ version of this function is +/// that we haven't yet wired up anything that uses it. +#[no_mangle] +pub extern "C" fn diagnostic_begin_capture_warning_here() -> *mut Diagnostic { + let mut warning = Diagnostic::warning(); + Globals::with(|globals| { + rs_diagnostic_print_file_line(globals, &mut warning); + rs_capture_to_diagnostic(globals, Some(Box::new(warning))); + ptr::from_mut(globals.out.current_diagnostic.as_deref_mut().unwrap()) + }) +} + +// From C code: This replaces the "print file+line number" block at the start of errors +/// Start the error, print file line, and set the current diagnostic to a new one +pub fn rs_error_here_with_diagnostic(globals: &mut Globals<'_, '_>, message: &[u8]) { + let mut diag = Diagnostic::error(); + rs_diagnostic_print_file_line(globals, &mut diag); + diag.append(String::from_utf8_lossy(message)); + + if globals.out.file_line_error_style_p != 0 { + rs_print_file_line(globals) + } else { + rs_print_nl_bytes(globals, b"! ") + } + rs_print_bytes(globals, message); + rs_capture_to_diagnostic(globals, Some(Box::new(diag))); +} + +/// A replacement for xetex print_file_line+print_nl_ctr blocks. e.g. Replace +/// +/// ```c +/// if (file_line_error_style_p) +/// print_file_line(); +/// else +/// print_nl_cstr("! "); +/// print_cstr("Cannot use "); +/// ``` +/// with +/// ```c +/// ttbc_diagnostic_t *errmsg = error_here_with_diagnostic("Cannot use "); +/// ``` +/// +/// This function calls `capture_to_diagnostic(errmsg)` to begin diagnostic +/// capture. You must call `capture_to_diagnostic(NULL)` to mark the capture as +/// complete. +#[no_mangle] +pub extern "C" fn error_here_with_diagnostic(msg: *const libc::c_char) -> *mut Diagnostic { + let str = unsafe { CStr::from_ptr(msg) }; + Globals::with(|globals| { + rs_error_here_with_diagnostic(globals, str.to_bytes()); + ptr::from_mut(globals.out.current_diagnostic.as_deref_mut().unwrap()) + }) +} + +pub fn rs_warn_char(out: &mut OutputCtx, c: char) { + if let Some(diag) = out.current_diagnostic.as_deref_mut() { + diag.append_char(c); + } +} + +#[no_mangle] +pub extern "C" fn warn_char(c: libc::c_int) { + OUTPUT_CTX.with_borrow_mut(|out| { + rs_warn_char( + out, + char::from_u32(c as u32).unwrap_or(char::REPLACEMENT_CHARACTER), + ); + }) +} + +pub fn rs_print_ln(globals: &mut Globals<'_, '_>) { + match globals.engine.selector { + Selector::File(val) => { + // TODO: Replace all write!(get_output) with output_write on state + write!( + globals + .state + .get_output(globals.out.write_file[val as usize].unwrap()), + "\n" + ) + .unwrap(); + } + Selector::TermOnly => { + rs_warn_char(globals.out, '\n'); + write!( + globals.state.get_output(globals.out.rust_stdout.unwrap()), + "\n" + ) + .unwrap(); + globals.out.term_offset = 0; + } + Selector::LogOnly => { + rs_warn_char(globals.out, '\n'); + write!( + globals.state.get_output(globals.out.log_file.unwrap()), + "\n" + ) + .unwrap(); + globals.out.file_offset = 0; + } + Selector::TermAndLog => { + rs_warn_char(globals.out, '\n'); + write!( + globals.state.get_output(globals.out.rust_stdout.unwrap()), + "\n" + ) + .unwrap(); + write!( + globals.state.get_output(globals.out.log_file.unwrap()), + "\n" + ) + .unwrap(); + globals.out.term_offset = 0; + globals.out.file_offset = 0; + } + Selector::NoPrint | Selector::Pseudo | Selector::NewString => {} + } +} + +#[no_mangle] +pub extern "C" fn print_ln() { + Globals::with(|globals| rs_print_ln(globals)) +} + +pub fn rs_print_raw_char(globals: &mut Globals<'_, '_>, s: u16, incr_offset: bool) { + let raw = &[s as u8]; + let c = char::from_u32(s as u32).unwrap_or(char::REPLACEMENT_CHARACTER); + match globals.engine.selector { + Selector::TermAndLog => { + // TODO: This produces a malformed warning currently, since we add unicode byte-by-byte + rs_warn_char(globals.out, c); + globals + .state + .get_output(globals.out.rust_stdout.unwrap()) + .write(raw) + .unwrap(); + globals + .state + .get_output(globals.out.log_file.unwrap()) + .write(raw) + .unwrap(); + if incr_offset { + globals.out.term_offset += 1; + globals.out.file_offset += 1; + } + if globals.out.term_offset as usize == MAX_PRINT_LINE { + writeln!(globals.state.get_output(globals.out.rust_stdout.unwrap())).unwrap(); + globals.out.term_offset = 0; + } + if globals.out.file_offset as usize == MAX_PRINT_LINE { + writeln!(globals.state.get_output(globals.out.log_file.unwrap())).unwrap(); + globals.out.file_offset = 0; + } + } + Selector::LogOnly => { + rs_warn_char(globals.out, c); + globals + .state + .get_output(globals.out.log_file.unwrap()) + .write(raw) + .unwrap(); + if incr_offset { + globals.out.file_offset += 1; + } + if globals.out.file_offset as usize == MAX_PRINT_LINE { + writeln!(globals.state.get_output(globals.out.log_file.unwrap())).unwrap(); + globals.out.file_offset = 0; + } + } + Selector::TermOnly => { + rs_warn_char(globals.out, c); + globals + .state + .get_output(globals.out.rust_stdout.unwrap()) + .write(raw) + .unwrap(); + if incr_offset { + globals.out.term_offset += 1; + } + if globals.out.term_offset as usize == MAX_PRINT_LINE { + writeln!(globals.state.get_output(globals.out.rust_stdout.unwrap())).unwrap(); + globals.out.term_offset = 0; + } + } + Selector::NoPrint => (), + Selector::Pseudo => { + if globals.engine.tally < globals.engine.trick_count { + globals.engine.trick_buf + [(globals.engine.tally % globals.engine.error_line) as usize] = s; + } + } + Selector::NewString => { + if globals.strings.pool_ptr < globals.strings.pool_size { + globals.strings.str_pool[globals.strings.pool_ptr] = s; + globals.strings.pool_ptr += 1; + } + } + Selector::File(val) => { + globals + .state + .get_output(globals.out.write_file[val as usize].unwrap()) + .write(raw) + .unwrap(); + } + } + globals.engine.tally += 1; +} + +#[no_mangle] +pub extern "C" fn print_raw_char(s: u16, offset: u8) { + Globals::with(|globals| rs_print_raw_char(globals, s, offset != 0)) +} + +pub fn rs_print_char(globals: &mut Globals<'_, '_>, s: i32) { + if globals.engine.selector == Selector::NewString && !globals.out.doing_special { + if let Ok(s) = s.try_into() { + rs_print_raw_char(globals, s, true) + } else { + let s = (s - 0x10000) as u16; + rs_print_raw_char(globals, 0xD800 + s / 1024, true); + rs_print_raw_char(globals, 0xDC00 + s % 1024, true) + } + return; + } + + if globals.engine.int_par(IntPar::NewLineChar) == s + && !matches!( + globals.engine.selector, + Selector::Pseudo | Selector::NewString + ) + { + rs_print_ln(globals); + return; + } + + if s < 32 && !globals.out.doing_special { + rs_print_raw_char(globals, b'^' as u16, true); + rs_print_raw_char(globals, b'^' as u16, true); + rs_print_raw_char(globals, (s + 64) as u16, true); + } else if s < 127 { + rs_print_raw_char(globals, s as u16, true); + } else if s == 127 { + if !globals.out.doing_special { + rs_print_raw_char(globals, b'^' as u16, true); + rs_print_raw_char(globals, b'^' as u16, true); + rs_print_raw_char(globals, b'?' as u16, true); + } else { + rs_print_raw_char(globals, s as u16, true); + } + } else if s < 160 && !globals.out.doing_special { + rs_print_raw_char(globals, b'^' as u16, true); + rs_print_raw_char(globals, b'^' as u16, true); + + let l = (s % 256 / 16) as u16; + if l < 10 { + rs_print_raw_char(globals, b'0' as u16 + l, true); + } else { + rs_print_raw_char(globals, b'a' as u16 + l - 10, true); + } + + let l = (s % 16) as u16; + if l < 10 { + rs_print_raw_char(globals, b'0' as u16 + l, true); + } else { + rs_print_raw_char(globals, b'a' as u16 + l - 10, true); + } + } else if globals.engine.selector == Selector::Pseudo { + rs_print_raw_char(globals, s as u16, true); + } else { + // Encode into UTF-8 + if s < 2048 { + rs_print_raw_char(globals, (192 + s / 64) as u16, false); + rs_print_raw_char(globals, (128 + s % 64) as u16, true); + } else if s < 0x10000 { + rs_print_raw_char(globals, (224 + s / 4096) as u16, false); + rs_print_raw_char(globals, (128 + s % 4096 / 64) as u16, false); + rs_print_raw_char(globals, (128 + s % 64) as u16, true); + } else { + rs_print_raw_char(globals, (240 + s / 0x40000) as u16, false); + rs_print_raw_char(globals, (128 + s % 0x40000 / 4096) as u16, false); + rs_print_raw_char(globals, (128 + s % 4096 / 64) as u16, false); + rs_print_raw_char(globals, (128 + s % 64) as u16, true); + } + } +} + +#[no_mangle] +pub extern "C" fn print_char(s: i32) { + Globals::with(|globals| rs_print_char(globals, s)) +} + +pub fn rs_print_bytes(globals: &mut Globals<'_, '_>, bytes: &[u8]) { + for b in bytes { + rs_print_char(globals, *b as i32) + } +} + +pub fn rs_print_nl_bytes(globals: &mut Globals<'_, '_>, bytes: &[u8]) { + if (globals.out.term_offset > 0 + && matches!( + globals.engine.selector, + Selector::TermOnly | Selector::TermAndLog + )) + || (globals.out.file_offset > 0 + && matches!( + globals.engine.selector, + Selector::LogOnly | Selector::TermAndLog + )) + { + rs_print_ln(globals); + } + rs_print_bytes(globals, bytes); +} + +pub fn rs_print_esc_bytes(globals: &mut Globals<'_, '_>, bytes: &[u8]) { + let c = globals.engine.int_par(IntPar::EscapeChar); + if c >= 0 && c <= BIGGEST_USV { + rs_print_char(globals, c); + } + rs_print_bytes(globals, bytes); +} + +#[no_mangle] +pub extern "C" fn print_cstr(str: *const libc::c_char) { + let bytes = unsafe { CStr::from_ptr(str) }.to_bytes(); + Globals::with(|globals| rs_print_bytes(globals, bytes)) +} + +#[no_mangle] +pub extern "C" fn print_nl_cstr(str: *const libc::c_char) { + let bytes = unsafe { CStr::from_ptr(str) }.to_bytes(); + Globals::with(|globals| rs_print_nl_bytes(globals, bytes)) +} + +#[no_mangle] +pub extern "C" fn print_esc_cstr(str: *const libc::c_char) { + let bytes = unsafe { CStr::from_ptr(str) }.to_bytes(); + Globals::with(|globals| rs_print_esc_bytes(globals, bytes)) +} + +pub fn rs_print(globals: &mut Globals<'_, '_>, str: StrNumber) { + if str as usize >= globals.strings.str_ptr { + rs_print_bytes(globals, b"???"); + return; + } else if str <= BIGGEST_CHAR { + if str < 0 { + rs_print_bytes(globals, b"???"); + } else { + if globals.engine.selector == Selector::NewString { + rs_print_char(globals, str); + } else if globals.engine.int_par(IntPar::NewLineChar) == str + && !matches!( + globals.engine.selector, + Selector::Pseudo | Selector::NewString + ) + { + rs_print_ln(globals); + } else { + let nl = globals.engine.int_par(IntPar::NewLineChar); + globals.engine.set_int_par(IntPar::NewLineChar, -1); + rs_print_char(globals, str); + globals.engine.set_int_par(IntPar::NewLineChar, nl); + } + } + return; + } + + let pool_idx = str - 0x10000; + + let str_len = globals.strings.str(pool_idx).len(); + let mut idx = 0; + while idx < str_len { + let str = globals.strings.str(pool_idx); + let byte = str[idx]; + if (0xD800..0xDC00).contains(&byte) + && idx + 1 < str_len + && (0xDC00..0xE000).contains(&str[idx + 1]) + { + rs_print_char( + globals, + 0x10000 + (byte as i32 - 0xD800) * 1024 + (str[idx + 1] as i32 - 0xDC00), + ); + idx += 1; + } else { + rs_print_char(globals, byte as i32); + } + idx += 1; + } +} + +pub fn rs_print_nl(globals: &mut Globals<'_, '_>, str: StrNumber) { + if (globals.out.term_offset > 0 + && matches!( + globals.engine.selector, + Selector::TermOnly | Selector::TermAndLog + )) + || (globals.out.file_offset > 0 + && matches!( + globals.engine.selector, + Selector::LogOnly | Selector::TermAndLog + )) + { + rs_print_ln(globals); + } + rs_print(globals, str); +} + +pub fn rs_print_esc(globals: &mut Globals<'_, '_>, str: StrNumber) { + let c = globals.engine.int_par(IntPar::EscapeChar); + if c >= 0 && c <= BIGGEST_USV { + rs_print_char(globals, c); + } + rs_print(globals, str); +} + +#[no_mangle] +pub extern "C" fn print(str: StrNumber) { + Globals::with(|globals| rs_print(globals, str)) +} + +#[no_mangle] +pub extern "C" fn print_nl(str: StrNumber) { + Globals::with(|globals| rs_print_nl(globals, str)) +} + +#[no_mangle] +pub extern "C" fn print_esc(str: StrNumber) { + Globals::with(|globals| rs_print_esc(globals, str)) +} + +pub fn rs_print_the_digs(globals: &mut Globals<'_, '_>, k: usize) { + for k in (0..k).rev() { + if globals.out.digits[k] < 10 { + rs_print_char(globals, (b'0' + globals.out.digits[k]) as i32) + } else { + rs_print_char(globals, (55 + globals.out.digits[k]) as i32) + } + } +} + +pub fn rs_print_int(globals: &mut Globals<'_, '_>, mut n: i32) { + let mut k = 0; + + if n < 0 { + rs_print_char(globals, b'-' as i32); + if n > -100000000 { + n = -n; + } else { + let mut m = -1 - n; + n = m / 10; + m = (m % 10) + 1; + k = 1; + if m < 10 { + globals.out.digits[0] = m as u8; + } else { + globals.out.digits[0] = 0; + n += 1; + } + } + } + + loop { + globals.out.digits[k] = (n % 10) as u8; + n /= 10; + k += 1; + if n == 0 { + break; + } + } + + rs_print_the_digs(globals, k); +} + +pub fn rs_print_file_line(globals: &mut Globals<'_, '_>) { + let mut level = globals.files.in_open as usize; + while level > 0 && globals.files.full_source_filename_stack[level] == 0 { + level -= 1; + } + + if level == 0 { + rs_print_nl_bytes(globals, b"! ") + } else { + rs_print_nl_bytes(globals, b""); + rs_print(globals, globals.files.full_source_filename_stack[level]); + rs_print(globals, ':' as i32); + if level == globals.files.in_open as usize { + rs_print_int(globals, globals.files.line); + } else { + rs_print_int(globals, globals.files.line_stack[level + 1]) + } + rs_print_bytes(globals, b": "); + } +} + +#[no_mangle] +pub extern "C" fn print_the_digs(k: u8) { + Globals::with(|globals| rs_print_the_digs(globals, k as usize)) +} + +#[no_mangle] +pub extern "C" fn print_int(n: i32) { + Globals::with(|globals| rs_print_int(globals, n)) +} + +#[no_mangle] +pub extern "C" fn print_file_line() { + Globals::with(|globals| rs_print_file_line(globals)) +} + +pub fn rs_print_cs(globals: &mut Globals<'_, '_>, p: i32) { + let p = p as usize; + if p < HASH_BASE { + if p >= SINGLE_BASE { + if p == NULL_CS { + rs_print_esc_bytes(globals, b"csname"); + rs_print_esc_bytes(globals, b"endcsname"); + rs_print_char(globals, b' ' as i32); + } else { + rs_print_esc(globals, (p - SINGLE_BASE) as i32); + if globals.engine.cat_code(p - SINGLE_BASE) == Ok(CatCode::Letter) { + rs_print_char(globals, b' ' as i32); + } + } + } else if p < ACTIVE_BASE { + rs_print_esc_bytes(globals, b"IMPOSSIBLE."); + } else { + rs_print_char(globals, (p - 1) as i32); + } + } else if (p >= UNDEFINED_CONTROL_SEQUENCE && p <= EQTB_SIZE) + || (p > globals.engine.eqtb_top as usize) + { + rs_print_esc_bytes(globals, b"IMPOSSIBLE."); + } else if globals.hash.hash(p).s1 as usize >= globals.strings.str_ptr { + rs_print_esc_bytes(globals, b"NONEXISTENT."); + } else { + if p >= PRIM_EQTB_BASE && p < FROZEN_NULL_FONT { + rs_print_esc(globals, globals.engine.prim[p - PRIM_EQTB_BASE].s1 - 1); + } else { + rs_print_esc(globals, globals.hash.hash(p).s1); + } + rs_print_char(globals, b' ' as i32); + } +} + +pub fn rs_sprint_cs(globals: &mut Globals<'_, '_>, p: i32) { + let p = p as usize; + if p < HASH_BASE { + if p < SINGLE_BASE { + rs_print_char(globals, (p - 1) as i32); + } else if p < NULL_CS { + rs_print_esc(globals, (p - SINGLE_BASE) as i32); + } else { + rs_print_esc_bytes(globals, b"csname"); + rs_print_esc_bytes(globals, b"endcsname"); + } + } else if p >= PRIM_EQTB_BASE && p < FROZEN_NULL_FONT { + rs_print_esc(globals, globals.engine.prim[p - PRIM_EQTB_BASE].s1 - 1); + } else { + rs_print_esc(globals, globals.hash.hash(p).s1); + } +} + +#[no_mangle] +pub extern "C" fn print_cs(p: i32) { + Globals::with(|globals| rs_print_cs(globals, p)) +} + +#[no_mangle] +pub extern "C" fn sprint_cs(p: i32) { + Globals::with(|globals| rs_sprint_cs(globals, p)) +} + +pub fn rs_print_file_name(globals: &mut Globals<'_, '_>, n: i32, a: i32, e: i32) { + let mut quote = None; + + for s in [a, n, e] { + if s == 0 || quote.is_some() { + continue; + } + let str = globals.strings.str(s - 0x10000); + quote = str + .iter() + .find(|&&c| c == ' ' as u16 || c == '"' as u16 || c == '\'' as u16) + .copied(); + } + + if quote == Some(' ' as u16) { + quote = Some('"' as u16); + } else if let Some(q) = quote { + quote = Some(73 - q); + } + + if let Some(q) = quote { + rs_print_char(globals, q as i32); + } + + for s in [a, n, e] { + if s == 0 { + continue; + } + // TODO: Fix up borrowing so we can use `strings.str` + let str = globals.strings.str_range(s - 0x10000); + for idx in str { + let c = globals.strings.char_at(idx); + if let Some(qc) = quote { + if c == qc { + rs_print(globals, qc as i32); + rs_print(globals, (73 - qc) as i32); + quote = Some(73 - qc); + } + } + rs_print(globals, c as i32); + } + } + + if let Some(q) = quote { + rs_print_char(globals, q as i32); + } +} + +#[no_mangle] +pub extern "C" fn print_file_name(n: i32, a: i32, e: i32) { + Globals::with(|globals| rs_print_file_name(globals, n, a, e)) +} + +pub fn rs_print_size(globals: &mut Globals<'_, '_>, s: i32) { + let s = s as usize; + if s == TEXT_SIZE { + rs_print_esc_bytes(globals, b"textfont"); + } else if s == SCRIPT_SIZE { + rs_print_esc_bytes(globals, b"scriptfont"); + } else { + rs_print_esc_bytes(globals, b"scriptscriptfont"); + } +} + +#[no_mangle] +pub extern "C" fn print_size(s: i32) { + Globals::with(|globals| rs_print_size(globals, s)) +} + +pub fn rs_print_write_whatsit(globals: &mut Globals<'_, '_>, s: &[u8], p: i32) { + rs_print_esc_bytes(globals, s); + let p = p as usize; + + let val = globals.engine.mem[p + 1].i32_0(); + if val < 16 { + rs_print_int(globals, val) + } else if val == 16 { + rs_print_char(globals, '*' as i32); + } else { + rs_print_char(globals, '-' as i32); + } +} + +#[no_mangle] +pub extern "C" fn print_write_whatsit(s: *const libc::c_char, p: i32) { + let s = unsafe { CStr::from_ptr(s) }.to_bytes(); + Globals::with(|globals| rs_print_write_whatsit(globals, s, p)) +} + +pub fn rs_print_native_word(globals: &mut Globals<'_, '_>, p: i32) { + let p = p as usize; + let size = globals.engine.node::(p).len(); + let mut skip = false; + for i in 0..size { + if skip { + skip = false; + continue; + } + + let node = globals.engine.node::(p); + let c = node.text()[i]; + if c >= 0xD800 && c < 0xDC00 { + if i < size - 1 { + let cc = node.text()[i + 1]; + if cc >= 0xDC00 && cc < 0xE000 { + let c = 0x10000 + (c as i32 - 0xD800) * 1024 + (cc as i32 - 0xDC00); + rs_print_char(globals, c); + skip = true; + } else { + rs_print(globals, '.' as i32); + } + } else { + rs_print(globals, '.' as i32); + } + } else { + rs_print_char(globals, c as i32); + } + } +} + +#[no_mangle] +pub extern "C" fn print_native_word(p: i32) { + Globals::with(|globals| rs_print_native_word(globals, p)) +} + +pub fn rs_print_sa_num(globals: &mut Globals<'_, '_>, q: i32) { + let q = q as usize; + // TODO: Convert to symbolic access + let word = globals.engine.raw_mem(q); + let n = if (word.u16_1() as usize) < DIMEN_VAL_LIMIT { + globals.engine.raw_mem(q + 1).i32_1() + } else { + let next = globals.engine.base_node(q).next(); + let next2 = globals.engine.base_node(next).next(); + let next3 = globals.engine.base_node(next2).next(); + + let word2 = globals.engine.raw_mem(next); + let word3 = globals.engine.raw_mem(next2); + let word4 = globals.engine.raw_mem(next3); + + word.u16_1() as i32 % 64 + + (64 * word2.u16_1() as i32) + + (64 * 64 * (word3.u16_1() as i32 + 64 * word4.u16_1() as i32)) + }; + + rs_print_int(globals, n); +} + +#[no_mangle] +pub extern "C" fn print_sa_num(q: i32) { + Globals::with(|globals| rs_print_sa_num(globals, q)) +} + +pub fn rs_print_two(globals: &mut Globals<'_, '_>, n: i32) { + let n = (n.abs() % 100) as u8; + rs_print_char(globals, (b'0' + n / 10) as i32); + rs_print_char(globals, (b'0' + n % 10) as i32); +} + +pub fn rs_print_hex(globals: &mut Globals<'_, '_>, mut n: i32) { + let mut k = 0; + + rs_print_char(globals, '"' as i32); + loop { + globals.out.digits[k] = (n % 16) as u8; + n /= 16; + k += 1; + if n == 0 { + break; + } + } + + rs_print_the_digs(globals, k); +} + +pub fn rs_print_scaled(globals: &mut Globals<'_, '_>, mut s: Scaled) { + let mut delta; + + if s < 0 { + rs_print_char(globals, '-' as i32); + s = -s; + } + + rs_print_int(globals, s / 0x10000); + rs_print_char(globals, '.' as i32); + s = 10 * (s % 0x10000) + 5; + delta = 10; + loop { + if delta > 0x10000 { + s += 0x8000 - 50000; + } + rs_print_char(globals, '0' as i32 + (s / 0x10000)); + s = 10 * (s % 0x10000); + delta *= 10; + + if s <= delta { + break; + } + } +} + +pub fn rs_print_ucs_code(globals: &mut Globals<'_, '_>, c: char) { + rs_print_bytes(globals, b"U+"); + + let mut k = 0; + let mut n = c as u32; + while n > 0 { + globals.out.digits[k] = (n % 16) as u8; + n /= 16; + k += 1; + } + + while k < 4 { + globals.out.digits[k] = 0; + k += 1; + } + + rs_print_the_digs(globals, k); +} + +#[no_mangle] +pub extern "C" fn print_two(n: i32) { + Globals::with(|globals| rs_print_two(globals, n)) +} + +#[no_mangle] +pub extern "C" fn print_hex(n: i32) { + Globals::with(|globals| rs_print_hex(globals, n)) +} + +#[no_mangle] +pub extern "C" fn print_scaled(s: Scaled) { + Globals::with(|globals| rs_print_scaled(globals, s)) +} + +#[no_mangle] +pub extern "C" fn print_ucs_code(n: u32) { + Globals::with(|globals| { + rs_print_ucs_code( + globals, + char::from_u32(n).unwrap_or(char::REPLACEMENT_CHARACTER), + ) + }) +} + +pub fn rs_print_current_string(globals: &mut Globals<'_, '_>) { + let start = globals.strings.str_start[globals.strings.str_ptr - 0x10000] as usize; + let end = globals.strings.pool_ptr; + for j in start..end { + rs_print_char(globals, globals.strings.str_pool[j] as i32); + } +} + +#[no_mangle] +pub extern "C" fn print_current_string() { + Globals::with(rs_print_current_string) +} + +pub fn rs_print_roman_int(globals: &mut Globals<'_, '_>, mut n: i32) { + const ROMAN_DATA: &[u8] = b"m2d5c2l5x2v5i"; + + let mut j = 0; + let mut v = 1000; + + loop { + while n >= v { + rs_print_char(globals, ROMAN_DATA[j] as i32); + n -= v; + } + + if n <= 0 { + return; + } + + let mut k = j + 2; + let mut u = v / (ROMAN_DATA[k - 1] - b'0') as i32; + if ROMAN_DATA[k - 1] == b'2' { + k += 2; + u /= (ROMAN_DATA[k - 1] - b'0') as i32; + } + + if n + u >= v { + rs_print_char(globals, ROMAN_DATA[k] as i32); + n += u; + } else { + j += 2; + v /= (ROMAN_DATA[j - 1] - b'0') as i32; + } + } +} + +#[no_mangle] +pub extern "C" fn print_roman_int(n: i32) { + Globals::with(|globals| rs_print_roman_int(globals, n)) +} diff --git a/crates/engine_xetex/src/c_api/pool.rs b/crates/engine_xetex/src/c_api/pool.rs new file mode 100644 index 000000000..06c8bd3d3 --- /dev/null +++ b/crates/engine_xetex/src/c_api/pool.rs @@ -0,0 +1,252 @@ +use crate::ty::StrNumber; +use std::cell::RefCell; +use std::ops::Range; +use std::ptr; + +pub const TOO_BIG_CHAR: usize = 65536; +pub const EMPTY_STRING: StrNumber = 65536 + 1; + +thread_local! { + pub static STRING_POOL: RefCell = const { RefCell::new(StringPool::new()) }; +} + +pub struct StringPool { + pub(crate) str_pool: Vec, + pub(crate) str_start: Vec, + pub(crate) pool_ptr: usize, + pub(crate) str_ptr: usize, + pub(crate) pool_size: usize, + pub(crate) max_strings: usize, +} + +impl StringPool { + const fn new() -> StringPool { + StringPool { + str_pool: Vec::new(), + str_start: Vec::new(), + pool_ptr: 0, + str_ptr: 0, + pool_size: 0, + max_strings: 565536, + } + } + + pub fn str(&self, str: StrNumber) -> &[u16] { + let str = str as usize; + &self.str_pool[self.str_start[str] as usize..self.str_start[str + 1] as usize] + } + + pub fn tex_str(&self, str: StrNumber) -> &[u16] { + if str < 0x10000 { + &[] + } else { + self.str(str - 0x10000) + } + } + + pub fn char_at(&self, idx: usize) -> u16 { + self.str_pool[idx] + } + + pub fn str_range(&self, str: StrNumber) -> Range { + let str = str as usize; + self.str_start[str] as usize..self.str_start[str + 1] as usize + } + + /// The length of the current string in the pool + pub fn cur_length(&self) -> usize { + self.pool_ptr - self.str_start[self.str_ptr - TOO_BIG_CHAR] as usize + } +} + +#[no_mangle] +pub extern "C" fn resize_str_pool(size: usize) { + STRING_POOL.with_borrow_mut(|strings| strings.str_pool.resize(size, 0)) +} + +#[no_mangle] +pub extern "C" fn clear_str_pool() { + STRING_POOL.with_borrow_mut(|strings| strings.str_pool.clear()); +} + +#[no_mangle] +pub extern "C" fn str_pool(idx: usize) -> u16 { + STRING_POOL.with_borrow(|strings| strings.str_pool[idx]) +} + +#[no_mangle] +pub extern "C" fn str_pool_ptr(idx: usize) -> *mut u16 { + STRING_POOL.with_borrow_mut(|strings| ptr::from_mut(&mut strings.str_pool[idx..]).cast()) +} + +#[no_mangle] +pub extern "C" fn set_str_pool(idx: usize, val: u16) { + STRING_POOL.with_borrow_mut(|strings| strings.str_pool[idx] = val) +} + +#[no_mangle] +pub extern "C" fn str_start(idx: usize) -> u32 { + STRING_POOL.with_borrow(|strings| strings.str_start[idx]) +} + +#[no_mangle] +pub extern "C" fn str_start_ptr(idx: usize) -> *mut u32 { + STRING_POOL.with_borrow_mut(|strings| ptr::from_mut(&mut strings.str_start[idx..]).cast()) +} + +#[no_mangle] +pub extern "C" fn resize_str_start(size: usize) { + STRING_POOL.with_borrow_mut(|strings| strings.str_start.resize(size, 0)) +} + +#[no_mangle] +pub extern "C" fn clear_str_start() { + STRING_POOL.with_borrow_mut(|strings| strings.str_start.clear()); +} + +#[no_mangle] +pub extern "C" fn set_str_start(idx: usize, val: u32) { + STRING_POOL.with_borrow_mut(|strings| strings.str_start[idx] = val) +} + +#[no_mangle] +pub extern "C" fn pool_ptr() -> usize { + STRING_POOL.with_borrow(|strings| strings.pool_ptr) +} + +#[no_mangle] +pub extern "C" fn set_pool_ptr(val: usize) { + STRING_POOL.with_borrow_mut(|strings| strings.pool_ptr = val) +} + +#[no_mangle] +pub extern "C" fn str_ptr() -> usize { + STRING_POOL.with_borrow(|strings| strings.str_ptr) +} + +#[no_mangle] +pub extern "C" fn set_str_ptr(val: usize) { + STRING_POOL.with_borrow_mut(|strings| strings.str_ptr = val) +} + +#[no_mangle] +pub extern "C" fn pool_size() -> usize { + STRING_POOL.with_borrow(|strings| strings.pool_size) +} + +#[no_mangle] +pub extern "C" fn set_pool_size(val: usize) { + STRING_POOL.with_borrow_mut(|strings| strings.pool_size = val) +} + +#[no_mangle] +pub extern "C" fn max_strings() -> usize { + STRING_POOL.with_borrow(|strings| strings.max_strings) +} + +#[no_mangle] +pub extern "C" fn set_max_strings(val: usize) { + STRING_POOL.with_borrow_mut(|strings| strings.max_strings = val) +} + +pub fn rs_make_string(pool: &mut StringPool) -> StrNumber { + if pool.str_ptr == pool.max_strings { + todo!("overflow(\"number of strings\", max_strings() - init_str_ptr);"); + } + + pool.str_ptr += 1; + pool.str_start[pool.str_ptr - TOO_BIG_CHAR] = pool.pool_ptr as u32; + (pool.str_ptr - 1) as StrNumber +} + +pub fn rs_slow_make_string(pool: &mut StringPool) -> StrNumber { + let t = rs_make_string(pool); + let s = rs_search_string(pool, t); + + if s > 0 { + pool.str_ptr -= 1; + pool.pool_ptr = pool.str_start[pool.str_ptr - TOO_BIG_CHAR] as usize; + s + } else { + t + } +} + +#[no_mangle] +pub extern "C" fn make_string() -> StrNumber { + STRING_POOL.with_borrow_mut(rs_make_string) +} + +#[no_mangle] +pub extern "C" fn slow_make_string() -> StrNumber { + STRING_POOL.with_borrow_mut(|pool| rs_slow_make_string(pool)) +} + +pub fn rs_str_length(pool: &StringPool, s: StrNumber) -> usize { + if s >= 0x10000 { + pool.str(s - 0x10000).len() + } else if (32..127).contains(&s) { + 1 + } else if s <= 127 { + 3 + } else if s < 256 { + 4 + } else { + 8 + } +} + +pub fn rs_str_eq_str(pool: &StringPool, s1: StrNumber, s2: StrNumber) -> bool { + let s1_len = rs_str_length(pool, s1); + let s2_len = rs_str_length(pool, s2); + if s1_len != s2_len { + return false; + } + + if s1_len == 1 { + let c1 = if s1 < 0x10000 { + s1 as u16 + } else { + pool.str_pool[pool.str_start[(s1 - 0x10000) as usize] as usize] + }; + let c2 = if s2 < 0x10000 { + s2 as u16 + } else { + pool.str_pool[pool.str_start[(s2 - 0x10000) as usize] as usize] + }; + c1 == c2 + } else { + pool.str(s1 - 0x10000) == pool.str(s2 - 0x10000) + } +} + +pub fn rs_search_string(pool: &StringPool, search: StrNumber) -> StrNumber { + let len = rs_str_length(pool, search); + if len == 0 { + EMPTY_STRING + } else { + let mut s = search - 1; + while s > 0x10000 { + if rs_str_eq_str(pool, s, search) { + return s; + } + s -= 1; + } + 0 + } +} + +#[no_mangle] +pub extern "C" fn length(s: StrNumber) -> usize { + STRING_POOL.with_borrow(|pool| rs_str_length(pool, s)) +} + +#[no_mangle] +pub extern "C" fn str_eq_str(s1: StrNumber, s2: StrNumber) -> bool { + STRING_POOL.with_borrow(|pool| rs_str_eq_str(pool, s1, s2)) +} + +#[no_mangle] +pub extern "C" fn search_string(search: StrNumber) -> StrNumber { + STRING_POOL.with_borrow(|pool| rs_search_string(pool, search)) +} diff --git a/crates/engine_xetex/src/c_api/scaled_math.rs b/crates/engine_xetex/src/c_api/scaled_math.rs new file mode 100644 index 000000000..a0dca1e71 --- /dev/null +++ b/crates/engine_xetex/src/c_api/scaled_math.rs @@ -0,0 +1,487 @@ +use crate::ty::Scaled; +use std::cell::RefCell; +use std::mem; + +thread_local! { + static MATH_CTX: RefCell = const { RefCell::new(MathContext::new()) }; +} + +struct MathContext { + arith_error: bool, + tex_remainder: Scaled, + randoms: [i32; 55], + j_random: u8, +} + +impl MathContext { + const fn new() -> MathContext { + MathContext { + arith_error: false, + tex_remainder: 0, + randoms: [0; 55], + j_random: 0, + } + } + + fn next_rand(&mut self) -> i32 { + if self.j_random == 0 { + rs_new_randoms(self); + } else { + self.j_random -= 1; + } + self.randoms[self.j_random as usize] + } +} + +#[no_mangle] +pub extern "C" fn arith_error() -> bool { + MATH_CTX.with_borrow(|ctx| ctx.arith_error) +} + +#[no_mangle] +pub extern "C" fn set_arith_error(val: bool) { + MATH_CTX.with_borrow_mut(|ctx| ctx.arith_error = val) +} + +#[no_mangle] +pub extern "C" fn tex_remainder() -> Scaled { + MATH_CTX.with_borrow(|ctx| ctx.tex_remainder) +} + +#[no_mangle] +pub extern "C" fn set_tex_remainder(val: Scaled) { + MATH_CTX.with_borrow_mut(|ctx| ctx.tex_remainder = val) +} + +#[no_mangle] +pub extern "C" fn randoms(idx: usize) -> i32 { + MATH_CTX.with_borrow(|ctx| ctx.randoms[idx]) +} + +#[no_mangle] +pub extern "C" fn j_random() -> u8 { + MATH_CTX.with_borrow(|ctx| ctx.j_random) +} + +#[no_mangle] +pub extern "C" fn set_j_random(val: u8) { + MATH_CTX.with_borrow_mut(|ctx| ctx.j_random = val) +} + +#[no_mangle] +pub extern "C" fn tex_round(r: f64) -> i32 { + /* We must reproduce very particular rounding semantics to pass the TRIP + * test. Specifically, values within the 32-bit range of TeX int32_ts are + * rounded to the nearest int32_t with half-integral values going away + * from zero: 0.5 => 1, -0.5 => -1. + * + * `r` does not necessarily lie within the range of a 32-bit TeX int32_t; + * if it doesn't, we clip. The following LaTeX document allegedly triggers + * that codepath: + * + * \documentstyle{article} + * \begin{document} + * \begin{flushleft} + * $\hbox{} $\hfill + * \filbreak + * \eject + * + */ + + if r > 2147483647.0 + /* 0x7FFFFFFF */ + { + return 2147483647; + } + + if r < -2147483648.0 + /* -0x80000000 */ + { + return -2147483648; + } + + /* ANSI defines the float-to-int32_t cast to truncate towards zero, so the + * following code is all that's necessary to get the desired behavior. The + * truncation technically causes an uncaught "inexact" floating-point + * exception, but exception is virtually impossible to avoid in real + * code. */ + + if r >= 0.0 { + (r + 0.5) as i32 + } else { + (r - 0.5) as i32 + } +} + +#[no_mangle] +pub extern "C" fn half(x: i32) -> i32 { + if x % 2 != 0 { + (x + 1) / 2 + } else { + x / 2 + } +} + +#[no_mangle] +pub extern "C" fn mult_and_add(n: i32, x: Scaled, y: Scaled, max_answer: Scaled) -> Scaled { + if n < 0 { + mult_and_add(-n, -x, y, max_answer) + } else if n == 0 { + y + } else if x <= (max_answer - y) / n && (-(x) <= (max_answer + y) / n) { + n * x + y + } else { + set_arith_error(true); + 0 + } +} + +#[no_mangle] +pub extern "C" fn x_over_n(x: Scaled, n: i32) -> Scaled { + if n == 0 { + set_arith_error(true); + set_tex_remainder(x); + 0 + } else if n < 0 { + set_tex_remainder(-tex_remainder()); + x_over_n(-x, -n) + } else { + set_tex_remainder(x % n); + x / n + } +} + +#[no_mangle] +pub extern "C" fn xn_over_d(mut x: Scaled, n: i32, d: i32) -> Scaled { + let pos = x >= 0; + if !pos { + x = -x; + } + let t = (x % 32768) * n; + let mut u = (x / 32768) * n + (t / 32768); + let v = (u % d) * 32768 + (t % 32768); + + if u / d >= 32768 { + set_arith_error(true); + } else { + u = 32768 * (u / d) + (v / d); + } + + if pos { + set_tex_remainder(v % d); + u + } else { + set_tex_remainder(-(v % d)); + -u + } +} + +#[no_mangle] +pub extern "C" fn round_xn_over_d(mut x: Scaled, n: i32, d: i32) -> Scaled { + let pos = x >= 0; + if !pos { + x = -x; + } + let t = (x % 32768) * n; + let mut u = (x / 32768) * n + (t / 32768); + let mut v = (u % d) * 32768 + (t % 32768); + + if u / d >= 32768 { + set_arith_error(true); + } else { + u = 32768 * (u / d) + (v / d); + } + v %= d; + if 2 * v >= d { + u += 1; + } + if pos { + u + } else { + -u + } +} + +#[no_mangle] +pub extern "C" fn make_frac(mut p: i32, mut q: i32) -> i32 { + let mut neg = p < 0; + if neg { + p = -p; + } + + if q <= 0 { + q = -q; + neg = !neg; + } + + let mut n = p / q; + p %= q; + + if n >= 8 { + set_arith_error(true); + if neg { + -0x7FFFFFFF + } else { + 0x7FFFFFFF + } + } else { + n = (n - 1) * 0x10000000; + let mut f = 1; + + let mut be_careful; + loop { + be_careful = p - q; + p += be_careful; + if p >= 0 { + f = f + f + 1; + } else { + f = f + f; + p += q; + } + + if f >= 0x10000000 { + break; + } + } + + be_careful = p - q; + if be_careful + p >= 0 { + f += 1; + } + + if neg { + -(f + n) + } else { + f + n + } + } +} + +#[no_mangle] +pub extern "C" fn take_frac(mut q: i32, mut f: i32) -> i32 { + let mut neg = f < 0; + + if neg { + f = -f; + } + + if q < 0 { + q = -q; + neg = !neg; + } + + let mut n; + if f < 0x10000000 { + n = 0; + } else { + n = f / 0x10000000; + f %= 0x10000000; + + if q <= 0x7FFFFFFF / n { + n *= q; + } else { + set_arith_error(true); + n = 0x7FFFFFFF; + } + } + + f += 0x10000000; + let mut p = 0x08000000; + + if q < 0x40000000 { + loop { + if f % 2 != 0 { + p = (p + q) / 2; + } else { + p /= 2; + } + f /= 2; + if f == 1 { + break; + } + } + } else { + loop { + if f % 2 != 0 { + p = p + (q - p) / 2; + } else { + p /= 2; + } + f /= 2; + if f == 1 { + break; + } + } + } + + let be_careful = n - 0x7FFFFFFF; + + if be_careful + p > 0 { + set_arith_error(true); + n = 0x7FFFFFFF - p; + } + + if neg { + -(n + p) + } else { + n + p + } +} + +#[no_mangle] +pub extern "C" fn ab_vs_cd(mut a: i32, mut b: i32, mut c: i32, mut d: i32) -> i32 { + if a < 0 { + return ab_vs_cd(-a, -b, c, d); + } else if c < 0 { + return ab_vs_cd(a, b, -c, -d); + } + + if d <= 0 { + if b >= 0 { + return if a == 0 || b == 0 && c == 0 || d == 0 { + 0 + } else { + 1 + }; + } else if d == 0 { + return if a == 0 { 0 } else { -1 }; + } else { + mem::swap(&mut a, &mut c); + mem::swap(&mut b, &mut d); + b = -b; + d = -d; + } + } else if b <= 0 { + if b < 0 && a > 0 { + return -1; + } + + return if c == 0 { 0 } else { -1 }; + } + + loop { + let mut q = a / d; + let mut r = c / b; + + if q != r { + return if q > r { 1 } else { -1 }; + } + + q = a % d; + r = c % b; + + if r == 0 { + return if q == 0 { 0 } else { 1 }; + } + + if q == 0 { + return -1; + } + + a = b; + b = q; + c = d; + d = r; + } +} + +fn rs_new_randoms(math: &mut MathContext) { + for k in 0..24 { + let mut x = math.randoms[k] - math.randoms[k + 31]; + if x < 0 { + x += 0x10000000; + } + math.randoms[k] = x; + } + + for k in 24..55 { + let mut x = math.randoms[k] - math.randoms[k - 24]; + if x < 0 { + x += 0x10000000; + } + math.randoms[k] = x; + } + + math.j_random = 54; +} + +#[no_mangle] +pub extern "C" fn new_randoms() { + MATH_CTX.with_borrow_mut(|math| { + rs_new_randoms(math); + }) +} + +#[no_mangle] +pub extern "C" fn init_randoms(seed: i32) { + MATH_CTX.with_borrow_mut(|math| { + let mut j = seed.abs(); + while j >= 0x10000000 { + j /= 2; + } + + let mut k = 1; + + for i in 0..55 { + let jj = k; + k = j - k; + j = jj; + if k < 0 { + k += 0x10000000; + } + math.randoms[(i * 21) % 55] = j; + } + + rs_new_randoms(math); + rs_new_randoms(math); + rs_new_randoms(math); + }) +} + +#[no_mangle] +pub extern "C" fn unif_rand(x: i32) -> i32 { + MATH_CTX.with_borrow_mut(|math| { + let y = take_frac(x.abs(), math.next_rand()); + if y == x.abs() { + 0 + } else if x > 0 { + y + } else { + -y + } + }) +} + +#[no_mangle] +pub extern "C" fn norm_rand() -> i32 { + MATH_CTX.with_borrow_mut(|math| { + let mut x; + + loop { + let mut u; + + loop { + x = take_frac(112429, math.next_rand() - 0x08000000); + + u = math.next_rand(); + + if x.abs() < u { + break; + } + } + + x = make_frac(x, u); + let l = 139548960 - m_log(u); + + if ab_vs_cd(1024, l, x, x) >= 0 { + break; + } + } + + x + }) +} + +unsafe extern "C" { + safe fn m_log(val: i32) -> i32; +} diff --git a/crates/engine_xetex/src/lib.rs b/crates/engine_xetex/src/lib.rs index b1ca2ebb9..48a761003 100644 --- a/crates/engine_xetex/src/lib.rs +++ b/crates/engine_xetex/src/lib.rs @@ -1,6 +1,8 @@ // Copyright 2021-2022 the Tectonic Project // Licensed under the MIT License. +#![allow(clippy::undocumented_unsafe_blocks)] + //! The [XeTeX] program as a reusable crate. //! //! [XeTeX]: http://www.xetex.org/ @@ -22,6 +24,8 @@ use std::{ffi::CString, time::SystemTime}; use tectonic_bridge_core::{CoreBridgeLauncher, EngineAbortedError}; use tectonic_errors::prelude::*; +mod ty; + /// A serial number describing the detailed binary layout of the TeX "format /// files" used by this crate. This number will occasionally increment, /// indicating that the format file structure has changed. There is no provision @@ -232,6 +236,21 @@ pub mod c_api { use tectonic_bridge_core::CoreBridgeState; + mod dvi; + mod engine; + mod errors; + mod globals; + mod hash; + mod inputs; + mod output; + mod pool; + mod scaled_math; + + /// Copy of `IS_DIR_SEP` from bridge_core + fn is_dir_sep(c: char) -> bool { + c == '/' + } + #[allow(improper_ctypes)] // for CoreBridgeState extern "C" { pub fn tt_xetex_set_int_variable( diff --git a/crates/engine_xetex/src/ty.rs b/crates/engine_xetex/src/ty.rs new file mode 100644 index 000000000..1d35433fa --- /dev/null +++ b/crates/engine_xetex/src/ty.rs @@ -0,0 +1,2 @@ +pub type Scaled = i32; +pub type StrNumber = i32; diff --git a/crates/engine_xetex/xetex/xetex-constants.h b/crates/engine_xetex/xetex/xetex-constants.h index 4f53d8f12..6577b6748 100644 --- a/crates/engine_xetex/xetex/xetex-constants.h +++ b/crates/engine_xetex/xetex/xetex-constants.h @@ -67,24 +67,24 @@ #define FONT_ID_BASE FROZEN_NULL_FONT /* nominally minus FONT_BASE, but that's 0 */ -#define GLUEPAR(p) (eqtb[GLUE_BASE + GLUE_PAR__##p].b32.s1) -#define SKIP_REG(n) (eqtb[SKIP_BASE + (n)].b32.s1) -#define MU_SKIP_REG(n) (eqtb[MU_SKIP_BASE + (n)].b32.s1) -#define LOCAL(p) (eqtb[LOCAL_BASE + LOCAL__##p].b32.s1) -#define TOKS_REG(n) (eqtb[TOKS_BASE + (n)].b32.s1) -#define ETEX_PENALTIES_PAR(p) (eqtb[ETEX_PEN_BASE + ETEX_PENALTIES_PAR__##p].b32.s1) -#define BOX_REG(n) (eqtb[BOX_BASE + (n)].b32.s1) -#define MATH_FONT(n) (eqtb[MATH_FONT_BASE + (n)].b32.s1) -#define CAT_CODE(n) (eqtb[CAT_CODE_BASE + (n)].b32.s1) -#define LC_CODE(n) (eqtb[LC_CODE_BASE + (n)].b32.s1) -#define UC_CODE(n) (eqtb[UC_CODE_BASE + (n)].b32.s1) -#define SF_CODE(n) (eqtb[SF_CODE_BASE + (n)].b32.s1) -#define MATH_CODE(n) (eqtb[MATH_CODE_BASE + (n)].b32.s1) -#define INTPAR(n) (eqtb[INT_BASE + INT_PAR__##n].b32.s1) -#define COUNT_REG(n) (eqtb[COUNT_BASE + (n)].b32.s1) -#define DEL_CODE(n) (eqtb[DEL_CODE_BASE + (n)].b32.s1) -#define DIMENPAR(n) (eqtb[DIMEN_BASE + DIMEN_PAR__##n].b32.s1) -#define SCALED_REG(n) (eqtb[SCALED_BASE + (n)].b32.s1) +#define GLUEPAR(p) (eqtb_ptr(GLUE_BASE + GLUE_PAR__##p)->b32.s1) +#define SKIP_REG(n) (eqtb_ptr(SKIP_BASE + (n))->b32.s1) +#define MU_SKIP_REG(n) (eqtb_ptr(MU_SKIP_BASE + (n))->b32.s1) +#define LOCAL(p) (eqtb_ptr(LOCAL_BASE + LOCAL__##p)->b32.s1) +#define TOKS_REG(n) (eqtb_ptr(TOKS_BASE + (n))->b32.s1) +#define ETEX_PENALTIES_PAR(p) (eqtb_ptr(ETEX_PEN_BASE + ETEX_PENALTIES_PAR__##p)->b32.s1) +#define BOX_REG(n) (eqtb_ptr(BOX_BASE + (n))->b32.s1) +#define MATH_FONT(n) (eqtb_ptr(MATH_FONT_BASE + (n))->b32.s1) +#define CAT_CODE(n) (eqtb_ptr(CAT_CODE_BASE + (n))->b32.s1) +#define LC_CODE(n) (eqtb_ptr(LC_CODE_BASE + (n))->b32.s1) +#define UC_CODE(n) (eqtb_ptr(UC_CODE_BASE + (n))->b32.s1) +#define SF_CODE(n) (eqtb_ptr(SF_CODE_BASE + (n))->b32.s1) +#define MATH_CODE(n) (eqtb_ptr(MATH_CODE_BASE + (n))->b32.s1) +#define INTPAR(n) (eqtb_ptr(INT_BASE + INT_PAR__##n)->b32.s1) +#define COUNT_REG(n) (eqtb_ptr(COUNT_BASE + (n))->b32.s1) +#define DEL_CODE(n) (eqtb_ptr(DEL_CODE_BASE + (n))->b32.s1) +#define DIMENPAR(n) (eqtb_ptr(DIMEN_BASE + DIMEN_PAR__##n)->b32.s1) +#define SCALED_REG(n) (eqtb_ptr(SCALED_BASE + (n))->b32.s1) #define LEVEL_ZERO 0 /* "really" MIN_QUARTERWORD */ #define LEVEL_ONE 1 diff --git a/crates/engine_xetex/xetex/xetex-errors.c b/crates/engine_xetex/xetex/xetex-errors.c index fb6c9d324..6e5b828f7 100644 --- a/crates/engine_xetex/xetex/xetex-errors.c +++ b/crates/engine_xetex/xetex/xetex-errors.c @@ -5,60 +5,41 @@ #include "xetex-core.h" #include "xetex-xetexd.h" +#include "xetex_bindings.h" #include /* WEBby error-handling code: */ -static void -pre_error_message (void) -{ - /* FKA normalize_selector(): */ - - if (log_opened) - selector = SELECTOR_TERM_AND_LOG; - else - selector = SELECTOR_TERM_ONLY; - - if (job_name == 0) - open_log_file(); - - if (interaction == BATCH_MODE) - selector--; - - error_here_with_diagnostic(""); -} - - /*82: */ static void post_error_message(int need_to_print_it) { capture_to_diagnostic(NULL); - if (interaction == ERROR_STOP_MODE) - interaction = SCROLL_MODE; + if (interaction() == ERROR_STOP_MODE) + set_interaction(SCROLL_MODE); - if (need_to_print_it && log_opened) + if (need_to_print_it && log_opened()) error(); - history = HISTORY_FATAL_ERROR; + set_history(HISTORY_FATAL_ERROR); close_files_and_terminate(); tt_cleanup(); - ttstub_output_flush(rust_stdout); + ttstub_output_flush(rust_stdout()); } void error(void) { - if (history < HISTORY_ERROR_ISSUED) - history = HISTORY_ERROR_ISSUED; + if (history() < HISTORY_ERROR_ISSUED) + set_history(HISTORY_ERROR_ISSUED); print_char('.'); show_context(); if (halt_on_error_p) { - history = HISTORY_FATAL_ERROR; + set_history(HISTORY_FATAL_ERROR); post_error_message(0); _tt_abort("halted on potentially-recoverable error as specified"); } @@ -70,13 +51,13 @@ error(void) error_count++; if (error_count == 100) { print_nl_cstr("(That makes 100 errors; please try again.)"); - history = HISTORY_FATAL_ERROR; + set_history(HISTORY_FATAL_ERROR); post_error_message(0); _tt_abort("halted after 100 potentially-recoverable errors"); } - if (interaction > BATCH_MODE) - selector--; + if (interaction() > BATCH_MODE) + set_selector(selector()-1); if (use_err_help) { print_ln(); @@ -89,8 +70,8 @@ error(void) } print_ln(); - if (interaction > BATCH_MODE) - selector++; + if (interaction() > BATCH_MODE) + set_selector(selector()+1); print_ln(); } @@ -105,7 +86,7 @@ fatal_error(const char* s) close_files_and_terminate(); tt_cleanup(); - ttstub_output_flush(rust_stdout); + ttstub_output_flush(rust_stdout()); _tt_abort("%s", s); } @@ -134,7 +115,7 @@ confusion(const char* s) { pre_error_message(); - if (history < HISTORY_ERROR_ISSUED) { + if (history() < HISTORY_ERROR_ISSUED) { print_cstr("This can't happen ("); print_cstr(s); print_char(')'); diff --git a/crates/engine_xetex/xetex/xetex-ext.c b/crates/engine_xetex/xetex/xetex-ext.c index 3a64bc05e..b1d09d12f 100644 --- a/crates/engine_xetex/xetex/xetex-ext.c +++ b/crates/engine_xetex/xetex/xetex-ext.c @@ -133,38 +133,38 @@ get_encoding_mode_and_info(int32_t* info) UErrorCode err = U_ZERO_ERROR; UConverter* cnv; *info = 0; - if (strcasecmp(name_of_file, "auto") == 0) { + if (strcasecmp(name_of_file(), "auto") == 0) { return AUTO; } - if (strcasecmp(name_of_file, "utf8") == 0) { + if (strcasecmp(name_of_file(), "utf8") == 0) { return UTF8; } - if (strcasecmp(name_of_file, "utf16") == 0) { /* depends on host platform */ + if (strcasecmp(name_of_file(), "utf16") == 0) { /* depends on host platform */ return US_NATIVE_UTF16; } - if (strcasecmp(name_of_file, "utf16be") == 0) { + if (strcasecmp(name_of_file(), "utf16be") == 0) { return UTF16BE; } - if (strcasecmp(name_of_file, "utf16le") == 0) { + if (strcasecmp(name_of_file(), "utf16le") == 0) { return UTF16LE; } - if (strcasecmp(name_of_file, "bytes") == 0) { + if (strcasecmp(name_of_file(), "bytes") == 0) { return RAW; } /* try for an ICU converter */ - cnv = ucnv_open(name_of_file, &err); + cnv = ucnv_open(name_of_file(), &err); if (cnv == NULL) { begin_diagnostic(); print_nl('U'); /* ensure message starts on a new line */ print_c_string("nknown encoding `"); - print_c_string(name_of_file); + print_c_string(name_of_file()); print_c_string("'; reading as raw bytes"); end_diagnostic(1); return RAW; } else { ucnv_close(cnv); - *info = maketexstring(name_of_file); + *info = maketexstring(name_of_file()); return ICUMAPPING; } } @@ -235,7 +235,7 @@ static char *saved_mapping_name = NULL; void check_for_tfm_font_mapping(void) { - char* cp = strstr(name_of_file, ":mapping="); + char* cp = strstr(name_of_file(), ":mapping="); saved_mapping_name = mfree(saved_mapping_name); if (cp != NULL) { *cp = 0; @@ -816,14 +816,12 @@ find_native_font(char* uname, int32_t scaled_size) if (fontRef) { /* update name_of_file to the full name of the font, for error messages during font loading */ const char* fullName = getFullName(fontRef); - name_length = strlen(fullName); - if (featString != NULL) - name_length += strlen(featString) + 1; - if (varString != NULL) - name_length += strlen(varString) + 1; - free(name_of_file); - name_of_file = xmalloc(name_length + 1); - strcpy(name_of_file, fullName); +// name_length = strlen(fullName); +// if (featString != NULL) +// name_length += strlen(featString) + 1; +// if (varString != NULL) +// name_length += strlen(varString) + 1; + set_name_of_file(fullName); if (scaled_size < 0) { font = createFont(fontRef, scaled_size); @@ -866,14 +864,14 @@ find_native_font(char* uname, int32_t scaled_size) /* append the style and feature strings, so that \show\fontID will give a full result */ if (varString != NULL && *varString != 0) { - strcat(name_of_file, "/"); - strcat(name_of_file, varString); + strcat(name_of_file(), "/"); + strcat(name_of_file(), varString); } if (featString != NULL && *featString != 0) { - strcat(name_of_file, ":"); - strcat(name_of_file, featString); + strcat(name_of_file(), ":"); + strcat(name_of_file(), featString); } - name_length = strlen(name_of_file); +// name_length = strlen(name_of_file()); } } @@ -1058,7 +1056,7 @@ gr_font_get_named(int32_t what, void* pEngine) XeTeXLayoutEngine engine = (XeTeXLayoutEngine)pEngine; switch (what) { case XeTeX_find_feature_by_name: - rval = findGraphiteFeatureNamed(engine, name_of_file, name_length); + rval = findGraphiteFeatureNamed(engine, name_of_file(), name_length()); break; } return rval; @@ -1071,7 +1069,7 @@ gr_font_get_named_1(int32_t what, void* pEngine, int32_t param) XeTeXLayoutEngine engine = (XeTeXLayoutEngine)pEngine; switch (what) { case XeTeX_find_selector_by_name: - rval = findGraphiteFeatureSettingNamed(engine, param, name_of_file, name_length); + rval = findGraphiteFeatureSettingNamed(engine, param, name_of_file(), name_length()); break; } return rval; @@ -1856,11 +1854,11 @@ map_glyph_to_index(int32_t font) { #ifdef XETEX_MAC if (font_area[font] == AAT_FONT_FLAG) - return MapGlyphToIndex_AAT((CFDictionaryRef)(font_layout_engine[font]), name_of_file); + return MapGlyphToIndex_AAT((CFDictionaryRef)(font_layout_engine[font]), name_of_file()); else #endif if (font_area[font] == OTGR_FONT_FLAG) - return mapGlyphToIndex((XeTeXLayoutEngine)(font_layout_engine[font]), name_of_file); + return mapGlyphToIndex((XeTeXLayoutEngine)(font_layout_engine[font]), name_of_file()); else _tt_abort("bad native font flag in `map_glyph_to_index`"); } @@ -2045,7 +2043,7 @@ aat_font_get_named(int what, CFDictionaryRef attributes) CFArrayRef features = CTFontCopyFeatures(font); if (features) { CFDictionaryRef feature = findDictionaryInArray(features, kCTFontFeatureTypeNameKey, - name_of_file, name_length); + name_of_file(), name_length()); if (feature) { CFNumberRef identifier = CFDictionaryGetValue(feature, kCTFontFeatureTypeIdentifierKey); CFNumberGetValue(identifier, kCFNumberIntType, &rval); @@ -2071,7 +2069,7 @@ aat_font_get_named_1(int what, CFDictionaryRef attributes, int param) if (features) { CFDictionaryRef feature = findDictionaryInArrayWithIdentifier(features, kCTFontFeatureTypeIdentifierKey, param); if (feature) { - CFNumberRef selector = findSelectorByName(feature, name_of_file, name_length); + CFNumberRef selector = findSelectorByName(feature, name_of_file(), name_length()); if (selector) CFNumberGetValue(selector, kCFNumberIntType, &rval); } diff --git a/crates/engine_xetex/xetex/xetex-ini.c b/crates/engine_xetex/xetex/xetex-ini.c index 2763182fa..217eb0d7f 100644 --- a/crates/engine_xetex/xetex/xetex-ini.c +++ b/crates/engine_xetex/xetex/xetex-ini.c @@ -18,24 +18,15 @@ /* All the following variables are declared in xetex-xetexd.h */ bool shell_escape_enabled = false; -memory_word *eqtb; int32_t bad; -char *name_of_file; -UTF16_code *name_of_file16; -int32_t name_length; -int32_t name_length16; -UnicodeScalar *buffer; int32_t first; int32_t last; int32_t max_buf_stack; bool in_initex_mode; -int32_t error_line; int32_t half_error_line; int32_t max_print_line; -int32_t max_strings; int32_t strings_free; int32_t string_vacancies; -int32_t pool_size; int32_t pool_free; int32_t font_mem_size; int32_t font_max; @@ -48,51 +39,28 @@ int32_t param_size; int32_t nest_size; int32_t save_size; int32_t expand_depth; -int file_line_error_style_p; int halt_on_error_p; -bool quoted_filename; bool insert_src_special_auto; bool insert_src_special_every_par; bool insert_src_special_every_math; bool insert_src_special_every_vbox; -packed_UTF16_code *str_pool; -pool_pointer *str_start; -pool_pointer pool_ptr; -str_number str_ptr; pool_pointer init_pool_ptr; str_number init_str_ptr; -rust_output_handle_t rust_stdout; -rust_output_handle_t log_file; -selector_t selector; -unsigned char dig[23]; -int32_t tally; -int32_t term_offset; -int32_t file_offset; -UTF16_code trick_buf[256]; -int32_t trick_count; int32_t first_count; -bool doing_special; UTF16_code *native_text; int32_t native_text_size; int32_t native_len; int32_t save_native_len; -unsigned char interaction; bool deletions_allowed; bool set_box_allowed; -tt_history_t history; signed char error_count; const char* help_line[6]; unsigned char help_ptr; bool use_err_help; -bool arith_error; -scaled_t tex_remainder; -int32_t randoms[55]; -unsigned char j_random; scaled_t random_seed; int32_t two_to_the[31]; int32_t spec_log[29]; int32_t temp_ptr; -memory_word *mem; int32_t lo_mem_max; int32_t hi_mem_min; int32_t var_used, dyn_used; @@ -114,15 +82,9 @@ int32_t max_nest_stack; list_state_record cur_list; short shown_mode; unsigned char old_setting; -b32x2 *hash; -int32_t hash_used; -int32_t hash_extra; -int32_t hash_top; -int32_t eqtb_top; int32_t hash_high; bool no_new_control_sequence; int32_t cs_count; -b32x2 prim[PRIM_SIZE + 1]; int32_t prim_used; memory_word *save_stack; int32_t save_ptr; @@ -135,17 +97,10 @@ eight_bits cur_cmd; int32_t cur_chr; int32_t cur_cs; int32_t cur_tok; -input_state_t *input_stack; -int32_t input_ptr; int32_t max_in_stack; -input_state_t cur_input; -int32_t in_open; int32_t open_parens; UFILE **input_file; -int32_t line; -int32_t *line_stack; str_number *source_filename_stack; -str_number *full_source_filename_stack; unsigned char scanner_status; int32_t warning_index; int32_t def_ref; @@ -174,19 +129,9 @@ unsigned char if_limit; small_number cur_if; int32_t if_line; int32_t skip_line; -str_number cur_name; -str_number cur_area; -str_number cur_ext; -pool_pointer area_delimiter; -pool_pointer ext_delimiter; -UTF16_code file_name_quote_char; int32_t format_default_length; char *TEX_format_default; -bool name_in_progress; -str_number job_name; -bool log_opened; const char* output_file_extension; -str_number texmf_log_name; memory_word *font_info; font_index fmem_ptr; internal_font_number font_ptr; @@ -314,7 +259,6 @@ int32_t cur_box; int32_t after_token; bool long_help_seen; str_number format_ident; -rust_output_handle_t write_file[16]; bool write_open[18]; int32_t write_loc; scaled_t cur_page_width; @@ -341,7 +285,6 @@ trie_pointer hyph_start; trie_pointer hyph_index; int32_t disc_ptr[4]; pool_pointer edit_name_start; -bool stop_at_space; int32_t native_font_type_flag; bool xtx_ligature_present; scaled_t delta; @@ -457,7 +400,7 @@ do_dump (char *p, size_t item_size, size_t nitems, rust_output_handle_t out_file ssize_t r = ttstub_output_write (out_file, p, item_size * nitems); if (r < 0 || (size_t) r != item_size * nitems) _tt_abort ("could not write %"PRIuZ" %"PRIuZ"-byte item(s) to %s", - nitems, item_size, name_of_file); + nitems, item_size, name_of_file()); /* Have to restore the old contents of memory, since some of it might get used again. */ @@ -473,17 +416,34 @@ do_undump (char *p, size_t item_size, size_t nitems, rust_input_handle_t in_file ssize_t r = ttstub_input_read (in_file, p, item_size * nitems); if (r < 0 || (size_t) r != item_size * nitems) _tt_abort("could not undump %"PRIuZ" %"PRIuZ"-byte item(s) from %s", - nitems, item_size, name_of_file); + nitems, item_size, name_of_file()); swap_items (p, nitems, item_size); } - +#define dump_ptr(base, len) \ + do_dump ((char *) (base), sizeof *(base), (size_t) (len), fmt_out) #define dump_things(base, len) \ do_dump ((char *) &(base), sizeof (base), (size_t) (len), fmt_out) +#define undump_ptr(base, len) \ + do_undump ((char *) (base), sizeof *(base), (size_t) (len), fmt_in) #define undump_things(base, len) \ do_undump ((char *) &(base), sizeof (base), (size_t) (len), fmt_in) +#define undump_checked_ptr(low, high, base, len) \ + do { \ + int i; \ + undump_ptr (base, len); \ + for (i = 0; i < (len); i++) { \ + if ((base)[i] < (low) || (base)[i] > (high)) { \ + _tt_abort ("item %u (=%" PRIdPTR ") of .fmt array at %" PRIxPTR \ + " <%" PRIdPTR " or >%" PRIdPTR, \ + i, (uintptr_t) (base)[i], (uintptr_t) (base),\ + (uintptr_t) low, (uintptr_t) high); \ + } \ + } \ + } while (0) + /* Like do_undump, but check each value against LOW and HIGH. The slowdown isn't significant, and this improves the chances of detecting incompatible format files. In fact, Knuth himself noted @@ -557,8 +517,8 @@ sort_avail(void) int32_t old_rover; p = get_node(0x40000000); - p = mem[rover + 1].b32.s1; - mem[rover + 1].b32.s1 = MAX_HALFWORD; + p = mem(rover + 1).b32.s1; + mem_ptr(rover + 1)->b32.s1 = MAX_HALFWORD; old_rover = rover; /*136: */ @@ -566,29 +526,29 @@ sort_avail(void) while (p != old_rover) { if (p < rover) { q = p; - p = mem[q + 1].b32.s1; - mem[q + 1].b32.s1 = rover; + p = mem(q + 1).b32.s1; + mem_ptr(q + 1)->b32.s1 = rover; rover = q; } else { q = rover; - while (mem[q + 1].b32.s1 < p) - q = mem[q + 1].b32.s1; - r = mem[p + 1].b32.s1; - mem[p + 1].b32.s1 = mem[q + 1].b32.s1; - mem[q + 1].b32.s1 = p; + while (mem(q + 1).b32.s1 < p) + q = mem(q + 1).b32.s1; + r = mem(p + 1).b32.s1; + mem_ptr(p + 1)->b32.s1 = mem(q + 1).b32.s1; + mem_ptr(q + 1)->b32.s1 = p; p = r; } } p = rover; - while (mem[p + 1].b32.s1 != MAX_HALFWORD) { - mem[mem[p + 1].b32.s1 + 1].b32.s0 = p; - p = mem[p + 1].b32.s1; + while (mem(p + 1).b32.s1 != MAX_HALFWORD) { + mem_ptr(mem(p + 1).b32.s1 + 1)->b32.s0 = p; + p = mem(p + 1).b32.s1; } - mem[p + 1].b32.s1 = rover; - mem[rover + 1].b32.s0 = p; + mem_ptr(p + 1)->b32.s1 = rover; + mem_ptr(rover + 1)->b32.s0 = p; } /*:271*//*276: */ @@ -605,24 +565,24 @@ primitive(const char* ident, uint16_t c, int32_t o) overflow("buffer size", buf_size); for (int i = 0; i < len; i++) - buffer[first + i] = ident[i]; + set_buffer(first + i, ident[i]); cur_val = id_lookup(first, len); - str_ptr--; - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; - hash[cur_val].s1 = s; + set_str_ptr(str_ptr()-1); + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); + hash_ptr(cur_val)->s1 = s; prim_val = prim_lookup(s); } else { cur_val = ident[0] + SINGLE_BASE; prim_val = prim_lookup(ident[0]); } - eqtb[cur_val].b16.s0 = LEVEL_ONE; - eqtb[cur_val].b16.s1 = c; - eqtb[cur_val].b32.s1 = o; - eqtb[PRIM_EQTB_BASE + prim_val].b16.s0 = LEVEL_ONE; - eqtb[PRIM_EQTB_BASE + prim_val].b16.s1 = c; - eqtb[PRIM_EQTB_BASE + prim_val].b32.s1 = o; + eqtb_ptr(cur_val)->b16.s0 = LEVEL_ONE; + eqtb_ptr(cur_val)->b16.s1 = c; + eqtb_ptr(cur_val)->b32.s1 = o; + eqtb_ptr(PRIM_EQTB_BASE + prim_val)->b16.s0 = LEVEL_ONE; + eqtb_ptr(PRIM_EQTB_BASE + prim_val)->b16.s1 = c; + eqtb_ptr(PRIM_EQTB_BASE + prim_val)->b32.s1 = o; } /*:925*//*977: */ @@ -1002,7 +962,7 @@ new_patterns(void) help_line[0] = "All patterns must be given before typesetting begins."; error(); - mem[GARBAGE].b32.s1 = scan_toks(false, false); + mem_ptr(GARBAGE)->b32.s1 = scan_toks(false, false); flush_list(def_ref); } } @@ -1187,8 +1147,8 @@ new_hyph_exceptions(void) if (cur_chr == '-' ) { /*973:*/ if (n < max_hyphenatable_length()) { q = get_avail(); - mem[q].b32.s1 = p; - mem[q].b32.s0 = n; + mem_ptr(q)->b32.s1 = p; + mem_ptr(q)->b32.s0 = n; p = q; } } else { @@ -1232,14 +1192,14 @@ new_hyph_exceptions(void) if (n > 1) { /*974:*/ n++; hc[n] = cur_lang; - if (pool_ptr + n > pool_size) - overflow("pool size", pool_size - init_pool_ptr); + if (pool_ptr() + n > pool_size()) + overflow("pool size", pool_size() - init_pool_ptr); h = 0; for (j = 1; j <= n; j++) { h = (h + h + hc[j]) % HYPH_PRIME; - str_pool[pool_ptr] = hc[j]; - pool_ptr++; + set_str_pool(pool_ptr(), hc[j]); + set_pool_ptr(pool_ptr()+1); } s = make_string(); @@ -1259,18 +1219,18 @@ new_hyph_exceptions(void) if (length(k) != length(s)) goto not_found; - u = str_start[(k) - 65536L]; - v = str_start[(s) - 65536L]; + u = str_start((k) - 65536L); + v = str_start((s) - 65536L); do { - if (str_pool[u] != str_pool[v]) + if (str_pool(u) != str_pool(v)) goto not_found; u++; v++; - } while (u != str_start[(k + 1) - 65536L]); + } while (u != str_start((k + 1) - 65536L)); - str_ptr--; - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + set_str_ptr(str_ptr()-1); + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); s = hyph_word[h]; hyph_count--; goto found; @@ -1402,9 +1362,9 @@ prefixed_command(void) if (j != 0) { q = get_avail(); - mem[q].b32.s0 = j; - mem[q].b32.s1 = mem[def_ref].b32.s1; - mem[def_ref].b32.s1 = q; + mem_ptr(q)->b32.s0 = j; + mem_ptr(q)->b32.s1 = mem(def_ref).b32.s1; + mem_ptr(def_ref)->b32.s1 = q; } if (a >= 4) @@ -1438,10 +1398,10 @@ prefixed_command(void) } if (cur_cmd >= CALL) { - mem[cur_chr].b32.s0++; + mem_ptr(cur_chr)->b32.s0++; } else if (cur_cmd == REGISTER || cur_cmd == TOKS_REGISTER) { if (cur_chr < 0 || cur_chr > 19) /* 19 = lo_mem_stat_max, I think */ - mem[cur_chr + 1].b32.s0++; + mem_ptr(cur_chr + 1)->b32.s0++; } if (a >= 4) @@ -1518,7 +1478,7 @@ prefixed_command(void) j = TOK_VAL; find_sa_element(j, cur_val, true); - mem[cur_ptr + 1].b32.s0++; + mem_ptr(cur_ptr + 1)->b32.s0++; if (j == TOK_VAL) j = TOKS_REGISTER; @@ -1637,10 +1597,10 @@ prefixed_command(void) if (cur_ptr == TEX_NULL) q = TEX_NULL; else - q = mem[cur_ptr + 1].b32.s1; + q = mem(cur_ptr + 1).b32.s1; } } else { - q = mem[cur_chr + 1].b32.s1; + q = mem(cur_chr + 1).b32.s1; } } else if (cur_chr == LOCAL_BASE + LOCAL__xetex_inter_char_toks) { scan_char_class_not_ignored(); @@ -1650,9 +1610,9 @@ prefixed_command(void) if (cur_ptr == TEX_NULL) q = TEX_NULL; else - q = mem[cur_ptr + 1].b32.s1; + q = mem(cur_ptr + 1).b32.s1; } else { - q = eqtb[cur_chr].b32.s1; + q = eqtb_ptr(cur_chr)->b32.s1; } if (q == TEX_NULL) { @@ -1667,7 +1627,7 @@ prefixed_command(void) eq_define(p, UNDEFINED_CS, TEX_NULL); } } else { - mem[q].b32.s0++; + mem_ptr(q)->b32.s0++; if (e) { if (a >= 4) gsa_def(p, q); @@ -1688,7 +1648,7 @@ prefixed_command(void) cur_cs = q; q = scan_toks(false, false); - if (mem[def_ref].b32.s1 == TEX_NULL) { + if (mem(def_ref).b32.s1 == TEX_NULL) { if (e) { if (a >= 4) gsa_def(p, TEX_NULL); @@ -1700,17 +1660,17 @@ prefixed_command(void) eq_define(p, UNDEFINED_CS, TEX_NULL); } - mem[def_ref].b32.s1 = avail; + mem_ptr(def_ref)->b32.s1 = avail; avail = def_ref; } else { if (p == LOCAL_BASE + LOCAL__output_routine && !e) { - mem[q].b32.s1 = get_avail(); + mem_ptr(q)->b32.s1 = get_avail(); q = LLIST_link(q); - mem[q].b32.s0 = (RIGHT_BRACE_TOKEN + 125); + mem_ptr(q)->b32.s0 = (RIGHT_BRACE_TOKEN + 125); q = get_avail(); - mem[q].b32.s0 = (LEFT_BRACE_TOKEN + 123); - mem[q].b32.s1 = mem[def_ref].b32.s1; - mem[def_ref].b32.s1 = q; + mem_ptr(q)->b32.s0 = (LEFT_BRACE_TOKEN + 123); + mem_ptr(q)->b32.s1 = mem(def_ref).b32.s1; + mem_ptr(def_ref)->b32.s1 = q; } if (e) { @@ -1862,7 +1822,7 @@ prefixed_command(void) if (p < MATH_CODE_BASE) { if (p >= SF_CODE_BASE) { - n = eqtb[p].b32.s1 / 65536L; + n = eqtb_ptr(p)->b32.s1 / 65536L; if (a >= 4) geq_define(p, DATA, n * 65536L + cur_val); else @@ -1961,26 +1921,26 @@ prefixed_command(void) } else if (q > LOCAL_BASE + LOCAL__par_shape) { n = (cur_val / 2) + 1; p = get_node(2 * n + 1); - mem[p].b32.s0 = n; + mem_ptr(p)->b32.s0 = n; n = cur_val; - mem[p + 1].b32.s1 = n; + mem_ptr(p + 1)->b32.s1 = n; for (j = p + 2; j <= p + n + 1; j++) { scan_int(); - mem[j].b32.s1 = cur_val; + mem_ptr(j)->b32.s1 = cur_val; } if (!odd(n)) - mem[p + n + 2].b32.s1 = 0; + mem_ptr(p + n + 2)->b32.s1 = 0; } else { p = get_node(2 * n + 1); - mem[p].b32.s0 = n; + mem_ptr(p)->b32.s0 = n; for (j = 1; j <= n; j++) { scan_dimen(false, false, false); - mem[p + 2 * j - 1].b32.s1 = cur_val; + mem_ptr(p + 2 * j - 1)->b32.s1 = cur_val; scan_dimen(false, false, false); - mem[p + 2 * j].b32.s1 = cur_val; + mem_ptr(p + 2 * j)->b32.s1 = cur_val; } } @@ -2091,20 +2051,20 @@ store_fmt_file(void) help_ptr = 1; help_line[0] = "`{...\\dump}' is a no-no."; - if (interaction == ERROR_STOP_MODE) - interaction = SCROLL_MODE; - if (log_opened) + if (interaction() == ERROR_STOP_MODE) + set_interaction(SCROLL_MODE); + if (log_opened()) error(); - history = HISTORY_FATAL_ERROR; + set_history(HISTORY_FATAL_ERROR); close_files_and_terminate(); - ttstub_output_flush (rust_stdout); + ttstub_output_flush(rust_stdout()); _tt_abort("\\dump inside a group"); } - selector = SELECTOR_NEW_STRING; + set_selector(SELECTOR_NEW_STRING); print_cstr(" (preloaded format="); - print(job_name); + print(job_name()); print_char(' '); print_int(INTPAR(year)); print_char('.'); @@ -2113,26 +2073,26 @@ store_fmt_file(void) print_int(INTPAR(day)); print_char(')'); - if (interaction == BATCH_MODE) - selector = SELECTOR_LOG_ONLY; + if (interaction() == BATCH_MODE) + set_selector(SELECTOR_LOG_ONLY); else - selector = SELECTOR_TERM_AND_LOG; + set_selector(SELECTOR_TERM_AND_LOG); - if (pool_ptr + 1 > pool_size) - overflow("pool size", pool_size - init_pool_ptr); + if (pool_ptr() + 1 > pool_size()) + overflow("pool size", pool_size() - init_pool_ptr); format_ident = make_string(); pack_job_name(".fmt"); - fmt_out = ttstub_output_open (name_of_file, 0); + fmt_out = ttstub_output_open (name_of_file(), 0); if (fmt_out == INVALID_HANDLE) - _tt_abort ("cannot open format output file \"%s\"", name_of_file); + _tt_abort ("cannot open format output file \"%s\"", name_of_file()); print_nl_cstr("Beginning to dump on file "); print(make_name_string()); - str_ptr--; - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + set_str_ptr(str_ptr()-1); + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); print_nl_cstr(""); print(format_ident); @@ -2153,15 +2113,15 @@ store_fmt_file(void) /* string pool */ - dump_int(pool_ptr); - dump_int(str_ptr); - dump_things(str_start[0], str_ptr - TOO_BIG_CHAR + 1); - dump_things(str_pool[0], pool_ptr); + dump_int(pool_ptr()); + dump_int(str_ptr()); + dump_ptr(str_start_ptr(0), str_ptr() - TOO_BIG_CHAR + 1); + dump_ptr(str_pool_ptr(0), pool_ptr()); print_ln(); - print_int(str_ptr); + print_int(str_ptr()); print_cstr(" strings of total length "); - print_int(pool_ptr); + print_int(pool_ptr()); /* "memory locations" */ @@ -2177,21 +2137,21 @@ store_fmt_file(void) q = rover; x = 0; do { - dump_things(mem[p], q + 2 - p); + dump_ptr(mem_ptr(p), q + 2 - p); x = x + q + 2 - p; var_used = var_used + q - p; - p = q + mem[q].b32.s0; - q = mem[q + 1].b32.s1; + p = q + mem(q).b32.s0; + q = mem(q + 1).b32.s1; } while (q != rover); var_used = var_used + lo_mem_max - p; dyn_used = mem_end + 1 - hi_mem_min; - dump_things(mem[p], lo_mem_max + 1 - p); + dump_ptr(mem_ptr(p), lo_mem_max + 1 - p); x = x + lo_mem_max + 1 - p; dump_int(hi_mem_min); dump_int(avail); - dump_things(mem[hi_mem_min], mem_end + 1 - hi_mem_min); + dump_ptr(mem_ptr(hi_mem_min), mem_end + 1 - hi_mem_min); x = x + mem_end + 1 - hi_mem_min; p = avail; @@ -2218,9 +2178,9 @@ store_fmt_file(void) j = k; while (j < INT_BASE - 1) { - if (eqtb[j].b32.s1 == eqtb[j + 1].b32.s1 && - eqtb[j].b16.s1 == eqtb[j + 1].b16.s1 && - eqtb[j].b16.s0 == eqtb[j + 1].b16.s0) + if (eqtb_ptr(j)->b32.s1 == eqtb_ptr(j + 1)->b32.s1 && + eqtb_ptr(j)->b16.s1 == eqtb_ptr(j + 1)->b16.s1 && + eqtb_ptr(j)->b16.s0 == eqtb_ptr(j + 1)->b16.s0) goto found1; j++; } @@ -2233,16 +2193,16 @@ store_fmt_file(void) l = j; while (j < INT_BASE - 1) { - if (eqtb[j].b32.s1 != eqtb[j + 1].b32.s1 || - eqtb[j].b16.s1 != eqtb[j + 1].b16.s1 || - eqtb[j].b16.s0 != eqtb[j + 1].b16.s0) + if (eqtb_ptr(j)->b32.s1 != eqtb_ptr(j + 1)->b32.s1 || + eqtb_ptr(j)->b16.s1 != eqtb_ptr(j + 1)->b16.s1 || + eqtb_ptr(j)->b16.s0 != eqtb_ptr(j + 1)->b16.s0) goto done1; j++; } done1: dump_int(l - k); - dump_things(eqtb[k], l - k); + dump_ptr(eqtb_ptr(k), l - k); k = j + 1; dump_int(k - l); } while (k != INT_BASE); /*:1350*/ @@ -2251,7 +2211,7 @@ store_fmt_file(void) j = k; while (j < EQTB_SIZE) { - if (eqtb[j].b32.s1 == eqtb[j + 1].b32.s1) + if (eqtb_ptr(j)->b32.s1 == eqtb_ptr(j + 1)->b32.s1) goto found2; j++; } @@ -2264,43 +2224,43 @@ store_fmt_file(void) l = j; while (j < EQTB_SIZE) { - if (eqtb[j].b32.s1 != eqtb[j + 1].b32.s1) + if (eqtb_ptr(j)->b32.s1 != eqtb_ptr(j + 1)->b32.s1) goto done2; j++; } done2: dump_int(l - k); - dump_things(eqtb[k], l - k); + dump_ptr(eqtb_ptr(k), l - k); k = j + 1; dump_int(k - l); } while (k <= EQTB_SIZE); if (hash_high > 0) - dump_things(eqtb[EQTB_SIZE + 1], hash_high); + dump_ptr(eqtb_ptr(EQTB_SIZE + 1), hash_high); dump_int(par_loc); dump_int(write_loc); for (p = 0; p <= PRIM_SIZE; p++) - dump_b32(prim[p]); + dump_ptr(prim_ptr(p), 1); /* control sequences */ - dump_int(hash_used); - cs_count = (FROZEN_CONTROL_SEQUENCE - 1) - hash_used + hash_high; + dump_int(hash_used()); + cs_count = (FROZEN_CONTROL_SEQUENCE - 1) - hash_used() + hash_high; - for (p = HASH_BASE; p <= hash_used; p++) { - if (hash[p].s1 != 0) { + for (p = HASH_BASE; p <= hash_used(); p++) { + if (hash(p).s1 != 0) { dump_int(p); - dump_b32(hash[p]); + dump_ptr(hash_ptr(p), 1); cs_count++; } } - dump_things(hash[hash_used + 1], (UNDEFINED_CONTROL_SEQUENCE - 1) - hash_used); + dump_ptr(hash_ptr(hash_used() + 1), (UNDEFINED_CONTROL_SEQUENCE - 1) - hash_used()); if (hash_high > 0) - dump_things(hash[EQTB_SIZE + 1], hash_high); + dump_ptr(hash_ptr(EQTB_SIZE + 1), hash_high); dump_int(cs_count); @@ -2339,7 +2299,7 @@ store_fmt_file(void) for (k = FONT_BASE; k <= font_ptr; k++) { print_nl_cstr("\\font"); - print_esc(hash[FONT_ID_BASE + k].s1); + print_esc(hash(FONT_ID_BASE + k).s1); print_char('='); if (font_area[k] == AAT_FONT_FLAG || font_area[k] == OTGR_FONT_FLAG || font_mapping[k] != NULL) { @@ -2443,11 +2403,8 @@ store_fmt_file(void) static void pack_buffered_name(small_number n, int32_t a, int32_t b) { - free(name_of_file); - name_of_file = xmalloc_array(UTF8_code, format_default_length + 1); - - strcpy(name_of_file, TEX_format_default); - name_length = strlen(name_of_file); + set_name_of_file(TEX_format_default); +// name_length = strlen(name_of_file()); } @@ -2459,27 +2416,26 @@ load_fmt_file(void) int32_t x; rust_input_handle_t fmt_in; - j = cur_input.loc; + j = cur_input().loc; /* This is where a first line starting with "&" used to * trigger code that would change the format file. */ pack_buffered_name(format_default_length - 4, 1, 0); - fmt_in = ttstub_input_open(name_of_file, TTBC_FILE_FORMAT_FORMAT, 0); + fmt_in = ttstub_input_open(name_of_file(), TTBC_FILE_FORMAT_FORMAT, 0); if (fmt_in == INVALID_HANDLE) - _tt_abort("cannot open the format file \"%s\"", name_of_file); + _tt_abort("cannot open the format file \"%s\"", name_of_file()); - cur_input.loc = j; + cur_input_ptr()->loc = j; if (in_initex_mode) { free(font_info); - free(str_pool); - free(str_start); + clear_str_pool(); + clear_str_start(); free(yhash); - free(eqtb); - free(mem); - mem = NULL; + clear_eqtb(); + clear_mem(); } /* start reading the header */ @@ -2491,37 +2447,36 @@ load_fmt_file(void) undump_int(x); if (x != FORMAT_SERIAL) _tt_abort("format file \"%s\" is of the wrong version: expected %d, found %d", - name_of_file, FORMAT_SERIAL, x); + name_of_file(), FORMAT_SERIAL, x); /* hash table parameters */ undump_int(hash_high); if (hash_high < 0 || hash_high > sup_hash_extra) goto bad_fmt; - if (hash_extra < hash_high) - hash_extra = hash_high; + if (hash_extra() < hash_high) + set_hash_extra(hash_high); - eqtb_top = EQTB_SIZE + hash_extra; - if (hash_extra == 0) - hash_top = UNDEFINED_CONTROL_SEQUENCE; + set_eqtb_top(EQTB_SIZE + hash_extra()); + if (hash_extra() == 0) + set_hash_top(UNDEFINED_CONTROL_SEQUENCE); else - hash_top = eqtb_top; + set_hash_top(eqtb_top()); - yhash = xmalloc_array(b32x2, 1 + hash_top - hash_offset); - hash = yhash - hash_offset; - hash[HASH_BASE].s0 = 0; - hash[HASH_BASE].s1 = 0; + resize_hash(1 + hash_top() - hash_offset); + hash_ptr(HASH_BASE)->s0 = 0; + hash_ptr(HASH_BASE)->s1 = 0; - for (x = HASH_BASE + 1; x <= hash_top; x++) - hash[x] = hash[HASH_BASE]; + for (x = HASH_BASE + 1; x <= hash_top(); x++) + set_hash(x, hash(HASH_BASE)); - eqtb = xmalloc_array(memory_word, eqtb_top + 1); - eqtb[UNDEFINED_CONTROL_SEQUENCE].b16.s1 = UNDEFINED_CS; - eqtb[UNDEFINED_CONTROL_SEQUENCE].b32.s1 = TEX_NULL; - eqtb[UNDEFINED_CONTROL_SEQUENCE].b16.s0 = LEVEL_ZERO; + resize_eqtb(eqtb_top() + 1); + eqtb_ptr(UNDEFINED_CONTROL_SEQUENCE)->b16.s1 = UNDEFINED_CS; + eqtb_ptr(UNDEFINED_CONTROL_SEQUENCE)->b32.s1 = TEX_NULL; + eqtb_ptr(UNDEFINED_CONTROL_SEQUENCE)->b16.s0 = LEVEL_ZERO; - for (x = EQTB_SIZE + 1; x <= eqtb_top; x++) - eqtb[x] = eqtb[UNDEFINED_CONTROL_SEQUENCE]; + for (x = EQTB_SIZE + 1; x <= eqtb_top(); x++) + set_eqtb(x, eqtb(UNDEFINED_CONTROL_SEQUENCE)); max_reg_num = 32767; max_reg_help_line = "A register number must be between 0 and 32767."; @@ -2535,7 +2490,7 @@ load_fmt_file(void) cur_list.head = CONTRIB_HEAD; cur_list.tail = CONTRIB_HEAD; page_tail = PAGE_HEAD; - mem = xmalloc_array(memory_word, MEM_TOP + 1); + resize_mem(MEM_TOP + 1); undump_int(x); if (x != EQTB_SIZE) @@ -2556,29 +2511,30 @@ load_fmt_file(void) goto bad_fmt; if (x > sup_pool_size - pool_free) _tt_abort ("must increase string_pool_size"); - pool_ptr = x; + set_pool_ptr(x); - if (pool_size < pool_ptr + pool_free) - pool_size = pool_ptr + pool_free; + if (pool_size() < pool_ptr() + pool_free) + set_pool_size(pool_ptr() + pool_free); undump_int(x); if (x < 0) goto bad_fmt; if (x > sup_max_strings - strings_free) _tt_abort ("must increase sup_strings"); - str_ptr = x; + set_str_ptr(x); - if (max_strings < str_ptr + strings_free) - max_strings = str_ptr + strings_free; + if (max_strings() < str_ptr() + strings_free) + set_max_strings(str_ptr() + strings_free); - str_start = xmalloc_array(pool_pointer, max_strings); - undump_checked_things(0, pool_ptr, str_start[0], str_ptr - TOO_BIG_CHAR + 1); - str_pool = xmalloc_array(packed_UTF16_code, pool_size); + resize_str_start(max_strings()); + uint32_t* ptr = str_start_ptr(0); + undump_checked_ptr(0, pool_ptr(), ptr, str_ptr() - TOO_BIG_CHAR + 1); + resize_str_pool(pool_size()); - undump_things(str_pool[0], pool_ptr); + undump_ptr(str_pool_ptr(0), pool_ptr()); - init_str_ptr = str_ptr; - init_pool_ptr = pool_ptr; /*:1345 */ + init_str_ptr = str_ptr(); + init_pool_ptr = pool_ptr(); /*:1345 */ /* "By sorting the list of available spaces in the variable-size portion * of |mem|, we are usually able to get by without having to dump very @@ -2608,14 +2564,14 @@ load_fmt_file(void) q = rover; do { - undump_things(mem[p], q + 2 - p); - p = q + mem[q].b32.s0; - if (p > lo_mem_max || (q >= mem[q + 1].b32.s1 && mem[q + 1].b32.s1 != rover)) + undump_ptr(mem_ptr(p), q + 2 - p); + p = q + mem(q).b32.s0; + if (p > lo_mem_max || (q >= mem(q + 1).b32.s1 && mem(q + 1).b32.s1 != rover)) goto bad_fmt; - q = mem[q + 1].b32.s1; + q = mem(q + 1).b32.s1; } while (q != rover); - undump_things(mem[p], lo_mem_max + 1 - p); + undump_ptr(mem_ptr(p), lo_mem_max + 1 - p); undump_int(x); if (x < lo_mem_max + 1 || x > PRE_ADJUST_HEAD) @@ -2631,7 +2587,7 @@ load_fmt_file(void) mem_end = MEM_TOP; - undump_things(mem[hi_mem_min], mem_end + 1 - hi_mem_min); + undump_ptr(mem_ptr(hi_mem_min), mem_end + 1 - hi_mem_min); undump_int(var_used); undump_int(dyn_used); @@ -2651,7 +2607,7 @@ load_fmt_file(void) if (x < 1 || k + x > EQTB_SIZE + 1) goto bad_fmt; - undump_things(eqtb[k], x); + undump_ptr(eqtb_ptr(k), x); k = k + x; undump_int(x); @@ -2659,16 +2615,16 @@ load_fmt_file(void) goto bad_fmt; for (j = k; j <= k + x - 1; j++) - eqtb[j] = eqtb[k - 1]; + set_eqtb(j, eqtb(k - 1)); k = k + x; } while (k <= EQTB_SIZE); if (hash_high > 0) - undump_things(eqtb[EQTB_SIZE + 1], hash_high); + undump_ptr(eqtb_ptr(EQTB_SIZE + 1), hash_high); undump_int(x); - if (x < HASH_BASE || x > hash_top) + if (x < HASH_BASE || x > hash_top()) goto bad_fmt; else par_loc = x; @@ -2676,7 +2632,7 @@ load_fmt_file(void) par_token = CS_TOKEN_FLAG + par_loc; undump_int(x); - if (x < HASH_BASE || x > hash_top) + if (x < HASH_BASE || x > hash_top()) goto bad_fmt; else write_loc = x; @@ -2691,29 +2647,29 @@ load_fmt_file(void) */ for (p = 0; p <= PRIM_SIZE; p++) - undump_b32(prim[p]); + undump_ptr(prim_ptr(p), 1); undump_int(x); if (x < HASH_BASE || x > FROZEN_CONTROL_SEQUENCE) goto bad_fmt; else - hash_used = x; + set_hash_used(x); p = HASH_BASE - 1; do { undump_int(x); - if (x < p + 1 || x > hash_used) + if (x < p + 1 || x > hash_used()) goto bad_fmt; else p = x; - undump_b32(hash[p]); - } while (p != hash_used); + undump_ptr(hash_ptr(p), 1); + } while (p != hash_used()); - undump_things(hash[hash_used + 1], (UNDEFINED_CONTROL_SEQUENCE - 1) - hash_used); + undump_ptr(hash_ptr(hash_used() + 1), (UNDEFINED_CONTROL_SEQUENCE - 1) - hash_used()); if (hash_high > 0) - undump_things(hash[EQTB_SIZE + 1], hash_high); + undump_ptr(hash_ptr(EQTB_SIZE + 1), hash_high); undump_int(cs_count); @@ -2777,8 +2733,8 @@ load_fmt_file(void) undump_checked_things(MIN_HALFWORD, MAX_HALFWORD, font_params[FONT_BASE], font_ptr + 1); undump_things(hyphen_char[FONT_BASE], font_ptr + 1); undump_things(skew_char[FONT_BASE], font_ptr + 1); - undump_upper_check_things(str_ptr, font_name[FONT_BASE], font_ptr + 1); - undump_upper_check_things(str_ptr, font_area[FONT_BASE], font_ptr + 1); + undump_upper_check_things(str_ptr(), font_name[FONT_BASE], font_ptr + 1); + undump_upper_check_things(str_ptr(), font_area[FONT_BASE], font_ptr + 1); undump_things(font_bc[FONT_BASE], font_ptr + 1); undump_things(font_ec[FONT_BASE], font_ptr + 1); undump_things(char_base[FONT_BASE], font_ptr + 1); @@ -2830,7 +2786,7 @@ load_fmt_file(void) hyph_link[j] = hyph_next; undump_int(x); - if (x < 0 || x > str_ptr) + if (x < 0 || x > str_ptr()) goto bad_fmt; else hyph_word[j] = x; @@ -2941,11 +2897,11 @@ final_cleanup(void) if (c != 1) INTPAR(new_line_char) = -1; - if (job_name == 0) + if (job_name() == 0) open_log_file(); - while (input_ptr > 0) - if (cur_input.state == TOKEN_LIST) + while (input_ptr() > 0) + if (cur_input().state == TOKEN_LIST) end_token_list(); else end_file_reading(); @@ -2973,20 +2929,20 @@ final_cleanup(void) print_int(if_line); } print_cstr(" was incomplete)"); - if_line = mem[cond_ptr + 1].b32.s1; - cur_if = mem[cond_ptr].b16.s0; + if_line = mem(cond_ptr + 1).b32.s1; + cur_if = mem(cond_ptr).b16.s0; temp_ptr = cond_ptr; cond_ptr = LLIST_link(cond_ptr); free_node(temp_ptr, IF_NODE_SIZE); } - if (history != HISTORY_SPOTLESS) { - if ((history == HISTORY_WARNING_ISSUED || (interaction < ERROR_STOP_MODE))) { + if (history() != HISTORY_SPOTLESS) { + if ((history() == HISTORY_WARNING_ISSUED || (interaction() < ERROR_STOP_MODE))) { - if (selector == SELECTOR_TERM_AND_LOG) { - selector = SELECTOR_TERM_ONLY; + if (selector() == SELECTOR_TERM_AND_LOG) { + set_selector(SELECTOR_TERM_ONLY); print_nl_cstr("(see the transcript file for additional information)"); - selector = SELECTOR_TERM_AND_LOG; + set_selector(SELECTOR_TERM_AND_LOG); } } } @@ -3042,10 +2998,10 @@ init_io(void) stdin_ufile.conversionData = 0; input_file[0] = &stdin_ufile; - buffer[first] = 0; + set_buffer(first, 0); last = first; - cur_input.loc = first; - cur_input.limit = last; + cur_input_ptr()->loc = first; + cur_input_ptr()->limit = last; first = last + 1; } @@ -3056,11 +3012,11 @@ initialize_more_variables(void) int32_t k; hyph_pointer z; - doing_special = false; + set_doing_special(false); native_text_size = 128; native_text = xmalloc(native_text_size * sizeof(UTF16_code)); - interaction = ERROR_STOP_MODE; + set_interaction(ERROR_STOP_MODE); deletions_allowed = true; set_box_allowed = true; @@ -3111,11 +3067,11 @@ initialize_more_variables(void) XEQ_LEVEL(k) = LEVEL_ONE; no_new_control_sequence = true; - prim[0].s0 = 0; - prim[0].s1 = 0; + prim_ptr(0)->s0 = 0; + prim_ptr(0)->s1 = 0; for (k = 1; k <= PRIM_SIZE; k++) - prim[k] = prim[0]; + set_prim(k, prim(0)); save_ptr = 0; cur_level = LEVEL_ONE; @@ -3207,7 +3163,7 @@ initialize_more_variables(void) disc_ptr[LAST_BOX_CODE] = TEX_NULL; disc_ptr[VSPLIT_CODE] = TEX_NULL; edit_name_start = 0; - stop_at_space = true; + set_stop_at_space(true); } static void @@ -3216,97 +3172,97 @@ initialize_more_initex_variables(void) int32_t i, k; for (k = 1; k <= 19; k++) - mem[k].b32.s1 = 0; + mem_ptr(k)->b32.s1 = 0; for (k = 0; k <= 19; k += 4) { - mem[k].b32.s1 = TEX_NULL + 1; - mem[k].b16.s1 = NORMAL; - mem[k].b16.s0 = NORMAL; + mem_ptr(k)->b32.s1 = TEX_NULL + 1; + mem_ptr(k)->b16.s1 = NORMAL; + mem_ptr(k)->b16.s0 = NORMAL; } - mem[6].b32.s1 = 65536L; - mem[4].b16.s1 = FIL; - mem[10].b32.s1 = 65536L; - mem[8].b16.s1 = FILL; - mem[14].b32.s1 = 65536L; - mem[12].b16.s1 = FIL; - mem[15].b32.s1 = 65536L; - mem[12].b16.s0 = FIL; - mem[18].b32.s1 = -65536L; - mem[16].b16.s1 = FIL; + mem_ptr(6)->b32.s1 = 65536L; + mem_ptr(4)->b16.s1 = FIL; + mem_ptr(10)->b32.s1 = 65536L; + mem_ptr(8)->b16.s1 = FILL; + mem_ptr(14)->b32.s1 = 65536L; + mem_ptr(12)->b16.s1 = FIL; + mem_ptr(15)->b32.s1 = 65536L; + mem_ptr(12)->b16.s0 = FIL; + mem_ptr(18)->b32.s1 = -65536L; + mem_ptr(16)->b16.s1 = FIL; rover = 20; - mem[rover].b32.s1 = MAX_HALFWORD; - mem[rover].b32.s0 = 1000; - mem[rover + 1].b32.s0 = rover; - mem[rover + 1].b32.s1 = rover; + mem_ptr(rover)->b32.s1 = MAX_HALFWORD; + mem_ptr(rover)->b32.s0 = 1000; + mem_ptr(rover + 1)->b32.s0 = rover; + mem_ptr(rover + 1)->b32.s1 = rover; lo_mem_max = rover + 1000; - mem[lo_mem_max].b32.s1 = TEX_NULL; - mem[lo_mem_max].b32.s0 = TEX_NULL; + mem_ptr(lo_mem_max)->b32.s1 = TEX_NULL; + mem_ptr(lo_mem_max)->b32.s0 = TEX_NULL; for (k = PRE_ADJUST_HEAD; k <= MEM_TOP; k++) - mem[k] = mem[lo_mem_max]; - - mem[OMIT_TEMPLATE].b32.s0 = CS_TOKEN_FLAG + FROZEN_END_TEMPLATE; - mem[END_SPAN].b32.s1 = UINT16_MAX + 1; - mem[END_SPAN].b32.s0 = TEX_NULL; - mem[ACTIVE_LIST].b16.s1 = HYPHENATED; - mem[ACTIVE_LIST+1].b32.s0 = MAX_HALFWORD; - mem[ACTIVE_LIST].b16.s0 = 0; - mem[PAGE_INS_HEAD].b16.s0 = 255; - mem[PAGE_INS_HEAD].b16.s1 = SPLIT_UP; - mem[PAGE_INS_HEAD].b32.s1 = PAGE_INS_HEAD; + set_mem(k, mem(lo_mem_max)); + + mem_ptr(OMIT_TEMPLATE)->b32.s0 = CS_TOKEN_FLAG + FROZEN_END_TEMPLATE; + mem_ptr(END_SPAN)->b32.s1 = UINT16_MAX + 1; + mem_ptr(END_SPAN)->b32.s0 = TEX_NULL; + mem_ptr(ACTIVE_LIST)->b16.s1 = HYPHENATED; + mem_ptr(ACTIVE_LIST+1)->b32.s0 = MAX_HALFWORD; + mem_ptr(ACTIVE_LIST)->b16.s0 = 0; + mem_ptr(PAGE_INS_HEAD)->b16.s0 = 255; + mem_ptr(PAGE_INS_HEAD)->b16.s1 = SPLIT_UP; + mem_ptr(PAGE_INS_HEAD)->b32.s1 = PAGE_INS_HEAD; NODE_type(PAGE_HEAD) = GLUE_NODE; - mem[PAGE_HEAD].b16.s0 = NORMAL; + mem_ptr(PAGE_HEAD)->b16.s0 = NORMAL; avail = TEX_NULL; mem_end = MEM_TOP; hi_mem_min = PRE_ADJUST_HEAD; var_used = 20; dyn_used = HI_MEM_STAT_USAGE; - eqtb[UNDEFINED_CONTROL_SEQUENCE].b16.s1 = UNDEFINED_CS; - eqtb[UNDEFINED_CONTROL_SEQUENCE].b32.s1 = TEX_NULL; - eqtb[UNDEFINED_CONTROL_SEQUENCE].b16.s0 = LEVEL_ZERO; + eqtb_ptr(UNDEFINED_CONTROL_SEQUENCE)->b16.s1 = UNDEFINED_CS; + eqtb_ptr(UNDEFINED_CONTROL_SEQUENCE)->b32.s1 = TEX_NULL; + eqtb_ptr(UNDEFINED_CONTROL_SEQUENCE)->b16.s0 = LEVEL_ZERO; - for (k = ACTIVE_BASE; k <= eqtb_top; k++) - eqtb[k] = eqtb[UNDEFINED_CONTROL_SEQUENCE]; + for (k = ACTIVE_BASE; k <= eqtb_top(); k++) + set_eqtb(k, eqtb(UNDEFINED_CONTROL_SEQUENCE)); - eqtb[GLUE_BASE].b32.s1 = 0; - eqtb[GLUE_BASE].b16.s0 = LEVEL_ONE; - eqtb[GLUE_BASE].b16.s1 = GLUE_REF; + eqtb_ptr(GLUE_BASE)->b32.s1 = 0; + eqtb_ptr(GLUE_BASE)->b16.s0 = LEVEL_ONE; + eqtb_ptr(GLUE_BASE)->b16.s1 = GLUE_REF; for (k = GLUE_BASE + 1; k <= LOCAL_BASE - 1; k++) - eqtb[k] = eqtb[GLUE_BASE]; + set_eqtb(k, eqtb(GLUE_BASE)); - mem[0].b32.s1 += 531; + mem_ptr(0)->b32.s1 += 531; LOCAL(par_shape) = TEX_NULL; - eqtb[LOCAL_BASE + LOCAL__par_shape].b16.s1 = SHAPE_REF; - eqtb[LOCAL_BASE + LOCAL__par_shape].b16.s0 = LEVEL_ONE; + eqtb_ptr(LOCAL_BASE + LOCAL__par_shape)->b16.s1 = SHAPE_REF; + eqtb_ptr(LOCAL_BASE + LOCAL__par_shape)->b16.s0 = LEVEL_ONE; for (k = ETEX_PEN_BASE; k <= NUM_ETEX_PENALTIES - 1; k++) - eqtb[k] = eqtb[LOCAL_BASE + LOCAL__par_shape]; + set_eqtb(k, eqtb(LOCAL_BASE + LOCAL__par_shape)); for (k = LOCAL_BASE + LOCAL__output_routine; k <= TOKS_BASE + NUMBER_REGS - 1; k++) - eqtb[k] = eqtb[UNDEFINED_CONTROL_SEQUENCE]; + set_eqtb(k, eqtb(UNDEFINED_CONTROL_SEQUENCE)); - eqtb[BOX_BASE].b32.s1 = TEX_NULL; - eqtb[BOX_BASE].b16.s1 = BOX_REF; - eqtb[BOX_BASE].b16.s0 = LEVEL_ONE; + eqtb_ptr(BOX_BASE)->b32.s1 = TEX_NULL; + eqtb_ptr(BOX_BASE)->b16.s1 = BOX_REF; + eqtb_ptr(BOX_BASE)->b16.s0 = LEVEL_ONE; for (k = BOX_BASE + 1; k <= BOX_BASE + NUMBER_REGS - 1; k++) - eqtb[k] = eqtb[BOX_BASE]; + set_eqtb(k, eqtb(BOX_BASE)); - eqtb[CUR_FONT_LOC].b32.s1 = FONT_BASE; - eqtb[CUR_FONT_LOC].b16.s1 = DATA; - eqtb[CUR_FONT_LOC].b16.s0 = LEVEL_ONE; + eqtb_ptr(CUR_FONT_LOC)->b32.s1 = FONT_BASE; + eqtb_ptr(CUR_FONT_LOC)->b16.s1 = DATA; + eqtb_ptr(CUR_FONT_LOC)->b16.s0 = LEVEL_ONE; for (k = MATH_FONT_BASE; k <= MATH_FONT_BASE + NUMBER_MATH_FONTS - 1; k++) - eqtb[k] = eqtb[CUR_FONT_LOC]; + set_eqtb(k, eqtb(CUR_FONT_LOC)); - eqtb[CAT_CODE_BASE].b32.s1 = 0; - eqtb[CAT_CODE_BASE].b16.s1 = DATA; - eqtb[CAT_CODE_BASE].b16.s0 = LEVEL_ONE; + eqtb_ptr(CAT_CODE_BASE)->b32.s1 = 0; + eqtb_ptr(CAT_CODE_BASE)->b16.s1 = DATA; + eqtb_ptr(CAT_CODE_BASE)->b16.s0 = LEVEL_ONE; for (k = CAT_CODE_BASE + 1; k <= INT_BASE - 1; k++) - eqtb[k] = eqtb[CAT_CODE_BASE]; + set_eqtb(k, eqtb(CAT_CODE_BASE)); for (k = 0; k <= NUMBER_USVS - 1; k++) { CAT_CODE(k) = OTHER_CHAR; @@ -3319,7 +3275,7 @@ initialize_more_initex_variables(void) CAT_CODE(92) = ESCAPE; CAT_CODE(37) = COMMENT; CAT_CODE(127) = INVALID_CHAR; - eqtb[CAT_CODE_BASE].b32.s1 = IGNORE; + eqtb_ptr(CAT_CODE_BASE)->b32.s1 = IGNORE; for (k = '0'; k <= '9'; k++) MATH_CODE(k) = k + set_class(VAR_FAM_CLASS); @@ -3337,7 +3293,7 @@ initialize_more_initex_variables(void) } for (k = INT_BASE; k <= DEL_CODE_BASE - 1; k++) - eqtb[k].b32.s1 = 0; + eqtb_ptr(k)->b32.s1 = 0; INTPAR(mag) = 1000; INTPAR(tolerance) = 10000; @@ -3352,10 +3308,10 @@ initialize_more_initex_variables(void) DEL_CODE(46 /* '.' */) = 0; for (k = DIMEN_BASE; k <= EQTB_SIZE; k++) - eqtb[k].b32.s1 = 0; + eqtb_ptr(k)->b32.s1 = 0; prim_used = PRIM_SIZE; - hash_used = FROZEN_CONTROL_SEQUENCE; + set_hash_used(FROZEN_CONTROL_SEQUENCE); hash_high = 0; cs_count = 0; @@ -3412,37 +3368,38 @@ initialize_primitives(void) default: /* A "frozen" primitive */ - hash[prim.extra_init].s1 = maketexstring(prim.name); - eqtb[prim.extra_init] = eqtb[cur_val]; + hash_ptr(prim.extra_init)->s1 = maketexstring(prim.name); + set_eqtb(prim.extra_init, eqtb(cur_val)); break; } } } - hash[FROZEN_END_TEMPLATE].s1 = maketexstring("endtemplate"); - eqtb[FROZEN_END_TEMPLATE].b16.s1 = END_TEMPLATE; - eqtb[FROZEN_END_TEMPLATE].b32.s1 = NULL_LIST; - eqtb[FROZEN_END_TEMPLATE].b16.s0 = LEVEL_ONE; + hash_ptr(FROZEN_END_TEMPLATE)->s1 = maketexstring("endtemplate"); + eqtb_ptr(FROZEN_END_TEMPLATE)->b16.s1 = END_TEMPLATE; + eqtb_ptr(FROZEN_END_TEMPLATE)->b32.s1 = NULL_LIST; + eqtb_ptr(FROZEN_END_TEMPLATE)->b16.s0 = LEVEL_ONE; + - hash[FROZEN_ENDV].s1 = maketexstring("endtemplate"); - eqtb[FROZEN_ENDV].b16.s1 = ENDV; - eqtb[FROZEN_ENDV].b32.s1 = NULL_LIST; - eqtb[FROZEN_ENDV].b16.s0 = LEVEL_ONE; + hash_ptr(FROZEN_ENDV)->s1 = maketexstring("endtemplate"); + eqtb_ptr(FROZEN_ENDV)->b16.s1 = ENDV; + eqtb_ptr(FROZEN_ENDV)->b32.s1 = NULL_LIST; + eqtb_ptr(FROZEN_ENDV)->b16.s0 = LEVEL_ONE; - hash[FROZEN_DONT_EXPAND].s1 = maketexstring("notexpanded:"); - eqtb[FROZEN_DONT_EXPAND].b16.s1 = DONT_EXPAND; + hash_ptr(FROZEN_DONT_EXPAND)->s1 = maketexstring("notexpanded:"); + eqtb_ptr(FROZEN_DONT_EXPAND)->b16.s1 = DONT_EXPAND; - hash[FROZEN_PRIMITIVE].s1 = maketexstring("primitive"); - eqtb[FROZEN_PRIMITIVE].b16.s1 = IGNORE_SPACES; - eqtb[FROZEN_PRIMITIVE].b32.s1 = 1; - eqtb[FROZEN_PRIMITIVE].b16.s0 = LEVEL_ONE; + hash_ptr(FROZEN_PRIMITIVE)->s1 = maketexstring("primitive"); + eqtb_ptr(FROZEN_PRIMITIVE)->b16.s1 = IGNORE_SPACES; + eqtb_ptr(FROZEN_PRIMITIVE)->b32.s1 = 1; + eqtb_ptr(FROZEN_PRIMITIVE)->b16.s0 = LEVEL_ONE; - hash[FROZEN_PROTECTION].s1 = maketexstring("inaccessible"); + hash_ptr(FROZEN_PROTECTION)->s1 = maketexstring("inaccessible"); - hash[END_WRITE].s1 = maketexstring("endwrite"); - eqtb[END_WRITE].b16.s0 = LEVEL_ONE; - eqtb[END_WRITE].b16.s1 = OUTER_CALL; - eqtb[END_WRITE].b32.s1 = TEX_NULL; + hash_ptr(END_WRITE)->s1 = maketexstring("endwrite"); + eqtb_ptr(END_WRITE)->b16.s0 = LEVEL_ONE; + eqtb_ptr(END_WRITE)->b16.s1 = OUTER_CALL; + eqtb_ptr(END_WRITE)->b32.s1 = TEX_NULL; no_new_control_sequence = true; } @@ -3451,12 +3408,12 @@ initialize_primitives(void) static void get_strings_started(void) { - pool_ptr = 0; - str_ptr = 0; - str_start[0] = 0; - str_ptr = TOO_BIG_CHAR; + set_pool_ptr(0); + set_str_ptr(0); + set_str_start(0, 0); + set_str_ptr(TOO_BIG_CHAR); - if (load_pool_strings(pool_size - string_vacancies) == 0) + if (load_pool_strings(pool_size() - string_vacancies) == 0) _tt_abort ("must increase pool_size"); } /*:1001*/ @@ -3489,24 +3446,24 @@ tt_cleanup(void) { } } - for (int i = 1; i <= in_open; i++) { + for (int i = 1; i <= in_open(); i++) { if (input_file[i] != NULL) { u_close(input_file[i]); } } // Free the big allocated arrays - free(buffer); + clear_buffer(); free(nest); free(save_stack); - free(input_stack); + clear_input_stack(); free(input_file); - free(line_stack); + clear_line_stack(); free(eof_seen); free(grp_stack); free(if_stack); free(source_filename_stack); - free(full_source_filename_stack); + clear_full_source_filename_stack(); free(param_stack); free(hyph_word); free(hyph_list); @@ -3517,10 +3474,10 @@ tt_cleanup(void) { // Free arrays allocated in load_fmt_file free(yhash); - free(eqtb); - free(mem); - free(str_start); - free(str_pool); + clear_eqtb(); + clear_mem(); + clear_str_start(); + clear_str_pool(); free(font_info); free(font_mapping); @@ -3566,7 +3523,7 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d /* Get our stdout handle */ - rust_stdout = ttstub_output_open_stdout (); + set_rust_stdout(ttstub_output_open_stdout()); size_t len = strlen (dump_name); TEX_format_default = xmalloc (len + 1); @@ -3575,16 +3532,16 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d /* Not sure why these get custom initializations. */ - if (file_line_error_style_p < 0) - file_line_error_style_p = 0; + if (file_line_error_style_p() < 0) + set_file_line_error_style_p(0); /* These various parameters were configurable in web2c TeX. We don't * bother to allow that. */ - pool_size = 6250000L; + set_pool_size(6250000L); string_vacancies = 90000L; pool_free = 47500L; - max_strings = 565536L; + set_max_strings(565536L); strings_free = 100; font_mem_size = 8000000L; font_max = 9000; @@ -3596,25 +3553,23 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d param_size = 10000; save_size = 80000L; stack_size = 5000; - error_line = 79; + set_error_line(79); half_error_line = 50; max_print_line = 79; - hash_extra = 600000L; + set_hash_extra(600000L); expand_depth = 10000; /* Allocate many of our big arrays. */ - buffer = xmalloc_array(UnicodeScalar, buf_size); + resize_buffer(buf_size+1); nest = xmalloc_array(list_state_record, nest_size); save_stack = xmalloc_array(memory_word, save_size); - input_stack = xmalloc_array(input_state_t, stack_size); + resize_input_stack(stack_size+1); input_file = xmalloc_array(UFILE *, max_in_open); - line_stack = xmalloc_array(int32_t, max_in_open); eof_seen = xmalloc_array(bool, max_in_open); grp_stack = xmalloc_array(save_pointer, max_in_open); if_stack = xmalloc_array(int32_t, max_in_open); source_filename_stack = xmalloc_array(str_number, max_in_open); - full_source_filename_stack = xmalloc_array(str_number, max_in_open); param_stack = xmalloc_array(int32_t, param_size); hyph_word = xmalloc_array(str_number, hyph_size); hyph_list = xmalloc_array(int32_t, hyph_size); @@ -3623,34 +3578,33 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d /* First bit of initex handling: more allocations. */ if (in_initex_mode) { - mem = xmalloc_array(memory_word, MEM_TOP + 1); - eqtb_top = EQTB_SIZE + hash_extra; + resize_mem(MEM_TOP + 1); + set_eqtb_top(EQTB_SIZE + hash_extra()); - if (hash_extra == 0) - hash_top = UNDEFINED_CONTROL_SEQUENCE; + if (hash_extra() == 0) + set_hash_top(UNDEFINED_CONTROL_SEQUENCE); else - hash_top = eqtb_top; + set_hash_top(eqtb_top()); - yhash = xmalloc_array(b32x2, 1 + hash_top - hash_offset); - hash = yhash - hash_offset; - hash[HASH_BASE].s0 = 0; - hash[HASH_BASE].s1 = 0; + resize_hash(1 + hash_top() - hash_offset); + hash_ptr(HASH_BASE)->s0 = 0; + hash_ptr(HASH_BASE)->s1 = 0; - for (hash_used = HASH_BASE + 1; hash_used <= hash_top; hash_used++) - hash[hash_used] = hash[HASH_BASE]; + for (set_hash_used(HASH_BASE + 1); hash_used() <= hash_top(); set_hash_used(hash_used()+1)) + set_hash(hash_used(), hash(HASH_BASE)); - eqtb = xcalloc_array(memory_word, eqtb_top); - str_start = xmalloc_array(pool_pointer, max_strings); - str_pool = xmalloc_array(packed_UTF16_code, pool_size); + resize_eqtb(eqtb_top() + 1); + resize_str_start(max_strings()); + resize_str_pool(pool_size()); font_info = xmalloc_array(memory_word, font_mem_size); } /* Sanity-check various invariants. */ - history = HISTORY_FATAL_ERROR; + set_history(HISTORY_FATAL_ERROR); bad = 0; - if (half_error_line < 30 || half_error_line > error_line - 15) + if (half_error_line < 30 || half_error_line > error_line() - 15) bad = 1; if (max_print_line < 60) bad = 2; @@ -3668,11 +3622,11 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d bad = 15; if (font_max > FONT_BASE + 9000) bad = 16; - if (save_size > MAX_HALFWORD || max_strings > MAX_HALFWORD) + if (save_size > MAX_HALFWORD || max_strings() > MAX_HALFWORD) bad = 17; if (buf_size > MAX_HALFWORD) bad = 18; - if (CS_TOKEN_FLAG + EQTB_SIZE + hash_extra > MAX_HALFWORD) + if (CS_TOKEN_FLAG + EQTB_SIZE + hash_extra() > MAX_HALFWORD) bad = 21; if (hash_offset < 0 || hash_offset > HASH_BASE) bad = 42; @@ -3692,8 +3646,8 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d get_strings_started(); initialize_more_initex_variables(); initialize_primitives(); - init_str_ptr = str_ptr; - init_pool_ptr = pool_ptr; + init_str_ptr = str_ptr(); + init_pool_ptr = pool_ptr(); } /*55:*/ @@ -3704,24 +3658,24 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d get_seconds_and_micros(&epochseconds, µseconds); init_start_time(build_date); - selector = SELECTOR_TERM_ONLY; - tally = 0; - term_offset = 0; - file_offset = 0; - job_name = 0; - name_in_progress = false; - log_opened = false; + set_selector(SELECTOR_TERM_ONLY); + set_tally(0); + set_term_offset(0); + set_file_offset(0); + set_job_name(0); + set_name_in_progress(false); + set_log_opened(false); if (semantic_pagination_enabled) output_file_extension = ".spx"; else output_file_extension = ".xdv"; - input_ptr = 0; + set_input_ptr(0); max_in_stack = 0; source_filename_stack[0] = 0; - full_source_filename_stack[0] = 0; - in_open = 0; + set_full_source_filename_stack(0, 0); + set_in_open(0); open_parens = 0; max_buf_stack = 0; grp_stack[0] = 0; @@ -3731,17 +3685,17 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d used_tectonic_coda_tokens = false; gave_char_warning_help = false; - memset(buffer, 0, buf_size * sizeof(buffer[0])); + memset(buffer_ptr(), 0, buf_size * sizeof(buffer(0))); first = 0; scanner_status = NORMAL; warning_index = TEX_NULL; first = 1; - cur_input.state = NEW_LINE; - cur_input.start = 1; - cur_input.index = 0; - line = 0; - cur_input.name = 0; + cur_input_ptr()->state = NEW_LINE; + cur_input_ptr()->start = 1; + cur_input_ptr()->index = 0; + set_line(0); + cur_input_ptr()->name = 0; force_eof = false; align_state = 1000000L; @@ -3757,13 +3711,13 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d if (!in_initex_mode) { if (!load_fmt_file()) - return history; + return history(); } if (INTPAR(end_line_char) < 0 || INTPAR(end_line_char) > BIGGEST_CHAR) - cur_input.limit--; + cur_input_ptr()->limit--; else - buffer[cur_input.limit] = INTPAR(end_line_char); + set_buffer(cur_input().limit, INTPAR(end_line_char)); if (in_initex_mode) { /* TeX initializes with the real date and time, but for format file @@ -3859,10 +3813,10 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d random_seed = (microseconds * 1000) + (epochseconds % 1000000L); init_randoms(random_seed); - if (interaction == BATCH_MODE) - selector = SELECTOR_NO_PRINT; + if (interaction() == BATCH_MODE) + set_selector(SELECTOR_NO_PRINT); else - selector = SELECTOR_TERM_ONLY; /*:79*/ + set_selector(SELECTOR_TERM_ONLY); /*:79*/ if (semantic_pagination_enabled) INTPAR(xetex_generate_actual_text) = 1; @@ -3870,12 +3824,12 @@ tt_run_engine(const char *dump_name, const char *input_file_name, time_t build_d pdf_files_init(); synctex_init_command(); start_input(input_file_name); - history = HISTORY_SPOTLESS; + set_history(HISTORY_SPOTLESS); main_control(); final_cleanup(); close_files_and_terminate(); tt_cleanup(); - return history; + return history(); } diff --git a/crates/engine_xetex/xetex/xetex-io.c b/crates/engine_xetex/xetex/xetex-io.c index de71b33b4..08a09a62e 100644 --- a/crates/engine_xetex/xetex/xetex-io.c +++ b/crates/engine_xetex/xetex/xetex-io.c @@ -26,7 +26,7 @@ tt_xetex_open_input (int filefmt) if (filefmt == TTBC_FILE_FORMAT_TECTONIC_PRIMARY) { handle = ttstub_input_open_primary (); - } else if (name_of_file[0] == '|') { + } else if (name_of_file()[0] == '|') { // Tectonic TODO: issue #859. In mainline XeTeX, a pipe symbol indicates // piped input from an external command via `popen()`. Now that we have // shell-escape support we could also support this, but we don't have a @@ -37,7 +37,7 @@ tt_xetex_open_input (int filefmt) capture_to_diagnostic(NULL); return INVALID_HANDLE; } else { - handle = ttstub_input_open (name_of_file, (ttbc_file_format) filefmt, 0); + handle = ttstub_input_open (name_of_file(), (ttbc_file_format) filefmt, 0); } if (handle == INVALID_HANDLE) @@ -47,9 +47,9 @@ tt_xetex_open_input (int filefmt) abspath_of_input_file[0] = '\0'; } - name_length = strlen(name_of_file); +// name_length = strlen(name_of_file()); free(name_of_input_file); - name_of_input_file = xstrdup(name_of_file); + name_of_input_file = xstrdup(name_of_file()); return handle; } @@ -209,11 +209,11 @@ apply_normalization(uint32_t* buf, int len, int norm) } status = TECkit_ConvertBuffer(*normPtr, (Byte*)buf, len * sizeof(UInt32), &inUsed, - (Byte*)&buffer[first], sizeof(*buffer) * (buf_size - first), &outUsed, 1); + (Byte*)&buffer_ptr()[first], sizeof(buffer(0)) * (buf_size - first), &outUsed, 1); TECkit_ResetConverter(*normPtr); if (status != kStatus_NoError) buffer_overflow(); - last = first + outUsed / sizeof(*buffer); + last = first + outUsed / sizeof(buffer(0)); } @@ -279,13 +279,13 @@ input_line(UFILE* f) default: // none outLen = ucnv_toAlgorithmic(UCNV_UTF32_NativeEndian, cnv, - (char*)&buffer[first], sizeof(*buffer) * (buf_size - first), + (char*)&buffer_ptr()[first], sizeof(buffer(0)) * (buf_size - first), byteBuffer, bytesRead, &errorCode); if (errorCode != 0) { conversion_error((int)errorCode); return false; } - outLen /= sizeof(*buffer); + outLen /= sizeof(buffer(0)); last = first + outLen; break; } @@ -322,10 +322,10 @@ input_line(UFILE* f) default: // none if (last < buf_size && i != EOF && i != '\n' && i != '\r') - buffer[last++] = i; + set_buffer(last++, i); if (i != EOF && i != '\n' && i != '\r') while (last < buf_size && (i = get_uni_c(f)) != EOF && i != '\n' && i != '\r') - buffer[last++] = i; + set_buffer(last++, i); if (i == EOF && errno != EINTR && last == first) return false; @@ -341,13 +341,13 @@ input_line(UFILE* f) if (i == '\r') f->skipNextLF = 1; - buffer[last] = ' '; + set_buffer(last, ' '); if (last >= max_buf_stack) max_buf_stack = last; /* Trim trailing space or EOL characters. */ #define IS_SPC_OR_EOL(c) ((c) == ' ' || (c) == '\r' || (c) == '\n') - while (last > first && IS_SPC_OR_EOL(buffer[last - 1])) + while (last > first && IS_SPC_OR_EOL(buffer(last - 1))) --last; return true; @@ -478,45 +478,6 @@ get_uni_c(UFILE* f) } -void -make_utf16_name(void) -{ - unsigned char* s = (unsigned char *) name_of_file; - uint32_t rval; - uint16_t* t; - static int name16len = 0; - if (name16len <= name_length) { - free(name_of_file16); - name16len = name_length + 10; - name_of_file16 = xcalloc(name16len, sizeof(uint16_t)); - } - t = name_of_file16; - - while (s < (unsigned char *) name_of_file + name_length) { - uint16_t extraBytes; - rval = *(s++); - extraBytes = bytesFromUTF8[rval]; - switch (extraBytes) { /* note: code falls through cases! */ - case 5: rval <<= 6; if (*s) rval += *(s++); - case 4: rval <<= 6; if (*s) rval += *(s++); - case 3: rval <<= 6; if (*s) rval += *(s++); - case 2: rval <<= 6; if (*s) rval += *(s++); - case 1: rval <<= 6; if (*s) rval += *(s++); - case 0: ; - }; - rval -= offsetsFromUTF8[extraBytes]; - if (rval > 0xffff) { - rval -= 0x10000; - *(t++) = 0xd800 + rval / 0x0400; - *(t++) = 0xdc00 + rval % 0x0400; - } else { - *(t++) = rval; - } - } - name_length16 = t - name_of_file16; -} - - void open_or_close_in(void) { @@ -535,20 +496,20 @@ open_or_close_in(void) if (c != 0) { scan_optional_equals(); scan_file_name(); - pack_file_name(cur_name, cur_area, cur_ext); + pack_file_name(cur_name(), cur_area(), cur_ext()); if (u_open_in(&read_file[n], TTBC_FILE_FORMAT_TEX, "rb", INTPAR(xetex_default_input_mode), INTPAR(xetex_default_input_encoding))) { make_utf16_name(); - name_in_progress = true; + set_name_in_progress(true); begin_name(); - stop_at_space = false; + set_stop_at_space(false); k = 0; - while ((k < name_length16) && (more_name(name_of_file16[k]))) + while ((k < name_length16()) && (more_name(name_of_file16()[k]))) k++; - stop_at_space = true; + set_stop_at_space(true); end_name(); - name_in_progress = false; + set_name_in_progress(false); read_open[n] = JUST_OPEN; } } diff --git a/crates/engine_xetex/xetex/xetex-linebreak.c b/crates/engine_xetex/xetex/xetex-linebreak.c index 59e13ed28..c15ef5b71 100644 --- a/crates/engine_xetex/xetex/xetex-linebreak.c +++ b/crates/engine_xetex/xetex/xetex-linebreak.c @@ -13,6 +13,7 @@ #include "xetex-core.h" #include "xetex-xetexd.h" #include "tectonic_bridge_core.h" +#include "xetex_bindings.h" #define AWFUL_BAD 0x3FFFFFFF @@ -212,8 +213,8 @@ line_break(bool d) } else { last_special_line = LLIST_info(LOCAL(par_shape)) - 1; /* These direct `mem` accesses are in the original WEB code */ - second_width = mem[LOCAL(par_shape) + 2 * (last_special_line + 1)].b32.s1; - second_indent = mem[LOCAL(par_shape) + 2 * last_special_line + 1].b32.s1; + second_width = mem(LOCAL(par_shape) + 2 * (last_special_line + 1)).b32.s1; + second_indent = mem(LOCAL(par_shape) + 2 * last_special_line + 1).b32.s1; } if (INTPAR(looseness) == 0) @@ -1015,35 +1016,35 @@ post_line_break(bool d) **/ if (INTPAR(texxet) > 0) { /*1494:*/ - q = mem[TEMP_HEAD].b32.s1; + q = mem(TEMP_HEAD).b32.s1; if (LR_ptr != TEX_NULL) { temp_ptr = LR_ptr; r = q; do { - s = new_math(0, (mem[temp_ptr].b32.s0 - 1)); - mem[s].b32.s1 = r; + s = new_math(0, (mem(temp_ptr).b32.s0 - 1)); + mem_ptr(s)->b32.s1 = r; r = s; temp_ptr = LLIST_link(temp_ptr); } while (temp_ptr != TEX_NULL); - mem[TEMP_HEAD].b32.s1 = r; + mem_ptr(TEMP_HEAD)->b32.s1 = r; } - while (q != mem[cur_p + 1].b32.s1) { + while (q != mem(cur_p + 1).b32.s1) { if (q < hi_mem_min && NODE_type(q) == MATH_NODE) { /*1495:*/ - if (odd(mem[q].b16.s0)) { - if (LR_ptr != TEX_NULL && mem[LR_ptr].b32.s0 == (L_CODE * (mem[q].b16.s0 / L_CODE) + 3)) { + if (odd(mem(q).b16.s0)) { + if (LR_ptr != TEX_NULL && mem(LR_ptr).b32.s0 == (L_CODE * (mem(q).b16.s0 / L_CODE) + 3)) { temp_ptr = LR_ptr; - LR_ptr = mem[temp_ptr].b32.s1; - mem[temp_ptr].b32.s1 = avail; + LR_ptr = mem(temp_ptr).b32.s1; + mem_ptr(temp_ptr)->b32.s1 = avail; avail = temp_ptr; } } else { temp_ptr = get_avail(); - mem[temp_ptr].b32.s0 = (L_CODE * (mem[q].b16.s0 / L_CODE) + 3); - mem[temp_ptr].b32.s1 = LR_ptr; + mem_ptr(temp_ptr)->b32.s0 = (L_CODE * (mem(q).b16.s0 / L_CODE) + 3); + mem_ptr(temp_ptr)->b32.s1 = LR_ptr; LR_ptr = temp_ptr; } } @@ -1124,17 +1125,17 @@ post_line_break(bool d) BOX_width(q) = 0; if (INTPAR(texxet) > 0) { /*1495:*/ - if (odd(mem[q].b16.s0)) { - if (LR_ptr != TEX_NULL && mem[LR_ptr].b32.s0 == (L_CODE * (mem[q].b16.s0 / L_CODE) + 3)) { + if (odd(mem(q).b16.s0)) { + if (LR_ptr != TEX_NULL && mem(LR_ptr).b32.s0 == (L_CODE * (mem(q).b16.s0 / L_CODE) + 3)) { temp_ptr = LR_ptr; - LR_ptr = mem[temp_ptr].b32.s1; - mem[temp_ptr].b32.s1 = avail; + LR_ptr = mem(temp_ptr).b32.s1; + mem_ptr(temp_ptr)->b32.s1 = avail; avail = temp_ptr; } } else { temp_ptr = get_avail(); - mem[temp_ptr].b32.s0 = (L_CODE * (mem[q].b16.s0 / L_CODE) + 3); - mem[temp_ptr].b32.s1 = LR_ptr; + mem_ptr(temp_ptr)->b32.s0 = (L_CODE * (mem(q).b16.s0 / L_CODE) + 3); + mem_ptr(temp_ptr)->b32.s1 = LR_ptr; LR_ptr = temp_ptr; } } @@ -1149,17 +1150,17 @@ post_line_break(bool d) p = q; ptmp = p; } else { - p = prev_rightmost(mem[TEMP_HEAD].b32.s1, q); + p = prev_rightmost(mem(TEMP_HEAD).b32.s1, q); ptmp = p; - p = find_protchar_right(mem[TEMP_HEAD].b32.s1, p); + p = find_protchar_right(mem(TEMP_HEAD).b32.s1, p); } w = char_pw(p, 1); if (w != 0) { k = new_margin_kern(-(int32_t) w, last_rightmost_char, 1); - mem[k].b32.s1 = mem[ptmp].b32.s1; - mem[ptmp].b32.s1 = k; + mem_ptr(k)->b32.s1 = mem(ptmp).b32.s1; + mem_ptr(ptmp)->b32.s1 = k; if (ptmp == q) q = LLIST_link(q); } @@ -1175,23 +1176,23 @@ post_line_break(bool d) if (INTPAR(texxet) > 0) { /*1496:*/ if (LR_ptr != TEX_NULL) { s = TEMP_HEAD; - r = mem[s].b32.s1; + r = mem(s).b32.s1; while (r != q) { s = r; - r = mem[s].b32.s1; + r = mem(s).b32.s1; } r = LR_ptr; while (r != TEX_NULL) { - temp_ptr = new_math(0, mem[r].b32.s0); - mem[s].b32.s1 = temp_ptr; + temp_ptr = new_math(0, mem(r).b32.s0); + mem_ptr(s)->b32.s1 = temp_ptr; s = temp_ptr; r = LLIST_link(r); } - mem[s].b32.s1 = q; + mem_ptr(s)->b32.s1 = q; } } @@ -1232,8 +1233,8 @@ post_line_break(bool d) cur_indent = first_indent; } else { /* These manual `mem` indices are in the original WEB code */ - cur_width = mem[LOCAL(par_shape) + 2 * cur_line].b32.s1; - cur_indent = mem[LOCAL(par_shape) + 2 * cur_line - 1].b32.s1; + cur_width = mem(LOCAL(par_shape) + 2 * cur_line).b32.s1; + cur_indent = mem(LOCAL(par_shape) + 2 * cur_line - 1).b32.s1; } adjust_tail = ADJUST_HEAD; @@ -1348,17 +1349,17 @@ post_line_break(bool d) r = q; if (NODE_type(q) == MATH_NODE && INTPAR(texxet) > 0) { /*1495:*/ - if (odd(mem[q].b16.s0)) { - if (LR_ptr != TEX_NULL && mem[LR_ptr].b32.s0 == (L_CODE * (mem[q].b16.s0 / L_CODE) + 3)) { + if (odd(mem(q).b16.s0)) { + if (LR_ptr != TEX_NULL && mem(LR_ptr).b32.s0 == (L_CODE * (mem(q).b16.s0 / L_CODE) + 3)) { temp_ptr = LR_ptr; - LR_ptr = mem[temp_ptr].b32.s1; - mem[temp_ptr].b32.s1 = avail; + LR_ptr = mem(temp_ptr).b32.s1; + mem_ptr(temp_ptr)->b32.s1 = avail; avail = temp_ptr; } } else { temp_ptr = get_avail(); - mem[temp_ptr].b32.s0 = (L_CODE * (mem[q].b16.s0 / L_CODE) + 3); - mem[temp_ptr].b32.s1 = LR_ptr; + mem_ptr(temp_ptr)->b32.s0 = (L_CODE * (mem(q).b16.s0 / L_CODE) + 3); + mem_ptr(temp_ptr)->b32.s1 = LR_ptr; LR_ptr = temp_ptr; } } @@ -1538,9 +1539,9 @@ try_break(int32_t pi, small_number break_type) f = CHAR_NODE_font(s); eff_char = effective_char(true, f, CHAR_NODE_character(s)); - break_width[1] += FONT_CHARACTER_WIDTH(f, eff_char);; + break_width[1] += FONT_CHARACTER_WIDTH(f, eff_char); } else - switch (mem[s].b16.s1) { + switch (mem(s).b16.s1) { case LIGATURE_NODE: { int32_t eff_char; @@ -1723,7 +1724,7 @@ try_break(int32_t pi, small_number break_type) else if (LOCAL(par_shape) == TEX_NULL) line_width = first_width; else - line_width = mem[LOCAL(par_shape) + 2 * l].b32.s1; /* this mem access is in the WEB */ + line_width = mem(LOCAL(par_shape) + 2 * l).b32.s1; /* this mem access is in the WEB */ } } @@ -1770,12 +1771,12 @@ try_break(int32_t pi, small_number break_type) if (g <= 0) goto not_found; - arith_error = false; + set_arith_error(false); g = fract(g, ACTIVE_NODE_shortfall(r), ACTIVE_NODE_glue(r), MAX_HALFWORD); if (INTPAR(last_line_fit) < 1000) g = fract(g, INTPAR(last_line_fit), 1000, MAX_HALFWORD); - if (arith_error) { + if (arith_error()) { if (ACTIVE_NODE_shortfall(r) > 0) g = MAX_HALFWORD; else @@ -2052,9 +2053,9 @@ hyphenate(void) goto not_found; if (length(k) == hn) { j = 1; - u = str_start[(k) - 65536L]; + u = str_start((k) - 65536L); do { - if (str_pool[u] != hc[j]) + if (str_pool(u) != hc[j]) goto done; j++; u++; @@ -2062,7 +2063,7 @@ hyphenate(void) s = hyph_list[h]; while (s != TEX_NULL) { - hyf[mem[s].b32.s0] = 1; + hyf[mem(s).b32.s0] = 1; s = LLIST_link(s); } hn--; @@ -2140,9 +2141,9 @@ hyphenate(void) found1: if ((((ha) != TEX_NULL && (!(is_char_node(ha))) && (NODE_type(ha) == WHATSIT_NODE) - && ((mem[ha].b16.s0 == NATIVE_WORD_NODE) || (mem[ha].b16.s0 == NATIVE_WORD_NODE_AT))))) { + && ((mem(ha).b16.s0 == NATIVE_WORD_NODE) || (mem(ha).b16.s0 == NATIVE_WORD_NODE_AT))))) { s = cur_p; - while (mem[s].b32.s1 != ha) + while (mem(s).b32.s1 != ha) s = LLIST_link(s); hyphen_passed = 0; { @@ -2153,7 +2154,7 @@ hyphenate(void) do { if (odd(hyf[j])) { q = new_native_word_node(hf, j - hyphen_passed); - mem[q].b16.s0 = mem[ha].b16.s0; + mem_ptr(q)->b16.s0 = mem(ha).b16.s0; { register int32_t for_end; i = 0; @@ -2164,20 +2165,20 @@ hyphenate(void) while (i++ < for_end); } set_native_metrics(q, (INTPAR(xetex_use_glyph_metrics) > 0)); - mem[s].b32.s1 = q; + mem_ptr(s)->b32.s1 = q; s = q; q = new_disc(); - mem[q + 1].b32.s0 = new_native_character(hf, hyf_char); - mem[s].b32.s1 = q; + mem_ptr(q + 1)->b32.s0 = new_native_character(hf, hyf_char); + mem_ptr(s)->b32.s1 = q; s = q; hyphen_passed = j; } } while (j++ < for_end); } - hn = mem[ha + 4].b16.s1; + hn = mem(ha + 4).b16.s1; q = new_native_word_node(hf, hn - hyphen_passed); - mem[q].b16.s0 = mem[ha].b16.s0; + mem_ptr(q)->b16.s0 = mem(ha).b16.s0; { register int32_t for_end; i = 0; @@ -2188,39 +2189,39 @@ hyphenate(void) while (i++ < for_end); } set_native_metrics(q, (INTPAR(xetex_use_glyph_metrics) > 0)); - mem[s].b32.s1 = q; + mem_ptr(s)->b32.s1 = q; s = q; - q = mem[ha].b32.s1; - mem[s].b32.s1 = q; - mem[ha].b32.s1 = TEX_NULL; + q = mem(ha).b32.s1; + mem_ptr(s)->b32.s1 = q; + mem_ptr(ha)->b32.s1 = TEX_NULL; flush_node_list(ha); } else { - q = mem[hb].b32.s1; - mem[hb].b32.s1 = TEX_NULL; - r = mem[ha].b32.s1; - mem[ha].b32.s1 = TEX_NULL; + q = mem(hb).b32.s1; + mem_ptr(hb)->b32.s1 = TEX_NULL; + r = mem(ha).b32.s1; + mem_ptr(ha)->b32.s1 = TEX_NULL; bchar = hyf_bchar; if ((is_char_node(ha))) { - if (mem[ha].b16.s1 != hf) + if (mem(ha).b16.s1 != hf) goto found2; else { init_list = ha; init_lig = false; - hu[0] = mem[ha].b16.s0; + hu[0] = mem(ha).b16.s0; } } else if (NODE_type(ha) == LIGATURE_NODE) { - if (mem[ha + 1].b16.s1 != hf) + if (mem(ha + 1).b16.s1 != hf) goto found2; else { - init_list = mem[ha + 1].b32.s1; + init_list = mem(ha + 1).b32.s1; init_lig = true; - init_lft = (mem[ha].b16.s0 > 1); - hu[0] = mem[ha + 1].b16.s0; + init_lft = (mem(ha).b16.s0 > 1); + hu[0] = mem(ha + 1).b16.s0; if (init_list == TEX_NULL) { if (init_lft) { @@ -2236,7 +2237,7 @@ hyphenate(void) if (NODE_type(r) == LIGATURE_NODE) { - if (mem[r].b16.s0 > 1) + if (mem(r).b16.s0 > 1) goto found2; } } @@ -2246,7 +2247,7 @@ hyphenate(void) goto common_ending; } s = cur_p; - while (mem[s].b32.s1 != ha) + while (mem(s).b32.s1 != ha) s = LLIST_link(s); j = 0; goto common_ending; @@ -2263,23 +2264,23 @@ hyphenate(void) l = j; j = reconstitute(j, hn, bchar, hyf_char) + 1; if (hyphen_passed == 0) { - mem[s].b32.s1 = mem[HOLD_HEAD].b32.s1; - while (mem[s].b32.s1 > TEX_NULL) + mem_ptr(s)->b32.s1 = mem(HOLD_HEAD).b32.s1; + while (mem(s).b32.s1 > TEX_NULL) s = LLIST_link(s); if (odd(hyf[j - 1])) { l = j; hyphen_passed = j - 1; - mem[HOLD_HEAD].b32.s1 = TEX_NULL; + mem_ptr(HOLD_HEAD)->b32.s1 = TEX_NULL; } } if (hyphen_passed > 0) /*949: */ do { r = get_node(SMALL_NODE_SIZE); - mem[r].b32.s1 = mem[HOLD_HEAD].b32.s1; + mem_ptr(r)->b32.s1 = mem(HOLD_HEAD).b32.s1; NODE_type(r) = DISC_NODE; major_tail = r; r_count = 0; - while (mem[major_tail].b32.s1 > TEX_NULL) { + while (mem(major_tail).b32.s1 > TEX_NULL) { major_tail = LLIST_link(major_tail); r_count++; @@ -2287,27 +2288,27 @@ hyphenate(void) i = hyphen_passed; hyf[i] = 0; minor_tail = TEX_NULL; - mem[r + 1].b32.s0 = TEX_NULL; + mem_ptr(r + 1)->b32.s0 = TEX_NULL; hyf_node = new_character(hf, hyf_char); if (hyf_node != TEX_NULL) { i++; c = hu[i]; hu[i] = hyf_char; { - mem[hyf_node].b32.s1 = avail; + mem_ptr(hyf_node)->b32.s1 = avail; avail = hyf_node; } } while (l <= i) { l = reconstitute(l, i, font_bchar[hf], TOO_BIG_CHAR) + 1; - if (mem[HOLD_HEAD].b32.s1 > TEX_NULL) { + if (mem(HOLD_HEAD).b32.s1 > TEX_NULL) { if (minor_tail == TEX_NULL) - mem[r + 1].b32.s0 = mem[HOLD_HEAD].b32.s1; + mem_ptr(r + 1)->b32.s0 = mem(HOLD_HEAD).b32.s1; else - mem[minor_tail].b32.s1 = mem[HOLD_HEAD].b32.s1; - minor_tail = mem[HOLD_HEAD].b32.s1; - while (mem[minor_tail].b32.s1 > TEX_NULL) + mem_ptr(minor_tail)->b32.s1 = mem(HOLD_HEAD).b32.s1; + minor_tail = mem(HOLD_HEAD).b32.s1; + while (mem(minor_tail).b32.s1 > TEX_NULL) minor_tail = LLIST_link(minor_tail); } } @@ -2317,7 +2318,7 @@ hyphenate(void) i--; } minor_tail = TEX_NULL; - mem[r + 1].b32.s1 = TEX_NULL; + mem_ptr(r + 1)->b32.s1 = TEX_NULL; c_loc = 0; if (bchar_label[hf] != NON_ADDRESS) { l--; @@ -2333,21 +2334,21 @@ hyphenate(void) hu[c_loc] = c; c_loc = 0; } - if (mem[HOLD_HEAD].b32.s1 > TEX_NULL) { + if (mem(HOLD_HEAD).b32.s1 > TEX_NULL) { if (minor_tail == TEX_NULL) - mem[r + 1].b32.s1 = mem[HOLD_HEAD].b32.s1; + mem_ptr(r + 1)->b32.s1 = mem(HOLD_HEAD).b32.s1; else - mem[minor_tail].b32.s1 = mem[HOLD_HEAD].b32.s1; - minor_tail = mem[HOLD_HEAD].b32.s1; - while (mem[minor_tail].b32.s1 > TEX_NULL) + mem_ptr(minor_tail)->b32.s1 = mem(HOLD_HEAD).b32.s1; + minor_tail = mem(HOLD_HEAD).b32.s1; + while (mem(minor_tail).b32.s1 > TEX_NULL) minor_tail = LLIST_link(minor_tail); } } while (!(l >= j)); while (l > j) { /*952: */ j = reconstitute(j, hn, bchar, TOO_BIG_CHAR) + 1; - mem[major_tail].b32.s1 = mem[HOLD_HEAD].b32.s1; - while (mem[major_tail].b32.s1 > TEX_NULL) { + mem_ptr(major_tail)->b32.s1 = mem(HOLD_HEAD).b32.s1; + while (mem(major_tail).b32.s1 > TEX_NULL) { major_tail = LLIST_link(major_tail); r_count++; @@ -2355,20 +2356,20 @@ hyphenate(void) } } if (r_count > 127) { - mem[s].b32.s1 = mem[r].b32.s1; - mem[r].b32.s1 = TEX_NULL; + mem_ptr(s)->b32.s1 = mem(r).b32.s1; + mem_ptr(r)->b32.s1 = TEX_NULL; flush_node_list(r); } else { - mem[s].b32.s1 = r; - mem[r].b16.s0 = r_count; + mem_ptr(s)->b32.s1 = r; + mem_ptr(r)->b16.s0 = r_count; } s = /*:953 */ major_tail; hyphen_passed = j - 1; - mem[HOLD_HEAD].b32.s1 = TEX_NULL; + mem_ptr(HOLD_HEAD)->b32.s1 = TEX_NULL; } while (!(!odd(hyf[j - 1]) /*:949 */ )); } while (!(j > hn)); - mem[s].b32.s1 = /*:948 */ q; + mem_ptr(s)->b32.s1 = /*:948 */ q; flush_list(init_list); } } @@ -2412,7 +2413,7 @@ reconstitute(small_number j, small_number n, int32_t bchar, int32_t hchar) hyphen_passed = 0; t = HOLD_HEAD; w = 0; - mem[HOLD_HEAD].b32.s1 = TEX_NULL; + mem_ptr(HOLD_HEAD)->b32.s1 = TEX_NULL; cur_l = hu[j]; cur_q = t; if (j == 0) { @@ -2423,18 +2424,18 @@ reconstitute(small_number j, small_number n, int32_t bchar, int32_t hchar) while (p > TEX_NULL) { { - mem[t].b32.s1 = get_avail(); + mem_ptr(t)->b32.s1 = get_avail(); t = LLIST_link(t); - mem[t].b16.s1 = hf; - mem[t].b16.s0 = mem[p].b16.s0; + mem_ptr(t)->b16.s1 = hf; + mem_ptr(t)->b16.s0 = mem(p).b16.s0; } p = LLIST_link(p); } } else if (cur_l < TOO_BIG_CHAR) { - mem[t].b32.s1 = get_avail(); + mem_ptr(t)->b32.s1 = get_avail(); t = LLIST_link(t); - mem[t].b16.s1 = hf; - mem[t].b16.s0 = cur_l; + mem_ptr(t)->b16.s1 = hf; + mem_ptr(t)->b16.s0 = cur_l; } lig_stack = TEX_NULL; { @@ -2511,7 +2512,7 @@ reconstitute(small_number j, small_number n, int32_t bchar, int32_t hchar) { cur_r = q.s0; if (lig_stack > TEX_NULL) - mem[lig_stack].b16.s0 = cur_r; + mem_ptr(lig_stack)->b16.s0 = cur_r; else { lig_stack = new_lig_item(cur_r); @@ -2520,9 +2521,9 @@ reconstitute(small_number j, small_number n, int32_t bchar, int32_t hchar) else { p = get_avail(); - mem[lig_stack + 1].b32.s1 = p; - mem[p].b16.s0 = hu[j + 1]; - mem[p].b16.s1 = hf; + mem_ptr(lig_stack + 1)->b32.s1 = p; + mem_ptr(p)->b16.s0 = hu[j + 1]; + mem_ptr(p)->b16.s1 = hf; } } } @@ -2532,26 +2533,26 @@ reconstitute(small_number j, small_number n, int32_t bchar, int32_t hchar) cur_r = q.s0; p = lig_stack; lig_stack = new_lig_item(cur_r); - mem[lig_stack].b32.s1 = p; + mem_ptr(lig_stack)->b32.s1 = p; } break; case 7: case 11: { if (ligature_present) { - p = new_ligature(hf, cur_l, mem[cur_q].b32.s1); + p = new_ligature(hf, cur_l, mem(cur_q).b32.s1); if (lft_hit) { - mem[p].b16.s0 = 2; + mem_ptr(p)->b16.s0 = 2; lft_hit = false; } if (false) { if (lig_stack == TEX_NULL) { - mem[p].b16.s0++; + mem_ptr(p)->b16.s0++; rt_hit = false; } } - mem[cur_q].b32.s1 = p; + mem_ptr(cur_q)->b32.s1 = p; t = p; ligature_present = false; } @@ -2565,13 +2566,13 @@ reconstitute(small_number j, small_number n, int32_t bchar, int32_t hchar) cur_l = q.s0; ligature_present = true; if (lig_stack > TEX_NULL) { - if (mem[lig_stack + 1].b32.s1 > TEX_NULL) { - mem[t].b32.s1 = mem[lig_stack + 1].b32.s1; + if (mem(lig_stack + 1).b32.s1 > TEX_NULL) { + mem_ptr(t)->b32.s1 = mem(lig_stack + 1).b32.s1; t = LLIST_link(t); j++; } p = lig_stack; - lig_stack = mem[p].b32.s1; + lig_stack = mem(p).b32.s1; free_node(p, SMALL_NODE_SIZE); if (lig_stack == TEX_NULL) { if (j < n) @@ -2583,16 +2584,16 @@ reconstitute(small_number j, small_number n, int32_t bchar, int32_t hchar) else cur_rh = TOO_BIG_CHAR; } else - cur_r = mem[lig_stack].b16.s0; + cur_r = mem(lig_stack).b16.s0; } else if (j == n) goto done; else { { - mem[t].b32.s1 = get_avail(); + mem_ptr(t)->b32.s1 = get_avail(); t = LLIST_link(t); - mem[t].b16.s1 = hf; - mem[t].b16.s0 = cur_r; + mem_ptr(t)->b16.s1 = hf; + mem_ptr(t)->b16.s0 = cur_r; } j++; { @@ -2636,40 +2637,40 @@ reconstitute(small_number j, small_number n, int32_t bchar, int32_t hchar) } /*:944*/ done: if (ligature_present) { - p = new_ligature(hf, cur_l, mem[cur_q].b32.s1); + p = new_ligature(hf, cur_l, mem(cur_q).b32.s1); if (lft_hit) { - mem[p].b16.s0 = 2; + mem_ptr(p)->b16.s0 = 2; lft_hit = false; } if (rt_hit) { if (lig_stack == TEX_NULL) { - mem[p].b16.s0++; + mem_ptr(p)->b16.s0++; rt_hit = false; } } - mem[cur_q].b32.s1 = p; + mem_ptr(cur_q)->b32.s1 = p; t = p; ligature_present = false; } if (w != 0) { - mem[t].b32.s1 = new_kern(w); + mem_ptr(t)->b32.s1 = new_kern(w); t = LLIST_link(t); w = 0; - mem[t + 2].b32.s0 = 0; + mem_ptr(t + 2)->b32.s0 = 0; } if (lig_stack > TEX_NULL) { cur_q = t; - cur_l = mem[lig_stack].b16.s0; + cur_l = mem(lig_stack).b16.s0; ligature_present = true; { - if (mem[lig_stack + 1].b32.s1 > TEX_NULL) { - mem[t].b32.s1 = mem[lig_stack + 1].b32.s1; + if (mem(lig_stack + 1).b32.s1 > TEX_NULL) { + mem_ptr(t)->b32.s1 = mem(lig_stack + 1).b32.s1; t = LLIST_link(t); j++; } p = lig_stack; - lig_stack = mem[p].b32.s1; + lig_stack = mem(p).b32.s1; free_node(p, SMALL_NODE_SIZE); if (lig_stack == TEX_NULL) { if (j < n) @@ -2681,7 +2682,7 @@ reconstitute(small_number j, small_number n, int32_t bchar, int32_t hchar) else cur_rh = TOO_BIG_CHAR; } else - cur_r = mem[lig_stack].b16.s0; + cur_r = mem(lig_stack).b16.s0; } goto continue_; } @@ -2694,28 +2695,28 @@ total_pw(int32_t q, int32_t p) { int32_t l, r; int32_t n; - if (mem[q + 1].b32.s1 == TEX_NULL) + if (mem(q + 1).b32.s1 == TEX_NULL) l = first_p; else - l = mem[mem[q + 1].b32.s1 + 1].b32.s1; + l = mem(mem(q + 1).b32.s1 + 1).b32.s1; r = prev_rightmost(global_prev_p, p); - if ((p != TEX_NULL) && (NODE_type(p) == DISC_NODE) && (mem[p + 1].b32.s0 != TEX_NULL)) { - r = mem[p + 1].b32.s0; - while (mem[r].b32.s1 != TEX_NULL) + if ((p != TEX_NULL) && (NODE_type(p) == DISC_NODE) && (mem(p + 1).b32.s0 != TEX_NULL)) { + r = mem(p + 1).b32.s0; + while (mem(r).b32.s1 != TEX_NULL) r = LLIST_link(r); } else r = find_protchar_right(l, r); if ((l != TEX_NULL) && (NODE_type(l) == DISC_NODE)) { - if (mem[l + 1].b32.s1 != TEX_NULL) { - l = mem[l + 1].b32.s1; + if (mem(l + 1).b32.s1 != TEX_NULL) { + l = mem(l + 1).b32.s1; goto done; } else { - n = mem[l].b16.s0; + n = mem(l).b16.s0; l = LLIST_link(l); while (n > 0) { - if (mem[l].b32.s1 != TEX_NULL) + if (mem(l).b32.s1 != TEX_NULL) l = LLIST_link(l); n--; } @@ -2733,39 +2734,39 @@ find_protchar_left(int32_t l, bool d) { int32_t t; bool run; - if ((mem[l].b32.s1 != TEX_NULL) && (NODE_type(l) == HLIST_NODE) && (mem[l + 1].b32.s1 == 0) - && (mem[l + 3].b32.s1 == 0) && (mem[l + 2].b32.s1 == 0) && (mem[l + 5].b32.s1 == TEX_NULL)) + if ((mem(l).b32.s1 != TEX_NULL) && (NODE_type(l) == HLIST_NODE) && (mem(l + 1).b32.s1 == 0) + && (mem(l + 3).b32.s1 == 0) && (mem(l + 2).b32.s1 == 0) && (mem(l + 5).b32.s1 == TEX_NULL)) l = LLIST_link(l); else if (d) - while ((mem[l].b32.s1 != TEX_NULL) && (!((is_char_node(l)) || (is_non_discardable_node(l))))) + while ((mem(l).b32.s1 != TEX_NULL) && (!((is_char_node(l)) || (is_non_discardable_node(l))))) l = LLIST_link(l); hlist_stack_level = 0; run = true; do { t = l; - while (run && (NODE_type(l) == HLIST_NODE) && (mem[l + 5].b32.s1 != TEX_NULL)) { + while (run && (NODE_type(l) == HLIST_NODE) && (mem(l + 5).b32.s1 != TEX_NULL)) { push_node(l); - l = mem[l + 5].b32.s1; + l = mem(l + 5).b32.s1; } while (run && (!(is_char_node(l)) && ((NODE_type(l) == INS_NODE) || (NODE_type(l) == MARK_NODE) || (NODE_type(l) == ADJUST_NODE) || (NODE_type(l) == PENALTY_NODE) - || ((NODE_type(l) == DISC_NODE) && (mem[l + 1].b32.s0 == TEX_NULL) - && (mem[l + 1].b32.s1 == TEX_NULL) && (mem[l].b16.s0 == 0)) - || ((NODE_type(l) == MATH_NODE) && (mem[l + 1].b32.s1 == 0)) + || ((NODE_type(l) == DISC_NODE) && (mem(l + 1).b32.s0 == TEX_NULL) + && (mem(l + 1).b32.s1 == TEX_NULL) && (mem(l).b16.s0 == 0)) + || ((NODE_type(l) == MATH_NODE) && (mem(l + 1).b32.s1 == 0)) || ((NODE_type(l) == KERN_NODE) - && ((mem[l + 1].b32.s1 == 0) || (mem[l].b16.s0 == NORMAL))) - || ((NODE_type(l) == GLUE_NODE) && (mem[l + 1].b32.s0 == 0)) - || ((NODE_type(l) == HLIST_NODE) && (mem[l + 1].b32.s1 == 0) && (mem[l + 3].b32.s1 == 0) - && (mem[l + 2].b32.s1 == 0) && (mem[l + 5].b32.s1 == TEX_NULL))))) { + && ((mem(l + 1).b32.s1 == 0) || (mem(l).b16.s0 == NORMAL))) + || ((NODE_type(l) == GLUE_NODE) && (mem(l + 1).b32.s0 == 0)) + || ((NODE_type(l) == HLIST_NODE) && (mem(l + 1).b32.s1 == 0) && (mem(l + 3).b32.s1 == 0) + && (mem(l + 2).b32.s1 == 0) && (mem(l + 5).b32.s1 == TEX_NULL))))) { - while ((mem[l].b32.s1 == TEX_NULL) && (hlist_stack_level > 0)) { + while ((mem(l).b32.s1 == TEX_NULL) && (hlist_stack_level > 0)) { l = pop_node(); } - if (mem[l].b32.s1 != TEX_NULL) + if (mem(l).b32.s1 != TEX_NULL) l = LLIST_link(l); else if (hlist_stack_level == 0) run = false; @@ -2786,27 +2787,27 @@ find_protchar_right(int32_t l, int32_t r) run = true; do { t = r; - while (run && (NODE_type(r) == HLIST_NODE) && (mem[r + 5].b32.s1 != TEX_NULL)) { + while (run && (NODE_type(r) == HLIST_NODE) && (mem(r + 5).b32.s1 != TEX_NULL)) { push_node(l); push_node(r); - l = mem[r + 5].b32.s1; + l = mem(r + 5).b32.s1; r = l; - while (mem[r].b32.s1 != TEX_NULL) + while (mem(r).b32.s1 != TEX_NULL) r = LLIST_link(r); } while (run && (!(is_char_node(r)) && ((NODE_type(r) == INS_NODE) || (NODE_type(r) == MARK_NODE) || (NODE_type(r) == ADJUST_NODE) || (NODE_type(r) == PENALTY_NODE) - || ((NODE_type(r) == DISC_NODE) && (mem[r + 1].b32.s0 == TEX_NULL) - && (mem[r + 1].b32.s1 == TEX_NULL) && (mem[r].b16.s0 == 0)) - || ((NODE_type(r) == MATH_NODE) && (mem[r + 1].b32.s1 == 0)) + || ((NODE_type(r) == DISC_NODE) && (mem(r + 1).b32.s0 == TEX_NULL) + && (mem(r + 1).b32.s1 == TEX_NULL) && (mem(r).b16.s0 == 0)) + || ((NODE_type(r) == MATH_NODE) && (mem(r + 1).b32.s1 == 0)) || ((NODE_type(r) == KERN_NODE) - && ((mem[r + 1].b32.s1 == 0) || (mem[r].b16.s0 == NORMAL))) - || ((NODE_type(r) == GLUE_NODE) && (mem[r + 1].b32.s0 == 0)) - || ((NODE_type(r) == HLIST_NODE) && (mem[r + 1].b32.s1 == 0) && (mem[r + 3].b32.s1 == 0) - && (mem[r + 2].b32.s1 == 0) && (mem[r + 5].b32.s1 == TEX_NULL))))) { + && ((mem(r + 1).b32.s1 == 0) || (mem(r).b16.s0 == NORMAL))) + || ((NODE_type(r) == GLUE_NODE) && (mem(r + 1).b32.s0 == 0)) + || ((NODE_type(r) == HLIST_NODE) && (mem(r + 1).b32.s1 == 0) && (mem(r + 3).b32.s1 == 0) + && (mem(r + 2).b32.s1 == 0) && (mem(r + 5).b32.s1 == TEX_NULL))))) { while ((r == l) && (hlist_stack_level > 0)) { diff --git a/crates/engine_xetex/xetex/xetex-math.c b/crates/engine_xetex/xetex/xetex-math.c index 5d6a923dd..e097f0eb1 100644 --- a/crates/engine_xetex/xetex/xetex-math.c +++ b/crates/engine_xetex/xetex/xetex-math.c @@ -6,6 +6,7 @@ #include "xetex-xetexd.h" #include "xetex-synctex.h" #include "tectonic_bridge_core.h" +#include "xetex_bindings.h" static scaled_t math_x_height(int32_t size_code); @@ -100,7 +101,7 @@ void init_math(void) pop_nest(); if (cur_list.eTeX_aux == TEX_NULL) x = 0; - else if (mem[cur_list.eTeX_aux].b32.s0 >= R_CODE) + else if (mem(cur_list.eTeX_aux).b32.s0 >= R_CODE) x = -1; else x = 1 /*:1519 */ ; @@ -117,39 +118,39 @@ void init_math(void) else p = new_param_glue(GLUE_PAR__left_skip); - mem[p].b32.s1 = j; + mem_ptr(p)->b32.s1 = j; j = new_null_box(); - mem[j + 1].b32.s1 = mem[just_box + 1].b32.s1; - mem[j + 4].b32.s1 = mem[just_box + 4].b32.s1; - mem[j + 5].b32.s1 = p; - mem[j + 5].b16.s0 = mem[just_box + 5].b16.s0; - mem[j + 5].b16.s1 = mem[just_box + 5].b16.s1; + mem_ptr(j + 1)->b32.s1 = mem(just_box + 1).b32.s1; + mem_ptr(j + 4)->b32.s1 = mem(just_box + 4).b32.s1; + mem_ptr(j + 5)->b32.s1 = p; + mem_ptr(j + 5)->b16.s0 = mem(just_box + 5).b16.s0; + mem_ptr(j + 5)->b16.s1 = mem(just_box + 5).b16.s1; BOX_glue_set(j) = BOX_glue_set(just_box); - v = mem[just_box + 4].b32.s1; + v = mem(just_box + 4).b32.s1; if (cur_list.eTeX_aux == TEX_NULL) x = 0; - else if (mem[cur_list.eTeX_aux].b32.s0 >= R_CODE) + else if (mem(cur_list.eTeX_aux).b32.s0 >= R_CODE) x = -1; else x = 1 /*:1519 */ ; if (x >= 0) { - p = mem[just_box + 5].b32.s1; - mem[TEMP_HEAD].b32.s1 = TEX_NULL; + p = mem(just_box + 5).b32.s1; + mem_ptr(TEMP_HEAD)->b32.s1 = TEX_NULL; } else { - v = -(int32_t) v - mem[just_box + 1].b32.s1; + v = -(int32_t) v - mem(just_box + 1).b32.s1; p = new_math(0, BEGIN_L_CODE); - mem[TEMP_HEAD].b32.s1 = p; - just_copy(mem[just_box + 5].b32.s1, p, new_math(0, END_L_CODE)); + mem_ptr(TEMP_HEAD)->b32.s1 = p; + just_copy(mem(just_box + 5).b32.s1, p, new_math(0, END_L_CODE)); cur_dir = RIGHT_TO_LEFT; } - v = v + 2 * font_info[QUAD_CODE + param_base[eqtb[CUR_FONT_LOC].b32.s1]].b32.s1; + v = v + 2 * font_info[QUAD_CODE + param_base[eqtb_ptr(CUR_FONT_LOC)->b32.s1]].b32.s1; if (INTPAR(texxet) > 0) { /*1497: */ temp_ptr = get_avail(); - mem[temp_ptr].b32.s0 = BEFORE; - mem[temp_ptr].b32.s1 = LR_ptr; + mem_ptr(temp_ptr)->b32.s0 = BEFORE; + mem_ptr(temp_ptr)->b32.s1 = LR_ptr; LR_ptr = temp_ptr; } while (p != TEX_NULL) { @@ -161,43 +162,43 @@ void init_math(void) effective_char(true, f, CHAR_NODE_character(p))); goto found; } - switch (mem[p].b16.s1) { + switch (mem(p).b16.s1) { case 0: case 1: case 2: { - d = mem[p + 1].b32.s1; + d = mem(p + 1).b32.s1; goto found; } break; case 6: { - mem[GARBAGE] = mem[p + 1]; - mem[GARBAGE].b32.s1 = mem[p].b32.s1; + set_mem(GARBAGE, mem(p + 1)); + mem_ptr(GARBAGE)->b32.s1 = mem(p).b32.s1; p = GARBAGE; xtx_ligature_present = true; goto reswitch; } break; case 11: - d = mem[p + 1].b32.s1; + d = mem(p + 1).b32.s1; break; case 40: - d = mem[p + 1].b32.s1; + d = mem(p + 1).b32.s1; break; case 9: { - d = mem[p + 1].b32.s1; + d = mem(p + 1).b32.s1; if (INTPAR(texxet) > 0) { /*1525: */ - if (odd(mem[p].b16.s0)) { - if (mem[LR_ptr].b32.s0 == (L_CODE * (mem[p].b16.s0 / L_CODE) + 3)) { + if (odd(mem(p).b16.s0)) { + if (mem(LR_ptr).b32.s0 == (L_CODE * (mem(p).b16.s0 / L_CODE) + 3)) { temp_ptr = LR_ptr; - LR_ptr = mem[temp_ptr].b32.s1; + LR_ptr = mem(temp_ptr).b32.s1; { - mem[temp_ptr].b32.s1 = avail; + mem_ptr(temp_ptr)->b32.s1 = avail; avail = temp_ptr; } - } else if (mem[p].b16.s0 > L_CODE) { + } else if (mem(p).b16.s0 > L_CODE) { w = MAX_HALFWORD; goto done; } @@ -205,16 +206,16 @@ void init_math(void) { temp_ptr = get_avail(); - mem[temp_ptr].b32.s0 = (L_CODE * (mem[p].b16.s0 / L_CODE) + 3); - mem[temp_ptr].b32.s1 = LR_ptr; + mem_ptr(temp_ptr)->b32.s0 = (L_CODE * (mem(p).b16.s0 / L_CODE) + 3); + mem_ptr(temp_ptr)->b32.s1 = LR_ptr; LR_ptr = temp_ptr; } - if ((mem[p].b16.s0 / R_CODE) != cur_dir) { + if ((mem(p).b16.s0 / R_CODE) != cur_dir) { just_reverse(p); p = TEMP_HEAD; } } - } else if (mem[p].b16.s0 >= L_CODE) { + } else if (mem(p).b16.s0 >= L_CODE) { w = MAX_HALFWORD; goto done; } @@ -222,30 +223,30 @@ void init_math(void) break; case 14: { - d = mem[p + 1].b32.s1; - cur_dir = mem[p].b16.s0; + d = mem(p + 1).b32.s1; + cur_dir = mem(p).b16.s0; } break; case 10: { - q = mem[p + 1].b32.s0; - d = mem[q + 1].b32.s1; - if (mem[just_box + 5].b16.s1 == STRETCHING) { - if ((mem[just_box + 5].b16.s0 == mem[q].b16.s1) && (mem[q + 2].b32.s1 != 0)) + q = mem(p + 1).b32.s0; + d = mem(q + 1).b32.s1; + if (mem(just_box + 5).b16.s1 == STRETCHING) { + if ((mem(just_box + 5).b16.s0 == mem(q).b16.s1) && (mem(q + 2).b32.s1 != 0)) v = MAX_HALFWORD; - } else if (mem[just_box + 5].b16.s1 == SHRINKING) { - if ((mem[just_box + 5].b16.s0 == mem[q].b16.s0) && (mem[q + 3].b32.s1 != 0)) + } else if (mem(just_box + 5).b16.s1 == SHRINKING) { + if ((mem(just_box + 5).b16.s0 == mem(q).b16.s0) && (mem(q + 3).b32.s1 != 0)) v = MAX_HALFWORD; } - if (mem[p].b16.s0 >= A_LEADERS) + if (mem(p).b16.s0 >= A_LEADERS) goto found; } break; case 8: - if ((mem[p].b16.s0 == NATIVE_WORD_NODE) || (mem[p].b16.s0 == NATIVE_WORD_NODE_AT) - || (mem[p].b16.s0 == GLYPH_NODE) || (mem[p].b16.s0 == PIC_NODE) - || (mem[p].b16.s0 == PDF_NODE)) { - d = mem[p + 1].b32.s1; + if ((mem(p).b16.s0 == NATIVE_WORD_NODE) || (mem(p).b16.s0 == NATIVE_WORD_NODE_AT) + || (mem(p).b16.s0 == GLYPH_NODE) || (mem(p).b16.s0 == PIC_NODE) + || (mem(p).b16.s0 == PDF_NODE)) { + d = mem(p + 1).b32.s1; goto found; } else d = 0 /*:1398 */ ; @@ -274,9 +275,9 @@ void init_math(void) while (LR_ptr != TEX_NULL) { temp_ptr = LR_ptr; - LR_ptr = mem[temp_ptr].b32.s1; + LR_ptr = mem(temp_ptr).b32.s1; { - mem[temp_ptr].b32.s1 = avail; + mem_ptr(temp_ptr)->b32.s1 = avail; avail = temp_ptr; } } @@ -286,7 +287,7 @@ void init_math(void) } } cur_dir = LEFT_TO_RIGHT; - flush_node_list(mem[TEMP_HEAD].b32.s1); + flush_node_list(mem(TEMP_HEAD).b32.s1); } if (LOCAL(par_shape) == TEX_NULL) { @@ -307,13 +308,13 @@ void init_math(void) } } else { - n = mem[LOCAL(par_shape)].b32.s0; + n = mem(LOCAL(par_shape)).b32.s0; if (cur_list.prev_graf + 2 >= n) p = LOCAL(par_shape) + 2 * n; else p = LOCAL(par_shape) + 2 * (cur_list.prev_graf + 2); - s = mem[p - 1].b32.s1; - l = mem[p].b32.s1; + s = mem(p - 1).b32.s1; + l = mem(p).b32.s1; } push_math(MATH_SHIFT_GROUP); cur_list.mode = MMODE; @@ -369,8 +370,8 @@ void math_limit_switch(void) { if (cur_list.head != cur_list.tail) { - if (mem[cur_list.tail].b16.s1 == OP_NOAD) { - mem[cur_list.tail].b16.s0 = cur_chr; + if (mem(cur_list.tail).b16.s1 == OP_NOAD) { + mem_ptr(cur_list.tail)->b16.s0 = cur_chr; return; } } @@ -428,7 +429,7 @@ scan_delimiter(int32_t p, bool r) } if (cur_val < 0) { - if (file_line_error_style_p) + if (file_line_error_style_p()) print_file_line(); else print_nl_cstr("! "); @@ -445,15 +446,15 @@ scan_delimiter(int32_t p, bool r) } if (cur_val >= 0x40000000) { - mem[p].b16.s3 = ((cur_val % 0x200000) / 0x10000) * 0x100 + (cur_val / 0x200000) % 0x100; - mem[p].b16.s2 = cur_val % 0x10000; - mem[p].b16.s1 = 0; - mem[p].b16.s0 = 0; + mem_ptr(p)->b16.s3 = ((cur_val % 0x200000) / 0x10000) * 0x100 + (cur_val / 0x200000) % 0x100; + mem_ptr(p)->b16.s2 = cur_val % 0x10000; + mem_ptr(p)->b16.s1 = 0; + mem_ptr(p)->b16.s0 = 0; } else { - mem[p].b16.s3 = (cur_val / 0x100000) % 16; - mem[p].b16.s2 = (cur_val / 0x1000) % 0x100; - mem[p].b16.s1 = (cur_val / 0x100) % 16; - mem[p].b16.s0 = cur_val % 0x100; + mem_ptr(p)->b16.s3 = (cur_val / 0x100000) % 16; + mem_ptr(p)->b16.s2 = (cur_val / 0x1000) % 0x100; + mem_ptr(p)->b16.s1 = (cur_val / 0x100) % 16; + mem_ptr(p)->b16.s0 = cur_val % 0x100; } } @@ -461,14 +462,14 @@ scan_delimiter(int32_t p, bool r) void math_radical(void) { { - mem[cur_list.tail].b32.s1 = get_node(RADICAL_NOAD_SIZE); + mem_ptr(cur_list.tail)->b32.s1 = get_node(RADICAL_NOAD_SIZE); cur_list.tail = LLIST_link(cur_list.tail); } - mem[cur_list.tail].b16.s1 = RADICAL_NOAD; - mem[cur_list.tail].b16.s0 = NORMAL; - mem[cur_list.tail + 1].b32 = empty; - mem[cur_list.tail + 3].b32 = empty; - mem[cur_list.tail + 2].b32 = empty; + mem_ptr(cur_list.tail)->b16.s1 = RADICAL_NOAD; + mem_ptr(cur_list.tail)->b16.s0 = NORMAL; + mem_ptr(cur_list.tail + 1)->b32 = empty; + mem_ptr(cur_list.tail + 3)->b32 = empty; + mem_ptr(cur_list.tail + 2)->b32 = empty; scan_delimiter(cur_list.tail + 4, true); scan_math(cur_list.tail + 1); } @@ -490,23 +491,23 @@ void math_ac(void) error(); } { - mem[cur_list.tail].b32.s1 = get_node(ACCENT_NOAD_SIZE); + mem_ptr(cur_list.tail)->b32.s1 = get_node(ACCENT_NOAD_SIZE); cur_list.tail = LLIST_link(cur_list.tail); } - mem[cur_list.tail].b16.s1 = ACCENT_NOAD; - mem[cur_list.tail].b16.s0 = NORMAL; - mem[cur_list.tail + 1].b32 = empty; - mem[cur_list.tail + 3].b32 = empty; - mem[cur_list.tail + 2].b32 = empty; - mem[cur_list.tail + 4].b32.s1 = MATH_CHAR; + mem_ptr(cur_list.tail)->b16.s1 = ACCENT_NOAD; + mem_ptr(cur_list.tail)->b16.s0 = NORMAL; + mem_ptr(cur_list.tail + 1)->b32 = empty; + mem_ptr(cur_list.tail + 3)->b32 = empty; + mem_ptr(cur_list.tail + 2)->b32 = empty; + mem_ptr(cur_list.tail + 4)->b32.s1 = MATH_CHAR; if (cur_chr == 1) { if (scan_keyword("fixed")) - mem[cur_list.tail].b16.s0 = FIXED_ACC; + mem_ptr(cur_list.tail)->b16.s0 = FIXED_ACC; else if (scan_keyword("bottom")) { if (scan_keyword("fixed")) - mem[cur_list.tail].b16.s0 = (BOTTOM_ACC + 1); + mem_ptr(cur_list.tail)->b16.s0 = (BOTTOM_ACC + 1); else - mem[cur_list.tail].b16.s0 = BOTTOM_ACC; + mem_ptr(cur_list.tail)->b16.s0 = BOTTOM_ACC; } scan_math_class_int(); c = set_class(cur_val); @@ -519,21 +520,21 @@ void math_ac(void) scan_fifteen_bit_int(); cur_val = set_class(cur_val / 4096) + set_family((cur_val % 4096) / 256) + (cur_val % 256); } - mem[cur_list.tail + 4].b16.s0 = cur_val % 65536L; + mem_ptr(cur_list.tail + 4)->b16.s0 = cur_val % 65536L; if ((math_class(cur_val) == 7) && ((INTPAR(cur_fam) >= 0) && (INTPAR(cur_fam) < NUMBER_MATH_FAMILIES))) - mem[cur_list.tail + 4].b16.s1 = INTPAR(cur_fam); + mem_ptr(cur_list.tail + 4)->b16.s1 = INTPAR(cur_fam); else - mem[cur_list.tail + 4].b16.s1 = math_fam(cur_val); - mem[cur_list.tail + 4].b16.s1 = mem[cur_list.tail + 4].b16.s1 + (math_char(cur_val) / 65536L) * 256; + mem_ptr(cur_list.tail + 4)->b16.s1 = math_fam(cur_val); + mem_ptr(cur_list.tail + 4)->b16.s1 = mem(cur_list.tail + 4).b16.s1 + (math_char(cur_val) / 65536L) * 256; scan_math(cur_list.tail + 1); } void append_choices(void) { { - mem[cur_list.tail].b32.s1 = new_choice(); + mem_ptr(cur_list.tail)->b32.s1 = new_choice(); cur_list.tail = LLIST_link(cur_list.tail); } save_ptr++; @@ -546,23 +547,23 @@ int32_t fin_mlist(int32_t p) { int32_t q; if (cur_list.aux.b32.s1 != TEX_NULL) { /*1220: */ - mem[cur_list.aux.b32.s1 + 3].b32.s1 = SUB_MLIST; - mem[cur_list.aux.b32.s1 + 3].b32.s0 = mem[cur_list.head].b32.s1; + mem_ptr(cur_list.aux.b32.s1 + 3)->b32.s1 = SUB_MLIST; + mem_ptr(cur_list.aux.b32.s1 + 3)->b32.s0 = mem(cur_list.head).b32.s1; if (p == TEX_NULL) q = cur_list.aux.b32.s1; else { - q = mem[cur_list.aux.b32.s1 + 2].b32.s0; - if ((mem[q].b16.s1 != LEFT_NOAD) || (cur_list.eTeX_aux == TEX_NULL)) + q = mem(cur_list.aux.b32.s1 + 2).b32.s0; + if ((mem(q).b16.s1 != LEFT_NOAD) || (cur_list.eTeX_aux == TEX_NULL)) confusion("right"); - mem[cur_list.aux.b32.s1 + 2].b32.s0 = mem[cur_list.eTeX_aux].b32.s1; - mem[cur_list.eTeX_aux].b32.s1 = cur_list.aux.b32.s1; - mem[cur_list.aux.b32.s1].b32.s1 = p; + mem_ptr(cur_list.aux.b32.s1 + 2)->b32.s0 = mem(cur_list.eTeX_aux).b32.s1; + mem_ptr(cur_list.eTeX_aux)->b32.s1 = cur_list.aux.b32.s1; + mem_ptr(cur_list.aux.b32.s1)->b32.s1 = p; } } else { - mem[cur_list.tail].b32.s1 = p; - q = mem[cur_list.head].b32.s1; + mem_ptr(cur_list.tail)->b32.s1 = p; + q = mem(cur_list.head).b32.s1; } pop_nest(); return q; @@ -575,17 +576,17 @@ void build_choices(void) p = fin_mlist(TEX_NULL); switch (save_stack[save_ptr - 1].b32.s1) { case 0: - mem[cur_list.tail + 1].b32.s0 = p; + mem_ptr(cur_list.tail + 1)->b32.s0 = p; break; case 1: - mem[cur_list.tail + 1].b32.s1 = p; + mem_ptr(cur_list.tail + 1)->b32.s1 = p; break; case 2: - mem[cur_list.tail + 2].b32.s0 = p; + mem_ptr(cur_list.tail + 2)->b32.s0 = p; break; case 3: { - mem[cur_list.tail + 2].b32.s1 = p; + mem_ptr(cur_list.tail + 2)->b32.s1 = p; save_ptr--; return; } @@ -604,15 +605,15 @@ void sub_sup(void) p = TEX_NULL; if (cur_list.tail != cur_list.head) { - if ((mem[cur_list.tail].b16.s1 >= ORD_NOAD) - && (mem[cur_list.tail].b16.s1 < LEFT_NOAD)) { + if ((mem(cur_list.tail).b16.s1 >= ORD_NOAD) + && (mem(cur_list.tail).b16.s1 < LEFT_NOAD)) { p = cur_list.tail + 2 + cur_cmd - 7; - t = mem[p].b32.s1; + t = mem(p).b32.s1; } } if ((p == TEX_NULL) || (t != EMPTY)) { /*1212: */ { - mem[cur_list.tail].b32.s1 = new_noad(); + mem_ptr(cur_list.tail)->b32.s1 = new_noad(); cur_list.tail = LLIST_link(cur_list.tail); } p = cur_list.tail + 2 + cur_cmd - 7; @@ -656,7 +657,7 @@ math_fraction(void) if (c % DELIMITED_CODE == ABOVE_CODE) scan_dimen(false, false, false); - if (file_line_error_style_p) + if (file_line_error_style_p()) print_file_line(); else print_nl_cstr("! "); @@ -668,14 +669,14 @@ math_fraction(void) error(); } else { cur_list.aux.b32.s1 = get_node(FRACTION_NOAD_SIZE); - mem[cur_list.aux.b32.s1].b16.s1 = FRACTION_NOAD; - mem[cur_list.aux.b32.s1].b16.s0 = NORMAL; - mem[cur_list.aux.b32.s1 + 2].b32.s1 = SUB_MLIST; - mem[cur_list.aux.b32.s1 + 2].b32.s0 = mem[cur_list.head].b32.s1; - mem[cur_list.aux.b32.s1 + 3].b32 = empty; - mem[cur_list.aux.b32.s1 + 4].b16 = null_delimiter; - mem[cur_list.aux.b32.s1 + 5].b16 = null_delimiter; - mem[cur_list.head].b32.s1 = TEX_NULL; + mem_ptr(cur_list.aux.b32.s1)->b16.s1 = FRACTION_NOAD; + mem_ptr(cur_list.aux.b32.s1)->b16.s0 = NORMAL; + mem_ptr(cur_list.aux.b32.s1 + 2)->b32.s1 = SUB_MLIST; + mem_ptr(cur_list.aux.b32.s1 + 2)->b32.s0 = mem(cur_list.head).b32.s1; + mem_ptr(cur_list.aux.b32.s1 + 3)->b32 = empty; + mem_ptr(cur_list.aux.b32.s1 + 4)->b16 = null_delimiter; + mem_ptr(cur_list.aux.b32.s1 + 5)->b16 = null_delimiter; + mem_ptr(cur_list.head)->b32.s1 = TEX_NULL; cur_list.tail = cur_list.head; @@ -687,13 +688,13 @@ math_fraction(void) switch (c % DELIMITED_CODE) { case ABOVE_CODE: scan_dimen(false, false, false); - mem[cur_list.aux.b32.s1 + 1].b32.s1 = cur_val; + mem_ptr(cur_list.aux.b32.s1 + 1)->b32.s1 = cur_val; break; case OVER_CODE: - mem[cur_list.aux.b32.s1 + 1].b32.s1 = DEFAULT_CODE; + mem_ptr(cur_list.aux.b32.s1 + 1)->b32.s1 = DEFAULT_CODE; break; case ATOP_CODE: - mem[cur_list.aux.b32.s1 + 1].b32.s1 = 0; + mem_ptr(cur_list.aux.b32.s1 + 1)->b32.s1 = 0; break; } } @@ -731,11 +732,11 @@ void math_left_right(void) } else { p = new_noad(); - mem[p].b16.s1 = t; + mem_ptr(p)->b16.s1 = t; scan_delimiter(p + 1, false); if (t == 1) { - mem[p].b16.s1 = RIGHT_NOAD; - mem[p].b16.s0 = 1; + mem_ptr(p)->b16.s1 = RIGHT_NOAD; + mem_ptr(p)->b16.s0 = 1; } if (t == LEFT_NOAD) q = p; @@ -746,18 +747,18 @@ void math_left_right(void) } if (t != RIGHT_NOAD) { push_math(MATH_LEFT_GROUP); - mem[cur_list.head].b32.s1 = q; + mem_ptr(cur_list.head)->b32.s1 = q; cur_list.tail = p; cur_list.eTeX_aux = p; } else { { - mem[cur_list.tail].b32.s1 = new_noad(); + mem_ptr(cur_list.tail)->b32.s1 = new_noad(); cur_list.tail = LLIST_link(cur_list.tail); } - mem[cur_list.tail].b16.s1 = INNER_NOAD; - mem[cur_list.tail + 1].b32.s1 = SUB_MLIST; - mem[cur_list.tail + 1].b32.s0 = q; + mem_ptr(cur_list.tail)->b16.s1 = INNER_NOAD; + mem_ptr(cur_list.tail + 1)->b32.s1 = SUB_MLIST; + mem_ptr(cur_list.tail + 1)->b32.s0 = q; } } } @@ -776,31 +777,31 @@ app_display(int32_t j, int32_t b, scaled_t d) x = INTPAR(pre_display_direction); if (x == 0) - mem[b + 4].b32.s1 = s + d; + mem_ptr(b + 4)->b32.s1 = s + d; else { z = DIMENPAR(display_width); p = b; if (x > 0) - e = z - d - mem[p + 1].b32.s1; + e = z - d - mem(p + 1).b32.s1; else { e = d; - d = z - e - mem[p + 1].b32.s1; + d = z - e - mem(p + 1).b32.s1; } if (j != TEX_NULL) { b = copy_node_list(j); - mem[b + 3].b32.s1 = mem[p + 3].b32.s1; - mem[b + 2].b32.s1 = mem[p + 2].b32.s1; - s = s - mem[b + 4].b32.s1; + mem_ptr(b + 3)->b32.s1 = mem(p + 3).b32.s1; + mem_ptr(b + 2)->b32.s1 = mem(p + 2).b32.s1; + s = s - mem(b + 4).b32.s1; d = d + s; - e = e + mem[b + 1].b32.s1 - z - s; + e = e + mem(b + 1).b32.s1 - z - s; } - if ((mem[p].b16.s0) == DLIST) + if ((mem(p).b16.s0) == DLIST) q = p; else { - r = mem[p + 5].b32.s1; + r = mem(p + 5).b32.s1; free_node(p, BOX_NODE_SIZE); if (r == TEX_NULL) confusion("LR4"); @@ -815,8 +816,8 @@ app_display(int32_t j, int32_t b, scaled_t d) p = TEX_NULL; q = r; do { - t = mem[r].b32.s1; - mem[r].b32.s1 = p; + t = mem(r).b32.s1; + mem_ptr(r)->b32.s1 = p; p = r; r = t; } while (!(r == TEX_NULL)); @@ -827,49 +828,49 @@ app_display(int32_t j, int32_t b, scaled_t d) t = new_kern(0); } else { - r = mem[b + 5].b32.s1; - t = mem[r].b32.s1; + r = mem(b + 5).b32.s1; + t = mem(r).b32.s1; } u = new_math(0, END_M_CODE); if (NODE_type(t) == GLUE_NODE) { j = new_skip_param(GLUE_PAR__right_skip); - mem[q].b32.s1 = j; - mem[j].b32.s1 = u; - j = mem[t + 1].b32.s0; - mem[temp_ptr].b16.s1 = mem[j].b16.s1; - mem[temp_ptr].b16.s0 = mem[j].b16.s0; - mem[temp_ptr + 1].b32.s1 = e - mem[j + 1].b32.s1; - mem[temp_ptr + 2].b32.s1 = -(int32_t) mem[j + 2].b32.s1; - mem[temp_ptr + 3].b32.s1 = -(int32_t) mem[j + 3].b32.s1; - mem[u].b32.s1 = t; + mem_ptr(q)->b32.s1 = j; + mem_ptr(j)->b32.s1 = u; + j = mem(t + 1).b32.s0; + mem_ptr(temp_ptr)->b16.s1 = mem(j).b16.s1; + mem_ptr(temp_ptr)->b16.s0 = mem(j).b16.s0; + mem_ptr(temp_ptr + 1)->b32.s1 = e - mem(j + 1).b32.s1; + mem_ptr(temp_ptr + 2)->b32.s1 = -(int32_t) mem(j + 2).b32.s1; + mem_ptr(temp_ptr + 3)->b32.s1 = -(int32_t) mem(j + 3).b32.s1; + mem_ptr(u)->b32.s1 = t; } else { - mem[t + 1].b32.s1 = e; - mem[t].b32.s1 = u; - mem[q].b32.s1 = t; + mem_ptr(t + 1)->b32.s1 = e; + mem_ptr(t)->b32.s1 = u; + mem_ptr(q)->b32.s1 = t; } u = new_math(0, BEGIN_M_CODE); if (NODE_type(r) == GLUE_NODE) { j = new_skip_param(GLUE_PAR__left_skip); - mem[u].b32.s1 = j; - mem[j].b32.s1 = p; - j = mem[r + 1].b32.s0; - mem[temp_ptr].b16.s1 = mem[j].b16.s1; - mem[temp_ptr].b16.s0 = mem[j].b16.s0; - mem[temp_ptr + 1].b32.s1 = d - mem[j + 1].b32.s1; - mem[temp_ptr + 2].b32.s1 = -(int32_t) mem[j + 2].b32.s1; - mem[temp_ptr + 3].b32.s1 = -(int32_t) mem[j + 3].b32.s1; - mem[r].b32.s1 = u; + mem_ptr(u)->b32.s1 = j; + mem_ptr(j)->b32.s1 = p; + j = mem(r + 1).b32.s0; + mem_ptr(temp_ptr)->b16.s1 = mem(j).b16.s1; + mem_ptr(temp_ptr)->b16.s0 = mem(j).b16.s0; + mem_ptr(temp_ptr + 1)->b32.s1 = d - mem(j + 1).b32.s1; + mem_ptr(temp_ptr + 2)->b32.s1 = -(int32_t) mem(j + 2).b32.s1; + mem_ptr(temp_ptr + 3)->b32.s1 = -(int32_t) mem(j + 3).b32.s1; + mem_ptr(r)->b32.s1 = u; } else { - mem[r + 1].b32.s1 = d; - mem[r].b32.s1 = p; - mem[u].b32.s1 = r; + mem_ptr(r + 1)->b32.s1 = d; + mem_ptr(r)->b32.s1 = p; + mem_ptr(u)->b32.s1 = r; if (j == TEX_NULL) { b = hpack(u, 0, ADDITIONAL); - mem[b + 4].b32.s1 = s; + mem_ptr(b + 4)->b32.s1 = s; } else - mem[b + 5].b32.s1 = u; + mem_ptr(b + 5)->b32.s1 = u; } } append_to_vlist(b); @@ -968,8 +969,8 @@ void after_math(void) cur_style = TEXT_STYLE; mlist_penalties = false; mlist_to_hlist(); - a = hpack(mem[TEMP_HEAD].b32.s1, 0, ADDITIONAL); - mem[a].b16.s0 = DLIST; + a = hpack(mem(TEMP_HEAD).b32.s1, 0, ADDITIONAL); + mem_ptr(a)->b16.s0 = DLIST; unsave(); save_ptr--; if (save_stack[save_ptr + 0].b32.s1 == 1) @@ -1032,18 +1033,18 @@ void after_math(void) a = TEX_NULL; if (m < 0) { /*1231: */ { - mem[cur_list.tail].b32.s1 = new_math(DIMENPAR(math_surround), BEFORE); + mem_ptr(cur_list.tail)->b32.s1 = new_math(DIMENPAR(math_surround), BEFORE); cur_list.tail = LLIST_link(cur_list.tail); } cur_mlist = p; cur_style = TEXT_STYLE; mlist_penalties = (cur_list.mode > 0); mlist_to_hlist(); - mem[cur_list.tail].b32.s1 = mem[TEMP_HEAD].b32.s1; - while (mem[cur_list.tail].b32.s1 != TEX_NULL) + mem_ptr(cur_list.tail)->b32.s1 = mem(TEMP_HEAD).b32.s1; + while (mem(cur_list.tail).b32.s1 != TEX_NULL) cur_list.tail = LLIST_link(cur_list.tail); { - mem[cur_list.tail].b32.s1 = new_math(DIMENPAR(math_surround), AFTER); + mem_ptr(cur_list.tail)->b32.s1 = new_math(DIMENPAR(math_surround), AFTER); cur_list.tail = LLIST_link(cur_list.tail); } cur_list.aux.b32.s0 = 1000; @@ -1072,16 +1073,16 @@ void after_math(void) cur_style = DISPLAY_STYLE; mlist_penalties = false; mlist_to_hlist(); - p = mem[TEMP_HEAD].b32.s1; + p = mem(TEMP_HEAD).b32.s1; adjust_tail = ADJUST_HEAD; pre_adjust_tail = PRE_ADJUST_HEAD; b = hpack(p, 0, ADDITIONAL); - p = mem[b + 5].b32.s1; + p = mem(b + 5).b32.s1; t = adjust_tail; adjust_tail = TEX_NULL; pre_t = pre_adjust_tail; pre_adjust_tail = TEX_NULL; - w = mem[b + 1].b32.s1; + w = mem(b + 1).b32.s1; z = DIMENPAR(display_width); s = DIMENPAR(display_indent); if (INTPAR(pre_display_direction) < 0) @@ -1091,7 +1092,7 @@ void after_math(void) q = 0; } else { - e = mem[a + 1].b32.s1; + e = mem(a + 1).b32.s1; q = e + math_quad(TEXT_SIZE); } if (w + q > z) { /*1236: */ @@ -1108,9 +1109,9 @@ void after_math(void) b = hpack(p, z, EXACTLY); } } - w = mem[b + 1].b32.s1; + w = mem(b + 1).b32.s1; } - mem[b].b16.s0 = DLIST; + mem_ptr(b)->b16.s0 = DLIST; d = half(z - w); if ((e > 0) && (d < 2 * e)) { d = half(z - w - e); @@ -1124,7 +1125,7 @@ void after_math(void) } } { - mem[cur_list.tail].b32.s1 = new_penalty(INTPAR(pre_display_penalty)); + mem_ptr(cur_list.tail)->b32.s1 = new_penalty(INTPAR(pre_display_penalty)); cur_list.tail = LLIST_link(cur_list.tail); } if ((d + s <= DIMENPAR(pre_display_size)) || l) { @@ -1137,51 +1138,51 @@ void after_math(void) if (l && (e == 0)) { app_display(j, a, 0); { - mem[cur_list.tail].b32.s1 = new_penalty(INF_PENALTY); + mem_ptr(cur_list.tail)->b32.s1 = new_penalty(INF_PENALTY); cur_list.tail = LLIST_link(cur_list.tail); } } else { - mem[cur_list.tail].b32.s1 = new_param_glue(g1); + mem_ptr(cur_list.tail)->b32.s1 = new_param_glue(g1); cur_list.tail = LLIST_link(cur_list.tail); } if (e != 0) { r = new_kern(z - w - e - d); if (l) { - mem[a].b32.s1 = r; - mem[r].b32.s1 = b; + mem_ptr(a)->b32.s1 = r; + mem_ptr(r)->b32.s1 = b; b = a; d = 0; } else { - mem[b].b32.s1 = r; - mem[r].b32.s1 = a; + mem_ptr(b)->b32.s1 = r; + mem_ptr(r)->b32.s1 = a; } b = hpack(b, 0, ADDITIONAL); } app_display(j, b, d); if ((a != TEX_NULL) && (e == 0) && !l) { { - mem[cur_list.tail].b32.s1 = new_penalty(INF_PENALTY); + mem_ptr(cur_list.tail)->b32.s1 = new_penalty(INF_PENALTY); cur_list.tail = LLIST_link(cur_list.tail); } - app_display(j, a, z - mem[a + 1].b32.s1); + app_display(j, a, z - mem(a + 1).b32.s1); g2 = 0; } if (t != ADJUST_HEAD) { - mem[cur_list.tail].b32.s1 = mem[ADJUST_HEAD].b32.s1; + mem_ptr(cur_list.tail)->b32.s1 = mem(ADJUST_HEAD).b32.s1; cur_list.tail = t; } if (pre_t != PRE_ADJUST_HEAD) { - mem[cur_list.tail].b32.s1 = mem[PRE_ADJUST_HEAD].b32.s1; + mem_ptr(cur_list.tail)->b32.s1 = mem(PRE_ADJUST_HEAD).b32.s1; cur_list.tail = pre_t; } { - mem[cur_list.tail].b32.s1 = new_penalty(INTPAR(post_display_penalty)); + mem_ptr(cur_list.tail)->b32.s1 = new_penalty(INTPAR(post_display_penalty)); cur_list.tail = LLIST_link(cur_list.tail); } if (g2 > 0) { - mem[cur_list.tail].b32.s1 = new_param_glue(g2); + mem_ptr(cur_list.tail)->b32.s1 = new_param_glue(g2); cur_list.tail = LLIST_link(cur_list.tail); } flush_node_list(j); @@ -1559,8 +1560,8 @@ fraction_rule(scaled_t t) { int32_t p; p = new_rule(); - mem[p + 3].b32.s1 = t; - mem[p + 2].b32.s1 = 0; + mem_ptr(p + 3)->b32.s1 = t; + mem_ptr(p + 2)->b32.s1 = 0; return p; } @@ -1570,11 +1571,11 @@ overbar(int32_t b, scaled_t k, scaled_t t) { int32_t p, q; p = new_kern(k); - mem[p].b32.s1 = b; + mem_ptr(p)->b32.s1 = b; q = fraction_rule(t); - mem[q].b32.s1 = p; + mem_ptr(q)->b32.s1 = p; p = new_kern(t); - mem[p].b32.s1 = q; + mem_ptr(p)->b32.s1 = q; return vpackage(p, 0, ADDITIONAL, MAX_HALFWORD); } @@ -1586,23 +1587,23 @@ math_glue(int32_t g, scaled_t m) int32_t n; scaled_t f; n = x_over_n(m, 65536L); - f = tex_remainder; + f = tex_remainder(); if (f < 0) { n--; f = f + 65536L; } p = get_node(GLUE_SPEC_SIZE); - mem[p + 1].b32.s1 = mult_and_add(n, mem[g + 1].b32.s1, xn_over_d(mem[g + 1].b32.s1, f, 65536L), MAX_HALFWORD); - mem[p].b16.s1 = mem[g].b16.s1; - if (mem[p].b16.s1 == NORMAL) - mem[p + 2].b32.s1 = mult_and_add(n, mem[g + 2].b32.s1, xn_over_d(mem[g + 2].b32.s1, f, 65536L), MAX_HALFWORD); + mem_ptr(p + 1)->b32.s1 = mult_and_add(n, mem(g + 1).b32.s1, xn_over_d(mem(g + 1).b32.s1, f, 65536L), MAX_HALFWORD); + mem_ptr(p)->b16.s1 = mem(g).b16.s1; + if (mem(p).b16.s1 == NORMAL) + mem_ptr(p + 2)->b32.s1 = mult_and_add(n, mem(g + 2).b32.s1, xn_over_d(mem(g + 2).b32.s1, f, 65536L), MAX_HALFWORD); else - mem[p + 2].b32.s1 = mem[g + 2].b32.s1; - mem[p].b16.s0 = mem[g].b16.s0; + mem_ptr(p + 2)->b32.s1 = mem(g + 2).b32.s1; + mem_ptr(p)->b16.s0 = mem(g).b16.s0; if (GLUE_SPEC_shrink_order(p) == NORMAL) - mem[p + 3].b32.s1 = mult_and_add(n, mem[g + 3].b32.s1, xn_over_d(mem[g + 3].b32.s1, f, 65536L), MAX_HALFWORD); + mem_ptr(p + 3)->b32.s1 = mult_and_add(n, mem(g + 3).b32.s1, xn_over_d(mem(g + 3).b32.s1, f, 65536L), MAX_HALFWORD); else - mem[p + 3].b32.s1 = mem[g + 3].b32.s1; + mem_ptr(p + 3)->b32.s1 = mem(g + 3).b32.s1; return p; } @@ -1612,14 +1613,14 @@ math_kern(int32_t p, scaled_t m) { int32_t n; scaled_t f; - if (mem[p].b16.s0 == MU_GLUE) { + if (mem(p).b16.s0 == MU_GLUE) { n = x_over_n(m, 65536L); - f = tex_remainder; + f = tex_remainder(); if (f < 0) { n--; f = f + 65536L; } - mem[p + 1].b32.s1 = mult_and_add(n, mem[p + 1].b32.s1, xn_over_d(mem[p + 1].b32.s1, f, 65536L), MAX_HALFWORD); + mem_ptr(p + 1)->b32.s1 = mult_and_add(n, mem(p + 1).b32.s1, xn_over_d(mem(p + 1).b32.s1, f, 65536L), MAX_HALFWORD); NODE_subtype(p) = EXPLICIT; } } @@ -1628,9 +1629,9 @@ math_kern(int32_t p, scaled_t m) void flush_math(void) { - flush_node_list(mem[cur_list.head].b32.s1); + flush_node_list(mem(cur_list.head).b32.s1); flush_node_list(cur_list.aux.b32.s1); - mem[cur_list.head].b32.s1 = TEX_NULL; + mem_ptr(cur_list.head)->b32.s1 = TEX_NULL; cur_list.tail = cur_list.head; cur_list.aux.b32.s1 = TEX_NULL; } @@ -1643,18 +1644,18 @@ clean_box(int32_t p, small_number s) small_number save_style; int32_t x; int32_t r; - switch (mem[p].b32.s1) { + switch (mem(p).b32.s1) { case 1: { cur_mlist = new_noad(); - mem[cur_mlist + 1] = mem[p]; + set_mem(cur_mlist + 1, mem(p)); } break; case 2: - q = mem[p].b32.s0; + q = mem(p).b32.s0; goto found; case 3: - cur_mlist = mem[p].b32.s0; + cur_mlist = mem(p).b32.s0; break; default: q = new_null_box(); @@ -1664,7 +1665,7 @@ clean_box(int32_t p, small_number s) cur_style = s; mlist_penalties = false; mlist_to_hlist(); - q = mem[TEMP_HEAD].b32.s1; + q = mem(TEMP_HEAD).b32.s1; cur_style = save_style; { if (cur_style < SCRIPT_STYLE) @@ -1676,22 +1677,22 @@ clean_box(int32_t p, small_number s) found: if ((is_char_node(q)) || (q == TEX_NULL)) x = hpack(q, 0, ADDITIONAL); - else if ((mem[q].b32.s1 == TEX_NULL) && (NODE_type(q) <= VLIST_NODE) && (mem[q + 4].b32.s1 == 0)) + else if ((mem(q).b32.s1 == TEX_NULL) && (NODE_type(q) <= VLIST_NODE) && (mem(q + 4).b32.s1 == 0)) x = q; else x = hpack(q, 0, ADDITIONAL); - q = mem[x + 5].b32.s1; + q = mem(x + 5).b32.s1; if ((is_char_node(q))) { - r = mem[q].b32.s1; + r = mem(q).b32.s1; if (r != TEX_NULL) { - if (mem[r].b32.s1 == TEX_NULL) { + if (mem(r).b32.s1 == TEX_NULL) { if (!(is_char_node(r))) { if (NODE_type(r) == KERN_NODE) { free_node(r, MEDIUM_NODE_SIZE); - mem[q].b32.s1 = TEX_NULL; + mem_ptr(q)->b32.s1 = TEX_NULL; } } } @@ -1704,14 +1705,14 @@ clean_box(int32_t p, small_number s) static void fetch(int32_t a) { - cur_c = (unsigned short) mem[a].b16.s0; - cur_f = MATH_FONT((mem[a].b16.s1 % 256) + cur_size); - cur_c = cur_c + (mem[a].b16.s1 / 256) * 65536L; + cur_c = (unsigned short) mem(a).b16.s0; + cur_f = MATH_FONT((mem(a).b16.s1 % 256) + cur_size); + cur_c = cur_c + (mem(a).b16.s1 / 256) * 65536L; if (cur_f == FONT_BASE) { /*749: */ error_here_with_diagnostic(""); print_size(cur_size); print_char(' '); - print_int((mem[a].b16.s1 % 256)); + print_int((mem(a).b16.s1 % 256)); print_cstr(" is undefined (character "); print(cur_c); print_char(')'); @@ -1725,7 +1726,7 @@ fetch(int32_t a) } error(); cur_i = null_character; - mem[a].b32.s1 = EMPTY; + mem_ptr(a)->b32.s1 = EMPTY; } else if (((font_area[cur_f] == AAT_FONT_FLAG) || (font_area[cur_f] == OTGR_FONT_FLAG))) { cur_i = null_character; } else { @@ -1736,7 +1737,7 @@ fetch(int32_t a) cur_i = null_character; if (!((cur_i.s3 > 0))) { char_warning(cur_f, cur_c); - mem[a].b32.s1 = EMPTY; + mem_ptr(a)->b32.s1 = EMPTY; cur_i = null_character; } } @@ -1746,9 +1747,9 @@ fetch(int32_t a) static void make_over(int32_t q) { - mem[q + 1].b32.s0 = + mem_ptr(q + 1)->b32.s0 = overbar(clean_box(q + 1, 2 * (cur_style / 2) + 1), 3 * default_rule_thickness(), default_rule_thickness()); - mem[q + 1].b32.s1 = SUB_BOX; + mem_ptr(q + 1)->b32.s1 = SUB_BOX; } @@ -1759,14 +1760,14 @@ make_under(int32_t q) scaled_t delta; x = clean_box(q + 1, cur_style); p = new_kern(3 * default_rule_thickness()); - mem[x].b32.s1 = p; - mem[p].b32.s1 = fraction_rule(default_rule_thickness()); + mem_ptr(x)->b32.s1 = p; + mem_ptr(p)->b32.s1 = fraction_rule(default_rule_thickness()); y = vpackage(x, 0, ADDITIONAL, MAX_HALFWORD); - delta = mem[y + 3].b32.s1 + mem[y + 2].b32.s1 + default_rule_thickness(); - mem[y + 3].b32.s1 = mem[x + 3].b32.s1; - mem[y + 2].b32.s1 = delta - mem[y + 3].b32.s1; - mem[q + 1].b32.s0 = y; - mem[q + 1].b32.s1 = SUB_BOX; + delta = mem(y + 3).b32.s1 + mem(y + 2).b32.s1 + default_rule_thickness(); + mem_ptr(y + 3)->b32.s1 = mem(x + 3).b32.s1; + mem_ptr(y + 2)->b32.s1 = delta - mem(y + 3).b32.s1; + mem_ptr(q + 1)->b32.s0 = y; + mem_ptr(q + 1)->b32.s1 = SUB_BOX; } @@ -1775,12 +1776,12 @@ make_vcenter(int32_t q) { int32_t v; scaled_t delta; - v = mem[q + 1].b32.s0; + v = mem(q + 1).b32.s0; if (NODE_type(v) != VLIST_NODE) confusion("vcenter"); - delta = mem[v + 3].b32.s1 + mem[v + 2].b32.s1; - mem[v + 3].b32.s1 = axis_height(cur_size) + half(delta); - mem[v + 2].b32.s1 = delta - mem[v + 3].b32.s1; + delta = mem(v + 3).b32.s1 + mem(v + 2).b32.s1; + mem_ptr(v + 3)->b32.s1 = axis_height(cur_size) + half(delta); + mem_ptr(v + 2)->b32.s1 = delta - mem(v + 3).b32.s1; } @@ -1792,7 +1793,7 @@ make_radical(int32_t q) scaled_t rule_thickness; scaled_t delta, clr; - f = MATH_FONT((mem[q + 4].b16.s3 % 256) + cur_size); + f = MATH_FONT((mem(q + 4).b16.s3 % 256) + cur_size); if (((font_area[f] == OTGR_FONT_FLAG) && (isOpenTypeMathFont(font_layout_engine[f])))) rule_thickness = get_ot_math_constant(f, RADICALRULETHICKNESS); else @@ -1813,18 +1814,18 @@ make_radical(int32_t q) clr = clr + (abs(clr) / 4); } } - y = var_delimiter(q + 4, cur_size, mem[x + 3].b32.s1 + mem[x + 2].b32.s1 + clr + rule_thickness); + y = var_delimiter(q + 4, cur_size, mem(x + 3).b32.s1 + mem(x + 2).b32.s1 + clr + rule_thickness); if (((font_area[f] == OTGR_FONT_FLAG) && (isOpenTypeMathFont(font_layout_engine[f])))) { - mem[y + 2].b32.s1 = mem[y + 3].b32.s1 + mem[y + 2].b32.s1 - rule_thickness; - mem[y + 3].b32.s1 = rule_thickness; + mem_ptr(y + 2)->b32.s1 = mem(y + 3).b32.s1 + mem(y + 2).b32.s1 - rule_thickness; + mem_ptr(y + 3)->b32.s1 = rule_thickness; } - delta = mem[y + 2].b32.s1 - (mem[x + 3].b32.s1 + mem[x + 2].b32.s1 + clr); + delta = mem(y + 2).b32.s1 - (mem(x + 3).b32.s1 + mem(x + 2).b32.s1 + clr); if (delta > 0) clr = clr + half(delta); - mem[y + 4].b32.s1 = -(int32_t) (mem[x + 3].b32.s1 + clr); - mem[y].b32.s1 = overbar(x, clr, mem[y + 3].b32.s1); - mem[q + 1].b32.s0 = hpack(y, 0, ADDITIONAL); - mem[q + 1].b32.s1 = SUB_BOX; + mem_ptr(y + 4)->b32.s1 = -(int32_t) (mem(x + 3).b32.s1 + clr); + mem_ptr(y)->b32.s1 = overbar(x, clr, mem(y + 3).b32.s1); + mem_ptr(q + 1)->b32.s0 = hpack(y, 0, ADDITIONAL); + mem_ptr(q + 1)->b32.s1 = SUB_BOX; } @@ -1833,16 +1834,16 @@ compute_ot_math_accent_pos(int32_t p) { int32_t q, r; scaled_t s, g; - if (mem[p + 1].b32.s1 == MATH_CHAR) { + if (mem(p + 1).b32.s1 == MATH_CHAR) { fetch(p + 1); q = new_native_character(cur_f, cur_c); g = get_native_glyph(q, 0); s = get_ot_math_accent_pos(cur_f, g); } else { - if (mem[p + 1].b32.s1 == SUB_MLIST) { - r = mem[p + 1].b32.s0; - if ((r != TEX_NULL) && (mem[r].b16.s1 == ACCENT_NOAD)) + if (mem(p + 1).b32.s1 == SUB_MLIST) { + r = mem(p + 1).b32.s0; + if ((r != TEX_NULL) && (mem(r).b16.s1 == ACCENT_NOAD)) s = compute_ot_math_accent_pos(r); else s = TEX_INFINITY; @@ -1872,19 +1873,19 @@ make_math_accent(int32_t q) if (((font_area[cur_f] == AAT_FONT_FLAG) || (font_area[cur_f] == OTGR_FONT_FLAG))) { c = cur_c; f = cur_f; - if (!((mem[q].b16.s0 == BOTTOM_ACC) || (mem[q].b16.s0 == (BOTTOM_ACC + 1)))) + if (!((mem(q).b16.s0 == BOTTOM_ACC) || (mem(q).b16.s0 == (BOTTOM_ACC + 1)))) s = compute_ot_math_accent_pos(q); else s = 0; x = clean_box(q + 1, 2 * (cur_style / 2) + 1); - w = mem[x + 1].b32.s1; - h = mem[x + 3].b32.s1; + w = mem(x + 1).b32.s1; + h = mem(x + 3).b32.s1; } else if ((cur_i.s3 > 0)) { i = cur_i; c = cur_c; f = cur_f; s = 0; - if (mem[q + 1].b32.s1 == MATH_CHAR) { + if (mem(q + 1).b32.s1 == MATH_CHAR) { fetch(q + 1); if (((cur_i.s1) % 4) == LIG_TAG) { a = lig_kern_base[cur_f] + cur_i.s0; @@ -1912,8 +1913,8 @@ make_math_accent(int32_t q) } done1: x = clean_box(q + 1, 2 * (cur_style / 2) + 1); - w = mem[x + 1].b32.s1; - h = mem[x + 3].b32.s1; + w = mem(x + 1).b32.s1; + h = mem(x + 3).b32.s1; while (true) { if (((i.s1) % 4) != LIST_TAG) @@ -1933,7 +1934,7 @@ make_math_accent(int32_t q) if (x != TEX_NULL) { if (((font_area[f] == OTGR_FONT_FLAG) && (isOpenTypeMathFont(font_layout_engine[f])))) { - if (((mem[q].b16.s0 == BOTTOM_ACC) || (mem[q].b16.s0 == (BOTTOM_ACC + 1)))) + if (((mem(q).b16.s0 == BOTTOM_ACC) || (mem(q).b16.s0 == (BOTTOM_ACC + 1)))) delta = 0; else if (h < get_ot_math_constant(f, ACCENTBASEHEIGHT)) delta = h; @@ -1943,43 +1944,43 @@ make_math_accent(int32_t q) delta = h; else delta = font_info[X_HEIGHT_CODE + param_base[f]].b32.s1; - if ((mem[q + 2].b32.s1 != EMPTY) || (mem[q + 3].b32.s1 != EMPTY)) { + if ((mem(q + 2).b32.s1 != EMPTY) || (mem(q + 3).b32.s1 != EMPTY)) { - if (mem[q + 1].b32.s1 == MATH_CHAR) { /*769: */ + if (mem(q + 1).b32.s1 == MATH_CHAR) { /*769: */ flush_node_list(x); x = new_noad(); - mem[x + 1] = mem[q + 1]; - mem[x + 2] = mem[q + 2]; - mem[x + 3] = mem[q + 3]; - mem[q + 2].b32 = empty; - mem[q + 3].b32 = empty; - mem[q + 1].b32.s1 = SUB_MLIST; - mem[q + 1].b32.s0 = x; + set_mem(x + 1, mem(q + 1)); + set_mem(x + 2, mem(q + 2)); + set_mem(x + 3, mem(q + 3)); + mem_ptr(q + 2)->b32 = empty; + mem_ptr(q + 3)->b32 = empty; + mem_ptr(q + 1)->b32.s1 = SUB_MLIST; + mem_ptr(q + 1)->b32.s0 = x; x = clean_box(q + 1, cur_style); - delta = delta + mem[x + 3].b32.s1 - h; - h = mem[x + 3].b32.s1; + delta = delta + mem(x + 3).b32.s1 - h; + h = mem(x + 3).b32.s1; } } y = char_box(f, c); if (((font_area[f] == AAT_FONT_FLAG) || (font_area[f] == OTGR_FONT_FLAG))) { p = get_node(GLYPH_NODE_SIZE); NODE_type(p) = WHATSIT_NODE; - mem[p].b16.s0 = GLYPH_NODE; - mem[p + 4].b16.s2 = f; - mem[p + 4].b16.s1 = get_native_glyph(mem[y + 5].b32.s1, 0); + mem_ptr(p)->b16.s0 = GLYPH_NODE; + mem_ptr(p + 4)->b16.s2 = f; + mem_ptr(p + 4)->b16.s1 = get_native_glyph(mem(y + 5).b32.s1, 0); set_native_glyph_metrics(p, 1); - free_node(mem[y + 5].b32.s1, mem[mem[y + 5].b32.s1 + 4].b16.s3); - mem[y + 5].b32.s1 = p; - if (odd(mem[q].b16.s0)) + free_node(mem(y + 5).b32.s1, mem(mem(y + 5).b32.s1 + 4).b16.s3); + mem_ptr(y + 5)->b32.s1 = p; + if (odd(mem(q).b16.s0)) set_native_glyph_metrics(p, 1); else { - c = mem[p + 4].b16.s1; + c = mem(p + 4).b16.s1; a = 0; do { g = get_ot_math_variant(f, c, a, &w2, 1); if ((w2 > 0) && (w2 <= w)) { - mem[p + 4].b16.s1 = g; + mem_ptr(p + 4)->b16.s1 = g; set_native_glyph_metrics(p, 1); a++; } @@ -1989,54 +1990,54 @@ make_math_accent(int32_t q) if (ot_assembly_ptr != NULL) { free_node(p, GLYPH_NODE_SIZE); p = build_opentype_assembly(f, ot_assembly_ptr, w, 1); - mem[y + 5].b32.s1 = p; + mem_ptr(y + 5)->b32.s1 = p; goto found; } } else set_native_glyph_metrics(p, 1); } found: - mem[y + 1].b32.s1 = mem[p + 1].b32.s1; - mem[y + 3].b32.s1 = mem[p + 3].b32.s1; - mem[y + 2].b32.s1 = mem[p + 2].b32.s1; - if (((mem[q].b16.s0 == BOTTOM_ACC) || (mem[q].b16.s0 == (BOTTOM_ACC + 1)))) { - if (mem[y + 3].b32.s1 < 0) - mem[y + 3].b32.s1 = 0; - } else if (mem[y + 2].b32.s1 < 0) - mem[y + 2].b32.s1 = 0; + mem_ptr(y + 1)->b32.s1 = mem(p + 1).b32.s1; + mem_ptr(y + 3)->b32.s1 = mem(p + 3).b32.s1; + mem_ptr(y + 2)->b32.s1 = mem(p + 2).b32.s1; + if (((mem(q).b16.s0 == BOTTOM_ACC) || (mem(q).b16.s0 == (BOTTOM_ACC + 1)))) { + if (mem(y + 3).b32.s1 < 0) + mem_ptr(y + 3)->b32.s1 = 0; + } else if (mem(y + 2).b32.s1 < 0) + mem_ptr(y + 2)->b32.s1 = 0; if ((((p) != TEX_NULL && (!(is_char_node(p))) && (NODE_type(p) == WHATSIT_NODE) - && (mem[p].b16.s0 == GLYPH_NODE)))) { - sa = get_ot_math_accent_pos(f, mem[p + 4].b16.s1); + && (mem(p).b16.s0 == GLYPH_NODE)))) { + sa = get_ot_math_accent_pos(f, mem(p + 4).b16.s1); if (sa == TEX_INFINITY) - sa = half(mem[y + 1].b32.s1); + sa = half(mem(y + 1).b32.s1); } else - sa = half(mem[y + 1].b32.s1); - if (((mem[q].b16.s0 == BOTTOM_ACC) || (mem[q].b16.s0 == (BOTTOM_ACC + 1))) || (s == TEX_INFINITY)) + sa = half(mem(y + 1).b32.s1); + if (((mem(q).b16.s0 == BOTTOM_ACC) || (mem(q).b16.s0 == (BOTTOM_ACC + 1))) || (s == TEX_INFINITY)) s = half(w); - mem[y + 4].b32.s1 = s - sa; + mem_ptr(y + 4)->b32.s1 = s - sa; } else - mem[y + 4].b32.s1 = s + half(w - mem[y + 1].b32.s1); - mem[y + 1].b32.s1 = 0; - if (((mem[q].b16.s0 == BOTTOM_ACC) || (mem[q].b16.s0 == (BOTTOM_ACC + 1)))) { - mem[x].b32.s1 = y; + mem_ptr(y + 4)->b32.s1 = s + half(w - mem(y + 1).b32.s1); + mem_ptr(y + 1)->b32.s1 = 0; + if (((mem(q).b16.s0 == BOTTOM_ACC) || (mem(q).b16.s0 == (BOTTOM_ACC + 1)))) { + mem_ptr(x)->b32.s1 = y; y = vpackage(x, 0, ADDITIONAL, MAX_HALFWORD); - mem[y + 4].b32.s1 = -(int32_t) (h - mem[y + 3].b32.s1); + mem_ptr(y + 4)->b32.s1 = -(int32_t) (h - mem(y + 3).b32.s1); } else { p = new_kern(-(int32_t) delta); - mem[p].b32.s1 = x; - mem[y].b32.s1 = p; + mem_ptr(p)->b32.s1 = x; + mem_ptr(y)->b32.s1 = p; y = vpackage(y, 0, ADDITIONAL, MAX_HALFWORD); - if (mem[y + 3].b32.s1 < h) { /*765: */ - p = new_kern(h - mem[y + 3].b32.s1); - mem[p].b32.s1 = mem[y + 5].b32.s1; - mem[y + 5].b32.s1 = p; - mem[y + 3].b32.s1 = h; + if (mem(y + 3).b32.s1 < h) { /*765: */ + p = new_kern(h - mem(y + 3).b32.s1); + mem_ptr(p)->b32.s1 = mem(y + 5).b32.s1; + mem_ptr(y + 5)->b32.s1 = p; + mem_ptr(y + 3)->b32.s1 = h; } } - mem[y + 1].b32.s1 = mem[x + 1].b32.s1; - mem[q + 1].b32.s0 = y; - mem[q + 1].b32.s1 = SUB_BOX; + mem_ptr(y + 1)->b32.s1 = mem(x + 1).b32.s1; + mem_ptr(q + 1)->b32.s0 = y; + mem_ptr(q + 1)->b32.s1 = SUB_BOX; } free_ot_assembly(ot_assembly_ptr); @@ -2049,29 +2050,29 @@ make_fraction(int32_t q) int32_t p, v, x, y, z; scaled_t delta, delta1, delta2, shift_up, shift_down, clr; - if (mem[q + 1].b32.s1 == DEFAULT_CODE) - mem[q + 1].b32.s1 = default_rule_thickness(); + if (mem(q + 1).b32.s1 == DEFAULT_CODE) + mem_ptr(q + 1)->b32.s1 = default_rule_thickness(); x = clean_box(q + 2, cur_style + 2 - 2 * (cur_style / 6)); z = clean_box(q + 3, 2 * (cur_style / 2) + 3 - 2 * (cur_style / 6)); - if (mem[x + 1].b32.s1 < mem[z + 1].b32.s1) - x = rebox(x, mem[z + 1].b32.s1); + if (mem(x + 1).b32.s1 < mem(z + 1).b32.s1) + x = rebox(x, mem(z + 1).b32.s1); else - z = rebox(z, mem[x + 1].b32.s1); + z = rebox(z, mem(x + 1).b32.s1); if (cur_style < TEXT_STYLE) { shift_up = num1(cur_size); shift_down = denom1(cur_size); } else { shift_down = denom2(cur_size); - if (mem[q + 1].b32.s1 != 0) + if (mem(q + 1).b32.s1 != 0) shift_up = num2(cur_size); else shift_up = num3(cur_size); } - if (mem[q + 1].b32.s1 == 0) { /*772:*/ + if (mem(q + 1).b32.s1 == 0) { /*772:*/ if (font_area[cur_f] == OTGR_FONT_FLAG && isOpenTypeMathFont(font_layout_engine[cur_f])) { if (cur_style < TEXT_STYLE) clr = get_ot_math_constant(cur_f, STACKDISPLAYSTYLEGAPMIN); @@ -2084,7 +2085,7 @@ make_fraction(int32_t q) clr = 3 * default_rule_thickness(); } - delta = half(clr - ((shift_up - mem[x + 2].b32.s1) - (mem[z + 3].b32.s1 - shift_down))); + delta = half(clr - ((shift_up - mem(x + 2).b32.s1) - (mem(z + 3).b32.s1 - shift_down))); if (delta > 0) { shift_up = shift_up + delta; @@ -2092,29 +2093,29 @@ make_fraction(int32_t q) } } else { /*773:*/ if (font_area[cur_f] == OTGR_FONT_FLAG && isOpenTypeMathFont(font_layout_engine[cur_f])) { - delta = half(mem[q + 1].b32.s1); + delta = half(mem(q + 1).b32.s1); if (cur_style < TEXT_STYLE) clr = get_ot_math_constant(cur_f, FRACTIONNUMDISPLAYSTYLEGAPMIN); else clr = get_ot_math_constant(cur_f, FRACTIONNUMERATORGAPMIN); - delta1 = clr - ((shift_up - mem[x + 2].b32.s1) - (axis_height(cur_size) + delta)); + delta1 = clr - ((shift_up - mem(x + 2).b32.s1) - (axis_height(cur_size) + delta)); if (cur_style < TEXT_STYLE) clr = get_ot_math_constant(cur_f, FRACTIONDENOMDISPLAYSTYLEGAPMIN); else clr = get_ot_math_constant(cur_f, FRACTIONDENOMINATORGAPMIN); - delta2 = clr - ((axis_height(cur_size) - delta) - (mem[z + 3].b32.s1 - shift_down)); + delta2 = clr - ((axis_height(cur_size) - delta) - (mem(z + 3).b32.s1 - shift_down)); } else { if (cur_style < TEXT_STYLE) - clr = 3 * mem[q + 1].b32.s1; + clr = 3 * mem(q + 1).b32.s1; else - clr = mem[q + 1].b32.s1; - delta = half(mem[q + 1].b32.s1); - delta1 = clr - ((shift_up - mem[x + 2].b32.s1) - (axis_height(cur_size) + delta)); - delta2 = clr - ((axis_height(cur_size) - delta) - (mem[z + 3].b32.s1 - shift_down)); + clr = mem(q + 1).b32.s1; + delta = half(mem(q + 1).b32.s1); + delta1 = clr - ((shift_up - mem(x + 2).b32.s1) - (axis_height(cur_size) + delta)); + delta2 = clr - ((axis_height(cur_size) - delta) - (mem(z + 3).b32.s1 - shift_down)); } if (delta1 > 0) @@ -2126,24 +2127,24 @@ make_fraction(int32_t q) v = new_null_box(); NODE_type(v) = VLIST_NODE; - mem[v + 3].b32.s1 = shift_up + mem[x + 3].b32.s1; - mem[v + 2].b32.s1 = mem[z + 2].b32.s1 + shift_down; - mem[v + 1].b32.s1 = mem[x + 1].b32.s1; + mem_ptr(v + 3)->b32.s1 = shift_up + mem(x + 3).b32.s1; + mem_ptr(v + 2)->b32.s1 = mem(z + 2).b32.s1 + shift_down; + mem_ptr(v + 1)->b32.s1 = mem(x + 1).b32.s1; - if (mem[q + 1].b32.s1 == 0) { - p = new_kern((shift_up - mem[x + 2].b32.s1) - (mem[z + 3].b32.s1 - shift_down)); - mem[p].b32.s1 = z; + if (mem(q + 1).b32.s1 == 0) { + p = new_kern((shift_up - mem(x + 2).b32.s1) - (mem(z + 3).b32.s1 - shift_down)); + mem_ptr(p)->b32.s1 = z; } else { - y = fraction_rule(mem[q + 1].b32.s1); - p = new_kern((axis_height(cur_size) - delta) - (mem[z + 3].b32.s1 - shift_down)); - mem[y].b32.s1 = p; - mem[p].b32.s1 = z; - p = new_kern((shift_up - mem[x + 2].b32.s1) - (axis_height(cur_size) + delta)); - mem[p].b32.s1 = y; + y = fraction_rule(mem(q + 1).b32.s1); + p = new_kern((axis_height(cur_size) - delta) - (mem(z + 3).b32.s1 - shift_down)); + mem_ptr(y)->b32.s1 = p; + mem_ptr(p)->b32.s1 = z; + p = new_kern((shift_up - mem(x + 2).b32.s1) - (axis_height(cur_size) + delta)); + mem_ptr(p)->b32.s1 = y; } - mem[x].b32.s1 = p; - mem[v + 5].b32.s1 = x; /*:774*/ + mem_ptr(x)->b32.s1 = p; + mem_ptr(v + 5)->b32.s1 = x; /*:774*/ if (cur_style < TEXT_STYLE) delta = delim1(cur_size); @@ -2151,10 +2152,10 @@ make_fraction(int32_t q) delta = delim2(cur_size); x = var_delimiter(q + 4, cur_size, delta); - mem[x].b32.s1 = v; + mem_ptr(x)->b32.s1 = v; z = var_delimiter(q + 5, cur_size, delta); - mem[v].b32.s1 = z; - mem[q + 1].b32.s1 = hpack(x, 0, ADDITIONAL); /*:775*/ + mem_ptr(v)->b32.s1 = z; + mem_ptr(q + 1)->b32.s1 = hpack(x, 0, ADDITIONAL); /*:775*/ } @@ -2170,11 +2171,11 @@ make_op(int32_t q) int32_t n, g; void *ot_assembly_ptr; internal_font_number save_f; - if ((mem[q].b16.s0 == NORMAL) && (cur_style < TEXT_STYLE)) - mem[q].b16.s0 = LIMITS; + if ((mem(q).b16.s0 == NORMAL) && (cur_style < TEXT_STYLE)) + mem_ptr(q)->b16.s0 = LIMITS; delta = 0; ot_assembly_ptr = NULL; - if (mem[q + 1].b32.s1 == MATH_CHAR) { + if (mem(q + 1).b32.s1 == MATH_CHAR) { fetch(q + 1); if (!((font_area[cur_f] == OTGR_FONT_FLAG) && (usingOpenType(font_layout_engine[cur_f])))) { if ((cur_style < TEXT_STYLE) && (((cur_i.s1) % 4) == LIST_TAG)) { @@ -2183,26 +2184,26 @@ make_op(int32_t q) if ((i.s3 > 0)) { cur_c = c; cur_i = i; - mem[q + 1].b16.s0 = c; + mem_ptr(q + 1)->b16.s0 = c; } } delta = FONT_CHARINFO_ITALCORR(cur_f, cur_i); } x = clean_box(q + 1, cur_style); if (((font_area[cur_f] == OTGR_FONT_FLAG) && (isOpenTypeMathFont(font_layout_engine[cur_f])))) { - p = mem[x + 5].b32.s1; + p = mem(x + 5).b32.s1; if ((((p) != TEX_NULL && (!(is_char_node(p))) && (NODE_type(p) == WHATSIT_NODE) - && (mem[p].b16.s0 == GLYPH_NODE)))) { + && (mem(p).b16.s0 == GLYPH_NODE)))) { if (cur_style < TEXT_STYLE) { h1 = get_ot_math_constant(cur_f, DISPLAYOPERATORMINHEIGHT); - if (h1 < (mem[p + 3].b32.s1 + mem[p + 2].b32.s1) * 5 / ((double)4)) - h1 = (mem[p + 3].b32.s1 + mem[p + 2].b32.s1) * 5 / ((double)4); - c = mem[p + 4].b16.s1; + if (h1 < (mem(p + 3).b32.s1 + mem(p + 2).b32.s1) * 5 / ((double)4)) + h1 = (mem(p + 3).b32.s1 + mem(p + 2).b32.s1) * 5 / ((double)4); + c = mem(p + 4).b16.s1; n = 0; do { g = get_ot_math_variant(cur_f, c, n, &h2, 0); if (h2 > 0) { - mem[p + 4].b16.s1 = g; + mem_ptr(p + 4)->b16.s1 = g; set_native_glyph_metrics(p, 1); } n++; @@ -2212,77 +2213,77 @@ make_op(int32_t q) if (ot_assembly_ptr != NULL) { free_node(p, GLYPH_NODE_SIZE); p = build_opentype_assembly(cur_f, ot_assembly_ptr, h1, 0); - mem[x + 5].b32.s1 = p; + mem_ptr(x + 5)->b32.s1 = p; delta = 0; goto found; } } else set_native_glyph_metrics(p, 1); } - delta = get_ot_math_ital_corr(cur_f, mem[p + 4].b16.s1); + delta = get_ot_math_ital_corr(cur_f, mem(p + 4).b16.s1); found: - mem[x + 1].b32.s1 = mem[p + 1].b32.s1; - mem[x + 3].b32.s1 = mem[p + 3].b32.s1; - mem[x + 2].b32.s1 = mem[p + 2].b32.s1; + mem_ptr(x + 1)->b32.s1 = mem(p + 1).b32.s1; + mem_ptr(x + 3)->b32.s1 = mem(p + 3).b32.s1; + mem_ptr(x + 2)->b32.s1 = mem(p + 2).b32.s1; } } - if ((mem[q + 3].b32.s1 != EMPTY) && (mem[q].b16.s0 != LIMITS)) - mem[x + 1].b32.s1 = mem[x + 1].b32.s1 - delta; - mem[x + 4].b32.s1 = half(mem[x + 3].b32.s1 - mem[x + 2].b32.s1) - axis_height(cur_size); - mem[q + 1].b32.s1 = SUB_BOX; - mem[q + 1].b32.s0 = x; + if ((mem(q + 3).b32.s1 != EMPTY) && (mem(q).b16.s0 != LIMITS)) + mem_ptr(x + 1)->b32.s1 = mem(x + 1).b32.s1 - delta; + mem_ptr(x + 4)->b32.s1 = half(mem(x + 3).b32.s1 - mem(x + 2).b32.s1) - axis_height(cur_size); + mem_ptr(q + 1)->b32.s1 = SUB_BOX; + mem_ptr(q + 1)->b32.s0 = x; } save_f = cur_f; - if (mem[q].b16.s0 == LIMITS) { /*777: */ + if (mem(q).b16.s0 == LIMITS) { /*777: */ x = clean_box(q + 2, 2 * (cur_style / 4) + 4 + (cur_style % 2)); y = clean_box(q + 1, cur_style); z = clean_box(q + 3, 2 * (cur_style / 4) + 5); v = new_null_box(); NODE_type(v) = VLIST_NODE; - mem[v + 1].b32.s1 = mem[y + 1].b32.s1; - if (mem[x + 1].b32.s1 > mem[v + 1].b32.s1) - mem[v + 1].b32.s1 = mem[x + 1].b32.s1; - if (mem[z + 1].b32.s1 > mem[v + 1].b32.s1) - mem[v + 1].b32.s1 = mem[z + 1].b32.s1; - x = rebox(x, mem[v + 1].b32.s1); - y = rebox(y, mem[v + 1].b32.s1); - z = rebox(z, mem[v + 1].b32.s1); - mem[x + 4].b32.s1 = half(delta); - mem[z + 4].b32.s1 = -(int32_t) mem[x + 4].b32.s1; - mem[v + 3].b32.s1 = mem[y + 3].b32.s1; - mem[v + 2].b32.s1 = mem[y + 2].b32.s1; + mem_ptr(v + 1)->b32.s1 = mem(y + 1).b32.s1; + if (mem(x + 1).b32.s1 > mem(v + 1).b32.s1) + mem_ptr(v + 1)->b32.s1 = mem(x + 1).b32.s1; + if (mem(z + 1).b32.s1 > mem(v + 1).b32.s1) + mem_ptr(v + 1)->b32.s1 = mem(z + 1).b32.s1; + x = rebox(x, mem(v + 1).b32.s1); + y = rebox(y, mem(v + 1).b32.s1); + z = rebox(z, mem(v + 1).b32.s1); + mem_ptr(x + 4)->b32.s1 = half(delta); + mem_ptr(z + 4)->b32.s1 = -(int32_t) mem(x + 4).b32.s1; + mem_ptr(v + 3)->b32.s1 = mem(y + 3).b32.s1; + mem_ptr(v + 2)->b32.s1 = mem(y + 2).b32.s1; cur_f = save_f; - if (mem[q + 2].b32.s1 == EMPTY) { + if (mem(q + 2).b32.s1 == EMPTY) { free_node(x, BOX_NODE_SIZE); - mem[v + 5].b32.s1 = y; + mem_ptr(v + 5)->b32.s1 = y; } else { - shift_up = big_op_spacing3() - mem[x + 2].b32.s1; + shift_up = big_op_spacing3() - mem(x + 2).b32.s1; if (shift_up < big_op_spacing1()) shift_up = big_op_spacing1(); p = new_kern(shift_up); - mem[p].b32.s1 = y; - mem[x].b32.s1 = p; + mem_ptr(p)->b32.s1 = y; + mem_ptr(x)->b32.s1 = p; p = new_kern(big_op_spacing5()); - mem[p].b32.s1 = x; - mem[v + 5].b32.s1 = p; - mem[v + 3].b32.s1 = mem[v + 3].b32.s1 + big_op_spacing5() + mem[x + 3].b32.s1 + mem[x + 2].b32.s1 + shift_up; + mem_ptr(p)->b32.s1 = x; + mem_ptr(v + 5)->b32.s1 = p; + mem_ptr(v + 3)->b32.s1 = mem(v + 3).b32.s1 + big_op_spacing5() + mem(x + 3).b32.s1 + mem(x + 2).b32.s1 + shift_up; } - if (mem[q + 3].b32.s1 == EMPTY) + if (mem(q + 3).b32.s1 == EMPTY) free_node(z, BOX_NODE_SIZE); else { - shift_down = big_op_spacing4() - mem[z + 3].b32.s1; + shift_down = big_op_spacing4() - mem(z + 3).b32.s1; if (shift_down < big_op_spacing2()) shift_down = big_op_spacing2(); p = new_kern(shift_down); - mem[y].b32.s1 = p; - mem[p].b32.s1 = z; + mem_ptr(y)->b32.s1 = p; + mem_ptr(p)->b32.s1 = z; p = new_kern(big_op_spacing5()); - mem[z].b32.s1 = p; - mem[v + 2].b32.s1 = mem[v + 2].b32.s1 + big_op_spacing5() + mem[z + 3].b32.s1 + mem[z + 2].b32.s1 + shift_down; + mem_ptr(z)->b32.s1 = p; + mem_ptr(v + 2)->b32.s1 = mem(v + 2).b32.s1 + big_op_spacing5() + mem(z + 3).b32.s1 + mem(z + 2).b32.s1 + shift_down; } - mem[q + 1].b32.s1 = v; + mem_ptr(q + 1)->b32.s1 = v; } free_ot_assembly(ot_assembly_ptr); return delta; @@ -2296,24 +2297,24 @@ make_ord(int32_t q) int32_t p, r; restart: - if (mem[q + 3].b32.s1 == EMPTY) { + if (mem(q + 3).b32.s1 == EMPTY) { - if (mem[q + 2].b32.s1 == EMPTY) { + if (mem(q + 2).b32.s1 == EMPTY) { - if (mem[q + 1].b32.s1 == MATH_CHAR) { - p = mem[q].b32.s1; + if (mem(q + 1).b32.s1 == MATH_CHAR) { + p = mem(q).b32.s1; if (p != TEX_NULL) { - if ((mem[p].b16.s1 >= ORD_NOAD) && (mem[p].b16.s1 <= PUNCT_NOAD)) { + if ((mem(p).b16.s1 >= ORD_NOAD) && (mem(p).b16.s1 <= PUNCT_NOAD)) { - if (mem[p + 1].b32.s1 == MATH_CHAR) { + if (mem(p + 1).b32.s1 == MATH_CHAR) { - if ((mem[p + 1].b16.s1 % 256) == (mem[q + 1].b16.s1 % 256)) { - mem[q + 1].b32.s1 = MATH_TEXT_CHAR; + if ((mem(p + 1).b16.s1 % 256) == (mem(q + 1).b16.s1 % 256)) { + mem_ptr(q + 1)->b32.s1 = MATH_TEXT_CHAR; fetch(q + 1); if (((cur_i.s1) % 4) == LIG_TAG) { a = lig_kern_base[cur_f] + cur_i.s0; - cur_c = mem[p + 1].b16.s0; + cur_c = mem(p + 1).b16.s0; cur_i = font_info[a].b16; if (cur_i.s3 > 128) { a = lig_kern_base[cur_f] + 256 * cur_i.s1 + cur_i.s0 + 32768L - 256 * (128); @@ -2328,47 +2329,47 @@ make_ord(int32_t q) if (cur_i.s1 >= 128) { p = new_kern(font_info [kern_base[cur_f] + 256 * cur_i.s1 + cur_i.s0].b32.s1); - mem[p].b32.s1 = mem[q].b32.s1; - mem[q].b32.s1 = p; + mem_ptr(p)->b32.s1 = mem(q).b32.s1; + mem_ptr(q)->b32.s1 = p; return; } else { switch (cur_i.s1) { case 1: case 5: - mem[q + 1].b16.s0 = cur_i.s0; + mem_ptr(q + 1)->b16.s0 = cur_i.s0; break; case 2: case 6: - mem[p + 1].b16.s0 = cur_i.s0; + mem_ptr(p + 1)->b16.s0 = cur_i.s0; break; case 3: case 7: case 11: { r = new_noad(); - mem[r + 1].b16.s0 = cur_i.s0; - mem[r + 1].b16.s1 = (mem[q + 1].b16.s1 % 256); - mem[q].b32.s1 = r; - mem[r].b32.s1 = p; + mem_ptr(r + 1)->b16.s0 = cur_i.s0; + mem_ptr(r + 1)->b16.s1 = (mem(q + 1).b16.s1 % 256); + mem_ptr(q)->b32.s1 = r; + mem_ptr(r)->b32.s1 = p; if (cur_i.s1 < 11) - mem[r + 1].b32.s1 = MATH_CHAR; + mem_ptr(r + 1)->b32.s1 = MATH_CHAR; else - mem[r + 1].b32.s1 = MATH_TEXT_CHAR; + mem_ptr(r + 1)->b32.s1 = MATH_TEXT_CHAR; } break; default: { - mem[q].b32.s1 = mem[p].b32.s1; - mem[q + 1].b16.s0 = cur_i.s0; - mem[q + 3] = mem[p + 3]; - mem[q + 2] = mem[p + 2]; + mem_ptr(q)->b32.s1 = mem(p).b32.s1; + mem_ptr(q + 1)->b16.s0 = cur_i.s0; + set_mem(q + 3, mem(p + 3)); + set_mem(q + 2, mem(p + 2)); free_node(p, NOAD_SIZE); } break; } if (cur_i.s1 > 3) return; - mem[q + 1].b32.s1 = MATH_CHAR; + mem_ptr(q + 1)->b32.s1 = MATH_CHAR; goto restart; } } @@ -2394,16 +2395,16 @@ attach_hkern_to_new_hlist(int32_t q, scaled_t delta) { int32_t y, z; z = new_kern(delta); - if (mem[q + 1].b32.s1 == TEX_NULL) - mem[q + 1].b32.s1 = z; + if (mem(q + 1).b32.s1 == TEX_NULL) + mem_ptr(q + 1)->b32.s1 = z; else { - y = mem[q + 1].b32.s1; - while (mem[y].b32.s1 != TEX_NULL) + y = mem(q + 1).b32.s1; + while (mem(y).b32.s1 != TEX_NULL) y = LLIST_link(y); - mem[y].b32.s1 = z; + mem_ptr(y)->b32.s1 = z; } - return mem[q + 1].b32.s1; + return mem(q + 1).b32.s1; } @@ -2426,7 +2427,7 @@ make_scripts(int32_t q, scaled_t delta) small_number saved_math_style; small_number this_math_style; - p = mem[q + 1].b32.s1; + p = mem(q + 1).b32.s1; script_c = TEX_NULL; script_g = 0; script_f = 0; @@ -2436,7 +2437,7 @@ make_scripts(int32_t q, scaled_t delta) if ((is_char_node(p)) || (((p) != TEX_NULL && (!(is_char_node(p))) && (NODE_type(p) == WHATSIT_NODE) - && (mem[p].b16.s0 == GLYPH_NODE)))) { + && (mem(p).b16.s0 == GLYPH_NODE)))) { shift_up = 0; shift_down = 0; } else { @@ -2445,12 +2446,12 @@ make_scripts(int32_t q, scaled_t delta) t = SCRIPT_SIZE; else t = SCRIPT_SCRIPT_SIZE; - shift_up = mem[z + 3].b32.s1 - sup_drop(t); - shift_down = mem[z + 2].b32.s1 + sub_drop(t); + shift_up = mem(z + 3).b32.s1 - sup_drop(t); + shift_down = mem(z + 2).b32.s1 + sub_drop(t); free_node(z, BOX_NODE_SIZE); } - if (mem[q + 2].b32.s1 == EMPTY) { /*801: */ + if (mem(q + 2).b32.s1 == EMPTY) { /*801: */ /* "Construct a subscript box when there is no superscript[.] The top of * the subscript should not exceed the baseline plus four-fifths of the * x-height." @@ -2471,7 +2472,7 @@ make_scripts(int32_t q, scaled_t delta) * Don’t try to do anything clever if the nucleus of the script head * is empty, e.g., Pj and the such." */ - if (mem[script_head].b32.s1 == SUB_MLIST) { /* math_type(script_head) */ + if (mem(script_head).b32.s1 == SUB_MLIST) { /* math_type(script_head) */ script_ptr = LLIST_info(script_head); script_head = TEX_NULL; @@ -2502,16 +2503,16 @@ make_scripts(int32_t q, scaled_t delta) if (NODE_type(script_ptr) == CHOICE_NODE) { switch (this_math_style / 2) { case 0: - script_ptr = mem[script_ptr + 1].b32.s0; /*display_mlist(.)*/ + script_ptr = mem(script_ptr + 1).b32.s0; /*display_mlist(.)*/ break; case 1: - script_ptr = mem[script_ptr + 1].b32.s1; /*text_mlist(.)*/ + script_ptr = mem(script_ptr + 1).b32.s1; /*text_mlist(.)*/ break; case 2: - script_ptr = mem[script_ptr + 2].b32.s0; /*script_mlist(.)*/ + script_ptr = mem(script_ptr + 2).b32.s0; /*script_mlist(.)*/ break; case 3: - script_ptr = mem[script_ptr + 2].b32.s1; /*script_script_mlist(.)*/ + script_ptr = mem(script_ptr + 2).b32.s1; /*script_script_mlist(.)*/ break; } } else { @@ -2521,7 +2522,7 @@ make_scripts(int32_t q, scaled_t delta) } } - if (script_head >= 0 && script_head <= mem_end && mem[script_head].b32.s1 == MATH_CHAR) { + if (script_head >= 0 && script_head <= mem_end && mem(script_head).b32.s1 == MATH_CHAR) { save_f = cur_f; saved_math_style = cur_style; cur_style = this_math_style; @@ -2557,24 +2558,24 @@ make_scripts(int32_t q, scaled_t delta) x = clean_box(q + 3, 2 * (cur_style / 4) + 5); cur_f = save_f; - mem[x + 1].b32.s1 = mem[x + 1].b32.s1 + DIMENPAR(script_space); + mem_ptr(x + 1)->b32.s1 = mem(x + 1).b32.s1 + DIMENPAR(script_space); if (shift_down < sub1(cur_size)) shift_down = sub1(cur_size); if (((font_area[cur_f] == OTGR_FONT_FLAG) && (isOpenTypeMathFont(font_layout_engine[cur_f])))) - clr = mem[x + 3].b32.s1 - get_ot_math_constant(cur_f, SUBSCRIPTTOPMAX); + clr = mem(x + 3).b32.s1 - get_ot_math_constant(cur_f, SUBSCRIPTTOPMAX); else - clr = mem[x + 3].b32.s1 - (abs(math_x_height(cur_size) * 4) / 5); + clr = mem(x + 3).b32.s1 - (abs(math_x_height(cur_size) * 4) / 5); if (shift_down < clr) shift_down = clr; - mem[x + 4].b32.s1 = shift_down; + mem_ptr(x + 4)->b32.s1 = shift_down; if (font_area[cur_f] == OTGR_FONT_FLAG && isOpenTypeMathFont(font_layout_engine[cur_f])) { /*787: */ - if (p != TEX_NULL && !is_char_node(p) && NODE_type(p) == WHATSIT_NODE && mem[p].b16.s0 == GLYPH_NODE) { - sub_kern = get_ot_math_kern(mem[p + 4].b16.s2, mem[p + 4].b16.s1, sub_f, sub_g, SUB_CMD, shift_down); + if (p != TEX_NULL && !is_char_node(p) && NODE_type(p) == WHATSIT_NODE && mem(p).b16.s0 == GLYPH_NODE) { + sub_kern = get_ot_math_kern(mem(p + 4).b16.s2, mem(p + 4).b16.s1, sub_f, sub_g, SUB_CMD, shift_down); if (sub_kern != 0) p = attach_hkern_to_new_hlist(q, sub_kern); @@ -2590,7 +2591,7 @@ make_scripts(int32_t q, scaled_t delta) script_f = 0; this_math_style = 2 * (cur_style / 4) + 5; - if (mem[script_head].b32.s1 == SUB_MLIST) { /* math_type(script_head) */ + if (mem(script_head).b32.s1 == SUB_MLIST) { /* math_type(script_head) */ script_ptr = LLIST_info(script_head); script_head = TEX_NULL; @@ -2621,16 +2622,16 @@ make_scripts(int32_t q, scaled_t delta) if (NODE_type(script_ptr) == CHOICE_NODE) { switch (this_math_style / 2) { case 0: - script_ptr = mem[script_ptr + 1].b32.s0; /*display_mlist(.)*/ + script_ptr = mem(script_ptr + 1).b32.s0; /*display_mlist(.)*/ break; case 1: - script_ptr = mem[script_ptr + 1].b32.s1; /*text_mlist(.)*/ + script_ptr = mem(script_ptr + 1).b32.s1; /*text_mlist(.)*/ break; case 2: - script_ptr = mem[script_ptr + 2].b32.s0; /*script_mlist(.)*/ + script_ptr = mem(script_ptr + 2).b32.s0; /*script_mlist(.)*/ break; case 3: - script_ptr = mem[script_ptr + 2].b32.s1; /*script_script_mlist(.)*/ + script_ptr = mem(script_ptr + 2).b32.s1; /*script_script_mlist(.)*/ break; } } else { @@ -2640,7 +2641,7 @@ make_scripts(int32_t q, scaled_t delta) } } - if (script_head >= 0 && script_head <= mem_end && mem[script_head].b32.s1 == MATH_CHAR) { + if (script_head >= 0 && script_head <= mem_end && mem(script_head).b32.s1 == MATH_CHAR) { save_f = cur_f; saved_math_style = cur_style; cur_style = this_math_style; @@ -2676,7 +2677,7 @@ make_scripts(int32_t q, scaled_t delta) x = clean_box(q + 2, 2 * (cur_style / 4) + 4 + (cur_style % 2)); cur_f = save_f; - mem[x + 1].b32.s1 = mem[x + 1].b32.s1 + DIMENPAR(script_space); + mem_ptr(x + 1)->b32.s1 = mem(x + 1).b32.s1 + DIMENPAR(script_space); if (odd(cur_style)) clr = sup3(cur_size); @@ -2689,17 +2690,17 @@ make_scripts(int32_t q, scaled_t delta) shift_up = clr; if (font_area[cur_f] == OTGR_FONT_FLAG && isOpenTypeMathFont(font_layout_engine[cur_f])) - clr = mem[x + 2].b32.s1 + get_ot_math_constant(cur_f, SUPERSCRIPTBOTTOMMIN); + clr = mem(x + 2).b32.s1 + get_ot_math_constant(cur_f, SUPERSCRIPTBOTTOMMIN); else - clr = mem[x + 2].b32.s1 + (abs(math_x_height(cur_size)) / 4); + clr = mem(x + 2).b32.s1 + (abs(math_x_height(cur_size)) / 4); if (shift_up < clr) shift_up = clr; if (font_area[cur_f] == OTGR_FONT_FLAG && isOpenTypeMathFont(font_layout_engine[cur_f])) { /*788: */ - if (mem[q + 3].b32.s1 == EMPTY) { - if (p != TEX_NULL && !is_char_node(p) && NODE_type(p) == WHATSIT_NODE && mem[p].b16.s0 == GLYPH_NODE) { - sup_kern = get_ot_math_kern(mem[p + 4].b16.s2, mem[p + 4].b16.s1, sup_f, sup_g, SUP_CMD, shift_up); + if (mem(q + 3).b32.s1 == EMPTY) { + if (p != TEX_NULL && !is_char_node(p) && NODE_type(p) == WHATSIT_NODE && mem(p).b16.s0 == GLYPH_NODE) { + sup_kern = get_ot_math_kern(mem(p + 4).b16.s2, mem(p + 4).b16.s1, sup_f, sup_g, SUP_CMD, shift_up); if (sup_kern != 0) p = attach_hkern_to_new_hlist(q, sup_kern); @@ -2707,8 +2708,8 @@ make_scripts(int32_t q, scaled_t delta) } } - if (mem[q + 3].b32.s1 == EMPTY) - mem[x + 4].b32.s1 = -(int32_t) shift_up; + if (mem(q + 3).b32.s1 == EMPTY) + mem_ptr(x + 4)->b32.s1 = -(int32_t) shift_up; else { /*786: */ save_f = cur_f; @@ -2719,7 +2720,7 @@ make_scripts(int32_t q, scaled_t delta) script_f = 0; this_math_style = 2 * (cur_style / 4) + 5; - if (mem[script_head].b32.s1 == SUB_MLIST) { /* math_type(script_head) */ + if (mem(script_head).b32.s1 == SUB_MLIST) { /* math_type(script_head) */ script_ptr = LLIST_info(script_head); script_head = TEX_NULL; @@ -2750,16 +2751,16 @@ make_scripts(int32_t q, scaled_t delta) if (NODE_type(script_ptr) == CHOICE_NODE) { switch (this_math_style / 2) { case 0: - script_ptr = mem[script_ptr + 1].b32.s0; /*display_mlist(.)*/ + script_ptr = mem(script_ptr + 1).b32.s0; /*display_mlist(.)*/ break; case 1: - script_ptr = mem[script_ptr + 1].b32.s1; /*text_mlist(.)*/ + script_ptr = mem(script_ptr + 1).b32.s1; /*text_mlist(.)*/ break; case 2: - script_ptr = mem[script_ptr + 2].b32.s0; /*script_mlist(.)*/ + script_ptr = mem(script_ptr + 2).b32.s0; /*script_mlist(.)*/ break; case 3: - script_ptr = mem[script_ptr + 2].b32.s1; /*script_script_mlist(.)*/ + script_ptr = mem(script_ptr + 2).b32.s1; /*script_script_mlist(.)*/ break; } } else { @@ -2769,7 +2770,7 @@ make_scripts(int32_t q, scaled_t delta) } } - if (script_head >= 0 && script_head <= mem_end && mem[script_head].b32.s1 == MATH_CHAR) { + if (script_head >= 0 && script_head <= mem_end && mem(script_head).b32.s1 == MATH_CHAR) { save_f = cur_f; saved_math_style = cur_style; cur_style = this_math_style; @@ -2804,7 +2805,7 @@ make_scripts(int32_t q, scaled_t delta) y = clean_box(q + 3, 2 * (cur_style / 4) + 5); cur_f = save_f; - mem[y + 1].b32.s1 = mem[y + 1].b32.s1 + DIMENPAR(script_space); + mem_ptr(y + 1)->b32.s1 = mem(y + 1).b32.s1 + DIMENPAR(script_space); if (shift_down < sub2(cur_size)) shift_down = sub2(cur_size); @@ -2812,10 +2813,10 @@ make_scripts(int32_t q, scaled_t delta) if (((font_area[cur_f] == OTGR_FONT_FLAG) && (isOpenTypeMathFont(font_layout_engine[cur_f])))) clr = get_ot_math_constant(cur_f, - SUBSUPERSCRIPTGAPMIN) - ((shift_up - mem[x + 2].b32.s1) - - (mem[y + 3].b32.s1 - shift_down)); + SUBSUPERSCRIPTGAPMIN) - ((shift_up - mem(x + 2).b32.s1) - + (mem(y + 3).b32.s1 - shift_down)); else - clr = 4 * default_rule_thickness() - ((shift_up - mem[x + 2].b32.s1) - (mem[y + 3].b32.s1 - shift_down)); + clr = 4 * default_rule_thickness() - ((shift_up - mem(x + 2).b32.s1) - (mem(y + 3).b32.s1 - shift_down)); if (clr > 0) { shift_down = shift_down + clr; @@ -2823,9 +2824,9 @@ make_scripts(int32_t q, scaled_t delta) && (isOpenTypeMathFont(font_layout_engine[cur_f])))) clr = get_ot_math_constant(cur_f, - SUPERSCRIPTBOTTOMMAXWITHSUBSCRIPT) - (shift_up - mem[x + 2].b32.s1); + SUPERSCRIPTBOTTOMMAXWITHSUBSCRIPT) - (shift_up - mem(x + 2).b32.s1); else - clr = (abs(math_x_height(cur_size) * 4) / 5) - (shift_up - mem[x + 2].b32.s1); + clr = (abs(math_x_height(cur_size) * 4) / 5) - (shift_up - mem(x + 2).b32.s1); if (clr > 0) { shift_up = shift_up + clr; shift_down = shift_down - clr; @@ -2833,16 +2834,16 @@ make_scripts(int32_t q, scaled_t delta) } if (font_area[cur_f] == OTGR_FONT_FLAG && isOpenTypeMathFont(font_layout_engine[cur_f])) { - if (p != TEX_NULL && !is_char_node(p) && NODE_type(p) == WHATSIT_NODE && mem[p].b16.s0 == GLYPH_NODE) { - sub_kern = get_ot_math_kern(mem[p + 4].b16.s2, mem[p + 4].b16.s1, sub_f, sub_g, SUB_CMD, shift_down); + if (p != TEX_NULL && !is_char_node(p) && NODE_type(p) == WHATSIT_NODE && mem(p).b16.s0 == GLYPH_NODE) { + sub_kern = get_ot_math_kern(mem(p + 4).b16.s2, mem(p + 4).b16.s1, sub_f, sub_g, SUB_CMD, shift_down); if (sub_kern != 0) p = attach_hkern_to_new_hlist(q, sub_kern); } - if (mem[q + 3].b32.s1 == EMPTY) { - if (p != TEX_NULL && !is_char_node(p) && NODE_type(p) == WHATSIT_NODE && mem[p].b16.s0 == GLYPH_NODE) { - sup_kern = get_ot_math_kern(mem[p + 4].b16.s2, mem[p + 4].b16.s1, sup_f, sup_g, SUP_CMD, shift_up); + if (mem(q + 3).b32.s1 == EMPTY) { + if (p != TEX_NULL && !is_char_node(p) && NODE_type(p) == WHATSIT_NODE && mem(p).b16.s0 == GLYPH_NODE) { + sup_kern = get_ot_math_kern(mem(p + 4).b16.s2, mem(p + 4).b16.s1, sup_f, sup_g, SUP_CMD, shift_up); if (sup_kern != 0) p = attach_hkern_to_new_hlist(q, sup_kern); @@ -2853,22 +2854,22 @@ make_scripts(int32_t q, scaled_t delta) sub_kern = 0; } - mem[x + 4].b32.s1 = sup_kern + delta - sub_kern; - p = new_kern((shift_up - mem[x + 2].b32.s1) - (mem[y + 3].b32.s1 - shift_down)); - mem[x].b32.s1 = p; - mem[p].b32.s1 = y; + mem_ptr(x + 4)->b32.s1 = sup_kern + delta - sub_kern; + p = new_kern((shift_up - mem(x + 2).b32.s1) - (mem(y + 3).b32.s1 - shift_down)); + mem_ptr(x)->b32.s1 = p; + mem_ptr(p)->b32.s1 = y; x = vpackage(x, 0, ADDITIONAL, MAX_HALFWORD); - mem[x + 4].b32.s1 = shift_down; + mem_ptr(x + 4)->b32.s1 = shift_down; } } - if (mem[q + 1].b32.s1 == TEX_NULL) - mem[q + 1].b32.s1 = x; + if (mem(q + 1).b32.s1 == TEX_NULL) + mem_ptr(q + 1)->b32.s1 = x; else { - p = mem[q + 1].b32.s1; - while (mem[p].b32.s1 != TEX_NULL) + p = mem(q + 1).b32.s1; + while (mem(p).b32.s1 != TEX_NULL) p = LLIST_link(p); - mem[p].b32.s1 = x; + mem_ptr(p)->b32.s1 = x; } } @@ -2894,8 +2895,8 @@ make_left_right(int32_t q, small_number style, scaled_t max_d, scaled_t max_h) delta2 = delta1 + delta1 - DIMENPAR(delimiter_shortfall); if (delta < delta2) delta = delta2; - mem[q + 1].b32.s1 = var_delimiter(q + 1, cur_size, delta); - return mem[q].b16.s1 - ((LEFT_NOAD - 20)); + mem_ptr(q + 1)->b32.s1 = var_delimiter(q + 1, cur_size, delta); + return mem(q).b16.s1 - ((LEFT_NOAD - 20)); } @@ -2935,7 +2936,7 @@ mlist_to_hlist(void) reswitch: delta = 0; - switch (mem[q].b16.s1) { + switch (mem(q).b16.s1) { case BIN_NOAD: switch (r_type) { case BIN_NOAD: @@ -2944,7 +2945,7 @@ mlist_to_hlist(void) case OPEN_NOAD: case PUNCT_NOAD: case LEFT_NOAD: - mem[q].b16.s1 = ORD_NOAD; + mem_ptr(q)->b16.s1 = ORD_NOAD; goto reswitch; default: break; @@ -2956,8 +2957,8 @@ mlist_to_hlist(void) case RIGHT_NOAD: { if (r_type == BIN_NOAD) - mem[r].b16.s1 = ORD_NOAD /*:755 */ ; - if (mem[q].b16.s1 == RIGHT_NOAD) + mem_ptr(r)->b16.s1 = ORD_NOAD /*:755 */ ; + if (mem(q).b16.s1 == RIGHT_NOAD) goto lab80; } break; @@ -2969,7 +2970,7 @@ mlist_to_hlist(void) goto lab82; case OP_NOAD: delta = make_op(q); - if (mem[q].b16.s0 == LIMITS) + if (mem(q).b16.s0 == LIMITS) goto lab82; break; case ORD_NOAD: @@ -2995,7 +2996,7 @@ mlist_to_hlist(void) break; case STYLE_NODE: { - cur_style = mem[q].b16.s0; + cur_style = mem(q).b16.s0; { if (cur_style < SCRIPT_STYLE) cur_size = TEXT_SIZE; @@ -3011,43 +3012,43 @@ mlist_to_hlist(void) switch (cur_style / 2) { case 0: { - p = mem[q + 1].b32.s0; - mem[q + 1].b32.s0 = TEX_NULL; + p = mem(q + 1).b32.s0; + mem_ptr(q + 1)->b32.s0 = TEX_NULL; } break; case 1: { - p = mem[q + 1].b32.s1; - mem[q + 1].b32.s1 = TEX_NULL; + p = mem(q + 1).b32.s1; + mem_ptr(q + 1)->b32.s1 = TEX_NULL; } break; case 2: { - p = mem[q + 2].b32.s0; - mem[q + 2].b32.s0 = TEX_NULL; + p = mem(q + 2).b32.s0; + mem_ptr(q + 2)->b32.s0 = TEX_NULL; } break; case 3: { - p = mem[q + 2].b32.s1; - mem[q + 2].b32.s1 = TEX_NULL; + p = mem(q + 2).b32.s1; + mem_ptr(q + 2)->b32.s1 = TEX_NULL; } break; } - flush_node_list(mem[q + 1].b32.s0); - flush_node_list(mem[q + 1].b32.s1); - flush_node_list(mem[q + 2].b32.s0); - flush_node_list(mem[q + 2].b32.s1); + flush_node_list(mem(q + 1).b32.s0); + flush_node_list(mem(q + 1).b32.s1); + flush_node_list(mem(q + 2).b32.s0); + flush_node_list(mem(q + 2).b32.s1); NODE_type(q) = STYLE_NODE; - mem[q].b16.s0 = cur_style; - mem[q + 1].b32.s1 = 0; - mem[q + 2].b32.s1 = 0; + mem_ptr(q)->b16.s0 = cur_style; + mem_ptr(q + 1)->b32.s1 = 0; + mem_ptr(q + 2)->b32.s1 = 0; if (p != TEX_NULL) { - z = mem[q].b32.s1; - mem[q].b32.s1 = p; - while (mem[p].b32.s1 != TEX_NULL) + z = mem(q).b32.s1; + mem_ptr(q)->b32.s1 = p; + while (mem(p).b32.s1 != TEX_NULL) p = LLIST_link(p); - mem[p].b32.s1 = z; + mem_ptr(p)->b32.s1 = z; } goto lab81; } @@ -3060,26 +3061,26 @@ mlist_to_hlist(void) case DISC_NODE: goto lab81; case RULE_NODE: - if (mem[q + 3].b32.s1 > max_h) - max_h = mem[q + 3].b32.s1; - if (mem[q + 2].b32.s1 > max_d) - max_d = mem[q + 2].b32.s1; + if (mem(q + 3).b32.s1 > max_h) + max_h = mem(q + 3).b32.s1; + if (mem(q + 2).b32.s1 > max_d) + max_d = mem(q + 2).b32.s1; goto lab81; case GLUE_NODE: { - if (mem[q].b16.s0 == MU_GLUE) { - x = mem[q + 1].b32.s0; + if (mem(q).b16.s0 == MU_GLUE) { + x = mem(q + 1).b32.s0; y = math_glue(x, cur_mu); delete_glue_ref(x); - mem[q + 1].b32.s0 = y; - mem[q].b16.s0 = NORMAL; - } else if ((cur_size != TEXT_SIZE) && (mem[q].b16.s0 == COND_MATH_GLUE)) { - p = mem[q].b32.s1; + mem_ptr(q + 1)->b32.s0 = y; + mem_ptr(q)->b16.s0 = NORMAL; + } else if ((cur_size != TEXT_SIZE) && (mem(q).b16.s0 == COND_MATH_GLUE)) { + p = mem(q).b32.s1; if (p != TEX_NULL) { if ((NODE_type(p) == GLUE_NODE) || (NODE_type(p) == KERN_NODE)) { - mem[q].b32.s1 = mem[p].b32.s1; - mem[p].b32.s1 = TEX_NULL; + mem_ptr(q)->b32.s1 = mem(p).b32.s1; + mem_ptr(p)->b32.s1 = TEX_NULL; flush_node_list(p); } } @@ -3097,7 +3098,7 @@ mlist_to_hlist(void) confusion("mlist1"); break; } - switch (mem[q + 1].b32.s1) { + switch (mem(q + 1).b32.s1) { case 1: case 4: { @@ -3107,29 +3108,29 @@ mlist_to_hlist(void) z = new_native_character(cur_f, cur_c); p = get_node(GLYPH_NODE_SIZE); NODE_type(p) = WHATSIT_NODE; - mem[p].b16.s0 = GLYPH_NODE; - mem[p + 4].b16.s2 = cur_f; - mem[p + 4].b16.s1 = get_native_glyph(z, 0); + mem_ptr(p)->b16.s0 = GLYPH_NODE; + mem_ptr(p + 4)->b16.s2 = cur_f; + mem_ptr(p + 4)->b16.s1 = get_native_glyph(z, 0); set_native_glyph_metrics(p, 1); - free_node(z, mem[z + 4].b16.s3); - delta = get_ot_math_ital_corr(cur_f, mem[p + 4].b16.s1); - if ((mem[q + 1].b32.s1 == MATH_TEXT_CHAR) + free_node(z, mem(z + 4).b16.s3); + delta = get_ot_math_ital_corr(cur_f, mem(p + 4).b16.s1); + if ((mem(q + 1).b32.s1 == MATH_TEXT_CHAR) && (!((font_area[cur_f] == OTGR_FONT_FLAG) && (isOpenTypeMathFont(font_layout_engine[cur_f]))) != 0)) delta = 0; - if ((mem[q + 3].b32.s1 == EMPTY) && (delta != 0)) { - mem[p].b32.s1 = new_kern(delta); + if ((mem(q + 3).b32.s1 == EMPTY) && (delta != 0)) { + mem_ptr(p)->b32.s1 = new_kern(delta); delta = 0; } } else if ((cur_i.s3 > 0)) { delta = FONT_CHARINFO_ITALCORR(cur_f, cur_i); p = new_character(cur_f, cur_c); - if ((mem[q + 1].b32.s1 == MATH_TEXT_CHAR) + if ((mem(q + 1).b32.s1 == MATH_TEXT_CHAR) && (font_info[SPACE_CODE + param_base[cur_f]].b32.s1 != 0)) delta = 0; - if ((mem[q + 3].b32.s1 == EMPTY) && (delta != 0)) { - mem[p].b32.s1 = new_kern(delta); + if ((mem(q + 3).b32.s1 == EMPTY) && (delta != 0)) { + mem_ptr(p)->b32.s1 = new_kern(delta); delta = 0; } } else @@ -3140,11 +3141,11 @@ mlist_to_hlist(void) p = TEX_NULL; break; case 2: - p = mem[q + 1].b32.s0; + p = mem(q + 1).b32.s0; break; case 3: { - cur_mlist = mem[q + 1].b32.s0; + cur_mlist = mem(q + 1).b32.s0; save_style = cur_style; mlist_penalties = false; mlist_to_hlist(); @@ -3156,25 +3157,25 @@ mlist_to_hlist(void) cur_size = SCRIPT_SIZE * ((cur_style - 2) / 2); cur_mu = x_over_n(math_quad(cur_size), 18); } - p = hpack(mem[TEMP_HEAD].b32.s1, 0, ADDITIONAL); + p = hpack(mem(TEMP_HEAD).b32.s1, 0, ADDITIONAL); } break; default: confusion("mlist2"); break; } - mem[q + 1].b32.s1 = p; - if ((mem[q + 3].b32.s1 == EMPTY) && (mem[q + 2].b32.s1 == EMPTY)) + mem_ptr(q + 1)->b32.s1 = p; + if ((mem(q + 3).b32.s1 == EMPTY) && (mem(q + 2).b32.s1 == EMPTY)) goto lab82; make_scripts(q, delta); - lab82:/*check_dimensions */ z = hpack(mem[q + 1].b32.s1, 0, ADDITIONAL); - if (mem[z + 3].b32.s1 > max_h) - max_h = mem[z + 3].b32.s1; - if (mem[z + 2].b32.s1 > max_d) - max_d = mem[z + 2].b32.s1; + lab82:/*check_dimensions */ z = hpack(mem(q + 1).b32.s1, 0, ADDITIONAL); + if (mem(z + 3).b32.s1 > max_h) + max_h = mem(z + 3).b32.s1; + if (mem(z + 2).b32.s1 > max_d) + max_d = mem(z + 2).b32.s1; free_node(z, BOX_NODE_SIZE); lab80: /*done_with_noad */ r = q; - r_type = mem[r].b16.s1; + r_type = mem(r).b16.s1; if (r_type == RIGHT_NOAD) { r_type = LEFT_NOAD; cur_style = style; @@ -3189,9 +3190,9 @@ mlist_to_hlist(void) lab81: /*done_with_node */ q = LLIST_link(q); } if (r_type == BIN_NOAD) - mem[r].b16.s1 = 16 /*ord_noad *//*:755 */ ; + mem_ptr(r)->b16.s1 = 16 /*ord_noad *//*:755 */ ; p = TEMP_HEAD; - mem[p].b32.s1 = TEX_NULL; + mem_ptr(p)->b32.s1 = TEX_NULL; q = mlist; r_type = 0; cur_style = style; @@ -3207,13 +3208,13 @@ mlist_to_hlist(void) t = ORD_NOAD; s = NOAD_SIZE; pen = INF_PENALTY; - switch (mem[q].b16.s1) { + switch (mem(q).b16.s1) { case OP_NOAD: case OPEN_NOAD: case CLOSE_NOAD: case PUNCT_NOAD: case INNER_NOAD: - t = mem[q].b16.s1; + t = mem(q).b16.s1; break; case BIN_NOAD: { @@ -3247,7 +3248,7 @@ mlist_to_hlist(void) break; case STYLE_NODE: { - cur_style = mem[q].b16.s0; + cur_style = mem(q).b16.s0; s = STYLE_NODE_SIZE; { if (cur_style < SCRIPT_STYLE) @@ -3269,10 +3270,10 @@ mlist_to_hlist(void) case GLUE_NODE: case KERN_NODE: { - mem[p].b32.s1 = q; + mem_ptr(p)->b32.s1 = q; p = q; q = LLIST_link(q); - mem[p].b32.s1 = TEX_NULL; + mem_ptr(p)->b32.s1 = TEX_NULL; goto done; } break; @@ -3324,38 +3325,38 @@ mlist_to_hlist(void) break; } if (x != 0) { - y = math_glue(eqtb[GLUE_BASE + x].b32.s1, cur_mu); + y = math_glue(eqtb_ptr(GLUE_BASE + x)->b32.s1, cur_mu); z = new_glue(y); - mem[y].b32.s1 = TEX_NULL; - mem[p].b32.s1 = z; + mem_ptr(y)->b32.s1 = TEX_NULL; + mem_ptr(p)->b32.s1 = z; p = z; - mem[z].b16.s0 = x + 1; + mem_ptr(z)->b16.s0 = x + 1; } } - if (mem[q + 1].b32.s1 != TEX_NULL) { - mem[p].b32.s1 = mem[q + 1].b32.s1; + if (mem(q + 1).b32.s1 != TEX_NULL) { + mem_ptr(p)->b32.s1 = mem(q + 1).b32.s1; do { p = LLIST_link(p); - } while (!(mem[p].b32.s1 == TEX_NULL)); + } while (!(mem(p).b32.s1 == TEX_NULL)); } if (penalties) { - if (mem[q].b32.s1 != TEX_NULL) { + if (mem(q).b32.s1 != TEX_NULL) { if (pen < INF_PENALTY) { - r_type = mem[mem[q].b32.s1].b16.s1; + r_type = mem(mem(q).b32.s1).b16.s1; if (r_type != PENALTY_NODE) { if (r_type != REL_NOAD) { z = new_penalty(pen); - mem[p].b32.s1 = z; + mem_ptr(p)->b32.s1 = z; p = z; } } } } } - if (mem[q].b16.s1 == RIGHT_NOAD) + if (mem(q).b16.s1 == RIGHT_NOAD) t = OPEN_NOAD; r_type = t; lab83: /*delete_q */ r = q; @@ -3385,8 +3386,8 @@ var_delimiter(int32_t d, int32_t s, scaled_t v) f = FONT_BASE; w = 0; large_attempt = false; - z = (mem[d].b16.s3 % 256); - x = (mem[d].b16.s2 + (mem[d].b16.s3 / 256) * 65536L); + z = (mem(d).b16.s3 % 256); + x = (mem(d).b16.s2 + (mem(d).b16.s3 / 256) * 65536L); ot_assembly_ptr = NULL; while (true) { @@ -3449,8 +3450,8 @@ var_delimiter(int32_t d, int32_t s, scaled_t v) if (large_attempt) goto found; large_attempt = true; - z = (mem[d].b16.s1 % 256); - x = (mem[d].b16.s0 + (mem[d].b16.s1 / 256) * 65536L); + z = (mem(d).b16.s1 % 256); + x = (mem(d).b16.s0 + (mem(d).b16.s1 / 256) * 65536L); } found: if (f != FONT_BASE) { @@ -3464,7 +3465,7 @@ var_delimiter(int32_t d, int32_t s, scaled_t v) u = height_plus_depth(f, c); w = 0; q = FONT_CHARACTER_INFO(f, effective_char(true, f, c)); - mem[b + 1].b32.s1 = FONT_CHARINFO_WIDTH(f, q) + FONT_CHARINFO_ITALCORR(f, q); + mem_ptr(b + 1)->b32.s1 = FONT_CHARINFO_WIDTH(f, q) + FONT_CHARINFO_ITALCORR(f, q); c = r.s1; if (c != 0) w = w + height_plus_depth(f, c); @@ -3513,7 +3514,7 @@ var_delimiter(int32_t d, int32_t s, scaled_t v) c = r.s3; if (c != 0) stack_into_box(b, f, c); - mem[b + 2].b32.s1 = w - mem[b + 3].b32.s1; + mem_ptr(b + 2)->b32.s1 = w - mem(b + 3).b32.s1; } else b = char_box(f, c) /*:736 */ ; } else { @@ -3524,23 +3525,23 @@ var_delimiter(int32_t d, int32_t s, scaled_t v) b = new_null_box(); NODE_type(b) = VLIST_NODE; - mem[b + 5].b32.s1 = get_node(GLYPH_NODE_SIZE); - NODE_type(mem[b + 5].b32.s1) = WHATSIT_NODE; - mem[mem[b + 5].b32.s1].b16.s0 = GLYPH_NODE; - mem[mem[b + 5].b32.s1 + 4].b16.s2 = f; - mem[mem[b + 5].b32.s1 + 4].b16.s1 = c; - set_native_glyph_metrics(mem[b + 5].b32.s1, 1); - mem[b + 1].b32.s1 = mem[mem[b + 5].b32.s1 + 1].b32.s1; - mem[b + 3].b32.s1 = mem[mem[b + 5].b32.s1 + 3].b32.s1; - mem[b + 2].b32.s1 = mem[mem[b + 5].b32.s1 + 2].b32.s1; + mem_ptr(b + 5)->b32.s1 = get_node(GLYPH_NODE_SIZE); + NODE_type(mem(b + 5).b32.s1) = WHATSIT_NODE; + mem_ptr(mem(b + 5).b32.s1)->b16.s0 = GLYPH_NODE; + mem_ptr(mem(b + 5).b32.s1 + 4)->b16.s2 = f; + mem_ptr(mem(b + 5).b32.s1 + 4)->b16.s1 = c; + set_native_glyph_metrics(mem(b + 5).b32.s1, 1); + mem_ptr(b + 1)->b32.s1 = mem(mem(b + 5).b32.s1 + 1).b32.s1; + mem_ptr(b + 3)->b32.s1 = mem(mem(b + 5).b32.s1 + 3).b32.s1; + mem_ptr(b + 2)->b32.s1 = mem(mem(b + 5).b32.s1 + 2).b32.s1; } } } else { b = new_null_box(); - mem[b + 1].b32.s1 = DIMENPAR(null_delimiter_space); + mem_ptr(b + 1)->b32.s1 = DIMENPAR(null_delimiter_space); } - mem[b + 4].b32.s1 = half(mem[b + 3].b32.s1 - mem[b + 2].b32.s1) - axis_height(s); + mem_ptr(b + 4)->b32.s1 = half(mem(b + 3).b32.s1 - mem(b + 2).b32.s1) - axis_height(s); free_ot_assembly(ot_assembly_ptr); return b; } @@ -3554,25 +3555,25 @@ char_box(internal_font_number f, int32_t c) if (((font_area[f] == AAT_FONT_FLAG) || (font_area[f] == OTGR_FONT_FLAG))) { b = new_null_box(); p = new_native_character(f, c); - mem[b + 5].b32.s1 = p; - mem[b + 3].b32.s1 = mem[p + 3].b32.s1; - mem[b + 1].b32.s1 = mem[p + 1].b32.s1; - if (mem[p + 2].b32.s1 < 0) - mem[b + 2].b32.s1 = 0; + mem_ptr(b + 5)->b32.s1 = p; + mem_ptr(b + 3)->b32.s1 = mem(p + 3).b32.s1; + mem_ptr(b + 1)->b32.s1 = mem(p + 1).b32.s1; + if (mem(p + 2).b32.s1 < 0) + mem_ptr(b + 2)->b32.s1 = 0; else - mem[b + 2].b32.s1 = mem[p + 2].b32.s1; + mem_ptr(b + 2)->b32.s1 = mem(p + 2).b32.s1; } else { q = FONT_CHARACTER_INFO(f, effective_char(true, f, c)); b = new_null_box(); - mem[b + 1].b32.s1 = FONT_CHARINFO_WIDTH(f, q) + FONT_CHARINFO_ITALCORR(f, q); - mem[b + 3].b32.s1 = FONT_CHARINFO_HEIGHT(f, q); - mem[b + 2].b32.s1 = FONT_CHARINFO_DEPTH(f, q); + mem_ptr(b + 1)->b32.s1 = FONT_CHARINFO_WIDTH(f, q) + FONT_CHARINFO_ITALCORR(f, q); + mem_ptr(b + 3)->b32.s1 = FONT_CHARINFO_HEIGHT(f, q); + mem_ptr(b + 2)->b32.s1 = FONT_CHARINFO_DEPTH(f, q); p = get_avail(); - mem[p].b16.s0 = c; - mem[p].b16.s1 = f; + mem_ptr(p)->b16.s0 = c; + mem_ptr(p)->b16.s1 = f; } - mem[b + 5].b32.s1 = p; + mem_ptr(b + 5)->b32.s1 = p; return b; } @@ -3582,9 +3583,9 @@ stack_into_box(int32_t b, internal_font_number f, uint16_t c) { int32_t p; p = char_box(f, c); - mem[p].b32.s1 = mem[b + 5].b32.s1; - mem[b + 5].b32.s1 = p; - mem[b + 3].b32.s1 = mem[p + 3].b32.s1; + mem_ptr(p)->b32.s1 = mem(b + 5).b32.s1; + mem_ptr(b + 5)->b32.s1 = p; + mem_ptr(b + 3)->b32.s1 = mem(p + 3).b32.s1; } @@ -3602,31 +3603,31 @@ stack_glyph_into_box(int32_t b, internal_font_number f, int32_t g) int32_t p, q; p = get_node(GLYPH_NODE_SIZE); NODE_type(p) = WHATSIT_NODE; - mem[p].b16.s0 = GLYPH_NODE; - mem[p + 4].b16.s2 = f; - mem[p + 4].b16.s1 = g; + mem_ptr(p)->b16.s0 = GLYPH_NODE; + mem_ptr(p + 4)->b16.s2 = f; + mem_ptr(p + 4)->b16.s1 = g; set_native_glyph_metrics(p, 1); if (NODE_type(b) == HLIST_NODE) { - q = mem[b + 5].b32.s1; + q = mem(b + 5).b32.s1; if (q == TEX_NULL) - mem[b + 5].b32.s1 = p; + mem_ptr(b + 5)->b32.s1 = p; else { - while (mem[q].b32.s1 != TEX_NULL) + while (mem(q).b32.s1 != TEX_NULL) q = LLIST_link(q); - mem[q].b32.s1 = p; - if ((mem[b + 3].b32.s1 < mem[p + 3].b32.s1)) - mem[b + 3].b32.s1 = mem[p + 3].b32.s1; - if ((mem[b + 2].b32.s1 < mem[p + 2].b32.s1)) - mem[b + 2].b32.s1 = mem[p + 2].b32.s1; + mem_ptr(q)->b32.s1 = p; + if ((mem(b + 3).b32.s1 < mem(p + 3).b32.s1)) + mem_ptr(b + 3)->b32.s1 = mem(p + 3).b32.s1; + if ((mem(b + 2).b32.s1 < mem(p + 2).b32.s1)) + mem_ptr(b + 2)->b32.s1 = mem(p + 2).b32.s1; } } else { - mem[p].b32.s1 = mem[b + 5].b32.s1; - mem[b + 5].b32.s1 = p; - mem[b + 3].b32.s1 = mem[p + 3].b32.s1; - if ((mem[b + 1].b32.s1 < mem[p + 1].b32.s1)) - mem[b + 1].b32.s1 = mem[p + 1].b32.s1; + mem_ptr(p)->b32.s1 = mem(b + 5).b32.s1; + mem_ptr(b + 5)->b32.s1 = p; + mem_ptr(b + 3)->b32.s1 = mem(p + 3).b32.s1; + if ((mem(b + 1).b32.s1 < mem(p + 1).b32.s1)) + mem_ptr(b + 1)->b32.s1 = mem(p + 1).b32.s1; } } @@ -3636,25 +3637,25 @@ stack_glue_into_box(int32_t b, scaled_t min, scaled_t max) { int32_t p, q; q = new_spec(0); - mem[q + 1].b32.s1 = min; - mem[q + 2].b32.s1 = max - min; + mem_ptr(q + 1)->b32.s1 = min; + mem_ptr(q + 2)->b32.s1 = max - min; p = new_glue(q); if (NODE_type(b) == HLIST_NODE) { - q = mem[b + 5].b32.s1; + q = mem(b + 5).b32.s1; if (q == TEX_NULL) - mem[b + 5].b32.s1 = p; + mem_ptr(b + 5)->b32.s1 = p; else { - while (mem[q].b32.s1 != TEX_NULL) + while (mem(q).b32.s1 != TEX_NULL) q = LLIST_link(q); - mem[q].b32.s1 = p; + mem_ptr(q)->b32.s1 = p; } } else { - mem[p].b32.s1 = mem[b + 5].b32.s1; - mem[b + 5].b32.s1 = p; - mem[b + 3].b32.s1 = mem[p + 3].b32.s1; - mem[b + 1].b32.s1 = mem[p + 1].b32.s1; + mem_ptr(p)->b32.s1 = mem(b + 5).b32.s1; + mem_ptr(b + 5)->b32.s1 = p; + mem_ptr(b + 3)->b32.s1 = mem(p + 3).b32.s1; + mem_ptr(b + 1)->b32.s1 = mem(p + 1).b32.s1; } } @@ -3765,19 +3766,19 @@ build_opentype_assembly(internal_font_number f, void *a, scaled_t s, bool horiz) } while (i++ < for_end); } - p = mem[b + 5].b32.s1; + p = mem(b + 5).b32.s1; nat = 0; str = 0; while (p != TEX_NULL) { if (NODE_type(p) == WHATSIT_NODE) { if (horiz) - nat = nat + mem[p + 1].b32.s1; + nat = nat + mem(p + 1).b32.s1; else - nat = nat + mem[p + 3].b32.s1 + mem[p + 2].b32.s1; + nat = nat + mem(p + 3).b32.s1 + mem(p + 2).b32.s1; } else if (NODE_type(p) == GLUE_NODE) { - nat = nat + mem[mem[p + 1].b32.s0 + 1].b32.s1; - str = str + mem[mem[p + 1].b32.s0 + 2].b32.s1; + nat = nat + mem(mem(p + 1).b32.s0 + 1).b32.s1; + str = str + mem(mem(p + 1).b32.s0 + 2).b32.s1; } p = LLIST_link(p); } @@ -3786,17 +3787,17 @@ build_opentype_assembly(internal_font_number f, void *a, scaled_t s, bool horiz) o = (s - nat); if ((o > str)) o = str; - mem[b + 5].b16.s0 = NORMAL; - mem[b + 5].b16.s1 = STRETCHING; + mem_ptr(b + 5)->b16.s0 = NORMAL; + mem_ptr(b + 5)->b16.s1 = STRETCHING; BOX_glue_set(b) = o / ((double)str); if (horiz) - mem[b + 1].b32.s1 = nat + tex_round(str * BOX_glue_set(b)); + mem_ptr(b + 1)->b32.s1 = nat + tex_round(str * BOX_glue_set(b)); else - mem[b + 3].b32.s1 = nat + tex_round(str * BOX_glue_set(b)); + mem_ptr(b + 3)->b32.s1 = nat + tex_round(str * BOX_glue_set(b)); } else if (horiz) - mem[b + 1].b32.s1 = nat; + mem_ptr(b + 1)->b32.s1 = nat; else - mem[b + 3].b32.s1 = nat; + mem_ptr(b + 3)->b32.s1 = nat; return b; } @@ -3807,27 +3808,27 @@ rebox(int32_t b, scaled_t w) int32_t p; internal_font_number f; scaled_t v; - if ((mem[b + 1].b32.s1 != w) && (mem[b + 5].b32.s1 != TEX_NULL)) { + if ((mem(b + 1).b32.s1 != w) && (mem(b + 5).b32.s1 != TEX_NULL)) { if (NODE_type(b) == VLIST_NODE) b = hpack(b, 0, ADDITIONAL); - p = mem[b + 5].b32.s1; - if (((is_char_node(p))) && (mem[p].b32.s1 == TEX_NULL)) { + p = mem(b + 5).b32.s1; + if (((is_char_node(p))) && (mem(p).b32.s1 == TEX_NULL)) { f = CHAR_NODE_font(p); v = FONT_CHARACTER_WIDTH(f, effective_char(true, f, CHAR_NODE_character(p))); - if (v != mem[b + 1].b32.s1) - mem[p].b32.s1 = new_kern(mem[b + 1].b32.s1 - v); + if (v != mem(b + 1).b32.s1) + mem_ptr(p)->b32.s1 = new_kern(mem(b + 1).b32.s1 - v); } free_node(b, BOX_NODE_SIZE); b = new_glue(12); - mem[b].b32.s1 = p; - while (mem[p].b32.s1 != TEX_NULL) + mem_ptr(b)->b32.s1 = p; + while (mem(p).b32.s1 != TEX_NULL) p = LLIST_link(p); - mem[p].b32.s1 = new_glue(12); + mem_ptr(p)->b32.s1 = new_glue(12); return hpack(b, w, EXACTLY); } else { - mem[b + 1].b32.s1 = w; + mem_ptr(b + 1)->b32.s1 = w; return b; } } diff --git a/crates/engine_xetex/xetex/xetex-output.c b/crates/engine_xetex/xetex/xetex-output.c deleted file mode 100644 index 85b49dc88..000000000 --- a/crates/engine_xetex/xetex/xetex-output.c +++ /dev/null @@ -1,768 +0,0 @@ -/* tectonic/output.c -- functions related to outputting messages - * Copyright 2016 the Tectonic Project - * Licensed under the MIT License. -*/ - -#include "xetex-core.h" -#include "xetex-xetexd.h" -#include "xetex-synctex.h" -#include "tectonic_bridge_core.h" - -static ttbc_diagnostic_t *current_diagnostic = 0; - -void -capture_to_diagnostic(ttbc_diagnostic_t *diagnostic) -{ - if (current_diagnostic) { - ttstub_diag_finish(current_diagnostic); - } - - current_diagnostic = diagnostic; -} - -static void -diagnostic_print_file_line(ttbc_diagnostic_t *diagnostic) -{ - // Add file/line number information - // This duplicates logic from print_file_line - - int32_t level = in_open; - while (level > 0 && full_source_filename_stack[level] == 0) - level--; - - if (level == 0) { - ttbc_diag_append(diagnostic, "!"); - } else { - int32_t source_line = line; - if (level != in_open) { - source_line = line_stack[level + 1]; - } - - char* filename = gettexstring(full_source_filename_stack[level]); - ttstub_diag_printf(diagnostic, "%s:%d: ", filename, source_line); - free(filename); - } -} - -ttbc_diagnostic_t * -diagnostic_begin_capture_warning_here(void) -{ - ttbc_diagnostic_t *warning = ttbc_diag_begin_warning(); - diagnostic_print_file_line(warning); - capture_to_diagnostic(warning); - return warning; -} - -// This replaces the "print file+line number" block at the start of errors -ttbc_diagnostic_t * -error_here_with_diagnostic(const char* message) -{ - ttbc_diagnostic_t *error = ttbc_diag_begin_error(); - diagnostic_print_file_line(error); - ttstub_diag_printf(error, "%s", message); - - if (file_line_error_style_p) - print_file_line(); - else - print_nl_cstr("! "); - print_cstr(message); - - capture_to_diagnostic(error); - - return error; -} - -static void -warn_char(int c) -{ - if (current_diagnostic) { - char bytes[2] = { c, 0 }; - ttbc_diag_append(current_diagnostic, bytes); - } -} - -void -print_ln(void) -{ - switch (selector) { - case SELECTOR_TERM_AND_LOG: - warn_char('\n'); - ttstub_output_putc(rust_stdout, '\n'); - ttstub_output_putc(log_file, '\n'); - term_offset = 0; - file_offset = 0; - break; - case SELECTOR_LOG_ONLY: - warn_char('\n'); - ttstub_output_putc(log_file, '\n'); - file_offset = 0; - break; - case SELECTOR_TERM_ONLY: - warn_char('\n'); - ttstub_output_putc(rust_stdout, '\n'); - term_offset = 0; - break; - case SELECTOR_NO_PRINT: - case SELECTOR_PSEUDO: - case SELECTOR_NEW_STRING: - break; - default: - ttstub_output_putc(write_file[selector], '\n'); - break; - } -} - - -void -print_raw_char(UTF16_code s, bool incr_offset) -{ - switch (selector) { - case SELECTOR_TERM_AND_LOG: - warn_char(s); - ttstub_output_putc(rust_stdout, s); - ttstub_output_putc(log_file, s); - if (incr_offset) { - term_offset++; - file_offset++; - } - if (term_offset == max_print_line) { - ttstub_output_putc(rust_stdout, '\n'); - term_offset = 0; - } - if (file_offset == max_print_line) { - ttstub_output_putc(log_file, '\n'); - file_offset = 0; - } - break; - case SELECTOR_LOG_ONLY: - warn_char(s); - ttstub_output_putc(log_file, s); - if (incr_offset) - file_offset++; - if (file_offset == max_print_line) { - ttstub_output_putc(log_file, '\n'); - file_offset = 0; - } - break; - case SELECTOR_TERM_ONLY: - warn_char(s); - ttstub_output_putc(rust_stdout, s); - if (incr_offset) - term_offset++; - if (term_offset == max_print_line) { - ttstub_output_putc(rust_stdout, '\n'); - term_offset = 0; - } - break; - case SELECTOR_NO_PRINT: - break; - case SELECTOR_PSEUDO: - if (tally < trick_count) - trick_buf[tally % error_line] = s; - break; - case SELECTOR_NEW_STRING: - if (pool_ptr < pool_size) { - str_pool[pool_ptr] = s; - pool_ptr++; - } - break; - default: - ttstub_output_putc(write_file[selector], s); - break; - } - tally++; -} - - -void -print_char(int32_t s) -{ - small_number l; - - if ((selector > SELECTOR_PSEUDO) && (!doing_special)) { - if (s >= 0x10000) { - print_raw_char(0xD800 + (s - 0x10000) / 1024, true); - print_raw_char(0xDC00 + (s - 0x10000) % 1024, true); - } else - print_raw_char(s, true); - return; - } - - if ( /*252: */ s == INTPAR(new_line_char) /*:252 */ ) { - if (selector < SELECTOR_PSEUDO) { - print_ln(); - return; - } - } - - if (s < 32 && !doing_special) { - print_raw_char('^' , true); - print_raw_char('^' , true); - print_raw_char(s + 64, true); - } else if (s < 127) { - print_raw_char(s, true); - } else if (s == 127) { - if (!doing_special) { - print_raw_char('^' , true); - print_raw_char('^' , true); - print_raw_char('?' , true); - } else { - print_raw_char(s, true); - } - } else if (s < 160 && !doing_special) { - print_raw_char('^' , true); - print_raw_char('^' , true); - - l = (s % 256) / 16; - if (l < 10) - print_raw_char('0' + l, true); - else - print_raw_char('a' + l - 10, true); - - l = s % 16; - if (l < 10) - print_raw_char('0' + l, true); - else - print_raw_char('a' + l - 10, true); - } else if (selector == SELECTOR_PSEUDO) { - print_raw_char(s, true); - } else { - if (s < 2048) { - print_raw_char(192 + s / 64, false); - print_raw_char(128 + s % 64, true); - } else if (s < 0x10000) { - print_raw_char(224 + (s / 4096), false); - print_raw_char(128 + (s % 4096) / 64, false); - print_raw_char(128 + (s % 64), true); - } else { - print_raw_char(240 + (s / 0x40000), false); - print_raw_char(128 + (s % 0x40000) / 4096, false); - print_raw_char(128 + (s % 4096) / 64, false); - print_raw_char(128 + (s % 64), true); - } - } -} - - -void -print(int32_t s) -{ - int32_t nl; - - if (s >= str_ptr) - return print_cstr("???"); - else if (s <= BIGGEST_CHAR) { - if (s < 0) - return print_cstr("???"); - else { - if (selector > SELECTOR_PSEUDO) { - print_char(s); - return; - } - - if ( /*252: */ s == INTPAR(new_line_char) /*:252 */ ) { - if (selector < SELECTOR_PSEUDO) { - print_ln(); - return; - } - } - - nl = INTPAR(new_line_char); - INTPAR(new_line_char) = -1; - print_char(s); - INTPAR(new_line_char) = nl; - return; - } - } - - int32_t pool_idx = s - 0x10000; - - for (pool_pointer i = str_start[pool_idx]; i < str_start[pool_idx + 1]; i++) { - if ( - (str_pool[i] >= 0xD800) && - (str_pool[i] < 0xDC00) && - (i + 1 < str_start[pool_idx + 1]) && - (str_pool[i + 1] >= 0xDC00) && - (str_pool[i + 1] < 0xE000) - ) { - print_char( - 0x10000 + - (str_pool[i] - 0xD800) * 1024 + - str_pool[i + 1] - 0xDC00 - ); - i++; - } else { - print_char(str_pool[i]); - } - } -} - - -void -print_cstr(const char* str) -{ - for (unsigned int i = 0; i < strlen(str); i++) { - print_char(str[i]); - } -} - - -void -print_nl(str_number s) -{ - if (((term_offset > 0) && (odd(selector))) || ((file_offset > 0) && (selector >= SELECTOR_LOG_ONLY))) - print_ln(); - print(s); -} - -void -print_nl_cstr(const char* str) -{ - if (((term_offset > 0) && (odd(selector))) || ((file_offset > 0) && (selector >= SELECTOR_LOG_ONLY))) - print_ln(); - print_cstr(str); -} - - -void -print_esc(str_number s) -{ - - int32_t c = INTPAR(escape_char) /*:251 */ ; - - if (c >= 0 && c <= BIGGEST_USV) - print_char(c); - print(s); -} - -void -print_esc_cstr(const char* s) -{ - - int32_t c = INTPAR(escape_char) /*:251 */ ; - - if (c >= 0 && c <= BIGGEST_USV) - print_char(c); - print_cstr(s); -} - - -static void -print_the_digs(eight_bits k) -{ - while (k > 0) { - k--; - if (dig[k] < 10) - print_char('0' + dig[k]); - else - print_char(55 /*"A" -10 */ + dig[k]); - } -} - - -void -print_int(int32_t n) -{ - unsigned char k = 0; - int32_t m; - - if (n < 0) { - print_char('-'); - if (n > -100000000L) - n = -(int32_t) n; - else { - m = -1 - n; - n = m / 10; - m = (m % 10) + 1; - k = 1; - if (m < 10) - dig[0] = m; - else { - dig[0] = 0; - n++; - } - } - } - - do { - dig[k] = n % 10; - n = n / 10; - k++; - } while (!(n == 0)); - - print_the_digs(k); -} - - -void -print_cs(int32_t p) -{ - if (p < HASH_BASE) { - if (p >= SINGLE_BASE) { - if (p == NULL_CS) { - print_esc_cstr("csname"); - print_esc_cstr("endcsname"); - print_char(' '); - } else { - print_esc(p - SINGLE_BASE); - if (CAT_CODE(p - SINGLE_BASE) == LETTER) - print_char(' '); - } - } else if (p < ACTIVE_BASE) - print_esc_cstr("IMPOSSIBLE."); - else - print_char(p - 1); - } else if (((p >= UNDEFINED_CONTROL_SEQUENCE) && (p <= EQTB_SIZE)) || (p > eqtb_top)) { - print_esc_cstr("IMPOSSIBLE."); - } else if (hash[p].s1 >= str_ptr) { - print_esc_cstr("NONEXISTENT."); - } else { - if (p >= PRIM_EQTB_BASE && p < FROZEN_NULL_FONT) - print_esc(prim[p - PRIM_EQTB_BASE].s1 - 1); - else - print_esc(hash[p].s1); - print_char(' '); - } -} - - -void -sprint_cs(int32_t p) -{ - if (p < HASH_BASE) { - if (p < SINGLE_BASE) - print_char(p - 1); - else if (p < NULL_CS) - print_esc(p - SINGLE_BASE); - else { - print_esc_cstr("csname"); - print_esc_cstr("endcsname"); - } - } else if (p >= PRIM_EQTB_BASE && p < FROZEN_NULL_FONT) { - print_esc(prim[p - PRIM_EQTB_BASE].s1 - 1); - } else { - print_esc(hash[p].s1); - } -} - - -void -print_file_name(int32_t n, int32_t a, int32_t e) -{ - bool must_quote = false; - int32_t quote_char = 0; - pool_pointer j; - - if (a != 0) { - j = str_start[(a) - 0x10000]; - while (((!must_quote) || (quote_char == 0)) && (j < str_start[(a + 1) - 0x10000])) { - if (str_pool[j] == ' ' ) - must_quote = true; - else if ((str_pool[j] == '"' ) || (str_pool[j] == '\'' )) { - must_quote = true; - quote_char = 73 /*""" 39 */ - str_pool[j]; - } - j++; - } - } - - if (n != 0) { - j = str_start[(n) - 0x10000]; - while (((!must_quote) || (quote_char == 0)) && (j < str_start[(n + 1) - 0x10000])) { - if (str_pool[j] == ' ' ) - must_quote = true; - else if ((str_pool[j] == '"' ) || (str_pool[j] == '\'' )) { - must_quote = true; - quote_char = 73 /*""" 39 */ - str_pool[j]; - } - j++; - } - } - - if (e != 0) { - j = str_start[(e) - 0x10000]; - while (((!must_quote) || (quote_char == 0)) && (j < str_start[(e + 1) - 0x10000])) { - if (str_pool[j] == ' ' ) - must_quote = true; - else if ((str_pool[j] == '"' ) || (str_pool[j] == '\'' )) { - must_quote = true; - quote_char = 73 /*""" 39 */ - str_pool[j]; - } - j++; - } - } - - if (must_quote) { - if (quote_char == 0) - quote_char = '"' ; - print_char(quote_char); - } - - if (a != 0) { - register int32_t for_end; - j = str_start[(a) - 0x10000]; - for_end = str_start[(a + 1) - 0x10000] - 1; - if (j <= for_end) - do { - if (str_pool[j] == quote_char) { - print(quote_char); - quote_char = 73 /*""" 39 */ - quote_char; - print(quote_char); - } - print(str_pool[j]); - } - while (j++ < for_end); - } - - if (n != 0) { - register int32_t for_end; - j = str_start[(n) - 0x10000]; - for_end = str_start[(n + 1) - 0x10000] - 1; - if (j <= for_end) - do { - if (str_pool[j] == quote_char) { - print(quote_char); - quote_char = 73 /*""" 39 */ - quote_char; - print(quote_char); - } - print(str_pool[j]); - } - while (j++ < for_end); - } - - if (e != 0) { - register int32_t for_end; - j = str_start[(e) - 0x10000]; - for_end = str_start[(e + 1) - 0x10000] - 1; - if (j <= for_end) - do { - if (str_pool[j] == quote_char) { - print(quote_char); - quote_char = 73 /*""" 39 */ - quote_char; - print(quote_char); - } - print(str_pool[j]); - } - while (j++ < for_end); - } - - if (quote_char != 0) - print_char(quote_char); -} - - -void -print_size(int32_t s) -{ - if (s == TEXT_SIZE) - print_esc_cstr("textfont"); - else if (s == SCRIPT_SIZE) - print_esc_cstr("scriptfont"); - else - print_esc_cstr("scriptscriptfont"); -} - - -void -print_write_whatsit(const char* s, int32_t p) -{ - - print_esc_cstr(s); - - if (mem[p + 1].b32.s0 < 16) - print_int(mem[p + 1].b32.s0); - else if (mem[p + 1].b32.s0 == 16) - print_char('*'); - else - print_char('-'); -} - - -void -print_native_word(int32_t p) -{ - int32_t i, c, cc; - int32_t for_end = mem[p + 4].b16.s1 - 1; - - for (i = 0; i <= for_end; i++) { - c = NATIVE_NODE_text(p)[i]; - if ((c >= 0xD800) && (c < 0xDC00)) { - if (i < mem[p + 4].b16.s1 - 1) { - cc = NATIVE_NODE_text(p)[i + 1]; - if ((cc >= 0xDC00) && (cc < 0xE000)) { - c = 0x10000 + (c - 0xD800) * 1024 + (cc - 0xDC00); - print_char(c); - i++; - } else - print('.'); - } else - print('.'); - } else - print_char(c); - } -} - - -void -print_sa_num(int32_t q) -{ - int32_t n; - - if (mem[q].b16.s1 < DIMEN_VAL_LIMIT) - n = mem[q + 1].b32.s1; - else { - n = mem[q].b16.s1 % 64; - q = LLIST_link(q); - n = n + 64 * mem[q].b16.s1; - q = LLIST_link(q); - n = n + 64 * 64 * (mem[q].b16.s1 + 64 * mem[mem[q].b32.s1].b16.s1); - } - - print_int(n); -} - - -void -print_file_line(void) -{ - int32_t level = in_open; - - while ((level > 0) && (full_source_filename_stack[level] == 0)) - level--; - - if (level == 0) - print_nl_cstr("! "); - else { - print_nl_cstr(""); - print(full_source_filename_stack[level]); - print(':'); - if (level == in_open) - print_int(line); - else - print_int(line_stack[level + 1]); - print_cstr(": "); - } -} -/*:1660*/ - - -void -print_two(int32_t n) -{ - n = abs(n) % 100; - print_char('0' + (n / 10)); - print_char('0' + (n % 10)); -} - - -void -print_hex(int32_t n) -{ - unsigned char k = 0; - - print_char('"'); - - do { - dig[k] = n % 16; - n = n / 16; - k++; - } while (n != 0); - - print_the_digs(k); -} - - -void -print_roman_int(int32_t n) -{ - int32_t u, v; - - const char* roman_data = "m2d5c2l5x2v5i"; - unsigned char j = 0; - unsigned char k = 0; - v = 1000; - - while (true) { - while (n >= v) { - print_char(roman_data[j]); - n = n - v; - } - - if (n <= 0) - return; - - k = j + 2; - u = v / (roman_data[k - 1] - '0'); - if (roman_data[k - 1] == '2' ) { - k = k + 2; - u = u / (roman_data[k - 1] - '0'); - } - - if (n + u >= v) { - print_char(roman_data[k]); - n = n + u; - } else { - j = j + 2; - v = v / (roman_data[j - 1] - '0'); - } - } -} - - -void -print_current_string(void) -{ - pool_pointer j = str_start[str_ptr - 0x10000]; - - while (j < pool_ptr) { - print_char(str_pool[j]); - j++; - } -} - - -void -print_scaled(scaled_t s) -{ - scaled_t delta; - - if (s < 0) { - print_char('-'); - s = -(int32_t) s; - } - - print_int(s / 0x10000); - print_char('.'); - s = 10 * (s % 0x10000) + 5; - delta = 10; - - do { - if (delta > 0x10000) - s = s + 0x8000 - 50000; - print_char('0' + (s / 0x10000)); - s = 10 * (s % 0x10000); - delta = delta * 10; - } while (s > delta); -} - - -void -print_ucs_code(UnicodeScalar n) -{ - unsigned char k = 0; - - print_cstr("U+"); - - do { - dig[k] = n % 16; - n = n / 16; - k++; - } while (n != 0); - - while (k < 4) { - dig[k] = 0; - k++; - } - - print_the_digs(k); -} diff --git a/crates/engine_xetex/xetex/xetex-pagebuilder.c b/crates/engine_xetex/xetex/xetex-pagebuilder.c index 4e1e87f69..78c8c767f 100644 --- a/crates/engine_xetex/xetex/xetex-pagebuilder.c +++ b/crates/engine_xetex/xetex/xetex-pagebuilder.c @@ -14,6 +14,7 @@ #include "xetex-core.h" #include "xetex-xetexd.h" +#include "xetex_bindings.h" static int32_t best_page_break; @@ -366,7 +367,7 @@ fire_up(int32_t c) push_nest(); cur_list.mode = -VMODE; cur_list.aux.b32.s1 = IGNORE_DEPTH; /* this is `prev_depth` */ - cur_list.mode_line = -line; + cur_list.mode_line = -line(); begin_token_list(LOCAL(output_routine), OUTPUT_TEXT); new_save_level(OUTPUT_GROUP); normal_paragraph(); diff --git a/crates/engine_xetex/xetex/xetex-pic.c b/crates/engine_xetex/xetex/xetex-pic.c index 826e9f339..b0bd7ba3c 100644 --- a/crates/engine_xetex/xetex/xetex-pic.c +++ b/crates/engine_xetex/xetex/xetex-pic.c @@ -79,11 +79,11 @@ count_pdf_file_pages (void) rust_input_handle_t handle; pdf_file *pf; - handle = ttstub_input_open (name_of_file, TTBC_FILE_FORMAT_PICT, 0); + handle = ttstub_input_open (name_of_file(), TTBC_FILE_FORMAT_PICT, 0); if (handle == INVALID_HANDLE) return 0; - if ((pf = pdf_open(name_of_file, handle)) == NULL) { + if ((pf = pdf_open(name_of_file(), handle)) == NULL) { /* TODO: issue warning */ ttstub_input_close(handle); return 0; @@ -226,7 +226,7 @@ find_pic_file (char **path, real_rect *bounds, int pdfBoxType, int page) int err = -1; rust_input_handle_t handle; - handle = ttstub_input_open (name_of_file, TTBC_FILE_FORMAT_PICT, 0); + handle = ttstub_input_open (name_of_file(), TTBC_FILE_FORMAT_PICT, 0); bounds->x = bounds->y = bounds->wd = bounds->ht = 0.0; if (handle == INVALID_HANDLE) @@ -234,7 +234,7 @@ find_pic_file (char **path, real_rect *bounds, int pdfBoxType, int page) if (pdfBoxType != 0) { /* if cmd was \XeTeXpdffile, use xpdflib to read it */ - err = pdf_get_rect (name_of_file, handle, page, pdfBoxType, bounds); + err = pdf_get_rect (name_of_file(), handle, page, pdfBoxType, bounds); } else { /* Tectonic customization: if we use single-precision math, we can * sometimes get numerical results that vary depending on whether we're @@ -246,7 +246,7 @@ find_pic_file (char **path, real_rect *bounds, int pdfBoxType, int page) } if (err == 0) - *path = xstrdup(name_of_file); + *path = xstrdup(name_of_file()); ttstub_input_close (handle); @@ -347,7 +347,7 @@ load_picture(bool is_pdf) int32_t pdf_box_type; int32_t result; scan_file_name(); - pack_file_name(cur_name, cur_area, cur_ext); + pack_file_name(cur_name(), cur_area(), cur_ext()); pdf_box_type = 0; page = 0; if (is_pdf) { @@ -623,26 +623,26 @@ load_picture(bool is_pdf) new_whatsit(PIC_NODE, PIC_NODE_SIZE + (strlen(pic_path) + sizeof(memory_word) - 1) / sizeof(memory_word)); if (is_pdf) { - mem[cur_list.tail].b16.s0 = PDF_NODE; + mem_ptr(cur_list.tail)->b16.s0 = PDF_NODE; } PIC_NODE_path_len(cur_list.tail) = strlen(pic_path); - mem[cur_list.tail + 4].b16.s0 = page; - mem[cur_list.tail + 8].b16.s1 = pdf_box_type; - mem[cur_list.tail + 1].b32.s1 = D2Fix(xmax - xmin); - mem[cur_list.tail + 3].b32.s1 = D2Fix(ymax - ymin); - mem[cur_list.tail + 2].b32.s1 = 0; - mem[cur_list.tail + 5].b32.s0 = D2Fix(t.a); - mem[cur_list.tail + 5].b32.s1 = D2Fix(t.b); - mem[cur_list.tail + 6].b32.s0 = D2Fix(t.c); - mem[cur_list.tail + 6].b32.s1 = D2Fix(t.d); - mem[cur_list.tail + 7].b32.s0 = D2Fix(t.x); - mem[cur_list.tail + 7].b32.s1 = D2Fix(t.y); + mem_ptr(cur_list.tail + 4)->b16.s0 = page; + mem_ptr(cur_list.tail + 8)->b16.s1 = pdf_box_type; + mem_ptr(cur_list.tail + 1)->b32.s1 = D2Fix(xmax - xmin); + mem_ptr(cur_list.tail + 3)->b32.s1 = D2Fix(ymax - ymin); + mem_ptr(cur_list.tail + 2)->b32.s1 = 0; + mem_ptr(cur_list.tail + 5)->b32.s0 = D2Fix(t.a); + mem_ptr(cur_list.tail + 5)->b32.s1 = D2Fix(t.b); + mem_ptr(cur_list.tail + 6)->b32.s0 = D2Fix(t.c); + mem_ptr(cur_list.tail + 6)->b32.s1 = D2Fix(t.d); + mem_ptr(cur_list.tail + 7)->b32.s0 = D2Fix(t.x); + mem_ptr(cur_list.tail + 7)->b32.s1 = D2Fix(t.y); memcpy(PIC_NODE_path(cur_list.tail), pic_path, strlen(pic_path)); free(pic_path); } else { error_here_with_diagnostic("Unable to load picture or PDF file '"); - print_file_name(cur_name, cur_area, cur_ext); + print_file_name(cur_name(), cur_area(), cur_ext()); print('\''); capture_to_diagnostic(NULL); if (result == -43) { diff --git a/crates/engine_xetex/xetex/xetex-scaledmath.c b/crates/engine_xetex/xetex/xetex-scaledmath.c index 98163002f..752fc58ba 100644 --- a/crates/engine_xetex/xetex/xetex-scaledmath.c +++ b/crates/engine_xetex/xetex/xetex-scaledmath.c @@ -5,285 +5,9 @@ #include "xetex-core.h" #include "xetex-xetexd.h" - +#include "xetex_bindings.h" int32_t -tex_round (double r) -{ - /* We must reproduce very particular rounding semantics to pass the TRIP - * test. Specifically, values within the 32-bit range of TeX int32_ts are - * rounded to the nearest int32_t with half-integral values going away - * from zero: 0.5 => 1, -0.5 => -1. - * - * `r` does not necessarily lie within the range of a 32-bit TeX int32_t; - * if it doesn't, we clip. The following LaTeX document allegedly triggers - * that codepath: - * - * \documentstyle{article} - * \begin{document} - * \begin{flushleft} - * $\hbox{} $\hfill - * \filbreak - * \eject - * - */ - - if (r > 2147483647.0) /* 0x7FFFFFFF */ - return 2147483647; - - if (r < -2147483648.0) /* -0x80000000 */ - return -2147483648; - - /* ANSI defines the float-to-int32_t cast to truncate towards zero, so the - * following code is all that's necessary to get the desired behavior. The - * truncation technically causes an uncaught "inexact" floating-point - * exception, but exception is virtually impossible to avoid in real - * code. */ - - if (r >= 0.0) - return (int32_t) (r + 0.5); - - return (int32_t) (r - 0.5); -} - - -int32_t -half(int32_t x) -{ - if (odd(x)) - return (x + 1) / 2; - return x / 2; -} - - -scaled_t -mult_and_add(int32_t n, scaled_t x, scaled_t y, scaled_t max_answer) -{ - if (n < 0) { - x = -(int32_t) x; - n = -(int32_t) n; - } - - if (n == 0) - return y; - else if (x <= (max_answer - y) / n && (-(int32_t) x <= (max_answer + y) / n)) - return n * x + y; - else { - arith_error = true; - return 0; - } -} - - -scaled_t -x_over_n(scaled_t x, int32_t n) -{ - if (n == 0) { - arith_error = true; - tex_remainder = x; - return 0; - } else { - if (n < 0) { - // negative - x = -(int32_t) x; - n = -(int32_t) n; - tex_remainder = -(int32_t) tex_remainder; - } - - if (x >= 0) { - tex_remainder = x % n; - return x / n; - } else { - tex_remainder = -(int32_t) ((-(int32_t) x) % n); - return -(int32_t) ((-(int32_t) x) / n); - } - } -} - - -scaled_t -xn_over_d(scaled_t x, int32_t n, int32_t d) -{ - bool positive; - int32_t t, u, v; - - if (x >= 0) - positive = true; - else { - x = -(int32_t) x; - positive = false; - } - - t = (x % 32768L) * n; - u = (x / 32768L) * n + (t / 32768L); - v = (u % d) * 32768L + (t % 32768L); - - if (u / d >= 32768L) - arith_error = true; - else - u = 32768L * (u / d) + (v / d); - - if (positive) { - tex_remainder = v % d; - return u; - } else { - tex_remainder = -(int32_t) (v % d); - return -(int32_t) u; - } -} - - -scaled_t -round_xn_over_d(scaled_t x, int32_t n, int32_t d) -{ - bool positive; - int32_t t, u, v; - - if (x >= 0) { - positive = true; - } else { - x = -(int32_t) x; - positive = false; - } - t = (x % 32768L) * n; - u = (x / 32768L) * n + (t / 32768L); - v = (u % d) * 32768L + (t % 32768L); - if (u / d >= 32768L) - arith_error = true; - else - u = 32768L * (u / d) + (v / d); - v = v % d; - if (2 * v >= d) - u++; - if (positive) - return u; - else - return -(int32_t) u; -} - -static int32_t -make_frac(int32_t p, int32_t q) -{ - int32_t f; - int32_t n; - bool negative; - int32_t be_careful; - - if (p >= 0) - negative = false; - else { - p = -p; - negative = true; - } - - if (q <= 0) { - q = -q; - negative = !negative; - } - - n = p / q; - p = p % q; - - if (n >= 8) { - arith_error = true; - if (negative) - return -0x7FFFFFFF; - else - return 0x7FFFFFFF; - } else { - n = (n - 1) * 0x10000000; - f = 1; - - do { - be_careful = p - q; - p = be_careful + p; - if (p >= 0) - f = f + f + 1; - else { - f = f + f; - p = p + q; - } - } while (f < 0x10000000); - - be_careful = p - q; - if (be_careful + p >= 0) - f += 1; - - if (negative) - return -(f + n); - else - return f + n; - } -} - -static int32_t -take_frac(int32_t q, int32_t f) -{ - int32_t p; - bool negative; - int32_t n; - int32_t be_careful; - - if (f >= 0) - negative = false; - else { - f = -f; - negative = true; - } - - if (q < 0) { - q = -q; - negative = !negative; - } - - if (f < 0x10000000) - n = 0; - else { - n = f / 0x10000000; - f = f % 0x10000000; - - if (q <= 0x7FFFFFFF / n) - n = n * q; - else { - arith_error = true; - n = 0x7FFFFFFF; - } - } - - f = f + 0x10000000; - p = 0x08000000; - - if (q < 0x40000000) { - do { - if (odd(f)) - p = (p + q) / 2; - else - p = p / 2; - f = f / 2; - } while (f != 1); - } else { - do { - if (odd(f)) - p = p + (q - p) / 2; - else - p = p / 2; - f = f / 2; - } while (f != 1); /*:120 */ - } - - be_careful = n - 0x7FFFFFFF; - if (be_careful + p > 0) { - arith_error = true; - n = 0x7FFFFFFF - p; - } - - if (negative) - return -(n + p); - else - return n + p; -} - -static int32_t m_log(int32_t x) { int32_t y, z; @@ -327,187 +51,3 @@ m_log(int32_t x) return y / 8; } } - -static int32_t -ab_vs_cd(int32_t a, int32_t b, int32_t c, int32_t d) -{ - int32_t q, r; - - if (a < 0) { - a = -a; - b = -b; - } - - if (c < 0) { - c = -c; - d = -d; - } - - if (d <= 0) { - if (b >= 0) { - if ((a == 0 || b == 0) && (c == 0 || d == 0)) { - return 0; - } else { - return 1; - } - } - - if (d == 0) { - if (a == 0) { - return 0; - } else { - return -1; - } - } - - q = a; - a = c; - c = q; - q = -b; - b = -d; - d = q; - } else if (b <= 0) { - if (b < 0) { - if (a > 0) { - return -1; - } - } - - if (c == 0) { - return 0; - } else { - return -1; - } - } - - while (true) { - q = a / d; - r = c / b; - - if (q != r) { - if (q > r) { - return 1; - } else { - return -1; - } - } - - q = a % d; - r = c % b; - - if (r == 0) { - if (q == 0) { - return 0; - } else { - return 1; - } - } - - if (q == 0) { - return -1; - } - - a = b; - b = q; - c = d; - d = r; - } -} - -static void -new_randoms(void) -{ - unsigned char k; - int32_t x; - - for (k = 0; k < 24; k++) { - x = randoms[k] - randoms[k + 31]; - if (x < 0) - x = x + 0x10000000; - randoms[k] = x; - } - - for (k = 24; k < 55; k++) { - x = randoms[k] - randoms[k - 24]; - if (x < 0) - x = x + 0x10000000; - randoms[k] = x; - } - - j_random = 54; -} - -void -init_randoms(int32_t seed) -{ - int32_t j, jj, k; - unsigned char i; - - j = abs(seed); - - while (j >= 0x10000000) - j = j / 2; - - k = 1; - - for (i = 0; i < 55; i++) { - jj = k; - k = j - k; - j = jj; - if (k < 0) - k = k + 0x10000000; - randoms[(i * 21) % 55] = j; - } - - new_randoms(); - new_randoms(); - new_randoms(); -} - -int32_t -unif_rand(int32_t x) -{ - int32_t y; - - if (j_random == 0) - new_randoms(); - else - j_random--; - - y = take_frac(abs(x), randoms[j_random]); - if (y == abs(x)) - return 0; - else if (x > 0) - return y; - else - return -y; -} - -int32_t -norm_rand(void) -{ - int32_t x, u, l; - - do { - do { - if (j_random == 0) - new_randoms(); - else - j_random--; - - x = take_frac(112429L, randoms[j_random] - 0x08000000); - - if (j_random == 0) - new_randoms(); - else - j_random--; - - u = randoms[j_random]; - } while (abs(x) >= u); - - x = make_frac(x, u); - l = 139548960L - m_log(u); - } while (ab_vs_cd(1024, l, x, x) < 0); - - return x; -} diff --git a/crates/engine_xetex/xetex/xetex-shipout.c b/crates/engine_xetex/xetex/xetex-shipout.c index f90839d01..08fe99598 100644 --- a/crates/engine_xetex/xetex/xetex-shipout.c +++ b/crates/engine_xetex/xetex/xetex-shipout.c @@ -5,6 +5,7 @@ #include "xetex-core.h" #include "xetex-xetexd.h" #include "xetex-synctex.h" +#include "xetex_bindings.h" #include "tectonic_bridge_core.h" @@ -12,15 +13,9 @@ #define HALF_BUF 8192 #define FNT_NUM_0 171 /* DVI code */ -static rust_output_handle_t dvi_file; static str_number output_file_name; -static eight_bits *dvi_buf = NULL; -static int32_t dvi_limit; static int32_t g; static int32_t lq, lr; -static int32_t dvi_ptr; -static int32_t dvi_offset; -static int32_t dvi_gone; static int32_t down_ptr, right_ptr; static scaled_t dvi_h, dvi_v; static internal_font_number dvi_f; @@ -48,11 +43,11 @@ void initialize_shipout_variables(void) { output_file_name = 0; - dvi_buf = xmalloc_array(eight_bits, DVI_BUF_SIZE); - dvi_limit = DVI_BUF_SIZE; - dvi_ptr = 0; - dvi_offset = 0; - dvi_gone = 0; + resize_dvi_buf(DVI_BUF_SIZE); + set_dvi_limit(DVI_BUF_SIZE); + set_dvi_ptr(0); + set_dvi_offset(0); + set_dvi_gone(0); down_ptr = TEX_NULL; right_ptr = TEX_NULL; cur_s = -1; @@ -62,16 +57,16 @@ initialize_shipout_variables(void) void deinitialize_shipout_variables(void) { - free(dvi_buf); - dvi_buf = NULL; + clear_dvi_buf(); } static inline void dvi_out(eight_bits c) { - dvi_buf[dvi_ptr++] = c; - if (dvi_ptr == dvi_limit) + set_dvi_buf(dvi_ptr(), c); + set_dvi_ptr(dvi_ptr()+1); + if (dvi_ptr() == dvi_limit()) dvi_swap(); } @@ -89,7 +84,7 @@ ship_out(int32_t p) synctex_sheet(INTPAR(mag)); - if (job_name == 0) + if (job_name() == 0) open_log_file(); if (INTPAR(tracing_output) > 0) { @@ -98,9 +93,9 @@ ship_out(int32_t p) print_cstr("Completed box being shipped out"); } - if (term_offset > max_print_line - 9) + if (term_offset() > max_print_line - 9) print_ln(); - else if (term_offset > 0 || file_offset > 0) + else if (term_offset() > 0 || file_offset() > 0) print_char(' ' ); print_char('[' ); @@ -114,7 +109,7 @@ ship_out(int32_t p) print_char('.' ); } - ttstub_output_flush(rust_stdout); + ttstub_output_flush(rust_stdout()); if (INTPAR(tracing_output) > 0) { print_char(']' ); @@ -179,12 +174,12 @@ ship_out(int32_t p) /* ... resuming 637 ... open up the DVI file if needed */ if (output_file_name == 0) { - if (job_name == 0) + if (job_name() == 0) open_log_file(); pack_job_name(output_file_extension); - dvi_file = ttstub_output_open(name_of_file, 0); - if (dvi_file == INVALID_HANDLE) - _tt_abort("cannot open output file \"%s\"", name_of_file); + set_dvi_file(ttstub_output_open(name_of_file(), 0)); + if (dvi_file() == INVALID_HANDLE) + _tt_abort("cannot open output file \"%s\"", name_of_file()); output_file_name = make_name_string(); } @@ -212,7 +207,7 @@ ship_out(int32_t p) /* ... resuming 662 ... Emit per-page preamble. */ - page_loc = dvi_offset + dvi_ptr; + page_loc = dvi_offset() + dvi_ptr(); dvi_out(BOP); @@ -224,8 +219,8 @@ ship_out(int32_t p) /* Generate a PDF pagesize special unilaterally */ - old_setting = selector; - selector = SELECTOR_NEW_STRING; + old_setting = selector(); + set_selector(SELECTOR_NEW_STRING); print_cstr("pdf:pagesize "); if (DIMENPAR(pdf_page_width) <= 0 || DIMENPAR(pdf_page_height) <= 0) { print_cstr("default"); @@ -240,15 +235,15 @@ ship_out(int32_t p) print_scaled(DIMENPAR(pdf_page_height)); print_cstr("pt"); } - selector = old_setting; + set_selector(old_setting); dvi_out(XXX1); dvi_out(cur_length()); - for (s = str_start[str_ptr - TOO_BIG_CHAR]; s < pool_ptr; s++) - dvi_out(str_pool[s]); + for (s = str_start(str_ptr() - TOO_BIG_CHAR); s < pool_ptr(); s++) + dvi_out(str_pool(s)); - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); /* Done with the synthesized special. The meat: emit this page box. */ @@ -285,7 +280,7 @@ ship_out(int32_t p) print_char(']'); dead_cycles = 0; - ttstub_output_flush(rust_stdout); + ttstub_output_flush(rust_stdout()); flush_node_list(p); synctex_teehs(); } @@ -382,7 +377,7 @@ hlist_out(void) && !is_char_node(q) && NODE_type(q) == WHATSIT_NODE && (NODE_subtype(q) == NATIVE_WORD_NODE || NODE_subtype(q) == NATIVE_WORD_NODE_AT) - && (mem[q + 4].b16.s2 == mem[r + 4].b16.s2) + && (mem(q + 4).b16.s2 == mem(r + 4).b16.s2) ) { p = q; k += 1 + NATIVE_NODE_length(q); @@ -442,8 +437,8 @@ hlist_out(void) * and p to the last." */ if (p != r) { - if (pool_ptr + k > pool_size) - overflow("pool size", pool_size - init_pool_ptr); + if (pool_ptr() + k > pool_size()) + overflow("pool size", pool_size() - init_pool_ptr); k = 0; q = r; @@ -452,15 +447,15 @@ hlist_out(void) if (NODE_type(q) == WHATSIT_NODE) { if (NODE_subtype(q) == NATIVE_WORD_NODE || NODE_subtype(q) == NATIVE_WORD_NODE_AT) { for (j = 0; j < NATIVE_NODE_length(q); j++) { - str_pool[pool_ptr] = NATIVE_NODE_text(q)[j]; - pool_ptr++; + set_str_pool(pool_ptr(), NATIVE_NODE_text(q)[j]); + set_pool_ptr(pool_ptr()+1); } k += BOX_width(q); } } else if (NODE_type(q) == GLUE_NODE) { - str_pool[pool_ptr] = ' '; - pool_ptr++; + set_str_pool(pool_ptr(), ' '); + set_pool_ptr(pool_ptr()+1); g = GLUE_NODE_glue_ptr(q); k += BOX_width(g); @@ -487,7 +482,7 @@ hlist_out(void) NODE_subtype(q) = NODE_subtype(r); for (j = 0; j < cur_length(); j++) - NATIVE_NODE_text(q)[j] = str_pool[str_start[str_ptr - TOO_BIG_CHAR] + j]; + NATIVE_NODE_text(q)[j] = str_pool(str_start(str_ptr() - TOO_BIG_CHAR) + j); /* "Link q into the list in place of r...p" */ @@ -524,7 +519,7 @@ hlist_out(void) } flush_node_list(r); - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); p = q; } } @@ -546,7 +541,7 @@ hlist_out(void) if (cur_s > max_push) max_push = cur_s; - save_loc = dvi_offset + dvi_ptr; + save_loc = dvi_offset() + dvi_ptr(); base_line = cur_v; prev_p = this_box + 5; /* this is list_offset, the offset of the box list pointer */ @@ -1002,7 +997,7 @@ hlist_out(void) case LIGATURE_NODE: /* 675: "Make node p look like a char_node and goto reswitch" */ - mem[LIG_TRICK] = mem[p + 1]; /* = lig_char(p) */ + set_mem(LIG_TRICK, mem(p + 1)); /* = lig_char(p) */ LLIST_link(LIG_TRICK) = LLIST_link(p); p = LIG_TRICK; xtx_ligature_present = true; @@ -1135,7 +1130,7 @@ vlist_out(void) if (cur_s > max_push) max_push = cur_s; - save_loc = dvi_offset + dvi_ptr; + save_loc = dvi_offset() + dvi_ptr(); left_edge = cur_h; synctex_vlist(this_box); @@ -1360,7 +1355,7 @@ vlist_out(void) lq = rule_ht / leader_ht; lr = rule_ht % leader_ht; - if (mem[p].b16.s0 == C_LEADERS) + if (mem(p).b16.s0 == C_LEADERS) cur_v = cur_v + (lr / 2); else { lx = lr / (lq + 1); @@ -1583,8 +1578,8 @@ reverse(int32_t this_box, int32_t t, scaled_t *cur_g, double *cur_glue) rule_wd += *cur_g; - if ((g_sign == STRETCHING && mem[g].b16.s1 == g_order) - || (g_sign == SHRINKING && mem[g].b16.s0 == g_order)) { + if ((g_sign == STRETCHING && mem(g).b16.s1 == g_order) + || (g_sign == SHRINKING && mem(g).b16.s0 == g_order)) { if (GLUE_SPEC_ref_count(g) == TEX_NULL) free_node(g, GLUE_SPEC_SIZE); else @@ -1609,7 +1604,7 @@ reverse(int32_t this_box, int32_t t, scaled_t *cur_g, double *cur_glue) flush_node_list(LIGATURE_NODE_lig_ptr(p)); temp_ptr = p; p = get_avail(); - mem[p] = mem[temp_ptr + 1]; /* = mem[lig_char(temp_ptr)] */ + set_mem(p, mem(temp_ptr + 1)); /* = mem(lig_char(temp_ptr)) */ LLIST_link(p) = q; free_node(temp_ptr, SMALL_NODE_SIZE); goto reswitch; @@ -1724,23 +1719,23 @@ out_what(int32_t p) small_number j; unsigned char old_setting; - switch (mem[p].b16.s0) { + switch (mem(p).b16.s0) { case OPEN_NODE: case WRITE_NODE: case CLOSE_NODE: if (doing_leaders) break; - j = mem[p + 1].b32.s0; - if (mem[p].b16.s0 == WRITE_NODE) { + j = mem(p + 1).b32.s0; + if (mem(p).b16.s0 == WRITE_NODE) { write_out(p); break; } if (write_open[j]) - ttstub_output_close(write_file[j]); + ttstub_output_close(write_file(j)); - if (mem[p].b16.s0 == CLOSE_NODE) { + if (mem(p).b16.s0 == CLOSE_NODE) { write_open[j] = false; break; } @@ -1750,34 +1745,34 @@ out_what(int32_t p) if (j >= 16) break; - cur_name = mem[p + 1].b32.s1; - cur_area = mem[p + 2].b32.s0; - cur_ext = mem[p + 2].b32.s1; - if (length(cur_ext) == 0) - cur_ext = maketexstring(".tex"); + set_cur_name(mem(p + 1).b32.s1); + set_cur_area(mem(p + 2).b32.s0); + set_cur_ext(mem(p + 2).b32.s1); + if (length(cur_ext()) == 0) + set_cur_ext(maketexstring(".tex")); - pack_file_name(cur_name, cur_area, cur_ext); + pack_file_name(cur_name(), cur_area(), cur_ext()); - write_file[j] = ttstub_output_open(name_of_file, 0); - if (write_file[j] == INVALID_HANDLE) - _tt_abort("cannot open output file \"%s\"", name_of_file); + set_write_file(j, ttstub_output_open(name_of_file(), 0)); + if (write_file(j) == INVALID_HANDLE) + _tt_abort("cannot open output file \"%s\"", name_of_file()); write_open[j] = true; - if (log_opened) { - old_setting = selector; + if (log_opened()) { + old_setting = selector(); if (INTPAR(tracing_online) <= 0) - selector = SELECTOR_LOG_ONLY; + set_selector(SELECTOR_LOG_ONLY); else - selector = SELECTOR_TERM_AND_LOG; + set_selector(SELECTOR_TERM_AND_LOG); print_nl_cstr("\\openout"); print_int(j); print_cstr(" = `"); - print_file_name(cur_name, cur_area, cur_ext); + print_file_name(cur_name(), cur_area(), cur_ext()); print_cstr("'."); print_nl_cstr(""); print_ln(); - selector = old_setting; + set_selector(old_setting); } break; @@ -1835,12 +1830,12 @@ dvi_font_def(internal_font_number f) dvi_four(font_dsize[f]); dvi_out(length(font_area[f])); l = 0; - k = str_start[(font_name[f]) - 65536L]; + k = str_start((font_name[f]) - 65536L); - while ((l == 0) && (k < str_start[(font_name[f] + 1) - 65536L])) { + while ((l == 0) && (k < str_start((font_name[f] + 1) - 65536L))) { - if (str_pool[k] == ':' ) - l = k - str_start[(font_name[f]) - 65536L]; + if (str_pool(k) == ':' ) + l = k - str_start((font_name[f]) - 65536L); k++; } @@ -1851,22 +1846,22 @@ dvi_font_def(internal_font_number f) { register int32_t for_end; - k = str_start[(font_area[f]) - 65536L]; - for_end = str_start[(font_area[f] + 1) - 65536L] - 1; + k = str_start((font_area[f]) - 65536L); + for_end = str_start((font_area[f] + 1) - 65536L) - 1; if (k <= for_end) do { - dvi_out(str_pool[k]); + dvi_out(str_pool(k)); } while (k++ < for_end); } { register int32_t for_end; - k = str_start[(font_name[f]) - 65536L]; - for_end = str_start[(font_name[f]) - 65536L] + l - 1; + k = str_start((font_name[f]) - 65536L); + for_end = str_start((font_name[f]) - 65536L) + l - 1; if (k <= for_end) do { - dvi_out(str_pool[k]); + dvi_out(str_pool(k)); } while (k++ < for_end); } @@ -1882,35 +1877,35 @@ movement(scaled_t w, eight_bits o) int32_t k; q = get_node(MOVEMENT_NODE_SIZE); - mem[q + 1].b32.s1 = w; - mem[q + 2].b32.s1 = dvi_offset + dvi_ptr; + mem_ptr(q + 1)->b32.s1 = w; + mem_ptr(q + 2)->b32.s1 = dvi_offset() + dvi_ptr(); if (o == DOWN1) { - mem[q].b32.s1 = down_ptr; + mem_ptr(q)->b32.s1 = down_ptr; down_ptr = q; } else { - mem[q].b32.s1 = right_ptr; + mem_ptr(q)->b32.s1 = right_ptr; right_ptr = q; } - p = mem[q].b32.s1; + p = mem(q).b32.s1; mstate = MOV_NONE_SEEN; while (p != TEX_NULL) { - if (mem[p + 1].b32.s1 == w) { /*632:*/ - switch (mstate + mem[p].b32.s0) { + if (mem(p + 1).b32.s1 == w) { /*632:*/ + switch (mstate + mem(p).b32.s0) { case (MOV_NONE_SEEN + MOV_YZ_OK): case (MOV_NONE_SEEN + MOV_Y_OK): case (MOV_Z_SEEN + MOV_YZ_OK): case (MOV_Z_SEEN + MOV_Y_OK): - if (mem[p + 2].b32.s1 < dvi_gone) { + if (mem(p + 2).b32.s1 < dvi_gone()) { goto not_found; } else { /*633:*/ - k = mem[p + 2].b32.s1 - dvi_offset; + k = mem(p + 2).b32.s1 - dvi_offset(); if (k < 0) k = k + DVI_BUF_SIZE; - dvi_buf[k] = dvi_buf[k] + 5; - mem[p].b32.s0 = MOV_Y_HERE; + set_dvi_buf(k, dvi_buf(k) + 5); + mem_ptr(p)->b32.s0 = MOV_Y_HERE; goto found; } break; @@ -1918,14 +1913,14 @@ movement(scaled_t w, eight_bits o) case (MOV_NONE_SEEN + MOV_Z_OK): case (MOV_Y_SEEN + MOV_YZ_OK): case (MOV_Y_SEEN + MOV_Z_OK): - if (mem[p + 2].b32.s1 < dvi_gone) { + if (mem(p + 2).b32.s1 < dvi_gone()) { goto not_found; } else { /*634:*/ - k = mem[p + 2].b32.s1 - dvi_offset; + k = mem(p + 2).b32.s1 - dvi_offset(); if (k < 0) k = k + DVI_BUF_SIZE; - dvi_buf[k] = dvi_buf[k] + 10; - mem[p].b32.s0 = MOV_Z_HERE; + set_dvi_buf(k, dvi_buf(k) + 10); + mem_ptr(p)->b32.s0 = MOV_Z_HERE; goto found; } break; @@ -1941,7 +1936,7 @@ movement(scaled_t w, eight_bits o) break; } } else { - switch (mstate + mem[p].b32.s0) { + switch (mstate + mem(p).b32.s0) { case (MOV_NONE_SEEN + MOV_Y_HERE): mstate = MOV_Y_SEEN; break; @@ -1961,7 +1956,7 @@ movement(scaled_t w, eight_bits o) } not_found: - mem[q].b32.s0 = MOV_YZ_OK; + mem_ptr(q)->b32.s0 = MOV_YZ_OK; if (abs(w) >= 0x800000) { dvi_out(o + 3); @@ -2003,35 +1998,35 @@ movement(scaled_t w, eight_bits o) return; found: /*629:*/ - mem[q].b32.s0 = mem[p].b32.s0; + mem_ptr(q)->b32.s0 = mem(p).b32.s0; - if (mem[q].b32.s0 == MOV_Y_HERE) { + if (mem(q).b32.s0 == MOV_Y_HERE) { dvi_out(o + 4); - while (mem[q].b32.s1 != p) { + while (mem(q).b32.s1 != p) { q = LLIST_link(q); - switch (mem[q].b32.s0) { + switch (mem(q).b32.s0) { case MOV_YZ_OK: - mem[q].b32.s0 = MOV_Z_OK; + mem_ptr(q)->b32.s0 = MOV_Z_OK; break; case MOV_Y_OK: - mem[q].b32.s0 = MOV_D_FIXED; + mem_ptr(q)->b32.s0 = MOV_D_FIXED; break; } } } else { dvi_out(o + 9); - while (mem[q].b32.s1 != p) { + while (mem(q).b32.s1 != p) { q = LLIST_link(q); - switch (mem[q].b32.s0) { + switch (mem(q).b32.s0) { case MOV_YZ_OK: - mem[q].b32.s0 = MOV_Y_OK; + mem_ptr(q)->b32.s0 = MOV_Y_OK; break; case MOV_Z_OK: - mem[q].b32.s0 = MOV_D_FIXED; + mem_ptr(q)->b32.s0 = MOV_D_FIXED; break; } } @@ -2045,19 +2040,19 @@ prune_movements(int32_t l) int32_t p; while (down_ptr != TEX_NULL) { - if (mem[down_ptr + 2].b32.s1 < l) + if (mem(down_ptr + 2).b32.s1 < l) break; p = down_ptr; - down_ptr = mem[p].b32.s1; + down_ptr = mem(p).b32.s1; free_node(p, MOVEMENT_NODE_SIZE); } while (right_ptr != TEX_NULL) { - if (mem[right_ptr + 2].b32.s1 < l) + if (mem(right_ptr + 2).b32.s1 < l) return; p = right_ptr; - right_ptr = mem[p].b32.s1; + right_ptr = mem(p).b32.s1; free_node(p, MOVEMENT_NODE_SIZE); } } @@ -2077,14 +2072,14 @@ special_out(int32_t p) movement(cur_v - dvi_v, DOWN1); dvi_v = cur_v; } - doing_special = true; - old_setting = selector; - selector = SELECTOR_NEW_STRING ; - show_token_list(mem[mem[p + 1].b32.s1].b32.s1, TEX_NULL, pool_size - pool_ptr); - selector = old_setting; + set_doing_special(true); + old_setting = selector(); + set_selector(SELECTOR_NEW_STRING); + show_token_list(mem(mem(p + 1).b32.s1).b32.s1, TEX_NULL, pool_size() - pool_ptr()); + set_selector(old_setting); - if (pool_ptr + 1 > pool_size) - overflow("pool size", pool_size - init_pool_ptr); + if (pool_ptr() + 1 > pool_size()) + overflow("pool size", pool_size() - init_pool_ptr); if (cur_length() < 256) { dvi_out(XXX1); @@ -2096,16 +2091,16 @@ special_out(int32_t p) { register int32_t for_end; - k = str_start[str_ptr - TOO_BIG_CHAR]; - for_end = pool_ptr - 1; + k = str_start(str_ptr() - TOO_BIG_CHAR); + for_end = pool_ptr() - 1; if (k <= for_end) do { - dvi_out(str_pool[k]); + dvi_out(str_pool(k)); } while (k++ < for_end); } - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; - doing_special = false; + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); + set_doing_special(false); } @@ -2119,14 +2114,14 @@ write_out(int32_t p) int32_t d; q = get_avail(); - mem[q].b32.s0 = (RIGHT_BRACE_TOKEN + '}' ); + mem_ptr(q)->b32.s0 = (RIGHT_BRACE_TOKEN + '}' ); r = get_avail(); - mem[q].b32.s1 = r; - mem[r].b32.s0 = CS_TOKEN_FLAG + END_WRITE; + mem_ptr(q)->b32.s1 = r; + mem_ptr(r)->b32.s0 = CS_TOKEN_FLAG + END_WRITE; begin_token_list(q, INSERTED); - begin_token_list(mem[p + 1].b32.s1, WRITE_TEXT); + begin_token_list(mem(p + 1).b32.s1, WRITE_TEXT); q = get_avail(); - mem[q].b32.s0 = (LEFT_BRACE_TOKEN + '{' ); + mem_ptr(q)->b32.s0 = (LEFT_BRACE_TOKEN + '{' ); begin_token_list(q, INSERTED); old_mode = cur_list.mode; @@ -2150,16 +2145,16 @@ write_out(int32_t p) cur_list.mode = old_mode; end_token_list(); - old_setting = selector; - j = mem[p + 1].b32.s0; + old_setting = selector(); + j = mem(p + 1).b32.s0; if (j == 18) { - selector = SELECTOR_NEW_STRING; + set_selector(SELECTOR_NEW_STRING); } else if (write_open[j]) { - selector = j; + set_selector(j); } else { - if (j == 17 && selector == SELECTOR_TERM_AND_LOG) - selector = SELECTOR_LOG_ONLY; + if (j == 17 && selector() == SELECTOR_TERM_AND_LOG) + set_selector(SELECTOR_LOG_ONLY); print_nl_cstr(""); } @@ -2169,12 +2164,12 @@ write_out(int32_t p) if (j == 18) { if (INTPAR(tracing_online) <= 0) - selector = SELECTOR_LOG_ONLY; + set_selector(SELECTOR_LOG_ONLY); else - selector = SELECTOR_TERM_AND_LOG; + set_selector(SELECTOR_TERM_AND_LOG); - if (!log_opened) - selector = SELECTOR_TERM_ONLY; + if (!log_opened()) + set_selector(SELECTOR_TERM_ONLY); // Tectonic: don't emit warnings for shell-escape invocations when // enabled; we can provide a better UX inside the driver code. @@ -2184,7 +2179,7 @@ write_out(int32_t p) print_nl_cstr("runsystem("); for (d = 0; d <= (cur_length()) - 1; d++) - print(str_pool[str_start[str_ptr - TOO_BIG_CHAR] + d]); + print(str_pool(str_start(str_ptr() - TOO_BIG_CHAR) + d)); print_cstr(")..."); print_cstr("disabled"); @@ -2193,14 +2188,14 @@ write_out(int32_t p) print_nl_cstr(""); print_ln(); } else { - ttstub_shell_escape(&str_pool[str_start[str_ptr - TOO_BIG_CHAR]], cur_length()); + ttstub_shell_escape(str_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)), cur_length()); } // Clear shell escape command - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); } - selector = old_setting; + set_selector(old_setting); } @@ -2221,27 +2216,27 @@ pic_out(int32_t p) dvi_v = cur_v; } - old_setting = selector; - selector = SELECTOR_NEW_STRING; + old_setting = selector(); + set_selector(SELECTOR_NEW_STRING); print_cstr("pdf:image "); print_cstr("matrix "); - print_scaled(mem[p + 5].b32.s0); + print_scaled(mem(p + 5).b32.s0); print(' '); - print_scaled(mem[p + 5].b32.s1); + print_scaled(mem(p + 5).b32.s1); print(' '); - print_scaled(mem[p + 6].b32.s0); + print_scaled(mem(p + 6).b32.s0); print(' '); - print_scaled(mem[p + 6].b32.s1); + print_scaled(mem(p + 6).b32.s1); print(' '); - print_scaled(mem[p + 7].b32.s0); + print_scaled(mem(p + 7).b32.s0); print(' '); - print_scaled(mem[p + 7].b32.s1); + print_scaled(mem(p + 7).b32.s1); print(' '); print_cstr("page "); - print_int(mem[p + 4].b16.s0); + print_int(mem(p + 4).b16.s0); print(' '); - switch (mem[p + 8].b16.s1) { + switch (mem(p + 8).b16.s1) { case 1: print_cstr("pagebox cropbox "); break; @@ -2266,7 +2261,7 @@ pic_out(int32_t p) print_raw_char(PIC_NODE_path(p)[i], true); print(')'); - selector = old_setting; + set_selector(old_setting); if (cur_length() < 256) { dvi_out(XXX1); dvi_out(cur_length()); @@ -2275,10 +2270,10 @@ pic_out(int32_t p) dvi_four(cur_length()); } - for (k = str_start[str_ptr - TOO_BIG_CHAR]; k < pool_ptr; k++) - dvi_out(str_pool[k]); + for (k = str_start(str_ptr() - TOO_BIG_CHAR); k < pool_ptr(); k++) + dvi_out(str_pool(k)); - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; /* discard the string we just made */ + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); /* discard the string we just made */ } @@ -2309,7 +2304,7 @@ finalize_dvi_file(void) dvi_out(POST); dvi_four(last_bop); - last_bop = dvi_offset + dvi_ptr - 5; + last_bop = dvi_offset() + dvi_ptr() - 5; dvi_four(25400000L); /* magic values: conversion ratio for sp */ dvi_four(473628672L); /* magic values: conversion ratio for sp */ prepare_mag(); @@ -2335,25 +2330,25 @@ finalize_dvi_file(void) else dvi_out(XDV_ID_BYTE); - k = 4 + (DVI_BUF_SIZE - dvi_ptr) % 4; + k = 4 + (DVI_BUF_SIZE - dvi_ptr()) % 4; while (k > 0) { dvi_out(223); k--; } - if (dvi_limit == HALF_BUF) + if (dvi_limit() == HALF_BUF) write_to_dvi(HALF_BUF, DVI_BUF_SIZE - 1); - if (dvi_ptr > TEX_INFINITY - dvi_offset) { + if (dvi_ptr() > TEX_INFINITY - dvi_offset()) { cur_s = -2; fatal_error("dvi length exceeds 0x7FFFFFFF"); } - if (dvi_ptr > 0) - write_to_dvi(0, dvi_ptr - 1); + if (dvi_ptr() > 0) + write_to_dvi(0, dvi_ptr() - 1); - k = ttstub_output_close(dvi_file); + k = ttstub_output_close(dvi_file()); if (k == 0) { print_nl_cstr("Output written on "); @@ -2365,7 +2360,7 @@ finalize_dvi_file(void) else print_cstr(" page"); print_cstr(", "); - print_int(dvi_offset + dvi_ptr); + print_int(dvi_offset() + dvi_ptr()); print_cstr(" bytes)."); } else { print_nl_cstr("Error "); @@ -2386,7 +2381,7 @@ write_to_dvi(int32_t a, int32_t b) { int32_t n = b - a + 1; - if (ttstub_output_write (dvi_file, (char *) &dvi_buf[a], n) != n) + if (ttstub_output_write (dvi_file(), (char *) dvi_buf_ptr(a), n) != n) _tt_abort ("failed to write data to XDV file"); } @@ -2394,22 +2389,22 @@ write_to_dvi(int32_t a, int32_t b) static void dvi_swap(void) { - if (dvi_ptr > (TEX_INFINITY - dvi_offset)) { + if (dvi_ptr() > (TEX_INFINITY - dvi_offset())) { cur_s = -2; fatal_error("dvi length exceeds 0x7FFFFFFF"); } - if (dvi_limit == DVI_BUF_SIZE) { + if (dvi_limit() == DVI_BUF_SIZE) { write_to_dvi(0, HALF_BUF - 1); - dvi_limit = HALF_BUF; - dvi_offset = dvi_offset + DVI_BUF_SIZE; - dvi_ptr = 0; + set_dvi_limit(HALF_BUF); + set_dvi_offset(dvi_offset() + DVI_BUF_SIZE); + set_dvi_ptr(0); } else { write_to_dvi(HALF_BUF, DVI_BUF_SIZE - 1); - dvi_limit = DVI_BUF_SIZE; + set_dvi_limit(DVI_BUF_SIZE); } - dvi_gone = dvi_gone + HALF_BUF; + set_dvi_gone(dvi_gone() + HALF_BUF); } @@ -2444,8 +2439,9 @@ dvi_two(UTF16_code s) static void dvi_pop(int32_t l) { - if (l == dvi_offset + dvi_ptr && dvi_ptr > 0) - dvi_ptr--; - else + if (l == dvi_offset() + dvi_ptr() && dvi_ptr() > 0) { + set_dvi_ptr(dvi_ptr()-1); + } else { dvi_out(POP); + } } diff --git a/crates/engine_xetex/xetex/xetex-stringpool.c b/crates/engine_xetex/xetex/xetex-stringpool.c index 3085d9de8..ef7709ab8 100644 --- a/crates/engine_xetex/xetex/xetex-stringpool.c +++ b/crates/engine_xetex/xetex/xetex-stringpool.c @@ -29,8 +29,10 @@ load_pool_strings(int32_t spare_size) if (total_len >= spare_size) return 0; - while (len-- > 0) - str_pool[pool_ptr++] = *s++; + while (len-- > 0) { + set_str_pool(pool_ptr(), *s++); + set_pool_ptr(pool_ptr() + 1); + } g = make_string(); /* Returns 0 on error. */ } @@ -38,34 +40,6 @@ load_pool_strings(int32_t spare_size) return g; } - -int32_t -length(str_number s) -{ - if (s >= 65536L) - return str_start[s + 1 - 65536L] - str_start[s - 65536L]; - if (s >= 32 && s < 127) - return 1; - if (s <= 127) - return 3; - if (s < 256) - return 4; - return 8; -} - - -str_number -make_string(void) -{ - if (str_ptr == max_strings) - overflow("number of strings", max_strings - init_str_ptr); - - str_ptr++; - str_start[str_ptr - TOO_BIG_CHAR] = pool_ptr; - return str_ptr - 1; -} - - void append_str(str_number s) { @@ -74,14 +48,14 @@ append_str(str_number s) i = length(s); - if (pool_ptr + i > pool_size) - overflow("pool size", pool_size - init_pool_ptr); + if (pool_ptr() + i > pool_size()) + overflow("pool size", pool_size() - init_pool_ptr); - j = str_start[s - 65536L]; + j = str_start(s - 65536L); while (i > 0) { - str_pool[pool_ptr] = str_pool[j]; - pool_ptr++; + set_str_pool(pool_ptr(), str_pool(j)); + set_pool_ptr(pool_ptr()+1); j++; i--; } @@ -93,18 +67,18 @@ str_eq_buf(str_number s, int32_t k) { pool_pointer j; - j = str_start[s - 65536L]; + j = str_start(s - 65536L); - while (j < str_start[s + 1 - 65536L]) { - if (buffer[k] >= 65536L) { - if (str_pool[j] != 55296L + (buffer[k] - 65536L) / 1024) { + while (j < str_start(s + 1 - 65536L)) { + if (buffer(k) >= 65536L) { + if (str_pool(j) != 55296L + (buffer(k) - 65536L) / 1024) { return false; - } else if (str_pool[j + 1] != 56320L + (buffer[k] - 65536L) % 1024) { + } else if (str_pool(j + 1) != 56320L + (buffer(k) - 65536L) % 1024) { return false; } else { j++; } - } else if (str_pool[j] != buffer[k]) { + } else if (str_pool(j) != buffer(k)) { return false; } @@ -114,93 +88,3 @@ str_eq_buf(str_number s, int32_t k) return true; } - - -bool -str_eq_str(str_number s, str_number t) -{ - pool_pointer j, k; - - if (length(s) != length(t)) - return false; - - if (length(s) == 1) { - if (s < 65536L) { - if (t < 65536L) { - if (s != t) - return false; - } else { - if (s != str_pool[str_start[t - 65536L]]) - return false; - } - } else { - if (t < 65536L) { - if (str_pool[str_start[s - 65536L]] != t) - return false; - } else { - if (str_pool[str_start[s - 65536L]] != str_pool[str_start[t - 65536L]]) - return false; - } - } - } else { - j = str_start[s - 65536L]; - k = str_start[t - 65536L]; - - while (j < str_start[s + 1 - 65536L]) { - if (str_pool[j] != str_pool[k]) - return false; - - j++; - k++; - } - } - - return true; -} - - -str_number -search_string(str_number search) -{ - str_number s; - int32_t len; - - len = length(search); - - if (len == 0) { - return EMPTY_STRING; - } else { - s = search - 1; - - while (s > 65535L) { - if (length(s) == len) { - if (str_eq_str(s, search)) { - return s; - } - } - - s--; - } - } - - return 0; -} - - -str_number -slow_make_string(void) -{ - str_number s; - str_number t; - - t = make_string(); - s = search_string(t); - - if (s > 0) { - str_ptr--; - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; - return s; - } - - return t; -} diff --git a/crates/engine_xetex/xetex/xetex-stringpool.h b/crates/engine_xetex/xetex/xetex-stringpool.h index bd868048c..790fa9e2b 100644 --- a/crates/engine_xetex/xetex/xetex-stringpool.h +++ b/crates/engine_xetex/xetex/xetex-stringpool.h @@ -14,7 +14,6 @@ BEGIN_EXTERN_C int load_pool_strings(int32_t spare_size); -int32_t length(str_number s); str_number make_string(void); void append_str(str_number s); bool str_eq_buf(str_number s, int32_t k); diff --git a/crates/engine_xetex/xetex/xetex-synctex.c b/crates/engine_xetex/xetex/xetex-synctex.c index d2d915a73..4e3abccb4 100644 --- a/crates/engine_xetex/xetex/xetex-synctex.c +++ b/crates/engine_xetex/xetex/xetex-synctex.c @@ -22,8 +22,8 @@ /* in XeTeX, "halfword" fields are at least 32 bits, so we'll use those for * tag and line so that the sync field size is only one memory_word. */ -#define SYNCTEX_TAG_MODEL(NODE,TYPE) mem[NODE + TYPE##_NODE_SIZE - SYNCTEX_FIELD_SIZE].b32.s0 -#define SYNCTEX_LINE_MODEL(NODE,TYPE) mem[NODE + TYPE##_NODE_SIZE - SYNCTEX_FIELD_SIZE].b32.s1 +#define SYNCTEX_TAG_MODEL(NODE,TYPE) mem_ptr(NODE + TYPE##_NODE_SIZE - SYNCTEX_FIELD_SIZE)->b32.s0 +#define SYNCTEX_LINE_MODEL(NODE,TYPE) mem_ptr(NODE + TYPE##_NODE_SIZE - SYNCTEX_FIELD_SIZE)->b32.s1 #define GLUE_NODE_SIZE MEDIUM_NODE_SIZE #define KERN_NODE_SIZE MEDIUM_NODE_SIZE @@ -43,11 +43,11 @@ #define glue_node 10 #define kern_node 11 -#define SYNCTEX_TYPE(NODE) mem[NODE].b16.s1 -#define SYNCTEX_SUBTYPE(NODE) mem[NODE].b16.s0 -#define SYNCTEX_WIDTH(NODE) mem[NODE + width_offset].b32.s1 -#define SYNCTEX_DEPTH(NODE) mem[NODE + depth_offset].b32.s1 -#define SYNCTEX_HEIGHT(NODE) mem[NODE + height_offset].b32.s1 +#define SYNCTEX_TYPE(NODE) mem_ptr(NODE)->b16.s1 +#define SYNCTEX_SUBTYPE(NODE) mem_ptr(NODE)->b16.s0 +#define SYNCTEX_WIDTH(NODE) mem_ptr(NODE + width_offset)->b32.s1 +#define SYNCTEX_DEPTH(NODE) mem_ptr(NODE + depth_offset)->b32.s1 +#define SYNCTEX_HEIGHT(NODE) mem_ptr(NODE + height_offset)->b32.s1 /* For non-GCC compilation. */ #if !defined(__GNUC__) || (__GNUC__ < 2) @@ -234,7 +234,7 @@ synctex_dot_open(void) if (synctex_ctxt.file) return synctex_ctxt.file; - tmp = gettexstring(job_name); + tmp = gettexstring(job_name()); len = strlen(tmp); if (len <= 0) @@ -337,10 +337,10 @@ void synctex_start_input(void) * use the 16 other bits to store the column number */ synctex_ctxt.synctex_tag_counter = 0; /* was this, but this looks like a bug */ - /* cur_input.synctex_tag = 0; */ + /* cur_input_ptr()->synctex_tag = 0; */ return; } - cur_input.synctex_tag = (int) synctex_ctxt.synctex_tag_counter; /* -> *TeX.web */ + cur_input_ptr()->synctex_tag = (int) synctex_ctxt.synctex_tag_counter; /* -> *TeX.web */ if (synctex_ctxt.synctex_tag_counter == 1) { /* this is the first file TeX ever opens, in general \jobname.tex we * do not know yet if synchronization will ever be enabled so we have @@ -357,7 +357,7 @@ void synctex_start_input(void) || (INVALID_HANDLE != synctex_dot_open())) { char *tmp = get_current_name(); /* Always record the input, even if INTPAR(synctex) is 0 */ - synctex_record_input(cur_input.synctex_tag, tmp); + synctex_record_input(cur_input().synctex_tag, tmp); free(tmp); } return; diff --git a/crates/engine_xetex/xetex/xetex-texmfmp.c b/crates/engine_xetex/xetex/xetex-texmfmp.c index 60a4f722a..b8bdf7263 100644 --- a/crates/engine_xetex/xetex/xetex-texmfmp.c +++ b/crates/engine_xetex/xetex/xetex-texmfmp.c @@ -101,14 +101,16 @@ getcreationdate(void) /* In e-pTeX, "init len => call init_start_time()" (as pdftexdir/utils.c) yields unintentional output. */ - if ((unsigned) (pool_ptr + len) >= (unsigned) (pool_size)) { - pool_ptr = pool_size; + if ((unsigned) (pool_ptr() + len) >= (unsigned) (pool_size())) { + set_pool_ptr(pool_size()); /* error by str_toks that calls str_room(1) */ return; } - for (i = 0; i < len; i++) - str_pool[pool_ptr++] = (uint16_t)start_time_str[i]; + for (i = 0; i < len; i++) { + set_str_pool(pool_ptr(), (uint16_t)start_time_str[i]); + set_pool_ptr(pool_ptr() + 1); + } } @@ -167,14 +169,16 @@ getfilemoddate(str_number s) makepdftime(mtime, buf, /* utc= */true); text_len = strlen(buf); - if ((unsigned) (pool_ptr + text_len) >= (unsigned) pool_size) { - pool_ptr = pool_size; + if ((unsigned) (pool_ptr() + text_len) >= (unsigned) pool_size()) { + set_pool_ptr(pool_size()); /* error by str_toks that calls str_room(1) */ } else { int i; - for (i = 0; i < text_len; i++) - str_pool[pool_ptr++] = (uint16_t) buf[i]; + for (i = 0; i < text_len; i++) { + set_str_pool(pool_ptr(), (uint16_t) buf[i]); + set_pool_ptr(pool_ptr()+1); + } } } @@ -203,14 +207,16 @@ getfilesize(str_number s) check_nprintf(i, sizeof(buf)); text_len = strlen(buf); - if ((unsigned) (pool_ptr + text_len) >= (unsigned) pool_size) { - pool_ptr = pool_size; + if ((unsigned) (pool_ptr() + text_len) >= (unsigned) pool_size()) { + set_pool_ptr(pool_size()); /* error by str_toks that calls str_room(1) */ } else { int i; - for (i = 0; i < text_len; i++) - str_pool[pool_ptr++] = (uint16_t) buf[i]; + for (i = 0; i < text_len; i++) { + set_str_pool(pool_ptr(), (uint16_t) buf[i]); + set_pool_ptr(pool_ptr()+1); + } } } @@ -226,15 +232,15 @@ void getfiledump(int32_t s, int offset, int length) if (length == 0) return; /* => evaluate to the empty string; intentional */ - if (pool_ptr + 2 * length + 1 >= pool_size) { + if (pool_ptr() + 2 * length + 1 >= pool_size()) { /* not enough room to hold the result; trigger an error back in TeX: */ - pool_ptr = pool_size; + set_pool_ptr(pool_size()); return; } buffer = (unsigned char *) xmalloc(length + 1); if (buffer == NULL) { - pool_ptr = pool_size; + set_pool_ptr(pool_size()); return; } @@ -254,110 +260,15 @@ void getfiledump(int32_t s, int offset, int length) for (j = 0; j < actual; j++) { i = snprintf(strbuf, 3, "%.2X", (unsigned int) buffer[j]); check_nprintf(i, 3); - for (k = 0; k < i; k++) - str_pool[pool_ptr++] = (uint16_t) strbuf[k]; - } - - free(buffer); -} - - -static void -checkpool_pointer (pool_pointer pool_ptr, size_t len) -{ - if (pool_ptr + len >= pool_size) - _tt_abort ("string pool overflow [%i bytes]", (int) pool_size); -} - - -int -maketexstring(const char *s) -{ - size_t len; - UInt32 rval; - const unsigned char *cp = (const unsigned char *)s; - - if (s == NULL || *s == 0) - return EMPTY_STRING; - - len = strlen(s); - checkpool_pointer (pool_ptr, len); /* in the XeTeX case, this may be more than enough */ - - while ((rval = *(cp++)) != 0) { - UInt16 extraBytes = bytesFromUTF8[rval]; - switch (extraBytes) { /* note: code falls through cases! */ - case 5: rval <<= 6; if (*cp) rval += *(cp++); - case 4: rval <<= 6; if (*cp) rval += *(cp++); - case 3: rval <<= 6; if (*cp) rval += *(cp++); - case 2: rval <<= 6; if (*cp) rval += *(cp++); - case 1: rval <<= 6; if (*cp) rval += *(cp++); - case 0: ; - }; - rval -= offsetsFromUTF8[extraBytes]; - if (rval > 0xffff) { - rval -= 0x10000; - str_pool[pool_ptr++] = 0xd800 + rval / 0x0400; - str_pool[pool_ptr++] = 0xdc00 + rval % 0x0400; + for (k = 0; k < i; k++) { + set_str_pool(pool_ptr(), (uint16_t) strbuf[k]); + set_pool_ptr(pool_ptr()+1); } - else - str_pool[pool_ptr++] = rval; } - return make_string(); -} - - -char * -gettexstring (str_number s) -{ - unsigned int bytesToWrite = 0; - pool_pointer len, i, j; - char *name; - - if (s >= 65536L) - len = str_start[s + 1 - 65536L] - str_start[s - 65536L]; - else - len = 0; - - name = xmalloc(len * 3 + 1); /* max UTF16->UTF8 expansion - (code units, not bytes) */ - for (i = 0, j = 0; i < len; i++) { - uint32_t c = str_pool[i + str_start[s - 65536L]]; - if (c >= 0xD800 && c <= 0xDBFF) { - uint32_t lo = str_pool[++i + str_start[s - 65536L]]; - if (lo >= 0xDC00 && lo <= 0xDFFF) - c = (c - 0xD800) * 0x0400 + lo - 0xDC00 + 0x10000; - else - c = 0xFFFD; - } - - if (c < 0x80) - bytesToWrite = 1; - else if (c < 0x800) - bytesToWrite = 2; - else if (c < 0x10000) - bytesToWrite = 3; - else if (c < 0x110000) - bytesToWrite = 4; - else { - bytesToWrite = 3; - c = 0xFFFD; - } - - j += bytesToWrite; - switch (bytesToWrite) { /* note: everything falls through. */ - case 4: name[--j] = ((c | 0x80) & 0xBF); c >>= 6; - case 3: name[--j] = ((c | 0x80) & 0xBF); c >>= 6; - case 2: name[--j] = ((c | 0x80) & 0xBF); c >>= 6; - case 1: name[--j] = (c | firstByteMark[bytesToWrite]); - } - j += bytesToWrite; - } - name[j] = 0; - return name; + free(buffer); } - static int compare_paths (const char *p1, const char *p2) { @@ -392,7 +303,7 @@ remember_source_info (str_number srcfilename, int lineno) pool_pointer make_src_special (str_number srcfilename, int lineno) { - pool_pointer oldpool_ptr = pool_ptr; + pool_pointer oldpool_ptr = pool_ptr(); char *filename = gettexstring(srcfilename); /* FIXME: Magic number. */ char buf[40]; @@ -403,16 +314,20 @@ make_src_special (str_number srcfilename, int lineno) */ sprintf (buf, "src:%d ", lineno); - if (pool_ptr + strlen(buf) + strlen(filename) >= (size_t)pool_size) + if (pool_ptr() + strlen(buf) + strlen(filename) >= (size_t)pool_size()) _tt_abort ("string pool overflow"); s = buf; - while (*s) - str_pool[pool_ptr++] = *s++; + while (*s) { + set_str_pool(pool_ptr(), *s++); + set_pool_ptr(pool_ptr()+1); + } s = filename; - while (*s) - str_pool[pool_ptr++] = *s++; + while (*s) { + set_str_pool(pool_ptr(), *s++); + set_pool_ptr(pool_ptr()+1); + } return (oldpool_ptr); } @@ -456,12 +371,14 @@ void getmd5sum(str_number s, bool file) if (ret) return; - if (pool_ptr + 2 * DIGEST_SIZE >= pool_size) { + if (pool_ptr() + 2 * DIGEST_SIZE >= pool_size()) { /* error by str_toks that calls str_room(1) */ return; } convertStringToHexString((char *) digest, outbuf, DIGEST_SIZE); - for (i = 0; i < 2 * DIGEST_SIZE; i++) - str_pool[pool_ptr++] = (uint16_t)outbuf[i]; + for (i = 0; i < 2 * DIGEST_SIZE; i++) { + set_str_pool(pool_ptr(), (uint16_t)outbuf[i]); + set_pool_ptr(pool_ptr()+1); + } } diff --git a/crates/engine_xetex/xetex/xetex-xetex0.c b/crates/engine_xetex/xetex/xetex-xetex0.c index b9cade3dc..191572092 100644 --- a/crates/engine_xetex/xetex/xetex-xetex0.c +++ b/crates/engine_xetex/xetex/xetex-xetex0.c @@ -6,6 +6,7 @@ #include "xetex-core.h" #include "xetex-xetexd.h" #include "xetex-synctex.h" +#include "xetex_bindings.h" #include /* for EOF */ @@ -57,15 +58,15 @@ show_token_list(int32_t p, int32_t q, int32_t l) match_chr = '#' ; n = '0' ; - tally = 0; + set_tally(0); - while (p != TEX_NULL && tally < l) { + while (p != TEX_NULL && tally() < l) { /*332:*/ if (p == q) { - first_count = tally; - trick_count = tally + 1 + error_line - half_error_line; - if (trick_count < error_line) - trick_count = error_line; + first_count = tally(); + set_trick_count(tally() + 1 + error_line() - half_error_line); + if (trick_count() < error_line()) + set_trick_count(error_line()); } if (p < hi_mem_min || p > mem_end) { @@ -73,13 +74,13 @@ show_token_list(int32_t p, int32_t q, int32_t l) return; } - if (mem[p].b32.s0 >= CS_TOKEN_FLAG) { - print_cs(mem[p].b32.s0 - CS_TOKEN_FLAG); + if (mem(p).b32.s0 >= CS_TOKEN_FLAG) { + print_cs(mem(p).b32.s0 - CS_TOKEN_FLAG); } else { - m = mem[p].b32.s0 / MAX_CHAR_VAL; - c = mem[p].b32.s0 % MAX_CHAR_VAL; + m = mem(p).b32.s0 / MAX_CHAR_VAL; + c = mem(p).b32.s0 % MAX_CHAR_VAL; - if (mem[p].b32.s0 < 0) { + if (mem(p).b32.s0 < 0) { print_esc_cstr("BAD."); } else { /*306:*/ @@ -162,7 +163,7 @@ runaway(void) print_char('?'); print_ln(); - show_token_list(mem[p].b32.s1, TEX_NULL, error_line - 10); + show_token_list(mem(p).b32.s1, TEX_NULL, error_line() - 10); } } @@ -185,7 +186,7 @@ int32_t get_avail(void) overflow("main memory size", MEM_TOP + 1); } } - mem[p].b32.s1 = TEX_NULL; + mem_ptr(p)->b32.s1 = TEX_NULL; return p; } @@ -198,7 +199,7 @@ void flush_list(int32_t p) q = r; r = LLIST_link(r); } while (!(r == TEX_NULL)); - mem[q].b32.s1 = avail; + mem_ptr(q)->b32.s1 = avail; avail = p; } } @@ -214,34 +215,34 @@ int32_t get_node(int32_t s) p = rover; do { - /*131: */ q = p + mem[p].b32.s0; - while (mem[q].b32.s1 == MAX_HALFWORD) { + /*131: */ q = p + mem(p).b32.s0; + while (mem(q).b32.s1 == MAX_HALFWORD) { - t = mem[q + 1].b32.s1; + t = mem(q + 1).b32.s1; if (q == rover) rover = t; - mem[t + 1].b32.s0 = mem[q + 1].b32.s0; - mem[mem[q + 1].b32.s0 + 1].b32.s1 = t; - q = q + mem[q].b32.s0; + mem_ptr(t + 1)->b32.s0 = mem(q + 1).b32.s0; + mem_ptr(mem(q + 1).b32.s0 + 1)->b32.s1 = t; + q = q + mem(q).b32.s0; } r = q - s; if (r > p + 1) { /*132: */ - mem[p].b32.s0 = r - p; + mem_ptr(p)->b32.s0 = r - p; rover = p; goto found; } if (r == p) { - if (mem[p + 1].b32.s1 != p) { /*133: */ - rover = mem[p + 1].b32.s1; - t = mem[p + 1].b32.s0; - mem[rover + 1].b32.s0 = t; - mem[t + 1].b32.s1 = rover; + if (mem(p + 1).b32.s1 != p) { /*133: */ + rover = mem(p + 1).b32.s1; + t = mem(p + 1).b32.s0; + mem_ptr(rover + 1)->b32.s0 = t; + mem_ptr(t + 1)->b32.s1 = rover; goto found; } } - mem[p].b32.s0 = q - /*:131 */ p; - p = mem[p + 1].b32.s1; + mem_ptr(p)->b32.s0 = q - /*:131 */ p; + p = mem(p + 1).b32.s1; } while (!(p == rover)); if (s == 0x40000000) { return MAX_HALFWORD; @@ -253,19 +254,19 @@ int32_t get_node(int32_t s) t = lo_mem_max + 1000; else t = lo_mem_max + 1 + (hi_mem_min - lo_mem_max) / 2; - p = mem[rover + 1].b32.s0; + p = mem(rover + 1).b32.s0; q = lo_mem_max; - mem[p + 1].b32.s1 = q; - mem[rover + 1].b32.s0 = q; + mem_ptr(p + 1)->b32.s1 = q; + mem_ptr(rover + 1)->b32.s0 = q; if (t > MAX_HALFWORD) t = MAX_HALFWORD; - mem[q + 1].b32.s1 = rover; - mem[q + 1].b32.s0 = p; - mem[q].b32.s1 = MAX_HALFWORD; - mem[q].b32.s0 = t - lo_mem_max; + mem_ptr(q + 1)->b32.s1 = rover; + mem_ptr(q + 1)->b32.s0 = p; + mem_ptr(q)->b32.s1 = MAX_HALFWORD; + mem_ptr(q)->b32.s0 = t - lo_mem_max; lo_mem_max = t; - mem[lo_mem_max].b32.s1 = TEX_NULL; - mem[lo_mem_max].b32.s0 = TEX_NULL; + mem_ptr(lo_mem_max)->b32.s1 = TEX_NULL; + mem_ptr(lo_mem_max)->b32.s0 = TEX_NULL; rover = q; goto restart; } @@ -273,10 +274,10 @@ int32_t get_node(int32_t s) overflow("main memory size", MEM_TOP + 1); found: - mem[r].b32.s1 = TEX_NULL; + mem_ptr(r)->b32.s1 = TEX_NULL; if (s >= MEDIUM_NODE_SIZE) { - mem[r + s - 1].b32.s0 = cur_input.synctex_tag; - mem[r + s - 1].b32.s1 = line; + mem_ptr(r + s - 1)->b32.s0 = cur_input().synctex_tag; + mem_ptr(r + s - 1)->b32.s1 = line(); } return r; } @@ -284,13 +285,13 @@ int32_t get_node(int32_t s) void free_node(int32_t p, int32_t s) { int32_t q; - mem[p].b32.s0 = s; - mem[p].b32.s1 = MAX_HALFWORD; - q = mem[rover + 1].b32.s0; - mem[p + 1].b32.s0 = q; - mem[p + 1].b32.s1 = rover; - mem[rover + 1].b32.s0 = p; - mem[q + 1].b32.s1 = p; + mem_ptr(p)->b32.s0 = s; + mem_ptr(p)->b32.s1 = MAX_HALFWORD; + q = mem(rover + 1).b32.s0; + mem_ptr(p + 1)->b32.s0 = q; + mem_ptr(p + 1)->b32.s1 = rover; + mem_ptr(rover + 1)->b32.s0 = p; + mem_ptr(q + 1)->b32.s1 = p; } int32_t new_null_box(void) @@ -298,14 +299,14 @@ int32_t new_null_box(void) int32_t p; p = get_node(BOX_NODE_SIZE); NODE_type(p) = HLIST_NODE; - mem[p].b16.s0 = 0; - mem[p + 1].b32.s1 = 0; - mem[p + 2].b32.s1 = 0; - mem[p + 3].b32.s1 = 0; - mem[p + 4].b32.s1 = 0; - mem[p + 5].b32.s1 = TEX_NULL; - mem[p + 5].b16.s1 = NORMAL; - mem[p + 5].b16.s0 = NORMAL; + mem_ptr(p)->b16.s0 = 0; + mem_ptr(p + 1)->b32.s1 = 0; + mem_ptr(p + 2)->b32.s1 = 0; + mem_ptr(p + 3)->b32.s1 = 0; + mem_ptr(p + 4)->b32.s1 = 0; + mem_ptr(p + 5)->b32.s1 = TEX_NULL; + mem_ptr(p + 5)->b16.s1 = NORMAL; + mem_ptr(p + 5)->b16.s0 = NORMAL; BOX_glue_set(p) = 0.0; return p; } @@ -315,10 +316,10 @@ int32_t new_rule(void) int32_t p; p = get_node(RULE_NODE_SIZE); NODE_type(p) = RULE_NODE; - mem[p].b16.s0 = 0; - mem[p + 1].b32.s1 = NULL_FLAG; - mem[p + 2].b32.s1 = NULL_FLAG; - mem[p + 3].b32.s1 = NULL_FLAG; + mem_ptr(p)->b16.s0 = 0; + mem_ptr(p + 1)->b32.s1 = NULL_FLAG; + mem_ptr(p + 2)->b32.s1 = NULL_FLAG; + mem_ptr(p + 3)->b32.s1 = NULL_FLAG; return p; } @@ -327,10 +328,10 @@ int32_t new_ligature(internal_font_number f, uint16_t c, int32_t q) int32_t p; p = get_node(SMALL_NODE_SIZE); NODE_type(p) = LIGATURE_NODE; - mem[p + 1].b16.s1 = f; - mem[p + 1].b16.s0 = c; - mem[p + 1].b32.s1 = q; - mem[p].b16.s0 = 0; + mem_ptr(p + 1)->b16.s1 = f; + mem_ptr(p + 1)->b16.s0 = c; + mem_ptr(p + 1)->b32.s1 = q; + mem_ptr(p)->b16.s0 = 0; return p; } @@ -338,8 +339,8 @@ int32_t new_lig_item(uint16_t c) { int32_t p; p = get_node(SMALL_NODE_SIZE); - mem[p].b16.s0 = c; - mem[p + 1].b32.s1 = TEX_NULL; + mem_ptr(p)->b16.s0 = c; + mem_ptr(p + 1)->b32.s1 = TEX_NULL; return p; } @@ -348,9 +349,9 @@ int32_t new_disc(void) int32_t p; p = get_node(SMALL_NODE_SIZE); NODE_type(p) = DISC_NODE; - mem[p].b16.s0 = 0; - mem[p + 1].b32.s0 = TEX_NULL; - mem[p + 1].b32.s1 = TEX_NULL; + mem_ptr(p)->b16.s0 = 0; + mem_ptr(p + 1)->b32.s0 = TEX_NULL; + mem_ptr(p + 1)->b32.s1 = TEX_NULL; return p; } @@ -374,8 +375,8 @@ int32_t new_math(scaled_t w, small_number s) int32_t p; p = get_node(MEDIUM_NODE_SIZE); NODE_type(p) = MATH_NODE; - mem[p].b16.s0 = s; - mem[p + 1].b32.s1 = w; + mem_ptr(p)->b16.s0 = s; + mem_ptr(p + 1)->b32.s1 = w; return p; } @@ -383,11 +384,11 @@ int32_t new_spec(int32_t p) { int32_t q; q = get_node(GLUE_SPEC_SIZE); - mem[q] = mem[p]; - mem[q].b32.s1 = TEX_NULL; - mem[q + 1].b32.s1 = mem[p + 1].b32.s1; - mem[q + 2].b32.s1 = mem[p + 2].b32.s1; - mem[q + 3].b32.s1 = mem[p + 3].b32.s1; + set_mem(q, mem(p)); + mem_ptr(q)->b32.s1 = TEX_NULL; + mem_ptr(q + 1)->b32.s1 = mem(p + 1).b32.s1; + mem_ptr(q + 2)->b32.s1 = mem(p + 2).b32.s1; + mem_ptr(q + 3)->b32.s1 = mem(p + 3).b32.s1; return q; } @@ -398,10 +399,10 @@ int32_t new_param_glue(small_number n) p = get_node(MEDIUM_NODE_SIZE); NODE_type(p) = GLUE_NODE; - mem[p].b16.s0 = n + 1; - mem[p + 1].b32.s1 = TEX_NULL; - q = /*232: */ eqtb[GLUE_BASE + n].b32.s1 /*:232 */ ; - mem[p + 1].b32.s0 = q; + mem_ptr(p)->b16.s0 = n + 1; + mem_ptr(p + 1)->b32.s1 = TEX_NULL; + q = /*232: */ eqtb_ptr(GLUE_BASE + n)->b32.s1 /*:232 */ ; + mem_ptr(p + 1)->b32.s0 = q; GLUE_SPEC_ref_count(q)++; return p; } @@ -412,8 +413,8 @@ int32_t new_glue(int32_t q) p = get_node(MEDIUM_NODE_SIZE); NODE_type(p) = GLUE_NODE; GLUE_SPEC_shrink_order(p) = NORMAL; - mem[p + 1].b32.s1 = TEX_NULL; - mem[p + 1].b32.s0 = q; + mem_ptr(p + 1)->b32.s1 = TEX_NULL; + mem_ptr(p + 1)->b32.s0 = q; GLUE_SPEC_ref_count(q)++; return p; } @@ -422,10 +423,10 @@ int32_t new_skip_param(small_number n) { int32_t p; - temp_ptr = new_spec( /*232: */ eqtb[GLUE_BASE + n].b32.s1 /*:232 */ ); + temp_ptr = new_spec( /*232: */ eqtb_ptr(GLUE_BASE + n)->b32.s1 /*:232 */ ); p = new_glue(temp_ptr); - mem[temp_ptr].b32.s1 = TEX_NULL; - mem[p].b16.s0 = n + 1; + mem_ptr(temp_ptr)->b32.s1 = TEX_NULL; + mem_ptr(p)->b16.s0 = n + 1; return p; } @@ -434,8 +435,8 @@ int32_t new_kern(scaled_t w) int32_t p; p = get_node(MEDIUM_NODE_SIZE); NODE_type(p) = KERN_NODE; - mem[p].b16.s0 = NORMAL; - mem[p + 1].b32.s1 = w; + mem_ptr(p)->b16.s0 = NORMAL; + mem_ptr(p + 1)->b32.s1 = w; return p; } @@ -444,8 +445,8 @@ int32_t new_penalty(int32_t m) int32_t p; p = get_node(MEDIUM_NODE_SIZE); NODE_type(p) = PENALTY_NODE; - mem[p].b16.s0 = 0; - mem[p + 1].b32.s1 = m; + mem_ptr(p)->b16.s0 = 0; + mem_ptr(p + 1)->b32.s1 = m; return p; } @@ -457,7 +458,7 @@ int32_t prev_rightmost(int32_t s, int32_t e) p = s; if (p == TEX_NULL) return TEX_NULL; - while (mem[p].b32.s1 != e) { + while (mem(p).b32.s1 != e) { p = LLIST_link(p); if (p == TEX_NULL) @@ -489,19 +490,19 @@ short_display(int32_t p) while (p > 0) { if (is_char_node(p)) { if (p <= mem_end) { - if (mem[p].b16.s1 != font_in_short_display) { - if (mem[p].b16.s1 > font_max) + if (mem(p).b16.s1 != font_in_short_display) { + if (mem(p).b16.s1 > font_max) print_char('*'); else /*279:*/ - print_esc(hash[FONT_ID_BASE + mem[p].b16.s1].s1); + print_esc(hash(FONT_ID_BASE + mem(p).b16.s1).s1); print_char(' '); - font_in_short_display = mem[p].b16.s1; + font_in_short_display = mem(p).b16.s1; } - print(mem[p].b16.s0); + print(mem(p).b16.s0); } } else { /*183:*/ - switch (mem[p].b16.s1) { + switch (mem(p).b16.s1) { case HLIST_NODE: case VLIST_NODE: case INS_NODE: @@ -511,13 +512,13 @@ short_display(int32_t p) print_cstr("[]"); break; case WHATSIT_NODE: - switch (mem[p].b16.s0) { + switch (mem(p).b16.s0) { case NATIVE_WORD_NODE: case NATIVE_WORD_NODE_AT: - if (mem[p + 4].b16.s2 != font_in_short_display) { - print_esc(hash[FONT_ID_BASE + mem[p + 4].b16.s2].s1); + if (mem(p + 4).b16.s2 != font_in_short_display) { + print_esc(hash(FONT_ID_BASE + mem(p + 4).b16.s2).s1); print_char(' '); - font_in_short_display = mem[p + 4].b16.s2; + font_in_short_display = mem(p + 4).b16.s2; } print_native_word(p); break; @@ -530,25 +531,25 @@ short_display(int32_t p) print_char('|'); break; case GLUE_NODE: - if (mem[p + 1].b32.s0 != 0) + if (mem(p + 1).b32.s0 != 0) print_char(' '); break; case MATH_NODE: - if (mem[p].b16.s0 >= L_CODE) + if (mem(p).b16.s0 >= L_CODE) print_cstr("[]"); else print_char('$'); break; case LIGATURE_NODE: - short_display(mem[p + 1].b32.s1); + short_display(mem(p + 1).b32.s1); break; case DISC_NODE: - short_display(mem[p + 1].b32.s0); - short_display(mem[p + 1].b32.s1); - n = mem[p].b16.s0; + short_display(mem(p + 1).b32.s0); + short_display(mem(p + 1).b32.s1); + n = mem(p).b16.s0; while (n > 0) { - if (mem[p].b32.s1 != TEX_NULL) + if (mem(p).b32.s1 != TEX_NULL) p = LLIST_link(p); n--; } @@ -569,12 +570,12 @@ void print_font_and_char(int32_t p) print_esc_cstr("CLOBBERED."); else { - if ((mem[p].b16.s1 > font_max)) + if ((mem(p).b16.s1 > font_max)) print_char('*'); else /*279: */ - print_esc(hash[FONT_ID_BASE + mem[p].b16.s1].s1); + print_esc(hash(FONT_ID_BASE + mem(p).b16.s1).s1); print_char(' '); - print(mem[p].b16.s0); + print(mem(p).b16.s0); } } @@ -584,7 +585,7 @@ void print_mark(int32_t p) if ((p < hi_mem_min) || (p > mem_end)) print_esc_cstr("CLOBBERED."); else - show_token_list(mem[p].b32.s1, TEX_NULL, max_print_line - 10); + show_token_list(mem(p).b32.s1, TEX_NULL, max_print_line - 10); print_char('}'); } @@ -618,16 +619,16 @@ void print_spec(int32_t p, const char* s) if (p < 0 || p >= lo_mem_max) print_char('*'); else { - print_scaled(mem[p + 1].b32.s1); + print_scaled(mem(p + 1).b32.s1); if (s != NULL) print_cstr(s); - if (mem[p + 2].b32.s1 != 0) { + if (mem(p + 2).b32.s1 != 0) { print_cstr(" plus "); - print_glue(mem[p + 2].b32.s1, mem[p].b16.s1, s); + print_glue(mem(p + 2).b32.s1, mem(p).b16.s1, s); } - if (mem[p + 3].b32.s1 != 0) { + if (mem(p + 3).b32.s1 != 0) { print_cstr(" minus "); - print_glue(mem[p + 3].b32.s1, mem[p].b16.s0, s); + print_glue(mem(p + 3).b32.s1, mem(p).b16.s0, s); } } } @@ -636,9 +637,9 @@ void print_fam_and_char(int32_t p) { int32_t c; print_esc_cstr("fam"); - print_int((mem[p].b16.s1 % 256) % 256); + print_int((mem(p).b16.s1 % 256) % 256); print_char(' '); - c = ((unsigned short) mem[p].b16.s0 + ((mem[p].b16.s1 / 256) * 65536L)); + c = ((unsigned short) mem(p).b16.s0 + ((mem(p).b16.s1 / 256) * 65536L)); if (c < 65536L) print(c); else @@ -648,8 +649,8 @@ void print_fam_and_char(int32_t p) void print_delimiter(int32_t p) { int32_t a; - a = (mem[p].b16.s3 % 256) * 256 + (mem[p].b16.s2 + (mem[p].b16.s3 / 256) * 65536L); - a = a * 4096 + (mem[p].b16.s1 % 256) * 256 + (mem[p].b16.s0 + (mem[p].b16.s1 / 256) * 65536L); + a = (mem(p).b16.s3 % 256) * 256 + (mem(p).b16.s2 + (mem(p).b16.s3 / 256) * 65536L); + a = a * 4096 + (mem(p).b16.s1 % 256) * 256 + (mem(p).b16.s0 + (mem(p).b16.s1 / 256) * 65536L); if (a < 0) print_int(a); else @@ -662,14 +663,14 @@ print_subsidiary_data(int32_t p, UTF16_code c) { if (cur_length() >= depth_threshold) { - if (mem[p].b32.s1 != EMPTY) + if (mem(p).b32.s1 != EMPTY) print_cstr(" []"); } else { - str_pool[pool_ptr] = c; - pool_ptr++; + set_str_pool(pool_ptr(), c); + set_pool_ptr(pool_ptr()+1); temp_ptr = p; - switch (mem[p].b32.s1) { + switch (mem(p).b32.s1) { case MATH_CHAR: print_ln(); print_current_string(); @@ -679,7 +680,7 @@ print_subsidiary_data(int32_t p, UTF16_code c) show_info(); break; case SUB_MLIST: - if (mem[p].b32.s0 == TEX_NULL) { + if (mem(p).b32.s0 == TEX_NULL) { print_ln(); print_current_string(); print_cstr("{}"); @@ -691,7 +692,7 @@ print_subsidiary_data(int32_t p, UTF16_code c) break; } - pool_ptr--; + set_pool_ptr(pool_ptr()-1); } } @@ -818,7 +819,7 @@ show_node_list(int32_t p) if (is_char_node(p)) { print_font_and_char(p); } else { - switch (mem[p].b16.s1) { + switch (mem(p).b16.s1) { case HLIST_NODE: case VLIST_NODE: case UNSET_NODE: @@ -830,32 +831,32 @@ show_node_list(int32_t p) print_esc_cstr("unset"); print_cstr("box("); - print_scaled(mem[p + 3].b32.s1); + print_scaled(mem(p + 3).b32.s1); print_char('+'); - print_scaled(mem[p + 2].b32.s1); + print_scaled(mem(p + 2).b32.s1); print_cstr(")x"); - print_scaled(mem[p + 1].b32.s1); + print_scaled(mem(p + 1).b32.s1); if (NODE_type(p) == UNSET_NODE) { /*193:*/ - if (mem[p].b16.s0 != 0) { + if (mem(p).b16.s0 != 0) { print_cstr(" ("); - print_int(mem[p].b16.s0 + 1); + print_int(mem(p).b16.s0 + 1); print_cstr(" columns)"); } - if (mem[p + 6].b32.s1 != 0) { + if (mem(p + 6).b32.s1 != 0) { print_cstr(", stretch "); - print_glue(mem[p + 6].b32.s1, mem[p + 5].b16.s0, NULL); + print_glue(mem(p + 6).b32.s1, mem(p + 5).b16.s0, NULL); } - if (mem[p + 4].b32.s1 != 0) { + if (mem(p + 4).b32.s1 != 0) { print_cstr(", shrink "); - print_glue(mem[p + 4].b32.s1, mem[p + 5].b16.s1, NULL); + print_glue(mem(p + 4).b32.s1, mem(p + 5).b16.s1, NULL); } } else { g = BOX_glue_set(p); - if (g != 0.0 && mem[p + 5].b16.s1 != NORMAL) { + if (g != 0.0 && mem(p + 5).b16.s1 != NORMAL) { print_cstr(", glue set "); - if (mem[p + 5].b16.s1 == SHRINKING) + if (mem(p + 5).b16.s1 == SHRINKING) print_cstr("- "); if (fabs(g) > 20000.0) { @@ -863,79 +864,79 @@ show_node_list(int32_t p) print_char('>'); else print_cstr("< -"); - print_glue(20000 * 65536L, mem[p + 5].b16.s0, NULL); + print_glue(20000 * 65536L, mem(p + 5).b16.s0, NULL); } else { - print_glue(tex_round(65536L * g), mem[p + 5].b16.s0, NULL); + print_glue(tex_round(65536L * g), mem(p + 5).b16.s0, NULL); } } - if (mem[p + 4].b32.s1 != 0) { + if (mem(p + 4).b32.s1 != 0) { print_cstr(", shifted "); - print_scaled(mem[p + 4].b32.s1); + print_scaled(mem(p + 4).b32.s1); } /*1491:*/ - if (NODE_type(p) == HLIST_NODE && mem[p].b16.s0 == DLIST) + if (NODE_type(p) == HLIST_NODE && mem(p).b16.s0 == DLIST) print_cstr(", display"); } - str_pool[pool_ptr] = '.' ; - pool_ptr++; - show_node_list(mem[p + 5].b32.s1); - pool_ptr--; + set_str_pool(pool_ptr(), '.'); + set_pool_ptr(pool_ptr()+1); + show_node_list(mem(p + 5).b32.s1); + set_pool_ptr(pool_ptr()-1); break; case RULE_NODE: print_esc_cstr("rule("); - print_rule_dimen(mem[p + 3].b32.s1); + print_rule_dimen(mem(p + 3).b32.s1); print_char('+'); - print_rule_dimen(mem[p + 2].b32.s1); + print_rule_dimen(mem(p + 2).b32.s1); print_cstr(")x"); - print_rule_dimen(mem[p + 1].b32.s1); + print_rule_dimen(mem(p + 1).b32.s1); break; case INS_NODE: print_esc_cstr("insert"); - print_int(mem[p].b16.s0); + print_int(mem(p).b16.s0); print_cstr(", natural size "); - print_scaled(mem[p + 3].b32.s1); + print_scaled(mem(p + 3).b32.s1); print_cstr("; split("); - print_spec(mem[p + 4].b32.s1, NULL); + print_spec(mem(p + 4).b32.s1, NULL); print_char(','); - print_scaled(mem[p + 2].b32.s1); + print_scaled(mem(p + 2).b32.s1); print_cstr("); float cost "); - print_int(mem[p + 1].b32.s1); - str_pool[pool_ptr] = '.' ; - pool_ptr++; - show_node_list(mem[p + 4].b32.s0); - pool_ptr--; + print_int(mem(p + 1).b32.s1); + set_str_pool(pool_ptr(), '.'); + set_pool_ptr(pool_ptr()+1); + show_node_list(mem(p + 4).b32.s0); + set_pool_ptr(pool_ptr()-1); break; case WHATSIT_NODE: - switch (mem[p].b16.s0) { + switch (mem(p).b16.s0) { case OPEN_NODE: print_write_whatsit("openout", p); print_char('='); - print_file_name(mem[p + 1].b32.s1, mem[p + 2].b32.s0, mem[p + 2].b32.s1); + print_file_name(mem(p + 1).b32.s1, mem(p + 2).b32.s0, mem(p + 2).b32.s1); break; case WRITE_NODE: print_write_whatsit("write", p); - print_mark(mem[p + 1].b32.s1); + print_mark(mem(p + 1).b32.s1); break; case CLOSE_NODE: print_write_whatsit("closeout", p); break; case SPECIAL_NODE: print_esc_cstr("special"); - print_mark(mem[p + 1].b32.s1); + print_mark(mem(p + 1).b32.s1); break; case LANGUAGE_NODE: print_esc_cstr("setlanguage"); - print_int(mem[p + 1].b32.s1); + print_int(mem(p + 1).b32.s1); print_cstr(" (hyphenmin "); - print_int(mem[p + 1].b16.s1); + print_int(mem(p + 1).b16.s1); print_char(','); - print_int(mem[p + 1].b16.s0); + print_int(mem(p + 1).b16.s0); print_char(')'); break; case PDF_SAVE_POS_NODE: @@ -943,18 +944,18 @@ show_node_list(int32_t p) break; case NATIVE_WORD_NODE: case NATIVE_WORD_NODE_AT: - print_esc(hash[FONT_ID_BASE + mem[p + 4].b16.s2].s1); + print_esc(hash(FONT_ID_BASE + mem(p + 4).b16.s2).s1); print_char(' '); print_native_word(p); break; case GLYPH_NODE: - print_esc(hash[FONT_ID_BASE + mem[p + 4].b16.s2].s1); + print_esc(hash(FONT_ID_BASE + mem(p + 4).b16.s2).s1); print_cstr(" glyph#"); - print_int(mem[p + 4].b16.s1); + print_int(mem(p + 4).b16.s1); break; case PIC_NODE: case PDF_NODE: - if (mem[p].b16.s0 == PIC_NODE) + if (mem(p).b16.s0 == PIC_NODE) print_esc_cstr("XeTeXpicfile"); else print_esc_cstr("XeTeXpdffile"); @@ -971,89 +972,89 @@ show_node_list(int32_t p) break; /* WHATSIT_NODE */ case GLUE_NODE: - if (mem[p].b16.s0 >= A_LEADERS) { /*198: */ + if (mem(p).b16.s0 >= A_LEADERS) { /*198: */ print_esc_cstr(""); - if (mem[p].b16.s0 == C_LEADERS) + if (mem(p).b16.s0 == C_LEADERS) print_char('c'); - else if (mem[p].b16.s0 == X_LEADERS) + else if (mem(p).b16.s0 == X_LEADERS) print_char('x'); print_cstr("leaders "); - print_spec(mem[p + 1].b32.s0, NULL); - str_pool[pool_ptr] = '.' ; - pool_ptr++; - show_node_list(mem[p + 1].b32.s1); - pool_ptr--; + print_spec(mem(p + 1).b32.s0, NULL); + set_str_pool(pool_ptr(), '.'); + set_pool_ptr(pool_ptr()+1); + show_node_list(mem(p + 1).b32.s1); + set_pool_ptr(pool_ptr()-1); } else { print_esc_cstr("glue"); if (GLUE_SPEC_shrink_order(p) != NORMAL) { print_char('('); - if (mem[p].b16.s0 < COND_MATH_GLUE) - print_skip_param(mem[p].b16.s0 - 1); - else if (mem[p].b16.s0 == COND_MATH_GLUE) + if (mem(p).b16.s0 < COND_MATH_GLUE) + print_skip_param(mem(p).b16.s0 - 1); + else if (mem(p).b16.s0 == COND_MATH_GLUE) print_esc_cstr("nonscript"); else print_esc_cstr("mskip"); print_char(')'); } - if (mem[p].b16.s0 != COND_MATH_GLUE) { + if (mem(p).b16.s0 != COND_MATH_GLUE) { print_char(' '); - if (mem[p].b16.s0 < COND_MATH_GLUE) - print_spec(mem[p + 1].b32.s0, NULL); + if (mem(p).b16.s0 < COND_MATH_GLUE) + print_spec(mem(p + 1).b32.s0, NULL); else - print_spec(mem[p + 1].b32.s0, "mu"); + print_spec(mem(p + 1).b32.s0, "mu"); } } break; case KERN_NODE: - if (mem[p].b16.s0 != MU_GLUE) { + if (mem(p).b16.s0 != MU_GLUE) { print_esc_cstr("kern"); - if (mem[p].b16.s0 != NORMAL) + if (mem(p).b16.s0 != NORMAL) print_char(' '); - print_scaled(mem[p + 1].b32.s1); + print_scaled(mem(p + 1).b32.s1); if (NODE_subtype(p) == ACC_KERN) print_cstr(" (for accent)"); else if (NODE_subtype(p) == SPACE_ADJUSTMENT) print_cstr(" (space adjustment)"); } else { print_esc_cstr("mkern"); - print_scaled(mem[p + 1].b32.s1); + print_scaled(mem(p + 1).b32.s1); print_cstr("mu"); } break; case MARGIN_KERN_NODE: print_esc_cstr("kern"); - print_scaled(mem[p + 1].b32.s1); - if (mem[p].b16.s0 == 0) + print_scaled(mem(p + 1).b32.s1); + if (mem(p).b16.s0 == 0) print_cstr(" (left margin)"); else print_cstr(" (right margin)"); break; case MATH_NODE: - if (mem[p].b16.s0 > AFTER) { - if (odd(mem[p].b16.s0)) + if (mem(p).b16.s0 > AFTER) { + if (odd(mem(p).b16.s0)) print_esc_cstr("end"); else print_esc_cstr("begin"); - if (mem[p].b16.s0 > R_CODE) + if (mem(p).b16.s0 > R_CODE) print_char('R'); - else if (mem[p].b16.s0 > L_CODE) + else if (mem(p).b16.s0 > L_CODE) print_char('L'); else print_char('M'); } else { print_esc_cstr("math"); - if (mem[p].b16.s0 == BEFORE) + if (mem(p).b16.s0 == BEFORE) print_cstr("on"); else print_cstr("off"); - if (mem[p + 1].b32.s1 != 0) { + if (mem(p + 1).b32.s1 != 0) { print_cstr(", surrounded "); - print_scaled(mem[p + 1].b32.s1); + print_scaled(mem(p + 1).b32.s1); } } break; @@ -1061,79 +1062,79 @@ show_node_list(int32_t p) case LIGATURE_NODE: print_font_and_char(p + 1); print_cstr(" (ligature "); - if (mem[p].b16.s0 > 1) + if (mem(p).b16.s0 > 1) print_char('|'); - font_in_short_display = mem[p + 1].b16.s1; - short_display(mem[p + 1].b32.s1); - if (odd(mem[p].b16.s0)) + font_in_short_display = mem(p + 1).b16.s1; + short_display(mem(p + 1).b32.s1); + if (odd(mem(p).b16.s0)) print_char('|'); print_char(')'); break; case PENALTY_NODE: print_esc_cstr("penalty "); - print_int(mem[p + 1].b32.s1); + print_int(mem(p + 1).b32.s1); break; case DISC_NODE: print_esc_cstr("discretionary"); - if (mem[p].b16.s0 > 0) { + if (mem(p).b16.s0 > 0) { print_cstr(" replacing "); - print_int(mem[p].b16.s0); + print_int(mem(p).b16.s0); } - str_pool[pool_ptr] = '.' ; - pool_ptr++; - show_node_list(mem[p + 1].b32.s0); - pool_ptr--; - str_pool[pool_ptr] = '|' ; - pool_ptr++; - show_node_list(mem[p + 1].b32.s1); - pool_ptr--; + set_str_pool(pool_ptr(), '.'); + set_pool_ptr(pool_ptr()+1); + show_node_list(mem(p + 1).b32.s0); + set_pool_ptr(pool_ptr()-1); + set_str_pool(pool_ptr(), '|' ); + set_pool_ptr(pool_ptr()+1); + show_node_list(mem(p + 1).b32.s1); + set_pool_ptr(pool_ptr()-1); break; case MARK_NODE: print_esc_cstr("mark"); - if (mem[p + 1].b32.s0 != 0) { + if (mem(p + 1).b32.s0 != 0) { print_char('s'); - print_int(mem[p + 1].b32.s0); + print_int(mem(p + 1).b32.s0); } - print_mark(mem[p + 1].b32.s1); + print_mark(mem(p + 1).b32.s1); break; case ADJUST_NODE: print_esc_cstr("vadjust"); - if (mem[p].b16.s0 != 0) + if (mem(p).b16.s0 != 0) print_cstr(" pre "); - str_pool[pool_ptr] = '.' ; - pool_ptr++; - show_node_list(mem[p + 1].b32.s1); - pool_ptr--; + set_str_pool(pool_ptr(), '.' ); + set_pool_ptr(pool_ptr()+1); + show_node_list(mem(p + 1).b32.s1); + set_pool_ptr(pool_ptr()-1); break; case STYLE_NODE: - print_style(mem[p].b16.s0); + print_style(mem(p).b16.s0); break; case CHOICE_NODE: print_esc_cstr("mathchoice"); - str_pool[pool_ptr] = 'D' ; - pool_ptr++; - show_node_list(mem[p + 1].b32.s0); - pool_ptr--; - str_pool[pool_ptr] = 'T' ; - pool_ptr++; - show_node_list(mem[p + 1].b32.s1); - pool_ptr--; - str_pool[pool_ptr] = 'S' ; - pool_ptr++; - show_node_list(mem[p + 2].b32.s0); - pool_ptr--; - str_pool[pool_ptr] = 's' ; - pool_ptr++; - show_node_list(mem[p + 2].b32.s1); - pool_ptr--; + set_str_pool(pool_ptr(), 'D' ); + set_pool_ptr(pool_ptr()+1); + show_node_list(mem(p + 1).b32.s0); + set_pool_ptr(pool_ptr()-1); + set_str_pool(pool_ptr(), 'T' ); + set_pool_ptr(pool_ptr()+1); + show_node_list(mem(p + 1).b32.s1); + set_pool_ptr(pool_ptr()-1); + set_str_pool(pool_ptr(), 'S' ); + set_pool_ptr(pool_ptr()+1); + show_node_list(mem(p + 2).b32.s0); + set_pool_ptr(pool_ptr()-1); + set_str_pool(pool_ptr(), 's' ); + set_pool_ptr(pool_ptr()+1); + show_node_list(mem(p + 2).b32.s1); + set_pool_ptr(pool_ptr()-1); break; case ORD_NOAD: @@ -1152,7 +1153,7 @@ show_node_list(int32_t p) case LEFT_NOAD: case RIGHT_NOAD: { - switch (mem[p].b16.s1) { + switch (mem(p).b16.s1) { case ORD_NOAD: print_esc_cstr("mathord"); break; @@ -1199,7 +1200,7 @@ show_node_list(int32_t p) print_delimiter(p + 1); break; case RIGHT_NOAD: - if (mem[p].b16.s0 == NORMAL) + if (mem(p).b16.s0 == NORMAL) print_esc_cstr("right"); else print_esc_cstr("middle"); @@ -1207,9 +1208,9 @@ show_node_list(int32_t p) break; } - if (mem[p].b16.s1 < LEFT_NOAD) { - if (mem[p].b16.s0 != NORMAL) { - if (mem[p].b16.s0 == LIMITS) + if (mem(p).b16.s1 < LEFT_NOAD) { + if (mem(p).b16.s0 != NORMAL) { + if (mem(p).b16.s0 == LIMITS) print_esc_cstr("limits"); else print_esc_cstr("nolimits"); @@ -1224,23 +1225,23 @@ show_node_list(int32_t p) case FRACTION_NOAD: print_esc_cstr("fraction, thickness "); - if (mem[p + 1].b32.s1 == DEFAULT_CODE) + if (mem(p + 1).b32.s1 == DEFAULT_CODE) print_cstr("= default"); else - print_scaled(mem[p + 1].b32.s1); + print_scaled(mem(p + 1).b32.s1); - if (mem[p + 4].b16.s3 % 256 != 0 || - (mem[p + 4].b16.s2 + (mem[p + 4].b16.s3 / 256) * 65536L) != 0 || - mem[p + 4].b16.s1 % 256 != 0 || - (mem[p + 4].b16.s0 + (mem[p + 4].b16.s1 / 256) * 65536L) != 0) { + if (mem(p + 4).b16.s3 % 256 != 0 || + (mem(p + 4).b16.s2 + (mem(p + 4).b16.s3 / 256) * 65536L) != 0 || + mem(p + 4).b16.s1 % 256 != 0 || + (mem(p + 4).b16.s0 + (mem(p + 4).b16.s1 / 256) * 65536L) != 0) { print_cstr(", left-delimiter "); print_delimiter(p + 4); } - if (mem[p + 5].b16.s3 % 256 != 0 || - (mem[p + 5].b16.s2 + (mem[p + 5].b16.s3 / 256) * 65536L) != 0 || - mem[p + 5].b16.s1 % 256 != 0 || - (mem[p + 5].b16.s0 + (mem[p + 5].b16.s1 / 256) * 65536L) != 0) { + if (mem(p + 5).b16.s3 % 256 != 0 || + (mem(p + 5).b16.s2 + (mem(p + 5).b16.s3 / 256) * 65536L) != 0 || + mem(p + 5).b16.s1 % 256 != 0 || + (mem(p + 5).b16.s0 + (mem(p + 5).b16.s1 / 256) * 65536L) != 0) { print_cstr(", right-delimiter "); print_delimiter(p + 5); } @@ -1267,8 +1268,8 @@ void show_box(int32_t p) breadth_max = INTPAR(show_box_breadth) /*:244 */ ; if (breadth_max <= 0) breadth_max = 5; - if (pool_ptr + depth_threshold >= pool_size) - depth_threshold = pool_size - pool_ptr - 1; + if (pool_ptr() + depth_threshold >= pool_size()) + depth_threshold = pool_size() - pool_ptr() - 1; show_node_list(p); print_ln(); } @@ -1276,24 +1277,24 @@ void show_box(int32_t p) void short_display_n(int32_t p, int32_t m) { breadth_max = m; - depth_threshold = pool_size - pool_ptr - 1; + depth_threshold = pool_size() - pool_ptr() - 1; show_node_list(p); } void delete_token_ref(int32_t p) { - if (mem[p].b32.s0 == TEX_NULL) + if (mem(p).b32.s0 == TEX_NULL) flush_list(p); else - mem[p].b32.s0--; + mem_ptr(p)->b32.s0--; } void delete_glue_ref(int32_t p) { - if (mem[p].b32.s1 == TEX_NULL) + if (mem(p).b32.s1 == TEX_NULL) free_node(p, GLUE_SPEC_SIZE); else - mem[p].b32.s1--; + mem_ptr(p)->b32.s1--; } @@ -1303,17 +1304,17 @@ flush_node_list(int32_t p) int32_t q; while (p != TEX_NULL) { - q = mem[p].b32.s1; + q = mem(p).b32.s1; if (is_char_node(p)) { - mem[p].b32.s1 = avail; + mem_ptr(p)->b32.s1 = avail; avail = p; } else { - switch (mem[p].b16.s1) { + switch (mem(p).b16.s1) { case HLIST_NODE: case VLIST_NODE: case UNSET_NODE: - flush_node_list(mem[p + 5].b32.s1); + flush_node_list(mem(p + 5).b32.s1); free_node(p, BOX_NODE_SIZE); goto done; break; @@ -1324,20 +1325,20 @@ flush_node_list(int32_t p) break; case INS_NODE: - flush_node_list(mem[p + 4].b32.s0); + flush_node_list(mem(p + 4).b32.s0); delete_glue_ref(INSERTION_NODE_split_top_ptr(p)); free_node(p, INS_NODE_SIZE); goto done; break; case WHATSIT_NODE: - switch (mem[p].b16.s0) { + switch (mem(p).b16.s0) { case OPEN_NODE: free_node(p, OPEN_NODE_SIZE); break; case WRITE_NODE: case SPECIAL_NODE: - delete_token_ref(mem[p + 1].b32.s1); + delete_token_ref(mem(p + 1).b32.s1); free_node(p, WRITE_NODE_SIZE); goto done; break; @@ -1360,7 +1361,7 @@ flush_node_list(int32_t p) case PDF_NODE: free_node(p, (PIC_NODE_SIZE + - (mem[p + 4].b16.s1 + sizeof(memory_word) - 1) / sizeof(memory_word))); + (mem(p + 4).b16.s1 + sizeof(memory_word) - 1) / sizeof(memory_word))); break; case PDF_SAVE_POS_NODE: free_node(p, SMALL_NODE_SIZE); @@ -1373,13 +1374,13 @@ flush_node_list(int32_t p) break; case GLUE_NODE: - if (mem[mem[p + 1].b32.s0].b32.s1 == TEX_NULL) - free_node(mem[p + 1].b32.s0, GLUE_SPEC_SIZE); + if (mem(mem(p + 1).b32.s0).b32.s1 == TEX_NULL) + free_node(mem(p + 1).b32.s0, GLUE_SPEC_SIZE); else - mem[mem[p + 1].b32.s0].b32.s1--; + mem_ptr(mem(p + 1).b32.s0)->b32.s1--; - if (mem[p + 1].b32.s1 != TEX_NULL) - flush_node_list(mem[p + 1].b32.s1); + if (mem(p + 1).b32.s1 != TEX_NULL) + flush_node_list(mem(p + 1).b32.s1); free_node(p, MEDIUM_NODE_SIZE); goto done; break; @@ -1397,20 +1398,20 @@ flush_node_list(int32_t p) break; case LIGATURE_NODE: - flush_node_list(mem[p + 1].b32.s1); + flush_node_list(mem(p + 1).b32.s1); break; case MARK_NODE: - delete_token_ref(mem[p + 1].b32.s1); + delete_token_ref(mem(p + 1).b32.s1); break; case DISC_NODE: - flush_node_list(mem[p + 1].b32.s0); - flush_node_list(mem[p + 1].b32.s1); + flush_node_list(mem(p + 1).b32.s0); + flush_node_list(mem(p + 1).b32.s1); break; case ADJUST_NODE: - flush_node_list(mem[p + 1].b32.s1); + flush_node_list(mem(p + 1).b32.s1); break; case STYLE_NODE: @@ -1419,10 +1420,10 @@ flush_node_list(int32_t p) break; case CHOICE_NODE: - flush_node_list(mem[p + 1].b32.s0); - flush_node_list(mem[p + 1].b32.s1); - flush_node_list(mem[p + 2].b32.s0); - flush_node_list(mem[p + 2].b32.s1); + flush_node_list(mem(p + 1).b32.s0); + flush_node_list(mem(p + 1).b32.s1); + flush_node_list(mem(p + 2).b32.s0); + flush_node_list(mem(p + 2).b32.s1); free_node(p, STYLE_NODE_SIZE); goto done; break; @@ -1440,15 +1441,15 @@ flush_node_list(int32_t p) case UNDER_NOAD: case VCENTER_NOAD: case ACCENT_NOAD: - if (mem[p + 1].b32.s1 >= SUB_BOX) - flush_node_list(mem[p + 1].b32.s0); - if (mem[p + 2].b32.s1 >= SUB_BOX) - flush_node_list(mem[p + 2].b32.s0); - if (mem[p + 3].b32.s1 >= SUB_BOX) - flush_node_list(mem[p + 3].b32.s0); - if (mem[p].b16.s1 == RADICAL_NOAD) + if (mem(p + 1).b32.s1 >= SUB_BOX) + flush_node_list(mem(p + 1).b32.s0); + if (mem(p + 2).b32.s1 >= SUB_BOX) + flush_node_list(mem(p + 2).b32.s0); + if (mem(p + 3).b32.s1 >= SUB_BOX) + flush_node_list(mem(p + 3).b32.s0); + if (mem(p).b16.s1 == RADICAL_NOAD) free_node(p, RADICAL_NOAD_SIZE); - else if (mem[p].b16.s1 == ACCENT_NOAD) + else if (mem(p).b16.s1 == ACCENT_NOAD) free_node(p, ACCENT_NOAD_SIZE); else free_node(p, NOAD_SIZE); @@ -1462,8 +1463,8 @@ flush_node_list(int32_t p) break; case FRACTION_NOAD: - flush_node_list(mem[p + 2].b32.s0); - flush_node_list(mem[p + 3].b32.s0); + flush_node_list(mem(p + 2).b32.s0); + flush_node_list(mem(p + 3).b32.s0); free_node(p, FRACTION_NOAD_SIZE); goto done; break; @@ -1499,16 +1500,16 @@ copy_node_list(int32_t p) if (is_char_node(p)) { r = get_avail(); } else { /*214:*/ - switch (mem[p].b16.s1) { + switch (mem(p).b16.s1) { case HLIST_NODE: case VLIST_NODE: case UNSET_NODE: r = get_node(BOX_NODE_SIZE); SYNCTEX_tag(r, BOX_NODE_SIZE) = SYNCTEX_tag(p, BOX_NODE_SIZE); SYNCTEX_line(r, BOX_NODE_SIZE) = SYNCTEX_line(p, BOX_NODE_SIZE); - mem[r + 6] = mem[p + 6]; - mem[r + 5] = mem[p + 5]; - mem[r + 5].b32.s1 = copy_node_list(mem[p + 5].b32.s1); + set_mem(r + 6, mem(p + 6)); + set_mem(r + 5, mem(p + 5)); + mem_ptr(r + 5)->b32.s1 = copy_node_list(mem(p + 5).b32.s1); words = 5; break; @@ -1519,14 +1520,14 @@ copy_node_list(int32_t p) case INS_NODE: r = get_node(INS_NODE_SIZE); - mem[r + 4] = mem[p + 4]; - GLUE_SPEC_ref_count(mem[p + 4].b32.s1)++; - mem[r + 4].b32.s0 = copy_node_list(mem[p + 4].b32.s0); + set_mem(r + 4, mem(p + 4)); + GLUE_SPEC_ref_count(mem(p + 4).b32.s1)++; + mem_ptr(r + 4)->b32.s0 = copy_node_list(mem(p + 4).b32.s0); words = (INS_NODE_SIZE - 1); break; case WHATSIT_NODE: - switch (mem[p].b16.s0) { + switch (mem(p).b16.s0) { case OPEN_NODE: r = get_node(OPEN_NODE_SIZE); words = OPEN_NODE_SIZE; @@ -1534,7 +1535,7 @@ copy_node_list(int32_t p) case WRITE_NODE: case SPECIAL_NODE: r = get_node(WRITE_NODE_SIZE); - mem[mem[p + 1].b32.s1].b32.s0++; + mem_ptr(mem(p + 1).b32.s1)->b32.s0++; words = WRITE_NODE_SIZE; break; case CLOSE_NODE: @@ -1549,7 +1550,7 @@ copy_node_list(int32_t p) while (words > 0) { words--; - mem[r + words] = mem[p + words]; + set_mem(r + words, mem(p + words)); } NATIVE_NODE_glyph_info_ptr(r) = NULL; @@ -1564,7 +1565,7 @@ copy_node_list(int32_t p) case PDF_NODE: words = (PIC_NODE_SIZE + - (mem[p + 4].b16.s1 + sizeof(memory_word) - 1) / sizeof(memory_word)); + (mem(p + 4).b16.s1 + sizeof(memory_word) - 1) / sizeof(memory_word)); r = get_node(words); break; case PDF_SAVE_POS_NODE: @@ -1578,11 +1579,11 @@ copy_node_list(int32_t p) case GLUE_NODE: r = get_node(MEDIUM_NODE_SIZE); - GLUE_SPEC_ref_count(mem[p + 1].b32.s0)++; - mem[r + 2].b32.s0 = mem[p + 2].b32.s0; - mem[r + 2].b32.s1 = mem[p + 2].b32.s1; - mem[r + 1].b32.s0 = mem[p + 1].b32.s0; - mem[r + 1].b32.s1 = copy_node_list(mem[p + 1].b32.s1); + GLUE_SPEC_ref_count(mem(p + 1).b32.s0)++; + mem_ptr(r + 2)->b32.s0 = mem(p + 2).b32.s0; + mem_ptr(r + 2)->b32.s1 = mem(p + 2).b32.s1; + mem_ptr(r + 1)->b32.s0 = mem(p + 1).b32.s0; + mem_ptr(r + 1)->b32.s1 = copy_node_list(mem(p + 1).b32.s1); break; case KERN_NODE: @@ -1599,25 +1600,25 @@ copy_node_list(int32_t p) case LIGATURE_NODE: r = get_node(SMALL_NODE_SIZE); - mem[r + 1] = mem[p + 1]; - mem[r + 1].b32.s1 = copy_node_list(mem[p + 1].b32.s1); + set_mem(r + 1, mem(p + 1)); + mem_ptr(r + 1)->b32.s1 = copy_node_list(mem(p + 1).b32.s1); break; case DISC_NODE: r = get_node(SMALL_NODE_SIZE); - mem[r + 1].b32.s0 = copy_node_list(mem[p + 1].b32.s0); - mem[r + 1].b32.s1 = copy_node_list(mem[p + 1].b32.s1); + mem_ptr(r + 1)->b32.s0 = copy_node_list(mem(p + 1).b32.s0); + mem_ptr(r + 1)->b32.s1 = copy_node_list(mem(p + 1).b32.s1); break; case MARK_NODE: r = get_node(SMALL_NODE_SIZE); - mem[mem[p + 1].b32.s1].b32.s0++; + mem_ptr(mem(p + 1).b32.s1)->b32.s0++; words = SMALL_NODE_SIZE; break; case ADJUST_NODE: r = get_node(SMALL_NODE_SIZE); - mem[r + 1].b32.s1 = copy_node_list(mem[p + 1].b32.s1); + mem_ptr(r + 1)->b32.s1 = copy_node_list(mem(p + 1).b32.s1); break; default: @@ -1628,17 +1629,17 @@ copy_node_list(int32_t p) while (words > 0) { words--; - mem[r + words] = mem[p + words]; + set_mem(r + words, mem(p + words)); } - mem[q].b32.s1 = r; + mem_ptr(q)->b32.s1 = r; q = r; p = LLIST_link(p); } - mem[q].b32.s1 = TEX_NULL; - q = mem[h].b32.s1; - mem[h].b32.s1 = avail; + mem_ptr(q)->b32.s1 = TEX_NULL; + q = mem(h).b32.s1; + mem_ptr(h)->b32.s1 = avail; avail = h; return q; } @@ -1714,14 +1715,14 @@ void push_nest(void) cur_list.head = get_avail(); cur_list.tail = cur_list.head; cur_list.prev_graf = 0; - cur_list.mode_line = line; + cur_list.mode_line = line(); cur_list.eTeX_aux = TEX_NULL; } void pop_nest(void) { { - mem[cur_list.head].b32.s1 = avail; + mem_ptr(cur_list.head)->b32.s1 = avail; avail = cur_list.head; } nest_ptr--; @@ -1770,33 +1771,33 @@ void show_activities(void) print_nl_cstr("### current page:"); if (output_active) print_cstr(" (held over for next output)"); - show_box(mem[PAGE_HEAD].b32.s1); + show_box(mem(PAGE_HEAD).b32.s1); if (page_contents > EMPTY) { print_nl_cstr("total height "); print_totals(); print_nl_cstr(" goal height "); print_scaled(page_so_far[0]); - r = mem[PAGE_INS_HEAD].b32.s1; + r = mem(PAGE_INS_HEAD).b32.s1; while (r != PAGE_INS_HEAD) { print_ln(); print_esc_cstr("insert"); - t = mem[r].b16.s0; + t = mem(r).b16.s0; print_int(t); print_cstr(" adds "); if (COUNT_REG(t) == 1000) - t = mem[r + 3].b32.s1; + t = mem(r + 3).b32.s1; else - t = x_over_n(mem[r + 3].b32.s1, 1000) * COUNT_REG(t); + t = x_over_n(mem(r + 3).b32.s1, 1000) * COUNT_REG(t); print_scaled(t); - if (mem[r].b16.s1 == SPLIT_UP) { + if (mem(r).b16.s1 == SPLIT_UP) { q = PAGE_HEAD; t = 0; do { q = LLIST_link(q); - if ((NODE_type(q) == INS_NODE) && (mem[q].b16.s0 == mem[r].b16.s0)) + if ((NODE_type(q) == INS_NODE) && (mem(q).b16.s0 == mem(r).b16.s0)) t++; - } while (!(q == mem[r + 1].b32.s0)); + } while (!(q == mem(r + 1).b32.s0)); print_cstr(", #"); print_int(t); print_cstr(" might split"); @@ -1805,10 +1806,10 @@ void show_activities(void) } } } - if (mem[CONTRIB_HEAD].b32.s1 != TEX_NULL) + if (mem(CONTRIB_HEAD).b32.s1 != TEX_NULL) print_nl_cstr("### recent contributions:"); } - show_box(mem[nest[p].head].b32.s1); + show_box(mem(nest[p].head).b32.s1); switch (abs(m) / ((MAX_COMMAND + 1))) { case 0: { @@ -2105,12 +2106,12 @@ void print_param(int32_t n) void begin_diagnostic(void) { - old_setting = selector; + old_setting = selector(); - if (INTPAR(tracing_online) <= 0 && selector == SELECTOR_TERM_AND_LOG) { - selector--; - if (history == HISTORY_SPOTLESS) - history = HISTORY_WARNING_ISSUED; + if (INTPAR(tracing_online) <= 0 && selector() == SELECTOR_TERM_AND_LOG) { + set_selector(selector()-1); + if (history() == HISTORY_SPOTLESS) + set_history(HISTORY_WARNING_ISSUED); } } @@ -2119,7 +2120,7 @@ void end_diagnostic(bool blank_line) print_nl_cstr(""); if (blank_line) print_ln(); - selector = old_setting; + set_selector(old_setting); } void print_length_param(int32_t n) @@ -2639,7 +2640,7 @@ print_cmd_chr(uint16_t cmd, int32_t chr_code) case REGISTER: if (chr_code < 0 || chr_code > 19 /*lo_mem_stat_max*/) { - cmd = (mem[chr_code].b16.s1 / 64); + cmd = (mem(chr_code).b16.s1 / 64); } else { cmd = chr_code; chr_code = TEX_NULL; @@ -3472,7 +3473,7 @@ print_cmd_chr(uint16_t cmd, int32_t chr_code) quote_char = '"' ; for (n = 0; n <= for_end; n++) { - if (str_pool[str_start[(font_name_str) - 65536L] + n] == '"' ) + if (str_pool(str_start((font_name_str) - 65536L) + n) == '"' ) quote_char = '\'' ; } @@ -3563,7 +3564,7 @@ print_cmd_chr(uint16_t cmd, int32_t chr_code) case OUTER_CALL: case LONG_OUTER_CALL: n = cmd - CALL; - if (mem[mem[chr_code].b32.s1].b32.s0 == PROTECTED_TOKEN) + if (mem(mem(chr_code).b32.s1).b32.s0 == PROTECTED_TOKEN) n = n + 4; if (odd(n / 4)) print_esc_cstr("protected"); @@ -3703,7 +3704,7 @@ id_lookup(int32_t j, int32_t l) h = 0; for (k = j; k <= j + l - 1; k++) { - h = h + h + buffer[k]; + h = h + h + buffer(k); while (h >= HASH_PRIME) h = h - 8501; } @@ -3712,69 +3713,69 @@ id_lookup(int32_t j, int32_t l) ll = l; for (d = 0; d <= l - 1; d++) { - if (buffer[j + d] >= 65536L) + if (buffer(j + d) >= 65536L) ll++; } while (true) { - if (hash[p].s1 > 0) { - if (length(hash[p].s1) == ll) { - if (str_eq_buf(hash[p].s1, j)) + if (hash(p).s1 > 0) { + if (length(hash(p).s1) == ll) { + if (str_eq_buf(hash(p).s1, j)) goto found; } } - if (hash[p].s0 == 0) { + if (hash(p).s0 == 0) { if (no_new_control_sequence) { p = UNDEFINED_CONTROL_SEQUENCE; } else { /*269:*/ - if (hash[p].s1 > 0) { - if (hash_high < hash_extra) { + if (hash(p).s1 > 0) { + if (hash_high < hash_extra()) { hash_high++; - hash[p].s0 = hash_high + EQTB_SIZE; + hash_ptr(p)->s0 = hash_high + EQTB_SIZE; p = hash_high + EQTB_SIZE; } else { do { - if (hash_used == HASH_BASE) - overflow("hash size", HASH_SIZE + hash_extra); - hash_used--; - } while (hash[hash_used].s1 != 0); + if (hash_used() == HASH_BASE) + overflow("hash size", HASH_SIZE + hash_extra()); + set_hash_used(hash_used()-1); + } while (hash(hash_used()).s1 != 0); - hash[p].s0 = hash_used; - p = hash_used; + hash_ptr(p)->s0 = hash_used(); + p = hash_used(); } } - if (pool_ptr + ll > pool_size) - overflow("pool size", pool_size - init_pool_ptr); + if (pool_ptr() + ll > pool_size()) + overflow("pool size", pool_size() - init_pool_ptr); d = cur_length(); - while (pool_ptr > str_start[str_ptr - TOO_BIG_CHAR]) { - pool_ptr--; - str_pool[pool_ptr + l] = str_pool[pool_ptr]; + while (pool_ptr() > str_start(str_ptr() - TOO_BIG_CHAR)) { + set_pool_ptr(pool_ptr()-1); + set_str_pool(pool_ptr() + l, str_pool(pool_ptr())); } for (k = j; k <= j + l - 1; k++) { - if (buffer[k] < 65536L) { - str_pool[pool_ptr] = buffer[k]; - pool_ptr++; + if (buffer(k) < 65536L) { + set_str_pool(pool_ptr(), buffer(k)); + set_pool_ptr(pool_ptr()+1); } else { - str_pool[pool_ptr] = 0xD800 + (buffer[k] - 65536L) / 1024; - pool_ptr++; - str_pool[pool_ptr] = 0xDC00 + (buffer[k] - 65536L) % 1024; - pool_ptr++; + set_str_pool(pool_ptr(), 0xD800 + (buffer(k) - 65536L) / 1024); + set_pool_ptr(pool_ptr()+1); + set_str_pool(pool_ptr(), 0xDC00 + (buffer(k) - 65536L) % 1024); + set_pool_ptr(pool_ptr()+1); } } - hash[p].s1 = make_string(); - pool_ptr += d; + hash_ptr(p)->s1 = make_string(); + set_pool_ptr(pool_ptr() + d); } goto found; } - p = hash[p].s0; + p = hash(p).s0; } found: @@ -3797,19 +3798,19 @@ int32_t prim_lookup(str_number s) p = (s % PRIM_PRIME) + 1; } else { - j = str_start[(s) - 65536L]; - if (s == str_ptr) + j = str_start((s) - 65536L); + if (s == str_ptr()) l = (cur_length()); else l = length(s); - h = str_pool[j]; + h = str_pool(j); { register int32_t for_end; k = j + 1; for_end = j + l - 1; if (k <= for_end) do { - h = h + h + str_pool[k]; + h = h + h + str_pool(k); while (h >= PRIM_PRIME) h = h - PRIM_PRIME; } @@ -3819,32 +3820,32 @@ int32_t prim_lookup(str_number s) } while (true) { - if (prim[p].s1 > 65536L) { - if (length(prim[p].s1) - 1 == l) { - if (str_eq_str(prim[p].s1 - 1, s)) + if (prim(p).s1 > 65536L) { + if (length(prim(p).s1) - 1 == l) { + if (str_eq_str(prim(p).s1 - 1, s)) goto found; } - } else if (prim[p].s1 == 1 + s) + } else if (prim(p).s1 == 1 + s) goto found; - if (prim[p].s0 == 0) { + if (prim(p).s0 == 0) { if (no_new_control_sequence) p = UNDEFINED_PRIMITIVE; else { /*272:*/ - if (prim[p].s1 > 0) { + if (prim(p).s1 > 0) { do { if (prim_used == PRIM_BASE) overflow("primitive size", PRIM_SIZE); prim_used--; - } while (!(prim[prim_used].s1 == 0)); - prim[p].s0 = prim_used; + } while (!(prim(prim_used).s1 == 0)); + prim_ptr(p)->s0 = prim_used; p = prim_used; } - prim[p].s1 = s + 1; + prim_ptr(p)->s1 = s + 1; } goto found; } - p = prim[p].s0; + p = prim(p).s0; } found: @@ -3937,16 +3938,16 @@ bool pseudo_input(void) b16x4 w; int32_t r; last = first; - p = mem[pseudo_files].b32.s0; + p = mem(pseudo_files).b32.s0; if (p == TEX_NULL) return false; else { - mem[pseudo_files].b32.s0 = mem[p].b32.s1; - sz = mem[p].b32.s0; + mem_ptr(pseudo_files)->b32.s0 = mem(p).b32.s1; + sz = mem(p).b32.s0; if (4 * sz - 3 >= buf_size - last) { /*35: */ - cur_input.loc = first; - cur_input.limit = last - 1; + cur_input_ptr()->loc = first; + cur_input_ptr()->limit = last - 1; overflow("buffer size", buf_size); } last = first; @@ -3956,18 +3957,18 @@ bool pseudo_input(void) for_end = p + sz - 1; if (r <= for_end) do { - w = mem[r].b16; - buffer[last] = w.s3; - buffer[last + 1] = w.s2; - buffer[last + 2] = w.s1; - buffer[last + 3] = w.s0; + w = mem(r).b16; + set_buffer(last, w.s3); + set_buffer(last + 1, w.s2); + set_buffer(last + 2, w.s1); + set_buffer(last + 3, w.s0); last = last + 4; } while (r++ < for_end); } if (last >= max_buf_stack) max_buf_stack = last + 1; - while ((last > first) && (buffer[last - 1] == ' ' )) + while ((last > first) && (buffer(last - 1) == ' ' )) last--; free_node(p, sz); return true; @@ -3977,18 +3978,18 @@ bool pseudo_input(void) void pseudo_close(void) { int32_t p, q; - p = mem[pseudo_files].b32.s1; - q = mem[pseudo_files].b32.s0; + p = mem(pseudo_files).b32.s1; + q = mem(pseudo_files).b32.s0; { - mem[pseudo_files].b32.s1 = avail; + mem_ptr(pseudo_files)->b32.s1 = avail; avail = pseudo_files; } pseudo_files = p; while (q != TEX_NULL) { p = q; - q = mem[p].b32.s1; - free_node(p, mem[p].b32.s0); + q = mem(p).b32.s1; + free_node(p, mem(p).b32.s0); } } @@ -3997,16 +3998,16 @@ void group_warning(void) int32_t i; bool w; - base_ptr = input_ptr; - input_stack[base_ptr] = cur_input; - i = in_open; + base_ptr = input_ptr(); + set_input_stack(base_ptr, cur_input()); + i = in_open(); w = false; while ((grp_stack[i] == cur_boundary) && (i > 0)) { if (INTPAR(tracing_nesting) > 0) { - while ((input_stack[base_ptr].state == TOKEN_LIST) || (input_stack[base_ptr].index > i)) + while ((input_stack(base_ptr).state == TOKEN_LIST) || (input_stack(base_ptr).index > i)) base_ptr--; - if (input_stack[base_ptr].name > 17) + if (input_stack(base_ptr).name > 17) w = true; } grp_stack[i] = save_stack[save_ptr].b32.s1; @@ -4022,8 +4023,8 @@ void group_warning(void) if (INTPAR(tracing_nesting) > 1) show_context(); - if (history == HISTORY_SPOTLESS) - history = HISTORY_WARNING_ISSUED; + if (history() == HISTORY_SPOTLESS) + set_history(HISTORY_WARNING_ISSUED); capture_to_diagnostic(NULL); } @@ -4034,19 +4035,19 @@ void if_warning(void) int32_t i; bool w; - base_ptr = input_ptr; - input_stack[base_ptr] = cur_input; - i = in_open; + base_ptr = input_ptr(); + set_input_stack(base_ptr, cur_input()); + i = in_open(); w = false; while (if_stack[i] == cond_ptr) { if (INTPAR(tracing_nesting) > 0) { - while ((input_stack[base_ptr].state == TOKEN_LIST) || (input_stack[base_ptr].index > i)) + while ((input_stack(base_ptr).state == TOKEN_LIST) || (input_stack(base_ptr).index > i)) base_ptr--; - if (input_stack[base_ptr].name > 17) + if (input_stack(base_ptr).name > 17) w = true; } - if_stack[i] = mem[cond_ptr].b32.s1; + if_stack[i] = mem(cond_ptr).b32.s1; i--; } if (w) { @@ -4065,8 +4066,8 @@ void if_warning(void) show_context(); capture_to_diagnostic(NULL); - if (history == HISTORY_SPOTLESS) - history = HISTORY_WARNING_ISSUED; + if (history() == HISTORY_SPOTLESS) + set_history(HISTORY_WARNING_ISSUED); } } @@ -4081,7 +4082,7 @@ void file_warning(void) l = cur_level; c = cur_group; save_ptr = cur_boundary; - while (grp_stack[in_open] != save_ptr) { + while (grp_stack[in_open()] != save_ptr) { cur_level--; print_nl_cstr("Warning: "); @@ -4101,7 +4102,7 @@ void file_warning(void) l = if_limit; c = cur_if; i = if_line; - while (if_stack[in_open] != cond_ptr) { + while (if_stack[in_open()] != cond_ptr) { print_nl_cstr("Warning: "); diagnostic_begin_capture_warning_here(); print_cstr("end of file when "); @@ -4115,9 +4116,9 @@ void file_warning(void) print_cstr(" is incomplete"); capture_to_diagnostic(NULL); - if_line = mem[cond_ptr + 1].b32.s1; - cur_if = mem[cond_ptr].b16.s0; - if_limit = mem[cond_ptr].b16.s1; + if_line = mem(cond_ptr + 1).b32.s1; + cur_if = mem(cond_ptr).b16.s0; + if_limit = mem(cond_ptr).b16.s1; cond_ptr = LLIST_link(cond_ptr); } cond_ptr = p; @@ -4130,8 +4131,8 @@ void file_warning(void) show_context(); capture_to_diagnostic(NULL); } - if (history == HISTORY_SPOTLESS) - history = HISTORY_WARNING_ISSUED; + if (history() == HISTORY_SPOTLESS) + set_history(HISTORY_WARNING_ISSUED); } void delete_sa_ref(int32_t q) @@ -4139,31 +4140,31 @@ void delete_sa_ref(int32_t q) int32_t p; small_number i; small_number s; - mem[q + 1].b32.s0--; - if (mem[q + 1].b32.s0 != TEX_NULL) + mem_ptr(q + 1)->b32.s0--; + if (mem(q + 1).b32.s0 != TEX_NULL) return; - if (mem[q].b16.s1 < DIMEN_VAL_LIMIT) { + if (mem(q).b16.s1 < DIMEN_VAL_LIMIT) { - if (mem[q + 2].b32.s1 == 0) + if (mem(q + 2).b32.s1 == 0) s = WORD_NODE_SIZE; else return; } else { - if (mem[q].b16.s1 < MU_VAL_LIMIT) { + if (mem(q).b16.s1 < MU_VAL_LIMIT) { - if (mem[q + 1].b32.s1 == 0) + if (mem(q + 1).b32.s1 == 0) delete_glue_ref(0); else return; - } else if (mem[q + 1].b32.s1 != TEX_NULL) + } else if (mem(q + 1).b32.s1 != TEX_NULL) return; s = POINTER_NODE_SIZE; } do { - i = mem[q].b16.s1 % 64; + i = mem(q).b16.s1 % 64; p = q; - q = mem[p].b32.s1; + q = mem(p).b32.s1; free_node(p, s); if (q == TEX_NULL) { sa_root[i] = TEX_NULL; @@ -4171,13 +4172,13 @@ void delete_sa_ref(int32_t q) } { if (odd(i)) - mem[q + (i / 2) + 1].b32.s1 = TEX_NULL; + mem_ptr(q + (i / 2) + 1)->b32.s1 = TEX_NULL; else - mem[q + (i / 2) + 1].b32.s0 = TEX_NULL; - mem[q].b16.s0--; + mem_ptr(q + (i / 2) + 1)->b32.s0 = TEX_NULL; + mem_ptr(q)->b16.s0--; } s = INDEX_NODE_SIZE; - } while (!(mem[q].b16.s0 > 0)); + } while (!(mem(q).b16.s0 > 0)); } /*:1609*//*1611: */ @@ -4199,56 +4200,56 @@ void sa_save(int32_t p) sa_chain = TEX_NULL; sa_level = cur_level; } - i = mem[p].b16.s1; + i = mem(p).b16.s1; if (i < DIMEN_VAL_LIMIT) { - if (mem[p + 2].b32.s1 == 0) { + if (mem(p + 2).b32.s1 == 0) { q = get_node(POINTER_NODE_SIZE); i = TOK_VAL_LIMIT; } else { q = get_node(WORD_NODE_SIZE); - mem[q + 2].b32.s1 = mem[p + 2].b32.s1; + mem_ptr(q + 2)->b32.s1 = mem(p + 2).b32.s1; } - mem[q + 1].b32.s1 = TEX_NULL; + mem_ptr(q + 1)->b32.s1 = TEX_NULL; } else { q = get_node(POINTER_NODE_SIZE); - mem[q + 1].b32.s1 = mem[p + 1].b32.s1; + mem_ptr(q + 1)->b32.s1 = mem(p + 1).b32.s1; } - mem[q + 1].b32.s0 = p; - mem[q].b16.s1 = i; - mem[q].b16.s0 = mem[p].b16.s0; - mem[q].b32.s1 = sa_chain; + mem_ptr(q + 1)->b32.s0 = p; + mem_ptr(q)->b16.s1 = i; + mem_ptr(q)->b16.s0 = mem(p).b16.s0; + mem_ptr(q)->b32.s1 = sa_chain; sa_chain = q; - mem[p + 1].b32.s0++; + mem_ptr(p + 1)->b32.s0++; } void sa_destroy(int32_t p) { - if (mem[p].b16.s1 < MU_VAL_LIMIT) - delete_glue_ref(mem[p + 1].b32.s1); - else if (mem[p + 1].b32.s1 != TEX_NULL) { + if (mem(p).b16.s1 < MU_VAL_LIMIT) + delete_glue_ref(mem(p + 1).b32.s1); + else if (mem(p + 1).b32.s1 != TEX_NULL) { - if (mem[p].b16.s1 < BOX_VAL_LIMIT) - flush_node_list(mem[p + 1].b32.s1); + if (mem(p).b16.s1 < BOX_VAL_LIMIT) + flush_node_list(mem(p + 1).b32.s1); else - delete_token_ref(mem[p + 1].b32.s1); + delete_token_ref(mem(p + 1).b32.s1); } } void sa_def(int32_t p, int32_t e) { - mem[p + 1].b32.s0++; - if (mem[p + 1].b32.s1 == e) { + mem_ptr(p + 1)->b32.s0++; + if (mem(p + 1).b32.s1 == e) { sa_destroy(p); } else { - if (mem[p].b16.s0 == cur_level) + if (mem(p).b16.s0 == cur_level) sa_destroy(p); else sa_save(p); - mem[p].b16.s0 = cur_level; - mem[p + 1].b32.s1 = e; + mem_ptr(p)->b16.s0 = cur_level; + mem_ptr(p + 1)->b32.s1 = e; } delete_sa_ref(p); } @@ -4256,14 +4257,14 @@ void sa_def(int32_t p, int32_t e) void sa_w_def(int32_t p, int32_t w) { - mem[p + 1].b32.s0++; + mem_ptr(p + 1)->b32.s0++; - if (mem[p + 2].b32.s1 == w) { + if (mem(p + 2).b32.s1 == w) { } else { - if (mem[p].b16.s0 != cur_level) + if (mem(p).b16.s0 != cur_level) sa_save(p); - mem[p].b16.s0 = cur_level; - mem[p + 2].b32.s1 = w; + mem_ptr(p)->b16.s0 = cur_level; + mem_ptr(p + 2)->b32.s1 = w; } delete_sa_ref(p); } @@ -4271,19 +4272,19 @@ void sa_w_def(int32_t p, int32_t w) void gsa_def(int32_t p, int32_t e) { - mem[p + 1].b32.s0++; + mem_ptr(p + 1)->b32.s0++; sa_destroy(p); - mem[p].b16.s0 = LEVEL_ONE; - mem[p + 1].b32.s1 = e; + mem_ptr(p)->b16.s0 = LEVEL_ONE; + mem_ptr(p + 1)->b32.s1 = e; delete_sa_ref(p); } void gsa_w_def(int32_t p, int32_t w) { - mem[p + 1].b32.s0++; - mem[p].b16.s0 = LEVEL_ONE; - mem[p + 2].b32.s1 = w; + mem_ptr(p + 1)->b32.s0++; + mem_ptr(p)->b16.s0 = LEVEL_ONE; + mem_ptr(p + 2)->b32.s1 = w; delete_sa_ref(p); } @@ -4292,29 +4293,29 @@ void sa_restore(void) int32_t p; do { - p = mem[sa_chain + 1].b32.s0; - if (mem[p].b16.s0 == LEVEL_ONE) { - if (mem[p].b16.s1 >= DIMEN_VAL_LIMIT) + p = mem(sa_chain + 1).b32.s0; + if (mem(p).b16.s0 == LEVEL_ONE) { + if (mem(p).b16.s1 >= DIMEN_VAL_LIMIT) sa_destroy(sa_chain); } else { - if (mem[p].b16.s1 < DIMEN_VAL_LIMIT) { + if (mem(p).b16.s1 < DIMEN_VAL_LIMIT) { - if (mem[sa_chain].b16.s1 < DIMEN_VAL_LIMIT) - mem[p + 2].b32.s1 = mem[sa_chain + 2].b32.s1; + if (mem(sa_chain).b16.s1 < DIMEN_VAL_LIMIT) + mem_ptr(p + 2)->b32.s1 = mem(sa_chain + 2).b32.s1; else - mem[p + 2].b32.s1 = 0; + mem_ptr(p + 2)->b32.s1 = 0; } else { sa_destroy(p); - mem[p + 1].b32.s1 = mem[sa_chain + 1].b32.s1; + mem_ptr(p + 1)->b32.s1 = mem(sa_chain + 1).b32.s1; } - mem[p].b16.s0 = mem[sa_chain].b16.s0; + mem_ptr(p)->b16.s0 = mem(sa_chain).b16.s0; } delete_sa_ref(p); p = sa_chain; - sa_chain = mem[p].b32.s1; - if (mem[p].b16.s1 < DIMEN_VAL_LIMIT) + sa_chain = mem(p).b32.s1; + if (mem(p).b16.s1 < DIMEN_VAL_LIMIT) free_node(p, WORD_NODE_SIZE); else free_node(p, POINTER_NODE_SIZE); @@ -4329,7 +4330,7 @@ void new_save_level(group_code c) overflow("save size", save_size); } - save_stack[save_ptr + 0].b32.s1 = line; + save_stack[save_ptr + 0].b32.s1 = line(); save_ptr++; save_stack[save_ptr].b16.s1 = LEVEL_BOUNDARY; save_stack[save_ptr].b16.s0 = cur_group; @@ -4359,7 +4360,7 @@ void eq_destroy(memory_word w) { q = w.b32.s1; if (q != TEX_NULL) - free_node(q, mem[q].b32.s0 + mem[q].b32.s0 + 1); + free_node(q, mem(q).b32.s0 + mem(q).b32.s0 + 1); } break; case 121: @@ -4388,7 +4389,7 @@ void eq_save(int32_t p, uint16_t l) save_stack[save_ptr].b16.s1 = RESTORE_ZERO; else { - save_stack[save_ptr] = eqtb[p]; + save_stack[save_ptr] = eqtb(p); save_ptr++; save_stack[save_ptr].b16.s1 = RESTORE_OLD_VALUE; } @@ -4401,48 +4402,48 @@ void eq_define(int32_t p, uint16_t t, int32_t e) { - if (eqtb[p].b16.s1 == t && eqtb[p].b32.s1 == e) { - eq_destroy(eqtb[p]); + if (eqtb(p).b16.s1 == t && eqtb(p).b32.s1 == e) { + eq_destroy(eqtb(p)); return; } - if (eqtb[p].b16.s0 == cur_level) - eq_destroy(eqtb[p]); + if (eqtb(p).b16.s0 == cur_level) + eq_destroy(eqtb(p)); else if (cur_level > LEVEL_ONE) - eq_save(p, eqtb[p].b16.s0); + eq_save(p, eqtb(p).b16.s0); - eqtb[p].b16.s0 = cur_level; - eqtb[p].b16.s1 = t; - eqtb[p].b32.s1 = e; + eqtb_ptr(p)->b16.s0 = cur_level; + eqtb_ptr(p)->b16.s1 = t; + eqtb_ptr(p)->b32.s1 = e; } void eq_word_define(int32_t p, int32_t w) { - if (eqtb[p].b32.s1 == w) + if (eqtb(p).b32.s1 == w) return; if (XEQ_LEVEL(p) != cur_level) { eq_save(p, XEQ_LEVEL(p)); XEQ_LEVEL(p) = cur_level; } - eqtb[p].b32.s1 = w; + eqtb_ptr(p)->b32.s1 = w; } void geq_define(int32_t p, uint16_t t, int32_t e) { - eq_destroy(eqtb[p]); - eqtb[p].b16.s0 = LEVEL_ONE; - eqtb[p].b16.s1 = t; - eqtb[p].b32.s1 = e; + eq_destroy(eqtb(p)); + eqtb_ptr(p)->b16.s0 = LEVEL_ONE; + eqtb_ptr(p)->b16.s1 = t; + eqtb_ptr(p)->b32.s1 = e; } void geq_word_define(int32_t p, int32_t w) { - eqtb[p].b32.s1 = w; + eqtb_ptr(p)->b32.s1 = w; XEQ_LEVEL(p) = LEVEL_ONE; } @@ -4482,10 +4483,10 @@ void unsave(void) cur_tok = p; if (a) { p = get_avail(); - mem[p].b32.s0 = cur_tok; - mem[p].b32.s1 = cur_input.loc; - cur_input.loc = p; - cur_input.start = p; + mem_ptr(p)->b32.s0 = cur_tok; + mem_ptr(p)->b32.s1 = cur_input().loc; + cur_input_ptr()->loc = p; + cur_input_ptr()->start = p; if (cur_tok < RIGHT_BRACE_LIMIT) { if (cur_tok < LEFT_BRACE_LIMIT) @@ -4508,24 +4509,24 @@ void unsave(void) l = save_stack[save_ptr].b16.s0; save_ptr--; } else - save_stack[save_ptr] = eqtb[UNDEFINED_CONTROL_SEQUENCE]; + save_stack[save_ptr] = eqtb(UNDEFINED_CONTROL_SEQUENCE); if ((p < INT_BASE) || (p > EQTB_SIZE)) { - if (eqtb[p].b16.s0 == LEVEL_ONE) { + if (eqtb_ptr(p)->b16.s0 == LEVEL_ONE) { eq_destroy(save_stack[save_ptr]); } else { - eq_destroy(eqtb[p]); - eqtb[p] = save_stack[save_ptr]; + eq_destroy(eqtb(p)); + set_eqtb(p, save_stack[save_ptr]); } } else if (XEQ_LEVEL(p) != LEVEL_ONE) { - eqtb[p] = save_stack[save_ptr]; + set_eqtb(p, save_stack[save_ptr]); XEQ_LEVEL(p) = l; } } } done: - if (grp_stack[in_open] == cur_boundary) + if (grp_stack[in_open()] == cur_boundary) group_warning(); cur_group = save_stack[save_ptr].b16.s0; cur_boundary = save_stack[save_ptr].b32.s1; @@ -4573,7 +4574,7 @@ void token_show(int32_t p) { if (p != TEX_NULL) - show_token_list(mem[p].b32.s1, TEX_NULL, 10000000L); + show_token_list(mem(p).b32.s1, TEX_NULL, 10000000L); } void print_meaning(void) @@ -4622,7 +4623,7 @@ void show_cur_cmd_chr(void) } else { n = 1; - l = line; + l = line(); } p = cond_ptr; while (p != TEX_NULL) { @@ -4660,28 +4661,28 @@ void show_context(void) int32_t p; int32_t q; - base_ptr = input_ptr; - input_stack[base_ptr] = cur_input; + base_ptr = input_ptr(); + set_input_stack(base_ptr, cur_input()); nn = -1; bottom_line = false; while (true) { - cur_input = input_stack[base_ptr]; - if ((cur_input.state != TOKEN_LIST)) { + set_cur_input(input_stack(base_ptr)); + if ((cur_input().state != TOKEN_LIST)) { - if ((cur_input.name > 19) || (base_ptr == 0)) + if ((cur_input().name > 19) || (base_ptr == 0)) bottom_line = true; } - if ((base_ptr == input_ptr) || bottom_line || (nn < INTPAR(error_context_lines))) { /*324: */ - if ((base_ptr == input_ptr) || (cur_input.state != TOKEN_LIST) - || (cur_input.index != BACKED_UP) || (cur_input.loc != TEX_NULL)) { - tally = 0; - old_setting = selector; - if (cur_input.state != TOKEN_LIST) { - if (cur_input.name <= 17) { + if ((base_ptr == input_ptr()) || bottom_line || (nn < INTPAR(error_context_lines))) { /*324: */ + if ((base_ptr == input_ptr()) || (cur_input().state != TOKEN_LIST) + || (cur_input().index != BACKED_UP) || (cur_input().loc != TEX_NULL)) { + set_tally(0); + old_setting = selector(); + if (cur_input().state != TOKEN_LIST) { + if (cur_input().name <= 17) { - if (cur_input.name == 0) { + if (cur_input().name == 0) { if (base_ptr == 0) print_nl_cstr("<*>"); @@ -4690,50 +4691,50 @@ void show_context(void) } else { print_nl_cstr("'); } } else { print_nl_cstr("l."); - if (cur_input.index == in_open) - print_int(line); + if (cur_input().index == in_open()) + print_int(line()); else - print_int(line_stack[cur_input.index + 1]); + print_int(line_stack(cur_input().index + 1)); } print_char(' '); { - l = tally; - tally = 0; - selector = SELECTOR_PSEUDO; - trick_count = 1000000L; + l = tally(); + set_tally(0); + set_selector(SELECTOR_PSEUDO); + set_trick_count(1000000L); } - if (buffer[cur_input.limit] == INTPAR(end_line_char)) - j = cur_input.limit; + if (buffer(cur_input().limit) == INTPAR(end_line_char)) + j = cur_input().limit; else - j = cur_input.limit + 1; + j = cur_input().limit + 1; if (j > 0) { register int32_t for_end; - i = cur_input.start; + i = cur_input().start; for_end = j - 1; if (i <= for_end) do { - if (i == cur_input.loc) { - first_count = tally; - trick_count = tally + 1 + error_line - half_error_line; - if (trick_count < error_line) - trick_count = error_line; + if (i == cur_input().loc) { + first_count = tally(); + set_trick_count(tally() + 1 + error_line() - half_error_line); + if (trick_count() < error_line()) + set_trick_count(error_line()); } - print_char(buffer[i]); + print_char(buffer(i)); } while (i++ < for_end); } } else { - switch (cur_input.index) { + switch (cur_input().index) { case PARAMETER: print_nl_cstr(" "); break; @@ -4743,7 +4744,7 @@ void show_context(void) break; case BACKED_UP: case BACKED_UP_CHAR: - if (cur_input.loc == TEX_NULL) + if (cur_input().loc == TEX_NULL) print_nl_cstr(" "); else print_nl_cstr(" "); @@ -4753,7 +4754,7 @@ void show_context(void) break; case MACRO: print_ln(); - print_cs(cur_input.name); + print_cs(cur_input().name); break; case OUTPUT_TEXT: print_nl_cstr(" "); @@ -4799,27 +4800,27 @@ void show_context(void) break; } { - l = tally; - tally = 0; - selector = SELECTOR_PSEUDO; - trick_count = 1000000L; + l = tally(); + set_tally(0); + set_selector(SELECTOR_PSEUDO); + set_trick_count(1000000L); } - if (cur_input.index < MACRO) - show_token_list(cur_input.start, cur_input.loc, 100000L); + if (cur_input().index < MACRO) + show_token_list(cur_input().start, cur_input().loc, 100000L); else - show_token_list(mem[cur_input.start].b32.s1, cur_input.loc, 100000L); + show_token_list(mem(cur_input().start).b32.s1, cur_input().loc, 100000L); } - selector = old_setting; - if (trick_count == 1000000L) { - first_count = tally; - trick_count = tally + 1 + error_line - half_error_line; - if (trick_count < error_line) - trick_count = error_line; + set_selector(old_setting); + if (trick_count() == 1000000L) { + first_count = tally(); + set_trick_count(tally() + 1 + error_line() - half_error_line); + if (trick_count() < error_line()) + set_trick_count(error_line()); } - if (tally < trick_count) - m = tally - first_count; + if (tally() < trick_count()) + m = tally() - first_count; else - m = trick_count - first_count; + m = trick_count() - first_count; if (l + first_count <= half_error_line) { p = 0; n = l + first_count; @@ -4835,7 +4836,7 @@ void show_context(void) for_end = first_count - 1; if (q <= for_end) do - print_char(trick_buf[q % error_line]); + print_char(trick_buf(q % error_line())); while (q++ < for_end); } print_ln(); @@ -4848,20 +4849,20 @@ void show_context(void) print_raw_char(' ', true); while (q++ < for_end); } - if (m + n <= error_line) + if (m + n <= error_line()) p = first_count + m; else - p = first_count + (error_line - n - 3); + p = first_count + (error_line() - n - 3); { register int32_t for_end; q = first_count; for_end = p - 1; if (q <= for_end) do - print_char(trick_buf[q % error_line]); + print_char(trick_buf(q % error_line())); while (q++ < for_end); } - if (m + n > error_line) + if (m + n > error_line()) print_cstr("..."); nn++; } @@ -4874,7 +4875,7 @@ void show_context(void) base_ptr--; } done: - cur_input = input_stack[input_ptr]; + set_cur_input(input_stack(input_ptr())); } @@ -4882,26 +4883,26 @@ void begin_token_list(int32_t p, uint16_t t) { - if (input_ptr > max_in_stack) { - max_in_stack = input_ptr; - if (input_ptr == stack_size) + if (input_ptr() > max_in_stack) { + max_in_stack = input_ptr(); + if (input_ptr() == stack_size) overflow("input stack size", stack_size); } - input_stack[input_ptr] = cur_input; - input_ptr++; + set_input_stack(input_ptr(), cur_input()); + set_input_ptr(input_ptr()+1); - cur_input.state = TOKEN_LIST; - cur_input.start = p; - cur_input.index = t; + cur_input_ptr()->state = TOKEN_LIST; + cur_input_ptr()->start = p; + cur_input_ptr()->index = t; if (t >= MACRO) { - mem[p].b32.s0++; + mem_ptr(p)->b32.s0++; if (t == MACRO) { - cur_input.limit = param_ptr; + cur_input_ptr()->limit = param_ptr; } else { - cur_input.loc = mem[p].b32.s1; + cur_input_ptr()->loc = mem(p).b32.s1; if (INTPAR(tracing_macros) > 1) { begin_diagnostic(); @@ -4925,27 +4926,27 @@ begin_token_list(int32_t p, uint16_t t) } } } else { - cur_input.loc = p; + cur_input_ptr()->loc = p; } } void end_token_list(void) { - if (cur_input.index >= BACKED_UP) { - if (cur_input.index <= INSERTED) - flush_list(cur_input.start); + if (cur_input().index >= BACKED_UP) { + if (cur_input().index <= INSERTED) + flush_list(cur_input().start); else { - delete_token_ref(cur_input.start); - if (cur_input.index == MACRO) - while (param_ptr > cur_input.limit) { + delete_token_ref(cur_input().start); + if (cur_input().index == MACRO) + while (param_ptr > cur_input().limit) { param_ptr--; flush_list(param_stack[param_ptr]); } } - } else if (cur_input.index == U_TEMPLATE) { + } else if (cur_input().index == U_TEMPLATE) { if (align_state > 500000L) align_state = 0; @@ -4953,19 +4954,19 @@ void end_token_list(void) fatal_error("(interwoven alignment preambles are not allowed)"); } { - input_ptr--; - cur_input = input_stack[input_ptr]; + set_input_ptr(input_ptr()-1); + set_cur_input(input_stack(input_ptr())); } } void back_input(void) { int32_t p; - while ((cur_input.state == TOKEN_LIST) && (cur_input.loc == TEX_NULL) - && (cur_input.index != V_TEMPLATE)) + while ((cur_input().state == TOKEN_LIST) && (cur_input().loc == TEX_NULL) + && (cur_input().index != V_TEMPLATE)) end_token_list(); p = get_avail(); - mem[p].b32.s0 = cur_tok; + mem_ptr(p)->b32.s0 = cur_tok; if (cur_tok < RIGHT_BRACE_LIMIT) { if (cur_tok < LEFT_BRACE_LIMIT) @@ -4974,18 +4975,18 @@ void back_input(void) align_state++; } { - if (input_ptr > max_in_stack) { - max_in_stack = input_ptr; - if (input_ptr == stack_size) + if (input_ptr() > max_in_stack) { + max_in_stack = input_ptr(); + if (input_ptr() == stack_size) overflow("input stack size", stack_size); } - input_stack[input_ptr] = cur_input; - input_ptr++; + set_input_stack(input_ptr(), cur_input()); + set_input_ptr(input_ptr()+1); } - cur_input.state = TOKEN_LIST; - cur_input.start = p; - cur_input.index = BACKED_UP; - cur_input.loc = p; + cur_input_ptr()->state = TOKEN_LIST; + cur_input_ptr()->start = p; + cur_input_ptr()->index = BACKED_UP; + cur_input_ptr()->loc = p; } void @@ -4999,55 +5000,55 @@ void ins_error(void) { back_input(); - cur_input.index = INSERTED; + cur_input_ptr()->index = INSERTED; error(); } void begin_file_reading(void) { - if (in_open == max_in_open) + if (in_open() == max_in_open) overflow("text input levels", max_in_open); if (first == buf_size) overflow("buffer size", buf_size); - in_open++; + set_in_open(in_open()+1); { - if (input_ptr > max_in_stack) { - max_in_stack = input_ptr; - if (input_ptr == stack_size) + if (input_ptr() > max_in_stack) { + max_in_stack = input_ptr(); + if (input_ptr() == stack_size) overflow("input stack size", stack_size); } - input_stack[input_ptr] = cur_input; - input_ptr++; + set_input_stack(input_ptr(), cur_input()); + set_input_ptr(input_ptr()+1); } - cur_input.index = in_open; - source_filename_stack[cur_input.index] = 0; - full_source_filename_stack[cur_input.index] = 0; - eof_seen[cur_input.index] = false; - grp_stack[cur_input.index] = cur_boundary; - if_stack[cur_input.index] = cond_ptr; - line_stack[cur_input.index] = line; - cur_input.start = first; - cur_input.state = MID_LINE; - cur_input.name = 0; - cur_input.synctex_tag = 0; + cur_input_ptr()->index = in_open(); + source_filename_stack[cur_input().index] = 0; + set_full_source_filename_stack(cur_input().index, 0); + eof_seen[cur_input().index] = false; + grp_stack[cur_input().index] = cur_boundary; + if_stack[cur_input().index] = cond_ptr; + set_line_stack(cur_input().index, line()); + cur_input_ptr()->start = first; + cur_input_ptr()->state = MID_LINE; + cur_input_ptr()->name = 0; + cur_input_ptr()->synctex_tag = 0; } void end_file_reading(void) { - first = cur_input.start; - line = line_stack[cur_input.index]; + first = cur_input().start; + set_line(line_stack(cur_input().index)); - if (cur_input.name == 18 || cur_input.name == 19) { + if (cur_input().name == 18 || cur_input().name == 19) { pseudo_close(); - } else if (cur_input.name > 17) { - u_close(input_file[cur_input.index]); - input_file[cur_input.index] = NULL; + } else if (cur_input().name > 17) { + u_close(input_file[cur_input().index]); + input_file[cur_input().index] = NULL; } - input_ptr--; - cur_input = input_stack[input_ptr]; - in_open--; + set_input_ptr(input_ptr()-1); + set_cur_input(input_stack(input_ptr())); + set_in_open(in_open() - 1); } @@ -5061,9 +5062,9 @@ check_outer_validity(void) deletions_allowed = false; if (cur_cs != 0) { - if (cur_input.state == TOKEN_LIST || cur_input.name < 1 || cur_input.name > 17) { + if (cur_input().state == TOKEN_LIST || cur_input().name < 1 || cur_input().name > 17) { p = get_avail(); - mem[p].b32.s0 = CS_TOKEN_FLAG + cur_cs; + mem_ptr(p)->b32.s0 = CS_TOKEN_FLAG + cur_cs; begin_token_list(p, BACKED_UP); } @@ -5086,27 +5087,27 @@ check_outer_validity(void) switch (scanner_status) { case DEFINING: print_cstr(" while scanning definition"); - mem[p].b32.s0 = (RIGHT_BRACE_TOKEN + '}' ); + mem_ptr(p)->b32.s0 = (RIGHT_BRACE_TOKEN + '}' ); break; case MATCHING: print_cstr(" while scanning use"); - mem[p].b32.s0 = par_token; + mem_ptr(p)->b32.s0 = par_token; long_state = OUTER_CALL; break; case ALIGNING: print_cstr(" while scanning preamble"); - mem[p].b32.s0 = (RIGHT_BRACE_TOKEN + '}' ); + mem_ptr(p)->b32.s0 = (RIGHT_BRACE_TOKEN + '}' ); q = p; p = get_avail(); - mem[p].b32.s1 = q; - mem[p].b32.s0 = CS_TOKEN_FLAG + FROZEN_CR; + mem_ptr(p)->b32.s1 = q; + mem_ptr(p)->b32.s0 = CS_TOKEN_FLAG + FROZEN_CR; align_state = -1000000L; break; case ABSORBING: print_cstr(" while scanning text"); - mem[p].b32.s0 = (RIGHT_BRACE_TOKEN + '}' ); + mem_ptr(p)->b32.s0 = (RIGHT_BRACE_TOKEN + '}' ); break; } @@ -5166,23 +5167,23 @@ get_next(void) restart: cur_cs = 0; - if (cur_input.state != TOKEN_LIST) { /*355:*/ + if (cur_input().state != TOKEN_LIST) { /*355:*/ texswitch: - if (cur_input.loc <= cur_input.limit) { - cur_chr = buffer[cur_input.loc]; - cur_input.loc++; - - if (cur_chr >= 0xD800 && cur_chr < 0xDC00 && cur_input.loc <= cur_input.limit && - buffer[cur_input.loc] >= 0xDC00 && buffer[cur_input.loc] < 0xE000) { - lower = buffer[cur_input.loc] - 0xDC00; - cur_input.loc++; + if (cur_input().loc <= cur_input().limit) { + cur_chr = buffer(cur_input().loc); + cur_input_ptr()->loc++; + + if (cur_chr >= 0xD800 && cur_chr < 0xDC00 && cur_input().loc <= cur_input().limit && + buffer(cur_input().loc) >= 0xDC00 && buffer(cur_input().loc) < 0xE000) { + lower = buffer(cur_input().loc) - 0xDC00; + cur_input_ptr()->loc++; cur_chr = 65536L + (cur_chr - 0xD800) * 1024 + lower; } reswitch: cur_cmd = CAT_CODE(cur_chr); - switch (cur_input.state + cur_cmd) { /*357:*/ + switch (cur_input().state + cur_cmd) { /*357:*/ ANY_STATE_PLUS(IGNORE): case SKIP_BLANKS + SPACER: case NEW_LINE + SPACER: @@ -5190,30 +5191,30 @@ get_next(void) break; ANY_STATE_PLUS(ESCAPE): - if (cur_input.loc > cur_input.limit) { + if (cur_input().loc > cur_input().limit) { cur_cs = NULL_CS; } else { start_cs: - k = cur_input.loc; - cur_chr = buffer[k]; + k = cur_input().loc; + cur_chr = buffer(k); cat = CAT_CODE(cur_chr); k++; if (cat == LETTER) - cur_input.state = SKIP_BLANKS; + cur_input_ptr()->state = SKIP_BLANKS; else if (cat == SPACER) - cur_input.state = SKIP_BLANKS; + cur_input_ptr()->state = SKIP_BLANKS; else - cur_input.state = MID_LINE; + cur_input_ptr()->state = MID_LINE; - if (cat == LETTER && k <= cur_input.limit) { /*368:*/ + if (cat == LETTER && k <= cur_input().limit) { /*368:*/ do { - cur_chr = buffer[k]; + cur_chr = buffer(k); cat = CAT_CODE(cur_chr); k++; - } while (cat == LETTER && k <= cur_input.limit); + } while (cat == LETTER && k <= cur_input().limit); - if (cat == SUP_MARK && buffer[k] == cur_chr && k < cur_input.limit) { + if (cat == SUP_MARK && buffer(k) == cur_chr && k < cur_input().limit) { /* Special characters: either ^^X, or up to six * ^'s followed by one hex character for each * ^. */ @@ -5224,8 +5225,8 @@ get_next(void) sup_count = 2; - while (sup_count < 6 && k + 2 * sup_count - 2 <= cur_input.limit && - buffer[k + sup_count - 1] == cur_chr) + while (sup_count < 6 && k + 2 * sup_count - 2 <= cur_input().limit && + buffer(k + sup_count - 1) == cur_chr) sup_count++; /* If they are followed by a sufficient number of @@ -5236,19 +5237,19 @@ get_next(void) sup_count_save = sup_count; for (d = 1; d <= sup_count_save; d++) { - if (!IS_LC_HEX(buffer[k + sup_count - 2 + d])) { + if (!IS_LC_HEX(buffer(k + sup_count - 2 + d))) { /* Non-hex: do it old style */ - c = buffer[k + 1]; + c = buffer(k + 1); if (c < 128) { if (c < 64) - buffer[k - 1] = c + 64; + set_buffer(k - 1, c + 64); else - buffer[k - 1] = c - 64; + set_buffer(k - 1, c - 64); d = 2; - cur_input.limit = cur_input.limit - d; - while (k <= cur_input.limit) { - buffer[k] = buffer[k + d]; + cur_input_ptr()->limit = cur_input().limit - d; + while (k <= cur_input().limit) { + set_buffer(k, buffer(k + d)); k++; } goto start_cs; @@ -5262,7 +5263,7 @@ get_next(void) cur_chr = 0; for (d = 1; d <= sup_count; d++) { - c = buffer[k + sup_count - 2 + d]; + c = buffer(k + sup_count - 2 + d); if (c <= '9' ) cur_chr = 16 * cur_chr + c - '0'; else @@ -5270,14 +5271,14 @@ get_next(void) } if (cur_chr > BIGGEST_USV) { - cur_chr = buffer[k]; + cur_chr = buffer(k); } else { - buffer[k - 1] = cur_chr; + set_buffer(k - 1, cur_chr); d = 2 * sup_count - 1; - cur_input.limit = cur_input.limit - d; + cur_input_ptr()->limit = cur_input().limit - d; - while (k <= cur_input.limit) { - buffer[k] = buffer[k + d]; + while (k <= cur_input().limit) { + set_buffer(k, buffer(k + d)); k++; } goto start_cs; @@ -5288,35 +5289,35 @@ get_next(void) if (cat != LETTER) k--; - if (k > cur_input.loc + 1) { - cur_cs = id_lookup(cur_input.loc, k - cur_input.loc); - cur_input.loc = k; + if (k > cur_input().loc + 1) { + cur_cs = id_lookup(cur_input().loc, k - cur_input().loc); + cur_input_ptr()->loc = k; goto found; } } else { /*367:*/ - if (cat == SUP_MARK && buffer[k] == cur_chr && k < cur_input.limit) { + if (cat == SUP_MARK && buffer(k) == cur_chr && k < cur_input().limit) { int32_t sup_count_save; sup_count = 2; - while (sup_count < 6 && k + 2 * sup_count - 2 <= cur_input.limit && - buffer[k + sup_count - 1] == cur_chr) + while (sup_count < 6 && k + 2 * sup_count - 2 <= cur_input().limit && + buffer(k + sup_count - 1) == cur_chr) sup_count++; sup_count_save = sup_count; for (d = 1; d <= sup_count_save; d++) { - if (!IS_LC_HEX(buffer[k + sup_count - 2 + d])) { - c = buffer[k + 1]; + if (!IS_LC_HEX(buffer(k + sup_count - 2 + d))) { + c = buffer(k + 1); if (c < 128) { if (c < 64) - buffer[k - 1] = c + 64; + set_buffer(k - 1, c + 64); else - buffer[k - 1] = c - 64; + set_buffer(k - 1, c - 64); d = 2; - cur_input.limit = cur_input.limit - d; - while (k <= cur_input.limit) { - buffer[k] = buffer[k + d]; + cur_input_ptr()->limit = cur_input().limit - d; + while (k <= cur_input().limit) { + set_buffer(k, buffer(k + d)); k++; } goto start_cs; @@ -5330,7 +5331,7 @@ get_next(void) cur_chr = 0; for (d = 1; d <= sup_count; d++) { - c = buffer[k + sup_count - 2 + d]; + c = buffer(k + sup_count - 2 + d); if (c <= '9' ) cur_chr = 16 * cur_chr + c - '0'; else @@ -5338,13 +5339,13 @@ get_next(void) } if (cur_chr > BIGGEST_USV) { - cur_chr = buffer[k]; + cur_chr = buffer(k); } else { - buffer[k - 1] = cur_chr; + set_buffer(k - 1, cur_chr); d = 2 * sup_count - 1; - cur_input.limit = cur_input.limit - d; - while (k <= cur_input.limit) { - buffer[k] = buffer[k + d]; + cur_input_ptr()->limit = cur_input().limit - d; + while (k <= cur_input().limit) { + set_buffer(k, buffer(k + d)); k++; } goto start_cs; @@ -5353,46 +5354,46 @@ get_next(void) } } - if (buffer[cur_input.loc] > 65535L) { - cur_cs = id_lookup(cur_input.loc, 1); - cur_input.loc++; + if (buffer(cur_input().loc) > 65535L) { + cur_cs = id_lookup(cur_input().loc, 1); + cur_input_ptr()->loc++; goto found; } - cur_cs = SINGLE_BASE + buffer[cur_input.loc]; - cur_input.loc++; + cur_cs = SINGLE_BASE + buffer(cur_input().loc); + cur_input_ptr()->loc++; } found: - cur_cmd = eqtb[cur_cs].b16.s1; - cur_chr = eqtb[cur_cs].b32.s1; + cur_cmd = eqtb_ptr(cur_cs)->b16.s1; + cur_chr = eqtb_ptr(cur_cs)->b32.s1; if (cur_cmd >= OUTER_CALL) check_outer_validity(); break; ANY_STATE_PLUS(ACTIVE_CHAR): cur_cs = cur_chr + 1; - cur_cmd = eqtb[cur_cs].b16.s1; - cur_chr = eqtb[cur_cs].b32.s1; - cur_input.state = MID_LINE; + cur_cmd = eqtb_ptr(cur_cs)->b16.s1; + cur_chr = eqtb_ptr(cur_cs)->b32.s1; + cur_input_ptr()->state = MID_LINE; if (cur_cmd >= OUTER_CALL) check_outer_validity(); break; ANY_STATE_PLUS(SUP_MARK): - if (cur_chr == buffer[cur_input.loc]) { - if (cur_input.loc < cur_input.limit) { + if (cur_chr == buffer(cur_input().loc)) { + if (cur_input().loc < cur_input().limit) { sup_count = 2; - while (sup_count < 6 && cur_input.loc + 2 * sup_count - 2 <= cur_input.limit && - cur_chr == buffer[cur_input.loc + sup_count - 1]) + while (sup_count < 6 && cur_input().loc + 2 * sup_count - 2 <= cur_input().limit && + cur_chr == buffer(cur_input().loc + sup_count - 1)) sup_count++; for (d = 1; d <= sup_count; d++) { - if (!IS_LC_HEX(buffer[cur_input.loc + sup_count - 2 + d])) { - c = buffer[cur_input.loc + 1]; + if (!IS_LC_HEX(buffer(cur_input().loc + sup_count - 2 + d))) { + c = buffer(cur_input().loc + 1); if (c < 128) { - cur_input.loc = cur_input.loc + 2; + cur_input_ptr()->loc = cur_input().loc + 2; if (c < 64) cur_chr = c + 64; else @@ -5406,7 +5407,7 @@ get_next(void) cur_chr = 0; for (d = 1; d <= sup_count; d++) { - c = buffer[cur_input.loc + sup_count - 2 + d]; + c = buffer(cur_input().loc + sup_count - 2 + d); if (c <= '9' ) cur_chr = 16 * cur_chr + c - '0'; else @@ -5414,17 +5415,17 @@ get_next(void) } if (cur_chr > BIGGEST_USV) { - cur_chr = buffer[cur_input.loc]; + cur_chr = buffer(cur_input().loc); goto not_exp; } - cur_input.loc = cur_input.loc + 2 * sup_count - 1; + cur_input_ptr()->loc = cur_input().loc + 2 * sup_count - 1; goto reswitch; } } not_exp: - cur_input.state = MID_LINE; + cur_input_ptr()->state = MID_LINE; break; ANY_STATE_PLUS(INVALID_CHAR): @@ -5441,27 +5442,27 @@ get_next(void) break; case MID_LINE + SPACER: - cur_input.state = SKIP_BLANKS; + cur_input_ptr()->state = SKIP_BLANKS; cur_chr = ' ' ; break; case MID_LINE + CAR_RET: - cur_input.loc = cur_input.limit + 1; + cur_input_ptr()->loc = cur_input().limit + 1; cur_cmd = SPACER; cur_chr = ' ' ; break; ANY_STATE_PLUS(COMMENT): case SKIP_BLANKS + CAR_RET: - cur_input.loc = cur_input.limit + 1; + cur_input_ptr()->loc = cur_input().limit + 1; goto texswitch; break; case NEW_LINE + CAR_RET: - cur_input.loc = cur_input.limit + 1; + cur_input_ptr()->loc = cur_input().limit + 1; cur_cs = par_loc; - cur_cmd = eqtb[cur_cs].b16.s1; - cur_chr = eqtb[cur_cs].b32.s1; + cur_cmd = eqtb_ptr(cur_cs)->b16.s1; + cur_chr = eqtb_ptr(cur_cs)->b32.s1; if (cur_cmd >= OUTER_CALL) check_outer_validity(); break; @@ -5472,7 +5473,7 @@ get_next(void) case SKIP_BLANKS + LEFT_BRACE: case NEW_LINE + LEFT_BRACE: - cur_input.state = MID_LINE; + cur_input_ptr()->state = MID_LINE; align_state++; break; @@ -5482,43 +5483,43 @@ get_next(void) case SKIP_BLANKS + RIGHT_BRACE: case NEW_LINE + RIGHT_BRACE: - cur_input.state = MID_LINE; + cur_input_ptr()->state = MID_LINE; align_state--; break; ADD_DELIMS_TO(SKIP_BLANKS): ADD_DELIMS_TO(NEW_LINE): - cur_input.state = MID_LINE; + cur_input_ptr()->state = MID_LINE; break; default: break; } } else { - cur_input.state = NEW_LINE; + cur_input_ptr()->state = NEW_LINE; - if (cur_input.name > 17) { /*374:*/ - line++; - first = cur_input.start; + if (cur_input().name > 17) { /*374:*/ + set_line(line()+1); + first = cur_input().start; if (!force_eof) { - if (cur_input.name <= 19) { + if (cur_input().name <= 19) { if (pseudo_input()) { - cur_input.limit = last; - } else if (LOCAL(every_eof) != TEX_NULL && !eof_seen[cur_input.index]) { - cur_input.limit = first - 1; - eof_seen[cur_input.index] = true; + cur_input_ptr()->limit = last; + } else if (LOCAL(every_eof) != TEX_NULL && !eof_seen[cur_input().index]) { + cur_input_ptr()->limit = first - 1; + eof_seen[cur_input().index] = true; begin_token_list(LOCAL(every_eof), EVERY_EOF_TEXT); goto restart; } else { force_eof = true; } } else { - if (input_line(input_file[cur_input.index])) { - cur_input.limit = last; - } else if (LOCAL(every_eof) != TEX_NULL && !eof_seen[cur_input.index]) { - cur_input.limit = first - 1; - eof_seen[cur_input.index] = true; + if (input_line(input_file[cur_input().index])) { + cur_input_ptr()->limit = last; + } else if (LOCAL(every_eof) != TEX_NULL && !eof_seen[cur_input().index]) { + cur_input_ptr()->limit = first - 1; + eof_seen[cur_input().index] = true; begin_token_list(LOCAL(every_eof), EVERY_EOF_TEXT); goto restart; } else { @@ -5529,14 +5530,14 @@ get_next(void) if (force_eof) { if (INTPAR(tracing_nesting) > 0) { - if (grp_stack[in_open] != cur_boundary || if_stack[in_open] != cond_ptr) + if (grp_stack[in_open()] != cur_boundary || if_stack[in_open()] != cond_ptr) file_warning(); } - if (cur_input.name >= 19) { + if (cur_input().name >= 19) { print_char(')'); open_parens--; - ttstub_output_flush(rust_stdout); + ttstub_output_flush(rust_stdout()); } force_eof = false; @@ -5546,20 +5547,20 @@ get_next(void) } if (INTPAR(end_line_char) < 0 || INTPAR(end_line_char) > 255) - cur_input.limit--; + cur_input_ptr()->limit--; else - buffer[cur_input.limit] = INTPAR(end_line_char); + set_buffer(cur_input().limit, INTPAR(end_line_char)); - first = cur_input.limit + 1; - cur_input.loc = cur_input.start; + first = cur_input().limit + 1; + cur_input_ptr()->loc = cur_input().start; } else { - if (cur_input.name != 0) { + if (cur_input().name != 0) { cur_cmd = 0; cur_chr = 0; return; } - if (input_ptr > 0) { + if (input_ptr() > 0) { end_file_reading(); goto restart; } @@ -5575,28 +5576,28 @@ get_next(void) goto restart; } - if (selector < SELECTOR_LOG_ONLY) + if (selector() < SELECTOR_LOG_ONLY) open_log_file(); fatal_error("*** (job aborted, no legal \\end found)"); } goto texswitch; } - } else if (cur_input.loc != TEX_NULL) { /* if we're inputting from a non-null token list: */ - t = mem[cur_input.loc].b32.s0; - cur_input.loc = LLIST_link(cur_input.loc); + } else if (cur_input().loc != TEX_NULL) { /* if we're inputting from a non-null token list: */ + t = mem(cur_input().loc).b32.s0; + cur_input_ptr()->loc = LLIST_link(cur_input().loc); if (t >= CS_TOKEN_FLAG) { cur_cs = t - CS_TOKEN_FLAG; - cur_cmd = eqtb[cur_cs].b16.s1; - cur_chr = eqtb[cur_cs].b32.s1; + cur_cmd = eqtb_ptr(cur_cs)->b16.s1; + cur_chr = eqtb_ptr(cur_cs)->b32.s1; if (cur_cmd >= OUTER_CALL) { if (cur_cmd == DONT_EXPAND) { /*370:*/ - cur_cs = mem[cur_input.loc].b32.s0 - CS_TOKEN_FLAG; - cur_input.loc = TEX_NULL; - cur_cmd = eqtb[cur_cs].b16.s1; - cur_chr = eqtb[cur_cs].b32.s1; + cur_cs = mem(cur_input().loc).b32.s0 - CS_TOKEN_FLAG; + cur_input_ptr()->loc = TEX_NULL; + cur_cmd = eqtb_ptr(cur_cs)->b16.s1; + cur_chr = eqtb_ptr(cur_cs)->b32.s1; if (cur_cmd > MAX_COMMAND) { cur_cmd = RELAX; cur_chr = NO_EXPAND_FLAG; @@ -5617,7 +5618,7 @@ get_next(void) align_state--; break; case OUT_PARAM: - begin_token_list(param_stack[cur_input.limit + cur_chr - 1], PARAMETER); + begin_token_list(param_stack[cur_input().limit + cur_chr - 1], PARAMETER); goto restart; break; default: @@ -5633,12 +5634,12 @@ get_next(void) if (scanner_status == ALIGNING || cur_align == TEX_NULL) fatal_error("(interwoven alignment preambles are not allowed)"); - cur_cmd = mem[cur_align + 5].b32.s0; - mem[cur_align + 5].b32.s0 = cur_chr; + cur_cmd = mem(cur_align + 5).b32.s0; + mem_ptr(cur_align + 5)->b32.s0 = cur_chr; if (cur_cmd == OMIT) begin_token_list(OMIT_TEMPLATE, V_TEMPLATE); else - begin_token_list(mem[cur_align + 2].b32.s1, V_TEMPLATE); + begin_token_list(mem(cur_align + 2).b32.s1, V_TEMPLATE); align_state = 1000000L; goto restart; } @@ -5679,7 +5680,7 @@ macro_call(void) save_warning_index = warning_index; warning_index = cur_cs; ref_count = cur_chr; - r = mem[ref_count].b32.s1; + r = mem(ref_count).b32.s1; n = 0; if (INTPAR(tracing_macros) > 0) { /*419:*/ @@ -5687,8 +5688,8 @@ macro_call(void) diagnostic_begin_capture_warning_here(); if (INTPAR(tracing_stack_levels) > 0) { - if (input_ptr < INTPAR(tracing_stack_levels)) { - v = input_ptr; + if (input_ptr() < INTPAR(tracing_stack_levels)) { + v = input_ptr(); print_ln(); print_char('~'); @@ -5714,24 +5715,24 @@ macro_call(void) end_diagnostic(false); } - if (mem[r].b32.s0 == PROTECTED_TOKEN) + if (mem(r).b32.s0 == PROTECTED_TOKEN) r = LLIST_link(r); - if (mem[r].b32.s0 != END_MATCH_TOKEN) { /*409:*/ + if (mem(r).b32.s0 != END_MATCH_TOKEN) { /*409:*/ scanner_status = MATCHING; unbalance = 0; - long_state = eqtb[cur_cs].b16.s1; + long_state = eqtb_ptr(cur_cs)->b16.s1; if (long_state >= OUTER_CALL) long_state = long_state - 2; do { - mem[TEMP_HEAD].b32.s1 = TEX_NULL; - if (mem[r].b32.s0 >= END_MATCH_TOKEN || mem[r].b32.s0 < MATCH_TOKEN) { + mem_ptr(TEMP_HEAD)->b32.s1 = TEX_NULL; + if (mem(r).b32.s0 >= END_MATCH_TOKEN || mem(r).b32.s0 < MATCH_TOKEN) { s = TEX_NULL; } else { - match_chr = mem[r].b32.s0 - MATCH_TOKEN; - s = mem[r].b32.s1; + match_chr = mem(r).b32.s0 - MATCH_TOKEN; + s = mem(r).b32.s1; r = s; p = TEMP_HEAD; m = 0; @@ -5740,9 +5741,9 @@ macro_call(void) continue_: get_token(); - if (cur_tok == mem[r].b32.s0) { /*412:*/ + if (cur_tok == mem(r).b32.s0) { /*412:*/ r = LLIST_link(r); - if (mem[r].b32.s0 >= MATCH_TOKEN && mem[r].b32.s0 <= END_MATCH_TOKEN) { + if (mem(r).b32.s0 >= MATCH_TOKEN && mem(r).b32.s0 <= END_MATCH_TOKEN) { if (cur_tok < LEFT_BRACE_LIMIT) align_state--; goto found; @@ -5769,25 +5770,25 @@ macro_call(void) do { q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = mem[t].b32.s0; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = mem(t).b32.s0; p = q; m++; - u = mem[t].b32.s1; + u = mem(t).b32.s1; v = s; while (true) { if (u == r) { - if (cur_tok != mem[v].b32.s0) { + if (cur_tok != mem(v).b32.s0) { goto done; } else { - r = mem[v].b32.s1; + r = mem(v).b32.s1; goto continue_; } } - if (mem[u].b32.s0 != mem[v].b32.s0) + if (mem(u).b32.s0 != mem(v).b32.s0) goto done; u = LLIST_link(u); @@ -5817,7 +5818,7 @@ macro_call(void) back_error(); } - pstack[n] = mem[TEMP_HEAD].b32.s1; + pstack[n] = mem(TEMP_HEAD).b32.s1; align_state = align_state - unbalance; for (m = 0; m <= n; m++) @@ -5836,12 +5837,12 @@ macro_call(void) if (q == TEX_NULL) { q = get_avail(); } else { - avail = mem[q].b32.s1; - mem[q].b32.s1 = TEX_NULL; + avail = mem(q).b32.s1; + mem_ptr(q)->b32.s1 = TEX_NULL; } - mem[p].b32.s1 = q; - mem[q].b32.s0 = cur_tok; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = cur_tok; p = q; get_token(); @@ -5861,7 +5862,7 @@ macro_call(void) back_error(); } - pstack[n] = mem[TEMP_HEAD].b32.s1; + pstack[n] = mem(TEMP_HEAD).b32.s1; align_state = align_state - unbalance; for (m = 0; m <= n; m++) @@ -5887,8 +5888,8 @@ macro_call(void) rbrace_ptr = p; q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = cur_tok; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = cur_tok; p = q; } else { /*413:*/ back_input(); @@ -5913,43 +5914,43 @@ macro_call(void) } } else { /*411:*/ if (cur_tok == SPACE_TOKEN) { - if (mem[r].b32.s0 <= END_MATCH_TOKEN) { - if (mem[r].b32.s0 >= MATCH_TOKEN) + if (mem(r).b32.s0 <= END_MATCH_TOKEN) { + if (mem(r).b32.s0 >= MATCH_TOKEN) goto continue_; } } q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = cur_tok; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = cur_tok; p = q; } m++; - if (mem[r].b32.s0 > END_MATCH_TOKEN) + if (mem(r).b32.s0 > END_MATCH_TOKEN) goto continue_; - if (mem[r].b32.s0 < MATCH_TOKEN) + if (mem(r).b32.s0 < MATCH_TOKEN) goto continue_; found: if (s != TEX_NULL) { /*418:*/ - if (m == 1 && mem[p].b32.s0 < RIGHT_BRACE_LIMIT) { - mem[rbrace_ptr].b32.s1 = TEX_NULL; - mem[p].b32.s1 = avail; + if (m == 1 && mem(p).b32.s0 < RIGHT_BRACE_LIMIT) { + mem_ptr(rbrace_ptr)->b32.s1 = TEX_NULL; + mem_ptr(p)->b32.s1 = avail; avail = p; - p = mem[TEMP_HEAD].b32.s1; - pstack[n] = mem[p].b32.s1; - mem[p].b32.s1 = avail; + p = mem(TEMP_HEAD).b32.s1; + pstack[n] = mem(p).b32.s1; + mem_ptr(p)->b32.s1 = avail; avail = p; } else { - pstack[n] = mem[TEMP_HEAD].b32.s1; + pstack[n] = mem(TEMP_HEAD).b32.s1; } n++; if (INTPAR(tracing_macros) > 0) { - if (INTPAR(tracing_stack_levels) == 0 || input_ptr < INTPAR(tracing_stack_levels)) { + if (INTPAR(tracing_stack_levels) == 0 || input_ptr() < INTPAR(tracing_stack_levels)) { begin_diagnostic(); diagnostic_begin_capture_warning_here(); print_nl(match_chr); @@ -5961,15 +5962,15 @@ macro_call(void) } } } - } while (mem[r].b32.s0 != END_MATCH_TOKEN); + } while (mem(r).b32.s0 != END_MATCH_TOKEN); } - while (cur_input.state == TOKEN_LIST && cur_input.loc == TEX_NULL && cur_input.index != V_TEMPLATE) + while (cur_input().state == TOKEN_LIST && cur_input().loc == TEX_NULL && cur_input().index != V_TEMPLATE) end_token_list(); begin_token_list(ref_count, MACRO); - cur_input.name = warning_index; - cur_input.loc = mem[r].b32.s1; + cur_input_ptr()->name = warning_index; + cur_input_ptr()->loc = mem(r).b32.s1; if (n > 0) { if (param_ptr + n > max_param_stack) { @@ -5997,7 +5998,7 @@ insert_relax(void) back_input(); cur_tok = CS_TOKEN_FLAG + FROZEN_RELAX; back_input(); - cur_input.index = INSERTED; + cur_input_ptr()->index = INSERTED; } @@ -6005,16 +6006,16 @@ void new_index(uint16_t i, int32_t q) { small_number k; cur_ptr = get_node(INDEX_NODE_SIZE); - mem[cur_ptr].b16.s1 = i; - mem[cur_ptr].b16.s0 = 0; - mem[cur_ptr].b32.s1 = q; + mem_ptr(cur_ptr)->b16.s1 = i; + mem_ptr(cur_ptr)->b16.s0 = 0; + mem_ptr(cur_ptr)->b32.s1 = q; { register int32_t for_end; k = 1; for_end = (INDEX_NODE_SIZE - 1); if (k <= for_end) do - mem[cur_ptr + k] = sa_null; + set_mem(cur_ptr + k, sa_null); while (k++ < for_end); } } @@ -6036,9 +6037,9 @@ void find_sa_element(small_number t, int32_t n, bool w) q = cur_ptr; i = n / 0x40000; if (odd(i)) - cur_ptr = mem[q + (i / 2) + 1].b32.s1; + cur_ptr = mem(q + (i / 2) + 1).b32.s1; else - cur_ptr = mem[q + (i / 2) + 1].b32.s0; + cur_ptr = mem(q + (i / 2) + 1).b32.s0; { if (cur_ptr == TEX_NULL) { @@ -6051,9 +6052,9 @@ void find_sa_element(small_number t, int32_t n, bool w) q = cur_ptr; i = (n / 4096) % 64; if (odd(i)) - cur_ptr = mem[q + (i / 2) + 1].b32.s1; + cur_ptr = mem(q + (i / 2) + 1).b32.s1; else - cur_ptr = mem[q + (i / 2) + 1].b32.s0; + cur_ptr = mem(q + (i / 2) + 1).b32.s0; { if (cur_ptr == TEX_NULL) { @@ -6066,9 +6067,9 @@ void find_sa_element(small_number t, int32_t n, bool w) q = cur_ptr; i = (n / 64) % 64; if (odd(i)) - cur_ptr = mem[q + (i / 2) + 1].b32.s1; + cur_ptr = mem(q + (i / 2) + 1).b32.s1; else - cur_ptr = mem[q + (i / 2) + 1].b32.s0; + cur_ptr = mem(q + (i / 2) + 1).b32.s0; { if (cur_ptr == TEX_NULL) { @@ -6081,9 +6082,9 @@ void find_sa_element(small_number t, int32_t n, bool w) q = cur_ptr; i = n % 64; if (odd(i)) - cur_ptr = mem[q + (i / 2) + 1].b32.s1; + cur_ptr = mem(q + (i / 2) + 1).b32.s1; else - cur_ptr = mem[q + (i / 2) + 1].b32.s0; + cur_ptr = mem(q + (i / 2) + 1).b32.s0; if ((cur_ptr == TEX_NULL) && w) goto lab49; return; @@ -6095,64 +6096,64 @@ void find_sa_element(small_number t, int32_t n, bool w) lab46: /*not_found1 */ new_index(i, q); { if (odd(i)) - mem[q + (i / 2) + 1].b32.s1 = cur_ptr; + mem_ptr(q + (i / 2) + 1)->b32.s1 = cur_ptr; else - mem[q + (i / 2) + 1].b32.s0 = cur_ptr; - mem[q].b16.s0++; + mem_ptr(q + (i / 2) + 1)->b32.s0 = cur_ptr; + mem_ptr(q)->b16.s0++; } q = cur_ptr; i = (n / 4096) % 64; lab47: /*not_found2 */ new_index(i, q); { if (odd(i)) - mem[q + (i / 2) + 1].b32.s1 = cur_ptr; + mem_ptr(q + (i / 2) + 1)->b32.s1 = cur_ptr; else - mem[q + (i / 2) + 1].b32.s0 = cur_ptr; - mem[q].b16.s0++; + mem_ptr(q + (i / 2) + 1)->b32.s0 = cur_ptr; + mem_ptr(q)->b16.s0++; } q = cur_ptr; i = (n / 64) % 64; lab48: /*not_found3 */ new_index(i, q); { if (odd(i)) - mem[q + (i / 2) + 1].b32.s1 = cur_ptr; + mem_ptr(q + (i / 2) + 1)->b32.s1 = cur_ptr; else - mem[q + (i / 2) + 1].b32.s0 = cur_ptr; - mem[q].b16.s0++; + mem_ptr(q + (i / 2) + 1)->b32.s0 = cur_ptr; + mem_ptr(q)->b16.s0++; } q = cur_ptr; i = n % 64; lab49:/*not_found4 *//*1608: */ if (t == MARK_VAL) { cur_ptr = get_node(MARK_CLASS_NODE_SIZE); - mem[cur_ptr + 1] = sa_null; - mem[cur_ptr + 2] = sa_null; - mem[cur_ptr + 3] = sa_null; + set_mem(cur_ptr + 1, sa_null); + set_mem(cur_ptr + 2, sa_null); + set_mem(cur_ptr + 3, sa_null); } else { if (t <= DIMEN_VAL) { cur_ptr = get_node(WORD_NODE_SIZE); - mem[cur_ptr + 2].b32.s1 = 0; - mem[cur_ptr + 1].b32.s1 = n; + mem_ptr(cur_ptr + 2)->b32.s1 = 0; + mem_ptr(cur_ptr + 1)->b32.s1 = n; } else { cur_ptr = get_node(POINTER_NODE_SIZE); if (t <= MU_VAL) { - mem[cur_ptr + 1].b32.s1 = 0; + mem_ptr(cur_ptr + 1)->b32.s1 = 0; GLUE_SPEC_ref_count(0)++; } else - mem[cur_ptr + 1].b32.s1 = TEX_NULL; + mem_ptr(cur_ptr + 1)->b32.s1 = TEX_NULL; } - mem[cur_ptr + 1].b32.s0 = TEX_NULL; + mem_ptr(cur_ptr + 1)->b32.s0 = TEX_NULL; } - mem[cur_ptr].b16.s1 = 64 * t + i; - mem[cur_ptr].b16.s0 = 1 /*level_one *//*:1608 */ ; - mem[cur_ptr].b32.s1 = q; + mem_ptr(cur_ptr)->b16.s1 = 64 * t + i; + mem_ptr(cur_ptr)->b16.s0 = 1 /*level_one *//*:1608 */ ; + mem_ptr(cur_ptr)->b32.s1 = q; { if (odd(i)) - mem[q + (i / 2) + 1].b32.s1 = cur_ptr; + mem_ptr(q + (i / 2) + 1)->b32.s1 = cur_ptr; else - mem[q + (i / 2) + 1].b32.s0 = cur_ptr; - mem[q].b16.s0++; + mem_ptr(q + (i / 2) + 1)->b32.s0 = cur_ptr; + mem_ptr(q)->b16.s0++; } } @@ -6177,7 +6178,7 @@ expand(void) cvl_backup = cur_val_level; radix_backup = radix; co_backup = cur_order; - backup_backup = mem[BACKUP_HEAD].b32.s1; + backup_backup = mem(BACKUP_HEAD).b32.s1; reswitch: if (cur_cmd < CALL) { /*384:*/ @@ -6199,9 +6200,9 @@ expand(void) find_sa_element(MARK_VAL, cur_val, false); if (cur_ptr != TEX_NULL) { if (odd(t)) - cur_ptr = mem[cur_ptr + (t / 2) + 1].b32.s1; + cur_ptr = mem(cur_ptr + (t / 2) + 1).b32.s1; else - cur_ptr = mem[cur_ptr + (t / 2) + 1].b32.s0; + cur_ptr = mem(cur_ptr + (t / 2) + 1).b32.s0; } } @@ -6250,10 +6251,10 @@ expand(void) back_input(); if (t >= CS_TOKEN_FLAG) { p = get_avail(); - mem[p].b32.s0 = CS_TOKEN_FLAG + FROZEN_DONT_EXPAND; - mem[p].b32.s1 = cur_input.loc; - cur_input.start = p; - cur_input.loc = p; + mem_ptr(p)->b32.s0 = CS_TOKEN_FLAG + FROZEN_DONT_EXPAND; + mem_ptr(p)->b32.s1 = cur_input().loc; + cur_input_ptr()->start = p; + cur_input_ptr()->loc = p; } } else { /*387: \primitive implementation */ save_scanner_status = scanner_status; @@ -6264,23 +6265,23 @@ expand(void) if (cur_cs < HASH_BASE) cur_cs = prim_lookup(cur_cs - SINGLE_BASE); else - cur_cs = prim_lookup(hash[cur_cs].s1); + cur_cs = prim_lookup(hash(cur_cs).s1); if (cur_cs != UNDEFINED_PRIMITIVE) { - t = eqtb[PRIM_EQTB_BASE + cur_cs].b16.s1; + t = eqtb_ptr(PRIM_EQTB_BASE + cur_cs)->b16.s1; if (t > MAX_COMMAND) { cur_cmd = t; - cur_chr = eqtb[PRIM_EQTB_BASE + cur_cs].b32.s1; + cur_chr = eqtb_ptr(PRIM_EQTB_BASE + cur_cs)->b32.s1; cur_tok = (cur_cmd * MAX_CHAR_VAL) + cur_chr; cur_cs = 0; goto reswitch; } else { back_input(); p = get_avail(); - mem[p].b32.s0 = CS_TOKEN_FLAG + FROZEN_PRIMITIVE; - mem[p].b32.s1 = cur_input.loc; - cur_input.loc = p; - cur_input.start = p; + mem_ptr(p)->b32.s0 = CS_TOKEN_FLAG + FROZEN_PRIMITIVE; + mem_ptr(p)->b32.s1 = cur_input().loc; + cur_input_ptr()->loc = p; + cur_input_ptr()->start = p; } } } @@ -6296,8 +6297,8 @@ expand(void) get_x_token(); if (cur_cs == 0) { q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = cur_tok; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = cur_tok; p = q; } } while (cur_cs == 0); @@ -6316,7 +6317,7 @@ expand(void) is_in_csname = b; j = first; - p = mem[r].b32.s1; + p = mem(r).b32.s1; while (p != TEX_NULL) { if (j >= max_buf_stack) { @@ -6324,24 +6325,24 @@ expand(void) if (max_buf_stack == buf_size) overflow("buffer size", buf_size); } - buffer[j] = mem[p].b32.s0 % MAX_CHAR_VAL; + set_buffer(j, mem(p).b32.s0 % MAX_CHAR_VAL); j++; p = LLIST_link(p); } - if (j > first + 1 || buffer[first] > 65535L) { + if (j > first + 1 || buffer(first) > 65535L) { no_new_control_sequence = false; cur_cs = id_lookup(first, j - first); no_new_control_sequence = true; } else if (j == first) { cur_cs = NULL_CS; } else { - cur_cs = SINGLE_BASE + buffer[first]; /*:392*/ + cur_cs = SINGLE_BASE + buffer(first); /*:392*/ } flush_list(r); - if (eqtb[cur_cs].b16.s1 == UNDEFINED_CS) + if (eqtb_ptr(cur_cs)->b16.s1 == UNDEFINED_CS) eq_define(cur_cs, RELAX, TOO_BIG_USV); cur_tok = cur_cs + CS_TOKEN_FLAG; @@ -6382,13 +6383,13 @@ expand(void) while (cur_chr != FI_CODE) pass_text(); - if (if_stack[in_open] == cond_ptr) + if (if_stack[in_open()] == cond_ptr) if_warning(); p = cond_ptr; - if_line = mem[p + 1].b32.s1; - cur_if = mem[p].b16.s0; - if_limit = mem[p].b16.s1; - cond_ptr = mem[p].b32.s1; + if_line = mem(p + 1).b32.s1; + cur_if = mem(p).b16.s0; + if_limit = mem(p).b16.s1; + cond_ptr = mem(p).b32.s1; free_node(p, IF_NODE_SIZE); } break; @@ -6398,7 +6399,7 @@ expand(void) force_eof = true; /*1537:*/ else if (cur_chr == 2) /* \scantokens */ pseudo_start(); - else if (name_in_progress) + else if (name_in_progress()) insert_relax(); else /* \input */ start_input(NULL); @@ -6428,7 +6429,7 @@ expand(void) cur_val_level = cvl_backup; radix = radix_backup; cur_order = co_backup; - mem[BACKUP_HEAD].b32.s1 = backup_backup; + mem_ptr(BACKUP_HEAD)->b32.s1 = backup_backup; expand_depth_count--; } @@ -6517,7 +6518,7 @@ bool scan_keyword(const char* s) int32_t q; int32_t save_cur_cs; - mem[p].b32.s1 = TEX_NULL; + mem_ptr(p)->b32.s1 = TEX_NULL; if (strlen(s) == 1) { char c = s[0]; @@ -6528,16 +6529,16 @@ bool scan_keyword(const char* s) if ((cur_cs == 0) && ((cur_chr == c) || (cur_chr == c - 32))) { { q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = cur_tok; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = cur_tok; p = q; } - flush_list(mem[BACKUP_HEAD].b32.s1); + flush_list(mem(BACKUP_HEAD).b32.s1); return true; } else if ((cur_cmd != SPACER) || (p != BACKUP_HEAD)) { back_input(); if (p != BACKUP_HEAD) - begin_token_list(mem[BACKUP_HEAD].b32.s1, BACKED_UP); + begin_token_list(mem(BACKUP_HEAD).b32.s1, BACKED_UP); cur_cs = save_cur_cs; return false; } @@ -6552,19 +6553,19 @@ bool scan_keyword(const char* s) if ((cur_cs == 0) && ((cur_chr == s[i]) || (cur_chr == s[i] - 32))) { { q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = cur_tok; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = cur_tok; p = q; } i++; } else if ((cur_cmd != SPACER) || (p != BACKUP_HEAD)) { back_input(); if (p != BACKUP_HEAD) - begin_token_list(mem[BACKUP_HEAD].b32.s1, BACKED_UP); + begin_token_list(mem(BACKUP_HEAD).b32.s1, BACKED_UP); return false; } } - flush_list(mem[BACKUP_HEAD].b32.s1); + flush_list(mem(BACKUP_HEAD).b32.s1); return true; } @@ -6736,8 +6737,8 @@ void scan_math(int32_t p) if (math_char(c) == ACTIVE_MATH_CHAR) { { cur_cs = cur_chr + 1; - cur_cmd = eqtb[cur_cs].b16.s1; - cur_chr = eqtb[cur_cs].b32.s1; + cur_cmd = eqtb_ptr(cur_cs)->b16.s1; + cur_chr = eqtb_ptr(cur_cs)->b32.s1; x_token(); back_input(); } @@ -6806,15 +6807,15 @@ void scan_math(int32_t p) } break; } - mem[p].b32.s1 = MATH_CHAR; - mem[p].b16.s0 = c % 65536L; + mem_ptr(p)->b32.s1 = MATH_CHAR; + mem_ptr(p)->b16.s0 = c % 65536L; if ((math_class(c) == 7) && ((INTPAR(cur_fam) >= 0) && (INTPAR(cur_fam) < NUMBER_MATH_FAMILIES))) - mem[p].b16.s1 = INTPAR(cur_fam); + mem_ptr(p)->b16.s1 = INTPAR(cur_fam); else - mem[p].b16.s1 = (math_fam(c)); - mem[p].b16.s1 = mem[p].b16.s1 + (math_char(c) / 65536L) * 256; + mem_ptr(p)->b16.s1 = (math_fam(c)); + mem_ptr(p)->b16.s1 = mem(p).b16.s1 + (math_char(c) / 65536L) * 256; } void set_math_char(int32_t c) @@ -6824,26 +6825,26 @@ void set_math_char(int32_t c) if (math_char(c) == ACTIVE_MATH_CHAR) { /*1187: */ cur_cs = cur_chr + 1; - cur_cmd = eqtb[cur_cs].b16.s1; - cur_chr = eqtb[cur_cs].b32.s1; + cur_cmd = eqtb_ptr(cur_cs)->b16.s1; + cur_chr = eqtb_ptr(cur_cs)->b32.s1; x_token(); back_input(); } else { p = new_noad(); - mem[p + 1].b32.s1 = MATH_CHAR; + mem_ptr(p + 1)->b32.s1 = MATH_CHAR; ch = math_char(c); - mem[p + 1].b16.s0 = ch % 65536L; - mem[p + 1].b16.s1 = math_fam(c); + mem_ptr(p + 1)->b16.s0 = ch % 65536L; + mem_ptr(p + 1)->b16.s1 = math_fam(c); if (math_class(c) == 7) { if (((INTPAR(cur_fam) >= 0) && (INTPAR(cur_fam) < NUMBER_MATH_FAMILIES))) - mem[p + 1].b16.s1 = INTPAR(cur_fam); - mem[p].b16.s1 = ORD_NOAD; + mem_ptr(p + 1)->b16.s1 = INTPAR(cur_fam); + mem_ptr(p)->b16.s1 = ORD_NOAD; } else - mem[p].b16.s1 = ORD_NOAD + math_class(c); - mem[p + 1].b16.s1 = mem[p + 1].b16.s1 + (ch / 65536L) * 256; - mem[cur_list.tail].b32.s1 = p; + mem_ptr(p)->b16.s1 = ORD_NOAD + math_class(c); + mem_ptr(p + 1)->b16.s1 = mem(p + 1).b16.s1 + (ch / 65536L) * 256; + mem_ptr(cur_list.tail)->b32.s1 = p; cur_list.tail = p; } } @@ -6985,7 +6986,7 @@ void get_x_or_protected(void) return; if ((cur_cmd >= CALL) && (cur_cmd < END_TEMPLATE)) { - if (mem[mem[cur_chr].b32.s1].b32.s0 == PROTECTED_TOKEN) + if (mem(mem(cur_chr).b32.s1).b32.s0 == PROTECTED_TOKEN) return; } expand(); @@ -7014,13 +7015,13 @@ void scan_font_ident(void) } while (cur_cmd == SPACER); if (cur_cmd == DEF_FONT) - f = eqtb[CUR_FONT_LOC].b32.s1; + f = eqtb_ptr(CUR_FONT_LOC)->b32.s1; else if (cur_cmd == SET_FONT) f = cur_chr; else if (cur_cmd == DEF_FAMILY) { m = cur_chr; scan_math_fam_int(); - f = eqtb[m + cur_val].b32.s1; + f = eqtb_ptr(m + cur_val)->b32.s1; } else { error_here_with_diagnostic("Missing font identifier"); capture_to_diagnostic(NULL); @@ -7071,7 +7072,7 @@ void find_font_dimen(bool writing) } if (cur_val == fmem_ptr) { error_here_with_diagnostic("Font "); - print_esc(hash[FONT_ID_BASE + f].s1); + print_esc(hash(FONT_ID_BASE + f).s1); print_cstr(" has only "); print_int(font_params[f]); print_cstr(" fontdimen parameters"); @@ -7138,13 +7139,13 @@ scan_something_internal(small_number level, bool negative) cur_val_level = INT_VAL; } } else if (m < SF_CODE_BASE) { - cur_val = eqtb[m + cur_val].b32.s1; + cur_val = eqtb_ptr(m + cur_val)->b32.s1; cur_val_level = INT_VAL; } else if (m < MATH_CODE_BASE) { - cur_val = eqtb[m + cur_val].b32.s1 % 65536L; + cur_val = eqtb_ptr(m + cur_val)->b32.s1 % 65536L; cur_val_level = INT_VAL; } else { - cur_val = eqtb[m + cur_val].b32.s1; + cur_val = eqtb_ptr(m + cur_val)->b32.s1; cur_val_level = INT_VAL; } break; @@ -7211,10 +7212,10 @@ scan_something_internal(small_number level, bool negative) if (cur_ptr == TEX_NULL) cur_val = TEX_NULL; else - cur_val = mem[cur_ptr + 1].b32.s1; + cur_val = mem(cur_ptr + 1).b32.s1; } } else { - cur_val = mem[m + 1].b32.s1; + cur_val = mem(m + 1).b32.s1; } } else if (cur_chr == LOCAL_BASE + LOCAL__xetex_inter_char_toks) { scan_char_class_not_ignored(); @@ -7224,9 +7225,9 @@ scan_something_internal(small_number level, bool negative) if (cur_ptr == TEX_NULL) cur_val = TEX_NULL; else - cur_val = mem[cur_ptr + 1].b32.s1; + cur_val = mem(cur_ptr + 1).b32.s1; } else { - cur_val = eqtb[m].b32.s1; + cur_val = eqtb_ptr(m)->b32.s1; } cur_val_level = TOK_VAL; } else { @@ -7238,22 +7239,22 @@ scan_something_internal(small_number level, bool negative) break; case ASSIGN_INT: - cur_val = eqtb[m].b32.s1; + cur_val = eqtb_ptr(m)->b32.s1; cur_val_level = INT_VAL; break; case ASSIGN_DIMEN: - cur_val = eqtb[m].b32.s1; + cur_val = eqtb_ptr(m)->b32.s1; cur_val_level = DIMEN_VAL; break; case ASSIGN_GLUE: - cur_val = eqtb[m].b32.s1; + cur_val = eqtb_ptr(m)->b32.s1; cur_val_level = GLUE_VAL; break; case ASSIGN_MU_GLUE: - cur_val = eqtb[m].b32.s1; + cur_val = eqtb_ptr(m)->b32.s1; cur_val_level = MU_VAL; break; @@ -7305,7 +7306,7 @@ scan_something_internal(small_number level, bool negative) if (m == 0) cur_val = dead_cycles; else if (m == 2) - cur_val = interaction; + cur_val = interaction(); else cur_val = insert_penalties; cur_val_level = INT_VAL; @@ -7327,17 +7328,17 @@ scan_something_internal(small_number level, bool negative) case SET_SHAPE: if (m > LOCAL_BASE + LOCAL__par_shape) { /*1654:*/ scan_int(); - if (eqtb[m].b32.s1 == TEX_NULL || cur_val < 0) { + if (eqtb(m).b32.s1 == TEX_NULL || cur_val < 0) { cur_val = 0; } else { - if (cur_val > mem[eqtb[m].b32.s1 + 1].b32.s1) - cur_val = mem[eqtb[m].b32.s1 + 1].b32.s1; - cur_val = mem[eqtb[m].b32.s1 + cur_val + 1].b32.s1; + if (cur_val > mem(eqtb(m).b32.s1 + 1).b32.s1) + cur_val = mem(eqtb(m).b32.s1 + 1).b32.s1; + cur_val = mem(eqtb(m).b32.s1 + cur_val + 1).b32.s1; } } else if (LOCAL(par_shape) == TEX_NULL) { cur_val = 0; } else { - cur_val = mem[LOCAL(par_shape)].b32.s0; + cur_val = mem(LOCAL(par_shape)).b32.s0; } cur_val_level = INT_VAL; @@ -7353,13 +7354,13 @@ scan_something_internal(small_number level, bool negative) if (cur_ptr == TEX_NULL) q = TEX_NULL; else - q = mem[cur_ptr + 1].b32.s1; + q = mem(cur_ptr + 1).b32.s1; } if (q == TEX_NULL) cur_val = 0; else - cur_val = mem[q + m].b32.s1; + cur_val = mem(q + m).b32.s1; cur_val_level = DIMEN_VAL; break; @@ -7409,11 +7410,11 @@ scan_something_internal(small_number level, bool negative) case REGISTER: if (m < 0 || m > 19) { /* 19 = "lo_mem_stat_max" */ - cur_val_level = (mem[m].b16.s1 / 64); + cur_val_level = (mem(m).b16.s1 / 64); if (cur_val_level < GLUE_VAL) - cur_val = mem[m + 2].b32.s1; + cur_val = mem(m + 2).b32.s1; else - cur_val = mem[m + 1].b32.s1; + cur_val = mem(m + 1).b32.s1; } else { scan_register_num(); cur_val_level = m; @@ -7422,9 +7423,9 @@ scan_something_internal(small_number level, bool negative) if (cur_ptr == TEX_NULL) cur_val = 0; else if (cur_val_level < GLUE_VAL) - cur_val = mem[cur_ptr + 2].b32.s1; + cur_val = mem(cur_ptr + 2).b32.s1; else - cur_val = mem[cur_ptr + 1].b32.s1; + cur_val = mem(cur_ptr + 1).b32.s1; } else { switch (cur_val_level) { case INT_VAL: @@ -7469,7 +7470,7 @@ scan_something_internal(small_number level, bool negative) while (cur_val_level > level) { if (cur_val_level == GLUE_VAL) { m = cur_val; - cur_val = mem[m + 1].b32.s1; + cur_val = mem(m + 1).b32.s1; delete_glue_ref(m); } else if (cur_val_level == MU_VAL) { mu_error(); @@ -7482,9 +7483,9 @@ scan_something_internal(small_number level, bool negative) m = cur_val; cur_val = new_spec(m); delete_glue_ref(m); - mem[cur_val + 1].b32.s1 = -(int32_t) mem[cur_val + 1].b32.s1; - mem[cur_val + 2].b32.s1 = -(int32_t) mem[cur_val + 2].b32.s1; - mem[cur_val + 3].b32.s1 = -(int32_t) mem[cur_val + 3].b32.s1; + mem_ptr(cur_val + 1)->b32.s1 = -(int32_t) mem(cur_val + 1).b32.s1; + mem_ptr(cur_val + 2)->b32.s1 = -(int32_t) mem(cur_val + 2).b32.s1; + mem_ptr(cur_val + 3)->b32.s1 = -(int32_t) mem(cur_val + 3).b32.s1; } else { cur_val = -(int32_t) cur_val; } @@ -7495,8 +7496,8 @@ scan_something_internal(small_number level, bool negative) if (m >= XETEX_DIM) { switch (m) { /*1435:*/ case XETEX_GLYPH_BOUNDS_CODE: - if (font_area[eqtb[CUR_FONT_LOC].b32.s1] == AAT_FONT_FLAG || - font_area[eqtb[CUR_FONT_LOC].b32.s1] == OTGR_FONT_FLAG) { + if (font_area[eqtb_ptr(CUR_FONT_LOC)->b32.s1] == AAT_FONT_FLAG || + font_area[eqtb_ptr(CUR_FONT_LOC)->b32.s1] == OTGR_FONT_FLAG) { scan_int(); n = cur_val; if (n < 1 || n > 4) { @@ -7509,10 +7510,10 @@ scan_something_internal(small_number level, bool negative) cur_val = 0; } else { scan_int(); - cur_val = get_glyph_bounds(eqtb[CUR_FONT_LOC].b32.s1, n, cur_val); + cur_val = get_glyph_bounds(eqtb_ptr(CUR_FONT_LOC)->b32.s1, n, cur_val); } } else { - not_native_font_error(LAST_ITEM, m, eqtb[CUR_FONT_LOC].b32.s1); + not_native_font_error(LAST_ITEM, m, eqtb_ptr(CUR_FONT_LOC)->b32.s1); cur_val = 0; } break; @@ -7575,9 +7576,9 @@ scan_something_internal(small_number level, bool negative) q = cur_val % 2; cur_val = (cur_val + q) / 2; } - if (cur_val > mem[LOCAL(par_shape)].b32.s0) - cur_val = mem[LOCAL(par_shape)].b32.s0; - cur_val = mem[LOCAL(par_shape) + 2 * cur_val - q].b32.s1; + if (cur_val > mem(LOCAL(par_shape)).b32.s0) + cur_val = mem(LOCAL(par_shape)).b32.s0; + cur_val = mem(LOCAL(par_shape) + 2 * cur_val - q).b32.s1; } cur_val_level = DIMEN_VAL; break; @@ -7587,9 +7588,9 @@ scan_something_internal(small_number level, bool negative) scan_normal_glue(); q = cur_val; if (m == GLUE_STRETCH_CODE) - cur_val = mem[q + 2].b32.s1; + cur_val = mem(q + 2).b32.s1; else - cur_val = mem[q + 3].b32.s1; + cur_val = mem(q + 3).b32.s1; delete_glue_ref(q); break; } @@ -7597,7 +7598,7 @@ scan_something_internal(small_number level, bool negative) } else { /* if(m >= XETEX_DIM) */ switch (m) { case INPUT_LINE_NO_CODE: - cur_val = line; + cur_val = line(); break; case BADNESS_CODE: @@ -7803,24 +7804,24 @@ scan_something_internal(small_number level, bool negative) break; case XETEX_MAP_CHAR_TO_GLYPH_CODE: - if (font_area[eqtb[CUR_FONT_LOC].b32.s1] == AAT_FONT_FLAG || - font_area[eqtb[CUR_FONT_LOC].b32.s1] == OTGR_FONT_FLAG) { + if (font_area[eqtb_ptr(CUR_FONT_LOC)->b32.s1] == AAT_FONT_FLAG || + font_area[eqtb_ptr(CUR_FONT_LOC)->b32.s1] == OTGR_FONT_FLAG) { scan_int(); n = cur_val; - cur_val = map_char_to_glyph(eqtb[CUR_FONT_LOC].b32.s1, n); + cur_val = map_char_to_glyph(eqtb_ptr(CUR_FONT_LOC)->b32.s1, n); } else { - not_native_font_error(LAST_ITEM, m, eqtb[CUR_FONT_LOC].b32.s1); + not_native_font_error(LAST_ITEM, m, eqtb_ptr(CUR_FONT_LOC)->b32.s1); cur_val = 0; } break; case XETEX_GLYPH_INDEX_CODE: - if (font_area[eqtb[CUR_FONT_LOC].b32.s1] == AAT_FONT_FLAG || - font_area[eqtb[CUR_FONT_LOC].b32.s1] == OTGR_FONT_FLAG) { + if (font_area[eqtb_ptr(CUR_FONT_LOC)->b32.s1] == AAT_FONT_FLAG || + font_area[eqtb_ptr(CUR_FONT_LOC)->b32.s1] == OTGR_FONT_FLAG) { scan_and_pack_name(); - cur_val = map_glyph_to_index(eqtb[CUR_FONT_LOC].b32.s1); + cur_val = map_glyph_to_index(eqtb_ptr(CUR_FONT_LOC)->b32.s1); } else { - not_native_font_error(LAST_ITEM, m, eqtb[CUR_FONT_LOC].b32.s1); + not_native_font_error(LAST_ITEM, m, eqtb_ptr(CUR_FONT_LOC)->b32.s1); cur_val = 0; } break; @@ -7905,9 +7906,9 @@ scan_something_internal(small_number level, bool negative) scan_normal_glue(); q = cur_val; if (m == GLUE_STRETCH_ORDER_CODE) - cur_val = mem[q].b16.s1; + cur_val = mem(q).b16.s1; else - cur_val = mem[q].b16.s0; + cur_val = mem(q).b16.s0; delete_glue_ref(q); break; } @@ -7919,11 +7920,11 @@ scan_something_internal(small_number level, bool negative) tx = cur_list.tail; if (tx < hi_mem_min) { - if (NODE_type(tx) == MATH_NODE && mem[tx].b16.s0 == END_M_CODE) { + if (NODE_type(tx) == MATH_NODE && mem(tx).b16.s0 == END_M_CODE) { r = cur_list.head; do { q = r; - r = mem[q].b32.s1; + r = mem(q).b32.s1; } while (r != tx); tx = q; } @@ -7941,22 +7942,22 @@ scan_something_internal(small_number level, bool negative) switch (cur_chr) { case INT_VAL: if (NODE_type(tx) == PENALTY_NODE) - cur_val = mem[tx + 1].b32.s1; + cur_val = mem(tx + 1).b32.s1; break; case DIMEN_VAL: if (NODE_type(tx) == KERN_NODE) - cur_val = mem[tx + 1].b32.s1; + cur_val = mem(tx + 1).b32.s1; break; case GLUE_VAL: if (NODE_type(tx) == GLUE_NODE) { - cur_val = mem[tx + 1].b32.s0; - if (mem[tx].b16.s0 == MU_GLUE) + cur_val = mem(tx + 1).b32.s0; + if (mem(tx).b16.s0 == MU_GLUE) cur_val_level = MU_VAL; } break; case LAST_NODE_TYPE_CODE: if (NODE_type(tx) <= UNSET_NODE) - cur_val = mem[tx].b16.s1 + 1; + cur_val = mem(tx).b16.s1 + 1; else cur_val = (UNSET_NODE + 2); break; @@ -7986,12 +7987,12 @@ scan_something_internal(small_number level, bool negative) if (cur_cs < HASH_BASE) { cur_cs = prim_lookup(cur_cs - SINGLE_BASE); } else { - cur_cs = prim_lookup(hash[cur_cs].s1); + cur_cs = prim_lookup(hash(cur_cs).s1); } if (cur_cs != UNDEFINED_PRIMITIVE) { - cur_cmd = eqtb[PRIM_EQTB_BASE + cur_cs].b16.s1; - cur_chr = eqtb[PRIM_EQTB_BASE + cur_cs].b32.s1; + cur_cmd = eqtb_ptr(PRIM_EQTB_BASE + cur_cs)->b16.s1; + cur_chr = eqtb_ptr(PRIM_EQTB_BASE + cur_cs)->b32.s1; cur_cs = PRIM_EQTB_BASE + cur_cs; cur_tok = CS_TOKEN_FLAG + cur_cs; } else { @@ -8025,7 +8026,7 @@ scan_something_internal(small_number level, bool negative) while (cur_val_level > level) { /*447:*/ if (cur_val_level == GLUE_VAL) - cur_val = mem[cur_val + 1].b32.s1; + cur_val = mem(cur_val + 1).b32.s1; else if (cur_val_level == MU_VAL) mu_error(); cur_val_level--; @@ -8034,9 +8035,9 @@ scan_something_internal(small_number level, bool negative) if (negative) { if (cur_val_level >= GLUE_VAL) { cur_val = new_spec(cur_val); - mem[cur_val + 1].b32.s1 = -(int32_t) mem[cur_val + 1].b32.s1; - mem[cur_val + 2].b32.s1 = -(int32_t) mem[cur_val + 2].b32.s1; - mem[cur_val + 3].b32.s1 = -(int32_t) mem[cur_val + 3].b32.s1; + mem_ptr(cur_val + 1)->b32.s1 = -(int32_t) mem(cur_val + 1).b32.s1; + mem_ptr(cur_val + 2)->b32.s1 = -(int32_t) mem(cur_val + 2).b32.s1; + mem_ptr(cur_val + 3)->b32.s1 = -(int32_t) mem(cur_val + 3).b32.s1; } else { cur_val = -(int32_t) cur_val; } @@ -8108,12 +8109,12 @@ scan_int(void) if (cur_cs < HASH_BASE) { cur_cs = prim_lookup(cur_cs - SINGLE_BASE); } else { - cur_cs = prim_lookup(hash[cur_cs].s1); + cur_cs = prim_lookup(hash(cur_cs).s1); } if (cur_cs != UNDEFINED_PRIMITIVE) { - cur_cmd = eqtb[PRIM_EQTB_BASE + cur_cs].b16.s1; - cur_chr = eqtb[PRIM_EQTB_BASE + cur_cs].b32.s1; + cur_cmd = eqtb_ptr(PRIM_EQTB_BASE + cur_cs)->b16.s1; + cur_chr = eqtb_ptr(PRIM_EQTB_BASE + cur_cs)->b32.s1; cur_cs = PRIM_EQTB_BASE + cur_cs; cur_tok = CS_TOKEN_FLAG + cur_cs; } else { @@ -8203,7 +8204,7 @@ round_decimals(small_number k) while (k > 0) { k--; - a = (a + dig[k] * 0x20000) / 10; + a = (a + dig(k) * 0x20000) / 10; } return (a + 1) / 2; @@ -8222,7 +8223,7 @@ xetex_scan_dimen(bool mu, bool inf, bool shortcut, bool requires_units) int32_t save_cur_val; f = 0; - arith_error = false; + set_arith_error(false); cur_order = NORMAL; negative = false; @@ -8244,7 +8245,7 @@ xetex_scan_dimen(bool mu, bool inf, bool shortcut, bool requires_units) if (mu) { scan_something_internal(MU_VAL, false); if (cur_val_level >= GLUE_VAL) { - v = mem[cur_val + 1].b32.s1; + v = mem(cur_val + 1).b32.s1; delete_glue_ref(cur_val); cur_val = v; } @@ -8286,8 +8287,8 @@ xetex_scan_dimen(bool mu, bool inf, bool shortcut, bool requires_units) if (k < 17) { q = get_avail(); - mem[q].b32.s1 = p; - mem[q].b32.s0 = cur_tok - ZERO_TOKEN; + mem_ptr(q)->b32.s1 = p; + mem_ptr(q)->b32.s0 = cur_tok - ZERO_TOKEN; p = q; k++; } @@ -8295,10 +8296,10 @@ xetex_scan_dimen(bool mu, bool inf, bool shortcut, bool requires_units) done1: for (kk = k; kk >= 1; kk--) { - dig[kk - 1] = mem[p].b32.s0; + set_dig(kk - 1, mem(p).b32.s0); q = p; p = LLIST_link(p); - mem[q].b32.s1 = avail; + mem_ptr(q)->b32.s1 = avail; avail = q; } @@ -8349,7 +8350,7 @@ xetex_scan_dimen(bool mu, bool inf, bool shortcut, bool requires_units) if (mu) { scan_something_internal(MU_VAL, false); if (cur_val_level >= GLUE_VAL) { - v = mem[cur_val + 1].b32.s1; + v = mem(cur_val + 1).b32.s1; delete_glue_ref(cur_val); cur_val = v; } @@ -8367,9 +8368,9 @@ xetex_scan_dimen(bool mu, bool inf, bool shortcut, bool requires_units) goto not_found; if (scan_keyword("em")) - v = font_info[QUAD_CODE + param_base[eqtb[CUR_FONT_LOC].b32.s1]].b32.s1; + v = font_info[QUAD_CODE + param_base[eqtb_ptr(CUR_FONT_LOC)->b32.s1]].b32.s1; else if (scan_keyword("ex")) - v = font_info[X_HEIGHT_CODE + param_base[eqtb[CUR_FONT_LOC].b32.s1]].b32.s1; + v = font_info[X_HEIGHT_CODE + param_base[eqtb_ptr(CUR_FONT_LOC)->b32.s1]].b32.s1; else goto not_found; @@ -8403,7 +8404,7 @@ xetex_scan_dimen(bool mu, bool inf, bool shortcut, bool requires_units) prepare_mag(); if (INTPAR(mag) != 1000) { cur_val = xn_over_d(cur_val, 1000, INTPAR(mag)); - f = (1000 * f + 65536L * tex_remainder) / INTPAR(mag); + f = (1000 * f + 65536L * tex_remainder()) / INTPAR(mag); cur_val = cur_val + (f / 65536L); f = f % 65536L; } @@ -8451,7 +8452,7 @@ xetex_scan_dimen(bool mu, bool inf, bool shortcut, bool requires_units) } cur_val = xn_over_d(cur_val, num, denom); - f = (num * f + 65536L * tex_remainder) / denom; + f = (num * f + 65536L * tex_remainder()) / denom; cur_val = cur_val + (f / 65536L); f = f % 65536L; @@ -8460,7 +8461,7 @@ xetex_scan_dimen(bool mu, bool inf, bool shortcut, bool requires_units) attach_fraction: if (cur_val >= 16384) - arith_error = true; + set_arith_error(true); else cur_val = cur_val * 65536L + f; @@ -8470,13 +8471,13 @@ xetex_scan_dimen(bool mu, bool inf, bool shortcut, bool requires_units) back_input(); } else { /* if(requires_units) */ if (cur_val >= 16384) - arith_error = true; + set_arith_error(true); else cur_val = cur_val * 65536L + f; } attach_sign: - if (arith_error || abs(cur_val) >= 0x40000000) { /*479:*/ + if (arith_error() || abs(cur_val) >= 0x40000000) { /*479:*/ error_here_with_diagnostic("Dimension too large"); capture_to_diagnostic(NULL); @@ -8485,7 +8486,7 @@ xetex_scan_dimen(bool mu, bool inf, bool shortcut, bool requires_units) help_line[0] = "Continue and I'll use the largest value I can."; error(); cur_val = MAX_HALFWORD; - arith_error = false; + set_arith_error(false); } if (negative) @@ -8545,18 +8546,18 @@ scan_glue(small_number level) } q = new_spec(0); - mem[q + 1].b32.s1 = cur_val; + mem_ptr(q + 1)->b32.s1 = cur_val; if (scan_keyword("plus")) { scan_dimen(mu, true, false); - mem[q + 2].b32.s1 = cur_val; - mem[q].b16.s1 = cur_order; + mem_ptr(q + 2)->b32.s1 = cur_val; + mem_ptr(q)->b16.s1 = cur_order; } if (scan_keyword("minus")) { scan_dimen(mu, true, false); - mem[q + 3].b32.s1 = cur_val; - mem[q].b16.s0 = cur_order; + mem_ptr(q + 3)->b32.s1 = cur_val; + mem_ptr(q)->b16.s0 = cur_order; } cur_val = q; /*:481*/ @@ -8574,14 +8575,14 @@ int32_t add_or_sub(int32_t x, int32_t y, int32_t max_answer, bool negative) a = x + y; else { - arith_error = true; + set_arith_error(true); a = 0; } } else if (y >= -(int32_t) max_answer - x) a = x + y; else { - arith_error = true; + set_arith_error(true); a = 0; } return a; @@ -8592,7 +8593,7 @@ int32_t quotient(int32_t n, int32_t d) bool negative; int32_t a; if (d == 0) { - arith_error = true; + set_arith_error(true); a = 0; } else { @@ -8705,7 +8706,7 @@ int32_t fract(int32_t x, int32_t n, int32_t d, int32_t max_answer) goto done; too_big: { - arith_error = true; + set_arith_error(true); a = 0; } done: @@ -8726,7 +8727,7 @@ void scan_expr(void) int32_t p; int32_t q; l = cur_val_level; - a = arith_error; + a = arith_error(); b = false; p = TEX_NULL; @@ -8750,12 +8751,12 @@ void scan_expr(void) } while (cur_cmd == SPACER); if (cur_tok == (OTHER_TOKEN + 40)) { /*1576: */ q = get_node(EXPR_NODE_SIZE); - mem[q].b32.s1 = p; - mem[q].b16.s1 = l; - mem[q].b16.s0 = 4 * s + r; - mem[q + 1].b32.s1 = e; - mem[q + 2].b32.s1 = t; - mem[q + 3].b32.s1 = n; + mem_ptr(q)->b32.s1 = p; + mem_ptr(q)->b16.s1 = l; + mem_ptr(q)->b16.s0 = 4 * s + r; + mem_ptr(q + 1)->b32.s1 = e; + mem_ptr(q + 2)->b32.s1 = t; + mem_ptr(q + 3)->b32.s1 = n; p = q; l = o; goto restart; @@ -8799,22 +8800,22 @@ void scan_expr(void) back_error(); } } - arith_error = b; + set_arith_error(b); if ((l == INT_VAL) || (s > EXPR_SUB)) { if ((f > TEX_INFINITY) || (f < -TEX_INFINITY)) { - arith_error = true; + set_arith_error(true); f = 0; } } else if (l == DIMEN_VAL) { if (abs(f) > MAX_HALFWORD) { - arith_error = true; + set_arith_error(true); f = 0; } } else { - if ((abs(mem[f + 1].b32.s1) > MAX_HALFWORD) || (abs(mem[f + 2].b32.s1) > MAX_HALFWORD) - || (abs(mem[f + 3].b32.s1) > MAX_HALFWORD)) { - arith_error = true; + if ((abs(mem(f + 1).b32.s1) > MAX_HALFWORD) || (abs(mem(f + 2).b32.s1) > MAX_HALFWORD) + || (abs(mem(f + 3).b32.s1) > MAX_HALFWORD)) { + set_arith_error(true); delete_glue_ref(f); f = new_spec(0); } @@ -8824,10 +8825,10 @@ void scan_expr(void) if ((l >= GLUE_VAL) && (o != EXPR_NONE)) { t = new_spec(f); delete_glue_ref(f); - if (mem[t + 2].b32.s1 == 0) - mem[t].b16.s1 = NORMAL; - if (mem[t + 3].b32.s1 == 0) - mem[t].b16.s0 = NORMAL; + if (mem(t + 2).b32.s1 == 0) + mem_ptr(t)->b16.s1 = NORMAL; + if (mem(t + 3).b32.s1 == 0) + mem_ptr(t)->b16.s0 = NORMAL; } else t = f; break; @@ -8841,9 +8842,9 @@ void scan_expr(void) t = mult_and_add(t, f, 0, MAX_HALFWORD); else { - mem[t + 1].b32.s1 = mult_and_add(mem[t + 1].b32.s1, f, 0, MAX_HALFWORD); - mem[t + 2].b32.s1 = mult_and_add(mem[t + 2].b32.s1, f, 0, MAX_HALFWORD); - mem[t + 3].b32.s1 = mult_and_add(mem[t + 3].b32.s1, f, 0, MAX_HALFWORD); + mem_ptr(t + 1)->b32.s1 = mult_and_add(mem(t + 1).b32.s1, f, 0, MAX_HALFWORD); + mem_ptr(t + 2)->b32.s1 = mult_and_add(mem(t + 2).b32.s1, f, 0, MAX_HALFWORD); + mem_ptr(t + 3)->b32.s1 = mult_and_add(mem(t + 3).b32.s1, f, 0, MAX_HALFWORD); } break; case 4: @@ -8851,9 +8852,9 @@ void scan_expr(void) t = quotient(t, f); else { - mem[t + 1].b32.s1 = quotient(mem[t + 1].b32.s1, f); - mem[t + 2].b32.s1 = quotient(mem[t + 2].b32.s1, f); - mem[t + 3].b32.s1 = quotient(mem[t + 3].b32.s1, f); + mem_ptr(t + 1)->b32.s1 = quotient(mem(t + 1).b32.s1, f); + mem_ptr(t + 2)->b32.s1 = quotient(mem(t + 2).b32.s1, f); + mem_ptr(t + 3)->b32.s1 = quotient(mem(t + 3).b32.s1, f); } break; case 5: @@ -8863,9 +8864,9 @@ void scan_expr(void) t = fract(t, n, f, MAX_HALFWORD); else { - mem[t + 1].b32.s1 = fract(mem[t + 1].b32.s1, n, f, MAX_HALFWORD); - mem[t + 2].b32.s1 = fract(mem[t + 2].b32.s1, n, f, MAX_HALFWORD); - mem[t + 3].b32.s1 = fract(mem[t + 3].b32.s1, n, f, MAX_HALFWORD); + mem_ptr(t + 1)->b32.s1 = fract(mem(t + 1).b32.s1, n, f, MAX_HALFWORD); + mem_ptr(t + 2)->b32.s1 = fract(mem(t + 2).b32.s1, n, f, MAX_HALFWORD); + mem_ptr(t + 3)->b32.s1 = fract(mem(t + 3).b32.s1, n, f, MAX_HALFWORD); } break; } @@ -8882,40 +8883,40 @@ void scan_expr(void) e = add_or_sub(e, t, MAX_HALFWORD, r == EXPR_SUB); else { /*1582: */ - mem[e + 1].b32.s1 = add_or_sub(mem[e + 1].b32.s1, mem[t + 1].b32.s1, MAX_HALFWORD, r == EXPR_SUB); - if (mem[e].b16.s1 == mem[t].b16.s1) - mem[e + 2].b32.s1 = add_or_sub(mem[e + 2].b32.s1, mem[t + 2].b32.s1, MAX_HALFWORD, r == EXPR_SUB); - else if ((mem[e].b16.s1 < mem[t].b16.s1) && (mem[t + 2].b32.s1 != 0)) { - mem[e + 2].b32.s1 = mem[t + 2].b32.s1; - mem[e].b16.s1 = mem[t].b16.s1; + mem_ptr(e + 1)->b32.s1 = add_or_sub(mem(e + 1).b32.s1, mem(t + 1).b32.s1, MAX_HALFWORD, r == EXPR_SUB); + if (mem(e).b16.s1 == mem(t).b16.s1) + mem_ptr(e + 2)->b32.s1 = add_or_sub(mem(e + 2).b32.s1, mem(t + 2).b32.s1, MAX_HALFWORD, r == EXPR_SUB); + else if ((mem(e).b16.s1 < mem(t).b16.s1) && (mem(t + 2).b32.s1 != 0)) { + mem_ptr(e + 2)->b32.s1 = mem(t + 2).b32.s1; + mem_ptr(e)->b16.s1 = mem(t).b16.s1; } - if (mem[e].b16.s0 == mem[t].b16.s0) - mem[e + 3].b32.s1 = add_or_sub(mem[e + 3].b32.s1, mem[t + 3].b32.s1, MAX_HALFWORD, r == EXPR_SUB); - else if ((mem[e].b16.s0 < mem[t].b16.s0) && (mem[t + 3].b32.s1 != 0)) { - mem[e + 3].b32.s1 = mem[t + 3].b32.s1; - mem[e].b16.s0 = mem[t].b16.s0; + if (mem(e).b16.s0 == mem(t).b16.s0) + mem_ptr(e + 3)->b32.s1 = add_or_sub(mem(e + 3).b32.s1, mem(t + 3).b32.s1, MAX_HALFWORD, r == EXPR_SUB); + else if ((mem(e).b16.s0 < mem(t).b16.s0) && (mem(t + 3).b32.s1 != 0)) { + mem_ptr(e + 3)->b32.s1 = mem(t + 3).b32.s1; + mem_ptr(e)->b16.s0 = mem(t).b16.s0; } delete_glue_ref(t); - if (mem[e + 2].b32.s1 == 0) - mem[e].b16.s1 = NORMAL; - if (mem[e + 3].b32.s1 == 0) - mem[e].b16.s0 = NORMAL; + if (mem(e + 2).b32.s1 == 0) + mem_ptr(e)->b16.s1 = NORMAL; + if (mem(e + 3).b32.s1 == 0) + mem_ptr(e)->b16.s0 = NORMAL; } r = o; } - b = arith_error; + b = arith_error(); if (o != EXPR_NONE) goto continue_; if (p != TEX_NULL) { /*1577: */ f = e; q = p; - e = mem[q + 1].b32.s1; - t = mem[q + 2].b32.s1; - n = mem[q + 3].b32.s1; - s = mem[q].b16.s0 / 4; - r = mem[q].b16.s0 % 4; - l = mem[q].b16.s1; - p = mem[q].b32.s1; + e = mem(q + 1).b32.s1; + t = mem(q + 2).b32.s1; + n = mem(q + 3).b32.s1; + s = mem(q).b16.s0 / 4; + r = mem(q).b16.s0 % 4; + l = mem(q).b16.s1; + p = mem(q).b32.s1; free_node(q, EXPR_NODE_SIZE); goto found; } @@ -8939,7 +8940,7 @@ void scan_expr(void) } else e = 0; } - arith_error = a; + set_arith_error(a); cur_val = e; cur_val_level = l; } @@ -8959,26 +8960,26 @@ int32_t scan_rule_spec(void) int32_t q; q = new_rule(); if (cur_cmd == VRULE) - mem[q + 1].b32.s1 = DEFAULT_RULE; + mem_ptr(q + 1)->b32.s1 = DEFAULT_RULE; else { - mem[q + 3].b32.s1 = DEFAULT_RULE; - mem[q + 2].b32.s1 = 0; + mem_ptr(q + 3)->b32.s1 = DEFAULT_RULE; + mem_ptr(q + 2)->b32.s1 = 0; } reswitch: if (scan_keyword("width")) { scan_dimen(false, false, false); - mem[q + 1].b32.s1 = cur_val; + mem_ptr(q + 1)->b32.s1 = cur_val; goto reswitch; } if (scan_keyword("height")) { scan_dimen(false, false, false); - mem[q + 3].b32.s1 = cur_val; + mem_ptr(q + 3)->b32.s1 = cur_val; goto reswitch; } if (scan_keyword("depth")) { scan_dimen(false, false, false); - mem[q + 2].b32.s1 = cur_val; + mem_ptr(q + 2)->b32.s1 = cur_val; goto reswitch; } return q; @@ -8998,7 +8999,7 @@ void scan_general_text(void) scanner_status = ABSORBING; warning_index = cur_cs; def_ref = get_avail(); - mem[def_ref].b32.s0 = TEX_NULL; + mem_ptr(def_ref)->b32.s0 = TEX_NULL; p = def_ref; scan_left_brace(); unbalance = 1; @@ -9018,22 +9019,22 @@ void scan_general_text(void) } { q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = cur_tok; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = cur_tok; p = q; } } found: - q = mem[def_ref].b32.s1; + q = mem(def_ref).b32.s1; { - mem[def_ref].b32.s1 = avail; + mem_ptr(def_ref)->b32.s1 = avail; avail = def_ref; } if (q == TEX_NULL) cur_val = TEMP_HEAD; else cur_val = p; - mem[TEMP_HEAD].b32.s1 = q; + mem_ptr(TEMP_HEAD)->b32.s1 = q; scanner_status = s; warning_index = w; def_ref = d; @@ -9049,42 +9050,42 @@ void pseudo_start(void) int32_t nl, sz; scan_general_text(); - old_setting = selector; - selector = SELECTOR_NEW_STRING ; + old_setting = selector(); + set_selector(SELECTOR_NEW_STRING); token_show(TEMP_HEAD); - selector = old_setting; - flush_list(mem[TEMP_HEAD].b32.s1); + set_selector(old_setting); + flush_list(mem(TEMP_HEAD).b32.s1); { - if (pool_ptr + 1 > pool_size) - overflow("pool size", pool_size - init_pool_ptr); + if (pool_ptr() + 1 > pool_size()) + overflow("pool size", pool_size() - init_pool_ptr); } s = make_string(); - str_pool[pool_ptr] = ' ' ; - l = str_start[(s) - 65536L]; + set_str_pool(pool_ptr(), ' ' ); + l = str_start((s) - 65536L); nl = INTPAR(new_line_char); p = get_avail(); q = p; - while (l < pool_ptr) { + while (l < pool_ptr()) { m = l; - while ((l < pool_ptr) && (str_pool[l] != nl)) + while ((l < pool_ptr()) && (str_pool(l) != nl)) l++; sz = (l - m + 7) / 4; if (sz == 1) sz = 2; r = get_node(sz); - mem[q].b32.s1 = r; + mem_ptr(q)->b32.s1 = r; q = r; - mem[q].b32.s0 = sz; + mem_ptr(q)->b32.s0 = sz; while (sz > 2) { sz--; r++; - w.s3 = str_pool[m]; - w.s2 = str_pool[m + 1]; - w.s1 = str_pool[m + 2]; - w.s0 = str_pool[m + 3]; - mem[r].b16 = w; + w.s3 = str_pool(m); + w.s2 = str_pool(m + 1); + w.s1 = str_pool(m + 2); + w.s0 = str_pool(m + 3); + mem_ptr(r)->b16 = w; m = m + 4; } w.s3 = ' ' ; @@ -9092,44 +9093,44 @@ void pseudo_start(void) w.s1 = ' ' ; w.s0 = ' ' ; if (l > m) { - w.s3 = str_pool[m]; + w.s3 = str_pool(m); if (l > m + 1) { - w.s2 = str_pool[m + 1]; + w.s2 = str_pool(m + 1); if (l > m + 2) { - w.s1 = str_pool[m + 2]; + w.s1 = str_pool(m + 2); if (l > m + 3) - w.s0 = str_pool[m + 3]; + w.s0 = str_pool(m + 3); } } } - mem[r + 1].b16 = w; - if (str_pool[l] == nl) + mem_ptr(r + 1)->b16 = w; + if (str_pool(l) == nl) l++; } - mem[p].b32.s0 = mem[p].b32.s1; - mem[p].b32.s1 = pseudo_files; + mem_ptr(p)->b32.s0 = mem(p).b32.s1; + mem_ptr(p)->b32.s1 = pseudo_files; pseudo_files = /*:1542 */ p; { - str_ptr--; - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + set_str_ptr(str_ptr()-1); + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); } begin_file_reading(); - line = 0; - cur_input.limit = cur_input.start; - cur_input.loc = cur_input.limit + 1; + set_line(0); + cur_input_ptr()->limit = cur_input().start; + cur_input_ptr()->loc = cur_input().limit + 1; if (INTPAR(tracing_scan_tokens) > 0) { - if (term_offset > max_print_line - 3) + if (term_offset() > max_print_line - 3) print_ln(); - else if ((term_offset > 0) || (file_offset > 0)) + else if ((term_offset() > 0) || (file_offset() > 0)) print_char(' '); - cur_input.name = 19; + cur_input_ptr()->name = 19; print_cstr("( "); open_parens++; - ttstub_output_flush (rust_stdout); + ttstub_output_flush(rust_stdout()); } else { - cur_input.name = 18; - cur_input.synctex_tag = 0; + cur_input_ptr()->name = 18; + cur_input_ptr()->synctex_tag = 0; } } @@ -9144,22 +9145,22 @@ str_toks_cat(pool_pointer b, small_number cat) int32_t t; pool_pointer k; - if (pool_ptr + 1 > pool_size) - overflow("pool size", pool_size - init_pool_ptr); + if (pool_ptr() + 1 > pool_size()) + overflow("pool size", pool_size() - init_pool_ptr); p = TEMP_HEAD; LLIST_link(p) = TEX_NULL; k = b; - while (k < pool_ptr) { - t = str_pool[k]; + while (k < pool_ptr()) { + t = str_pool(k); if (t == ' ' && cat == 0) { t = SPACE_TOKEN; } else { - if (t >= 0xD800 && t < 0xDC00 && k + 1 < pool_ptr && str_pool[k + 1] >= 0xDC00 && str_pool[k + 1] < 0xE000) { + if (t >= 0xD800 && t < 0xDC00 && k + 1 < pool_ptr() && str_pool(k + 1) >= 0xDC00 && str_pool(k + 1) < 0xE000) { k++; - t = 0x10000 + ((t - 0xD800) << 10) + (str_pool[k] - 0xDC00); + t = 0x10000 + ((t - 0xD800) << 10) + (str_pool(k) - 0xDC00); } if (cat == 0) @@ -9185,7 +9186,7 @@ str_toks_cat(pool_pointer b, small_number cat) k++; } - pool_ptr = b; + set_pool_ptr(b); return p; } @@ -9210,14 +9211,14 @@ int32_t the_toks(void) return cur_val; else { - old_setting = selector; - selector = SELECTOR_NEW_STRING ; - b = pool_ptr; + old_setting = selector(); + set_selector(SELECTOR_NEW_STRING); + b = pool_ptr(); p = get_avail(); - mem[p].b32.s1 = mem[TEMP_HEAD].b32.s1; + mem_ptr(p)->b32.s1 = mem(TEMP_HEAD).b32.s1; token_show(p); flush_list(p); - selector = old_setting; + set_selector(old_setting); return str_toks(b); } } @@ -9225,14 +9226,14 @@ int32_t the_toks(void) scan_something_internal(TOK_VAL, false); if (cur_val_level >= IDENT_VAL) { /*485: */ p = TEMP_HEAD; - mem[p].b32.s1 = TEX_NULL; + mem_ptr(p)->b32.s1 = TEX_NULL; if (cur_val_level == IDENT_VAL) { q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = CS_TOKEN_FLAG + cur_val; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = CS_TOKEN_FLAG + cur_val; p = q; } else if (cur_val != TEX_NULL) { - r = mem[cur_val].b32.s1; + r = mem(cur_val).b32.s1; while (r != TEX_NULL) { { @@ -9242,12 +9243,12 @@ int32_t the_toks(void) q = get_avail(); else { - avail = mem[q].b32.s1; - mem[q].b32.s1 = TEX_NULL; + avail = mem(q).b32.s1; + mem_ptr(q)->b32.s1 = TEX_NULL; } } - mem[p].b32.s1 = q; - mem[q].b32.s0 = mem[r].b32.s0; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = mem(r).b32.s0; p = q; } r = LLIST_link(r); @@ -9256,9 +9257,9 @@ int32_t the_toks(void) return p; } else { - old_setting = selector; - selector = SELECTOR_NEW_STRING ; - b = pool_ptr; + old_setting = selector(); + set_selector(SELECTOR_NEW_STRING); + b = pool_ptr(); switch (cur_val_level) { case 0: print_int(cur_val); @@ -9282,15 +9283,15 @@ int32_t the_toks(void) } break; } - selector = old_setting; + set_selector(old_setting); return str_toks(b); } } void ins_the_toks(void) { - mem[GARBAGE].b32.s1 = the_toks(); - begin_token_list(mem[TEMP_HEAD].b32.s1, INSERTED); + mem_ptr(GARBAGE)->b32.s1 = the_toks(); + begin_token_list(mem(TEMP_HEAD).b32.s1, INSERTED); } @@ -9341,19 +9342,19 @@ conv_toks(void) save_scanner_status = scanner_status; save_warning_index = warning_index; save_def_ref = def_ref; - if (str_start[str_ptr - TOO_BIG_CHAR] < pool_ptr) + if (str_start(str_ptr() - TOO_BIG_CHAR) < pool_ptr()) u = make_string(); else u = 0; scan_pdf_ext_toks(); warning_index = save_warning_index; scanner_status = save_scanner_status; - begin_token_list(mem[def_ref].b32.s1, INSERTED); - mem[def_ref].b32.s1 = avail; + begin_token_list(mem(def_ref).b32.s1, INSERTED); + mem_ptr(def_ref)->b32.s1 = avail; avail = def_ref; def_ref = save_def_ref; if (u != 0) - str_ptr--; + set_str_ptr(str_ptr()-1); return; case LEFT_MARGIN_KERN_CODE: @@ -9367,7 +9368,7 @@ conv_toks(void) if (cur_ptr == TEX_NULL) p = TEX_NULL; else - p = mem[cur_ptr + 1].b32.s1; + p = mem(cur_ptr + 1).b32.s1; } if (p == TEX_NULL || NODE_type(p) != HLIST_NODE) @@ -9375,82 +9376,82 @@ conv_toks(void) break; case PDF_CREATION_DATE_CODE: - b = pool_ptr; + b = pool_ptr(); getcreationdate(); - mem[GARBAGE].b32.s1 = str_toks(b); - begin_token_list(mem[TEMP_HEAD].b32.s1, INSERTED); + mem_ptr(GARBAGE)->b32.s1 = str_toks(b); + begin_token_list(mem(TEMP_HEAD).b32.s1, INSERTED); break; case PDF_FILE_MOD_DATE_CODE: save_scanner_status = scanner_status; save_warning_index = warning_index; save_def_ref = def_ref; - if (str_start[str_ptr - TOO_BIG_CHAR] < pool_ptr) + if (str_start(str_ptr() - TOO_BIG_CHAR) < pool_ptr()) u = make_string(); else u = 0; scan_pdf_ext_toks(); - if (selector == SELECTOR_NEW_STRING) + if (selector() == SELECTOR_NEW_STRING) pdf_error("tokens", "tokens_to_string() called while selector = new_string"); - old_setting = selector; - selector = SELECTOR_NEW_STRING; - show_token_list(mem[def_ref].b32.s1, TEX_NULL, pool_size - pool_ptr); - selector = old_setting; + old_setting = selector(); + set_selector(SELECTOR_NEW_STRING); + show_token_list(mem(def_ref).b32.s1, TEX_NULL, pool_size() - pool_ptr()); + set_selector(old_setting); s = make_string(); delete_token_ref(def_ref); def_ref = save_def_ref; warning_index = save_warning_index; scanner_status = save_scanner_status; - b = pool_ptr; + b = pool_ptr(); getfilemoddate(s); /* <= the difference-maker */ - mem[GARBAGE].b32.s1 = str_toks(b); + mem_ptr(GARBAGE)->b32.s1 = str_toks(b); - if (s == str_ptr - 1) { - str_ptr--; - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + if (s == str_ptr() - 1) { + set_str_ptr(str_ptr()-1); + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); } - begin_token_list(mem[TEMP_HEAD].b32.s1, INSERTED); + begin_token_list(mem(TEMP_HEAD).b32.s1, INSERTED); if (u != 0) - str_ptr--; + set_str_ptr(str_ptr()-1); return; case PDF_FILE_SIZE_CODE: save_scanner_status = scanner_status; save_warning_index = warning_index; save_def_ref = def_ref; - if (str_start[str_ptr - TOO_BIG_CHAR] < pool_ptr) + if (str_start(str_ptr() - TOO_BIG_CHAR) < pool_ptr()) u = make_string(); else u = 0; scan_pdf_ext_toks(); - if (selector == SELECTOR_NEW_STRING) + if (selector() == SELECTOR_NEW_STRING) pdf_error("tokens", "tokens_to_string() called while selector = new_string"); - old_setting = selector; - selector = SELECTOR_NEW_STRING; - show_token_list(mem[def_ref].b32.s1, TEX_NULL, pool_size - pool_ptr); - selector = old_setting; + old_setting = selector(); + set_selector(SELECTOR_NEW_STRING); + show_token_list(mem(def_ref).b32.s1, TEX_NULL, pool_size() - pool_ptr()); + set_selector(old_setting); s = make_string(); delete_token_ref(def_ref); def_ref = save_def_ref; warning_index = save_warning_index; scanner_status = save_scanner_status; - b = pool_ptr; + b = pool_ptr(); getfilesize(s); /* <= the difference-maker */ - mem[GARBAGE].b32.s1 = str_toks(b); + mem_ptr(GARBAGE)->b32.s1 = str_toks(b); - if (s == str_ptr - 1) { - str_ptr--; - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + if (s == str_ptr() - 1) { + set_str_ptr(str_ptr()-1); + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); } - begin_token_list(mem[TEMP_HEAD].b32.s1, INSERTED); + begin_token_list(mem(TEMP_HEAD).b32.s1, INSERTED); if (u != 0) - str_ptr--; + set_str_ptr(str_ptr()-1); return; case PDF_MDFIVE_SUM_CODE: @@ -9458,7 +9459,7 @@ conv_toks(void) save_warning_index = warning_index; save_def_ref = def_ref; - if (str_start[str_ptr - TOO_BIG_CHAR] < pool_ptr) + if (str_start(str_ptr() - TOO_BIG_CHAR) < pool_ptr()) u = make_string(); else u = 0; @@ -9466,30 +9467,30 @@ conv_toks(void) boolvar = scan_keyword("file"); scan_pdf_ext_toks(); - if (selector == SELECTOR_NEW_STRING) + if (selector() == SELECTOR_NEW_STRING) pdf_error("tokens", "tokens_to_string() called while selector = new_string"); - old_setting = selector; - selector = SELECTOR_NEW_STRING; - show_token_list(mem[def_ref].b32.s1, TEX_NULL, pool_size - pool_ptr); - selector = old_setting; + old_setting = selector(); + set_selector(SELECTOR_NEW_STRING); + show_token_list(mem(def_ref).b32.s1, TEX_NULL, pool_size() - pool_ptr()); + set_selector(old_setting); s = make_string(); delete_token_ref(def_ref); def_ref = save_def_ref; warning_index = save_warning_index; scanner_status = save_scanner_status; - b = pool_ptr; + b = pool_ptr(); getmd5sum(s, boolvar); /* <== the difference-maker */ - mem[GARBAGE].b32.s1 = str_toks(b); + mem_ptr(GARBAGE)->b32.s1 = str_toks(b); - if (s == str_ptr - 1) { - str_ptr--; - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + if (s == str_ptr() - 1) { + set_str_ptr(str_ptr()-1); + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); } - begin_token_list(mem[TEMP_HEAD].b32.s1, INSERTED); + begin_token_list(mem(TEMP_HEAD).b32.s1, INSERTED); if (u != 0) - str_ptr--; + set_str_ptr(str_ptr()-1); return; break; @@ -9498,7 +9499,7 @@ conv_toks(void) save_warning_index = warning_index; save_def_ref = def_ref; - if (str_start[str_ptr - TOO_BIG_CHAR] < pool_ptr) + if (str_start(str_ptr() - TOO_BIG_CHAR) < pool_ptr()) u = make_string(); else u = 0; @@ -9540,37 +9541,37 @@ conv_toks(void) scan_pdf_ext_toks(); - if (selector == SELECTOR_NEW_STRING) + if (selector() == SELECTOR_NEW_STRING) pdf_error("tokens", "tokens_to_string() called while selector = new_string"); - old_setting = selector; - selector = SELECTOR_NEW_STRING; - show_token_list(mem[def_ref].b32.s1, TEX_NULL, pool_size - pool_ptr); - selector = old_setting; + old_setting = selector(); + set_selector(SELECTOR_NEW_STRING); + show_token_list(mem(def_ref).b32.s1, TEX_NULL, pool_size() - pool_ptr()); + set_selector(old_setting); s = make_string(); delete_token_ref(def_ref); def_ref = save_def_ref; warning_index = save_warning_index; scanner_status = save_scanner_status; - b = pool_ptr; + b = pool_ptr(); getfiledump(s, i, j); /* <=== non-boilerplate */ - mem[GARBAGE].b32.s1 = str_toks(b); + mem_ptr(GARBAGE)->b32.s1 = str_toks(b); - if (s == str_ptr - 1) { - str_ptr--; - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + if (s == str_ptr() - 1) { + set_str_ptr(str_ptr()-1); + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); } - begin_token_list(mem[TEMP_HEAD].b32.s1, INSERTED); + begin_token_list(mem(TEMP_HEAD).b32.s1, INSERTED); if (u != 0) - str_ptr--; + set_str_ptr(str_ptr()-1); return; case PDF_STRCMP_CODE: save_scanner_status = scanner_status; save_warning_index = warning_index; save_def_ref = def_ref; - if (str_start[str_ptr - TOO_BIG_CHAR] < pool_ptr) + if (str_start(str_ptr() - TOO_BIG_CHAR) < pool_ptr()) u = make_string(); else u = 0; @@ -9579,7 +9580,7 @@ conv_toks(void) warning_index = save_warning_index; scanner_status = save_scanner_status; if (u != 0) - str_ptr--; + set_str_ptr(str_ptr()-1); break; case XETEX_UCHAR_CODE: @@ -9662,7 +9663,7 @@ conv_toks(void) break; case JOB_NAME_CODE: - if (job_name == 0) + if (job_name() == 0) open_log_file(); break; @@ -9674,9 +9675,9 @@ conv_toks(void) break; } - old_setting = selector; - selector = SELECTOR_NEW_STRING; - b = pool_ptr; + old_setting = selector(); + set_selector(SELECTOR_NEW_STRING); + b = pool_ptr(); switch (c) { case NUMBER_CODE: @@ -9705,7 +9706,7 @@ conv_toks(void) quote_char = '"' ; for (i = 0; i <= length(font_name_str) - 1; i++) - if (str_pool[str_start[(font_name_str) - 65536L] + i] == '"' ) + if (str_pool(str_start((font_name_str) - 65536L) + i) == '"' ) quote_char = '\'' ; print_char(quote_char); @@ -9727,7 +9728,7 @@ conv_toks(void) break; case LEFT_MARGIN_KERN_CODE: - p = mem[p + 5].b32.s1; + p = mem(p + 5).b32.s1; while (p != TEX_NULL && ((p < hi_mem_min && (NODE_type(p) == INS_NODE || @@ -9735,33 +9736,33 @@ conv_toks(void) NODE_type(p) == ADJUST_NODE || NODE_type(p) == PENALTY_NODE || (NODE_type(p) == DISC_NODE && - mem[p + 1].b32.s0 == TEX_NULL && - mem[p + 1].b32.s1 == TEX_NULL && - mem[p].b16.s0 == 0) || + mem(p + 1).b32.s0 == TEX_NULL && + mem(p + 1).b32.s1 == TEX_NULL && + mem(p).b16.s0 == 0) || (NODE_type(p) == MATH_NODE && - mem[p + 1].b32.s1 == 0) || + mem(p + 1).b32.s1 == 0) || (NODE_type(p) == KERN_NODE && - (mem[p + 1].b32.s1 == 0 || mem[p].b16.s0 == NORMAL)) || + (mem(p + 1).b32.s1 == 0 || mem(p).b16.s0 == NORMAL)) || (NODE_type(p) == GLUE_NODE && - mem[p + 1].b32.s0 == 0) || + mem(p + 1).b32.s0 == 0) || (NODE_type(p) == HLIST_NODE && - mem[p + 1].b32.s1 == 0 && - mem[p + 3].b32.s1 == 0 && - mem[p + 2].b32.s1 == 0 && - mem[p + 5].b32.s1 == TEX_NULL) + mem(p + 1).b32.s1 == 0 && + mem(p + 3).b32.s1 == 0 && + mem(p + 2).b32.s1 == 0 && + mem(p + 5).b32.s1 == TEX_NULL) )) || - (p < hi_mem_min && NODE_type(p) == GLUE_NODE && mem[p].b16.s0 == (GLUE_PAR__left_skip + 1)))) + (p < hi_mem_min && NODE_type(p) == GLUE_NODE && mem(p).b16.s0 == (GLUE_PAR__left_skip + 1)))) p = LLIST_link(p); - if (p != TEX_NULL && p < hi_mem_min && NODE_type(p) == MARGIN_KERN_NODE && mem[p].b16.s0 == 0) - print_scaled(mem[p + 1].b32.s1); + if (p != TEX_NULL && p < hi_mem_min && NODE_type(p) == MARGIN_KERN_NODE && mem(p).b16.s0 == 0) + print_scaled(mem(p + 1).b32.s1); else print('0'); print_cstr("pt"); break; case RIGHT_MARGIN_KERN_CODE: - q = mem[p + 5].b32.s1; + q = mem(p + 5).b32.s1; p = prev_rightmost(q, TEX_NULL); while (p != TEX_NULL && ((p < hi_mem_min && @@ -9770,26 +9771,26 @@ conv_toks(void) NODE_type(p) == ADJUST_NODE || NODE_type(p) == PENALTY_NODE || (NODE_type(p) == DISC_NODE && - mem[p + 1].b32.s0 == TEX_NULL && - mem[p + 1].b32.s1 == TEX_NULL && - mem[p].b16.s0 == 0) || + mem(p + 1).b32.s0 == TEX_NULL && + mem(p + 1).b32.s1 == TEX_NULL && + mem(p).b16.s0 == 0) || (NODE_type(p) == MATH_NODE && - mem[p + 1].b32.s1 == 0) || + mem(p + 1).b32.s1 == 0) || (NODE_type(p) == KERN_NODE && - (mem[p + 1].b32.s1 == 0 || mem[p].b16.s0 == NORMAL)) || + (mem(p + 1).b32.s1 == 0 || mem(p).b16.s0 == NORMAL)) || (NODE_type(p) == GLUE_NODE && - mem[p + 1].b32.s0 == 0) || + mem(p + 1).b32.s0 == 0) || (NODE_type(p) == HLIST_NODE && - mem[p + 1].b32.s1 == 0 && - mem[p + 3].b32.s1 == 0 && - mem[p + 2].b32.s1 == 0 && - mem[p + 5].b32.s1 == TEX_NULL) + mem(p + 1).b32.s1 == 0 && + mem(p + 3).b32.s1 == 0 && + mem(p + 2).b32.s1 == 0 && + mem(p + 5).b32.s1 == TEX_NULL) )) || - (p < hi_mem_min && NODE_type(p) == GLUE_NODE && mem[p].b16.s0 == (GLUE_PAR__right_skip + 1)))) + (p < hi_mem_min && NODE_type(p) == GLUE_NODE && mem(p).b16.s0 == (GLUE_PAR__right_skip + 1)))) p = prev_rightmost(q, p); - if (p != TEX_NULL && p < hi_mem_min && NODE_type(p) == MARGIN_KERN_NODE && mem[p].b16.s0 == 1) - print_scaled(mem[p + 1].b32.s1); + if (p != TEX_NULL && p < hi_mem_min && NODE_type(p) == MARGIN_KERN_NODE && mem(p).b16.s0 == 1) + print_scaled(mem(p + 1).b32.s1); else print('0'); print_cstr("pt"); @@ -9835,13 +9836,13 @@ conv_toks(void) break; case JOB_NAME_CODE: - print_file_name(job_name, 0, 0); + print_file_name(job_name(), 0, 0); break; } - selector = old_setting; - mem[GARBAGE].b32.s1 = str_toks_cat(b, cat); - begin_token_list(mem[TEMP_HEAD].b32.s1, INSERTED); + set_selector(old_setting); + mem_ptr(GARBAGE)->b32.s1 = str_toks_cat(b, cat); + begin_token_list(mem(TEMP_HEAD).b32.s1, INSERTED); } @@ -9859,7 +9860,7 @@ int32_t scan_toks(bool macro_def, bool xpand) scanner_status = ABSORBING; warning_index = cur_cs; def_ref = get_avail(); - mem[def_ref].b32.s0 = TEX_NULL; + mem_ptr(def_ref)->b32.s0 = TEX_NULL; p = def_ref; hash_brace = 0; t = ZERO_TOKEN; @@ -9876,14 +9877,14 @@ int32_t scan_toks(bool macro_def, bool xpand) hash_brace = cur_tok; { q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = cur_tok; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = cur_tok; p = q; } { q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = END_MATCH_TOKEN; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = END_MATCH_TOKEN; p = q; } goto done; @@ -9915,16 +9916,16 @@ int32_t scan_toks(bool macro_def, bool xpand) } { q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = cur_tok; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = cur_tok; p = q; } } done1: { q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = END_MATCH_TOKEN; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = END_MATCH_TOKEN; p = q; } if (cur_cmd == RIGHT_BRACE) { /*494: */ @@ -9951,7 +9952,7 @@ int32_t scan_toks(bool macro_def, bool xpand) get_next(); if (cur_cmd >= CALL) { - if (mem[mem[cur_chr].b32.s1].b32.s0 == PROTECTED_TOKEN) { + if (mem(mem(cur_chr).b32.s1).b32.s0 == PROTECTED_TOKEN) { cur_cmd = RELAX; cur_chr = NO_EXPAND_FLAG; } @@ -9963,8 +9964,8 @@ int32_t scan_toks(bool macro_def, bool xpand) else { q = the_toks(); - if (mem[TEMP_HEAD].b32.s1 != TEX_NULL) { - mem[p].b32.s1 = mem[TEMP_HEAD].b32.s1; + if (mem(TEMP_HEAD).b32.s1 != TEX_NULL) { + mem_ptr(p)->b32.s1 = mem(TEMP_HEAD).b32.s1; p = q; } } @@ -10012,8 +10013,8 @@ int32_t scan_toks(bool macro_def, bool xpand) } { q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = cur_tok; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = cur_tok; p = q; } } @@ -10021,8 +10022,8 @@ int32_t scan_toks(bool macro_def, bool xpand) scanner_status = NORMAL; if (hash_brace != 0) { q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = hash_brace; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = hash_brace; p = q; } return p; @@ -10040,12 +10041,12 @@ read_toks(int32_t n, int32_t r, int32_t j) scanner_status = DEFINING; warning_index = r; def_ref = get_avail(); - mem[def_ref].b32.s0 = TEX_NULL; + mem_ptr(def_ref)->b32.s0 = TEX_NULL; p = def_ref; q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = END_MATCH_TOKEN; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = END_MATCH_TOKEN; p = q; if (n < 0 || n > 15) @@ -10058,7 +10059,7 @@ read_toks(int32_t n, int32_t r, int32_t j) do { /*502:*/ begin_file_reading(); - cur_input.name = m + 1; + cur_input_ptr()->name = m + 1; if (read_open[m] == CLOSED) { /*503:*/ _tt_abort ("terminal input forbidden"); @@ -10081,35 +10082,35 @@ read_toks(int32_t n, int32_t r, int32_t j) help_ptr = 1; help_line[0] = "This \\read has unbalanced braces."; align_state = 1000000L; - cur_input.limit = 0; + cur_input_ptr()->limit = 0; error(); } } } - cur_input.limit = last; + cur_input_ptr()->limit = last; if (INTPAR(end_line_char) < 0 || INTPAR(end_line_char) > 255) - cur_input.limit--; + cur_input_ptr()->limit--; else - buffer[cur_input.limit] = INTPAR(end_line_char); + set_buffer(cur_input().limit, INTPAR(end_line_char)); - first = cur_input.limit + 1; - cur_input.loc = cur_input.start; - cur_input.state = NEW_LINE; + first = cur_input().limit + 1; + cur_input_ptr()->loc = cur_input().start; + cur_input_ptr()->state = NEW_LINE; if (j == 1) { - while (cur_input.loc <= cur_input.limit) { - cur_chr = buffer[cur_input.loc]; - cur_input.loc++; + while (cur_input().loc <= cur_input().limit) { + cur_chr = buffer(cur_input().loc); + cur_input_ptr()->loc++; if (cur_chr == ' ' ) cur_tok = SPACE_TOKEN; else cur_tok = cur_chr + OTHER_TOKEN; q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = cur_tok; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = cur_tok; p = q; } goto done; @@ -10129,8 +10130,8 @@ read_toks(int32_t n, int32_t r, int32_t j) } q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = cur_tok; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = cur_tok; p = q; } @@ -10152,7 +10153,7 @@ void pass_text(void) save_scanner_status = scanner_status; scanner_status = SKIPPING; l = 0; - skip_line = line; + skip_line = line(); while (true) { @@ -10183,8 +10184,8 @@ void change_if_limit(small_number l, int32_t p) if (q == TEX_NULL) confusion("if"); - if (mem[q].b32.s1 == p) { - mem[q].b16.s1 = l; + if (mem(q).b32.s1 == p) { + mem_ptr(q)->b16.s1 = l; return; } q = LLIST_link(q); @@ -10212,14 +10213,14 @@ conditional(void) } p = get_node(IF_NODE_SIZE); - mem[p].b32.s1 = cond_ptr; - mem[p].b16.s1 = if_limit; - mem[p].b16.s0 = cur_if; - mem[p + 1].b32.s1 = if_line; + mem_ptr(p)->b32.s1 = cond_ptr; + mem_ptr(p)->b16.s1 = if_limit; + mem_ptr(p)->b16.s0 = cur_if; + mem_ptr(p + 1)->b32.s1 = if_line; cond_ptr = p; cur_if = cur_chr; if_limit = IF_CODE; - if_line = line; + if_line = line(); save_cond_ptr = cond_ptr; is_unless = (cur_chr >= UNLESS_CODE); @@ -10341,7 +10342,7 @@ conditional(void) if (cur_ptr == TEX_NULL) p = TEX_NULL; else - p = mem[cur_ptr + 1].b32.s1; + p = mem(cur_ptr + 1).b32.s1; } if (this_if == IF_VOID_CODE) @@ -10368,13 +10369,13 @@ conditional(void) } else if (cur_cmd < CALL) { b = (cur_chr == q); } else { /*527:*/ - p = mem[cur_chr].b32.s1; - q = mem[eqtb[n].b32.s1].b32.s1; + p = mem(cur_chr).b32.s1; + q = mem(eqtb_ptr(n)->b32.s1).b32.s1; if (p == q) { b = true; } else { while (p != TEX_NULL && q != TEX_NULL) { - if (mem[p].b32.s0 != mem[q].b32.s0) { + if (mem(p).b32.s0 != mem(q).b32.s0) { p = TEX_NULL; } else { p = LLIST_link(p); @@ -10423,8 +10424,8 @@ conditional(void) get_x_token(); if (cur_cs == 0) { q = get_avail(); - mem[p].b32.s1 = q; - mem[q].b32.s0 = cur_tok; + mem_ptr(p)->b32.s1 = q; + mem_ptr(q)->b32.s0 = cur_tok; p = q; } } while (cur_cs == 0); @@ -10442,7 +10443,7 @@ conditional(void) } m = first; - p = mem[n].b32.s1; + p = mem(n).b32.s1; while (p != TEX_NULL) { if (m >= max_buf_stack) { @@ -10451,7 +10452,7 @@ conditional(void) overflow("buffer size", buf_size); } - buffer[m] = mem[p].b32.s0 % MAX_CHAR_VAL; + set_buffer(m, mem(p).b32.s0 % MAX_CHAR_VAL); m++; p = LLIST_link(p); } @@ -10459,12 +10460,12 @@ conditional(void) if (m == first) cur_cs = NULL_CS; else if (m == first + 1) - cur_cs = SINGLE_BASE + buffer[first]; + cur_cs = SINGLE_BASE + buffer(first); else cur_cs = id_lookup(first, m - first); /*:1556*/ flush_list(n); - b = (eqtb[cur_cs].b16.s1 != UNDEFINED_CS); + b = (eqtb_ptr(cur_cs)->b16.s1 != UNDEFINED_CS); is_in_csname = e; break; @@ -10510,13 +10511,13 @@ conditional(void) else goto common_ending; } else if (cur_chr == FI_CODE) { /*515:*/ - if (if_stack[in_open] == cond_ptr) + if (if_stack[in_open()] == cond_ptr) if_warning(); p = cond_ptr; - if_line = mem[p + 1].b32.s1; - cur_if = mem[p].b16.s0; - if_limit = mem[p].b16.s1; - cond_ptr = mem[p].b32.s1; + if_line = mem(p + 1).b32.s1; + cur_if = mem(p).b16.s0; + if_limit = mem(p).b16.s1; + cond_ptr = mem(p).b32.s1; free_node(p, IF_NODE_SIZE); } } @@ -10532,11 +10533,11 @@ conditional(void) if (cur_cs < HASH_BASE) m = prim_lookup(cur_cs - SINGLE_BASE); else - m = prim_lookup(hash[cur_cs].s1); + m = prim_lookup(hash(cur_cs).s1); b = (cur_cmd != UNDEFINED_CS && m != UNDEFINED_PRIMITIVE - && cur_cmd == eqtb[PRIM_EQTB_BASE + m].b16.s1 - && cur_chr == eqtb[PRIM_EQTB_BASE + m].b32.s1); + && cur_cmd == eqtb_ptr(PRIM_EQTB_BASE + m)->b16.s1 + && cur_chr == eqtb_ptr(PRIM_EQTB_BASE + m)->b32.s1); break; } @@ -10574,209 +10575,32 @@ conditional(void) help_line[0] = "I'm ignoring this; it doesn't match any \\if."; error(); } else if (cur_chr == FI_CODE) { /*515:*/ - if (if_stack[in_open] == cond_ptr) + if (if_stack[in_open()] == cond_ptr) if_warning(); p = cond_ptr; - if_line = mem[p + 1].b32.s1; - cur_if = mem[p].b16.s0; - if_limit = mem[p].b16.s1; - cond_ptr = mem[p].b32.s1; + if_line = mem(p + 1).b32.s1; + cur_if = mem(p).b16.s0; + if_limit = mem(p).b16.s1; + cond_ptr = mem(p).b32.s1; free_node(p, IF_NODE_SIZE); } } common_ending: if (cur_chr == FI_CODE) { /*515:*/ - if (if_stack[in_open] == cond_ptr) + if (if_stack[in_open()] == cond_ptr) if_warning(); p = cond_ptr; - if_line = mem[p + 1].b32.s1; - cur_if = mem[p].b16.s0; - if_limit = mem[p].b16.s1; - cond_ptr = mem[p].b32.s1; + if_line = mem(p + 1).b32.s1; + cur_if = mem(p).b16.s0; + if_limit = mem(p).b16.s1; + cond_ptr = mem(p).b32.s1; free_node(p, IF_NODE_SIZE); } else { if_limit = FI_CODE; } } - -void -begin_name(void) -{ - area_delimiter = 0; - ext_delimiter = 0; - quoted_filename = false; - file_name_quote_char = 0; -} - - -bool -more_name(UTF16_code c) -{ - if (stop_at_space && file_name_quote_char == 0 && c == ' ' ) - return false; - - if (stop_at_space && file_name_quote_char != 0 && c == file_name_quote_char) { - file_name_quote_char = 0; - return true; - } - - if (stop_at_space && file_name_quote_char == 0 && (c == '"' || c == '\'' )) { - file_name_quote_char = c; - quoted_filename = true; - return true; - } - - if (pool_ptr + 1 > pool_size) - overflow("pool size", pool_size - init_pool_ptr); - - str_pool[pool_ptr++] = c; - - if (IS_DIR_SEP(c)) { - area_delimiter = cur_length(); - ext_delimiter = 0; - } else if (c == '.' ) { - ext_delimiter = cur_length(); - } - - return true; -} - - -void -end_name(void) -{ - str_number temp_str; - pool_pointer j; - - if (str_ptr + 3 > max_strings) - overflow("number of strings", max_strings - init_str_ptr); - - /* area_delimiter is the length from the start of the filename to the - * directory seperator "/", which we use to construct the stringpool - * string `cur_area`. If there was already a string in the stringpool for - * the area, reuse it. */ - - if (area_delimiter == 0) { - cur_area = EMPTY_STRING; - } else { - cur_area = str_ptr; - str_start[(str_ptr + 1) - 65536L] = str_start[str_ptr - TOO_BIG_CHAR] + area_delimiter; - str_ptr++; - temp_str = search_string(cur_area); - - if (temp_str > 0) { - cur_area = temp_str; - str_ptr--; - - for (j = str_start[(str_ptr + 1) - 65536L]; j <= pool_ptr - 1; j++) - str_pool[j - area_delimiter] = str_pool[j]; - - pool_ptr = pool_ptr - area_delimiter; - } - } - - /* ext_delimiter is the length from the start of the filename to the - * extension '.' delimiter, which we use to construct the stringpool - * strings `cur_ext` and `cur_name`. */ - - if (ext_delimiter == 0) { - cur_ext = EMPTY_STRING; - cur_name = slow_make_string(); - } else { - cur_name = str_ptr; - str_start[(str_ptr + 1) - 65536L] = str_start[str_ptr - TOO_BIG_CHAR] + ext_delimiter - area_delimiter - 1; - str_ptr++; - - cur_ext = make_string(); - str_ptr--; - temp_str = search_string(cur_name); - - if (temp_str > 0) { - cur_name = temp_str; - str_ptr--; - - for (j = str_start[(str_ptr + 1) - 65536L]; j <= pool_ptr - 1; j++) - str_pool[j - ext_delimiter + area_delimiter + 1] = str_pool[j]; - - pool_ptr = pool_ptr - ext_delimiter + area_delimiter + 1; - } - - cur_ext = slow_make_string(); - } -} - - -void -pack_file_name(str_number n, str_number a, str_number e) -{ - // Note that we populate the buffer in an order different than how the - // arguments are passed to this function! - char* work_buffer = xmalloc_array(UTF8_code, (length(a) + length(n) + length(e)) * 3 + 1); - work_buffer[0] = '\0'; - - char* a_utf8 = gettexstring(a); - strcat(work_buffer, a_utf8); - free(a_utf8); - - char* n_utf8 = gettexstring(n); - strcat(work_buffer, n_utf8); - free(n_utf8); - - char* e_utf8 = gettexstring(e); - strcat(work_buffer, e_utf8); - free(e_utf8); - - name_length = strlen(work_buffer); - - free(name_of_file); - name_of_file = xmalloc_array(char, name_length + 1); - strcpy(name_of_file, work_buffer); - free(work_buffer); -} - - -str_number -make_name_string(void) -{ - int32_t k; - pool_pointer save_area_delimiter, save_ext_delimiter; - bool save_name_in_progress, save_stop_at_space; - - if (pool_ptr + name_length > pool_size || str_ptr == max_strings || cur_length() > 0) - return '?'; - - make_utf16_name(); - - for (k = 0; k < name_length16; k++) - str_pool[pool_ptr++] = name_of_file16[k]; - - - str_number Result = make_string(); - - save_area_delimiter = area_delimiter; - save_ext_delimiter = ext_delimiter; - save_name_in_progress = name_in_progress; - save_stop_at_space = stop_at_space; - name_in_progress = true; - begin_name(); - stop_at_space = false; - k = 0; - - while (k < name_length16 && more_name(name_of_file16[k])) - k++; - - stop_at_space = save_stop_at_space; - end_name(); - name_in_progress = save_name_in_progress; - area_delimiter = save_area_delimiter; - ext_delimiter = save_ext_delimiter; - - return Result; -} - - static void scan_file_name_braced(void) { @@ -10792,23 +10616,23 @@ scan_file_name_braced(void) cur_cs = warning_index; scan_toks(false, true); - old_setting = selector; - selector = SELECTOR_NEW_STRING; - show_token_list(mem[def_ref].b32.s1, TEX_NULL, pool_size - pool_ptr); - selector = old_setting; + old_setting = selector(); + set_selector(SELECTOR_NEW_STRING); + show_token_list(mem(def_ref).b32.s1, TEX_NULL, pool_size() - pool_ptr()); + set_selector(old_setting); s = make_string(); delete_token_ref(def_ref); def_ref = save_def_ref; cur_cs = save_cur_cs; scanner_status = save_scanner_status; - save_stop_at_space = stop_at_space; + save_stop_at_space = stop_at_space(); begin_name(); - for (i = str_start[s - TOO_BIG_CHAR]; i < str_start[s + 1 - TOO_BIG_CHAR]; i++) - more_name(str_pool[i]); + for (i = str_start(s - TOO_BIG_CHAR); i < str_start(s + 1 - TOO_BIG_CHAR); i++) + more_name(str_pool(i)); - stop_at_space = save_stop_at_space; + set_stop_at_space(save_stop_at_space); } @@ -10828,7 +10652,7 @@ scan_file_name(void) if (cur_cmd == LEFT_BRACE) { scan_file_name_braced(); } else { - name_in_progress = true; + set_name_in_progress(true); begin_name(); do { @@ -10849,59 +10673,10 @@ scan_file_name(void) } end_name(); - name_in_progress = false; + set_name_in_progress(false); warning_index = save_warning_index; } - -void pack_job_name(const char* s) -{ - cur_area = EMPTY_STRING; - cur_ext = maketexstring(s); - cur_name = job_name; - pack_file_name(cur_name, cur_area, cur_ext); -} - - -void -open_log_file(void) -{ - unsigned char old_setting; - int32_t k; - int32_t l; - - old_setting = selector; - if (job_name == 0) - job_name = maketexstring("texput"); - - pack_job_name(".log"); - - log_file = ttstub_output_open (name_of_file, 0); - if (log_file == INVALID_HANDLE) - _tt_abort ("cannot open log file output \"%s\"", name_of_file); - - texmf_log_name = make_name_string(); - selector = SELECTOR_LOG_ONLY; - log_opened = true; - - input_stack[input_ptr] = cur_input; - - /* Here we catch the log file up with anything that has already been - * printed. The eqtb reference is end_line_char. */ - - print_nl_cstr("**"); - l = input_stack[0].limit; - if (buffer[l] == INTPAR(end_line_char)) - l--; - - for (k = 1; k <= l; k++) - print(buffer[k]); - - print_ln(); - selector = old_setting + 2; -} - - void start_input(const char *primary_input_name) { @@ -10917,14 +10692,14 @@ start_input(const char *primary_input_name) format = TTBC_FILE_FORMAT_TECTONIC_PRIMARY; - name_in_progress = true; + set_name_in_progress(true); begin_name(); - stop_at_space = false; + set_stop_at_space(false); const unsigned char *cp = (const unsigned char *) primary_input_name; - if (pool_ptr + strlen(primary_input_name) * 2 >= pool_size) - _tt_abort ("string pool overflow [%i bytes]", (int) pool_size); + if (pool_ptr() + strlen(primary_input_name) * 2 >= pool_size()) + _tt_abort ("string pool overflow [%i bytes]", (int) pool_size()); UInt32 rval; while ((rval = *(cp++)) != 0) { @@ -10940,23 +10715,26 @@ start_input(const char *primary_input_name) rval -= offsetsFromUTF8[extraBytes]; if (rval > 0xffff) { rval -= 0x10000; - str_pool[pool_ptr++] = 0xd800 + rval / 0x0400; - str_pool[pool_ptr++] = 0xdc00 + rval % 0x0400; + set_str_pool(pool_ptr(), 0xd800 + rval / 0x0400); + set_pool_ptr(pool_ptr()+1); + set_str_pool(pool_ptr(), 0xdc00 + rval % 0x0400); + set_pool_ptr(pool_ptr()+1); } else { - str_pool[pool_ptr++] = rval; + set_str_pool(pool_ptr(), rval); + set_pool_ptr(pool_ptr()+1); } if (IS_DIR_SEP(rval)) { - area_delimiter = cur_length(); - ext_delimiter = 0; + set_area_delimiter(cur_length()); + set_ext_delimiter(0); } else if (rval == '.' ) { - ext_delimiter = cur_length(); + set_ext_delimiter(cur_length()); } } - stop_at_space = true; + set_stop_at_space(true); end_name(); - name_in_progress = false; + set_name_in_progress(false); } else { /* Scan in the file name from the current token stream. The file name to * input is saved as the stringpool strings `cur_{name,area,ext}` and the @@ -10964,66 +10742,66 @@ start_input(const char *primary_input_name) scan_file_name(); } - pack_file_name(cur_name, cur_area, cur_ext); + pack_file_name(cur_name(), cur_area(), cur_ext()); /* Open up the new file to be read. The name of the file to be read comes * from `name_of_file`. */ begin_file_reading(); - if (!u_open_in(&input_file[cur_input.index], format, "rb", + if (!u_open_in(&input_file[cur_input().index], format, "rb", INTPAR(xetex_default_input_mode), INTPAR(xetex_default_input_encoding))) - _tt_abort ("failed to open input file \"%s\"", name_of_file); + _tt_abort ("failed to open input file \"%s\"", name_of_file()); /* Now re-encode `name_of_file` into the UTF-16 variable `name_of_file16`, * and use that to recompute `cur_{name,area,ext}`. */ make_utf16_name(); - name_in_progress = true; + set_name_in_progress(true); begin_name(); - stop_at_space = false; + set_stop_at_space(false); int k = 0; - while (k < name_length16 && more_name(name_of_file16[k])) + while (k < name_length16() && more_name(name_of_file16()[k])) k++; - stop_at_space = true; + set_stop_at_space(true); end_name(); - name_in_progress = false; + set_name_in_progress(false); /* Now generate a stringpool string corresponding to the full path of the * input file. This calls make_utf16_name() again and reruns through the * {begin,more,end}_name() trifecta to re-re-compute * `cur_{name,area,ext}`. */ - cur_input.name = make_name_string(); - source_filename_stack[in_open] = cur_input.name; + cur_input_ptr()->name = make_name_string(); + source_filename_stack[in_open()] = cur_input().name; /* *This* variant is a TeX string made out of `name_of_input_file`. */ - full_source_filename_stack[in_open] = maketexstring(name_of_input_file); - if (cur_input.name == str_ptr - 1) { - temp_str = search_string(cur_input.name); + set_full_source_filename_stack(in_open(), maketexstring(name_of_input_file)); + if (cur_input().name == str_ptr() - 1) { + temp_str = search_string(cur_input().name); if (temp_str > 0) { - cur_input.name = temp_str; - str_ptr--; - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + cur_input_ptr()->name = temp_str; + set_str_ptr(str_ptr()-1); + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); } } /* Finally we start really doing stuff with the newly-opened file. */ - if (job_name == 0) { - job_name = cur_name; + if (job_name() == 0) { + set_job_name(cur_name()); open_log_file(); } - if (term_offset + length(full_source_filename_stack[in_open]) > max_print_line - 2) + if (term_offset() + length(full_source_filename_stack(in_open())) > max_print_line - 2) print_ln(); - else if (term_offset > 0 || file_offset > 0) + else if (term_offset() > 0 || file_offset() > 0) print_char(' '); print_char('('); open_parens++; - print(full_source_filename_stack[in_open]); - ttstub_output_flush(rust_stdout); + print(full_source_filename_stack(in_open())); + ttstub_output_flush(rust_stdout()); if (INTPAR(tracing_stack_levels) > 0) { int32_t v; @@ -11032,7 +10810,7 @@ start_input(const char *primary_input_name) diagnostic_begin_capture_warning_here(); print_ln(); print_char('~'); - v = input_ptr - 1; + v = input_ptr() - 1; if (v < INTPAR(tracing_stack_levels)) { while (v > 0) { print_char('.'); @@ -11042,28 +10820,28 @@ start_input(const char *primary_input_name) print_char('~'); } print_cstr("INPUT "); - print(cur_name); - print(cur_ext); + print(cur_name()); + print(cur_ext()); print_ln(); capture_to_diagnostic(NULL); end_diagnostic(false); } - cur_input.state = NEW_LINE; + cur_input_ptr()->state = NEW_LINE; synctex_start_input(); - line = 1; - input_line(input_file[cur_input.index]); - cur_input.limit = last; + set_line(1); + input_line(input_file[cur_input().index]); + cur_input_ptr()->limit = last; if (INTPAR(end_line_char) < 0 || INTPAR(end_line_char) > 255) - cur_input.limit--; + cur_input_ptr()->limit--; else - buffer[cur_input.limit] = INTPAR(end_line_char); + set_buffer(cur_input().limit, INTPAR(end_line_char)); - first = cur_input.limit + 1; - cur_input.loc = cur_input.start; + first = cur_input().limit + 1; + cur_input_ptr()->loc = cur_input().start; } @@ -11088,7 +10866,7 @@ void char_warning(internal_font_number f, int32_t c) INTPAR(tracing_online) = 1; if (INTPAR(tracing_lost_chars) > 2) { - if (file_line_error_style_p) + if (file_line_error_style_p()) print_file_line(); else print_nl_cstr("! "); @@ -11134,19 +10912,19 @@ void char_warning(internal_font_number f, int32_t c) { char *fn = gettexstring(font_name[f]); char *chr = NULL; - selector_t prev_selector = selector; + selector_t prev_selector = selector(); int s; - selector = SELECTOR_NEW_STRING; + set_selector(SELECTOR_NEW_STRING); if (c < 0x10000) print(c); else print_char(c); - selector = prev_selector; + set_selector(prev_selector); s = make_string(); chr = gettexstring(s); - str_ptr--; /* this is the "flush_string" macro which discards the most recent string */ - pool_ptr = str_start[str_ptr - 0x10000]; + set_str_ptr(str_ptr()-1); /* this is the "flush_string" macro which discards the most recent string */ + set_pool_ptr(str_start(str_ptr() - 0x10000)); ttstub_issue_warning("could not represent character \"%s\" (0x%" PRIx32 ") in font \"%s\"", chr, c, fn); @@ -11194,27 +10972,27 @@ new_native_character(internal_font_number f, UnicodeScalar c) if (font_mapping[f] != NULL) { if (c > 65535L) { - if (pool_ptr + 2 > pool_size) - overflow("pool size", pool_size - init_pool_ptr); + if (pool_ptr() + 2 > pool_size()) + overflow("pool size", pool_size() - init_pool_ptr); - str_pool[pool_ptr] = (c - 65536L) / 1024 + 0xD800; - pool_ptr++; - str_pool[pool_ptr] = (c - 65536L) % 1024 + 0xDC00; - pool_ptr++; + set_str_pool(pool_ptr(), (c - 65536L) / 1024 + 0xD800); + set_pool_ptr(pool_ptr()+1); + set_str_pool(pool_ptr(), (c - 65536L) % 1024 + 0xDC00); + set_pool_ptr(pool_ptr()+1); } else { - if (pool_ptr + 1 > pool_size) - overflow("pool size", pool_size - init_pool_ptr); + if (pool_ptr() + 1 > pool_size()) + overflow("pool size", pool_size() - init_pool_ptr); - str_pool[pool_ptr] = c; - pool_ptr++; + set_str_pool(pool_ptr(), c); + set_pool_ptr(pool_ptr()+1); } len = apply_mapping( font_mapping[f], - &str_pool[str_start[str_ptr - TOO_BIG_CHAR]], + str_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)), cur_length() ); - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); i = 0; @@ -11278,8 +11056,8 @@ void font_feature_warning(const void *featureNameP, int32_t featLen, const void print_cstr("feature `"); print_utf8_str(featureNameP, featLen); print_cstr("' in font `"); - for (int32_t i = 0; name_of_file[i] != 0; i++) - print_raw_char(name_of_file[i], true); + for (int32_t i = 0; name_of_file()[i] != 0; i++) + print_raw_char(name_of_file()[i], true); print_cstr("'."); capture_to_diagnostic(NULL); end_diagnostic(false); @@ -11296,8 +11074,8 @@ void font_mapping_warning(const void *mappingNameP, int32_t mappingNameLen, int3 print_utf8_str(mappingNameP, mappingNameLen); print_cstr("' for font `"); - for (int32_t i = 0; name_of_file[i] != 0; i++) - print_raw_char(name_of_file[i], true); + for (int32_t i = 0; name_of_file()[i] != 0; i++) + print_raw_char(name_of_file()[i], true); switch (warningType) { case 1: @@ -11323,8 +11101,8 @@ void graphite_warning(void) diagnostic_begin_capture_warning_here(); print_nl_cstr("Font `"); - for (int32_t i = 0; name_of_file[i] != 0; i++) - print_raw_char(name_of_file[i], true); + for (int32_t i = 0; name_of_file()[i] != 0; i++) + print_raw_char(name_of_file()[i], true); print_cstr("' does not support Graphite. Trying OpenType layout instead."); capture_to_diagnostic(NULL); @@ -11343,7 +11121,7 @@ load_native_font(int32_t u, str_number nom, str_number aire, scaled_t s) internal_font_number f; str_number full_name; - font_engine = find_native_font(name_of_file, s); + font_engine = find_native_font(name_of_file(), s); if (!font_engine) return FONT_BASE; @@ -11354,11 +11132,13 @@ load_native_font(int32_t u, str_number nom, str_number aire, scaled_t s) else actual_size = get_loaded_font_design_size(); - if (pool_ptr + name_length > pool_size) - overflow("pool size", pool_size - init_pool_ptr); + if (pool_ptr() + name_length() > pool_size()) + overflow("pool size", pool_size() - init_pool_ptr); - for (k = 0; k < name_length; k++) - str_pool[pool_ptr++] = name_of_file[k]; + for (k = 0; k < name_length(); k++) { + set_str_pool(pool_ptr(), name_of_file()[k]); + set_pool_ptr(pool_ptr()+1); + } full_name = make_string(); @@ -11366,8 +11146,8 @@ load_native_font(int32_t u, str_number nom, str_number aire, scaled_t s) if (font_area[f] == native_font_type_flag && str_eq_str(font_name[f], full_name) && font_size[f] == actual_size) { release_font_engine(font_engine, native_font_type_flag); - str_ptr--; - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + set_str_ptr(str_ptr()-1); + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); return f; } @@ -11382,11 +11162,11 @@ load_native_font(int32_t u, str_number nom, str_number aire, scaled_t s) error_here_with_diagnostic("Font "); sprint_cs(u); print_char('='); - if (file_name_quote_char != 0) - print_char(file_name_quote_char); - print_file_name(nom, aire, cur_ext); - if (file_name_quote_char != 0) - print_char(file_name_quote_char); + if (file_name_quote_char() != 0) + print_char(file_name_quote_char()); + print_file_name(nom, aire, cur_ext()); + if (file_name_quote_char() != 0) + print_char(file_name_quote_char()); if (s >= 0) { print_cstr(" at "); print_scaled(s); @@ -11474,7 +11254,7 @@ void do_locale_linebreaks(int32_t s, int32_t len) bool use_penalty, use_skip; if ((INTPAR(xetex_linebreak_locale) == 0) || (len == 1)) { - mem[cur_list.tail].b32.s1 = new_native_word_node(main_f, len); + mem_ptr(cur_list.tail)->b32.s1 = new_native_word_node(main_f, len); cur_list.tail = LLIST_link(cur_list.tail); { register int32_t for_end; @@ -11498,15 +11278,15 @@ void do_locale_linebreaks(int32_t s, int32_t len) if (offs > 0) { if (prevOffs != 0) { if (use_penalty) { - mem[cur_list.tail].b32.s1 = new_penalty(INTPAR(xetex_linebreak_penalty)); + mem_ptr(cur_list.tail)->b32.s1 = new_penalty(INTPAR(xetex_linebreak_penalty)); cur_list.tail = LLIST_link(cur_list.tail); } if (use_skip) { - mem[cur_list.tail].b32.s1 = new_param_glue(GLUE_PAR__xetex_linebreak_skip); + mem_ptr(cur_list.tail)->b32.s1 = new_param_glue(GLUE_PAR__xetex_linebreak_skip); cur_list.tail = LLIST_link(cur_list.tail); } } - mem[cur_list.tail].b32.s1 = new_native_word_node(main_f, offs - prevOffs); + mem_ptr(cur_list.tail)->b32.s1 = new_native_word_node(main_f, offs - prevOffs); cur_list.tail = LLIST_link(cur_list.tail); { register int32_t for_end; @@ -11528,12 +11308,12 @@ void bad_utf8_warning(void) begin_diagnostic(); diagnostic_begin_capture_warning_here(); print_nl_cstr("Invalid UTF-8 byte or sequence"); - if (cur_input.name == 0) + if (cur_input().name == 0) print_cstr(" in terminal input"); else { print_cstr(" at line "); - print_int(line); + print_int(line()); } print_cstr(" replaced by U+FFFD."); capture_to_diagnostic(NULL); @@ -11543,7 +11323,7 @@ void bad_utf8_warning(void) int32_t get_input_normalization_state(void) { - if (eqtb == NULL) + if (eqtb_ptr(0) == NULL) return 0; else return INTPAR(xetex_input_normalization); @@ -11577,13 +11357,13 @@ read_font_info(int32_t u, str_number nom, str_number aire, scaled_t s) g = FONT_BASE; file_opened = false; - pack_file_name(nom, aire, cur_ext); + pack_file_name(nom, aire, cur_ext()); if (INTPAR(xetex_tracing_fonts) > 0) { begin_diagnostic(); diagnostic_begin_capture_warning_here(); print_nl_cstr("Requested font \""); - print_c_string(name_of_file); + print_c_string(name_of_file()); print('"'); if (s < 0) { print_cstr(" scaled "); @@ -11597,7 +11377,7 @@ read_font_info(int32_t u, str_number nom, str_number aire, scaled_t s) end_diagnostic(false); } - if (quoted_filename) { + if (quoted_filename()) { g = load_native_font(u, nom, aire, s); if (g != FONT_BASE) goto done; @@ -11612,7 +11392,7 @@ read_font_info(int32_t u, str_number nom, str_number aire, scaled_t s) tfm_file = tt_xetex_open_input (TTBC_FILE_FORMAT_TFM); if (tfm_file == INVALID_HANDLE) { - if (!quoted_filename) { + if (!quoted_filename()) { g = load_native_font(u, nom, aire, s); if (g != FONT_BASE) goto done; @@ -11965,11 +11745,11 @@ read_font_info(int32_t u, str_number nom, str_number aire, scaled_t s) error_here_with_diagnostic("Font "); sprint_cs(u); print_char('='); - if (file_name_quote_char != 0) - print_char(file_name_quote_char); - print_file_name(nom, aire, cur_ext); - if (file_name_quote_char != 0) - print_char(file_name_quote_char); + if (file_name_quote_char() != 0) + print_char(file_name_quote_char()); + print_file_name(nom, aire, cur_ext()); + if (file_name_quote_char() != 0) + print_char(file_name_quote_char()); if (s >= 0) { print_cstr(" at "); print_scaled(s); @@ -12010,7 +11790,7 @@ read_font_info(int32_t u, str_number nom, str_number aire, scaled_t s) if (g == FONT_BASE) print_c_string("font not found, using \"nullfont\""); else - print_c_string(name_of_file); + print_c_string(name_of_file()); capture_to_diagnostic(NULL); end_diagnostic(false); @@ -12034,8 +11814,8 @@ int32_t new_character(internal_font_number f, UTF16_code c) if ((FONT_CHARACTER_INFO(f, ec).s3 > 0)) { p = get_avail(); - mem[p].b16.s1 = f; - mem[p].b16.s0 = c; + mem_ptr(p)->b16.s1 = f; + mem_ptr(p)->b16.s0 = c; return p; } } @@ -12094,9 +11874,9 @@ scaled_t char_pw(int32_t p, small_number side) } } if ((((p) != TEX_NULL && (!(is_char_node(p))) && (NODE_type(p) == WHATSIT_NODE) - && (mem[p].b16.s0 == GLYPH_NODE)))) { - f = mem[p + 4].b16.s2; - return round_xn_over_d(font_info[QUAD_CODE + param_base[f]].b32.s1, get_cp_code(f, mem[p + 4].b16.s1, side), + && (mem(p).b16.s0 == GLYPH_NODE)))) { + f = mem(p + 4).b16.s2; + return round_xn_over_d(font_info[QUAD_CODE + param_base[f]].b32.s1, get_cp_code(f, mem(p + 4).b16.s1, side), 1000); } if (!(is_char_node(p))) { @@ -12106,7 +11886,7 @@ scaled_t char_pw(int32_t p, small_number side) return 0; } f = CHAR_NODE_font(p); - c = get_cp_code(f, mem[p].b16.s0, side); + c = get_cp_code(f, mem(p).b16.s0, side); switch (side) { case 0: last_leftmost_char = p; @@ -12125,8 +11905,8 @@ int32_t new_margin_kern(scaled_t w, int32_t p, small_number side) int32_t k; k = get_node(MARGIN_KERN_NODE_SIZE); NODE_type(k) = MARGIN_KERN_NODE; - mem[k].b16.s0 = side; - mem[k + 1].b32.s1 = w; + mem_ptr(k)->b16.s0 = side; + mem_ptr(k + 1)->b32.s1 = w; return k; } @@ -12146,10 +11926,10 @@ int32_t hpack(int32_t p, scaled_t w, small_number m) last_badness = 0; r = get_node(BOX_NODE_SIZE); NODE_type(r) = HLIST_NODE; - mem[r].b16.s0 = 0; - mem[r + 4].b32.s1 = 0; + mem_ptr(r)->b16.s0 = 0; + mem_ptr(r + 4)->b32.s1 = 0; q = r + 5; - mem[q].b32.s1 = p; + mem_ptr(q)->b32.s1 = p; h = 0; d = 0; x = 0; @@ -12163,8 +11943,8 @@ int32_t hpack(int32_t p, scaled_t w, small_number m) total_shrink[FILLL] = 0 /*:673 */ ; if (INTPAR(texxet) > 0) { /*1497: */ temp_ptr = get_avail(); - mem[temp_ptr].b32.s0 = BEFORE; - mem[temp_ptr].b32.s1 = LR_ptr; + mem_ptr(temp_ptr)->b32.s0 = BEFORE; + mem_ptr(temp_ptr)->b32.s1 = LR_ptr; LR_ptr = temp_ptr; } while (p != TEX_NULL) { /*674: */ @@ -12185,117 +11965,117 @@ int32_t hpack(int32_t p, scaled_t w, small_number m) p = LLIST_link(p); } if (p != TEX_NULL) { - switch (mem[p].b16.s1) { + switch (mem(p).b16.s1) { case 0: case 1: case 2: case 13: { - x = x + mem[p + 1].b32.s1; + x = x + mem(p + 1).b32.s1; if (NODE_type(p) >= RULE_NODE) s = 0; else - s = mem[p + 4].b32.s1; - if (mem[p + 3].b32.s1 - s > h) - h = mem[p + 3].b32.s1 - s; - if (mem[p + 2].b32.s1 + s > d) - d = mem[p + 2].b32.s1 + s; + s = mem(p + 4).b32.s1; + if (mem(p + 3).b32.s1 - s > h) + h = mem(p + 3).b32.s1 - s; + if (mem(p + 2).b32.s1 + s > d) + d = mem(p + 2).b32.s1 + s; } break; case 3: case 4: case 5: if ((adjust_tail != TEX_NULL) || (pre_adjust_tail != TEX_NULL)) { /*680: */ - while (mem[q].b32.s1 != p) + while (mem(q).b32.s1 != p) q = LLIST_link(q); if (NODE_type(p) == ADJUST_NODE) { - if (mem[p].b16.s0 != 0) { + if (mem(p).b16.s0 != 0) { if (pre_adjust_tail == TEX_NULL) confusion("pre vadjust"); - mem[pre_adjust_tail].b32.s1 = mem[p + 1].b32.s1; - while (mem[pre_adjust_tail].b32.s1 != TEX_NULL) + mem_ptr(pre_adjust_tail)->b32.s1 = mem(p + 1).b32.s1; + while (mem(pre_adjust_tail).b32.s1 != TEX_NULL) pre_adjust_tail = LLIST_link(pre_adjust_tail); } else { if (adjust_tail == TEX_NULL) confusion("pre vadjust"); - mem[adjust_tail].b32.s1 = mem[p + 1].b32.s1; - while (mem[adjust_tail].b32.s1 != TEX_NULL) + mem_ptr(adjust_tail)->b32.s1 = mem(p + 1).b32.s1; + while (mem(adjust_tail).b32.s1 != TEX_NULL) adjust_tail = LLIST_link(adjust_tail); } p = LLIST_link(p); - free_node(mem[q].b32.s1, SMALL_NODE_SIZE); + free_node(mem(q).b32.s1, SMALL_NODE_SIZE); } else { - mem[adjust_tail].b32.s1 = p; + mem_ptr(adjust_tail)->b32.s1 = p; adjust_tail = p; p = LLIST_link(p); } - mem[q].b32.s1 = p; + mem_ptr(q)->b32.s1 = p; p = q; } break; case 8: { - switch (mem[p].b16.s0) { + switch (mem(p).b16.s0) { case 40: case 41: { if ((q != r + 5) && (NODE_type(q) == DISC_NODE)) - k = mem[q].b16.s0; + k = mem(q).b16.s0; else k = 0; - while ((mem[q].b32.s1 != p)) { + while ((mem(q).b32.s1 != p)) { k--; q = LLIST_link(q); if (NODE_type(q) == DISC_NODE) - k = mem[q].b16.s0; + k = mem(q).b16.s0; } - pp = mem[p].b32.s1; + pp = mem(p).b32.s1; restart: if ((k <= 0) && (pp != TEX_NULL) && (!(is_char_node(pp)))) { if ((NODE_type(pp) == WHATSIT_NODE) - && ((mem[pp].b16.s0 == NATIVE_WORD_NODE) - || (mem[pp].b16.s0 == NATIVE_WORD_NODE_AT)) - && (mem[pp + 4].b16.s2 == mem[p + 4].b16.s2)) { + && ((mem(pp).b16.s0 == NATIVE_WORD_NODE) + || (mem(pp).b16.s0 == NATIVE_WORD_NODE_AT)) + && (mem(pp + 4).b16.s2 == mem(p + 4).b16.s2)) { pp = LLIST_link(pp); goto restart; } else if (NODE_type(pp) == DISC_NODE) { - ppp = mem[pp].b32.s1; + ppp = mem(pp).b32.s1; if ((((ppp) != TEX_NULL && (!(is_char_node(ppp))) && (NODE_type(ppp) == WHATSIT_NODE) - && ((mem[ppp].b16.s0 == NATIVE_WORD_NODE) - || (mem[ppp].b16.s0 == NATIVE_WORD_NODE_AT)))) - && (mem[ppp + 4].b16.s2 == mem[p + 4].b16.s2)) { - pp = mem[ppp].b32.s1; + && ((mem(ppp).b16.s0 == NATIVE_WORD_NODE) + || (mem(ppp).b16.s0 == NATIVE_WORD_NODE_AT)))) + && (mem(ppp + 4).b16.s2 == mem(p + 4).b16.s2)) { + pp = mem(ppp).b32.s1; goto restart; } } } - if ((pp != mem[p].b32.s1)) { + if ((pp != mem(p).b32.s1)) { total_chars = 0; - p = mem[q].b32.s1; + p = mem(q).b32.s1; while ((p != pp)) { if (NODE_type(p) == WHATSIT_NODE) - total_chars = total_chars + mem[p + 4].b16.s1; + total_chars = total_chars + mem(p + 4).b16.s1; ppp = p; p = LLIST_link(p); } - p = mem[q].b32.s1; - pp = new_native_word_node(mem[p + 4].b16.s2, total_chars); - mem[pp].b16.s0 = mem[p].b16.s0; - mem[q].b32.s1 = pp; - mem[pp].b32.s1 = mem[ppp].b32.s1; - mem[ppp].b32.s1 = TEX_NULL; + p = mem(q).b32.s1; + pp = new_native_word_node(mem(p + 4).b16.s2, total_chars); + mem_ptr(pp)->b16.s0 = mem(p).b16.s0; + mem_ptr(q)->b32.s1 = pp; + mem_ptr(pp)->b32.s1 = mem(ppp).b32.s1; + mem_ptr(ppp)->b32.s1 = TEX_NULL; total_chars = 0; ppp = p; do { if (NODE_type(ppp) == WHATSIT_NODE) { register int32_t for_end; k = 0; - for_end = mem[ppp + 4].b16.s1 - 1; + for_end = mem(ppp + 4).b16.s1 - 1; if (k <= for_end) do { NATIVE_NODE_text(pp)[total_chars] = NATIVE_NODE_text(ppp)[k]; @@ -12306,25 +12086,25 @@ int32_t hpack(int32_t p, scaled_t w, small_number m) ppp = LLIST_link(ppp); } while (!((ppp == TEX_NULL))); flush_node_list(p); - p = mem[q].b32.s1; + p = mem(q).b32.s1; set_native_metrics(p, (INTPAR(xetex_use_glyph_metrics) > 0)); } - if (mem[p + 3].b32.s1 > h) - h = mem[p + 3].b32.s1; - if (mem[p + 2].b32.s1 > d) - d = mem[p + 2].b32.s1; - x = x + mem[p + 1].b32.s1; + if (mem(p + 3).b32.s1 > h) + h = mem(p + 3).b32.s1; + if (mem(p + 2).b32.s1 > d) + d = mem(p + 2).b32.s1; + x = x + mem(p + 1).b32.s1; } break; case 42: case 43: case 44: { - if (mem[p + 3].b32.s1 > h) - h = mem[p + 3].b32.s1; - if (mem[p + 2].b32.s1 > d) - d = mem[p + 2].b32.s1; - x = x + mem[p + 1].b32.s1; + if (mem(p + 3).b32.s1 > h) + h = mem(p + 3).b32.s1; + if (mem(p + 2).b32.s1 > d) + d = mem(p + 2).b32.s1; + x = x + mem(p + 1).b32.s1; } break; default: @@ -12335,39 +12115,39 @@ int32_t hpack(int32_t p, scaled_t w, small_number m) break; case 10: { - g = mem[p + 1].b32.s0; - x = x + mem[g + 1].b32.s1; - o = mem[g].b16.s1; - total_stretch[o] = total_stretch[o] + mem[g + 2].b32.s1; - o = mem[g].b16.s0; - total_shrink[o] = total_shrink[o] + mem[g + 3].b32.s1; - if (mem[p].b16.s0 >= A_LEADERS) { - g = mem[p + 1].b32.s1; - if (mem[g + 3].b32.s1 > h) - h = mem[g + 3].b32.s1; - if (mem[g + 2].b32.s1 > d) - d = mem[g + 2].b32.s1; + g = mem(p + 1).b32.s0; + x = x + mem(g + 1).b32.s1; + o = mem(g).b16.s1; + total_stretch[o] = total_stretch[o] + mem(g + 2).b32.s1; + o = mem(g).b16.s0; + total_shrink[o] = total_shrink[o] + mem(g + 3).b32.s1; + if (mem(p).b16.s0 >= A_LEADERS) { + g = mem(p + 1).b32.s1; + if (mem(g + 3).b32.s1 > h) + h = mem(g + 3).b32.s1; + if (mem(g + 2).b32.s1 > d) + d = mem(g + 2).b32.s1; } } break; case 11: - x = x + mem[p + 1].b32.s1; + x = x + mem(p + 1).b32.s1; break; case 40: - x = x + mem[p + 1].b32.s1; + x = x + mem(p + 1).b32.s1; break; case 9: { - x = x + mem[p + 1].b32.s1; + x = x + mem(p + 1).b32.s1; if (INTPAR(texxet) > 0) { /*1498: */ - if (odd(mem[p].b16.s0)) { + if (odd(mem(p).b16.s0)) { - if (mem[LR_ptr].b32.s0 == (L_CODE * (mem[p].b16.s0 / L_CODE) + 3)) { + if (mem(LR_ptr).b32.s0 == (L_CODE * (mem(p).b16.s0 / L_CODE) + 3)) { temp_ptr = LR_ptr; - LR_ptr = mem[temp_ptr].b32.s1; + LR_ptr = mem(temp_ptr).b32.s1; { - mem[temp_ptr].b32.s1 = avail; + mem_ptr(temp_ptr)->b32.s1 = avail; avail = temp_ptr; } } else { @@ -12379,16 +12159,16 @@ int32_t hpack(int32_t p, scaled_t w, small_number m) } else { temp_ptr = get_avail(); - mem[temp_ptr].b32.s0 = (L_CODE * (mem[p].b16.s0 / L_CODE) + 3); - mem[temp_ptr].b32.s1 = LR_ptr; + mem_ptr(temp_ptr)->b32.s0 = (L_CODE * (mem(p).b16.s0 / L_CODE) + 3); + mem_ptr(temp_ptr)->b32.s1 = LR_ptr; LR_ptr = temp_ptr; } } } break; case 6: - mem[GARBAGE] = mem[p + 1]; - mem[GARBAGE].b32.s1 = mem[p].b32.s1; + set_mem(GARBAGE, mem(p + 1)); + mem_ptr(GARBAGE)->b32.s1 = mem(p).b32.s1; p = GARBAGE; xtx_ligature_present = true; goto reswitch; @@ -12399,18 +12179,18 @@ int32_t hpack(int32_t p, scaled_t w, small_number m) } } if (adjust_tail != TEX_NULL) - mem[adjust_tail].b32.s1 = TEX_NULL; + mem_ptr(adjust_tail)->b32.s1 = TEX_NULL; if (pre_adjust_tail != TEX_NULL) - mem[pre_adjust_tail].b32.s1 = TEX_NULL; - mem[r + 3].b32.s1 = h; - mem[r + 2].b32.s1 = d; + mem_ptr(pre_adjust_tail)->b32.s1 = TEX_NULL; + mem_ptr(r + 3)->b32.s1 = h; + mem_ptr(r + 2)->b32.s1 = d; if (m == ADDITIONAL) w = x + w; - mem[r + 1].b32.s1 = w; + mem_ptr(r + 1)->b32.s1 = w; x = w - x; if (x == 0) { - mem[r + 5].b16.s1 = NORMAL; - mem[r + 5].b16.s0 = NORMAL; + mem_ptr(r + 5)->b16.s1 = NORMAL; + mem_ptr(r + 5)->b16.s0 = NORMAL; BOX_glue_set(r) = 0.0; goto exit; } else if (x > 0) { /*683: */ @@ -12422,18 +12202,18 @@ int32_t hpack(int32_t p, scaled_t w, small_number m) o = FIL; else o = 0 /*normal *//*:684 */ ; - mem[r + 5].b16.s0 = o; - mem[r + 5].b16.s1 = STRETCHING; + mem_ptr(r + 5)->b16.s0 = o; + mem_ptr(r + 5)->b16.s1 = STRETCHING; if (total_stretch[o] != 0) BOX_glue_set(r) = x / ((double)total_stretch[o]); else { - mem[r + 5].b16.s1 = NORMAL; + mem_ptr(r + 5)->b16.s1 = NORMAL; BOX_glue_set(r) = 0.0; } if (o == NORMAL) { - if (mem[r + 5].b32.s1 != TEX_NULL) { /*685: */ + if (mem(r + 5).b32.s1 != TEX_NULL) { /*685: */ last_badness = badness(x, total_stretch[NORMAL]); if (last_badness > INTPAR(hbadness)) { print_ln(); @@ -12461,25 +12241,25 @@ int32_t hpack(int32_t p, scaled_t w, small_number m) o = FIL; else o = 0 /*normal *//*:690 */ ; - mem[r + 5].b16.s0 = o; - mem[r + 5].b16.s1 = SHRINKING; + mem_ptr(r + 5)->b16.s0 = o; + mem_ptr(r + 5)->b16.s1 = SHRINKING; if (total_shrink[o] != 0) BOX_glue_set(r) = (-(int32_t) x) / ((double)total_shrink[o]); else { - mem[r + 5].b16.s1 = NORMAL; + mem_ptr(r + 5)->b16.s1 = NORMAL; BOX_glue_set(r) = 0.0; } - if ((total_shrink[o] < -(int32_t) x) && (o == NORMAL) && (mem[r + 5].b32.s1 != TEX_NULL)) { + if ((total_shrink[o] < -(int32_t) x) && (o == NORMAL) && (mem(r + 5).b32.s1 != TEX_NULL)) { last_badness = 1000000L; BOX_glue_set(r) = 1.0; if ((-(int32_t) x - total_shrink[NORMAL] > DIMENPAR(hfuzz)) || (INTPAR(hbadness) < 100)) { if ((DIMENPAR(overfull_rule) > 0) && (-(int32_t) x - total_shrink[NORMAL] > DIMENPAR(hfuzz))) { - while (mem[q].b32.s1 != TEX_NULL) + while (mem(q).b32.s1 != TEX_NULL) q = LLIST_link(q); - mem[q].b32.s1 = new_rule(); - mem[mem[q].b32.s1 + 1].b32.s1 = DIMENPAR(overfull_rule); + mem_ptr(q)->b32.s1 = new_rule(); + mem_ptr(mem(q).b32.s1 + 1)->b32.s1 = DIMENPAR(overfull_rule); } print_ln(); @@ -12491,7 +12271,7 @@ int32_t hpack(int32_t p, scaled_t w, small_number m) } } else if (o == NORMAL) { - if (mem[r + 5].b32.s1 != TEX_NULL) { /*692: */ + if (mem(r + 5).b32.s1 != TEX_NULL) { /*692: */ last_badness = badness(-(int32_t) x, total_shrink[NORMAL]); if (last_badness > INTPAR(hbadness)) { print_ln(); @@ -12520,14 +12300,14 @@ int32_t hpack(int32_t p, scaled_t w, small_number m) print_cstr("--"); } else print_cstr(") detected at line "); - print_int(line); + print_int(line()); } capture_to_diagnostic(NULL); print_ln(); font_in_short_display = FONT_BASE; - short_display(mem[r + 5].b32.s1); + short_display(mem(r + 5).b32.s1); print_ln(); begin_diagnostic(); show_box(r); @@ -12536,23 +12316,23 @@ int32_t hpack(int32_t p, scaled_t w, small_number m) exit: if (INTPAR(texxet) > 0) { /*1499: */ - if (mem[LR_ptr].b32.s0 != BEFORE) { - while (mem[q].b32.s1 != TEX_NULL) + if (mem(LR_ptr).b32.s0 != BEFORE) { + while (mem(q).b32.s1 != TEX_NULL) q = LLIST_link(q); do { temp_ptr = q; - q = new_math(0, mem[LR_ptr].b32.s0); - mem[temp_ptr].b32.s1 = q; + q = new_math(0, mem(LR_ptr).b32.s0); + mem_ptr(temp_ptr)->b32.s1 = q; LR_problems = LR_problems + 10000; { temp_ptr = LR_ptr; - LR_ptr = mem[temp_ptr].b32.s1; + LR_ptr = mem(temp_ptr).b32.s1; { - mem[temp_ptr].b32.s1 = avail; + mem_ptr(temp_ptr)->b32.s1 = avail; avail = temp_ptr; } } - } while (!(mem[LR_ptr].b32.s0 == BEFORE)); + } while (!(mem(LR_ptr).b32.s0 == BEFORE)); } if (LR_problems > 0) { { @@ -12570,9 +12350,9 @@ int32_t hpack(int32_t p, scaled_t w, small_number m) } { temp_ptr = LR_ptr; - LR_ptr = mem[temp_ptr].b32.s1; + LR_ptr = mem(temp_ptr).b32.s1; { - mem[temp_ptr].b32.s1 = avail; + mem_ptr(temp_ptr)->b32.s1 = avail; avail = temp_ptr; } } @@ -12594,11 +12374,11 @@ int32_t vpackage(int32_t p, scaled_t h, small_number m, scaled_t l) r = get_node(BOX_NODE_SIZE); NODE_type(r) = VLIST_NODE; if ((INTPAR(xetex_upwards) > 0)) - mem[r].b16.s0 = 1; + mem_ptr(r)->b16.s0 = 1; else - mem[r].b16.s0 = 0; - mem[r + 4].b32.s1 = 0; - mem[r + 5].b32.s1 = p; + mem_ptr(r)->b16.s0 = 0; + mem_ptr(r + 4)->b32.s1 = 0; + mem_ptr(r + 5)->b32.s1 = p; w = 0; d = 0; x = 0; @@ -12615,29 +12395,29 @@ int32_t vpackage(int32_t p, scaled_t h, small_number m, scaled_t l) if ((is_char_node(p))) confusion("vpack"); else - switch (mem[p].b16.s1) { + switch (mem(p).b16.s1) { case 0: case 1: case 2: case 13: { - x = x + d + mem[p + 3].b32.s1; - d = mem[p + 2].b32.s1; + x = x + d + mem(p + 3).b32.s1; + d = mem(p + 2).b32.s1; if (NODE_type(p) >= RULE_NODE) s = 0; else - s = mem[p + 4].b32.s1; - if (mem[p + 1].b32.s1 + s > w) - w = mem[p + 1].b32.s1 + s; + s = mem(p + 4).b32.s1; + if (mem(p + 1).b32.s1 + s > w) + w = mem(p + 1).b32.s1 + s; } break; case 8: { - if ((mem[p].b16.s0 == PIC_NODE) || (mem[p].b16.s0 == PDF_NODE)) { - x = x + d + mem[p + 3].b32.s1; - d = mem[p + 2].b32.s1; - if (mem[p + 1].b32.s1 > w) - w = mem[p + 1].b32.s1; + if ((mem(p).b16.s0 == PIC_NODE) || (mem(p).b16.s0 == PDF_NODE)) { + x = x + d + mem(p + 3).b32.s1; + d = mem(p + 2).b32.s1; + if (mem(p + 1).b32.s1 > w) + w = mem(p + 1).b32.s1; } } break; @@ -12645,22 +12425,22 @@ int32_t vpackage(int32_t p, scaled_t h, small_number m, scaled_t l) { x = x + d; d = 0; - g = mem[p + 1].b32.s0; - x = x + mem[g + 1].b32.s1; - o = mem[g].b16.s1; - total_stretch[o] = total_stretch[o] + mem[g + 2].b32.s1; - o = mem[g].b16.s0; - total_shrink[o] = total_shrink[o] + mem[g + 3].b32.s1; - if (mem[p].b16.s0 >= A_LEADERS) { - g = mem[p + 1].b32.s1; - if (mem[g + 1].b32.s1 > w) - w = mem[g + 1].b32.s1; + g = mem(p + 1).b32.s0; + x = x + mem(g + 1).b32.s1; + o = mem(g).b16.s1; + total_stretch[o] = total_stretch[o] + mem(g + 2).b32.s1; + o = mem(g).b16.s0; + total_shrink[o] = total_shrink[o] + mem(g + 3).b32.s1; + if (mem(p).b16.s0 >= A_LEADERS) { + g = mem(p + 1).b32.s1; + if (mem(g + 1).b32.s1 > w) + w = mem(g + 1).b32.s1; } } break; case 11: { - x = x + d + mem[p + 1].b32.s1; + x = x + d + mem(p + 1).b32.s1; d = 0; } break; @@ -12670,19 +12450,19 @@ int32_t vpackage(int32_t p, scaled_t h, small_number m, scaled_t l) } p = LLIST_link(p); } - mem[r + 1].b32.s1 = w; + mem_ptr(r + 1)->b32.s1 = w; if (d > l) { x = x + d - l; - mem[r + 2].b32.s1 = l; + mem_ptr(r + 2)->b32.s1 = l; } else - mem[r + 2].b32.s1 = d; + mem_ptr(r + 2)->b32.s1 = d; if (m == ADDITIONAL) h = x + h; - mem[r + 3].b32.s1 = h; + mem_ptr(r + 3)->b32.s1 = h; x = h - x; if (x == 0) { - mem[r + 5].b16.s1 = NORMAL; - mem[r + 5].b16.s0 = NORMAL; + mem_ptr(r + 5)->b16.s1 = NORMAL; + mem_ptr(r + 5)->b16.s0 = NORMAL; BOX_glue_set(r) = 0.0; goto exit; } else if (x > 0) { /*698: */ @@ -12694,17 +12474,17 @@ int32_t vpackage(int32_t p, scaled_t h, small_number m, scaled_t l) o = FIL; else o = 0 /*normal *//*:684 */ ; - mem[r + 5].b16.s0 = o; - mem[r + 5].b16.s1 = STRETCHING; + mem_ptr(r + 5)->b16.s0 = o; + mem_ptr(r + 5)->b16.s1 = STRETCHING; if (total_stretch[o] != 0) BOX_glue_set(r) = x / ((double)total_stretch[o]); else { - mem[r + 5].b16.s1 = NORMAL; + mem_ptr(r + 5)->b16.s1 = NORMAL; BOX_glue_set(r) = 0.0; } if (o == NORMAL) { - if (mem[r + 5].b32.s1 != TEX_NULL) { /*699: */ + if (mem(r + 5).b32.s1 != TEX_NULL) { /*699: */ last_badness = badness(x, total_stretch[NORMAL]); if (last_badness > INTPAR(vbadness)) { print_ln(); @@ -12731,15 +12511,15 @@ int32_t vpackage(int32_t p, scaled_t h, small_number m, scaled_t l) o = FIL; else o = 0 /*normal *//*:690 */ ; - mem[r + 5].b16.s0 = o; - mem[r + 5].b16.s1 = SHRINKING; + mem_ptr(r + 5)->b16.s0 = o; + mem_ptr(r + 5)->b16.s1 = SHRINKING; if (total_shrink[o] != 0) BOX_glue_set(r) = (-(int32_t) x) / ((double)total_shrink[o]); else { - mem[r + 5].b16.s1 = NORMAL; + mem_ptr(r + 5)->b16.s1 = NORMAL; BOX_glue_set(r) = 0.0; } - if ((total_shrink[o] < -(int32_t) x) && (o == NORMAL) && (mem[r + 5].b32.s1 != TEX_NULL)) { + if ((total_shrink[o] < -(int32_t) x) && (o == NORMAL) && (mem(r + 5).b32.s1 != TEX_NULL)) { last_badness = 1000000L; BOX_glue_set(r) = 1.0; if ((-(int32_t) x - total_shrink[NORMAL] > DIMENPAR(vfuzz)) @@ -12754,7 +12534,7 @@ int32_t vpackage(int32_t p, scaled_t h, small_number m, scaled_t l) } } else if (o == NORMAL) { - if (mem[r + 5].b32.s1 != TEX_NULL) { /*703: */ + if (mem(r + 5).b32.s1 != TEX_NULL) { /*703: */ last_badness = badness(-(int32_t) x, total_shrink[NORMAL]); if (last_badness > INTPAR(vbadness)) { print_ln(); @@ -12780,7 +12560,7 @@ int32_t vpackage(int32_t p, scaled_t h, small_number m, scaled_t l) print_cstr("--"); } else print_cstr(") detected at line "); - print_int(line); + print_int(line()); print_ln(); } @@ -12803,36 +12583,36 @@ void append_to_vlist(int32_t b) upwards = (INTPAR(xetex_upwards) > 0); if (cur_list.aux.b32.s1 > IGNORE_DEPTH) { if (upwards) - d = mem[GLUEPAR(baseline_skip) + 1].b32.s1 - cur_list.aux.b32.s1 - mem[b + 2].b32.s1; + d = mem(GLUEPAR(baseline_skip) + 1).b32.s1 - cur_list.aux.b32.s1 - mem(b + 2).b32.s1; else - d = mem[GLUEPAR(baseline_skip) + 1].b32.s1 - cur_list.aux.b32.s1 - mem[b + 3].b32.s1; + d = mem(GLUEPAR(baseline_skip) + 1).b32.s1 - cur_list.aux.b32.s1 - mem(b + 3).b32.s1; if (d < DIMENPAR(line_skip_limit)) p = new_param_glue(GLUE_PAR__line_skip); else { p = new_skip_param(GLUE_PAR__baseline_skip); - mem[temp_ptr + 1].b32.s1 = d; + mem_ptr(temp_ptr + 1)->b32.s1 = d; } - mem[cur_list.tail].b32.s1 = p; + mem_ptr(cur_list.tail)->b32.s1 = p; cur_list.tail = p; } - mem[cur_list.tail].b32.s1 = b; + mem_ptr(cur_list.tail)->b32.s1 = b; cur_list.tail = b; if (upwards) - cur_list.aux.b32.s1 = mem[b + 3].b32.s1; + cur_list.aux.b32.s1 = mem(b + 3).b32.s1; else - cur_list.aux.b32.s1 = mem[b + 2].b32.s1; + cur_list.aux.b32.s1 = mem(b + 2).b32.s1; } int32_t new_noad(void) { int32_t p; p = get_node(NOAD_SIZE); - mem[p].b16.s1 = ORD_NOAD; - mem[p].b16.s0 = NORMAL; - mem[p + 1].b32 = empty; - mem[p + 3].b32 = empty; - mem[p + 2].b32 = empty; + mem_ptr(p)->b16.s1 = ORD_NOAD; + mem_ptr(p)->b16.s0 = NORMAL; + mem_ptr(p + 1)->b32 = empty; + mem_ptr(p + 3)->b32 = empty; + mem_ptr(p + 2)->b32 = empty; return p; } @@ -12841,9 +12621,9 @@ int32_t new_style(small_number s) int32_t p; p = get_node(STYLE_NODE_SIZE); NODE_type(p) = STYLE_NODE; - mem[p].b16.s0 = s; - mem[p + 1].b32.s1 = 0; - mem[p + 2].b32.s1 = 0; + mem_ptr(p)->b16.s0 = s; + mem_ptr(p + 1)->b32.s1 = 0; + mem_ptr(p + 2)->b32.s1 = 0; return p; } @@ -12852,34 +12632,34 @@ int32_t new_choice(void) int32_t p; p = get_node(STYLE_NODE_SIZE); NODE_type(p) = CHOICE_NODE; - mem[p].b16.s0 = 0; - mem[p + 1].b32.s0 = TEX_NULL; - mem[p + 1].b32.s1 = TEX_NULL; - mem[p + 2].b32.s0 = TEX_NULL; - mem[p + 2].b32.s1 = TEX_NULL; + mem_ptr(p)->b16.s0 = 0; + mem_ptr(p + 1)->b32.s0 = TEX_NULL; + mem_ptr(p + 1)->b32.s1 = TEX_NULL; + mem_ptr(p + 2)->b32.s0 = TEX_NULL; + mem_ptr(p + 2)->b32.s1 = TEX_NULL; return p; } void show_info(void) { - show_node_list(mem[temp_ptr].b32.s0); + show_node_list(mem(temp_ptr).b32.s0); } void push_alignment(void) { int32_t p; p = get_node(ALIGN_STACK_NODE_SIZE); - mem[p].b32.s1 = align_ptr; - mem[p].b32.s0 = cur_align; - mem[p + 1].b32.s0 = mem[ALIGN_HEAD].b32.s1; - mem[p + 1].b32.s1 = cur_span; - mem[p + 2].b32.s1 = cur_loop; - mem[p + 3].b32.s1 = align_state; - mem[p + 4].b32.s0 = cur_head; - mem[p + 4].b32.s1 = cur_tail; - mem[p + 5].b32.s0 = cur_pre_head; - mem[p + 5].b32.s1 = cur_pre_tail; + mem_ptr(p)->b32.s1 = align_ptr; + mem_ptr(p)->b32.s0 = cur_align; + mem_ptr(p + 1)->b32.s0 = mem(ALIGN_HEAD).b32.s1; + mem_ptr(p + 1)->b32.s1 = cur_span; + mem_ptr(p + 2)->b32.s1 = cur_loop; + mem_ptr(p + 3)->b32.s1 = align_state; + mem_ptr(p + 4)->b32.s0 = cur_head; + mem_ptr(p + 4)->b32.s1 = cur_tail; + mem_ptr(p + 5)->b32.s0 = cur_pre_head; + mem_ptr(p + 5)->b32.s1 = cur_pre_tail; align_ptr = p; cur_head = get_avail(); cur_pre_head = get_avail(); @@ -12889,24 +12669,24 @@ void pop_alignment(void) { int32_t p; { - mem[cur_head].b32.s1 = avail; + mem_ptr(cur_head)->b32.s1 = avail; avail = cur_head; } { - mem[cur_pre_head].b32.s1 = avail; + mem_ptr(cur_pre_head)->b32.s1 = avail; avail = cur_pre_head; } p = align_ptr; - cur_tail = mem[p + 4].b32.s1; - cur_head = mem[p + 4].b32.s0; - cur_pre_tail = mem[p + 5].b32.s1; - cur_pre_head = mem[p + 5].b32.s0; - align_state = mem[p + 3].b32.s1; - cur_loop = mem[p + 2].b32.s1; - cur_span = mem[p + 1].b32.s1; - mem[ALIGN_HEAD].b32.s1 = mem[p + 1].b32.s0; - cur_align = mem[p].b32.s0; - align_ptr = mem[p].b32.s1; + cur_tail = mem(p + 4).b32.s1; + cur_head = mem(p + 4).b32.s0; + cur_pre_tail = mem(p + 5).b32.s1; + cur_pre_head = mem(p + 5).b32.s0; + align_state = mem(p + 3).b32.s1; + cur_loop = mem(p + 2).b32.s1; + cur_span = mem(p + 1).b32.s1; + mem_ptr(ALIGN_HEAD)->b32.s1 = mem(p + 1).b32.s0; + cur_align = mem(p).b32.s0; + align_ptr = mem(p).b32.s1; free_node(p, ALIGN_STACK_NODE_SIZE); } @@ -12971,7 +12751,7 @@ init_align(void) } scan_spec(ALIGN_GROUP, false); - mem[ALIGN_HEAD].b32.s1 = TEX_NULL; + mem_ptr(ALIGN_HEAD)->b32.s1 = TEX_NULL; cur_align = ALIGN_HEAD; cur_loop = TEX_NULL; scanner_status = ALIGNING; @@ -12979,13 +12759,13 @@ init_align(void) align_state = -1000000L; while (true) { - mem[cur_align].b32.s1 = new_param_glue(GLUE_PAR__tab_skip); + mem_ptr(cur_align)->b32.s1 = new_param_glue(GLUE_PAR__tab_skip); cur_align = LLIST_link(cur_align); /*:807*/ if (cur_cmd == CAR_RET) goto done; p = HOLD_HEAD; - mem[p].b32.s1 = TEX_NULL; + mem_ptr(p)->b32.s1 = TEX_NULL; while (true) { get_preamble_token(); @@ -13006,20 +12786,20 @@ init_align(void) goto done1; } } else if (cur_cmd != SPACER || p != HOLD_HEAD) { - mem[p].b32.s1 = get_avail(); + mem_ptr(p)->b32.s1 = get_avail(); p = LLIST_link(p); - mem[p].b32.s0 = cur_tok; + mem_ptr(p)->b32.s0 = cur_tok; } } done1: - mem[cur_align].b32.s1 = new_null_box(); + mem_ptr(cur_align)->b32.s1 = new_null_box(); cur_align = LLIST_link(cur_align); - mem[cur_align].b32.s0 = END_SPAN; - mem[cur_align + 1].b32.s1 = NULL_FLAG; - mem[cur_align + 3].b32.s1 = mem[HOLD_HEAD].b32.s1; + mem_ptr(cur_align)->b32.s0 = END_SPAN; + mem_ptr(cur_align + 1)->b32.s1 = NULL_FLAG; + mem_ptr(cur_align + 3)->b32.s1 = mem(HOLD_HEAD).b32.s1; p = HOLD_HEAD; - mem[p].b32.s1 = TEX_NULL; + mem_ptr(p)->b32.s1 = TEX_NULL; while (true) { continue_: @@ -13039,16 +12819,16 @@ init_align(void) goto continue_; } - mem[p].b32.s1 = get_avail(); + mem_ptr(p)->b32.s1 = get_avail(); p = LLIST_link(p); - mem[p].b32.s0 = cur_tok; + mem_ptr(p)->b32.s0 = cur_tok; } done2: - mem[p].b32.s1 = get_avail(); + mem_ptr(p)->b32.s1 = get_avail(); p = LLIST_link(p); - mem[p].b32.s0 = CS_TOKEN_FLAG + FROZEN_END_TEMPLATE; /*:813*/ - mem[cur_align + 2].b32.s1 = mem[HOLD_HEAD].b32.s1; /*:808 */ + mem_ptr(p)->b32.s0 = CS_TOKEN_FLAG + FROZEN_END_TEMPLATE; /*:813*/ + mem_ptr(cur_align + 2)->b32.s1 = mem(HOLD_HEAD).b32.s1; /*:808 */ } done: @@ -13084,11 +12864,11 @@ void init_row(void) else cur_list.aux.b32.s1 = 0; { - mem[cur_list.tail].b32.s1 = new_glue(mem[mem[ALIGN_HEAD].b32.s1 + 1].b32.s0); + mem_ptr(cur_list.tail)->b32.s1 = new_glue(mem(mem(ALIGN_HEAD).b32.s1 + 1).b32.s0); cur_list.tail = LLIST_link(cur_list.tail); } - mem[cur_list.tail].b16.s0 = (GLUE_PAR__tab_skip + 1); - cur_align = mem[mem[ALIGN_HEAD].b32.s1].b32.s1; + mem_ptr(cur_list.tail)->b16.s0 = (GLUE_PAR__tab_skip + 1); + cur_align = mem(mem(ALIGN_HEAD).b32.s1).b32.s1; cur_tail = cur_head; cur_pre_tail = cur_pre_head; init_span(cur_align); @@ -13096,13 +12876,13 @@ void init_row(void) void init_col(void) { - mem[cur_align + 5].b32.s0 = cur_cmd; + mem_ptr(cur_align + 5)->b32.s0 = cur_cmd; if (cur_cmd == OMIT) align_state = 0; else { back_input(); - begin_token_list(mem[cur_align + 3].b32.s1, U_TEMPLATE); + begin_token_list(mem(cur_align + 3).b32.s1, U_TEMPLATE); } } @@ -13117,44 +12897,44 @@ bool fin_col(void) int32_t n; if (cur_align == TEX_NULL) confusion("endv"); - q = mem[cur_align].b32.s1; + q = mem(cur_align).b32.s1; if (q == TEX_NULL) confusion("endv"); if (align_state < 500000L) fatal_error("(interwoven alignment preambles are not allowed)"); - p = mem[q].b32.s1; - if ((p == TEX_NULL) && (mem[cur_align + 5].b32.s0 < CR_CODE)) { + p = mem(q).b32.s1; + if ((p == TEX_NULL) && (mem(cur_align + 5).b32.s0 < CR_CODE)) { if (cur_loop != TEX_NULL) { /*822: */ - mem[q].b32.s1 = new_null_box(); - p = mem[q].b32.s1; - mem[p].b32.s0 = END_SPAN; - mem[p + 1].b32.s1 = NULL_FLAG; + mem_ptr(q)->b32.s1 = new_null_box(); + p = mem(q).b32.s1; + mem_ptr(p)->b32.s0 = END_SPAN; + mem_ptr(p + 1)->b32.s1 = NULL_FLAG; cur_loop = LLIST_link(cur_loop); q = HOLD_HEAD; - r = mem[cur_loop + 3].b32.s1; + r = mem(cur_loop + 3).b32.s1; while (r != TEX_NULL) { - mem[q].b32.s1 = get_avail(); + mem_ptr(q)->b32.s1 = get_avail(); q = LLIST_link(q); - mem[q].b32.s0 = mem[r].b32.s0; + mem_ptr(q)->b32.s0 = mem(r).b32.s0; r = LLIST_link(r); } - mem[q].b32.s1 = TEX_NULL; - mem[p + 3].b32.s1 = mem[HOLD_HEAD].b32.s1; + mem_ptr(q)->b32.s1 = TEX_NULL; + mem_ptr(p + 3)->b32.s1 = mem(HOLD_HEAD).b32.s1; q = HOLD_HEAD; - r = mem[cur_loop + 2].b32.s1; + r = mem(cur_loop + 2).b32.s1; while (r != TEX_NULL) { - mem[q].b32.s1 = get_avail(); + mem_ptr(q)->b32.s1 = get_avail(); q = LLIST_link(q); - mem[q].b32.s0 = mem[r].b32.s0; + mem_ptr(q)->b32.s0 = mem(r).b32.s0; r = LLIST_link(r); } - mem[q].b32.s1 = TEX_NULL; - mem[p + 2].b32.s1 = mem[HOLD_HEAD].b32.s1 /*:823 */ ; + mem_ptr(q)->b32.s1 = TEX_NULL; + mem_ptr(p + 2)->b32.s1 = mem(HOLD_HEAD).b32.s1 /*:823 */ ; cur_loop = LLIST_link(cur_loop); - mem[p].b32.s1 = new_glue(mem[cur_loop + 1].b32.s0); + mem_ptr(p)->b32.s1 = new_glue(mem(cur_loop + 1).b32.s0); NODE_subtype(LLIST_link(p)) = GLUE_PAR__tab_skip + 1; } else { error_here_with_diagnostic("Extra alignment tab has been changed to "); @@ -13167,52 +12947,52 @@ bool fin_col(void) help_line[1] = "in the preamble to the \\halign or \\valign now in progress."; help_line[0] = "So I'll assume that you meant to type \\cr instead."; } - mem[cur_align + 5].b32.s0 = CR_CODE; + mem_ptr(cur_align + 5)->b32.s0 = CR_CODE; error(); } } - if (mem[cur_align + 5].b32.s0 != SPAN_CODE) { + if (mem(cur_align + 5).b32.s0 != SPAN_CODE) { unsave(); new_save_level(ALIGN_GROUP); { if (cur_list.mode == -104) { adjust_tail = cur_tail; pre_adjust_tail = cur_pre_tail; - u = hpack(mem[cur_list.head].b32.s1, 0, ADDITIONAL); - w = mem[u + 1].b32.s1; + u = hpack(mem(cur_list.head).b32.s1, 0, ADDITIONAL); + w = mem(u + 1).b32.s1; cur_tail = adjust_tail; adjust_tail = TEX_NULL; cur_pre_tail = pre_adjust_tail; pre_adjust_tail = TEX_NULL; } else { - u = vpackage(mem[cur_list.head].b32.s1, 0, ADDITIONAL, 0); - w = mem[u + 3].b32.s1; + u = vpackage(mem(cur_list.head).b32.s1, 0, ADDITIONAL, 0); + w = mem(u + 3).b32.s1; } n = 0; if (cur_span != cur_align) { /*827: */ q = cur_span; do { n++; - q = mem[mem[q].b32.s1].b32.s1; + q = mem(mem(q).b32.s1).b32.s1; } while (!(q == cur_align)); if (n > UINT16_MAX) confusion("too many spans"); q = cur_span; - while (mem[mem[q].b32.s0].b32.s1 < n) - q = mem[q].b32.s0; - if (mem[mem[q].b32.s0].b32.s1 > n) { + while (mem(mem(q).b32.s0).b32.s1 < n) + q = mem(q).b32.s0; + if (mem(mem(q).b32.s0).b32.s1 > n) { s = get_node(SPAN_NODE_SIZE); - mem[s].b32.s0 = mem[q].b32.s0; - mem[s].b32.s1 = n; - mem[q].b32.s0 = s; - mem[s + 1].b32.s1 = w; - } else if (mem[mem[q].b32.s0 + 1].b32.s1 < w) - mem[mem[q].b32.s0 + 1].b32.s1 = w; - } else if (w > mem[cur_align + 1].b32.s1) - mem[cur_align + 1].b32.s1 = w; + mem_ptr(s)->b32.s0 = mem(q).b32.s0; + mem_ptr(s)->b32.s1 = n; + mem_ptr(q)->b32.s0 = s; + mem_ptr(s + 1)->b32.s1 = w; + } else if (mem(mem(q).b32.s0 + 1).b32.s1 < w) + mem_ptr(mem(q).b32.s0 + 1)->b32.s1 = w; + } else if (w > mem(cur_align + 1).b32.s1) + mem_ptr(cur_align + 1)->b32.s1 = w; NODE_type(u) = UNSET_NODE; - mem[u].b16.s0 = n; + mem_ptr(u)->b16.s0 = n; if (total_stretch[FILLL] != 0) o = FILLL; else if (total_stretch[FILL] != 0) @@ -13221,8 +13001,8 @@ bool fin_col(void) o = FIL; else o = 0 /*normal *//*:684 */ ; - mem[u + 5].b16.s0 = o; - mem[u + 6].b32.s1 = total_stretch[o]; + mem_ptr(u + 5)->b16.s0 = o; + mem_ptr(u + 6)->b32.s1 = total_stretch[o]; if (total_shrink[FILLL] != 0) o = FILLL; else if (total_shrink[FILL] != 0) @@ -13231,18 +13011,18 @@ bool fin_col(void) o = FIL; else o = 0 /*normal *//*:690 */ ; - mem[u + 5].b16.s1 = o; - mem[u + 4].b32.s1 = total_shrink[o]; + mem_ptr(u + 5)->b16.s1 = o; + mem_ptr(u + 4)->b32.s1 = total_shrink[o]; pop_nest(); - mem[cur_list.tail].b32.s1 = u; + mem_ptr(cur_list.tail)->b32.s1 = u; cur_list.tail = u; } { - mem[cur_list.tail].b32.s1 = new_glue(mem[mem[cur_align].b32.s1 + 1].b32.s0); + mem_ptr(cur_list.tail)->b32.s1 = new_glue(mem(mem(cur_align).b32.s1 + 1).b32.s0); cur_list.tail = LLIST_link(cur_list.tail); } - mem[cur_list.tail].b16.s0 = 12 /*tab_skip_code 1 *//*:824 */ ; - if (mem[cur_align + 5].b32.s0 >= CR_CODE) { + mem_ptr(cur_list.tail)->b16.s0 = 12 /*tab_skip_code 1 *//*:824 */ ; + if (mem(cur_align + 5).b32.s0 >= CR_CODE) { return true; } init_span(p); @@ -13261,27 +13041,27 @@ void fin_row(void) int32_t p; if (cur_list.mode == -104) { - p = hpack(mem[cur_list.head].b32.s1, 0, ADDITIONAL); + p = hpack(mem(cur_list.head).b32.s1, 0, ADDITIONAL); pop_nest(); if (cur_pre_head != cur_pre_tail) { - mem[cur_list.tail].b32.s1 = mem[cur_pre_head].b32.s1; + mem_ptr(cur_list.tail)->b32.s1 = mem(cur_pre_head).b32.s1; cur_list.tail = cur_pre_tail; } append_to_vlist(p); if (cur_head != cur_tail) { - mem[cur_list.tail].b32.s1 = mem[cur_head].b32.s1; + mem_ptr(cur_list.tail)->b32.s1 = mem(cur_head).b32.s1; cur_list.tail = cur_tail; } } else { - p = vpackage(mem[cur_list.head].b32.s1, 0, ADDITIONAL, MAX_HALFWORD); + p = vpackage(mem(cur_list.head).b32.s1, 0, ADDITIONAL, MAX_HALFWORD); pop_nest(); - mem[cur_list.tail].b32.s1 = p; + mem_ptr(cur_list.tail)->b32.s1 = p; cur_list.tail = p; cur_list.aux.b32.s0 = 1000; } NODE_type(p) = UNSET_NODE; - mem[p + 6].b32.s1 = 0; + mem_ptr(p + 6)->b32.s1 = 0; if (LOCAL(every_cr) != TEX_NULL) begin_token_list(LOCAL(every_cr), EVERY_CR_TEXT); align_peek(); @@ -13306,57 +13086,57 @@ void fin_align(void) o = DIMENPAR(display_indent); else o = 0; - q = mem[mem[ALIGN_HEAD].b32.s1].b32.s1; + q = mem(mem(ALIGN_HEAD).b32.s1).b32.s1; do { - flush_list(mem[q + 3].b32.s1); - flush_list(mem[q + 2].b32.s1); - p = mem[mem[q].b32.s1].b32.s1; - if (mem[q + 1].b32.s1 == NULL_FLAG) { /*831: */ - mem[q + 1].b32.s1 = 0; - r = mem[q].b32.s1; - s = mem[r + 1].b32.s0; + flush_list(mem(q + 3).b32.s1); + flush_list(mem(q + 2).b32.s1); + p = mem(mem(q).b32.s1).b32.s1; + if (mem(q + 1).b32.s1 == NULL_FLAG) { /*831: */ + mem_ptr(q + 1)->b32.s1 = 0; + r = mem(q).b32.s1; + s = mem(r + 1).b32.s0; if (s != 0) { GLUE_SPEC_ref_count(0)++; delete_glue_ref(s); - mem[r + 1].b32.s0 = 0; + mem_ptr(r + 1)->b32.s0 = 0; } } - if (mem[q].b32.s0 != END_SPAN) { /*832: */ - t = mem[q + 1].b32.s1 + mem[mem[mem[q].b32.s1 + 1].b32.s0 + 1].b32.s1; - r = mem[q].b32.s0; + if (mem(q).b32.s0 != END_SPAN) { /*832: */ + t = mem(q + 1).b32.s1 + mem(mem(mem(q).b32.s1 + 1).b32.s0 + 1).b32.s1; + r = mem(q).b32.s0; s = END_SPAN; - mem[s].b32.s0 = p; + mem_ptr(s)->b32.s0 = p; n = 1; do { - mem[r + 1].b32.s1 = mem[r + 1].b32.s1 - t; - u = mem[r].b32.s0; - while (mem[r].b32.s1 > n) { + mem_ptr(r + 1)->b32.s1 = mem(r + 1).b32.s1 - t; + u = mem(r).b32.s0; + while (mem(r).b32.s1 > n) { - s = mem[s].b32.s0; - n = mem[mem[s].b32.s0].b32.s1 + 1; + s = mem(s).b32.s0; + n = mem(mem(s).b32.s0).b32.s1 + 1; } - if (mem[r].b32.s1 < n) { - mem[r].b32.s0 = mem[s].b32.s0; - mem[s].b32.s0 = r; - mem[r].b32.s1--; + if (mem(r).b32.s1 < n) { + mem_ptr(r)->b32.s0 = mem(s).b32.s0; + mem_ptr(s)->b32.s0 = r; + mem_ptr(r)->b32.s1--; s = r; } else { - if (mem[r + 1].b32.s1 > mem[mem[s].b32.s0 + 1].b32.s1) - mem[mem[s].b32.s0 + 1].b32.s1 = mem[r + 1].b32.s1; + if (mem(r + 1).b32.s1 > mem(mem(s).b32.s0 + 1).b32.s1) + mem_ptr(mem(s).b32.s0 + 1)->b32.s1 = mem(r + 1).b32.s1; free_node(r, SPAN_NODE_SIZE); } r = u; } while (!(r == END_SPAN)); } NODE_type(q) = UNSET_NODE; - mem[q].b16.s0 = 0; - mem[q + 3].b32.s1 = 0; - mem[q + 2].b32.s1 = 0; - mem[q + 5].b16.s0 = NORMAL; - mem[q + 5].b16.s1 = NORMAL; - mem[q + 6].b32.s1 = 0; - mem[q + 4].b32.s1 = 0; + mem_ptr(q)->b16.s0 = 0; + mem_ptr(q + 3)->b32.s1 = 0; + mem_ptr(q + 2)->b32.s1 = 0; + mem_ptr(q + 5)->b16.s0 = NORMAL; + mem_ptr(q + 5)->b16.s1 = NORMAL; + mem_ptr(q + 6)->b32.s1 = 0; + mem_ptr(q + 4)->b32.s1 = 0; q = p; } while (!(q == TEX_NULL /*:830 */ )); save_ptr = save_ptr - 2; @@ -13364,27 +13144,27 @@ void fin_align(void) if (cur_list.mode == -1) { rule_save = DIMENPAR(overfull_rule); DIMENPAR(overfull_rule) = 0; - p = hpack(mem[ALIGN_HEAD].b32.s1, save_stack[save_ptr + 1].b32.s1, save_stack[save_ptr + 0].b32.s1); + p = hpack(mem(ALIGN_HEAD).b32.s1, save_stack[save_ptr + 1].b32.s1, save_stack[save_ptr + 0].b32.s1); DIMENPAR(overfull_rule) = rule_save; } else { - q = mem[mem[ALIGN_HEAD].b32.s1].b32.s1; + q = mem(mem(ALIGN_HEAD).b32.s1).b32.s1; do { - mem[q + 3].b32.s1 = mem[q + 1].b32.s1; - mem[q + 1].b32.s1 = 0; - q = mem[mem[q].b32.s1].b32.s1; + mem_ptr(q + 3)->b32.s1 = mem(q + 1).b32.s1; + mem_ptr(q + 1)->b32.s1 = 0; + q = mem(mem(q).b32.s1).b32.s1; } while (!(q == TEX_NULL)); - p = vpackage(mem[ALIGN_HEAD].b32.s1, save_stack[save_ptr + 1].b32.s1, save_stack[save_ptr + 0].b32.s1, + p = vpackage(mem(ALIGN_HEAD).b32.s1, save_stack[save_ptr + 1].b32.s1, save_stack[save_ptr + 0].b32.s1, MAX_HALFWORD); - q = mem[mem[ALIGN_HEAD].b32.s1].b32.s1; + q = mem(mem(ALIGN_HEAD).b32.s1).b32.s1; do { - mem[q + 1].b32.s1 = mem[q + 3].b32.s1; - mem[q + 3].b32.s1 = 0; - q = mem[mem[q].b32.s1].b32.s1; + mem_ptr(q + 1)->b32.s1 = mem(q + 3).b32.s1; + mem_ptr(q + 3)->b32.s1 = 0; + q = mem(mem(q).b32.s1).b32.s1; } while (!(q == TEX_NULL)); } pack_begin_line = 0 /*:833 */ ; - q = mem[cur_list.head].b32.s1; + q = mem(cur_list.head).b32.s1; s = cur_list.head; while (q != TEX_NULL) { @@ -13393,130 +13173,130 @@ void fin_align(void) if (NODE_type(q) == UNSET_NODE) { /*836: */ if (cur_list.mode == -1) { NODE_type(q) = HLIST_NODE; - mem[q + 1].b32.s1 = mem[p + 1].b32.s1; + mem_ptr(q + 1)->b32.s1 = mem(p + 1).b32.s1; if (nest[nest_ptr - 1].mode == MMODE) - mem[q].b16.s0 = DLIST; + mem_ptr(q)->b16.s0 = DLIST; } else { NODE_type(q) = VLIST_NODE; - mem[q + 3].b32.s1 = mem[p + 3].b32.s1; + mem_ptr(q + 3)->b32.s1 = mem(p + 3).b32.s1; } - mem[q + 5].b16.s0 = mem[p + 5].b16.s0; - mem[q + 5].b16.s1 = mem[p + 5].b16.s1; + mem_ptr(q + 5)->b16.s0 = mem(p + 5).b16.s0; + mem_ptr(q + 5)->b16.s1 = mem(p + 5).b16.s1; BOX_glue_set(q) = BOX_glue_set(p); - mem[q + 4].b32.s1 = o; - r = mem[mem[q + 5].b32.s1].b32.s1; - s = mem[mem[p + 5].b32.s1].b32.s1; + mem_ptr(q + 4)->b32.s1 = o; + r = mem(mem(q + 5).b32.s1).b32.s1; + s = mem(mem(p + 5).b32.s1).b32.s1; do { - /*837: */ n = mem[r].b16.s0; - t = mem[s + 1].b32.s1; + /*837: */ n = mem(r).b16.s0; + t = mem(s + 1).b32.s1; w = t; u = HOLD_HEAD; - mem[r].b16.s0 = 0; + mem_ptr(r)->b16.s0 = 0; while (n > 0) { n--; s = LLIST_link(s); - v = mem[s + 1].b32.s0; - mem[u].b32.s1 = new_glue(v); + v = mem(s + 1).b32.s0; + mem_ptr(u)->b32.s1 = new_glue(v); u = LLIST_link(u); - mem[u].b16.s0 = (GLUE_PAR__tab_skip + 1); - t = t + mem[v + 1].b32.s1; - if (mem[p + 5].b16.s1 == STRETCHING) { - if (mem[v].b16.s1 == mem[p + 5].b16.s0) - t = t + tex_round(BOX_glue_set(p) * mem[v + 2].b32.s1); - } else if (mem[p + 5].b16.s1 == SHRINKING) { - if (mem[v].b16.s0 == mem[p + 5].b16.s0) - t = t - tex_round(BOX_glue_set(p) * mem[v + 3].b32.s1); + mem_ptr(u)->b16.s0 = (GLUE_PAR__tab_skip + 1); + t = t + mem(v + 1).b32.s1; + if (mem(p + 5).b16.s1 == STRETCHING) { + if (mem(v).b16.s1 == mem(p + 5).b16.s0) + t = t + tex_round(BOX_glue_set(p) * mem(v + 2).b32.s1); + } else if (mem(p + 5).b16.s1 == SHRINKING) { + if (mem(v).b16.s0 == mem(p + 5).b16.s0) + t = t - tex_round(BOX_glue_set(p) * mem(v + 3).b32.s1); } s = LLIST_link(s); - mem[u].b32.s1 = new_null_box(); + mem_ptr(u)->b32.s1 = new_null_box(); u = LLIST_link(u); - t = t + mem[s + 1].b32.s1; + t = t + mem(s + 1).b32.s1; if (cur_list.mode == -1) - mem[u + 1].b32.s1 = mem[s + 1].b32.s1; + mem_ptr(u + 1)->b32.s1 = mem(s + 1).b32.s1; else { NODE_type(u) = VLIST_NODE; - mem[u + 3].b32.s1 = mem[s + 1].b32.s1; + mem_ptr(u + 3)->b32.s1 = mem(s + 1).b32.s1; } } if (cur_list.mode == -1) { /*839: */ - mem[r + 3].b32.s1 = mem[q + 3].b32.s1; - mem[r + 2].b32.s1 = mem[q + 2].b32.s1; - if (t == mem[r + 1].b32.s1) { - mem[r + 5].b16.s1 = NORMAL; - mem[r + 5].b16.s0 = NORMAL; + mem_ptr(r + 3)->b32.s1 = mem(q + 3).b32.s1; + mem_ptr(r + 2)->b32.s1 = mem(q + 2).b32.s1; + if (t == mem(r + 1).b32.s1) { + mem_ptr(r + 5)->b16.s1 = NORMAL; + mem_ptr(r + 5)->b16.s0 = NORMAL; BOX_glue_set(r) = 0.0; - } else if (t > mem[r + 1].b32.s1) { - mem[r + 5].b16.s1 = STRETCHING; - if (mem[r + 6].b32.s1 == 0) + } else if (t > mem(r + 1).b32.s1) { + mem_ptr(r + 5)->b16.s1 = STRETCHING; + if (mem(r + 6).b32.s1 == 0) BOX_glue_set(r) = 0.0; else - BOX_glue_set(r) = (t - mem[r + 1].b32.s1) / ((double)mem[r + 6].b32.s1); + BOX_glue_set(r) = (t - mem(r + 1).b32.s1) / ((double)mem(r + 6).b32.s1); } else { - mem[r + 5].b16.s0 = mem[r + 5].b16.s1; - mem[r + 5].b16.s1 = SHRINKING; - if (mem[r + 4].b32.s1 == 0) + mem_ptr(r + 5)->b16.s0 = mem(r + 5).b16.s1; + mem_ptr(r + 5)->b16.s1 = SHRINKING; + if (mem(r + 4).b32.s1 == 0) BOX_glue_set(r) = 0.0; - else if ((mem[r + 5].b16.s0 == NORMAL) && (mem[r + 1].b32.s1 - t > mem[r + 4].b32.s1)) + else if ((mem(r + 5).b16.s0 == NORMAL) && (mem(r + 1).b32.s1 - t > mem(r + 4).b32.s1)) BOX_glue_set(r) = 1.0; else - BOX_glue_set(r) = (mem[r + 1].b32.s1 - t) / ((double)mem[r + 4].b32.s1); + BOX_glue_set(r) = (mem(r + 1).b32.s1 - t) / ((double)mem(r + 4).b32.s1); } - mem[r + 1].b32.s1 = w; + mem_ptr(r + 1)->b32.s1 = w; NODE_type(r) = HLIST_NODE; } else { /*840: */ - mem[r + 1].b32.s1 = mem[q + 1].b32.s1; - if (t == mem[r + 3].b32.s1) { - mem[r + 5].b16.s1 = NORMAL; - mem[r + 5].b16.s0 = NORMAL; + mem_ptr(r + 1)->b32.s1 = mem(q + 1).b32.s1; + if (t == mem(r + 3).b32.s1) { + mem_ptr(r + 5)->b16.s1 = NORMAL; + mem_ptr(r + 5)->b16.s0 = NORMAL; BOX_glue_set(r) = 0.0; - } else if (t > mem[r + 3].b32.s1) { - mem[r + 5].b16.s1 = STRETCHING; - if (mem[r + 6].b32.s1 == 0) + } else if (t > mem(r + 3).b32.s1) { + mem_ptr(r + 5)->b16.s1 = STRETCHING; + if (mem(r + 6).b32.s1 == 0) BOX_glue_set(r) = 0.0; else - BOX_glue_set(r) = (t - mem[r + 3].b32.s1) / ((double)mem[r + 6].b32.s1); + BOX_glue_set(r) = (t - mem(r + 3).b32.s1) / ((double)mem(r + 6).b32.s1); } else { - mem[r + 5].b16.s0 = mem[r + 5].b16.s1; - mem[r + 5].b16.s1 = SHRINKING; - if (mem[r + 4].b32.s1 == 0) + mem_ptr(r + 5)->b16.s0 = mem(r + 5).b16.s1; + mem_ptr(r + 5)->b16.s1 = SHRINKING; + if (mem(r + 4).b32.s1 == 0) BOX_glue_set(r) = 0.0; - else if ((mem[r + 5].b16.s0 == NORMAL) && (mem[r + 3].b32.s1 - t > mem[r + 4].b32.s1)) + else if ((mem(r + 5).b16.s0 == NORMAL) && (mem(r + 3).b32.s1 - t > mem(r + 4).b32.s1)) BOX_glue_set(r) = 1.0; else - BOX_glue_set(r) = (mem[r + 3].b32.s1 - t) / ((double)mem[r + 4].b32.s1); + BOX_glue_set(r) = (mem(r + 3).b32.s1 - t) / ((double)mem(r + 4).b32.s1); } - mem[r + 3].b32.s1 = w; + mem_ptr(r + 3)->b32.s1 = w; NODE_type(r) = VLIST_NODE; } - mem[r + 4].b32.s1 = 0; + mem_ptr(r + 4)->b32.s1 = 0; if (u != HOLD_HEAD) { - mem[u].b32.s1 = mem[r].b32.s1; - mem[r].b32.s1 = mem[HOLD_HEAD].b32.s1; + mem_ptr(u)->b32.s1 = mem(r).b32.s1; + mem_ptr(r)->b32.s1 = mem(HOLD_HEAD).b32.s1; r = u; } - r = mem[mem[r].b32.s1].b32.s1; - s = mem[mem[s].b32.s1].b32.s1; + r = mem(mem(r).b32.s1).b32.s1; + s = mem(mem(s).b32.s1).b32.s1; } while (!(r == TEX_NULL)); } else if (NODE_type(q) == RULE_NODE) { /*835: */ - if (mem[q + 1].b32.s1 == NULL_FLAG) - mem[q + 1].b32.s1 = mem[p + 1].b32.s1; - if (mem[q + 3].b32.s1 == NULL_FLAG) - mem[q + 3].b32.s1 = mem[p + 3].b32.s1; - if (mem[q + 2].b32.s1 == NULL_FLAG) - mem[q + 2].b32.s1 = mem[p + 2].b32.s1; + if (mem(q + 1).b32.s1 == NULL_FLAG) + mem_ptr(q + 1)->b32.s1 = mem(p + 1).b32.s1; + if (mem(q + 3).b32.s1 == NULL_FLAG) + mem_ptr(q + 3)->b32.s1 = mem(p + 3).b32.s1; + if (mem(q + 2).b32.s1 == NULL_FLAG) + mem_ptr(q + 2)->b32.s1 = mem(p + 2).b32.s1; if (o != 0) { - r = mem[q].b32.s1; - mem[q].b32.s1 = TEX_NULL; + r = mem(q).b32.s1; + mem_ptr(q)->b32.s1 = TEX_NULL; q = hpack(q, 0, ADDITIONAL); - mem[q + 4].b32.s1 = o; - mem[q].b32.s1 = r; - mem[s].b32.s1 = q; + mem_ptr(q + 4)->b32.s1 = o; + mem_ptr(q)->b32.s1 = r; + mem_ptr(s)->b32.s1 = q; } } } @@ -13526,7 +13306,7 @@ void fin_align(void) flush_node_list(p); pop_alignment(); aux_save = cur_list.aux; - p = mem[cur_list.head].b32.s1; + p = mem(cur_list.head).b32.s1; q = cur_list.tail; pop_nest(); if (cur_list.mode == MMODE) { /*1241: */ @@ -13557,22 +13337,22 @@ void fin_align(void) flush_node_list(cur_list.eTeX_aux); pop_nest(); { - mem[cur_list.tail].b32.s1 = new_penalty(INTPAR(pre_display_penalty)); + mem_ptr(cur_list.tail)->b32.s1 = new_penalty(INTPAR(pre_display_penalty)); cur_list.tail = LLIST_link(cur_list.tail); } { - mem[cur_list.tail].b32.s1 = new_param_glue(GLUE_PAR__above_display_skip); + mem_ptr(cur_list.tail)->b32.s1 = new_param_glue(GLUE_PAR__above_display_skip); cur_list.tail = LLIST_link(cur_list.tail); } - mem[cur_list.tail].b32.s1 = p; + mem_ptr(cur_list.tail)->b32.s1 = p; if (p != TEX_NULL) cur_list.tail = q; { - mem[cur_list.tail].b32.s1 = new_penalty(INTPAR(post_display_penalty)); + mem_ptr(cur_list.tail)->b32.s1 = new_penalty(INTPAR(post_display_penalty)); cur_list.tail = LLIST_link(cur_list.tail); } { - mem[cur_list.tail].b32.s1 = new_param_glue(GLUE_PAR__below_display_skip); + mem_ptr(cur_list.tail)->b32.s1 = new_param_glue(GLUE_PAR__below_display_skip); cur_list.tail = LLIST_link(cur_list.tail); } cur_list.aux.b32.s1 = aux_save.b32.s1; @@ -13580,7 +13360,7 @@ void fin_align(void) } else { cur_list.aux = aux_save; - mem[cur_list.tail].b32.s1 = p; + mem_ptr(cur_list.tail)->b32.s1 = p; if (p != TEX_NULL) cur_list.tail = q; if (cur_list.mode == VMODE) @@ -13783,7 +13563,7 @@ show_save_groups(void) break; case MATH_LEFT_GROUP: - if (mem[nest[p + 1].eTeX_aux].b16.s1 == LEFT_NOAD) + if (mem(nest[p + 1].eTeX_aux).b16.s1 == LEFT_NOAD) print_esc_cstr("left"); else print_esc_cstr("middle"); @@ -13874,17 +13654,17 @@ int32_t vert_break(int32_t p, scaled_t h, scaled_t d) if (p == TEX_NULL) pi = EJECT_PENALTY; else /*1008: */ - switch (mem[p].b16.s1) { + switch (mem(p).b16.s1) { case 0: case 1: case 2: - active_width[1] = active_width[1] + prev_dp + mem[p + 3].b32.s1; - prev_dp = mem[p + 2].b32.s1; + active_width[1] = active_width[1] + prev_dp + mem(p + 3).b32.s1; + prev_dp = mem(p + 2).b32.s1; goto not_found; case 8: - if ((mem[p].b16.s0 == PIC_NODE) || (mem[p].b16.s0 == PDF_NODE)) { - active_width[1] = active_width[1] + prev_dp + mem[p + 3].b32.s1; - prev_dp = mem[p + 2].b32.s1; + if ((mem(p).b16.s0 == PIC_NODE) || (mem(p).b16.s0 == PDF_NODE)) { + active_width[1] = active_width[1] + prev_dp + mem(p + 3).b32.s1; + prev_dp = mem(p + 2).b32.s1; } goto not_found; case 10: @@ -13895,10 +13675,10 @@ int32_t vert_break(int32_t p, scaled_t h, scaled_t d) goto update_heights; } case 11: - if (mem[p].b32.s1 == TEX_NULL) { + if (mem(p).b32.s1 == TEX_NULL) { t = PENALTY_NODE; } else { - t = mem[mem[p].b32.s1].b16.s1; + t = mem(mem(p).b32.s1).b16.s1; } if (t == GLUE_NODE) { pi = 0; @@ -13907,7 +13687,7 @@ int32_t vert_break(int32_t p, scaled_t h, scaled_t d) goto update_heights; } case 12: - pi = mem[p + 1].b32.s1; + pi = mem(p + 1).b32.s1; break; case 4: case 3: @@ -13952,10 +13732,10 @@ int32_t vert_break(int32_t p, scaled_t h, scaled_t d) q = p; else { - q = mem[p + 1].b32.s0; - active_width[2 + mem[q].b16.s1] = active_width[2 + mem[q].b16.s1] + mem[q + 2].b32.s1; - active_width[6] = active_width[6] + mem[q + 3].b32.s1; - if ((mem[q].b16.s0 != NORMAL) && (mem[q + 3].b32.s1 != 0)) { + q = mem(p + 1).b32.s0; + active_width[2 + mem(q).b16.s1] = active_width[2 + mem(q).b16.s1] + mem(q + 2).b32.s1; + active_width[6] = active_width[6] + mem(q + 3).b32.s1; + if ((mem(q).b16.s0 != NORMAL) && (mem(q + 3).b32.s1 != 0)) { error_here_with_diagnostic("Infinite glue shrinkage found in box being split"); capture_to_diagnostic(NULL); { @@ -13969,11 +13749,11 @@ int32_t vert_break(int32_t p, scaled_t h, scaled_t d) r = new_spec(q); GLUE_SPEC_shrink_order(r) = NORMAL; delete_glue_ref(q); - mem[p + 1].b32.s0 = r; + mem_ptr(p + 1)->b32.s0 = r; q = r; } } - active_width[1] = active_width[1] + prev_dp + mem[q + 1].b32.s1; + active_width[1] = active_width[1] + prev_dp + mem(q + 1).b32.s1; prev_dp = 0 /*:1011 */ ; not_found: if (prev_dp > d) { @@ -13981,7 +13761,7 @@ int32_t vert_break(int32_t p, scaled_t h, scaled_t d) prev_dp = d; } prev_p = p; - p = mem[prev_p].b32.s1; + p = mem(prev_p).b32.s1; } done: return best_place; @@ -14002,7 +13782,7 @@ int32_t vsplit(int32_t n, scaled_t h) if (cur_ptr == TEX_NULL) v = TEX_NULL; else - v = mem[cur_ptr + 1].b32.s1; + v = mem(cur_ptr + 1).b32.s1; } flush_node_list(disc_ptr[VSPLIT_CODE]); disc_ptr[VSPLIT_CODE] = TEX_NULL; @@ -14035,45 +13815,45 @@ int32_t vsplit(int32_t n, scaled_t h) error(); return TEX_NULL; } - q = vert_break(mem[v + 5].b32.s1, h, DIMENPAR(split_max_depth)); - p = mem[v + 5].b32.s1; + q = vert_break(mem(v + 5).b32.s1, h, DIMENPAR(split_max_depth)); + p = mem(v + 5).b32.s1; if (p == q) - mem[v + 5].b32.s1 = TEX_NULL; + mem_ptr(v + 5)->b32.s1 = TEX_NULL; else while (true) { if (NODE_type(p) == MARK_NODE) { - if (mem[p + 1].b32.s0 != 0) { /*1615: */ - find_sa_element(MARK_VAL, mem[p + 1].b32.s0, true); - if (mem[cur_ptr + 2].b32.s1 == TEX_NULL) { - mem[cur_ptr + 2].b32.s1 = mem[p + 1].b32.s1; - mem[mem[p + 1].b32.s1].b32.s0++; + if (mem(p + 1).b32.s0 != 0) { /*1615: */ + find_sa_element(MARK_VAL, mem(p + 1).b32.s0, true); + if (mem(cur_ptr + 2).b32.s1 == TEX_NULL) { + mem_ptr(cur_ptr + 2)->b32.s1 = mem(p + 1).b32.s1; + mem_ptr(mem(p + 1).b32.s1)->b32.s0++; } else - delete_token_ref(mem[cur_ptr + 3].b32.s0); - mem[cur_ptr + 3].b32.s0 = mem[p + 1].b32.s1; - mem[mem[p + 1].b32.s1].b32.s0++; + delete_token_ref(mem(cur_ptr + 3).b32.s0); + mem_ptr(cur_ptr + 3)->b32.s0 = mem(p + 1).b32.s1; + mem_ptr(mem(p + 1).b32.s1)->b32.s0++; } else if (cur_mark[SPLIT_FIRST_MARK_CODE] == TEX_NULL) { - cur_mark[SPLIT_FIRST_MARK_CODE] = mem[p + 1].b32.s1; + cur_mark[SPLIT_FIRST_MARK_CODE] = mem(p + 1).b32.s1; cur_mark[SPLIT_BOT_MARK_CODE] = cur_mark[SPLIT_FIRST_MARK_CODE]; - mem[cur_mark[SPLIT_FIRST_MARK_CODE]].b32.s0 = - mem[cur_mark[SPLIT_FIRST_MARK_CODE]].b32.s0 + 2; + mem_ptr(cur_mark[SPLIT_FIRST_MARK_CODE])->b32.s0 = + mem(cur_mark[SPLIT_FIRST_MARK_CODE]).b32.s0 + 2; } else { delete_token_ref(cur_mark[SPLIT_BOT_MARK_CODE]); - cur_mark[SPLIT_BOT_MARK_CODE] = mem[p + 1].b32.s1; - mem[cur_mark[SPLIT_BOT_MARK_CODE]].b32.s0++; + cur_mark[SPLIT_BOT_MARK_CODE] = mem(p + 1).b32.s1; + mem_ptr(cur_mark[SPLIT_BOT_MARK_CODE])->b32.s0++; } } - if (mem[p].b32.s1 == q) { - mem[p].b32.s1 = TEX_NULL; + if (mem(p).b32.s1 == q) { + mem_ptr(p)->b32.s1 = TEX_NULL; goto done; } p = LLIST_link(p); } /*:1014*/ done: q = prune_page_top(q, INTPAR(saving_vdiscards) > 0); - p = mem[v + 5].b32.s1; + p = mem(v + 5).b32.s1; free_node(v, BOX_NODE_SIZE); if (q != TEX_NULL) q = vpackage(q, 0, ADDITIONAL, MAX_HALFWORD); @@ -14083,8 +13863,8 @@ int32_t vsplit(int32_t n, scaled_t h) find_sa_element(4, cur_val, false); if (cur_ptr != TEX_NULL) { - mem[cur_ptr + 1].b32.s1 = q; - mem[cur_ptr + 1].b32.s0++; + mem_ptr(cur_ptr + 1)->b32.s1 = q; + mem_ptr(cur_ptr + 1)->b32.s0++; delete_sa_ref(cur_ptr); } } @@ -14150,27 +13930,27 @@ void app_space(void) main_p = GLUEPAR(space_skip); else { /*1077: */ - main_p = font_glue[eqtb[CUR_FONT_LOC].b32.s1]; + main_p = font_glue[eqtb_ptr(CUR_FONT_LOC)->b32.s1]; if (main_p == TEX_NULL) { main_p = new_spec(0); - main_k = param_base[eqtb[CUR_FONT_LOC].b32.s1] + 2; - mem[main_p + 1].b32.s1 = font_info[main_k].b32.s1; - mem[main_p + 2].b32.s1 = font_info[main_k + 1].b32.s1; - mem[main_p + 3].b32.s1 = font_info[main_k + 2].b32.s1; - font_glue[eqtb[CUR_FONT_LOC].b32.s1] = main_p; + main_k = param_base[eqtb_ptr(CUR_FONT_LOC)->b32.s1] + 2; + mem_ptr(main_p + 1)->b32.s1 = font_info[main_k].b32.s1; + mem_ptr(main_p + 2)->b32.s1 = font_info[main_k + 1].b32.s1; + mem_ptr(main_p + 3)->b32.s1 = font_info[main_k + 2].b32.s1; + font_glue[eqtb_ptr(CUR_FONT_LOC)->b32.s1] = main_p; } } main_p = new_spec(main_p); if (cur_list.aux.b32.s0 >= 2000) - mem[main_p + 1].b32.s1 = - mem[main_p + 1].b32.s1 + font_info[EXTRA_SPACE_CODE + - param_base[eqtb[CUR_FONT_LOC].b32.s1]].b32.s1; - mem[main_p + 2].b32.s1 = xn_over_d(mem[main_p + 2].b32.s1, cur_list.aux.b32.s0, 1000); - mem[main_p + 3].b32.s1 = xn_over_d(mem[main_p + 3].b32.s1, 1000, cur_list.aux.b32.s0) /*:1079 */ ; + mem_ptr(main_p + 1)->b32.s1 = + mem(main_p + 1).b32.s1 + font_info[EXTRA_SPACE_CODE + + param_base[eqtb_ptr(CUR_FONT_LOC)->b32.s1]].b32.s1; + mem_ptr(main_p + 2)->b32.s1 = xn_over_d(mem(main_p + 2).b32.s1, cur_list.aux.b32.s0, 1000); + mem_ptr(main_p + 3)->b32.s1 = xn_over_d(mem(main_p + 3).b32.s1, 1000, cur_list.aux.b32.s0) /*:1079 */ ; q = new_glue(main_p); - mem[main_p].b32.s1 = TEX_NULL; + mem_ptr(main_p)->b32.s1 = TEX_NULL; } - mem[cur_list.tail].b32.s1 = q; + mem_ptr(cur_list.tail)->b32.s1 = q; cur_list.tail = q; } @@ -14229,16 +14009,16 @@ bool its_all_over(void) } back_input(); { - mem[cur_list.tail].b32.s1 = new_null_box(); + mem_ptr(cur_list.tail)->b32.s1 = new_null_box(); cur_list.tail = LLIST_link(cur_list.tail); } - mem[cur_list.tail + 1].b32.s1 = DIMENPAR(hsize); + mem_ptr(cur_list.tail + 1)->b32.s1 = DIMENPAR(hsize); { - mem[cur_list.tail].b32.s1 = new_glue(8); + mem_ptr(cur_list.tail)->b32.s1 = new_glue(8); cur_list.tail = LLIST_link(cur_list.tail); } { - mem[cur_list.tail].b32.s1 = new_penalty(NULL_FLAG); + mem_ptr(cur_list.tail)->b32.s1 = new_penalty(NULL_FLAG); cur_list.tail = LLIST_link(cur_list.tail); } build_page(); @@ -14271,13 +14051,13 @@ void append_glue(void) break; } { - mem[cur_list.tail].b32.s1 = new_glue(cur_val); + mem_ptr(cur_list.tail)->b32.s1 = new_glue(cur_val); cur_list.tail = LLIST_link(cur_list.tail); } if (s >= SKIP_CODE) { - mem[cur_val].b32.s1--; + mem_ptr(cur_val)->b32.s1--; if (s > SKIP_CODE) - mem[cur_list.tail].b16.s0 = MU_GLUE; + mem_ptr(cur_list.tail)->b16.s0 = MU_GLUE; } } @@ -14287,10 +14067,10 @@ void append_kern(void) s = cur_chr; scan_dimen(s == MU_GLUE, false, false); { - mem[cur_list.tail].b32.s1 = new_kern(cur_val); + mem_ptr(cur_list.tail)->b32.s1 = new_kern(cur_val); cur_list.tail = LLIST_link(cur_list.tail); } - mem[cur_list.tail].b16.s0 = s; + mem_ptr(cur_list.tail)->b16.s0 = s; } @@ -14310,34 +14090,34 @@ off_save(void) } else { back_input(); p = get_avail(); - mem[TEMP_HEAD].b32.s1 = p; + mem_ptr(TEMP_HEAD)->b32.s1 = p; error_here_with_diagnostic("Missing "); switch (cur_group) { case SEMI_SIMPLE_GROUP: - mem[p].b32.s0 = CS_TOKEN_FLAG + FROZEN_END_GROUP; + mem_ptr(p)->b32.s0 = CS_TOKEN_FLAG + FROZEN_END_GROUP; print_esc_cstr("endgroup"); break; case MATH_SHIFT_GROUP: - mem[p].b32.s0 = MATH_SHIFT_TOKEN + '$' ; + mem_ptr(p)->b32.s0 = MATH_SHIFT_TOKEN + '$' ; print_char('$'); break; case MATH_LEFT_GROUP: - mem[p].b32.s0 = CS_TOKEN_FLAG + FROZEN_RIGHT; - mem[p].b32.s1 = get_avail(); + mem_ptr(p)->b32.s0 = CS_TOKEN_FLAG + FROZEN_RIGHT; + mem_ptr(p)->b32.s1 = get_avail(); p = LLIST_link(p); - mem[p].b32.s0 = OTHER_TOKEN + '.' ; + mem_ptr(p)->b32.s0 = OTHER_TOKEN + '.' ; print_esc_cstr("right."); break; default: - mem[p].b32.s0 = (RIGHT_BRACE_TOKEN + '}' ); + mem_ptr(p)->b32.s0 = (RIGHT_BRACE_TOKEN + '}' ); print_char('}'); break; } print_cstr(" inserted"); - begin_token_list(mem[TEMP_HEAD].b32.s1, INSERTED); + begin_token_list(mem(TEMP_HEAD).b32.s1, INSERTED); capture_to_diagnostic(NULL); help_ptr = 5; @@ -14411,12 +14191,12 @@ box_end(int32_t box_context) if (box_context < BOX_FLAG) { /*1111:*/ if (cur_box != TEX_NULL) { - mem[cur_box + 4].b32.s1 = box_context; + mem_ptr(cur_box + 4)->b32.s1 = box_context; if (abs(cur_list.mode) == VMODE) { if (pre_adjust_tail != TEX_NULL) { if (PRE_ADJUST_HEAD != pre_adjust_tail) { - mem[cur_list.tail].b32.s1 = mem[PRE_ADJUST_HEAD].b32.s1; + mem_ptr(cur_list.tail)->b32.s1 = mem(PRE_ADJUST_HEAD).b32.s1; cur_list.tail = pre_adjust_tail; } pre_adjust_tail = TEX_NULL; @@ -14426,7 +14206,7 @@ box_end(int32_t box_context) if (adjust_tail != TEX_NULL) { if (ADJUST_HEAD != adjust_tail) { - mem[cur_list.tail].b32.s1 = mem[ADJUST_HEAD].b32.s1; + mem_ptr(cur_list.tail)->b32.s1 = mem(ADJUST_HEAD).b32.s1; cur_list.tail = adjust_tail; } adjust_tail = TEX_NULL; @@ -14439,12 +14219,12 @@ box_end(int32_t box_context) cur_list.aux.b32.s0 = 1000; } else { p = new_noad(); - mem[p + 1].b32.s1 = SUB_BOX; - mem[p + 1].b32.s0 = cur_box; + mem_ptr(p + 1)->b32.s1 = SUB_BOX; + mem_ptr(p + 1)->b32.s0 = cur_box; cur_box = p; } - mem[cur_list.tail].b32.s1 = cur_box; + mem_ptr(cur_list.tail)->b32.s1 = cur_box; cur_list.tail = cur_box; } } @@ -14477,8 +14257,8 @@ box_end(int32_t box_context) if ((cur_cmd == HSKIP && abs(cur_list.mode) != VMODE) || (cur_cmd == VSKIP && abs(cur_list.mode) == VMODE)) { append_glue(); - mem[cur_list.tail].b16.s0 = box_context - (LEADER_FLAG - A_LEADERS); - mem[cur_list.tail + 1].b32.s1 = cur_box; + mem_ptr(cur_list.tail)->b16.s0 = box_context - (LEADER_FLAG - A_LEADERS); + mem_ptr(cur_list.tail + 1)->b32.s1 = cur_box; } else { error_here_with_diagnostic("Leaders not followed by proper glue"); capture_to_diagnostic(NULL); @@ -14519,7 +14299,7 @@ begin_box(int32_t box_context) if (cur_ptr == TEX_NULL) cur_box = TEX_NULL; else - cur_box = mem[cur_ptr + 1].b32.s1; + cur_box = mem(cur_ptr + 1).b32.s1; } if (cur_val < 256) { @@ -14527,8 +14307,8 @@ begin_box(int32_t box_context) } else { find_sa_element(4, cur_val, false); if (cur_ptr != TEX_NULL) { - mem[cur_ptr + 1].b32.s1 = TEX_NULL; - mem[cur_ptr + 1].b32.s0++; + mem_ptr(cur_ptr + 1)->b32.s1 = TEX_NULL; + mem_ptr(cur_ptr + 1)->b32.s0++; delete_sa_ref(cur_ptr); } } @@ -14544,7 +14324,7 @@ begin_box(int32_t box_context) if (cur_ptr == TEX_NULL) q = TEX_NULL; else - q = mem[cur_ptr + 1].b32.s1; + q = mem(cur_ptr + 1).b32.s1; } cur_box = copy_node_list(q); @@ -14568,11 +14348,11 @@ begin_box(int32_t box_context) tx = cur_list.tail; if (tx < hi_mem_min) { - if (NODE_type(tx) == MATH_NODE && mem[tx].b16.s0 == END_M_CODE) { + if (NODE_type(tx) == MATH_NODE && mem(tx).b16.s0 == END_M_CODE) { r = cur_list.head; do { q = r; - r = mem[q].b32.s1; + r = mem(q).b32.s1; } while (r != tx); tx = q; } @@ -14590,22 +14370,22 @@ begin_box(int32_t box_context) if (q < hi_mem_min) { if (NODE_type(q) == DISC_NODE) { - for (m = 1; m <= mem[q].b16.s0; m++) + for (m = 1; m <= mem(q).b16.s0; m++) p = LLIST_link(p); if (p == tx) goto done; - } else if (NODE_type(q) == MATH_NODE && mem[q].b16.s0 == BEGIN_M_CODE) { + } else if (NODE_type(q) == MATH_NODE && mem(q).b16.s0 == BEGIN_M_CODE) { fm = true; } } - q = mem[p].b32.s1; + q = mem(p).b32.s1; } while (q != tx); - q = mem[tx].b32.s1; - mem[p].b32.s1 = q; - mem[tx].b32.s1 = TEX_NULL; + q = mem(tx).b32.s1; + mem_ptr(p)->b32.s1 = q; + mem_ptr(tx)->b32.s1 = TEX_NULL; if (q == TEX_NULL) { if (fm) @@ -14614,12 +14394,12 @@ begin_box(int32_t box_context) cur_list.tail = p; } else if (fm) { cur_list.tail = r; - mem[r].b32.s1 = TEX_NULL; + mem_ptr(r)->b32.s1 = TEX_NULL; flush_node_list(p); } cur_box = tx; - mem[cur_box + 4].b32.s1 = 0; + mem_ptr(cur_box + 4)->b32.s1 = 0; } } done: @@ -14722,21 +14502,21 @@ void package(small_number c) v = INTPAR(xetex_upwards); INTPAR(xetex_upwards) = u; if (cur_list.mode == -104) - cur_box = hpack(mem[cur_list.head].b32.s1, save_stack[save_ptr + 2].b32.s1, save_stack[save_ptr + 1].b32.s1); + cur_box = hpack(mem(cur_list.head).b32.s1, save_stack[save_ptr + 2].b32.s1, save_stack[save_ptr + 1].b32.s1); else { cur_box = - vpackage(mem[cur_list.head].b32.s1, save_stack[save_ptr + 2].b32.s1, save_stack[save_ptr + 1].b32.s1, d); + vpackage(mem(cur_list.head).b32.s1, save_stack[save_ptr + 2].b32.s1, save_stack[save_ptr + 1].b32.s1, d); if (c == VTOP_CODE) { /*1122: */ h = 0; - p = mem[cur_box + 5].b32.s1; + p = mem(cur_box + 5).b32.s1; if (p != TEX_NULL) { if (NODE_type(p) <= RULE_NODE) - h = mem[p + 3].b32.s1; + h = mem(p + 3).b32.s1; } - mem[cur_box + 2].b32.s1 = mem[cur_box + 2].b32.s1 - h + mem[cur_box + 3].b32.s1; - mem[cur_box + 3].b32.s1 = h; + mem_ptr(cur_box + 2)->b32.s1 = mem(cur_box + 2).b32.s1 - h + mem(cur_box + 3).b32.s1; + mem_ptr(cur_box + 3)->b32.s1 = h; } } INTPAR(xetex_upwards) = v; @@ -14761,7 +14541,7 @@ new_graf(bool indented) cur_list.prev_graf = 0; if (cur_list.mode == VMODE || cur_list.head != cur_list.tail) { - mem[cur_list.tail].b32.s1 = new_param_glue(GLUE_PAR__par_skip); + mem_ptr(cur_list.tail)->b32.s1 = new_param_glue(GLUE_PAR__par_skip); cur_list.tail = LLIST_link(cur_list.tail); } @@ -14783,8 +14563,8 @@ new_graf(bool indented) if (indented) { cur_list.tail = new_null_box(); - mem[cur_list.head].b32.s1 = cur_list.tail; - mem[cur_list.tail + 1].b32.s1 = eqtb[DIMEN_BASE].b32.s1; + mem_ptr(cur_list.head)->b32.s1 = cur_list.tail; + mem_ptr(cur_list.tail + 1)->b32.s1 = eqtb_ptr(DIMEN_BASE)->b32.s1; if (insert_src_special_every_par) insert_src_special(); } @@ -14802,18 +14582,18 @@ void indent_in_hmode(void) if (cur_chr > 0) { p = new_null_box(); - mem[p + 1].b32.s1 = eqtb[DIMEN_BASE].b32.s1; + mem_ptr(p + 1)->b32.s1 = eqtb_ptr(DIMEN_BASE)->b32.s1; if (abs(cur_list.mode) == HMODE) cur_list.aux.b32.s0 = 1000; else { q = new_noad(); - mem[q + 1].b32.s1 = SUB_BOX; - mem[q + 1].b32.s0 = p; + mem_ptr(q + 1)->b32.s1 = SUB_BOX; + mem_ptr(q + 1)->b32.s0 = p; p = q; } { - mem[cur_list.tail].b32.s1 = p; + mem_ptr(cur_list.tail)->b32.s1 = p; cur_list.tail = LLIST_link(cur_list.tail); } } @@ -14843,7 +14623,7 @@ void head_for_vmode(void) back_input(); cur_tok = par_token; back_input(); - cur_input.index = INSERTED; + cur_input_ptr()->index = INSERTED; } } @@ -14914,11 +14694,11 @@ void make_mark(void) } p = scan_toks(false, true); p = get_node(SMALL_NODE_SIZE); - mem[p + 1].b32.s0 = c; + mem_ptr(p + 1)->b32.s0 = c; NODE_type(p) = MARK_NODE; - mem[p].b16.s0 = 0; - mem[p + 1].b32.s1 = def_ref; - mem[cur_list.tail].b32.s1 = p; + mem_ptr(p)->b16.s0 = 0; + mem_ptr(p + 1)->b32.s1 = def_ref; + mem_ptr(cur_list.tail)->b32.s1 = p; cur_list.tail = p; } @@ -14926,7 +14706,7 @@ void append_penalty(void) { scan_int(); { - mem[cur_list.tail].b32.s1 = new_penalty(cur_val); + mem_ptr(cur_list.tail)->b32.s1 = new_penalty(cur_val); cur_list.tail = LLIST_link(cur_list.tail); } if (cur_list.mode == VMODE) @@ -14959,18 +14739,18 @@ void delete_last(void) tx = cur_list.tail; if (!(is_char_node(tx))) { - if ((NODE_type(tx) == MATH_NODE) && (mem[tx].b16.s0 == END_M_CODE)) { + if ((NODE_type(tx) == MATH_NODE) && (mem(tx).b16.s0 == END_M_CODE)) { r = cur_list.head; do { q = r; - r = mem[q].b32.s1; + r = mem(q).b32.s1; } while (!(r == tx)); tx = q; } } if (!(is_char_node(tx))) { - if (mem[tx].b16.s1 == cur_chr) { + if (mem(tx).b16.s1 == cur_chr) { q = cur_list.head; p = TEX_NULL; do { @@ -14983,7 +14763,7 @@ void delete_last(void) { register int32_t for_end; m = 1; - for_end = mem[q].b16.s0; + for_end = mem(q).b16.s0; if (m <= for_end) do p = LLIST_link(p); @@ -14991,14 +14771,14 @@ void delete_last(void) } if (p == tx) return; - } else if ((NODE_type(q) == MATH_NODE) && (mem[q].b16.s0 == BEGIN_M_CODE)) + } else if ((NODE_type(q) == MATH_NODE) && (mem(q).b16.s0 == BEGIN_M_CODE)) fm = true; } - q = mem[p].b32.s1; + q = mem(p).b32.s1; } while (!(q == tx)); - q = mem[tx].b32.s1; - mem[p].b32.s1 = q; - mem[tx].b32.s1 = TEX_NULL; + q = mem(tx).b32.s1; + mem_ptr(p)->b32.s1 = q; + mem_ptr(tx)->b32.s1 = TEX_NULL; if (q == TEX_NULL) { if (fm) @@ -15007,7 +14787,7 @@ void delete_last(void) cur_list.tail = p; } else if (fm) { cur_list.tail = r; - mem[r].b32.s1 = TEX_NULL; + mem_ptr(r)->b32.s1 = TEX_NULL; flush_node_list(p); } flush_node_list(tx); @@ -15023,7 +14803,7 @@ void unpackage(void) unsigned char /*copy_code */ c; if (cur_chr > COPY_CODE) { /*1651: */ - mem[cur_list.tail].b32.s1 = disc_ptr[cur_chr]; + mem_ptr(cur_list.tail)->b32.s1 = disc_ptr[cur_chr]; disc_ptr[cur_chr] = TEX_NULL; goto done; } @@ -15037,7 +14817,7 @@ void unpackage(void) if (cur_ptr == TEX_NULL) p = TEX_NULL; else - p = mem[cur_ptr + 1].b32.s1; + p = mem(cur_ptr + 1).b32.s1; } if (p == TEX_NULL) return; @@ -15056,29 +14836,29 @@ void unpackage(void) return; } if (c == COPY_CODE) - mem[cur_list.tail].b32.s1 = copy_node_list(mem[p + 5].b32.s1); + mem_ptr(cur_list.tail)->b32.s1 = copy_node_list(mem(p + 5).b32.s1); else { - mem[cur_list.tail].b32.s1 = mem[p + 5].b32.s1; + mem_ptr(cur_list.tail)->b32.s1 = mem(p + 5).b32.s1; if (cur_val < 256) BOX_REG(cur_val) = TEX_NULL; else { find_sa_element(4, cur_val, false); if (cur_ptr != TEX_NULL) { - mem[cur_ptr + 1].b32.s1 = TEX_NULL; - mem[cur_ptr + 1].b32.s0++; + mem_ptr(cur_ptr + 1)->b32.s1 = TEX_NULL; + mem_ptr(cur_ptr + 1)->b32.s0++; delete_sa_ref(cur_ptr); } } free_node(p, BOX_NODE_SIZE); } done: - while (mem[cur_list.tail].b32.s1 != TEX_NULL) { + while (mem(cur_list.tail).b32.s1 != TEX_NULL) { - r = mem[cur_list.tail].b32.s1; + r = mem(cur_list.tail).b32.s1; if (!(is_char_node(r)) && (NODE_type(r) == MARGIN_KERN_NODE)) { - mem[cur_list.tail].b32.s1 = mem[r].b32.s1; + mem_ptr(cur_list.tail)->b32.s1 = mem(r).b32.s1; free_node(r, MARGIN_KERN_NODE_SIZE); } cur_list.tail = LLIST_link(cur_list.tail); @@ -15095,16 +14875,16 @@ void append_italic_correction(void) else if (NODE_type(cur_list.tail) == LIGATURE_NODE) p = cur_list.tail + 1; else if (NODE_type(cur_list.tail) == WHATSIT_NODE) { - if ((mem[cur_list.tail].b16.s0 == NATIVE_WORD_NODE) - || (mem[cur_list.tail].b16.s0 == NATIVE_WORD_NODE_AT)) { + if ((mem(cur_list.tail).b16.s0 == NATIVE_WORD_NODE) + || (mem(cur_list.tail).b16.s0 == NATIVE_WORD_NODE_AT)) { { - mem[cur_list.tail].b32.s1 = new_kern(get_native_italic_correction(cur_list.tail)); + mem_ptr(cur_list.tail)->b32.s1 = new_kern(get_native_italic_correction(cur_list.tail)); cur_list.tail = LLIST_link(cur_list.tail); } NODE_subtype(cur_list.tail) = EXPLICIT; - } else if (mem[cur_list.tail].b16.s0 == GLYPH_NODE) { + } else if (mem(cur_list.tail).b16.s0 == GLYPH_NODE) { { - mem[cur_list.tail].b32.s1 = + mem_ptr(cur_list.tail)->b32.s1 = new_kern(get_native_glyph_italic_correction(cur_list.tail)); cur_list.tail = LLIST_link(cur_list.tail); } @@ -15115,7 +14895,7 @@ void append_italic_correction(void) return; f = CHAR_NODE_font(p); { - mem[cur_list.tail].b32.s1 = + mem_ptr(cur_list.tail)->b32.s1 = new_kern(FONT_CHARINFO_ITALCORR(f, FONT_CHARACTER_INFO(f, effective_char(true, f, CHAR_NODE_character(p))))); cur_list.tail = LLIST_link(cur_list.tail); } @@ -15127,15 +14907,15 @@ void append_discretionary(void) { int32_t c; - mem[cur_list.tail].b32.s1 = new_disc(); + mem_ptr(cur_list.tail)->b32.s1 = new_disc(); cur_list.tail = LLIST_link(cur_list.tail); if (cur_chr == 1) { - c = hyphen_char[eqtb[CUR_FONT_LOC].b32.s1]; + c = hyphen_char[eqtb_ptr(CUR_FONT_LOC)->b32.s1]; if (c >= 0) { if (c <= BIGGEST_CHAR) - mem[cur_list.tail + 1].b32.s0 = new_character(eqtb[CUR_FONT_LOC].b32.s1, c); + mem_ptr(cur_list.tail + 1)->b32.s0 = new_character(eqtb_ptr(CUR_FONT_LOC)->b32.s1, c); } } else { @@ -15155,7 +14935,7 @@ void build_discretionary(void) int32_t n; unsave(); q = cur_list.head; - p = mem[q].b32.s1; + p = mem(q).b32.s1; n = 0; while (p != TEX_NULL) { @@ -15168,9 +14948,9 @@ void build_discretionary(void) if (NODE_type(p) != LIGATURE_NODE) { if ((NODE_type(p) != WHATSIT_NODE) - || ((mem[p].b16.s0 != NATIVE_WORD_NODE) - && (mem[p].b16.s0 != NATIVE_WORD_NODE_AT) - && (mem[p].b16.s0 != GLYPH_NODE))) { + || ((mem(p).b16.s0 != NATIVE_WORD_NODE) + && (mem(p).b16.s0 != NATIVE_WORD_NODE_AT) + && (mem(p).b16.s0 != GLYPH_NODE))) { error_here_with_diagnostic("Improper discretionary list"); capture_to_diagnostic(NULL); { @@ -15188,7 +14968,7 @@ void build_discretionary(void) capture_to_diagnostic(NULL); end_diagnostic(true); flush_node_list(p); - mem[q].b32.s1 = TEX_NULL; + mem_ptr(q)->b32.s1 = TEX_NULL; goto done; } } @@ -15196,18 +14976,18 @@ void build_discretionary(void) } } q = p; - p = mem[q].b32.s1; + p = mem(q).b32.s1; n++; } /*:1156 */ done: - p = mem[cur_list.head].b32.s1; + p = mem(cur_list.head).b32.s1; pop_nest(); switch (save_stack[save_ptr - 1].b32.s1) { case 0: - mem[cur_list.tail + 1].b32.s0 = p; + mem_ptr(cur_list.tail + 1)->b32.s0 = p; break; case 1: - mem[cur_list.tail + 1].b32.s1 = p; + mem_ptr(cur_list.tail + 1)->b32.s1 = p; break; case 2: { @@ -15225,9 +15005,9 @@ void build_discretionary(void) n = 0; error(); } else - mem[cur_list.tail].b32.s1 = p; + mem_ptr(cur_list.tail)->b32.s1 = p; if (n <= UINT16_MAX) - mem[cur_list.tail].b16.s0 = n; + mem_ptr(cur_list.tail)->b16.s0 = n; else { error_here_with_diagnostic("Discretionary list is too long"); capture_to_diagnostic(NULL); @@ -15263,14 +15043,14 @@ void make_accent(void) b16x4 i; scan_char_num(); - f = eqtb[CUR_FONT_LOC].b32.s1; + f = eqtb_ptr(CUR_FONT_LOC)->b32.s1; p = new_character(f, cur_val); if (p != TEX_NULL) { x = font_info[X_HEIGHT_CODE + param_base[f]].b32.s1; s = font_info[SLANT_CODE + param_base[f]].b32.s1 / ((double)65536.0); if (((font_area[f] == AAT_FONT_FLAG) || (font_area[f] == OTGR_FONT_FLAG))) { - a = mem[p + 1].b32.s1; + a = mem(p + 1).b32.s1; if (a == 0) get_native_char_sidebearings(f, cur_val, &lsb, &rsb); } else @@ -15278,7 +15058,7 @@ void make_accent(void) effective_char(true, f, CHAR_NODE_character(p))); do_assignments(); q = TEX_NULL; - f = eqtb[CUR_FONT_LOC].b32.s1; + f = eqtb_ptr(CUR_FONT_LOC)->b32.s1; if ((cur_cmd == LETTER) || (cur_cmd == OTHER_CHAR) || (cur_cmd == CHAR_GIVEN)) { q = new_character(f, cur_chr); cur_val = cur_chr; @@ -15290,7 +15070,7 @@ void make_accent(void) if (q != TEX_NULL) { /*1160: */ t = font_info[SLANT_CODE + param_base[f]].b32.s1 / ((double)65536.0); if (((font_area[f] == AAT_FONT_FLAG) || (font_area[f] == OTGR_FONT_FLAG))) { - w = mem[q + 1].b32.s1; + w = mem(q + 1).b32.s1; get_native_char_height_depth(f, cur_val, &h, &delta); } else { @@ -15300,7 +15080,7 @@ void make_accent(void) } if (h != x) { p = hpack(p, 0, ADDITIONAL); - mem[p + 4].b32.s1 = x - h; + mem_ptr(p + 4)->b32.s1 = x - h; } if (((font_area[f] == AAT_FONT_FLAG) || (font_area[f] == OTGR_FONT_FLAG)) && (a == 0)) @@ -15309,14 +15089,14 @@ void make_accent(void) delta = tex_round((w - a) / ((double)2.0) + h * t - x * s); r = new_kern(delta); NODE_subtype(r) = ACC_KERN; - mem[cur_list.tail].b32.s1 = r; - mem[r].b32.s1 = p; + mem_ptr(cur_list.tail)->b32.s1 = r; + mem_ptr(r)->b32.s1 = p; cur_list.tail = new_kern(-(int32_t) a - delta); NODE_subtype(cur_list.tail) = ACC_KERN; - mem[p].b32.s1 = cur_list.tail; + mem_ptr(p)->b32.s1 = cur_list.tail; p = q; } - mem[cur_list.tail].b32.s1 = p; + mem_ptr(cur_list.tail)->b32.s1 = p; cur_list.tail = p; cur_list.aux.b32.s0 = 1000; } @@ -15405,13 +15185,13 @@ void omit_error(void) void do_endv(void) { - base_ptr = input_ptr; - input_stack[base_ptr] = cur_input; - while ((input_stack[base_ptr].index != V_TEMPLATE) && (input_stack[base_ptr].loc == TEX_NULL) - && (input_stack[base_ptr].state == TOKEN_LIST)) + base_ptr = input_ptr(); + set_input_stack(base_ptr, cur_input()); + while ((input_stack(base_ptr).index != V_TEMPLATE) && (input_stack(base_ptr).loc == TEX_NULL) + && (input_stack(base_ptr).state == TOKEN_LIST)) base_ptr--; - if ((input_stack[base_ptr].index != V_TEMPLATE) || (input_stack[base_ptr].loc != TEX_NULL) - || (input_stack[base_ptr].state != TOKEN_LIST)) + if ((input_stack(base_ptr).index != V_TEMPLATE) || (input_stack(base_ptr).loc != TEX_NULL) + || (input_stack(base_ptr).state != TOKEN_LIST)) fatal_error("(interwoven alignment preambles are not allowed)"); if (cur_group == ALIGN_GROUP) { end_graf(); @@ -15460,8 +15240,8 @@ just_copy(int32_t p, int32_t h, int32_t t) r = get_node(BOX_NODE_SIZE); SYNCTEX_tag(r, BOX_NODE_SIZE) = SYNCTEX_tag(p, BOX_NODE_SIZE); SYNCTEX_line(r, BOX_NODE_SIZE) = SYNCTEX_line(p, BOX_NODE_SIZE); - mem[r + 6] = mem[p + 6]; - mem[r + 5] = mem[p + 5]; + set_mem(r + 6, mem(p + 6)); + set_mem(r + 5, mem(p + 5)); words = 5; BOX_list_ptr(r) = TEX_NULL; break; @@ -15473,7 +15253,7 @@ just_copy(int32_t p, int32_t h, int32_t t) case LIGATURE_NODE: r = get_avail(); - mem[r] = mem[p + 1]; + set_mem(r, mem(p + 1)); goto found; break; @@ -15519,7 +15299,7 @@ just_copy(int32_t p, int32_t h, int32_t t) while (words > 0) { words--; - mem[r + words] = mem[p + words]; + set_mem(r + words, mem(p + words)); } NATIVE_NODE_glyph_info_ptr(r) = NULL; @@ -15555,7 +15335,7 @@ just_copy(int32_t p, int32_t h, int32_t t) while (words > 0) { words--; - mem[r + words] = mem[p + words]; + set_mem(r + words, mem(p + words)); } found: @@ -15577,14 +15357,14 @@ void just_reverse(int32_t p) int32_t m, n; m = MIN_HALFWORD; n = MIN_HALFWORD; - if (mem[TEMP_HEAD].b32.s1 == TEX_NULL) { - just_copy(mem[p].b32.s1, TEMP_HEAD, TEX_NULL); - q = mem[TEMP_HEAD].b32.s1; + if (mem(TEMP_HEAD).b32.s1 == TEX_NULL) { + just_copy(mem(p).b32.s1, TEMP_HEAD, TEX_NULL); + q = mem(TEMP_HEAD).b32.s1; } else { - q = mem[p].b32.s1; - mem[p].b32.s1 = TEX_NULL; - flush_node_list(mem[TEMP_HEAD].b32.s1); + q = mem(p).b32.s1; + mem_ptr(p)->b32.s1 = TEX_NULL; + flush_node_list(mem(TEMP_HEAD).b32.s1); } t = new_edge(cur_dir, 0); l = t; @@ -15593,42 +15373,42 @@ void just_reverse(int32_t p) if ((is_char_node(q))) do { p = q; - q = mem[p].b32.s1; - mem[p].b32.s1 = l; + q = mem(p).b32.s1; + mem_ptr(p)->b32.s1 = l; l = p; } while (!(!(is_char_node(q)))); else { p = q; - q = mem[p].b32.s1; + q = mem(p).b32.s1; if (NODE_type(p) == MATH_NODE) { /*1527: */ - if (odd(mem[p].b16.s0)) { + if (odd(mem(p).b16.s0)) { - if (mem[LR_ptr].b32.s0 != (L_CODE * (mem[p].b16.s0 / L_CODE) + 3)) { + if (mem(LR_ptr).b32.s0 != (L_CODE * (mem(p).b16.s0 / L_CODE) + 3)) { NODE_type(p) = KERN_NODE; LR_problems++; } else { { temp_ptr = LR_ptr; - LR_ptr = mem[temp_ptr].b32.s1; + LR_ptr = mem(temp_ptr).b32.s1; { - mem[temp_ptr].b32.s1 = avail; + mem_ptr(temp_ptr)->b32.s1 = avail; avail = temp_ptr; } } if (n > MIN_HALFWORD) { n--; - mem[p].b16.s0--; + mem_ptr(p)->b16.s0--; } else { if (m > MIN_HALFWORD) m--; else { - mem[t + 1].b32.s1 = mem[p + 1].b32.s1; - mem[t].b32.s1 = q; + mem_ptr(t + 1)->b32.s1 = mem(p + 1).b32.s1; + mem_ptr(t)->b32.s1 = q; free_node(p, MEDIUM_NODE_SIZE); goto done; } @@ -15639,13 +15419,13 @@ void just_reverse(int32_t p) { temp_ptr = get_avail(); - mem[temp_ptr].b32.s0 = (L_CODE * (mem[p].b16.s0 / L_CODE) + 3); - mem[temp_ptr].b32.s1 = LR_ptr; + mem_ptr(temp_ptr)->b32.s0 = (L_CODE * (mem(p).b16.s0 / L_CODE) + 3); + mem_ptr(temp_ptr)->b32.s1 = LR_ptr; LR_ptr = temp_ptr; } - if ((n > MIN_HALFWORD) || ((mem[p].b16.s0 / R_CODE) != cur_dir)) { + if ((n > MIN_HALFWORD) || ((mem(p).b16.s0 / R_CODE) != cur_dir)) { n++; - mem[p].b16.s0++; + mem_ptr(p)->b16.s0++; } else { NODE_type(p) = KERN_NODE; @@ -15653,15 +15433,15 @@ void just_reverse(int32_t p) } } } - mem[p].b32.s1 = l; + mem_ptr(p)->b32.s1 = l; l = p; } goto done; - mem[t + 1].b32.s1 = mem[p + 1].b32.s1; - mem[t].b32.s1 = q; + mem_ptr(t + 1)->b32.s1 = mem(p + 1).b32.s1; + mem_ptr(t)->b32.s1 = q; free_node(p, SMALL_NODE_SIZE); done: - mem[TEMP_HEAD].b32.s1 = l; + mem_ptr(TEMP_HEAD)->b32.s1 = l; } @@ -15673,7 +15453,7 @@ get_r_token(void) get_token(); } while (cur_tok == SPACE_TOKEN); - if (cur_cs == 0 || cur_cs > eqtb_top || (cur_cs > FROZEN_CONTROL_SEQUENCE && cur_cs <= EQTB_SIZE)) { + if (cur_cs == 0 || cur_cs > eqtb_top() || (cur_cs > FROZEN_CONTROL_SEQUENCE && cur_cs <= EQTB_SIZE)) { error_here_with_diagnostic("Missing control sequence inserted"); capture_to_diagnostic(NULL); @@ -15697,7 +15477,7 @@ get_r_token(void) void trap_zero_glue(void) { - if ((mem[cur_val + 1].b32.s1 == 0) && (mem[cur_val + 2].b32.s1 == 0) && (mem[cur_val + 3].b32.s1 == 0)) { + if ((mem(cur_val + 1).b32.s1 == 0) && (mem(cur_val + 2).b32.s1 == 0) && (mem(cur_val + 3).b32.s1 == 0)) { GLUE_SPEC_ref_count(0)++; delete_glue_ref(cur_val); cur_val = 0; @@ -15741,7 +15521,7 @@ do_register_command(small_number a) if (cur_chr < 0 || cur_chr > 19 /*lo_mem_stat_max*/) { l = cur_chr; - p = (mem[l].b16.s1 / 64); + p = (mem(l).b16.s1 / 64); e = true; } else { p = cur_chr; @@ -15771,13 +15551,13 @@ do_register_command(small_number a) found: if (p < GLUE_VAL) { if (e) - w = mem[l + 2].b32.s1; + w = mem(l + 2).b32.s1; else - w = eqtb[l].b32.s1; + w = eqtb_ptr(l)->b32.s1; } else if (e) { - s = mem[l + 1].b32.s1; + s = mem(l + 1).b32.s1; } else { - s = eqtb[l].b32.s1; /*:1272*/ + s = eqtb_ptr(l)->b32.s1; /*:1272*/ } if (q == REGISTER) @@ -15785,7 +15565,7 @@ do_register_command(small_number a) else scan_keyword("by"); - arith_error = false; + set_arith_error(false); if (q < MULTIPLY) { /*1273:*/ if (p < GLUE_VAL) { @@ -15803,26 +15583,26 @@ do_register_command(small_number a) q = new_spec(cur_val); r = s; delete_glue_ref(cur_val); - mem[q + 1].b32.s1 = mem[q + 1].b32.s1 + mem[r + 1].b32.s1; + mem_ptr(q + 1)->b32.s1 = mem(q + 1).b32.s1 + mem(r + 1).b32.s1; - if (mem[q + 2].b32.s1 == 0) - mem[q].b16.s1 = NORMAL; + if (mem(q + 2).b32.s1 == 0) + mem_ptr(q)->b16.s1 = NORMAL; - if (mem[q].b16.s1 == mem[r].b16.s1) { - mem[q + 2].b32.s1 = mem[q + 2].b32.s1 + mem[r + 2].b32.s1; - } else if (mem[q].b16.s1 < mem[r].b16.s1 && mem[r + 2].b32.s1 != 0) { - mem[q + 2].b32.s1 = mem[r + 2].b32.s1; - mem[q].b16.s1 = mem[r].b16.s1; + if (mem(q).b16.s1 == mem(r).b16.s1) { + mem_ptr(q + 2)->b32.s1 = mem(q + 2).b32.s1 + mem(r + 2).b32.s1; + } else if (mem(q).b16.s1 < mem(r).b16.s1 && mem(r + 2).b32.s1 != 0) { + mem_ptr(q + 2)->b32.s1 = mem(r + 2).b32.s1; + mem_ptr(q)->b16.s1 = mem(r).b16.s1; } - if (mem[q + 3].b32.s1 == 0) - mem[q].b16.s0 = NORMAL; + if (mem(q + 3).b32.s1 == 0) + mem_ptr(q)->b16.s0 = NORMAL; - if (mem[q].b16.s0 == mem[r].b16.s0) { - mem[q + 3].b32.s1 = mem[q + 3].b32.s1 + mem[r + 3].b32.s1; - } else if (mem[q].b16.s0 < mem[r].b16.s0 && mem[r + 3].b32.s1 != 0) { - mem[q + 3].b32.s1 = mem[r + 3].b32.s1; - mem[q].b16.s0 = mem[r].b16.s0; + if (mem(q).b16.s0 == mem(r).b16.s0) { + mem_ptr(q + 3)->b32.s1 = mem(q + 3).b32.s1 + mem(r + 3).b32.s1; + } else if (mem(q).b16.s0 < mem(r).b16.s0 && mem(r + 3).b32.s1 != 0) { + mem_ptr(q + 3)->b32.s1 = mem(r + 3).b32.s1; + mem_ptr(q)->b16.s0 = mem(r).b16.s0; } cur_val = q; @@ -15844,20 +15624,20 @@ do_register_command(small_number a) r = new_spec(s); if (q == MULTIPLY) { - mem[r + 1].b32.s1 = mult_and_add(mem[s + 1].b32.s1, cur_val, 0, MAX_HALFWORD); - mem[r + 2].b32.s1 = mult_and_add(mem[s + 2].b32.s1, cur_val, 0, MAX_HALFWORD); - mem[r + 3].b32.s1 = mult_and_add(mem[s + 3].b32.s1, cur_val, 0, MAX_HALFWORD); + mem_ptr(r + 1)->b32.s1 = mult_and_add(mem(s + 1).b32.s1, cur_val, 0, MAX_HALFWORD); + mem_ptr(r + 2)->b32.s1 = mult_and_add(mem(s + 2).b32.s1, cur_val, 0, MAX_HALFWORD); + mem_ptr(r + 3)->b32.s1 = mult_and_add(mem(s + 3).b32.s1, cur_val, 0, MAX_HALFWORD); } else { - mem[r + 1].b32.s1 = x_over_n(mem[s + 1].b32.s1, cur_val); - mem[r + 2].b32.s1 = x_over_n(mem[s + 2].b32.s1, cur_val); - mem[r + 3].b32.s1 = x_over_n(mem[s + 3].b32.s1, cur_val); + mem_ptr(r + 1)->b32.s1 = x_over_n(mem(s + 1).b32.s1, cur_val); + mem_ptr(r + 2)->b32.s1 = x_over_n(mem(s + 2).b32.s1, cur_val); + mem_ptr(r + 3)->b32.s1 = x_over_n(mem(s + 3).b32.s1, cur_val); } cur_val = r; } } - if (arith_error) { + if (arith_error()) { error_here_with_diagnostic("Arithmetic overflow"); capture_to_diagnostic(NULL); @@ -16007,12 +15787,12 @@ void alter_box_dimen(void) if (cur_ptr == TEX_NULL) b = TEX_NULL; else - b = mem[cur_ptr + 1].b32.s1; + b = mem(cur_ptr + 1).b32.s1; } scan_optional_equals(); scan_dimen(false, false, false); if (b != TEX_NULL) - mem[b + c].b32.s1 = cur_val; + mem_ptr(b + c)->b32.s1 = cur_val; } void new_font(small_number a) @@ -16023,13 +15803,13 @@ void new_font(small_number a) str_number t; unsigned char /*max_selector */ old_setting; - if (job_name == 0) + if (job_name() == 0) open_log_file(); get_r_token(); u = cur_cs; if (u >= HASH_BASE) - t = hash[u].s1; + t = hash(u).s1; else if (u >= SINGLE_BASE) { if (u == NULL_CS) @@ -16038,14 +15818,14 @@ void new_font(small_number a) t = u - SINGLE_BASE; } else { - old_setting = selector; - selector = SELECTOR_NEW_STRING ; + old_setting = selector(); + set_selector(SELECTOR_NEW_STRING); print_cstr("FONT"); print(u - 1); - selector = old_setting; + set_selector(old_setting); { - if (pool_ptr + 1 > pool_size) - overflow("pool size", pool_size - init_pool_ptr); + if (pool_ptr() + 1 > pool_size()) + overflow("pool size", pool_size() - init_pool_ptr); } t = make_string(); } @@ -16055,7 +15835,7 @@ void new_font(small_number a) eq_define(u, SET_FONT, FONT_BASE); scan_optional_equals(); scan_file_name(); - name_in_progress = true; + set_name_in_progress(true); if (scan_keyword("at")) { /*1294: */ scan_dimen(false, false, false); s = cur_val; @@ -16089,7 +15869,7 @@ void new_font(small_number a) } } else s = -1000; - name_in_progress = false /*:1293 */ ; + set_name_in_progress(false); { register int32_t for_end; f = (FONT_BASE + 1); @@ -16097,12 +15877,12 @@ void new_font(small_number a) if (f <= for_end) do { if ( - str_eq_str(font_name[f], cur_name) && + str_eq_str(font_name[f], cur_name()) && ( ( - (length(cur_area) == 0) && + (length(cur_area()) == 0) && ((font_area[f] == AAT_FONT_FLAG) || (font_area[f] == OTGR_FONT_FLAG)) - ) || str_eq_str(font_area[f], cur_area) + ) || str_eq_str(font_area[f], cur_area()) ) ) { if (s > 0) { @@ -16111,13 +15891,13 @@ void new_font(small_number a) } else if (font_size[f] == xn_over_d(font_dsize[f], -(int32_t) s, 1000)) goto common_ending; } - append_str(cur_area); - append_str(cur_name); - append_str(cur_ext); + append_str(cur_area()); + append_str(cur_name()); + append_str(cur_ext()); if (str_eq_str(font_name[f], make_string())) { { - str_ptr--; - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + set_str_ptr(str_ptr()-1); + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); } if (((font_area[f] == AAT_FONT_FLAG) || (font_area[f] == OTGR_FONT_FLAG))) { if (s > 0) { @@ -16128,33 +15908,33 @@ void new_font(small_number a) } } else { - str_ptr--; - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + set_str_ptr(str_ptr()-1); + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); } } while (f++ < for_end); } - f = read_font_info(u, cur_name, cur_area, s); + f = read_font_info(u, cur_name(), cur_area(), s); common_ending: if ((a >= 4)) geq_define(u, SET_FONT, f); else eq_define(u, SET_FONT, f); - eqtb[FONT_ID_BASE + f] = eqtb[u]; - hash[FONT_ID_BASE + f].s1 = t; + set_eqtb(FONT_ID_BASE + f, eqtb(u)); + hash_ptr(FONT_ID_BASE + f)->s1 = t; } void new_interaction(void) { print_ln(); - interaction = cur_chr; - if (interaction == BATCH_MODE) - selector = SELECTOR_NO_PRINT; + set_interaction(cur_chr); + if (interaction() == BATCH_MODE) + set_selector(SELECTOR_NO_PRINT); else - selector = SELECTOR_TERM_ONLY/*:79 */ ; - if (log_opened) - selector = selector + 2; + set_selector(SELECTOR_TERM_ONLY); + if (log_opened()) + set_selector(selector() + 2); } void issue_message(void) @@ -16164,24 +15944,24 @@ void issue_message(void) str_number s; c = cur_chr; - mem[GARBAGE].b32.s1 = scan_toks(false, true); - old_setting = selector; - selector = SELECTOR_NEW_STRING ; + mem_ptr(GARBAGE)->b32.s1 = scan_toks(false, true); + old_setting = selector(); + set_selector(SELECTOR_NEW_STRING); token_show(def_ref); - selector = old_setting; + set_selector(old_setting); flush_list(def_ref); { - if (pool_ptr + 1 > pool_size) - overflow("pool size", pool_size - init_pool_ptr); + if (pool_ptr() + 1 > pool_size()) + overflow("pool size", pool_size( )- init_pool_ptr); } s = make_string(); if (c == 0) { /*1315: */ - if (term_offset + length(s) > max_print_line - 2) + if (term_offset() + length(s) > max_print_line - 2) print_ln(); - else if ((term_offset > 0) || (file_offset > 0)) + else if ((term_offset() > 0) || (file_offset() > 0)) print_char(' '); print(s); - ttstub_output_flush (rust_stdout); + ttstub_output_flush(rust_stdout()); } else { /*1318: */ error_here_with_diagnostic(""); print(s); @@ -16194,7 +15974,7 @@ void issue_message(void) help_line[0] = "(That was another \\errmessage.)"; } else { - if (interaction < ERROR_STOP_MODE) + if (interaction() < ERROR_STOP_MODE) long_help_seen = true; { help_ptr = 4; @@ -16208,8 +15988,8 @@ void issue_message(void) use_err_help = false; } { - str_ptr--; - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + set_str_ptr(str_ptr()-1); + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); } } @@ -16224,20 +16004,20 @@ shift_case(void) b = cur_chr; p = scan_toks(false, false); - p = mem[def_ref].b32.s1; + p = mem(def_ref).b32.s1; while (p != TEX_NULL) { - t = mem[p].b32.s0; + t = mem(p).b32.s0; if (t < CS_TOKEN_FLAG + SINGLE_BASE) { c = t % MAX_CHAR_VAL; - if (eqtb[b + c].b32.s1 != 0) - mem[p].b32.s0 = t - c + eqtb[b + c].b32.s1; + if (eqtb_ptr(b + c)->b32.s1 != 0) + mem_ptr(p)->b32.s0 = t - c + eqtb_ptr(b + c)->b32.s1; } p = LLIST_link(p); } - begin_token_list(mem[def_ref].b32.s1, BACKED_UP); - mem[def_ref].b32.s1 = avail; + begin_token_list(mem(def_ref).b32.s1, BACKED_UP); + mem_ptr(def_ref)->b32.s1 = avail; avail = def_ref; } @@ -16271,7 +16051,7 @@ void show_whatever(void) if (cur_ptr == TEX_NULL) p = TEX_NULL; else - p = mem[cur_ptr + 1].b32.s1; + p = mem(cur_ptr + 1).b32.s1; } begin_diagnostic(); print_nl_cstr("> \\box"); @@ -16333,9 +16113,9 @@ void show_whatever(void) print_int(l); } n--; - t = mem[p].b16.s0; - l = mem[p + 1].b32.s1; - m = mem[p].b16.s1; + t = mem(p).b16.s0; + l = mem(p + 1).b32.s1; + m = mem(p).b16.s1; p = LLIST_link(p); } while (!(p == TEX_NULL)); } @@ -16346,7 +16126,7 @@ void show_whatever(void) p = the_toks(); print_nl_cstr("> "); token_show(TEMP_HEAD); - flush_list(mem[TEMP_HEAD].b32.s1); + flush_list(mem(TEMP_HEAD).b32.s1); goto common_ending; } break; @@ -16354,24 +16134,24 @@ void show_whatever(void) capture_to_diagnostic(NULL); end_diagnostic(true); { - if (file_line_error_style_p) + if (file_line_error_style_p()) print_file_line(); else print_nl_cstr("! "); print_cstr("OK"); } - if (selector == SELECTOR_TERM_AND_LOG) { + if (selector() == SELECTOR_TERM_AND_LOG) { if (INTPAR(tracing_online) <= 0) { - selector = SELECTOR_TERM_ONLY; + set_selector(SELECTOR_TERM_ONLY); print_cstr(" (see the transcript file)"); - selector = SELECTOR_TERM_AND_LOG; + set_selector(SELECTOR_TERM_AND_LOG); } } common_ending: capture_to_diagnostic(NULL); // calling with null twice is fine - if (interaction < ERROR_STOP_MODE) { + if (interaction() < ERROR_STOP_MODE) { help_ptr = 0; error_count--; } else if (INTPAR(tracing_online) > 0) { @@ -16408,13 +16188,13 @@ void new_write_whatsit(small_number w) else if ((cur_val > 15) && (cur_val != 18)) cur_val = 16; } - mem[cur_list.tail + 1].b32.s0 = cur_val; + mem_ptr(cur_list.tail + 1)->b32.s0 = cur_val; } void scan_and_pack_name(void) { scan_file_name(); - pack_file_name(cur_name, cur_area, cur_ext); + pack_file_name(cur_name(), cur_area(), cur_ext()); } void do_extension(void) @@ -16428,9 +16208,9 @@ void do_extension(void) new_write_whatsit(OPEN_NODE_SIZE); scan_optional_equals(); scan_file_name(); - mem[cur_list.tail + 1].b32.s1 = cur_name; - mem[cur_list.tail + 2].b32.s0 = cur_area; - mem[cur_list.tail + 2].b32.s1 = cur_ext; + mem_ptr(cur_list.tail + 1)->b32.s1 = cur_name(); + mem_ptr(cur_list.tail + 2)->b32.s0 = cur_area(); + mem_ptr(cur_list.tail + 2)->b32.s1 = cur_ext(); } break; @@ -16440,23 +16220,23 @@ void do_extension(void) new_write_whatsit(WRITE_NODE_SIZE); cur_cs = k; p = scan_toks(false, false); - mem[cur_list.tail + 1].b32.s1 = def_ref; + mem_ptr(cur_list.tail + 1)->b32.s1 = def_ref; } break; case CLOSE_NODE: { new_write_whatsit(WRITE_NODE_SIZE); - mem[cur_list.tail + 1].b32.s1 = TEX_NULL; + mem_ptr(cur_list.tail + 1)->b32.s1 = TEX_NULL; } break; case SPECIAL_NODE: { new_whatsit(SPECIAL_NODE, WRITE_NODE_SIZE); - mem[cur_list.tail + 1].b32.s0 = TEX_NULL; + mem_ptr(cur_list.tail + 1)->b32.s0 = TEX_NULL; p = scan_toks(false, true); - mem[cur_list.tail + 1].b32.s1 = def_ref; + mem_ptr(cur_list.tail + 1)->b32.s1 = def_ref; } break; @@ -16469,7 +16249,7 @@ void do_extension(void) out_what(cur_list.tail); flush_node_list(cur_list.tail); cur_list.tail = p; - mem[p].b32.s1 = TEX_NULL; + mem_ptr(p)->b32.s1 = TEX_NULL; } else back_input(); } @@ -16487,9 +16267,9 @@ void do_extension(void) cur_list.aux.b32.s1 = 0; else cur_list.aux.b32.s1 = cur_val; - mem[cur_list.tail + 1].b32.s1 = cur_list.aux.b32.s1; - mem[cur_list.tail + 1].b16.s1 = norm_min(INTPAR(left_hyphen_min)); - mem[cur_list.tail + 1].b16.s0 = norm_min(INTPAR(right_hyphen_min)); + mem_ptr(cur_list.tail + 1)->b32.s1 = cur_list.aux.b32.s1; + mem_ptr(cur_list.tail + 1)->b16.s1 = norm_min(INTPAR(left_hyphen_min)); + mem_ptr(cur_list.tail + 1)->b16.s0 = norm_min(INTPAR(right_hyphen_min)); } break; @@ -16532,8 +16312,8 @@ void do_extension(void) report_illegal_case(); else { - if (((font_area[eqtb[CUR_FONT_LOC].b32.s1] == AAT_FONT_FLAG) - || (font_area[eqtb[CUR_FONT_LOC].b32.s1] == OTGR_FONT_FLAG))) { + if (((font_area[eqtb_ptr(CUR_FONT_LOC)->b32.s1] == AAT_FONT_FLAG) + || (font_area[eqtb_ptr(CUR_FONT_LOC)->b32.s1] == OTGR_FONT_FLAG))) { new_whatsit(GLYPH_NODE, GLYPH_NODE_SIZE); scan_int(); if ((cur_val < 0) || (cur_val > 65535L)) { @@ -16549,12 +16329,12 @@ void do_extension(void) int_error(cur_val); cur_val = 0; } - mem[cur_list.tail + 4].b16.s2 = eqtb[CUR_FONT_LOC].b32.s1; - mem[cur_list.tail + 4].b16.s1 = cur_val; + mem_ptr(cur_list.tail + 4)->b16.s2 = eqtb_ptr(CUR_FONT_LOC)->b32.s1; + mem_ptr(cur_list.tail + 4)->b16.s1 = cur_val; set_native_glyph_metrics(cur_list.tail, (INTPAR(xetex_use_glyph_metrics) > 0)); } else not_native_font_error(EXTENSION, GLYPH_CODE, - eqtb[CUR_FONT_LOC].b32.s1); + eqtb_ptr(CUR_FONT_LOC)->b32.s1); } } break; @@ -16573,7 +16353,7 @@ void do_extension(void) } error(); } else - set_input_file_encoding(input_file[in_open], i, j); + set_input_file_encoding(input_file[in_open()], i, j); } break; @@ -16589,10 +16369,10 @@ void do_extension(void) case XETEX_LINEBREAK_LOCALE_EXTENSION_CODE: { scan_file_name(); - if (length(cur_name) == 0) + if (length(cur_name()) == 0) INTPAR(xetex_linebreak_locale) = 0; else - INTPAR(xetex_linebreak_locale) = cur_name; + INTPAR(xetex_linebreak_locale) = cur_name(); } break; @@ -16614,10 +16394,10 @@ void fix_language(void) l = INTPAR(language); if (l != cur_list.aux.b32.s1) { new_whatsit(LANGUAGE_NODE, SMALL_NODE_SIZE); - mem[cur_list.tail + 1].b32.s1 = l; + mem_ptr(cur_list.tail + 1)->b32.s1 = l; cur_list.aux.b32.s1 = l; - mem[cur_list.tail + 1].b16.s1 = norm_min(INTPAR(left_hyphen_min)); - mem[cur_list.tail + 1].b16.s0 = norm_min(INTPAR(right_hyphen_min)); + mem_ptr(cur_list.tail + 1)->b16.s1 = norm_min(INTPAR(left_hyphen_min)); + mem_ptr(cur_list.tail + 1)->b16.s0 = norm_min(INTPAR(right_hyphen_min)); } } @@ -16627,36 +16407,36 @@ insert_src_special(void) { int32_t toklist, p, q; - if (source_filename_stack[in_open] > 0 && is_new_source(source_filename_stack[in_open], line)) { + if (source_filename_stack[in_open()] > 0 && is_new_source(source_filename_stack[in_open()], line())) { toklist = get_avail(); p = toklist; - mem[p].b32.s0 = CS_TOKEN_FLAG + FROZEN_SPECIAL; - mem[p].b32.s1 = get_avail(); + mem_ptr(p)->b32.s0 = CS_TOKEN_FLAG + FROZEN_SPECIAL; + mem_ptr(p)->b32.s1 = get_avail(); p = LLIST_link(p); - mem[p].b32.s0 = (LEFT_BRACE_TOKEN + '{' ); - q = str_toks(make_src_special(source_filename_stack[in_open], line)); - mem[p].b32.s1 = mem[TEMP_HEAD].b32.s1; + mem_ptr(p)->b32.s0 = (LEFT_BRACE_TOKEN + '{' ); + q = str_toks(make_src_special(source_filename_stack[in_open()], line())); + mem_ptr(p)->b32.s1 = mem(TEMP_HEAD).b32.s1; p = q; - mem[p].b32.s1 = get_avail(); + mem_ptr(p)->b32.s1 = get_avail(); p = LLIST_link(p); - mem[p].b32.s0 = (RIGHT_BRACE_TOKEN + '}' ); + mem_ptr(p)->b32.s0 = (RIGHT_BRACE_TOKEN + '}' ); begin_token_list(toklist, INSERTED); - remember_source_info(source_filename_stack[in_open], line); + remember_source_info(source_filename_stack[in_open()], line()); } } void append_src_special(void) { - if ((source_filename_stack[in_open] > 0 && is_new_source(source_filename_stack[in_open], line))) { + if ((source_filename_stack[in_open()] > 0 && is_new_source(source_filename_stack[in_open()], line()))) { new_whatsit(SPECIAL_NODE, WRITE_NODE_SIZE); - mem[cur_list.tail + 1].b32.s0 = 0; + mem_ptr(cur_list.tail + 1)->b32.s0 = 0; def_ref = get_avail(); - mem[def_ref].b32.s0 = TEX_NULL; - str_toks(make_src_special(source_filename_stack[in_open], line)); - mem[def_ref].b32.s1 = mem[TEMP_HEAD].b32.s1; - mem[cur_list.tail + 1].b32.s1 = def_ref; - remember_source_info(source_filename_stack[in_open], line); + mem_ptr(def_ref)->b32.s0 = TEX_NULL; + str_toks(make_src_special(source_filename_stack[in_open()], line())); + mem_ptr(def_ref)->b32.s1 = mem(TEMP_HEAD).b32.s1; + mem_ptr(cur_list.tail + 1)->b32.s1 = def_ref; + remember_source_info(source_filename_stack[in_open()], line()); } } @@ -16666,14 +16446,16 @@ void tt_insert_special(const char *ascii_text) { int32_t toklist_start, p, q; - pool_pointer start_pool_ptr = pool_ptr; + pool_pointer start_pool_ptr = pool_ptr(); /* Copy the text into the string pool so that we can use str_toks() */ - if (pool_ptr + strlen(ascii_text) >= (size_t) pool_size) + if (pool_ptr() + strlen(ascii_text) >= (size_t) pool_size()) _tt_abort("string pool overflow"); - while (*ascii_text) - str_pool[pool_ptr++] = *ascii_text++; + while (*ascii_text) { + set_str_pool(pool_ptr(), *ascii_text++); + set_pool_ptr(pool_ptr()+1); + } /* Create the linked list of inserted tokens */ p = toklist_start = get_avail(); @@ -16750,25 +16532,25 @@ handle_right_brace(void) f = INTPAR(floating_penalty); unsave(); save_ptr = save_ptr - 2; - p = vpackage(mem[cur_list.head].b32.s1, 0, ADDITIONAL, MAX_HALFWORD); + p = vpackage(mem(cur_list.head).b32.s1, 0, ADDITIONAL, MAX_HALFWORD); pop_nest(); if (save_stack[save_ptr + 0].b32.s1 < 255) { - mem[cur_list.tail].b32.s1 = get_node(INS_NODE_SIZE); + mem_ptr(cur_list.tail)->b32.s1 = get_node(INS_NODE_SIZE); cur_list.tail = LLIST_link(cur_list.tail); NODE_type(cur_list.tail) = INS_NODE; - mem[cur_list.tail].b16.s0 = save_stack[save_ptr + 0].b32.s1; - mem[cur_list.tail + 3].b32.s1 = mem[p + 3].b32.s1 + mem[p + 2].b32.s1; - mem[cur_list.tail + 4].b32.s0 = mem[p + 5].b32.s1; - mem[cur_list.tail + 4].b32.s1 = q; - mem[cur_list.tail + 2].b32.s1 = d; - mem[cur_list.tail + 1].b32.s1 = f; + mem_ptr(cur_list.tail)->b16.s0 = save_stack[save_ptr + 0].b32.s1; + mem_ptr(cur_list.tail + 3)->b32.s1 = mem(p + 3).b32.s1 + mem(p + 2).b32.s1; + mem_ptr(cur_list.tail + 4)->b32.s0 = mem(p + 5).b32.s1; + mem_ptr(cur_list.tail + 4)->b32.s1 = q; + mem_ptr(cur_list.tail + 2)->b32.s1 = d; + mem_ptr(cur_list.tail + 1)->b32.s1 = f; } else { - mem[cur_list.tail].b32.s1 = get_node(SMALL_NODE_SIZE); + mem_ptr(cur_list.tail)->b32.s1 = get_node(SMALL_NODE_SIZE); cur_list.tail = LLIST_link(cur_list.tail); NODE_type(cur_list.tail) = ADJUST_NODE; - mem[cur_list.tail].b16.s0 = save_stack[save_ptr + 1].b32.s1; - mem[cur_list.tail + 1].b32.s1 = mem[p + 5].b32.s1; + mem_ptr(cur_list.tail)->b16.s0 = save_stack[save_ptr + 1].b32.s1; + mem_ptr(cur_list.tail + 1)->b32.s1 = mem(p + 5).b32.s1; delete_glue_ref(q); } @@ -16778,7 +16560,7 @@ handle_right_brace(void) break; case OUTPUT_GROUP: /*1062:*/ - if (cur_input.loc != TEX_NULL || (cur_input.index != OUTPUT_TEXT && cur_input.index != BACKED_UP)) { + if (cur_input().loc != TEX_NULL || (cur_input().index != OUTPUT_TEXT && cur_input().index != BACKED_UP)) { error_here_with_diagnostic("Unbalanced output routine"); capture_to_diagnostic(NULL); help_ptr = 2; @@ -16788,7 +16570,7 @@ handle_right_brace(void) do { get_token(); - } while (cur_input.loc != TEX_NULL); + } while (cur_input().loc != TEX_NULL); } end_token_list(); @@ -16811,16 +16593,16 @@ handle_right_brace(void) } if (cur_list.tail != cur_list.head) { - mem[page_tail].b32.s1 = mem[cur_list.head].b32.s1; + mem_ptr(page_tail)->b32.s1 = mem(cur_list.head).b32.s1; page_tail = cur_list.tail; } - if (mem[PAGE_HEAD].b32.s1 != TEX_NULL) { - if (mem[CONTRIB_HEAD].b32.s1 == TEX_NULL) + if (mem(PAGE_HEAD).b32.s1 != TEX_NULL) { + if (mem(CONTRIB_HEAD).b32.s1 == TEX_NULL) nest[0].tail = page_tail; - mem[page_tail].b32.s1 = mem[CONTRIB_HEAD].b32.s1; - mem[CONTRIB_HEAD].b32.s1 = mem[PAGE_HEAD].b32.s1; - mem[PAGE_HEAD].b32.s1 = TEX_NULL; + mem_ptr(page_tail)->b32.s1 = mem(CONTRIB_HEAD).b32.s1; + mem_ptr(CONTRIB_HEAD)->b32.s1 = mem(PAGE_HEAD).b32.s1; + mem_ptr(PAGE_HEAD)->b32.s1 = TEX_NULL; page_tail = PAGE_HEAD; } @@ -16858,16 +16640,16 @@ handle_right_brace(void) end_graf(); unsave(); save_ptr = save_ptr - 2; - p = vpackage(mem[cur_list.head].b32.s1, + p = vpackage(mem(cur_list.head).b32.s1, save_stack[save_ptr + 1].b32.s1, save_stack[save_ptr + 0].b32.s1, MAX_HALFWORD); pop_nest(); - mem[cur_list.tail].b32.s1 = new_noad(); + mem_ptr(cur_list.tail)->b32.s1 = new_noad(); cur_list.tail = LLIST_link(cur_list.tail); - mem[cur_list.tail].b16.s1 = VCENTER_NOAD; - mem[cur_list.tail + 1].b32.s1 = SUB_BOX; - mem[cur_list.tail + 1].b32.s0 = p; + mem_ptr(cur_list.tail)->b16.s1 = VCENTER_NOAD; + mem_ptr(cur_list.tail + 1)->b32.s1 = SUB_BOX; + mem_ptr(cur_list.tail + 1)->b32.s0 = p; break; case MATH_CHOICE_GROUP: @@ -16877,26 +16659,26 @@ handle_right_brace(void) case MATH_GROUP: unsave(); save_ptr--; - mem[save_stack[save_ptr + 0].b32.s1].b32.s1 = SUB_MLIST; + mem_ptr(save_stack[save_ptr + 0].b32.s1)->b32.s1 = SUB_MLIST; p = fin_mlist(TEX_NULL); - mem[save_stack[save_ptr + 0].b32.s1].b32.s0 = p; + mem_ptr(save_stack[save_ptr + 0].b32.s1)->b32.s0 = p; if (p != TEX_NULL) { - if (mem[p].b32.s1 == TEX_NULL) { - if (mem[p].b16.s1 == ORD_NOAD) { - if (mem[p + 3].b32.s1 == EMPTY) { - if (mem[p + 2].b32.s1 == EMPTY) { - mem[save_stack[save_ptr + 0].b32.s1].b32 = mem[p + 1].b32; + if (mem(p).b32.s1 == TEX_NULL) { + if (mem(p).b16.s1 == ORD_NOAD) { + if (mem(p + 3).b32.s1 == EMPTY) { + if (mem(p + 2).b32.s1 == EMPTY) { + mem_ptr(save_stack[save_ptr + 0].b32.s1)->b32 = mem(p + 1).b32; free_node(p, NOAD_SIZE); } } - } else if (mem[p].b16.s1 == ACCENT_NOAD) { + } else if (mem(p).b16.s1 == ACCENT_NOAD) { if (save_stack[save_ptr + 0].b32.s1 == cur_list.tail + 1) { - if (mem[cur_list.tail].b16.s1 == ORD_NOAD) { /*1222:*/ + if (mem(cur_list.tail).b16.s1 == ORD_NOAD) { /*1222:*/ q = cur_list.head; - while (mem[q].b32.s1 != cur_list.tail) + while (mem(q).b32.s1 != cur_list.tail) q = LLIST_link(q); - mem[q].b32.s1 = p; + mem_ptr(q)->b32.s1 = p; free_node(cur_list.tail, NOAD_SIZE); cur_list.tail = p; } @@ -17024,11 +16806,11 @@ main_control(void) if (cur_cs < HASH_BASE) cur_cs = prim_lookup(cur_cs - SINGLE_BASE); else - cur_cs = prim_lookup(hash[cur_cs].s1); + cur_cs = prim_lookup(hash(cur_cs).s1); if (cur_cs != UNDEFINED_PRIMITIVE) { - cur_cmd = eqtb[PRIM_EQTB_BASE + cur_cs].b16.s1; - cur_chr = eqtb[PRIM_EQTB_BASE + cur_cs].b32.s1; + cur_cmd = eqtb_ptr(PRIM_EQTB_BASE + cur_cs)->b16.s1; + cur_chr = eqtb_ptr(PRIM_EQTB_BASE + cur_cs)->b32.s1; cur_tok = CS_TOKEN_FLAG + PRIM_EQTB_BASE + cur_cs; } } @@ -17082,7 +16864,7 @@ main_control(void) case VMODE + HRULE: /* 1112*: cases of main_control that build boxes and lists */ case HMODE + VRULE: case MMODE + VRULE: - mem[cur_list.tail].b32.s1 = scan_rule_spec(); + mem_ptr(cur_list.tail)->b32.s1 = scan_rule_spec(); cur_list.tail = LLIST_link(cur_list.tail); if (abs(cur_list.mode) == VMODE) @@ -17218,7 +17000,7 @@ main_control(void) break; case MMODE + ITAL_CORR: - mem[cur_list.tail].b32.s1 = new_kern(0); + mem_ptr(cur_list.tail)->b32.s1 = new_kern(0); cur_list.tail = LLIST_link(cur_list.tail); break; @@ -17251,7 +17033,7 @@ main_control(void) case HMODE + VALIGN: if (cur_chr > 0) { if (eTeX_enabled(INTPAR(texxet) > 0, cur_cmd, cur_chr)) { - mem[cur_list.tail].b32.s1 = new_math(0, cur_chr); + mem_ptr(cur_list.tail)->b32.s1 = new_math(0, cur_chr); cur_list.tail = LLIST_link(cur_list.tail); } } else /*:1490 */ @@ -17292,7 +17074,7 @@ main_control(void) break; case MMODE + LEFT_BRACE: - mem[cur_list.tail].b32.s1 = new_noad(); + mem_ptr(cur_list.tail)->b32.s1 = new_noad(); cur_list.tail = LLIST_link(cur_list.tail); back_input(); scan_math(cur_list.tail + 1); @@ -17357,9 +17139,9 @@ main_control(void) break; case MMODE + MATH_COMP: - mem[cur_list.tail].b32.s1 = new_noad(); + mem_ptr(cur_list.tail)->b32.s1 = new_noad(); cur_list.tail = LLIST_link(cur_list.tail); - mem[cur_list.tail].b16.s1 = cur_chr; + mem_ptr(cur_list.tail)->b16.s1 = cur_chr; scan_math(cur_list.tail + 1); break; @@ -17389,14 +17171,14 @@ main_control(void) break; case MMODE + MATH_STYLE: - mem[cur_list.tail].b32.s1 = new_style(cur_chr); + mem_ptr(cur_list.tail)->b32.s1 = new_style(cur_chr); cur_list.tail = LLIST_link(cur_list.tail); break; case MMODE + NON_SCRIPT: - mem[cur_list.tail].b32.s1 = new_glue(0); + mem_ptr(cur_list.tail)->b32.s1 = new_glue(0); cur_list.tail = LLIST_link(cur_list.tail); - mem[cur_list.tail].b16.s0 = COND_MATH_GLUE; + mem_ptr(cur_list.tail)->b16.s0 = COND_MATH_GLUE; break; case MMODE + MATH_CHOICE: @@ -17501,14 +17283,14 @@ main_control(void) prev_class = CHAR_CLASS_LIMIT - 1; - if (font_area[eqtb[CUR_FONT_LOC].b32.s1] == AAT_FONT_FLAG || font_area[eqtb[CUR_FONT_LOC].b32.s1] == OTGR_FONT_FLAG) { + if (font_area[eqtb_ptr(CUR_FONT_LOC)->b32.s1] == AAT_FONT_FLAG || font_area[eqtb_ptr(CUR_FONT_LOC)->b32.s1] == OTGR_FONT_FLAG) { if (cur_list.mode > 0) { if (INTPAR(language) != cur_list.aux.b32.s1) fix_language(); } main_h = 0; - main_f = eqtb[CUR_FONT_LOC].b32.s1; + main_f = eqtb_ptr(CUR_FONT_LOC)->b32.s1; native_len = 0; collect_native: @@ -17530,7 +17312,7 @@ main_control(void) if (INTPAR(xetex_inter_char_tokens) > 0 && space_class != CHAR_CLASS_LIMIT) { if (prev_class == CHAR_CLASS_LIMIT - 1) { - if (cur_input.state != TOKEN_LIST || cur_input.index != BACKED_UP_CHAR) { + if (cur_input().state != TOKEN_LIST || cur_input().index != BACKED_UP_CHAR) { find_sa_element(INTER_CHAR_VAL, ((CHAR_CLASS_LIMIT - 1)) * CHAR_CLASS_LIMIT + space_class, false); @@ -17539,8 +17321,8 @@ main_control(void) cur_cmd = OTHER_CHAR; cur_tok = (cur_cmd * MAX_CHAR_VAL) + cur_chr; back_input(); - cur_input.index = BACKED_UP_CHAR; - begin_token_list(mem[cur_ptr + 1].b32.s1, INTER_CHAR_TEXT); + cur_input_ptr()->index = BACKED_UP_CHAR; + begin_token_list(mem(cur_ptr + 1).b32.s1, INTER_CHAR_TEXT); goto big_switch; } } @@ -17551,8 +17333,8 @@ main_control(void) cur_cmd = OTHER_CHAR; cur_tok = (cur_cmd * MAX_CHAR_VAL) + cur_chr; back_input(); - cur_input.index = BACKED_UP_CHAR; - begin_token_list(mem[cur_ptr + 1].b32.s1, INTER_CHAR_TEXT); + cur_input_ptr()->index = BACKED_UP_CHAR; + begin_token_list(mem(cur_ptr + 1).b32.s1, INTER_CHAR_TEXT); prev_class = ((CHAR_CLASS_LIMIT - 1)); goto collected; } @@ -17613,7 +17395,7 @@ main_control(void) } else cur_tok = CS_TOKEN_FLAG + cur_cs; back_input(); - begin_token_list(mem[cur_ptr + 1].b32.s1, INTER_CHAR_TEXT); + begin_token_list(mem(cur_ptr + 1).b32.s1, INTER_CHAR_TEXT); goto collected; } } @@ -17671,13 +17453,13 @@ main_control(void) if (cur_list.mode == HMODE) { main_ppp = cur_list.head; - while (main_ppp != main_pp && mem[main_ppp].b32.s1 != main_pp) { + while (main_ppp != main_pp && mem(main_ppp).b32.s1 != main_pp) { if (!is_char_node(main_ppp) && NODE_type(main_ppp) == DISC_NODE) { temp_ptr = main_ppp; { register int32_t for_end; main_p = 1; - for_end = mem[temp_ptr].b16.s0; + for_end = mem(temp_ptr).b16.s0; if (main_p <= for_end) do main_ppp = LLIST_link(main_ppp); @@ -17697,12 +17479,12 @@ main_control(void) if ((((main_pp) != TEX_NULL && (!(is_char_node(main_pp))) && (NODE_type(main_pp) == WHATSIT_NODE) - && ((mem[main_pp].b16.s0 == NATIVE_WORD_NODE) - || (mem[main_pp].b16.s0 == NATIVE_WORD_NODE_AT)))) - && (mem[main_pp + 4].b16.s2 == main_f) && (main_ppp != main_pp) && (!(is_char_node(main_ppp))) + && ((mem(main_pp).b16.s0 == NATIVE_WORD_NODE) + || (mem(main_pp).b16.s0 == NATIVE_WORD_NODE_AT)))) + && (mem(main_pp + 4).b16.s2 == main_f) && (main_ppp != main_pp) && (!(is_char_node(main_ppp))) && (NODE_type(main_ppp) != DISC_NODE) ) { - main_k = main_h + mem[main_pp + 4].b16.s1; + main_k = main_h + mem(main_pp + 4).b16.s1; while (native_text_size <= native_len + main_k) { native_text_size = native_text_size + 128; @@ -17714,7 +17496,7 @@ main_control(void) { register int32_t for_end; main_p = 0; - for_end = mem[main_pp + 4].b16.s1 - 1; + for_end = mem(main_pp + 4).b16.s1 - 1; if (main_p <= for_end) do { native_text[native_len] = NATIVE_NODE_text(main_pp)[main_p]; @@ -17749,12 +17531,12 @@ main_control(void) if ((main_h < main_k)) main_h++; - mem[main_ppp].b32.s1 = mem[main_pp].b32.s1; - mem[main_pp].b32.s1 = TEX_NULL; + mem_ptr(main_ppp)->b32.s1 = mem(main_pp).b32.s1; + mem_ptr(main_pp)->b32.s1 = TEX_NULL; flush_node_list(main_pp); main_pp = cur_list.tail; - while ((mem[main_ppp].b32.s1 != main_pp)) + while ((mem(main_ppp).b32.s1 != main_pp)) main_ppp = LLIST_link(main_ppp); } else { do_locale_linebreaks(temp_ptr, main_h); @@ -17771,7 +17553,7 @@ main_control(void) } if ((main_k > 0) || is_hyph) { - mem[cur_list.tail].b32.s1 = new_disc(); + mem_ptr(cur_list.tail)->b32.s1 = new_disc(); cur_list.tail = LLIST_link(cur_list.tail); main_pp = cur_list.tail; } @@ -17779,13 +17561,13 @@ main_control(void) } else { main_ppp = cur_list.head; - while (main_ppp != main_pp && mem[main_ppp].b32.s1 != main_pp) { + while (main_ppp != main_pp && mem(main_ppp).b32.s1 != main_pp) { if (!is_char_node(main_ppp) && NODE_type(main_ppp) == DISC_NODE) { temp_ptr = main_ppp; { register int32_t for_end; main_p = 1; - for_end = mem[temp_ptr].b16.s0; + for_end = mem(temp_ptr).b16.s0; if (main_p <= for_end) do main_ppp = LLIST_link(main_ppp); @@ -17798,16 +17580,16 @@ main_control(void) } if ((((main_pp) != TEX_NULL && (!(is_char_node(main_pp))) && (NODE_type(main_pp) == WHATSIT_NODE) - && ((mem[main_pp].b16.s0 == NATIVE_WORD_NODE) - || (mem[main_pp].b16.s0 == NATIVE_WORD_NODE_AT)))) && (mem[main_pp + 4].b16.s2 == main_f) + && ((mem(main_pp).b16.s0 == NATIVE_WORD_NODE) + || (mem(main_pp).b16.s0 == NATIVE_WORD_NODE_AT)))) && (mem(main_pp + 4).b16.s2 == main_f) && (main_ppp != main_pp) && (!(is_char_node(main_ppp))) && (NODE_type(main_ppp) != DISC_NODE) ) { - mem[main_pp].b32.s1 = new_native_word_node(main_f, main_k + mem[main_pp + 4].b16.s1); - cur_list.tail = mem[main_pp].b32.s1; + mem_ptr(main_pp)->b32.s1 = new_native_word_node(main_f, main_k + mem(main_pp + 4).b16.s1); + cur_list.tail = mem(main_pp).b32.s1; { register int32_t for_end; main_p = 0; - for_end = mem[main_pp + 4].b16.s1 - 1; + for_end = mem(main_pp + 4).b16.s1 - 1; if (main_p <= for_end) do NATIVE_NODE_text(cur_list.tail)[main_p] = NATIVE_NODE_text(main_pp)[main_p]; @@ -17819,20 +17601,20 @@ main_control(void) for_end = main_k - 1; if (main_p <= for_end) do - NATIVE_NODE_text(cur_list.tail)[main_p + mem[main_pp + 4].b16.s1] = native_text[main_p]; + NATIVE_NODE_text(cur_list.tail)[main_p + mem(main_pp + 4).b16.s1] = native_text[main_p]; while (main_p++ < for_end); } set_native_metrics(cur_list.tail, (INTPAR(xetex_use_glyph_metrics) > 0)); main_p = cur_list.head; if (main_p != main_pp) - while (mem[main_p].b32.s1 != main_pp) + while (mem(main_p).b32.s1 != main_pp) main_p = LLIST_link(main_p); - mem[main_p].b32.s1 = mem[main_pp].b32.s1; - mem[main_pp].b32.s1 = TEX_NULL; + mem_ptr(main_p)->b32.s1 = mem(main_pp).b32.s1; + mem_ptr(main_pp)->b32.s1 = TEX_NULL; flush_node_list(main_pp); } else { - mem[main_pp].b32.s1 = new_native_word_node(main_f, main_k); - cur_list.tail = mem[main_pp].b32.s1; + mem_ptr(main_pp)->b32.s1 = new_native_word_node(main_f, main_k); + cur_list.tail = mem(main_pp).b32.s1; { register int32_t for_end; main_p = 0; @@ -17853,39 +17635,40 @@ main_control(void) if ((((main_p) != TEX_NULL && (!(is_char_node(main_p))) && (NODE_type(main_p) == WHATSIT_NODE) - && ((mem[main_p].b16.s0 == NATIVE_WORD_NODE) - || (mem[main_p].b16.s0 == NATIVE_WORD_NODE_AT))))) + && ((mem(main_p).b16.s0 == NATIVE_WORD_NODE) + || (mem(main_p).b16.s0 == NATIVE_WORD_NODE_AT))))) main_pp = main_p; main_p = LLIST_link(main_p); } if ((main_pp != TEX_NULL)) { - if (mem[main_pp + 4].b16.s2 == main_f) { - main_p = mem[main_pp].b32.s1; + if (mem(main_pp + 4).b16.s2 == main_f) { + main_p = mem(main_pp).b32.s1; while (!(is_char_node(main_p)) && ((NODE_type(main_p) == PENALTY_NODE) || (NODE_type(main_p) == INS_NODE) || (NODE_type(main_p) == MARK_NODE) || (NODE_type(main_p) == ADJUST_NODE) - || ((NODE_type(main_p) == WHATSIT_NODE) && (mem[main_p].b16.s0 <= 4)))) + || ((NODE_type(main_p) == WHATSIT_NODE) && (mem(main_p).b16.s0 <= 4)))) main_p = LLIST_link(main_p); if (!(is_char_node(main_p)) && (NODE_type(main_p) == GLUE_NODE)) { - main_ppp = mem[main_p].b32.s1; + main_ppp = mem(main_p).b32.s1; while (!(is_char_node(main_ppp)) && ((NODE_type(main_ppp) == PENALTY_NODE) || (NODE_type(main_ppp) == INS_NODE) || (NODE_type(main_ppp) == MARK_NODE) || (NODE_type(main_ppp) == ADJUST_NODE) - || ((NODE_type(main_ppp) == WHATSIT_NODE) && (mem[main_ppp].b16.s0 <= 4)))) + || ((NODE_type(main_ppp) == WHATSIT_NODE) && (mem(main_ppp).b16.s0 <= 4)))) main_ppp = LLIST_link(main_ppp); if (main_ppp == cur_list.tail) { temp_ptr = - new_native_word_node(main_f, - mem[main_pp + 4].b16.s1 + 1 + mem[cur_list.tail + - 4].b16.s1); + new_native_word_node( + main_f, + mem(main_pp + 4).b16.s1 + 1 + mem(cur_list.tail + 4).b16.s1 + ); main_k = 0; { register int32_t for_end; t = 0; - for_end = mem[main_pp + 4].b16.s1 - 1; + for_end = mem(main_pp + 4).b16.s1 - 1; if (t <= for_end) do { NATIVE_NODE_text(temp_ptr)[main_k] = NATIVE_NODE_text(main_pp)[t]; @@ -17898,7 +17681,7 @@ main_control(void) { register int32_t for_end; t = 0; - for_end = mem[cur_list.tail + 4].b16.s1 - 1; + for_end = mem(cur_list.tail + 4).b16.s1 - 1; if (t <= for_end) do { NATIVE_NODE_text(temp_ptr)[main_k] = NATIVE_NODE_text(cur_list.tail)[t]; @@ -17907,13 +17690,13 @@ main_control(void) while (t++ < for_end); } set_native_metrics(temp_ptr, (INTPAR(xetex_use_glyph_metrics) > 0)); - t = mem[temp_ptr + 1].b32.s1 - mem[main_pp + 1].b32.s1 - mem[cur_list.tail + 1].b32.s1; - free_node(temp_ptr, mem[temp_ptr + 4].b16.s3); - if (t != mem[font_glue[main_f] + 1].b32.s1) { - temp_ptr = new_kern(t - mem[font_glue[main_f] + 1].b32.s1); + t = mem(temp_ptr + 1).b32.s1 - mem(main_pp + 1).b32.s1 - mem(cur_list.tail + 1).b32.s1; + free_node(temp_ptr, mem(temp_ptr + 4).b16.s3); + if (t != mem(font_glue[main_f] + 1).b32.s1) { + temp_ptr = new_kern(t - mem(font_glue[main_f] + 1).b32.s1); NODE_subtype(temp_ptr) = SPACE_ADJUSTMENT; - mem[temp_ptr].b32.s1 = mem[main_p].b32.s1; - mem[main_p].b32.s1 = temp_ptr; + mem_ptr(temp_ptr)->b32.s1 = mem(main_p).b32.s1; + mem_ptr(main_p)->b32.s1 = temp_ptr; } } } @@ -17945,7 +17728,7 @@ main_control(void) if ((INTPAR(xetex_inter_char_tokens) > 0) && space_class != CHAR_CLASS_LIMIT) { if (prev_class == ((CHAR_CLASS_LIMIT - 1))) { - if ((cur_input.state != TOKEN_LIST) || (cur_input.index != BACKED_UP_CHAR)) { + if ((cur_input().state != TOKEN_LIST) || (cur_input().index != BACKED_UP_CHAR)) { find_sa_element(INTER_CHAR_VAL, ((CHAR_CLASS_LIMIT - 1)) * CHAR_CLASS_LIMIT + space_class, false); if (cur_ptr != TEX_NULL && ETEX_SA_ptr(cur_ptr) != TEX_NULL) { @@ -17953,8 +17736,8 @@ main_control(void) cur_cmd = OTHER_CHAR; cur_tok = (cur_cmd * MAX_CHAR_VAL) + cur_chr; back_input(); - cur_input.index = BACKED_UP_CHAR; - begin_token_list(mem[cur_ptr + 1].b32.s1, INTER_CHAR_TEXT); + cur_input_ptr()->index = BACKED_UP_CHAR; + begin_token_list(mem(cur_ptr + 1).b32.s1, INTER_CHAR_TEXT); goto big_switch; } } @@ -17965,8 +17748,8 @@ main_control(void) cur_cmd = OTHER_CHAR; cur_tok = (cur_cmd * MAX_CHAR_VAL) + cur_chr; back_input(); - cur_input.index = BACKED_UP_CHAR; - begin_token_list(mem[cur_ptr + 1].b32.s1, INTER_CHAR_TEXT); + cur_input_ptr()->index = BACKED_UP_CHAR; + begin_token_list(mem(cur_ptr + 1).b32.s1, INTER_CHAR_TEXT); prev_class = ((CHAR_CLASS_LIMIT - 1)); goto big_switch; } @@ -17975,7 +17758,7 @@ main_control(void) prev_class = space_class; } - main_f = eqtb[CUR_FONT_LOC].b32.s1; + main_f = eqtb_ptr(CUR_FONT_LOC)->b32.s1; bchar = font_bchar[main_f]; false_bchar = font_false_bchar[main_f]; @@ -17990,14 +17773,14 @@ main_control(void) lig_stack = get_avail(); else { - avail = mem[lig_stack].b32.s1; - mem[lig_stack].b32.s1 = TEX_NULL; + avail = mem(lig_stack).b32.s1; + mem_ptr(lig_stack)->b32.s1 = TEX_NULL; } } - mem[lig_stack].b16.s1 = main_f; + mem_ptr(lig_stack)->b16.s1 = main_f; cur_l = cur_chr; - mem[lig_stack].b16.s0 = cur_l; + mem_ptr(lig_stack)->b16.s0 = cur_l; cur_q = cur_list.tail; if (cancel_boundary) { @@ -18016,25 +17799,25 @@ main_control(void) main_loop_wrapup: /*1070: */ if (cur_l < TOO_BIG_CHAR) { - if (mem[cur_q].b32.s1 > TEX_NULL) { - if (mem[cur_list.tail].b16.s0 == hyphen_char[main_f]) + if (mem(cur_q).b32.s1 > TEX_NULL) { + if (mem(cur_list.tail).b16.s0 == hyphen_char[main_f]) ins_disc = true; } if (ligature_present) { - main_p = new_ligature(main_f, cur_l, mem[cur_q].b32.s1); + main_p = new_ligature(main_f, cur_l, mem(cur_q).b32.s1); if (lft_hit) { - mem[main_p].b16.s0 = 2; + mem_ptr(main_p)->b16.s0 = 2; lft_hit = false; } if (rt_hit) { if (lig_stack == TEX_NULL) { - mem[main_p].b16.s0++; + mem_ptr(main_p)->b16.s0++; rt_hit = false; } } - mem[cur_q].b32.s1 = main_p; + mem_ptr(cur_q)->b32.s1 = main_p; cur_list.tail = main_p; ligature_present = false; } @@ -18042,7 +17825,7 @@ main_control(void) if (ins_disc) { ins_disc = false; if (cur_list.mode > 0) { - mem[cur_list.tail].b32.s1 = new_disc(); + mem_ptr(cur_list.tail)->b32.s1 = new_disc(); cur_list.tail = LLIST_link(cur_list.tail); } } @@ -18053,7 +17836,7 @@ main_control(void) goto reswitch; cur_q = cur_list.tail; - cur_l = mem[lig_stack].b16.s0; + cur_l = mem(lig_stack).b16.s0; main_loop_move_1: if (!is_char_node(lig_stack)) @@ -18063,7 +17846,7 @@ main_control(void) if ((effective_char(false, main_f, cur_chr) > font_ec[main_f]) || (effective_char(false, main_f, cur_chr) < font_bc[main_f])) { char_warning(main_f, cur_chr); - mem[lig_stack].b32.s1 = avail; + mem_ptr(lig_stack)->b32.s1 = avail; avail = lig_stack; goto big_switch; } @@ -18072,12 +17855,12 @@ main_control(void) if (!(main_i.s3 > 0)) { char_warning(main_f, cur_chr); - mem[lig_stack].b32.s1 = avail; + mem_ptr(lig_stack)->b32.s1 = avail; avail = lig_stack; goto big_switch; } - mem[cur_list.tail].b32.s1 = lig_stack; + mem_ptr(cur_list.tail)->b32.s1 = lig_stack; cur_list.tail = lig_stack; /*:1071 */ main_loop_lookahead: /*1073: */ @@ -18130,7 +17913,7 @@ main_control(void) if ((INTPAR(xetex_inter_char_tokens) > 0) && space_class != CHAR_CLASS_LIMIT) { if (prev_class == ((CHAR_CLASS_LIMIT - 1))) { - if ((cur_input.state != TOKEN_LIST) || (cur_input.index != BACKED_UP_CHAR)) { + if ((cur_input().state != TOKEN_LIST) || (cur_input().index != BACKED_UP_CHAR)) { find_sa_element(INTER_CHAR_VAL, ((CHAR_CLASS_LIMIT - 1)) * CHAR_CLASS_LIMIT + space_class, false); if (cur_ptr != TEX_NULL && ETEX_SA_ptr(cur_ptr) != TEX_NULL) { @@ -18138,8 +17921,8 @@ main_control(void) cur_cmd = OTHER_CHAR; cur_tok = (cur_cmd * MAX_CHAR_VAL) + cur_chr; back_input(); - cur_input.index = BACKED_UP_CHAR; - begin_token_list(mem[cur_ptr + 1].b32.s1, INTER_CHAR_TEXT); + cur_input_ptr()->index = BACKED_UP_CHAR; + begin_token_list(mem(cur_ptr + 1).b32.s1, INTER_CHAR_TEXT); goto big_switch; } } @@ -18150,8 +17933,8 @@ main_control(void) cur_cmd = OTHER_CHAR; cur_tok = (cur_cmd * MAX_CHAR_VAL) + cur_chr; back_input(); - cur_input.index = BACKED_UP_CHAR; - begin_token_list(mem[cur_ptr + 1].b32.s1, INTER_CHAR_TEXT); + cur_input_ptr()->index = BACKED_UP_CHAR; + begin_token_list(mem(cur_ptr + 1).b32.s1, INTER_CHAR_TEXT); prev_class = ((CHAR_CLASS_LIMIT - 1)); goto big_switch; } @@ -18165,14 +17948,14 @@ main_control(void) lig_stack = get_avail(); else { - avail = mem[lig_stack].b32.s1; - mem[lig_stack].b32.s1 = TEX_NULL; + avail = mem(lig_stack).b32.s1; + mem_ptr(lig_stack)->b32.s1 = TEX_NULL; } } - mem[lig_stack].b16.s1 = main_f; + mem_ptr(lig_stack)->b16.s1 = main_f; cur_r = cur_chr; - mem[lig_stack].b16.s0 = cur_r; + mem_ptr(lig_stack)->b16.s0 = cur_r; if (cur_r == false_bchar) cur_r = TOO_BIG_CHAR; /*:1073 */ @@ -18198,25 +17981,25 @@ main_control(void) if (main_j.s3 <= 128) { /*1075: */ if (main_j.s1 >= 128) { if (cur_l < TOO_BIG_CHAR) { - if (mem[cur_q].b32.s1 > TEX_NULL) { - if (mem[cur_list.tail].b16.s0 == hyphen_char[main_f]) + if (mem(cur_q).b32.s1 > TEX_NULL) { + if (mem(cur_list.tail).b16.s0 == hyphen_char[main_f]) ins_disc = true; } if (ligature_present) { - main_p = new_ligature(main_f, cur_l, mem[cur_q].b32.s1); + main_p = new_ligature(main_f, cur_l, mem(cur_q).b32.s1); if (lft_hit) { - mem[main_p].b16.s0 = 2; + mem_ptr(main_p)->b16.s0 = 2; lft_hit = false; } if (rt_hit) { if (lig_stack == TEX_NULL) { - mem[main_p].b16.s0++; + mem_ptr(main_p)->b16.s0++; rt_hit = false; } } - mem[cur_q].b32.s1 = main_p; + mem_ptr(cur_q)->b32.s1 = main_p; cur_list.tail = main_p; ligature_present = false; } @@ -18224,13 +18007,13 @@ main_control(void) if (ins_disc) { ins_disc = false; if (cur_list.mode > 0) { - mem[cur_list.tail].b32.s1 = new_disc(); + mem_ptr(cur_list.tail)->b32.s1 = new_disc(); cur_list.tail = LLIST_link(cur_list.tail); } } } - mem[cur_list.tail].b32.s1 = + mem_ptr(cur_list.tail)->b32.s1 = new_kern(font_info[kern_base[main_f] + 256 * main_j.s1 + main_j.s0].b32.s1); cur_list.tail = LLIST_link(cur_list.tail); goto main_loop_move; @@ -18259,9 +18042,9 @@ main_control(void) } else if (is_char_node(lig_stack)) { main_p = lig_stack; lig_stack = new_lig_item(cur_r); - mem[lig_stack + 1].b32.s1 = main_p; + mem_ptr(lig_stack + 1)->b32.s1 = main_p; } else { - mem[lig_stack].b16.s0 = cur_r; + mem_ptr(lig_stack)->b16.s0 = cur_r; } break; @@ -18269,38 +18052,38 @@ main_control(void) cur_r = main_j.s0; main_p = lig_stack; lig_stack = new_lig_item(cur_r); - mem[lig_stack].b32.s1 = main_p; + mem_ptr(lig_stack)->b32.s1 = main_p; break; case 7: case 11: if (cur_l < TOO_BIG_CHAR) { - if (mem[cur_q].b32.s1 > TEX_NULL) { + if (mem(cur_q).b32.s1 > TEX_NULL) { - if (mem[cur_list.tail].b16.s0 == hyphen_char[main_f]) + if (mem(cur_list.tail).b16.s0 == hyphen_char[main_f]) ins_disc = true; } if (ligature_present) { - main_p = new_ligature(main_f, cur_l, mem[cur_q].b32.s1); + main_p = new_ligature(main_f, cur_l, mem(cur_q).b32.s1); if (lft_hit) { - mem[main_p].b16.s0 = 2; + mem_ptr(main_p)->b16.s0 = 2; lft_hit = false; } if (false) { if (lig_stack == TEX_NULL) { - mem[main_p].b16.s0++; + mem_ptr(main_p)->b16.s0++; rt_hit = false; } } - mem[cur_q].b32.s1 = main_p; + mem_ptr(cur_q)->b32.s1 = main_p; cur_list.tail = main_p; ligature_present = false; } if (ins_disc) { ins_disc = false; if (cur_list.mode > 0) { - mem[cur_list.tail].b32.s1 = new_disc(); + mem_ptr(cur_list.tail)->b32.s1 = new_disc(); cur_list.tail = LLIST_link(cur_list.tail); } } @@ -18345,15 +18128,15 @@ main_control(void) goto main_lig_loop_1; main_loop_move_lig: /*1072: */ - main_p = mem[lig_stack + 1].b32.s1; + main_p = mem(lig_stack + 1).b32.s1; if (main_p > TEX_NULL) { - mem[cur_list.tail].b32.s1 = main_p; + mem_ptr(cur_list.tail)->b32.s1 = main_p; cur_list.tail = LLIST_link(cur_list.tail); } temp_ptr = lig_stack; - lig_stack = mem[temp_ptr].b32.s1; + lig_stack = mem(temp_ptr).b32.s1; free_node(temp_ptr, SMALL_NODE_SIZE); main_i = FONT_CHARACTER_INFO(main_f, effective_char(true, main_f, cur_l)); ligature_present = true; @@ -18364,7 +18147,7 @@ main_control(void) else cur_r = bchar; } else - cur_r = mem[lig_stack].b16.s0; + cur_r = mem(lig_stack).b16.s0; goto main_lig_loop; @@ -18383,26 +18166,26 @@ main_control(void) } else cur_tok = CS_TOKEN_FLAG + cur_cs; back_input(); - begin_token_list(mem[cur_ptr + 1].b32.s1, INTER_CHAR_TEXT); + begin_token_list(mem(cur_ptr + 1).b32.s1, INTER_CHAR_TEXT); goto big_switch; } } if (GLUEPAR(space_skip) == 0) { - main_p = font_glue[eqtb[CUR_FONT_LOC].b32.s1]; + main_p = font_glue[eqtb_ptr(CUR_FONT_LOC)->b32.s1]; if (main_p == TEX_NULL) { main_p = new_spec(0); - main_k = param_base[eqtb[CUR_FONT_LOC].b32.s1] + 2; - mem[main_p + 1].b32.s1 = font_info[main_k].b32.s1; - mem[main_p + 2].b32.s1 = font_info[main_k + 1].b32.s1; - mem[main_p + 3].b32.s1 = font_info[main_k + 2].b32.s1; - font_glue[eqtb[CUR_FONT_LOC].b32.s1] = main_p; + main_k = param_base[eqtb_ptr(CUR_FONT_LOC)->b32.s1] + 2; + mem_ptr(main_p + 1)->b32.s1 = font_info[main_k].b32.s1; + mem_ptr(main_p + 2)->b32.s1 = font_info[main_k + 1].b32.s1; + mem_ptr(main_p + 3)->b32.s1 = font_info[main_k + 2].b32.s1; + font_glue[eqtb_ptr(CUR_FONT_LOC)->b32.s1] = main_p; } temp_ptr = new_glue(main_p); } else temp_ptr = new_param_glue(GLUE_PAR__space_skip); - mem[cur_list.tail].b32.s1 = temp_ptr; + mem_ptr(cur_list.tail)->b32.s1 = temp_ptr; cur_list.tail = temp_ptr; goto big_switch; } @@ -18422,21 +18205,21 @@ close_files_and_terminate(void) for (k = 0; k <= 15; k++) { if (write_open[k]) - ttstub_output_close(write_file[k]); + ttstub_output_close(write_file(k)); } INTPAR(new_line_char) = -1; finalize_dvi_file(); - synctex_terminate(log_opened); + synctex_terminate(log_opened()); - if (log_opened) { - ttstub_output_putc (log_file, '\n'); - ttstub_output_close (log_file); - selector = selector - 2; - if (selector == SELECTOR_TERM_ONLY) { + if (log_opened()) { + ttstub_output_putc(log_file(), '\n'); + ttstub_output_close(log_file()); + set_selector(selector() - 2); + if (selector() == SELECTOR_TERM_ONLY) { print_nl_cstr("Transcript written on "); - print(texmf_log_name); + print(texmf_log_name()); print_char('.'); } } @@ -18447,20 +18230,20 @@ close_files_and_terminate(void) void flush_str(str_number s) { - if (s == str_ptr - 1) { - str_ptr--; - pool_ptr = str_start[str_ptr - TOO_BIG_CHAR]; + if (s == str_ptr() - 1) { + set_str_ptr(str_ptr()-1); + set_pool_ptr(str_start(str_ptr() - TOO_BIG_CHAR)); } } str_number tokens_to_string(int32_t p) { - if (selector == SELECTOR_NEW_STRING ) + if (selector() == SELECTOR_NEW_STRING ) pdf_error("tokens", "tokens_to_string() called while selector = new_string"); - old_setting = selector; - selector = SELECTOR_NEW_STRING ; - show_token_list(mem[p].b32.s1, TEX_NULL, pool_size - pool_ptr); - selector = old_setting; + old_setting = selector(); + set_selector(SELECTOR_NEW_STRING); + show_token_list(mem(p).b32.s1, TEX_NULL, pool_size() - pool_ptr()); + set_selector(old_setting); return make_string(); } @@ -18487,17 +18270,17 @@ void compare_strings(void) } s2 = tokens_to_string(def_ref); delete_token_ref(def_ref); - i1 = str_start[(s1) - 65536L]; - j1 = str_start[(s1 + 1) - 65536L]; - i2 = str_start[(s2) - 65536L]; - j2 = str_start[(s2 + 1) - 65536L]; + i1 = str_start((s1) - 65536L); + j1 = str_start((s1 + 1) - 65536L); + i2 = str_start((s2) - 65536L); + j2 = str_start((s2 + 1) - 65536L); while ((i1 < j1) && (i2 < j2)) { - if (str_pool[i1] < str_pool[i2]) { + if (str_pool(i1) < str_pool(i2)) { cur_val = -1; goto done; } - if (str_pool[i1] > str_pool[i2]) { + if (str_pool(i1) > str_pool(i2)) { cur_val = 1; goto done; } @@ -18524,40 +18307,40 @@ prune_page_top(int32_t p, bool s) int32_t q, r = TEX_NULL; prev_p = TEMP_HEAD; - mem[TEMP_HEAD].b32.s1 = p; + mem_ptr(TEMP_HEAD)->b32.s1 = p; while (p != TEX_NULL) { - switch (mem[p].b16.s1) { + switch (mem(p).b16.s1) { case HLIST_NODE: case VLIST_NODE: case RULE_NODE: q = new_skip_param(GLUE_PAR__split_top_skip); - mem[prev_p].b32.s1 = q; - mem[q].b32.s1 = p; - if (mem[temp_ptr + 1].b32.s1 > mem[p + 3].b32.s1) - mem[temp_ptr + 1].b32.s1 = mem[temp_ptr + 1].b32.s1 - mem[p + 3].b32.s1; + mem_ptr(prev_p)->b32.s1 = q; + mem_ptr(q)->b32.s1 = p; + if (mem(temp_ptr + 1).b32.s1 > mem(p + 3).b32.s1) + mem_ptr(temp_ptr + 1)->b32.s1 = mem(temp_ptr + 1).b32.s1 - mem(p + 3).b32.s1; else - mem[temp_ptr + 1].b32.s1 = 0; + mem_ptr(temp_ptr + 1)->b32.s1 = 0; p = TEX_NULL; break; case WHATSIT_NODE: case MARK_NODE: case INS_NODE: prev_p = p; - p = mem[prev_p].b32.s1; + p = mem(prev_p).b32.s1; break; case GLUE_NODE: case KERN_NODE: case PENALTY_NODE: q = p; - p = mem[q].b32.s1; - mem[q].b32.s1 = TEX_NULL; - mem[prev_p].b32.s1 = p; + p = mem(q).b32.s1; + mem_ptr(q)->b32.s1 = TEX_NULL; + mem_ptr(prev_p)->b32.s1 = p; if (s) { if (disc_ptr[VSPLIT_CODE] == TEX_NULL) disc_ptr[VSPLIT_CODE] = q; else - mem[r].b32.s1 = q; + mem_ptr(r)->b32.s1 = q; r = q; } else { flush_node_list(q); @@ -18569,7 +18352,7 @@ prune_page_top(int32_t p, bool s) } } - return mem[TEMP_HEAD].b32.s1; + return mem(TEMP_HEAD).b32.s1; } @@ -18581,78 +18364,78 @@ do_marks(small_number a, small_number l, int32_t q) if (l < 4) { for (i = 0; i <= 15; i++) { if (odd(i)) - cur_ptr = mem[q + (i / 2) + 1].b32.s1; + cur_ptr = mem(q + (i / 2) + 1).b32.s1; else - cur_ptr = mem[q + (i / 2) + 1].b32.s0; + cur_ptr = mem(q + (i / 2) + 1).b32.s0; if (cur_ptr != TEX_NULL) { if (do_marks(a, l + 1, cur_ptr)) { if (odd(i)) - mem[q + (i / 2) + 1].b32.s1 = TEX_NULL; + mem_ptr(q + (i / 2) + 1)->b32.s1 = TEX_NULL; else - mem[q + (i / 2) + 1].b32.s0 = TEX_NULL; - mem[q].b16.s0--; + mem_ptr(q + (i / 2) + 1)->b32.s0 = TEX_NULL; + mem_ptr(q)->b16.s0--; } } } - if (mem[q].b16.s0 == 0) { + if (mem(q).b16.s0 == 0) { free_node(q, INDEX_NODE_SIZE); q = TEX_NULL; } } else { switch (a) { /*1614: */ case VSPLIT_INIT: - if (mem[q + 2].b32.s1 != TEX_NULL) { - delete_token_ref(mem[q + 2].b32.s1); - mem[q + 2].b32.s1 = TEX_NULL; - delete_token_ref(mem[q + 3].b32.s0); - mem[q + 3].b32.s0 = TEX_NULL; + if (mem(q + 2).b32.s1 != TEX_NULL) { + delete_token_ref(mem(q + 2).b32.s1); + mem_ptr(q + 2)->b32.s1 = TEX_NULL; + delete_token_ref(mem(q + 3).b32.s0); + mem_ptr(q + 3)->b32.s0 = TEX_NULL; } break; case FIRE_UP_INIT: - if (mem[q + 2].b32.s0 != TEX_NULL) { - if (mem[q + 1].b32.s0 != TEX_NULL) - delete_token_ref(mem[q + 1].b32.s0); - delete_token_ref(mem[q + 1].b32.s1); - mem[q + 1].b32.s1 = TEX_NULL; - if (mem[mem[q + 2].b32.s0].b32.s1 == TEX_NULL) { - delete_token_ref(mem[q + 2].b32.s0); - mem[q + 2].b32.s0 = TEX_NULL; + if (mem(q + 2).b32.s0 != TEX_NULL) { + if (mem(q + 1).b32.s0 != TEX_NULL) + delete_token_ref(mem(q + 1).b32.s0); + delete_token_ref(mem(q + 1).b32.s1); + mem_ptr(q + 1)->b32.s1 = TEX_NULL; + if (mem(mem(q + 2).b32.s0).b32.s1 == TEX_NULL) { + delete_token_ref(mem(q + 2).b32.s0); + mem_ptr(q + 2)->b32.s0 = TEX_NULL; } else - mem[mem[q + 2].b32.s0].b32.s0++; - mem[q + 1].b32.s0 = mem[q + 2].b32.s0; + mem_ptr(mem(q + 2).b32.s0)->b32.s0++; + mem_ptr(q + 1)->b32.s0 = mem(q + 2).b32.s0; } break; case FIRE_UP_DONE: - if ((mem[q + 1].b32.s0 != TEX_NULL) && (mem[q + 1].b32.s1 == TEX_NULL)) { - mem[q + 1].b32.s1 = mem[q + 1].b32.s0; - mem[mem[q + 1].b32.s0].b32.s0++; + if ((mem(q + 1).b32.s0 != TEX_NULL) && (mem(q + 1).b32.s1 == TEX_NULL)) { + mem_ptr(q + 1)->b32.s1 = mem(q + 1).b32.s0; + mem_ptr(mem(q + 1).b32.s0)->b32.s0++; } break; case DESTROY_MARKS: for (i = TOP_MARK_CODE; i <= SPLIT_BOT_MARK_CODE; i++) { if (odd(i)) - cur_ptr = mem[q + (i / 2) + 1].b32.s1; + cur_ptr = mem(q + (i / 2) + 1).b32.s1; else - cur_ptr = mem[q + (i / 2) + 1].b32.s0; + cur_ptr = mem(q + (i / 2) + 1).b32.s0; if (cur_ptr != TEX_NULL) { delete_token_ref(cur_ptr); if (odd(i)) - mem[q + (i / 2) + 1].b32.s1 = TEX_NULL; + mem_ptr(q + (i / 2) + 1)->b32.s1 = TEX_NULL; else - mem[q + (i / 2) + 1].b32.s0 = TEX_NULL; + mem_ptr(q + (i / 2) + 1)->b32.s0 = TEX_NULL; } } break; } - if (mem[q + 2].b32.s0 == TEX_NULL) { - if (mem[q + 3].b32.s0 == TEX_NULL) { + if (mem(q + 2).b32.s0 == TEX_NULL) { + if (mem(q + 3).b32.s0 == TEX_NULL) { free_node(q, MARK_CLASS_NODE_SIZE); q = TEX_NULL; } @@ -18688,7 +18471,7 @@ new_whatsit(small_number s, small_number w) p = get_node(w); NODE_type(p) = WHATSIT_NODE; - mem[p].b16.s0 = s; - mem[cur_list.tail].b32.s1 = p; + mem_ptr(p)->b16.s0 = s; + mem_ptr(cur_list.tail)->b32.s1 = p; cur_list.tail = p; } diff --git a/crates/engine_xetex/xetex/xetex-xetexd.h b/crates/engine_xetex/xetex/xetex-xetexd.h index 49746c9c2..b6b15223d 100644 --- a/crates/engine_xetex/xetex/xetex-xetexd.h +++ b/crates/engine_xetex/xetex/xetex-xetexd.h @@ -11,6 +11,7 @@ #include "teckit-Common.h" #include "xetex-ext.h" #include "tectonic_bridge_core.h" +#include "xetex_bindings.h" /* xetex_format.h needs this: */ typedef unsigned char eight_bits; @@ -84,24 +85,28 @@ typedef unsigned char four_choices; * */ -#ifdef WORDS_BIGENDIAN - -typedef struct b32x2_be_t { int32_t s1, s0; } b32x2; -typedef struct b16x4_be_t { uint16_t s3, s2, s1, s0; } b16x4; - -#else - -typedef struct b32x2_le_t { int32_t s0, s1; } b32x2; -typedef struct b16x4_le_t { uint16_t s0, s1, s2, s3; } b16x4; +//#ifdef WORDS_BIGENDIAN +// +//typedef struct b32x2_be_t { int32_t s1, s0; } b32x2; +//typedef struct b16x4_be_t { uint16_t s3, s2, s1, s0; } b16x4; +// +//#else +// +//typedef struct b32x2_le_t { int32_t s0, s1; } b32x2; +//typedef struct b16x4_le_t { uint16_t s0, s1, s2, s3; } b16x4; +// +//#endif /*WORDS_BIGENDIAN*/ -#endif /*WORDS_BIGENDIAN*/ +typedef B16x4 b16x4; +typedef B32x2 b32x2; +typedef MemoryWord memory_word; -typedef union { - b32x2 b32; - b16x4 b16; - double gr; - void *ptr; -} memory_word; +//typedef union { +// b32x2 b32; +// b16x4 b16; +// double gr; +// void *ptr; +//} memory_word; /* ## THE ORIGINAL SITUATION (archived for posterity) * @@ -201,104 +206,104 @@ typedef union { * this conversion besides painstakingly annotating things. */ -#define LLIST_link(p) mem[p].b32.s1 -#define LLIST_info(p) mem[p].b32.s0 +#define LLIST_link(p) mem_ptr(p)->b32.s1 +#define LLIST_info(p) mem_ptr(p)->b32.s0 -#define NODE_type(p) mem[p].b16.s1 /* half of LLIST_info(p) */ -#define NODE_subtype(p) mem[p].b16.s0 /* the other half of LLIST_info(p) */ +#define NODE_type(p) mem_ptr(p)->b16.s1 /* half of LLIST_info(p) */ +#define NODE_subtype(p) mem_ptr(p)->b16.s0 /* the other half of LLIST_info(p) */ -#define BOX_lr_mode(p) mem[p].b16.s0 /* subtype; records L/R direction mode */ -#define BOX_width(p) mem[(p) + 1].b32.s1 /* a scaled; 1 <=> WEB const `width_offset` */ -#define BOX_depth(p) mem[(p) + 2].b32.s1 /* a scaled; 2 <=> WEB const `depth_offset` */ -#define BOX_height(p) mem[(p) + 3].b32.s1 /* a scaled; 3 <=> WEB const `height_offset` */ -#define BOX_shift_amount(p) mem[(p) + 4].b32.s1 /* a scaled */ -#define BOX_list_ptr(p) mem[(p) + 5].b32.s1 /* aka `link` of p+5 */ -#define BOX_glue_sign(p) mem[(p) + 5].b16.s1 /* aka `type` of p+5 */ -#define BOX_glue_order(p) mem[(p) + 5].b16.s0 /* aka `subtype` of p+5 */ -#define BOX_glue_set(p) mem[(p) + 6].gr /* the glue ratio */ +#define BOX_lr_mode(p) mem_ptr(p)->b16.s0 /* subtype; records L/R direction mode */ +#define BOX_width(p) mem_ptr((p) + 1)->b32.s1 /* a scaled; 1 <=> WEB const `width_offset` */ +#define BOX_depth(p) mem_ptr((p) + 2)->b32.s1 /* a scaled; 2 <=> WEB const `depth_offset` */ +#define BOX_height(p) mem_ptr((p) + 3)->b32.s1 /* a scaled; 3 <=> WEB const `height_offset` */ +#define BOX_shift_amount(p) mem_ptr((p) + 4)->b32.s1 /* a scaled */ +#define BOX_list_ptr(p) mem_ptr((p) + 5)->b32.s1 /* aka `link` of p+5 */ +#define BOX_glue_sign(p) mem_ptr((p) + 5)->b16.s1 /* aka `type` of p+5 */ +#define BOX_glue_order(p) mem_ptr((p) + 5)->b16.s0 /* aka `subtype` of p+5 */ +#define BOX_glue_set(p) mem_ptr((p) + 6)->gr /* the glue ratio */ -#define ACTIVE_NODE_fitness(p) mem[p].b16.s0 /* aka "subtype" of a node */ -#define ACTIVE_NODE_break_node(p) mem[(p) + 1].b32.s1 /* aka "rlink" in double-linked list */ -#define ACTIVE_NODE_line_number(p) mem[(p) + 1].b32.s0 /* aka "llink" in doubly-linked list */ -#define ACTIVE_NODE_total_demerits(p) mem[(p) + 2].b32.s1 /* was originally the `mem[x+2].int` field */ -#define ACTIVE_NODE_shortfall(p) mem[(p) + 3].b32.s1 /* a scaled; "active_short" in the WEB */ -#define ACTIVE_NODE_glue(p) mem[(p) + 4].b32.s1 /* a scaled */ +#define ACTIVE_NODE_fitness(p) mem_ptr(p)->b16.s0 /* aka "subtype" of a node */ +#define ACTIVE_NODE_break_node(p) mem_ptr((p) + 1)->b32.s1 /* aka "rlink" in double-linked list */ +#define ACTIVE_NODE_line_number(p) mem_ptr((p) + 1)->b32.s0 /* aka "llink" in doubly-linked list */ +#define ACTIVE_NODE_total_demerits(p) mem_ptr((p) + 2)->b32.s1 /* was originally the `mem(x+2).int` field */ +#define ACTIVE_NODE_shortfall(p) mem_ptr((p) + 3)->b32.s1 /* a scaled; "active_short" in the WEB */ +#define ACTIVE_NODE_glue(p) mem_ptr((p) + 4)->b32.s1 /* a scaled */ -#define CHAR_NODE_font(p) mem[p].b16.s1 /* aka "type" of a node */ -#define CHAR_NODE_character(p) mem[p].b16.s0 /* aka "subtype" of a node */ +#define CHAR_NODE_font(p) mem_ptr(p)->b16.s1 /* aka "type" of a node */ +#define CHAR_NODE_character(p) mem_ptr(p)->b16.s0 /* aka "subtype" of a node */ -#define DELTA_NODE_dwidth(p) mem[(p) + 1].b32.s1 /* the "natural width" difference */ -#define DELTA_NODE_dstretch0(p) mem[(p) + 2].b32.s1 /* the stretch difference in points */ -#define DELTA_NODE_dstretch1(p) mem[(p) + 3].b32.s1 /* the stretch difference in fil */ -#define DELTA_NODE_dstretch2(p) mem[(p) + 4].b32.s1 /* the stretch difference in fill */ -#define DELTA_NODE_dstretch3(p) mem[(p) + 5].b32.s1 /* the stretch difference in fill */ -#define DELTA_NODE_dshrink(p) mem[(p) + 6].b32.s1 /* the shrink difference */ +#define DELTA_NODE_dwidth(p) mem_ptr((p) + 1)->b32.s1 /* the "natural width" difference */ +#define DELTA_NODE_dstretch0(p) mem_ptr((p) + 2)->b32.s1 /* the stretch difference in points */ +#define DELTA_NODE_dstretch1(p) mem_ptr((p) + 3)->b32.s1 /* the stretch difference in fil */ +#define DELTA_NODE_dstretch2(p) mem_ptr((p) + 4)->b32.s1 /* the stretch difference in fill */ +#define DELTA_NODE_dstretch3(p) mem_ptr((p) + 5)->b32.s1 /* the stretch difference in fill */ +#define DELTA_NODE_dshrink(p) mem_ptr((p) + 6)->b32.s1 /* the shrink difference */ -#define DISCRETIONARY_NODE_replace_count(p) mem[p].b16.s0 /* aka "subtype" of a node */ -#define DISCRETIONARY_NODE_pre_break(p) mem[(p) + 1].b32.s0 /* aka "llink" in doubly-linked list */ -#define DISCRETIONARY_NODE_post_break(p) mem[(p) + 1].b32.s1 /* aka "rlink" in double-linked list */ +#define DISCRETIONARY_NODE_replace_count(p) mem_ptr(p)->b16.s0 /* aka "subtype" of a node */ +#define DISCRETIONARY_NODE_pre_break(p) mem_ptr((p) + 1)->b32.s0 /* aka "llink" in doubly-linked list */ +#define DISCRETIONARY_NODE_post_break(p) mem_ptr((p) + 1)->b32.s1 /* aka "rlink" in double-linked list */ -#define EDGE_NODE_edge_dist(p) mem[(p) + 2].b32.s1 /* "new left_edge position relative to cur_h" */ +#define EDGE_NODE_edge_dist(p) mem_ptr((p) + 2)->b32.s1 /* "new left_edge position relative to cur_h" */ -#define GLUE_NODE_glue_ptr(p) mem[(p) + 1].b32.s0 /* aka "llink" in doubly-linked list */ -#define GLUE_NODE_leader_ptr(p) mem[(p) + 1].b32.s1 /* aka "rlink" in double-linked list */ +#define GLUE_NODE_glue_ptr(p) mem_ptr((p) + 1)->b32.s0 /* aka "llink" in doubly-linked list */ +#define GLUE_NODE_leader_ptr(p) mem_ptr((p) + 1)->b32.s1 /* aka "rlink" in double-linked list */ -#define INSERTION_NODE_float_cost(p) mem[(p) + 1].b32.s1 /* "the floating_penalty to be used" */ -#define INSERTION_NODE_split_top_ptr(p) mem[(p) + 4].b32.s1 /* a glue pointer */ -#define INSERTION_NODE_ins_ptr(p) mem[(p) + 4].b32.s0 /* a pointer to a vlist */ +#define INSERTION_NODE_float_cost(p) mem_ptr((p) + 1)->b32.s1 /* "the floating_penalty to be used" */ +#define INSERTION_NODE_split_top_ptr(p) mem_ptr((p) + 4)->b32.s1 /* a glue pointer */ +#define INSERTION_NODE_ins_ptr(p) mem_ptr((p) + 4)->b32.s0 /* a pointer to a vlist */ -#define LANGUAGE_NODE_what_lang(p) mem[(p) + 1].b32.s1 /* language number, 0..255 */ -#define LANGUAGE_NODE_what_lhm(p) mem[(p) + 1].b16.s1 /* "minimum left fragment, range 1..63" */ -#define LANGUAGE_NODE_what_rhm(p) mem[(p) + 1].b16.s0 /* "minimum right fragment, range 1..63" */ +#define LANGUAGE_NODE_what_lang(p) mem_ptr((p) + 1)->b32.s1 /* language number, 0..255 */ +#define LANGUAGE_NODE_what_lhm(p) mem_ptr((p) + 1)->b16.s1 /* "minimum left fragment, range 1..63" */ +#define LANGUAGE_NODE_what_rhm(p) mem_ptr((p) + 1)->b16.s0 /* "minimum right fragment, range 1..63" */ -#define LIGATURE_NODE_lig_font(p) mem[(p) + 1].b16.s1 /* WEB: font(lig_char(p)) */ -#define LIGATURE_NODE_lig_char(p) mem[(p) + 1].b16.s0 /* WEB: character(lig_char(p)) */ -#define LIGATURE_NODE_lig_ptr(p) mem[(p) + 1].b32.s1 /* WEB: link(lig_char(p)) */ +#define LIGATURE_NODE_lig_font(p) mem_ptr((p) + 1)->b16.s1 /* WEB: font(lig_char(p)) */ +#define LIGATURE_NODE_lig_char(p) mem_ptr((p) + 1)->b16.s0 /* WEB: character(lig_char(p)) */ +#define LIGATURE_NODE_lig_ptr(p) mem_ptr((p) + 1)->b32.s1 /* WEB: link(lig_char(p)) */ -#define MARK_NODE_ptr(p) mem[(p) + 1].b32.s1 /* "head of the token list for the mark" */ -#define MARK_NODE_class(p) mem[(p) + 1].b32.s0 /* "the mark class" */ +#define MARK_NODE_ptr(p) mem_ptr((p) + 1)->b32.s1 /* "head of the token list for the mark" */ +#define MARK_NODE_class(p) mem_ptr((p) + 1)->b32.s0 /* "the mark class" */ /* To check: do these really only apply to MATH_NODEs? */ #define MATH_NODE_lr_dir(p) (NODE_subtype(p) / R_CODE) #define MATH_NODE_end_lr_type(p) (L_CODE * (NODE_subtype(p) / L_CODE) + END_M_CODE) -#define NATIVE_NODE_size(p) mem[(p) + 4].b16.s3 -#define NATIVE_NODE_font(p) mem[(p) + 4].b16.s2 -#define NATIVE_NODE_length(p) mem[(p) + 4].b16.s1 /* number of UTF16 items in the text */ -#define NATIVE_NODE_glyph(p) mem[(p) + 4].b16.s1 /* ... or the glyph number, if subtype==GLYPH_NODE */ -#define NATIVE_NODE_glyph_count(p) mem[(p) + 4].b16.s0 -#define NATIVE_NODE_glyph_info_ptr(p) mem[(p) + 5].ptr -#define NATIVE_NODE_text(p) ((unsigned short *) &mem[(p) + NATIVE_NODE_SIZE]) +#define NATIVE_NODE_size(p) mem_ptr((p) + 4)->b16.s3 +#define NATIVE_NODE_font(p) mem_ptr((p) + 4)->b16.s2 +#define NATIVE_NODE_length(p) mem_ptr((p) + 4)->b16.s1 /* number of UTF16 items in the text */ +#define NATIVE_NODE_glyph(p) mem_ptr((p) + 4)->b16.s1 /* ... or the glyph number, if subtype==GLYPH_NODE */ +#define NATIVE_NODE_glyph_count(p) mem_ptr((p) + 4)->b16.s0 +#define NATIVE_NODE_glyph_info_ptr(p) mem_ptr((p) + 5)->ptr +#define NATIVE_NODE_text(p) ((unsigned short *) mem_ptr((p) + NATIVE_NODE_SIZE)) -#define PAGE_INS_NODE_broken_ptr(p) mem[(p) + 1].b32.s1 /* "an insertion for this class will break here if anywhere" */ -#define PAGE_INS_NODE_broken_ins(p) mem[(p) + 1].b32.s0 /* "this insertion might break at broken_ptr" */ -#define PAGE_INS_NODE_last_ins_ptr(p) mem[(p) + 2].b32.s1 /* "the most recent insertion for this subtype" */ -#define PAGE_INS_NODE_best_ins_ptr(p) mem[(p) + 2].b32.s0 /* "the optimum most recent insertion" */ +#define PAGE_INS_NODE_broken_ptr(p) mem_ptr((p) + 1)->b32.s1 /* "an insertion for this class will break here if anywhere" */ +#define PAGE_INS_NODE_broken_ins(p) mem_ptr((p) + 1)->b32.s0 /* "this insertion might break at broken_ptr" */ +#define PAGE_INS_NODE_last_ins_ptr(p) mem_ptr((p) + 2)->b32.s1 /* "the most recent insertion for this subtype" */ +#define PAGE_INS_NODE_best_ins_ptr(p) mem_ptr((p) + 2)->b32.s0 /* "the optimum most recent insertion" */ -#define PASSIVE_NODE_prev_break(p) mem[(p) + 1].b32.s0 /* aka "llink" in doubly-linked list */ +#define PASSIVE_NODE_prev_break(p) mem_ptr((p) + 1)->b32.s0 /* aka "llink" in doubly-linked list */ #define PASSIVE_NODE_next_break(p) PASSIVE_NODE_prev_break(p) /* siggggghhhhh */ -#define PASSIVE_NODE_cur_break(p) mem[(p) + 1].b32.s1 /* aka "rlink" in double-linked list */ -#define PASSIVE_NODE_serial(p) mem[p].b32.s0 /* aka "info" */ +#define PASSIVE_NODE_cur_break(p) mem_ptr((p) + 1)->b32.s1 /* aka "rlink" in double-linked list */ +#define PASSIVE_NODE_serial(p) mem_ptr(p)->b32.s0 /* aka "info" */ -#define PENALTY_NODE_penalty(p) mem[(p) + 1].b32.s1 /* was originally the `mem[x+1].int` field */ +#define PENALTY_NODE_penalty(p) mem_ptr((p) + 1)->b32.s1 /* was originally the `mem(x+1).int` field */ -#define PIC_NODE_path_len(p) mem[(p) + 4].b16.s1 /* number of bytes in the path item */ -#define PIC_NODE_path(p) ((unsigned char *) &mem[(p) + PIC_NODE_SIZE]) +#define PIC_NODE_path_len(p) mem_ptr((p) + 4)->b16.s1 /* number of bytes in the path item */ +#define PIC_NODE_path(p) ((unsigned char *) mem_ptr((p) + PIC_NODE_SIZE)) #define PIC_NODE_total_size(p) (PIC_NODE_SIZE + (PIC_NODE_path_len(p) + sizeof(memory_word) - 1) / sizeof(memory_word)) -#define WRITE_NODE_tokens(p) mem[(p) + 1].b32.s1 /* "reference count of token list to write" */ +#define WRITE_NODE_tokens(p) mem_ptr((p) + 1)->b32.s1 /* "reference count of token list to write" */ /* Synctex hacks various nodes to add an extra word at the end to store its * information, hence the need to know the node size to get the synctex * info. */ -#define SYNCTEX_tag(p, nodesize) mem[(p) + nodesize - SYNCTEX_FIELD_SIZE].b32.s0 -#define SYNCTEX_line(p, nodesize) mem[(p) + nodesize - SYNCTEX_FIELD_SIZE].b32.s1 +#define SYNCTEX_tag(p, nodesize) mem_ptr((p) + nodesize - SYNCTEX_FIELD_SIZE)->b32.s0 +#define SYNCTEX_line(p, nodesize) mem_ptr((p) + nodesize - SYNCTEX_FIELD_SIZE)->b32.s1 -#define GLUE_SPEC_ref_count(p) mem[p].b32.s1 /* aka "link" of a link-list node */ -#define GLUE_SPEC_stretch_order(p) mem[p].b16.s1 /* aka "type" of a node */ -#define GLUE_SPEC_shrink_order(p) mem[p].b16.s0 /* aka "subtype" of a node */ -#define GLUE_SPEC_stretch(p) mem[(p) + 2].b32.s1 /* a scaled */ -#define GLUE_SPEC_shrink(p) mem[(p) + 3].b32.s1 /* a scaled */ +#define GLUE_SPEC_ref_count(p) mem_ptr(p)->b32.s1 /* aka "link" of a link-list node */ +#define GLUE_SPEC_stretch_order(p) mem_ptr(p)->b16.s1 /* aka "type" of a node */ +#define GLUE_SPEC_shrink_order(p) mem_ptr(p)->b16.s0 /* aka "subtype" of a node */ +#define GLUE_SPEC_stretch(p) mem_ptr((p) + 2)->b32.s1 /* a scaled */ +#define GLUE_SPEC_shrink(p) mem_ptr((p) + 3)->b32.s1 /* a scaled */ #define FONT_CHARACTER_INFO(f, c) font_info[char_base[f] + (c)].b16 #define FONT_CHARINFO_WIDTH(f, info) font_info[width_base[f] + (info).s3].b32.s1 @@ -307,19 +312,19 @@ typedef union { #define FONT_CHARINFO_ITALCORR(f, info) font_info[italic_base[f] + (info).s1 / 4].b32.s1 #define FONT_CHARACTER_WIDTH(f, c) FONT_CHARINFO_WIDTH(f, FONT_CHARACTER_INFO(f, c)) -#define TOKEN_LIST_ref_count(p) mem[p].b32.s0 +#define TOKEN_LIST_ref_count(p) mem_ptr(p)->b32.s0 /* e-TeX sparse arrays for large-numebered registers, etc. */ -#define ETEX_SA_ref(p) mem[(p) + 1].b32.s0 -#define ETEX_SA_ptr(p) mem[(p) + 1].b32.s1 +#define ETEX_SA_ref(p) mem_ptr((p) + 1)->b32.s0 +#define ETEX_SA_ptr(p) mem_ptr((p) + 1)->b32.s1 #define ETEX_SA_num(p) ETEX_SA_ptr(p) /* e-TeX extended marks stuff ... not sure where to put these */ -#define ETEX_MARK_sa_top_mark(p) mem[(p) + 1].b32.s0 /* \topmarks */ -#define ETEX_MARK_sa_first_mark(p) mem[(p) + 1].b32.s1 /* \firstmarks */ -#define ETEX_MARK_sa_bot_mark(p) mem[(p) + 2].b32.s0 /* \botmarks */ -#define ETEX_MARK_sa_split_first_mark(p) mem[(p) + 2].b32.s1 /* \splitfirstmarks */ -#define ETEX_MARK_sa_split_bot_mark(p) mem[(p) + 3].b32.s0 /* \splitbotmarks */ +#define ETEX_MARK_sa_top_mark(p) mem_ptr((p) + 1)->b32.s0 /* \topmarks */ +#define ETEX_MARK_sa_first_mark(p) mem_ptr((p) + 1)->b32.s1 /* \firstmarks */ +#define ETEX_MARK_sa_bot_mark(p) mem_ptr((p) + 2)->b32.s0 /* \botmarks */ +#define ETEX_MARK_sa_split_first_mark(p) mem_ptr((p) + 2)->b32.s1 /* \splitfirstmarks */ +#define ETEX_MARK_sa_split_bot_mark(p) mem_ptr((p) + 3)->b32.s0 /* \splitbotmarks */ typedef unsigned char glue_ord; /* enum: normal .. filll */ typedef unsigned char group_code; @@ -341,16 +346,6 @@ typedef struct { memory_word aux; /* prev_depth or space_factor/clang or incompleat_noad */ } list_state_record; -typedef struct { - uint16_t state; /* tokenizer state: mid_line, skip_blanks, new_line */ - uint16_t index; /* index of this level of input in input_file array */ - int32_t start; /* position of beginning of current line in `buffer` */ - int32_t loc; /* position of next character to read in `buffer` */ - int32_t limit; /* position of end of line in `buffer` */ - int32_t name; /* string number: name of current file or magic value for terminal, etc. */ - int32_t synctex_tag; -} input_state_t; - typedef enum { HISTORY_SPOTLESS = 0, HISTORY_WARNING_ISSUED = 1, @@ -383,24 +378,15 @@ void remember_source_info(str_number, int); /* All the following variables are defined in xetexini.c */ extern bool shell_escape_enabled; -extern memory_word *eqtb; extern int32_t bad; -extern char *name_of_file; -extern UTF16_code *name_of_file16; -extern int32_t name_length; -extern int32_t name_length16; -extern UnicodeScalar *buffer; extern int32_t first; extern int32_t last; extern int32_t max_buf_stack; extern bool in_initex_mode; -extern int32_t error_line; extern int32_t half_error_line; extern int32_t max_print_line; -extern int32_t max_strings; extern int32_t strings_free; extern int32_t string_vacancies; -extern int32_t pool_size; extern int32_t pool_free; extern int32_t font_mem_size; extern int32_t font_max; @@ -413,51 +399,28 @@ extern int32_t param_size; extern int32_t nest_size; extern int32_t save_size; extern int32_t expand_depth; -extern int file_line_error_style_p; extern int halt_on_error_p; -extern bool quoted_filename; extern bool insert_src_special_auto; extern bool insert_src_special_every_par; extern bool insert_src_special_every_math; extern bool insert_src_special_every_vbox; -extern packed_UTF16_code *str_pool; -extern pool_pointer *str_start; -extern pool_pointer pool_ptr; -extern str_number str_ptr; extern pool_pointer init_pool_ptr; extern str_number init_str_ptr; -extern rust_output_handle_t rust_stdout; -extern rust_output_handle_t log_file; -extern selector_t selector; -extern unsigned char dig[23]; -extern int32_t tally; -extern int32_t term_offset; -extern int32_t file_offset; -extern UTF16_code trick_buf[256]; -extern int32_t trick_count; extern int32_t first_count; -extern bool doing_special; extern UTF16_code *native_text; extern int32_t native_text_size; extern int32_t native_len; extern int32_t save_native_len; -extern unsigned char interaction; extern bool deletions_allowed; extern bool set_box_allowed; -extern tt_history_t history; extern signed char error_count; extern const char* help_line[6]; extern unsigned char help_ptr; extern bool use_err_help; -extern bool arith_error; -extern scaled_t tex_remainder; -extern int32_t randoms[55]; -extern unsigned char j_random; extern scaled_t random_seed; extern int32_t two_to_the[31]; extern int32_t spec_log[29]; extern int32_t temp_ptr; -extern memory_word *mem; extern int32_t lo_mem_max; extern int32_t hi_mem_min; extern int32_t var_used, dyn_used; @@ -479,15 +442,9 @@ extern int32_t max_nest_stack; extern list_state_record cur_list; extern short shown_mode; extern unsigned char old_setting; -extern b32x2 *hash; -extern int32_t hash_used; -extern int32_t hash_extra; -extern int32_t hash_top; -extern int32_t eqtb_top; extern int32_t hash_high; extern bool no_new_control_sequence; extern int32_t cs_count; -extern b32x2 prim[PRIM_SIZE + 1]; extern int32_t prim_used; extern memory_word *save_stack; extern int32_t save_ptr; @@ -500,17 +457,10 @@ extern eight_bits cur_cmd; extern int32_t cur_chr; extern int32_t cur_cs; extern int32_t cur_tok; -extern input_state_t *input_stack; -extern int32_t input_ptr; extern int32_t max_in_stack; -extern input_state_t cur_input; -extern int32_t in_open; extern int32_t open_parens; extern UFILE **input_file; -extern int32_t line; -extern int32_t *line_stack; extern str_number *source_filename_stack; -extern str_number *full_source_filename_stack; extern unsigned char scanner_status; extern int32_t warning_index; extern int32_t def_ref; @@ -539,19 +489,9 @@ extern unsigned char if_limit; extern small_number cur_if; extern int32_t if_line; extern int32_t skip_line; -extern str_number cur_name; -extern str_number cur_area; -extern str_number cur_ext; -extern pool_pointer area_delimiter; -extern pool_pointer ext_delimiter; -extern UTF16_code file_name_quote_char; extern int32_t format_default_length; extern char *TEX_format_default; -extern bool name_in_progress; -extern str_number job_name; -extern bool log_opened; extern const char* output_file_extension; -extern str_number texmf_log_name; extern memory_word *font_info; extern font_index fmem_ptr; extern internal_font_number font_ptr; @@ -688,7 +628,6 @@ extern int32_t cur_box; extern int32_t after_token; extern bool long_help_seen; extern str_number format_ident; -extern rust_output_handle_t write_file[16]; extern bool write_open[18]; extern int32_t write_loc; extern scaled_t cur_page_width; @@ -715,7 +654,6 @@ extern trie_pointer hyph_start; extern trie_pointer hyph_index; extern int32_t disc_ptr[4]; extern pool_pointer edit_name_start; -extern bool stop_at_space; extern int32_t native_font_type_flag; extern bool xtx_ligature_present; extern scaled_t delta; @@ -1053,73 +991,6 @@ void math_fraction(void); void math_left_right(void); void flush_math(void); -/* xetex-output */ - -// Duplicate messages printed to log/terminal into a warning diagnostic buffer, -// until a call capture_to_diagnostic(0). A standard usage of this is -// -// ttbc_diagnostic_t *warning = diagnostic_begin_capture_warning_here(); -// -// ... XeTeX prints some errors using print_* functions ... -// -// capture_to_diagnostic(NULL); -// -// The current file and line number information are prefixed to the captured -// output. -// -// NOTE: the only reason there isn't also an _error_ version of this function is -// that we haven't yet wired up anything that uses it. -ttbc_diagnostic_t *diagnostic_begin_capture_warning_here(void); - -// A lower-level API to begin or end the capture of messages into the diagnostic -// buffer. You can start capture by obtaining a diagnostic_t and passing it to -// this function -- however, the other functions in this API generally do this -// for you. Complete capture by passing NULL. Either way, if a capture is in -// progress when this function is called, it will be completed and reported. -void capture_to_diagnostic(ttbc_diagnostic_t *diagnostic); - -// A replacement for xetex print_file_line+print_nl_ctr blocks. e.g. Replace -// -// if (file_line_error_style_p) -// print_file_line(); -// else -// print_nl_cstr("! "); -// print_cstr("Cannot use "); -// -// with -// -// ttbc_diagnostic_t *errmsg = error_here_with_diagnostic("Cannot use "); -// -// This function calls capture_to_diagnostic(errmsg) to begin diagnostic -// capture. You must call capture_to_diagnostic(NULL) to mark the capture as -// complete. -ttbc_diagnostic_t *error_here_with_diagnostic(const char* message); - -void print_ln(void); -void print_raw_char(UTF16_code s, bool incr_offset); -void print_char(int32_t s); -void print(int32_t s); -void print_cstr(const char* s); -void print_nl(str_number s); -void print_nl_cstr(const char* s); -void print_esc(str_number s); -void print_esc_cstr(const char* s); -void print_int(int32_t n); -void print_cs(int32_t p); -void sprint_cs(int32_t p); -void print_file_name(int32_t n, int32_t a, int32_t e); -void print_size(int32_t s); -void print_write_whatsit(const char* s, int32_t p); -void print_native_word(int32_t p); -void print_sa_num(int32_t q); -void print_file_line(void); -void print_two(int32_t n); -void print_hex(int32_t n); -void print_roman_int(int32_t n); -void print_current_string(void); -void print_scaled(scaled_t s); -void print_ucs_code(UnicodeScalar n); - /* xetex-pagebuilder */ void initialize_pagebuilder_variables(void); @@ -1166,7 +1037,7 @@ print_c_string(const char *str) { static inline pool_pointer cur_length(void) { /*41: The length of the current string in the pool */ - return pool_ptr - str_start[str_ptr - TOO_BIG_CHAR]; + return pool_ptr() - str_start(str_ptr() - TOO_BIG_CHAR); } @@ -1181,14 +1052,14 @@ void tt_insert_special(const char *ascii_text); /* additional declarations we want to slip in for xetex */ /* p is native_word node; g is XeTeX_use_glyph_metrics flag */ -#define set_native_metrics(p,g) measure_native_node(&(mem[p]), g) -#define set_native_glyph_metrics(p,g) measure_native_glyph(&(mem[p]), g) -#define set_justified_native_glyphs(p) store_justified_native_glyphs(&(mem[p])) -#define get_native_italic_correction(p) real_get_native_italic_correction(&(mem[p])) -#define get_native_glyph_italic_correction(p) real_get_native_glyph_italic_correction(&(mem[p])) -#define get_native_glyph(p,i) real_get_native_glyph(&(mem[p]), i) -#define make_xdv_glyph_array_data(p) makeXDVGlyphArrayData(&(mem[p])) -#define get_native_word_cp(p,s) real_get_native_word_cp(&(mem[p]), s) +#define set_native_metrics(p,g) measure_native_node((mem_ptr(p)), g) +#define set_native_glyph_metrics(p,g) measure_native_glyph((mem_ptr(p)), g) +#define set_justified_native_glyphs(p) store_justified_native_glyphs((mem_ptr(p))) +#define get_native_italic_correction(p) real_get_native_italic_correction((mem_ptr(p))) +#define get_native_glyph_italic_correction(p) real_get_native_glyph_italic_correction((mem_ptr(p))) +#define get_native_glyph(p,i) real_get_native_glyph((mem_ptr(p)), i) +#define make_xdv_glyph_array_data(p) makeXDVGlyphArrayData((mem_ptr(p))) +#define get_native_word_cp(p,s) real_get_native_word_cp((mem_ptr(p)), s) /* easier to do the bit-twiddling here than in Pascal */ /* read fields from a 32-bit math code */ diff --git a/crates/engine_xetex/xetex/xetex_bindings.h b/crates/engine_xetex/xetex/xetex_bindings.h index 3156007c2..b3a42d11c 100644 --- a/crates/engine_xetex/xetex/xetex_bindings.h +++ b/crates/engine_xetex/xetex/xetex_bindings.h @@ -18,6 +18,132 @@ */ #define FORMAT_SERIAL 33 +#define NULL_CS 2228225 + +#define PRIM_SIZE 2100 + +#define UNDEFINED_CONTROL_SEQUENCE 2254339 + +#define FROZEN_NULL_FONT 2245338 + +#define DIMEN_VAL_LIMIT 128 + +#define TEXT_SIZE 0 + +#define SCRIPT_SIZE 256 + +#define SCRIPT_SCRIPT_SIZE 512 + +#define WHATSIT_NODE 8 + +#define NATIVE_WORD_NODE 40 + +#define EQTB_SIZE 8941458 + +#define ACTIVE_BASE 1 + +#define SINGLE_BASE 1114113 + +#define PRIM_EQTB_BASE 2243238 + +#define CAT_CODE_BASE 2256169 + +#define INT_BASE 7826729 + +#define INT_PARS 83 + +#define HASH_OFFSET 514 + +#define HASH_BASE 2228226 + +#define MAX_PRINT_LINE 79 + +#define BIGGEST_CHAR 65535 + +#define BIGGEST_USV 1114111 + +#define TOO_BIG_CHAR 65536 + +typedef enum { + History_Spotless = 0, + History_WarningIssued = 1, + History_ErrorIssued = 2, + History_FatalError = 3, +} History; + +typedef int32_t StrNumber; + +typedef struct { + /** + * tokenizer state: mid_line, skip_blanks, new_line + */ + uint16_t state; + /** + * index of this level of input in input_file array + */ + uint16_t index; + /** + * position of beginning of current line in `buffer` + */ + int32_t start; + /** + * position of next character to read in `buffer` + */ + int32_t loc; + /** + * position of end of line in `buffer` + */ + int32_t limit; + /** + * name of current file or magic value for terminal, etc. + */ + StrNumber name; + int32_t synctex_tag; +} input_state_t; + +#if defined(WORDS_BIGENDIAN) +typedef struct { + int32_t s1; + int32_t s0; +} B32x2; +#endif + +#if !defined(WORDS_BIGENDIAN) +typedef struct { + int32_t s0; + int32_t s1; +} B32x2; +#endif + +#if defined(WORDS_BIGENDIAN) +typedef struct { + uint16_t s3; + uint16_t s2; + uint16_t s1; + uint16_t s0; +} B16x4; +#endif + +#if !defined(WORDS_BIGENDIAN) +typedef struct { + uint16_t s0; + uint16_t s1; + uint16_t s2; + uint16_t s3; +} B16x4; +#endif + +typedef union { + B32x2 b32; + B16x4 b16; + double gr; + void *ptr; +} MemoryWord; + +typedef int32_t Scaled; + +#define EMPTY_STRING (65536 + 1) + #ifdef __cplusplus extern "C" { #endif // __cplusplus @@ -29,8 +155,459 @@ extern int tt_engine_xetex_main(ttbc_state_t *api, const char *input_file_name, uint64_t build_date); +rust_output_handle_t dvi_file(void); + +void set_dvi_file(rust_output_handle_t file); + +int32_t dvi_limit(void); + +void set_dvi_limit(int32_t val); + +uint8_t dvi_buf(uintptr_t idx); + +void set_dvi_buf(uintptr_t idx, uint8_t val); + +uint8_t *dvi_buf_ptr(uintptr_t idx); + +void resize_dvi_buf(uintptr_t len); + +void clear_dvi_buf(void); + +uint32_t selector(void); + +void set_selector(uint32_t val); + +int32_t tally(void); + +void set_tally(int32_t val); + +int32_t error_line(void); + +void set_error_line(int32_t val); + +int32_t trick_count(void); + +void set_trick_count(int32_t val); + +uint16_t trick_buf(uintptr_t idx); + +void set_trick_buf(uintptr_t idx, uint16_t val); + +int32_t eqtb_top(void); + +void set_eqtb_top(int32_t val); + +uintptr_t name_length(void); + +const char *name_of_file(void); + +void set_name_of_file(const char *val); + +uintptr_t name_length16(void); + +const uint16_t *name_of_file16(void); + +void set_name_of_file16(const uint16_t *val, uintptr_t len); + +StrNumber cur_name(void); + +void set_cur_name(StrNumber val); + +StrNumber cur_area(void); + +void set_cur_area(StrNumber val); + +StrNumber cur_ext(void); + +void set_cur_ext(StrNumber val); + +StrNumber job_name(void); + +void set_job_name(StrNumber val); + +uintptr_t area_delimiter(void); + +void set_area_delimiter(uintptr_t val); + +uintptr_t ext_delimiter(void); + +void set_ext_delimiter(uintptr_t val); + +bool name_in_progress(void); + +void set_name_in_progress(bool val); + +bool stop_at_space(void); + +void set_stop_at_space(bool val); + +uint16_t file_name_quote_char(void); + +void set_file_name_quote_char(uint16_t val); + +bool quoted_filename(void); + +void set_quoted_filename(bool val); + +StrNumber texmf_log_name(void); + +void set_texmf_log_name(StrNumber val); + +bool log_opened(void); + +void set_log_opened(bool val); + +void resize_input_stack(uintptr_t len); + +input_state_t input_stack(uintptr_t idx); + +void set_input_stack(uintptr_t idx, input_state_t state); + +void clear_input_stack(void); + +uintptr_t input_ptr(void); + +void set_input_ptr(uintptr_t val); + +input_state_t cur_input(void); + +input_state_t *cur_input_ptr(void); + +void set_cur_input(input_state_t val); + +uint8_t interaction(void); + +void set_interaction(uint8_t val); + +History history(void); + +void set_history(uint8_t val); + +MemoryWord eqtb(uintptr_t idx); + +void set_eqtb(uintptr_t idx, MemoryWord val); + +MemoryWord *eqtb_ptr(uintptr_t idx); + +void resize_eqtb(uintptr_t len); + +void clear_eqtb(void); + +MemoryWord mem(uintptr_t idx); + +void set_mem(uintptr_t idx, MemoryWord val); + +MemoryWord *mem_ptr(uintptr_t idx); + +void resize_mem(uintptr_t len); + +void clear_mem(void); + +B32x2 prim(uintptr_t idx); + +void set_prim(uintptr_t idx, B32x2 val); + +B32x2 *prim_ptr(uintptr_t idx); + +void resize_buffer(uintptr_t len); + +uint32_t *buffer_ptr(void); + +uint32_t buffer(uintptr_t idx); + +void set_buffer(uintptr_t idx, uint32_t val); + +void clear_buffer(void); + +StrNumber maketexstring(const char *str); + +char *gettexstring(StrNumber s); + +void pack_file_name(StrNumber n, StrNumber a, StrNumber e); + +void pack_job_name(const char *s); + +void make_utf16_name(void); + +void begin_name(void); + +void end_name(void); + +bool more_name(uint16_t c); + +StrNumber make_name_string(void); + +void open_log_file(void); + +void pre_error_message(void); + +void resize_hash(uintptr_t len); + +B32x2 hash(uintptr_t idx); + +void set_hash(uintptr_t idx, B32x2 val); + +B32x2 *hash_ptr(uintptr_t idx); + +void clear_hash(void); + +int32_t hash_used(void); + +void set_hash_used(int32_t val); + +int32_t hash_extra(void); + +void set_hash_extra(int32_t val); + +int32_t hash_top(void); + +void set_hash_top(int32_t val); + +int32_t in_open(void); + +void set_in_open(int32_t val); + +StrNumber full_source_filename_stack(uintptr_t idx); + +void set_full_source_filename_stack(uintptr_t idx, StrNumber val); + +void clear_full_source_filename_stack(void); + +int32_t line(void); + +void set_line(int32_t val); + +int32_t line_stack(uintptr_t idx); + +void set_line_stack(uintptr_t idx, int32_t val); + +void clear_line_stack(void); + +int32_t file_line_error_style_p(void); + +void set_file_line_error_style_p(int32_t val); + +ttbc_diagnostic_t *current_diagnostic(void); + +int32_t term_offset(void); + +void set_term_offset(int32_t val); + +int32_t file_offset(void); + +void set_file_offset(int32_t val); + +Option_OutputId rust_stdout(void); + +void set_rust_stdout(Option_OutputId val); + +Option_OutputId log_file(void); + +void set_log_file(Option_OutputId val); + +Option_OutputId write_file(uintptr_t idx); + +void set_write_file(uintptr_t idx, Option_OutputId val); + +bool doing_special(void); + +void set_doing_special(bool val); + +uint8_t dig(uintptr_t idx); + +void set_dig(uintptr_t idx, uint8_t val); + +/** + * A lower-level API to begin or end the capture of messages into the diagnostic + * buffer. You can start capture by obtaining a diagnostic_t and passing it to + * this function -- however, the other functions in this API generally do this + * for you. Complete capture by passing NULL. Either way, if a capture is in + * progress when this function is called, it will be completed and reported. + */ +void capture_to_diagnostic(ttbc_diagnostic_t *diagnostic); + +void diagnostic_print_file_line(ttbc_diagnostic_t *diagnostic); + +/** + * Duplicate messages printed to log/terminal into a warning diagnostic buffer, + * until a call capture_to_diagnostic(0). A standard usage of this is + * ```c + * ttbc_diagnostic_t *warning = diagnostic_begin_capture_warning_here(); + * + * // ... XeTeX prints some errors using print_* functions ... + * + * capture_to_diagnostic(NULL); + * ``` + * + * The current file and line number information are prefixed to the captured + * output. + * + * NOTE: the only reason there isn't also an _error_ version of this function is + * that we haven't yet wired up anything that uses it. + */ +ttbc_diagnostic_t *diagnostic_begin_capture_warning_here(void); + +/** + * A replacement for xetex print_file_line+print_nl_ctr blocks. e.g. Replace + * + * ```c + * if (file_line_error_style_p) + * print_file_line(); + * else + * print_nl_cstr("! "); + * print_cstr("Cannot use "); + * ``` + * with + * ```c + * ttbc_diagnostic_t *errmsg = error_here_with_diagnostic("Cannot use "); + * ``` + * + * This function calls `capture_to_diagnostic(errmsg)` to begin diagnostic + * capture. You must call `capture_to_diagnostic(NULL)` to mark the capture as + * complete. + */ +ttbc_diagnostic_t *error_here_with_diagnostic(const char *msg); + +void warn_char(int c); + +void print_ln(void); + +void print_raw_char(uint16_t s, uint8_t offset); + +void print_char(int32_t s); + +void print_cstr(const char *str); + +void print_nl_cstr(const char *str); + +void print_esc_cstr(const char *str); + +void print(StrNumber str); + +void print_nl(StrNumber str); + +void print_esc(StrNumber str); + +void print_the_digs(uint8_t k); + +void print_int(int32_t n); + +void print_file_line(void); + +void print_cs(int32_t p); + +void sprint_cs(int32_t p); + +void print_file_name(int32_t n, int32_t a, int32_t e); + +void print_size(int32_t s); + +void print_write_whatsit(const char *s, int32_t p); + +void print_native_word(int32_t p); + +void print_sa_num(int32_t q); + +void print_two(int32_t n); + +void print_hex(int32_t n); + +void print_scaled(Scaled s); + +void print_ucs_code(uint32_t n); + +void print_current_string(void); + +void print_roman_int(int32_t n); + +void resize_str_pool(uintptr_t size); + +void clear_str_pool(void); + +uint16_t str_pool(uintptr_t idx); + +uint16_t *str_pool_ptr(uintptr_t idx); + +void set_str_pool(uintptr_t idx, uint16_t val); + +uint32_t str_start(uintptr_t idx); + +uint32_t *str_start_ptr(uintptr_t idx); + +void resize_str_start(uintptr_t size); + +void clear_str_start(void); + +void set_str_start(uintptr_t idx, uint32_t val); + +uintptr_t pool_ptr(void); + +void set_pool_ptr(uintptr_t val); + +uintptr_t str_ptr(void); + +void set_str_ptr(uintptr_t val); + +uintptr_t pool_size(void); + +void set_pool_size(uintptr_t val); + +uintptr_t max_strings(void); + +void set_max_strings(uintptr_t val); + +StrNumber make_string(void); + +StrNumber slow_make_string(void); + +uintptr_t length(StrNumber s); + +bool str_eq_str(StrNumber s1, StrNumber s2); + +StrNumber search_string(StrNumber search); + +bool arith_error(void); + +void set_arith_error(bool val); + +Scaled tex_remainder(void); + +void set_tex_remainder(Scaled val); + +int32_t randoms(uintptr_t idx); + +uint8_t j_random(void); + +void set_j_random(uint8_t val); + +int32_t tex_round(double r); + +int32_t half(int32_t x); + +Scaled mult_and_add(int32_t n, Scaled x, Scaled y, Scaled max_answer); + +Scaled x_over_n(Scaled x, int32_t n); + +Scaled xn_over_d(Scaled x, int32_t n, int32_t d); + +Scaled round_xn_over_d(Scaled x, int32_t n, int32_t d); + +int32_t make_frac(int32_t p, int32_t q); + +int32_t take_frac(int32_t q, int32_t f); + +int32_t ab_vs_cd(int32_t a, int32_t b, int32_t c, int32_t d); + +void new_randoms(void); + +void init_randoms(int32_t seed); + +int32_t unif_rand(int32_t x); + +int32_t norm_rand(void); + #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} // extern "C" +#endif // __cplusplus -#endif /* TECTONIC_ENGINE_XETEX_BINDGEN_H */ +#endif /* TECTONIC_ENGINE_XETEX_BINDGEN_H */ diff --git a/crates/engine_xetex/xetex/xetex_format.h b/crates/engine_xetex/xetex/xetex_format.h index 85cb9144b..40161d84a 100644 --- a/crates/engine_xetex/xetex/xetex_format.h +++ b/crates/engine_xetex/xetex/xetex_format.h @@ -199,7 +199,7 @@ #define NULL_CS 2228225 /* = 0x220001 */ #define HASH_BASE 2228226 /* = 0x220002 */ #define FROZEN_CONTROL_SEQUENCE 2243226 /* = 0x223a9a */ -#define PRIM_EQTB_BASE 2243238 /* = 0x223aa6 */ +#define PRIM_EQTB_BASE 2243238 /* = FROZEN_NULL_FONT */ #define FROZEN_NULL_FONT 2245338 /* = 0x2242da */ #define UNDEFINED_CONTROL_SEQUENCE 2254339 /* = 0x226603 */ #define GLUE_BASE 2254340 /* = 0x226604 */