mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2026-01-20 12:11:08 +00:00
Completes refactor & clean-up. Implements full conv flag parsing.
- All conv flags now parsed (full functionality is TODO) - Changes functionality of eg. conv=ebcdic,ucase to match gnudd
This commit is contained in:
parent
5c8c7efe68
commit
9e933a3860
16 changed files with 681 additions and 493 deletions
|
|
@ -4,6 +4,45 @@
|
|||
// obtained by treating the ASCII representation as a number.
|
||||
pub type ConversionTable = [u8; 256];
|
||||
|
||||
pub const ASCII_UCASE_TO_LCASE: ConversionTable = [
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
|
||||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
||||
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
];
|
||||
|
||||
pub const ASCII_LCASE_TO_UCASE: ConversionTable = [
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 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 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
||||
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
|
||||
];
|
||||
|
||||
pub const ASCII_TO_EBCDIC: ConversionTable = [
|
||||
0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, 0x16, 0x05, 0x25, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
|
|
@ -23,6 +62,44 @@ pub const ASCII_TO_EBCDIC: ConversionTable = [
|
|||
0xdc, 0xdd, 0xde, 0xdf, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
];
|
||||
|
||||
pub const ASCII_TO_EBCDIC_UCASE_TO_LCASE: ConversionTable = [
|
||||
0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, 0x16, 0x05, 0x25, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f,
|
||||
0x7c, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
|
||||
0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xad, 0xe0, 0xbd, 0x9a, 0x6d,
|
||||
0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
|
||||
0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xc0, 0x4f, 0xd0, 0x5f, 0x07,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x15, 0x06, 0x17, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x1b,
|
||||
0x30, 0x31, 0x1a, 0x33, 0x34, 0x35, 0x36, 0x08, 0x38, 0x39, 0x3a, 0x3b, 0x04, 0x14, 0x3e, 0xe1,
|
||||
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
|
||||
0x58, 0x59, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
|
||||
0x76, 0x77, 0x78, 0x80, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x6a, 0x9b, 0x9c, 0x9d, 0x9e,
|
||||
0x9f, 0xa0, 0xaa, 0xab, 0xac, 0x4a, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xa1, 0xbe, 0xbf, 0xca, 0xcb, 0x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2a, 0x2b, 0x2c, 0x09, 0x0a, 0x1b,
|
||||
0x30, 0x31, 0x1a, 0x33, 0x34, 0x35, 0x36, 0x08, 0x38, 0x39, 0x3a, 0x3b, 0x04, 0x14, 0x3e, 0xe1,
|
||||
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
|
||||
0x58, 0x59, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
|
||||
0x76, 0x77, 0x78, 0x80, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x6a, 0x9b, 0x9c, 0x9d, 0x9e,
|
||||
0x9f, 0xa0, 0xaa, 0xab, 0xac, 0x4a, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xa1, 0xbe, 0xbf, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xda, 0xdb,
|
||||
0xdc, 0xdd, 0xde, 0xdf, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
];
|
||||
|
||||
pub const ASCII_TO_IBM: ConversionTable = [
|
||||
0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, 0x16, 0x05, 0x25, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
|
|
@ -42,6 +119,45 @@ pub const ASCII_TO_IBM: ConversionTable = [
|
|||
0xdc, 0xdd, 0xde, 0xdf, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
];
|
||||
|
||||
pub const ASCII_TO_IBM_UCASE_TO_LCASE: ConversionTable = [
|
||||
0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, 0x16, 0x05, 0x25, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f,
|
||||
0x7c, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
|
||||
0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xad, 0xe0, 0xbd, 0x5f, 0x6d,
|
||||
0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
|
||||
0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xc0, 0x4f, 0xd0, 0xa1, 0x07,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x15, 0x06, 0x17, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x1b,
|
||||
0x30, 0x31, 0x1a, 0x33, 0x34, 0x35, 0x36, 0x08, 0x38, 0x39, 0x3a, 0x3b, 0x04, 0x14, 0x3e, 0xe1,
|
||||
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
|
||||
0x58, 0x59, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
|
||||
0x76, 0x77, 0x78, 0x80, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e,
|
||||
0x9f, 0xa0, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xda, 0xdb,
|
||||
0xdc, 0xdd, 0xde, 0xdf, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
];
|
||||
|
||||
|
||||
pub const ASCII_TO_IBM_LCASE_TO_UCASE: ConversionTable = [
|
||||
0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, 0x16, 0x05, 0x25, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f,
|
||||
0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0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, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
];
|
||||
|
||||
pub const EBCDIC_TO_ASCII: ConversionTable = [
|
||||
0x00, 0x01, 0x02, 0x03, 0x9c, 0x09, 0x86, 0x7f, 0x97, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x9d, 0x85, 0x08, 0x87, 0x18, 0x19, 0x92, 0x8f, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
|
|
@ -61,79 +177,42 @@ pub const EBCDIC_TO_ASCII: ConversionTable = [
|
|||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
];
|
||||
|
||||
pub const ASCII_LCASE_TO_UCASE: ConversionTable = [
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
|
||||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
||||
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
|
||||
];
|
||||
|
||||
pub const ASCII_UCASE_TO_LCASE: ConversionTable = [
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
|
||||
0xb0, 0xb1, 0xb2, 0xb3, 0xb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0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xad, 0xe0, 0xbd, 0x9a, 0x6d,
|
||||
0x79, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6,
|
||||
0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xc0, 0x4f, 0xd0, 0x5f, 0x07,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x15, 0x06, 0x17, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x1b,
|
||||
0x30, 0x31, 0x1a, 0x33, 0x34, 0x35, 0x36, 0x08, 0x38, 0x39, 0x3a, 0x3b, 0x04, 0x14, 0x3e, 0xe1,
|
||||
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
|
||||
0x58, 0x59, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
|
||||
0x76, 0x77, 0x78, 0x80, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x6a, 0x9b, 0x9c, 0x9d, 0x9e,
|
||||
0x9f, 0xa0, 0xaa, 0xab, 0xac, 0x4a, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xa1, 0xbe, 0xbf, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xda, 0xdb,
|
||||
0xdc, 0xdd, 0xde, 0xdf, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
];
|
||||
|
||||
pub const EBCDIC_UCASE_TO_LCASE: ConversionTable = [
|
||||
pub const EBCDIC_TO_ASCII_UCASE_TO_LCASE: ConversionTable = [
|
||||
0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, 0x16, 0x05, 0x25, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f,
|
||||
0x7c, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
|
||||
0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xad, 0xe0, 0xbd, 0x9a, 0x6d,
|
||||
0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xad, 0xe0, 0xbd, 0x5f, 0x6d,
|
||||
0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
|
||||
0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xc0, 0x4f, 0xd0, 0x5f, 0x07,
|
||||
0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xc0, 0x4f, 0xd0, 0xa1, 0x07,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x15, 0x06, 0x17, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x1b,
|
||||
0x30, 0x31, 0x1a, 0x33, 0x34, 0x35, 0x36, 0x08, 0x38, 0x39, 0x3a, 0x3b, 0x04, 0x14, 0x3e, 0xe1,
|
||||
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
|
||||
0x58, 0x59, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
|
||||
0x76, 0x77, 0x78, 0x80, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x6a, 0x9b, 0x9c, 0x9d, 0x9e,
|
||||
0x9f, 0xa0, 0xaa, 0xab, 0xac, 0x4a, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xa1, 0xbe, 0xbf, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xda, 0xdb,
|
||||
0x76, 0x77, 0x78, 0x80, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e,
|
||||
0x9f, 0xa0, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xda, 0xdb,
|
||||
0xdc, 0xdd, 0xde, 0xdf, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
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, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
|
||||
0x58, 0x59, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
|
||||
0x76, 0x77, 0x78, 0x80, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e,
|
||||
0x9f, 0xa0, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xda, 0xdb,
|
||||
0xdc, 0xdd, 0xde, 0xdf, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ mod parseargs;
|
|||
mod conversion_tables;
|
||||
|
||||
use conversion_tables::*;
|
||||
use parseargs::*;
|
||||
|
||||
use std::error::Error;
|
||||
use std::fs::File;
|
||||
|
|
@ -32,6 +31,8 @@ const SYNTAX: &str = "dd [OPERAND]...\ndd OPTION";
|
|||
const SUMMARY: &str = "convert, and optionally copy, a file";
|
||||
const LONG_HELP: &str = "";
|
||||
|
||||
const DEFAULT_FILL_BYTE: u8 = 0xDD;
|
||||
|
||||
const RTN_SUCCESS: i32 = 0;
|
||||
const RTN_FAILURE: i32 = 1;
|
||||
|
||||
|
|
@ -42,6 +43,39 @@ enum SrcStat
|
|||
EOF,
|
||||
}
|
||||
|
||||
/// Captures all Conv Flags that apply to the input
|
||||
pub struct ConvFlagInput
|
||||
{
|
||||
ctable: Option<ConversionTable>,
|
||||
block: bool,
|
||||
unblock: bool,
|
||||
swab: bool,
|
||||
sync: bool,
|
||||
noerror: bool,
|
||||
}
|
||||
|
||||
/// Captures all Conv Flags that apply to the output
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct ConvFlagOutput
|
||||
{
|
||||
sparse: bool,
|
||||
excl: bool,
|
||||
nocreat: bool,
|
||||
notrunc: bool,
|
||||
fdatasync: bool,
|
||||
fsync: bool,
|
||||
}
|
||||
|
||||
/// The value of the status cl-option.
|
||||
/// Controls printing of transfer stats
|
||||
#[derive(PartialEq)]
|
||||
pub enum StatusLevel
|
||||
{
|
||||
Progress,
|
||||
Noxfer,
|
||||
None,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum InternalError
|
||||
{
|
||||
|
|
@ -62,13 +96,25 @@ struct Input<R: Read>
|
|||
{
|
||||
src: R,
|
||||
ibs: usize,
|
||||
xfer_stats: StatusLevel,
|
||||
cf: ConvFlagInput,
|
||||
}
|
||||
|
||||
impl<R: Read> Read for Input<R>
|
||||
{
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize>
|
||||
fn read(&mut self, mut buf: &mut [u8]) -> io::Result<usize>
|
||||
{
|
||||
self.src.read(buf)
|
||||
let len = self.src.read(&mut buf)?;
|
||||
|
||||
if let Some(ct) = self.cf.ctable
|
||||
{
|
||||
for idx in 0..len
|
||||
{
|
||||
buf[idx] = ct[buf[idx] as usize];
|
||||
}
|
||||
}
|
||||
|
||||
Ok(len)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,12 +122,16 @@ impl Input<io::Stdin>
|
|||
{
|
||||
fn new(matches: &getopts::Matches) -> Result<Self, Box<dyn Error>>
|
||||
{
|
||||
let ibs: usize = parseargs::parse_ibs(matches)?;
|
||||
let ibs = parseargs::parse_ibs(matches)?;
|
||||
let xfer_stats = parseargs::parse_status_level(matches)?;
|
||||
let cf = parseargs::parse_conv_flag_input(matches)?;
|
||||
|
||||
Ok(
|
||||
Input {
|
||||
src: io::stdin(),
|
||||
ibs,
|
||||
xfer_stats,
|
||||
cf,
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -92,13 +142,17 @@ impl Input<File>
|
|||
{
|
||||
fn new(matches: &getopts::Matches) -> Result<Self, Box<dyn Error>>
|
||||
{
|
||||
let ibs: usize = parseargs::parse_ibs(matches)?;
|
||||
let ibs = parseargs::parse_ibs(matches)?;
|
||||
let xfer_stats = parseargs::parse_status_level(matches)?;
|
||||
let cf = parseargs::parse_conv_flag_input(matches)?;
|
||||
|
||||
if let Some(fname) = matches.opt_str("if")
|
||||
{
|
||||
Ok(Input {
|
||||
src: File::open(fname)?,
|
||||
ibs,
|
||||
xfer_stats,
|
||||
cf,
|
||||
})
|
||||
}
|
||||
else
|
||||
|
|
@ -139,17 +193,20 @@ struct Output<W: Write>
|
|||
{
|
||||
dst: W,
|
||||
obs: usize,
|
||||
cf: ConvFlagOutput,
|
||||
}
|
||||
|
||||
impl Output<io::Stdout> {
|
||||
fn new(matches: &getopts::Matches) -> Result<Self, Box<dyn Error>>
|
||||
{
|
||||
let obs: usize = parseargs::parse_obs(matches)?;
|
||||
let obs = parseargs::parse_obs(matches)?;
|
||||
let cf = parseargs::parse_conv_flag_output(matches)?;
|
||||
|
||||
Ok(
|
||||
Output {
|
||||
dst: io::stdout(),
|
||||
obs,
|
||||
cf,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
@ -158,13 +215,15 @@ impl Output<io::Stdout> {
|
|||
impl Output<File> {
|
||||
fn new(matches: &getopts::Matches) -> Result<Self, Box<dyn Error>>
|
||||
{
|
||||
let obs: usize = parseargs::parse_obs(matches)?;
|
||||
let obs = parseargs::parse_obs(matches)?;
|
||||
let cf = parseargs::parse_conv_flag_output(matches)?;
|
||||
|
||||
if let Some(fname) = matches.opt_str("if")
|
||||
{
|
||||
Ok(Output {
|
||||
dst: File::open(fname)?,
|
||||
obs,
|
||||
cf,
|
||||
})
|
||||
}
|
||||
else
|
||||
|
|
@ -178,21 +237,7 @@ impl<W: Write> Write for Output<W>
|
|||
{
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize>
|
||||
{
|
||||
if let Some(ct) = self.conv_table
|
||||
{
|
||||
let mut cbuf = vec![0; buf.len()];
|
||||
|
||||
for (idx, byte) in buf.iter().enumerate()
|
||||
{
|
||||
cbuf[idx] = ct[*byte as usize]
|
||||
}
|
||||
|
||||
self.dst.write(&cbuf)
|
||||
}
|
||||
else
|
||||
{
|
||||
self.dst.write(buf)
|
||||
}
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> io::Result<()>
|
||||
|
|
@ -201,33 +246,6 @@ impl<W: Write> Write for Output<W>
|
|||
}
|
||||
}
|
||||
|
||||
struct Options
|
||||
{
|
||||
conv: Option<ConversionOptions>,
|
||||
status_level: StatusLevel,
|
||||
// ...
|
||||
}
|
||||
|
||||
struct ConversionOptions
|
||||
{
|
||||
table: Option<ConversionTable>,
|
||||
block: bool,
|
||||
unblock: bool,
|
||||
lcase: bool,
|
||||
ucase: bool,
|
||||
sparse: bool,
|
||||
swab: bool,
|
||||
sync: bool,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum StatusLevel
|
||||
{
|
||||
Progress,
|
||||
Noxfer,
|
||||
None,
|
||||
}
|
||||
|
||||
fn gen_prog_updater(rx: mpsc::Receiver<usize>) -> impl Fn() -> ()
|
||||
{
|
||||
move || {
|
||||
|
|
@ -251,9 +269,9 @@ fn gen_prog_updater(rx: mpsc::Receiver<usize>) -> impl Fn() -> ()
|
|||
}
|
||||
}
|
||||
|
||||
fn dd<R: Read, W: Write>(mut i: Input<R>, mut o: Output<W>, opts: Options) -> Result<(usize, usize), Box<dyn Error>>
|
||||
fn dd<R: Read, W: Write>(mut i: Input<R>, mut o: Output<W>) -> Result<(usize, usize), Box<dyn Error>>
|
||||
{
|
||||
let prog_tx = if opts.status_level == StatusLevel::Progress
|
||||
let prog_tx = if i.xfer_stats == StatusLevel::Progress
|
||||
{
|
||||
let (prog_tx, prog_rx) = mpsc::channel();
|
||||
|
||||
|
|
@ -271,7 +289,7 @@ fn dd<R: Read, W: Write>(mut i: Input<R>, mut o: Output<W>, opts: Options) -> Re
|
|||
|
||||
loop
|
||||
{
|
||||
let mut buf = vec![0xDD; o.obs];
|
||||
let mut buf = vec![DEFAULT_FILL_BYTE; o.obs];
|
||||
let r_len =
|
||||
match i.fill_n(&mut buf, o.obs)? {
|
||||
SrcStat::Read(len) =>
|
||||
|
|
@ -355,9 +373,6 @@ pub fn uumain(args: impl uucore::Args) -> i32
|
|||
|
||||
let matches = build_app!().parse(dashed_args);
|
||||
|
||||
let opts = parse_options(&matches)
|
||||
.expect("TODO: Return correct error code");
|
||||
|
||||
let result = match (matches.opt_present("if"), matches.opt_present("of"))
|
||||
{
|
||||
(true, true) =>
|
||||
|
|
@ -367,7 +382,7 @@ pub fn uumain(args: impl uucore::Args) -> i32
|
|||
let o = Output::<File>::new(&matches)
|
||||
.expect("TODO: Return correct error code");
|
||||
|
||||
dd(i, o, opts)
|
||||
dd(i,o)
|
||||
},
|
||||
(true, false) =>
|
||||
{
|
||||
|
|
@ -376,7 +391,7 @@ pub fn uumain(args: impl uucore::Args) -> i32
|
|||
let o = Output::<io::Stdout>::new(&matches)
|
||||
.expect("TODO: Return correct error code");
|
||||
|
||||
dd(i, o, opts)
|
||||
dd(i,o)
|
||||
},
|
||||
(false, true) =>
|
||||
{
|
||||
|
|
@ -385,7 +400,7 @@ pub fn uumain(args: impl uucore::Args) -> i32
|
|||
let o = Output::<File>::new(&matches)
|
||||
.expect("TODO: Return correct error code");
|
||||
|
||||
dd(i, o, opts)
|
||||
dd(i,o)
|
||||
},
|
||||
(false, false) =>
|
||||
{
|
||||
|
|
@ -394,7 +409,7 @@ pub fn uumain(args: impl uucore::Args) -> i32
|
|||
let o = Output::<io::Stdout>::new(&matches)
|
||||
.expect("TODO: Return correct error code");
|
||||
|
||||
dd(i, o, opts)
|
||||
dd(i,o)
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,16 @@ use super::*;
|
|||
|
||||
use crate::conversion_tables::*;
|
||||
|
||||
/// Parser Errors indicate erroneous cl-args
|
||||
#[derive(Debug)]
|
||||
enum ParseError
|
||||
pub enum ParseError
|
||||
{
|
||||
MultipleFmtTable,
|
||||
MultipleUCaseLCase,
|
||||
MultipleBlockUnblock,
|
||||
ConvFlagNoMatch(String),
|
||||
MultiplierString(String),
|
||||
NoMatchingMultiplier(String),
|
||||
MultiplierStringContainsNoValue(String),
|
||||
MultiplierStringWouldOverflow(String),
|
||||
}
|
||||
|
||||
|
|
@ -19,16 +24,29 @@ impl std::fmt::Display for ParseError
|
|||
|
||||
impl Error for ParseError {}
|
||||
|
||||
/// Some flags specified as part of a conv=CONV[,CONV]... block
|
||||
/// relate to the input file, others to the output file.
|
||||
/// They are separated here.
|
||||
enum ConvFlag
|
||||
{
|
||||
Table(ConversionTable),
|
||||
// Input
|
||||
FmtAtoE,
|
||||
FmtEtoA,
|
||||
FmtAtoI,
|
||||
Block,
|
||||
Unblock,
|
||||
UCase,
|
||||
LCase,
|
||||
Sparse,
|
||||
Swab,
|
||||
Sync,
|
||||
NoError,
|
||||
// Output
|
||||
Sparse,
|
||||
Excl,
|
||||
NoCreat,
|
||||
NoTrunc,
|
||||
FDataSync,
|
||||
FSync,
|
||||
}
|
||||
|
||||
impl std::str::FromStr for ConvFlag
|
||||
|
|
@ -39,36 +57,48 @@ impl std::str::FromStr for ConvFlag
|
|||
{
|
||||
match s
|
||||
{
|
||||
// Input
|
||||
"ascii" =>
|
||||
Ok(Self::Table(EBCDIC_TO_ASCII)),
|
||||
Ok(Self::FmtEtoA),
|
||||
"ebcdic" =>
|
||||
Ok(Self::Table(ASCII_TO_EBCDIC)),
|
||||
Ok(Self::FmtAtoE),
|
||||
"ibm" =>
|
||||
Ok(Self::Table(ASCII_TO_IBM)),
|
||||
Ok(Self::FmtAtoI),
|
||||
"lcase" =>
|
||||
Ok(Self::UCase),
|
||||
"ucase" =>
|
||||
Ok(Self::LCase),
|
||||
"block" =>
|
||||
Ok(Self::Block),
|
||||
"unblock" =>
|
||||
Ok(Self::Unblock),
|
||||
"lcase" =>
|
||||
Ok(Self::LCase),
|
||||
"ucase" =>
|
||||
Ok(Self::UCase),
|
||||
"sparse" =>
|
||||
Ok(Self::Sparse),
|
||||
"swab" =>
|
||||
Ok(Self::Swab),
|
||||
"sync" =>
|
||||
Ok(Self::Sync),
|
||||
"noerror" =>
|
||||
Ok(Self::NoError),
|
||||
// Output
|
||||
"sparse" =>
|
||||
Ok(Self::Sparse),
|
||||
"excl" =>
|
||||
Ok(Self::Excl),
|
||||
"nocreat" =>
|
||||
Ok(Self::NoCreat),
|
||||
"notrunc" =>
|
||||
Ok(Self::NoTrunc),
|
||||
"fdatasync" =>
|
||||
Ok(Self::FDataSync),
|
||||
"fsync" =>
|
||||
Ok(Self::FSync),
|
||||
_ =>
|
||||
Err(ParseError::ConvFlagNoMatch(String::from(s)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_multiplier<'a>(s: &'a str) -> Result<usize, Box<dyn Error>>
|
||||
fn parse_multiplier<'a>(s: &'a str) -> Result<usize, ParseError>
|
||||
{
|
||||
let s = s.trim();
|
||||
|
||||
match s
|
||||
{
|
||||
"c" =>
|
||||
|
|
@ -111,15 +141,19 @@ fn parse_multiplier<'a>(s: &'a str) -> Result<usize, Box<dyn Error>>
|
|||
// "Y" | "YiB" =>
|
||||
// Ok(1024*1024*1024*1024*1024*1024*1024*1024),
|
||||
_ =>
|
||||
Err(Box::new(ParseError::MultiplierString(String::from(s)))),
|
||||
Err(ParseError::NoMatchingMultiplier(String::from(s))),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_bytes_with_opt_multiplier(s: String) -> Result<usize, Box<dyn Error>>
|
||||
fn parse_bytes_with_opt_multiplier(s: String) -> Result<usize, ParseError>
|
||||
{
|
||||
if let Some(idx) = s.find(' ')
|
||||
if let Some(idx) = s.find(char::is_alphabetic)
|
||||
{
|
||||
let base: usize = s[0..idx].parse()?;
|
||||
let base: usize = match s[0..idx].parse()
|
||||
{
|
||||
Ok(val) => val,
|
||||
Err(_) => return Err(ParseError::MultiplierStringContainsNoValue(s)),
|
||||
};
|
||||
let mult = parse_multiplier(&s[idx..])?;
|
||||
|
||||
if let Some(bytes) = base.checked_mul(mult)
|
||||
|
|
@ -128,18 +162,21 @@ fn parse_bytes_with_opt_multiplier(s: String) -> Result<usize, Box<dyn Error>>
|
|||
}
|
||||
else
|
||||
{
|
||||
Err(Box::new(ParseError::MultiplierStringWouldOverflow(s)))
|
||||
Err(ParseError::MultiplierStringWouldOverflow(s))
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
let bytes: usize = s.parse()?;
|
||||
|
||||
let bytes: usize = match s.parse()
|
||||
{
|
||||
Ok(val) => val,
|
||||
Err(_) => return Err(ParseError::MultiplierStringContainsNoValue(s)),
|
||||
};
|
||||
Ok(bytes)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_ibs(matches: &getopts::Matches) -> Result<usize, Box<dyn Error>>
|
||||
pub fn parse_ibs(matches: &getopts::Matches) -> Result<usize, ParseError>
|
||||
{
|
||||
if let Some(mixed_str) = matches.opt_str("bs")
|
||||
{
|
||||
|
|
@ -155,13 +192,13 @@ pub fn parse_ibs(matches: &getopts::Matches) -> Result<usize, Box<dyn Error>>
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse_progress_level(matches: &getopts::Matches) -> Result<bool, Box<dyn Error>>
|
||||
pub fn parse_status_level(matches: &getopts::Matches) -> Result<StatusLevel, ParseError>
|
||||
{
|
||||
// TODO: Implement this stub proc
|
||||
Ok(false)
|
||||
// TODO: Impl
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn parse_obs(matches: &getopts::Matches) -> Result<usize, Box<dyn Error>>
|
||||
pub fn parse_obs(matches: &getopts::Matches) -> Result<usize, ParseError>
|
||||
{
|
||||
if let Some(mixed_str) = matches.opt_str("bs")
|
||||
{
|
||||
|
|
@ -177,80 +214,53 @@ pub fn parse_obs(matches: &getopts::Matches) -> Result<usize, Box<dyn Error>>
|
|||
}
|
||||
}
|
||||
|
||||
/// Parse the options and flags that control the way
|
||||
/// the file(s) is(are) copied and converted
|
||||
pub fn parse_options(matches: &getopts::Matches) -> Result<Options, Box<dyn Error>>
|
||||
fn parse_ctable(fmt: Option<ConvFlag>, case: Option<ConvFlag>) -> Option<ConversionTable>
|
||||
{
|
||||
panic!()
|
||||
match (fmt, case)
|
||||
{
|
||||
// Both specified
|
||||
(Some(fmt), Some(case)) =>
|
||||
match (fmt, case)
|
||||
{
|
||||
(ConvFlag::FmtAtoE, ConvFlag::UCase) =>
|
||||
Some(ASCII_TO_EBCDIC_LCASE_TO_UCASE),
|
||||
(ConvFlag::FmtAtoE, ConvFlag::LCase) =>
|
||||
Some(ASCII_TO_EBCDIC_UCASE_TO_LCASE),
|
||||
(ConvFlag::FmtEtoA, ConvFlag::UCase) =>
|
||||
Some(EBCDIC_TO_ASCII_LCASE_TO_UCASE),
|
||||
(ConvFlag::FmtEtoA, ConvFlag::LCase) =>
|
||||
Some(EBCDIC_TO_ASCII_UCASE_TO_LCASE),
|
||||
(ConvFlag::FmtAtoI, ConvFlag::UCase) =>
|
||||
Some(ASCII_TO_IBM_UCASE_TO_LCASE),
|
||||
(ConvFlag::FmtAtoI, ConvFlag::LCase) =>
|
||||
Some(ASCII_TO_IBM_LCASE_TO_UCASE),
|
||||
(_, _) =>
|
||||
None,
|
||||
},
|
||||
// Only one of {ascii, ebcdic, ibm} specified
|
||||
(Some(fmt), None) =>
|
||||
match fmt
|
||||
{
|
||||
ConvFlag::FmtAtoE =>
|
||||
Some(ASCII_TO_EBCDIC),
|
||||
ConvFlag::FmtEtoA =>
|
||||
Some(EBCDIC_TO_ASCII),
|
||||
ConvFlag::FmtAtoI =>
|
||||
Some(ASCII_TO_IBM),
|
||||
_ =>
|
||||
None,
|
||||
},
|
||||
// Only one of {ucase, lcase} specified
|
||||
(None, Some(ConvFlag::UCase)) =>
|
||||
Some(ASCII_LCASE_TO_UCASE),
|
||||
(None, Some(ConvFlag::LCase)) =>
|
||||
Some(ASCII_UCASE_TO_LCASE),
|
||||
(_, _) =>
|
||||
None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse Conversion Options that control how the file is converted
|
||||
pub fn parse_conv_options(matches: &getopts::Matches) -> Result<ConversionOptions, Box<dyn Error>>
|
||||
{
|
||||
let flags = parse_conv_opts(matches)?;
|
||||
|
||||
let mut table = None;
|
||||
let mut block = false;
|
||||
let mut unblock = false;
|
||||
let mut ucase = false;
|
||||
let mut lcase = false;
|
||||
let mut sparse = false;
|
||||
let mut swab = false;
|
||||
let mut sync = false;
|
||||
|
||||
for flag in flags
|
||||
{
|
||||
match flag
|
||||
{
|
||||
ConvFlag::Table(ct) =>
|
||||
{
|
||||
table = Some(ct);
|
||||
},
|
||||
ConvFlag::Block =>
|
||||
{
|
||||
block = true;
|
||||
},
|
||||
ConvFlag::Unblock =>
|
||||
{
|
||||
unblock = true;
|
||||
},
|
||||
ConvFlag::UCase =>
|
||||
{
|
||||
ucase = true;
|
||||
},
|
||||
ConvFlag::LCase =>
|
||||
{
|
||||
lcase = true;
|
||||
},
|
||||
ConvFlag::Sparse =>
|
||||
{
|
||||
sparse = true;
|
||||
},
|
||||
ConvFlag::Swab =>
|
||||
{
|
||||
swab = true;
|
||||
},
|
||||
ConvFlag::Sync =>
|
||||
{
|
||||
sync = true;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Ok(ConversionOptions
|
||||
{
|
||||
table,
|
||||
block,
|
||||
unblock,
|
||||
ucase,
|
||||
lcase,
|
||||
sparse,
|
||||
swab,
|
||||
sync,
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_conv_opts(matches: &getopts::Matches) -> Result<Vec<ConvFlag>, Box<dyn Error>>
|
||||
fn parse_conv_opts(matches: &getopts::Matches) -> Result<Vec<ConvFlag>, ParseError>
|
||||
{
|
||||
let mut flags = Vec::new();
|
||||
|
||||
|
|
@ -267,11 +277,187 @@ fn parse_conv_opts(matches: &getopts::Matches) -> Result<Vec<ConvFlag>, Box<dyn
|
|||
Ok(flags)
|
||||
}
|
||||
|
||||
/// Parse Conversion Options (Input Variety)
|
||||
/// Construct and validate a ConvFlagInput
|
||||
pub fn parse_conv_flag_input(matches: &getopts::Matches) -> Result<ConvFlagInput, ParseError>
|
||||
{
|
||||
let flags = parse_conv_opts(matches)?;
|
||||
|
||||
let mut fmt = None;
|
||||
let mut case = None;
|
||||
let mut block = false;
|
||||
let mut unblock = false;
|
||||
let mut swab = false;
|
||||
let mut sync = false;
|
||||
let mut noerror = false;
|
||||
|
||||
for flag in flags
|
||||
{
|
||||
match flag
|
||||
{
|
||||
ConvFlag::FmtEtoA =>
|
||||
if let Some(_) = fmt
|
||||
{
|
||||
return Err(ParseError::MultipleFmtTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt = Some(flag);
|
||||
},
|
||||
ConvFlag::FmtAtoE =>
|
||||
if let Some(_) = fmt
|
||||
{
|
||||
return Err(ParseError::MultipleFmtTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt = Some(flag);
|
||||
},
|
||||
ConvFlag::FmtAtoI =>
|
||||
if let Some(_) = fmt
|
||||
{
|
||||
return Err(ParseError::MultipleFmtTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt = Some(flag);
|
||||
},
|
||||
ConvFlag::UCase =>
|
||||
if let Some(_) = case
|
||||
{
|
||||
return Err(ParseError::MultipleUCaseLCase);
|
||||
}
|
||||
else
|
||||
{
|
||||
case = Some(flag)
|
||||
},
|
||||
ConvFlag::LCase =>
|
||||
if let Some(_) = case
|
||||
{
|
||||
return Err(ParseError::MultipleUCaseLCase);
|
||||
}
|
||||
else
|
||||
{
|
||||
case = Some(flag)
|
||||
},
|
||||
ConvFlag::Block =>
|
||||
if !unblock
|
||||
{
|
||||
block = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Err(ParseError::MultipleBlockUnblock);
|
||||
},
|
||||
ConvFlag::Unblock =>
|
||||
if !block
|
||||
{
|
||||
unblock = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Err(ParseError::MultipleBlockUnblock);
|
||||
},
|
||||
ConvFlag::Swab =>
|
||||
swab = true,
|
||||
ConvFlag::Sync =>
|
||||
sync = true,
|
||||
ConvFlag::NoError =>
|
||||
noerror = true,
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
||||
let ctable = parse_ctable(fmt, case);
|
||||
|
||||
Ok(ConvFlagInput {
|
||||
ctable,
|
||||
block,
|
||||
unblock,
|
||||
swab,
|
||||
sync,
|
||||
noerror,
|
||||
})
|
||||
}
|
||||
|
||||
/// Parse Conversion Options (Output Variety)
|
||||
/// Construct and validate a ConvFlagOutput
|
||||
pub fn parse_conv_flag_output(matches: &getopts::Matches) -> Result<ConvFlagOutput, ParseError>
|
||||
{
|
||||
let flags = parse_conv_opts(matches)?;
|
||||
|
||||
let mut sparse = false;
|
||||
let mut excl = false;
|
||||
let mut nocreat = false;
|
||||
let mut notrunc = false;
|
||||
let mut fdatasync = false;
|
||||
let mut fsync = false;
|
||||
|
||||
for flag in flags
|
||||
{
|
||||
match flag
|
||||
{
|
||||
ConvFlag::Sparse =>
|
||||
sparse = true,
|
||||
ConvFlag::Excl =>
|
||||
excl = true,
|
||||
ConvFlag::NoCreat =>
|
||||
nocreat = true,
|
||||
ConvFlag::NoTrunc =>
|
||||
notrunc = true,
|
||||
ConvFlag::FDataSync =>
|
||||
fdatasync = true,
|
||||
ConvFlag::FSync =>
|
||||
fsync = true,
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
||||
Ok(ConvFlagOutput {
|
||||
sparse,
|
||||
excl,
|
||||
nocreat,
|
||||
notrunc,
|
||||
fdatasync,
|
||||
fsync,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
use super::*;
|
||||
|
||||
// ----- ConvFlagInput/Output -----
|
||||
|
||||
#[test]
|
||||
fn build_cfi()
|
||||
{
|
||||
let cfi_expd = ConvFlagInput {
|
||||
ctable: Some(ASCII_TO_IBM),
|
||||
block: false,
|
||||
unblock: false,
|
||||
swab: false,
|
||||
sync: false,
|
||||
noerror: false,
|
||||
};
|
||||
|
||||
let args = vec![
|
||||
String::from("ketchup"),
|
||||
String::from("mustard"),
|
||||
String::from("--conv=ibm"),
|
||||
String::from("relish"),
|
||||
];
|
||||
|
||||
let matches = build_app!().parse(args);
|
||||
|
||||
let cfi_parsed = parse_conv_flag_input(&matches).unwrap();
|
||||
|
||||
unimplemented!()
|
||||
// assert_eq!(cfi_expd, cfi_parsed);
|
||||
}
|
||||
|
||||
// ----- Multiplier Strings etc. -----
|
||||
macro_rules! test_byte_parser (
|
||||
( $test_name:ident, $bs_str:expr, $bs:expr ) =>
|
||||
{
|
||||
|
|
@ -285,161 +471,122 @@ mod test {
|
|||
}
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_input_parser()
|
||||
{
|
||||
panic!()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_output_parser()
|
||||
{
|
||||
panic!()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conv_parser_ibm_conv_table()
|
||||
{
|
||||
let args = vec![
|
||||
String::from("ketchup"),
|
||||
String::from("mustard"),
|
||||
String::from("--conv=ibm"),
|
||||
String::from("relish"),
|
||||
];
|
||||
|
||||
let matches = build_app!().parse(args);
|
||||
|
||||
assert!(matches.opt_present("conv"));
|
||||
|
||||
if let Some(table) = parse_conv_opts(&matches).unwrap()
|
||||
{
|
||||
for (s, t) in ASCII_TO_IBM.iter().zip(table.iter())
|
||||
{
|
||||
assert_eq!(s, t)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
test_byte_parser!(
|
||||
test_byte_parser!(
|
||||
test_bytes_n,
|
||||
"765",
|
||||
765
|
||||
);
|
||||
test_byte_parser!(
|
||||
test_bytes_c,
|
||||
"13 c",
|
||||
"13c",
|
||||
13
|
||||
);
|
||||
|
||||
test_byte_parser!(
|
||||
test_bytes_w,
|
||||
"1 w",
|
||||
"1w",
|
||||
2
|
||||
);
|
||||
|
||||
test_byte_parser!(
|
||||
test_bytes_b,
|
||||
"1 b",
|
||||
"1b",
|
||||
512
|
||||
);
|
||||
|
||||
test_byte_parser!(
|
||||
test_bytes_k,
|
||||
"1 kB",
|
||||
"1kB",
|
||||
1000
|
||||
);
|
||||
test_byte_parser!(
|
||||
test_bytes_K,
|
||||
"1 K",
|
||||
"1K",
|
||||
1024
|
||||
);
|
||||
test_byte_parser!(
|
||||
test_bytes_Ki,
|
||||
"1 KiB",
|
||||
"1KiB",
|
||||
1024
|
||||
);
|
||||
|
||||
test_byte_parser!(
|
||||
test_bytes_MB,
|
||||
"1 MB",
|
||||
"1MB",
|
||||
1000*1000
|
||||
);
|
||||
test_byte_parser!(
|
||||
test_bytes_M,
|
||||
"1 M",
|
||||
"1M",
|
||||
1024*1024
|
||||
);
|
||||
test_byte_parser!(
|
||||
test_bytes_Mi,
|
||||
"1 MiB",
|
||||
"1MiB",
|
||||
1024*1024
|
||||
);
|
||||
|
||||
test_byte_parser!(
|
||||
test_bytes_GB,
|
||||
"1 GB",
|
||||
"1GB",
|
||||
1000*1000*1000
|
||||
);
|
||||
test_byte_parser!(
|
||||
test_bytes_G,
|
||||
"1 G",
|
||||
"1G",
|
||||
1024*1024*1024
|
||||
);
|
||||
test_byte_parser!(
|
||||
test_bytes_Gi,
|
||||
"1 GiB",
|
||||
"1GiB",
|
||||
1024*1024*1024
|
||||
);
|
||||
|
||||
test_byte_parser!(
|
||||
test_bytes_TB,
|
||||
"1 TB",
|
||||
"1TB",
|
||||
1000*1000*1000*1000
|
||||
);
|
||||
test_byte_parser!(
|
||||
test_bytes_T,
|
||||
"1 T",
|
||||
"1T",
|
||||
1024*1024*1024*1024
|
||||
);
|
||||
test_byte_parser!(
|
||||
test_bytes_Ti,
|
||||
"1 TiB",
|
||||
"1TiB",
|
||||
1024*1024*1024*1024
|
||||
);
|
||||
|
||||
test_byte_parser!(
|
||||
test_bytes_PB,
|
||||
"1 PB",
|
||||
"1PB",
|
||||
1000*1000*1000*1000*1000
|
||||
);
|
||||
test_byte_parser!(
|
||||
test_bytes_P,
|
||||
"1 P",
|
||||
"1P",
|
||||
1024*1024*1024*1024*1024
|
||||
);
|
||||
test_byte_parser!(
|
||||
test_bytes_Pi,
|
||||
"1 PiB",
|
||||
"1PiB",
|
||||
1024*1024*1024*1024*1024
|
||||
);
|
||||
|
||||
test_byte_parser!(
|
||||
test_bytes_EB,
|
||||
"1 EB",
|
||||
"1EB",
|
||||
1000*1000*1000*1000*1000*1000
|
||||
);
|
||||
test_byte_parser!(
|
||||
test_bytes_E,
|
||||
"1 E",
|
||||
"1E",
|
||||
1024*1024*1024*1024*1024*1024
|
||||
);
|
||||
test_byte_parser!(
|
||||
test_bytes_Ei,
|
||||
"1 EiB",
|
||||
"1EiB",
|
||||
1024*1024*1024*1024*1024*1024
|
||||
);
|
||||
|
||||
|
|
@ -449,7 +596,7 @@ mod test {
|
|||
fn test_KB_multiplier_error()
|
||||
{
|
||||
// KB is not valid (kB, K, and KiB are)
|
||||
let bs_str = String::from("2000 KB");
|
||||
let bs_str = String::from("2000KB");
|
||||
|
||||
parse_bytes_with_opt_multiplier(bs_str).unwrap();
|
||||
}
|
||||
|
|
@ -458,7 +605,7 @@ mod test {
|
|||
#[should_panic]
|
||||
fn test_overflow_panic()
|
||||
{
|
||||
let bs_str = format!("{} KiB", usize::MAX);
|
||||
let bs_str = format!("{}KiB", usize::MAX);
|
||||
|
||||
parse_bytes_with_opt_multiplier(bs_str).unwrap();
|
||||
}
|
||||
|
|
@ -467,7 +614,7 @@ mod test {
|
|||
#[should_panic]
|
||||
fn test_neg_panic()
|
||||
{
|
||||
let bs_str = format!("{} KiB", -1);
|
||||
let bs_str = format!("{}KiB", -1);
|
||||
|
||||
parse_bytes_with_opt_multiplier(bs_str).unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,88 +3,51 @@ use super::*;
|
|||
use std::io::prelude::*;
|
||||
use std::io::BufReader;
|
||||
use std::fs;
|
||||
// use md5::{ Md5, Digest, };
|
||||
// use hex_literal::hex;
|
||||
use md5::{ Md5, Digest, };
|
||||
use hex_literal::hex;
|
||||
|
||||
// use tempfile::tempfile;
|
||||
// TODO: (Maybe) Use tempfiles in the tests.
|
||||
|
||||
//macro_rules! make_hash_test (
|
||||
// ( $test_id:ident, $test_name:expr, $src:expr, $exp:expr ) =>
|
||||
// {
|
||||
// #[test]
|
||||
// fn $test_id()
|
||||
// {
|
||||
// let tmp_fname = format!("./test-resources/FAILED-{}.test", $test_name);
|
||||
//
|
||||
// let i = Input {
|
||||
// src: $src,
|
||||
// ibs: 256,
|
||||
// output_progress: false,
|
||||
// };
|
||||
//
|
||||
// let o = Output {
|
||||
// dst: File::create(&tmp_fname).unwrap(),
|
||||
// obs: 1024,
|
||||
// conv_table: None,
|
||||
// };
|
||||
//
|
||||
// dd(i,o).unwrap();
|
||||
//
|
||||
// let res = {
|
||||
// let res = File::open(&tmp_fname).unwrap();
|
||||
// let res = BufReader::new(res);
|
||||
//
|
||||
// let mut h = Md5::new();
|
||||
// for b in res.bytes()
|
||||
// {
|
||||
// h.update([b.unwrap()]);
|
||||
// }
|
||||
//
|
||||
// h.finalize()
|
||||
// };
|
||||
//
|
||||
// assert_eq!(hex!($exp), res[..]);
|
||||
//
|
||||
// fs::remove_file(&tmp_fname).unwrap();
|
||||
// }
|
||||
// };
|
||||
// ( $test_id:ident, $test_name:expr, $i:expr, $o:expr, $exp:expr ) =>
|
||||
// {
|
||||
// #[test]
|
||||
// fn $test_id()
|
||||
// {
|
||||
// let tmp_fname = format!("./test-resources/FAILED-{}.test", $test_name);
|
||||
//
|
||||
// let o = Output {
|
||||
// dst: File::create(&tmp_fname).unwrap(),
|
||||
// obs: $o.obs,
|
||||
// };
|
||||
//
|
||||
// dd($i,o).unwrap();
|
||||
//
|
||||
// let res = {
|
||||
// let res = File::open(&tmp_fname).unwrap();
|
||||
// let res = BufReader::new(res);
|
||||
//
|
||||
// let mut h = Md5::new();
|
||||
// for b in res.bytes()
|
||||
// {
|
||||
// h.update([b.unwrap()]);
|
||||
// }
|
||||
//
|
||||
// h.finalize()
|
||||
// };
|
||||
//
|
||||
// assert_eq!(hex!($exp), res[..]);
|
||||
//
|
||||
// fs::remove_file(&tmp_fname).unwrap();
|
||||
// }
|
||||
// };
|
||||
//);
|
||||
const DEFAULT_CFO: ConvFlagOutput = ConvFlagOutput {
|
||||
sparse: false,
|
||||
excl: false,
|
||||
nocreat: false,
|
||||
notrunc: false,
|
||||
fdatasync: false,
|
||||
fsync: false,
|
||||
};
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! cfi (
|
||||
() =>
|
||||
{
|
||||
cfi!(None)
|
||||
};
|
||||
( $ctable:expr ) =>
|
||||
{
|
||||
ConvFlagInput {
|
||||
ctable: $ctable,
|
||||
block: false,
|
||||
unblock: false,
|
||||
swab: false,
|
||||
sync: false,
|
||||
noerror: false,
|
||||
}
|
||||
};
|
||||
);
|
||||
|
||||
macro_rules! make_spec_test (
|
||||
( $test_id:ident, $test_name:expr, $src:expr ) =>
|
||||
{
|
||||
// When spec not given, output should match input
|
||||
make_spec_test!($test_id, $test_name, $src, None, $src);
|
||||
};
|
||||
( $test_id:ident, $test_name:expr, $src:expr, $spec:expr ) =>
|
||||
{
|
||||
make_spec_test!($test_id, $test_name, $src, None, $spec);
|
||||
};
|
||||
( $test_id:ident, $test_name:expr, $src:expr, $ctable:expr, $spec:expr ) =>
|
||||
{
|
||||
#[test]
|
||||
fn $test_id()
|
||||
|
|
@ -94,70 +57,17 @@ macro_rules! make_spec_test (
|
|||
let i = Input {
|
||||
src: $src,
|
||||
ibs: 512,
|
||||
xfer_stats: StatusLevel::None,
|
||||
cf: cfi!($ctable),
|
||||
};
|
||||
|
||||
let o = Output {
|
||||
dst: File::create(&tmp_fname).unwrap(),
|
||||
obs: 512,
|
||||
cf: DEFAULT_CFO,
|
||||
};
|
||||
|
||||
let opts = Options {
|
||||
conv: Some(ConversionOptions {
|
||||
table: None,
|
||||
block: false,
|
||||
unblock: false,
|
||||
lcase: false,
|
||||
ucase: false,
|
||||
sparse: false,
|
||||
swab: false,
|
||||
sync: false,
|
||||
}),
|
||||
status_level: None,
|
||||
};
|
||||
|
||||
dd($i,o,opts).unwrap();
|
||||
|
||||
let res = File::open(&tmp_fname).unwrap();
|
||||
let res = BufReader::new(res);
|
||||
|
||||
let spec = BufReader::new($spec);
|
||||
|
||||
for (b_res, b_spec) in res.bytes().zip(spec.bytes())
|
||||
{
|
||||
assert_eq!(b_res.unwrap(),
|
||||
b_spec.unwrap());
|
||||
}
|
||||
|
||||
fs::remove_file(&tmp_fname).unwrap();
|
||||
}
|
||||
};
|
||||
( $test_id:ident, $test_name:expr, $i:expr, $o:expr, $conv:expr, $spec:expr ) =>
|
||||
{
|
||||
#[test]
|
||||
fn $test_id()
|
||||
{
|
||||
let tmp_fname = format!("./test-resources/FAILED-{}.test", $test_name);
|
||||
|
||||
let o = Output {
|
||||
dst: File::create(&tmp_fname).unwrap(),
|
||||
obs: $o.obs,
|
||||
};
|
||||
|
||||
let opts = Options {
|
||||
conv: Some(ConversionOptions {
|
||||
table: $conv,
|
||||
block: false,
|
||||
unblock: false,
|
||||
lcase: false,
|
||||
ucase: false,
|
||||
sparse: false,
|
||||
swab: false,
|
||||
sync: false,
|
||||
}),
|
||||
status_level: None,
|
||||
};
|
||||
|
||||
dd($i,o,opts).unwrap();
|
||||
dd(i,o).unwrap();
|
||||
|
||||
let res = File::open(&tmp_fname).unwrap();
|
||||
let res = BufReader::new(res);
|
||||
|
|
@ -175,45 +85,56 @@ macro_rules! make_spec_test (
|
|||
};
|
||||
);
|
||||
|
||||
make_spec_test!(
|
||||
#[test]
|
||||
fn test_input_parser()
|
||||
{
|
||||
let args = vec![
|
||||
String::from("ketchup"),
|
||||
String::from("mustard"),
|
||||
String::from("--conv=ibm"),
|
||||
String::from("relish"),
|
||||
];
|
||||
|
||||
let matches = build_app!().parse(args);
|
||||
// ...
|
||||
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_output_parser()
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
make_spec_test!(
|
||||
zeros_4k_test,
|
||||
"zeros-4k",
|
||||
File::open("./test-resources/zeros-620f0b67a91f7f74151bc5be745b7110.test").unwrap(),
|
||||
File::open("./test-resources/zeros-620f0b67a91f7f74151bc5be745b7110.test").unwrap()
|
||||
);
|
||||
|
||||
make_spec_test!(
|
||||
ones_4k_test,
|
||||
"ones-4k",
|
||||
File::open("./test-resources/ones-6ae59e64850377ee5470c854761551ea.test").unwrap(),
|
||||
File::open("./test-resources/ones-6ae59e64850377ee5470c854761551ea.test").unwrap()
|
||||
);
|
||||
|
||||
make_spec_test!(
|
||||
deadbeef_32k_test,
|
||||
"deadbeef-32k",
|
||||
File::open("./test-resources/deadbeef-18d99661a1de1fc9af21b0ec2cd67ba3.test").unwrap(),
|
||||
File::open("./test-resources/deadbeef-18d99661a1de1fc9af21b0ec2cd67ba3.test").unwrap()
|
||||
);
|
||||
|
||||
make_spec_test!(
|
||||
random_73k_test,
|
||||
"random-73k",
|
||||
File::open("./test-resources/random-5828891cb1230748e146f34223bbd3b5.test").unwrap(),
|
||||
File::open("./test-resources/random-5828891cb1230748e146f34223bbd3b5.test").unwrap()
|
||||
);
|
||||
|
||||
make_spec_test!(
|
||||
atoe_conv_spec_test,
|
||||
"atoe-conv-spec-test",
|
||||
Input {
|
||||
src: File::open("./test-resources/seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test").unwrap(),
|
||||
ibs: 512,
|
||||
},
|
||||
Output {
|
||||
dst: Vec::new(), // unused!
|
||||
obs: 512,
|
||||
},
|
||||
File::open("./test-resources/seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test").unwrap(),
|
||||
Some(ASCII_TO_EBCDIC),
|
||||
File::open("./test-resources/gnudd-conv-atoe-seq-byte-values.spec").unwrap()
|
||||
);
|
||||
|
|
@ -221,14 +142,7 @@ make_spec_test!(
|
|||
make_spec_test!(
|
||||
etoa_conv_spec_test,
|
||||
"etoa-conv-spec-test",
|
||||
Input {
|
||||
src: File::open("./test-resources/seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test").unwrap(),
|
||||
ibs: 512,
|
||||
},
|
||||
Output {
|
||||
dst: Vec::new(), // unused!
|
||||
obs: 512,
|
||||
},
|
||||
File::open("./test-resources/seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test").unwrap(),
|
||||
Some(EBCDIC_TO_ASCII),
|
||||
File::open("./test-resources/gnudd-conv-etoa-seq-byte-values.spec").unwrap()
|
||||
);
|
||||
|
|
@ -236,14 +150,7 @@ make_spec_test!(
|
|||
make_spec_test!(
|
||||
atoibm_conv_spec_test,
|
||||
"atoibm-conv-spec-test",
|
||||
Input {
|
||||
src: File::open("./test-resources/seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test").unwrap(),
|
||||
ibs: 512,
|
||||
},
|
||||
Output {
|
||||
dst: Vec::new(), // unused!
|
||||
obs: 512,
|
||||
},
|
||||
File::open("./test-resources/seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test").unwrap(),
|
||||
Some(ASCII_TO_IBM),
|
||||
File::open("./test-resources/gnudd-conv-atoibm-seq-byte-values.spec").unwrap()
|
||||
);
|
||||
|
|
@ -251,33 +158,95 @@ make_spec_test!(
|
|||
make_spec_test!(
|
||||
lcase_ascii_to_ucase_ascii,
|
||||
"lcase_ascii_to_ucase_ascii",
|
||||
Input {
|
||||
src: File::open("./test-resources/lcase-ascii.test").unwrap(),
|
||||
ibs: 512,
|
||||
},
|
||||
Output {
|
||||
dst: Vec::new(), // unused!
|
||||
obs: 512,
|
||||
},
|
||||
Some(LCASE_TO_UCASE),
|
||||
File::open("./test-resources/lcase-ascii.test").unwrap(),
|
||||
Some(ASCII_LCASE_TO_UCASE),
|
||||
File::open("./test-resources/ucase-ascii.test").unwrap()
|
||||
);
|
||||
|
||||
make_spec_test!(
|
||||
ucase_ascii_to_lcase_ascii,
|
||||
"ucase_ascii_to_lcase_ascii",
|
||||
Input {
|
||||
src: File::open("./test-resources/ucase-ascii.test").unwrap(),
|
||||
ibs: 512,
|
||||
},
|
||||
Output {
|
||||
dst: Vec::new(), // unused!
|
||||
obs: 512,
|
||||
},
|
||||
Some(UCASE_TO_LCASE),
|
||||
File::open("./test-resources/ucase-ascii.test").unwrap(),
|
||||
Some(ASCII_UCASE_TO_LCASE),
|
||||
File::open("./test-resources/lcase-ascii.test").unwrap()
|
||||
);
|
||||
|
||||
// // ***
|
||||
// make_spec_test!(
|
||||
// lcase_ebcdic_to_ucase_ebcdic,
|
||||
// "lcase_ebcdic_to_ucase_ebcdic",
|
||||
// File::open("./test-resources/lcase-ebcdic.test").unwrap(),
|
||||
// None,
|
||||
// Some(EBCDIC_LCASE_TO_UCASE),
|
||||
// File::open("./test-resources/ucase-ebcdic.test").unwrap()
|
||||
// );
|
||||
//
|
||||
// // ***
|
||||
// make_spec_test!(
|
||||
// ucase_ebcdic_to_lcase_ebcdic,
|
||||
// "ucase_ebcdic_to_lcase_ebcdic",
|
||||
// File::open("./test-resources/ucase-ebcdic.test").unwrap(),
|
||||
// None,
|
||||
// Some(EBCDIC_UCASE_TO_LCASE),
|
||||
// File::open("./test-resources/lcase-ebcdic.test").unwrap()
|
||||
// );
|
||||
//
|
||||
// // ***
|
||||
// make_spec_test!(
|
||||
// lcase_ibm_to_ucase_ibm,
|
||||
// "lcase_ibm_to_ucase_ibm",
|
||||
// File::open("./test-resources/lcase-ibm.test").unwrap(),
|
||||
// None,
|
||||
// Some(IBM_LCASE_TO_UCASE),
|
||||
// File::open("./test-resources/ucase-ibm.test").unwrap()
|
||||
// );
|
||||
//
|
||||
// // ***
|
||||
// make_spec_test!(
|
||||
// ucase_ibm_to_lcase_ibm,
|
||||
// "ucase_ibm_to_lcase_ibm",
|
||||
// File::open("./test-resources/ucase-ibm.test").unwrap(),
|
||||
// None,
|
||||
// Some(IBM_UCASE_TO_LCASE),
|
||||
// File::open("./test-resources/lcase-ibm.test").unwrap()
|
||||
// );
|
||||
|
||||
make_spec_test!(
|
||||
// conv=ebcdic,ucase
|
||||
atoe_and_ucase_conv_spec_test,
|
||||
"atoe-and-ucase-conv-spec-test",
|
||||
File::open("./test-resources/seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test").unwrap(),
|
||||
Some(ASCII_TO_EBCDIC_LCASE_TO_UCASE),
|
||||
File::open("./test-resources/ucase-ebcdic.test").unwrap()
|
||||
);
|
||||
|
||||
make_spec_test!(
|
||||
// conv=ebcdic,lcase
|
||||
atoe_and_lcase_conv_spec_test,
|
||||
"atoe-and-lcase-conv-spec-test",
|
||||
File::open("./test-resources/seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test").unwrap(),
|
||||
Some(ASCII_TO_EBCDIC_UCASE_TO_LCASE),
|
||||
File::open("./test-resources/lcase-ebcdic.test").unwrap()
|
||||
);
|
||||
|
||||
make_spec_test!(
|
||||
// conv=ibm,ucase
|
||||
atoibm_and_ucase_conv_spec_test,
|
||||
"atoibm-and-ucase-conv-spec-test",
|
||||
File::open("./test-resources/seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test").unwrap(),
|
||||
Some(ASCII_TO_IBM_UCASE_TO_LCASE),
|
||||
File::open("./test-resources/lcase-ibm.test").unwrap()
|
||||
);
|
||||
|
||||
make_spec_test!(
|
||||
// conv=ibm,lcase
|
||||
atoibm_and_lcase_conv_spec_test,
|
||||
"atoibm-and-lcase-conv-spec-test",
|
||||
File::open("./test-resources/seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test").unwrap(),
|
||||
Some(ASCII_TO_IBM_LCASE_TO_UCASE),
|
||||
File::open("./test-resources/ucase-ibm.test").unwrap()
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test()
|
||||
{
|
||||
|
|
@ -288,28 +257,17 @@ fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test()
|
|||
let i = Input {
|
||||
src: File::open("./test-resources/all-valid-ascii-chars-37eff01866ba3f538421b30b7cbefcac.test").unwrap(),
|
||||
ibs: 256,
|
||||
xfer_stats: StatusLevel::None,
|
||||
cf: cfi!(Some(ASCII_TO_EBCDIC)),
|
||||
};
|
||||
|
||||
let o = Output {
|
||||
dst: File::create(&tmp_fname_ae).unwrap(),
|
||||
obs: 1024,
|
||||
cf: DEFAULT_CFO,
|
||||
};
|
||||
|
||||
let opts = Options {
|
||||
conv: Some(ConversionOptions {
|
||||
table: Some(ASCII_TO_EBCDIC),
|
||||
block: false,
|
||||
unblock: false,
|
||||
lcase: false,
|
||||
ucase: false,
|
||||
sparse: false,
|
||||
swab: false,
|
||||
sync: false,
|
||||
}),
|
||||
status_level: None,
|
||||
};
|
||||
|
||||
dd(i,o,opts).unwrap();
|
||||
dd(i,o).unwrap();
|
||||
|
||||
// EBCDIC->ASCII
|
||||
let test_name = "all-valid-ebcdic-to-ascii";
|
||||
|
|
@ -318,28 +276,17 @@ fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test()
|
|||
let i = Input {
|
||||
src: File::open(&tmp_fname_ae).unwrap(),
|
||||
ibs: 256,
|
||||
xfer_stats: StatusLevel::None,
|
||||
cf: cfi!(Some(EBCDIC_TO_ASCII)),
|
||||
};
|
||||
|
||||
let o = Output {
|
||||
dst: File::create(&tmp_fname_ea).unwrap(),
|
||||
obs: 1024,
|
||||
cf: DEFAULT_CFO,
|
||||
};
|
||||
|
||||
let opts = Options {
|
||||
conv: Some(ConversionOptions {
|
||||
table: Some(ASCII_TO_EBCDIC),
|
||||
block: false,
|
||||
unblock: false,
|
||||
lcase: false,
|
||||
ucase: false,
|
||||
sparse: false,
|
||||
swab: false,
|
||||
sync: false,
|
||||
}),
|
||||
status_level: None,
|
||||
};
|
||||
|
||||
dd(i,o,opts).unwrap();
|
||||
dd(i,o).unwrap();
|
||||
|
||||
let res = {
|
||||
let res = File::open(&tmp_fname_ea).unwrap();
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
src/uu/dd/test-resources/lcase-ebcdic.spec
Normal file
BIN
src/uu/dd/test-resources/lcase-ebcdic.spec
Normal file
Binary file not shown.
BIN
src/uu/dd/test-resources/lcase-ebcdic.test
Normal file
BIN
src/uu/dd/test-resources/lcase-ebcdic.test
Normal file
Binary file not shown.
BIN
src/uu/dd/test-resources/lcase-ibm.spec
Normal file
BIN
src/uu/dd/test-resources/lcase-ibm.spec
Normal file
Binary file not shown.
BIN
src/uu/dd/test-resources/lcase-ibm.test
Normal file
BIN
src/uu/dd/test-resources/lcase-ibm.test
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/uu/dd/test-resources/ucase-ebcdic.spec
Normal file
BIN
src/uu/dd/test-resources/ucase-ebcdic.spec
Normal file
Binary file not shown.
BIN
src/uu/dd/test-resources/ucase-ebcdic.test
Normal file
BIN
src/uu/dd/test-resources/ucase-ebcdic.test
Normal file
Binary file not shown.
BIN
src/uu/dd/test-resources/ucase-ibm.spec
Normal file
BIN
src/uu/dd/test-resources/ucase-ibm.spec
Normal file
Binary file not shown.
BIN
src/uu/dd/test-resources/ucase-ibm.test
Normal file
BIN
src/uu/dd/test-resources/ucase-ibm.test
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue