yac
/
coreutils
Archived
2
0
Fork 0

actually added stdin support to cat

This commit is contained in:
Emma Tebibyte 2022-12-05 21:03:42 -05:00
parent 5b47345bf5
commit c030d6828c
1 changed files with 25 additions and 25 deletions

View File

@ -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();
}