@@ -186,7 +186,7 @@ fn read_byte(r: &mut io::Read) -> io::Result<u8> {
186
186
/// Parse a compiled terminfo entry, using long capability names if `longnames`
187
187
/// is true
188
188
pub fn parse ( file : & mut io:: Read , longnames : bool ) -> Result < TermInfo , String > {
189
- macro_rules! try ( ( $e: expr) => (
189
+ macro_rules! t ( ( $e: expr) => (
190
190
match $e {
191
191
Ok ( e) => e,
192
192
Err ( e) => return Err ( format!( "{}" , e) )
@@ -200,7 +200,7 @@ pub fn parse(file: &mut io::Read, longnames: bool) -> Result<TermInfo, String> {
200
200
} ;
201
201
202
202
// Check magic number
203
- let magic = read_le_u16 ( file) ? ;
203
+ let magic = t ! ( read_le_u16( file) ) ;
204
204
if magic != 0x011A {
205
205
return Err ( format ! ( "invalid magic number: expected {:x}, found {:x}" ,
206
206
0x011A ,
@@ -211,7 +211,7 @@ pub fn parse(file: &mut io::Read, longnames: bool) -> Result<TermInfo, String> {
211
211
// supported. Using 0 instead of -1 works because we skip sections with length 0.
212
212
macro_rules! read_nonneg {
213
213
( ) => { {
214
- match try !( read_le_u16( file) ) as i16 {
214
+ match t !( read_le_u16( file) ) as i16 {
215
215
n if n >= 0 => n as usize ,
216
216
-1 => 0 ,
217
217
_ => 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> {
243
243
244
244
// don't read NUL
245
245
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) ) ;
247
247
let names_str = match String :: from_utf8 ( bytes) {
248
248
Ok ( s) => s,
249
249
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> {
253
253
. map ( |s| s. to_string ( ) )
254
254
. collect ( ) ;
255
255
// consume NUL
256
- if read_byte ( file) ? != b'\0' {
256
+ if t ! ( read_byte( file) ) != b'\0' {
257
257
return Err ( "incompatible file: missing null terminator for names section" . to_string ( ) ) ;
258
258
}
259
259
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) {
261
262
Err ( e) => Some ( Err ( e) ) ,
262
263
Ok ( 1 ) => Some ( Ok ( ( bnames[ i] . to_string( ) , true ) ) ) ,
263
264
Ok ( _) => None
264
- } ) . collect ( ) ?;
265
+ } ) . collect( )
266
+ } ;
265
267
266
268
if ( bools_bytes + names_bytes) % 2 == 1 {
267
- read_byte ( file) ? ; // compensate for padding
269
+ t ! ( read_byte( file) ) ; // compensate for padding
268
270
}
269
271
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) {
271
274
Ok ( 0xFFFF ) => None ,
272
275
Ok ( n) => Some ( Ok ( ( nnames[ i] . to_string( ) , n) ) ) ,
273
276
Err ( e) => Some ( Err ( e) )
274
- } ) . collect ( ) ?;
277
+ } ) . collect( )
278
+ } ;
275
279
276
280
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)
278
282
. map( |_| read_le_u16( file) )
279
- . collect ( ) ? ;
283
+ . collect( ) ) ;
280
284
281
285
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) ) ;
283
287
284
- string_offsets. into_iter ( ) . enumerate ( ) . filter ( |& ( _, offset) | {
288
+ t ! ( string_offsets. into_iter( ) . enumerate( ) . filter( |& ( _, offset) | {
285
289
// non-entry
286
290
offset != 0xFFFF
287
291
} ) . map( |( i, offset) | {
@@ -305,7 +309,7 @@ pub fn parse(file: &mut io::Read, longnames: bool) -> Result<TermInfo, String> {
305
309
Some ( len) => Ok ( ( name. to_string( ) , string_table[ offset..offset + len] . to_vec( ) ) ) ,
306
310
None => Err ( "invalid file: missing NUL in string_table" . to_string( ) ) ,
307
311
}
308
- } ) . collect ( ) ?
312
+ } ) . collect( ) )
309
313
} else {
310
314
HashMap :: new ( )
311
315
} ;
0 commit comments