actually added stdin support to cat
This commit is contained in:
parent
5b47345bf5
commit
c030d6828c
|
@ -25,6 +25,8 @@ fn main() {
|
||||||
// delay as each is read.
|
// delay as each is read.
|
||||||
"-u" => {},
|
"-u" => {},
|
||||||
|
|
||||||
|
"-" => {},
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
println!("Usage: {} [options...] [files...]", argv0);
|
println!("Usage: {} [options...] [files...]", argv0);
|
||||||
process::exit(64); // sysexits(3) EX_USAGE
|
process::exit(64); // sysexits(3) EX_USAGE
|
||||||
|
@ -32,35 +34,33 @@ fn main() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
for path in args {
|
||||||
for path in args {
|
let mut val = String::new();
|
||||||
let mut val = String::new();
|
|
||||||
|
|
||||||
match path.as_str() {
|
match path.as_str() {
|
||||||
"-" => {
|
"-" => {
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
match io::stdin().read_line(&mut content) {
|
match io::stdin().read_line(&mut content) {
|
||||||
Ok(_) => { val.push_str(&content); },
|
Ok(_) => { val.push_str(&content); },
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
println!("Usage: {} [options...] [files...]", argv0);
|
println!("Usage: {} [options...] [files...]", argv0);
|
||||||
process::exit(64); // sysexits(3) EX_USAGE
|
process::exit(64); // sysexits(3) EX_USAGE
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
match read_to_string(&path) {
|
match read_to_string(&path) {
|
||||||
Ok(output) => { val.push_str(&output); },
|
Ok(output) => { val.push_str(&output); },
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
println!("{}: {}: No such file or directory.", argv0, path);
|
println!("{}: {}: No such file or directory.", argv0, path);
|
||||||
process::exit(66); // sysexits(3) EX_NOINPUT
|
process::exit(66); // sysexits(3) EX_NOINPUT
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
print!("{}", val);
|
print!("{}", val);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
io::stdout().flush().unwrap();
|
io::stdout().flush().unwrap();
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue