mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
join: do not wrap stdin in BufReader
This commit is contained in:
parent
3aa63ad9dd
commit
d28e09de04
1 changed files with 14 additions and 10 deletions
|
@ -15,7 +15,7 @@ extern crate getopts;
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader, Lines, Read, stdin};
|
use std::io::{BufRead, BufReader, Lines, Stdin, stdin};
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
static NAME: &'static str = "join";
|
static NAME: &'static str = "join";
|
||||||
|
@ -77,20 +77,20 @@ impl Line {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct State {
|
struct State<'a> {
|
||||||
key: usize,
|
key: usize,
|
||||||
print_unpaired: bool,
|
print_unpaired: bool,
|
||||||
lines: Lines<BufReader<Box<Read>>>,
|
lines: Lines<Box<BufRead + 'a>>,
|
||||||
seq: Vec<Line>,
|
seq: Vec<Line>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl<'a> State<'a> {
|
||||||
fn new(name: &str, key: usize, print_unpaired: bool) -> State {
|
fn new(name: &str, stdin: &'a Stdin, key: usize, print_unpaired: bool) -> State<'a> {
|
||||||
let f: Box<Read> = if name == "-" {
|
let f = if name == "-" {
|
||||||
Box::new(stdin()) as Box<Read>
|
Box::new(stdin.lock()) as Box<BufRead>
|
||||||
} else {
|
} else {
|
||||||
match File::open(name) {
|
match File::open(name) {
|
||||||
Ok(file) => Box::new(file) as Box<Read>,
|
Ok(file) => Box::new(BufReader::new(file)) as Box<BufRead>,
|
||||||
Err(err) => crash!(1, "{}: {}", name, err),
|
Err(err) => crash!(1, "{}: {}", name, err),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -98,7 +98,7 @@ impl State {
|
||||||
State {
|
State {
|
||||||
key: key,
|
key: key,
|
||||||
print_unpaired: print_unpaired,
|
print_unpaired: print_unpaired,
|
||||||
lines: BufReader::new(f).lines(),
|
lines: f.lines(),
|
||||||
seq: Vec::new(),
|
seq: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ impl State {
|
||||||
fn next_line(&mut self) {
|
fn next_line(&mut self) {
|
||||||
match self.read_line() {
|
match self.read_line() {
|
||||||
Some(line) => self.seq[0] = line,
|
Some(line) => self.seq[0] = line,
|
||||||
None => self.seq.clear()
|
None => self.seq.clear(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,14 +282,18 @@ standard output. The default join field is the first, delimited by blanks.",
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(files: Vec<String>, settings: &Settings) -> i32 {
|
fn exec(files: Vec<String>, settings: &Settings) -> i32 {
|
||||||
|
let stdin = stdin();
|
||||||
|
|
||||||
let mut state1 = State::new(
|
let mut state1 = State::new(
|
||||||
&files[0],
|
&files[0],
|
||||||
|
&stdin,
|
||||||
settings.key1,
|
settings.key1,
|
||||||
settings.print_unpaired == FileNum::File1,
|
settings.print_unpaired == FileNum::File1,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut state2 = State::new(
|
let mut state2 = State::new(
|
||||||
&files[1],
|
&files[1],
|
||||||
|
&stdin,
|
||||||
settings.key2,
|
settings.key2,
|
||||||
settings.print_unpaired == FileNum::File2,
|
settings.print_unpaired == FileNum::File2,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue