yac
/
coreutils
Archived
2
0
Fork 0
This repository has been archived on 2024-01-01. You can view files and clone it, but cannot push or open issues or pull requests.
coreutils/src/rs/cat.rs

48 lines
1.1 KiB
Rust

// Copyright (c) 2022 Emma Tebibyte
// SPDX-License-Identifier: AGPL-3.0-or-later
use std::fs::read_to_string;
use std::io::{stdin, stdout, Write};
use std::env;
use std::process;
fn main() {
let mut args: Vec<String> = env::args().collect();
let argv0 = args.remove(0);
let mut opts = Vec::new();
for arg in &args {
if arg.starts_with("-") {
opts.push(arg);
}
}
if opts.is_empty() == false {
for option in opts {
match option.as_str() {
// Write bytes from the input file to the standard output without
// delay as each is read.
"-u" => {},
_ => {
println! ("Usage: {} [options...] [files...]", argv0);
process::exit(64); // sysexits(3) EX_USAGE
},
};
}
}
else {
for path in args {
match read_to_string(&path) {
Ok(val) => println!("{}", val),
Err(_) => {
println!("{}: {}: No such file or directory.", argv0, path);
process::exit(66); // sysexits(3) EX_NOINPUT
},
};
}
}
stdout().flush().unwrap();
}