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);
|
||||
}
|
||||
|
||||
|
||||
#[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 opts = [
|
||||
getopts::optflag("h", "help", "show this help message"),
|
||||
|
@ -89,11 +88,11 @@ pub fn uumain(args: Vec<String>) {
|
|||
\n\
|
||||
{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));
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
if matches.opt_present("version") {
|
||||
println!("{} {}", program, VERSION);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.free.is_empty() {
|
||||
|
@ -105,4 +104,5 @@ pub fn uumain(args: Vec<String>) {
|
|||
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";
|
||||
|
||||
#[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 sleep_sec = 1000u64;
|
||||
|
||||
|
@ -51,15 +51,15 @@ pub fn uumain(args: Vec<String>) {
|
|||
Ok (m) => { m }
|
||||
Err(_) => {
|
||||
println!("{:s}", usage(PROGRAM, possible_options));
|
||||
return
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
if given_options.opt_present("h") {
|
||||
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");
|
||||
if follow {
|
||||
|
@ -112,6 +112,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
tail(&mut buffer, line_count, follow, sleep_sec);
|
||||
}
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
// It searches for an option in the form of -123123
|
||||
|
|
|
@ -14,6 +14,7 @@ extern crate getopts;
|
|||
extern crate base64;
|
||||
extern crate basename;
|
||||
extern crate cat;
|
||||
extern crate chroot;
|
||||
extern crate cksum;
|
||||
extern crate comm;
|
||||
extern crate cp;
|
||||
|
@ -21,6 +22,7 @@ extern crate dirname;
|
|||
extern crate du;
|
||||
extern crate echo;
|
||||
extern crate env;
|
||||
extern crate factor;
|
||||
extern crate fold;
|
||||
extern crate groups;
|
||||
extern crate head;
|
||||
|
@ -30,6 +32,7 @@ extern crate id;
|
|||
extern crate kill;
|
||||
extern crate logname;
|
||||
extern crate mkdir;
|
||||
extern crate nl;
|
||||
extern crate paste;
|
||||
extern crate printenv;
|
||||
extern crate pwd;
|
||||
|
@ -39,6 +42,7 @@ extern crate seq;
|
|||
extern crate sleep;
|
||||
extern crate sum;
|
||||
extern crate tac;
|
||||
extern crate tail;
|
||||
extern crate tee;
|
||||
extern crate touch;
|
||||
extern crate tr;
|
||||
|
@ -66,6 +70,7 @@ fn util_map() -> HashMap<&str, fn(Vec<String>) -> int> {
|
|||
map.insert("base64", base64::uumain);
|
||||
map.insert("basename", basename::uumain);
|
||||
map.insert("cat", cat::uumain);
|
||||
map.insert("chroot", chroot::uumain);
|
||||
map.insert("cksum", cksum::uumain);
|
||||
map.insert("comm", comm::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("echo", echo::uumain);
|
||||
map.insert("env", env::uumain);
|
||||
map.insert("factor", factor::uumain);
|
||||
map.insert("false", uufalse);
|
||||
map.insert("fold", fold::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("logname", logname::uumain);
|
||||
map.insert("mkdir", mkdir::uumain);
|
||||
map.insert("nl", nl::uumain);
|
||||
map.insert("paste", paste::uumain);
|
||||
map.insert("printenv", printenv::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("sum", sum::uumain);
|
||||
map.insert("tac", tac::uumain);
|
||||
map.insert("tail", tail::uumain);
|
||||
map.insert("tee", tee::uumain);
|
||||
map.insert("touch", touch::uumain);
|
||||
map.insert("tr", tr::uumain);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue