X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibterm%2Fterminfo%2Fparser%2Fcompiled.rs;h=db5dd2d5c1907375cc56b339837c1cbae86308db;hb=169a57ee8d301c44fb285cc95fc1309d96aa37ab;hp=edaa55a66031975f169887cc5703218079ad6943;hpb=3eb3a02c92e129e87561ebcf927543679bf7c74d;p=rust.git diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index edaa55a6603..db5dd2d5c19 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -195,21 +195,21 @@ macro_rules! try( ($e:expr) => ( assert!(names_bytes > 0); if (bools_bytes as uint) > boolnames.len() { - return Err(~"incompatible file: more booleans than expected"); + return Err("incompatible file: more booleans than expected".to_owned()); } if (numbers_count as uint) > numnames.len() { - return Err(~"incompatible file: more numbers than expected"); + return Err("incompatible file: more numbers than expected".to_owned()); } if (string_offsets_count as uint) > stringnames.len() { - return Err(~"incompatible file: more string offsets than expected"); + return Err("incompatible file: more string offsets than expected".to_owned()); } // don't read NUL let bytes = try!(file.read_exact(names_bytes as uint - 1)); - let names_str = match str::from_utf8_owned(bytes) { - Some(s) => s, None => return Err(~"input not utf-8"), + let names_str = match str::from_utf8(bytes.as_slice()) { + Some(s) => s.to_owned(), None => return Err("input not utf-8".to_owned()), }; let term_names: Vec<~str> = names_str.split('|').map(|s| s.to_owned()).collect(); @@ -220,10 +220,8 @@ macro_rules! try( ($e:expr) => ( if bools_bytes != 0 { for i in range(0, bools_bytes) { let b = try!(file.read_byte()); - if b < 0 { - return Err(~"error: expected more bools but hit EOF"); - } else if b == 1 { - bools_map.insert(bnames[i].to_owned(), true); + if b == 1 { + bools_map.insert(bnames[i as uint].to_owned(), true); } } } @@ -237,7 +235,7 @@ macro_rules! try( ($e:expr) => ( for i in range(0, numbers_count) { let n = try!(file.read_le_u16()); if n != 0xFFFF { - numbers_map.insert(nnames[i].to_owned(), n); + numbers_map.insert(nnames[i as uint].to_owned(), n); } } } @@ -253,7 +251,7 @@ macro_rules! try( ($e:expr) => ( let string_table = try!(file.read_exact(string_table_bytes as uint)); if string_table.len() != string_table_bytes as uint { - return Err(~"error: hit EOF before end of string table"); + return Err("error: hit EOF before end of string table".to_owned()); } for (i, v) in string_offsets.iter().enumerate() { @@ -287,25 +285,30 @@ macro_rules! try( ($e:expr) => ( offset as uint + len))) }, None => { - return Err(~"invalid file: missing NUL in string_table"); + return Err("invalid file: missing NUL in string_table".to_owned()); } }; } } // And that's all there is to it - Ok(~TermInfo {names: term_names, bools: bools_map, numbers: numbers_map, strings: string_map }) + Ok(box TermInfo { + names: term_names, + bools: bools_map, + numbers: numbers_map, + strings: string_map + }) } /// Create a dummy TermInfo struct for msys terminals pub fn msys_terminfo() -> ~TermInfo { let mut strings = HashMap::new(); - strings.insert(~"sgr0", Vec::from_slice(bytes!("\x1b[0m"))); - strings.insert(~"bold", Vec::from_slice(bytes!("\x1b[1m"))); - strings.insert(~"setaf", Vec::from_slice(bytes!("\x1b[3%p1%dm"))); - strings.insert(~"setab", Vec::from_slice(bytes!("\x1b[4%p1%dm"))); - ~TermInfo { - names: vec!(~"cygwin"), // msys is a fork of an older cygwin version + strings.insert("sgr0".to_owned(), Vec::from_slice(bytes!("\x1b[0m"))); + strings.insert("bold".to_owned(), Vec::from_slice(bytes!("\x1b[1m"))); + strings.insert("setaf".to_owned(), Vec::from_slice(bytes!("\x1b[3%p1%dm"))); + strings.insert("setab".to_owned(), Vec::from_slice(bytes!("\x1b[4%p1%dm"))); + box TermInfo { + names: vec!("cygwin".to_owned()), // msys is a fork of an older cygwin version bools: HashMap::new(), numbers: HashMap::new(), strings: strings