Skip to content

Commit 427a552

Browse files
authored
Merge pull request #226 from v1gnesh/master
Add codepage 1047 for EBCDIC
2 parents d2cc025 + 120cf29 commit 427a552

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

src/colors.rs

+34
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,37 @@ pub const CP437: [char; 256] = [
4646
'α','ß','Γ','π','Σ','σ','µ','τ','Φ','Θ','Ω','δ','∞','φ','ε','∩',
4747
'≡','±','≥','≤','⌠','⌡','÷','≈','°','∙','·','√','ⁿ','²','■','ff',
4848
];
49+
50+
#[rustfmt::skip]
51+
pub const CP1047: [char; 256] = [
52+
//
53+
// Copyright (c) 2016,2024 IBM Corporation and other Contributors.
54+
//
55+
// All rights reserved. This program and the accompanying materials
56+
// are made available under the terms of the Eclipse Public License v1.0
57+
// which accompanies this distribution, and is available at
58+
// http://www.eclipse.org/legal/epl-v10.html
59+
//
60+
// Contributors:
61+
// Mark Taylor - Initial Contribution
62+
//
63+
64+
// ref1 https://github.com/ibm-messaging/mq-smf-csv/blob/master/src/smfConv.c
65+
// ref2 https://web.archive.org/web/20150607033635/http://www-01.ibm.com/software/globalization/cp/cp01047.html
66+
'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
67+
'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
68+
'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
69+
'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',
70+
' ','.','.','.','.','.','.','.','.','.','$','.','<','(','+','|',
71+
'&','.','.','.','.','.','.','.','.','.','!','$','*',')',';','.',
72+
'-','/','.','.','.','.','.','.','.','.','.',',','%','_','>','?',
73+
'.','.','.','.','.','.','.','.','.','.',':','#','@','\'','=','.',
74+
'.','a','b','c','d','e','f','g','h','i','.','{','.','(','+','.',
75+
'.','j','k','l','m','n','o','p','q','r','.','}','.',')','.','.',
76+
'.','~','s','t','u','v','w','x','y','z','.','.','.','.','.','.',
77+
'.','.','.','.','.','.','.','.','.','.','[',']','.','.','.','-',
78+
'{','A','B','C','D','E','F','G','H','I','.','.','.','.','.','.',
79+
'}','J','K','L','M','N','O','P','Q','R','.','.','.','.','.','.',
80+
'.','.','S','T','U','V','W','X','Y','Z','.','.','.','.','.','.',
81+
'0','1','2','3','4','5','6','7','8','9','.','.','.','.','.','.'
82+
];

src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ pub enum CharacterTable {
3636
/// Show printable ASCII as-is, ' ' for space, '.' for everything else.
3737
Ascii,
3838

39+
/// Show printable EBCDIC as-is, ' ' for space, '.' for everything else.
40+
#[value(name = "codepage-1047")]
41+
CP1047,
42+
3943
/// Uses code page 437 (for non-ASCII bytes).
4044
#[value(name = "codepage-437")]
4145
CP437,
@@ -107,6 +111,7 @@ impl Byte {
107111
AsciiOther => '.',
108112
NonAscii => '.',
109113
},
114+
CharacterTable::CP1047 => CP1047[self.0 as usize],
110115
CharacterTable::CP437 => CP437[self.0 as usize],
111116
}
112117
}

tests/integration_tests.rs

+54
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,60 @@ mod character_table {
727727
│00002110│ 00 00 00 00 00 00 00 00 ┊ 01 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊☺⋄⋄⋄⋄⋄⋄⋄│
728728
│00002120│ 00 00 00 00 00 00 00 00 ┊ │⋄⋄⋄⋄⋄⋄⋄⋄┊ │
729729
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘
730+
",
731+
);
732+
}
733+
734+
#[test]
735+
fn codepage_1047() {
736+
hexyl()
737+
.arg("hello_world_elf64")
738+
.arg("--color=never")
739+
.arg("--character-table=codepage-1047")
740+
.assert()
741+
.success()
742+
.pretty_stdout(
743+
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
744+
│00000000│ 7f 45 4c 46 02 01 01 00 ┊ 00 00 00 00 00 00 00 00 │..<.....┊........│
745+
│00000010│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │........┊.. .....│
746+
│00000020│ 40 00 00 00 00 00 00 00 ┊ 28 20 00 00 00 00 00 00 │ .......┊........│
747+
│00000030│ 00 00 00 00 40 00 38 00 ┊ 03 00 40 00 04 00 03 00 │.... ...┊.. .....│
748+
│00000040│ 01 00 00 00 04 00 00 00 ┊ 00 00 00 00 00 00 00 00 │........┊........│
749+
│00000050│ 00 00 40 00 00 00 00 00 ┊ 00 00 40 00 00 00 00 00 │.. .....┊.. .....│
750+
│00000060│ e8 00 00 00 00 00 00 00 ┊ e8 00 00 00 00 00 00 00 │Y.......┊Y.......│
751+
│00000070│ 00 10 00 00 00 00 00 00 ┊ 01 00 00 00 05 00 00 00 │........┊........│
752+
│00000080│ 00 10 00 00 00 00 00 00 ┊ 00 10 40 00 00 00 00 00 │........┊.. .....│
753+
│00000090│ 00 10 40 00 00 00 00 00 ┊ 1d 00 00 00 00 00 00 00 │.. .....┊........│
754+
│000000a0│ 1d 00 00 00 00 00 00 00 ┊ 00 10 00 00 00 00 00 00 │........┊........│
755+
│000000b0│ 01 00 00 00 06 00 00 00 ┊ 00 20 00 00 00 00 00 00 │........┊........│
756+
│000000c0│ 00 20 40 00 00 00 00 00 ┊ 00 20 40 00 00 00 00 00 │.. .....┊.. .....│
757+
│000000d0│ 0e 00 00 00 00 00 00 00 ┊ 0e 00 00 00 00 00 00 00 │........┊........│
758+
│000000e0│ 00 10 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │........┊........│
759+
│000000f0│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │........┊........│
760+
│* │ ┊ │ ┊ │
761+
│00001000│ ba 0e 00 00 00 b9 00 20 ┊ 40 00 bb 01 00 00 00 b8 │[.......┊ .].....│
762+
│00001010│ 04 00 00 00 cd 80 b8 01 ┊ 00 00 00 cd 80 00 00 00 │........┊........│
763+
│00001020│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │........┊........│
764+
│* │ ┊ │ ┊ │
765+
│00002000│ 48 65 6c 6c 6f 2c 20 77 ┊ 6f 72 6c 64 21 0a 00 2e │..%%?...┊?.%.....│
766+
│00002010│ 73 68 73 74 72 74 61 62 ┊ 00 2e 74 65 78 74 00 2e │....../.┊........│
767+
│00002020│ 64 61 74 61 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │././....┊........│
768+
│00002030│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │........┊........│
769+
│* │ ┊ │ ┊ │
770+
│00002060│ 00 00 00 00 00 00 00 00 ┊ 0b 00 00 00 01 00 00 00 │........┊........│
771+
│00002070│ 06 00 00 00 00 00 00 00 ┊ 00 10 40 00 00 00 00 00 │........┊.. .....│
772+
│00002080│ 00 10 00 00 00 00 00 00 ┊ 1d 00 00 00 00 00 00 00 │........┊........│
773+
│00002090│ 00 00 00 00 00 00 00 00 ┊ 10 00 00 00 00 00 00 00 │........┊........│
774+
│000020a0│ 00 00 00 00 00 00 00 00 ┊ 11 00 00 00 01 00 00 00 │........┊........│
775+
│000020b0│ 03 00 00 00 00 00 00 00 ┊ 00 20 40 00 00 00 00 00 │........┊.. .....│
776+
│000020c0│ 00 20 00 00 00 00 00 00 ┊ 0e 00 00 00 00 00 00 00 │........┊........│
777+
│000020d0│ 00 00 00 00 00 00 00 00 ┊ 04 00 00 00 00 00 00 00 │........┊........│
778+
│000020e0│ 00 00 00 00 00 00 00 00 ┊ 01 00 00 00 03 00 00 00 │........┊........│
779+
│000020f0│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │........┊........│
780+
│00002100│ 0e 20 00 00 00 00 00 00 ┊ 17 00 00 00 00 00 00 00 │........┊........│
781+
│00002110│ 00 00 00 00 00 00 00 00 ┊ 01 00 00 00 00 00 00 00 │........┊........│
782+
│00002120│ 00 00 00 00 00 00 00 00 ┊ │........┊ │
783+
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘
730784
",
731785
);
732786
}

0 commit comments

Comments
 (0)