Skip to content

Commit 3f809e4

Browse files
committed
Port begin_name and end_name
1 parent 6d3e76a commit 3f809e4

File tree

3 files changed

+101
-77
lines changed

3 files changed

+101
-77
lines changed

crates/engine_xetex/src/c_api/engine.rs

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use std::{ptr, slice};
66

77
mod memory;
88

9-
use crate::c_api::pool::{rs_make_string, StringPool, EMPTY_STRING};
9+
use crate::c_api::pool::{
10+
rs_make_string, rs_search_string, rs_slow_make_string, StringPool, EMPTY_STRING, TOO_BIG_CHAR,
11+
};
1012
pub use memory::*;
1113

1214
pub const NULL_CS: usize = 0x220001;
@@ -547,6 +549,90 @@ pub fn rs_make_utf16_name(engine: &mut EngineCtx) {
547549
.map(|s| s.encode_utf16().collect());
548550
}
549551

552+
pub fn rs_begin_name(globals: &mut Globals<'_, '_>) {
553+
globals.engine.area_delimiter = 0;
554+
globals.engine.ext_delimiter = 0;
555+
globals.engine.quoted_filename = false;
556+
globals.engine.file_name_quote_char = 0;
557+
}
558+
559+
pub fn rs_end_name(globals: &mut Globals<'_, '_>) {
560+
if globals.strings.str_ptr + 3 > globals.strings.max_strings {
561+
todo!("overflow(\"number of strings\", max_strings() - init_str_ptr)");
562+
}
563+
564+
/* area_delimiter is the length from the start of the filename to the
565+
* directory seperator "/", which we use to construct the stringpool
566+
* string `cur_area`. If there was already a string in the stringpool for
567+
* the area, reuse it. */
568+
569+
if globals.engine.area_delimiter == 0 {
570+
globals.engine.cur_area = EMPTY_STRING;
571+
} else {
572+
globals.engine.cur_area = globals.strings.str_ptr as StrNumber;
573+
globals.strings.str_start[globals.strings.str_ptr + 1 - 0x10000] =
574+
globals.strings.str_start[globals.strings.str_ptr - TOO_BIG_CHAR]
575+
+ globals.engine.area_delimiter as u32;
576+
globals.strings.str_ptr += 1;
577+
578+
let temp_str = rs_search_string(globals.strings, globals.engine.cur_area);
579+
580+
if temp_str > 0 {
581+
globals.engine.cur_area = temp_str;
582+
globals.strings.str_ptr -= 1;
583+
584+
for j in (globals.strings.str_start[globals.strings.str_ptr + 1 - 0x10000] as usize)
585+
..globals.strings.pool_ptr
586+
{
587+
globals.strings.str_pool[j - globals.engine.area_delimiter] =
588+
globals.strings.str_pool[j];
589+
}
590+
591+
globals.strings.pool_ptr -= globals.engine.area_delimiter;
592+
}
593+
}
594+
595+
/* ext_delimiter is the length from the start of the filename to the
596+
* extension '.' delimiter, which we use to construct the stringpool
597+
* strings `cur_ext` and `cur_name`. */
598+
599+
if globals.engine.ext_delimiter == 0 {
600+
globals.engine.cur_ext = EMPTY_STRING;
601+
globals.engine.cur_name = rs_slow_make_string(globals.strings);
602+
} else {
603+
globals.engine.cur_name = globals.strings.str_ptr as StrNumber;
604+
globals.strings.str_start[globals.strings.str_ptr + 1 - 0x10000] =
605+
globals.strings.str_start[globals.strings.str_ptr - TOO_BIG_CHAR]
606+
+ globals.engine.ext_delimiter as u32
607+
- globals.engine.area_delimiter as u32
608+
- 1;
609+
globals.strings.str_ptr += 1;
610+
611+
globals.engine.cur_ext = rs_make_string(globals.strings);
612+
globals.strings.str_ptr -= 1;
613+
614+
let temp_str = rs_search_string(globals.strings, globals.engine.cur_name);
615+
616+
if temp_str > 0 {
617+
globals.engine.cur_name = temp_str;
618+
globals.strings.str_ptr -= 1;
619+
620+
for j in (globals.strings.str_start[globals.strings.str_ptr + 1 - 0x10000] as usize)
621+
..globals.strings.pool_ptr
622+
{
623+
globals.strings.str_pool
624+
[j - globals.engine.ext_delimiter + globals.engine.area_delimiter + 1] =
625+
globals.strings.str_pool[j];
626+
}
627+
628+
globals.strings.pool_ptr -=
629+
globals.engine.ext_delimiter - globals.engine.area_delimiter - 1;
630+
}
631+
}
632+
633+
globals.engine.cur_ext = rs_slow_make_string(globals.strings);
634+
}
635+
550636
#[no_mangle]
551637
pub unsafe extern "C" fn maketexstring(str: *const libc::c_char) -> StrNumber {
552638
if str.is_null() {
@@ -580,3 +666,13 @@ pub extern "C" fn pack_job_name(s: *const libc::c_char) {
580666
pub extern "C" fn make_utf16_name() {
581667
ENGINE_CTX.with_borrow_mut(|engine| rs_make_utf16_name(engine))
582668
}
669+
670+
#[no_mangle]
671+
pub extern "C" fn begin_name() {
672+
Globals::with(|globals| rs_begin_name(globals))
673+
}
674+
675+
#[no_mangle]
676+
pub extern "C" fn end_name() {
677+
Globals::with(|globals| rs_end_name(globals))
678+
}

crates/engine_xetex/xetex/xetex-xetex0.c

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10601,17 +10601,6 @@ conditional(void)
1060110601
}
1060210602
}
1060310603

10604-
10605-
void
10606-
begin_name(void)
10607-
{
10608-
set_area_delimiter(0);
10609-
set_ext_delimiter(0);
10610-
set_quoted_filename(false);
10611-
set_file_name_quote_char(0);
10612-
}
10613-
10614-
1061510604
bool
1061610605
more_name(UTF16_code c)
1061710606
{
@@ -10645,71 +10634,6 @@ more_name(UTF16_code c)
1064510634
return true;
1064610635
}
1064710636

10648-
10649-
void
10650-
end_name(void)
10651-
{
10652-
str_number temp_str;
10653-
pool_pointer j;
10654-
10655-
if (str_ptr() + 3 > max_strings())
10656-
overflow("number of strings", max_strings() - init_str_ptr);
10657-
10658-
/* area_delimiter is the length from the start of the filename to the
10659-
* directory seperator "/", which we use to construct the stringpool
10660-
* string `cur_area`. If there was already a string in the stringpool for
10661-
* the area, reuse it. */
10662-
10663-
if (area_delimiter() == 0) {
10664-
set_cur_area(EMPTY_STRING);
10665-
} else {
10666-
set_cur_area(str_ptr());
10667-
set_str_start((str_ptr() + 1) - 65536L, str_start(str_ptr() - TOO_BIG_CHAR) + area_delimiter());
10668-
set_str_ptr(str_ptr()+1);
10669-
temp_str = search_string(cur_area());
10670-
10671-
if (temp_str > 0) {
10672-
set_cur_area(temp_str);
10673-
set_str_ptr(str_ptr()-1);
10674-
10675-
for (j = str_start((str_ptr() + 1) - 65536L); j <= pool_ptr() - 1; j++)
10676-
set_str_pool(j - area_delimiter(), str_pool(j));
10677-
10678-
set_pool_ptr(pool_ptr() - area_delimiter());
10679-
}
10680-
}
10681-
10682-
/* ext_delimiter is the length from the start of the filename to the
10683-
* extension '.' delimiter, which we use to construct the stringpool
10684-
* strings `cur_ext` and `cur_name`. */
10685-
10686-
if (ext_delimiter() == 0) {
10687-
set_cur_ext(EMPTY_STRING);
10688-
set_cur_name(slow_make_string());
10689-
} else {
10690-
set_cur_name(str_ptr());
10691-
set_str_start((str_ptr() + 1) - 65536L, str_start(str_ptr() - TOO_BIG_CHAR) + ext_delimiter() - area_delimiter() - 1);
10692-
set_str_ptr(str_ptr()+1);
10693-
10694-
set_cur_ext(make_string());
10695-
set_str_ptr(str_ptr()-1);
10696-
temp_str = search_string(cur_name());
10697-
10698-
if (temp_str > 0) {
10699-
set_cur_name(temp_str);
10700-
set_str_ptr(str_ptr()-1);
10701-
10702-
for (j = str_start((str_ptr() + 1) - 65536L); j <= pool_ptr() - 1; j++)
10703-
set_str_pool(j - ext_delimiter() + area_delimiter() + 1, str_pool(j));
10704-
10705-
set_pool_ptr(pool_ptr() - ext_delimiter() + area_delimiter() + 1);
10706-
}
10707-
10708-
set_cur_ext(slow_make_string());
10709-
}
10710-
}
10711-
10712-
1071310637
str_number
1071410638
make_name_string(void)
1071510639
{

crates/engine_xetex/xetex/xetex_bindings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ void pack_job_name(const char *s);
232232

233233
void make_utf16_name(void);
234234

235+
void begin_name(void);
236+
237+
void end_name(void);
238+
235239
void resize_hash(uintptr_t len);
236240

237241
B32x2 hash(uintptr_t idx);

0 commit comments

Comments
 (0)