1
2 /*
3 * CP1252
4 */
5
6 static const unsigned short cp1252_2uni[32] = {
7 /* 0x80 */
8 0x20ac, 0xfffd, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021,
9 0x02c6, 0x2030, 0x0160, 0x2039, 0x0152, 0xfffd, 0x017d, 0xfffd,
10 /* 0x90 */
11 0xfffd, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014,
12 0x02dc, 0x2122, 0x0161, 0x203a, 0x0153, 0xfffd, 0x017e, 0x0178,
13 };
14
15 static int
cp1252_mbtowc(conv_t conv,ucs4_t * pwc,const unsigned char * s,int n)16 cp1252_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
17 {
18 unsigned char c = *s;
19 if (c < 0x80 || c >= 0xa0) {
20 *pwc = (ucs4_t) c;
21 return 1;
22 }
23 else {
24 unsigned short wc = cp1252_2uni[c-0x80];
25 if (wc != 0xfffd) {
26 *pwc = (ucs4_t) wc;
27 return 1;
28 }
29 }
30 return RET_ILSEQ;
31 }
32
33 static const unsigned char cp1252_page01[72] = {
34 0x00, 0x00, 0x8c, 0x9c, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
35 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
36 0x8a, 0x9a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
37 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
38 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
39 0x9f, 0x00, 0x00, 0x00, 0x00, 0x8e, 0x9e, 0x00, /* 0x78-0x7f */
40 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
42 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
43 };
44 static const unsigned char cp1252_page02[32] = {
45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x00, /* 0xc0-0xc7 */
46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
47 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
48 0x00, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
49 };
50 static const unsigned char cp1252_page20[48] = {
51 0x00, 0x00, 0x00, 0x96, 0x97, 0x00, 0x00, 0x00, /* 0x10-0x17 */
52 0x91, 0x92, 0x82, 0x00, 0x93, 0x94, 0x84, 0x00, /* 0x18-0x1f */
53 0x86, 0x87, 0x95, 0x00, 0x00, 0x00, 0x85, 0x00, /* 0x20-0x27 */
54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
55 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
56 0x00, 0x8b, 0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
57 };
58
59 static int
cp1252_wctomb(conv_t conv,unsigned char * r,ucs4_t wc,int n)60 cp1252_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)
61 {
62 unsigned char c = 0;
63 if (wc < 0x0080) {
64 *r = wc;
65 return 1;
66 }
67 else if (wc >= 0x00a0 && wc < 0x0100)
68 c = wc;
69 else if (wc >= 0x0150 && wc < 0x0198)
70 c = cp1252_page01[wc-0x0150];
71 else if (wc >= 0x02c0 && wc < 0x02e0)
72 c = cp1252_page02[wc-0x02c0];
73 else if (wc >= 0x2010 && wc < 0x2040)
74 c = cp1252_page20[wc-0x2010];
75 else if (wc == 0x20ac)
76 c = 0x80;
77 else if (wc == 0x2122)
78 c = 0x99;
79 if (c != 0) {
80 *r = c;
81 return 1;
82 }
83 return RET_ILSEQ;
84 }
85