OSDN Git Service

Add PuTTY 0.61 to contrib directory.
[ffftp/ffftp.git] / contrib / putty / CHARSET / XENC.C
1 /*\r
2  * xenc.c - translate our internal character set codes to and from\r
3  * X11 character encoding names.\r
4  * \r
5  */\r
6 \r
7 #include <ctype.h>\r
8 #include "charset.h"\r
9 #include "internal.h"\r
10 \r
11 static const struct {\r
12     const char *name;\r
13     int charset;\r
14 } xencs[] = {\r
15     /*\r
16      * Officially registered encoding names. This list is derived\r
17      * from the font encodings section of\r
18      * \r
19      *   http://ftp.x.org/pub/DOCS/registry\r
20      * \r
21      * Where multiple encoding names map to the same encoding id\r
22      * (such as iso8859-15 and fcd8859-15), the first is considered\r
23      * canonical and will be returned when translating the id to a\r
24      * string.\r
25      */\r
26     { "iso8859-1", CS_ISO8859_1 },\r
27     { "iso8859-2", CS_ISO8859_2 },\r
28     { "iso8859-3", CS_ISO8859_3 },\r
29     { "iso8859-4", CS_ISO8859_4 },\r
30     { "iso8859-5", CS_ISO8859_5 },\r
31     { "iso8859-6", CS_ISO8859_6 },\r
32     { "iso8859-7", CS_ISO8859_7 },\r
33     { "iso8859-8", CS_ISO8859_8 },\r
34     { "iso8859-9", CS_ISO8859_9 },\r
35     { "iso8859-10", CS_ISO8859_10 },\r
36     { "iso8859-13", CS_ISO8859_13 },\r
37     { "iso8859-14", CS_ISO8859_14 },\r
38     { "iso8859-15", CS_ISO8859_15 },\r
39     { "fcd8859-15", CS_ISO8859_15 },\r
40     { "hp-roman8", CS_HP_ROMAN8 },\r
41     { "koi8-r", CS_KOI8_R },\r
42     /*\r
43      * Unofficial encoding names found in the wild.\r
44      */\r
45     { "iso8859-16", CS_ISO8859_16 },\r
46     { "koi8-u", CS_KOI8_U },\r
47     { "ibm-cp437", CS_CP437 },\r
48     { "ibm-cp850", CS_CP850 },\r
49     { "ibm-cp866", CS_CP866 },\r
50     { "microsoft-cp1250", CS_CP1250 },\r
51     { "microsoft-cp1251", CS_CP1251 },\r
52     { "microsoft-cp1252", CS_CP1252 },\r
53     { "microsoft-cp1253", CS_CP1253 },\r
54     { "microsoft-cp1254", CS_CP1254 },\r
55     { "microsoft-cp1255", CS_CP1255 },\r
56     { "microsoft-cp1256", CS_CP1256 },\r
57     { "microsoft-cp1257", CS_CP1257 },\r
58     { "microsoft-cp1258", CS_CP1258 },\r
59     { "mac-roman", CS_MAC_ROMAN },\r
60     { "viscii1.1-1", CS_VISCII },\r
61     { "viscii1-1", CS_VISCII },\r
62 };\r
63 \r
64 const char *charset_to_xenc(int charset)\r
65 {\r
66     int i;\r
67 \r
68     for (i = 0; i < (int)lenof(xencs); i++)\r
69         if (charset == xencs[i].charset)\r
70             return xencs[i].name;\r
71 \r
72     return NULL;                       /* not found */\r
73 }\r
74 \r
75 int charset_from_xenc(const char *name)\r
76 {\r
77     int i;\r
78 \r
79     for (i = 0; i < (int)lenof(xencs); i++) {\r
80         const char *p, *q;\r
81         p = name;\r
82         q = xencs[i].name;\r
83         while (*p || *q) {\r
84                 if (tolower((unsigned char)*p) != tolower((unsigned char)*q))\r
85                 break;\r
86             p++; q++;\r
87         }\r
88         if (!*p && !*q)\r
89             return xencs[i].charset;\r
90     }\r
91 \r
92     return CS_NONE;                    /* not found */\r
93 }\r