mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
Handle exit status more consistently. #211
This changes the `uumain` functions to return the exit code as `int`. It does not eliminate all calls to `os::set_exit_status` and `libc::exit`.
This commit is contained in:
parent
ce19eb4329
commit
0ee4fb0576
42 changed files with 285 additions and 195 deletions
|
@ -35,7 +35,7 @@ mod util;
|
|||
|
||||
static NAME: &'static str = "base64";
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
pub fn uumain(args: Vec<String>) -> int {
|
||||
let opts = [
|
||||
optflag("d", "decode", "decode data"),
|
||||
optflag("i", "ignore-garbage", "when decoding, ignore non-alphabetic characters"),
|
||||
|
@ -88,10 +88,12 @@ pub fn uumain(args: Vec<String>) {
|
|||
Help => help(progname.as_slice(), usage.as_slice()),
|
||||
Version => version()
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn main() { uumain(os::args()); }
|
||||
fn main() { os::set_exit_status(uumain(os::args())); }
|
||||
|
||||
fn decode(input: &mut Reader, ignore_garbage: bool) {
|
||||
let mut to_decode = match input.read_to_str() {
|
||||
|
|
|
@ -24,9 +24,9 @@ static NAME: &'static str = "basename";
|
|||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
#[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 = strip_dir(args.get(0).as_slice());
|
||||
|
||||
//
|
||||
|
@ -50,25 +50,25 @@ pub fn uumain(args: Vec<String>) {
|
|||
|
||||
print(getopts::usage("", opts).as_slice());
|
||||
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("version") {
|
||||
println!("{} {}", program, VERSION);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// too few arguments
|
||||
if args.len() < 2 {
|
||||
println!("{}: {}", program, "missing operand");
|
||||
println!("Try '{} --help' for more information.", program);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
// too many arguments
|
||||
else if args.len() > 3 {
|
||||
println!("{}: extra operand '{}'", program, args.get(3));
|
||||
println!("Try '{} --help' for more information.", program);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -85,6 +85,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
}
|
||||
|
||||
println(name.as_slice());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn strip_dir(fullname: &str) -> String {
|
||||
|
|
10
cat/cat.rs
10
cat/cat.rs
|
@ -20,9 +20,9 @@ use std::io::{IoResult};
|
|||
use std::ptr::{copy_nonoverlapping_memory};
|
||||
|
||||
#[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("A", "show-all", "equivalent to -vET"),
|
||||
|
@ -53,11 +53,11 @@ pub fn uumain(args: Vec<String>) {
|
|||
standard output.", opts).as_slice());
|
||||
println!("");
|
||||
println!("With no FILE, or when FILE is -, read standard input.");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
if matches.opt_present("version") {
|
||||
println!("cat 1.0.0");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
let mut number_mode = NumberNone;
|
||||
|
@ -80,6 +80,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
}
|
||||
|
||||
exec(files, number_mode, show_nonprint, show_ends, show_tabs, squeeze_blank);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#[deriving(Eq, PartialEq)]
|
||||
|
|
|
@ -78,9 +78,9 @@ fn open_file(name: &str) -> IoResult<Box<Reader>> {
|
|||
}
|
||||
|
||||
#[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 opts = [
|
||||
getopts::optflag("h", "help", "display this help and exit"),
|
||||
getopts::optflag("V", "version", "output version information and exit"),
|
||||
|
@ -98,12 +98,12 @@ pub fn uumain(args: Vec<String>) {
|
|||
println!(" {} [OPTIONS] [FILE]...", NAME);
|
||||
println!("");
|
||||
print(getopts::usage("Print CRC and size for each file.", opts.as_slice()).as_slice());
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("version") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
let files = matches.free;
|
||||
|
@ -113,7 +113,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
Ok((crc, size)) => println!("{} {}", crc, size),
|
||||
Err(err) => show_error!(2, "{}", err),
|
||||
}
|
||||
return
|
||||
return 0;
|
||||
}
|
||||
|
||||
for fname in files.iter() {
|
||||
|
@ -122,4 +122,6 @@ pub fn uumain(args: Vec<String>) {
|
|||
Err(err) => show_error!(2, "'{}' {}", fname, err),
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
14
comm/comm.rs
14
comm/comm.rs
|
@ -95,9 +95,9 @@ fn open_file(name: &str) -> IoResult<Box<Buffer>> {
|
|||
}
|
||||
|
||||
#[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 opts = [
|
||||
getopts::optflag("1", "", "suppress column 1 (lines uniq to FILE1)"),
|
||||
getopts::optflag("2", "", "suppress column 2 (lines uniq to FILE2)"),
|
||||
|
@ -114,7 +114,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
|
||||
if matches.opt_present("version") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("help") || matches.free.len() != 2 {
|
||||
|
@ -125,14 +125,16 @@ pub fn uumain(args: Vec<String>) {
|
|||
println!("");
|
||||
print(getopts::usage("Compare sorted files line by line.", opts.as_slice()).as_slice());
|
||||
if matches.free.len() != 2 {
|
||||
os::set_exit_status(1);
|
||||
return 0;
|
||||
}
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
let mut f1 = open_file(matches.free.get(0).as_slice()).unwrap();
|
||||
let mut f2 = open_file(matches.free.get(1).as_slice()).unwrap();
|
||||
|
||||
comm(&mut f1, &mut f2, &matches)
|
||||
comm(&mut f1, &mut f2, &matches);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
6
cp/cp.rs
6
cp/cp.rs
|
@ -32,9 +32,9 @@ pub enum Mode {
|
|||
}
|
||||
|
||||
#[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 opts = [
|
||||
optflag("h", "help", "display this help and exit"),
|
||||
optflag("", "version", "output version information and exit"),
|
||||
|
@ -62,6 +62,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
Help => help(progname.as_slice(), usage.as_slice()),
|
||||
Version => version(),
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn version() {
|
||||
|
|
|
@ -17,9 +17,9 @@ use std::io::print;
|
|||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
#[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).clone();
|
||||
let opts = [
|
||||
getopts::optflag("z", "zero", "separate output with NUL rather than newline"),
|
||||
|
@ -41,11 +41,12 @@ pub fn uumain(args: Vec<String>) {
|
|||
print(getopts::usage("Output each NAME with its last non-slash component and trailing slashes
|
||||
removed; if NAME contains no /'s, output '.' (meaning the current
|
||||
directory).", opts).as_slice());
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("version") {
|
||||
return println!("dirname version: {:s}", VERSION);
|
||||
println!("dirname version: {:s}", VERSION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
let separator = match matches.opt_present("zero") {
|
||||
|
@ -66,4 +67,6 @@ directory).", opts).as_slice());
|
|||
println!("{0:s}: missing operand", program);
|
||||
println!("Try '{0:s} --help' for more information.", program);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
24
du/du.rs
24
du/du.rs
|
@ -90,9 +90,9 @@ fn du(path: &Path, mut my_stat: Stat,
|
|||
}
|
||||
|
||||
#[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 = [
|
||||
// In task
|
||||
|
@ -163,7 +163,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
show_error!(1, "Invalid options\n{}", f.to_err_msg());
|
||||
return
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -187,10 +187,10 @@ ers of 1000).",
|
|||
program = program,
|
||||
version = VERSION,
|
||||
usage = getopts::usage("Summarize disk usage of each FILE, recursively for directories.", opts));
|
||||
return
|
||||
return 0;
|
||||
} else if matches.opt_present("version") {
|
||||
println!("{} version: {}", program, VERSION);
|
||||
return
|
||||
return 0;
|
||||
}
|
||||
|
||||
let summarize = matches.opt_present("summarize");
|
||||
|
@ -200,11 +200,11 @@ ers of 1000).",
|
|||
match (max_depth_str, max_depth) {
|
||||
(Some(ref s), _) if summarize => {
|
||||
println!("{}: warning: summarizing conflicts with --max-depth={:s}", program, *s);
|
||||
return
|
||||
return 0;
|
||||
}
|
||||
(Some(ref s), None) => {
|
||||
println!("{}: invalid maximum depth '{:s}'", program, *s);
|
||||
return
|
||||
return 0;
|
||||
}
|
||||
(Some(_), Some(_)) | (None, _) => { /* valid */ }
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ ers of 1000).",
|
|||
for c in s.as_slice().chars() {
|
||||
if found_letter && c.is_digit() || !found_number && !c.is_digit() {
|
||||
println!("{}: invalid --block-size argument '{}'", program, s);
|
||||
return
|
||||
return 0;
|
||||
} else if c.is_digit() {
|
||||
found_number = true;
|
||||
numbers.push(c as u8);
|
||||
|
@ -261,7 +261,7 @@ ers of 1000).",
|
|||
"ZB" => 1000 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000,
|
||||
"YB" => 1000 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000,
|
||||
_ => {
|
||||
println!("{}: invalid --block-size argument '{}'", program, s); return
|
||||
println!("{}: invalid --block-size argument '{}'", program, s); return 0;
|
||||
}
|
||||
};
|
||||
number * multiple
|
||||
|
@ -300,7 +300,7 @@ Valid arguments are:
|
|||
- 'long-iso'
|
||||
- 'iso'
|
||||
Try '{program} --help' for more information.", s, program = program);
|
||||
return
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -339,7 +339,7 @@ Try '{program} --help' for more information.", s, program = program);
|
|||
Valid arguments are:
|
||||
- 'accessed', 'created', 'modified'
|
||||
Try '{program} --help' for more information.", program = program);
|
||||
return
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
None => stat.fstat.modified
|
||||
|
@ -366,4 +366,6 @@ Try '{program} --help' for more information.", s, program = program);
|
|||
print!("{:<10} total", convert_size(grand_total));
|
||||
print!("{}", line_separator);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
11
echo/echo.rs
11
echo/echo.rs
|
@ -70,9 +70,9 @@ fn convert_str(string: &str, index: uint, base: uint) -> (char, int) {
|
|||
}
|
||||
|
||||
#[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).clone();
|
||||
let opts = [
|
||||
getopts::optflag("n", "", "do not output the trailing newline"),
|
||||
|
@ -109,11 +109,12 @@ pub fn uumain(args: Vec<String>) {
|
|||
\\v vertical tab
|
||||
\\0NNN byte with octal value NNN (1 to 3 digits)
|
||||
\\xHH byte with hexadecimal value HH (1 to 2 digits)");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("version") {
|
||||
return println!("echo version: {:s}", VERSION);
|
||||
println!("echo version: {:s}", VERSION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if !matches.free.is_empty() {
|
||||
|
@ -185,4 +186,6 @@ pub fn uumain(args: Vec<String>) {
|
|||
if !matches.opt_present("n") {
|
||||
println!("")
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
24
env/env.rs
vendored
24
env/env.rs
vendored
|
@ -54,9 +54,9 @@ fn print_env(null: bool) {
|
|||
}
|
||||
|
||||
#[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 prog = args.get(0).as_slice();
|
||||
|
||||
// to handle arguments the same way than GNU env, we can't use getopts
|
||||
|
@ -97,8 +97,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
}
|
||||
} else if opt.as_slice().starts_with("--") {
|
||||
match opt.as_slice() {
|
||||
"--help" => { usage(prog); return }
|
||||
"--version" => { version(); return }
|
||||
"--help" => { usage(prog); return 0; }
|
||||
"--version" => { version(); return 0; }
|
||||
|
||||
"--ignore-environment" => opts.ignore_env = true,
|
||||
"--null" => opts.null = true,
|
||||
|
@ -114,7 +114,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
_ => {
|
||||
println!("{:s}: invalid option \"{:s}\"", prog, *opt);
|
||||
println!("Type \"{:s} --help\" for detailed informations", prog);
|
||||
return
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else if opt.as_slice().starts_with("-") {
|
||||
|
@ -131,8 +131,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
for c in chars {
|
||||
// short versions of options
|
||||
match c {
|
||||
'h' => { usage(prog); return }
|
||||
'V' => { version(); return }
|
||||
'h' => { usage(prog); return 0; }
|
||||
'V' => { version(); return 0; }
|
||||
'i' => opts.ignore_env = true,
|
||||
'0' => opts.null = true,
|
||||
'u' => {
|
||||
|
@ -146,7 +146,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
_ => {
|
||||
println!("{:s}: illegal option -- {:c}", prog, c);
|
||||
println!("Type \"{:s} --help\" for detailed informations", prog);
|
||||
return
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -200,14 +200,16 @@ pub fn uumain(args: Vec<String>) {
|
|||
let args = opts.program.slice_from(1);
|
||||
match Command::new(prog).args(args).stdin(InheritFd(0)).stdout(InheritFd(1)).stderr(InheritFd(2)).status() {
|
||||
Ok(exit) =>
|
||||
std::os::set_exit_status(match exit {
|
||||
return match exit {
|
||||
std::io::process::ExitStatus(s) => s,
|
||||
_ => 1
|
||||
}),
|
||||
Err(_) => std::os::set_exit_status(1)
|
||||
},
|
||||
Err(_) => return 1
|
||||
}
|
||||
} else {
|
||||
// no program provided
|
||||
print_env(opts.null);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -27,9 +27,9 @@ static NAME: &'static str = "fold";
|
|||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
#[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 (args, obs_width) = handle_obsolete(args.as_slice());
|
||||
let program = args.get(0).clone();
|
||||
|
@ -82,6 +82,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
};
|
||||
fold(files, bytes, spaces, width);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
|
||||
|
|
|
@ -26,9 +26,9 @@ use c_types::{get_pw_from_args, group};
|
|||
static NAME: &'static str = "groups";
|
||||
|
||||
#[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 options = [
|
||||
optflag("h", "", "Help")
|
||||
];
|
||||
|
@ -37,9 +37,11 @@ pub fn uumain(args: Vec<String>) {
|
|||
Ok(m) => { m },
|
||||
Err(_) => {
|
||||
show_error!(1, "{}", usage(NAME, options));
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
group(get_pw_from_args(&matches.free), true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
12
head/head.rs
12
head/head.rs
|
@ -23,9 +23,9 @@ use getopts::{optopt, optflag, getopts, usage};
|
|||
static PROGRAM: &'static str = "head";
|
||||
|
||||
#[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;
|
||||
|
||||
// handle obsolete -number syntax
|
||||
|
@ -46,15 +46,15 @@ pub fn uumain(args: Vec<String>) {
|
|||
Ok (m) => { m }
|
||||
Err(_) => {
|
||||
println!("{:s}", usage(PROGRAM, possible_options));
|
||||
return
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
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 }
|
||||
|
||||
match given_options.opt_str("n") {
|
||||
Some(n) => {
|
||||
|
@ -93,6 +93,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
head(&mut buffer, line_count);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// It searches for an option in the form of -123123
|
||||
|
|
|
@ -50,9 +50,9 @@ extern {
|
|||
}
|
||||
|
||||
#[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 opts = [
|
||||
optflag("", "help", "display this help and exit"),
|
||||
|
@ -66,7 +66,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
show_error!(EXIT_ERR, "{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice()));
|
||||
return
|
||||
return 0;
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -83,6 +83,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
Help => help(NAME, usage.as_slice()),
|
||||
Version => version(),
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn version() {
|
||||
|
|
|
@ -24,9 +24,9 @@ extern {
|
|||
}
|
||||
|
||||
#[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);
|
||||
|
||||
let options = [
|
||||
|
@ -38,14 +38,14 @@ pub fn uumain(args: Vec<String>) {
|
|||
|
||||
let matches = match getopts(args.tail(), options) {
|
||||
Ok(m) => { m }
|
||||
_ => { help_menu(program.as_slice(), options); return; }
|
||||
_ => { help_menu(program.as_slice(), options); return 0; }
|
||||
};
|
||||
|
||||
if matches.opt_present("h") {
|
||||
help_menu(program.as_slice(), options);
|
||||
return
|
||||
return 0
|
||||
}
|
||||
if matches.opt_present("V") { version(); return }
|
||||
if matches.opt_present("V") { version(); return 0 }
|
||||
|
||||
match matches.free.len() {
|
||||
0 => {
|
||||
|
@ -55,7 +55,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
let pos = hostname.as_slice().find_str(".");
|
||||
if pos.is_some() {
|
||||
println!("{:s}", hostname.as_slice().slice_to(pos.unwrap()));
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
1 => { xsethostname( matches.free.last().unwrap().as_slice() ) }
|
||||
_ => { help_menu(program.as_slice(), options); }
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn version() {
|
||||
|
|
22
id/id.rs
22
id/id.rs
|
@ -88,9 +88,9 @@ extern {
|
|||
static NAME: &'static str = "id";
|
||||
|
||||
#[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 args_t = args.tail();
|
||||
|
||||
let options = [
|
||||
|
@ -109,18 +109,18 @@ pub fn uumain(args: Vec<String>) {
|
|||
Ok(m) => { m },
|
||||
Err(_) => {
|
||||
println!("{:s}", usage(NAME, options));
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
if matches.opt_present("h") {
|
||||
println!("{:s}", usage(NAME, options));
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("A") {
|
||||
auditid();
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -149,7 +149,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
} else {
|
||||
println!("{:u}", id);
|
||||
}
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if uflag {
|
||||
|
@ -171,22 +171,22 @@ pub fn uumain(args: Vec<String>) {
|
|||
println!("{:d}", id);
|
||||
}
|
||||
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("G") {
|
||||
group(possible_pw, nflag);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("P") {
|
||||
pline(possible_pw);
|
||||
return;
|
||||
return 0;
|
||||
};
|
||||
|
||||
if matches.opt_present("p") {
|
||||
pretty(possible_pw);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if possible_pw.is_some() {
|
||||
|
@ -194,6 +194,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
} else {
|
||||
id_print(possible_pw, false, true, true)
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn pretty(possible_pw: Option<c_passwd>) {
|
||||
|
|
|
@ -53,9 +53,9 @@ pub enum Mode {
|
|||
}
|
||||
|
||||
#[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 opts = [
|
||||
optflag("h", "help", "display this help and exit"),
|
||||
|
@ -72,7 +72,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
show_error!(EXIT_ERR, "{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice()));
|
||||
return
|
||||
return 0
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -96,6 +96,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
Help => help(NAME, usage.as_slice()),
|
||||
Version => version(),
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn version() {
|
||||
|
|
|
@ -44,9 +44,9 @@ fn version() {
|
|||
}
|
||||
|
||||
#[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).clone();
|
||||
|
||||
//
|
||||
|
@ -69,14 +69,16 @@ pub fn uumain(args: Vec<String>) {
|
|||
println!(" {:s}", program);
|
||||
println!("");
|
||||
print(getopts::usage("print user's login name", opts).as_slice());
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
if matches.opt_present("version") {
|
||||
version();
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
exec();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn exec() {
|
||||
|
|
|
@ -27,8 +27,10 @@ mod util;
|
|||
static NAME: &'static str = "md5sum";
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
#[allow(dead_code)]
|
||||
fn main() { os::set_exit_status(uumain(os::args())); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> int {
|
||||
|
||||
let program = args.get(0).clone();
|
||||
|
||||
|
@ -72,11 +74,16 @@ fn main() {
|
|||
} else {
|
||||
matches.free
|
||||
};
|
||||
md5sum(files, binary, check, tag, status, quiet, strict, warn);
|
||||
match md5sum(files, binary, check, tag, status, quiet, strict, warn) {
|
||||
Ok(()) => return 0,
|
||||
Err(e) => return e
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn md5sum(files: Vec<String>, binary: bool, check: bool, tag: bool, status: bool, quiet: bool, strict: bool, warn: bool) {
|
||||
fn md5sum(files: Vec<String>, binary: bool, check: bool, tag: bool, status: bool, quiet: bool, strict: bool, warn: bool) -> Result<(), int> {
|
||||
let mut md5 = crypto::md5::Md5::new();
|
||||
let bytes = md5.output_bits() / 4;
|
||||
let mut bad_format = 0;
|
||||
|
@ -102,7 +109,7 @@ fn md5sum(files: Vec<String>, binary: bool, check: bool, tag: bool, status: bool
|
|||
None => {
|
||||
bad_format += 1;
|
||||
if strict {
|
||||
os::set_exit_status(1);
|
||||
return Err(1);
|
||||
}
|
||||
if warn {
|
||||
show_warning!("{}: {}: improperly formatted MD5 checksum line", filename, i + 1);
|
||||
|
@ -121,7 +128,7 @@ fn md5sum(files: Vec<String>, binary: bool, check: bool, tag: bool, status: bool
|
|||
println!("{}: FAILED", ck_filename);
|
||||
}
|
||||
failed += 1;
|
||||
os::set_exit_status(1);
|
||||
return Err(1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -143,6 +150,8 @@ fn md5sum(files: Vec<String>, binary: bool, check: bool, tag: bool, status: bool
|
|||
show_warning!("{} computed checksum did NOT match", failed);
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fn calc_sum(md5: &mut crypto::md5::Md5, file: &mut Reader, binary: bool) -> String {
|
||||
|
|
|
@ -29,9 +29,9 @@ static VERSION: &'static str = "1.0.0";
|
|||
* Handles option parsing
|
||||
*/
|
||||
#[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 opts = [
|
||||
// Linux-specific options, not implemented
|
||||
|
@ -54,11 +54,11 @@ pub fn uumain(args: Vec<String>) {
|
|||
|
||||
if args.len() == 1 || matches.opt_present("help") {
|
||||
print_help(opts);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
if matches.opt_present("version") {
|
||||
println!("mkdir v{}", VERSION);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
let verbose_flag = matches.opt_present("verbose");
|
||||
let mk_parents = matches.opt_present("parents");
|
||||
|
@ -85,6 +85,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
crash!(1, "missing operand");
|
||||
}
|
||||
exec(dirs, mk_parents, mode, verbose_flag);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn print_help(opts: &[getopts::OptGroup]) {
|
||||
|
|
|
@ -24,9 +24,9 @@ static NAME: &'static str = "paste";
|
|||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
#[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).clone();
|
||||
|
||||
let opts = [
|
||||
|
@ -56,6 +56,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
};
|
||||
paste(matches.free, serial, delimiters.as_slice());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn paste(filenames: Vec<String>, serial: bool, delimiters: &str) {
|
||||
|
|
|
@ -25,9 +25,9 @@ mod util;
|
|||
static NAME: &'static str = "printenv";
|
||||
|
||||
#[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).clone();
|
||||
let opts = [
|
||||
getopts::optflag("0", "null", "end each output line with 0 byte rather than newline"),
|
||||
|
@ -47,11 +47,11 @@ pub fn uumain(args: Vec<String>) {
|
|||
println!(" {0:s} [VARIABLE]... [OPTION]...", program);
|
||||
println!("");
|
||||
print(getopts::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", opts).as_slice());
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
if matches.opt_present("version") {
|
||||
println!("printenv 1.0.0");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
let mut separator = "\n";
|
||||
if matches.opt_present("null") {
|
||||
|
@ -59,6 +59,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
};
|
||||
|
||||
exec(matches.free, separator);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pub fn exec(args: Vec<String>, separator: &str) {
|
||||
|
|
12
pwd/pwd.rs
12
pwd/pwd.rs
|
@ -24,9 +24,9 @@ static NAME: &'static str = "pwd";
|
|||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
#[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).clone();
|
||||
let opts = [
|
||||
getopts::optflag("", "help", "display this help and exit"),
|
||||
|
@ -48,9 +48,15 @@ pub fn uumain(args: Vec<String>) {
|
|||
println!("");
|
||||
print(getopts::usage("Print the full filename of the current working directory.", opts).as_slice());
|
||||
} else if matches.opt_present("version") {
|
||||
return println!("pwd version: {}", VERSION);
|
||||
println!("pwd version: {}", VERSION);
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
let cwd = std::os::getcwd();
|
||||
println!("{}", cwd.display());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
8
rm/rm.rs
8
rm/rm.rs
|
@ -30,9 +30,9 @@ enum InteractiveMode {
|
|||
static NAME: &'static str = "rm";
|
||||
|
||||
#[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).clone();
|
||||
|
||||
// TODO: make getopts support -R in addition to -r
|
||||
|
@ -113,12 +113,14 @@ pub fn uumain(args: Vec<String>) {
|
|||
"Remove all arguments? "
|
||||
};
|
||||
if !prompt(msg) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
remove(matches.free, force, interactive, one_fs, preserve_root,
|
||||
recursive, dir, verbose);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: implement one-file-system
|
||||
|
|
|
@ -23,9 +23,9 @@ mod util;
|
|||
static NAME: &'static str = "rmdir";
|
||||
|
||||
#[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).clone();
|
||||
|
||||
let opts = [
|
||||
|
@ -39,7 +39,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
show_error!(1, "{}", f.to_err_msg());
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -61,6 +61,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
let verbose = matches.opt_present("verbose");
|
||||
remove(matches.free, ignore, parents, verbose);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn remove(dirs: Vec<String>, ignore: bool, parents: bool, verbose: bool) {
|
||||
|
|
21
seq/seq.rs
21
seq/seq.rs
|
@ -34,9 +34,9 @@ fn escape_sequences(s: &str) -> String {
|
|||
}
|
||||
|
||||
#[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 opts = [
|
||||
getopts::optopt("s", "separator", "Separator character (defaults to \\n)", ""),
|
||||
getopts::optopt("t", "terminator", "Terminator character (defaults to separator)", ""),
|
||||
|
@ -49,26 +49,25 @@ pub fn uumain(args: Vec<String>) {
|
|||
Err(f) => {
|
||||
show_error!(1, "{:s}", f.to_err_msg());
|
||||
print_usage(opts);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
if matches.opt_present("help") {
|
||||
print_usage(opts);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
if matches.opt_present("version") {
|
||||
println!("seq 1.0.0");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
if matches.free.len() < 1 || matches.free.len() > 3 {
|
||||
os::set_exit_status(1);
|
||||
print_usage(opts);
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
let first = if matches.free.len() > 1 {
|
||||
match parse_float(matches.free.get(0).as_slice()) {
|
||||
Ok(n) => n,
|
||||
Err(s) => { show_error!(1, "{:s}", s); return; }
|
||||
Err(s) => { show_error!(1, "{:s}", s); return 0; }
|
||||
}
|
||||
} else {
|
||||
1.0
|
||||
|
@ -76,18 +75,20 @@ pub fn uumain(args: Vec<String>) {
|
|||
let step = if matches.free.len() > 2 {
|
||||
match parse_float(matches.free.get(1).as_slice()) {
|
||||
Ok(n) => n,
|
||||
Err(s) => { show_error!(1, "{:s}", s); return; }
|
||||
Err(s) => { show_error!(1, "{:s}", s); return 0; }
|
||||
}
|
||||
} else {
|
||||
1.0
|
||||
};
|
||||
let last = match parse_float(matches.free.get(matches.free.len()-1).as_slice()) {
|
||||
Ok(n) => n,
|
||||
Err(s) => { show_error!(1, "{:s}", s); return; }
|
||||
Err(s) => { show_error!(1, "{:s}", s); return 0; }
|
||||
};
|
||||
let separator = escape_sequences(matches.opt_str("s").unwrap_or("\n".to_string()).as_slice());
|
||||
let terminator = escape_sequences(matches.opt_str("t").unwrap_or(separator.to_string()).as_slice());
|
||||
print_seq(first, step, last, separator, terminator, matches.opt_present("w"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn done_printing(next: f32, step: f32, last: f32) -> bool {
|
||||
|
|
|
@ -24,9 +24,9 @@ mod util;
|
|||
static NAME: &'static str = "sleep";
|
||||
|
||||
#[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).clone();
|
||||
|
||||
let opts = [
|
||||
|
@ -37,7 +37,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
show_error!(1, "{}", f.to_err_msg());
|
||||
return
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -62,6 +62,8 @@ specified by the sum of their values.", opts).as_slice());
|
|||
} else {
|
||||
sleep(matches.free);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn sleep(args: Vec<String>) {
|
||||
|
|
10
sum/sum.rs
10
sum/sum.rs
|
@ -77,9 +77,9 @@ fn open(name: &str) -> IoResult<Box<Reader>> {
|
|||
}
|
||||
|
||||
#[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("r", "", "use the BSD compatible algorithm (default)"),
|
||||
|
@ -102,11 +102,11 @@ pub fn uumain(args: Vec<String>) {
|
|||
print(getopts::usage("checksum and count the blocks in a file", opts).as_slice());
|
||||
println!("");
|
||||
println!("With no FILE, or when FILE is -, read standard input.");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
if matches.opt_present("version") {
|
||||
println!("{} {}", program, VERSION);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
let sysv = matches.opt_present("sysv");
|
||||
|
@ -128,4 +128,6 @@ pub fn uumain(args: Vec<String>) {
|
|||
};
|
||||
|
||||
println!("{} {}", sum, blocks);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -24,9 +24,9 @@ static NAME: &'static str = "tac";
|
|||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
#[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).clone();
|
||||
|
||||
let opts = [
|
||||
|
@ -69,6 +69,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
};
|
||||
tac(files, before, regex, separator.as_slice());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn tac(filenames: Vec<String>, before: bool, _: bool, separator: &str) {
|
||||
|
|
12
tee/tee.rs
12
tee/tee.rs
|
@ -18,19 +18,19 @@ extern crate getopts;
|
|||
use std::io::{println, stdin, stdout, Append, File, Truncate, Write};
|
||||
use std::io::{IoResult};
|
||||
use std::io::util::{copy, NullWriter, MultiWriter};
|
||||
use std::os::{args, set_exit_status};
|
||||
use std::os;
|
||||
use getopts::{getopts, optflag, usage};
|
||||
|
||||
static NAME: &'static str = "tee";
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn main() { uumain(args()); }
|
||||
fn main() { os::set_exit_status(uumain(os::args())); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) {
|
||||
pub fn uumain(args: Vec<String>) -> int {
|
||||
match options(args.as_slice()).and_then(exec) {
|
||||
Ok(_) => set_exit_status(0),
|
||||
Err(_) => set_exit_status(1)
|
||||
Ok(_) => 0,
|
||||
Err(_) => 1
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,5 +153,5 @@ fn with_path<T>(path: &Path, cb: || -> IoResult<T>) -> IoResult<T> {
|
|||
}
|
||||
|
||||
fn warn(message: &str) {
|
||||
error!("{}: {}", args().get(0), message);
|
||||
error!("{}: {}", os::args().get(0), message);
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ static NAME: &'static str = "touch";
|
|||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
#[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 opts = [
|
||||
getopts::optflag("a", "", "change only the access time"),
|
||||
getopts::optflag("c", "no-create", "do not create any files"),
|
||||
|
@ -49,7 +49,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
|
||||
if matches.opt_present("version") {
|
||||
println!("{:s} {:s}", NAME, VERSION);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("help") || matches.free.is_empty() {
|
||||
|
@ -59,7 +59,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
println!("");
|
||||
println!("{:s}", getopts::usage("Update the access and modification times of \
|
||||
each FILE to the current time.", opts));
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("date") && matches.opts_present(["reference".to_string(), "t".to_string()]) ||
|
||||
|
@ -131,6 +131,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
Err(e) => fail!("Unable to modify times\n{}", e.desc)
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn stat(path: &Path, follow: bool) -> std::io::FileStat {
|
||||
|
|
17
tr/tr.rs
17
tr/tr.rs
|
@ -147,9 +147,9 @@ fn usage(opts: &[OptGroup]) {
|
|||
}
|
||||
|
||||
#[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 opts = [
|
||||
getopts::optflag("c", "complement", "use the complement of SET1"),
|
||||
getopts::optflag("C", "", "same as -c"),
|
||||
|
@ -162,24 +162,23 @@ pub fn uumain(args: Vec<String>) {
|
|||
Ok(m) => m,
|
||||
Err(err) => {
|
||||
show_error!(1, "{}", err.to_err_msg());
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
if matches.opt_present("help") {
|
||||
usage(opts);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("version") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.free.len() == 0 {
|
||||
usage(opts);
|
||||
os::set_exit_status(1);
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
let dflag = matches.opt_present("d");
|
||||
|
@ -188,7 +187,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
|
||||
if cflag && !dflag {
|
||||
show_error!(1, "-c is only supported with -d");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if dflag {
|
||||
|
@ -199,4 +198,6 @@ pub fn uumain(args: Vec<String>) {
|
|||
let set2 = expand_set(sets.get(1).as_slice());
|
||||
tr(set1.as_slice(), set2.as_slice());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -47,9 +47,9 @@ enum TruncateMode {
|
|||
static NAME: &'static str = "truncate";
|
||||
|
||||
#[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).clone();
|
||||
|
||||
let opts = [
|
||||
|
@ -108,6 +108,8 @@ file based on its current size:
|
|||
truncate(no_create, io_blocks, reference, size, matches.free);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn truncate(no_create: bool, _: bool, reference: Option<String>, size: Option<String>, filenames: Vec<String>) {
|
||||
|
|
|
@ -35,9 +35,9 @@ extern {
|
|||
static NAME: &'static str = "tty";
|
||||
|
||||
#[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 options = [
|
||||
optflag("s", "silent", "print nothing, only return an exit status")
|
||||
];
|
||||
|
@ -49,7 +49,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
Err(f) => {
|
||||
println(f.to_err_msg().as_slice());
|
||||
usage();
|
||||
return
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -71,10 +71,9 @@ pub fn uumain(args: Vec<String>) {
|
|||
}
|
||||
};
|
||||
|
||||
os::set_exit_status(exit_code as int);
|
||||
return exit_code as int;
|
||||
}
|
||||
|
||||
fn usage () {
|
||||
safe_writeln!(&mut stderr() as &mut Writer, "usage: tty [-s]");
|
||||
os::set_exit_status(2);
|
||||
}
|
||||
|
|
|
@ -52,9 +52,9 @@ unsafe fn getuname() -> utsrust {
|
|||
static NAME: &'static str = "uname";
|
||||
|
||||
#[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", "display this help and exit"),
|
||||
|
@ -77,7 +77,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
println!(" {:s}", program);
|
||||
println!("");
|
||||
print(getopts::usage("The uname utility writes symbols representing one or more system characteristics to the standard output.", opts).as_slice());
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
let uname = unsafe { getuname() };
|
||||
let mut output = String::new();
|
||||
|
@ -103,5 +103,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
output.push_str(uname.machine.as_slice());
|
||||
output.push_str(" ");
|
||||
}
|
||||
println!("{}", output.as_slice().trim_left())
|
||||
println!("{}", output.as_slice().trim_left());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -27,9 +27,9 @@ mod util;
|
|||
static NAME: &'static str = "unlink";
|
||||
|
||||
#[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).clone();
|
||||
let opts = [
|
||||
getopts::optflag("h", "help", "display this help and exit"),
|
||||
|
@ -50,12 +50,12 @@ pub fn uumain(args: Vec<String>) {
|
|||
println!(" {0:s} [FILE]... [OPTION]...", program);
|
||||
println!("");
|
||||
print(getopts::usage("Unlink the file at [FILE].", opts).as_slice());
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("version") {
|
||||
println!("unlink 1.0.0");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.free.len() == 0 {
|
||||
|
@ -86,4 +86,6 @@ pub fn uumain(args: Vec<String>) {
|
|||
crash!(1, "cannot unlink '{0}': {1}", path.display(), e.desc);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -48,9 +48,9 @@ extern {
|
|||
}
|
||||
|
||||
#[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).clone();
|
||||
let opts = [
|
||||
getopts::optflag("v", "version", "output version information and exit"),
|
||||
|
@ -62,7 +62,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
};
|
||||
if matches.opt_present("version") {
|
||||
println!("uptime 1.0.0");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
if matches.opt_present("help") || matches.free.len() > 0 {
|
||||
println!("Usage:");
|
||||
|
@ -71,7 +71,7 @@ pub fn uumain(args: Vec<String>) {
|
|||
print(getopts::usage("Print the current time, the length of time the system has been up,\n\
|
||||
the number of users on the system, and the average number of jobs\n\
|
||||
in the run queue over the last 1, 5 and 15 minutes.", opts).as_slice());
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
print_time();
|
||||
|
@ -80,6 +80,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
print_uptime(upsecs);
|
||||
print_nusers(user_count);
|
||||
print_loadavg();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn print_loadavg() {
|
||||
|
|
|
@ -48,9 +48,9 @@ extern {
|
|||
static NAME: &'static str = "users";
|
||||
|
||||
#[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", "display this help and exit"),
|
||||
|
@ -69,12 +69,12 @@ pub fn uumain(args: Vec<String>) {
|
|||
println!(" {:s} [OPTION]... [FILE]", program);
|
||||
println!("");
|
||||
print(getopts::usage("Output who is currently logged in according to FILE.", opts).as_slice());
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("version") {
|
||||
println!("users 1.0.0");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
let mut filename = DEFAULT_FILE;
|
||||
|
@ -83,6 +83,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
}
|
||||
|
||||
exec(filename);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn exec(filename: &str) {
|
||||
|
|
|
@ -58,9 +58,9 @@ use std::collections::hashmap::HashMap;
|
|||
static NAME: &'static str = "uutils";
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
fn util_map() -> HashMap<&str, fn(Vec<String>)> {
|
||||
fn uutrue(_: Vec<String>) { os::set_exit_status(0); }
|
||||
fn uufalse(_: Vec<String>) { os::set_exit_status(1); }
|
||||
fn util_map() -> HashMap<&str, fn(Vec<String>) -> int> {
|
||||
fn uutrue(_: Vec<String>) -> int { 0 }
|
||||
fn uufalse(_: Vec<String>) -> int { 1 }
|
||||
|
||||
let mut map = HashMap::new();
|
||||
map.insert("base64", base64::uumain);
|
||||
|
@ -108,7 +108,7 @@ fn util_map() -> HashMap<&str, fn(Vec<String>)> {
|
|||
map
|
||||
}
|
||||
|
||||
fn usage(cmap: &HashMap<&str, fn(Vec<String>)>) {
|
||||
fn usage(cmap: &HashMap<&str, fn(Vec<String>) -> int>) {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
println!("");
|
||||
println!("Usage:");
|
||||
|
@ -131,7 +131,7 @@ fn main() {
|
|||
let binary_as_util = binary.filename_str().unwrap();
|
||||
if umap.contains_key(&binary_as_util) {
|
||||
let &uumain = umap.get(&binary_as_util);
|
||||
uumain(args);
|
||||
os::set_exit_status(uumain(args));
|
||||
return
|
||||
} else if binary_as_util.starts_with("uutils")
|
||||
|| binary_as_util.starts_with("busybox") {
|
||||
|
@ -150,7 +150,7 @@ fn main() {
|
|||
let util = args.get(0).as_slice();
|
||||
if umap.contains_key(&util) {
|
||||
let &uumain = umap.get(&util);
|
||||
uumain(args.clone());
|
||||
os::set_exit_status(uumain(args.clone()));
|
||||
return
|
||||
} else if args.get(0).as_slice() == "--help" {
|
||||
// see if they want help on a specific util
|
||||
|
@ -158,7 +158,7 @@ fn main() {
|
|||
let util = args.get(1).as_slice();
|
||||
if umap.contains_key(&util) {
|
||||
let &uumain = umap.get(&util);
|
||||
uumain(vec!["--help".to_string()]);
|
||||
os::set_exit_status(uumain(vec!["--help".to_string()]));
|
||||
return
|
||||
} else {
|
||||
println!("{}: applet not found", util);
|
||||
|
@ -167,6 +167,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
usage(&umap);
|
||||
os::set_exit_status(0);
|
||||
return
|
||||
} else {
|
||||
println!("{}: applet not found", util);
|
||||
|
@ -176,6 +177,7 @@ fn main() {
|
|||
} else {
|
||||
// no arguments provided
|
||||
usage(&umap);
|
||||
os::set_exit_status(0);
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
10
wc/wc.rs
10
wc/wc.rs
|
@ -34,9 +34,9 @@ struct Result {
|
|||
static NAME: &'static str = "wc";
|
||||
|
||||
#[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).clone();
|
||||
let opts = [
|
||||
getopts::optflag("c", "bytes", "print the byte counts"),
|
||||
|
@ -62,12 +62,12 @@ pub fn uumain(args: Vec<String>) {
|
|||
print(getopts::usage("Print newline, word and byte counts for each FILE", opts).as_slice());
|
||||
println!("");
|
||||
println!("With no FILE, or when FILE is -, read standard input.");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("version") {
|
||||
println!("wc 1.0.0");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
let mut files = matches.free.clone();
|
||||
|
@ -76,6 +76,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
}
|
||||
|
||||
wc(files, &matches);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static CR: u8 = '\r' as u8;
|
||||
|
|
|
@ -42,9 +42,9 @@ unsafe fn getusername() -> String {
|
|||
static NAME: &'static str = "whoami";
|
||||
|
||||
#[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", "display this help and exit"),
|
||||
|
@ -61,14 +61,16 @@ pub fn uumain(args: Vec<String>) {
|
|||
println!(" {:s}", program);
|
||||
println!("");
|
||||
print(getopts::usage("print effective userid", opts).as_slice());
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
if matches.opt_present("version") {
|
||||
println!("whoami 1.0.0");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
exec();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pub fn exec() {
|
||||
|
|
10
yes/yes.rs
10
yes/yes.rs
|
@ -25,9 +25,9 @@ mod util;
|
|||
static NAME: &'static str = "yes";
|
||||
|
||||
#[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).clone();
|
||||
let opts = [
|
||||
getopts::optflag("h", "help", "display this help and exit"),
|
||||
|
@ -46,11 +46,11 @@ pub fn uumain(args: Vec<String>) {
|
|||
println!(" {0:s} [STRING]... [OPTION]...", program);
|
||||
println!("");
|
||||
print(getopts::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", opts).as_slice());
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
if matches.opt_present("version") {
|
||||
println!("yes 1.0.0");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
let mut string = "y".to_string();
|
||||
if !matches.free.is_empty() {
|
||||
|
@ -58,6 +58,8 @@ pub fn uumain(args: Vec<String>) {
|
|||
}
|
||||
|
||||
exec(string.as_slice());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pub fn exec(string: &str) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue