mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
Merge pull request #212 from brson/exitcodes
Change the signature of `uumain` to return `int`
This commit is contained in:
@@ -145,6 +145,11 @@ build/busybox: build/uutils
|
||||
rm -f build/busybox
|
||||
ln -s $(SRC_DIR)/build/uutils build/busybox
|
||||
|
||||
# This is a busybox-specific config file their test suite wants to parse.
|
||||
# For now it's blank.
|
||||
build/.config: build/uutils
|
||||
touch $@
|
||||
|
||||
ifeq ($(BUSYBOX_SRC),)
|
||||
busytest:
|
||||
@echo
|
||||
@@ -153,7 +158,7 @@ busytest:
|
||||
@echo
|
||||
@false
|
||||
else
|
||||
busytest: build/busybox
|
||||
busytest: build/busybox build/.config
|
||||
(cd $(BUSYBOX_SRC)/testsuite && bindir=$(SRC_DIR)/build tstdir=$(BUSYBOX_SRC)/testsuite $(BUSYBOX_SRC)/testsuite/runtest $(RUNTEST_ARGS))
|
||||
endif
|
||||
endif
|
||||
|
||||
+5
-3
@@ -15,7 +15,7 @@
|
||||
extern crate serialize;
|
||||
extern crate getopts;
|
||||
extern crate libc;
|
||||
#[phase(syntax, link)] extern crate log;
|
||||
#[phase(plugin, link)] extern crate log;
|
||||
|
||||
use std::io::{println, File, stdin, stdout};
|
||||
use std::os;
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
+10
-8
@@ -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());
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
fn strip_dir(fullname: &str) -> String {
|
||||
@@ -97,7 +99,7 @@ fn strip_dir(fullname: &str) -> String {
|
||||
name.push_char(c);
|
||||
}
|
||||
|
||||
return name.as_slice().chars().rev().collect();
|
||||
name.as_slice().chars().rev().collect()
|
||||
}
|
||||
|
||||
fn strip_suffix(name: &str, suffix: &str) -> String {
|
||||
@@ -109,5 +111,5 @@ fn strip_suffix(name: &str, suffix: &str) -> String {
|
||||
return name.slice_to(name.len() - suffix.len()).into_string();
|
||||
}
|
||||
|
||||
return name.into_string();
|
||||
name.into_string()
|
||||
}
|
||||
|
||||
+9
-7
@@ -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);
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
#[deriving(Eq, PartialEq)]
|
||||
@@ -283,12 +285,12 @@ fn open(path: &str) -> Option<(Box<Reader>, bool)> {
|
||||
}
|
||||
|
||||
match File::open(&std::path::Path::new(path)) {
|
||||
Ok(f) => return Some((box f as Box<Reader>, false)),
|
||||
Ok(f) => Some((box f as Box<Reader>, false)),
|
||||
Err(e) => {
|
||||
(writeln!(stderr(), "cat: {0:s}: {1:s}", path, e.to_str())).unwrap();
|
||||
return None;
|
||||
None
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
struct UnsafeWriter<'a, W> {
|
||||
|
||||
+16
-7
@@ -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;
|
||||
@@ -111,15 +111,24 @@ pub fn uumain(args: Vec<String>) {
|
||||
if files.is_empty() {
|
||||
match cksum("-") {
|
||||
Ok((crc, size)) => println!("{} {}", crc, size),
|
||||
Err(err) => show_error!(2, "{}", err),
|
||||
Err(err) => {
|
||||
show_error!("{}", err);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return
|
||||
return 0;
|
||||
}
|
||||
|
||||
let mut exit_code = 0;
|
||||
for fname in files.iter() {
|
||||
match cksum(fname.as_slice()) {
|
||||
Ok((crc, size)) => println!("{} {} {}", crc, size, fname),
|
||||
Err(err) => show_error!(2, "'{}' {}", fname, err),
|
||||
Err(err) => {
|
||||
show_error!("'{}' {}", fname, err);
|
||||
exit_code = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit_code
|
||||
}
|
||||
|
||||
+8
-6
@@ -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);
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
+3
-3
@@ -13,8 +13,7 @@ extern crate libc;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! show_error(
|
||||
($exitcode:expr, $($args:expr),+) => ({
|
||||
::std::os::set_exit_status($exitcode as int);
|
||||
($($args:expr),+) => ({
|
||||
safe_write!(&mut ::std::io::stderr(), "{}: error: ", ::NAME);
|
||||
safe_writeln!(&mut ::std::io::stderr(), $($args),+);
|
||||
})
|
||||
@@ -31,7 +30,8 @@ macro_rules! show_warning(
|
||||
#[macro_export]
|
||||
macro_rules! crash(
|
||||
($exitcode:expr, $($args:expr),+) => ({
|
||||
show_error!($exitcode, $($args),+);
|
||||
safe_write!(&mut ::std::io::stderr(), "{}: error: ", ::NAME);
|
||||
safe_writeln!(&mut ::std::io::stderr(), $($args),+);
|
||||
unsafe { self::libc::exit($exitcode as self::libc::c_int); }
|
||||
})
|
||||
)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
extern crate getopts;
|
||||
#[phase(syntax, link)] extern crate log;
|
||||
#[phase(plugin, link)] extern crate log;
|
||||
|
||||
use std::os;
|
||||
use std::io;
|
||||
@@ -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(),
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
fn version() {
|
||||
|
||||
+7
-4
@@ -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);
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
@@ -14,15 +14,14 @@
|
||||
|
||||
extern crate getopts;
|
||||
extern crate libc;
|
||||
extern crate sync;
|
||||
extern crate time;
|
||||
|
||||
use std::os;
|
||||
use std::io::{stderr, fs, FileStat, TypeDirectory};
|
||||
use std::option::Option;
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Future};
|
||||
use time::Timespec;
|
||||
use sync::{Arc, Future};
|
||||
|
||||
#[path = "../common/util.rs"]
|
||||
mod util;
|
||||
@@ -87,13 +86,13 @@ fn du(path: &Path, mut my_stat: Stat,
|
||||
|
||||
stats.push(Arc::new(my_stat));
|
||||
|
||||
return stats;
|
||||
stats
|
||||
}
|
||||
|
||||
#[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,8 +162,8 @@ pub fn uumain(args: Vec<String>) {
|
||||
let matches = match getopts::getopts(args.tail(), opts) {
|
||||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
show_error!(1, "Invalid options\n{}", f.to_err_msg());
|
||||
return
|
||||
show_error!("Invalid options\n{}", f.to_err_msg());
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -188,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");
|
||||
@@ -201,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 */ }
|
||||
}
|
||||
@@ -240,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);
|
||||
@@ -262,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
|
||||
@@ -301,7 +300,7 @@ Valid arguments are:
|
||||
- 'long-iso'
|
||||
- 'iso'
|
||||
Try '{program} --help' for more information.", s, program = program);
|
||||
return
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -340,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
|
||||
@@ -367,4 +366,6 @@ Try '{program} --help' for more information.", s, program = program);
|
||||
print!("{:<10} total", convert_size(grand_total));
|
||||
print!("{}", line_separator);
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
+9
-5
@@ -66,13 +66,14 @@ fn convert_str(string: &str, index: uint, base: uint) -> (char, int) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return (to_char(&bytes, base), max_digits)
|
||||
|
||||
(to_char(&bytes, base), max_digits)
|
||||
}
|
||||
|
||||
#[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 +110,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 +187,6 @@ pub fn uumain(args: Vec<String>) {
|
||||
if !matches.opt_present("n") {
|
||||
println!("")
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
Vendored
+13
-11
@@ -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);
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
+4
-2
@@ -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);
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
|
||||
|
||||
+6
-4
@@ -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")
|
||||
];
|
||||
@@ -36,10 +36,12 @@ pub fn uumain(args: Vec<String>) {
|
||||
let matches = match getopts(args.tail(), options) {
|
||||
Ok(m) => { m },
|
||||
Err(_) => {
|
||||
show_error!(1, "{}", usage(NAME, options));
|
||||
return;
|
||||
show_error!("{}", usage(NAME, options));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
group(get_pw_from_args(&matches.free), true);
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
+7
-5
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
// It searches for an option in the form of -123123
|
||||
|
||||
+8
-6
@@ -18,7 +18,7 @@ extern crate serialize;
|
||||
extern crate libc;
|
||||
|
||||
|
||||
#[phase(syntax, link)] extern crate log;
|
||||
#[phase(plugin, link)] extern crate log;
|
||||
|
||||
use std::os;
|
||||
|
||||
@@ -36,7 +36,7 @@ mod util;
|
||||
static NAME: &'static str = "hostid";
|
||||
static VERSION: &'static str = "0.0.1";
|
||||
|
||||
static EXIT_ERR: i32 = 1;
|
||||
static EXIT_ERR: int = 1;
|
||||
|
||||
pub enum Mode {
|
||||
HostId,
|
||||
@@ -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"),
|
||||
@@ -65,8 +65,8 @@ pub fn uumain(args: Vec<String>) {
|
||||
let matches = match getopts(args.tail(), opts) {
|
||||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
show_error!(EXIT_ERR, "{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice()));
|
||||
return
|
||||
show_error!("{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice()));
|
||||
return EXIT_ERR;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -83,6 +83,8 @@ pub fn uumain(args: Vec<String>) {
|
||||
Help => help(NAME, usage.as_slice()),
|
||||
Version => version(),
|
||||
}
|
||||
|
||||
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); }
|
||||
};
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
fn version() {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
fn pretty(possible_pw: Option<c_passwd>) {
|
||||
|
||||
+12
-10
@@ -17,7 +17,7 @@ extern crate libc;
|
||||
extern crate collections;
|
||||
extern crate serialize;
|
||||
|
||||
#[phase(syntax, link)] extern crate log;
|
||||
#[phase(plugin, link)] extern crate log;
|
||||
|
||||
use std::os;
|
||||
use std::from_str::from_str;
|
||||
@@ -41,8 +41,8 @@ mod util;
|
||||
static NAME: &'static str = "kill";
|
||||
static VERSION: &'static str = "0.0.1";
|
||||
|
||||
static EXIT_OK: i32 = 0;
|
||||
static EXIT_ERR: i32 = 1;
|
||||
static EXIT_OK: int = 0;
|
||||
static EXIT_ERR: int = 1;
|
||||
|
||||
pub enum Mode {
|
||||
Kill,
|
||||
@@ -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"),
|
||||
@@ -71,8 +71,8 @@ pub fn uumain(args: Vec<String>) {
|
||||
let matches = match getopts(args.tail(), opts) {
|
||||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
show_error!(EXIT_ERR, "{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice()));
|
||||
return
|
||||
show_error!("{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice()));
|
||||
return EXIT_ERR;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -96,6 +96,8 @@ pub fn uumain(args: Vec<String>) {
|
||||
Help => help(NAME, usage.as_slice()),
|
||||
Version => version(),
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
fn version() {
|
||||
@@ -126,10 +128,10 @@ fn print_signal(signal_name_or_value: &str) {
|
||||
for signal in ALL_SIGNALS.iter() {
|
||||
if signal.name == signal_name_or_value || (format!("SIG{}", signal.name).as_slice()) == signal_name_or_value {
|
||||
println!("{}", signal.value)
|
||||
exit!(EXIT_OK)
|
||||
exit!(EXIT_OK as i32)
|
||||
} else if signal_name_or_value == signal.value.to_str().as_slice() {
|
||||
println!("{}", signal.name);
|
||||
exit!(EXIT_OK)
|
||||
exit!(EXIT_OK as i32)
|
||||
}
|
||||
}
|
||||
crash!(EXIT_ERR, "unknown signal name {}", signal_name_or_value)
|
||||
@@ -175,7 +177,7 @@ fn signal_by_name_or_value(signal_name_or_value: &str) -> Option<uint> {
|
||||
return Some(signal.value);
|
||||
}
|
||||
}
|
||||
return None;
|
||||
None
|
||||
}
|
||||
|
||||
fn kill(signalname: &str, pids: std::vec::Vec<String>) {
|
||||
|
||||
+6
-4
@@ -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();
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
fn exec() {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user