cat(1): use bytes over strings, not all input is utf-8
This commit is contained in:
parent
834d363ead
commit
8b9c71c405
84
Cargo.lock
generated
84
Cargo.lock
generated
@ -20,9 +20,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "arg-derive"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7e502162a7be4391f8b0cda30b2aecce232cf6214230fe73f95a462e07f42ba2"
|
||||
checksum = "849efc162c06e51ce911bf4fe702f62a08f3b6ebbbfc5178e86c6bae449c2c60"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
@ -34,37 +34,63 @@ name = "coreutils"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"arg 0.1.0",
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
"exit-no-std",
|
||||
"libc",
|
||||
>>>>>>> cc5a4cf (true(1) & false(1): EVEN SMALLER)
|
||||
"sysexits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.47"
|
||||
name = "libc"
|
||||
version = "0.2.151"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
|
||||
checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
|
||||
|
||||
[[package]]
|
||||
name = "exit-no-std"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a606ffcfcbda9f10d5a4707951ff0ef8017e675bcb8fd1daefa963ed2e4d189"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"pc-ints",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.151"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
|
||||
|
||||
[[package]]
|
||||
name = "pc-ints"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf2cddb86eccbfcdbeb0f10adedcbb2d1d1a272b33911abf8e81332c828dc1b4"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.73"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dd5e8a1f1029c43224ad5898e50140c2aebb1705f19e67c918ebf5b9e797fe1"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.21"
|
||||
version = "1.0.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
|
||||
checksum = "22a37c9326af5ed140c86a46655b5278de879853be5573c01df185b6f49a580a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.105"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -79,21 +105,43 @@ checksum = "913b6c9c3fdc55ec78e76e281706cecfe0cfb4ba07545cbce8342ed943dcfa72"
|
||||
|
||||
[[package]]
|
||||
name = "tabwriter"
|
||||
version = "1.2.1"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36205cfc997faadcc4b0b87aaef3fbedafe20d38d4959a7ca6ff803564051111"
|
||||
checksum = "a327282c4f64f6dc37e3bba4c2b6842cc3a992f204fa58d917696a89f691e5f6"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.5"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
|
||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.10"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
|
||||
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
4
README
Normal file
4
README
Normal file
@ -0,0 +1,4 @@
|
||||
This repository was originally deleted and got royally fucked up in the
|
||||
restoration process. Hopefully it can be of some use as a reference for what
|
||||
not to do. See <https://git.tebibyte.media/bonsai/coreutils> for its successor
|
||||
project.
|
12
src/cat.rs
12
src/cat.rs
@ -20,8 +20,7 @@
|
||||
use std::env;
|
||||
use std::fs::{ File, read_to_string };
|
||||
use std::os::fd::{ AsRawFd, FromRawFd };
|
||||
use std::io;
|
||||
use std::io::{ Read, Write };
|
||||
use std::io::{ self, Read, Write };
|
||||
use std::str;
|
||||
|
||||
use arg::Args;
|
||||
@ -47,7 +46,7 @@ fn main() -> ExitCode {
|
||||
).unwrap();
|
||||
|
||||
let argv0 = args.argv0;
|
||||
let mut output = String::new();
|
||||
let mut output: Vec<u8> = vec![];
|
||||
let stdin = io::stdin();
|
||||
|
||||
if args.paths.is_empty() { args.paths.push("-".to_string()); }
|
||||
@ -76,24 +75,25 @@ fn main() -> ExitCode {
|
||||
}
|
||||
} return ExitCode::Ok;
|
||||
} else {
|
||||
let mut stdout = io::stdout();
|
||||
for path in args.paths {
|
||||
if path == "-" {
|
||||
let mut bytes: Vec<u8> = Vec::new();
|
||||
stdin.lock().read_to_end(&mut bytes).unwrap();
|
||||
|
||||
for byte in &bytes {
|
||||
output.push_str(str::from_utf8(&[byte.to_owned()]).unwrap());
|
||||
output.push(byte.to_owned());
|
||||
}
|
||||
} else {
|
||||
match read_to_string(&path) {
|
||||
Ok(contents) => { output.push_str(&contents) },
|
||||
Ok(contents) => output.append(&mut contents.as_bytes().to_owned()),
|
||||
Err(_) => {
|
||||
eprintln!("{}: {}: No such file or directory.", &argv0, &path);
|
||||
return ExitCode::NoInput;
|
||||
},
|
||||
};
|
||||
}
|
||||
print!("{}", output);
|
||||
stdout.write(&output[..]);
|
||||
output.clear();
|
||||
}
|
||||
}
|
||||
|
32
src/cut.rs
Normal file
32
src/cut.rs
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2022 silt <silt@tebibyte.media>
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, BufRead, Write, stdin};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>>{
|
||||
let mut args: Vec<String> = env::args().skip(1).collect();
|
||||
|
||||
println!("Args: {:#?}", args);
|
||||
|
||||
let mut delim = '\t';
|
||||
let mut field = 1;
|
||||
let mut file = stdin();
|
||||
|
||||
|
||||
match args.first().unwrap().as_str() {
|
||||
mode if ["-b", "-c", "-f"].iter().any(|&s| s == mode) => {
|
||||
let list = args.get(1).unwrap();
|
||||
if !list.chars().all(|s| "0123456789-, ".contains(s)) {
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
_ => { std::process::exit(1) }
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user