Skip to content

Commit 4547939

Browse files
authored
Merge pull request tectonic-typesetting#88 from burrbull/no_xetex
use Display formatter for C strings
2 parents 29a0622 + a7d65a6 commit 4547939

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1067
-1143
lines changed

dpx/src/dpx_agl.rs

+43-43
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
unused_mut
3030
)]
3131

32+
use crate::DisplayExt;
3233
use crate::{info, warn};
3334
use crate::{streq_ptr, strstartswith};
35+
use std::ffi::CStr;
3436

3537
use super::dpx_dpxfile::dpx_tt_open;
3638
use super::dpx_dpxutil::{ht_append_table, ht_clear_table, ht_init_table, ht_lookup_table};
37-
use super::dpx_error::{dpx_message, dpx_warning};
39+
use super::dpx_error::dpx_warning;
3840
use super::dpx_mem::new;
3941
use super::dpx_mfileio::tt_mfgets;
4042
use super::dpx_pdfparse::{parse_ident, skip_white};
@@ -800,7 +802,7 @@ unsafe extern "C" fn agl_load_listfile(mut filename: *const i8, mut is_predef: i
800802
return -1i32;
801803
}
802804
if verbose != 0 {
803-
dpx_message(b"<AGL:%s\x00" as *const u8 as *const i8, filename);
805+
info!("<AGL:{}", CStr::from_ptr(filename).display());
804806
}
805807
loop {
806808
p = tt_mfgets(wbuf.as_mut_ptr(), 1024i32, handle);
@@ -826,9 +828,9 @@ unsafe extern "C" fn agl_load_listfile(mut filename: *const i8, mut is_predef: i
826828
name = parse_ident(&mut p, nextptr);
827829
skip_white(&mut p, endptr);
828830
if name.is_null() || *p.offset(0) as i32 != ';' as i32 {
829-
dpx_warning(
830-
b"Invalid AGL entry: %s\x00" as *const u8 as *const i8,
831-
wbuf.as_mut_ptr(),
831+
warn!(
832+
"Invalid AGL entry: {}",
833+
CStr::from_ptr(wbuf.as_ptr()).display()
832834
);
833835
free(name as *mut libc::c_void);
834836
} else {
@@ -851,9 +853,9 @@ unsafe extern "C" fn agl_load_listfile(mut filename: *const i8, mut is_predef: i
851853
}
852854
}
853855
if n_unicodes == 0i32 {
854-
dpx_warning(
855-
b"AGL entry ignored (no mapping): %s\x00" as *const u8 as *const i8,
856-
wbuf.as_mut_ptr(),
856+
warn!(
857+
"AGL entry ignored (no mapping): {}",
858+
CStr::from_ptr(wbuf.as_ptr()).display(),
857859
);
858860
free(name as *mut libc::c_void);
859861
} else {
@@ -885,17 +887,17 @@ unsafe extern "C" fn agl_load_listfile(mut filename: *const i8, mut is_predef: i
885887
}
886888
if verbose > 3i32 {
887889
if !(*agln).suffix.is_null() {
888-
dpx_message(
889-
b"agl: %s [%s.%s] -->\x00" as *const u8 as *const i8,
890-
name,
891-
(*agln).name,
892-
(*agln).suffix,
890+
info!(
891+
"agl: {} [{}.{}] -->",
892+
CStr::from_ptr(name).display(),
893+
CStr::from_ptr((*agln).name).display(),
894+
CStr::from_ptr((*agln).suffix).display(),
893895
);
894896
} else {
895-
dpx_message(
896-
b"agl: %s [%s] -->\x00" as *const u8 as *const i8,
897-
name,
898-
(*agln).name,
897+
info!(
898+
"agl: {} [{}] -->",
899+
CStr::from_ptr(name).display(),
900+
CStr::from_ptr((*agln).name).display(),
899901
);
900902
}
901903
i = 0i32;
@@ -1100,9 +1102,9 @@ pub unsafe extern "C" fn agl_sput_UTF16BE(
11001102
* Glyph names starting with a underscore or two subsequent
11011103
* underscore in glyph name not allowed?
11021104
*/
1103-
dpx_warning(
1104-
b"Invalid glyph name component in \"%s\".\x00" as *const u8 as *const i8,
1105-
glyphstr,
1105+
warn!(
1106+
"Invalid glyph name component in \"{}\".",
1107+
CStr::from_ptr(glyphstr).display()
11061108
);
11071109
count += 1;
11081110
if !fail_count.is_null() {
@@ -1147,11 +1149,11 @@ pub unsafe extern "C" fn agl_sput_UTF16BE(
11471149
agln0 = agl_normalized_name(name);
11481150
if !agln0.is_null() {
11491151
if verbose > 1i32 && !(*agln0).suffix.is_null() {
1150-
dpx_warning(
1151-
b"agl: fix %s --> %s.%s\x00" as *const u8 as *const i8,
1152-
name,
1153-
(*agln0).name,
1154-
(*agln0).suffix,
1152+
warn!(
1153+
"agl: fix {} --> {}.{}",
1154+
CStr::from_ptr(name).display(),
1155+
CStr::from_ptr((*agln0).name).display(),
1156+
CStr::from_ptr((*agln0).suffix).display(),
11551157
);
11561158
}
11571159
agln1 = agl_lookup_list((*agln0).name);
@@ -1170,11 +1172,10 @@ pub unsafe extern "C" fn agl_sput_UTF16BE(
11701172
}
11711173
} else {
11721174
if verbose != 0 {
1173-
dpx_warning(
1174-
b"No Unicode mapping for glyph name \"%s\" found.\x00" as *const u8
1175-
as *const i8,
1176-
name,
1177-
);
1175+
warn!(
1176+
"No Unicode mapping for glyph name \"{}\" found.",
1177+
CStr::from_ptr(name).display()
1178+
)
11781179
}
11791180
count += 1
11801181
}
@@ -1214,9 +1215,9 @@ pub unsafe extern "C" fn agl_get_unicodes(
12141215
* Glyph names starting with a underscore or two subsequent
12151216
* underscore in glyph name not allowed?
12161217
*/
1217-
dpx_warning(
1218-
b"Invalid glyph name component in \"%s\".\x00" as *const u8 as *const i8,
1219-
glyphstr,
1218+
warn!(
1219+
"Invalid glyph name component in \"{}\".",
1220+
CStr::from_ptr(glyphstr).display()
12201221
);
12211222
return -1i32;
12221223
/* Cannot continue */
@@ -1275,11 +1276,11 @@ pub unsafe extern "C" fn agl_get_unicodes(
12751276
agln0 = agl_normalized_name(name);
12761277
if !agln0.is_null() {
12771278
if verbose > 1i32 && !(*agln0).suffix.is_null() {
1278-
dpx_warning(
1279-
b"agl: fix %s --> %s.%s\x00" as *const u8 as *const i8,
1280-
name,
1281-
(*agln0).name,
1282-
(*agln0).suffix,
1279+
warn!(
1280+
"agl: fix {} --> {}.{}",
1281+
CStr::from_ptr(name).display(),
1282+
CStr::from_ptr((*agln0).name).display(),
1283+
CStr::from_ptr((*agln0).suffix).display(),
12831284
);
12841285
}
12851286
agln1 = agl_lookup_list((*agln0).name);
@@ -1300,11 +1301,10 @@ pub unsafe extern "C" fn agl_get_unicodes(
13001301
}
13011302
} else {
13021303
if verbose > 1i32 {
1303-
dpx_warning(
1304-
b"No Unicode mapping for glyph name \"%s\" found.\x00" as *const u8
1305-
as *const i8,
1306-
name,
1307-
);
1304+
warn!(
1305+
"No Unicode mapping for glyph name \"{}\" found.",
1306+
CStr::from_ptr(name).display()
1307+
)
13081308
}
13091309
free(name as *mut libc::c_void);
13101310
return -1i32;

dpx/src/dpx_bmpimage.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
unused_mut
3030
)]
3131

32-
use super::dpx_error::dpx_warning;
3332
use super::dpx_mem::new;
3433
use super::dpx_numbers::tt_get_unsigned_byte;
3534
use super::dpx_pdfximage::{pdf_ximage_init_image_info, pdf_ximage_set_image};
@@ -177,10 +176,7 @@ pub unsafe extern "C" fn bmp_include_image(
177176
&& hdr.bit_count as i32 != 4i32
178177
&& hdr.bit_count as i32 != 8i32
179178
{
180-
dpx_warning(
181-
b"Unsupported palette size: %hu\x00" as *const u8 as *const i8,
182-
hdr.bit_count as i32,
183-
);
179+
warn!("Unsupported palette size: {}", hdr.bit_count as i32,);
184180
return -1i32;
185181
}
186182
num_palette = hdr
@@ -196,8 +192,8 @@ pub unsafe extern "C" fn bmp_include_image(
196192
info.bits_per_component = 8i32;
197193
info.num_components = 3i32
198194
} else {
199-
dpx_warning(
200-
b"Unkown/Unsupported BMP bitCount value: %hu\x00" as *const u8 as *const i8,
195+
warn!(
196+
"Unkown/Unsupported BMP bitCount value: {}",
201197
hdr.bit_count as i32,
202198
);
203199
return -1i32;

dpx/src/dpx_cff.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use crate::streq_ptr;
3333
use crate::warn;
3434

3535
use super::dpx_cff_dict::{cff_dict_get, cff_dict_known, cff_dict_unpack, cff_release_dict};
36-
use super::dpx_error::dpx_warning;
3736
use super::dpx_mem::{new, renew};
3837
use super::dpx_numbers::{tt_get_unsigned_byte, tt_get_unsigned_pair};
3938
use crate::{ttstub_input_read, ttstub_input_seek};
@@ -118,7 +117,6 @@ impl Pack for CffIndex {
118117
fn pack(&mut self, mut dest: &mut [u8]) -> usize {
119118
let destlen = dest.len();
120119
let mut datalen: size_t = 0;
121-
let mut i: u16 = 0;
122120
if self.count < 1 {
123121
if destlen < 2 {
124122
panic!("Not enough space available...");
@@ -759,9 +757,9 @@ pub unsafe extern "C" fn cff_open(
759757
panic!("invalid offsize data");
760758
}
761759
if (*cff).header.major as i32 > 1i32 || (*cff).header.minor as i32 > 0i32 {
762-
dpx_warning(
763-
b"%s: CFF version %u.%u not supported.\x00" as *const u8 as *const i8,
764-
b"CFF\x00" as *const u8 as *const i8,
760+
warn!(
761+
"{}: CFF version {}.{} not supported.",
762+
"CFF",
765763
(*cff).header.major as i32,
766764
(*cff).header.minor as i32,
767765
);
@@ -1543,7 +1541,6 @@ pub unsafe extern "C" fn cff_read_encoding(cff: &mut cff_font) -> i32 {
15431541
}
15441542
#[no_mangle]
15451543
pub unsafe extern "C" fn cff_pack_encoding(cff: &cff_font, dest: &mut [u8]) -> usize {
1546-
let destlen = dest.len();
15471544
let mut len = 0_usize;
15481545
if cff.flag & (1i32 << 3i32 | 1i32 << 4i32) != 0 || cff.encoding.is_null() {
15491546
return 0;
@@ -1795,7 +1792,6 @@ pub unsafe extern "C" fn cff_read_charsets(cff: &mut cff_font) -> i32 {
17951792
pub unsafe extern "C" fn cff_pack_charsets(cff: &cff_font, dest: &mut [u8]) -> usize {
17961793
let destlen = dest.len();
17971794
let mut len = 0;
1798-
let mut i: u16 = 0;
17991795
let mut charset: *mut cff_charsets = 0 as *mut cff_charsets;
18001796
if cff.flag & (1 << 5 | 1 << 6 | 1 << 7) != 0 || cff.charsets.is_null() {
18011797
return 0;
@@ -2170,9 +2166,7 @@ pub unsafe extern "C" fn cff_read_fdselect(cff: &mut cff_font) -> i32 {
21702166
}
21712167
#[no_mangle]
21722168
pub unsafe extern "C" fn cff_pack_fdselect(cff: &cff_font, dest: &mut [u8]) -> usize {
2173-
let destlen = dest.len();
21742169
let mut len = 0;
2175-
let mut i: u16 = 0;
21762170
if cff.fdselect.is_null() {
21772171
return 0;
21782172
}

dpx/src/dpx_cff_dict.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@
2929
unused_mut
3030
)]
3131

32+
use crate::DisplayExt;
33+
use std::ffi::CStr;
34+
3235
use super::dpx_cff::{cff_add_string, cff_get_string};
3336
use super::dpx_mem::{new, renew};
3437
use super::dpx_mfileio::work_buffer;
3538
use crate::mfree;
3639
use crate::streq_ptr;
3740
use crate::stub_errno as errno;
3841
use crate::warn;
39-
use bridge::_tt_abort;
4042
use libc::{free, memset, sprintf, strcmp, strtod};
4143

4244
pub type rust_input_handle_t = *mut libc::c_void;
@@ -885,7 +887,6 @@ unsafe extern "C" fn cff_dict_put_number(
885887
}
886888
unsafe extern "C" fn put_dict_entry(mut de: *mut cff_dict_entry, dest: &mut [u8]) -> usize {
887889
let mut len = 0_usize;
888-
let mut i: i32 = 0;
889890
let mut type_0: i32 = 0;
890891
let mut id: i32 = 0;
891892
if (*de).count > 0i32 {
@@ -1048,10 +1049,10 @@ pub unsafe extern "C" fn cff_dict_get(
10481049
}
10491050
}
10501051
if i == (*dict).count {
1051-
_tt_abort(
1052-
b"%s: DICT entry \"%s\" not found.\x00" as *const u8 as *const i8,
1053-
b"CFF\x00" as *const u8 as *const i8,
1054-
key,
1052+
panic!(
1053+
"{}: DICT entry \"{}\" not found.",
1054+
"CFF",
1055+
CStr::from_ptr(key).display(),
10551056
);
10561057
}
10571058
value
@@ -1081,10 +1082,10 @@ pub unsafe extern "C" fn cff_dict_set(
10811082
}
10821083
}
10831084
if i == (*dict).count {
1084-
_tt_abort(
1085-
b"%s: DICT entry \"%s\" not found.\x00" as *const u8 as *const i8,
1086-
b"CFF\x00" as *const u8 as *const i8,
1087-
key,
1085+
panic!(
1086+
"{}: DICT entry \"{}\" not found.",
1087+
"CFF",
1088+
CStr::from_ptr(key).display(),
10881089
);
10891090
};
10901091
}

0 commit comments

Comments
 (0)