mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
add uutils multicall binary
This commit is contained in:
parent
9665fb0a26
commit
13f01e4c11
42 changed files with 293 additions and 80 deletions
18
Makefile
18
Makefile
|
@ -58,6 +58,9 @@ BUILD ?= $(PROGS)
|
|||
EXES := \
|
||||
$(sort $(filter $(BUILD),$(filter-out $(DONT_BUILD),$(PROGS))))
|
||||
|
||||
CRATES := \
|
||||
$(sort $(filter $(EXES), $(filter-out md5sum, $(EXES))))
|
||||
|
||||
# Programs with usable tests
|
||||
TEST_PROGS := \
|
||||
cat \
|
||||
|
@ -89,6 +92,11 @@ clean_$(1):
|
|||
endif
|
||||
endef
|
||||
|
||||
define CRATE_BUILD
|
||||
build/$(2): $(1)/$(1).rs
|
||||
$(call command,$(RUSTC) $(RUSTCFLAGS) --crate-type rlib $(1)/$(1).rs --out-dir build)
|
||||
endef
|
||||
|
||||
# Test exe built rules
|
||||
define TEST_BUILD
|
||||
test_$(1): tmp/$(1)_test build build/$(1)
|
||||
|
@ -99,7 +107,14 @@ tmp/$(1)_test: $(1)/test.rs
|
|||
endef
|
||||
|
||||
# Main rules
|
||||
ifneq ($(MULTICALL), 1)
|
||||
all: build $(EXES_PATHS)
|
||||
else
|
||||
all: build build/uutils
|
||||
|
||||
build/uutils: uutils/uutils.rs $(addprefix build/, $(foreach crate,$(CRATES),$(shell $(RUSTC) --crate-type rlib --crate-file-name $(crate)/$(crate).rs)))
|
||||
$(RUSTC) $(RUSTCFLAGS) -L build/ uutils/uutils.rs -o $@
|
||||
endif
|
||||
|
||||
test: tmp $(addprefix test_,$(TESTS))
|
||||
$(RM) -rf tmp
|
||||
|
@ -117,5 +132,8 @@ tmp:
|
|||
# Creating necessary rules for each targets
|
||||
$(foreach exe,$(EXES),$(eval $(call EXE_BUILD,$(exe))))
|
||||
$(foreach test,$(TESTS),$(eval $(call TEST_BUILD,$(test))))
|
||||
ifeq ($(MULTICALL), 1)
|
||||
$(foreach crate,$(CRATES),$(eval $(call CRATE_BUILD,$(crate),$(shell $(RUSTC) --crate-type rlib --crate-file-name --out-dir build $(crate)/$(crate).rs))))
|
||||
endif
|
||||
|
||||
.PHONY: all test clean
|
||||
|
|
|
@ -35,8 +35,7 @@ mod util;
|
|||
|
||||
static NAME: &'static str = "base64";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let opts = ~[
|
||||
optflag("d", "decode", "decode data"),
|
||||
optflag("i", "ignore-garbage", "when decoding, ignore non-alphabetic characters"),
|
||||
|
@ -91,6 +90,10 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
uumain(os::args());
|
||||
}
|
||||
|
||||
fn decode(input: &mut Reader, ignore_garbage: bool) {
|
||||
let mut to_decode = match input.read_to_str() {
|
||||
Ok(m) => m,
|
||||
|
|
|
@ -23,8 +23,9 @@ mod util;
|
|||
static NAME: &'static str = "basename";
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = strip_dir(args.get(0).as_slice());
|
||||
|
||||
//
|
||||
|
|
|
@ -19,8 +19,9 @@ use std::io::{print, File};
|
|||
use std::io::stdio::{stdout_raw, stdin_raw};
|
||||
use std::io::{BufferedWriter};
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).as_slice();
|
||||
let opts = ~[
|
||||
getopts::optflag("A", "show-all", "equivalent to -vET"),
|
||||
|
|
|
@ -77,8 +77,9 @@ fn open_file(name: &str) -> IoResult<Box<Reader>> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let args = os::args();
|
||||
pub fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let opts = [
|
||||
getopts::optflag("h", "help", "display this help and exit"),
|
||||
getopts::optflag("V", "version", "output version information and exit"),
|
||||
|
|
|
@ -87,8 +87,9 @@ fn open_file(name: &str) -> IoResult<Box<Buffer>> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let args = os::args();
|
||||
pub fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let opts = [
|
||||
getopts::optflag("1", "", "suppress column 1 (lines uniq to FILE1)"),
|
||||
getopts::optflag("2", "", "suppress column 2 (lines uniq to FILE2)"),
|
||||
|
|
5
cp/cp.rs
5
cp/cp.rs
|
@ -31,8 +31,9 @@ pub enum Mode {
|
|||
Version,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let opts = ~[
|
||||
optflag("h", "help", "display this help and exit"),
|
||||
optflag("", "version", "output version information and exit"),
|
||||
|
|
|
@ -16,8 +16,9 @@ use std::io::print;
|
|||
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).clone();
|
||||
let opts = ~[
|
||||
getopts::optflag("z", "zero", "separate output with NUL rather than newline"),
|
||||
|
|
5
du/du.rs
5
du/du.rs
|
@ -90,8 +90,9 @@ fn du(path: &Path, mut my_stat: Stat,
|
|||
return stats;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).as_slice();
|
||||
let opts = ~[
|
||||
// In task
|
||||
|
|
|
@ -69,8 +69,9 @@ fn convert_str(string: &str, index: uint, base: uint) -> (char, int) {
|
|||
return (to_char(&bytes, base), max_digits)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).clone();
|
||||
let opts = ~[
|
||||
getopts::optflag("n", "", "do not output the trailing newline"),
|
||||
|
|
7
env/env.rs
vendored
7
env/env.rs
vendored
|
@ -13,6 +13,8 @@
|
|||
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
use std::os;
|
||||
|
||||
struct options {
|
||||
ignore_env: bool,
|
||||
null: bool,
|
||||
|
@ -51,8 +53,9 @@ fn print_env(null: bool) {
|
|||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = std::os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let prog = args.get(0).as_slice();
|
||||
|
||||
// to handle arguments the same way than GNU env, we can't use getopts
|
||||
|
|
|
@ -26,9 +26,10 @@ mod util;
|
|||
static NAME: &'static str = "fold";
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
fn main() {
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
|
||||
let args = os::args();
|
||||
let (args, obs_width) = handle_obsolete(args.as_slice());
|
||||
let program = args.get(0).clone();
|
||||
|
||||
|
|
|
@ -25,8 +25,9 @@ use c_types::{get_pw_from_args, group};
|
|||
|
||||
static NAME: &'static str = "groups";
|
||||
|
||||
fn main () {
|
||||
let args = os::args();
|
||||
fn main () { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let options = [
|
||||
optflag("h", "", "Help")
|
||||
];
|
||||
|
|
|
@ -22,11 +22,13 @@ use getopts::{optopt, optflag, getopts, usage};
|
|||
|
||||
static PROGRAM: &'static str = "head";
|
||||
|
||||
fn main () {
|
||||
fn main () { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let mut line_count = 10u;
|
||||
|
||||
// handle obsolete -number syntax
|
||||
let options = match obsolete(os::args().tail()) {
|
||||
let options = match obsolete(args.tail()) {
|
||||
(args, Some(n)) => { line_count = n; args },
|
||||
(args, None) => args
|
||||
};
|
||||
|
|
|
@ -49,8 +49,9 @@ extern {
|
|||
pub fn gethostid() -> c_long;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
|
||||
let opts = [
|
||||
optflag("", "help", "display this help and exit"),
|
||||
|
|
|
@ -23,8 +23,9 @@ extern {
|
|||
fn sethostname(name: *libc::c_char, namelen: libc::c_int) -> libc::c_int;
|
||||
}
|
||||
|
||||
fn main () {
|
||||
let args = os::args();
|
||||
fn main () { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0);
|
||||
|
||||
let options = [
|
||||
|
|
5
id/id.rs
5
id/id.rs
|
@ -87,8 +87,9 @@ extern {
|
|||
|
||||
static NAME: &'static str = "id";
|
||||
|
||||
fn main () {
|
||||
let args = os::args();
|
||||
fn main () { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let args_t = args.tail();
|
||||
|
||||
let options = [
|
||||
|
|
|
@ -53,8 +53,9 @@ pub enum Mode {
|
|||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
|
||||
let opts = ~[
|
||||
optflag("h", "help", "display this help and exit"),
|
||||
|
|
|
@ -43,8 +43,9 @@ fn version() {
|
|||
println!("{} {}", NAME, VERSION);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).clone();
|
||||
|
||||
//
|
||||
|
|
|
@ -28,8 +28,9 @@ static VERSION: &'static str = "1.0.0";
|
|||
/**
|
||||
* Handles option parsing
|
||||
*/
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
|
||||
let opts = ~[
|
||||
// Linux-specific options, not implemented
|
||||
|
|
|
@ -23,8 +23,9 @@ mod util;
|
|||
static NAME: &'static str = "paste";
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).clone();
|
||||
|
||||
let opts = ~[
|
||||
|
|
|
@ -24,8 +24,9 @@ mod util;
|
|||
|
||||
static NAME: &'static str = "printenv";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).clone();
|
||||
let opts = ~[
|
||||
getopts::optflag("0", "null", "end each output line with 0 byte rather than newline"),
|
||||
|
|
|
@ -23,8 +23,9 @@ mod util;
|
|||
static NAME: &'static str = "pwd";
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).clone();
|
||||
let opts = ~[
|
||||
getopts::optflag("", "help", "display this help and exit"),
|
||||
|
|
5
rm/rm.rs
5
rm/rm.rs
|
@ -29,8 +29,9 @@ enum InteractiveMode {
|
|||
|
||||
static NAME: &'static str = "rm";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).clone();
|
||||
|
||||
// TODO: make getopts support -R in addition to -r
|
||||
|
|
|
@ -22,8 +22,9 @@ mod util;
|
|||
|
||||
static NAME: &'static str = "rmdir";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).clone();
|
||||
|
||||
let opts = ~[
|
||||
|
|
|
@ -33,8 +33,9 @@ fn escape_sequences(s: &str) -> String {
|
|||
replace("\\t", "\t")
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let opts = ~[
|
||||
getopts::optopt("s", "separator", "Separator character (defaults to \\n)", ""),
|
||||
getopts::optopt("t", "terminator", "Terminator character (defaults to separator)", ""),
|
||||
|
|
|
@ -23,8 +23,9 @@ mod util;
|
|||
|
||||
static NAME: &'static str = "sleep";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).clone();
|
||||
|
||||
let opts = ~[
|
||||
|
|
|
@ -76,8 +76,9 @@ fn open(name: &str) -> IoResult<Box<Reader>> {
|
|||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).as_slice();
|
||||
let opts = [
|
||||
getopts::optflag("r", "", "use the BSD compatible algorithm (default)"),
|
||||
|
|
|
@ -23,8 +23,9 @@ mod util;
|
|||
static NAME: &'static str = "tac";
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).clone();
|
||||
|
||||
let opts = ~[
|
||||
|
|
|
@ -24,8 +24,10 @@ use getopts::{getopts, optflag, usage};
|
|||
static NAME: &'static str = "tee";
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
fn main() {
|
||||
match options(args().as_slice()).and_then(exec) {
|
||||
fn main() { uumain(args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
match options(args.as_slice()).and_then(exec) {
|
||||
Ok(_) => set_exit_status(0),
|
||||
Err(_) => set_exit_status(1)
|
||||
}
|
||||
|
|
|
@ -22,8 +22,9 @@ mod util;
|
|||
static NAME: &'static str = "touch";
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let opts = ~[
|
||||
getopts::optflag("a", "", "change only the access time"),
|
||||
getopts::optflag("c", "no-create", "do not create any files"),
|
||||
|
|
4
tr/tr.rs
4
tr/tr.rs
|
@ -146,8 +146,8 @@ fn usage(opts: &[OptGroup]) {
|
|||
print(getopts::usage("Translate or delete characters.", opts).as_slice());
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let args = os::args();
|
||||
pub fn main() { uumain(os::args()); }
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let opts = [
|
||||
getopts::optflag("c", "complement", "use the complement of SET1"),
|
||||
getopts::optflag("C", "", "same as -c"),
|
||||
|
|
|
@ -46,8 +46,9 @@ enum TruncateMode {
|
|||
|
||||
static NAME: &'static str = "truncate";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).clone();
|
||||
|
||||
let opts = ~[
|
||||
|
|
|
@ -34,9 +34,9 @@ extern {
|
|||
|
||||
static NAME: &'static str = "tty";
|
||||
|
||||
fn main () {
|
||||
let args = os::args();
|
||||
fn main () { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let options = [
|
||||
optflag("s", "silent", "print nothing, only return an exit status")
|
||||
];
|
||||
|
|
|
@ -51,8 +51,9 @@ unsafe fn getuname() -> utsrust {
|
|||
|
||||
static NAME: &'static str = "uname";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).as_slice();
|
||||
let opts = ~[
|
||||
getopts::optflag("h", "help", "display this help and exit"),
|
||||
|
|
|
@ -26,8 +26,9 @@ mod util;
|
|||
|
||||
static NAME: &'static str = "unlink";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).clone();
|
||||
let opts = ~[
|
||||
getopts::optflag("h", "help", "display this help and exit"),
|
||||
|
|
|
@ -47,8 +47,9 @@ extern {
|
|||
fn utmpxname(file: *c_char) -> c_int;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).clone();
|
||||
let opts = ~[
|
||||
getopts::optflag("v", "version", "output version information and exit"),
|
||||
|
|
|
@ -47,8 +47,9 @@ extern {
|
|||
|
||||
static NAME: &'static str = "users";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).as_slice();
|
||||
let opts = ~[
|
||||
getopts::optflag("h", "help", "display this help and exit"),
|
||||
|
|
151
uutils/uutils.rs
Normal file
151
uutils/uutils.rs
Normal file
|
@ -0,0 +1,151 @@
|
|||
#![crate_id(name="uutils", vers="1.0.0", author="Michael Gehring")]
|
||||
|
||||
/*
|
||||
* This file is part of the uutils coreutils package.
|
||||
*
|
||||
* (c) Michael Gehring <mg@ebfe.org>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
extern crate collections;
|
||||
extern crate getopts;
|
||||
|
||||
extern crate base64;
|
||||
extern crate basename;
|
||||
extern crate cat;
|
||||
extern crate cksum;
|
||||
extern crate comm;
|
||||
extern crate cp;
|
||||
extern crate dirname;
|
||||
extern crate du;
|
||||
extern crate echo;
|
||||
extern crate env;
|
||||
extern crate fold;
|
||||
extern crate groups;
|
||||
extern crate head;
|
||||
extern crate hostid;
|
||||
extern crate hostname;
|
||||
extern crate id;
|
||||
extern crate kill;
|
||||
extern crate logname;
|
||||
extern crate mkdir;
|
||||
extern crate paste;
|
||||
extern crate printenv;
|
||||
extern crate pwd;
|
||||
extern crate rm;
|
||||
extern crate rmdir;
|
||||
extern crate seq;
|
||||
extern crate sleep;
|
||||
extern crate sum;
|
||||
extern crate tac;
|
||||
extern crate tee;
|
||||
extern crate touch;
|
||||
extern crate tr;
|
||||
extern crate truncate;
|
||||
extern crate tty;
|
||||
extern crate uname;
|
||||
extern crate unlink;
|
||||
extern crate uptime;
|
||||
extern crate users;
|
||||
extern crate wc;
|
||||
extern crate whoami;
|
||||
extern crate yes;
|
||||
|
||||
use std::os;
|
||||
use collections::hashmap::HashMap;
|
||||
|
||||
static NAME: &'static str = "uutils";
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
fn util_map() -> HashMap<&str, fn(Vec<String>)> {
|
||||
fn uutrue(_: Vec<String>) { os::set_exit_status(0); }
|
||||
fn uufalse(_: Vec<String>) { os::set_exit_status(1); }
|
||||
|
||||
let mut map = HashMap::new();
|
||||
map.insert("base64", base64::uumain);
|
||||
map.insert("basename", basename::uumain);
|
||||
map.insert("cat", cat::uumain);
|
||||
map.insert("cksum", cksum::uumain);
|
||||
map.insert("comm", comm::uumain);
|
||||
map.insert("cp", cp::uumain);
|
||||
map.insert("dirname", dirname::uumain);
|
||||
map.insert("du", du::uumain);
|
||||
map.insert("echo", echo::uumain);
|
||||
map.insert("env", env::uumain);
|
||||
map.insert("false", uufalse);
|
||||
map.insert("fold", fold::uumain);
|
||||
map.insert("groups", groups::uumain);
|
||||
map.insert("head", head::uumain);
|
||||
map.insert("hostid", hostid::uumain);
|
||||
map.insert("hostname", hostname::uumain);
|
||||
map.insert("id", id::uumain);
|
||||
map.insert("kill", kill::uumain);
|
||||
map.insert("logname", logname::uumain);
|
||||
map.insert("mkdir", mkdir::uumain);
|
||||
map.insert("paste", paste::uumain);
|
||||
map.insert("printenv", printenv::uumain);
|
||||
map.insert("pwd", pwd::uumain);
|
||||
map.insert("rm", rm::uumain);
|
||||
map.insert("rmdir", rmdir::uumain);
|
||||
map.insert("seq", seq::uumain);
|
||||
map.insert("sleep", sleep::uumain);
|
||||
map.insert("sum", sum::uumain);
|
||||
map.insert("tac", tac::uumain);
|
||||
map.insert("tee", tee::uumain);
|
||||
map.insert("touch", touch::uumain);
|
||||
map.insert("tr", tr::uumain);
|
||||
map.insert("true", uutrue);
|
||||
map.insert("truncate", truncate::uumain);
|
||||
map.insert("tty", tty::uumain);
|
||||
map.insert("uname", uname::uumain);
|
||||
map.insert("unlink", unlink::uumain);
|
||||
map.insert("uptime", uptime::uumain);
|
||||
map.insert("users", users::uumain);
|
||||
map.insert("wc", wc::uumain);
|
||||
map.insert("whoami", whoami::uumain);
|
||||
map.insert("yes", yes::uumain);
|
||||
map
|
||||
}
|
||||
|
||||
fn usage(cmap: &HashMap<&str, fn(Vec<String>)>) {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
println!("");
|
||||
println!("Usage:");
|
||||
println!(" {} [util [arguments...]", NAME);
|
||||
println!("Utils:");
|
||||
let mut utils: Vec<&str> = cmap.keys().map(|&s| s).collect();
|
||||
utils.sort();
|
||||
for util in utils.iter() {
|
||||
println!("\t{}", util);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let umap = util_map();
|
||||
let mut args = os::args();
|
||||
|
||||
// try binary name as util name.
|
||||
let binary = Path::new(args.get(0).as_slice());
|
||||
let util = binary.filename_str().unwrap();
|
||||
if umap.contains_key(&util) {
|
||||
let &uumain = umap.get(&util);
|
||||
uumain(args);
|
||||
return
|
||||
}
|
||||
|
||||
// try first arg as util name.
|
||||
if args.len() >= 2 {
|
||||
args.shift();
|
||||
let util = args.get(0).as_slice().clone();
|
||||
if umap.contains_key(&util) {
|
||||
let &uumain = umap.get(&util);
|
||||
uumain(args.clone());
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
usage(&umap);
|
||||
os::set_exit_status(1);
|
||||
}
|
5
wc/wc.rs
5
wc/wc.rs
|
@ -33,8 +33,9 @@ struct Result {
|
|||
|
||||
static NAME: &'static str = "wc";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).clone();
|
||||
let opts = ~[
|
||||
getopts::optflag("c", "bytes", "print the byte counts"),
|
||||
|
|
|
@ -41,8 +41,9 @@ unsafe fn getusername() -> String {
|
|||
|
||||
static NAME: &'static str = "whoami";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).as_slice();
|
||||
let opts = ~[
|
||||
getopts::optflag("h", "help", "display this help and exit"),
|
||||
|
|
|
@ -24,8 +24,9 @@ mod util;
|
|||
|
||||
static NAME: &'static str = "yes";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
fn main() { uumain(os::args()); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
let program = args.get(0).clone();
|
||||
let opts = ~[
|
||||
getopts::optflag("h", "help", "display this help and exit"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue