mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
od: suppress duplicates
This commit is contained in:
+22
-5
@@ -237,14 +237,20 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
line_bytes = min_bytes;
|
||||
}
|
||||
|
||||
odfunc(line_bytes, &input_offset_base, &inputs, &formats[..])
|
||||
let output_duplicates = matches.opt_present("v");
|
||||
|
||||
odfunc(line_bytes, &input_offset_base, &inputs, &formats[..], output_duplicates)
|
||||
}
|
||||
|
||||
fn odfunc(line_bytes: usize, input_offset_base: &Radix, fnames: &[InputSource], formats: &[OdFormat]) -> i32 {
|
||||
fn odfunc(line_bytes: usize, input_offset_base: &Radix,
|
||||
fnames: &[InputSource], formats: &[OdFormat], output_duplicates: bool) -> i32 {
|
||||
|
||||
let mut mf = MultifileReader::new(fnames);
|
||||
let mut addr = 0;
|
||||
let mut bytes: Vec<u8> = vec![b'\x00'; line_bytes];
|
||||
let mut previous_bytes = Vec::<u8>::with_capacity(line_bytes);
|
||||
let mut duplicate_line = false;
|
||||
|
||||
loop {
|
||||
// print each line data (or multi-format raster of several lines describing the same data).
|
||||
|
||||
@@ -261,9 +267,20 @@ fn odfunc(line_bytes: usize, input_offset_base: &Radix, fnames: &[InputSource],
|
||||
bytes[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
print_bytes(&bytes, n, &print_with_radix(input_offset_base, addr), formats);
|
||||
|
||||
|
||||
if !output_duplicates && previous_bytes == bytes && n == line_bytes {
|
||||
if !duplicate_line {
|
||||
duplicate_line = true;
|
||||
println!("*");
|
||||
}
|
||||
}
|
||||
else {
|
||||
duplicate_line = false;
|
||||
previous_bytes.clone_from(&bytes);
|
||||
|
||||
print_bytes(&bytes, n, &print_with_radix(input_offset_base, addr), formats);
|
||||
}
|
||||
|
||||
addr += n;
|
||||
}
|
||||
Err(_) => {
|
||||
|
||||
+22
-2
@@ -266,7 +266,7 @@ fn test_width(){
|
||||
0000010
|
||||
");
|
||||
|
||||
let result = new_ucmd!().arg("-w4").run_piped_stdin(&input[..]);
|
||||
let result = new_ucmd!().arg("-w4").arg("-v").run_piped_stdin(&input[..]);
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
@@ -283,7 +283,7 @@ fn test_invalid_width(){
|
||||
0000004
|
||||
");
|
||||
|
||||
let result = new_ucmd!().arg("-w5").run_piped_stdin(&input[..]);
|
||||
let result = new_ucmd!().arg("-w5").arg("-v").run_piped_stdin(&input[..]);
|
||||
|
||||
assert_eq!(result.stderr, "od: warning: invalid width 5; using 2 instead\n");
|
||||
assert!(result.success);
|
||||
@@ -306,3 +306,23 @@ fn test_width_without_value(){
|
||||
assert!(result.success);
|
||||
assert_eq!(result.stdout, expected_output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_suppress_duplicates(){
|
||||
|
||||
let input = [0u8 ; 41];
|
||||
let expected_output = unindent("
|
||||
0000000 000000000000
|
||||
0000 0000
|
||||
*
|
||||
0000050 000000000000
|
||||
0000
|
||||
0000051
|
||||
");
|
||||
|
||||
let result = new_ucmd!().arg("-w4").arg("-O").arg("-x").run_piped_stdin(&input[..]);
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert_eq!(result.stdout, expected_output);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user