mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 01:38:04 +00:00
commit
5766a0f6eb
1 changed files with 16 additions and 37 deletions
|
@ -22,7 +22,7 @@ use std::io::{IoResult};
|
|||
use std::ptr::{copy_nonoverlapping_memory};
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> isize {
|
||||
let program = args[0].as_slice();
|
||||
let program = &args[0];
|
||||
let opts = [
|
||||
getopts::optflag("A", "show-all", "equivalent to -vET"),
|
||||
getopts::optflag("b", "number-nonblank",
|
||||
|
@ -48,8 +48,8 @@ pub fn uumain(args: Vec<String>) -> isize {
|
|||
println!("Usage:");
|
||||
println!(" {0} [OPTION]... [FILE]...", program);
|
||||
println!("");
|
||||
print(getopts::usage("Concatenate FILE(s), or standard input, to \
|
||||
standard output.", &opts).as_slice());
|
||||
print(&getopts::usage("Concatenate FILE(s), or standard input, to \
|
||||
standard output.", &opts)[]);
|
||||
println!("");
|
||||
println!("With no FILE, or when FILE is -, read standard input.");
|
||||
return 0;
|
||||
|
@ -95,21 +95,15 @@ fn write_lines(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
|
|||
|
||||
let mut line_counter: usize = 1;
|
||||
|
||||
for path in files.iter() {
|
||||
let (mut reader, interactive) = match open(path.as_slice()) {
|
||||
Some(f) => f,
|
||||
None => continue,
|
||||
};
|
||||
for (mut reader, interactive) in files.iter().filter_map(|p| open(&p[])) {
|
||||
|
||||
let mut in_buf = [0; 1024 * 31];
|
||||
let mut out_buf = [0; 1024 * 64];
|
||||
let mut writer = UnsafeWriter::new(out_buf.as_mut_slice(), stdout_raw());
|
||||
let mut at_line_start = true;
|
||||
loop {
|
||||
let n = match reader.read(&mut in_buf) {
|
||||
Ok(n) if n != 0 => n,
|
||||
_ => break,
|
||||
};
|
||||
while let Ok(n) = reader.read(&mut in_buf) {
|
||||
if n == 0 { break }
|
||||
|
||||
let in_buf = &in_buf[..n];
|
||||
let mut buf_pos = range(0, n);
|
||||
loop {
|
||||
|
@ -168,11 +162,7 @@ fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
|
|||
|
||||
let mut line_counter: usize = 1;
|
||||
|
||||
for path in files.iter() {
|
||||
let (mut reader, interactive) = match open(path.as_slice()) {
|
||||
Some(f) => f,
|
||||
None => continue,
|
||||
};
|
||||
for (mut reader, interactive) in files.iter().filter_map(|p| open(&p[])) {
|
||||
|
||||
// Flush all 1024 iterations.
|
||||
let mut flush_counter = range(0us, 1024);
|
||||
|
@ -181,11 +171,9 @@ fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
|
|||
let mut out_buf = [0; 1024 * 64];
|
||||
let mut writer = UnsafeWriter::new(out_buf.as_mut_slice(), stdout_raw());
|
||||
let mut at_line_start = true;
|
||||
loop {
|
||||
let n = match reader.read(&mut in_buf) {
|
||||
Ok(n) if n != 0 => n,
|
||||
_ => break,
|
||||
};
|
||||
while let Ok(n) = reader.read(&mut in_buf) {
|
||||
if n == 0 { break }
|
||||
|
||||
for &byte in in_buf[..n].iter() {
|
||||
if flush_counter.next().is_none() {
|
||||
writer.possibly_flush();
|
||||
|
@ -246,20 +234,11 @@ fn write_fast(files: Vec<String>) {
|
|||
let mut writer = stdout_raw();
|
||||
let mut in_buf = [0; 1024 * 64];
|
||||
|
||||
for path in files.iter() {
|
||||
let (mut reader, _) = match open(path.as_slice()) {
|
||||
Some(x) => x,
|
||||
None => continue,
|
||||
};
|
||||
|
||||
loop {
|
||||
match reader.read(&mut in_buf) {
|
||||
Ok(n) if n != 0 => {
|
||||
// This interface is completely broken.
|
||||
writer.write(&in_buf[..n]).unwrap();
|
||||
},
|
||||
_ => break
|
||||
}
|
||||
for (mut reader, _) in files.iter().filter_map(|p| open(&p[])) {
|
||||
while let Ok(n) = reader.read(&mut in_buf) {
|
||||
if n == 0 { break }
|
||||
// This interface is completely broken.
|
||||
writer.write(&in_buf[..n]).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue