mirror of
https://github.com/uutils/coreutils
synced 2024-12-15 07:42:48 +00:00
commit
8328ba2e0a
1 changed files with 38 additions and 26 deletions
|
@ -19,16 +19,16 @@ use std::collections::hashmap::HashMap;
|
||||||
static NAME: &'static str = "uutils";
|
static NAME: &'static str = "uutils";
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
fn util_map() -> HashMap<&str, fn(Vec<String>) -> int> {
|
fn util_map() -> HashMap<&'static str, fn(Vec<String>) -> int> {
|
||||||
fn uutrue(_: Vec<String>) -> int { 0 }
|
fn uutrue(_: Vec<String>) -> int { 0 }
|
||||||
fn uufalse(_: Vec<String>) -> int { 1 }
|
fn uufalse(_: Vec<String>) -> int { 1 }
|
||||||
|
|
||||||
let mut map = HashMap::<&str, fn(Vec<String>) -> int>::new();
|
let mut map = HashMap::new();
|
||||||
@UTIL_MAP@
|
@UTIL_MAP@
|
||||||
map
|
map
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(cmap: &HashMap<&str, fn(Vec<String>) -> int>) {
|
fn usage(cmap: &HashMap<&'static str, fn(Vec<String>) -> int>) {
|
||||||
println!("{} {}", NAME, VERSION);
|
println!("{} {}", NAME, VERSION);
|
||||||
println!("");
|
println!("");
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
|
@ -49,11 +49,16 @@ fn main() {
|
||||||
// try binary name as util name.
|
// try binary name as util name.
|
||||||
let binary = Path::new(args.get(0).as_slice());
|
let binary = Path::new(args.get(0).as_slice());
|
||||||
let binary_as_util = binary.filename_str().unwrap();
|
let binary_as_util = binary.filename_str().unwrap();
|
||||||
if umap.contains_key(&binary_as_util) {
|
|
||||||
let &uumain = umap.get(&binary_as_util);
|
match umap.find_equiv(&binary_as_util) {
|
||||||
|
Some(&uumain) => {
|
||||||
os::set_exit_status(uumain(args));
|
os::set_exit_status(uumain(args));
|
||||||
return
|
return
|
||||||
} else if binary_as_util.starts_with("uutils")
|
}
|
||||||
|
None => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
if binary_as_util.starts_with("uutils")
|
||||||
|| binary_as_util.starts_with("busybox") {
|
|| binary_as_util.starts_with("busybox") {
|
||||||
// uutils can be called as either "uutils", "busybox"
|
// uutils can be called as either "uutils", "busybox"
|
||||||
// "uutils-suffix" or "busybox-suffix". Not sure
|
// "uutils-suffix" or "busybox-suffix". Not sure
|
||||||
|
@ -68,24 +73,29 @@ fn main() {
|
||||||
if args.len() >= 2 {
|
if args.len() >= 2 {
|
||||||
args.shift();
|
args.shift();
|
||||||
let util = args.get(0).as_slice();
|
let util = args.get(0).as_slice();
|
||||||
if umap.contains_key(&util) {
|
|
||||||
let &uumain = umap.get(&util);
|
match umap.find_equiv(&util) {
|
||||||
|
Some(&uumain) => {
|
||||||
os::set_exit_status(uumain(args.clone()));
|
os::set_exit_status(uumain(args.clone()));
|
||||||
return
|
return
|
||||||
} else if args.get(0).as_slice() == "--help" {
|
}
|
||||||
|
None => {
|
||||||
|
if args.get(0).as_slice() == "--help" {
|
||||||
// see if they want help on a specific util
|
// see if they want help on a specific util
|
||||||
if args.len() >= 2 {
|
if args.len() >= 2 {
|
||||||
let util = args.get(1).as_slice();
|
let util = args.get(1).as_slice();
|
||||||
if umap.contains_key(&util) {
|
match umap.find_equiv(&util) {
|
||||||
let &uumain = umap.get(&util);
|
Some(&uumain) => {
|
||||||
os::set_exit_status(uumain(vec!["--help".to_string()]));
|
os::set_exit_status(uumain(vec![util.to_string(), "--help".to_string()]));
|
||||||
return
|
return
|
||||||
} else {
|
}
|
||||||
|
None => {
|
||||||
println!("{}: applet not found", util);
|
println!("{}: applet not found", util);
|
||||||
os::set_exit_status(1);
|
os::set_exit_status(1);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
usage(&umap);
|
usage(&umap);
|
||||||
os::set_exit_status(0);
|
os::set_exit_status(0);
|
||||||
return
|
return
|
||||||
|
@ -94,6 +104,8 @@ fn main() {
|
||||||
os::set_exit_status(1);
|
os::set_exit_status(1);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// no arguments provided
|
// no arguments provided
|
||||||
usage(&umap);
|
usage(&umap);
|
||||||
|
|
Loading…
Reference in a new issue