This source file includes following definitions.
- mbfl_filt_conv_wchar_cp1252
- mbfl_filt_conv_cp1252_wchar
- mbfl_filt_ident_cp1252
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34 #include "mbfilter.h"
35 #include "mbfilter_cp1252.h"
36 #include "unicode_table_cp1252.h"
37
38 static int mbfl_filt_ident_cp1252(int c, mbfl_identify_filter *filter);
39
40 static const char *mbfl_encoding_cp1252_aliases[] = {"cp1252", NULL};
41
42 const mbfl_encoding mbfl_encoding_cp1252 = {
43 mbfl_no_encoding_cp1252,
44 "Windows-1252",
45 "Windows-1252",
46 (const char *(*)[])&mbfl_encoding_cp1252_aliases,
47 NULL,
48 MBFL_ENCTYPE_SBCS
49 };
50
51 const struct mbfl_identify_vtbl vtbl_identify_cp1252 = {
52 mbfl_no_encoding_cp1252,
53 mbfl_filt_ident_common_ctor,
54 mbfl_filt_ident_common_dtor,
55 mbfl_filt_ident_cp1252
56 };
57
58 const struct mbfl_convert_vtbl vtbl_cp1252_wchar = {
59 mbfl_no_encoding_cp1252,
60 mbfl_no_encoding_wchar,
61 mbfl_filt_conv_common_ctor,
62 mbfl_filt_conv_common_dtor,
63 mbfl_filt_conv_cp1252_wchar,
64 mbfl_filt_conv_common_flush
65 };
66
67 const struct mbfl_convert_vtbl vtbl_wchar_cp1252 = {
68 mbfl_no_encoding_wchar,
69 mbfl_no_encoding_cp1252,
70 mbfl_filt_conv_common_ctor,
71 mbfl_filt_conv_common_dtor,
72 mbfl_filt_conv_wchar_cp1252,
73 mbfl_filt_conv_common_flush
74 };
75
76 #define CK(statement) do { if ((statement) < 0) return (-1); } while (0)
77
78
79
80
81 int mbfl_filt_conv_wchar_cp1252(int c, mbfl_convert_filter *filter)
82 {
83 int s=-1, n;
84
85 if (c >= 0x100) {
86
87 s = -1;
88 n = 31;
89 while (n >= 0) {
90 if (c == cp1252_ucs_table[n] && c != 0xfffe) {
91 s = 0x80 + n;
92 break;
93 }
94 n--;
95 }
96 if (s <= 0 && (c & ~MBFL_WCSPLANE_MASK) == MBFL_WCSPLANE_8859_1)
97 {
98 s = c & MBFL_WCSPLANE_MASK;
99 }
100 }
101 else if (c >= 0 && c < 0x100) {
102 s = c;
103 }
104 if (s >= 0) {
105 CK((*filter->output_function)(s, filter->data));
106 } else {
107 if (filter->illegal_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE) {
108 CK(mbfl_filt_conv_illegal_output(c, filter));
109 }
110 }
111 return c;
112 }
113
114
115
116
117 int mbfl_filt_conv_cp1252_wchar(int c, mbfl_convert_filter *filter)
118 {
119 int s;
120
121 if (c >= 0x80 && c < 0xa0) {
122 s = cp1252_ucs_table[c - 0x80];
123 } else {
124 s = c;
125 }
126
127 CK((*filter->output_function)(s, filter->data));
128
129 return c;
130 }
131
132
133
134
135
136
137
138 static int mbfl_filt_ident_cp1252(int c, mbfl_identify_filter *filter)
139 {
140 if (c >= 0x80 && c < 0xa0)
141 filter->flag = 0;
142 else
143 filter->flag = 1;
144 return c;
145 }
146
147