[Way OT] Does anyone know c callable API for converting from ascii to ebcdic?
Guys, The subject speaks for itself. i.e. Does anyone know C callable API for converting from ascii to ebcdic? And I know "dd" can do this, but I need to be able to do it from C, or possibly Java. I just need to be able to convert one char at a time, so I guess I can write my own easily enough once I find an ebcdic chart. Thanks, Greg Freemyer Internet Engineer Deployment and Integration Specialist Compaq ASE - Tru64 Compaq Master ASE - SAN Architect The Norcross Group www.NorcrossGroup.com
* Greg Freemyer
Guys,
The subject speaks for itself.
i.e. Does anyone know C callable API for converting from ascii to ebcdic?
And I know "dd" can do this, but I need to be able to do it from C, or possibly Java.
I just need to be able to convert one char at a time, so I guess I can write my own easily enough once I find an ebcdic chart.
Look at the dd source perhaps? And these questions should go to our new suse-programming-e list :) -- Mads Martin Jørgensen, http://mmj.dk "Why make things difficult, when it is possible to make them cryptic and totally illogic, with just a little bit more effort?" -- A. P. J.
Mads Martin Joergensen writes:
* Greg Freemyer
[May 30. 2002 19:35]: Guys,
The subject speaks for itself.
i.e. Does anyone know C callable API for converting from ascii to ebcdic?
And I know "dd" can do this, but I need to be able to do it from C, or possibly Java.
I just need to be able to convert one char at a time, so I guess I can write my own easily enough once I find an ebcdic chart.
Look at the dd source perhaps?
And these questions should go to our new suse-programming-e list :)
Here is something that I have found. It uses a simple table lookup to convert an entire buffer. We also have a swedish to ebcdic as well. static unsigned char const latin1_to_ebcdicus[256] = { 0, 1, 2, 3, 4, 5, 6, 7, /* 0 - 7 */ 8, 9, 10, 11, 12, 13, 14, 15, /* 8 - 15 */ 16, 17, 18, 19, 20, 21, 22, 23, /* 16 - 23 */ 24, 25, 26, 27, 28, 29, 30, 31, /* 24 - 31 */ 64, 90, 127, 123, 91, 108, 80, 125, /* 32 - 39 */ 77, 93, 92, 78, 107, 96, 75, 97, /* 40 - 47 */ 240, 241, 242, 243, 244, 245, 246, 247, /* 48 - 55 */ 248, 249, 122, 94, 76, 126, 110, 111, /* 56 - 63 */ 124, 193, 194, 195, 196, 197, 198, 199, /* 64 - 71 */ 200, 201, 209, 210, 211, 212, 213, 214, /* 72 - 79 */ 215, 216, 217, 226, 227, 228, 229, 230, /* 80 - 87 */ 231, 232, 233, 36, 224, 41, 59, 109, /* 88 - 95 */ 121, 129, 130, 131, 132, 133, 134, 135, /* 96 - 103 */ 136, 137, 145, 146, 147, 148, 149, 150, /* 104 - 111 */ 151, 152, 153, 162, 163, 164, 165, 166, /* 112 - 119 */ 167, 168, 169, 192, 79, 208, 161, 255, /* 120 - 127 */ 128, 47, 98, 99, 100, 101, 102, 103, /* 128 - 135 */ 104, 105, 138, 139, 140, 141, 142, 143, /* 136 - 143 */ 144, 119, 44, 37, 172, 62, 63, 112, /* 144 - 151 */ 113, 114, 154, 155, 156, 157, 158, 159, /* 152 - 159 */ 160, 61, 74, 116, 117, 118, 106, 120, /* 160 - 167 */ 45, 58, 170, 171, 95, 173, 174, 175, /* 168 - 175 */ 176, 177, 178, 179, 180, 181, 182, 183, /* 176 - 183 */ 184, 185, 186, 187, 188, 189, 190, 191, /* 184 - 191 */ 35, 65, 66, 67, 68, 69, 70, 71, /* 192 - 199 */ 72, 73, 202, 203, 204, 205, 206, 207, /* 200 - 207 */ 39, 115, 46, 60, 40, 43, 32, 38, /* 208 - 215 */ 81, 82, 218, 219, 220, 221, 222, 223, /* 216 - 223 */ 42, 225, 83, 84, 85, 86, 87, 88, /* 224 - 231 */ 89, 33, 234, 235, 236, 237, 238, 239, /* 232 - 239 */ 48, 49, 50, 51, 52, 53, 54, 55, /* 240 - 247 */ 56, 57, 250, 251, 252, 253, 254, 34, /* 248 - 255 */ }; void us_ascii_to_ebcdic ( void *in, void *out, int len ) { unsigned char *src = (unsigned char *) in, *dst = (unsigned char *) out; for (; lgt > 0; lgt--) *dst++ = latin1_to_ebcdicus[(int) *src++]; }
[Jesse Marlin]
Here is something that I have found. It uses a simple table lookup to convert an entire buffer. We also have a swedish to ebcdic as well.
static unsigned char const latin1_to_ebcdicus[256] = [...]
Looks much like the output of "recode -h latin1..ebcdicus"... :-) -- François Pinard http://www.iro.umontreal.ca/~pinard
François Pinard writes:
[Jesse Marlin]
Here is something that I have found. It uses a simple table lookup to convert an entire buffer. We also have a swedish to ebcdic as well.
static unsigned char const latin1_to_ebcdicus[256] = [...]
Looks much like the output of "recode -h latin1..ebcdicus"... :-)
Might be, it is a function we use at work which was probably scraped from somewhere.
-- François Pinard http://www.iro.umontreal.ca/~pinard
Once you have a translate table, then you simply index into the table. (exactly what the ctype functions do). The work is building the translate table. The IBM mainframe OSs used to have them built in because many of the devices were ASCII. More specifically, the table itself is a character array (or unsigned int array) containing 256 elements. Assuming the array is atoe: To convert: int c; int ebc; while((c = getchar()) != EOF) { ebc = atoe[c]; putc(ebc, ebcidic_file); } On 30 May 2002 at 16:31, Jesse Marlin Jesse Marlin wrote:
François Pinard writes:
[Jesse Marlin]
Here is something that I have found. It uses a simple table lookup to convert an entire buffer. We also have a swedish to ebcdic as well.
static unsigned char const latin1_to_ebcdicus[256] = [...]
Looks much like the output of "recode -h latin1..ebcdicus"... :-)
Might be, it is a function we use at work which was probably scraped from somewhere.
-- François Pinard http://www.iro.umontreal.ca/~pinard
-- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com
-- Jerry Feldman Enterprise Systems Group Hewlett-Packard Company 200 Forest Street MRO1-3/F1 Marlboro, Ma. 01752 508-467-4315 http://www.testdrive.compaq.com/linux/
participants (6)
-
Greg Freemyer
-
Jerry Feldman
-
Jesse Marlin
-
Jesse Marlin <Jesse Marlin
-
Mads Martin Joergensen
-
pinard@iro.umontreal.ca