]>
diplodocus.org Git - nmh/blob - sbr/norm_charmap.c
1 /* norm_charmap.c -- map locale's encoding to MIME charset.
3 * The Single Unix Specification function nl_langinfo(CODESET)
4 * returns the name of the encoding used by the currently selected
7 * http://www.opengroup.org/onlinepubs/7908799/xsh/langinfo.h.html
9 * Unfortunately the encoding names are not yet standardized.
10 * This function knows about the encoding names used on many
11 * different systems and converts them where possible into
12 * the corresponding MIME charset name registered in
14 * http://www.iana.org/assignments/character-sets
16 * Please extend it as needed and suggest improvements to the author.
18 * Markus.Kuhn@cl.cam.ac.uk -- 2002-03-11
19 * Permission to use, copy, modify, and distribute this software
20 * for any purpose and without fee is hereby granted. The author
21 * disclaims all warranties with regard to this software.
25 * http://www.cl.cam.ac.uk/~mgk25/ucs/norm_charmap.c
30 #define digit(x) ((x) >= '0' && (x) <= '9')
35 norm_charmap(char *name
)
42 /* Many need no remapping, but they are listed here so you
43 * can see what output to expect, and modify for your needs
45 if (!strcmp(name
, "UTF-8"))
47 if (!strcmp(name
, "EUC-JP"))
49 if (!strcmp(name
, "EUC-KR"))
51 if (!strcmp(name
, "EUC-TW"))
53 if (!strcmp(name
, "KOI8-R"))
55 if (!strcmp(name
, "KOI8-U"))
57 if (!strcmp(name
, "GBK"))
59 if (!strcmp(name
, "GB2312"))
61 if (!strcmp(name
, "GB18030"))
63 if (!strcmp(name
, "VSCII"))
66 /* ASCII comes in many names */
67 if (!strcmp(name
, "ASCII") ||
68 !strcmp(name
, "US-ASCII") ||
69 !strcmp(name
, "ANSI_X3.4-1968") ||
70 !strcmp(name
, "646") ||
71 !strcmp(name
, "ISO646") ||
72 !strcmp(name
, "ISO_646.IRV"))
75 /* ISO 8859 will be converted to "ISO-8859-x" */
76 if ((p
= strstr(name
, "8859-"))) {
77 memcpy(buf
, "ISO-8859-\0\0", 12);
81 if (digit(*p
)) buf
[10] = *p
++;
86 /* Windows code pages will be converted to "WINDOWS-12xx" */
87 if ((p
= strstr(name
, "CP12"))) {
88 memcpy(buf
, "WINDOWS-12\0\0", 13);
92 if (digit(*p
)) buf
[11] = *p
++;
97 /* TIS-620 comes in at least the following two forms */
98 if (!strcmp(name
, "TIS-620") ||
99 !strcmp(name
, "TIS620.2533"))
100 return "ISO-8859-11";
102 /* For some, uppercase/lowercase might differ */
103 if (!strcmp(name
, "Big5") || !strcmp(name
, "BIG5"))
105 if (!strcmp(name
, "Big5HKSCS") || !strcmp(name
, "BIG5HKSCS"))
108 /* I don't know of any implementation of nl_langinfo(CODESET) out
109 * there that returns anything else (and I'm not even certain all of
110 * the above occur in the wild), but just in case, as a fallback,
111 * return the unmodified name. */