--- pgp/src/charset.c 2018/04/24 16:39:38 1.1.1.3 +++ pgp/src/charset.c 2018/04/24 16:43:52 1.1.1.6 @@ -3,6 +3,20 @@ * * Conversion tables and routines to support different character sets. * The PGP internal format is latin-1. + * + * (c) Copyright 1990-1994 by Philip Zimmermann. All rights reserved. + * The author assumes no liability for damages resulting from the use + * of this software, even if the damage results from defects in this + * software. No warranty is expressed or implied. + * + * Code that has been incorporated into PGP from other sources was + * either originally published in the public domain or is used with + * permission from the various authors. + * + * PGP is available for free to the public under certain restrictions. + * See the PGP User's Guide (included in the release package) for + * important information about licensing, patent restrictions on + * certain algorithms, trademarks, copyrights, and export controls. */ #include @@ -20,18 +34,19 @@ static unsigned char intern2ascii[] = { /* ISO 8859-1 Latin Alphabet 1 to US ASCII */ -UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, -UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, - 32, 33, 99, 35, 36, 89, 124, 80, 34, 67, 97, 34, 126, 45, 82, 95, -111, UNK, 50, 51, 39, 117, 45, 45, 44, 49, 111, 34, UNK, UNK, UNK, 63, - 65, 65, 65, 65, 65, 65, 65, 67, 69, 69, 69, 69, 73, 73, 73, 73, - 68, 78, 79, 79, 79, 79, 79, 120, 79, 85, 85, 85, 85, 89, 84, 115, - 97, 97, 97, 97, 97, 97, 97, 99, 101, 101, 101, 101, 105, 105, 105, 105, -100, 110, 111, 111, 111, 111, 111, 47, 111, 117, 117, 117, 117, 121, 116, 121 +UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, +UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, UNK, + 32, 33, 99, 35, 36, 89, 124, 80, 34, 67, 97, 34, 126, 45, 82, 95, +111, UNK, 50, 51, 39, 117, 45, 45, 44, 49, 111, 34, UNK, UNK, UNK, 63, + 65, 65, 65, 65, 65, 65, 65, 67, 69, 69, 69, 69, 73, 73, 73, 73, + 68, 78, 79, 79, 79, 79, 79, 120, 79, 85, 85, 85, 85, 89, 84, 115, + 97, 97, 97, 97, 97, 97, 97, 99, 101, 101, 101, 101, 105, 105, 105, 105, +100, 110, 111, 111, 111, 111, 111, 47, 111, 117, 117, 117, 117, 121, 116, 121 }; static unsigned char -intern2cp850[] = { /* ISO 8859-1 Latin Alphabet 1 (Latin-1) to IBM Code Page 850 */ +intern2cp850[] = { /* ISO 8859-1 Latin Alphabet 1 + (Latin-1) to IBM Code Page 850 */ 186, 205, 201, 187, 200, 188, 204, 185, 203, 202, 206, 223, 220, 219, 254, 242, 179, 196, 218, 191, 192, 217, 195, 180, 194, 193, 197, 176, 177, 178, 213, 159, 255, 173, 189, 156, 207, 190, 221, 245, 249, 184, 166, 174, 170, 240, 169, 238, @@ -55,18 +70,18 @@ cp8502intern[] = { /* IBM Code Page 850 }; /* Russian language specific conversation section */ -/* Two point-to-point charset decode tables */ - -/* Decode single char from KOI8 to ALT-CODES, if present */ +/* Two point-to-point charset decode tables */ +/* produced by Andrew A. Chernov */ +/* Decode single char from KOI8-R to ALT-CODES, if present */ static unsigned char intern2alt[] = { - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, - 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, - 0xc8, 0xc9, 0xca, 0xff, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xf1, 0xd4, 0xd5, 0xd6, 0xd7, - 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xd3, 0xf3, 0xf2, 0xf0, 0xf4, 0xf5, 0xf6, 0xf7, - 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xcb, + 0xc4, 0xb3, 0xda, 0xbf, 0xc0, 0xd9, 0xc3, 0xb4, + 0xc2, 0xc1, 0xc5, 0xdf, 0xdc, 0xdb, 0xdd, 0xde, + 0xb0, 0xb1, 0xb2, 0xf4, 0xfe, 0xf9, 0xfb, 0xf7, + 0xf3, 0xf2, 0xff, 0xf5, 0xf8, 0xfd, 0xfa, 0xf6, + 0xcd, 0xba, 0xd5, 0xf1, 0xd6, 0xc9, 0xb8, 0xb7, + 0xbb, 0xd4, 0xd3, 0xc8, 0xbe, 0xbd, 0xbc, 0xc6, + 0xc7, 0xcc, 0xb5, 0xf0, 0xb6, 0xb9, 0xd1, 0xd2, + 0xcb, 0xcf, 0xd0, 0xca, 0xd8, 0xd7, 0xce, 0xfc, 0xee, 0xa0, 0xa1, 0xe6, 0xa4, 0xa5, 0xe4, 0xa3, 0xe5, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xa6, 0xa2, @@ -77,7 +92,7 @@ static unsigned char intern2alt[] = { 0x9c, 0x9b, 0x87, 0x98, 0x9d, 0x99, 0x97, 0x9a }; -/* Decode single char from ALT-CODES, if present, to KOI8 */ +/* Decode single char from ALT-CODES, if present, to KOI8-R */ static unsigned char alt2intern[] = { 0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, @@ -85,20 +100,18 @@ static unsigned char alt2intern[] = { 0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1, 0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, - 0x98, 0x99, 0x9a, 0xbf, 0x9c, 0x9d, 0x9e, 0x9f, - 0xa0, 0xa1, 0xa2, 0xb0, 0xa4, 0xa5, 0xa6, 0xa7, - 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0x90, 0x91, 0x92, 0x81, 0x87, 0xb2, 0xb4, 0xa7, + 0xa6, 0xb5, 0xa1, 0xa8, 0xae, 0xad, 0xac, 0x83, + 0x84, 0x89, 0x88, 0x86, 0x80, 0x8a, 0xaf, 0xb0, + 0xab, 0xa5, 0xbb, 0xb8, 0xb1, 0xa0, 0xbe, 0xb9, + 0xba, 0xb6, 0xb7, 0xaa, 0xa9, 0xa2, 0xa4, 0xbd, + 0xbc, 0x85, 0x82, 0x8d, 0x8c, 0x8e, 0x8f, 0x8b, 0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, 0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1, - 0xb3, 0xa3, 0xb2, 0xb1, 0xb4, 0xb5, 0xb6, 0xb7, - 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0x9b + 0xb3, 0xa3, 0x99, 0x98, 0x93, 0x9b, 0x9f, 0x97, + 0x9c, 0x95, 0x9e, 0x96, 0xbf, 0x9d, 0x94, 0x9a }; -/* End of Russian section */ - /* * Most Unixes has KOI8, and DOS has ALT_CODE * If your Unix is non-standard, set CHARSET to "alt_codes" @@ -112,6 +125,7 @@ static unsigned char alt2intern[] = { #define DEFAULT_RU_CSET "noconv" #endif +/* End of Russian section */ int CONVERSION = NO_CONV; /* None text file conversion at start time */ @@ -127,35 +141,36 @@ char charset[64] = ""; void init_charset(void) { - ext_c_ptr = NULL; /* NULL means latin1 or KOI8 (internal format) */ + ext_c_ptr = NULL; /* NULL means latin1 or KOI8 + (internal format) */ int_c_ptr = NULL; - if (charset[0] == '\0') - { /* use default character set for this system */ + if (charset[0] == '\0') { + /* use default character set for this system */ if (strcmp(language, "ru") == 0) strcpy(charset, DEFAULT_RU_CSET); else strcpy(charset, DEFAULT_CSET); - } - else + } else { strlwr(charset); + } /* latin-1 and KOI8 are in internal format: no conversion needed */ if (!strcmp(charset, "latin1") || !strcmp(charset, "koi8") || !strcmp(charset, "noconv")) return; - if (!strcmp(charset, "alt_codes")) - { ext_c_ptr = intern2alt; + if (!strcmp(charset, "alt_codes")) { + ext_c_ptr = intern2alt; int_c_ptr = alt2intern; - } else if (!strcmp(charset, "cp850")) - { ext_c_ptr = intern2cp850; + } else if (!strcmp(charset, "cp850")) { + ext_c_ptr = intern2cp850; int_c_ptr = cp8502intern; - } else if (!strcmp(charset, "ascii")) - { ext_c_ptr = intern2ascii; - } else - { - fprintf(stderr, PSTR("Unsupported character set: '%s'\n"), charset); + } else if (!strcmp(charset, "ascii")) { + ext_c_ptr = intern2ascii; + } else { + fprintf(stderr, LANG("Unsupported character set: '%s'\n"), + charset); } }