mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 09:48:03 +00:00
Merge pull request #2909 from jfinkels/dd-conv-ascii-unblock
dd: block/unblock on ebcdic/ascii conversions
This commit is contained in:
commit
630b5d8577
3 changed files with 62 additions and 0 deletions
|
@ -444,6 +444,20 @@ pub fn parse_conv_flag_input(matches: &Matches) -> Result<IConvFlags, ParseError
|
||||||
return Err(ParseError::MultipleFmtTable);
|
return Err(ParseError::MultipleFmtTable);
|
||||||
} else {
|
} else {
|
||||||
fmt = Some(flag);
|
fmt = Some(flag);
|
||||||
|
// From the GNU documentation:
|
||||||
|
//
|
||||||
|
// > ‘ascii’
|
||||||
|
// >
|
||||||
|
// > Convert EBCDIC to ASCII, using the conversion
|
||||||
|
// > table specified by POSIX. This provides a 1:1
|
||||||
|
// > translation for all 256 bytes. This implies
|
||||||
|
// > ‘conv=unblock’; input is converted to ASCII
|
||||||
|
// > before trailing spaces are deleted.
|
||||||
|
//
|
||||||
|
// -- https://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html
|
||||||
|
if cbs.is_some() {
|
||||||
|
iconvflags.unblock = cbs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConvFlag::FmtAtoE => {
|
ConvFlag::FmtAtoE => {
|
||||||
|
@ -451,6 +465,19 @@ pub fn parse_conv_flag_input(matches: &Matches) -> Result<IConvFlags, ParseError
|
||||||
return Err(ParseError::MultipleFmtTable);
|
return Err(ParseError::MultipleFmtTable);
|
||||||
} else {
|
} else {
|
||||||
fmt = Some(flag);
|
fmt = Some(flag);
|
||||||
|
// From the GNU documentation:
|
||||||
|
//
|
||||||
|
// > ‘ebcdic’
|
||||||
|
// >
|
||||||
|
// > Convert ASCII to EBCDIC. This is the inverse
|
||||||
|
// > of the ‘ascii’ conversion. This implies
|
||||||
|
// > ‘conv=block’; trailing spaces are added before
|
||||||
|
// > being converted to EBCDIC.
|
||||||
|
//
|
||||||
|
// -- https://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html
|
||||||
|
if cbs.is_some() {
|
||||||
|
iconvflags.block = cbs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConvFlag::FmtAtoI => {
|
ConvFlag::FmtAtoI => {
|
||||||
|
|
|
@ -157,6 +157,7 @@ fn test_all_top_level_args_no_leading_dashes() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
IConvFlags {
|
IConvFlags {
|
||||||
ctable: Some(&EBCDIC_TO_ASCII_LCASE_TO_UCASE),
|
ctable: Some(&EBCDIC_TO_ASCII_LCASE_TO_UCASE),
|
||||||
|
unblock: Some(1), // because ascii implies unblock
|
||||||
..IConvFlags::default()
|
..IConvFlags::default()
|
||||||
},
|
},
|
||||||
parse_conv_flag_input(&matches).unwrap()
|
parse_conv_flag_input(&matches).unwrap()
|
||||||
|
@ -241,6 +242,7 @@ fn test_all_top_level_args_with_leading_dashes() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
IConvFlags {
|
IConvFlags {
|
||||||
ctable: Some(&EBCDIC_TO_ASCII_LCASE_TO_UCASE),
|
ctable: Some(&EBCDIC_TO_ASCII_LCASE_TO_UCASE),
|
||||||
|
unblock: Some(1), // because ascii implies unblock
|
||||||
..IConvFlags::default()
|
..IConvFlags::default()
|
||||||
},
|
},
|
||||||
parse_conv_flag_input(&matches).unwrap()
|
parse_conv_flag_input(&matches).unwrap()
|
||||||
|
|
|
@ -559,5 +559,38 @@ fn test_unicode_filenames() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_conv_ascii_implies_unblock() {
|
||||||
|
// 0x40 = 0o100 = 64, which gets converted to ' '
|
||||||
|
// 0xc1 = 0o301 = 193, which gets converted to 'A'
|
||||||
|
//
|
||||||
|
// `conv=ascii` implies `conv=unblock`, which means trailing paces
|
||||||
|
// are stripped and a newline is appended at the end of each
|
||||||
|
// block.
|
||||||
|
//
|
||||||
|
// `cbs=4` means use a conversion block size of 4 bytes per block.
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["conv=ascii", "cbs=4"])
|
||||||
|
.pipe_in(b"\x40\xc1\x40\xc1\x40\xc1\x40\x40".to_vec())
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is(" A A\n A\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_conv_ebcdic_implies_block() {
|
||||||
|
// 0x40 = 0o100 = 64, which is the result of converting from ' '
|
||||||
|
// 0xc1 = 0o301 = 193, which is the result of converting from 'A'
|
||||||
|
//
|
||||||
|
// `conv=ebcdic` implies `conv=block`, which means trailing spaces
|
||||||
|
// are added to pad each block.
|
||||||
|
//
|
||||||
|
// `cbs=4` means use a conversion block size of 4 bytes per block.
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["conv=ebcdic", "cbs=4"])
|
||||||
|
.pipe_in(" A A\n A\n")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is_bytes(b"\x40\xc1\x40\xc1\x40\xc1\x40\x40");
|
||||||
|
}
|
||||||
|
|
||||||
// conv=[ascii,ebcdic,ibm], conv=[ucase,lcase], conv=[block,unblock], conv=sync
|
// conv=[ascii,ebcdic,ibm], conv=[ucase,lcase], conv=[block,unblock], conv=sync
|
||||||
// TODO: Move conv tests from unit test module
|
// TODO: Move conv tests from unit test module
|
||||||
|
|
Loading…
Reference in a new issue