mirror of
https://github.com/uutils/coreutils
synced 2024-12-16 08:12:39 +00:00
Merge pull request #438 from ebfe/fix-build-master
shuf, comm: fix build
This commit is contained in:
commit
714f94d066
2 changed files with 37 additions and 9 deletions
|
@ -14,7 +14,7 @@ extern crate getopts;
|
||||||
use std::cmp::Ord;
|
use std::cmp::Ord;
|
||||||
use std::io::{BufferedReader, IoResult, print};
|
use std::io::{BufferedReader, IoResult, print};
|
||||||
use std::io::fs::File;
|
use std::io::fs::File;
|
||||||
use std::io::stdio::stdin;
|
use std::io::stdio::{stdin, StdReader};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
static NAME : &'static str = "comm";
|
static NAME : &'static str = "comm";
|
||||||
|
@ -44,7 +44,21 @@ fn ensure_nl(line: String) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn comm(a: &mut Box<Buffer>, b: &mut Box<Buffer>, opts: &getopts::Matches) {
|
enum LineReader {
|
||||||
|
Stdin(BufferedReader<StdReader>),
|
||||||
|
FileIn(BufferedReader<File>)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LineReader {
|
||||||
|
fn read_line(&mut self) -> IoResult<String> {
|
||||||
|
match self {
|
||||||
|
&Stdin(ref mut r) => r.read_line(),
|
||||||
|
&FileIn(ref mut r) => r.read_line(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn comm(a: &mut LineReader, b: &mut LineReader, opts: &getopts::Matches) {
|
||||||
|
|
||||||
let delim = Vec::from_fn(4, |col| mkdelim(col, opts));
|
let delim = Vec::from_fn(4, |col| mkdelim(col, opts));
|
||||||
|
|
||||||
|
@ -83,12 +97,12 @@ fn comm(a: &mut Box<Buffer>, b: &mut Box<Buffer>, opts: &getopts::Matches) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_file(name: &str) -> IoResult<Box<Buffer>> {
|
fn open_file(name: &str) -> IoResult<LineReader> {
|
||||||
match name {
|
match name {
|
||||||
"-" => Ok(box stdin() as Box<Buffer>),
|
"-" => Ok(LineReader::Stdin(stdin())),
|
||||||
_ => {
|
_ => {
|
||||||
let f = try!(File::open(&Path::new(name)));
|
let f = try!(std::io::File::open(&Path::new(name)));
|
||||||
Ok(box BufferedReader::new(f) as Box<Buffer>)
|
Ok(LineReader::FileIn(BufferedReader::new(f)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ use std::from_str::from_str;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::IoResult;
|
use std::io::IoResult;
|
||||||
use std::iter::{range_inclusive, RangeInclusive};
|
use std::iter::{range_inclusive, RangeInclusive};
|
||||||
use std::rand;
|
use std::rand::{mod, Rng};
|
||||||
use std::uint;
|
use std::uint;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
|
@ -151,14 +151,28 @@ fn shuf(input: Vec<String>, mode: Mode, repeat: bool, zero: bool, count: uint, o
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum WrappedRng {
|
||||||
|
RngFile(rand::reader::ReaderRng<io::File>),
|
||||||
|
RngDefault(rand::TaskRng),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WrappedRng {
|
||||||
|
fn next_u32(&mut self) -> u32 {
|
||||||
|
match self {
|
||||||
|
&RngFile(ref mut r) => r.next_u32(),
|
||||||
|
&RngDefault(ref mut r) => r.next_u32(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn shuf_lines(mut lines: Vec<String>, repeat: bool, zero: bool, count: uint, outname: Option<String>, random: Option<String>) -> IoResult<()> {
|
fn shuf_lines(mut lines: Vec<String>, repeat: bool, zero: bool, count: uint, outname: Option<String>, random: Option<String>) -> IoResult<()> {
|
||||||
let mut output = match outname {
|
let mut output = match outname {
|
||||||
Some(name) => box io::BufferedWriter::new(try!(io::File::create(&Path::new(name)))) as Box<Writer>,
|
Some(name) => box io::BufferedWriter::new(try!(io::File::create(&Path::new(name)))) as Box<Writer>,
|
||||||
None => box io::stdout() as Box<Writer>
|
None => box io::stdout() as Box<Writer>
|
||||||
};
|
};
|
||||||
let mut rng = match random {
|
let mut rng = match random {
|
||||||
Some(name) => box rand::reader::ReaderRng::new(try!(io::File::open(&Path::new(name)))) as Box<rand::Rng>,
|
Some(name) => RngFile(rand::reader::ReaderRng::new(try!(io::File::open(&Path::new(name))))),
|
||||||
None => box rand::task_rng() as Box<rand::Rng>
|
None => RngDefault(rand::task_rng()),
|
||||||
};
|
};
|
||||||
let mut len = lines.len();
|
let mut len = lines.len();
|
||||||
let max = if repeat { count } else { cmp::min(count, len) };
|
let max = if repeat { count } else { cmp::min(count, len) };
|
||||||
|
|
Loading…
Reference in a new issue