mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Merge pull request #266 from ebfe/uutils
uutils: add chroot, factor, nl, tail
This commit is contained in:
commit
ee92573584
3 changed files with 20 additions and 10 deletions
|
@ -64,11 +64,10 @@ fn print_factors_str(num_str: &str) {
|
||||||
print_factors(num);
|
print_factors(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn main() { uumain(os::args()); }
|
fn main() { os::set_exit_status(uumain(os::args())); }
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) {
|
pub fn uumain(args: Vec<String>) -> int {
|
||||||
let program = args.get(0).as_slice();
|
let program = args.get(0).as_slice();
|
||||||
let opts = [
|
let opts = [
|
||||||
getopts::optflag("h", "help", "show this help message"),
|
getopts::optflag("h", "help", "show this help message"),
|
||||||
|
@ -89,11 +88,11 @@ pub fn uumain(args: Vec<String>) {
|
||||||
\n\
|
\n\
|
||||||
{usage}", program = program, version = VERSION, usage = getopts::usage("Print the prime factors of the given number(s). \
|
{usage}", program = program, version = VERSION, usage = getopts::usage("Print the prime factors of the given number(s). \
|
||||||
If none are specified, read from standard input.", opts));
|
If none are specified, read from standard input.", opts));
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
println!("{} {}", program, VERSION);
|
println!("{} {}", program, VERSION);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.free.is_empty() {
|
if matches.free.is_empty() {
|
||||||
|
@ -105,4 +104,5 @@ pub fn uumain(args: Vec<String>) {
|
||||||
print_factors_str(num_str.as_slice());
|
print_factors_str(num_str.as_slice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
0
|
||||||
}
|
}
|
||||||
|
|
12
tail/tail.rs
12
tail/tail.rs
|
@ -25,9 +25,9 @@ use std::io::timer::sleep;
|
||||||
static PROGRAM: &'static str = "tail";
|
static PROGRAM: &'static str = "tail";
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn main () { uumain(os::args()); }
|
fn main() { os::set_exit_status(uumain(os::args())); }
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) {
|
pub fn uumain(args: Vec<String>) -> int {
|
||||||
let mut line_count = 10u;
|
let mut line_count = 10u;
|
||||||
let mut sleep_sec = 1000u64;
|
let mut sleep_sec = 1000u64;
|
||||||
|
|
||||||
|
@ -51,15 +51,15 @@ pub fn uumain(args: Vec<String>) {
|
||||||
Ok (m) => { m }
|
Ok (m) => { m }
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
println!("{:s}", usage(PROGRAM, possible_options));
|
println!("{:s}", usage(PROGRAM, possible_options));
|
||||||
return
|
return 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if given_options.opt_present("h") {
|
if given_options.opt_present("h") {
|
||||||
println!("{:s}", usage(PROGRAM, possible_options));
|
println!("{:s}", usage(PROGRAM, possible_options));
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
if given_options.opt_present("V") { version(); return }
|
if given_options.opt_present("V") { version(); return 0 }
|
||||||
|
|
||||||
let follow = given_options.opt_present("f");
|
let follow = given_options.opt_present("f");
|
||||||
if follow {
|
if follow {
|
||||||
|
@ -112,6 +112,8 @@ pub fn uumain(args: Vec<String>) {
|
||||||
tail(&mut buffer, line_count, follow, sleep_sec);
|
tail(&mut buffer, line_count, follow, sleep_sec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
// It searches for an option in the form of -123123
|
// It searches for an option in the form of -123123
|
||||||
|
|
|
@ -14,6 +14,7 @@ extern crate getopts;
|
||||||
extern crate base64;
|
extern crate base64;
|
||||||
extern crate basename;
|
extern crate basename;
|
||||||
extern crate cat;
|
extern crate cat;
|
||||||
|
extern crate chroot;
|
||||||
extern crate cksum;
|
extern crate cksum;
|
||||||
extern crate comm;
|
extern crate comm;
|
||||||
extern crate cp;
|
extern crate cp;
|
||||||
|
@ -21,6 +22,7 @@ extern crate dirname;
|
||||||
extern crate du;
|
extern crate du;
|
||||||
extern crate echo;
|
extern crate echo;
|
||||||
extern crate env;
|
extern crate env;
|
||||||
|
extern crate factor;
|
||||||
extern crate fold;
|
extern crate fold;
|
||||||
extern crate groups;
|
extern crate groups;
|
||||||
extern crate head;
|
extern crate head;
|
||||||
|
@ -30,6 +32,7 @@ extern crate id;
|
||||||
extern crate kill;
|
extern crate kill;
|
||||||
extern crate logname;
|
extern crate logname;
|
||||||
extern crate mkdir;
|
extern crate mkdir;
|
||||||
|
extern crate nl;
|
||||||
extern crate paste;
|
extern crate paste;
|
||||||
extern crate printenv;
|
extern crate printenv;
|
||||||
extern crate pwd;
|
extern crate pwd;
|
||||||
|
@ -39,6 +42,7 @@ extern crate seq;
|
||||||
extern crate sleep;
|
extern crate sleep;
|
||||||
extern crate sum;
|
extern crate sum;
|
||||||
extern crate tac;
|
extern crate tac;
|
||||||
|
extern crate tail;
|
||||||
extern crate tee;
|
extern crate tee;
|
||||||
extern crate touch;
|
extern crate touch;
|
||||||
extern crate tr;
|
extern crate tr;
|
||||||
|
@ -66,6 +70,7 @@ fn util_map() -> HashMap<&str, fn(Vec<String>) -> int> {
|
||||||
map.insert("base64", base64::uumain);
|
map.insert("base64", base64::uumain);
|
||||||
map.insert("basename", basename::uumain);
|
map.insert("basename", basename::uumain);
|
||||||
map.insert("cat", cat::uumain);
|
map.insert("cat", cat::uumain);
|
||||||
|
map.insert("chroot", chroot::uumain);
|
||||||
map.insert("cksum", cksum::uumain);
|
map.insert("cksum", cksum::uumain);
|
||||||
map.insert("comm", comm::uumain);
|
map.insert("comm", comm::uumain);
|
||||||
map.insert("cp", cp::uumain);
|
map.insert("cp", cp::uumain);
|
||||||
|
@ -73,6 +78,7 @@ fn util_map() -> HashMap<&str, fn(Vec<String>) -> int> {
|
||||||
map.insert("du", du::uumain);
|
map.insert("du", du::uumain);
|
||||||
map.insert("echo", echo::uumain);
|
map.insert("echo", echo::uumain);
|
||||||
map.insert("env", env::uumain);
|
map.insert("env", env::uumain);
|
||||||
|
map.insert("factor", factor::uumain);
|
||||||
map.insert("false", uufalse);
|
map.insert("false", uufalse);
|
||||||
map.insert("fold", fold::uumain);
|
map.insert("fold", fold::uumain);
|
||||||
map.insert("groups", groups::uumain);
|
map.insert("groups", groups::uumain);
|
||||||
|
@ -83,6 +89,7 @@ fn util_map() -> HashMap<&str, fn(Vec<String>) -> int> {
|
||||||
map.insert("kill", kill::uumain);
|
map.insert("kill", kill::uumain);
|
||||||
map.insert("logname", logname::uumain);
|
map.insert("logname", logname::uumain);
|
||||||
map.insert("mkdir", mkdir::uumain);
|
map.insert("mkdir", mkdir::uumain);
|
||||||
|
map.insert("nl", nl::uumain);
|
||||||
map.insert("paste", paste::uumain);
|
map.insert("paste", paste::uumain);
|
||||||
map.insert("printenv", printenv::uumain);
|
map.insert("printenv", printenv::uumain);
|
||||||
map.insert("pwd", pwd::uumain);
|
map.insert("pwd", pwd::uumain);
|
||||||
|
@ -92,6 +99,7 @@ fn util_map() -> HashMap<&str, fn(Vec<String>) -> int> {
|
||||||
map.insert("sleep", sleep::uumain);
|
map.insert("sleep", sleep::uumain);
|
||||||
map.insert("sum", sum::uumain);
|
map.insert("sum", sum::uumain);
|
||||||
map.insert("tac", tac::uumain);
|
map.insert("tac", tac::uumain);
|
||||||
|
map.insert("tail", tail::uumain);
|
||||||
map.insert("tee", tee::uumain);
|
map.insert("tee", tee::uumain);
|
||||||
map.insert("touch", touch::uumain);
|
map.insert("touch", touch::uumain);
|
||||||
map.insert("tr", tr::uumain);
|
map.insert("tr", tr::uumain);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue