Skip to content

Commit

Permalink
Merge pull request #98 from lukaslueg/byteorder_removed
Browse files Browse the repository at this point in the history
Remove byteorder-dependency
  • Loading branch information
Stebalien committed Aug 5, 2019
2 parents e2017f6 + faaa9a4 commit c6277a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Expand Up @@ -20,7 +20,6 @@ travis-ci = { repository = "Stebalien/term" }
appveyor = { repository = "Stebalien/term" }

[dependencies]
byteorder = "1.2.1"
dirs = "2.0.1"

[target.'cfg(windows)'.dependencies]
Expand Down
18 changes: 12 additions & 6 deletions src/terminfo/parser/compiled.rs
Expand Up @@ -14,8 +14,6 @@ use std::collections::HashMap;
use std::io;
use std::io::prelude::*;

use byteorder::{LittleEndian, ReadBytesExt};

use crate::terminfo::Error::*;
use crate::terminfo::TermInfo;
use crate::Result;
Expand All @@ -26,11 +24,14 @@ pub use crate::terminfo::parser::names::*;
// sure if portable.

fn read_le_u16(r: &mut dyn io::Read) -> io::Result<u32> {
r.read_u16::<LittleEndian>().map(u32::from)
let mut buf = [0; 2];
r.read_exact(&mut buf)
.map(|()| u32::from(u16::from_le_bytes(buf)))
}

fn read_le_u32(r: &mut dyn io::Read) -> io::Result<u32> {
r.read_u32::<LittleEndian>()
let mut buf = [0; 4];
r.read_exact(&mut buf).map(|()| u32::from_le_bytes(buf))
}

fn read_byte(r: &mut dyn io::Read) -> io::Result<u8> {
Expand All @@ -50,7 +51,9 @@ pub fn parse(file: &mut dyn io::Read, longnames: bool) -> Result<TermInfo> {
};

// Check magic number
let magic = file.read_u16::<LittleEndian>()?;
let mut buf = [0; 2];
file.read_exact(&mut buf)?;
let magic = u16::from_le_bytes(buf);

let read_number = match magic {
0x011A => read_le_u16,
Expand Down Expand Up @@ -131,7 +134,10 @@ pub fn parse(file: &mut dyn io::Read, longnames: bool) -> Result<TermInfo> {

let string_map: HashMap<&str, Vec<u8>> = if string_offsets_count > 0 {
let string_offsets = (0..string_offsets_count)
.map(|_| file.read_u16::<LittleEndian>())
.map(|_| {
let mut buf = [0; 2];
file.read_exact(&mut buf).map(|()| u16::from_le_bytes(buf))
})
.collect::<io::Result<Vec<_>>>()?;

let mut string_table = Vec::new();
Expand Down
8 changes: 4 additions & 4 deletions src/win.rs
Expand Up @@ -13,14 +13,14 @@
// FIXME (#13400): this is only a tiny fraction of the Windows console api

use crate::color;
use std::io;
use std::io::prelude::*;
use std::ops::Deref;
use std::ptr;
use crate::Attr;
use crate::Error;
use crate::Result;
use crate::Terminal;
use std::io;
use std::io::prelude::*;
use std::ops::Deref;
use std::ptr;

use winapi::shared::minwindef::{DWORD, WORD};
use winapi::um::consoleapi::{GetConsoleMode, SetConsoleMode};
Expand Down

0 comments on commit c6277a1

Please sign in to comment.