mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
Make test pass all of the Busybox tests
This commit is contained in:
parent
8df93584c8
commit
0e4e8f14d6
1 changed files with 25 additions and 13 deletions
|
@ -38,15 +38,7 @@ pub fn uumain(_: Vec<String>) -> int {
|
|||
},
|
||||
_ => args.slice(1, args.len()),
|
||||
};
|
||||
let rv = match args.len() {
|
||||
0 => false,
|
||||
1 => one(args),
|
||||
2 => two(args),
|
||||
3 => three(args),
|
||||
4 => four(args),
|
||||
_ => return 2,
|
||||
};
|
||||
1 - rv as int
|
||||
1 - dispatch(args) as int
|
||||
}
|
||||
|
||||
fn one(args: &[&[u8]]) -> bool {
|
||||
|
@ -88,6 +80,8 @@ fn three(args: &[&[u8]]) -> bool {
|
|||
b"-ge" => integers(args[0], args[2], GreaterEqual),
|
||||
b"-lt" => integers(args[0], args[2], Less),
|
||||
b"-le" => integers(args[0], args[2], LessEqual),
|
||||
b"-a" => one(args.slice_to(1)) && one(args.slice_from(2)),
|
||||
b"-o" => one(args.slice_to(1)) || one(args.slice_from(2)),
|
||||
_ => match args[0] {
|
||||
b"!" => !two(args.slice_from(1)),
|
||||
_ => false,
|
||||
|
@ -96,9 +90,18 @@ fn three(args: &[&[u8]]) -> bool {
|
|||
}
|
||||
|
||||
fn four(args: &[&[u8]]) -> bool {
|
||||
match args[0] {
|
||||
b"!" => !three(args.slice_from(1)),
|
||||
_ => false,
|
||||
let (val, len) = match args[0] {
|
||||
b"!" => (!three(args.slice_from(1)), 4),
|
||||
_ => (three(args), 3)
|
||||
};
|
||||
if len < args.len() {
|
||||
match args[len] {
|
||||
b"-a" => val && dispatch(args.slice_from(len + 1)),
|
||||
b"-o" => val || dispatch(args.slice_from(len + 1)),
|
||||
_ => false
|
||||
}
|
||||
} else {
|
||||
val
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,6 +139,16 @@ fn isatty(fd: &[u8]) -> bool {
|
|||
.map(|i| unsafe { isatty(i) == 1 }).unwrap_or(false)
|
||||
}
|
||||
|
||||
fn dispatch(args: &[&[u8]]) -> bool {
|
||||
match args.len() {
|
||||
0 => false,
|
||||
1 => one(args),
|
||||
2 => two(args),
|
||||
3 => three(args),
|
||||
_ => four(args)
|
||||
}
|
||||
}
|
||||
|
||||
#[deriving(Eq, PartialEq)]
|
||||
enum PathCondition {
|
||||
BlockSpecial,
|
||||
|
@ -242,4 +255,3 @@ fn path(path: &[u8], cond: PathCondition) -> bool {
|
|||
Executable => false, // TODO
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue