mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-14 11:07:59 +00:00
update coding style and add basename to makefile
This commit is contained in:
parent
8ef06144a1
commit
15465e21ec
2 changed files with 23 additions and 33 deletions
1
Makefile
1
Makefile
|
@ -17,6 +17,7 @@ EXES := \
|
||||||
wc \
|
wc \
|
||||||
whoami \
|
whoami \
|
||||||
yes \
|
yes \
|
||||||
|
basename \
|
||||||
|
|
||||||
|
|
||||||
TESTS := \
|
TESTS := \
|
||||||
|
|
|
@ -20,7 +20,6 @@ use extra::getopts::groups;
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
let args = os::args();
|
let args = os::args();
|
||||||
|
|
||||||
let program = strip_dir(&args[ 0 ].clone());
|
let program = strip_dir(&args[ 0 ].clone());
|
||||||
|
@ -45,7 +44,6 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
|
|
||||||
println!("Usage: {0:s} NAME [SUFFIX]", program);
|
println!("Usage: {0:s} NAME [SUFFIX]", program);
|
||||||
println!(" or: {0:s} OPTION", program);
|
println!(" or: {0:s} OPTION", program);
|
||||||
println("Print NAME with any leading directory components removed.");
|
println("Print NAME with any leading directory components removed.");
|
||||||
|
@ -57,21 +55,18 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
|
|
||||||
println(program + " " + VERSION);
|
println(program + " " + VERSION);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// too few arguments
|
// too few arguments
|
||||||
if args.len() < 2 {
|
if args.len() < 2 {
|
||||||
|
|
||||||
println(program + ": missing operand");
|
println(program + ": missing operand");
|
||||||
println("Try `" + program + " --help' for more information.");
|
println("Try `" + program + " --help' for more information.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// too many arguments
|
// too many arguments
|
||||||
else if args.len() > 3 {
|
else if args.len() > 3 {
|
||||||
|
|
||||||
println(program + ": extra operand `" + args[ 3 ] + "'");
|
println(program + ": extra operand `" + args[ 3 ] + "'");
|
||||||
println("Try `" + program + " --help' for more information.");
|
println("Try `" + program + " --help' for more information.");
|
||||||
return;
|
return;
|
||||||
|
@ -86,7 +81,6 @@ fn main() {
|
||||||
let mut name = strip_dir(&fullname);
|
let mut name = strip_dir(&fullname);
|
||||||
|
|
||||||
if args.len() > 2 {
|
if args.len() > 2 {
|
||||||
|
|
||||||
let suffix = args[ 2 ].clone();
|
let suffix = args[ 2 ].clone();
|
||||||
name = strip_suffix(&name, &suffix);
|
name = strip_suffix(&name, &suffix);
|
||||||
}
|
}
|
||||||
|
@ -95,30 +89,25 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn strip_dir(fullname :&~str) -> ~str {
|
fn strip_dir(fullname :&~str) -> ~str {
|
||||||
|
|
||||||
let mut name = ~"";
|
let mut name = ~"";
|
||||||
|
|
||||||
for c in fullname.rev_iter() {
|
for c in fullname.rev_iter() {
|
||||||
|
|
||||||
if c == '/' || c == '\\' {
|
if c == '/' || c == '\\' {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = str::from_char(c) + name;
|
name = str::from_char(c) + name;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fullname.clone();
|
return fullname.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn strip_suffix(name: &~str, suffix: &~str) -> ~str {
|
fn strip_suffix(name: &~str, suffix: &~str) -> ~str {
|
||||||
|
|
||||||
if name == suffix {
|
if name == suffix {
|
||||||
return name.clone();
|
return name.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
if name.ends_with(*suffix) {
|
if name.ends_with(*suffix) {
|
||||||
|
|
||||||
return name.slice_to(name.len() - suffix.len()).into_owned();
|
return name.slice_to(name.len() - suffix.len()).into_owned();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue