Compare commits
10 Commits
5c82375ff6
...
4584a6d662
Author | SHA1 | Date |
---|---|---|
silt! | 4584a6d662 | |
Emma Tebibyte | 834d363ead | |
Emma Tebibyte | 2bfeb4b221 | |
Emma Tebibyte | c33d9e0556 | |
Emma Tebibyte | eb0ae4665f | |
Emma Tebibyte | 20e9c19ccd | |
Emma Tebibyte | cc64ab08da | |
Emma Tebibyte | b3477e32f6 | |
Emma Tebibyte | bf07460e53 | |
Emma Tebibyte | 1e0682390d |
|
@ -1,3 +1,7 @@
|
|||
[unstable]
|
||||
build-std = [ "std", "panic_abort" ]
|
||||
build-std-features = [ "panic_immediate_abort" ]
|
||||
|
||||
[profile.release]
|
||||
strip = true # strip symbols from the binary
|
||||
opt-level = "z" # optimize for size
|
||||
|
|
|
@ -6,23 +6,23 @@ version = 3
|
|||
name = "arg"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arg 0.3.1",
|
||||
"arg 0.4.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arg"
|
||||
version = "0.3.1"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae60fcba735ceff2193950be268184f45271dd9e9c0823e6d1e9c5d1070caf81"
|
||||
checksum = "568bbed0b9810cd4b43c8560ff3c5d2318b29d78fc314818d156bbed7075d394"
|
||||
dependencies = [
|
||||
"arg-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arg-derive"
|
||||
version = "0.3.4"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f5f4f6d38dfe8c7ddd11686611d41897abd43db81e28d3cfe8903d78ee5cb06b"
|
||||
checksum = "849efc162c06e51ce911bf4fe702f62a08f3b6ebbbfc5178e86c6bae449c2c60"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
|
@ -34,32 +34,57 @@ name = "coreutils"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"arg 0.1.0",
|
||||
"exit-no-std",
|
||||
"libc",
|
||||
"sysexits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.47"
|
||||
name = "exit-no-std"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
|
||||
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",
|
||||
|
@ -74,21 +99,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"
|
||||
|
|
|
@ -9,6 +9,7 @@ authors = [
|
|||
]
|
||||
|
||||
[dependencies]
|
||||
libc = { version = "0.2.14", default-features = false }
|
||||
sysexits = "0.3.4"
|
||||
arg = { version = "0.1.0", path = "arg", package = "arg" }
|
||||
|
||||
|
|
|
@ -12,8 +12,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "arg"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae60fcba735ceff2193950be268184f45271dd9e9c0823e6d1e9c5d1070caf81"
|
||||
source = "git+https://github.com/DoumanAsh/arg.rs?branch=ignore_single_dash#14342e3fa59795345005bd21cd5f86a437bc0b10"
|
||||
dependencies = [
|
||||
"arg-derive",
|
||||
]
|
||||
|
@ -21,8 +20,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "arg-derive"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f5f4f6d38dfe8c7ddd11686611d41897abd43db81e28d3cfe8903d78ee5cb06b"
|
||||
source = "git+https://github.com/DoumanAsh/arg.rs?branch=ignore_single_dash#14342e3fa59795345005bd21cd5f86a437bc0b10"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
|
|
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
arg = "0.3.1"
|
||||
arg = "0.4.1"
|
||||
|
||||
[lib]
|
||||
crate-type = ["dylib"]
|
||||
|
|
35
build.sh
35
build.sh
|
@ -1,35 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Copyright (c) 2022 YAC
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
# This file is part of YAC coreutils.
|
||||
#
|
||||
# YAC coreutils is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published by the
|
||||
# Free Software Foundation, either version 3 of the License, or (at your
|
||||
# option) any later version.
|
||||
#
|
||||
# YAC coreutils is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
|
||||
if ! test -n "$1"; then
|
||||
printf "Usage: %s [target]\n" "$0" 1>&2
|
||||
printf "For a list of targets, type 'rustc --print target-list'\n" 1>&2
|
||||
exit 64 # sysexits(3) EX_USAGE
|
||||
fi
|
||||
|
||||
if ! command -v cargo; then
|
||||
printf "%s: Missing depenency: cargo(1)\n" "$0" 1>&2
|
||||
exit 69 # syexits(3) EX_UNAVAILABLE
|
||||
fi
|
||||
|
||||
cargo build --release \
|
||||
-Z build-std=std,panic_abort \
|
||||
-Z build-std-features=panic_immediate_abort \
|
||||
--target "$1"
|
87
src/cat.rs
87
src/cat.rs
|
@ -18,10 +18,10 @@
|
|||
*/
|
||||
|
||||
use std::env;
|
||||
use std::fs::{File, read_to_string};
|
||||
use std::io;
|
||||
use std::io::{ BufRead, Write };
|
||||
use std::os::unix::io::FromRawFd;
|
||||
use std::fs::{ File, read_to_string };
|
||||
use std::os::fd::{ AsRawFd, FromRawFd };
|
||||
use std::io::{ self, Read, Write };
|
||||
use std::str;
|
||||
|
||||
use arg::Args;
|
||||
|
||||
|
@ -29,6 +29,8 @@ use sysexits::ExitCode;
|
|||
|
||||
#[derive(Args, Debug)]
|
||||
struct Arguments {
|
||||
argv0: String,
|
||||
|
||||
#[arg(short = "u")]
|
||||
u: bool,
|
||||
|
||||
|
@ -36,47 +38,64 @@ struct Arguments {
|
|||
}
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let mut arguments = env::args().collect::<Vec<String>>();
|
||||
let argv0 = arguments.remove(0);
|
||||
|
||||
let mut args = Arguments::from_args(arguments
|
||||
let mut args = Arguments::from_args(env::args()
|
||||
.collect::<Vec<String>>()
|
||||
.iter()
|
||||
.map(String::as_str)
|
||||
.collect::<Vec<&str>>()
|
||||
).unwrap();
|
||||
|
||||
let mut output = String::new();
|
||||
let argv0 = args.argv0;
|
||||
let mut output: Vec<u8> = vec![];
|
||||
let stdin = io::stdin();
|
||||
|
||||
if args.paths.is_empty() { args.paths.push("-".to_string()); }
|
||||
|
||||
for path in args.paths {
|
||||
if path == "-" {
|
||||
loop {
|
||||
match io::stdin().lock().read_line(&mut output) {
|
||||
Ok(EOF) => if EOF == 0 { break },
|
||||
|
||||
if args.u {
|
||||
for path in args.paths {
|
||||
let handle: File;
|
||||
if path == "-" {
|
||||
handle = unsafe {
|
||||
File::from_raw_fd(stdin.as_raw_fd())
|
||||
}
|
||||
} else {
|
||||
handle = match File::open(&path) {
|
||||
Ok(file) => file,
|
||||
Err(_) => {
|
||||
eprintln!("Usage: {} [options...] [files...]", &argv0);
|
||||
return ExitCode::Usage;
|
||||
eprintln!("{}: {}: No such file or directory.", &argv0, &path);
|
||||
return ExitCode::NoInput;
|
||||
},
|
||||
};
|
||||
}
|
||||
} else {
|
||||
match read_to_string(&path) {
|
||||
Ok(contents) => { output.push_str(&contents) },
|
||||
Err(_) => {
|
||||
eprintln!("{}: {}: No such file or directory.", &argv0, &path);
|
||||
return ExitCode::NoInput;
|
||||
},
|
||||
};
|
||||
let mut stdout = io::BufWriter::with_capacity(0, io::stdout());
|
||||
|
||||
for byte in handle.bytes() {
|
||||
stdout.write(&[byte.unwrap()]).unwrap();
|
||||
stdout.flush().unwrap();
|
||||
}
|
||||
} 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(byte.to_owned());
|
||||
}
|
||||
} else {
|
||||
match read_to_string(&path) {
|
||||
Ok(contents) => output.append(&mut contents.as_bytes().to_owned()),
|
||||
Err(_) => {
|
||||
eprintln!("{}: {}: No such file or directory.", &argv0, &path);
|
||||
return ExitCode::NoInput;
|
||||
},
|
||||
};
|
||||
}
|
||||
stdout.write(&output[..]);
|
||||
output.clear();
|
||||
}
|
||||
print!("{}", output);
|
||||
output.clear();
|
||||
}
|
||||
match io::stdout().flush() {
|
||||
Ok(_) => return ExitCode::Ok,
|
||||
Err(_) => {
|
||||
eprintln!("{}: Cannot write to stdout", &argv0);
|
||||
return ExitCode::OsErr;
|
||||
},
|
||||
};
|
||||
ExitCode::Ok
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (c) 2022 Lilithium Hydride
|
||||
// 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(())
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) 2022 YAC
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/* This file is part of YAC coreutils.
|
||||
*
|
||||
* YAC coreutils is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* YAC coreutils is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#![feature(core_intrinsics, lang_items, start)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
#[lang = "eh_personality"]
|
||||
#[no_mangle]
|
||||
fn rust_eh_personality() {}
|
||||
|
||||
#[lang = "panic_impl"]
|
||||
#[no_mangle]
|
||||
fn panic(_: &core::panic::PanicInfo) -> ! { core::intrinsics::abort() }
|
||||
|
||||
#[no_mangle]
|
||||
fn main() { exit_no_std::exit(1); }
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) 2022 YAC
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/* This file is part of YAC coreutils.
|
||||
*
|
||||
* YAC coreutils is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* YAC coreutils is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#![feature(core_intrinsics, lang_items, start)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
#[lang = "eh_personality"]
|
||||
#[no_mangle]
|
||||
fn rust_eh_personality() {}
|
||||
|
||||
#[lang = "panic_impl"]
|
||||
#[no_mangle]
|
||||
fn panic(_: &core::panic::PanicInfo) -> ! { core::intrinsics::abort() }
|
||||
|
||||
#[no_mangle]
|
||||
fn main() { exit_no_std::exit(0); }
|
Reference in New Issue