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