mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Switch to external getopts cargo (part 1).
I switched over to the getopts crate on crates.io, instead of Rust's private implementation. This will allow coreutils to build for Rust 1.0. I'm splitting the updates into several commits for better reviewing.
This commit is contained in:
parent
d6837c8709
commit
b4b08de42c
33 changed files with 611 additions and 698 deletions
3
Makefile
3
Makefile
|
@ -196,7 +196,8 @@ define DEP_INCLUDE
|
||||||
-include $(SRCDIR)/$(1)/deps.mk
|
-include $(SRCDIR)/$(1)/deps.mk
|
||||||
endef
|
endef
|
||||||
# we always depend on libc because common/util does
|
# we always depend on libc because common/util does
|
||||||
DEPLIBS := libc
|
# we also depend on getopts since all utilities support command-line arguments
|
||||||
|
DEPLIBS := libc getopts
|
||||||
DEPPLUGS :=
|
DEPPLUGS :=
|
||||||
# now, add in deps in src/utilname/deps.mk
|
# now, add in deps in src/utilname/deps.mk
|
||||||
# if we're testing, only consider the TESTS variable,
|
# if we're testing, only consider the TESTS variable,
|
||||||
|
|
1
deps/Cargo.toml
vendored
1
deps/Cargo.toml
vendored
|
@ -7,6 +7,7 @@ name = "null"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.1.7"
|
libc = "0.1.7"
|
||||||
|
getopts = "0.2.11"
|
||||||
num_cpus = "*"
|
num_cpus = "*"
|
||||||
rand = "0.3.8"
|
rand = "0.3.8"
|
||||||
regex = "0.1.30"
|
regex = "0.1.30"
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "base64"]
|
#![crate_name = "base64"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -13,50 +12,43 @@
|
||||||
extern crate rustc_serialize as serialize;
|
extern crate rustc_serialize as serialize;
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
#[macro_use] extern crate log;
|
|
||||||
|
|
||||||
|
use getopts::Options;
|
||||||
|
use serialize::base64::{self, FromBase64, ToBase64};
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufReader, Read, stdin, stdout, Write};
|
use std::io::{BufReader, Read, stdin, stdout, Write};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use getopts::{
|
|
||||||
getopts,
|
|
||||||
optflag,
|
|
||||||
optopt,
|
|
||||||
usage
|
|
||||||
};
|
|
||||||
use serialize::base64;
|
|
||||||
use serialize::base64::{FromBase64, ToBase64};
|
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
|
enum Mode {
|
||||||
|
Decode,
|
||||||
|
Encode,
|
||||||
|
Help,
|
||||||
|
Version
|
||||||
|
}
|
||||||
|
|
||||||
static NAME: &'static str = "base64";
|
static NAME: &'static str = "base64";
|
||||||
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
pub type FileOrStdReader = BufReader<Box<Read+'static>>;
|
pub type FileOrStdReader = BufReader<Box<Read+'static>>;
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let opts = [
|
let mut opts = Options::new();
|
||||||
optflag("d", "decode", "decode data"),
|
opts.optflag("d", "decode", "decode data");
|
||||||
optflag("i", "ignore-garbage", "when decoding, ignore non-alphabetic characters"),
|
opts.optflag("i", "ignore-garbage", "when decoding, ignore non-alphabetic characters");
|
||||||
optopt("w", "wrap",
|
opts.optopt("w", "wrap", "wrap encoded lines after COLS character (default 76, 0 to disable wrapping)", "COLS");
|
||||||
"wrap encoded lines after COLS character (default 76, 0 to disable wrapping)", "COLS"
|
opts.optflag("h", "help", "display this help text and exit");
|
||||||
),
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
optflag("h", "help", "display this help text and exit"),
|
let matches = match opts.parse(&args[1..]) {
|
||||||
optflag("V", "version", "output version information and exit")
|
|
||||||
];
|
|
||||||
let matches = match getopts(&args[1..], &opts) {
|
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(e) => {
|
Err(e) => { crash!(1, "error: {}", e) }
|
||||||
crash!(1, "error: {}", e);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let progname = args[0].clone();
|
|
||||||
let usage = usage("Base64 encode or decode FILE, or standard input, to standard output.", &opts);
|
|
||||||
let mode = if matches.opt_present("help") {
|
let mode = if matches.opt_present("help") {
|
||||||
Mode::Help
|
Mode::Help
|
||||||
} else if matches.opt_present("version") {
|
} else if matches.opt_present("version") {
|
||||||
|
@ -90,7 +82,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
match mode {
|
match mode {
|
||||||
Mode::Decode => decode(&mut input, ignore_garbage),
|
Mode::Decode => decode(&mut input, ignore_garbage),
|
||||||
Mode::Encode => encode(&mut input, line_wrap),
|
Mode::Encode => encode(&mut input, line_wrap),
|
||||||
Mode::Help => help(&progname[..], &usage[..]),
|
Mode::Help => help(opts),
|
||||||
Mode::Version => version()
|
Mode::Version => version()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,28 +144,19 @@ fn encode(input: &mut FileOrStdReader, line_wrap: usize) {
|
||||||
println!("{}", &encoded[..]);
|
println!("{}", &encoded[..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn help(progname: &str, usage: &str) {
|
fn help(opts: Options) {
|
||||||
println!("Usage: {} [OPTION]... [FILE]", progname);
|
let msg = format!("Usage: {} [OPTION]... [FILE]\n\n\
|
||||||
println!("");
|
Base64 encode or decode FILE, or standard input, to standard output.\n\
|
||||||
println!("{}", usage);
|
With no FILE, or when FILE is -, read standard input.\n\n\
|
||||||
|
The data are encoded as described for the base64 alphabet in RFC \
|
||||||
|
3548. When\ndecoding, the input may contain newlines in addition \
|
||||||
|
to the bytes of the formal\nbase64 alphabet. Use --ignore-garbage \
|
||||||
|
to attempt to recover from any other\nnon-alphabet bytes in the \
|
||||||
|
encoded stream.", NAME);
|
||||||
|
|
||||||
let msg = "With no FILE, or when FILE is -, read standard input.\n\n\
|
print!("{}", opts.usage(&msg));
|
||||||
The data are encoded as described for the base64 alphabet in RFC \
|
|
||||||
3548. When\ndecoding, the input may contain newlines in addition \
|
|
||||||
to the bytes of the formal\nbase64 alphabet. Use --ignore-garbage \
|
|
||||||
to attempt to recover from any other\nnon-alphabet bytes in the \
|
|
||||||
encoded stream.";
|
|
||||||
|
|
||||||
println!("{}", msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn version() {
|
fn version() {
|
||||||
println!("base64 1.0.0");
|
println!("{} {}", NAME, VERSION);
|
||||||
}
|
|
||||||
|
|
||||||
enum Mode {
|
|
||||||
Decode,
|
|
||||||
Encode,
|
|
||||||
Help,
|
|
||||||
Version
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "basename"]
|
#![crate_name = "basename"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -13,6 +12,7 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
|
use getopts::Options;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::{is_separator, PathBuf};
|
use std::path::{is_separator, PathBuf};
|
||||||
|
|
||||||
|
@ -24,47 +24,43 @@ static NAME: &'static str = "basename";
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let program = strip_dir(&args[0]);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Argument parsing
|
// Argument parsing
|
||||||
//
|
//
|
||||||
let opts = [
|
let mut opts = Options::new();
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
getopts::optflag("V", "version", "output version information and exit"),
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
];
|
|
||||||
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => crash!(1, "Invalid options\n{}", f)
|
Err(f) => crash!(1, "Invalid options\n{}", f)
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
println!("Usage: {0} NAME [SUFFIX]", program);
|
let msg = format!("Usage: {0} NAME [SUFFIX]\n or: {0} OPTION\n\n\
|
||||||
println!(" or: {0} OPTION", program);
|
Print NAME with any leading directory components removed.\n\
|
||||||
println!("Print NAME with any leading directory components removed.");
|
If specified, also remove a trailing SUFFIX.", NAME);
|
||||||
println!("If specified, also remove a trailing SUFFIX.");
|
|
||||||
|
|
||||||
print!("{}", getopts::usage("", &opts));
|
print!("{}", opts.usage(&msg));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
println!("{} {}", program, VERSION);
|
println!("{} {}", NAME, VERSION);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// too few arguments
|
// too few arguments
|
||||||
if args.len() < 2 {
|
if args.len() < 2 {
|
||||||
println!("{}: {}", program, "missing operand");
|
println!("{}: {}", NAME, "missing operand");
|
||||||
println!("Try '{} --help' for more information.", program);
|
println!("Try '{} --help' for more information.", NAME);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// too many arguments
|
// too many arguments
|
||||||
else if args.len() > 3 {
|
else if args.len() > 3 {
|
||||||
println!("{}: extra operand '{}'", program, args[3]);
|
println!("{}: extra operand '{}'", NAME, args[3]);
|
||||||
println!("Try '{} --help' for more information.", program);
|
println!("Try '{} --help' for more information.", NAME);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "cat"]
|
#![crate_name = "cat"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -15,49 +14,47 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
|
use getopts::Options;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{stdout, stdin, stderr, Write, Read};
|
|
||||||
use std::io::Result;
|
|
||||||
use std::intrinsics::{copy_nonoverlapping};
|
use std::intrinsics::{copy_nonoverlapping};
|
||||||
|
use std::io::{stdout, stdin, stderr, Write, Read, Result};
|
||||||
use libc::consts::os::posix88::STDIN_FILENO;
|
use libc::consts::os::posix88::STDIN_FILENO;
|
||||||
use libc::funcs::posix88::unistd::isatty;
|
use libc::funcs::posix88::unistd::isatty;
|
||||||
use libc::types::os::arch::c95::c_int;
|
use libc::types::os::arch::c95::c_int;
|
||||||
|
|
||||||
|
static NAME: &'static str = "cat";
|
||||||
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let program = &args[0];
|
let mut opts = Options::new();
|
||||||
let opts = [
|
opts.optflag("A", "show-all", "equivalent to -vET");
|
||||||
getopts::optflag("A", "show-all", "equivalent to -vET"),
|
opts.optflag("b", "number-nonblank",
|
||||||
getopts::optflag("b", "number-nonblank",
|
"number nonempty output lines, overrides -n");
|
||||||
"number nonempty output lines, overrides -n"),
|
opts.optflag("e", "", "equivalent to -vE");
|
||||||
getopts::optflag("e", "", "equivalent to -vE"),
|
opts.optflag("E", "show-ends", "display $ at end of each line");
|
||||||
getopts::optflag("E", "show-ends", "display $ at end of each line"),
|
opts.optflag("n", "number", "number all output lines");
|
||||||
getopts::optflag("n", "number", "number all output lines"),
|
opts.optflag("s", "squeeze-blank", "suppress repeated empty output lines");
|
||||||
getopts::optflag("s", "squeeze-blank", "suppress repeated empty output lines"),
|
opts.optflag("t", "", "equivalent to -vT");
|
||||||
getopts::optflag("t", "", "equivalent to -vT"),
|
opts.optflag("T", "show-tabs", "display TAB characters as ^I");
|
||||||
getopts::optflag("T", "show-tabs", "display TAB characters as ^I"),
|
opts.optflag("v", "show-nonprinting",
|
||||||
getopts::optflag("v", "show-nonprinting",
|
"use ^ and M- notation, except for LF (\\n) and TAB (\\t)");
|
||||||
"use ^ and M- notation, except for LF (\\n) and TAB (\\t)"),
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
getopts::optflag("V", "version", "output version information and exit"),
|
let matches = match opts.parse(&args[1..]) {
|
||||||
];
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => panic!("Invalid options\n{}", f)
|
Err(f) => panic!("Invalid options\n{}", f)
|
||||||
};
|
};
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
println!("cat 1.0.0");
|
let msg = format!("{} {}\n\n\
|
||||||
println!("");
|
Usage:\n {0} [OPTION]... [FILE]...\n\n\
|
||||||
println!("Usage:");
|
Concatenate FILE(s), or standard input, to standard output.\n\n\
|
||||||
println!(" {0} [OPTION]... [FILE]...", program);
|
With no FILE, or when FILE is -, read standard input.", NAME, VERSION);
|
||||||
println!("");
|
|
||||||
print!("{}", &getopts::usage("Concatenate FILE(s), or standard input, to \
|
print!("{}", opts.usage(&msg));
|
||||||
standard output.", &opts)[..]);
|
|
||||||
println!("");
|
|
||||||
println!("With no FILE, or when FILE is -, read standard input.");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
println!("cat 1.0.0");
|
println!("{} {}", NAME, VERSION);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "chmod"]
|
#![crate_name = "chmod"]
|
||||||
#![feature(fs_walk, path_ext, rustc_private)]
|
#![feature(fs_walk, path_ext)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -16,12 +16,13 @@ extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
||||||
|
use getopts::Options;
|
||||||
|
use regex::Regex;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::fs::{self, PathExt};
|
use std::fs::{self, PathExt};
|
||||||
use std::path::Path;
|
|
||||||
use std::io::{Error, Write};
|
use std::io::{Error, Write};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use regex::Regex;
|
use std::path::Path;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -31,45 +32,41 @@ const NAME: &'static str = "chmod";
|
||||||
const VERSION: &'static str = "1.0.0";
|
const VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let program = args[0].clone();
|
let mut opts = Options::new();
|
||||||
|
opts.optflag("c", "changes", "like verbose but report only when a change is made (unimplemented)");
|
||||||
let opts = [
|
opts.optflag("f", "quiet", "suppress most error messages (unimplemented)"); // TODO: support --silent
|
||||||
getopts::optflag("c", "changes", "like verbose but report only when a change is made (unimplemented)"),
|
opts.optflag("v", "verbose", "output a diagnostic for every file processed (unimplemented)");
|
||||||
getopts::optflag("f", "quiet", "suppress most error messages (unimplemented)"), // TODO: support --silent
|
opts.optflag("", "no-preserve-root", "do not treat '/' specially (the default)");
|
||||||
getopts::optflag("v", "verbose", "output a diagnostic for every file processed (unimplemented)"),
|
opts.optflag("", "preserve-root", "fail to operate recursively on '/'");
|
||||||
getopts::optflag("", "no-preserve-root", "do not treat '/' specially (the default)"),
|
opts.optflagopt("", "reference", "use RFILE's mode instead of MODE values", "RFILE");
|
||||||
getopts::optflag("", "preserve-root", "fail to operate recursively on '/'"),
|
opts.optflag("R", "recursive", "change files and directories recursively");
|
||||||
getopts::optflagopt("", "reference", "use RFILE's mode instead of MODE values", "RFILE"),
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
getopts::optflag("R", "recursive", "change files and directories recursively"),
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
|
||||||
getopts::optflag("V", "version", "output version information and exit")
|
|
||||||
];
|
|
||||||
// TODO: sanitize input for - at beginning (e.g. chmod -x testfile). Solution is to add a to -x, making a-x
|
// TODO: sanitize input for - at beginning (e.g. chmod -x testfile). Solution is to add a to -x, making a-x
|
||||||
let mut matches = match getopts::getopts(&args[1..], &opts) {
|
let mut matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => { crash!(1, "{}", f) }
|
||||||
crash!(1, "{}", f)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
println!("{name} v{version}
|
let msg = format!("{name} v{version}
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
{program} [OPTION]... MODE[,MODE]... FILE...
|
{program} [OPTION]... MODE[,MODE]... FILE...
|
||||||
{program} [OPTION]... OCTAL-MODE FILE...
|
{program} [OPTION]... OCTAL-MODE FILE...
|
||||||
{program} [OPTION]... --reference=RFILE FILE...
|
{program} [OPTION]... --reference=RFILE FILE...
|
||||||
|
|
||||||
{usage}
|
Change the mode of each FILE to MODE.
|
||||||
|
With --reference, change the mode of each FILE to that of RFILE.
|
||||||
Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.",
|
Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.",
|
||||||
name = NAME, version = VERSION, program = program,
|
name = NAME, version = VERSION, program = NAME);
|
||||||
usage = getopts::usage("Change the mode of each FILE to MODE. \
|
|
||||||
\nWith --reference, change the mode of \
|
print!("{}", opts.usage(&msg));
|
||||||
each FILE to that of RFILE.", &opts));
|
return 0;
|
||||||
} else if matches.opt_present("version") {
|
} else if matches.opt_present("version") {
|
||||||
println!("{} v{}", NAME, VERSION);
|
println!("{} v{}", NAME, VERSION);
|
||||||
} else if matches.free.is_empty() && matches.opt_present("reference") || matches.free.len() < 2 {
|
} else if matches.free.is_empty() && matches.opt_present("reference") || matches.free.len() < 2 {
|
||||||
show_error!("missing an argument");
|
show_error!("missing an argument");
|
||||||
show_error!("for help, try '{} --help'", program);
|
show_error!("for help, try '{} --help'", NAME);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
let changes = matches.opt_present("changes");
|
let changes = matches.opt_present("changes");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "chroot"]
|
#![crate_name = "chroot"]
|
||||||
#![feature(rustc_private, path_ext)]
|
#![feature(path_ext)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -13,10 +13,10 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use getopts::{optflag, optopt, getopts, usage};
|
|
||||||
use c_types::{get_pw_from_args, get_group};
|
use c_types::{get_pw_from_args, get_group};
|
||||||
|
use getopts::Options;
|
||||||
use libc::funcs::posix88::unistd::{setgid, setuid};
|
use libc::funcs::posix88::unistd::{setgid, setuid};
|
||||||
use std::ffi::{CString};
|
use std::ffi::CString;
|
||||||
use std::fs::PathExt;
|
use std::fs::PathExt;
|
||||||
use std::io::{Error, Write};
|
use std::io::{Error, Write};
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
|
@ -44,34 +44,32 @@ static NAME: &'static str = "chroot";
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let program = &args[0];
|
let mut opts = Options::new();
|
||||||
|
|
||||||
let options = [
|
opts.optopt("u", "user", "User (ID or name) to switch before running the program", "USER");
|
||||||
optopt("u", "user", "User (ID or name) to switch before running the program", "USER"),
|
opts.optopt("g", "group", "Group (ID or name) to switch to", "GROUP");
|
||||||
optopt("g", "group", "Group (ID or name) to switch to", "GROUP"),
|
opts.optopt("G", "groups", "Comma-separated list of groups to switch to", "GROUP1,GROUP2…");
|
||||||
optopt("G", "groups", "Comma-separated list of groups to switch to", "GROUP1,GROUP2…"),
|
opts.optopt("", "userspec", "Colon-separated user and group to switch to. \
|
||||||
optopt("", "userspec", "Colon-separated user and group to switch to. \
|
Same as -u USER -g GROUP. \
|
||||||
Same as -u USER -g GROUP. \
|
Userspec has higher preference than -u and/or -g", "USER:GROUP");
|
||||||
Userspec has higher preference than -u and/or -g", "USER:GROUP"),
|
opts.optflag("h", "help", "Show help");
|
||||||
optflag("h", "help", "Show help"),
|
opts.optflag("V", "version", "Show program's version");
|
||||||
optflag("V", "version", "Show program's version")
|
|
||||||
];
|
|
||||||
|
|
||||||
let opts = match getopts(&args[1..], &options) {
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
show_error!("{}", f);
|
show_error!("{}", f);
|
||||||
help_menu(program, &options);
|
help_menu(opts);
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if opts.opt_present("V") { version(); return 0 }
|
if matches.opt_present("V") { version(); return 0 }
|
||||||
if opts.opt_present("h") { help_menu(program, &options); return 0 }
|
if matches.opt_present("h") { help_menu(opts); return 0 }
|
||||||
|
|
||||||
if opts.free.len() == 0 {
|
if matches.free.len() == 0 {
|
||||||
println!("Missing operand: NEWROOT");
|
println!("Missing operand: NEWROOT");
|
||||||
println!("Try `{} --help` for more information.", program);
|
println!("Try `{} --help` for more information.", NAME);
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,12 +77,12 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let default_option: &'static str = "-i";
|
let default_option: &'static str = "-i";
|
||||||
let user_shell = std::env::var("SHELL");
|
let user_shell = std::env::var("SHELL");
|
||||||
|
|
||||||
let newroot = Path::new(&opts.free[0][..]);
|
let newroot = Path::new(&matches.free[0][..]);
|
||||||
if !newroot.is_dir() {
|
if !newroot.is_dir() {
|
||||||
crash!(1, "cannot change root directory to `{}`: no such directory", newroot.display());
|
crash!(1, "cannot change root directory to `{}`: no such directory", newroot.display());
|
||||||
}
|
}
|
||||||
|
|
||||||
let command: Vec<&str> = match opts.free.len() {
|
let command: Vec<&str> = match matches.free.len() {
|
||||||
1 => {
|
1 => {
|
||||||
let shell: &str = match user_shell {
|
let shell: &str = match user_shell {
|
||||||
Err(_) => default_shell,
|
Err(_) => default_shell,
|
||||||
|
@ -92,10 +90,10 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
};
|
};
|
||||||
vec!(shell, default_option)
|
vec!(shell, default_option)
|
||||||
},
|
},
|
||||||
_ => opts.free[1..].iter().map(|x| &x[..]).collect()
|
_ => matches.free[1..].iter().map(|x| &x[..]).collect()
|
||||||
};
|
};
|
||||||
|
|
||||||
set_context(&newroot, &opts);
|
set_context(&newroot, &matches);
|
||||||
|
|
||||||
let pstatus = Command::new(command[0])
|
let pstatus = Command::new(command[0])
|
||||||
.args(&command[1..])
|
.args(&command[1..])
|
||||||
|
@ -207,13 +205,15 @@ fn version() {
|
||||||
println!("{} v{}", NAME, VERSION)
|
println!("{} v{}", NAME, VERSION)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn help_menu(program: &str, options: &[getopts::OptGroup]) {
|
fn help_menu(options: Options) {
|
||||||
version();
|
let msg = format!("{0} v{1}
|
||||||
println!("Usage:");
|
|
||||||
println!(" {} [OPTION]… NEWROOT [COMMAND [ARG]…]", program);
|
Usage:
|
||||||
println!("");
|
{0} [OPTION]… NEWROOT [COMMAND [ARG]…]
|
||||||
print!("{}", usage(
|
|
||||||
"Run COMMAND with root directory set to NEWROOT.\n\
|
Run COMMAND with root directory set to NEWROOT.
|
||||||
If COMMAND is not specified, it defaults to '${SHELL} -i'. \
|
If COMMAND is not specified, it defaults to '$(SHELL) -i'.
|
||||||
If ${SHELL} is not set, /bin/sh is used.", options))
|
If $(SHELL) is not set, /bin/sh is used.", NAME, VERSION);
|
||||||
|
|
||||||
|
print!("{}", options.usage(&msg));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "cksum"]
|
#![crate_name = "cksum"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -12,10 +11,11 @@
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
|
||||||
use std::io::{self, stdin, Read, Write, BufReader};
|
use getopts::Options;
|
||||||
use std::path::Path;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
use std::io::{self, stdin, Read, Write, BufReader};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use crc_table::CRC_TABLE;
|
use crc_table::CRC_TABLE;
|
||||||
|
|
||||||
|
@ -77,23 +77,24 @@ fn cksum(fname: &str) -> io::Result<(u32, usize)> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let opts = [
|
let mut opts = Options::new();
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
getopts::optflag("V", "version", "output version information and exit"),
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
];
|
|
||||||
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(err) => panic!("{}", err),
|
Err(err) => panic!("{}", err),
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
println!("{} {}", NAME, VERSION);
|
let msg = format!("{0} {1}
|
||||||
println!("");
|
|
||||||
println!("Usage:");
|
Usage:
|
||||||
println!(" {} [OPTIONS] [FILE]...", NAME);
|
{0} [OPTIONS] [FILE]...
|
||||||
println!("");
|
|
||||||
println!("{}", getopts::usage("Print CRC and size for each file.", opts.as_ref()));
|
Print CRC and size for each file.", NAME, VERSION);
|
||||||
|
|
||||||
|
print!("{}", opts.usage(&msg));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "comm"]
|
#![crate_name = "comm"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -12,13 +11,14 @@
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
|
||||||
|
use getopts::Options;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::io::{self, stdin, Stdin, BufReader, BufRead, Read};
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufRead, BufReader, Read, stdin, Stdin};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
static NAME : &'static str = "comm";
|
static NAME: &'static str = "comm";
|
||||||
static VERSION : &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
fn mkdelim(col: usize, opts: &getopts::Matches) -> String {
|
fn mkdelim(col: usize, opts: &getopts::Matches) -> String {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
|
@ -117,16 +117,15 @@ fn open_file(name: &str) -> io::Result<LineReader> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let opts = [
|
let mut opts = Options::new();
|
||||||
getopts::optflag("1", "", "suppress column 1 (lines uniq to FILE1)"),
|
opts.optflag("1", "", "suppress column 1 (lines uniq to FILE1)");
|
||||||
getopts::optflag("2", "", "suppress column 2 (lines uniq to FILE2)"),
|
opts.optflag("2", "", "suppress column 2 (lines uniq to FILE2)");
|
||||||
getopts::optflag("3", "", "suppress column 3 (lines that appear in both files)"),
|
opts.optflag("3", "", "suppress column 3 (lines that appear in both files)");
|
||||||
getopts::optopt("", "output-delimiter", "separate columns with STR", "STR"),
|
opts.optopt("", "output-delimiter", "separate columns with STR", "STR");
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
getopts::optflag("V", "version", "output version information and exit"),
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
];
|
|
||||||
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(err) => panic!("{}", err),
|
Err(err) => panic!("{}", err),
|
||||||
};
|
};
|
||||||
|
@ -137,19 +136,21 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.opt_present("help") || matches.free.len() != 2 {
|
if matches.opt_present("help") || matches.free.len() != 2 {
|
||||||
println!("{} {}", NAME, VERSION);
|
let msg = format!("{0} {1}
|
||||||
println!("");
|
|
||||||
println!("Usage:");
|
Usage:
|
||||||
println!(" {} [OPTIONS] FILE1 FILE2", NAME);
|
{0} [OPTIONS] FILE1 FILE2
|
||||||
println!("");
|
|
||||||
print!("{}", getopts::usage("Compare sorted files line by line.", opts.as_ref()));
|
Compare sorted files line by line.", NAME, VERSION);
|
||||||
|
|
||||||
|
print!("{}", opts.usage(&msg));
|
||||||
|
|
||||||
if matches.free.len() != 2 {
|
if matches.free.len() != 2 {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let mut f1 = open_file(matches.free[0].as_ref()).unwrap();
|
let mut f1 = open_file(matches.free[0].as_ref()).unwrap();
|
||||||
let mut f2 = open_file(matches.free[1].as_ref()).unwrap();
|
let mut f2 = open_file(matches.free[1].as_ref()).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "dirname"]
|
#![crate_name = "dirname"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -14,35 +13,36 @@ extern crate getopts;
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
static NAME: &'static str = "dirname";
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let program = args[0].clone();
|
let mut opts = getopts::Options::new();
|
||||||
let opts = [
|
opts.optflag("z", "zero", "separate output with NUL rather than newline");
|
||||||
getopts::optflag("z", "zero", "separate output with NUL rather than newline"),
|
opts.optflag("", "help", "display this help and exit");
|
||||||
getopts::optflag("", "help", "display this help and exit"),
|
opts.optflag("", "version", "output version information and exit");
|
||||||
getopts::optflag("", "version", "output version information and exit"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => panic!("Invalid options\n{}", f)
|
Err(f) => panic!("Invalid options\n{}", f)
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
println!("dirname {} - strip last component from file name", VERSION);
|
let msg = format!("{0} {1} - strip last component from file name
|
||||||
println!("");
|
|
||||||
println!("Usage:");
|
Usage:
|
||||||
println!(" {0} [OPTION] NAME...", program);
|
{0} [OPTION] NAME...
|
||||||
println!("");
|
|
||||||
print!("{}", getopts::usage("Output each NAME with its last non-slash component and trailing slashes
|
Output each NAME with its last non-slash component and trailing slashes
|
||||||
removed; if NAME contains no /'s, output '.' (meaning the current
|
removed; if NAME contains no /'s, output '.' (meaning the current
|
||||||
directory).", &opts));
|
directory).", NAME, VERSION);
|
||||||
|
|
||||||
|
print!("{}", opts.usage(&msg));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
println!("dirname version: {}", VERSION);
|
println!("{} {}", NAME, VERSION);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@ directory).", &opts));
|
||||||
print!("{}", separator);
|
print!("{}", separator);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("{0}: missing operand", program);
|
println!("{0}: missing operand", NAME);
|
||||||
println!("Try '{0} --help' for more information.", program);
|
println!("Try '{0} --help' for more information.", NAME);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "echo"]
|
#![crate_name = "echo"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -79,11 +78,10 @@ fn convert_str(string: &[u8], index: usize, base: u32) -> (char, usize) {
|
||||||
|
|
||||||
fn parse_options(args: Vec<String>, options: &mut EchoOptions) -> Option<Vec<String>> {
|
fn parse_options(args: Vec<String>, options: &mut EchoOptions) -> Option<Vec<String>> {
|
||||||
let mut echo_args = vec!();
|
let mut echo_args = vec!();
|
||||||
let program = args[0].clone();
|
|
||||||
'argloop: for arg in args.into_iter().skip(1) {
|
'argloop: for arg in args.into_iter().skip(1) {
|
||||||
match arg.as_ref() {
|
match arg.as_ref() {
|
||||||
"--help" | "-h" => {
|
"--help" | "-h" => {
|
||||||
print_help(&program);
|
print_help();
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
"--version" | "-V" => {
|
"--version" | "-V" => {
|
||||||
|
@ -99,7 +97,7 @@ fn parse_options(args: Vec<String>, options: &mut EchoOptions) -> Option<Vec<Str
|
||||||
for ch in arg.chars().skip(1) {
|
for ch in arg.chars().skip(1) {
|
||||||
match ch {
|
match ch {
|
||||||
'h' => {
|
'h' => {
|
||||||
print_help(&program);
|
print_help();
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
'V' => {
|
'V' => {
|
||||||
|
@ -125,22 +123,22 @@ fn parse_options(args: Vec<String>, options: &mut EchoOptions) -> Option<Vec<Str
|
||||||
Some(echo_args)
|
Some(echo_args)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_help(program: &String) {
|
fn print_help() {
|
||||||
let opts = [
|
let mut opts = getopts::Options::new();
|
||||||
getopts::optflag("n", "", "do not output the trailing newline"),
|
opts.optflag("n", "", "do not output the trailing newline");
|
||||||
getopts::optflag("e", "", "enable interpretation of backslash escapes"),
|
opts.optflag("e", "", "enable interpretation of backslash escapes");
|
||||||
getopts::optflag("E", "", "disable interpretation of backslash escapes (default)"),
|
opts.optflag("E", "", "disable interpretation of backslash escapes (default)");
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
getopts::optflag("V", "version", "output version information and exit"),
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
];
|
|
||||||
println!("echo {} - display a line of text", VERSION);
|
let msg = format!("{0} {1} - display a line of text
|
||||||
println!("");
|
|
||||||
println!("Usage:");
|
Usage:
|
||||||
println!(" {0} [SHORT-OPTION]... [STRING]...", *program);
|
{0} [SHORT-OPTION]... [STRING]...
|
||||||
println!(" {0} LONG-OPTION", *program);
|
{0} LONG-OPTION
|
||||||
println!("");
|
|
||||||
println!("{}", getopts::usage("Echo the STRING(s) to standard output.", &opts));
|
Echo the STRING(s) to standard output.
|
||||||
println!("{}", "If -e is in effect, the following sequences are recognized:
|
If -e is in effect, the following sequences are recognized:
|
||||||
|
|
||||||
\\\\ backslash
|
\\\\ backslash
|
||||||
\\a alert (BEL)
|
\\a alert (BEL)
|
||||||
|
@ -153,11 +151,13 @@ fn print_help(program: &String) {
|
||||||
\\t horizontal tab
|
\\t horizontal tab
|
||||||
\\v vertical tab
|
\\v vertical tab
|
||||||
\\0NNN byte with octal value NNN (1 to 3 digits)
|
\\0NNN byte with octal value NNN (1 to 3 digits)
|
||||||
\\xHH byte with hexadecimal value HH (1 to 2 digits)");
|
\\xHH byte with hexadecimal value HH (1 to 2 digits)", NAME, VERSION);
|
||||||
|
|
||||||
|
print!("{}", opts.usage(&msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_version() {
|
fn print_version() {
|
||||||
println!("echo version: {}", VERSION);
|
println!("{} {}", NAME, VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "factor"]
|
#![crate_name = "factor"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -20,12 +19,12 @@ extern crate rand;
|
||||||
|
|
||||||
use numeric::*;
|
use numeric::*;
|
||||||
use prime_table::P_INVS_U64;
|
use prime_table::P_INVS_U64;
|
||||||
|
use rand::weak_rng;
|
||||||
|
use rand::distributions::{Range, IndependentSample};
|
||||||
use std::cmp::{max, min};
|
use std::cmp::{max, min};
|
||||||
use std::io::{stdin, BufRead, BufReader, Write};
|
use std::io::{stdin, BufRead, BufReader, Write};
|
||||||
use std::num::Wrapping;
|
use std::num::Wrapping;
|
||||||
use std::mem::swap;
|
use std::mem::swap;
|
||||||
use rand::weak_rng;
|
|
||||||
use rand::distributions::{Range, IndependentSample};
|
|
||||||
|
|
||||||
#[path="../common/util.rs"]
|
#[path="../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -33,8 +32,8 @@ mod util;
|
||||||
mod numeric;
|
mod numeric;
|
||||||
mod prime_table;
|
mod prime_table;
|
||||||
|
|
||||||
static VERSION: &'static str = "1.0.0";
|
|
||||||
static NAME: &'static str = "factor";
|
static NAME: &'static str = "factor";
|
||||||
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
fn rho_pollard_pseudorandom_function(x: u64, a: u64, b: u64, num: u64) -> u64 {
|
fn rho_pollard_pseudorandom_function(x: u64, a: u64, b: u64, num: u64) -> u64 {
|
||||||
if num < 1 << 63 {
|
if num < 1 << 63 {
|
||||||
|
@ -157,33 +156,31 @@ fn print_factors_str(num_str: &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let opts = [
|
let mut opts = getopts::Options::new();
|
||||||
getopts::optflag("h", "help", "show this help message"),
|
opts.optflag("h", "help", "show this help message");
|
||||||
getopts::optflag("v", "version", "print the version and exit"),
|
opts.optflag("v", "version", "print the version and exit");
|
||||||
];
|
|
||||||
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => crash!(1, "Invalid options\n{}", f)
|
Err(f) => crash!(1, "Invalid options\n{}", f)
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
print!("{program} {version}\n\
|
let msg = format!("{0} {1}
|
||||||
\n\
|
|
||||||
Usage:\n\
|
Usage:
|
||||||
\t{program} [NUMBER]...\n\
|
\t{0} [NUMBER]...
|
||||||
\t{program} [OPTION]\n\
|
\t{0} [OPTION]
|
||||||
\n\
|
|
||||||
{usage}",
|
Print the prime factors of the given number(s). If none are specified,
|
||||||
program = &args[0][..],
|
read from standard input.", NAME, VERSION);
|
||||||
version = VERSION,
|
|
||||||
usage = getopts::usage("Print the prime factors of the given number(s). \
|
print!("{}", opts.usage(&msg));
|
||||||
If none are specified, read from standard input.", &opts));
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
println!("{} {}", &args[0][..], VERSION);
|
println!("{} {}", NAME, VERSION);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "groups"]
|
#![crate_name = "groups"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -13,7 +12,6 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
|
||||||
use c_types::{get_pw_from_args, group};
|
use c_types::{get_pw_from_args, group};
|
||||||
use getopts::{getopts, optflag, usage};
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
#[path = "../common/util.rs"] #[macro_use] mod util;
|
#[path = "../common/util.rs"] #[macro_use] mod util;
|
||||||
|
@ -23,14 +21,11 @@ static NAME: &'static str = "groups";
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let program = args[0].clone();
|
let mut opts = getopts::Options::new();
|
||||||
|
opts.optflag("h", "help", "display this help menu and exit");
|
||||||
|
opts.optflag("V", "version", "display version information and exit");
|
||||||
|
|
||||||
let options = [
|
let matches = match opts.parse(&args[1..]) {
|
||||||
optflag("h", "help", "display this help menu and exit"),
|
|
||||||
optflag("V", "version", "display version information and exit")
|
|
||||||
];
|
|
||||||
|
|
||||||
let matches = match getopts(&args[1..], &options) {
|
|
||||||
Ok(m) => { m },
|
Ok(m) => { m },
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
show_error!("{}", f);
|
show_error!("{}", f);
|
||||||
|
@ -41,10 +36,14 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
println!("{} v{}", NAME, VERSION);
|
println!("{} v{}", NAME, VERSION);
|
||||||
} else if matches.opt_present("help") {
|
} else if matches.opt_present("help") {
|
||||||
print!("{} v{}\n\n\
|
let msg = format!("{0} v{1}
|
||||||
Usage:\n \
|
|
||||||
{} [OPTION]... [USER]...\n\n\
|
Usage:
|
||||||
{}", NAME, VERSION, program, usage("Prints the groups a user is in to standard output.", &options));
|
{0} [OPTION]... [USER]...
|
||||||
|
|
||||||
|
Prints the groups a user is in to standard output.", NAME, VERSION);
|
||||||
|
|
||||||
|
print!("{}", opts.usage(&msg));
|
||||||
} else {
|
} else {
|
||||||
group(get_pw_from_args(&matches.free), true);
|
group(get_pw_from_args(&matches.free), true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "hashsum"]
|
#![crate_name = "hashsum"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -12,10 +11,9 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern crate regex;
|
|
||||||
|
|
||||||
extern crate crypto;
|
extern crate crypto;
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
extern crate regex;
|
||||||
|
|
||||||
use crypto::digest::Digest;
|
use crypto::digest::Digest;
|
||||||
use crypto::md5::Md5;
|
use crypto::md5::Md5;
|
||||||
|
@ -43,21 +41,6 @@ fn is_custom_binary(program: &str) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_algo_opts(program: &str) -> Vec<getopts::OptGroup> {
|
|
||||||
if is_custom_binary(program) {
|
|
||||||
Vec::new()
|
|
||||||
} else {
|
|
||||||
vec!(
|
|
||||||
getopts::optflag("", "md5", "work with MD5"),
|
|
||||||
getopts::optflag("", "sha1", "work with SHA1"),
|
|
||||||
getopts::optflag("", "sha224", "work with SHA224"),
|
|
||||||
getopts::optflag("", "sha256", "work with SHA256"),
|
|
||||||
getopts::optflag("", "sha384", "work with SHA384"),
|
|
||||||
getopts::optflag("", "sha512", "work with SHA512")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn detect_algo(program: &str, matches: &getopts::Matches) -> (&'static str, Box<Digest+'static>) {
|
fn detect_algo(program: &str, matches: &getopts::Matches) -> (&'static str, Box<Digest+'static>) {
|
||||||
let mut alg: Option<Box<Digest>> = None;
|
let mut alg: Option<Box<Digest>> = None;
|
||||||
let mut name: &'static str = "";
|
let mut name: &'static str = "";
|
||||||
|
@ -95,22 +78,28 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
// Default binary in Windows, text mode otherwise
|
// Default binary in Windows, text mode otherwise
|
||||||
let binary_flag_default = cfg!(windows);
|
let binary_flag_default = cfg!(windows);
|
||||||
|
|
||||||
let mut opts: Vec<getopts::OptGroup> = vec!(
|
let mut opts = getopts::Options::new();
|
||||||
getopts::optflag("b", "binary", &format!("read in binary mode{}", if binary_flag_default { " (default)" } else { "" })),
|
opts.optflag("b", "binary", &format!("read in binary mode{}", if binary_flag_default { " (default)" } else { "" }));
|
||||||
getopts::optflag("c", "check", "read hashsums from the FILEs and check them"),
|
opts.optflag("c", "check", "read hashsums from the FILEs and check them");
|
||||||
getopts::optflag("", "tag", "create a BSD-style checksum"),
|
opts.optflag("", "tag", "create a BSD-style checksum");
|
||||||
getopts::optflag("t", "text", &format!("read in text mode{}", if binary_flag_default { "" } else { " (default)" })),
|
opts.optflag("t", "text", &format!("read in text mode{}", if binary_flag_default { "" } else { " (default)" }));
|
||||||
getopts::optflag("q", "quiet", "don't print OK for each successfully verified file"),
|
opts.optflag("q", "quiet", "don't print OK for each successfully verified file");
|
||||||
getopts::optflag("s", "status", "don't output anything, status code shows success"),
|
opts.optflag("s", "status", "don't output anything, status code shows success");
|
||||||
getopts::optflag("", "strict", "exit non-zero for improperly formatted checksum lines"),
|
opts.optflag("", "strict", "exit non-zero for improperly formatted checksum lines");
|
||||||
getopts::optflag("w", "warn", "warn about improperly formatted checksum lines"),
|
opts.optflag("w", "warn", "warn about improperly formatted checksum lines");
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
getopts::optflag("V", "version", "output version information and exit"),
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
);
|
|
||||||
|
|
||||||
opts.extend(get_algo_opts(binary_name).into_iter());
|
if !is_custom_binary(program) {
|
||||||
|
opts.optflag("", "md5", "work with MD5");
|
||||||
|
opts.optflag("", "sha1", "work with SHA1");
|
||||||
|
opts.optflag("", "sha224", "work with SHA224");
|
||||||
|
opts.optflag("", "sha256", "work with SHA256");
|
||||||
|
opts.optflag("", "sha384", "work with SHA384");
|
||||||
|
opts.optflag("", "sha512", "work with SHA512");
|
||||||
|
}
|
||||||
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => crash!(1, "{}", f)
|
Err(f) => crash!(1, "{}", f)
|
||||||
};
|
};
|
||||||
|
@ -152,17 +141,21 @@ fn version() {
|
||||||
pipe_println!("{} v{}", NAME, VERSION);
|
pipe_println!("{} v{}", NAME, VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(program: &str, binary_name: &str, opts: &[getopts::OptGroup]) {
|
fn usage(program: &str, binary_name: &str, opts: &getopts::Options) {
|
||||||
version();
|
let spec = if is_custom_binary(binary_name) {
|
||||||
pipe_println!("");
|
format!(" {} [OPTION]... [FILE]...", program)
|
||||||
pipe_println!("Usage:");
|
|
||||||
if is_custom_binary(binary_name) {
|
|
||||||
pipe_println!(" {} [OPTION]... [FILE]...", program);
|
|
||||||
} else {
|
} else {
|
||||||
pipe_println!(" {} {{--md5|--sha1|--sha224|--sha256|--sha384|--sha512}} [OPTION]... [FILE]...", program);
|
format!(" {} {{--md5|--sha1|--sha224|--sha256|--sha384|--sha512}} [OPTION]... [FILE]...", program)
|
||||||
}
|
};
|
||||||
pipe_println!("");
|
|
||||||
pipe_print!("{}", getopts::usage("Compute and check message digests.", opts));
|
let msg = format!("{} v{}
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
{}
|
||||||
|
|
||||||
|
Compute and check message digests.", NAME, VERSION, spec);
|
||||||
|
|
||||||
|
pipe_print!("{}", opts.usage(&msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hashsum<'a>(algoname: &str, mut digest: Box<Digest+'a>, files: Vec<String>, binary: bool, check: bool, tag: bool, status: bool, quiet: bool, strict: bool, warn: bool) -> Result<(), i32> {
|
fn hashsum<'a>(algoname: &str, mut digest: Box<Digest+'a>, files: Vec<String>, binary: bool, check: bool, tag: bool, status: bool, quiet: bool, strict: bool, warn: bool) -> Result<(), i32> {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "hostid"]
|
#![crate_name = "hostid"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -11,20 +10,16 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate serialize;
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
#[macro_use] extern crate log;
|
|
||||||
|
|
||||||
use getopts::{getopts, optflag, usage};
|
use libc::c_long;
|
||||||
use libc::{c_long};
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
static NAME: &'static str = "hostid";
|
static NAME: &'static str = "hostid";
|
||||||
static VERSION: &'static str = "0.0.1";
|
static VERSION: &'static str = "0.0.1";
|
||||||
|
|
||||||
static EXIT_ERR: i32 = 1;
|
static EXIT_ERR: i32 = 1;
|
||||||
|
|
||||||
|
@ -34,23 +29,20 @@ pub enum Mode {
|
||||||
Version,
|
Version,
|
||||||
}
|
}
|
||||||
|
|
||||||
//currently rust libc interface doesn't include gethostid
|
// currently rust libc interface doesn't include gethostid
|
||||||
extern {
|
extern {
|
||||||
pub fn gethostid() -> c_long;
|
pub fn gethostid() -> c_long;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let opts = [
|
let mut opts = getopts::Options::new();
|
||||||
optflag("", "help", "display this help and exit"),
|
opts.optflag("", "help", "display this help and exit");
|
||||||
optflag("", "version", "output version information and exit"),
|
opts.optflag("", "version", "output version information and exit");
|
||||||
];
|
|
||||||
|
|
||||||
let usage = usage("[options]", &opts);
|
let matches = match opts.parse(&args[1..]) {
|
||||||
|
|
||||||
let matches = match getopts(&args[1..], &opts) {
|
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(e) => {
|
Err(_) => {
|
||||||
show_error!("{}\n{}", e, get_help_text(NAME, usage.as_ref()));
|
help(&opts);
|
||||||
return EXIT_ERR;
|
return EXIT_ERR;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -65,7 +57,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
|
|
||||||
match mode {
|
match mode {
|
||||||
Mode::HostId => hostid(),
|
Mode::HostId => hostid(),
|
||||||
Mode::Help => help(NAME, usage.as_ref()),
|
Mode::Help => help(&opts),
|
||||||
Mode::Version => version(),
|
Mode::Version => version(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,12 +68,9 @@ fn version() {
|
||||||
println!("{} {}", NAME, VERSION);
|
println!("{} {}", NAME, VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_help_text(progname: &str, usage: &str) -> String {
|
fn help(opts: &getopts::Options) {
|
||||||
format!("Usage: \n {0} {1}", progname, usage)
|
let msg = format!("Usage:\n {} [options]", NAME);
|
||||||
}
|
print!("{}", opts.usage(&msg));
|
||||||
|
|
||||||
fn help(progname: &str, usage: &str) {
|
|
||||||
println!("{}", get_help_text(progname, usage));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hostid() {
|
fn hostid() {
|
||||||
|
|
49
src/id/id.rs
49
src/id/id.rs
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "id"]
|
#![crate_name = "id"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -18,16 +17,11 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use std::io::Write;
|
use libc::{getgid, getuid, uid_t};
|
||||||
use std::ffi::CStr;
|
|
||||||
use std::ptr::read;
|
|
||||||
use libc::{
|
|
||||||
uid_t,
|
|
||||||
getgid,
|
|
||||||
getuid
|
|
||||||
};
|
|
||||||
use libc::funcs::posix88::unistd::{getegid, geteuid, getlogin};
|
use libc::funcs::posix88::unistd::{getegid, geteuid, getlogin};
|
||||||
use getopts::{getopts, optflag, usage};
|
use std::ffi::CStr;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::ptr::read;
|
||||||
use c_types::{
|
use c_types::{
|
||||||
c_passwd,
|
c_passwd,
|
||||||
c_group,
|
c_group,
|
||||||
|
@ -87,30 +81,27 @@ extern {
|
||||||
static NAME: &'static str = "id";
|
static NAME: &'static str = "id";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let args_t = &args[1..];
|
let mut opts = getopts::Options::new();
|
||||||
|
opts.optflag("h", "", "Show help");
|
||||||
|
opts.optflag("A", "", "Display the process audit (not available on Linux)");
|
||||||
|
opts.optflag("G", "", "Display the different group IDs");
|
||||||
|
opts.optflag("g", "", "Display the effective group ID as a number");
|
||||||
|
opts.optflag("n", "", "Display the name of the user or group ID for the -G, -g and -u options");
|
||||||
|
opts.optflag("P", "", "Display the id as a password file entry");
|
||||||
|
opts.optflag("p", "", "Make the output human-readable");
|
||||||
|
opts.optflag("r", "", "Display the real ID for the -g and -u options");
|
||||||
|
opts.optflag("u", "", "Display the effective user ID as a number");
|
||||||
|
|
||||||
let options = [
|
let matches = match opts.parse(&args[1..]) {
|
||||||
optflag("h", "", "Show help"),
|
|
||||||
optflag("A", "", "Display the process audit (not available on Linux)"),
|
|
||||||
optflag("G", "", "Display the different group IDs"),
|
|
||||||
optflag("g", "", "Display the effective group ID as a number"),
|
|
||||||
optflag("n", "", "Display the name of the user or group ID for the -G, -g and -u options"),
|
|
||||||
optflag("P", "", "Display the id as a password file entry"),
|
|
||||||
optflag("p", "", "Make the output human-readable"),
|
|
||||||
optflag("r", "", "Display the real ID for the -g and -u options"),
|
|
||||||
optflag("u", "", "Display the effective user ID as a number")
|
|
||||||
];
|
|
||||||
|
|
||||||
let matches = match getopts(args_t, &options) {
|
|
||||||
Ok(m) => { m },
|
Ok(m) => { m },
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
println!("{}", usage(NAME, &options));
|
println!("{}", opts.usage(NAME));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.opt_present("h") {
|
if matches.opt_present("h") {
|
||||||
println!("{}", usage(NAME, &options));
|
println!("{}", opts.usage(NAME));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +110,6 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let possible_pw = get_pw_from_args(&matches.free);
|
let possible_pw = get_pw_from_args(&matches.free);
|
||||||
|
|
||||||
let nflag = matches.opt_present("n");
|
let nflag = matches.opt_present("n");
|
||||||
|
@ -325,10 +315,7 @@ fn auditid() {
|
||||||
println!("asid={}", auditinfo.ai_asid);
|
println!("asid={}", auditinfo.ai_asid);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id_print(possible_pw: Option<c_passwd>,
|
fn id_print(possible_pw: Option<c_passwd>, p_euid: bool, p_egid: bool) {
|
||||||
p_euid: bool,
|
|
||||||
p_egid: bool) {
|
|
||||||
|
|
||||||
let uid;
|
let uid;
|
||||||
let gid;
|
let gid;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "kill"]
|
#![crate_name = "kill"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -12,11 +11,7 @@
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate serialize;
|
|
||||||
|
|
||||||
#[macro_use] extern crate log;
|
|
||||||
|
|
||||||
use getopts::{getopts, optflag, optflagopt, optopt, usage};
|
|
||||||
use libc::{c_int, pid_t};
|
use libc::{c_int, pid_t};
|
||||||
use signals::ALL_SIGNALS;
|
use signals::ALL_SIGNALS;
|
||||||
use std::io::{Error, Write};
|
use std::io::{Error, Write};
|
||||||
|
@ -47,22 +42,20 @@ pub enum Mode {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let opts = [
|
let mut opts = getopts::Options::new();
|
||||||
optflag("h", "help", "display this help and exit"),
|
|
||||||
optflag("V", "version", "output version information and exit"),
|
|
||||||
optopt("s", "signal", "specify the <signal> to be sent", "SIGNAL"),
|
|
||||||
optflagopt("l", "list", "list all signal names, or convert one to a name", "LIST"),
|
|
||||||
optflag("L", "table", "list all signal names in a nice table"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let usage = usage("[options] <pid> [...]", &opts);
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
|
opts.optopt("s", "signal", "specify the <signal> to be sent", "SIGNAL");
|
||||||
|
opts.optflagopt("l", "list", "list all signal names, or convert one to a name", "LIST");
|
||||||
|
opts.optflag("L", "table", "list all signal names in a nice table");
|
||||||
|
|
||||||
let (args, obs_signal) = handle_obsolete(args);
|
let (args, obs_signal) = handle_obsolete(args);
|
||||||
|
|
||||||
let matches = match getopts(&args[1..], &opts) {
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(e) => {
|
Err(_) => {
|
||||||
show_error!("{}\n{}", e, get_help_text(NAME, &usage));
|
help(&opts);
|
||||||
return EXIT_ERR;
|
return EXIT_ERR;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -83,7 +76,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
Mode::Kill => return kill(&matches.opt_str("signal").unwrap_or(obs_signal.unwrap_or("9".to_string())), matches.free),
|
Mode::Kill => return kill(&matches.opt_str("signal").unwrap_or(obs_signal.unwrap_or("9".to_string())), matches.free),
|
||||||
Mode::Table => table(),
|
Mode::Table => table(),
|
||||||
Mode::List => list(matches.opt_str("list")),
|
Mode::List => list(matches.opt_str("list")),
|
||||||
Mode::Help => help(NAME, &usage),
|
Mode::Help => help(&opts),
|
||||||
Mode::Version => version(),
|
Mode::Version => version(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +91,7 @@ fn handle_obsolete(mut args: Vec<String>) -> (Vec<String>, Option<String>) {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < args.len() {
|
while i < args.len() {
|
||||||
// this is safe because slice is valid when it is referenced
|
// this is safe because slice is valid when it is referenced
|
||||||
let slice = &args[i].clone();//unsafe { std::mem::transmute(args[i]) };
|
let slice = &args[i].clone();
|
||||||
if slice.chars().next().unwrap() == '-' && slice.len() > 1 && slice.chars().nth(1).unwrap().is_digit(10) {
|
if slice.chars().next().unwrap() == '-' && slice.len() > 1 && slice.chars().nth(1).unwrap().is_digit(10) {
|
||||||
let val = &slice[1..];
|
let val = &slice[1..];
|
||||||
match val.parse() {
|
match val.parse() {
|
||||||
|
@ -170,12 +163,13 @@ fn list(arg: Option<String>) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_help_text(progname: &str, usage: &str) -> String {
|
fn help(opts: &getopts::Options) {
|
||||||
format!("Usage: \n {0} {1}", progname, usage)
|
let msg = format!("{0} {1}
|
||||||
}
|
|
||||||
|
|
||||||
fn help(progname: &str, usage: &str) {
|
Usage:
|
||||||
println!("{}", get_help_text(progname, usage));
|
{0} [options] <pid> [...]", NAME, VERSION);
|
||||||
|
|
||||||
|
println!("{}", opts.usage(&msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn kill(signalname: &str, pids: std::vec::Vec<String>) -> i32 {
|
fn kill(signalname: &str, pids: std::vec::Vec<String>) -> i32 {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "link"]
|
#![crate_name = "link"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -12,24 +11,24 @@
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
|
||||||
use std::io::Write;
|
|
||||||
use std::fs::hard_link;
|
use std::fs::hard_link;
|
||||||
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
#[path="../common/util.rs"]
|
#[path="../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
static NAME : &'static str = "link";
|
static NAME: &'static str = "link";
|
||||||
static VERSION : &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let opts = [
|
let mut opts = getopts::Options::new();
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
|
||||||
getopts::optflag("V", "version", "output version information and exit"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
|
|
||||||
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(err) => panic!("{}", err),
|
Err(err) => panic!("{}", err),
|
||||||
};
|
};
|
||||||
|
@ -40,12 +39,14 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.opt_present("help") || matches.free.len() != 2 {
|
if matches.opt_present("help") || matches.free.len() != 2 {
|
||||||
println!("{} {}", NAME, VERSION);
|
let msg = format!("{0} {1}
|
||||||
println!("");
|
|
||||||
println!("Usage:");
|
Usage:
|
||||||
println!(" {} [OPTIONS] FILE1 FILE2", NAME);
|
{0} [OPTIONS] FILE1 FILE2
|
||||||
println!("");
|
|
||||||
print!("{}", getopts::usage("Create a link named FILE2 to FILE1.", &opts));
|
Create a link named FILE2 to FILE1.", NAME, VERSION);
|
||||||
|
|
||||||
|
println!("{}", opts.usage(&msg));
|
||||||
if matches.free.len() != 2 {
|
if matches.free.len() != 2 {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "logname"]
|
#![crate_name = "logname"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -39,37 +38,33 @@ fn get_userlogin() -> Option<String> {
|
||||||
static NAME: &'static str = "logname";
|
static NAME: &'static str = "logname";
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
fn version() {
|
|
||||||
println!("{} {}", NAME, VERSION);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let program = args[0].clone();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Argument parsing
|
// Argument parsing
|
||||||
//
|
//
|
||||||
let opts = [
|
let mut opts = getopts::Options::new();
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
|
||||||
getopts::optflag("V", "version", "output version information and exit"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
|
|
||||||
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => crash!(1, "Invalid options\n{}", f)
|
Err(f) => crash!(1, "Invalid options\n{}", f)
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
version();
|
let msg = format!("{0} {1}
|
||||||
println!("");
|
|
||||||
println!("Usage:");
|
Usage:
|
||||||
println!(" {}", program);
|
{0}
|
||||||
println!("");
|
|
||||||
print!("{}", getopts::usage("print user's login name", &opts));
|
Print user's login name.", NAME, VERSION);
|
||||||
|
|
||||||
|
print!("{}", opts.usage(&msg));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
version();
|
println!("{} {}", NAME, VERSION);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "mkfifo"]
|
#![crate_name = "mkfifo"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -13,25 +12,25 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
|
use libc::funcs::posix88::stat_::mkfifo;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::io::{Error, Write};
|
use std::io::{Error, Write};
|
||||||
use libc::funcs::posix88::stat_::mkfifo;
|
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
static NAME : &'static str = "mkfifo";
|
static NAME: &'static str = "mkfifo";
|
||||||
static VERSION : &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let opts = [
|
let mut opts = getopts::Options::new();
|
||||||
getopts::optopt("m", "mode", "file permissions for the fifo", "(default 0666)"),
|
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
|
||||||
getopts::optflag("V", "version", "output version information and exit"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
opts.optopt("m", "mode", "file permissions for the fifo", "(default 0666)");
|
||||||
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
|
|
||||||
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(err) => panic!("{}", err),
|
Err(err) => panic!("{}", err),
|
||||||
};
|
};
|
||||||
|
@ -42,12 +41,14 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.opt_present("help") || matches.free.is_empty() {
|
if matches.opt_present("help") || matches.free.is_empty() {
|
||||||
println!("{} {}", NAME, VERSION);
|
let msg = format!("{0} {1}
|
||||||
println!("");
|
|
||||||
println!("Usage:");
|
Usage:
|
||||||
println!(" {} [OPTIONS] NAME...", NAME);
|
{0} [OPTIONS] NAME...
|
||||||
println!("");
|
|
||||||
print!("{}", getopts::usage("Create a FIFO with the given name.", &opts));
|
Create a FIFO with the given name.", NAME, VERSION);
|
||||||
|
|
||||||
|
print!("{}", opts.usage(&msg));
|
||||||
if matches.free.is_empty() {
|
if matches.free.is_empty() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
124
src/nice/nice.rs
124
src/nice/nice.rs
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "nice"]
|
#![crate_name = "nice"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -13,9 +12,9 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
|
use libc::{c_char, c_int, execvp};
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::io::{Error, Write};
|
use std::io::{Error, Write};
|
||||||
use libc::{c_char, c_int, execvp};
|
|
||||||
|
|
||||||
const NAME: &'static str = "nice";
|
const NAME: &'static str = "nice";
|
||||||
const VERSION: &'static str = "1.0.0";
|
const VERSION: &'static str = "1.0.0";
|
||||||
|
@ -33,13 +32,13 @@ extern {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let opts = [
|
let mut opts = getopts::Options::new();
|
||||||
getopts::optopt("n", "adjustment", "add N to the niceness (default is 10)", "N"),
|
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
|
||||||
getopts::optflag("V", "version", "output version information and exit"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
opts.optopt("n", "adjustment", "add N to the niceness (default is 10)", "N");
|
||||||
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
|
|
||||||
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
show_error!("{}", err);
|
show_error!("{}", err);
|
||||||
|
@ -47,66 +46,67 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.opt_present("version") || matches.opt_present("help") {
|
if matches.opt_present("version") {
|
||||||
println!("{} v{}", NAME, VERSION);
|
println!("{} v{}", NAME, VERSION);
|
||||||
if matches.opt_present("help") {
|
return 0;
|
||||||
let usage = getopts::usage("Run COMMAND with an adjusted niceness, \
|
}
|
||||||
which affects process scheduling.\n\
|
|
||||||
With no COMMAND, print the current \
|
|
||||||
niceness. Niceness values range from \
|
|
||||||
at\nleast -20 (most favorable to the \
|
|
||||||
process) to 19 (least favorable to the\
|
|
||||||
\nprocess).", &opts);
|
|
||||||
println!("");
|
|
||||||
println!("Usage:");
|
|
||||||
println!(" {} [OPTIONS] [COMMAND [ARGS]]", NAME);
|
|
||||||
println!("");
|
|
||||||
print!("{}", usage);
|
|
||||||
}
|
|
||||||
0
|
|
||||||
} else {
|
|
||||||
let mut niceness = unsafe { getpriority(PRIO_PROCESS, 0) };
|
|
||||||
if Error::last_os_error().raw_os_error().unwrap() != 0 {
|
|
||||||
show_error!("{}", Error::last_os_error());
|
|
||||||
return 125;
|
|
||||||
}
|
|
||||||
|
|
||||||
let adjustment = match matches.opt_str("adjustment") {
|
if matches.opt_present("help") {
|
||||||
Some(nstr) => {
|
let msg = format!("{0} v{1}
|
||||||
if matches.free.len() == 0 {
|
|
||||||
show_error!("A command must be given with an adjustment.
|
Usage:
|
||||||
Try \"{} --help\" for more information.", args[0]);
|
{0} [OPTIONS] [COMMAND [ARGS]]
|
||||||
|
|
||||||
|
Run COMMAND with an adjusted niceness, which affects process scheduling.
|
||||||
|
With no COMMAND, print the current niceness. Niceness values range from at
|
||||||
|
least -20 (most favorable to the process) to 19 (least favorable to the
|
||||||
|
process).", NAME, VERSION);
|
||||||
|
|
||||||
|
print!("{}", opts.usage(&msg));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut niceness = unsafe { getpriority(PRIO_PROCESS, 0) };
|
||||||
|
if Error::last_os_error().raw_os_error().unwrap() != 0 {
|
||||||
|
show_error!("{}", Error::last_os_error());
|
||||||
|
return 125;
|
||||||
|
}
|
||||||
|
|
||||||
|
let adjustment = match matches.opt_str("adjustment") {
|
||||||
|
Some(nstr) => {
|
||||||
|
if matches.free.len() == 0 {
|
||||||
|
show_error!("A command must be given with an adjustment.
|
||||||
|
Try \"{} --help\" for more information.", args[0]);
|
||||||
|
return 125;
|
||||||
|
}
|
||||||
|
match nstr.parse() {
|
||||||
|
Ok(num) => num,
|
||||||
|
Err(e)=> {
|
||||||
|
show_error!("\"{}\" is not a valid number: {}", nstr, e);
|
||||||
return 125;
|
return 125;
|
||||||
}
|
}
|
||||||
match nstr.parse() {
|
|
||||||
Ok(num) => num,
|
|
||||||
Err(e)=> {
|
|
||||||
show_error!("\"{}\" is not a valid number: {}", nstr, e);
|
|
||||||
return 125;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
if matches.free.len() == 0 {
|
|
||||||
println!("{}", niceness);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
10 as c_int
|
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
|
None => {
|
||||||
niceness += adjustment;
|
if matches.free.len() == 0 {
|
||||||
unsafe { setpriority(PRIO_PROCESS, 0, niceness); }
|
println!("{}", niceness);
|
||||||
if Error::last_os_error().raw_os_error().unwrap() != 0 {
|
return 0;
|
||||||
show_warning!("{}", Error::last_os_error());
|
}
|
||||||
|
10 as c_int
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let cstrs: Vec<CString> = matches.free.iter().map(|x| CString::new(x.as_bytes()).unwrap()).collect();
|
niceness += adjustment;
|
||||||
let mut args: Vec<*const c_char> = cstrs.iter().map(|s| s.as_ptr()).collect();
|
unsafe { setpriority(PRIO_PROCESS, 0, niceness); }
|
||||||
args.push(0 as *const c_char);
|
if Error::last_os_error().raw_os_error().unwrap() != 0 {
|
||||||
unsafe { execvp(args[0], args.as_mut_ptr()); }
|
show_warning!("{}", Error::last_os_error());
|
||||||
|
|
||||||
show_error!("{}", Error::last_os_error());
|
|
||||||
if Error::last_os_error().raw_os_error().unwrap() as c_int == libc::ENOENT { 127 } else { 126 }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let cstrs: Vec<CString> = matches.free.iter().map(|x| CString::new(x.as_bytes()).unwrap()).collect();
|
||||||
|
let mut args: Vec<*const c_char> = cstrs.iter().map(|s| s.as_ptr()).collect();
|
||||||
|
args.push(0 as *const c_char);
|
||||||
|
unsafe { execvp(args[0], args.as_mut_ptr()); }
|
||||||
|
|
||||||
|
show_error!("{}", Error::last_os_error());
|
||||||
|
if Error::last_os_error().raw_os_error().unwrap() as c_int == libc::ENOENT { 127 } else { 126 }
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,11 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
||||||
|
use getopts::{getopts, optflag, OptGroup, optopt, usage};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader, Read, stdin, Write};
|
use std::io::{BufRead, BufReader, Read, stdin, Write};
|
||||||
use std::iter::repeat;
|
use std::iter::repeat;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use getopts::{getopts, optflag, OptGroup, optopt, usage};
|
|
||||||
|
|
||||||
#[path="../common/util.rs"]
|
#[path="../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "nohup"]
|
#![crate_name = "nohup"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -13,7 +12,6 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use getopts::{getopts, optflag, usage};
|
|
||||||
use libc::c_char;
|
use libc::c_char;
|
||||||
use libc::funcs::posix01::signal::signal;
|
use libc::funcs::posix01::signal::signal;
|
||||||
use libc::funcs::posix88::unistd::{dup2, execvp, isatty};
|
use libc::funcs::posix88::unistd::{dup2, execvp, isatty};
|
||||||
|
@ -41,28 +39,26 @@ extern {
|
||||||
unsafe fn _vprocmgr_detach_from_console(_: u32) -> *const libc::c_int { std::ptr::null() }
|
unsafe fn _vprocmgr_detach_from_console(_: u32) -> *const libc::c_int { std::ptr::null() }
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let program = &args[0];
|
let mut opts = getopts::Options::new();
|
||||||
|
|
||||||
let options = [
|
opts.optflag("h", "help", "Show help and exit");
|
||||||
optflag("h", "help", "Show help and exit"),
|
opts.optflag("V", "version", "Show version and exit");
|
||||||
optflag("V", "version", "Show version and exit"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let opts = match getopts(&args[1..], &options) {
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
show_error!("{}", f);
|
show_error!("{}", f);
|
||||||
show_usage(program, &options);
|
show_usage(&opts);
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if opts.opt_present("V") { version(); return 0 }
|
if matches.opt_present("V") { println!("{} v{}", NAME, VERSION); return 0 }
|
||||||
if opts.opt_present("h") { show_usage(program, &options); return 0 }
|
if matches.opt_present("h") { show_usage(&opts); return 0 }
|
||||||
|
|
||||||
if opts.free.len() == 0 {
|
if matches.free.len() == 0 {
|
||||||
show_error!("Missing operand: COMMAND");
|
show_error!("Missing operand: COMMAND");
|
||||||
println!("Try `{} --help` for more information.", program);
|
println!("Try `{} --help` for more information.", NAME);
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
replace_fds();
|
replace_fds();
|
||||||
|
@ -71,8 +67,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
|
|
||||||
if unsafe { _vprocmgr_detach_from_console(0) } != std::ptr::null() { crash!(2, "Cannot detach from console")};
|
if unsafe { _vprocmgr_detach_from_console(0) } != std::ptr::null() { crash!(2, "Cannot detach from console")};
|
||||||
|
|
||||||
let cstrs : Vec<CString> = opts.free.iter().map(|x| CString::new(x.as_bytes()).unwrap()).collect();
|
let cstrs: Vec<CString> = matches.free.iter().map(|x| CString::new(x.as_bytes()).unwrap()).collect();
|
||||||
let mut args : Vec<*const c_char> = cstrs.iter().map(|s| s.as_ptr()).collect();
|
let mut args: Vec<*const c_char> = cstrs.iter().map(|s| s.as_ptr()).collect();
|
||||||
args.push(std::ptr::null());
|
args.push(std::ptr::null());
|
||||||
unsafe { execvp(args[0], args.as_mut_ptr())}
|
unsafe { execvp(args[0], args.as_mut_ptr())}
|
||||||
}
|
}
|
||||||
|
@ -136,21 +132,18 @@ fn find_stdout() -> File {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn version() {
|
fn show_usage(opts: &getopts::Options) {
|
||||||
println!("{} v{}", NAME, VERSION)
|
let msg = format!("{0} v{1}
|
||||||
}
|
|
||||||
|
|
||||||
fn show_usage(program: &str, options: &[getopts::OptGroup]) {
|
Usage:
|
||||||
version();
|
{0} COMMAND [ARG]...
|
||||||
println!("Usage:");
|
{0} OPTION
|
||||||
println!(" {} COMMAND [ARG]…", program);
|
|
||||||
println!(" {} OPTION", program);
|
Run COMMAND ignoring hangup signals.
|
||||||
println!("");
|
If standard input is terminal, it'll be replaced with /dev/null.
|
||||||
print!("{}", usage(
|
If standard output is terminal, it'll be appended to nohup.out instead,
|
||||||
"Run COMMAND ignoring hangup signals.\n\
|
or $HOME/nohup.out, if nohup.out open failed.
|
||||||
If standard input is terminal, it'll be replaced with /dev/null.\n\
|
If standard error is terminal, it'll be redirected to stdout.", NAME, VERSION);
|
||||||
If standard output is terminal, it'll be appended to nohup.out instead, \
|
|
||||||
or $HOME/nohup.out, if nohup.out open failed.\n\
|
print!("{}", opts.usage(&msg));
|
||||||
If standard error is terminal, it'll be redirected to stdout.", options)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "nproc"]
|
#![crate_name = "nproc"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -24,14 +23,14 @@ static VERSION : &'static str = "0.0.0";
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let opts = [
|
let mut opts = getopts::Options::new();
|
||||||
getopts::optflag("", "all", "print the number of cores available to the system"),
|
|
||||||
getopts::optopt("", "ignore", "ignore up to N cores", "N"),
|
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
|
||||||
getopts::optflag("V", "version", "output version information and exit"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
opts.optflag("", "all", "print the number of cores available to the system");
|
||||||
|
opts.optopt("", "ignore", "ignore up to N cores", "N");
|
||||||
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
|
|
||||||
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
show_error!("{}", err);
|
show_error!("{}", err);
|
||||||
|
@ -45,12 +44,14 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
println!("{} {}", NAME, VERSION);
|
let msg = format!("{0} {1}
|
||||||
println!("");
|
|
||||||
println!("Usage:");
|
Usage:
|
||||||
println!(" {} [OPTIONS]...", NAME);
|
{0} [OPTIONS]...
|
||||||
println!("");
|
|
||||||
print!("{}", getopts::usage("Print the number of cores available to the current process.", &opts));
|
Print the number of cores available to the current process.", NAME, VERSION);
|
||||||
|
|
||||||
|
print!("{}", opts.usage(&msg));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
43
src/od/od.rs
43
src/od/od.rs
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "od"]
|
#![crate_name = "od"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -21,28 +20,28 @@ use std::path::Path;
|
||||||
enum Radix { Decimal, Hexadecimal, Octal, Binary }
|
enum Radix { Decimal, Hexadecimal, Octal, Binary }
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let opts = [
|
let mut opts = getopts::Options::new();
|
||||||
getopts::optopt("A", "address-radix",
|
|
||||||
"Select the base in which file offsets are printed.", "RADIX"),
|
|
||||||
getopts::optopt("j", "skip-bytes",
|
|
||||||
"Skip bytes input bytes before formatting and writing.", "BYTES"),
|
|
||||||
getopts::optopt("N", "read-bytes",
|
|
||||||
"limit dump to BYTES input bytes", "BYTES"),
|
|
||||||
getopts::optopt("S", "strings",
|
|
||||||
("output strings of at least BYTES graphic chars. 3 is assumed when \
|
|
||||||
BYTES is not specified."),
|
|
||||||
"BYTES"),
|
|
||||||
getopts::optopt("t", "format", "select output format or formats", "TYPE"),
|
|
||||||
getopts::optflag("v", "output-duplicates", "do not use * to mark line suppression"),
|
|
||||||
getopts::optopt("w", "width",
|
|
||||||
("output BYTES bytes per output line. 32 is implied when BYTES is not \
|
|
||||||
specified."),
|
|
||||||
"BYTES"),
|
|
||||||
getopts::optflag("h", "help", "display this help and exit."),
|
|
||||||
getopts::optflag("", "version", "output version information and exit."),
|
|
||||||
];
|
|
||||||
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
opts.optopt("A", "address-radix",
|
||||||
|
"Select the base in which file offsets are printed.", "RADIX");
|
||||||
|
opts.optopt("j", "skip-bytes",
|
||||||
|
"Skip bytes input bytes before formatting and writing.", "BYTES");
|
||||||
|
opts.optopt("N", "read-bytes",
|
||||||
|
"limit dump to BYTES input bytes", "BYTES");
|
||||||
|
opts.optopt("S", "strings",
|
||||||
|
("output strings of at least BYTES graphic chars. 3 is assumed when \
|
||||||
|
BYTES is not specified."),
|
||||||
|
"BYTES");
|
||||||
|
opts.optopt("t", "format", "select output format or formats", "TYPE");
|
||||||
|
opts.optflag("v", "output-duplicates", "do not use * to mark line suppression");
|
||||||
|
opts.optopt("w", "width",
|
||||||
|
("output BYTES bytes per output line. 32 is implied when BYTES is not \
|
||||||
|
specified."),
|
||||||
|
"BYTES");
|
||||||
|
opts.optflag("h", "help", "display this help and exit.");
|
||||||
|
opts.optflag("", "version", "output version information and exit.");
|
||||||
|
|
||||||
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => panic!("Invalid options\n{}", f)
|
Err(f) => panic!("Invalid options\n{}", f)
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "paste"]
|
#![crate_name = "paste"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -26,25 +25,27 @@ static NAME: &'static str = "paste";
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let program = &args[0];
|
let mut opts = getopts::Options::new();
|
||||||
|
|
||||||
let opts = [
|
opts.optflag("s", "serial", "paste one file at a time instead of in parallel");
|
||||||
getopts::optflag("s", "serial", "paste one file at a time instead of in parallel"),
|
opts.optopt("d", "delimiters", "reuse characters from LIST instead of TABs", "LIST");
|
||||||
getopts::optopt("d", "delimiters", "reuse characters from LIST instead of TABs", "LIST"),
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
getopts::optflag("V", "version", "output version information and exit")
|
|
||||||
];
|
let matches = match opts.parse(&args[1..]) {
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(e) => crash!(1, "{}", e)
|
Err(e) => crash!(1, "{}", e)
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
println!("{} {}", NAME, VERSION);
|
let msg = format!("{0} {1}
|
||||||
println!("");
|
|
||||||
println!("Usage:");
|
Usage:
|
||||||
println!(" {0} [OPTION]... [FILE]...", program);
|
{0} [OPTION]... [FILE]...
|
||||||
println!("");
|
|
||||||
print!("{}", getopts::usage("Write lines consisting of the sequentially corresponding lines from each FILE, separated by TABs, to standard output.", &opts));
|
Write lines consisting of the sequentially corresponding lines from each
|
||||||
|
FILE, separated by TABs, to standard output.", NAME, VERSION);
|
||||||
|
print!("{}", opts.usage(&msg));
|
||||||
} else if matches.opt_present("version") {
|
} else if matches.opt_present("version") {
|
||||||
println!("{} {}", NAME, VERSION);
|
println!("{} {}", NAME, VERSION);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "printenv"]
|
#![crate_name = "printenv"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -23,31 +22,31 @@ use std::io::Write;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
static NAME: &'static str = "printenv";
|
static NAME: &'static str = "printenv";
|
||||||
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let program = args[0].clone();
|
let mut opts = getopts::Options::new();
|
||||||
let opts = [
|
opts.optflag("0", "null", "end each output line with 0 byte rather than newline");
|
||||||
getopts::optflag("0", "null", "end each output line with 0 byte rather than newline"),
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
getopts::optflag("V", "version", "output version information and exit"),
|
let matches = match opts.parse(&args[1..]) {
|
||||||
];
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
crash!(1, "Invalid options\n{}", f)
|
crash!(1, "Invalid options\n{}", f)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
println!("printenv 1.0.0");
|
let msg = format!("{0} {1}
|
||||||
println!("");
|
|
||||||
println!("Usage:");
|
Usage:
|
||||||
println!(" {0} [VARIABLE]... [OPTION]...", program);
|
{0} [VARIABLE]... [OPTION]...
|
||||||
println!("");
|
|
||||||
print!("{}", getopts::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", &opts));
|
Prints the given environment VARIABLE(s), otherwise prints them all.", NAME, VERSION);
|
||||||
|
print!("{}", opts.usage(&msg));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
println!("printenv 1.0.0");
|
println!("{} {}", NAME, VERSION);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
let mut separator = "\n";
|
let mut separator = "\n";
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "pwd"]
|
#![crate_name = "pwd"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -24,13 +23,12 @@ static NAME: &'static str = "pwd";
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let program = args[0].clone();
|
let mut opts = getopts::Options::new();
|
||||||
let opts = [
|
|
||||||
getopts::optflag("", "help", "display this help and exit"),
|
|
||||||
getopts::optflag("", "version", "output version information and exit"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
opts.optflag("", "help", "display this help and exit");
|
||||||
|
opts.optflag("", "version", "output version information and exit");
|
||||||
|
|
||||||
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
crash!(1, "Invalid options\n{}", f)
|
crash!(1, "Invalid options\n{}", f)
|
||||||
|
@ -38,14 +36,15 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
println!("pwd {}", VERSION);
|
let msg = format!("{0} {1}
|
||||||
println!("");
|
|
||||||
println!("Usage:");
|
Usage:
|
||||||
println!(" {0} [OPTION]...", program);
|
{0} [OPTION]...
|
||||||
println!("");
|
|
||||||
print!("{}", getopts::usage("Print the full filename of the current working directory.", &opts));
|
Print the full filename of the current working directory.", NAME, VERSION);
|
||||||
|
print!("{}", opts.usage(&msg));
|
||||||
} else if matches.opt_present("version") {
|
} else if matches.opt_present("version") {
|
||||||
println!("pwd version: {}", VERSION);
|
println!("{} version: {}", NAME, VERSION);
|
||||||
} else {
|
} else {
|
||||||
println!("{}", env::current_dir().unwrap().display());
|
println!("{}", env::current_dir().unwrap().display());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "rmdir"]
|
#![crate_name = "rmdir"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -13,27 +12,27 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use std::path::Path;
|
|
||||||
use std::io::Write;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
static NAME: &'static str = "rmdir";
|
static NAME: &'static str = "rmdir";
|
||||||
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let program = args[0].clone();
|
let mut opts = getopts::Options::new();
|
||||||
|
|
||||||
let opts = [
|
opts.optflag("", "ignore-fail-on-non-empty", "ignore each failure that is solely because a directory is non-empty");
|
||||||
getopts::optflag("", "ignore-fail-on-non-empty", "ignore each failure that is solely because a directory is non-empty"),
|
opts.optflag("p", "parents", "remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is similar to rmdir a/b/c a/b a");
|
||||||
getopts::optflag("p", "parents", "remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is similar to rmdir a/b/c a/b a"),
|
opts.optflag("v", "verbose", "output a diagnostic for every directory processed");
|
||||||
getopts::optflag("v", "verbose", "output a diagnostic for every directory processed"),
|
opts.optflag("h", "help", "print this help and exit");
|
||||||
getopts::optflag("h", "help", "print this help and exit"),
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
getopts::optflag("V", "version", "output version information and exit")
|
|
||||||
];
|
let matches = match opts.parse(&args[1..]) {
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
show_error!("{}", f);
|
show_error!("{}", f);
|
||||||
|
@ -42,17 +41,18 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
println!("rmdir 1.0.0");
|
let msg = format!("{0} {1}
|
||||||
println!("");
|
|
||||||
println!("Usage:");
|
Usage:
|
||||||
println!(" {0} [OPTION]... DIRECTORY...", program);
|
{0} [OPTION]... DIRECTORY...
|
||||||
println!("");
|
|
||||||
println!("{}", &getopts::usage("Remove the DIRECTORY(ies), if they are empty.", &opts)[..]);
|
Remove the DIRECTORY(ies), if they are empty.", NAME, VERSION);
|
||||||
|
print!("{}", opts.usage(&msg));
|
||||||
} else if matches.opt_present("version") {
|
} else if matches.opt_present("version") {
|
||||||
println!("rmdir 1.0.0");
|
println!("{} {}", NAME, VERSION);
|
||||||
} else if matches.free.is_empty() {
|
} else if matches.free.is_empty() {
|
||||||
show_error!("missing an argument");
|
show_error!("missing an argument");
|
||||||
show_error!("for help, try '{0} --help'", program);
|
show_error!("for help, try '{0} --help'", NAME);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
let ignore = matches.opt_present("ignore-fail-on-non-empty");
|
let ignore = matches.opt_present("ignore-fail-on-non-empty");
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "shuf"]
|
#![crate_name = "shuf"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -14,8 +13,8 @@ extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
|
||||||
use rand::read::ReadRng;
|
|
||||||
use rand::{Rng, ThreadRng};
|
use rand::{Rng, ThreadRng};
|
||||||
|
use rand::read::ReadRng;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write};
|
use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write};
|
||||||
use std::usize::MAX as MAX_USIZE;
|
use std::usize::MAX as MAX_USIZE;
|
||||||
|
@ -34,34 +33,33 @@ static NAME: &'static str = "shuf";
|
||||||
static VERSION: &'static str = "0.0.1";
|
static VERSION: &'static str = "0.0.1";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let opts = [
|
let mut opts = getopts::Options::new();
|
||||||
getopts::optflag("e", "echo", "treat each ARG as an input line"),
|
opts.optflag("e", "echo", "treat each ARG as an input line");
|
||||||
getopts::optopt("i", "input-range", "treat each number LO through HI as an input line", "LO-HI"),
|
opts.optopt("i", "input-range", "treat each number LO through HI as an input line", "LO-HI");
|
||||||
getopts::optopt("n", "head-count", "output at most COUNT lines", "COUNT"),
|
opts.optopt("n", "head-count", "output at most COUNT lines", "COUNT");
|
||||||
getopts::optopt("o", "output", "write result to FILE instead of standard output", "FILE"),
|
opts.optopt("o", "output", "write result to FILE instead of standard output", "FILE");
|
||||||
getopts::optopt("", "random-source", "get random bytes from FILE", "FILE"),
|
opts.optopt("", "random-source", "get random bytes from FILE", "FILE");
|
||||||
getopts::optflag("r", "repeat", "output lines can be repeated"),
|
opts.optflag("r", "repeat", "output lines can be repeated");
|
||||||
getopts::optflag("z", "zero-terminated", "end lines with 0 byte, not newline"),
|
opts.optflag("z", "zero-terminated", "end lines with 0 byte, not newline");
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
getopts::optflag("V", "version", "output version information and exit")
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
];
|
let mut matches = match opts.parse(&args[1..]) {
|
||||||
let mut matches = match getopts::getopts(&args[1..], &opts) {
|
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
crash!(1, "{}", f)
|
crash!(1, "{}", f)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
println!("{name} v{version}
|
let msg = format!("{0} v{1}
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
{prog} [OPTION]... [FILE]
|
{0} [OPTION]... [FILE]
|
||||||
{prog} -e [OPTION]... [ARG]...
|
{0} -e [OPTION]... [ARG]...
|
||||||
{prog} -i LO-HI [OPTION]...\n
|
{0} -i LO-HI [OPTION]...
|
||||||
{usage}
|
|
||||||
With no FILE, or when FILE is -, read standard input.",
|
Write a random permutation of the input lines to standard output.
|
||||||
name = NAME, version = VERSION, prog = &args[0][..],
|
With no FILE, or when FILE is -, read standard input.", NAME, VERSION);
|
||||||
usage = getopts::usage("Write a random permutation of the input lines to standard output.", &opts));
|
print!("{}", opts.usage(&msg));
|
||||||
} else if matches.opt_present("version") {
|
} else if matches.opt_present("version") {
|
||||||
println!("{} v{}", NAME, VERSION);
|
println!("{} v{}", NAME, VERSION);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "sleep"]
|
#![crate_name = "sleep"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -25,13 +24,13 @@ mod util;
|
||||||
mod time;
|
mod time;
|
||||||
|
|
||||||
static NAME: &'static str = "sleep";
|
static NAME: &'static str = "sleep";
|
||||||
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let opts = [
|
let mut opts = getopts::Options::new();
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
getopts::optflag("V", "version", "output version information and exit")
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
];
|
let matches = match opts.parse(&args[1..]) {
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
show_error!("{}", f);
|
show_error!("{}", f);
|
||||||
|
@ -40,23 +39,24 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
println!("sleep 1.0.0");
|
let msg = format!("{0} {1}
|
||||||
println!("");
|
|
||||||
println!("Usage:");
|
Usage:
|
||||||
println!(" {0} NUMBER[SUFFIX]", &args[0][..]);
|
{0} NUMBER[SUFFIX]
|
||||||
println!("or");
|
or
|
||||||
println!(" {0} OPTION", &args[0][..]);
|
{0} OPTION
|
||||||
println!("");
|
|
||||||
println!("{}", getopts::usage("Pause for NUMBER seconds. SUFFIX may be 's' for seconds (the default),
|
Pause for NUMBER seconds. SUFFIX may be 's' for seconds (the default),
|
||||||
'm' for minutes, 'h' for hours or 'd' for days. Unlike most implementations
|
'm' for minutes, 'h' for hours or 'd' for days. Unlike most implementations
|
||||||
that require NUMBER be an integer, here NUMBER may be an arbitrary floating
|
that require NUMBER be an integer, here NUMBER may be an arbitrary floating
|
||||||
point number. Given two or more arguments, pause for the amount of time
|
point number. Given two or more arguments, pause for the amount of time
|
||||||
specified by the sum of their values.", &opts));
|
specified by the sum of their values.", NAME, VERSION);
|
||||||
|
print!("{}", opts.usage(&msg));
|
||||||
} else if matches.opt_present("version") {
|
} else if matches.opt_present("version") {
|
||||||
println!("sleep 1.0.0");
|
println!("{} {}", NAME, VERSION);
|
||||||
} else if matches.free.is_empty() {
|
} else if matches.free.is_empty() {
|
||||||
show_error!("missing an argument");
|
show_error!("missing an argument");
|
||||||
show_error!("for help, try '{0} --help'", &args[0][..]);
|
show_error!("for help, try '{0} --help'", NAME);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
sleep(matches.free);
|
sleep(matches.free);
|
||||||
|
@ -79,5 +79,3 @@ fn sleep(args: Vec<String>) {
|
||||||
};
|
};
|
||||||
sleep_ms(sleep_dur);
|
sleep_ms(sleep_dur);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "sort"]
|
#![crate_name = "sort"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -29,35 +28,40 @@ use std::str::Chars;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
static NAME: &'static str = "sort";
|
static NAME: &'static str = "sort";
|
||||||
static VERSION: &'static str = "0.0.1";
|
static VERSION: &'static str = "0.0.1";
|
||||||
|
|
||||||
static DECIMAL_PT: char = '.';
|
static DECIMAL_PT: char = '.';
|
||||||
static THOUSANDS_SEP: char = ',';
|
static THOUSANDS_SEP: char = ',';
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let opts = [
|
let mut opts = getopts::Options::new();
|
||||||
getopts::optflag("n", "numeric-sort", "compare according to string numerical value"),
|
|
||||||
getopts::optflag("r", "reverse", "reverse the output"),
|
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
|
||||||
getopts::optflag("", "version", "output version information and exit"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
opts.optflag("n", "numeric-sort", "compare according to string numerical value");
|
||||||
|
opts.optflag("r", "reverse", "reverse the output");
|
||||||
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
|
opts.optflag("", "version", "output version information and exit");
|
||||||
|
|
||||||
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => crash!(1, "Invalid options\n{}", f)
|
Err(f) => crash!(1, "Invalid options\n{}", f)
|
||||||
};
|
};
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
println!("Usage: {0} [OPTION]... [FILE]...", args[0]);
|
let msg = format!("{0} {1}
|
||||||
println!("Write the sorted concatenation of all FILE(s) to standard output.");
|
|
||||||
println!("");
|
Usage:
|
||||||
print!("{}", getopts::usage("Mandatory arguments for long options are mandatory for short options too.", &opts));
|
{0} [OPTION]... [FILE]...
|
||||||
println!("");
|
|
||||||
println!("With no FILE, or when FILE is -, read standard input.");
|
Write the sorted concatenation of all FILE(s) to standard output.
|
||||||
|
|
||||||
|
Mandatory arguments for long options are mandatory for short options too.
|
||||||
|
|
||||||
|
With no FILE, or when FILE is -, read standard input.", NAME, VERSION);
|
||||||
|
print!("{}", opts.usage(&msg));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
println!("sort 1.0.0");
|
println!("{} {}", NAME, VERSION);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,4 +176,3 @@ fn open<'a>(path: &str) -> Option<(Box<Read + 'a>, bool)> {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "uutils"]
|
#![crate_name = "uutils"]
|
||||||
#![feature(rustc_private)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -10,8 +9,6 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern crate getopts;
|
|
||||||
|
|
||||||
@CRATES@
|
@CRATES@
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
@ -54,7 +51,6 @@ fn main() {
|
||||||
match umap.get(binary_as_util) {
|
match umap.get(binary_as_util) {
|
||||||
Some(&uumain) => {
|
Some(&uumain) => {
|
||||||
std::process::exit(uumain(args));
|
std::process::exit(uumain(args));
|
||||||
return
|
|
||||||
}
|
}
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
|
@ -67,7 +63,6 @@ fn main() {
|
||||||
} else {
|
} else {
|
||||||
println!("{}: applet not found", binary_as_util);
|
println!("{}: applet not found", binary_as_util);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// try first arg as util name.
|
// try first arg as util name.
|
||||||
|
@ -78,7 +73,6 @@ fn main() {
|
||||||
match umap.get(util) {
|
match umap.get(util) {
|
||||||
Some(&uumain) => {
|
Some(&uumain) => {
|
||||||
std::process::exit(uumain(args.clone()));
|
std::process::exit(uumain(args.clone()));
|
||||||
return
|
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
if &args[0][..] == "--help" {
|
if &args[0][..] == "--help" {
|
||||||
|
@ -88,22 +82,18 @@ fn main() {
|
||||||
match umap.get(util) {
|
match umap.get(util) {
|
||||||
Some(&uumain) => {
|
Some(&uumain) => {
|
||||||
std::process::exit(uumain(vec![util.to_string(), "--help".to_string()]));
|
std::process::exit(uumain(vec![util.to_string(), "--help".to_string()]));
|
||||||
return
|
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
println!("{}: applet not found", util);
|
println!("{}: applet not found", util);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
usage(&umap);
|
usage(&umap);
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
return
|
|
||||||
} else {
|
} else {
|
||||||
println!("{}: applet not found", util);
|
println!("{}: applet not found", util);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,6 +101,5 @@ fn main() {
|
||||||
// no arguments provided
|
// no arguments provided
|
||||||
usage(&umap);
|
usage(&umap);
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue