1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

Merge pull request #991 from wimh/more_windows

more: fix build on windows
This commit is contained in:
Nathan Ross 2016-10-06 18:47:26 -04:00 committed by GitHub
commit 7bb5891810
2 changed files with 33 additions and 9 deletions

View file

@ -10,9 +10,11 @@ path = "more.rs"
[dependencies] [dependencies]
getopts = "*" getopts = "*"
libc = "*" libc = "*"
nix = "*"
uucore = { path="../uucore" } uucore = { path="../uucore" }
[target."cfg(unix)".dependencies]
nix = "*"
[[bin]] [[bin]]
name = "more" name = "more"
path = "main.rs" path = "main.rs"

View file

@ -18,7 +18,9 @@ use getopts::Options;
use std::io::{stdout, Write, Read}; use std::io::{stdout, Write, Read};
use std::fs::File; use std::fs::File;
#[cfg(unix)]
extern crate nix; extern crate nix;
#[cfg(unix)]
use nix::sys::termios; use nix::sys::termios;
#[derive(Clone, Eq, PartialEq)] #[derive(Clone, Eq, PartialEq)]
@ -74,17 +76,39 @@ fn help(usage: &str) {
println!("{}", msg); println!("{}", msg);
} }
fn more(matches: getopts::Matches) { #[cfg(unix)]
let files = matches.free; fn setup_term() -> termios::Termios {
let mut f = File::open(files.first().unwrap()).unwrap();
let mut buffer = [0; 1024];
let mut term = termios::tcgetattr(0).unwrap(); let mut term = termios::tcgetattr(0).unwrap();
// Unset canonical mode, so we get characters immediately // Unset canonical mode, so we get characters immediately
term.c_lflag.remove(termios::ICANON); term.c_lflag.remove(termios::ICANON);
// Disable local echo // Disable local echo
term.c_lflag.remove(termios::ECHO); term.c_lflag.remove(termios::ECHO);
termios::tcsetattr(0, termios::TCSADRAIN, &term).unwrap(); termios::tcsetattr(0, termios::TCSADRAIN, &term).unwrap();
term
}
#[cfg(windows)]
fn setup_term() -> usize {
0
}
#[cfg(unix)]
fn reset_term(term: &mut termios::Termios) {
term.c_lflag.insert(termios::ICANON);
term.c_lflag.insert(termios::ECHO);
termios::tcsetattr(0, termios::TCSADRAIN, &term).unwrap();
}
#[cfg(windows)]
fn reset_term(_: &mut usize) {
}
fn more(matches: getopts::Matches) {
let files = matches.free;
let mut f = File::open(files.first().unwrap()).unwrap();
let mut buffer = [0; 1024];
let mut term = setup_term();
let mut end = false; let mut end = false;
while let Ok(sz) = f.read(&mut buffer) { while let Ok(sz) = f.read(&mut buffer) {
@ -104,8 +128,6 @@ fn more(matches: getopts::Matches) {
if end { break;} if end { break;}
} }
term.c_lflag.insert(termios::ICANON); reset_term(&mut term);
term.c_lflag.insert(termios::ECHO);
termios::tcsetattr(0, termios::TCSADRAIN, &term).unwrap();
println!(""); println!("");
} }