1 /*
2 Bacula(R) - The Network Backup Solution
3
4 Copyright (C) 2000-2020 Kern Sibbald
5
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
8
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
13
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
16
17 Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /*
20 * Taken from the public domain ansitape program for
21 * integration into Bacula. KES - Mar 2005
22 */
23
24
25 /* Mapping of EBCDIC codes to ASCII equivalents. */
26 static char to_ascii_table[256] = {
27 '\000', '\001', '\002', '\003',
28 '\234', '\011', '\206', '\177',
29 '\227', '\215', '\216', '\013',
30 '\014', '\015', '\016', '\017',
31 '\020', '\021', '\022', '\023',
32 '\235', '\205', '\010', '\207',
33 '\030', '\031', '\222', '\217',
34 '\034', '\035', '\036', '\037',
35 '\200', '\201', '\202', '\203',
36 '\204', '\012', '\027', '\033',
37 '\210', '\211', '\212', '\213',
38 '\214', '\005', '\006', '\007',
39 '\220', '\221', '\026', '\223',
40 '\224', '\225', '\226', '\004',
41 '\230', '\231', '\232', '\233',
42 '\024', '\025', '\236', '\032',
43 '\040', '\240', '\241', '\242',
44 '\243', '\244', '\245', '\246',
45 '\247', '\250', '\133', '\056',
46 '\074', '\050', '\053', '\041',
47 '\046', '\251', '\252', '\253',
48 '\254', '\255', '\256', '\257',
49 '\260', '\261', '\135', '\044',
50 '\052', '\051', '\073', '\136',
51 '\055', '\057', '\262', '\263',
52 '\264', '\265', '\266', '\267',
53 '\270', '\271', '\174', '\054',
54 '\045', '\137', '\076', '\077',
55 '\272', '\273', '\274', '\275',
56 '\276', '\277', '\300', '\301',
57 '\302', '\140', '\072', '\043',
58 '\100', '\047', '\075', '\042',
59 '\303', '\141', '\142', '\143',
60 '\144', '\145', '\146', '\147',
61 '\150', '\151', '\304', '\305',
62 '\306', '\307', '\310', '\311',
63 '\312', '\152', '\153', '\154',
64 '\155', '\156', '\157', '\160',
65 '\161', '\162', '\313', '\314',
66 '\315', '\316', '\317', '\320',
67 '\321', '\176', '\163', '\164',
68 '\165', '\166', '\167', '\170',
69 '\171', '\172', '\322', '\323',
70 '\324', '\325', '\326', '\327',
71 '\330', '\331', '\332', '\333',
72 '\334', '\335', '\336', '\337',
73 '\340', '\341', '\342', '\343',
74 '\344', '\345', '\346', '\347',
75 '\173', '\101', '\102', '\103',
76 '\104', '\105', '\106', '\107',
77 '\110', '\111', '\350', '\351',
78 '\352', '\353', '\354', '\355',
79 '\175', '\112', '\113', '\114',
80 '\115', '\116', '\117', '\120',
81 '\121', '\122', '\356', '\357',
82 '\360', '\361', '\362', '\363',
83 '\134', '\237', '\123', '\124',
84 '\125', '\126', '\127', '\130',
85 '\131', '\132', '\364', '\365',
86 '\366', '\367', '\370', '\371',
87 '\060', '\061', '\062', '\063',
88 '\064', '\065', '\066', '\067',
89 '\070', '\071', '\372', '\373',
90 '\374', '\375', '\376', '\377'
91 };
92
93
94 /* Mapping of ASCII codes to EBCDIC equivalents. */
95 static char to_ebcdic_table[256] = {
96 '\000', '\001', '\002', '\003',
97 '\067', '\055', '\056', '\057',
98 '\026', '\005', '\045', '\013',
99 '\014', '\015', '\016', '\017',
100 '\020', '\021', '\022', '\023',
101 '\074', '\075', '\062', '\046',
102 '\030', '\031', '\077', '\047',
103 '\034', '\035', '\036', '\037',
104 '\100', '\117', '\177', '\173',
105 '\133', '\154', '\120', '\175',
106 '\115', '\135', '\134', '\116',
107 '\153', '\140', '\113', '\141',
108 '\360', '\361', '\362', '\363',
109 '\364', '\365', '\366', '\367',
110 '\370', '\371', '\172', '\136',
111 '\114', '\176', '\156', '\157',
112 '\174', '\301', '\302', '\303',
113 '\304', '\305', '\306', '\307',
114 '\310', '\311', '\321', '\322',
115 '\323', '\324', '\325', '\326',
116 '\327', '\330', '\331', '\342',
117 '\343', '\344', '\345', '\346',
118 '\347', '\350', '\351', '\112',
119 '\340', '\132', '\137', '\155',
120 '\171', '\201', '\202', '\203',
121 '\204', '\205', '\206', '\207',
122 '\210', '\211', '\221', '\222',
123 '\223', '\224', '\225', '\226',
124 '\227', '\230', '\231', '\242',
125 '\243', '\244', '\245', '\246',
126 '\247', '\250', '\251', '\300',
127 '\152', '\320', '\241', '\007',
128 '\040', '\041', '\042', '\043',
129 '\044', '\025', '\006', '\027',
130 '\050', '\051', '\052', '\053',
131 '\054', '\011', '\012', '\033',
132 '\060', '\061', '\032', '\063',
133 '\064', '\065', '\066', '\010',
134 '\070', '\071', '\072', '\073',
135 '\004', '\024', '\076', '\341',
136 '\101', '\102', '\103', '\104',
137 '\105', '\106', '\107', '\110',
138 '\111', '\121', '\122', '\123',
139 '\124', '\125', '\126', '\127',
140 '\130', '\131', '\142', '\143',
141 '\144', '\145', '\146', '\147',
142 '\150', '\151', '\160', '\161',
143 '\162', '\163', '\164', '\165',
144 '\166', '\167', '\170', '\200',
145 '\212', '\213', '\214', '\215',
146 '\216', '\217', '\220', '\232',
147 '\233', '\234', '\235', '\236',
148 '\237', '\240', '\252', '\253',
149 '\254', '\255', '\256', '\257',
150 '\260', '\261', '\262', '\263',
151 '\264', '\265', '\266', '\267',
152 '\270', '\271', '\272', '\273',
153 '\274', '\275', '\276', '\277',
154 '\312', '\313', '\314', '\315',
155 '\316', '\317', '\332', '\333',
156 '\334', '\335', '\336', '\337',
157 '\352', '\353', '\354', '\355',
158 '\356', '\357', '\372', '\373',
159 '\374', '\375', '\376', '\377'
160 };
161
162
163 /*
164 * Convert from ASCII to EBCDIC
165 */
ascii_to_ebcdic(char * dst,char * src,int count)166 void ascii_to_ebcdic(char *dst, char *src, int count)
167 {
168 while (count--) {
169 *dst++ = to_ebcdic_table[0377 & *src++];
170 }
171 }
172
173
174 /*
175 * Convert from EBCDIC to ASCII
176 */
ebcdic_to_ascii(char * dst,char * src,int count)177 void ebcdic_to_ascii(char *dst, char *src, int count)
178 {
179 while (count--) {
180 *dst++ = to_ascii_table[0377 & *src++];
181 }
182 }
183