Debian Codegraph @

src/ucs.c

raw symbols SCIP
1 /* Conversion of files between different charsets and surfaces.
2 Copyright © 1996-2018 Free Software Foundation, Inc.
3 Contributed by François Pinard <[email protected]>, 1996.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License
7 as published by the Free Software Foundation; either version 3 of the
8 License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be
11 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the Recode Library; see the file `COPYING.LIB'.
17 If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "config.h"
21 #include "common.h"
22 #include "decsteps.h"
23
24 /* Description of some UCS-2 combinings. */
25
26 #define DONE NOT_A_CHARACTER
27 #define ELSE BYTE_ORDER_MARK_SWAPPED
28
29 static const unsigned short combining_data [] =
30 {
31 /* Diacriticized letters. */
32
33 0x00C0, 0x0041, 0x0300, DONE,
34 0x00C1, 0x0041, 0x0301, DONE,
35 0x00C2, 0x0041, 0x0302, DONE,
36 0x00C3, 0x0041, 0x0303, DONE,
37 0x00C4, 0x0041, 0x0308, DONE,
38 0x00C5, 0x0041, 0x030A, DONE,
39 0x00C7, 0x0043, 0x0327, DONE,
40 0x00C8, 0x0045, 0x0300, DONE,
41 0x00C9, 0x0045, 0x0301, DONE,
42 0x00CA, 0x0045, 0x0302, DONE,
43 0x00CB, 0x0045, 0x0308, DONE,
44 0x00CC, 0x0049, 0x0300, DONE,
45 0x00CD, 0x0049, 0x0301, DONE,
46 0x00CE, 0x0049, 0x0302, DONE,
47 0x00CF, 0x0049, 0x0308, DONE,
48 0x00D1, 0x004E, 0x0303, DONE,
49 0x00D2, 0x004F, 0x0300, DONE,
50 0x00D3, 0x004F, 0x0301, DONE,
51 0x00D4, 0x004F, 0x0302, DONE,
52 0x00D5, 0x004F, 0x0303, DONE,
53 0x00D6, 0x004F, 0x0308, DONE,
54 0x00D8, 0x004F, 0x0338, DONE,
55 0x00D9, 0x0055, 0x0300, DONE,
56 0x00DA, 0x0055, 0x0301, DONE,
57 0x00DB, 0x0055, 0x0302, DONE,
58 0x00DC, 0x0055, 0x0308, DONE,
59 0x00DD, 0x0059, 0x0301, DONE,
60 0x00E0, 0x0061, 0x0300, DONE,
61 0x00E1, 0x0061, 0x0301, DONE,
62 0x00E2, 0x0061, 0x0302, DONE,
63 0x00E3, 0x0061, 0x0303, DONE,
64 0x00E4, 0x0061, 0x0308, DONE,
65 0x00E5, 0x0061, 0x030A, DONE,
66 0x00E7, 0x0063, 0x0327, DONE,
67 0x00E8, 0x0065, 0x0300, DONE,
68 0x00E9, 0x0065, 0x0301, DONE,
69 0x00EA, 0x0065, 0x0302, DONE,
70 0x00EB, 0x0065, 0x0308, DONE,
71 0x00EC, 0x0069, 0x0300, DONE,
72 0x00ED, 0x0069, 0x0301, DONE,
73 0x00EE, 0x0069, 0x0302, DONE,
74 0x00EF, 0x0069, 0x0308, DONE,
75 0x00F1, 0x006E, 0x0303, DONE,
76 0x00F2, 0x006F, 0x0300, DONE,
77 0x00F3, 0x006F, 0x0301, DONE,
78 0x00F4, 0x006F, 0x0302, DONE,
79 0x00F5, 0x006F, 0x0303, DONE,
80 0x00F6, 0x006F, 0x0308, DONE,
81 0x00F8, 0x006F, 0x0338, DONE,
82 0x00F9, 0x0075, 0x0300, DONE,
83 0x00FA, 0x0075, 0x0301, DONE,
84 0x00FB, 0x0075, 0x0302, DONE,
85 0x00FC, 0x0075, 0x0308, DONE,
86 0x00FD, 0x0079, 0x0301, DONE,
87 0x00FF, 0x0079, 0x0308, DONE,
88 0x0100, 0x0041, 0x0304, DONE,
89 0x0101, 0x0061, 0x0304, DONE,
90 0x0102, 0x0041, 0x0306, DONE,
91 0x0103, 0x0061, 0x0306, DONE,
92 0x0104, 0x0041, 0x0328, DONE,
93 0x0105, 0x0061, 0x0328, DONE,
94 0x0106, 0x0043, 0x0301, DONE,
95 0x0107, 0x0063, 0x0301, DONE,
96 0x0108, 0x0043, 0x0302, DONE,
97 0x0109, 0x0063, 0x0302, DONE,
98 0x010A, 0x0043, 0x0307, DONE,
99 0x010B, 0x0063, 0x0307, DONE,
100 0x010C, 0x0043, 0x030C, DONE,
101 0x010D, 0x0063, 0x030C, DONE,
102 0x010E, 0x0044, 0x030C, DONE,
103 0x010F, 0x0064, 0x030C, DONE,
104 0x0110, 0x0044, 0x0335, DONE,
105 0x0111, 0x0064, 0x0335, DONE,
106 0x0112, 0x0045, 0x0304, DONE,
107 0x0113, 0x0065, 0x0304, DONE,
108 0x0114, 0x0045, 0x0306, DONE,
109 0x0115, 0x0065, 0x0306, DONE,
110 0x0116, 0x0045, 0x0307, DONE,
111 0x0117, 0x0065, 0x0307, DONE,
112 0x0118, 0x0045, 0x0328, DONE,
113 0x0119, 0x0065, 0x0328, DONE,
114 0x011A, 0x0045, 0x030C, DONE,
115 0x011B, 0x0065, 0x030C, DONE,
116 0x011C, 0x0047, 0x0302, DONE,
117 0x011D, 0x0067, 0x0302, DONE,
118 0x011E, 0x0047, 0x0306, DONE,
119 0x011F, 0x0067, 0x0306, DONE,
120 0x0120, 0x0047, 0x0307, DONE,
121 0x0121, 0x0067, 0x0307, DONE,
122 0x0122, 0x0047, 0x0327, DONE,
123 0x0123, 0x0067, 0x0327, DONE,
124 0x0124, 0x0048, 0x0302, DONE,
125 0x0125, 0x0068, 0x0302, DONE,
126 0x0126, 0x0048, 0x0335, DONE,
127 0x0127, 0x0068, 0x0335, DONE,
128 0x0128, 0x0049, 0x0303, DONE,
129 0x0129, 0x0069, 0x0303, DONE,
130 0x012A, 0x0049, 0x0304, DONE,
131 0x012B, 0x0069, 0x0304, DONE,
132 0x012C, 0x0049, 0x0306, DONE,
133 0x012D, 0x0069, 0x0306, DONE,
134 0x012E, 0x0049, 0x0328, DONE,
135 0x012F, 0x0069, 0x0328, DONE,
136 0x0130, 0x0049, 0x0307, DONE,
137 0x0134, 0x004A, 0x0302, DONE,
138 0x0135, 0x006A, 0x0302, DONE,
139 0x0136, 0x004B, 0x0327, DONE,
140 0x0137, 0x006B, 0x0327, DONE,
141 0x0139, 0x004C, 0x0301, DONE,
142 0x013A, 0x006C, 0x0301, DONE,
143 0x013B, 0x004C, 0x0327, DONE,
144 0x013C, 0x006C, 0x0327, DONE,
145 0x013D, 0x004C, 0x030C, DONE,
146 0x013E, 0x006C, 0x030C, DONE,
147 0x0141, 0x004C, 0x0337, DONE,
148 0x0142, 0x006C, 0x0337, DONE,
149 0x0143, 0x004E, 0x0301, DONE,
150 0x0144, 0x006E, 0x0301, DONE,
151 0x0145, 0x004E, 0x0327, DONE,
152 0x0146, 0x006E, 0x0327, DONE,
153 0x0147, 0x004E, 0x030C, DONE,
154 0x0148, 0x006E, 0x030C, DONE,
155 0x014C, 0x004F, 0x0304, DONE,
156 0x014D, 0x006F, 0x0304, DONE,
157 0x014E, 0x004F, 0x0306, DONE,
158 0x014F, 0x006F, 0x0306, DONE,
159 0x0150, 0x004F, 0x030B, DONE,
160 0x0151, 0x006F, 0x030B, DONE,
161 0x0154, 0x0052, 0x0301, DONE,
162 0x0155, 0x0072, 0x0301, DONE,
163 0x0156, 0x0052, 0x0327, DONE,
164 0x0157, 0x0072, 0x0327, DONE,
165 0x0158, 0x0052, 0x030C, DONE,
166 0x0159, 0x0072, 0x030C, DONE,
167 0x015A, 0x0053, 0x0301, DONE,
168 0x015B, 0x0073, 0x0301, DONE,
169 0x015C, 0x0053, 0x0302, DONE,
170 0x015D, 0x0073, 0x0302, DONE,
171 0x015E, 0x0053, 0x0327, DONE,
172 0x015F, 0x0073, 0x0327, DONE,
173 0x0160, 0x0053, 0x030C, DONE,
174 0x0161, 0x0073, 0x030C, DONE,
175 0x0162, 0x0054, 0x0327, DONE,
176 0x0163, 0x0074, 0x0327, DONE,
177 0x0164, 0x0054, 0x030C, DONE,
178 0x0165, 0x0074, 0x030C, DONE,
179 0x0166, 0x0054, 0x0335, DONE,
180 0x0167, 0x0074, 0x0335, DONE,
181 0x0168, 0x0055, 0x0303, DONE,
182 0x0169, 0x0075, 0x0303, DONE,
183 0x016A, 0x0055, 0x0304, DONE,
184 0x016B, 0x0075, 0x0304, DONE,
185 0x016C, 0x0055, 0x0306, DONE,
186 0x016D, 0x0075, 0x0306, DONE,
187 0x016E, 0x0055, 0x030A, DONE,
188 0x016F, 0x0075, 0x030A, DONE,
189 0x0170, 0x0055, 0x030B, DONE,
190 0x0171, 0x0075, 0x030B, DONE,
191 0x0172, 0x0055, 0x0328, DONE,
192 0x0173, 0x0075, 0x0328, DONE,
193 0x0174, 0x0057, 0x0302, DONE,
194 0x0175, 0x0077, 0x0302, DONE,
195 0x0176, 0x0059, 0x0302, DONE,
196 0x0177, 0x0079, 0x0302, DONE,
197 0x0178, 0x0059, 0x0308, DONE,
198 0x0179, 0x005A, 0x0301, DONE,
199 0x017A, 0x007A, 0x0301, DONE,
200 0x017B, 0x005A, 0x0307, DONE,
201 0x017C, 0x007A, 0x0307, DONE,
202 0x017D, 0x005A, 0x030C, DONE,
203 0x017E, 0x007A, 0x030C, DONE,
204 0x0180, 0x0062, 0x0335, DONE,
205 0x0197, 0x0049, 0x0335, DONE,
206 0x019A, 0x006C, 0x0335, DONE,
207 0x019B, 0x03BB, 0x0335, DONE,
208 0x019F, 0x004F, 0x0335, DONE,
209 0x01A0, 0x004F, 0x031B, DONE,
210 0x01A1, 0x006F, 0x031B, DONE,
211 0x01AB, 0x0074, 0x0321, DONE,
212 0x01AE, 0x0054, 0x0322, DONE,
213 0x01AF, 0x0055, 0x031B, DONE,
214 0x01B0, 0x0075, 0x031B, DONE,
215 0x01CD, 0x0041, 0x030C, DONE,
216 0x01CE, 0x0061, 0x030C, DONE,
217 0x01CF, 0x0049, 0x030C, DONE,
218 0x01D0, 0x0069, 0x030C, DONE,
219 0x01D1, 0x004F, 0x030C, DONE,
220 0x01D2, 0x006F, 0x030C, DONE,
221 0x01D3, 0x0055, 0x030C, DONE,
222 0x01D4, 0x0075, 0x030C, DONE,
223 0x01D5, 0x0055, 0x0308, 0x0304, ELSE, 0x00DC, 0x0304, DONE,
224 0x01D6, 0x0075, 0x0308, 0x0304, ELSE, 0x00FC, 0x0304, DONE,
225 0x01D7, 0x0055, 0x0308, 0x0301, ELSE, 0x00DC, 0x0301, DONE,
226 0x01D8, 0x0075, 0x0308, 0x0301, ELSE, 0x00FC, 0x0301, DONE,
227 0x01D9, 0x0055, 0x0308, 0x030C, ELSE, 0x00DC, 0x030C, DONE,
228 0x01DA, 0x0075, 0x0308, 0x030C, ELSE, 0x00FC, 0x030C, DONE,
229 0x01DB, 0x0055, 0x0308, 0x0300, ELSE, 0x00DC, 0x0300, DONE,
230 0x01DC, 0x0075, 0x0308, 0x0300, ELSE, 0x00FC, 0x0300, DONE,
231 0x01DE, 0x0041, 0x0308, 0x0304, ELSE, 0x00C4, 0x0304, DONE,
232 0x01DF, 0x0061, 0x0308, 0x0304, ELSE, 0x00E4, 0x0304, DONE,
233 0x01E0, 0x0041, 0x0307, 0x0304, DONE,
234 0x01E1, 0x0061, 0x0307, 0x0304, DONE,
235 0x01E2, 0x00C6, 0x0304, DONE,
236 0x01E3, 0x00E6, 0x0304, DONE,
237 0x01E4, 0x0047, 0x0335, DONE,
238 0x01E5, 0x0067, 0x0335, DONE,
239 0x01E6, 0x0047, 0x030C, DONE,
240 0x01E7, 0x0067, 0x030C, DONE,
241 0x01E8, 0x004B, 0x030C, DONE,
242 0x01E9, 0x006B, 0x030C, DONE,
243 0x01EA, 0x004F, 0x0328, DONE,
244 0x01EB, 0x006F, 0x0328, DONE,
245 0x01EC, 0x004F, 0x0328, 0x0304, ELSE, 0x01EA, 0x0304, DONE,
246 0x01ED, 0x006F, 0x0328, 0x0304, ELSE, 0x01EB, 0x0304, DONE,
247 0x01EE, 0x01B7, 0x030C, DONE,
248 0x01EF, 0x0292, 0x030C, DONE,
249 0x01F0, 0x006A, 0x030C, DONE,
250 0x0386, 0x0391, 0x0384, DONE,
251 0x0388, 0x0395, 0x0384, DONE,
252 0x0389, 0x0397, 0x0384, DONE,
253 0x038A, 0x0399, 0x0384, DONE,
254 0x038C, 0x039F, 0x0384, DONE,
255 0x038E, 0x03A5, 0x0384, DONE,
256 0x038F, 0x03A9, 0x0384, DONE,
257 0x0390, 0x03B9, 0x0385, DONE,
258 0x03AA, 0x0399, 0x0308, DONE,
259 0x03AB, 0x03A5, 0x0308, DONE,
260 0x03AC, 0x03B1, 0x0384, DONE,
261 0x03AD, 0x03B5, 0x0384, DONE,
262 0x03AE, 0x03B7, 0x0384, DONE,
263 0x03AF, 0x03B9, 0x0384, DONE,
264 0x03B0, 0x03C5, 0x0385, DONE,
265 0x03CA, 0x03B9, 0x0308, DONE,
266 0x03CB, 0x03C5, 0x0308, DONE,
267 0x03CC, 0x03BF, 0x0384, DONE,
268 0x03CD, 0x03C5, 0x0384, DONE,
269 0x03CE, 0x03C9, 0x0384, DONE,
270 0x03D3, 0x03D2, 0x0384, DONE,
271 0x03D4, 0x03D2, 0x0308, DONE,
272 0x0401, 0x0415, 0x0308, DONE,
273 0x0403, 0x0413, 0x0301, DONE,
274 0x0407, 0x0406, 0x0308, DONE,
275 0x040C, 0x041A, 0x0301, DONE,
276 0x040E, 0x0423, 0x0306, DONE,
277 0x0419, 0x0418, 0x0306, DONE,
278 0x0439, 0x0438, 0x0306, DONE,
279 0x0451, 0x0435, 0x0308, DONE,
280 0x0453, 0x0433, 0x0301, DONE,
281 0x0457, 0x0456, 0x0308, DONE,
282 0x045C, 0x043A, 0x0301, DONE,
283 0x045E, 0x0443, 0x0306, DONE,
284 0x0476, 0x0474, 0x030F, DONE,
285 0x0477, 0x0475, 0x030F, DONE,
286 0x0492, 0x0413, 0x0335, DONE,
287 0x0493, 0x0433, 0x0335, DONE,
288 0x0498, 0x0417, 0x0327, DONE,
289 0x0499, 0x0437, 0x0327, DONE,
290 0x04AA, 0x0421, 0x0327, DONE,
291 0x04AB, 0x0441, 0x0327, DONE,
292 0x04B0, 0x04AE, 0x0335, DONE,
293 0x04B1, 0x04AF, 0x0335, DONE,
294 0x04BE, 0x04BC, 0x0328, DONE,
295 0x04BF, 0x04BD, 0x0328, DONE,
296 0x04C1, 0x0416, 0x0306, DONE,
297 0x04C2, 0x0436, 0x0306, DONE,
298 0x04C5, 0x041A, 0x0328, DONE,
299 0x04C6, 0x043A, 0x0328, DONE,
300 0x04C9, 0x0425, 0x0328, DONE,
301 0x04CA, 0x0445, 0x0328, DONE,
302 0x0958, 0x0915, 0x093C, DONE,
303 0x0959, 0x0916, 0x093C, DONE,
304 0x095A, 0x0917, 0x093C, DONE,
305 0x095B, 0x091C, 0x093C, DONE,
306 0x095C, 0x0921, 0x093C, DONE,
307 0x095D, 0x0922, 0x093C, DONE,
308 0x095E, 0x092B, 0x093C, DONE,
309 0x095F, 0x092F, 0x093C, DONE,
310 0x09DC, 0x09A1, 0x09BC, DONE,
311 0x09DD, 0x09A2, 0x09BC, DONE,
312 0x09DF, 0x09AF, 0x09BC, DONE,
313 0x0A59, 0x0A16, 0x0A3C, DONE,
314 0x0A5A, 0x0A17, 0x0A3C, DONE,
315 0x0A5B, 0x0A1C, 0x0A3C, DONE,
316 0x0A5C, 0x0A21, 0x0A3C, DONE,
317 0x0A5E, 0x0A2B, 0x0A3C, DONE,
318 0x0B5C, 0x0B21, 0x0B3C, DONE,
319 0x0B5D, 0x0B22, 0x0B3C, DONE,
320 0x0B5F, 0x0B2F, 0x0B3C, DONE,
321 0x1014, 0x1004, 0x104C, DONE,
322 0x1015, 0x1005, 0x104C, DONE,
323 0x1016, 0x1006, 0x104C, DONE,
324
325 /* Ligatures, digraphs. */
326
327 0x00C6, 0x0041, 0x0045, DONE,
328 0x00E6, 0x0061, 0x0065, DONE,
329 0x0132, 0x0049, 0x004A, DONE,
330 0x0133, 0x0069, 0x006A, DONE,
331 0x013F, 0x004C, 0x00B7, DONE,
332 0x0140, 0x006C, 0x00B7, DONE,
333 0x0149, 0x0027, 0x006E, DONE,
334 0x0152, 0x004F, 0x0045, DONE,
335 0x0153, 0x006F, 0x0065, DONE,
336 0x01C4, 0x0044, 0x005A, 0x030C, ELSE, 0x0044, 0x017D, DONE,
337 0x01C5, 0x0044, 0x007A, 0x030C, ELSE, 0x0044, 0x017E, DONE,
338 0x01C6, 0x0064, 0x007A, 0x030C, ELSE, 0x0064, 0x017E, DONE,
339 0x01C7, 0x004C, 0x004A, DONE,
340 0x01C8, 0x004C, 0x006A, DONE,
341 0x01C9, 0x006C, 0x006A, DONE,
342 0x01CA, 0x004E, 0x004A, DONE,
343 0x01CB, 0x004E, 0x006A, DONE,
344 0x01CC, 0x006E, 0x006A, DONE,
345 0x02A3, 0x0064, 0x007A, DONE,
346 0x02A4, 0x0064, 0x0292, DONE,
347 0x02A5, 0x0064, 0x0291, DONE,
348 0x02A6, 0x0074, 0x0073, DONE,
349 0x02A7, 0x0074, 0x0283, DONE,
350 0x02A8, 0x0074, 0x0255, DONE,
351 0x0409, 0x041B, 0x042C, DONE,
352 0x040A, 0x041D, 0x042C, DONE,
353 0x0459, 0x043B, 0x044C, DONE,
354 0x045A, 0x043D, 0x044C, DONE,
355 0x0EDC, 0x0EAB, 0x0E99, DONE,
356 0x0EDD, 0x0EAB, 0x0EA1, DONE,
357 0x203C, 0x0021, 0x0021, DONE,
358 0x203D, 0x003F, 0x0021, DONE,
359 DONE
360 };
361
362 /* UCS-2 input and output. */
363
364 /*-------------------------------------------------------------------------.
365 | Get one UCS-2 VALUE for TASK, maybe swapping pair of bytes as we go. |
366 | Whenever a byte order mark is seen, either straight or swapped, always |
367 | use it to decide whether itself and subsequent UCS-2 values should be |
368 | swapped, or not. At the very beginning of the text stream, a byte order |
369 | mark is merely swallowed and never returned. Everywhere else, it is |
370 | transmitted as a zero-width non-breaking space. |
371 `-------------------------------------------------------------------------*/
372
373 /* An UCS-2 file canonically has a byte order mark at its very beginning.
374 So, concatenating many UCS-2 files might produce some spurious, but valid
375 zero-width non-breaking spaces. Those are produced for each file, after
376 the first, starting with a byte order mark, regardless of byte order. */
377
378 bool
379 recode_get_ucs2 (unsigned *value, RECODE_SUBTASK subtask)
380 {
381 while (true)
382 {
383 int character1;
384 int character2;
385 unsigned chunk;
386
387 character1 = recode_get_byte (subtask);
388 if (character1 == EOF)
389 return false;
390 character2 = recode_get_byte (subtask);
391 if (character2 == EOF)
392 {
393 recode_if_nogo (RECODE_INVALID_INPUT, subtask);
394 return false;
395 }
396
397 switch (subtask->task->swap_input)
398 {
399 case RECODE_SWAP_UNDECIDED:
400 chunk = ((BIT_MASK (8) & character1) << 8) | (BIT_MASK (8) & character2);
401 switch (chunk)
402 {
403 case BYTE_ORDER_MARK:
404 subtask->task->swap_input = RECODE_SWAP_NO;
405 break;
406
407 case BYTE_ORDER_MARK_SWAPPED:
408 subtask->task->swap_input = RECODE_SWAP_YES;
409 break;
410
411 default:
412 *value = chunk;
413 subtask->task->swap_input = RECODE_SWAP_NO;
414 if (subtask->task->byte_order_mark)
415 RETURN_IF_NOGO (RECODE_NOT_CANONICAL, subtask);
416 return true;
417 }
418 break;
419
420 case RECODE_SWAP_NO:
421 chunk = ((BIT_MASK (8) & character1) << 8) | (BIT_MASK (8) & character2);
422 switch (chunk)
423 {
424 case BYTE_ORDER_MARK:
425 RETURN_IF_NOGO (RECODE_NOT_CANONICAL, subtask);
426 break;
427
428 case BYTE_ORDER_MARK_SWAPPED:
429 subtask->task->swap_input = RECODE_SWAP_YES;
430 RETURN_IF_NOGO (RECODE_NOT_CANONICAL, subtask);
431 break;
432
433 default:
434 *value = chunk;
435 return true;
436 }
437 break;
438
439 case RECODE_SWAP_YES:
440 chunk = ((BIT_MASK (8) & character2) << 8) | (BIT_MASK (8) & character1);
441 switch (chunk)
442 {
443 case BYTE_ORDER_MARK:
444 RETURN_IF_NOGO (RECODE_NOT_CANONICAL, subtask);
445 break;
446
447 case BYTE_ORDER_MARK_SWAPPED:
448 subtask->task->swap_input = RECODE_SWAP_NO;
449 RETURN_IF_NOGO (RECODE_NOT_CANONICAL, subtask);
450 break;
451
452 default:
453 *value = chunk;
454 return true;
455 }
456 break;
457
458 default:
459 break;
460 }
461 }
462 }
463
464 /*-------------------------------.
465 | Put one UCS-2 VALUE for TASK. |
466 `-------------------------------*/
467
468 bool
469 recode_put_ucs2 (unsigned value, RECODE_SUBTASK subtask)
470 {
471 recode_put_byte (BIT_MASK (8) & value >> 8, subtask);
472 recode_put_byte (BIT_MASK (8) & value, subtask);
473 return true;
474 }
475
476 /* UCS-4 input and output. */
477
478 /*-------------------------------.
479 | Get one UCS-4 VALUE for TASK. |
480 `-------------------------------*/
481
482 bool
483 recode_get_ucs4 (unsigned *value, RECODE_SUBTASK subtask)
484 {
485 int character;
486 unsigned chunk;
487
488 character = recode_get_byte (subtask);
489 if (character == EOF)
490 return false;
491 chunk = (BIT_MASK (8) & character) << 24;
492
493 character = recode_get_byte (subtask);
494 if (character == EOF)
495 {
496 recode_if_nogo (RECODE_INVALID_INPUT, subtask);
497 return false;
498 }
499 chunk |= (BIT_MASK (8) & character) << 16;
500
501 character = recode_get_byte (subtask);
502 if (character == EOF)
503 {
504 recode_if_nogo (RECODE_INVALID_INPUT, subtask);
505 return false;
506 }
507 chunk |= (BIT_MASK (8) & character) << 8;
508
509 character = recode_get_byte (subtask);
510 if (character == EOF)
511 {
512 recode_if_nogo (RECODE_INVALID_INPUT, subtask);
513 return false;
514 }
515 chunk |= BIT_MASK (8) & character;
516
517 *value = chunk;
518 return true;
519 }
520
521 /*-------------------------------.
522 | Put one UCS-4 VALUE for TASK. |
523 `-------------------------------*/
524
525 bool
526 recode_put_ucs4 (unsigned value, RECODE_SUBTASK subtask)
527 {
528 recode_put_byte (BIT_MASK (8) & value >> 24, subtask);
529 recode_put_byte (BIT_MASK (8) & value >> 16, subtask);
530 recode_put_byte (BIT_MASK (8) & value >> 8, subtask);
531 recode_put_byte (BIT_MASK (8) & value, subtask);
532 return true;
533 }
534
535 /* Provided steps. */
536
537 /*-----------.
538 | Combined. |
539 `-----------*/
540
541 static bool
542 init_combined_ucs2 (RECODE_STEP step,
543 RECODE_CONST_REQUEST request,
544 RECODE_CONST_OPTION_LIST before_options,
545 RECODE_CONST_OPTION_LIST after_options)
546 {
547 step->before->data_type = RECODE_EXPLODE_DATA;
548 step->before->data = (void *) combining_data;
549 return recode_init_explode (step, request, before_options, after_options);
550 }
551
552 static bool
553 init_ucs2_combined (RECODE_STEP step,
554 RECODE_CONST_REQUEST request,
555 RECODE_CONST_OPTION_LIST before_options,
556 RECODE_CONST_OPTION_LIST after_options)
557 {
558 step->after->data_type = RECODE_EXPLODE_DATA;
559 step->after->data = (void *) combining_data;
560 return recode_init_combine (step, request, before_options, after_options);
561 }
562
563 /*-----------------------------.
564 | Transform Latin-1 to UCS-4. |
565 `-----------------------------*/
566
567 static bool
568 transform_latin1_ucs4 (RECODE_SUBTASK subtask)
569 {
570 int character;
571
572 while (character = recode_get_byte (subtask), character != EOF)
573 recode_put_ucs4 (BIT_MASK (8) & character, subtask);
574
575 SUBTASK_RETURN (subtask);
576 }
577
578 /*---------------------------.
579 | Transform UCS-2 to UCS-4. |
580 `---------------------------*/
581
582 static bool
583 transform_ucs2_ucs4 (RECODE_SUBTASK subtask)
584 {
585 unsigned value;
586
587 while (recode_get_ucs2 (&value, subtask))
588 recode_put_ucs4 (value, subtask);
589
590 SUBTASK_RETURN (subtask);
591 }
592
593 /*-----------------------------------------------------------------.
594 | Declare the basic UCS-2 and UCS-4 charsets and transformations. |
595 `-----------------------------------------------------------------*/
596
597 bool
598 module_ucs (RECODE_OUTER outer)
599 {
600 return
601 recode_declare_single (outer, "combined-UCS-2", "ISO-10646-UCS-2",
602 outer->quality_ucs2_to_variable,
603 init_combined_ucs2, recode_explode_ucs2_ucs2)
604 && recode_declare_single (outer, "ISO-10646-UCS-2", "combined-UCS-2",
605 outer->quality_variable_to_ucs2,
606 init_ucs2_combined, recode_combine_ucs2_ucs2)
607 && recode_declare_single (outer, "latin1", "ISO-10646-UCS-4",
608 outer->quality_byte_to_variable,
609 NULL, transform_latin1_ucs4)
610 && recode_declare_single (outer, "ISO-10646-UCS-2", "ISO-10646-UCS-4",
611 outer->quality_variable_to_variable,
612 NULL, transform_ucs2_ucs4)
613
614 && recode_declare_alias (outer, "UCS", "ISO-10646-UCS-4")
615 && recode_declare_alias (outer, "UCS-4", "ISO-10646-UCS-4")
616 && recode_declare_alias (outer, "ISO_10646", "ISO-10646-UCS-4")
617 && recode_declare_alias (outer, "10646", "ISO-10646-UCS-4")
618 && recode_declare_alias (outer, "u4", "ISO-10646-UCS-4")
619
620 && recode_declare_alias (outer, "UCS-2", "ISO-10646-UCS-2")
621 && recode_declare_alias (outer, "UNICODE-1-1", "ISO-10646-UCS-2") /* RFC1641 */
622 && recode_declare_alias (outer, "BMP", "ISO-10646-UCS-2")
623 && recode_declare_alias (outer, "u2", "ISO-10646-UCS-2")
624 && recode_declare_alias (outer, "rune", "ISO-10646-UCS-2")
625
626 && recode_declare_alias (outer, "co", "combined-UCS-2");
627 }
628
629 void
630 delmodule_ucs (_GL_UNUSED RECODE_OUTER outer)
631 {
632 }