Skip to content

Commit acbf386

Browse files
author
Jorge Aparicio
committed
term: undo conversion of user defined try!s
1 parent f88a1e6 commit acbf386

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/libterm/terminfo/parser/compiled.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fn read_byte(r: &mut io::Read) -> io::Result<u8> {
186186
/// Parse a compiled terminfo entry, using long capability names if `longnames`
187187
/// is true
188188
pub fn parse(file: &mut io::Read, longnames: bool) -> Result<TermInfo, String> {
189-
macro_rules! try( ($e:expr) => (
189+
macro_rules! t( ($e:expr) => (
190190
match $e {
191191
Ok(e) => e,
192192
Err(e) => return Err(format!("{}", e))
@@ -200,7 +200,7 @@ pub fn parse(file: &mut io::Read, longnames: bool) -> Result<TermInfo, String> {
200200
};
201201

202202
// Check magic number
203-
let magic = read_le_u16(file)?;
203+
let magic = t!(read_le_u16(file));
204204
if magic != 0x011A {
205205
return Err(format!("invalid magic number: expected {:x}, found {:x}",
206206
0x011A,
@@ -211,7 +211,7 @@ pub fn parse(file: &mut io::Read, longnames: bool) -> Result<TermInfo, String> {
211211
// supported. Using 0 instead of -1 works because we skip sections with length 0.
212212
macro_rules! read_nonneg {
213213
() => {{
214-
match try!(read_le_u16(file)) as i16 {
214+
match t!(read_le_u16(file)) as i16 {
215215
n if n >= 0 => n as usize,
216216
-1 => 0,
217217
_ => return Err("incompatible file: length fields must be >= -1".to_string()),
@@ -243,7 +243,7 @@ pub fn parse(file: &mut io::Read, longnames: bool) -> Result<TermInfo, String> {
243243

244244
// don't read NUL
245245
let mut bytes = Vec::new();
246-
file.take((names_bytes - 1) as u64).read_to_end(&mut bytes)?;
246+
t!(file.take((names_bytes - 1) as u64).read_to_end(&mut bytes));
247247
let names_str = match String::from_utf8(bytes) {
248248
Ok(s) => s,
249249
Err(_) => return Err("input not utf-8".to_string()),
@@ -253,35 +253,39 @@ pub fn parse(file: &mut io::Read, longnames: bool) -> Result<TermInfo, String> {
253253
.map(|s| s.to_string())
254254
.collect();
255255
// consume NUL
256-
if read_byte(file)? != b'\0' {
256+
if t!(read_byte(file)) != b'\0' {
257257
return Err("incompatible file: missing null terminator for names section".to_string());
258258
}
259259

260-
let bools_map: HashMap<String, bool> = (0..bools_bytes).filter_map(|i| match read_byte(file) {
260+
let bools_map: HashMap<String, bool> = t! {
261+
(0..bools_bytes).filter_map(|i| match read_byte(file) {
261262
Err(e) => Some(Err(e)),
262263
Ok(1) => Some(Ok((bnames[i].to_string(), true))),
263264
Ok(_) => None
264-
}).collect()?;
265+
}).collect()
266+
};
265267

266268
if (bools_bytes + names_bytes) % 2 == 1 {
267-
read_byte(file)?; // compensate for padding
269+
t!(read_byte(file)); // compensate for padding
268270
}
269271

270-
let numbers_map: HashMap<String, u16> = (0..numbers_count).filter_map(|i| match read_le_u16(file) {
272+
let numbers_map: HashMap<String, u16> = t! {
273+
(0..numbers_count).filter_map(|i| match read_le_u16(file) {
271274
Ok(0xFFFF) => None,
272275
Ok(n) => Some(Ok((nnames[i].to_string(), n))),
273276
Err(e) => Some(Err(e))
274-
}).collect()?;
277+
}).collect()
278+
};
275279

276280
let string_map: HashMap<String, Vec<u8>> = if string_offsets_count > 0 {
277-
let string_offsets: Vec<u16> = (0..string_offsets_count)
281+
let string_offsets: Vec<u16> = t!((0..string_offsets_count)
278282
.map(|_| read_le_u16(file))
279-
.collect()?;
283+
.collect());
280284

281285
let mut string_table = Vec::new();
282-
file.take(string_table_bytes as u64).read_to_end(&mut string_table)?;
286+
t!(file.take(string_table_bytes as u64).read_to_end(&mut string_table));
283287

284-
string_offsets.into_iter().enumerate().filter(|&(_, offset)| {
288+
t!(string_offsets.into_iter().enumerate().filter(|&(_, offset)| {
285289
// non-entry
286290
offset != 0xFFFF
287291
}).map(|(i, offset)| {
@@ -305,7 +309,7 @@ pub fn parse(file: &mut io::Read, longnames: bool) -> Result<TermInfo, String> {
305309
Some(len) => Ok((name.to_string(), string_table[offset..offset + len].to_vec())),
306310
None => Err("invalid file: missing NUL in string_table".to_string()),
307311
}
308-
}).collect()?
312+
}).collect())
309313
} else {
310314
HashMap::new()
311315
};

0 commit comments

Comments
 (0)