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