mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Merge pull request #289 from Arcterus/gitmodules-update
Assorted fixes and improvements
This commit is contained in:
commit
0b89885199
4 changed files with 148 additions and 45 deletions
2
.gitmodules
vendored
2
.gitmodules
vendored
|
@ -1,3 +1,3 @@
|
||||||
[submodule "md5sum/rust-crypto"]
|
[submodule "deps/rust-crypto"]
|
||||||
path = deps/rust-crypto
|
path = deps/rust-crypto
|
||||||
url = git://github.com/DaGenix/rust-crypto.git
|
url = git://github.com/DaGenix/rust-crypto.git
|
||||||
|
|
10
Makefile
10
Makefile
|
@ -100,14 +100,14 @@ command = sh -c '$(1)'
|
||||||
define EXE_BUILD
|
define EXE_BUILD
|
||||||
-include build/$(1).d
|
-include build/$(1).d
|
||||||
|
|
||||||
build/$(1): $(1)/$(1).rs deps | build
|
build/$(1): $(1)/$(1).rs | build deps
|
||||||
$(call command,$(RUSTC) $(RUSTCFLAGS) -L build/ --dep-info build/$(1).d -o build/$(1) $(1)/$(1).rs)
|
$(call command,$(RUSTC) $(RUSTCFLAGS) -L build/ --dep-info build/$(1).d -o build/$(1) $(1)/$(1).rs)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define CRATE_BUILD
|
define CRATE_BUILD
|
||||||
-include build/$(1).d
|
-include build/$(1).d
|
||||||
|
|
||||||
build/$(2): $(1)/$(1).rs deps | build
|
build/$(2): $(1)/$(1).rs | build deps
|
||||||
$(call command,$(RUSTC) $(RUSTCFLAGS) -L build/ --crate-type rlib --dep-info build/$(1).d $(1)/$(1).rs --out-dir build)
|
$(call command,$(RUSTC) $(RUSTCFLAGS) -L build/ --crate-type rlib --dep-info build/$(1).d $(1)/$(1).rs --out-dir build)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
@ -122,9 +122,9 @@ endef
|
||||||
|
|
||||||
# Main rules
|
# Main rules
|
||||||
ifneq ($(MULTICALL), 1)
|
ifneq ($(MULTICALL), 1)
|
||||||
all: deps $(EXES_PATHS)
|
all: $(EXES_PATHS)
|
||||||
else
|
else
|
||||||
all: deps build/uutils
|
all: build/uutils
|
||||||
|
|
||||||
-include build/uutils.d
|
-include build/uutils.d
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ endif
|
||||||
# Dependencies
|
# Dependencies
|
||||||
LIBCRYPTO = $(shell $(RUSTC) --crate-file-name --crate-type rlib deps/rust-crypto/src/rust-crypto/lib.rs)
|
LIBCRYPTO = $(shell $(RUSTC) --crate-file-name --crate-type rlib deps/rust-crypto/src/rust-crypto/lib.rs)
|
||||||
-include build/rust-crypto.d
|
-include build/rust-crypto.d
|
||||||
build/$(LIBCRYPTO): build
|
build/$(LIBCRYPTO): | build
|
||||||
$(RUSTC) $(RUSTCFLAGS) --crate-type rlib --dep-info build/rust-crypto.d deps/rust-crypto/src/rust-crypto/lib.rs --out-dir build/
|
$(RUSTC) $(RUSTCFLAGS) --crate-type rlib --dep-info build/rust-crypto.d deps/rust-crypto/src/rust-crypto/lib.rs --out-dir build/
|
||||||
|
|
||||||
deps: build/$(LIBCRYPTO)
|
deps: build/$(LIBCRYPTO)
|
||||||
|
|
|
@ -96,7 +96,7 @@ fn parse_options(args: Vec<String>, options: &mut EchoOptions) -> Option<Vec<Str
|
||||||
"-e" => options.escape = true,
|
"-e" => options.escape = true,
|
||||||
"-E" => options.escape = false,
|
"-E" => options.escape = false,
|
||||||
_ => {
|
_ => {
|
||||||
if arg.as_slice().char_at(0) == '-' && arg.len() > 1 {
|
if arg.len() > 1 && arg.as_slice().char_at(0) == '-' {
|
||||||
let mut newopts = options.clone();
|
let mut newopts = options.clone();
|
||||||
let argptr: *String = &arg; // escape from the borrow checker
|
let argptr: *String = &arg; // escape from the borrow checker
|
||||||
for ch in unsafe { (*argptr).as_slice() }.chars().skip(1) {
|
for ch in unsafe { (*argptr).as_slice() }.chars().skip(1) {
|
||||||
|
|
179
seq/seq.rs
179
seq/seq.rs
|
@ -15,13 +15,14 @@ mod util;
|
||||||
|
|
||||||
static NAME: &'static str = "seq";
|
static NAME: &'static str = "seq";
|
||||||
|
|
||||||
fn print_usage(opts: &[getopts::OptGroup]) {
|
#[deriving(Clone)]
|
||||||
println!("seq 1.0.0\n");
|
struct SeqOptions {
|
||||||
println!("Usage:\n seq [-w] [-s string] [-t string] [first [step]] last\n");
|
separator: String,
|
||||||
println!("{:s}", getopts::usage("Print sequences of numbers", opts));
|
terminator: Option<String>,
|
||||||
|
widths: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_float(s: &str) -> Result<f32, String>{
|
fn parse_float(s: &str) -> Result<f64, String>{
|
||||||
match from_str(s) {
|
match from_str(s) {
|
||||||
Some(n) => Ok(n),
|
Some(n) => Ok(n),
|
||||||
None => Err(format!("seq: invalid floating point argument: {:s}", s))
|
None => Err(format!("seq: invalid floating point argument: {:s}", s))
|
||||||
|
@ -33,10 +34,99 @@ fn escape_sequences(s: &str) -> String {
|
||||||
replace("\\t", "\t")
|
replace("\\t", "\t")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
fn parse_options(args: Vec<String>, options: &mut SeqOptions) -> Result<Vec<String>, int> {
|
||||||
fn main() { os::set_exit_status(uumain(os::args())); }
|
let mut seq_args = vec!();
|
||||||
|
let program = args.get(0).clone();
|
||||||
|
let mut iter = args.move_iter().skip(1);
|
||||||
|
loop {
|
||||||
|
match iter.next() {
|
||||||
|
Some(arg) => match arg.as_slice() {
|
||||||
|
"--help" | "-h" => {
|
||||||
|
print_help(&program);
|
||||||
|
return Err(0);
|
||||||
|
}
|
||||||
|
"--version" | "-V" => {
|
||||||
|
print_version();
|
||||||
|
return Err(0);
|
||||||
|
}
|
||||||
|
"-s" | "--separator" => match iter.next() {
|
||||||
|
Some(sep) => options.separator = sep,
|
||||||
|
None => {
|
||||||
|
show_error!("expected a separator after {}", arg);
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"-t" | "--terminator" => match iter.next() {
|
||||||
|
Some(term) => options.terminator = Some(term),
|
||||||
|
None => {
|
||||||
|
show_error!("expected a terminator after '{}'", arg);
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"-w" | "--widths" => options.widths = true,
|
||||||
|
"--" => {
|
||||||
|
seq_args.push_all_move(iter.collect());
|
||||||
|
break;
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
if arg.len() > 1 && arg.as_slice().char_at(0) == '-' {
|
||||||
|
let argptr: *String = &arg; // escape from the borrow checker
|
||||||
|
let mut chiter = unsafe { (*argptr).as_slice() }.chars().skip(1);
|
||||||
|
let mut ch = ' ';
|
||||||
|
while match chiter.next() { Some(m) => { ch = m; true } None => false } {
|
||||||
|
match ch {
|
||||||
|
'h' => {
|
||||||
|
print_help(&program);
|
||||||
|
return Err(0);
|
||||||
|
}
|
||||||
|
'V' => {
|
||||||
|
print_version();
|
||||||
|
return Err(0);
|
||||||
|
}
|
||||||
|
's' => match iter.next() {
|
||||||
|
Some(sep) => {
|
||||||
|
options.separator = sep;
|
||||||
|
let next = chiter.next();
|
||||||
|
if next.is_some() {
|
||||||
|
show_error!("unexpected character ('{}')", next.unwrap());
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
show_error!("expected a separator after {}", arg);
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
't' => match iter.next() {
|
||||||
|
Some(term) => {
|
||||||
|
options.terminator = Some(term);
|
||||||
|
let next = chiter.next();
|
||||||
|
if next.is_some() {
|
||||||
|
show_error!("unexpected character ('{}')", next.unwrap());
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
show_error!("expected a terminator after {}", arg);
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'w' => options.widths = true,
|
||||||
|
_ => { seq_args.push(arg); break }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
seq_args.push(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(seq_args)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> int {
|
fn print_help(program: &String) {
|
||||||
let opts = [
|
let opts = [
|
||||||
getopts::optopt("s", "separator", "Separator character (defaults to \\n)", ""),
|
getopts::optopt("s", "separator", "Separator character (defaults to \\n)", ""),
|
||||||
getopts::optopt("t", "terminator", "Terminator character (defaults to separator)", ""),
|
getopts::optopt("t", "terminator", "Terminator character (defaults to separator)", ""),
|
||||||
|
@ -44,62 +134,73 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
getopts::optflag("h", "help", "print this help text and exit"),
|
getopts::optflag("h", "help", "print this help text and exit"),
|
||||||
getopts::optflag("V", "version", "print version and exit"),
|
getopts::optflag("V", "version", "print version and exit"),
|
||||||
];
|
];
|
||||||
let matches = match getopts::getopts(args.tail(), opts) {
|
println!("seq 1.0.0\n");
|
||||||
Ok(m) => { m }
|
println!("Usage:\n {} [-w] [-s string] [-t string] [first [step]] last\n", *program);
|
||||||
Err(f) => {
|
println!("{:s}", getopts::usage("Print sequences of numbers", opts));
|
||||||
show_error!("{}", f);
|
}
|
||||||
print_usage(opts);
|
|
||||||
return 1;
|
fn print_version() {
|
||||||
}
|
println!("seq 1.0.0\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn main() { os::set_exit_status(uumain(os::args())); }
|
||||||
|
|
||||||
|
pub fn uumain(args: Vec<String>) -> int {
|
||||||
|
let program = args.get(0).clone();
|
||||||
|
let mut options = SeqOptions {
|
||||||
|
separator: "\n".to_string(),
|
||||||
|
terminator: None,
|
||||||
|
widths: false
|
||||||
};
|
};
|
||||||
if matches.opt_present("help") {
|
let free = match parse_options(args, &mut options) {
|
||||||
print_usage(opts);
|
Ok(m) => m,
|
||||||
return 0;
|
Err(f) => return f
|
||||||
|
};
|
||||||
|
if free.len() < 1 || free.len() > 3 {
|
||||||
|
crash!(1, "too {} operands.\nTry '{} --help' for more information.",
|
||||||
|
if free.len() < 1 { "few" } else { "many" }, program);
|
||||||
}
|
}
|
||||||
if matches.opt_present("version") {
|
let first = if free.len() > 1 {
|
||||||
println!("seq 1.0.0");
|
match parse_float(free.get(0).as_slice()) {
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if matches.free.len() < 1 || matches.free.len() > 3 {
|
|
||||||
print_usage(opts);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
let first = if matches.free.len() > 1 {
|
|
||||||
match parse_float(matches.free.get(0).as_slice()) {
|
|
||||||
Ok(n) => n,
|
Ok(n) => n,
|
||||||
Err(s) => { show_error!("{:s}", s); return 1; }
|
Err(s) => { show_error!("{:s}", s); return 1; }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
1.0
|
1.0
|
||||||
};
|
};
|
||||||
let step = if matches.free.len() > 2 {
|
let step = if free.len() > 2 {
|
||||||
match parse_float(matches.free.get(1).as_slice()) {
|
match parse_float(free.get(1).as_slice()) {
|
||||||
Ok(n) => n,
|
Ok(n) => n,
|
||||||
Err(s) => { show_error!("{:s}", s); return 1; }
|
Err(s) => { show_error!("{:s}", s); return 1; }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
1.0
|
1.0
|
||||||
};
|
};
|
||||||
let last = match parse_float(matches.free.get(matches.free.len()-1).as_slice()) {
|
let last = match parse_float(free.get(free.len()-1).as_slice()) {
|
||||||
Ok(n) => n,
|
Ok(n) => n,
|
||||||
Err(s) => { show_error!("{:s}", s); return 1; }
|
Err(s) => { show_error!("{:s}", s); return 1; }
|
||||||
};
|
};
|
||||||
let separator = escape_sequences(matches.opt_str("s").unwrap_or("\n".to_string()).as_slice());
|
let separator = escape_sequences(options.separator.as_slice());
|
||||||
let terminator = escape_sequences(matches.opt_str("t").unwrap_or(separator.to_string()).as_slice());
|
let terminator = match options.terminator {
|
||||||
print_seq(first, step, last, separator, terminator, matches.opt_present("w"));
|
Some(term) => escape_sequences(term.as_slice()),
|
||||||
|
None => separator.clone()
|
||||||
|
};
|
||||||
|
print_seq(first, step, last, separator, terminator, options.widths);
|
||||||
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn done_printing(next: f32, step: f32, last: f32) -> bool {
|
#[inline(always)]
|
||||||
if step > 0f32 {
|
fn done_printing(next: f64, step: f64, last: f64) -> bool {
|
||||||
|
if step > 0f64 {
|
||||||
next > last
|
next > last
|
||||||
} else {
|
} else {
|
||||||
next < last
|
next < last
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_seq(first: f32, step: f32, last: f32, separator: String, terminator: String, pad: bool) {
|
fn print_seq(first: f64, step: f64, last: f64, separator: String, terminator: String, pad: bool) {
|
||||||
let mut i = first;
|
let mut i = first;
|
||||||
let maxlen = first.max(last).to_str().len();
|
let maxlen = first.max(last).to_str().len();
|
||||||
while !done_printing(i, step, last) {
|
while !done_printing(i, step, last) {
|
||||||
|
@ -115,5 +216,7 @@ fn print_seq(first: f32, step: f32, last: f32, separator: String, terminator: St
|
||||||
print!("{:s}", separator);
|
print!("{:s}", separator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print!("{:s}", terminator);
|
if i != first {
|
||||||
|
print!("{:s}", terminator);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue