]> git.saurik.com Git - apple/file_cmds.git/blame_incremental - dd/conv_tab.c
file_cmds-46.tar.gz
[apple/file_cmds.git] / dd / conv_tab.c
... / ...
CommitLineData
1/* $NetBSD: conv_tab.c,v 1.8 1997/07/20 21:58:38 christos Exp $ */
2
3/*-
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Keith Muller of the University of California, San Diego and Lance
9 * Visser of Convex Computer Corporation.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 */
39
40#include <sys/cdefs.h>
41#ifndef lint
42#if 0
43static char sccsid[] = "@(#)conv_tab.c 8.1 (Berkeley) 5/31/93";
44#else
45__RCSID("$NetBSD: conv_tab.c,v 1.8 1997/07/20 21:58:38 christos Exp $");
46#endif
47#endif /* not lint */
48
49#include <sys/types.h>
50
51/*
52 * There are currently six tables:
53 *
54 * ebcdic -> ascii 32V conv=oldascii
55 * ascii -> ebcdic 32V conv=oldebcdic
56 * ascii -> ibm ebcdic 32V conv=oldibm
57 *
58 * ebcdic -> ascii POSIX/S5 conv=ascii
59 * ascii -> ebcdic POSIX/S5 conv=ebcdic
60 * ascii -> ibm ebcdic POSIX/S5 conv=ibm
61 *
62 * Other tables are built from these if multiple conversions are being
63 * done.
64 *
65 * Tables used for conversions to/from IBM and EBCDIC to support an extension
66 * to POSIX P1003.2/D11. The tables referencing POSIX contain data extracted
67 * from tables 4-3 and 4-4 in P1003.2/Draft 11. The historic tables were
68 * constructed by running against a file with all possible byte values.
69 *
70 * More information can be obtained in "Correspondences of 8-Bit and Hollerith
71 * Codes for Computer Environments-A USASI Tutorial", Communications of the
72 * ACM, Volume 11, Number 11, November 1968, pp. 783-789.
73 */
74
75u_char casetab[256];
76
77/* EBCDIC to ASCII -- 32V compatible. */
78const u_char e2a_32V[] = {
79 0000, 0001, 0002, 0003, 0234, 0011, 0206, 0177, /* 0000 */
80 0227, 0215, 0216, 0013, 0014, 0015, 0016, 0017, /* 0010 */
81 0020, 0021, 0022, 0023, 0235, 0205, 0010, 0207, /* 0020 */
82 0030, 0031, 0222, 0217, 0034, 0035, 0036, 0037, /* 0030 */
83 0200, 0201, 0202, 0203, 0204, 0012, 0027, 0033, /* 0040 */
84 0210, 0211, 0212, 0213, 0214, 0005, 0006, 0007, /* 0050 */
85 0220, 0221, 0026, 0223, 0224, 0225, 0226, 0004, /* 0060 */
86 0230, 0231, 0232, 0233, 0024, 0025, 0236, 0032, /* 0070 */
87 0040, 0240, 0241, 0242, 0243, 0244, 0245, 0246, /* 0100 */
88 0247, 0250, 0133, 0056, 0074, 0050, 0053, 0041, /* 0110 */
89 0046, 0251, 0252, 0253, 0254, 0255, 0256, 0257, /* 0120 */
90 0260, 0261, 0135, 0044, 0052, 0051, 0073, 0136, /* 0130 */
91 0055, 0057, 0262, 0263, 0264, 0265, 0266, 0267, /* 0140 */
92 0270, 0271, 0174, 0054, 0045, 0137, 0076, 0077, /* 0150 */
93 0272, 0273, 0274, 0275, 0276, 0277, 0300, 0301, /* 0160 */
94 0302, 0140, 0072, 0043, 0100, 0047, 0075, 0042, /* 0170 */
95 0303, 0141, 0142, 0143, 0144, 0145, 0146, 0147, /* 0200 */
96 0150, 0151, 0304, 0305, 0306, 0307, 0310, 0311, /* 0210 */
97 0312, 0152, 0153, 0154, 0155, 0156, 0157, 0160, /* 0220 */
98 0161, 0162, 0313, 0314, 0315, 0316, 0317, 0320, /* 0230 */
99 0321, 0176, 0163, 0164, 0165, 0166, 0167, 0170, /* 0240 */
100 0171, 0172, 0322, 0323, 0324, 0325, 0326, 0327, /* 0250 */
101 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337, /* 0260 */
102 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347, /* 0270 */
103 0173, 0101, 0102, 0103, 0104, 0105, 0106, 0107, /* 0300 */
104 0110, 0111, 0350, 0351, 0352, 0353, 0354, 0355, /* 0310 */
105 0175, 0112, 0113, 0114, 0115, 0116, 0117, 0120, /* 0320 */
106 0121, 0122, 0356, 0357, 0360, 0361, 0362, 0363, /* 0330 */
107 0134, 0237, 0123, 0124, 0125, 0126, 0127, 0130, /* 0340 */
108 0131, 0132, 0364, 0365, 0366, 0367, 0370, 0371, /* 0350 */
109 0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067, /* 0360 */
110 0070, 0071, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
111};
112
113/* ASCII to EBCDIC -- 32V compatible. */
114const u_char a2e_32V[] = {
115 0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057, /* 0000 */
116 0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017, /* 0010 */
117 0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046, /* 0020 */
118 0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037, /* 0030 */
119 0100, 0117, 0177, 0173, 0133, 0154, 0120, 0175, /* 0040 */
120 0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141, /* 0050 */
121 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, /* 0060 */
122 0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157, /* 0070 */
123 0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307, /* 0100 */
124 0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326, /* 0110 */
125 0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346, /* 0120 */
126 0347, 0350, 0351, 0112, 0340, 0132, 0137, 0155, /* 0130 */
127 0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207, /* 0140 */
128 0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226, /* 0150 */
129 0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246, /* 0160 */
130 0247, 0250, 0251, 0300, 0152, 0320, 0241, 0007, /* 0170 */
131 0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027, /* 0200 */
132 0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033, /* 0210 */
133 0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010, /* 0220 */
134 0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341, /* 0230 */
135 0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, /* 0240 */
136 0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127, /* 0250 */
137 0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147, /* 0260 */
138 0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165, /* 0270 */
139 0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215, /* 0300 */
140 0216, 0217, 0220, 0232, 0233, 0234, 0235, 0236, /* 0310 */
141 0237, 0240, 0252, 0253, 0254, 0255, 0256, 0257, /* 0320 */
142 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, /* 0330 */
143 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, /* 0340 */
144 0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333, /* 0350 */
145 0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355, /* 0360 */
146 0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
147};
148
149/* ASCII to IBM EBCDIC -- 32V compatible. */
150const u_char a2ibm_32V[] = {
151 0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057, /* 0000 */
152 0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017, /* 0010 */
153 0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046, /* 0020 */
154 0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037, /* 0030 */
155 0100, 0132, 0177, 0173, 0133, 0154, 0120, 0175, /* 0040 */
156 0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141, /* 0050 */
157 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, /* 0060 */
158 0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157, /* 0070 */
159 0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307, /* 0100 */
160 0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326, /* 0110 */
161 0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346, /* 0120 */
162 0347, 0350, 0351, 0255, 0340, 0275, 0137, 0155, /* 0130 */
163 0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207, /* 0140 */
164 0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226, /* 0150 */
165 0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246, /* 0160 */
166 0247, 0250, 0251, 0300, 0117, 0320, 0241, 0007, /* 0170 */
167 0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027, /* 0200 */
168 0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033, /* 0210 */
169 0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010, /* 0220 */
170 0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341, /* 0230 */
171 0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, /* 0240 */
172 0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127, /* 0250 */
173 0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147, /* 0260 */
174 0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165, /* 0270 */
175 0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215, /* 0300 */
176 0216, 0217, 0220, 0232, 0233, 0234, 0235, 0236, /* 0310 */
177 0237, 0240, 0252, 0253, 0254, 0255, 0256, 0257, /* 0320 */
178 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, /* 0330 */
179 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, /* 0340 */
180 0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333, /* 0350 */
181 0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355, /* 0360 */
182 0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
183};
184
185/* EBCDIC to ASCII -- POSIX and System V compatible. */
186const u_char e2a_POSIX[] = {
187 0000, 0001, 0002, 0003, 0234, 0011, 0206, 0177, /* 0000 */
188 0227, 0215, 0216, 0013, 0014, 0015, 0016, 0017, /* 0010 */
189 0020, 0021, 0022, 0023, 0235, 0205, 0010, 0207, /* 0020 */
190 0030, 0031, 0222, 0217, 0034, 0035, 0036, 0037, /* 0030 */
191 0200, 0201, 0202, 0203, 0204, 0012, 0027, 0033, /* 0040 */
192 0210, 0211, 0212, 0213, 0214, 0005, 0006, 0007, /* 0050 */
193 0220, 0221, 0026, 0223, 0224, 0225, 0226, 0004, /* 0060 */
194 0230, 0231, 0232, 0233, 0024, 0025, 0236, 0032, /* 0070 */
195 0040, 0240, 0241, 0242, 0243, 0244, 0245, 0246, /* 0100 */
196 0247, 0250, 0325, 0056, 0074, 0050, 0053, 0174, /* 0110 */
197 0046, 0251, 0252, 0253, 0254, 0255, 0256, 0257, /* 0120 */
198 0260, 0261, 0041, 0044, 0052, 0051, 0073, 0176, /* 0130 */
199 0055, 0057, 0262, 0263, 0264, 0265, 0266, 0267, /* 0140 */
200 0270, 0271, 0313, 0054, 0045, 0137, 0076, 0077, /* 0150 */
201 0272, 0273, 0274, 0275, 0276, 0277, 0300, 0301, /* 0160 */
202 0302, 0140, 0072, 0043, 0100, 0047, 0075, 0042, /* 0170 */
203 0303, 0141, 0142, 0143, 0144, 0145, 0146, 0147, /* 0200 */
204 0150, 0151, 0304, 0305, 0306, 0307, 0310, 0311, /* 0210 */
205 0312, 0152, 0153, 0154, 0155, 0156, 0157, 0160, /* 0220 */
206 0161, 0162, 0136, 0314, 0315, 0316, 0317, 0320, /* 0230 */
207 0321, 0345, 0163, 0164, 0165, 0166, 0167, 0170, /* 0240 */
208 0171, 0172, 0322, 0323, 0324, 0133, 0326, 0327, /* 0250 */
209 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337, /* 0260 */
210 0340, 0341, 0342, 0343, 0344, 0135, 0346, 0347, /* 0270 */
211 0173, 0101, 0102, 0103, 0104, 0105, 0106, 0107, /* 0300 */
212 0110, 0111, 0350, 0351, 0352, 0353, 0354, 0355, /* 0310 */
213 0175, 0112, 0113, 0114, 0115, 0116, 0117, 0120, /* 0320 */
214 0121, 0122, 0356, 0357, 0360, 0361, 0362, 0363, /* 0330 */
215 0134, 0237, 0123, 0124, 0125, 0126, 0127, 0130, /* 0340 */
216 0131, 0132, 0364, 0365, 0366, 0367, 0370, 0371, /* 0350 */
217 0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067, /* 0360 */
218 0070, 0071, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
219};
220
221/* ASCII to EBCDIC -- POSIX and System V compatible. */
222const u_char a2e_POSIX[] = {
223 0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057, /* 0000 */
224 0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017, /* 0010 */
225 0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046, /* 0020 */
226 0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037, /* 0030 */
227 0100, 0132, 0177, 0173, 0133, 0154, 0120, 0175, /* 0040 */
228 0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141, /* 0050 */
229 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, /* 0060 */
230 0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157, /* 0070 */
231 0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307, /* 0100 */
232 0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326, /* 0110 */
233 0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346, /* 0120 */
234 0347, 0350, 0351, 0255, 0340, 0275, 0232, 0155, /* 0130 */
235 0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207, /* 0140 */
236 0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226, /* 0150 */
237 0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246, /* 0160 */
238 0247, 0250, 0251, 0300, 0117, 0320, 0137, 0007, /* 0170 */
239 0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027, /* 0200 */
240 0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033, /* 0210 */
241 0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010, /* 0220 */
242 0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341, /* 0230 */
243 0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, /* 0240 */
244 0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127, /* 0250 */
245 0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147, /* 0260 */
246 0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165, /* 0270 */
247 0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215, /* 0300 */
248 0216, 0217, 0220, 0152, 0233, 0234, 0235, 0236, /* 0310 */
249 0237, 0240, 0252, 0253, 0254, 0112, 0256, 0257, /* 0320 */
250 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, /* 0330 */
251 0270, 0271, 0272, 0273, 0274, 0241, 0276, 0277, /* 0340 */
252 0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333, /* 0350 */
253 0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355, /* 0360 */
254 0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
255};
256
257/* ASCII to IBM EBCDIC -- POSIX and System V compatible. */
258const u_char a2ibm_POSIX[] = {
259 0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057, /* 0000 */
260 0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017, /* 0010 */
261 0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046, /* 0020 */
262 0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037, /* 0030 */
263 0100, 0132, 0177, 0173, 0133, 0154, 0120, 0175, /* 0040 */
264 0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141, /* 0050 */
265 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, /* 0060 */
266 0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157, /* 0070 */
267 0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307, /* 0100 */
268 0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326, /* 0110 */
269 0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346, /* 0120 */
270 0347, 0350, 0351, 0255, 0340, 0275, 0137, 0155, /* 0130 */
271 0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207, /* 0140 */
272 0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226, /* 0150 */
273 0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246, /* 0160 */
274 0247, 0250, 0251, 0300, 0117, 0320, 0241, 0007, /* 0170 */
275 0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027, /* 0200 */
276 0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033, /* 0210 */
277 0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010, /* 0220 */
278 0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341, /* 0230 */
279 0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, /* 0240 */
280 0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127, /* 0250 */
281 0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147, /* 0260 */
282 0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165, /* 0270 */
283 0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215, /* 0300 */
284 0216, 0217, 0220, 0232, 0233, 0234, 0235, 0236, /* 0310 */
285 0237, 0240, 0252, 0253, 0254, 0255, 0256, 0257, /* 0320 */
286 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, /* 0330 */
287 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, /* 0340 */
288 0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333, /* 0350 */
289 0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355, /* 0360 */
290 0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
291};