Skip to content

Commit b502e0a

Browse files
committed
Port print_file_name
1 parent 9ab6638 commit b502e0a

File tree

2 files changed

+53
-126
lines changed

2 files changed

+53
-126
lines changed

crates/engine_xetex/src/c_api/output.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,3 +733,56 @@ pub extern "C" fn print_cs(p: i32) {
733733
pub extern "C" fn sprint_cs(p: i32) {
734734
Globals::with(|globals| rs_sprint_cs(globals, p))
735735
}
736+
737+
pub fn rs_print_file_name(globals: &mut Globals<'_, '_>, n: i32, a: i32, e: i32) {
738+
let mut quote = None;
739+
740+
for s in [a, n, e] {
741+
if s == 0 || quote.is_some() {
742+
continue;
743+
}
744+
let str = globals.strings.str(s - 0x10000);
745+
quote = str
746+
.iter()
747+
.find(|&&c| c == ' ' as u16 || c == '"' as u16 || c == '\'' as u16)
748+
.copied();
749+
}
750+
751+
if quote == Some(' ' as u16) {
752+
quote = Some('"' as u16);
753+
} else if let Some(q) = quote {
754+
quote = Some(73 - q);
755+
}
756+
757+
if let Some(q) = quote {
758+
rs_print_char(globals, q as i32);
759+
}
760+
761+
for s in [a, n, e] {
762+
if s == 0 {
763+
continue;
764+
}
765+
// TODO: Fix up borrowing so we can use `strings.str`
766+
let str = globals.strings.str_range(s - 0x10000);
767+
for idx in str {
768+
let c = globals.strings.char_at(idx);
769+
if let Some(qc) = quote {
770+
if c == qc {
771+
rs_print(globals, qc as i32);
772+
rs_print(globals, (73 - qc) as i32);
773+
quote = Some(73 - qc);
774+
}
775+
}
776+
rs_print(globals, c as i32);
777+
}
778+
}
779+
780+
if let Some(q) = quote {
781+
rs_print_char(globals, q as i32);
782+
}
783+
}
784+
785+
#[no_mangle]
786+
pub extern "C" fn print_file_name(n: i32, a: i32, e: i32) {
787+
Globals::with(|globals| rs_print_file_name(globals, n, a, e))
788+
}

crates/engine_xetex/xetex/xetex-output.c

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -9,132 +9,6 @@
99
#include "tectonic_bridge_core.h"
1010
#include "xetex_bindings.h"
1111

12-
/*
13-
void
14-
sprint_cs(int32_t p)
15-
{
16-
if (p < HASH_BASE) {
17-
if (p < SINGLE_BASE)
18-
print_char(p - 1);
19-
else if (p < NULL_CS)
20-
print_esc(p - SINGLE_BASE);
21-
else {
22-
print_esc_cstr("csname");
23-
print_esc_cstr("endcsname");
24-
}
25-
} else if (p >= PRIM_EQTB_BASE && p < FROZEN_NULL_FONT) {
26-
print_esc(prim(p - PRIM_EQTB_BASE).s1 - 1);
27-
} else {
28-
print_esc(hash(p).s1);
29-
}
30-
}
31-
*/
32-
33-
void
34-
print_file_name(int32_t n, int32_t a, int32_t e)
35-
{
36-
bool must_quote = false;
37-
int32_t quote_char = 0;
38-
pool_pointer j;
39-
40-
if (a != 0) {
41-
j = str_start((a) - 0x10000);
42-
while (((!must_quote) || (quote_char == 0)) && (j < str_start((a + 1) - 0x10000))) {
43-
if (str_pool(j) == ' ' )
44-
must_quote = true;
45-
else if ((str_pool(j) == '"' ) || (str_pool(j) == '\'' )) {
46-
must_quote = true;
47-
quote_char = 73 /*""" 39 */ - str_pool(j);
48-
}
49-
j++;
50-
}
51-
}
52-
53-
if (n != 0) {
54-
j = str_start((n) - 0x10000);
55-
while (((!must_quote) || (quote_char == 0)) && (j < str_start((n + 1) - 0x10000))) {
56-
if (str_pool(j) == ' ' )
57-
must_quote = true;
58-
else if ((str_pool(j) == '"' ) || (str_pool(j) == '\'' )) {
59-
must_quote = true;
60-
quote_char = 73 /*""" 39 */ - str_pool(j);
61-
}
62-
j++;
63-
}
64-
}
65-
66-
if (e != 0) {
67-
j = str_start((e) - 0x10000);
68-
while (((!must_quote) || (quote_char == 0)) && (j < str_start((e + 1) - 0x10000))) {
69-
if (str_pool(j) == ' ' )
70-
must_quote = true;
71-
else if ((str_pool(j) == '"' ) || (str_pool(j) == '\'' )) {
72-
must_quote = true;
73-
quote_char = 73 /*""" 39 */ - str_pool(j);
74-
}
75-
j++;
76-
}
77-
}
78-
79-
if (must_quote) {
80-
if (quote_char == 0)
81-
quote_char = '"' ;
82-
print_char(quote_char);
83-
}
84-
85-
if (a != 0) {
86-
register int32_t for_end;
87-
j = str_start((a) - 0x10000);
88-
for_end = str_start((a + 1) - 0x10000) - 1;
89-
if (j <= for_end)
90-
do {
91-
if (str_pool(j) == quote_char) {
92-
print(quote_char);
93-
quote_char = 73 /*""" 39 */ - quote_char;
94-
print(quote_char);
95-
}
96-
print(str_pool(j));
97-
}
98-
while (j++ < for_end);
99-
}
100-
101-
if (n != 0) {
102-
register int32_t for_end;
103-
j = str_start((n) - 0x10000);
104-
for_end = str_start((n + 1) - 0x10000) - 1;
105-
if (j <= for_end)
106-
do {
107-
if (str_pool(j) == quote_char) {
108-
print(quote_char);
109-
quote_char = 73 /*""" 39 */ - quote_char;
110-
print(quote_char);
111-
}
112-
print(str_pool(j));
113-
}
114-
while (j++ < for_end);
115-
}
116-
117-
if (e != 0) {
118-
register int32_t for_end;
119-
j = str_start((e) - 0x10000);
120-
for_end = str_start((e + 1) - 0x10000) - 1;
121-
if (j <= for_end)
122-
do {
123-
if (str_pool(j) == quote_char) {
124-
print(quote_char);
125-
quote_char = 73 /*""" 39 */ - quote_char;
126-
print(quote_char);
127-
}
128-
print(str_pool(j));
129-
}
130-
while (j++ < for_end);
131-
}
132-
133-
if (quote_char != 0)
134-
print_char(quote_char);
135-
}
136-
137-
13812
void
13913
print_size(int32_t s)
14014
{

0 commit comments

Comments
 (0)