--- pgp/src/charset.c 2018/04/24 16:37:54 1.1.1.1 +++ pgp/src/charset.c 2018/04/24 16:41:22 1.1.1.4 @@ -3,12 +3,28 @@ * * 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 +#include #include "usuals.h" #include "language.h" -#include "fileio.h" +#include "charset.h" +#include "system.h" #ifndef NULL #define NULL 0 @@ -18,14 +34,14 @@ 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 @@ -114,42 +130,45 @@ static unsigned char alt2intern[] = { int CONVERSION = NO_CONV; /* None text file conversion at start time */ unsigned char *ext_c_ptr; -unsigned char *int_c_ptr; +static unsigned char *int_c_ptr; +#ifdef MSDOS +char charset[64] = "cp850"; +#else char charset[64] = ""; +#endif void -init_charset() +init_charset(void) { 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); } } @@ -168,3 +187,22 @@ INT_C(char c) return c; return int_c_ptr[c & 0x7f]; } + +/* + * to_upper() and to_lower(), replacement for toupper() and tolower(), + * calling to_upper() on uppercase or to_lower on lowercase characters + * is handled correctly. + * + * XXX: should handle local characterset when 8-bit userID's are allowed + */ +int +to_upper(int c) +{ + return (c >= 'a' && c <= 'z' ? c - ('a' - 'A') : c); +} + +int +to_lower(int c) +{ + return (c >= 'A' && c <= 'Z' ? c + ('a' - 'A') : c); +}