diff --git a/src/cat.rs b/src/cat.rs index cb81066..e3b09a1 100644 --- a/src/cat.rs +++ b/src/cat.rs @@ -18,10 +18,9 @@ */ use std::env; -use std::fs::{File, read, read_to_string}; +use std::fs::{File, read_to_string}; use std::io; -use std::io::{ Read, Write }; -use std::os::unix::io::FromRawFd; +use std::io::{ BufRead, Read }; use std::str; use arg::Args; @@ -50,6 +49,33 @@ fn main() -> ExitCode { if args.paths.is_empty() { args.paths.push("-".to_string()); } + while args.u { + for path in &args.paths { + if path == "-" { + loop { + let mut buf = String::new(); + match io::stdin().lock().read_line(&mut buf) { + Ok(bytes) => { + if bytes == 0 { break }; + print!("{}", buf); + }, + Err(err) => println!("{}", err), + }; + } + } else { + let mut input = String::new(); + match File::open(path) { + Ok(input) => {}, + Err(_) => { + println!("{}: {}: No such file or directory.", &argv0, path); + return ExitCode::NoInput; + }, + }; + } + } + return ExitCode::Ok; + } + for path in args.paths { if path == "-" { let mut bytes: Vec = Vec::new();