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.
|
||||
"-u" => {},
|
||||
|
||||
"-" => {},
|
||||
|
||||
_ => {
|
||||
println!("Usage: {} [options...] [files...]", argv0);
|
||||
process::exit(64); // sysexits(3) EX_USAGE
|
||||
@ -32,35 +34,33 @@ fn main() {
|
||||
};
|
||||
}
|
||||
}
|
||||
else {
|
||||
for path in args {
|
||||
let mut val = String::new();
|
||||
for path in args {
|
||||
let mut val = String::new();
|
||||
|
||||
match path.as_str() {
|
||||
"-" => {
|
||||
let mut content = String::new();
|
||||
match io::stdin().read_line(&mut content) {
|
||||
Ok(_) => { val.push_str(&content); },
|
||||
Err(_) => {
|
||||
println!("Usage: {} [options...] [files...]", argv0);
|
||||
process::exit(64); // sysexits(3) EX_USAGE
|
||||
},
|
||||
};
|
||||
},
|
||||
match path.as_str() {
|
||||
"-" => {
|
||||
let mut content = String::new();
|
||||
match io::stdin().read_line(&mut content) {
|
||||
Ok(_) => { val.push_str(&content); },
|
||||
Err(_) => {
|
||||
println!("Usage: {} [options...] [files...]", argv0);
|
||||
process::exit(64); // sysexits(3) EX_USAGE
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
_ => {
|
||||
match read_to_string(&path) {
|
||||
Ok(output) => { val.push_str(&output); },
|
||||
Err(_) => {
|
||||
println!("{}: {}: No such file or directory.", argv0, path);
|
||||
process::exit(66); // sysexits(3) EX_NOINPUT
|
||||
},
|
||||
};
|
||||
},
|
||||
}
|
||||
_ => {
|
||||
match read_to_string(&path) {
|
||||
Ok(output) => { val.push_str(&output); },
|
||||
Err(_) => {
|
||||
println!("{}: {}: No such file or directory.", argv0, path);
|
||||
process::exit(66); // sysexits(3) EX_NOINPUT
|
||||
},
|
||||
};
|
||||
},
|
||||
}
|
||||
print!("{}", val);
|
||||
}
|
||||
}
|
||||
|
||||
io::stdout().flush().unwrap();
|
||||
}
|
||||
|
Reference in New Issue
Block a user