char *
norm_charmap(char *name)
{
- char *p;
-
- if (!name)
- return name;
-
- /* Many need no remapping, but they are listed here so you
- * can see what output to expect, and modify for your needs
- * as necessary. */
- if (!strcmp(name, "UTF-8"))
- return "UTF-8";
- if (!strcmp(name, "EUC-JP"))
- return "EUC-JP";
- if (!strcmp(name, "EUC-KR"))
- return "EUC-KR";
- if (!strcmp(name, "EUC-TW"))
- return "EUC-TW";
- if (!strcmp(name, "KOI8-R"))
- return "KOI8-R";
- if (!strcmp(name, "KOI8-U"))
- return "KOI8-U";
- if (!strcmp(name, "GBK"))
- return "GBK";
- if (!strcmp(name, "GB2312"))
- return "GB2312";
- if (!strcmp(name, "GB18030"))
- return "GB18030";
- if (!strcmp(name, "VSCII"))
- return "VSCII";
-
- /* ASCII comes in many names */
- if (!strcmp(name, "ASCII") ||
- !strcmp(name, "US-ASCII") ||
- !strcmp(name, "ANSI_X3.4-1968") ||
- !strcmp(name, "646") ||
- !strcmp(name, "ISO646") ||
- !strcmp(name, "ISO_646.IRV"))
- return "US-ASCII";
+ char *p;
- /* ISO 8859 will be converted to "ISO-8859-x" */
- if ((p = strstr(name, "8859-"))) {
- memcpy(buf, "ISO-8859-\0\0", 12);
- p += 5;
- if (digit(*p)) {
- buf[9] = *p++;
- if (digit(*p)) buf[10] = *p++;
- return buf;
- }
- }
+ if (!name)
+ return name;
- /* Windows code pages will be converted to "WINDOWS-12xx" */
- if ((p = strstr(name, "CP12"))) {
- memcpy(buf, "WINDOWS-12\0\0", 13);
- p += 4;
- if (digit(*p)) {
- buf[10] = *p++;
- if (digit(*p)) buf[11] = *p++;
- return buf;
- }
- }
+ /* Many need no remapping, but they are listed here so you
+ * can see what output to expect, and modify for your needs
+ * as necessary. */
+ if (!strcmp(name, "UTF-8"))
+ return "UTF-8";
+ if (!strcmp(name, "EUC-JP"))
+ return "EUC-JP";
+ if (!strcmp(name, "EUC-KR"))
+ return "EUC-KR";
+ if (!strcmp(name, "EUC-TW"))
+ return "EUC-TW";
+ if (!strcmp(name, "KOI8-R"))
+ return "KOI8-R";
+ if (!strcmp(name, "KOI8-U"))
+ return "KOI8-U";
+ if (!strcmp(name, "GBK"))
+ return "GBK";
+ if (!strcmp(name, "GB2312"))
+ return "GB2312";
+ if (!strcmp(name, "GB18030"))
+ return "GB18030";
+ if (!strcmp(name, "VSCII"))
+ return "VSCII";
- /* TIS-620 comes in at least the following two forms */
- if (!strcmp(name, "TIS-620") ||
- !strcmp(name, "TIS620.2533"))
- return "ISO-8859-11";
+ /* ASCII comes in many names */
+ if (!strcmp(name, "ASCII") ||
+ !strcmp(name, "US-ASCII") ||
+ !strcmp(name, "ANSI_X3.4-1968") ||
+ !strcmp(name, "646") ||
+ !strcmp(name, "ISO646") ||
+ !strcmp(name, "ISO_646.IRV"))
+ return "US-ASCII";
- /* For some, uppercase/lowercase might differ */
- if (!strcmp(name, "Big5") || !strcmp(name, "BIG5"))
- return "Big5";
- if (!strcmp(name, "Big5HKSCS") || !strcmp(name, "BIG5HKSCS"))
- return "Big5HKSCS";
+ /* ISO 8859 will be converted to "ISO-8859-x" */
+ if ((p = strstr(name, "8859-"))) {
+ memcpy(buf, "ISO-8859-\0\0", 12);
+ p += 5;
+ if (digit(*p)) {
+ buf[9] = *p++;
+ if (digit(*p))
+ buf[10] = *p++;
+ return buf;
+ }
+ }
- /* I don't know of any implementation of nl_langinfo(CODESET) out
- * there that returns anything else (and I'm not even certain all of
- * the above occur in the wild), but just in case, as a fallback,
- * return the unmodified name. */
- return name;
+ /* Windows code pages will be converted to "WINDOWS-12xx" */
+ if ((p = strstr(name, "CP12"))) {
+ memcpy(buf, "WINDOWS-12\0\0", 13);
+ p += 4;
+ if (digit(*p)) {
+ buf[10] = *p++;
+ if (digit(*p))
+ buf[11] = *p++;
+ return buf;
+ }
+ }
+
+ /* TIS-620 comes in at least the following two forms */
+ if (!strcmp(name, "TIS-620") ||
+ !strcmp(name, "TIS620.2533"))
+ return "ISO-8859-11";
+
+ /* For some, uppercase/lowercase might differ */
+ if (!strcmp(name, "Big5") || !strcmp(name, "BIG5"))
+ return "Big5";
+ if (!strcmp(name, "Big5HKSCS") || !strcmp(name, "BIG5HKSCS"))
+ return "Big5HKSCS";
+
+ /* I don't know of any implementation of nl_langinfo(CODESET) out
+ * there that returns anything else (and I'm not even certain all of
+ * the above occur in the wild), but just in case, as a fallback,
+ * return the unmodified name. */
+ return name;
}