+++ /dev/null
-/*\r
- * xenc.c - translate our internal character set codes to and from\r
- * X11 character encoding names.\r
- * \r
- */\r
-\r
-#include <ctype.h>\r
-#include "charset.h"\r
-#include "internal.h"\r
-\r
-static const struct {\r
- const char *name;\r
- int charset;\r
-} xencs[] = {\r
- /*\r
- * Officially registered encoding names. This list is derived\r
- * from the font encodings section of\r
- * \r
- * http://ftp.x.org/pub/DOCS/registry\r
- * \r
- * Where multiple encoding names map to the same encoding id\r
- * (such as iso8859-15 and fcd8859-15), the first is considered\r
- * canonical and will be returned when translating the id to a\r
- * string.\r
- */\r
- { "iso8859-1", CS_ISO8859_1 },\r
- { "iso8859-2", CS_ISO8859_2 },\r
- { "iso8859-3", CS_ISO8859_3 },\r
- { "iso8859-4", CS_ISO8859_4 },\r
- { "iso8859-5", CS_ISO8859_5 },\r
- { "iso8859-6", CS_ISO8859_6 },\r
- { "iso8859-7", CS_ISO8859_7 },\r
- { "iso8859-8", CS_ISO8859_8 },\r
- { "iso8859-9", CS_ISO8859_9 },\r
- { "iso8859-10", CS_ISO8859_10 },\r
- { "iso8859-13", CS_ISO8859_13 },\r
- { "iso8859-14", CS_ISO8859_14 },\r
- { "iso8859-15", CS_ISO8859_15 },\r
- { "fcd8859-15", CS_ISO8859_15 },\r
- { "hp-roman8", CS_HP_ROMAN8 },\r
- { "koi8-r", CS_KOI8_R },\r
- /*\r
- * Unofficial encoding names found in the wild.\r
- */\r
- { "iso8859-16", CS_ISO8859_16 },\r
- { "koi8-u", CS_KOI8_U },\r
- { "ibm-cp437", CS_CP437 },\r
- { "ibm-cp850", CS_CP850 },\r
- { "ibm-cp866", CS_CP866 },\r
- { "microsoft-cp1250", CS_CP1250 },\r
- { "microsoft-cp1251", CS_CP1251 },\r
- { "microsoft-cp1252", CS_CP1252 },\r
- { "microsoft-cp1253", CS_CP1253 },\r
- { "microsoft-cp1254", CS_CP1254 },\r
- { "microsoft-cp1255", CS_CP1255 },\r
- { "microsoft-cp1256", CS_CP1256 },\r
- { "microsoft-cp1257", CS_CP1257 },\r
- { "microsoft-cp1258", CS_CP1258 },\r
- { "mac-roman", CS_MAC_ROMAN },\r
- { "viscii1.1-1", CS_VISCII },\r
- { "viscii1-1", CS_VISCII },\r
-};\r
-\r
-const char *charset_to_xenc(int charset)\r
-{\r
- int i;\r
-\r
- for (i = 0; i < (int)lenof(xencs); i++)\r
- if (charset == xencs[i].charset)\r
- return xencs[i].name;\r
-\r
- return NULL; /* not found */\r
-}\r
-\r
-int charset_from_xenc(const char *name)\r
-{\r
- int i;\r
-\r
- for (i = 0; i < (int)lenof(xencs); i++) {\r
- const char *p, *q;\r
- p = name;\r
- q = xencs[i].name;\r
- while (*p || *q) {\r
- if (tolower((unsigned char)*p) != tolower((unsigned char)*q))\r
- break;\r
- p++; q++;\r
- }\r
- if (!*p && !*q)\r
- return xencs[i].charset;\r
- }\r
-\r
- return CS_NONE; /* not found */\r
-}\r