mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 20:17:45 +00:00
seq: fix broken pipe on Busybox test
This commit is contained in:
parent
d160c37d23
commit
3f06adfcbc
1 changed files with 21 additions and 6 deletions
27
seq/seq.rs
27
seq/seq.rs
|
@ -9,6 +9,7 @@ extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
use std::io;
|
||||||
use std::os;
|
use std::os;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
|
@ -16,6 +17,20 @@ mod util;
|
||||||
|
|
||||||
static NAME: &'static str = "seq";
|
static NAME: &'static str = "seq";
|
||||||
|
|
||||||
|
macro_rules! pipe_write(
|
||||||
|
($($args:expr),+) => (
|
||||||
|
match write!(&mut io::stdout() as &mut Writer, $($args),+) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(f) =>
|
||||||
|
if f.kind == io::BrokenPipe {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
fail!("{}", f.to_str())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
struct SeqOptions {
|
struct SeqOptions {
|
||||||
separator: String,
|
separator: String,
|
||||||
|
@ -226,27 +241,27 @@ fn print_seq(first: f64, step: f64, last: f64, largest_dec: uint, separator: Str
|
||||||
let before_dec = istr.as_slice().find('.').unwrap_or(ilen);
|
let before_dec = istr.as_slice().find('.').unwrap_or(ilen);
|
||||||
if pad && before_dec < padding {
|
if pad && before_dec < padding {
|
||||||
for _ in range(0, padding - before_dec) {
|
for _ in range(0, padding - before_dec) {
|
||||||
print!("0");
|
pipe_write!("0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print!("{}", istr);
|
pipe_write!("{}", istr);
|
||||||
let mut idec = ilen - before_dec;
|
let mut idec = ilen - before_dec;
|
||||||
if idec < largest_dec {
|
if idec < largest_dec {
|
||||||
if idec == 0 {
|
if idec == 0 {
|
||||||
print!(".");
|
pipe_write!(".");
|
||||||
idec += 1;
|
idec += 1;
|
||||||
}
|
}
|
||||||
for _ in range(idec, largest_dec) {
|
for _ in range(idec, largest_dec) {
|
||||||
print!("0")
|
pipe_write!("0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
value = first + i as f64 * step;
|
value = first + i as f64 * step;
|
||||||
if !done_printing(value, step, last) {
|
if !done_printing(value, step, last) {
|
||||||
print!("{:s}", separator);
|
pipe_write!("{:s}", separator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (first >= last && step < 0f64) || (first <= last && step > 0f64) {
|
if (first >= last && step < 0f64) || (first <= last && step > 0f64) {
|
||||||
print!("{:s}", terminator);
|
pipe_write!("{:s}", terminator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue