1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

Merge pull request #301 from Arcterus/seq-broken-pipe

seq: fix broken pipe on Busybox test
This commit is contained in:
Oly Mi 2014-06-23 21:48:08 +04:00
commit f5dfa0a9b9

View file

@ -9,6 +9,7 @@ extern crate getopts;
extern crate libc;
use std::cmp;
use std::io;
use std::os;
#[path = "../common/util.rs"]
@ -16,6 +17,20 @@ mod util;
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)]
struct SeqOptions {
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);
if pad && before_dec < padding {
for _ in range(0, padding - before_dec) {
print!("0");
pipe_write!("0");
}
}
print!("{}", istr);
pipe_write!("{}", istr);
let mut idec = ilen - before_dec;
if idec < largest_dec {
if idec == 0 {
print!(".");
pipe_write!(".");
idec += 1;
}
for _ in range(idec, largest_dec) {
print!("0")
pipe_write!("0")
}
}
i += 1;
value = first + i as f64 * step;
if !done_printing(value, step, last) {
print!("{:s}", separator);
pipe_write!("{:s}", separator);
}
}
if (first >= last && step < 0f64) || (first <= last && step > 0f64) {
print!("{:s}", terminator);
pipe_write!("{:s}", terminator);
}
}