@@ -6,16 +6,21 @@ use std::{ptr, slice};
66
77mod memory;
88
9+ use crate :: c_api:: errors:: rs_int_error;
910use crate :: c_api:: is_dir_sep;
1011use crate :: c_api:: output:: {
11- rs_print, rs_print_bytes, rs_print_char, rs_print_cs, rs_print_esc_bytes, rs_print_int,
12- rs_print_ln, rs_print_nl, rs_print_nl_bytes, rs_print_raw_char,
12+ rs_capture_to_diagnostic, rs_error_here_with_diagnostic, rs_print, rs_print_bytes,
13+ rs_print_char, rs_print_cs, rs_print_esc_bytes, rs_print_int, rs_print_ln, rs_print_nl,
14+ rs_print_nl_bytes, rs_print_raw_char,
1315} ;
1416use crate :: c_api:: pool:: {
1517 rs_make_string, rs_search_string, rs_slow_make_string, StringPool , EMPTY_STRING , TOO_BIG_CHAR ,
1618} ;
1719pub use memory:: * ;
1820
21+ pub const LEVEL_ZERO : u16 = 0 ;
22+ pub const LEVEL_ONE : u16 = 1 ;
23+
1924pub const NULL_CS : usize = 0x220001 ;
2025pub const PRIM_SIZE : usize = 2100 ;
2126pub const UNDEFINED_CONTROL_SEQUENCE : usize = 0x226603 ;
@@ -1726,3 +1731,73 @@ pub fn rs_token_show(globals: &mut Globals<'_, '_>, p: usize) {
17261731pub extern "C" fn token_show ( p : i32 ) {
17271732 Globals :: with ( |globals| rs_token_show ( globals, p as usize ) )
17281733}
1734+
1735+ pub fn rs_geq_word_define ( globals : & mut Globals < ' _ , ' _ > , p : usize , w : i32 ) {
1736+ globals. engine . eqtb [ p] . b32 . s1 = w;
1737+ globals. engine . set_xeq_level ( p, LEVEL_ONE ) ;
1738+ }
1739+
1740+ #[ no_mangle]
1741+ pub extern "C" fn geq_word_define ( p : i32 , w : i32 ) {
1742+ Globals :: with ( |globals| rs_geq_word_define ( globals, p as usize , w) )
1743+ }
1744+
1745+ pub fn rs_prepare_mag ( globals : & mut Globals < ' _ , ' _ > ) -> Option < Box < dyn Fn ( ) > > {
1746+ if globals. engine . mag_set > 0 && globals. engine . int_par ( IntPar :: Mag ) != globals. engine . mag_set {
1747+ rs_error_here_with_diagnostic ( globals, b"Incompatible magnification (" ) ;
1748+ rs_print_int ( globals, globals. engine . int_par ( IntPar :: Mag ) ) ;
1749+ rs_print_bytes ( globals, b")" ) ;
1750+ rs_print_nl_bytes ( globals, b" the previous value will be retained" ) ;
1751+
1752+ globals
1753+ . out
1754+ . current_diagnostic
1755+ . as_deref_mut ( )
1756+ . unwrap ( )
1757+ . append ( format ! ( " {}" , globals. engine. mag_set) ) ;
1758+ rs_capture_to_diagnostic ( globals, None ) ;
1759+
1760+ globals. engine . help_ptr = 2 ;
1761+ globals. engine . help_line [ 1 ] =
1762+ c"I can handle only one magnification ratio per job. So I've" . as_ptr ( ) ;
1763+ globals. engine . help_line [ 0 ] =
1764+ c"reverted to the magnification you used earlier on this run." . as_ptr ( ) ;
1765+
1766+ if let Some ( f) = rs_int_error ( globals, globals. engine . mag_set ) {
1767+ return Some ( f) ;
1768+ }
1769+ rs_geq_word_define (
1770+ globals,
1771+ INT_BASE + IntPar :: Mag as usize ,
1772+ globals. engine . mag_set ,
1773+ ) ;
1774+ }
1775+
1776+ if globals. engine . int_par ( IntPar :: Mag ) <= 0 || globals. engine . int_par ( IntPar :: Mag ) > 32768 {
1777+ rs_error_here_with_diagnostic ( globals, b"Illegal magnification has been changed to 1000" ) ;
1778+ globals
1779+ . out
1780+ . current_diagnostic
1781+ . as_deref_mut ( )
1782+ . unwrap ( )
1783+ . append ( format ! ( " {}" , globals. engine. int_par( IntPar :: Mag ) ) ) ;
1784+ rs_capture_to_diagnostic ( globals, None ) ;
1785+
1786+ globals. engine . help_ptr = 1 ;
1787+ globals. engine . help_line [ 0 ] =
1788+ c"The magnification ratio must be between 1 and 32768." . as_ptr ( ) ;
1789+ if let Some ( f) = rs_int_error ( globals, globals. engine . int_par ( IntPar :: Mag ) ) {
1790+ return Some ( f) ;
1791+ }
1792+ rs_geq_word_define ( globals, INT_BASE + IntPar :: Mag as usize , 1000 ) ;
1793+ }
1794+
1795+ globals. engine . mag_set = globals. engine . int_par ( IntPar :: Mag ) ;
1796+ None
1797+ }
1798+
1799+ #[ no_mangle]
1800+ pub extern "C" fn prepare_mag ( ) {
1801+ let outside_lock = Globals :: with ( |globals| rs_prepare_mag ( globals) ) ;
1802+ outside_lock. map ( |f| f ( ) ) ;
1803+ }
0 commit comments