771
|
1 /* Code to handle Unicode conversion.
|
|
2 Copyright (C) 2000, 2001, 2002 Ben Wing.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: FSF 20.3. Not in FSF. */
|
|
22
|
|
23 /* Authorship:
|
|
24
|
|
25 Current primary author: Ben Wing <ben@xemacs.org>
|
|
26
|
|
27 Written by Ben Wing <ben@xemacs.org>, June, 2001.
|
|
28 Separated out into this file, August, 2001.
|
|
29 Includes Unicode coding systems, some parts of which have been written
|
|
30 by someone else.
|
|
31
|
|
32 As of September 2001, the detection code is here and abstraction of the
|
|
33 detection system is finished. the unicode detectors have been rewritten
|
|
34 to include multiple levels of likelihood.
|
|
35 */
|
|
36
|
|
37 #include <config.h>
|
|
38 #include "lisp.h"
|
|
39
|
|
40 #include "charset.h"
|
|
41 #include "file-coding.h"
|
|
42 #include "opaque.h"
|
|
43
|
|
44 #include "sysfile.h"
|
|
45
|
|
46 /* #### WARNING! The current sledgehammer routines have a fundamental
|
|
47 problem in that they can't handle two characters mapping to a
|
|
48 single Unicode codepoint or vice-versa in a single charset table.
|
|
49 It's not clear there is any way to handle this and still make the
|
|
50 sledgehammer routines useful. */
|
|
51 /* #define SLEDGEHAMMER_CHECK_UNICODE */
|
|
52
|
|
53 /* We currently use the following format for tables:
|
|
54
|
|
55 If dimension == 1, to_unicode_table is a 96-element array of ints
|
|
56 (Unicode code points); else, it's a 96-element array of int *
|
|
57 pointers, each of which points to a 96-element array of ints. If no
|
|
58 elements in a row have been filled in, the pointer will point to a
|
|
59 default empty table; that way, memory usage is more reasonable but
|
|
60 lookup still fast.
|
|
61
|
|
62 -- If from_unicode_levels == 1, from_unicode_table is a 256-element
|
|
63 array of shorts (octet 1 in high byte, octet 2 in low byte; we don't
|
867
|
64 store Ichars directly to save space).
|
771
|
65
|
|
66 -- If from_unicode_levels == 2, from_unicode_table is a
|
|
67 256-element array of short * pointers, each of which points to a
|
|
68 256-element array of shorts.
|
|
69
|
|
70 -- If from_unicode_levels == 3, from_unicode_table is a
|
|
71 256-element array of short ** pointers, each of which points to
|
|
72 a 256-element array of short * pointers, each of which points to
|
|
73 a 256-element array of shorts.
|
|
74
|
|
75 -- If from_unicode_levels == 4, same thing but one level deeper.
|
|
76
|
|
77 Just as for to_unicode_table, we use default tables to fill in
|
|
78 all entries with no values in them.
|
|
79
|
|
80 #### An obvious space-saving optimization is to use variable-sized
|
|
81 tables, where each table instead of just being a 256-element array,
|
|
82 is a structure with a start value, an end value, and a variable
|
|
83 number of entries (END - START + 1). Only 8 bits are needed for
|
|
84 END and START, and could be stored at the end to avoid alignment
|
|
85 problems. However, before charging off and implementing this,
|
|
86 we need to consider whether it's worth it:
|
|
87
|
|
88 (1) Most tables will be highly localized in which code points are
|
|
89 defined, heavily reducing the possible memory waste. Before
|
|
90 doing any rewriting, write some code to see how much memory is
|
|
91 actually being wasted (i.e. ratio of empty entries to total # of
|
|
92 entries) and only start rewriting if it's unacceptably high. You
|
|
93 have to check over all charsets.
|
|
94
|
|
95 (2) Since entries are usually added one at a time, you have to be
|
|
96 very careful when creating the tables to avoid realloc()/free()
|
|
97 thrashing in the common case when you are in an area of high
|
|
98 localization and are going to end up using most entries in the
|
|
99 table. You'd certainly want to allow only certain sizes, not
|
|
100 arbitrary ones (probably powers of 2, where you want the entire
|
|
101 block including the START/END values to fit into a power of 2,
|
|
102 minus any malloc overhead if there is any -- there's none under
|
|
103 gmalloc.c, and probably most system malloc() functions are quite
|
|
104 smart nowadays and also have no overhead). You could optimize
|
|
105 somewhat during the in-C initializations, because you can compute
|
|
106 the actual usage of various tables by scanning the entries you're
|
|
107 going to add in a separate pass before adding them. (You could
|
|
108 actually do the same thing when entries are added on the Lisp
|
|
109 level by making the assumption that all the entries will come in
|
|
110 one after another before any use is made of the data. So as
|
|
111 they're coming in, you just store them in a big long list, and
|
|
112 the first time you need to retrieve an entry, you compute the
|
|
113 whole table at once.) You'd still have to deal with the
|
|
114 possibility of later entries coming in, though.
|
|
115
|
|
116 (3) You do lose some speed using START/END values, since you need
|
|
117 a couple of comparisons at each level. This could easily make
|
|
118 each single lookup become 3-4 times slower. The Unicode book
|
|
119 considers this a big issue, and recommends against variable-sized
|
|
120 tables for this reason; however, they almost certainly have in
|
|
121 mind applications that primarily involve conversion of large
|
|
122 amounts of data. Most Unicode strings that are translated in
|
|
123 XEmacs are fairly small. The only place where this might matter
|
|
124 is in loading large files -- e.g. a 3-megabyte Unicode-encoded
|
|
125 file. So think about this, and maybe do a trial implementation
|
|
126 where you don't worry too much about the intricacies of (2) and
|
|
127 just implement some basic "multiply by 1.5" trick or something to
|
|
128 do the resizing. There is a very good FAQ on Unicode called
|
|
129 something like the Linux-Unicode How-To (it should be part of the
|
|
130 Linux How-To's, I think), that lists the url of a guy with a
|
|
131 whole bunch of unicode files you can use to stress-test your
|
|
132 implementations, and he's highly likely to have a good
|
|
133 multi-megabyte Unicode-encoded file (with normal text in it -- if
|
|
134 you created your own just by creating repeated strings of letters
|
|
135 and numbers, you probably wouldn't get accurate results).
|
|
136 */
|
|
137
|
|
138 /* When MULE is not defined, we may still need some Unicode support --
|
|
139 in particular, some Windows API's always want Unicode, and the way
|
|
140 we've set up the Unicode encapsulation, we may as well go ahead and
|
|
141 always use the Unicode versions of split API's. (It would be
|
|
142 trickier to not use them, and pointless -- under NT, the ANSI API's
|
|
143 call the Unicode ones anyway, so in the case of structures, we'd be
|
|
144 converting from Unicode to ANSI structures, only to have the OS
|
|
145 convert them back.) */
|
|
146
|
|
147 Lisp_Object Qunicode;
|
|
148 Lisp_Object Qutf_16, Qutf_8, Qucs_4, Qutf_7;
|
|
149 Lisp_Object Qneed_bom;
|
|
150
|
|
151 Lisp_Object Qutf_16_little_endian, Qutf_16_bom;
|
|
152 Lisp_Object Qutf_16_little_endian_bom;
|
|
153
|
|
154 #ifdef MULE
|
|
155
|
|
156 static int *to_unicode_blank_1;
|
|
157 static int **to_unicode_blank_2;
|
|
158
|
|
159 static short *from_unicode_blank_1;
|
|
160 static short **from_unicode_blank_2;
|
|
161 static short ***from_unicode_blank_3;
|
|
162 static short ****from_unicode_blank_4;
|
|
163
|
|
164 #if 0
|
|
165
|
|
166 static const struct lrecord_description to_unicode_level_0_desc[] = {
|
|
167 { XD_END }
|
|
168 };
|
|
169
|
|
170 static const struct struct_description to_unicode_level_0_ptr_desc = {
|
|
171 sizeof (int), to_unicode_level_0_desc
|
|
172 };
|
|
173
|
|
174 static const struct lrecord_description to_unicode_level_1_desc[] = {
|
|
175 { XD_STRUCT_PTR, 0, 96, &to_unicode_level_0_ptr_desc },
|
|
176 { XD_END }
|
|
177 };
|
|
178
|
|
179 static const struct struct_description to_unicode_level_1_ptr_desc = {
|
|
180 0, to_unicode_level_1_desc
|
|
181 };
|
|
182
|
|
183 static const struct lrecord_description to_unicode_level_2_desc[] = {
|
|
184 { XD_STRUCT_PTR, 0, 96, &to_unicode_level_1_ptr_desc },
|
|
185 { XD_END }
|
|
186 };
|
|
187
|
|
188 /* Not static because each charset has a set of to and from tables and
|
|
189 needs to describe them to pdump. */
|
|
190 const struct struct_description to_unicode_description[] = {
|
|
191 { 1, to_unicode_level_1_desc },
|
|
192 { 2, to_unicode_level_2_desc },
|
|
193 { XD_END }
|
|
194 };
|
|
195
|
|
196 static const struct lrecord_description from_unicode_level_0_desc[] = {
|
|
197 { XD_END }
|
|
198 };
|
|
199
|
|
200 static const struct struct_description from_unicode_level_0_ptr_desc = {
|
|
201 sizeof (short), from_unicode_level_0_desc
|
|
202 };
|
|
203
|
|
204 static const struct lrecord_description from_unicode_level_1_desc[] = {
|
|
205 { XD_STRUCT_PTR, 0, 256, &from_unicode_level_0_ptr_desc },
|
|
206 { XD_END }
|
|
207 };
|
|
208
|
|
209 static const struct struct_description from_unicode_level_1_ptr_desc = {
|
|
210 0, from_unicode_level_1_desc
|
|
211 };
|
|
212
|
|
213 static const struct lrecord_description from_unicode_level_2_desc[] = {
|
|
214 { XD_STRUCT_PTR, 0, 256, &from_unicode_level_1_ptr_desc },
|
|
215 { XD_END }
|
|
216 };
|
|
217
|
|
218 static const struct struct_description from_unicode_level_2_ptr_desc = {
|
|
219 0, from_unicode_level_2_desc
|
|
220 };
|
|
221
|
|
222 static const struct lrecord_description from_unicode_level_3_desc[] = {
|
|
223 { XD_STRUCT_PTR, 0, 256, &from_unicode_level_2_ptr_desc },
|
|
224 { XD_END }
|
|
225 };
|
|
226
|
|
227 static const struct struct_description from_unicode_level_3_ptr_desc = {
|
|
228 0, from_unicode_level_3_desc
|
|
229 };
|
|
230
|
|
231 static const struct lrecord_description from_unicode_level_4_desc[] = {
|
|
232 { XD_STRUCT_PTR, 0, 256, &from_unicode_level_3_ptr_desc },
|
|
233 { XD_END }
|
|
234 };
|
|
235
|
|
236 /* Not static because each charset has a set of to and from tables and
|
|
237 needs to describe them to pdump. */
|
|
238 const struct struct_description from_unicode_description[] = {
|
|
239 { 1, from_unicode_level_1_desc },
|
|
240 { 2, from_unicode_level_2_desc },
|
|
241 { 3, from_unicode_level_3_desc },
|
|
242 { 4, from_unicode_level_4_desc },
|
|
243 { XD_END }
|
|
244 };
|
|
245
|
|
246 #endif /* 0 */
|
|
247
|
|
248 static Lisp_Object_dynarr *unicode_precedence_dynarr;
|
|
249
|
|
250 static const struct lrecord_description lo_description_1[] = {
|
|
251 { XD_LISP_OBJECT, 0 },
|
|
252 { XD_END }
|
|
253 };
|
|
254
|
|
255 static const struct struct_description lo_description = {
|
|
256 sizeof (Lisp_Object),
|
|
257 lo_description_1
|
|
258 };
|
|
259
|
|
260 static const struct lrecord_description lod_description_1[] = {
|
|
261 XD_DYNARR_DESC (Lisp_Object_dynarr, &lo_description),
|
|
262 { XD_END }
|
|
263 };
|
|
264
|
|
265 static const struct struct_description lisp_object_dynarr_description = {
|
|
266 sizeof (Lisp_Object_dynarr),
|
|
267 lod_description_1
|
|
268 };
|
|
269
|
|
270 Lisp_Object Vlanguage_unicode_precedence_list;
|
|
271 Lisp_Object Vdefault_unicode_precedence_list;
|
|
272
|
|
273 Lisp_Object Qignore_first_column;
|
|
274
|
|
275
|
|
276 /************************************************************************/
|
|
277 /* Unicode implementation */
|
|
278 /************************************************************************/
|
|
279
|
|
280 #define BREAKUP_UNICODE_CODE(val, u1, u2, u3, u4, levels) \
|
|
281 do { \
|
|
282 int buc_val = (val); \
|
|
283 \
|
|
284 (u1) = buc_val >> 24; \
|
|
285 (u2) = (buc_val >> 16) & 255; \
|
|
286 (u3) = (buc_val >> 8) & 255; \
|
|
287 (u4) = buc_val & 255; \
|
|
288 (levels) = (buc_val <= 0xFF ? 1 : \
|
|
289 buc_val <= 0xFFFF ? 2 : \
|
|
290 buc_val <= 0xFFFFFF ? 3 : \
|
|
291 4); \
|
|
292 } while (0)
|
|
293
|
|
294 static void
|
|
295 init_blank_unicode_tables (void)
|
|
296 {
|
|
297 int i;
|
|
298
|
|
299 from_unicode_blank_1 = xnew_array (short, 256);
|
|
300 from_unicode_blank_2 = xnew_array (short *, 256);
|
|
301 from_unicode_blank_3 = xnew_array (short **, 256);
|
|
302 from_unicode_blank_4 = xnew_array (short ***, 256);
|
|
303 for (i = 0; i < 256; i++)
|
|
304 {
|
|
305 from_unicode_blank_1[i] = (short) -1;
|
|
306 from_unicode_blank_2[i] = from_unicode_blank_1;
|
|
307 from_unicode_blank_3[i] = from_unicode_blank_2;
|
|
308 from_unicode_blank_4[i] = from_unicode_blank_3;
|
|
309 }
|
|
310
|
|
311 to_unicode_blank_1 = xnew_array (int, 96);
|
|
312 to_unicode_blank_2 = xnew_array (int *, 96);
|
|
313 for (i = 0; i < 96; i++)
|
|
314 {
|
|
315 to_unicode_blank_1[i] = -1;
|
|
316 to_unicode_blank_2[i] = to_unicode_blank_1;
|
|
317 }
|
|
318 }
|
|
319
|
|
320 static void *
|
|
321 create_new_from_unicode_table (int level)
|
|
322 {
|
|
323 switch (level)
|
|
324 {
|
|
325 /* WARNING: If you are thinking of compressing these, keep in
|
|
326 mind that sizeof (short) does not equal sizeof (short *). */
|
|
327 case 1:
|
|
328 {
|
|
329 short *newtab = xnew_array (short, 256);
|
|
330 memcpy (newtab, from_unicode_blank_1, 256 * sizeof (short));
|
|
331 return newtab;
|
|
332 }
|
|
333 case 2:
|
|
334 {
|
|
335 short **newtab = xnew_array (short *, 256);
|
|
336 memcpy (newtab, from_unicode_blank_2, 256 * sizeof (short *));
|
|
337 return newtab;
|
|
338 }
|
|
339 case 3:
|
|
340 {
|
|
341 short ***newtab = xnew_array (short **, 256);
|
|
342 memcpy (newtab, from_unicode_blank_3, 256 * sizeof (short **));
|
|
343 return newtab;
|
|
344 }
|
|
345 case 4:
|
|
346 {
|
|
347 short ****newtab = xnew_array (short ***, 256);
|
|
348 memcpy (newtab, from_unicode_blank_4, 256 * sizeof (short ***));
|
|
349 return newtab;
|
|
350 }
|
|
351 default:
|
|
352 abort ();
|
|
353 return 0;
|
|
354 }
|
|
355 }
|
|
356
|
|
357 void
|
|
358 init_charset_unicode_tables (Lisp_Object charset)
|
|
359 {
|
|
360 if (XCHARSET_DIMENSION (charset) == 1)
|
|
361 {
|
|
362 int *to_table = xnew_array (int, 96);
|
|
363 memcpy (to_table, to_unicode_blank_1, 96 * sizeof (int));
|
|
364 XCHARSET_TO_UNICODE_TABLE (charset) = to_table;
|
|
365 }
|
|
366 else
|
|
367 {
|
|
368 int **to_table = xnew_array (int *, 96);
|
|
369 memcpy (to_table, to_unicode_blank_2, 96 * sizeof (int *));
|
|
370 XCHARSET_TO_UNICODE_TABLE (charset) = to_table;
|
|
371 }
|
|
372
|
|
373 {
|
|
374 XCHARSET_FROM_UNICODE_TABLE (charset) = create_new_from_unicode_table (1);
|
|
375 XCHARSET_FROM_UNICODE_LEVELS (charset) = 1;
|
|
376 }
|
|
377 }
|
|
378
|
|
379 static void
|
|
380 free_from_unicode_table (void *table, int level)
|
|
381 {
|
|
382 int i;
|
|
383
|
|
384 switch (level)
|
|
385 {
|
|
386 case 2:
|
|
387 {
|
|
388 short **tab = (short **) table;
|
|
389 for (i = 0; i < 256; i++)
|
|
390 {
|
|
391 if (tab[i] != from_unicode_blank_1)
|
|
392 free_from_unicode_table (tab[i], 1);
|
|
393 }
|
|
394 break;
|
|
395 }
|
|
396 case 3:
|
|
397 {
|
|
398 short ***tab = (short ***) table;
|
|
399 for (i = 0; i < 256; i++)
|
|
400 {
|
|
401 if (tab[i] != from_unicode_blank_2)
|
|
402 free_from_unicode_table (tab[i], 2);
|
|
403 }
|
|
404 break;
|
|
405 }
|
|
406 case 4:
|
|
407 {
|
|
408 short ****tab = (short ****) table;
|
|
409 for (i = 0; i < 256; i++)
|
|
410 {
|
|
411 if (tab[i] != from_unicode_blank_3)
|
|
412 free_from_unicode_table (tab[i], 3);
|
|
413 }
|
|
414 break;
|
|
415 }
|
|
416 }
|
|
417
|
|
418 xfree (table);
|
|
419 }
|
|
420
|
|
421 static void
|
|
422 free_to_unicode_table (void *table, int level)
|
|
423 {
|
|
424 if (level == 2)
|
|
425 {
|
|
426 int i;
|
|
427 int **tab = (int **) table;
|
|
428
|
|
429 for (i = 0; i < 96; i++)
|
|
430 {
|
|
431 if (tab[i] != to_unicode_blank_1)
|
|
432 free_to_unicode_table (tab[i], 1);
|
|
433 }
|
|
434 }
|
|
435
|
|
436 xfree (table);
|
|
437 }
|
|
438
|
|
439 void
|
|
440 free_charset_unicode_tables (Lisp_Object charset)
|
|
441 {
|
|
442 free_to_unicode_table (XCHARSET_TO_UNICODE_TABLE (charset),
|
|
443 XCHARSET_DIMENSION (charset));
|
|
444 free_from_unicode_table (XCHARSET_FROM_UNICODE_TABLE (charset),
|
|
445 XCHARSET_FROM_UNICODE_LEVELS (charset));
|
|
446 }
|
|
447
|
|
448 #ifdef MEMORY_USAGE_STATS
|
|
449
|
|
450 static Bytecount
|
|
451 compute_from_unicode_table_size_1 (void *table, int level,
|
|
452 struct overhead_stats *stats)
|
|
453 {
|
|
454 int i;
|
|
455 Bytecount size = 0;
|
|
456
|
|
457 switch (level)
|
|
458 {
|
|
459 case 2:
|
|
460 {
|
|
461 short **tab = (short **) table;
|
|
462 for (i = 0; i < 256; i++)
|
|
463 {
|
|
464 if (tab[i] != from_unicode_blank_1)
|
|
465 size += compute_from_unicode_table_size_1 (tab[i], 1, stats);
|
|
466 }
|
|
467 break;
|
|
468 }
|
|
469 case 3:
|
|
470 {
|
|
471 short ***tab = (short ***) table;
|
|
472 for (i = 0; i < 256; i++)
|
|
473 {
|
|
474 if (tab[i] != from_unicode_blank_2)
|
|
475 size += compute_from_unicode_table_size_1 (tab[i], 2, stats);
|
|
476 }
|
|
477 break;
|
|
478 }
|
|
479 case 4:
|
|
480 {
|
|
481 short ****tab = (short ****) table;
|
|
482 for (i = 0; i < 256; i++)
|
|
483 {
|
|
484 if (tab[i] != from_unicode_blank_3)
|
|
485 size += compute_from_unicode_table_size_1 (tab[i], 3, stats);
|
|
486 }
|
|
487 break;
|
|
488 }
|
|
489 }
|
|
490
|
|
491 size += malloced_storage_size (table,
|
|
492 256 * (level == 1 ? sizeof (short) :
|
|
493 sizeof (void *)),
|
|
494 stats);
|
|
495 return size;
|
|
496 }
|
|
497
|
|
498 static Bytecount
|
|
499 compute_to_unicode_table_size_1 (void *table, int level,
|
|
500 struct overhead_stats *stats)
|
|
501 {
|
|
502 Bytecount size = 0;
|
|
503
|
|
504 if (level == 2)
|
|
505 {
|
|
506 int i;
|
|
507 int **tab = (int **) table;
|
|
508
|
|
509 for (i = 0; i < 96; i++)
|
|
510 {
|
|
511 if (tab[i] != to_unicode_blank_1)
|
|
512 size += compute_to_unicode_table_size_1 (tab[i], 1, stats);
|
|
513 }
|
|
514 }
|
|
515
|
|
516 size += malloced_storage_size (table,
|
|
517 96 * (level == 1 ? sizeof (int) :
|
|
518 sizeof (void *)),
|
|
519 stats);
|
|
520 return size;
|
|
521 }
|
|
522
|
|
523 Bytecount
|
|
524 compute_from_unicode_table_size (Lisp_Object charset,
|
|
525 struct overhead_stats *stats)
|
|
526 {
|
|
527 return (compute_from_unicode_table_size_1
|
|
528 (XCHARSET_FROM_UNICODE_TABLE (charset),
|
|
529 XCHARSET_FROM_UNICODE_LEVELS (charset),
|
|
530 stats));
|
|
531 }
|
|
532
|
|
533 Bytecount
|
|
534 compute_to_unicode_table_size (Lisp_Object charset,
|
|
535 struct overhead_stats *stats)
|
|
536 {
|
|
537 return (compute_to_unicode_table_size_1
|
|
538 (XCHARSET_TO_UNICODE_TABLE (charset),
|
|
539 XCHARSET_DIMENSION (charset),
|
|
540 stats));
|
|
541 }
|
|
542
|
|
543 #endif
|
|
544
|
|
545 #ifdef SLEDGEHAMMER_CHECK_UNICODE
|
|
546
|
|
547 /* "Sledgehammer checks" are checks that verify the self-consistency
|
|
548 of an entire structure every time a change is about to be made or
|
|
549 has been made to the structure. Not fast but a pretty much
|
|
550 sure-fire way of flushing out any incorrectnesses in the algorithms
|
|
551 that create the structure.
|
|
552
|
|
553 Checking only after a change has been made will speed things up by
|
|
554 a factor of 2, but it doesn't absolutely prove that the code just
|
|
555 checked caused the problem; perhaps it happened elsewhere, either
|
|
556 in some code you forgot to sledgehammer check or as a result of
|
|
557 data corruption. */
|
|
558
|
|
559 static void
|
|
560 assert_not_any_blank_table (void *tab)
|
|
561 {
|
|
562 assert (tab != from_unicode_blank_1);
|
|
563 assert (tab != from_unicode_blank_2);
|
|
564 assert (tab != from_unicode_blank_3);
|
|
565 assert (tab != from_unicode_blank_4);
|
|
566 assert (tab != to_unicode_blank_1);
|
|
567 assert (tab != to_unicode_blank_2);
|
|
568 assert (tab);
|
|
569 }
|
|
570
|
|
571 static void
|
|
572 sledgehammer_check_from_table (Lisp_Object charset, void *table, int level,
|
|
573 int codetop)
|
|
574 {
|
|
575 int i;
|
|
576
|
|
577 switch (level)
|
|
578 {
|
|
579 case 1:
|
|
580 {
|
|
581 short *tab = (short *) table;
|
|
582 for (i = 0; i < 256; i++)
|
|
583 {
|
|
584 if (tab[i] != -1)
|
|
585 {
|
|
586 Lisp_Object char_charset;
|
|
587 int c1, c2;
|
|
588
|
867
|
589 assert (valid_ichar_p (tab[i]));
|
|
590 BREAKUP_ICHAR (tab[i], char_charset, c1, c2);
|
771
|
591 assert (EQ (charset, char_charset));
|
|
592 if (XCHARSET_DIMENSION (charset) == 1)
|
|
593 {
|
|
594 int *to_table =
|
|
595 (int *) XCHARSET_TO_UNICODE_TABLE (charset);
|
|
596 assert_not_any_blank_table (to_table);
|
|
597 assert (to_table[c1 - 32] == (codetop << 8) + i);
|
|
598 }
|
|
599 else
|
|
600 {
|
|
601 int **to_table =
|
|
602 (int **) XCHARSET_TO_UNICODE_TABLE (charset);
|
|
603 assert_not_any_blank_table (to_table);
|
|
604 assert_not_any_blank_table (to_table[c1 - 32]);
|
|
605 assert (to_table[c1 - 32][c2 - 32] == (codetop << 8) + i);
|
|
606 }
|
|
607 }
|
|
608 }
|
|
609 break;
|
|
610 }
|
|
611 case 2:
|
|
612 {
|
|
613 short **tab = (short **) table;
|
|
614 for (i = 0; i < 256; i++)
|
|
615 {
|
|
616 if (tab[i] != from_unicode_blank_1)
|
|
617 sledgehammer_check_from_table (charset, tab[i], 1,
|
|
618 (codetop << 8) + i);
|
|
619 }
|
|
620 break;
|
|
621 }
|
|
622 case 3:
|
|
623 {
|
|
624 short ***tab = (short ***) table;
|
|
625 for (i = 0; i < 256; i++)
|
|
626 {
|
|
627 if (tab[i] != from_unicode_blank_2)
|
|
628 sledgehammer_check_from_table (charset, tab[i], 2,
|
|
629 (codetop << 8) + i);
|
|
630 }
|
|
631 break;
|
|
632 }
|
|
633 case 4:
|
|
634 {
|
|
635 short ****tab = (short ****) table;
|
|
636 for (i = 0; i < 256; i++)
|
|
637 {
|
|
638 if (tab[i] != from_unicode_blank_3)
|
|
639 sledgehammer_check_from_table (charset, tab[i], 3,
|
|
640 (codetop << 8) + i);
|
|
641 }
|
|
642 break;
|
|
643 }
|
|
644 default:
|
|
645 abort ();
|
|
646 }
|
|
647 }
|
|
648
|
|
649 static void
|
|
650 sledgehammer_check_to_table (Lisp_Object charset, void *table, int level,
|
|
651 int codetop)
|
|
652 {
|
|
653 int i;
|
|
654
|
|
655 switch (level)
|
|
656 {
|
|
657 case 1:
|
|
658 {
|
|
659 int *tab = (int *) table;
|
|
660
|
|
661 if (XCHARSET_CHARS (charset) == 94)
|
|
662 {
|
|
663 assert (tab[0] == -1);
|
|
664 assert (tab[95] == -1);
|
|
665 }
|
|
666
|
|
667 for (i = 0; i < 96; i++)
|
|
668 {
|
|
669 if (tab[i] != -1)
|
|
670 {
|
|
671 int u4, u3, u2, u1, levels;
|
867
|
672 Ichar ch;
|
|
673 Ichar this_ch;
|
771
|
674 short val;
|
|
675 void *frtab = XCHARSET_FROM_UNICODE_TABLE (charset);
|
|
676
|
|
677 if (XCHARSET_DIMENSION (charset) == 1)
|
867
|
678 this_ch = make_ichar (charset, i + 32, 0);
|
771
|
679 else
|
867
|
680 this_ch = make_ichar (charset, codetop + 32, i + 32);
|
771
|
681
|
|
682 assert (tab[i] >= 0);
|
|
683 BREAKUP_UNICODE_CODE (tab[i], u4, u3, u2, u1, levels);
|
|
684 assert (levels <= XCHARSET_FROM_UNICODE_LEVELS (charset));
|
|
685
|
|
686 switch (XCHARSET_FROM_UNICODE_LEVELS (charset))
|
|
687 {
|
|
688 case 1: val = ((short *) frtab)[u1]; break;
|
|
689 case 2: val = ((short **) frtab)[u2][u1]; break;
|
|
690 case 3: val = ((short ***) frtab)[u3][u2][u1]; break;
|
|
691 case 4: val = ((short ****) frtab)[u4][u3][u2][u1]; break;
|
|
692 default: abort ();
|
|
693 }
|
|
694
|
867
|
695 ch = make_ichar (charset, val >> 8, val & 0xFF);
|
771
|
696 assert (ch == this_ch);
|
|
697
|
|
698 switch (XCHARSET_FROM_UNICODE_LEVELS (charset))
|
|
699 {
|
|
700 case 4:
|
|
701 assert_not_any_blank_table (frtab);
|
|
702 frtab = ((short ****) frtab)[u4];
|
|
703 /* fall through */
|
|
704 case 3:
|
|
705 assert_not_any_blank_table (frtab);
|
|
706 frtab = ((short ***) frtab)[u3];
|
|
707 /* fall through */
|
|
708 case 2:
|
|
709 assert_not_any_blank_table (frtab);
|
|
710 frtab = ((short **) frtab)[u2];
|
|
711 /* fall through */
|
|
712 case 1:
|
|
713 assert_not_any_blank_table (frtab);
|
|
714 break;
|
|
715 default: abort ();
|
|
716 }
|
|
717 }
|
|
718 }
|
|
719 break;
|
|
720 }
|
|
721 case 2:
|
|
722 {
|
|
723 int **tab = (int **) table;
|
|
724
|
|
725 if (XCHARSET_CHARS (charset) == 94)
|
|
726 {
|
|
727 assert (tab[0] == to_unicode_blank_1);
|
|
728 assert (tab[95] == to_unicode_blank_1);
|
|
729 }
|
|
730
|
|
731 for (i = 0; i < 96; i++)
|
|
732 {
|
|
733 if (tab[i] != to_unicode_blank_1)
|
|
734 sledgehammer_check_to_table (charset, tab[i], 1, i);
|
|
735 }
|
|
736 break;
|
|
737 }
|
|
738 default:
|
|
739 abort ();
|
|
740 }
|
|
741 }
|
|
742
|
|
743 static void
|
|
744 sledgehammer_check_unicode_tables (Lisp_Object charset)
|
|
745 {
|
|
746 /* verify that the blank tables have not been modified */
|
|
747 int i;
|
|
748 int from_level = XCHARSET_FROM_UNICODE_LEVELS (charset);
|
|
749 int to_level = XCHARSET_FROM_UNICODE_LEVELS (charset);
|
|
750
|
|
751 for (i = 0; i < 256; i++)
|
|
752 {
|
|
753 assert (from_unicode_blank_1[i] == (short) -1);
|
|
754 assert (from_unicode_blank_2[i] == from_unicode_blank_1);
|
|
755 assert (from_unicode_blank_3[i] == from_unicode_blank_2);
|
|
756 assert (from_unicode_blank_4[i] == from_unicode_blank_3);
|
|
757 }
|
|
758
|
|
759 for (i = 0; i < 96; i++)
|
|
760 {
|
|
761 assert (to_unicode_blank_1[i] == -1);
|
|
762 assert (to_unicode_blank_2[i] == to_unicode_blank_1);
|
|
763 }
|
|
764
|
|
765 assert (from_level >= 1 && from_level <= 4);
|
|
766
|
|
767 sledgehammer_check_from_table (charset,
|
|
768 XCHARSET_FROM_UNICODE_TABLE (charset),
|
|
769 from_level, 0);
|
|
770
|
|
771 sledgehammer_check_to_table (charset,
|
|
772 XCHARSET_TO_UNICODE_TABLE (charset),
|
|
773 XCHARSET_DIMENSION (charset), 0);
|
|
774 }
|
|
775
|
|
776 #endif /* SLEDGEHAMMER_CHECK_UNICODE */
|
|
777
|
|
778 static void
|
867
|
779 set_unicode_conversion (Ichar chr, int code)
|
771
|
780 {
|
|
781 Lisp_Object charset;
|
|
782 int c1, c2;
|
|
783
|
867
|
784 BREAKUP_ICHAR (chr, charset, c1, c2);
|
771
|
785
|
|
786 assert (!EQ (charset, Vcharset_ascii));
|
|
787 assert (!EQ (charset, Vcharset_control_1));
|
|
788 assert (!EQ (charset, Vcharset_composite));
|
|
789
|
|
790 #ifdef SLEDGEHAMMER_CHECK_UNICODE
|
|
791 sledgehammer_check_unicode_tables (charset);
|
|
792 #endif
|
|
793
|
|
794 /* First, the char -> unicode translation */
|
|
795
|
|
796 if (XCHARSET_DIMENSION (charset) == 1)
|
|
797 {
|
|
798 int *to_table = (int *) XCHARSET_TO_UNICODE_TABLE (charset);
|
|
799 to_table[c1 - 32] = code;
|
|
800 }
|
|
801 else
|
|
802 {
|
|
803 int **to_table_2 = (int **) XCHARSET_TO_UNICODE_TABLE (charset);
|
|
804 int *to_table_1;
|
|
805
|
|
806 assert (XCHARSET_DIMENSION (charset) == 2);
|
|
807 to_table_1 = to_table_2[c1 - 32];
|
|
808 if (to_table_1 == to_unicode_blank_1)
|
|
809 {
|
|
810 to_table_1 = xnew_array (int, 96);
|
|
811 memcpy (to_table_1, to_unicode_blank_1, 96 * sizeof (int));
|
|
812 to_table_2[c1 - 32] = to_table_1;
|
|
813 }
|
|
814 to_table_1[c2 - 32] = code;
|
|
815 }
|
|
816
|
|
817 /* Then, unicode -> char: much harder */
|
|
818
|
|
819 {
|
|
820 int charset_levels;
|
|
821 int u4, u3, u2, u1;
|
|
822 int code_levels;
|
|
823 BREAKUP_UNICODE_CODE (code, u4, u3, u2, u1, code_levels);
|
|
824
|
|
825 charset_levels = XCHARSET_FROM_UNICODE_LEVELS (charset);
|
|
826
|
|
827 /* Make sure the charset's tables have at least as many levels as
|
|
828 the code point has: Note that the charset is guaranteed to have
|
|
829 at least one level, because it was created that way */
|
|
830 if (charset_levels < code_levels)
|
|
831 {
|
|
832 int i;
|
|
833
|
|
834 assert (charset_levels > 0);
|
|
835 for (i = 2; i <= code_levels; i++)
|
|
836 {
|
|
837 if (charset_levels < i)
|
|
838 {
|
|
839 void *old_table = XCHARSET_FROM_UNICODE_TABLE (charset);
|
|
840 void *table = create_new_from_unicode_table (i);
|
|
841 XCHARSET_FROM_UNICODE_TABLE (charset) = table;
|
|
842
|
|
843 switch (i)
|
|
844 {
|
|
845 case 2:
|
|
846 ((short **) table)[0] = (short *) old_table;
|
|
847 break;
|
|
848 case 3:
|
|
849 ((short ***) table)[0] = (short **) old_table;
|
|
850 break;
|
|
851 case 4:
|
|
852 ((short ****) table)[0] = (short ***) old_table;
|
|
853 break;
|
|
854 default: abort ();
|
|
855 }
|
|
856 }
|
|
857 }
|
|
858
|
|
859 charset_levels = code_levels;
|
|
860 XCHARSET_FROM_UNICODE_LEVELS (charset) = code_levels;
|
|
861 }
|
|
862
|
|
863 /* Now, make sure there is a non-default table at each level */
|
|
864 {
|
|
865 int i;
|
|
866 void *table = XCHARSET_FROM_UNICODE_TABLE (charset);
|
|
867
|
|
868 for (i = charset_levels; i >= 2; i--)
|
|
869 {
|
|
870 switch (i)
|
|
871 {
|
|
872 case 4:
|
|
873 if (((short ****) table)[u4] == from_unicode_blank_3)
|
|
874 ((short ****) table)[u4] =
|
|
875 ((short ***) create_new_from_unicode_table (3));
|
|
876 table = ((short ****) table)[u4];
|
|
877 break;
|
|
878 case 3:
|
|
879 if (((short ***) table)[u3] == from_unicode_blank_2)
|
|
880 ((short ***) table)[u3] =
|
|
881 ((short **) create_new_from_unicode_table (2));
|
|
882 table = ((short ***) table)[u3];
|
|
883 break;
|
|
884 case 2:
|
|
885 if (((short **) table)[u2] == from_unicode_blank_1)
|
|
886 ((short **) table)[u2] =
|
|
887 ((short *) create_new_from_unicode_table (1));
|
|
888 table = ((short **) table)[u2];
|
|
889 break;
|
|
890 default: abort ();
|
|
891 }
|
|
892 }
|
|
893 }
|
|
894
|
|
895 /* Finally, set the character */
|
|
896
|
|
897 {
|
|
898 void *table = XCHARSET_FROM_UNICODE_TABLE (charset);
|
|
899 switch (charset_levels)
|
|
900 {
|
|
901 case 1: ((short *) table)[u1] = (c1 << 8) + c2; break;
|
|
902 case 2: ((short **) table)[u2][u1] = (c1 << 8) + c2; break;
|
|
903 case 3: ((short ***) table)[u3][u2][u1] = (c1 << 8) + c2; break;
|
|
904 case 4: ((short ****) table)[u4][u3][u2][u1] = (c1 << 8) + c2; break;
|
|
905 default: abort ();
|
|
906 }
|
|
907 }
|
|
908 }
|
|
909
|
|
910 #ifdef SLEDGEHAMMER_CHECK_UNICODE
|
|
911 sledgehammer_check_unicode_tables (charset);
|
|
912 #endif
|
|
913 }
|
|
914
|
788
|
915 int
|
867
|
916 ichar_to_unicode (Ichar chr)
|
771
|
917 {
|
|
918 Lisp_Object charset;
|
|
919 int c1, c2;
|
|
920
|
867
|
921 type_checking_assert (valid_ichar_p (chr));
|
771
|
922 if (chr < 256)
|
|
923 return (int) chr;
|
|
924
|
867
|
925 BREAKUP_ICHAR (chr, charset, c1, c2);
|
771
|
926 if (EQ (charset, Vcharset_composite))
|
|
927 return -1; /* #### don't know how to handle */
|
|
928 else if (XCHARSET_DIMENSION (charset) == 1)
|
|
929 return ((int *) XCHARSET_TO_UNICODE_TABLE (charset))[c1 - 32];
|
|
930 else
|
|
931 return ((int **) XCHARSET_TO_UNICODE_TABLE (charset))[c1 - 32][c2 - 32];
|
|
932 }
|
|
933
|
867
|
934 static Ichar
|
771
|
935 unicode_to_char (int code, Lisp_Object_dynarr *charsets)
|
|
936 {
|
|
937 int u1, u2, u3, u4;
|
|
938 int code_levels;
|
|
939 int i;
|
|
940 int n = Dynarr_length (charsets);
|
|
941
|
|
942 type_checking_assert (code >= 0);
|
|
943 if (code < 256)
|
867
|
944 return (Ichar) code;
|
771
|
945
|
|
946 BREAKUP_UNICODE_CODE (code, u4, u3, u2, u1, code_levels);
|
|
947
|
|
948 for (i = 0; i < n; i++)
|
|
949 {
|
|
950 Lisp_Object charset = Dynarr_at (charsets, i);
|
|
951 int charset_levels = XCHARSET_FROM_UNICODE_LEVELS (charset);
|
|
952 if (charset_levels >= code_levels)
|
|
953 {
|
|
954 void *table = XCHARSET_FROM_UNICODE_TABLE (charset);
|
|
955 short retval;
|
|
956
|
|
957 switch (charset_levels)
|
|
958 {
|
|
959 case 1: retval = ((short *) table)[u1]; break;
|
|
960 case 2: retval = ((short **) table)[u2][u1]; break;
|
|
961 case 3: retval = ((short ***) table)[u3][u2][u1]; break;
|
|
962 case 4: retval = ((short ****) table)[u4][u3][u2][u1]; break;
|
|
963 default: abort (); retval = 0;
|
|
964 }
|
|
965
|
|
966 if (retval != -1)
|
867
|
967 return make_ichar (charset, retval >> 8, retval & 0xFF);
|
771
|
968 }
|
|
969 }
|
|
970
|
867
|
971 return (Ichar) -1;
|
771
|
972 }
|
|
973
|
|
974 static void
|
|
975 add_charsets_to_precedence_list (Lisp_Object list, int *lbs,
|
|
976 Lisp_Object_dynarr *dynarr)
|
|
977 {
|
|
978 {
|
|
979 EXTERNAL_LIST_LOOP_2 (elt, list)
|
|
980 {
|
|
981 Lisp_Object charset = Fget_charset (elt);
|
778
|
982 int lb = XCHARSET_LEADING_BYTE (charset);
|
771
|
983 if (lbs[lb - MIN_LEADING_BYTE] == 0)
|
|
984 {
|
|
985 Dynarr_add (unicode_precedence_dynarr, charset);
|
|
986 lbs[lb - MIN_LEADING_BYTE] = 1;
|
|
987 }
|
|
988 }
|
|
989 }
|
|
990 }
|
|
991
|
|
992 void
|
|
993 recalculate_unicode_precedence (void)
|
|
994 {
|
|
995 int lbs[NUM_LEADING_BYTES];
|
|
996 int i;
|
|
997
|
|
998 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
999 lbs[i] = 0;
|
|
1000
|
|
1001 Dynarr_reset (unicode_precedence_dynarr);
|
|
1002
|
|
1003 add_charsets_to_precedence_list (Vlanguage_unicode_precedence_list,
|
|
1004 lbs, unicode_precedence_dynarr);
|
|
1005 add_charsets_to_precedence_list (Vdefault_unicode_precedence_list,
|
|
1006 lbs, unicode_precedence_dynarr);
|
|
1007
|
|
1008 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
1009 {
|
|
1010 if (lbs[i] == 0)
|
|
1011 {
|
826
|
1012 Lisp_Object charset = charset_by_leading_byte (i + MIN_LEADING_BYTE);
|
771
|
1013 if (!NILP (charset))
|
|
1014 Dynarr_add (unicode_precedence_dynarr, charset);
|
|
1015 }
|
|
1016 }
|
|
1017 }
|
|
1018
|
|
1019 DEFUN ("set-language-unicode-precedence-list",
|
|
1020 Fset_language_unicode_precedence_list,
|
|
1021 1, 1, 0, /*
|
|
1022 Set the language-specific precedence list used for Unicode decoding.
|
|
1023 This is a list of charsets, which are consulted in order for a translation
|
|
1024 matching a given Unicode character. If no matches are found, the charsets
|
|
1025 in the default precedence list (see `set-default-unicode-precedence-list')
|
|
1026 are consulted, and then all remaining charsets, in some arbitrary order.
|
|
1027
|
|
1028 The language-specific precedence list is meant to be set as part of the
|
|
1029 language environment initialization; the default precedence list is meant
|
|
1030 to be set by the user.
|
|
1031 */
|
|
1032 (list))
|
|
1033 {
|
|
1034 {
|
|
1035 EXTERNAL_LIST_LOOP_2 (elt, list)
|
|
1036 Fget_charset (elt);
|
|
1037 }
|
|
1038
|
|
1039 Vlanguage_unicode_precedence_list = list;
|
|
1040 recalculate_unicode_precedence ();
|
|
1041 return Qnil;
|
|
1042 }
|
|
1043
|
|
1044 DEFUN ("language-unicode-precedence-list",
|
|
1045 Flanguage_unicode_precedence_list,
|
|
1046 0, 0, 0, /*
|
|
1047 Return the language-specific precedence list used for Unicode decoding.
|
|
1048 See `set-language-unicode-precedence-list' for more information.
|
|
1049 */
|
|
1050 ())
|
|
1051 {
|
|
1052 return Vlanguage_unicode_precedence_list;
|
|
1053 }
|
|
1054
|
|
1055 DEFUN ("set-default-unicode-precedence-list",
|
|
1056 Fset_default_unicode_precedence_list,
|
|
1057 1, 1, 0, /*
|
|
1058 Set the default precedence list used for Unicode decoding.
|
|
1059 This is meant to be set by the user. See
|
|
1060 `set-language-unicode-precedence-list' for more information.
|
|
1061 */
|
|
1062 (list))
|
|
1063 {
|
|
1064 {
|
|
1065 EXTERNAL_LIST_LOOP_2 (elt, list)
|
|
1066 Fget_charset (elt);
|
|
1067 }
|
|
1068
|
|
1069 Vdefault_unicode_precedence_list = list;
|
|
1070 recalculate_unicode_precedence ();
|
|
1071 return Qnil;
|
|
1072 }
|
|
1073
|
|
1074 DEFUN ("default-unicode-precedence-list",
|
|
1075 Fdefault_unicode_precedence_list,
|
|
1076 0, 0, 0, /*
|
|
1077 Return the default precedence list used for Unicode decoding.
|
|
1078 See `set-language-unicode-precedence-list' for more information.
|
|
1079 */
|
|
1080 ())
|
|
1081 {
|
|
1082 return Vdefault_unicode_precedence_list;
|
|
1083 }
|
|
1084
|
|
1085 DEFUN ("set-unicode-conversion", Fset_unicode_conversion,
|
|
1086 2, 2, 0, /*
|
|
1087 Add conversion information between Unicode codepoints and characters.
|
|
1088 CHARACTER is one of the following:
|
|
1089
|
|
1090 -- A character (in which case CODE must be a non-negative integer; values
|
|
1091 above 2^20 - 1 are allowed for the purpose of specifying private
|
|
1092 characters, but will cause errors when converted to utf-16)
|
|
1093 -- A vector of characters (in which case CODE must be a vector of integers
|
|
1094 of the same length)
|
|
1095 */
|
|
1096 (character, code))
|
|
1097 {
|
|
1098 Lisp_Object charset;
|
|
1099
|
|
1100 CHECK_CHAR (character);
|
|
1101 CHECK_NATNUM (code);
|
|
1102
|
867
|
1103 charset = ichar_charset (XCHAR (character));
|
771
|
1104 if (EQ (charset, Vcharset_ascii) ||
|
|
1105 EQ (charset, Vcharset_control_1) ||
|
|
1106 EQ (charset, Vcharset_composite))
|
|
1107 signal_error (Qinvalid_argument, "Cannot set Unicode translation for ASCII, Control-1 or Composite chars",
|
|
1108 character);
|
|
1109
|
|
1110 set_unicode_conversion (XCHAR (character), XINT (code));
|
|
1111 return Qnil;
|
|
1112 }
|
|
1113
|
|
1114 #endif /* MULE */
|
|
1115
|
800
|
1116 DEFUN ("char-to-unicode", Fchar_to_unicode, 1, 1, 0, /*
|
771
|
1117 Convert character to Unicode codepoint.
|
|
1118 When there is no international support (i.e. MULE is not defined),
|
|
1119 this function simply does `char-to-int'.
|
|
1120 */
|
|
1121 (character))
|
|
1122 {
|
|
1123 CHECK_CHAR (character);
|
|
1124 #ifdef MULE
|
867
|
1125 return make_int (ichar_to_unicode (XCHAR (character)));
|
771
|
1126 #else
|
|
1127 return Fchar_to_int (character);
|
|
1128 #endif /* MULE */
|
|
1129 }
|
|
1130
|
800
|
1131 DEFUN ("unicode-to-char", Funicode_to_char, 1, 2, 0, /*
|
771
|
1132 Convert Unicode codepoint to character.
|
|
1133 CODE should be a non-negative integer.
|
|
1134 If CHARSETS is given, it should be a list of charsets, and only those
|
|
1135 charsets will be consulted, in the given order, for a translation.
|
|
1136 Otherwise, the default ordering of all charsets will be given (see
|
|
1137 `set-unicode-charset-precedence').
|
|
1138
|
|
1139 When there is no international support (i.e. MULE is not defined),
|
|
1140 this function simply does `int-to-char' and ignores the CHARSETS
|
|
1141 argument..
|
|
1142 */
|
|
1143 (code, charsets))
|
|
1144 {
|
|
1145 #ifdef MULE
|
|
1146 Lisp_Object_dynarr *dyn;
|
|
1147 int lbs[NUM_LEADING_BYTES];
|
|
1148 int c;
|
|
1149
|
|
1150 CHECK_NATNUM (code);
|
|
1151 c = XINT (code);
|
|
1152 {
|
|
1153 EXTERNAL_LIST_LOOP_2 (elt, charsets)
|
|
1154 Fget_charset (elt);
|
|
1155 }
|
|
1156
|
|
1157 if (NILP (charsets))
|
|
1158 {
|
867
|
1159 Ichar ret = unicode_to_char (c, unicode_precedence_dynarr);
|
771
|
1160 if (ret == -1)
|
|
1161 return Qnil;
|
|
1162 return make_char (ret);
|
|
1163 }
|
|
1164
|
|
1165 dyn = Dynarr_new (Lisp_Object);
|
|
1166 memset (lbs, 0, NUM_LEADING_BYTES * sizeof (int));
|
|
1167 add_charsets_to_precedence_list (charsets, lbs, dyn);
|
|
1168 {
|
867
|
1169 Ichar ret = unicode_to_char (c, unicode_precedence_dynarr);
|
771
|
1170 Dynarr_free (dyn);
|
|
1171 if (ret == -1)
|
|
1172 return Qnil;
|
|
1173 return make_char (ret);
|
|
1174 }
|
|
1175 #else
|
|
1176 CHECK_NATNUM (code);
|
|
1177 return Fint_to_char (code);
|
|
1178 #endif /* MULE */
|
|
1179 }
|
|
1180
|
872
|
1181 #ifdef MULE
|
|
1182
|
771
|
1183 static Lisp_Object
|
|
1184 cerrar_el_fulano (Lisp_Object fulano)
|
|
1185 {
|
|
1186 FILE *file = (FILE *) get_opaque_ptr (fulano);
|
|
1187 retry_fclose (file);
|
|
1188 return Qnil;
|
|
1189 }
|
|
1190
|
|
1191 DEFUN ("parse-unicode-translation-table", Fparse_unicode_translation_table,
|
|
1192 2, 6, 0, /*
|
|
1193 Parse Unicode translation data in FILENAME for CHARSET.
|
|
1194 Data is text, in the form of one translation per line -- charset
|
|
1195 codepoint followed by Unicode codepoint. Numbers are decimal or hex
|
|
1196 \(preceded by 0x). Comments are marked with a #. Charset codepoints
|
|
1197 for two-dimensional charsets should have the first octet stored in the
|
|
1198 high 8 bits of the hex number and the second in the low 8 bits.
|
|
1199
|
|
1200 If START and END are given, only charset codepoints within the given
|
|
1201 range will be processed. If OFFSET is given, that value will be added
|
|
1202 to all charset codepoints in the file to obtain the internal charset
|
|
1203 codepoint. START and END apply to the codepoints in the file, before
|
|
1204 OFFSET is applied.
|
|
1205
|
|
1206 \(Note that, as usual, we assume that octets are in the range 32 to
|
|
1207 127 or 33 to 126. If you have a table in kuten form, with octets in
|
|
1208 the range 1 to 94, you will have to use an offset of 5140,
|
|
1209 i.e. 0x2020.)
|
|
1210
|
|
1211 FLAGS, if specified, control further how the tables are interpreted
|
|
1212 and are used to special-case certain known table weirdnesses in the
|
|
1213 Unicode tables:
|
|
1214
|
|
1215 `ignore-first-column'
|
|
1216 Exactly as it sounds. The JIS X 0208 tables have 3 columns of data instead
|
|
1217 of 2; the first is the Shift-JIS codepoint.
|
|
1218 `big5'
|
|
1219 The charset codepoint is a Big Five codepoint; convert it to the
|
|
1220 proper hacked-up codepoint in `chinese-big5-1' or `chinese-big5-2'.
|
|
1221 */
|
|
1222 (filename, charset, start, end, offset, flags))
|
|
1223 {
|
|
1224 int st = 0, en = INT_MAX, of = 0;
|
|
1225 FILE *file;
|
|
1226 struct gcpro gcpro1;
|
|
1227 char line[1025];
|
|
1228 int fondo = specpdl_depth ();
|
|
1229 int ignore_first_column = 0;
|
|
1230 int big5 = 0;
|
|
1231
|
|
1232 CHECK_STRING (filename);
|
|
1233 charset = Fget_charset (charset);
|
|
1234 if (!NILP (start))
|
|
1235 {
|
|
1236 CHECK_INT (start);
|
|
1237 st = XINT (start);
|
|
1238 }
|
|
1239 if (!NILP (end))
|
|
1240 {
|
|
1241 CHECK_INT (end);
|
|
1242 en = XINT (end);
|
|
1243 }
|
|
1244 if (!NILP (offset))
|
|
1245 {
|
|
1246 CHECK_INT (offset);
|
|
1247 of = XINT (offset);
|
|
1248 }
|
|
1249
|
|
1250 if (!LISTP (flags))
|
|
1251 flags = list1 (flags);
|
|
1252
|
|
1253 {
|
|
1254 EXTERNAL_LIST_LOOP_2 (elt, flags)
|
|
1255 {
|
|
1256 if (EQ (elt, Qignore_first_column))
|
|
1257 ignore_first_column = 1;
|
|
1258 else if (EQ (elt, Qbig5))
|
|
1259 big5 = 1;
|
|
1260 else
|
|
1261 invalid_constant
|
|
1262 ("Unrecognized `parse-unicode-table' flag", elt);
|
|
1263 }
|
|
1264 }
|
|
1265
|
|
1266 GCPRO1 (filename);
|
|
1267 filename = Fexpand_file_name (filename, Qnil);
|
|
1268 file = qxe_fopen (XSTRING_DATA (filename), READ_TEXT);
|
|
1269 if (!file)
|
|
1270 report_file_error ("Cannot open", filename);
|
|
1271 record_unwind_protect (cerrar_el_fulano, make_opaque_ptr (file));
|
|
1272 while (fgets (line, sizeof (line), file))
|
|
1273 {
|
|
1274 char *p = line;
|
|
1275 int cp1, cp2, endcount;
|
|
1276 int cp1high, cp1low;
|
|
1277 int dummy;
|
|
1278
|
|
1279 while (*p) /* erase all comments out of the line */
|
|
1280 {
|
|
1281 if (*p == '#')
|
|
1282 *p = '\0';
|
|
1283 else
|
|
1284 p++;
|
|
1285 }
|
|
1286 /* see if line is nothing but whitespace and skip if so */
|
|
1287 p = line + strspn (line, " \t\n\r\f");
|
|
1288 if (!*p)
|
|
1289 continue;
|
|
1290 /* NOTE: It appears that MS Windows and Newlib sscanf() have
|
|
1291 different interpretations for whitespace (== "skip all whitespace
|
|
1292 at processing point"): Newlib requires at least one corresponding
|
|
1293 whitespace character in the input, but MS allows none. The
|
|
1294 following would be easier to write if we could count on the MS
|
|
1295 interpretation.
|
|
1296
|
|
1297 Also, the return value does NOT include %n storage. */
|
|
1298 if ((!ignore_first_column ?
|
|
1299 sscanf (p, "%i %i%n", &cp1, &cp2, &endcount) < 2 :
|
|
1300 sscanf (p, "%i %i %i%n", &dummy, &cp1, &cp2, &endcount) < 3)
|
|
1301 || *(p + endcount + strspn (p + endcount, " \t\n\r\f")))
|
|
1302 {
|
793
|
1303 warn_when_safe (Qunicode, Qwarning,
|
771
|
1304 "Unrecognized line in translation file %s:\n%s",
|
|
1305 XSTRING_DATA (filename), line);
|
|
1306 continue;
|
|
1307 }
|
|
1308 if (cp1 >= st && cp1 <= en)
|
|
1309 {
|
|
1310 cp1 += of;
|
|
1311 if (cp1 < 0 || cp1 >= 65536)
|
|
1312 {
|
|
1313 out_of_range:
|
793
|
1314 warn_when_safe (Qunicode, Qwarning,
|
|
1315 "Out of range first codepoint 0x%x in "
|
|
1316 "translation file %s:\n%s",
|
771
|
1317 cp1, XSTRING_DATA (filename), line);
|
|
1318 continue;
|
|
1319 }
|
|
1320
|
|
1321 cp1high = cp1 >> 8;
|
|
1322 cp1low = cp1 & 255;
|
|
1323
|
|
1324 if (big5)
|
|
1325 {
|
867
|
1326 Ichar ch = decode_big5_char (cp1high, cp1low);
|
771
|
1327 if (ch == -1)
|
793
|
1328
|
|
1329 warn_when_safe (Qunicode, Qwarning,
|
|
1330 "Out of range Big5 codepoint 0x%x in "
|
|
1331 "translation file %s:\n%s",
|
771
|
1332 cp1, XSTRING_DATA (filename), line);
|
|
1333 else
|
|
1334 set_unicode_conversion (ch, cp2);
|
|
1335 }
|
|
1336 else
|
|
1337 {
|
|
1338 int l1, h1, l2, h2;
|
867
|
1339 Ichar emch;
|
771
|
1340
|
|
1341 switch (XCHARSET_TYPE (charset))
|
|
1342 {
|
|
1343 case CHARSET_TYPE_94: l1 = 33; h1 = 126; l2 = 0; h2 = 0; break;
|
|
1344 case CHARSET_TYPE_96: l1 = 32; h1 = 127; l2 = 0; h2 = 0; break;
|
|
1345 case CHARSET_TYPE_94X94: l1 = 33; h1 = 126; l2 = 33; h2 = 126;
|
|
1346 break;
|
|
1347 case CHARSET_TYPE_96X96: l1 = 32; h1 = 127; l2 = 32; h2 = 127;
|
|
1348 break;
|
|
1349 default: abort (); l1 = 0; h1 = 0; l2 = 0; h2 = 0;
|
|
1350 }
|
|
1351
|
|
1352 if (cp1high < l2 || cp1high > h2 || cp1low < l1 || cp1low > h1)
|
|
1353 goto out_of_range;
|
|
1354
|
867
|
1355 emch = (cp1high == 0 ? make_ichar (charset, cp1low, 0) :
|
|
1356 make_ichar (charset, cp1high, cp1low));
|
771
|
1357 set_unicode_conversion (emch, cp2);
|
|
1358 }
|
|
1359 }
|
|
1360 }
|
|
1361
|
|
1362 if (ferror (file))
|
|
1363 report_file_error ("IO error when reading", filename);
|
|
1364
|
|
1365 unbind_to (fondo); /* close file */
|
|
1366 UNGCPRO;
|
|
1367 return Qnil;
|
|
1368 }
|
|
1369
|
|
1370 #endif /* MULE */
|
|
1371
|
|
1372
|
|
1373 /************************************************************************/
|
|
1374 /* Unicode coding system */
|
|
1375 /************************************************************************/
|
|
1376
|
|
1377 /* ISO 10646 UTF-16, UCS-4, UTF-8, UTF-7, etc. */
|
|
1378 DEFINE_CODING_SYSTEM_TYPE (unicode);
|
|
1379
|
|
1380 enum unicode_type
|
|
1381 {
|
|
1382 UNICODE_UTF_16,
|
|
1383 UNICODE_UTF_8,
|
|
1384 UNICODE_UTF_7,
|
|
1385 UNICODE_UCS_4,
|
|
1386 };
|
|
1387
|
|
1388 struct unicode_coding_system
|
|
1389 {
|
|
1390 enum unicode_type type;
|
|
1391 int little_endian :1;
|
|
1392 int need_bom :1;
|
|
1393 };
|
|
1394
|
|
1395 #define CODING_SYSTEM_UNICODE_TYPE(codesys) \
|
|
1396 (CODING_SYSTEM_TYPE_DATA (codesys, unicode)->type)
|
|
1397 #define XCODING_SYSTEM_UNICODE_TYPE(codesys) \
|
|
1398 CODING_SYSTEM_UNICODE_TYPE (XCODING_SYSTEM (codesys))
|
|
1399 #define CODING_SYSTEM_UNICODE_LITTLE_ENDIAN(codesys) \
|
|
1400 (CODING_SYSTEM_TYPE_DATA (codesys, unicode)->little_endian)
|
|
1401 #define XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN(codesys) \
|
|
1402 CODING_SYSTEM_UNICODE_LITTLE_ENDIAN (XCODING_SYSTEM (codesys))
|
|
1403 #define CODING_SYSTEM_UNICODE_NEED_BOM(codesys) \
|
|
1404 (CODING_SYSTEM_TYPE_DATA (codesys, unicode)->need_bom)
|
|
1405 #define XCODING_SYSTEM_UNICODE_NEED_BOM(codesys) \
|
|
1406 CODING_SYSTEM_UNICODE_NEED_BOM (XCODING_SYSTEM (codesys))
|
|
1407
|
|
1408 struct unicode_coding_stream
|
|
1409 {
|
|
1410 /* decode */
|
|
1411 unsigned char counter;
|
|
1412 int seen_char;
|
|
1413 /* encode */
|
|
1414 Lisp_Object current_charset;
|
|
1415 int current_char_boundary;
|
|
1416 int wrote_bom;
|
|
1417 };
|
|
1418
|
|
1419 static const struct lrecord_description unicode_coding_system_description[] = {
|
|
1420 { XD_END }
|
|
1421 };
|
|
1422
|
|
1423 /* Decode a UCS-2 or UCS-4 character into a buffer. If the lookup fails, use
|
|
1424 <GETA MARK> (U+3013) of JIS X 0208, which means correct character
|
|
1425 is not found, instead.
|
|
1426 #### do something more appropriate (use blob?)
|
|
1427 Danger, Will Robinson! Data loss. Should we signal user? */
|
|
1428 static void
|
|
1429 decode_unicode_char (int ch, unsigned_char_dynarr *dst,
|
|
1430 struct unicode_coding_stream *data, int ignore_bom)
|
|
1431 {
|
|
1432 if (ch == 0xFEFF && !data->seen_char && ignore_bom)
|
|
1433 ;
|
|
1434 else
|
|
1435 {
|
|
1436 #ifdef MULE
|
867
|
1437 Ichar chr = unicode_to_char (ch, unicode_precedence_dynarr);
|
771
|
1438
|
|
1439 if (chr != -1)
|
|
1440 {
|
867
|
1441 Ibyte work[MAX_ICHAR_LEN];
|
771
|
1442 int len;
|
|
1443
|
867
|
1444 len = set_itext_ichar (work, chr);
|
771
|
1445 Dynarr_add_many (dst, work, len);
|
|
1446 }
|
|
1447 else
|
|
1448 {
|
|
1449 Dynarr_add (dst, LEADING_BYTE_JAPANESE_JISX0208);
|
|
1450 Dynarr_add (dst, 34 + 128);
|
|
1451 Dynarr_add (dst, 46 + 128);
|
|
1452 }
|
|
1453 #else
|
867
|
1454 Dynarr_add (dst, (Ibyte) ch);
|
771
|
1455 #endif /* MULE */
|
|
1456 }
|
|
1457
|
|
1458 data->seen_char = 1;
|
|
1459 }
|
|
1460
|
|
1461 static void
|
|
1462 encode_unicode_char_1 (int code, unsigned_char_dynarr *dst,
|
|
1463 enum unicode_type type, int little_endian)
|
|
1464 {
|
|
1465 switch (type)
|
|
1466 {
|
|
1467 case UNICODE_UTF_16:
|
|
1468 if (little_endian)
|
|
1469 {
|
|
1470 Dynarr_add (dst, (unsigned char) (code & 255));
|
|
1471 Dynarr_add (dst, (unsigned char) ((code >> 8) & 255));
|
|
1472 }
|
|
1473 else
|
|
1474 {
|
|
1475 Dynarr_add (dst, (unsigned char) ((code >> 8) & 255));
|
|
1476 Dynarr_add (dst, (unsigned char) (code & 255));
|
|
1477 }
|
|
1478 break;
|
|
1479
|
|
1480 case UNICODE_UCS_4:
|
|
1481 if (little_endian)
|
|
1482 {
|
|
1483 Dynarr_add (dst, (unsigned char) (code & 255));
|
|
1484 Dynarr_add (dst, (unsigned char) ((code >> 8) & 255));
|
|
1485 Dynarr_add (dst, (unsigned char) ((code >> 16) & 255));
|
|
1486 Dynarr_add (dst, (unsigned char) (code >> 24));
|
|
1487 }
|
|
1488 else
|
|
1489 {
|
|
1490 Dynarr_add (dst, (unsigned char) (code >> 24));
|
|
1491 Dynarr_add (dst, (unsigned char) ((code >> 16) & 255));
|
|
1492 Dynarr_add (dst, (unsigned char) ((code >> 8) & 255));
|
|
1493 Dynarr_add (dst, (unsigned char) (code & 255));
|
|
1494 }
|
|
1495 break;
|
|
1496
|
|
1497 case UNICODE_UTF_8:
|
|
1498 if (code <= 0x7f)
|
|
1499 {
|
|
1500 Dynarr_add (dst, (unsigned char) code);
|
|
1501 }
|
|
1502 else if (code <= 0x7ff)
|
|
1503 {
|
|
1504 Dynarr_add (dst, (unsigned char) ((code >> 6) | 0xc0));
|
|
1505 Dynarr_add (dst, (unsigned char) ((code & 0x3f) | 0x80));
|
|
1506 }
|
|
1507 else if (code <= 0xffff)
|
|
1508 {
|
|
1509 Dynarr_add (dst, (unsigned char) ((code >> 12) | 0xe0));
|
|
1510 Dynarr_add (dst, (unsigned char) (((code >> 6) & 0x3f) | 0x80));
|
|
1511 Dynarr_add (dst, (unsigned char) ((code & 0x3f) | 0x80));
|
|
1512 }
|
|
1513 else if (code <= 0x1fffff)
|
|
1514 {
|
|
1515 Dynarr_add (dst, (unsigned char) ((code >> 18) | 0xf0));
|
|
1516 Dynarr_add (dst, (unsigned char) (((code >> 12) & 0x3f) | 0x80));
|
|
1517 Dynarr_add (dst, (unsigned char) (((code >> 6) & 0x3f) | 0x80));
|
|
1518 Dynarr_add (dst, (unsigned char) ((code & 0x3f) | 0x80));
|
|
1519 }
|
|
1520 else if (code <= 0x3ffffff)
|
|
1521 {
|
|
1522 Dynarr_add (dst, (unsigned char) ((code >> 24) | 0xf8));
|
|
1523 Dynarr_add (dst, (unsigned char) (((code >> 18) & 0x3f) | 0x80));
|
|
1524 Dynarr_add (dst, (unsigned char) (((code >> 12) & 0x3f) | 0x80));
|
|
1525 Dynarr_add (dst, (unsigned char) (((code >> 6) & 0x3f) | 0x80));
|
|
1526 Dynarr_add (dst, (unsigned char) ((code & 0x3f) | 0x80));
|
|
1527 }
|
|
1528 else
|
|
1529 {
|
|
1530 Dynarr_add (dst, (unsigned char) ((code >> 30) | 0xfc));
|
|
1531 Dynarr_add (dst, (unsigned char) (((code >> 24) & 0x3f) | 0x80));
|
|
1532 Dynarr_add (dst, (unsigned char) (((code >> 18) & 0x3f) | 0x80));
|
|
1533 Dynarr_add (dst, (unsigned char) (((code >> 12) & 0x3f) | 0x80));
|
|
1534 Dynarr_add (dst, (unsigned char) (((code >> 6) & 0x3f) | 0x80));
|
|
1535 Dynarr_add (dst, (unsigned char) ((code & 0x3f) | 0x80));
|
|
1536 }
|
|
1537 break;
|
|
1538
|
|
1539 case UNICODE_UTF_7: abort ();
|
|
1540
|
|
1541 default: abort ();
|
|
1542 }
|
|
1543 }
|
|
1544
|
|
1545 static void
|
|
1546 encode_unicode_char (Lisp_Object charset, int h, int l,
|
|
1547 unsigned_char_dynarr *dst, enum unicode_type type,
|
|
1548 int little_endian)
|
|
1549 {
|
|
1550 #ifdef MULE
|
867
|
1551 int code = ichar_to_unicode (make_ichar (charset, h & 127, l & 127));
|
771
|
1552
|
|
1553 if (code == -1)
|
|
1554 {
|
|
1555 if (type != UNICODE_UTF_16 &&
|
|
1556 XCHARSET_DIMENSION (charset) == 2 &&
|
|
1557 XCHARSET_CHARS (charset) == 94)
|
|
1558 {
|
|
1559 unsigned char final = XCHARSET_FINAL (charset);
|
|
1560
|
|
1561 if (('@' <= final) && (final < 0x7f))
|
|
1562 code = (0xe00000 + (final - '@') * 94 * 94
|
|
1563 + ((h & 127) - 33) * 94 + (l & 127) - 33);
|
|
1564 else
|
|
1565 code = '?';
|
|
1566 }
|
|
1567 else
|
|
1568 code = '?';
|
|
1569 }
|
|
1570 #else
|
|
1571 int code = h;
|
|
1572 #endif /* MULE */
|
|
1573
|
|
1574 encode_unicode_char_1 (code, dst, type, little_endian);
|
|
1575 }
|
|
1576
|
|
1577 static Bytecount
|
|
1578 unicode_convert (struct coding_stream *str, const UExtbyte *src,
|
|
1579 unsigned_char_dynarr *dst, Bytecount n)
|
|
1580 {
|
|
1581 unsigned int ch = str->ch;
|
|
1582 struct unicode_coding_stream *data = CODING_STREAM_TYPE_DATA (str, unicode);
|
|
1583 enum unicode_type type =
|
|
1584 XCODING_SYSTEM_UNICODE_TYPE (str->codesys);
|
|
1585 int little_endian = XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN (str->codesys);
|
|
1586 int ignore_bom = XCODING_SYSTEM_UNICODE_NEED_BOM (str->codesys);
|
|
1587 Bytecount orign = n;
|
|
1588
|
|
1589 if (str->direction == CODING_DECODE)
|
|
1590 {
|
|
1591 unsigned char counter = data->counter;
|
|
1592
|
|
1593 while (n--)
|
|
1594 {
|
|
1595 UExtbyte c = *src++;
|
|
1596
|
|
1597 switch (type)
|
|
1598 {
|
|
1599 case UNICODE_UTF_8:
|
|
1600 switch (counter)
|
|
1601 {
|
|
1602 case 0:
|
|
1603 if (c >= 0xfc)
|
|
1604 {
|
|
1605 ch = c & 0x01;
|
|
1606 counter = 5;
|
|
1607 }
|
|
1608 else if (c >= 0xf8)
|
|
1609 {
|
|
1610 ch = c & 0x03;
|
|
1611 counter = 4;
|
|
1612 }
|
|
1613 else if (c >= 0xf0)
|
|
1614 {
|
|
1615 ch = c & 0x07;
|
|
1616 counter = 3;
|
|
1617 }
|
|
1618 else if (c >= 0xe0)
|
|
1619 {
|
|
1620 ch = c & 0x0f;
|
|
1621 counter = 2;
|
|
1622 }
|
|
1623 else if (c >= 0xc0)
|
|
1624 {
|
|
1625 ch = c & 0x1f;
|
|
1626 counter = 1;
|
|
1627 }
|
|
1628 else
|
|
1629 decode_unicode_char (c, dst, data, ignore_bom);
|
|
1630 break;
|
|
1631 case 1:
|
|
1632 ch = (ch << 6) | (c & 0x3f);
|
|
1633 decode_unicode_char (ch, dst, data, ignore_bom);
|
|
1634 ch = 0;
|
|
1635 counter = 0;
|
|
1636 break;
|
|
1637 default:
|
|
1638 ch = (ch << 6) | (c & 0x3f);
|
|
1639 counter--;
|
|
1640 }
|
|
1641 break;
|
|
1642
|
|
1643 case UNICODE_UTF_16:
|
|
1644 if (little_endian)
|
|
1645 ch = (c << counter) | ch;
|
|
1646 else
|
|
1647 ch = (ch << 8) | c;
|
|
1648 counter += 8;
|
|
1649 if (counter == 16)
|
|
1650 {
|
|
1651 int tempch = ch;
|
|
1652 ch = 0;
|
|
1653 counter = 0;
|
|
1654 decode_unicode_char (tempch, dst, data, ignore_bom);
|
|
1655 }
|
|
1656 break;
|
|
1657
|
|
1658 case UNICODE_UCS_4:
|
|
1659 if (little_endian)
|
|
1660 ch = (c << counter) | ch;
|
|
1661 else
|
|
1662 ch = (ch << 8) | c;
|
|
1663 counter += 8;
|
|
1664 if (counter == 32)
|
|
1665 {
|
|
1666 int tempch = ch;
|
|
1667 ch = 0;
|
|
1668 counter = 0;
|
|
1669 if (tempch < 0)
|
|
1670 {
|
|
1671 /* !!#### indicate an error */
|
|
1672 tempch = '~';
|
|
1673 }
|
|
1674 decode_unicode_char (tempch, dst, data, ignore_bom);
|
|
1675 }
|
|
1676 break;
|
|
1677
|
|
1678 case UNICODE_UTF_7:
|
|
1679 abort ();
|
|
1680 break;
|
|
1681
|
|
1682 default: abort ();
|
|
1683 }
|
|
1684
|
|
1685 }
|
|
1686 if (str->eof)
|
|
1687 DECODE_OUTPUT_PARTIAL_CHAR (ch, dst);
|
|
1688
|
|
1689 data->counter = counter;
|
|
1690 }
|
|
1691 else
|
|
1692 {
|
|
1693 unsigned char char_boundary = data->current_char_boundary;
|
|
1694 Lisp_Object charset = data->current_charset;
|
|
1695
|
|
1696 #ifdef ENABLE_COMPOSITE_CHARS
|
|
1697 /* flags for handling composite chars. We do a little switcheroo
|
|
1698 on the source while we're outputting the composite char. */
|
|
1699 Bytecount saved_n = 0;
|
867
|
1700 const Ibyte *saved_src = NULL;
|
771
|
1701 int in_composite = 0;
|
|
1702
|
|
1703 back_to_square_n:
|
|
1704 #endif /* ENABLE_COMPOSITE_CHARS */
|
|
1705
|
|
1706 if (XCODING_SYSTEM_UNICODE_NEED_BOM (str->codesys) && !data->wrote_bom)
|
|
1707 {
|
|
1708 encode_unicode_char_1 (0xFEFF, dst, type, little_endian);
|
|
1709 data->wrote_bom = 1;
|
|
1710 }
|
|
1711
|
|
1712 while (n--)
|
|
1713 {
|
867
|
1714 Ibyte c = *src++;
|
771
|
1715
|
|
1716 #ifdef MULE
|
826
|
1717 if (byte_ascii_p (c))
|
771
|
1718 #endif /* MULE */
|
|
1719 { /* Processing ASCII character */
|
|
1720 ch = 0;
|
|
1721 encode_unicode_char (Vcharset_ascii, c, 0, dst, type,
|
|
1722 little_endian);
|
|
1723
|
|
1724 char_boundary = 1;
|
|
1725 }
|
|
1726 #ifdef MULE
|
867
|
1727 else if (ibyte_leading_byte_p (c) || ibyte_leading_byte_p (ch))
|
771
|
1728 { /* Processing Leading Byte */
|
|
1729 ch = 0;
|
826
|
1730 charset = charset_by_leading_byte (c);
|
|
1731 if (leading_byte_prefix_p(c))
|
771
|
1732 ch = c;
|
|
1733 char_boundary = 0;
|
|
1734 }
|
|
1735 else
|
|
1736 { /* Processing Non-ASCII character */
|
|
1737 char_boundary = 1;
|
|
1738 if (EQ (charset, Vcharset_control_1))
|
|
1739 encode_unicode_char (Vcharset_control_1, c, 0, dst,
|
|
1740 type, little_endian);
|
|
1741 else
|
|
1742 {
|
|
1743 switch (XCHARSET_REP_BYTES (charset))
|
|
1744 {
|
|
1745 case 2:
|
|
1746 encode_unicode_char (charset, c, 0, dst, type,
|
|
1747 little_endian);
|
|
1748 break;
|
|
1749 case 3:
|
|
1750 if (XCHARSET_PRIVATE_P (charset))
|
|
1751 {
|
|
1752 encode_unicode_char (charset, c, 0, dst, type,
|
|
1753 little_endian);
|
|
1754 ch = 0;
|
|
1755 }
|
|
1756 else if (ch)
|
|
1757 {
|
|
1758 #ifdef ENABLE_COMPOSITE_CHARS
|
|
1759 if (EQ (charset, Vcharset_composite))
|
|
1760 {
|
|
1761 if (in_composite)
|
|
1762 {
|
|
1763 /* #### Bother! We don't know how to
|
|
1764 handle this yet. */
|
|
1765 encode_unicode_char (Vcharset_ascii, '~', 0,
|
|
1766 dst, type,
|
|
1767 little_endian);
|
|
1768 }
|
|
1769 else
|
|
1770 {
|
867
|
1771 Ichar emch = make_ichar (Vcharset_composite,
|
771
|
1772 ch & 0x7F,
|
|
1773 c & 0x7F);
|
|
1774 Lisp_Object lstr =
|
|
1775 composite_char_string (emch);
|
|
1776 saved_n = n;
|
|
1777 saved_src = src;
|
|
1778 in_composite = 1;
|
|
1779 src = XSTRING_DATA (lstr);
|
|
1780 n = XSTRING_LENGTH (lstr);
|
|
1781 }
|
|
1782 }
|
|
1783 else
|
|
1784 #endif /* ENABLE_COMPOSITE_CHARS */
|
|
1785 encode_unicode_char (charset, ch, c, dst, type,
|
|
1786 little_endian);
|
|
1787 ch = 0;
|
|
1788 }
|
|
1789 else
|
|
1790 {
|
|
1791 ch = c;
|
|
1792 char_boundary = 0;
|
|
1793 }
|
|
1794 break;
|
|
1795 case 4:
|
|
1796 if (ch)
|
|
1797 {
|
|
1798 encode_unicode_char (charset, ch, c, dst, type,
|
|
1799 little_endian);
|
|
1800 ch = 0;
|
|
1801 }
|
|
1802 else
|
|
1803 {
|
|
1804 ch = c;
|
|
1805 char_boundary = 0;
|
|
1806 }
|
|
1807 break;
|
|
1808 default:
|
|
1809 abort ();
|
|
1810 }
|
|
1811 }
|
|
1812 }
|
|
1813 #endif /* MULE */
|
|
1814 }
|
|
1815
|
|
1816 #ifdef ENABLE_COMPOSITE_CHARS
|
|
1817 if (in_composite)
|
|
1818 {
|
|
1819 n = saved_n;
|
|
1820 src = saved_src;
|
|
1821 in_composite = 0;
|
|
1822 goto back_to_square_n; /* Wheeeeeeeee ..... */
|
|
1823 }
|
|
1824 #endif /* ENABLE_COMPOSITE_CHARS */
|
|
1825
|
|
1826 data->current_char_boundary = char_boundary;
|
|
1827 data->current_charset = charset;
|
|
1828
|
|
1829 /* La palabra se hizo carne! */
|
|
1830 /* A palavra fez-se carne! */
|
|
1831 /* Whatever. */
|
|
1832 }
|
|
1833
|
|
1834 str->ch = ch;
|
|
1835 return orign;
|
|
1836 }
|
|
1837
|
|
1838 /* DEFINE_DETECTOR (utf_7); */
|
|
1839 DEFINE_DETECTOR (utf_8);
|
|
1840 DEFINE_DETECTOR_CATEGORY (utf_8, utf_8);
|
|
1841 DEFINE_DETECTOR (ucs_4);
|
|
1842 DEFINE_DETECTOR_CATEGORY (ucs_4, ucs_4);
|
|
1843 DEFINE_DETECTOR (utf_16);
|
|
1844 DEFINE_DETECTOR_CATEGORY (utf_16, utf_16);
|
|
1845 DEFINE_DETECTOR_CATEGORY (utf_16, utf_16_little_endian);
|
|
1846 DEFINE_DETECTOR_CATEGORY (utf_16, utf_16_bom);
|
|
1847 DEFINE_DETECTOR_CATEGORY (utf_16, utf_16_little_endian_bom);
|
|
1848
|
|
1849 struct ucs_4_detector
|
|
1850 {
|
|
1851 int in_ucs_4_byte;
|
|
1852 };
|
|
1853
|
|
1854 static void
|
|
1855 ucs_4_detect (struct detection_state *st, const UExtbyte *src,
|
|
1856 Bytecount n)
|
|
1857 {
|
|
1858 struct ucs_4_detector *data = DETECTION_STATE_DATA (st, ucs_4);
|
|
1859
|
|
1860 while (n--)
|
|
1861 {
|
|
1862 UExtbyte c = *src++;
|
|
1863 switch (data->in_ucs_4_byte)
|
|
1864 {
|
|
1865 case 0:
|
|
1866 if (c >= 128)
|
|
1867 {
|
|
1868 DET_RESULT (st, ucs_4) = DET_NEARLY_IMPOSSIBLE;
|
|
1869 return;
|
|
1870 }
|
|
1871 else
|
|
1872 data->in_ucs_4_byte++;
|
|
1873 break;
|
|
1874 case 3:
|
|
1875 data->in_ucs_4_byte = 0;
|
|
1876 break;
|
|
1877 default:
|
|
1878 data->in_ucs_4_byte++;
|
|
1879 }
|
|
1880 }
|
|
1881
|
|
1882 /* !!#### write this for real */
|
|
1883 DET_RESULT (st, ucs_4) = DET_AS_LIKELY_AS_UNLIKELY;
|
|
1884 }
|
|
1885
|
|
1886 struct utf_16_detector
|
|
1887 {
|
|
1888 unsigned int seen_ffff:1;
|
|
1889 unsigned int seen_forward_bom:1;
|
|
1890 unsigned int seen_rev_bom:1;
|
|
1891 int byteno;
|
|
1892 int prev_char;
|
|
1893 int text, rev_text;
|
|
1894 };
|
|
1895
|
|
1896 static void
|
|
1897 utf_16_detect (struct detection_state *st, const UExtbyte *src,
|
|
1898 Bytecount n)
|
|
1899 {
|
|
1900 struct utf_16_detector *data = DETECTION_STATE_DATA (st, utf_16);
|
|
1901
|
|
1902 while (n--)
|
|
1903 {
|
|
1904 UExtbyte c = *src++;
|
|
1905 int prevc = data->prev_char;
|
|
1906 if (data->byteno == 1 && c == 0xFF && prevc == 0xFE)
|
|
1907 data->seen_forward_bom = 1;
|
|
1908 else if (data->byteno == 1 && c == 0xFE && prevc == 0xFF)
|
|
1909 data->seen_rev_bom = 1;
|
|
1910
|
|
1911 if (data->byteno & 1)
|
|
1912 {
|
|
1913 if (c == 0xFF && prevc == 0xFF)
|
|
1914 data->seen_ffff = 1;
|
|
1915 if (prevc == 0
|
|
1916 && (c == '\r' || c == '\n'
|
|
1917 || (c >= 0x20 && c <= 0x7E)))
|
|
1918 data->text++;
|
|
1919 if (c == 0
|
|
1920 && (prevc == '\r' || prevc == '\n'
|
|
1921 || (prevc >= 0x20 && prevc <= 0x7E)))
|
|
1922 data->rev_text++;
|
|
1923 if (prevc == 0x20 && (c == 0x28 || c == 0x29))
|
|
1924 data->text++;
|
|
1925 if (c == 0x20 && (prevc == 0x28 || prevc == 0x29))
|
|
1926 data->rev_text++;
|
|
1927 }
|
|
1928
|
|
1929 data->byteno++;
|
|
1930 data->prev_char = c;
|
|
1931 }
|
|
1932
|
|
1933 {
|
|
1934 int variance_indicates_big_endian =
|
|
1935 (data->text >= 10
|
|
1936 && (data->rev_text == 0
|
|
1937 || data->text / data->rev_text >= 10));
|
|
1938 int variance_indicates_little_endian =
|
|
1939 (data->rev_text >= 10
|
|
1940 && (data->text == 0
|
|
1941 || data->rev_text / data->text >= 10));
|
|
1942
|
|
1943 if (data->seen_ffff)
|
|
1944 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE);
|
|
1945 else if (data->seen_forward_bom)
|
|
1946 {
|
|
1947 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE);
|
|
1948 if (variance_indicates_big_endian)
|
|
1949 DET_RESULT (st, utf_16_bom) = DET_NEAR_CERTAINTY;
|
|
1950 else if (variance_indicates_little_endian)
|
|
1951 DET_RESULT (st, utf_16_bom) = DET_SOMEWHAT_LIKELY;
|
|
1952 else
|
|
1953 DET_RESULT (st, utf_16_bom) = DET_QUITE_PROBABLE;
|
|
1954 }
|
|
1955 else if (data->seen_forward_bom)
|
|
1956 {
|
|
1957 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE);
|
|
1958 if (variance_indicates_big_endian)
|
|
1959 DET_RESULT (st, utf_16_bom) = DET_NEAR_CERTAINTY;
|
|
1960 else if (variance_indicates_little_endian)
|
|
1961 /* #### may need to rethink */
|
|
1962 DET_RESULT (st, utf_16_bom) = DET_SOMEWHAT_LIKELY;
|
|
1963 else
|
|
1964 /* #### may need to rethink */
|
|
1965 DET_RESULT (st, utf_16_bom) = DET_QUITE_PROBABLE;
|
|
1966 }
|
|
1967 else if (data->seen_rev_bom)
|
|
1968 {
|
|
1969 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE);
|
|
1970 if (variance_indicates_little_endian)
|
|
1971 DET_RESULT (st, utf_16_little_endian_bom) = DET_NEAR_CERTAINTY;
|
|
1972 else if (variance_indicates_big_endian)
|
|
1973 /* #### may need to rethink */
|
|
1974 DET_RESULT (st, utf_16_little_endian_bom) = DET_SOMEWHAT_LIKELY;
|
|
1975 else
|
|
1976 /* #### may need to rethink */
|
|
1977 DET_RESULT (st, utf_16_little_endian_bom) = DET_QUITE_PROBABLE;
|
|
1978 }
|
|
1979 else if (variance_indicates_big_endian)
|
|
1980 {
|
|
1981 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE);
|
|
1982 DET_RESULT (st, utf_16) = DET_SOMEWHAT_LIKELY;
|
|
1983 DET_RESULT (st, utf_16_little_endian) = DET_SOMEWHAT_UNLIKELY;
|
|
1984 }
|
|
1985 else if (variance_indicates_little_endian)
|
|
1986 {
|
|
1987 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE);
|
|
1988 DET_RESULT (st, utf_16) = DET_SOMEWHAT_UNLIKELY;
|
|
1989 DET_RESULT (st, utf_16_little_endian) = DET_SOMEWHAT_LIKELY;
|
|
1990 }
|
|
1991 else
|
|
1992 SET_DET_RESULTS (st, utf_16, DET_AS_LIKELY_AS_UNLIKELY);
|
|
1993 }
|
|
1994 }
|
|
1995
|
|
1996 struct utf_8_detector
|
|
1997 {
|
|
1998 int in_utf_8_byte;
|
|
1999 };
|
|
2000
|
|
2001 static void
|
|
2002 utf_8_detect (struct detection_state *st, const UExtbyte *src,
|
|
2003 Bytecount n)
|
|
2004 {
|
|
2005 struct utf_8_detector *data = DETECTION_STATE_DATA (st, utf_8);
|
|
2006
|
|
2007 while (n--)
|
|
2008 {
|
|
2009 UExtbyte c = *src++;
|
|
2010 switch (data->in_utf_8_byte)
|
|
2011 {
|
|
2012 case 0:
|
|
2013 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)
|
|
2014 {
|
|
2015 DET_RESULT (st, utf_8) = DET_SOMEWHAT_UNLIKELY;
|
|
2016 return;
|
|
2017 }
|
|
2018 else if (c >= 0xfc)
|
|
2019 data->in_utf_8_byte = 5;
|
|
2020 else if (c >= 0xf8)
|
|
2021 data->in_utf_8_byte = 4;
|
|
2022 else if (c >= 0xf0)
|
|
2023 data->in_utf_8_byte = 3;
|
|
2024 else if (c >= 0xe0)
|
|
2025 data->in_utf_8_byte = 2;
|
|
2026 else if (c >= 0xc0)
|
|
2027 data->in_utf_8_byte = 1;
|
|
2028 else if (c >= 0x80)
|
|
2029 {
|
|
2030 DET_RESULT (st, utf_8) = DET_SOMEWHAT_UNLIKELY;
|
|
2031 return;
|
|
2032 }
|
|
2033 break;
|
|
2034 default:
|
|
2035 if ((c & 0xc0) != 0x80)
|
|
2036 {
|
|
2037 DET_RESULT (st, utf_8) = DET_SOMEWHAT_UNLIKELY;
|
|
2038 return;
|
|
2039 }
|
|
2040 else
|
|
2041 data->in_utf_8_byte--;
|
|
2042 }
|
|
2043 }
|
|
2044 DET_RESULT (st, utf_8) = DET_SOMEWHAT_LIKELY;
|
|
2045 }
|
|
2046
|
|
2047 static void
|
|
2048 unicode_init_coding_stream (struct coding_stream *str)
|
|
2049 {
|
|
2050 struct unicode_coding_stream *data =
|
|
2051 CODING_STREAM_TYPE_DATA (str, unicode);
|
|
2052 xzero (*data);
|
|
2053 data->current_charset = Qnil;
|
|
2054 }
|
|
2055
|
|
2056 static void
|
|
2057 unicode_rewind_coding_stream (struct coding_stream *str)
|
|
2058 {
|
|
2059 unicode_init_coding_stream (str);
|
|
2060 }
|
|
2061
|
|
2062 static int
|
|
2063 unicode_putprop (Lisp_Object codesys, Lisp_Object key, Lisp_Object value)
|
|
2064 {
|
|
2065 if (EQ (key, Qtype))
|
|
2066 {
|
|
2067 enum unicode_type type;
|
|
2068
|
|
2069 if (EQ (value, Qutf_8))
|
|
2070 type = UNICODE_UTF_8;
|
|
2071 else if (EQ (value, Qutf_16))
|
|
2072 type = UNICODE_UTF_16;
|
|
2073 else if (EQ (value, Qutf_7))
|
|
2074 type = UNICODE_UTF_7;
|
|
2075 else if (EQ (value, Qucs_4))
|
|
2076 type = UNICODE_UCS_4;
|
|
2077 else
|
|
2078 invalid_constant ("Invalid Unicode type", key);
|
|
2079
|
|
2080 XCODING_SYSTEM_UNICODE_TYPE (codesys) = type;
|
|
2081 }
|
|
2082 else if (EQ (key, Qlittle_endian))
|
|
2083 XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN (codesys) = !NILP (value);
|
|
2084 else if (EQ (key, Qneed_bom))
|
|
2085 XCODING_SYSTEM_UNICODE_NEED_BOM (codesys) = !NILP (value);
|
|
2086 else
|
|
2087 return 0;
|
|
2088 return 1;
|
|
2089 }
|
|
2090
|
|
2091 static Lisp_Object
|
|
2092 unicode_getprop (Lisp_Object coding_system, Lisp_Object prop)
|
|
2093 {
|
|
2094 if (EQ (prop, Qtype))
|
|
2095 {
|
|
2096 switch (XCODING_SYSTEM_UNICODE_TYPE (coding_system))
|
|
2097 {
|
|
2098 case UNICODE_UTF_16: return Qutf_16;
|
|
2099 case UNICODE_UTF_8: return Qutf_8;
|
|
2100 case UNICODE_UTF_7: return Qutf_7;
|
|
2101 case UNICODE_UCS_4: return Qucs_4;
|
|
2102 default: abort ();
|
|
2103 }
|
|
2104 }
|
|
2105 else if (EQ (prop, Qlittle_endian))
|
|
2106 return XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN (coding_system) ? Qt : Qnil;
|
|
2107 else if (EQ (prop, Qneed_bom))
|
|
2108 return XCODING_SYSTEM_UNICODE_NEED_BOM (coding_system) ? Qt : Qnil;
|
|
2109 return Qunbound;
|
|
2110 }
|
|
2111
|
|
2112 static void
|
|
2113 unicode_print (Lisp_Object cs, Lisp_Object printcharfun, int escapeflag)
|
|
2114 {
|
800
|
2115 write_fmt_string_lisp (printcharfun, "(%s", 1, unicode_getprop (cs, Qtype));
|
771
|
2116 if (XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN (cs))
|
826
|
2117 write_c_string (printcharfun, ", little-endian");
|
771
|
2118 if (XCODING_SYSTEM_UNICODE_NEED_BOM (cs))
|
826
|
2119 write_c_string (printcharfun, ", need-bom");
|
|
2120 write_c_string (printcharfun, ")");
|
771
|
2121 }
|
|
2122
|
|
2123 int
|
|
2124 dfc_coding_system_is_unicode (Lisp_Object codesys)
|
|
2125 {
|
|
2126 #ifdef HAVE_WIN32_CODING_SYSTEMS
|
|
2127 codesys = Fget_coding_system (codesys);
|
|
2128 return (EQ (XCODING_SYSTEM_TYPE (codesys), Qunicode) &&
|
|
2129 XCODING_SYSTEM_UNICODE_TYPE (codesys) == UNICODE_UTF_16 &&
|
|
2130 XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN (codesys));
|
|
2131
|
|
2132 #else
|
|
2133 return 0;
|
|
2134 #endif
|
|
2135 }
|
|
2136
|
|
2137
|
|
2138 /************************************************************************/
|
|
2139 /* Initialization */
|
|
2140 /************************************************************************/
|
|
2141
|
|
2142 void
|
|
2143 syms_of_unicode (void)
|
|
2144 {
|
|
2145 #ifdef MULE
|
|
2146 DEFSUBR (Fset_language_unicode_precedence_list);
|
|
2147 DEFSUBR (Flanguage_unicode_precedence_list);
|
|
2148 DEFSUBR (Fset_default_unicode_precedence_list);
|
|
2149 DEFSUBR (Fdefault_unicode_precedence_list);
|
|
2150 DEFSUBR (Fset_unicode_conversion);
|
|
2151
|
|
2152 DEFSUBR (Fparse_unicode_translation_table);
|
|
2153
|
|
2154 DEFSYMBOL (Qignore_first_column);
|
|
2155 #endif /* MULE */
|
|
2156
|
800
|
2157 DEFSUBR (Fchar_to_unicode);
|
|
2158 DEFSUBR (Funicode_to_char);
|
771
|
2159
|
|
2160 DEFSYMBOL (Qunicode);
|
|
2161 DEFSYMBOL (Qucs_4);
|
|
2162 DEFSYMBOL (Qutf_16);
|
|
2163 DEFSYMBOL (Qutf_8);
|
|
2164 DEFSYMBOL (Qutf_7);
|
|
2165
|
|
2166 DEFSYMBOL (Qneed_bom);
|
|
2167
|
|
2168 DEFSYMBOL (Qutf_16);
|
|
2169 DEFSYMBOL (Qutf_16_little_endian);
|
|
2170 DEFSYMBOL (Qutf_16_bom);
|
|
2171 DEFSYMBOL (Qutf_16_little_endian_bom);
|
|
2172 }
|
|
2173
|
|
2174 void
|
|
2175 coding_system_type_create_unicode (void)
|
|
2176 {
|
|
2177 INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA (unicode, "unicode-coding-system-p");
|
|
2178 CODING_SYSTEM_HAS_METHOD (unicode, print);
|
|
2179 CODING_SYSTEM_HAS_METHOD (unicode, convert);
|
|
2180 CODING_SYSTEM_HAS_METHOD (unicode, init_coding_stream);
|
|
2181 CODING_SYSTEM_HAS_METHOD (unicode, rewind_coding_stream);
|
|
2182 CODING_SYSTEM_HAS_METHOD (unicode, putprop);
|
|
2183 CODING_SYSTEM_HAS_METHOD (unicode, getprop);
|
|
2184
|
|
2185 INITIALIZE_DETECTOR (utf_8);
|
|
2186 DETECTOR_HAS_METHOD (utf_8, detect);
|
|
2187 INITIALIZE_DETECTOR_CATEGORY (utf_8, utf_8);
|
|
2188
|
|
2189 INITIALIZE_DETECTOR (ucs_4);
|
|
2190 DETECTOR_HAS_METHOD (ucs_4, detect);
|
|
2191 INITIALIZE_DETECTOR_CATEGORY (ucs_4, ucs_4);
|
|
2192
|
|
2193 INITIALIZE_DETECTOR (utf_16);
|
|
2194 DETECTOR_HAS_METHOD (utf_16, detect);
|
|
2195 INITIALIZE_DETECTOR_CATEGORY (utf_16, utf_16);
|
|
2196 INITIALIZE_DETECTOR_CATEGORY (utf_16, utf_16_little_endian);
|
|
2197 INITIALIZE_DETECTOR_CATEGORY (utf_16, utf_16_bom);
|
|
2198 INITIALIZE_DETECTOR_CATEGORY (utf_16, utf_16_little_endian_bom);
|
|
2199 }
|
|
2200
|
|
2201 void
|
|
2202 reinit_coding_system_type_create_unicode (void)
|
|
2203 {
|
|
2204 REINITIALIZE_CODING_SYSTEM_TYPE (unicode);
|
|
2205 }
|
|
2206
|
|
2207 void
|
|
2208 reinit_vars_of_unicode (void)
|
|
2209 {
|
|
2210 #ifdef MULE
|
|
2211 init_blank_unicode_tables ();
|
|
2212 #endif /* MULE */
|
|
2213 }
|
|
2214
|
|
2215 void
|
|
2216 vars_of_unicode (void)
|
|
2217 {
|
|
2218 reinit_vars_of_unicode ();
|
|
2219
|
|
2220 Fprovide (intern ("unicode"));
|
|
2221
|
|
2222 #ifdef MULE
|
|
2223 staticpro (&Vlanguage_unicode_precedence_list);
|
|
2224 Vlanguage_unicode_precedence_list = Qnil;
|
|
2225
|
|
2226 staticpro (&Vdefault_unicode_precedence_list);
|
|
2227 Vdefault_unicode_precedence_list = Qnil;
|
|
2228
|
|
2229 unicode_precedence_dynarr = Dynarr_new (Lisp_Object);
|
|
2230 dump_add_root_struct_ptr (&unicode_precedence_dynarr,
|
|
2231 &lisp_object_dynarr_description);
|
|
2232 #if 0
|
|
2233 dump_add_root_thing (&to_unicode_blank_1, to_unicode_level_1_desc);
|
|
2234 dump_add_root_thing (&to_unicode_blank_2, to_unicode_level_2_desc);
|
|
2235
|
|
2236 dump_add_root_thing (&from_unicode_blank_1, from_unicode_level_1_desc);
|
|
2237 dump_add_root_thing (&from_unicode_blank_2, from_unicode_level_2_desc);
|
|
2238 dump_add_root_thing (&from_unicode_blank_3, from_unicode_level_3_desc);
|
|
2239 dump_add_root_thing (&from_unicode_blank_4, from_unicode_level_4_desc);
|
|
2240 #endif
|
|
2241
|
|
2242 #endif /* MULE */
|
|
2243 }
|