mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge branch 'main' into join-null-field-sep
This commit is contained in:
commit
08efa1fe5a
8 changed files with 55 additions and 12 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1361,9 +1361,9 @@ checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pretty_assertions"
|
name = "pretty_assertions"
|
||||||
version = "0.7.2"
|
version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1cab0e7c02cf376875e9335e0ba1da535775beb5450d21e1dffca068818ed98b"
|
checksum = "ec0cfe1b2403f172ba0f234e500906ee0a3e493fb81092dac23ebefe129301cc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term",
|
"ansi_term",
|
||||||
"ctor",
|
"ctor",
|
||||||
|
|
|
@ -328,7 +328,6 @@ sleep = { optional=true, version="0.0.9", package="uu_sleep", path="src/uu/sl
|
||||||
sort = { optional=true, version="0.0.9", package="uu_sort", path="src/uu/sort" }
|
sort = { optional=true, version="0.0.9", package="uu_sort", path="src/uu/sort" }
|
||||||
split = { optional=true, version="0.0.9", package="uu_split", path="src/uu/split" }
|
split = { optional=true, version="0.0.9", package="uu_split", path="src/uu/split" }
|
||||||
stat = { optional=true, version="0.0.9", package="uu_stat", path="src/uu/stat" }
|
stat = { optional=true, version="0.0.9", package="uu_stat", path="src/uu/stat" }
|
||||||
# Very ugly, uncomment when the issue #2876 is fixed
|
|
||||||
stdbuf = { optional=true, version="0.0.9", package="uu_stdbuf", path="src/uu/stdbuf" }
|
stdbuf = { optional=true, version="0.0.9", package="uu_stdbuf", path="src/uu/stdbuf" }
|
||||||
sum = { optional=true, version="0.0.9", package="uu_sum", path="src/uu/sum" }
|
sum = { optional=true, version="0.0.9", package="uu_sum", path="src/uu/sum" }
|
||||||
sync = { optional=true, version="0.0.9", package="uu_sync", path="src/uu/sync" }
|
sync = { optional=true, version="0.0.9", package="uu_sync", path="src/uu/sync" }
|
||||||
|
@ -362,12 +361,12 @@ yes = { optional=true, version="0.0.9", package="uu_yes", path="src/uu/yes"
|
||||||
#pin_cc = { version="1.0.61, < 1.0.62", package="cc" } ## cc v1.0.62 has compiler errors for MinRustV v1.32.0, requires 1.34 (for `std::str::split_ascii_whitespace()`)
|
#pin_cc = { version="1.0.61, < 1.0.62", package="cc" } ## cc v1.0.62 has compiler errors for MinRustV v1.32.0, requires 1.34 (for `std::str::split_ascii_whitespace()`)
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
chrono = "0.4.11"
|
chrono = "^0.4.11"
|
||||||
conv = "0.3"
|
conv = "0.3"
|
||||||
filetime = "0.2"
|
filetime = "0.2"
|
||||||
glob = "0.3.0"
|
glob = "0.3.0"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
pretty_assertions = "0.7.2"
|
pretty_assertions = "1"
|
||||||
rand = "0.7"
|
rand = "0.7"
|
||||||
regex = "1.0"
|
regex = "1.0"
|
||||||
sha1 = { version="0.6", features=["std"] }
|
sha1 = { version="0.6", features=["std"] }
|
||||||
|
|
|
@ -15,7 +15,7 @@ edition = "2018"
|
||||||
path = "src/date.rs"
|
path = "src/date.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4.4"
|
chrono = "^0.4.11"
|
||||||
clap = { version = "2.33", features = ["wrap_help"] }
|
clap = { version = "2.33", features = ["wrap_help"] }
|
||||||
uucore = { version=">=0.0.11", package="uucore", path="../../uucore" }
|
uucore = { version=">=0.0.11", package="uucore", path="../../uucore" }
|
||||||
uucore_procs = { version=">=0.0.8", package="uucore_procs", path="../../uucore_procs" }
|
uucore_procs = { version=">=0.0.8", package="uucore_procs", path="../../uucore_procs" }
|
||||||
|
|
|
@ -16,7 +16,7 @@ path = "src/du.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "2.33", features = ["wrap_help"] }
|
clap = { version = "2.33", features = ["wrap_help"] }
|
||||||
chrono = "0.4"
|
chrono = "^0.4.11"
|
||||||
uucore = { version=">=0.0.11", package="uucore", path="../../uucore" }
|
uucore = { version=">=0.0.11", package="uucore", path="../../uucore" }
|
||||||
uucore_procs = { version=">=0.0.8", package="uucore_procs", path="../../uucore_procs" }
|
uucore_procs = { version=">=0.0.8", package="uucore_procs", path="../../uucore_procs" }
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,13 @@ enum FileNum {
|
||||||
File2,
|
File2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(u8)]
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
enum LineEnding {
|
||||||
|
Nul = 0,
|
||||||
|
Newline = b'\n',
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
enum Sep {
|
enum Sep {
|
||||||
Char(u8),
|
Char(u8),
|
||||||
|
@ -46,6 +53,7 @@ struct Settings {
|
||||||
print_unpaired2: bool,
|
print_unpaired2: bool,
|
||||||
print_joined: bool,
|
print_joined: bool,
|
||||||
ignore_case: bool,
|
ignore_case: bool,
|
||||||
|
line_ending: LineEnding,
|
||||||
separator: Sep,
|
separator: Sep,
|
||||||
autoformat: bool,
|
autoformat: bool,
|
||||||
format: Vec<Spec>,
|
format: Vec<Spec>,
|
||||||
|
@ -63,6 +71,7 @@ impl Default for Settings {
|
||||||
print_unpaired2: false,
|
print_unpaired2: false,
|
||||||
print_joined: true,
|
print_joined: true,
|
||||||
ignore_case: false,
|
ignore_case: false,
|
||||||
|
line_ending: LineEnding::Newline,
|
||||||
separator: Sep::Whitespaces,
|
separator: Sep::Whitespaces,
|
||||||
autoformat: false,
|
autoformat: false,
|
||||||
format: vec![],
|
format: vec![],
|
||||||
|
@ -75,14 +84,21 @@ impl Default for Settings {
|
||||||
|
|
||||||
/// Output representation.
|
/// Output representation.
|
||||||
struct Repr<'a> {
|
struct Repr<'a> {
|
||||||
|
line_ending: LineEnding,
|
||||||
separator: u8,
|
separator: u8,
|
||||||
format: &'a [Spec],
|
format: &'a [Spec],
|
||||||
empty: &'a [u8],
|
empty: &'a [u8],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Repr<'a> {
|
impl<'a> Repr<'a> {
|
||||||
fn new(separator: u8, format: &'a [Spec], empty: &'a [u8]) -> Repr<'a> {
|
fn new(
|
||||||
|
line_ending: LineEnding,
|
||||||
|
separator: u8,
|
||||||
|
format: &'a [Spec],
|
||||||
|
empty: &'a [u8],
|
||||||
|
) -> Repr<'a> {
|
||||||
Repr {
|
Repr {
|
||||||
|
line_ending,
|
||||||
separator,
|
separator,
|
||||||
format,
|
format,
|
||||||
empty,
|
empty,
|
||||||
|
@ -133,6 +149,10 @@ impl<'a> Repr<'a> {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn print_line_ending(&self) -> Result<(), std::io::Error> {
|
||||||
|
stdout().write_all(&[self.line_ending as u8])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Input processing parameters.
|
/// Input processing parameters.
|
||||||
|
@ -260,6 +280,7 @@ impl<'a> State<'a> {
|
||||||
name: &'a str,
|
name: &'a str,
|
||||||
stdin: &'a Stdin,
|
stdin: &'a Stdin,
|
||||||
key: usize,
|
key: usize,
|
||||||
|
line_ending: LineEnding,
|
||||||
print_unpaired: bool,
|
print_unpaired: bool,
|
||||||
) -> State<'a> {
|
) -> State<'a> {
|
||||||
let f = if name == "-" {
|
let f = if name == "-" {
|
||||||
|
@ -276,7 +297,7 @@ impl<'a> State<'a> {
|
||||||
file_name: name,
|
file_name: name,
|
||||||
file_num,
|
file_num,
|
||||||
print_unpaired,
|
print_unpaired,
|
||||||
lines: f.split(b'\n'),
|
lines: f.split(line_ending as u8),
|
||||||
seq: Vec::new(),
|
seq: Vec::new(),
|
||||||
line_num: 0,
|
line_num: 0,
|
||||||
has_failed: false,
|
has_failed: false,
|
||||||
|
@ -351,7 +372,7 @@ impl<'a> State<'a> {
|
||||||
repr.print_fields(line2, other.key)?;
|
repr.print_fields(line2, other.key)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout().write_all(&[b'\n'])?;
|
repr.print_line_ending()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,7 +482,7 @@ impl<'a> State<'a> {
|
||||||
repr.print_fields(line, self.key)?;
|
repr.print_fields(line, self.key)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout().write_all(&[b'\n'])
|
repr.print_line_ending()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_first_line(&self, repr: &Repr) -> Result<(), std::io::Error> {
|
fn print_first_line(&self, repr: &Repr) -> Result<(), std::io::Error> {
|
||||||
|
@ -541,6 +562,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
settings.headers = true;
|
settings.headers = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if matches.is_present("z") {
|
||||||
|
settings.line_ending = LineEnding::Nul;
|
||||||
|
}
|
||||||
|
|
||||||
let file1 = matches.value_of("file1").unwrap();
|
let file1 = matches.value_of("file1").unwrap();
|
||||||
let file2 = matches.value_of("file2").unwrap();
|
let file2 = matches.value_of("file2").unwrap();
|
||||||
|
|
||||||
|
@ -647,6 +672,12 @@ FILENUM is 1 or 2, corresponding to FILE1 or FILE2",
|
||||||
"treat the first line in each file as field headers, \
|
"treat the first line in each file as field headers, \
|
||||||
print them without trying to pair them",
|
print them without trying to pair them",
|
||||||
))
|
))
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("z")
|
||||||
|
.short("z")
|
||||||
|
.long("zero-terminated")
|
||||||
|
.help("line delimiter is NUL, not newline"),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("file1")
|
Arg::with_name("file1")
|
||||||
.required(true)
|
.required(true)
|
||||||
|
@ -669,6 +700,7 @@ fn exec(file1: &str, file2: &str, settings: Settings) -> Result<(), std::io::Err
|
||||||
file1,
|
file1,
|
||||||
&stdin,
|
&stdin,
|
||||||
settings.key1,
|
settings.key1,
|
||||||
|
settings.line_ending,
|
||||||
settings.print_unpaired1,
|
settings.print_unpaired1,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -677,6 +709,7 @@ fn exec(file1: &str, file2: &str, settings: Settings) -> Result<(), std::io::Err
|
||||||
file2,
|
file2,
|
||||||
&stdin,
|
&stdin,
|
||||||
settings.key2,
|
settings.key2,
|
||||||
|
settings.line_ending,
|
||||||
settings.print_unpaired2,
|
settings.print_unpaired2,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -706,6 +739,7 @@ fn exec(file1: &str, file2: &str, settings: Settings) -> Result<(), std::io::Err
|
||||||
};
|
};
|
||||||
|
|
||||||
let repr = Repr::new(
|
let repr = Repr::new(
|
||||||
|
settings.line_ending,
|
||||||
match settings.separator {
|
match settings.separator {
|
||||||
Sep::Char(sep) => sep,
|
Sep::Char(sep) => sep,
|
||||||
_ => b' ',
|
_ => b' ',
|
||||||
|
|
|
@ -15,7 +15,7 @@ edition = "2018"
|
||||||
path = "src/uptime.rs"
|
path = "src/uptime.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4"
|
chrono = "^0.4.11"
|
||||||
clap = { version = "2.33", features = ["wrap_help"] }
|
clap = { version = "2.33", features = ["wrap_help"] }
|
||||||
uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["libc", "utmpx"] }
|
uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["libc", "utmpx"] }
|
||||||
uucore_procs = { version=">=0.0.8", package="uucore_procs", path="../../uucore_procs" }
|
uucore_procs = { version=">=0.0.8", package="uucore_procs", path="../../uucore_procs" }
|
||||||
|
|
|
@ -357,3 +357,13 @@ fn null_field_separators() {
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only_fixture("null-sep.expected");
|
.stdout_only_fixture("null-sep.expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn null_line_endings() {
|
||||||
|
new_ucmd!()
|
||||||
|
.arg("-z")
|
||||||
|
.arg("non-unicode_1.bin")
|
||||||
|
.arg("non-unicode_2.bin")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only_fixture("z.expected");
|
||||||
|
}
|
||||||
|
|
BIN
tests/fixtures/join/z.expected
vendored
Normal file
BIN
tests/fixtures/join/z.expected
vendored
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue