OSDN Git Service

Modify documents for 1.98d.
[ffftp/ffftp.git] / contrib / putty / CHARSET / MACENC.C
1 /* $Id: macenc.c 8037 2008-06-04 23:05:48Z simon $ */\r
2 /*\r
3  * Copyright (c) 2003 Ben Harris\r
4  * All rights reserved.\r
5  *\r
6  * Permission is hereby granted, free of charge, to any person\r
7  * obtaining a copy of this software and associated documentation\r
8  * files (the "Software"), to deal in the Software without\r
9  * restriction, including without limitation the rights to use,\r
10  * copy, modify, merge, publish, distribute, sublicense, and/or\r
11  * sell copies of the Software, and to permit persons to whom the\r
12  * Software is furnished to do so, subject to the following\r
13  * conditions:\r
14  * \r
15  * The above copyright notice and this permission notice shall be\r
16  * included in all copies or substantial portions of the Software.\r
17  * \r
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
21  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR\r
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF\r
23  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
24  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
25  * SOFTWARE.\r
26  */\r
27 /*\r
28  * macenc.c -- Convert a Mac OS script/region/font combination to our\r
29  * internal charset code.\r
30  */\r
31 \r
32 #include <string.h>\r
33 \r
34 #include "charset.h"\r
35 #include "internal.h"\r
36 \r
37 /*\r
38  * These are defined by Mac OS's <Script.h>, but we'd like to be\r
39  * independent of that.\r
40  */\r
41 \r
42 #define smRoman                 0\r
43 #define smJapanese              1\r
44 #define smTradChinese           2\r
45 #define smKorean                3\r
46 #define smArabic                4\r
47 #define smHebrew                5\r
48 #define smCyrillic              7\r
49 #define smDevenagari            9\r
50 #define smGurmukhi              10\r
51 #define smGujurati              11\r
52 #define smThai                  21\r
53 #define smSimpChinese           25\r
54 #define smTibetan               26\r
55 #define smEthiopic              28\r
56 #define smCentralEuroRoman      29\r
57 \r
58 #define verGreece               20\r
59 #define verIceland              21\r
60 #define verTurkey               24\r
61 #define verYugoCroatian         25\r
62 #define verRomania              39\r
63 #define verFaroeIsl             47\r
64 #define verIran                 48\r
65 #define verRussia               49\r
66 #define verSlovenian            66\r
67 #define verCroatia              68\r
68 #define verBulgaria             72\r
69 #define verScottishGaelic       75\r
70 #define verManxGaelic           76\r
71 #define verBreton               77\r
72 #define verNunavut              78\r
73 #define verWelsh                79\r
74 #define verIrishGaelicScript    81\r
75 \r
76 static const struct {\r
77     int script;\r
78     int region;\r
79     int sysvermin;\r
80     char const *fontname;\r
81     int charset;\r
82 } macencs[] = {\r
83     { smRoman, -1,                   0x850, "VT100", CS_MAC_VT100 },\r
84     { smRoman, -1,                   0,     "VT100", CS_MAC_VT100_OLD },\r
85     /*\r
86      * From here on, this table is largely derived from\r
87      * <http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/README.TXT>,\r
88      * with _OLD version added based on the comments in individual\r
89      * mapping files.\r
90      */\r
91     { smRoman, -1,                   0,     "Symbol", CS_MAC_SYMBOL },\r
92     { smRoman, -1,                   0,     "Zapf Dingbats", CS_MAC_DINGBATS },\r
93     { smRoman, verTurkey,            0,     NULL,    CS_MAC_TURKISH },\r
94     { smRoman, verYugoCroatian,      0x850, NULL,    CS_MAC_CROATIAN },\r
95     { smRoman, verYugoCroatian,      0,     NULL,    CS_MAC_CROATIAN_OLD },\r
96     { smRoman, verSlovenian,         0x850, NULL,    CS_MAC_CROATIAN },\r
97     { smRoman, verSlovenian,         0,     NULL,    CS_MAC_CROATIAN_OLD },\r
98     { smRoman, verCroatia,           0x850, NULL,    CS_MAC_CROATIAN },\r
99     { smRoman, verCroatia,           0,     NULL,    CS_MAC_CROATIAN_OLD },\r
100     { smRoman, verIceland,           0x850, NULL,    CS_MAC_ICELAND },\r
101     { smRoman, verIceland,           0,     NULL,    CS_MAC_ICELAND_OLD },\r
102     { smRoman, verFaroeIsl,          0x850, NULL,    CS_MAC_ICELAND },\r
103     { smRoman, verFaroeIsl,          0,     NULL,    CS_MAC_ICELAND_OLD },\r
104     { smRoman, verRomania,           0x850, NULL,    CS_MAC_ROMANIAN },\r
105     { smRoman, verRomania,           0,     NULL,    CS_MAC_ROMANIAN_OLD },\r
106 #if 0 /* No mapping table on ftp.unicode.org */\r
107     { smRoman, verIreland,           0x850, NULL,    CS_MAC_CELTIC },\r
108     { smRoman, verIreland,           0,     NULL,    CS_MAC_CELTIC_OLD },\r
109     { smRoman, verScottishGaelic,    0x850, NULL,    CS_MAC_CELTIC },\r
110     { smRoman, verScottishGaelic,    0,     NULL,    CS_MAC_CELTIC_OLD },\r
111     { smRoman, verManxGaelic,        0x850, NULL,    CS_MAC_CELTIC },\r
112     { smRoman, verManxGaelic,        0,     NULL,    CS_MAC_CELTIC_OLD },\r
113     { smRoman, verBreton,            0x850, NULL,    CS_MAC_CELTIC },\r
114     { smRoman, verBreton,            0,     NULL,    CS_MAC_CELTIC_OLD },\r
115     { smRoman, verWelsh,             0x850, NULL,    CS_MAC_CELTIC },\r
116     { smRoman, verWelsh,             0,     NULL,    CS_MAC_CELTIC_OLD },\r
117     { smRoman, verIrishGaelicScript, 0x850, NULL,    CS_MAC_GAELIC },\r
118     { smRoman, verIrishGaelicScript, 0,     NULL,    CS_MAC_GAELIC_OLD },\r
119 #endif\r
120     { smRoman, verGreece,            0x922, NULL,    CS_MAC_GREEK },\r
121     { smRoman, verGreece,            0,     NULL,    CS_MAC_GREEK_OLD },\r
122     { smRoman, -1,                   0x850, NULL,    CS_MAC_ROMAN },\r
123     { smRoman, -1,                   0,     NULL,    CS_MAC_ROMAN_OLD },\r
124 #if 0 /* Multi-byte encodings, not yet supported */\r
125     { smJapanese,    -1,             0,     NULL,    CS_MAC_JAPANESE },\r
126     { smTradChinese, -1,             0,     NULL,    CS_MAC_CHINTRAD },\r
127     { smKorean,      -1,             0,     NULL,    CS_MAC_KOREAN },\r
128 #endif\r
129 #if 0 /* Bidirectional encodings, not yet supported */\r
130     { smArabic, verIran,             0,     NULL,    CS_MAC_FARSI },\r
131     { smArabic, -1,                  0,     NULL,    CS_MAC_ARABIC },\r
132     { smHebrew, -1,                  0,     NULL,    CS_MAC_HEBREW },\r
133 #endif\r
134     { smCyrillic, -1,                0x900, NULL,    CS_MAC_CYRILLIC },\r
135     { smCyrillic, verRussia,         0,     NULL,    CS_MAC_CYRILLIC_OLD },\r
136     { smCyrillic, verBulgaria,       0,     NULL,    CS_MAC_CYRILLIC_OLD },\r
137     { smCyrillic, -1,                0,     NULL,    CS_MAC_UKRAINE },\r
138 #if 0 /* Complex Indic scripts, not yet supported */\r
139     { smDevanagari, -1,              0,     NULL,    CS_MAC_DEVENAGA },\r
140     { smGurmukhi, -1,                0,     NULL,    CS_MAC_GURMUKHI },\r
141     { smGujurati, -1,                0,     NULL,    CS_MAC_GUJURATI },\r
142 #endif\r
143     { smThai,  -1,                   0,     NULL,    CS_MAC_THAI },\r
144 #if 0 /* Multi-byte encoding, not yet supported */\r
145     { smSimpChinese, -1,             0,     NULL,    CS_MAC_CHINSIMP },\r
146 #endif\r
147 #if 0 /* No mapping table on ftp.unicode.org */\r
148     { smTibetan, -1,                 0,     NULL,    CS_MAC_TIBETAN },\r
149     { smEthiopic, -1,                0,     NULL,    CS_MAC_ETHIOPIC },\r
150     { smEthiopic, verNanavut,        0,     NULL,    CS_MAC_INUIT },\r
151 #endif\r
152     { smCentralEuroRoman, -1,        0,     NULL,    CS_MAC_CENTEURO },\r
153 };\r
154 \r
155 int charset_from_macenc(int script, int region, int sysvers,\r
156                         char const *fontname)\r
157 {\r
158     int i;\r
159 \r
160     for (i = 0; i < (int)lenof(macencs); i++)\r
161         if ((macencs[i].script == script) &&\r
162             (macencs[i].region < 0 || macencs[i].region == region) &&\r
163             (macencs[i].sysvermin <= sysvers) &&\r
164             (macencs[i].fontname == NULL ||\r
165              (fontname != NULL && strcmp(macencs[i].fontname, fontname) == 0)))\r
166             return macencs[i].charset;\r
167 \r
168     return CS_NONE;\r
169 }\r