X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibterm%2Fterminfo%2Fparser%2Fcompiled.rs;h=db5dd2d5c1907375cc56b339837c1cbae86308db;hb=169a57ee8d301c44fb285cc95fc1309d96aa37ab;hp=cc97e54709c81e70d835c06e533aa9e8c3fa2a72;hpb=95ee0a04fd78deb773da2d1b2544696c4f0278c7;p=rust.git diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index cc97e54709c..db5dd2d5c19 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -8,14 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[allow(non_uppercase_statics)]; +#![allow(non_uppercase_statics)] -/// ncurses-compatible compiled terminfo format parsing (term(5)) +//! ncurses-compatible compiled terminfo format parsing (term(5)) - -use std::{slice, str}; -use std::io; use collections::HashMap; +use std::io; +use std::str; use super::super::TermInfo; // These are the orders ncurses uses in its compiled format (as of 5.9). Not sure if portable. @@ -196,24 +195,24 @@ 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_bytes(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 bytes = try!(file.read_exact(names_bytes as uint - 1)); + 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: ~[~str] = names_str.split('|').map(|s| s.to_owned()).collect(); + let term_names: Vec<~str> = names_str.split('|').map(|s| s.to_owned()).collect(); try!(file.read_byte()); // consume NUL @@ -221,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); } } } @@ -238,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); } } } @@ -246,15 +243,15 @@ macro_rules! try( ($e:expr) => ( let mut string_map = HashMap::new(); if string_offsets_count != 0 { - let mut string_offsets = slice::with_capacity(10); + let mut string_offsets = Vec::with_capacity(10); for _ in range(0, string_offsets_count) { string_offsets.push(try!(file.read_le_u16())); } - let string_table = try!(file.read_bytes(string_table_bytes as uint)); + 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() { @@ -272,7 +269,7 @@ macro_rules! try( ($e:expr) => ( if offset == 0xFFFE { // undocumented: FFFE indicates cap@, which means the capability is not present // unsure if the handling for this is correct - string_map.insert(name.to_owned(), ~[]); + string_map.insert(name.to_owned(), Vec::new()); continue; } @@ -283,29 +280,35 @@ macro_rules! try( ($e:expr) => ( match nulpos { Some(len) => { string_map.insert(name.to_owned(), - string_table.slice(offset as uint, - offset as uint + len).to_owned()) + Vec::from_slice( + string_table.slice(offset as uint, + 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", bytes!("\x1b[0m").to_owned()); - strings.insert(~"bold", bytes!("\x1b[1m").to_owned()); - strings.insert(~"setaf", bytes!("\x1b[3%p1%dm").to_owned()); - strings.insert(~"setab", bytes!("\x1b[4%p1%dm").to_owned()); - ~TermInfo { - names: ~[~"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