-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Lew Pitcher wrote:
[snip]
To the OP: No, there is no 'standard' ASCII-to-EBCDIC translation in ISO C.
There is no 'standard' ASCII-to-EBCDIC anywhere, mostly because there is no
single thing known as EBCDIC. What you are looking for, by necessity, is
something that you will have to craft for yourself. To do it properly, you
will need to know
a) which variant of EBCDIC you are translating to,
b) what you are supposed to do with ASCII codepoints that have no equivalent
EBCDIC codepoint (the 'standard' says to use the EBCDIC 'SUB' character)
c) what you are supposed to do with source data that is not ASCII (i.e. values
< 0x00 and values > 0x7f)
The characterset tables at
http://anubis.dkuug.dk/i18n/charmaps/ can help you
here. Each table shows the codepoint for the target characterset, it's
character, and the codepoint for the same character in Unicode. Remember, only
the first 128 Unicode characters are usefull here; all Unicode characters
below 0x0080 map 1-to-1 to ASCII, while the rest (Unicode above 0x007f) have
no ASCII equivalent. There are 46 EBCDIC variants listed (although, some are
duplicate mappings); select the variant that your host people expect you to
use (probably EBCDIC-US at
http://anubis.dkuug.dk/i18n/charmaps/EBCDIC-US ,
EBCDIC-INT at
http://anubis.dkuug.dk/i18n/charmaps/EBCDIC-INT , or
EBCDIC-CP-US at
http://anubis.dkuug.dk/i18n/charmaps/EBCDIC-CP-US ) and code
up a simple translation table using the ASCII character as an index into the
table of EBCDIC codepoints.
Be prepared to determine what to do with out-of-bounds conditions (return an
error, or perhaps translate to the EBCDIC "SUBstitute" value) and characters
that have no EBCDIC equivalent (translate to the EBCDIC "SUBstitute" value).
Here's one example of an ASCII-to-EBCDIC characterset translation, based on
the EBCDIC-US table at
http://anubis.dkuug.dk/i18n/charmaps/EBCDIC-US
char ASCII_to_EBCDIC_US(char ascii)
{
char to_EBCDIC_US[128] =
{ 0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f,
0x16, 0x05, 0x25, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26,
0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f,
0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d,
0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f,
0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6,
0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6,
0xe7, 0xe8, 0xe9, 0x3f, 0xe0, 0x3f, 0x3f, 0x6d,
0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6,
0xa7, 0xa8, 0xa9, 0xc0, 0x4f, 0xd0, 0xa1, 0x07
}
if (ascii > 127 || ascii < 0) return 0x3f;
return to_EBCDIC_US[ascii];
}
- --
Lew Pitcher
Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (
http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird -
http://enigmail.mozdev.org
iD8DBQFAzTC3agVFX4UWr64RAsC0AKD0WLueR3RPRzDpaDawemKmZU8LswCdHYUO
UfMDzisQVbs+tku1M5sRtwI=
=Yria
-----END PGP SIGNATURE-----