Remove std::io once and for all!

This commit is contained in:
Alex Crichton 2013-10-21 23:06:12 -07:00
parent c4907cfd14
commit 6bb1df9251
11 changed files with 123 additions and 1854 deletions

View file

@ -97,6 +97,7 @@ pub mod reader {
use std::cast::transmute;
use std::int;
use std::option::{None, Option, Some};
use std::rt::io::extensions::u64_from_be_bytes;
// ebml reading
@ -258,17 +259,17 @@ pub mod reader {
pub fn doc_as_u16(d: Doc) -> u16 {
assert_eq!(d.end, d.start + 2u);
::std::io::u64_from_be_bytes(*d.data, d.start, 2u) as u16
u64_from_be_bytes(*d.data, d.start, 2u) as u16
}
pub fn doc_as_u32(d: Doc) -> u32 {
assert_eq!(d.end, d.start + 4u);
::std::io::u64_from_be_bytes(*d.data, d.start, 4u) as u32
u64_from_be_bytes(*d.data, d.start, 4u) as u32
}
pub fn doc_as_u64(d: Doc) -> u64 {
assert_eq!(d.end, d.start + 8u);
::std::io::u64_from_be_bytes(*d.data, d.start, 8u)
u64_from_be_bytes(*d.data, d.start, 8u)
}
pub fn doc_as_i8(d: Doc) -> i8 { doc_as_u8(d) as i8 }
@ -610,6 +611,7 @@ pub mod writer {
use std::rt::io;
use std::rt::io::{Writer, Seek};
use std::rt::io::mem::MemWriter;
use std::rt::io::extensions::u64_to_be_bytes;
// ebml writing
pub struct Encoder {
@ -693,19 +695,19 @@ pub mod writer {
}
pub fn wr_tagged_u64(&mut self, tag_id: uint, v: u64) {
do ::std::io::u64_to_be_bytes(v, 8u) |v| {
do u64_to_be_bytes(v, 8u) |v| {
self.wr_tagged_bytes(tag_id, v);
}
}
pub fn wr_tagged_u32(&mut self, tag_id: uint, v: u32) {
do ::std::io::u64_to_be_bytes(v as u64, 4u) |v| {
do u64_to_be_bytes(v as u64, 4u) |v| {
self.wr_tagged_bytes(tag_id, v);
}
}
pub fn wr_tagged_u16(&mut self, tag_id: uint, v: u16) {
do ::std::io::u64_to_be_bytes(v as u64, 2u) |v| {
do u64_to_be_bytes(v as u64, 2u) |v| {
self.wr_tagged_bytes(tag_id, v);
}
}
@ -715,19 +717,19 @@ pub mod writer {
}
pub fn wr_tagged_i64(&mut self, tag_id: uint, v: i64) {
do ::std::io::u64_to_be_bytes(v as u64, 8u) |v| {
do u64_to_be_bytes(v as u64, 8u) |v| {
self.wr_tagged_bytes(tag_id, v);
}
}
pub fn wr_tagged_i32(&mut self, tag_id: uint, v: i32) {
do ::std::io::u64_to_be_bytes(v as u64, 4u) |v| {
do u64_to_be_bytes(v as u64, 4u) |v| {
self.wr_tagged_bytes(tag_id, v);
}
}
pub fn wr_tagged_i16(&mut self, tag_id: uint, v: i16) {
do ::std::io::u64_to_be_bytes(v as u64, 2u) |v| {
do u64_to_be_bytes(v as u64, 2u) |v| {
self.wr_tagged_bytes(tag_id, v);
}
}

View file

@ -14,8 +14,9 @@
use std::{vec, str};
use std::io::Reader;
use std::hashmap::HashMap;
use std::rt::io;
use std::rt::io::extensions::{ReaderByteConversions, ReaderUtil};
use super::super::TermInfo;
// These are the orders ncurses uses in its compiled format (as of 5.9). Not sure if portable.
@ -160,7 +161,8 @@ pub static stringnames: &'static[&'static str] = &'static[ "cbt", "_", "cr", "cs
"box1"];
/// Parse a compiled terminfo entry, using long capability names if `longnames` is true
pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> {
pub fn parse(mut file: &mut io::Reader,
longnames: bool) -> Result<~TermInfo, ~str> {
let bnames;
let snames;
let nnames;
@ -176,17 +178,17 @@ pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> {
}
// Check magic number
let magic = file.read_le_u16();
let magic = file.read_le_u16_();
if (magic != 0x011A) {
return Err(format!("invalid magic number: expected {:x} but found {:x}",
0x011A, magic as uint));
}
let names_bytes = file.read_le_i16() as int;
let bools_bytes = file.read_le_i16() as int;
let numbers_count = file.read_le_i16() as int;
let string_offsets_count = file.read_le_i16() as int;
let string_table_bytes = file.read_le_i16() as int;
let names_bytes = file.read_le_i16_() as int;
let bools_bytes = file.read_le_i16_() as int;
let numbers_count = file.read_le_i16_() as int;
let string_offsets_count = file.read_le_i16_() as int;
let string_table_bytes = file.read_le_i16_() as int;
assert!(names_bytes > 0);
@ -224,7 +226,7 @@ pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> {
let mut bools_map = HashMap::new();
if bools_bytes != 0 {
for i in range(0, bools_bytes) {
let b = file.read_byte();
let b = file.read_byte().unwrap();
if b < 0 {
error!("EOF reading bools after {} entries", i);
return Err(~"error: expected more bools but hit EOF");
@ -245,7 +247,7 @@ pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> {
let mut numbers_map = HashMap::new();
if numbers_count != 0 {
for i in range(0, numbers_count) {
let n = file.read_le_u16();
let n = file.read_le_u16_();
if n != 0xFFFF {
debug!("{}\\#{}", nnames[i], n);
numbers_map.insert(nnames[i].to_owned(), n);
@ -260,7 +262,7 @@ pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> {
if string_offsets_count != 0 {
let mut string_offsets = vec::with_capacity(10);
for _ in range(0, string_offsets_count) {
string_offsets.push(file.read_le_u16());
string_offsets.push(file.read_le_u16_());
}
debug!("offsets: {:?}", string_offsets);

View file

@ -13,7 +13,8 @@
use std::{os, str};
use std::os::getenv;
use std::io::{file_reader, Reader};
use std::rt::io;
use std::rt::io::file::FileInfo;
/// Return path to database entry for `term`
pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
@ -73,9 +74,9 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
}
/// Return open file for `term`
pub fn open(term: &str) -> Result<@Reader, ~str> {
pub fn open(term: &str) -> Result<@mut io::Reader, ~str> {
match get_dbpath_for_term(term) {
Some(x) => file_reader(x),
Some(x) => Ok(@mut x.open_reader(io::Open).unwrap() as @mut io::Reader),
None => Err(format!("could not find terminfo entry for {}", term))
}
}