Port 'more' to Redox

This commit is contained in:
Ian Douglas Scott 2018-03-18 18:55:42 -07:00
parent ec6321a31e
commit f76b23e3df
No known key found for this signature in database
GPG key ID: 4924E10E199B5959
3 changed files with 32 additions and 1 deletions

View file

@ -66,7 +66,6 @@ fuchsia = [
generic = [ generic = [
"arch", "arch",
"hostname", "hostname",
"more",
"nproc", "nproc",
"sync", "sync",
"tail", "tail",
@ -108,6 +107,7 @@ redox_generic = [
"ls", "ls",
"mkdir", "mkdir",
"mktemp", "mktemp",
"more",
"mv", "mv",
"nl", "nl",
"od", "od",

View file

@ -12,6 +12,10 @@ path = "more.rs"
getopts = "0.2.14" getopts = "0.2.14"
uucore = { path="../uucore" } uucore = { path="../uucore" }
[target.'cfg(target_os = "redox")'.dependencies]
redox_termios = "0.1"
redox_syscall = "0.1"
[target.'cfg(all(unix, not(target_os = "fuchsia")))'.dependencies] [target.'cfg(all(unix, not(target_os = "fuchsia")))'.dependencies]
nix = "0.8.1" nix = "0.8.1"

View file

@ -23,6 +23,11 @@ extern crate nix;
#[cfg(all(unix, not(target_os = "fuchsia")))] #[cfg(all(unix, not(target_os = "fuchsia")))]
use nix::sys::termios; use nix::sys::termios;
#[cfg(target_os = "redox")]
extern crate redox_termios;
#[cfg(target_os = "redox")]
extern crate syscall;
#[derive(Clone, Eq, PartialEq)] #[derive(Clone, Eq, PartialEq)]
pub enum Mode { pub enum Mode {
More, More,
@ -96,6 +101,18 @@ fn setup_term() -> usize {
0 0
} }
#[cfg(target_os = "redox")]
fn setup_term() -> redox_termios::Termios {
let mut term = redox_termios::Termios::default();
let fd = syscall::dup(0, b"termios").unwrap();
syscall::read(fd, &mut term).unwrap();
term.c_lflag &= !redox_termios::ICANON;
term.c_lflag &= !redox_termios::ECHO;
syscall::write(fd, &term).unwrap();
let _ = syscall::close(fd);
term
}
#[cfg(all(unix, not(target_os = "fuchsia")))] #[cfg(all(unix, not(target_os = "fuchsia")))]
fn reset_term(term: &mut termios::Termios) { fn reset_term(term: &mut termios::Termios) {
term.c_lflag.insert(termios::ICANON); term.c_lflag.insert(termios::ICANON);
@ -107,6 +124,16 @@ fn reset_term(term: &mut termios::Termios) {
#[inline(always)] #[inline(always)]
fn reset_term(_: &mut usize) {} fn reset_term(_: &mut usize) {}
#[cfg(any(target_os = "redox"))]
fn reset_term(term: &mut redox_termios::Termios) {
let fd = syscall::dup(0, b"termios").unwrap();
syscall::read(fd, term).unwrap();
term.c_lflag |= redox_termios::ICANON;
term.c_lflag |= redox_termios::ECHO;
syscall::write(fd, &term).unwrap();
let _ = syscall::close(fd);
}
fn more(matches: getopts::Matches) { fn more(matches: getopts::Matches) {
let files = matches.free; let files = matches.free;
let mut f = File::open(files.first().unwrap()).unwrap(); let mut f = File::open(files.first().unwrap()).unwrap();