1 /* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */
2 
3 #include "../src/ef_ucs4_cp125x.h"
4 
5 #include "table/ef_cp1250_to_ucs4.table"
6 #include "table/ef_cp1251_to_ucs4.table"
7 #include "table/ef_cp1252_to_ucs4.table"
8 #include "table/ef_cp1253_to_ucs4.table"
9 #include "table/ef_cp1254_to_ucs4.table"
10 #include "table/ef_cp1255_to_ucs4.table"
11 #include "table/ef_cp1256_to_ucs4.table"
12 #include "table/ef_cp1257_to_ucs4.table"
13 #include "table/ef_cp1258_to_ucs4.table"
14 
15 #include "table/ef_ucs4_to_cp1250.table"
16 #include "table/ef_ucs4_to_cp1251.table"
17 #include "table/ef_ucs4_to_cp1252.table"
18 #include "table/ef_ucs4_to_cp1253.table"
19 #include "table/ef_ucs4_to_cp1254.table"
20 #include "table/ef_ucs4_to_cp1255.table"
21 #include "table/ef_ucs4_to_cp1256.table"
22 #include "table/ef_ucs4_to_cp1257.table"
23 #include "table/ef_ucs4_to_cp1258.table"
24 
25 #if 0
26 #define SELF_TEST
27 #endif
28 
29 /* --- global functions --- */
30 
ef_map_cp1250_to_ucs4(ef_char_t * ucs4,u_int16_t cp_code)31 int ef_map_cp1250_to_ucs4(ef_char_t *ucs4, u_int16_t cp_code) {
32   u_int32_t c;
33 
34   if ((c = CONV_CP1250_TO_UCS4(cp_code))) {
35     ef_int_to_bytes(ucs4->ch, 4, c);
36     ucs4->size = 4;
37     ucs4->cs = ISO10646_UCS4_1;
38     ucs4->property = 0;
39 
40     return 1;
41   } else if (0x20 <= cp_code && cp_code <= 0x7e) {
42     ucs4->ch[0] = 0x0;
43     ucs4->ch[1] = 0x0;
44     ucs4->ch[2] = 0x0;
45     ucs4->ch[3] = cp_code;
46     ucs4->size = 4;
47     ucs4->cs = ISO10646_UCS4_1;
48     ucs4->property = 0;
49 
50     return 1;
51   }
52 
53   return 0;
54 }
55 
ef_map_cp1251_to_ucs4(ef_char_t * ucs4,u_int16_t cp_code)56 int ef_map_cp1251_to_ucs4(ef_char_t *ucs4, u_int16_t cp_code) {
57   u_int32_t c;
58 
59   if ((c = CONV_CP1251_TO_UCS4(cp_code))) {
60     ef_int_to_bytes(ucs4->ch, 4, c);
61     ucs4->size = 4;
62     ucs4->cs = ISO10646_UCS4_1;
63     ucs4->property = 0;
64 
65     return 1;
66   } else if (0x20 <= cp_code && cp_code <= 0x7e) {
67     ucs4->ch[0] = 0x0;
68     ucs4->ch[1] = 0x0;
69     ucs4->ch[2] = 0x0;
70     ucs4->ch[3] = cp_code;
71     ucs4->size = 4;
72     ucs4->cs = ISO10646_UCS4_1;
73     ucs4->property = 0;
74 
75     return 1;
76   }
77 
78   return 0;
79 }
80 
ef_map_cp1252_to_ucs4(ef_char_t * ucs4,u_int16_t cp_code)81 int ef_map_cp1252_to_ucs4(ef_char_t *ucs4, u_int16_t cp_code) {
82   u_int32_t c;
83 
84   if ((c = CONV_CP1252_TO_UCS4(cp_code))) {
85     ef_int_to_bytes(ucs4->ch, 4, c);
86     ucs4->size = 4;
87     ucs4->cs = ISO10646_UCS4_1;
88     ucs4->property = 0;
89 
90     return 1;
91   } else if (0x20 <= cp_code && cp_code <= 0x7e) {
92     ucs4->ch[0] = 0x0;
93     ucs4->ch[1] = 0x0;
94     ucs4->ch[2] = 0x0;
95     ucs4->ch[3] = cp_code;
96     ucs4->size = 4;
97     ucs4->cs = ISO10646_UCS4_1;
98     ucs4->property = 0;
99 
100     return 1;
101   }
102 
103   return 0;
104 }
105 
ef_map_cp1253_to_ucs4(ef_char_t * ucs4,u_int16_t cp_code)106 int ef_map_cp1253_to_ucs4(ef_char_t *ucs4, u_int16_t cp_code) {
107   u_int32_t c;
108 
109   if ((c = CONV_CP1253_TO_UCS4(cp_code))) {
110     ef_int_to_bytes(ucs4->ch, 4, c);
111     ucs4->size = 4;
112     ucs4->cs = ISO10646_UCS4_1;
113     ucs4->property = 0;
114 
115     return 1;
116   } else if (0x20 <= cp_code && cp_code <= 0x7e) {
117     ucs4->ch[0] = 0x0;
118     ucs4->ch[1] = 0x0;
119     ucs4->ch[2] = 0x0;
120     ucs4->ch[3] = cp_code;
121     ucs4->size = 4;
122     ucs4->cs = ISO10646_UCS4_1;
123     ucs4->property = 0;
124 
125     return 1;
126   }
127 
128   return 0;
129 }
130 
ef_map_cp1254_to_ucs4(ef_char_t * ucs4,u_int16_t cp_code)131 int ef_map_cp1254_to_ucs4(ef_char_t *ucs4, u_int16_t cp_code) {
132   u_int32_t c;
133 
134   if ((c = CONV_CP1254_TO_UCS4(cp_code))) {
135     ef_int_to_bytes(ucs4->ch, 4, c);
136     ucs4->size = 4;
137     ucs4->cs = ISO10646_UCS4_1;
138     ucs4->property = 0;
139 
140     return 1;
141   } else if (0x20 <= cp_code && cp_code <= 0x7e) {
142     ucs4->ch[0] = 0x0;
143     ucs4->ch[1] = 0x0;
144     ucs4->ch[2] = 0x0;
145     ucs4->ch[3] = cp_code;
146     ucs4->size = 4;
147     ucs4->cs = ISO10646_UCS4_1;
148     ucs4->property = 0;
149 
150     return 1;
151   }
152 
153   return 0;
154 }
155 
ef_map_cp1255_to_ucs4(ef_char_t * ucs4,u_int16_t cp_code)156 int ef_map_cp1255_to_ucs4(ef_char_t *ucs4, u_int16_t cp_code) {
157   u_int32_t c;
158 
159   if ((c = CONV_CP1255_TO_UCS4(cp_code))) {
160     ef_int_to_bytes(ucs4->ch, 4, c);
161     ucs4->size = 4;
162     ucs4->cs = ISO10646_UCS4_1;
163     ucs4->property = 0;
164 
165     return 1;
166   } else if (0x20 <= cp_code && cp_code <= 0x7e) {
167     ucs4->ch[0] = 0x0;
168     ucs4->ch[1] = 0x0;
169     ucs4->ch[2] = 0x0;
170     ucs4->ch[3] = cp_code;
171     ucs4->size = 4;
172     ucs4->cs = ISO10646_UCS4_1;
173     ucs4->property = 0;
174 
175     return 1;
176   }
177 
178   return 0;
179 }
180 
ef_map_cp1256_to_ucs4(ef_char_t * ucs4,u_int16_t cp_code)181 int ef_map_cp1256_to_ucs4(ef_char_t *ucs4, u_int16_t cp_code) {
182   u_int32_t c;
183 
184   if ((c = CONV_CP1256_TO_UCS4(cp_code))) {
185     ef_int_to_bytes(ucs4->ch, 4, c);
186     ucs4->size = 4;
187     ucs4->cs = ISO10646_UCS4_1;
188     ucs4->property = 0;
189 
190     return 1;
191   } else if (0x20 <= cp_code && cp_code <= 0x7e) {
192     ucs4->ch[0] = 0x0;
193     ucs4->ch[1] = 0x0;
194     ucs4->ch[2] = 0x0;
195     ucs4->ch[3] = cp_code;
196     ucs4->size = 4;
197     ucs4->cs = ISO10646_UCS4_1;
198     ucs4->property = 0;
199 
200     return 1;
201   }
202 
203   return 0;
204 }
205 
ef_map_cp1257_to_ucs4(ef_char_t * ucs4,u_int16_t cp_code)206 int ef_map_cp1257_to_ucs4(ef_char_t *ucs4, u_int16_t cp_code) {
207   u_int32_t c;
208 
209   if ((c = CONV_CP1257_TO_UCS4(cp_code))) {
210     ef_int_to_bytes(ucs4->ch, 4, c);
211     ucs4->size = 4;
212     ucs4->cs = ISO10646_UCS4_1;
213     ucs4->property = 0;
214 
215     return 1;
216   } else if (0x20 <= cp_code && cp_code <= 0x7e) {
217     ucs4->ch[0] = 0x0;
218     ucs4->ch[1] = 0x0;
219     ucs4->ch[2] = 0x0;
220     ucs4->ch[3] = cp_code;
221     ucs4->size = 4;
222     ucs4->cs = ISO10646_UCS4_1;
223     ucs4->property = 0;
224 
225     return 1;
226   }
227 
228   return 0;
229 }
230 
ef_map_cp1258_to_ucs4(ef_char_t * ucs4,u_int16_t cp_code)231 int ef_map_cp1258_to_ucs4(ef_char_t *ucs4, u_int16_t cp_code) {
232   u_int32_t c;
233 
234   if ((c = CONV_CP1258_TO_UCS4(cp_code))) {
235     ef_int_to_bytes(ucs4->ch, 4, c);
236     ucs4->size = 4;
237     ucs4->cs = ISO10646_UCS4_1;
238     ucs4->property = 0;
239 
240     return 1;
241   } else if (0x20 <= cp_code && cp_code <= 0x7e) {
242     ucs4->ch[0] = 0x0;
243     ucs4->ch[1] = 0x0;
244     ucs4->ch[2] = 0x0;
245     ucs4->ch[3] = cp_code;
246     ucs4->size = 4;
247     ucs4->cs = ISO10646_UCS4_1;
248     ucs4->property = 0;
249 
250     return 1;
251   }
252 
253   return 0;
254 }
255 
ef_map_ucs4_to_cp1250(ef_char_t * non_ucs,u_int32_t ucs4_code)256 int ef_map_ucs4_to_cp1250(ef_char_t *non_ucs, u_int32_t ucs4_code) {
257   u_int8_t c;
258 
259   if ((c = CONV_UCS4_TO_CP1250(ucs4_code))) {
260     non_ucs->ch[0] = c;
261     non_ucs->size = 1;
262     non_ucs->cs = CP1250;
263     non_ucs->property = 0;
264 
265     return 1;
266   }
267 
268   return 0;
269 }
270 
ef_map_ucs4_to_cp1251(ef_char_t * non_ucs,u_int32_t ucs4_code)271 int ef_map_ucs4_to_cp1251(ef_char_t *non_ucs, u_int32_t ucs4_code) {
272   u_int8_t c;
273 
274   if ((c = CONV_UCS4_TO_CP1251(ucs4_code))) {
275     non_ucs->ch[0] = c;
276     non_ucs->size = 1;
277     non_ucs->cs = CP1251;
278     non_ucs->property = 0;
279 
280     return 1;
281   }
282 
283   return 0;
284 }
285 
ef_map_ucs4_to_cp1252(ef_char_t * non_ucs,u_int32_t ucs4_code)286 int ef_map_ucs4_to_cp1252(ef_char_t *non_ucs, u_int32_t ucs4_code) {
287   u_int8_t c;
288 
289   if ((c = CONV_UCS4_TO_CP1252(ucs4_code))) {
290     non_ucs->ch[0] = c;
291     non_ucs->size = 1;
292     non_ucs->cs = CP1252;
293     non_ucs->property = 0;
294 
295     return 1;
296   }
297 
298   return 0;
299 }
300 
ef_map_ucs4_to_cp1253(ef_char_t * non_ucs,u_int32_t ucs4_code)301 int ef_map_ucs4_to_cp1253(ef_char_t *non_ucs, u_int32_t ucs4_code) {
302   u_int8_t c;
303 
304   if ((c = CONV_UCS4_TO_CP1253(ucs4_code))) {
305     non_ucs->ch[0] = c;
306     non_ucs->size = 1;
307     non_ucs->cs = CP1253;
308     non_ucs->property = 0;
309 
310     return 1;
311   }
312 
313   return 0;
314 }
315 
ef_map_ucs4_to_cp1254(ef_char_t * non_ucs,u_int32_t ucs4_code)316 int ef_map_ucs4_to_cp1254(ef_char_t *non_ucs, u_int32_t ucs4_code) {
317   u_int8_t c;
318 
319   if ((c = CONV_UCS4_TO_CP1254(ucs4_code))) {
320     non_ucs->ch[0] = c;
321     non_ucs->size = 1;
322     non_ucs->cs = CP1254;
323     non_ucs->property = 0;
324 
325     return 1;
326   }
327 
328   return 0;
329 }
330 
ef_map_ucs4_to_cp1255(ef_char_t * non_ucs,u_int32_t ucs4_code)331 int ef_map_ucs4_to_cp1255(ef_char_t *non_ucs, u_int32_t ucs4_code) {
332   u_int8_t c;
333 
334   if ((c = CONV_UCS4_TO_CP1255(ucs4_code))) {
335     non_ucs->ch[0] = c;
336     non_ucs->size = 1;
337     non_ucs->cs = CP1255;
338     non_ucs->property = 0;
339 
340     return 1;
341   }
342 
343   return 0;
344 }
345 
ef_map_ucs4_to_cp1256(ef_char_t * non_ucs,u_int32_t ucs4_code)346 int ef_map_ucs4_to_cp1256(ef_char_t *non_ucs, u_int32_t ucs4_code) {
347   u_int8_t c;
348 
349   if ((c = CONV_UCS4_TO_CP1256(ucs4_code))) {
350     non_ucs->ch[0] = c;
351     non_ucs->size = 1;
352     non_ucs->cs = CP1256;
353     non_ucs->property = 0;
354 
355     return 1;
356   }
357 
358   return 0;
359 }
360 
ef_map_ucs4_to_cp1257(ef_char_t * non_ucs,u_int32_t ucs4_code)361 int ef_map_ucs4_to_cp1257(ef_char_t *non_ucs, u_int32_t ucs4_code) {
362   u_int8_t c;
363 
364   if ((c = CONV_UCS4_TO_CP1257(ucs4_code))) {
365     non_ucs->ch[0] = c;
366     non_ucs->size = 1;
367     non_ucs->cs = CP1257;
368     non_ucs->property = 0;
369 
370     return 1;
371   }
372 
373   return 0;
374 }
375 
ef_map_ucs4_to_cp1258(ef_char_t * non_ucs,u_int32_t ucs4_code)376 int ef_map_ucs4_to_cp1258(ef_char_t *non_ucs, u_int32_t ucs4_code) {
377   u_int8_t c;
378 
379   if ((c = CONV_UCS4_TO_CP1258(ucs4_code))) {
380     non_ucs->ch[0] = c;
381     non_ucs->size = 1;
382     non_ucs->cs = CP1258;
383     non_ucs->property = 0;
384 
385     return 1;
386   }
387 
388   return 0;
389 }
390 
391 #ifdef SELF_TEST
main(void)392 int main(void) {
393   u_int32_t ucs;
394   ef_char_t c;
395 
396   for (ucs = 0; ucs <= 0x10ffff; ucs++) {
397     if (!ef_map_ucs4_to_cp1251(&c, ucs)) {
398       c.ch[0] = '\0';
399     }
400 
401     printf("UCS %x => CP1251 %x\n", ucs, c.ch[0]);
402   }
403 }
404 #endif
405