771
|
1 /* Code to handle Unicode conversion.
|
3025
|
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Ben Wing.
|
771
|
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
|
877
|
30 by someone else. #### Morioka and Hayashi, I think.
|
771
|
31
|
|
32 As of September 2001, the detection code is here and abstraction of the
|
877
|
33 detection system is finished. The unicode detectors have been rewritten
|
771
|
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
|
2367
|
46 /* For more info about how Unicode works under Windows, see intl-win32.c. */
|
|
47
|
|
48 /* Info about Unicode translation tables [ben]:
|
|
49
|
|
50 FORMAT:
|
|
51 -------
|
|
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 * pointers,
|
|
57 each of which points to a 96-element array of ints. If no elements in a
|
|
58 row have been filled in, the pointer will point to a default empty
|
|
59 table; that way, memory usage is more reasonable but lookup still fast.
|
|
60
|
|
61 -- If from_unicode_levels == 1, from_unicode_table is a 256-element
|
|
62 array of shorts (octet 1 in high byte, octet 2 in low byte; we don't
|
|
63 store Ichars directly to save space).
|
|
64
|
|
65 -- If from_unicode_levels == 2, from_unicode_table is a 256-element
|
|
66 array of short * pointers, each of which points to a 256-element array
|
|
67 of shorts.
|
|
68
|
|
69 -- If from_unicode_levels == 3, from_unicode_table is a 256-element
|
|
70 array of short ** pointers, each of which points to a 256-element array
|
|
71 of short * pointers, each of which points to a 256-element array of
|
|
72 shorts.
|
|
73
|
|
74 -- If from_unicode_levels == 4, same thing but one level deeper.
|
|
75
|
|
76 Just as for to_unicode_table, we use default tables to fill in all
|
|
77 entries with no values in them.
|
|
78
|
|
79 #### An obvious space-saving optimization is to use variable-sized
|
|
80 tables, where each table instead of just being a 256-element array, is a
|
|
81 structure with a start value, an end value, and a variable number of
|
|
82 entries (END - START + 1). Only 8 bits are needed for END and START,
|
|
83 and could be stored at the end to avoid alignment problems. However,
|
|
84 before charging off and implementing this, we need to consider whether
|
|
85 it's worth it:
|
|
86
|
|
87 (1) Most tables will be highly localized in which code points are
|
|
88 defined, heavily reducing the possible memory waste. Before doing any
|
|
89 rewriting, write some code to see how much memory is actually being
|
|
90 wasted (i.e. ratio of empty entries to total # of entries) and only
|
|
91 start rewriting if it's unacceptably high. You have to check over all
|
|
92 charsets.
|
|
93
|
|
94 (2) Since entries are usually added one at a time, you have to be very
|
|
95 careful when creating the tables to avoid realloc()/free() thrashing in
|
|
96 the common case when you are in an area of high localization and are
|
|
97 going to end up using most entries in the table. You'd certainly want
|
|
98 to allow only certain sizes, not arbitrary ones (probably powers of 2,
|
|
99 where you want the entire block including the START/END values to fit
|
|
100 into a power of 2, minus any malloc overhead if there is any -- there's
|
|
101 none under gmalloc.c, and probably most system malloc() functions are
|
|
102 quite smart nowadays and also have no overhead). You could optimize
|
|
103 somewhat during the in-C initializations, because you can compute the
|
|
104 actual usage of various tables by scanning the entries you're going to
|
|
105 add in a separate pass before adding them. (You could actually do the
|
|
106 same thing when entries are added on the Lisp level by making the
|
|
107 assumption that all the entries will come in one after another before
|
|
108 any use is made of the data. So as they're coming in, you just store
|
|
109 them in a big long list, and the first time you need to retrieve an
|
|
110 entry, you compute the whole table at once.) You'd still have to deal
|
|
111 with the possibility of later entries coming in, though.
|
|
112
|
|
113 (3) You do lose some speed using START/END values, since you need a
|
|
114 couple of comparisons at each level. This could easily make each single
|
|
115 lookup become 3-4 times slower. The Unicode book considers this a big
|
|
116 issue, and recommends against variable-sized tables for this reason;
|
|
117 however, they almost certainly have in mind applications that primarily
|
|
118 involve conversion of large amounts of data. Most Unicode strings that
|
|
119 are translated in XEmacs are fairly small. The only place where this
|
|
120 might matter is in loading large files -- e.g. a 3-megabyte
|
|
121 Unicode-encoded file. So think about this, and maybe do a trial
|
|
122 implementation where you don't worry too much about the intricacies of
|
|
123 (2) and just implement some basic "multiply by 1.5" trick or something
|
|
124 to do the resizing. There is a very good FAQ on Unicode called
|
|
125 something like the Linux-Unicode How-To (it should be part of the Linux
|
|
126 How-To's, I think), that lists the url of a guy with a whole bunch of
|
|
127 unicode files you can use to stress-test your implementations, and he's
|
|
128 highly likely to have a good multi-megabyte Unicode-encoded file (with
|
|
129 normal text in it -- if you created your own just by creating repeated
|
|
130 strings of letters and numbers, you probably wouldn't get accurate
|
|
131 results).
|
|
132
|
|
133 INITIALIZATION:
|
|
134 ---------------
|
|
135
|
|
136 There are advantages and disadvantages to loading the tables at
|
|
137 run-time.
|
|
138
|
|
139 Advantages:
|
|
140
|
|
141 They're big, and it's very fast to recreate them (a fraction of a second
|
|
142 on modern processors).
|
|
143
|
|
144 Disadvantages:
|
|
145
|
|
146 (1) User-defined charsets: It would be inconvenient to require all
|
|
147 dumped user-defined charsets to be reloaded at init time.
|
|
148
|
|
149 (2) Starting up in a non-ISO-8859-1 directory. If we load at run-time,
|
|
150 we don't load the tables until after we've parsed the current
|
|
151 directories, and we run into a real bootstrapping problem, if the
|
|
152 directories themselves are non-ISO-8859-1. This is potentially fixable
|
|
153 once we switch to using Unicode internally, so we don't have to do any
|
|
154 conversion (other than the automatic kind, e.g. UTF-16 to UTF-8).
|
|
155
|
|
156 NB With run-time loading, we load in init-mule-at-startup, in
|
|
157 mule-cmds.el. This is called from startup.el, which is quite late in
|
|
158 the initialization process -- but data-directory isn't set until then.
|
|
159 With dump-time loading, you still can't dump in a Japanese directory
|
|
160 (again, until we move to Unicode internally), but this is not such an
|
|
161 imposition.
|
|
162
|
|
163
|
|
164 */
|
|
165
|
771
|
166 /* #### WARNING! The current sledgehammer routines have a fundamental
|
|
167 problem in that they can't handle two characters mapping to a
|
|
168 single Unicode codepoint or vice-versa in a single charset table.
|
|
169 It's not clear there is any way to handle this and still make the
|
877
|
170 sledgehammer routines useful.
|
|
171
|
|
172 Inquiring Minds Want To Know Dept: does the above WARNING mean that
|
|
173 _if_ it happens, then it will signal error, or then it will do
|
|
174 something evil and unpredictable? Signaling an error is OK: for
|
|
175 all national standards, the national to Unicode map is an inclusion
|
|
176 (1-to-1). Any character set that does not behave that way is
|
1318
|
177 broken according to the Unicode standard.
|
|
178
|
2500
|
179 Answer: You will get an ABORT(), since the purpose of the sledgehammer
|
1318
|
180 routines is self-checking. The above problem with non-1-to-1 mapping
|
|
181 occurs in the Big5 tables, as provided by the Unicode Consortium. */
|
877
|
182
|
771
|
183 /* #define SLEDGEHAMMER_CHECK_UNICODE */
|
|
184
|
|
185 /* When MULE is not defined, we may still need some Unicode support --
|
|
186 in particular, some Windows API's always want Unicode, and the way
|
|
187 we've set up the Unicode encapsulation, we may as well go ahead and
|
|
188 always use the Unicode versions of split API's. (It would be
|
|
189 trickier to not use them, and pointless -- under NT, the ANSI API's
|
|
190 call the Unicode ones anyway, so in the case of structures, we'd be
|
|
191 converting from Unicode to ANSI structures, only to have the OS
|
|
192 convert them back.) */
|
|
193
|
|
194 Lisp_Object Qunicode;
|
|
195 Lisp_Object Qutf_16, Qutf_8, Qucs_4, Qutf_7;
|
|
196 Lisp_Object Qneed_bom;
|
|
197
|
|
198 Lisp_Object Qutf_16_little_endian, Qutf_16_bom;
|
|
199 Lisp_Object Qutf_16_little_endian_bom;
|
|
200
|
985
|
201 Lisp_Object Qutf_8_bom;
|
|
202
|
771
|
203 #ifdef MULE
|
|
204
|
3352
|
205 /* Using ints for to_unicode is OK (as long as they are >= 32 bits).
|
|
206 In from_unicode, we're converting from Mule characters, which means
|
|
207 that the values being converted to are only 96x96, and we can save
|
|
208 space by using shorts (signedness doesn't matter). */
|
771
|
209 static int *to_unicode_blank_1;
|
|
210 static int **to_unicode_blank_2;
|
|
211
|
|
212 static short *from_unicode_blank_1;
|
|
213 static short **from_unicode_blank_2;
|
|
214 static short ***from_unicode_blank_3;
|
|
215 static short ****from_unicode_blank_4;
|
|
216
|
1204
|
217 static const struct memory_description to_unicode_level_0_desc_1[] = {
|
771
|
218 { XD_END }
|
|
219 };
|
|
220
|
1204
|
221 static const struct sized_memory_description to_unicode_level_0_desc = {
|
|
222 sizeof (int), to_unicode_level_0_desc_1
|
771
|
223 };
|
|
224
|
1204
|
225 static const struct memory_description to_unicode_level_1_desc_1[] = {
|
2551
|
226 { XD_BLOCK_PTR, 0, 96, { &to_unicode_level_0_desc } },
|
771
|
227 { XD_END }
|
|
228 };
|
|
229
|
1204
|
230 static const struct sized_memory_description to_unicode_level_1_desc = {
|
|
231 sizeof (void *), to_unicode_level_1_desc_1
|
771
|
232 };
|
|
233
|
1204
|
234 static const struct memory_description to_unicode_description_1[] = {
|
2551
|
235 { XD_BLOCK_PTR, 1, 96, { &to_unicode_level_0_desc } },
|
|
236 { XD_BLOCK_PTR, 2, 96, { &to_unicode_level_1_desc } },
|
771
|
237 { XD_END }
|
|
238 };
|
|
239
|
|
240 /* Not static because each charset has a set of to and from tables and
|
|
241 needs to describe them to pdump. */
|
1204
|
242 const struct sized_memory_description to_unicode_description = {
|
|
243 sizeof (void *), to_unicode_description_1
|
|
244 };
|
|
245
|
2367
|
246 /* Used only for to_unicode_blank_2 */
|
|
247 static const struct memory_description to_unicode_level_2_desc_1[] = {
|
2551
|
248 { XD_BLOCK_PTR, 0, 96, { &to_unicode_level_1_desc } },
|
2367
|
249 { XD_END }
|
|
250 };
|
|
251
|
1204
|
252 static const struct memory_description from_unicode_level_0_desc_1[] = {
|
771
|
253 { XD_END }
|
|
254 };
|
|
255
|
1204
|
256 static const struct sized_memory_description from_unicode_level_0_desc = {
|
|
257 sizeof (short), from_unicode_level_0_desc_1
|
771
|
258 };
|
|
259
|
1204
|
260 static const struct memory_description from_unicode_level_1_desc_1[] = {
|
2551
|
261 { XD_BLOCK_PTR, 0, 256, { &from_unicode_level_0_desc } },
|
771
|
262 { XD_END }
|
|
263 };
|
|
264
|
1204
|
265 static const struct sized_memory_description from_unicode_level_1_desc = {
|
|
266 sizeof (void *), from_unicode_level_1_desc_1
|
771
|
267 };
|
|
268
|
1204
|
269 static const struct memory_description from_unicode_level_2_desc_1[] = {
|
2551
|
270 { XD_BLOCK_PTR, 0, 256, { &from_unicode_level_1_desc } },
|
771
|
271 { XD_END }
|
|
272 };
|
|
273
|
1204
|
274 static const struct sized_memory_description from_unicode_level_2_desc = {
|
|
275 sizeof (void *), from_unicode_level_2_desc_1
|
771
|
276 };
|
|
277
|
1204
|
278 static const struct memory_description from_unicode_level_3_desc_1[] = {
|
2551
|
279 { XD_BLOCK_PTR, 0, 256, { &from_unicode_level_2_desc } },
|
771
|
280 { XD_END }
|
|
281 };
|
|
282
|
1204
|
283 static const struct sized_memory_description from_unicode_level_3_desc = {
|
|
284 sizeof (void *), from_unicode_level_3_desc_1
|
771
|
285 };
|
|
286
|
1204
|
287 static const struct memory_description from_unicode_description_1[] = {
|
2551
|
288 { XD_BLOCK_PTR, 1, 256, { &from_unicode_level_0_desc } },
|
|
289 { XD_BLOCK_PTR, 2, 256, { &from_unicode_level_1_desc } },
|
|
290 { XD_BLOCK_PTR, 3, 256, { &from_unicode_level_2_desc } },
|
|
291 { XD_BLOCK_PTR, 4, 256, { &from_unicode_level_3_desc } },
|
771
|
292 { XD_END }
|
|
293 };
|
|
294
|
|
295 /* Not static because each charset has a set of to and from tables and
|
|
296 needs to describe them to pdump. */
|
1204
|
297 const struct sized_memory_description from_unicode_description = {
|
|
298 sizeof (void *), from_unicode_description_1
|
771
|
299 };
|
|
300
|
2367
|
301 /* Used only for from_unicode_blank_4 */
|
|
302 static const struct memory_description from_unicode_level_4_desc_1[] = {
|
2551
|
303 { XD_BLOCK_PTR, 0, 256, { &from_unicode_level_3_desc } },
|
2367
|
304 { XD_END }
|
|
305 };
|
|
306
|
771
|
307 static Lisp_Object_dynarr *unicode_precedence_dynarr;
|
|
308
|
1204
|
309 static const struct memory_description lod_description_1[] = {
|
|
310 XD_DYNARR_DESC (Lisp_Object_dynarr, &lisp_object_description),
|
771
|
311 { XD_END }
|
|
312 };
|
|
313
|
1204
|
314 static const struct sized_memory_description lisp_object_dynarr_description = {
|
771
|
315 sizeof (Lisp_Object_dynarr),
|
|
316 lod_description_1
|
|
317 };
|
|
318
|
|
319 Lisp_Object Vlanguage_unicode_precedence_list;
|
|
320 Lisp_Object Vdefault_unicode_precedence_list;
|
|
321
|
|
322 Lisp_Object Qignore_first_column;
|
|
323
|
3439
|
324 Lisp_Object Vcurrent_jit_charset;
|
|
325 Lisp_Object Qlast_allocated_character;
|
|
326 Lisp_Object Qccl_encode_to_ucs_2;
|
|
327
|
771
|
328
|
|
329 /************************************************************************/
|
|
330 /* Unicode implementation */
|
|
331 /************************************************************************/
|
|
332
|
|
333 #define BREAKUP_UNICODE_CODE(val, u1, u2, u3, u4, levels) \
|
|
334 do { \
|
|
335 int buc_val = (val); \
|
|
336 \
|
|
337 (u1) = buc_val >> 24; \
|
|
338 (u2) = (buc_val >> 16) & 255; \
|
|
339 (u3) = (buc_val >> 8) & 255; \
|
|
340 (u4) = buc_val & 255; \
|
|
341 (levels) = (buc_val <= 0xFF ? 1 : \
|
|
342 buc_val <= 0xFFFF ? 2 : \
|
|
343 buc_val <= 0xFFFFFF ? 3 : \
|
|
344 4); \
|
|
345 } while (0)
|
|
346
|
|
347 static void
|
|
348 init_blank_unicode_tables (void)
|
|
349 {
|
|
350 int i;
|
|
351
|
|
352 from_unicode_blank_1 = xnew_array (short, 256);
|
|
353 from_unicode_blank_2 = xnew_array (short *, 256);
|
|
354 from_unicode_blank_3 = xnew_array (short **, 256);
|
|
355 from_unicode_blank_4 = xnew_array (short ***, 256);
|
|
356 for (i = 0; i < 256; i++)
|
|
357 {
|
877
|
358 /* #### IMWTK: Why does using -1 here work? Simply because there are
|
1318
|
359 no existing 96x96 charsets?
|
|
360
|
|
361 Answer: I don't understand the concern. -1 indicates there is no
|
|
362 entry for this particular codepoint, which is always the case for
|
|
363 blank tables. */
|
771
|
364 from_unicode_blank_1[i] = (short) -1;
|
|
365 from_unicode_blank_2[i] = from_unicode_blank_1;
|
|
366 from_unicode_blank_3[i] = from_unicode_blank_2;
|
|
367 from_unicode_blank_4[i] = from_unicode_blank_3;
|
|
368 }
|
|
369
|
|
370 to_unicode_blank_1 = xnew_array (int, 96);
|
|
371 to_unicode_blank_2 = xnew_array (int *, 96);
|
|
372 for (i = 0; i < 96; i++)
|
|
373 {
|
877
|
374 /* Here -1 is guaranteed OK. */
|
771
|
375 to_unicode_blank_1[i] = -1;
|
|
376 to_unicode_blank_2[i] = to_unicode_blank_1;
|
|
377 }
|
|
378 }
|
|
379
|
|
380 static void *
|
|
381 create_new_from_unicode_table (int level)
|
|
382 {
|
|
383 switch (level)
|
|
384 {
|
|
385 /* WARNING: If you are thinking of compressing these, keep in
|
|
386 mind that sizeof (short) does not equal sizeof (short *). */
|
|
387 case 1:
|
|
388 {
|
|
389 short *newtab = xnew_array (short, 256);
|
|
390 memcpy (newtab, from_unicode_blank_1, 256 * sizeof (short));
|
|
391 return newtab;
|
|
392 }
|
|
393 case 2:
|
|
394 {
|
|
395 short **newtab = xnew_array (short *, 256);
|
|
396 memcpy (newtab, from_unicode_blank_2, 256 * sizeof (short *));
|
|
397 return newtab;
|
|
398 }
|
|
399 case 3:
|
|
400 {
|
|
401 short ***newtab = xnew_array (short **, 256);
|
|
402 memcpy (newtab, from_unicode_blank_3, 256 * sizeof (short **));
|
|
403 return newtab;
|
|
404 }
|
|
405 case 4:
|
|
406 {
|
|
407 short ****newtab = xnew_array (short ***, 256);
|
|
408 memcpy (newtab, from_unicode_blank_4, 256 * sizeof (short ***));
|
|
409 return newtab;
|
|
410 }
|
|
411 default:
|
2500
|
412 ABORT ();
|
771
|
413 return 0;
|
|
414 }
|
|
415 }
|
|
416
|
877
|
417 /* Allocate and blank the tables.
|
1318
|
418 Loading them up is done by load-unicode-mapping-table. */
|
771
|
419 void
|
|
420 init_charset_unicode_tables (Lisp_Object charset)
|
|
421 {
|
|
422 if (XCHARSET_DIMENSION (charset) == 1)
|
|
423 {
|
|
424 int *to_table = xnew_array (int, 96);
|
|
425 memcpy (to_table, to_unicode_blank_1, 96 * sizeof (int));
|
|
426 XCHARSET_TO_UNICODE_TABLE (charset) = to_table;
|
|
427 }
|
|
428 else
|
|
429 {
|
|
430 int **to_table = xnew_array (int *, 96);
|
|
431 memcpy (to_table, to_unicode_blank_2, 96 * sizeof (int *));
|
|
432 XCHARSET_TO_UNICODE_TABLE (charset) = to_table;
|
|
433 }
|
|
434
|
|
435 {
|
2367
|
436 XCHARSET_FROM_UNICODE_TABLE (charset) =
|
|
437 create_new_from_unicode_table (1);
|
771
|
438 XCHARSET_FROM_UNICODE_LEVELS (charset) = 1;
|
|
439 }
|
|
440 }
|
|
441
|
|
442 static void
|
|
443 free_from_unicode_table (void *table, int level)
|
|
444 {
|
|
445 int i;
|
|
446
|
|
447 switch (level)
|
|
448 {
|
|
449 case 2:
|
|
450 {
|
|
451 short **tab = (short **) table;
|
|
452 for (i = 0; i < 256; i++)
|
|
453 {
|
|
454 if (tab[i] != from_unicode_blank_1)
|
|
455 free_from_unicode_table (tab[i], 1);
|
|
456 }
|
|
457 break;
|
|
458 }
|
|
459 case 3:
|
|
460 {
|
|
461 short ***tab = (short ***) table;
|
|
462 for (i = 0; i < 256; i++)
|
|
463 {
|
|
464 if (tab[i] != from_unicode_blank_2)
|
|
465 free_from_unicode_table (tab[i], 2);
|
|
466 }
|
|
467 break;
|
|
468 }
|
|
469 case 4:
|
|
470 {
|
|
471 short ****tab = (short ****) table;
|
|
472 for (i = 0; i < 256; i++)
|
|
473 {
|
|
474 if (tab[i] != from_unicode_blank_3)
|
|
475 free_from_unicode_table (tab[i], 3);
|
|
476 }
|
|
477 break;
|
|
478 }
|
|
479 }
|
|
480
|
1726
|
481 xfree (table, void *);
|
771
|
482 }
|
|
483
|
|
484 static void
|
|
485 free_to_unicode_table (void *table, int level)
|
|
486 {
|
|
487 if (level == 2)
|
|
488 {
|
|
489 int i;
|
|
490 int **tab = (int **) table;
|
|
491
|
|
492 for (i = 0; i < 96; i++)
|
|
493 {
|
|
494 if (tab[i] != to_unicode_blank_1)
|
|
495 free_to_unicode_table (tab[i], 1);
|
|
496 }
|
|
497 }
|
|
498
|
1726
|
499 xfree (table, void *);
|
771
|
500 }
|
|
501
|
|
502 void
|
|
503 free_charset_unicode_tables (Lisp_Object charset)
|
|
504 {
|
|
505 free_to_unicode_table (XCHARSET_TO_UNICODE_TABLE (charset),
|
|
506 XCHARSET_DIMENSION (charset));
|
|
507 free_from_unicode_table (XCHARSET_FROM_UNICODE_TABLE (charset),
|
|
508 XCHARSET_FROM_UNICODE_LEVELS (charset));
|
|
509 }
|
|
510
|
|
511 #ifdef MEMORY_USAGE_STATS
|
|
512
|
|
513 static Bytecount
|
|
514 compute_from_unicode_table_size_1 (void *table, int level,
|
|
515 struct overhead_stats *stats)
|
|
516 {
|
|
517 int i;
|
|
518 Bytecount size = 0;
|
|
519
|
|
520 switch (level)
|
|
521 {
|
|
522 case 2:
|
|
523 {
|
|
524 short **tab = (short **) table;
|
|
525 for (i = 0; i < 256; i++)
|
|
526 {
|
|
527 if (tab[i] != from_unicode_blank_1)
|
|
528 size += compute_from_unicode_table_size_1 (tab[i], 1, stats);
|
|
529 }
|
|
530 break;
|
|
531 }
|
|
532 case 3:
|
|
533 {
|
|
534 short ***tab = (short ***) table;
|
|
535 for (i = 0; i < 256; i++)
|
|
536 {
|
|
537 if (tab[i] != from_unicode_blank_2)
|
|
538 size += compute_from_unicode_table_size_1 (tab[i], 2, stats);
|
|
539 }
|
|
540 break;
|
|
541 }
|
|
542 case 4:
|
|
543 {
|
|
544 short ****tab = (short ****) table;
|
|
545 for (i = 0; i < 256; i++)
|
|
546 {
|
|
547 if (tab[i] != from_unicode_blank_3)
|
|
548 size += compute_from_unicode_table_size_1 (tab[i], 3, stats);
|
|
549 }
|
|
550 break;
|
|
551 }
|
|
552 }
|
|
553
|
3024
|
554 size += malloced_storage_size (table,
|
771
|
555 256 * (level == 1 ? sizeof (short) :
|
|
556 sizeof (void *)),
|
|
557 stats);
|
|
558 return size;
|
|
559 }
|
|
560
|
|
561 static Bytecount
|
|
562 compute_to_unicode_table_size_1 (void *table, int level,
|
|
563 struct overhead_stats *stats)
|
|
564 {
|
|
565 Bytecount size = 0;
|
|
566
|
|
567 if (level == 2)
|
|
568 {
|
|
569 int i;
|
|
570 int **tab = (int **) table;
|
|
571
|
|
572 for (i = 0; i < 96; i++)
|
|
573 {
|
|
574 if (tab[i] != to_unicode_blank_1)
|
|
575 size += compute_to_unicode_table_size_1 (tab[i], 1, stats);
|
|
576 }
|
|
577 }
|
|
578
|
3024
|
579 size += malloced_storage_size (table,
|
771
|
580 96 * (level == 1 ? sizeof (int) :
|
|
581 sizeof (void *)),
|
|
582 stats);
|
|
583 return size;
|
|
584 }
|
|
585
|
|
586 Bytecount
|
|
587 compute_from_unicode_table_size (Lisp_Object charset,
|
|
588 struct overhead_stats *stats)
|
|
589 {
|
|
590 return (compute_from_unicode_table_size_1
|
|
591 (XCHARSET_FROM_UNICODE_TABLE (charset),
|
|
592 XCHARSET_FROM_UNICODE_LEVELS (charset),
|
|
593 stats));
|
|
594 }
|
|
595
|
|
596 Bytecount
|
|
597 compute_to_unicode_table_size (Lisp_Object charset,
|
|
598 struct overhead_stats *stats)
|
|
599 {
|
|
600 return (compute_to_unicode_table_size_1
|
|
601 (XCHARSET_TO_UNICODE_TABLE (charset),
|
|
602 XCHARSET_DIMENSION (charset),
|
|
603 stats));
|
|
604 }
|
|
605
|
|
606 #endif
|
|
607
|
|
608 #ifdef SLEDGEHAMMER_CHECK_UNICODE
|
|
609
|
|
610 /* "Sledgehammer checks" are checks that verify the self-consistency
|
|
611 of an entire structure every time a change is about to be made or
|
|
612 has been made to the structure. Not fast but a pretty much
|
|
613 sure-fire way of flushing out any incorrectnesses in the algorithms
|
|
614 that create the structure.
|
|
615
|
|
616 Checking only after a change has been made will speed things up by
|
|
617 a factor of 2, but it doesn't absolutely prove that the code just
|
|
618 checked caused the problem; perhaps it happened elsewhere, either
|
|
619 in some code you forgot to sledgehammer check or as a result of
|
|
620 data corruption. */
|
|
621
|
|
622 static void
|
|
623 assert_not_any_blank_table (void *tab)
|
|
624 {
|
|
625 assert (tab != from_unicode_blank_1);
|
|
626 assert (tab != from_unicode_blank_2);
|
|
627 assert (tab != from_unicode_blank_3);
|
|
628 assert (tab != from_unicode_blank_4);
|
|
629 assert (tab != to_unicode_blank_1);
|
|
630 assert (tab != to_unicode_blank_2);
|
|
631 assert (tab);
|
|
632 }
|
|
633
|
|
634 static void
|
|
635 sledgehammer_check_from_table (Lisp_Object charset, void *table, int level,
|
|
636 int codetop)
|
|
637 {
|
|
638 int i;
|
|
639
|
|
640 switch (level)
|
|
641 {
|
|
642 case 1:
|
|
643 {
|
|
644 short *tab = (short *) table;
|
|
645 for (i = 0; i < 256; i++)
|
|
646 {
|
|
647 if (tab[i] != -1)
|
|
648 {
|
|
649 Lisp_Object char_charset;
|
|
650 int c1, c2;
|
|
651
|
867
|
652 assert (valid_ichar_p (tab[i]));
|
|
653 BREAKUP_ICHAR (tab[i], char_charset, c1, c2);
|
771
|
654 assert (EQ (charset, char_charset));
|
|
655 if (XCHARSET_DIMENSION (charset) == 1)
|
|
656 {
|
|
657 int *to_table =
|
|
658 (int *) XCHARSET_TO_UNICODE_TABLE (charset);
|
|
659 assert_not_any_blank_table (to_table);
|
|
660 assert (to_table[c1 - 32] == (codetop << 8) + i);
|
|
661 }
|
|
662 else
|
|
663 {
|
|
664 int **to_table =
|
|
665 (int **) XCHARSET_TO_UNICODE_TABLE (charset);
|
|
666 assert_not_any_blank_table (to_table);
|
|
667 assert_not_any_blank_table (to_table[c1 - 32]);
|
|
668 assert (to_table[c1 - 32][c2 - 32] == (codetop << 8) + i);
|
|
669 }
|
|
670 }
|
|
671 }
|
|
672 break;
|
|
673 }
|
|
674 case 2:
|
|
675 {
|
|
676 short **tab = (short **) table;
|
|
677 for (i = 0; i < 256; i++)
|
|
678 {
|
|
679 if (tab[i] != from_unicode_blank_1)
|
|
680 sledgehammer_check_from_table (charset, tab[i], 1,
|
|
681 (codetop << 8) + i);
|
|
682 }
|
|
683 break;
|
|
684 }
|
|
685 case 3:
|
|
686 {
|
|
687 short ***tab = (short ***) table;
|
|
688 for (i = 0; i < 256; i++)
|
|
689 {
|
|
690 if (tab[i] != from_unicode_blank_2)
|
|
691 sledgehammer_check_from_table (charset, tab[i], 2,
|
|
692 (codetop << 8) + i);
|
|
693 }
|
|
694 break;
|
|
695 }
|
|
696 case 4:
|
|
697 {
|
|
698 short ****tab = (short ****) table;
|
|
699 for (i = 0; i < 256; i++)
|
|
700 {
|
|
701 if (tab[i] != from_unicode_blank_3)
|
|
702 sledgehammer_check_from_table (charset, tab[i], 3,
|
|
703 (codetop << 8) + i);
|
|
704 }
|
|
705 break;
|
|
706 }
|
|
707 default:
|
2500
|
708 ABORT ();
|
771
|
709 }
|
|
710 }
|
|
711
|
|
712 static void
|
|
713 sledgehammer_check_to_table (Lisp_Object charset, void *table, int level,
|
|
714 int codetop)
|
|
715 {
|
|
716 int i;
|
|
717
|
|
718 switch (level)
|
|
719 {
|
|
720 case 1:
|
|
721 {
|
|
722 int *tab = (int *) table;
|
|
723
|
|
724 if (XCHARSET_CHARS (charset) == 94)
|
|
725 {
|
|
726 assert (tab[0] == -1);
|
|
727 assert (tab[95] == -1);
|
|
728 }
|
|
729
|
|
730 for (i = 0; i < 96; i++)
|
|
731 {
|
|
732 if (tab[i] != -1)
|
|
733 {
|
|
734 int u4, u3, u2, u1, levels;
|
867
|
735 Ichar ch;
|
|
736 Ichar this_ch;
|
771
|
737 short val;
|
|
738 void *frtab = XCHARSET_FROM_UNICODE_TABLE (charset);
|
|
739
|
|
740 if (XCHARSET_DIMENSION (charset) == 1)
|
867
|
741 this_ch = make_ichar (charset, i + 32, 0);
|
771
|
742 else
|
867
|
743 this_ch = make_ichar (charset, codetop + 32, i + 32);
|
771
|
744
|
|
745 assert (tab[i] >= 0);
|
|
746 BREAKUP_UNICODE_CODE (tab[i], u4, u3, u2, u1, levels);
|
|
747 assert (levels <= XCHARSET_FROM_UNICODE_LEVELS (charset));
|
|
748
|
|
749 switch (XCHARSET_FROM_UNICODE_LEVELS (charset))
|
|
750 {
|
|
751 case 1: val = ((short *) frtab)[u1]; break;
|
|
752 case 2: val = ((short **) frtab)[u2][u1]; break;
|
|
753 case 3: val = ((short ***) frtab)[u3][u2][u1]; break;
|
|
754 case 4: val = ((short ****) frtab)[u4][u3][u2][u1]; break;
|
2500
|
755 default: ABORT ();
|
771
|
756 }
|
|
757
|
867
|
758 ch = make_ichar (charset, val >> 8, val & 0xFF);
|
771
|
759 assert (ch == this_ch);
|
|
760
|
|
761 switch (XCHARSET_FROM_UNICODE_LEVELS (charset))
|
|
762 {
|
|
763 case 4:
|
|
764 assert_not_any_blank_table (frtab);
|
|
765 frtab = ((short ****) frtab)[u4];
|
|
766 /* fall through */
|
|
767 case 3:
|
|
768 assert_not_any_blank_table (frtab);
|
|
769 frtab = ((short ***) frtab)[u3];
|
|
770 /* fall through */
|
|
771 case 2:
|
|
772 assert_not_any_blank_table (frtab);
|
|
773 frtab = ((short **) frtab)[u2];
|
|
774 /* fall through */
|
|
775 case 1:
|
|
776 assert_not_any_blank_table (frtab);
|
|
777 break;
|
2500
|
778 default: ABORT ();
|
771
|
779 }
|
|
780 }
|
|
781 }
|
|
782 break;
|
|
783 }
|
|
784 case 2:
|
|
785 {
|
|
786 int **tab = (int **) table;
|
|
787
|
|
788 if (XCHARSET_CHARS (charset) == 94)
|
|
789 {
|
|
790 assert (tab[0] == to_unicode_blank_1);
|
|
791 assert (tab[95] == to_unicode_blank_1);
|
|
792 }
|
|
793
|
|
794 for (i = 0; i < 96; i++)
|
|
795 {
|
|
796 if (tab[i] != to_unicode_blank_1)
|
|
797 sledgehammer_check_to_table (charset, tab[i], 1, i);
|
|
798 }
|
|
799 break;
|
|
800 }
|
|
801 default:
|
2500
|
802 ABORT ();
|
771
|
803 }
|
|
804 }
|
|
805
|
|
806 static void
|
|
807 sledgehammer_check_unicode_tables (Lisp_Object charset)
|
|
808 {
|
|
809 /* verify that the blank tables have not been modified */
|
|
810 int i;
|
|
811 int from_level = XCHARSET_FROM_UNICODE_LEVELS (charset);
|
|
812 int to_level = XCHARSET_FROM_UNICODE_LEVELS (charset);
|
|
813
|
|
814 for (i = 0; i < 256; i++)
|
|
815 {
|
|
816 assert (from_unicode_blank_1[i] == (short) -1);
|
|
817 assert (from_unicode_blank_2[i] == from_unicode_blank_1);
|
|
818 assert (from_unicode_blank_3[i] == from_unicode_blank_2);
|
|
819 assert (from_unicode_blank_4[i] == from_unicode_blank_3);
|
|
820 }
|
|
821
|
|
822 for (i = 0; i < 96; i++)
|
|
823 {
|
|
824 assert (to_unicode_blank_1[i] == -1);
|
|
825 assert (to_unicode_blank_2[i] == to_unicode_blank_1);
|
|
826 }
|
|
827
|
|
828 assert (from_level >= 1 && from_level <= 4);
|
|
829
|
|
830 sledgehammer_check_from_table (charset,
|
|
831 XCHARSET_FROM_UNICODE_TABLE (charset),
|
|
832 from_level, 0);
|
|
833
|
|
834 sledgehammer_check_to_table (charset,
|
|
835 XCHARSET_TO_UNICODE_TABLE (charset),
|
|
836 XCHARSET_DIMENSION (charset), 0);
|
|
837 }
|
|
838
|
|
839 #endif /* SLEDGEHAMMER_CHECK_UNICODE */
|
|
840
|
|
841 static void
|
867
|
842 set_unicode_conversion (Ichar chr, int code)
|
771
|
843 {
|
|
844 Lisp_Object charset;
|
|
845 int c1, c2;
|
|
846
|
867
|
847 BREAKUP_ICHAR (chr, charset, c1, c2);
|
771
|
848
|
877
|
849 /* I tried an assert on code > 255 || chr == code, but that fails because
|
|
850 Mule gives many Latin characters separate code points for different
|
|
851 ISO 8859 coded character sets. Obvious in hindsight.... */
|
|
852 assert (!EQ (charset, Vcharset_ascii) || chr == code);
|
|
853 assert (!EQ (charset, Vcharset_latin_iso8859_1) || chr == code);
|
|
854 assert (!EQ (charset, Vcharset_control_1) || chr == code);
|
|
855
|
|
856 /* This assert is needed because it is simply unimplemented. */
|
771
|
857 assert (!EQ (charset, Vcharset_composite));
|
|
858
|
|
859 #ifdef SLEDGEHAMMER_CHECK_UNICODE
|
|
860 sledgehammer_check_unicode_tables (charset);
|
|
861 #endif
|
|
862
|
2704
|
863 if (EQ(charset, Vcharset_ascii) || EQ(charset, Vcharset_control_1))
|
|
864 return;
|
|
865
|
771
|
866 /* First, the char -> unicode translation */
|
|
867
|
|
868 if (XCHARSET_DIMENSION (charset) == 1)
|
|
869 {
|
|
870 int *to_table = (int *) XCHARSET_TO_UNICODE_TABLE (charset);
|
|
871 to_table[c1 - 32] = code;
|
|
872 }
|
|
873 else
|
|
874 {
|
|
875 int **to_table_2 = (int **) XCHARSET_TO_UNICODE_TABLE (charset);
|
|
876 int *to_table_1;
|
|
877
|
|
878 assert (XCHARSET_DIMENSION (charset) == 2);
|
|
879 to_table_1 = to_table_2[c1 - 32];
|
|
880 if (to_table_1 == to_unicode_blank_1)
|
|
881 {
|
|
882 to_table_1 = xnew_array (int, 96);
|
|
883 memcpy (to_table_1, to_unicode_blank_1, 96 * sizeof (int));
|
|
884 to_table_2[c1 - 32] = to_table_1;
|
|
885 }
|
|
886 to_table_1[c2 - 32] = code;
|
|
887 }
|
|
888
|
|
889 /* Then, unicode -> char: much harder */
|
|
890
|
|
891 {
|
|
892 int charset_levels;
|
|
893 int u4, u3, u2, u1;
|
|
894 int code_levels;
|
|
895 BREAKUP_UNICODE_CODE (code, u4, u3, u2, u1, code_levels);
|
|
896
|
|
897 charset_levels = XCHARSET_FROM_UNICODE_LEVELS (charset);
|
|
898
|
|
899 /* Make sure the charset's tables have at least as many levels as
|
|
900 the code point has: Note that the charset is guaranteed to have
|
|
901 at least one level, because it was created that way */
|
|
902 if (charset_levels < code_levels)
|
|
903 {
|
|
904 int i;
|
|
905
|
|
906 assert (charset_levels > 0);
|
|
907 for (i = 2; i <= code_levels; i++)
|
|
908 {
|
|
909 if (charset_levels < i)
|
|
910 {
|
|
911 void *old_table = XCHARSET_FROM_UNICODE_TABLE (charset);
|
|
912 void *table = create_new_from_unicode_table (i);
|
|
913 XCHARSET_FROM_UNICODE_TABLE (charset) = table;
|
|
914
|
|
915 switch (i)
|
|
916 {
|
|
917 case 2:
|
|
918 ((short **) table)[0] = (short *) old_table;
|
|
919 break;
|
|
920 case 3:
|
|
921 ((short ***) table)[0] = (short **) old_table;
|
|
922 break;
|
|
923 case 4:
|
|
924 ((short ****) table)[0] = (short ***) old_table;
|
|
925 break;
|
2500
|
926 default: ABORT ();
|
771
|
927 }
|
|
928 }
|
|
929 }
|
|
930
|
|
931 charset_levels = code_levels;
|
|
932 XCHARSET_FROM_UNICODE_LEVELS (charset) = code_levels;
|
|
933 }
|
|
934
|
|
935 /* Now, make sure there is a non-default table at each level */
|
|
936 {
|
|
937 int i;
|
|
938 void *table = XCHARSET_FROM_UNICODE_TABLE (charset);
|
|
939
|
|
940 for (i = charset_levels; i >= 2; i--)
|
|
941 {
|
|
942 switch (i)
|
|
943 {
|
|
944 case 4:
|
|
945 if (((short ****) table)[u4] == from_unicode_blank_3)
|
|
946 ((short ****) table)[u4] =
|
|
947 ((short ***) create_new_from_unicode_table (3));
|
|
948 table = ((short ****) table)[u4];
|
|
949 break;
|
|
950 case 3:
|
|
951 if (((short ***) table)[u3] == from_unicode_blank_2)
|
|
952 ((short ***) table)[u3] =
|
|
953 ((short **) create_new_from_unicode_table (2));
|
|
954 table = ((short ***) table)[u3];
|
|
955 break;
|
|
956 case 2:
|
|
957 if (((short **) table)[u2] == from_unicode_blank_1)
|
|
958 ((short **) table)[u2] =
|
|
959 ((short *) create_new_from_unicode_table (1));
|
|
960 table = ((short **) table)[u2];
|
|
961 break;
|
2500
|
962 default: ABORT ();
|
771
|
963 }
|
|
964 }
|
|
965 }
|
|
966
|
|
967 /* Finally, set the character */
|
|
968
|
|
969 {
|
|
970 void *table = XCHARSET_FROM_UNICODE_TABLE (charset);
|
|
971 switch (charset_levels)
|
|
972 {
|
|
973 case 1: ((short *) table)[u1] = (c1 << 8) + c2; break;
|
|
974 case 2: ((short **) table)[u2][u1] = (c1 << 8) + c2; break;
|
|
975 case 3: ((short ***) table)[u3][u2][u1] = (c1 << 8) + c2; break;
|
|
976 case 4: ((short ****) table)[u4][u3][u2][u1] = (c1 << 8) + c2; break;
|
2500
|
977 default: ABORT ();
|
771
|
978 }
|
|
979 }
|
|
980 }
|
|
981
|
|
982 #ifdef SLEDGEHAMMER_CHECK_UNICODE
|
|
983 sledgehammer_check_unicode_tables (charset);
|
|
984 #endif
|
|
985 }
|
|
986
|
788
|
987 int
|
867
|
988 ichar_to_unicode (Ichar chr)
|
771
|
989 {
|
|
990 Lisp_Object charset;
|
|
991 int c1, c2;
|
|
992
|
867
|
993 type_checking_assert (valid_ichar_p (chr));
|
877
|
994 /* This shortcut depends on the representation of an Ichar, see text.c. */
|
771
|
995 if (chr < 256)
|
|
996 return (int) chr;
|
|
997
|
867
|
998 BREAKUP_ICHAR (chr, charset, c1, c2);
|
771
|
999 if (EQ (charset, Vcharset_composite))
|
|
1000 return -1; /* #### don't know how to handle */
|
|
1001 else if (XCHARSET_DIMENSION (charset) == 1)
|
|
1002 return ((int *) XCHARSET_TO_UNICODE_TABLE (charset))[c1 - 32];
|
|
1003 else
|
|
1004 return ((int **) XCHARSET_TO_UNICODE_TABLE (charset))[c1 - 32][c2 - 32];
|
|
1005 }
|
|
1006
|
867
|
1007 static Ichar
|
3439
|
1008 get_free_codepoint(Lisp_Object charset)
|
|
1009 {
|
|
1010 Lisp_Object name = Fcharset_name(charset);
|
|
1011 Lisp_Object zeichen = Fget(name, Qlast_allocated_character, Qnil);
|
|
1012 Ichar res;
|
|
1013
|
|
1014 /* Only allow this with the 96x96 character sets we are using for
|
|
1015 temporary Unicode support. */
|
|
1016 assert(2 == XCHARSET_DIMENSION(charset) && 96 == XCHARSET_CHARS(charset));
|
|
1017
|
|
1018 if (!NILP(zeichen))
|
|
1019 {
|
|
1020 int c1, c2;
|
|
1021
|
|
1022 BREAKUP_ICHAR(XCHAR(zeichen), charset, c1, c2);
|
|
1023
|
|
1024 if (127 == c1 && 127 == c2)
|
|
1025 {
|
|
1026 /* We've already used the hightest-numbered character in this
|
|
1027 set--tell our caller to create another. */
|
|
1028 return -1;
|
|
1029 }
|
|
1030
|
|
1031 if (127 == c2)
|
|
1032 {
|
|
1033 ++c1;
|
|
1034 c2 = 0x20;
|
|
1035 }
|
|
1036 else
|
|
1037 {
|
|
1038 ++c2;
|
|
1039 }
|
|
1040
|
|
1041 res = make_ichar(charset, c1, c2);
|
|
1042 Fput(name, Qlast_allocated_character, make_char(res));
|
|
1043 }
|
|
1044 else
|
|
1045 {
|
|
1046 res = make_ichar(charset, 32, 32);
|
|
1047 Fput(name, Qlast_allocated_character, make_char(res));
|
|
1048 }
|
|
1049 return res;
|
|
1050 }
|
|
1051
|
|
1052 /* The just-in-time creation of XEmacs characters that correspond to unknown
|
|
1053 Unicode code points happens when:
|
|
1054
|
|
1055 1. The lookup would otherwise fail.
|
|
1056
|
|
1057 2. The charsets array is the nil or the default.
|
|
1058
|
|
1059 If there are no free code points in the just-in-time Unicode character
|
|
1060 set, and the charsets array is the default unicode precedence list,
|
|
1061 create a new just-in-time Unicode character set, add it at the end of the
|
|
1062 unicode precedence list, create the XEmacs character in that character
|
|
1063 set, and return it. */
|
|
1064
|
|
1065 static Ichar
|
877
|
1066 unicode_to_ichar (int code, Lisp_Object_dynarr *charsets)
|
771
|
1067 {
|
|
1068 int u1, u2, u3, u4;
|
|
1069 int code_levels;
|
|
1070 int i;
|
|
1071 int n = Dynarr_length (charsets);
|
3439
|
1072 static int number_of_jit_charsets;
|
|
1073 static Ascbyte last_jit_charset_final;
|
771
|
1074
|
|
1075 type_checking_assert (code >= 0);
|
877
|
1076 /* This shortcut depends on the representation of an Ichar, see text.c.
|
|
1077 Note that it may _not_ be extended to U+00A0 to U+00FF (many ISO 8859
|
893
|
1078 coded character sets have points that map into that region, so this
|
|
1079 function is many-valued). */
|
877
|
1080 if (code < 0xA0)
|
867
|
1081 return (Ichar) code;
|
771
|
1082
|
|
1083 BREAKUP_UNICODE_CODE (code, u4, u3, u2, u1, code_levels);
|
|
1084
|
|
1085 for (i = 0; i < n; i++)
|
|
1086 {
|
|
1087 Lisp_Object charset = Dynarr_at (charsets, i);
|
|
1088 int charset_levels = XCHARSET_FROM_UNICODE_LEVELS (charset);
|
|
1089 if (charset_levels >= code_levels)
|
|
1090 {
|
|
1091 void *table = XCHARSET_FROM_UNICODE_TABLE (charset);
|
|
1092 short retval;
|
|
1093
|
|
1094 switch (charset_levels)
|
|
1095 {
|
|
1096 case 1: retval = ((short *) table)[u1]; break;
|
|
1097 case 2: retval = ((short **) table)[u2][u1]; break;
|
|
1098 case 3: retval = ((short ***) table)[u3][u2][u1]; break;
|
|
1099 case 4: retval = ((short ****) table)[u4][u3][u2][u1]; break;
|
2500
|
1100 default: ABORT (); retval = 0;
|
771
|
1101 }
|
|
1102
|
|
1103 if (retval != -1)
|
867
|
1104 return make_ichar (charset, retval >> 8, retval & 0xFF);
|
771
|
1105 }
|
|
1106 }
|
3439
|
1107
|
|
1108 /* Only do the magic just-in-time assignment if we're using the default
|
|
1109 list. */
|
|
1110 if (unicode_precedence_dynarr == charsets)
|
|
1111 {
|
|
1112 if (NILP (Vcurrent_jit_charset) ||
|
|
1113 (-1 == (i = get_free_codepoint(Vcurrent_jit_charset))))
|
|
1114 {
|
3452
|
1115 Ibyte setname[32];
|
3439
|
1116 Lisp_Object charset_descr = build_string
|
|
1117 ("Mule charset for otherwise unknown Unicode code points.");
|
771
|
1118
|
3659
|
1119 struct gcpro gcpro1;
|
3439
|
1120
|
|
1121 if ('\0' == last_jit_charset_final)
|
|
1122 {
|
|
1123 /* This final byte shit is, umm, not that cool. */
|
|
1124 last_jit_charset_final = 0x30;
|
|
1125 }
|
|
1126
|
3452
|
1127 /* Assertion added partly because our Win32 layer doesn't
|
|
1128 support snprintf; with this, we're sure it won't overflow
|
|
1129 the buffer. */
|
|
1130 assert(100 > number_of_jit_charsets);
|
|
1131
|
|
1132 qxesprintf(setname, "jit-ucs-charset-%d", number_of_jit_charsets++);
|
3439
|
1133
|
|
1134 /* Aside: GCPROing here would be overkill according to the FSF's
|
|
1135 philosophy. make-charset cannot currently GC, but is intended
|
|
1136 to be called from Lisp, with its arguments protected by the
|
|
1137 Lisp reader. We GCPRO in case it GCs in the future and no-one
|
|
1138 checks all the C callers. */
|
|
1139
|
3659
|
1140 GCPRO1 (charset_descr);
|
3439
|
1141 Vcurrent_jit_charset = Fmake_charset
|
3452
|
1142 (intern((const CIbyte *)setname), charset_descr,
|
3439
|
1143 /* Set encode-as-utf-8 to t, to have this character set written
|
|
1144 using UTF-8 escapes in escape-quoted and ctext. This
|
|
1145 sidesteps the fact that our internal character -> Unicode
|
|
1146 mapping is not stable from one invocation to the next. */
|
|
1147 nconc2 (list2(Qencode_as_utf_8, Qt),
|
|
1148 nconc2 (list6(Qcolumns, make_int(1), Qchars, make_int(96),
|
|
1149 Qdimension, make_int(2)),
|
3659
|
1150 list6(Qregistries, Qunicode_registries,
|
3439
|
1151 Qfinal, make_char(last_jit_charset_final++),
|
|
1152 /* This CCL program is initialised in
|
|
1153 unicode.el. */
|
|
1154 Qccl_program, Qccl_encode_to_ucs_2))));
|
|
1155 UNGCPRO;
|
|
1156
|
|
1157 i = get_free_codepoint(Vcurrent_jit_charset);
|
|
1158 }
|
|
1159
|
|
1160 if (-1 != i)
|
|
1161 {
|
|
1162 set_unicode_conversion((Ichar)i, code);
|
|
1163 /* No need to add the charset to the end of the list; it's done
|
|
1164 automatically. */
|
|
1165 }
|
|
1166 }
|
|
1167 return (Ichar) i;
|
771
|
1168 }
|
|
1169
|
877
|
1170 /* Add charsets to precedence list.
|
|
1171 LIST must be a list of charsets. Charsets which are in the list more
|
|
1172 than once are given the precedence implied by their earliest appearance.
|
|
1173 Later appearances are ignored. */
|
771
|
1174 static void
|
|
1175 add_charsets_to_precedence_list (Lisp_Object list, int *lbs,
|
|
1176 Lisp_Object_dynarr *dynarr)
|
|
1177 {
|
|
1178 {
|
|
1179 EXTERNAL_LIST_LOOP_2 (elt, list)
|
|
1180 {
|
|
1181 Lisp_Object charset = Fget_charset (elt);
|
778
|
1182 int lb = XCHARSET_LEADING_BYTE (charset);
|
771
|
1183 if (lbs[lb - MIN_LEADING_BYTE] == 0)
|
|
1184 {
|
877
|
1185 Dynarr_add (dynarr, charset);
|
771
|
1186 lbs[lb - MIN_LEADING_BYTE] = 1;
|
|
1187 }
|
|
1188 }
|
|
1189 }
|
|
1190 }
|
|
1191
|
877
|
1192 /* Rebuild the charset precedence array.
|
|
1193 The "charsets preferred for the current language" get highest precedence,
|
|
1194 followed by the "charsets preferred by default", ordered as in
|
|
1195 Vlanguage_unicode_precedence_list and Vdefault_unicode_precedence_list,
|
|
1196 respectively. All remaining charsets follow in an arbitrary order. */
|
771
|
1197 void
|
|
1198 recalculate_unicode_precedence (void)
|
|
1199 {
|
|
1200 int lbs[NUM_LEADING_BYTES];
|
|
1201 int i;
|
|
1202
|
|
1203 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
1204 lbs[i] = 0;
|
|
1205
|
|
1206 Dynarr_reset (unicode_precedence_dynarr);
|
|
1207
|
|
1208 add_charsets_to_precedence_list (Vlanguage_unicode_precedence_list,
|
|
1209 lbs, unicode_precedence_dynarr);
|
|
1210 add_charsets_to_precedence_list (Vdefault_unicode_precedence_list,
|
|
1211 lbs, unicode_precedence_dynarr);
|
|
1212
|
|
1213 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
1214 {
|
|
1215 if (lbs[i] == 0)
|
|
1216 {
|
826
|
1217 Lisp_Object charset = charset_by_leading_byte (i + MIN_LEADING_BYTE);
|
771
|
1218 if (!NILP (charset))
|
|
1219 Dynarr_add (unicode_precedence_dynarr, charset);
|
|
1220 }
|
|
1221 }
|
|
1222 }
|
|
1223
|
877
|
1224 DEFUN ("unicode-precedence-list",
|
|
1225 Funicode_precedence_list,
|
|
1226 0, 0, 0, /*
|
|
1227 Return the precedence order among charsets used for Unicode decoding.
|
|
1228
|
|
1229 Value is a list of charsets, which are searched in order for a translation
|
|
1230 matching a given Unicode character.
|
|
1231
|
|
1232 The highest precedence is given to the language-specific precedence list of
|
|
1233 charsets, defined by `set-language-unicode-precedence-list'. These are
|
|
1234 followed by charsets in the default precedence list, defined by
|
|
1235 `set-default-unicode-precedence-list'. Charsets occurring multiple times are
|
|
1236 given precedence according to their first occurrance in either list. These
|
|
1237 are followed by the remaining charsets, in some arbitrary order.
|
771
|
1238
|
|
1239 The language-specific precedence list is meant to be set as part of the
|
|
1240 language environment initialization; the default precedence list is meant
|
|
1241 to be set by the user.
|
1318
|
1242
|
|
1243 #### NOTE: This interface may be changed.
|
771
|
1244 */
|
877
|
1245 ())
|
|
1246 {
|
|
1247 int i;
|
|
1248 Lisp_Object list = Qnil;
|
|
1249
|
|
1250 for (i = Dynarr_length (unicode_precedence_dynarr) - 1; i >= 0; i--)
|
|
1251 list = Fcons (Dynarr_at (unicode_precedence_dynarr, i), list);
|
|
1252 return list;
|
|
1253 }
|
|
1254
|
|
1255
|
|
1256 /* #### This interface is wrong. Cyrillic users and Chinese users are going
|
|
1257 to have varying opinions about whether ISO Cyrillic, KOI8-R, or Windows
|
|
1258 1251 should take precedence, and whether Big Five or CNS should take
|
|
1259 precedence, respectively. This means that users are sometimes going to
|
|
1260 want to set Vlanguage_unicode_precedence_list.
|
|
1261 Furthermore, this should be language-local (buffer-local would be a
|
1318
|
1262 reasonable approximation).
|
|
1263
|
|
1264 Answer: You are right, this needs rethinking. */
|
877
|
1265 DEFUN ("set-language-unicode-precedence-list",
|
|
1266 Fset_language_unicode_precedence_list,
|
|
1267 1, 1, 0, /*
|
|
1268 Set the language-specific precedence of charsets in Unicode decoding.
|
|
1269 LIST is a list of charsets.
|
|
1270 See `unicode-precedence-list' for more information.
|
1318
|
1271
|
|
1272 #### NOTE: This interface may be changed.
|
877
|
1273 */
|
771
|
1274 (list))
|
|
1275 {
|
|
1276 {
|
|
1277 EXTERNAL_LIST_LOOP_2 (elt, list)
|
|
1278 Fget_charset (elt);
|
|
1279 }
|
|
1280
|
|
1281 Vlanguage_unicode_precedence_list = list;
|
|
1282 recalculate_unicode_precedence ();
|
|
1283 return Qnil;
|
|
1284 }
|
|
1285
|
|
1286 DEFUN ("language-unicode-precedence-list",
|
|
1287 Flanguage_unicode_precedence_list,
|
|
1288 0, 0, 0, /*
|
|
1289 Return the language-specific precedence list used for Unicode decoding.
|
877
|
1290 See `unicode-precedence-list' for more information.
|
1318
|
1291
|
|
1292 #### NOTE: This interface may be changed.
|
771
|
1293 */
|
|
1294 ())
|
|
1295 {
|
|
1296 return Vlanguage_unicode_precedence_list;
|
|
1297 }
|
|
1298
|
|
1299 DEFUN ("set-default-unicode-precedence-list",
|
|
1300 Fset_default_unicode_precedence_list,
|
|
1301 1, 1, 0, /*
|
|
1302 Set the default precedence list used for Unicode decoding.
|
877
|
1303 This is intended to be set by the user. See
|
|
1304 `unicode-precedence-list' for more information.
|
1318
|
1305
|
|
1306 #### NOTE: This interface may be changed.
|
771
|
1307 */
|
|
1308 (list))
|
|
1309 {
|
|
1310 {
|
|
1311 EXTERNAL_LIST_LOOP_2 (elt, list)
|
|
1312 Fget_charset (elt);
|
|
1313 }
|
|
1314
|
|
1315 Vdefault_unicode_precedence_list = list;
|
|
1316 recalculate_unicode_precedence ();
|
|
1317 return Qnil;
|
|
1318 }
|
|
1319
|
|
1320 DEFUN ("default-unicode-precedence-list",
|
|
1321 Fdefault_unicode_precedence_list,
|
|
1322 0, 0, 0, /*
|
|
1323 Return the default precedence list used for Unicode decoding.
|
877
|
1324 See `unicode-precedence-list' for more information.
|
1318
|
1325
|
|
1326 #### NOTE: This interface may be changed.
|
771
|
1327 */
|
|
1328 ())
|
|
1329 {
|
|
1330 return Vdefault_unicode_precedence_list;
|
|
1331 }
|
|
1332
|
|
1333 DEFUN ("set-unicode-conversion", Fset_unicode_conversion,
|
|
1334 2, 2, 0, /*
|
|
1335 Add conversion information between Unicode codepoints and characters.
|
877
|
1336 Conversions for U+0000 to U+00FF are hardwired to ASCII, Control-1, and
|
|
1337 Latin-1. Attempts to set these values will raise an error.
|
|
1338
|
771
|
1339 CHARACTER is one of the following:
|
|
1340
|
|
1341 -- A character (in which case CODE must be a non-negative integer; values
|
|
1342 above 2^20 - 1 are allowed for the purpose of specifying private
|
877
|
1343 characters, but are illegal in standard Unicode---they will cause errors
|
|
1344 when converted to utf-16)
|
771
|
1345 -- A vector of characters (in which case CODE must be a vector of integers
|
|
1346 of the same length)
|
|
1347 */
|
|
1348 (character, code))
|
|
1349 {
|
|
1350 Lisp_Object charset;
|
877
|
1351 int ichar, unicode;
|
771
|
1352
|
|
1353 CHECK_CHAR (character);
|
|
1354 CHECK_NATNUM (code);
|
|
1355
|
877
|
1356 unicode = XINT (code);
|
|
1357 ichar = XCHAR (character);
|
|
1358 charset = ichar_charset (ichar);
|
|
1359
|
|
1360 /* The translations of ASCII, Control-1, and Latin-1 code points are
|
|
1361 hard-coded in ichar_to_unicode and unicode_to_ichar.
|
|
1362
|
|
1363 Checking unicode < 256 && ichar != unicode is wrong because Mule gives
|
|
1364 many Latin characters code points in a few different character sets. */
|
|
1365 if ((EQ (charset, Vcharset_ascii) ||
|
|
1366 EQ (charset, Vcharset_control_1) ||
|
|
1367 EQ (charset, Vcharset_latin_iso8859_1))
|
|
1368 && unicode != ichar)
|
893
|
1369 signal_error (Qinvalid_argument, "Can't change Unicode translation for ASCII, Control-1 or Latin-1 character",
|
771
|
1370 character);
|
|
1371
|
877
|
1372 /* #### Composite characters are not properly implemented yet. */
|
|
1373 if (EQ (charset, Vcharset_composite))
|
|
1374 signal_error (Qinvalid_argument, "Can't set Unicode translation for Composite char",
|
|
1375 character);
|
|
1376
|
|
1377 set_unicode_conversion (ichar, unicode);
|
771
|
1378 return Qnil;
|
|
1379 }
|
|
1380
|
|
1381 #endif /* MULE */
|
|
1382
|
800
|
1383 DEFUN ("char-to-unicode", Fchar_to_unicode, 1, 1, 0, /*
|
771
|
1384 Convert character to Unicode codepoint.
|
3025
|
1385 When there is no international support (i.e. the `mule' feature is not
|
877
|
1386 present), this function simply does `char-to-int'.
|
771
|
1387 */
|
|
1388 (character))
|
|
1389 {
|
|
1390 CHECK_CHAR (character);
|
|
1391 #ifdef MULE
|
867
|
1392 return make_int (ichar_to_unicode (XCHAR (character)));
|
771
|
1393 #else
|
|
1394 return Fchar_to_int (character);
|
|
1395 #endif /* MULE */
|
|
1396 }
|
|
1397
|
800
|
1398 DEFUN ("unicode-to-char", Funicode_to_char, 1, 2, 0, /*
|
771
|
1399 Convert Unicode codepoint to character.
|
|
1400 CODE should be a non-negative integer.
|
|
1401 If CHARSETS is given, it should be a list of charsets, and only those
|
|
1402 charsets will be consulted, in the given order, for a translation.
|
|
1403 Otherwise, the default ordering of all charsets will be given (see
|
|
1404 `set-unicode-charset-precedence').
|
|
1405
|
3025
|
1406 When there is no international support (i.e. the `mule' feature is not
|
877
|
1407 present), this function simply does `int-to-char' and ignores the CHARSETS
|
|
1408 argument.
|
2622
|
1409
|
3439
|
1410 If the CODE would not otherwise be converted to an XEmacs character, and the
|
|
1411 list of character sets to be consulted is nil or the default, a new XEmacs
|
|
1412 character will be created for it in one of the `jit-ucs-charset' Mule
|
|
1413 character sets, and that character will be returned. There is scope for
|
|
1414 tens of thousands of separate Unicode code points in every session using
|
|
1415 this technique, so despite XEmacs' internal encoding not being based on
|
|
1416 Unicode, your data won't be trashed.
|
771
|
1417 */
|
2333
|
1418 (code, USED_IF_MULE (charsets)))
|
771
|
1419 {
|
|
1420 #ifdef MULE
|
|
1421 Lisp_Object_dynarr *dyn;
|
|
1422 int lbs[NUM_LEADING_BYTES];
|
|
1423 int c;
|
|
1424
|
|
1425 CHECK_NATNUM (code);
|
|
1426 c = XINT (code);
|
|
1427 {
|
|
1428 EXTERNAL_LIST_LOOP_2 (elt, charsets)
|
|
1429 Fget_charset (elt);
|
|
1430 }
|
|
1431
|
|
1432 if (NILP (charsets))
|
|
1433 {
|
877
|
1434 Ichar ret = unicode_to_ichar (c, unicode_precedence_dynarr);
|
771
|
1435 if (ret == -1)
|
|
1436 return Qnil;
|
|
1437 return make_char (ret);
|
|
1438 }
|
|
1439
|
|
1440 dyn = Dynarr_new (Lisp_Object);
|
|
1441 memset (lbs, 0, NUM_LEADING_BYTES * sizeof (int));
|
|
1442 add_charsets_to_precedence_list (charsets, lbs, dyn);
|
|
1443 {
|
877
|
1444 Ichar ret = unicode_to_ichar (c, dyn);
|
771
|
1445 Dynarr_free (dyn);
|
|
1446 if (ret == -1)
|
|
1447 return Qnil;
|
|
1448 return make_char (ret);
|
|
1449 }
|
|
1450 #else
|
|
1451 CHECK_NATNUM (code);
|
|
1452 return Fint_to_char (code);
|
|
1453 #endif /* MULE */
|
|
1454 }
|
|
1455
|
872
|
1456 #ifdef MULE
|
|
1457
|
771
|
1458 static Lisp_Object
|
|
1459 cerrar_el_fulano (Lisp_Object fulano)
|
|
1460 {
|
|
1461 FILE *file = (FILE *) get_opaque_ptr (fulano);
|
|
1462 retry_fclose (file);
|
|
1463 return Qnil;
|
|
1464 }
|
|
1465
|
1318
|
1466 DEFUN ("load-unicode-mapping-table", Fload_unicode_mapping_table,
|
771
|
1467 2, 6, 0, /*
|
877
|
1468 Load Unicode tables with the Unicode mapping data in FILENAME for CHARSET.
|
771
|
1469 Data is text, in the form of one translation per line -- charset
|
|
1470 codepoint followed by Unicode codepoint. Numbers are decimal or hex
|
|
1471 \(preceded by 0x). Comments are marked with a #. Charset codepoints
|
877
|
1472 for two-dimensional charsets have the first octet stored in the
|
771
|
1473 high 8 bits of the hex number and the second in the low 8 bits.
|
|
1474
|
|
1475 If START and END are given, only charset codepoints within the given
|
877
|
1476 range will be processed. (START and END apply to the codepoints in the
|
|
1477 file, before OFFSET is applied.)
|
771
|
1478
|
877
|
1479 If OFFSET is given, that value will be added to all charset codepoints
|
|
1480 in the file to obtain the internal charset codepoint. \(We assume
|
|
1481 that octets in the table are in the range 33 to 126 or 32 to 127. If
|
|
1482 you have a table in ku-ten form, with octets in the range 1 to 94, you
|
|
1483 will have to use an offset of 5140, i.e. 0x2020.)
|
771
|
1484
|
|
1485 FLAGS, if specified, control further how the tables are interpreted
|
877
|
1486 and are used to special-case certain known format deviations in the
|
|
1487 Unicode tables or in the charset:
|
771
|
1488
|
|
1489 `ignore-first-column'
|
877
|
1490 The JIS X 0208 tables have 3 columns of data instead of 2. The first
|
|
1491 column contains the Shift-JIS codepoint, which we ignore.
|
771
|
1492 `big5'
|
877
|
1493 The charset codepoints are Big Five codepoints; convert it to the
|
|
1494 hacked-up Mule codepoint in `chinese-big5-1' or `chinese-big5-2'.
|
771
|
1495 */
|
|
1496 (filename, charset, start, end, offset, flags))
|
|
1497 {
|
|
1498 int st = 0, en = INT_MAX, of = 0;
|
|
1499 FILE *file;
|
|
1500 struct gcpro gcpro1;
|
|
1501 char line[1025];
|
|
1502 int fondo = specpdl_depth ();
|
|
1503 int ignore_first_column = 0;
|
|
1504 int big5 = 0;
|
|
1505
|
|
1506 CHECK_STRING (filename);
|
|
1507 charset = Fget_charset (charset);
|
|
1508 if (!NILP (start))
|
|
1509 {
|
|
1510 CHECK_INT (start);
|
|
1511 st = XINT (start);
|
|
1512 }
|
|
1513 if (!NILP (end))
|
|
1514 {
|
|
1515 CHECK_INT (end);
|
|
1516 en = XINT (end);
|
|
1517 }
|
|
1518 if (!NILP (offset))
|
|
1519 {
|
|
1520 CHECK_INT (offset);
|
|
1521 of = XINT (offset);
|
|
1522 }
|
|
1523
|
|
1524 if (!LISTP (flags))
|
|
1525 flags = list1 (flags);
|
|
1526
|
|
1527 {
|
|
1528 EXTERNAL_LIST_LOOP_2 (elt, flags)
|
|
1529 {
|
|
1530 if (EQ (elt, Qignore_first_column))
|
|
1531 ignore_first_column = 1;
|
|
1532 else if (EQ (elt, Qbig5))
|
|
1533 big5 = 1;
|
|
1534 else
|
|
1535 invalid_constant
|
1318
|
1536 ("Unrecognized `load-unicode-mapping-table' flag", elt);
|
771
|
1537 }
|
|
1538 }
|
|
1539
|
|
1540 GCPRO1 (filename);
|
|
1541 filename = Fexpand_file_name (filename, Qnil);
|
|
1542 file = qxe_fopen (XSTRING_DATA (filename), READ_TEXT);
|
|
1543 if (!file)
|
|
1544 report_file_error ("Cannot open", filename);
|
|
1545 record_unwind_protect (cerrar_el_fulano, make_opaque_ptr (file));
|
|
1546 while (fgets (line, sizeof (line), file))
|
|
1547 {
|
|
1548 char *p = line;
|
|
1549 int cp1, cp2, endcount;
|
|
1550 int cp1high, cp1low;
|
|
1551 int dummy;
|
|
1552
|
|
1553 while (*p) /* erase all comments out of the line */
|
|
1554 {
|
|
1555 if (*p == '#')
|
|
1556 *p = '\0';
|
|
1557 else
|
|
1558 p++;
|
|
1559 }
|
|
1560 /* see if line is nothing but whitespace and skip if so */
|
|
1561 p = line + strspn (line, " \t\n\r\f");
|
|
1562 if (!*p)
|
|
1563 continue;
|
|
1564 /* NOTE: It appears that MS Windows and Newlib sscanf() have
|
|
1565 different interpretations for whitespace (== "skip all whitespace
|
|
1566 at processing point"): Newlib requires at least one corresponding
|
|
1567 whitespace character in the input, but MS allows none. The
|
|
1568 following would be easier to write if we could count on the MS
|
|
1569 interpretation.
|
|
1570
|
|
1571 Also, the return value does NOT include %n storage. */
|
|
1572 if ((!ignore_first_column ?
|
|
1573 sscanf (p, "%i %i%n", &cp1, &cp2, &endcount) < 2 :
|
|
1574 sscanf (p, "%i %i %i%n", &dummy, &cp1, &cp2, &endcount) < 3)
|
2367
|
1575 /* #### Temporary code! Cygwin newlib fucked up scanf() handling
|
|
1576 of numbers beginning 0x0... starting in 04/2004, in an attempt
|
|
1577 to fix another bug. A partial fix for this was put in in
|
|
1578 06/2004, but as of 10/2004 the value of ENDCOUNT returned in
|
|
1579 such case is still wrong. If this gets fixed soon, remove
|
|
1580 this code. --ben */
|
|
1581 #ifndef CYGWIN_SCANF_BUG
|
|
1582 || *(p + endcount + strspn (p + endcount, " \t\n\r\f"))
|
|
1583 #endif
|
|
1584 )
|
771
|
1585 {
|
793
|
1586 warn_when_safe (Qunicode, Qwarning,
|
771
|
1587 "Unrecognized line in translation file %s:\n%s",
|
|
1588 XSTRING_DATA (filename), line);
|
|
1589 continue;
|
|
1590 }
|
|
1591 if (cp1 >= st && cp1 <= en)
|
|
1592 {
|
|
1593 cp1 += of;
|
|
1594 if (cp1 < 0 || cp1 >= 65536)
|
|
1595 {
|
|
1596 out_of_range:
|
793
|
1597 warn_when_safe (Qunicode, Qwarning,
|
|
1598 "Out of range first codepoint 0x%x in "
|
|
1599 "translation file %s:\n%s",
|
771
|
1600 cp1, XSTRING_DATA (filename), line);
|
|
1601 continue;
|
|
1602 }
|
|
1603
|
|
1604 cp1high = cp1 >> 8;
|
|
1605 cp1low = cp1 & 255;
|
|
1606
|
|
1607 if (big5)
|
|
1608 {
|
867
|
1609 Ichar ch = decode_big5_char (cp1high, cp1low);
|
771
|
1610 if (ch == -1)
|
793
|
1611
|
|
1612 warn_when_safe (Qunicode, Qwarning,
|
|
1613 "Out of range Big5 codepoint 0x%x in "
|
|
1614 "translation file %s:\n%s",
|
771
|
1615 cp1, XSTRING_DATA (filename), line);
|
|
1616 else
|
|
1617 set_unicode_conversion (ch, cp2);
|
|
1618 }
|
|
1619 else
|
|
1620 {
|
|
1621 int l1, h1, l2, h2;
|
867
|
1622 Ichar emch;
|
771
|
1623
|
|
1624 switch (XCHARSET_TYPE (charset))
|
|
1625 {
|
|
1626 case CHARSET_TYPE_94: l1 = 33; h1 = 126; l2 = 0; h2 = 0; break;
|
|
1627 case CHARSET_TYPE_96: l1 = 32; h1 = 127; l2 = 0; h2 = 0; break;
|
|
1628 case CHARSET_TYPE_94X94: l1 = 33; h1 = 126; l2 = 33; h2 = 126;
|
|
1629 break;
|
|
1630 case CHARSET_TYPE_96X96: l1 = 32; h1 = 127; l2 = 32; h2 = 127;
|
|
1631 break;
|
2500
|
1632 default: ABORT (); l1 = 0; h1 = 0; l2 = 0; h2 = 0;
|
771
|
1633 }
|
|
1634
|
|
1635 if (cp1high < l2 || cp1high > h2 || cp1low < l1 || cp1low > h1)
|
|
1636 goto out_of_range;
|
|
1637
|
867
|
1638 emch = (cp1high == 0 ? make_ichar (charset, cp1low, 0) :
|
|
1639 make_ichar (charset, cp1high, cp1low));
|
771
|
1640 set_unicode_conversion (emch, cp2);
|
|
1641 }
|
|
1642 }
|
|
1643 }
|
|
1644
|
|
1645 if (ferror (file))
|
|
1646 report_file_error ("IO error when reading", filename);
|
|
1647
|
|
1648 unbind_to (fondo); /* close file */
|
|
1649 UNGCPRO;
|
|
1650 return Qnil;
|
|
1651 }
|
|
1652
|
|
1653 #endif /* MULE */
|
|
1654
|
|
1655
|
|
1656 /************************************************************************/
|
|
1657 /* Unicode coding system */
|
|
1658 /************************************************************************/
|
|
1659
|
|
1660 struct unicode_coding_system
|
|
1661 {
|
|
1662 enum unicode_type type;
|
1887
|
1663 unsigned int little_endian :1;
|
|
1664 unsigned int need_bom :1;
|
771
|
1665 };
|
|
1666
|
|
1667 #define CODING_SYSTEM_UNICODE_TYPE(codesys) \
|
|
1668 (CODING_SYSTEM_TYPE_DATA (codesys, unicode)->type)
|
|
1669 #define XCODING_SYSTEM_UNICODE_TYPE(codesys) \
|
|
1670 CODING_SYSTEM_UNICODE_TYPE (XCODING_SYSTEM (codesys))
|
|
1671 #define CODING_SYSTEM_UNICODE_LITTLE_ENDIAN(codesys) \
|
|
1672 (CODING_SYSTEM_TYPE_DATA (codesys, unicode)->little_endian)
|
|
1673 #define XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN(codesys) \
|
|
1674 CODING_SYSTEM_UNICODE_LITTLE_ENDIAN (XCODING_SYSTEM (codesys))
|
|
1675 #define CODING_SYSTEM_UNICODE_NEED_BOM(codesys) \
|
|
1676 (CODING_SYSTEM_TYPE_DATA (codesys, unicode)->need_bom)
|
|
1677 #define XCODING_SYSTEM_UNICODE_NEED_BOM(codesys) \
|
|
1678 CODING_SYSTEM_UNICODE_NEED_BOM (XCODING_SYSTEM (codesys))
|
|
1679
|
|
1680 struct unicode_coding_stream
|
|
1681 {
|
|
1682 /* decode */
|
|
1683 unsigned char counter;
|
|
1684 int seen_char;
|
|
1685 /* encode */
|
|
1686 Lisp_Object current_charset;
|
|
1687 int current_char_boundary;
|
|
1688 int wrote_bom;
|
|
1689 };
|
|
1690
|
1204
|
1691 static const struct memory_description unicode_coding_system_description[] = {
|
771
|
1692 { XD_END }
|
|
1693 };
|
|
1694
|
1204
|
1695 DEFINE_CODING_SYSTEM_TYPE_WITH_DATA (unicode);
|
|
1696
|
771
|
1697 /* Decode a UCS-2 or UCS-4 character into a buffer. If the lookup fails, use
|
|
1698 <GETA MARK> (U+3013) of JIS X 0208, which means correct character
|
|
1699 is not found, instead.
|
|
1700 #### do something more appropriate (use blob?)
|
|
1701 Danger, Will Robinson! Data loss. Should we signal user? */
|
|
1702 static void
|
|
1703 decode_unicode_char (int ch, unsigned_char_dynarr *dst,
|
1887
|
1704 struct unicode_coding_stream *data,
|
|
1705 unsigned int ignore_bom)
|
771
|
1706 {
|
|
1707 if (ch == 0xFEFF && !data->seen_char && ignore_bom)
|
|
1708 ;
|
|
1709 else
|
|
1710 {
|
|
1711 #ifdef MULE
|
877
|
1712 Ichar chr = unicode_to_ichar (ch, unicode_precedence_dynarr);
|
771
|
1713
|
|
1714 if (chr != -1)
|
|
1715 {
|
867
|
1716 Ibyte work[MAX_ICHAR_LEN];
|
771
|
1717 int len;
|
|
1718
|
867
|
1719 len = set_itext_ichar (work, chr);
|
771
|
1720 Dynarr_add_many (dst, work, len);
|
|
1721 }
|
|
1722 else
|
|
1723 {
|
|
1724 Dynarr_add (dst, LEADING_BYTE_JAPANESE_JISX0208);
|
|
1725 Dynarr_add (dst, 34 + 128);
|
|
1726 Dynarr_add (dst, 46 + 128);
|
|
1727 }
|
|
1728 #else
|
867
|
1729 Dynarr_add (dst, (Ibyte) ch);
|
771
|
1730 #endif /* MULE */
|
|
1731 }
|
|
1732
|
|
1733 data->seen_char = 1;
|
|
1734 }
|
|
1735
|
|
1736 static void
|
|
1737 encode_unicode_char_1 (int code, unsigned_char_dynarr *dst,
|
1887
|
1738 enum unicode_type type, unsigned int little_endian)
|
771
|
1739 {
|
|
1740 switch (type)
|
|
1741 {
|
|
1742 case UNICODE_UTF_16:
|
|
1743 if (little_endian)
|
|
1744 {
|
|
1745 Dynarr_add (dst, (unsigned char) (code & 255));
|
|
1746 Dynarr_add (dst, (unsigned char) ((code >> 8) & 255));
|
|
1747 }
|
|
1748 else
|
|
1749 {
|
|
1750 Dynarr_add (dst, (unsigned char) ((code >> 8) & 255));
|
|
1751 Dynarr_add (dst, (unsigned char) (code & 255));
|
|
1752 }
|
|
1753 break;
|
|
1754
|
|
1755 case UNICODE_UCS_4:
|
|
1756 if (little_endian)
|
|
1757 {
|
|
1758 Dynarr_add (dst, (unsigned char) (code & 255));
|
|
1759 Dynarr_add (dst, (unsigned char) ((code >> 8) & 255));
|
|
1760 Dynarr_add (dst, (unsigned char) ((code >> 16) & 255));
|
|
1761 Dynarr_add (dst, (unsigned char) (code >> 24));
|
|
1762 }
|
|
1763 else
|
|
1764 {
|
|
1765 Dynarr_add (dst, (unsigned char) (code >> 24));
|
|
1766 Dynarr_add (dst, (unsigned char) ((code >> 16) & 255));
|
|
1767 Dynarr_add (dst, (unsigned char) ((code >> 8) & 255));
|
|
1768 Dynarr_add (dst, (unsigned char) (code & 255));
|
|
1769 }
|
|
1770 break;
|
|
1771
|
|
1772 case UNICODE_UTF_8:
|
|
1773 if (code <= 0x7f)
|
|
1774 {
|
|
1775 Dynarr_add (dst, (unsigned char) code);
|
|
1776 }
|
|
1777 else if (code <= 0x7ff)
|
|
1778 {
|
|
1779 Dynarr_add (dst, (unsigned char) ((code >> 6) | 0xc0));
|
|
1780 Dynarr_add (dst, (unsigned char) ((code & 0x3f) | 0x80));
|
|
1781 }
|
|
1782 else if (code <= 0xffff)
|
|
1783 {
|
|
1784 Dynarr_add (dst, (unsigned char) ((code >> 12) | 0xe0));
|
|
1785 Dynarr_add (dst, (unsigned char) (((code >> 6) & 0x3f) | 0x80));
|
|
1786 Dynarr_add (dst, (unsigned char) ((code & 0x3f) | 0x80));
|
|
1787 }
|
|
1788 else if (code <= 0x1fffff)
|
|
1789 {
|
|
1790 Dynarr_add (dst, (unsigned char) ((code >> 18) | 0xf0));
|
|
1791 Dynarr_add (dst, (unsigned char) (((code >> 12) & 0x3f) | 0x80));
|
|
1792 Dynarr_add (dst, (unsigned char) (((code >> 6) & 0x3f) | 0x80));
|
|
1793 Dynarr_add (dst, (unsigned char) ((code & 0x3f) | 0x80));
|
|
1794 }
|
|
1795 else if (code <= 0x3ffffff)
|
|
1796 {
|
|
1797 Dynarr_add (dst, (unsigned char) ((code >> 24) | 0xf8));
|
|
1798 Dynarr_add (dst, (unsigned char) (((code >> 18) & 0x3f) | 0x80));
|
|
1799 Dynarr_add (dst, (unsigned char) (((code >> 12) & 0x3f) | 0x80));
|
|
1800 Dynarr_add (dst, (unsigned char) (((code >> 6) & 0x3f) | 0x80));
|
|
1801 Dynarr_add (dst, (unsigned char) ((code & 0x3f) | 0x80));
|
|
1802 }
|
|
1803 else
|
|
1804 {
|
|
1805 Dynarr_add (dst, (unsigned char) ((code >> 30) | 0xfc));
|
|
1806 Dynarr_add (dst, (unsigned char) (((code >> 24) & 0x3f) | 0x80));
|
|
1807 Dynarr_add (dst, (unsigned char) (((code >> 18) & 0x3f) | 0x80));
|
|
1808 Dynarr_add (dst, (unsigned char) (((code >> 12) & 0x3f) | 0x80));
|
|
1809 Dynarr_add (dst, (unsigned char) (((code >> 6) & 0x3f) | 0x80));
|
|
1810 Dynarr_add (dst, (unsigned char) ((code & 0x3f) | 0x80));
|
|
1811 }
|
|
1812 break;
|
|
1813
|
2500
|
1814 case UNICODE_UTF_7: ABORT ();
|
771
|
1815
|
2500
|
1816 default: ABORT ();
|
771
|
1817 }
|
|
1818 }
|
|
1819
|
3439
|
1820 /* Also used in mule-coding.c for UTF-8 handling in ISO 2022-oriented
|
|
1821 encodings. */
|
|
1822 void
|
2333
|
1823 encode_unicode_char (Lisp_Object USED_IF_MULE (charset), int h,
|
|
1824 int USED_IF_MULE (l), unsigned_char_dynarr *dst,
|
|
1825 enum unicode_type type, unsigned int little_endian)
|
771
|
1826 {
|
|
1827 #ifdef MULE
|
867
|
1828 int code = ichar_to_unicode (make_ichar (charset, h & 127, l & 127));
|
771
|
1829
|
|
1830 if (code == -1)
|
|
1831 {
|
|
1832 if (type != UNICODE_UTF_16 &&
|
|
1833 XCHARSET_DIMENSION (charset) == 2 &&
|
|
1834 XCHARSET_CHARS (charset) == 94)
|
|
1835 {
|
|
1836 unsigned char final = XCHARSET_FINAL (charset);
|
|
1837
|
|
1838 if (('@' <= final) && (final < 0x7f))
|
|
1839 code = (0xe00000 + (final - '@') * 94 * 94
|
|
1840 + ((h & 127) - 33) * 94 + (l & 127) - 33);
|
|
1841 else
|
|
1842 code = '?';
|
|
1843 }
|
|
1844 else
|
|
1845 code = '?';
|
|
1846 }
|
|
1847 #else
|
|
1848 int code = h;
|
|
1849 #endif /* MULE */
|
|
1850
|
|
1851 encode_unicode_char_1 (code, dst, type, little_endian);
|
|
1852 }
|
|
1853
|
|
1854 static Bytecount
|
|
1855 unicode_convert (struct coding_stream *str, const UExtbyte *src,
|
|
1856 unsigned_char_dynarr *dst, Bytecount n)
|
|
1857 {
|
|
1858 unsigned int ch = str->ch;
|
|
1859 struct unicode_coding_stream *data = CODING_STREAM_TYPE_DATA (str, unicode);
|
|
1860 enum unicode_type type =
|
|
1861 XCODING_SYSTEM_UNICODE_TYPE (str->codesys);
|
1887
|
1862 unsigned int little_endian =
|
|
1863 XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN (str->codesys);
|
|
1864 unsigned int ignore_bom = XCODING_SYSTEM_UNICODE_NEED_BOM (str->codesys);
|
771
|
1865 Bytecount orign = n;
|
|
1866
|
|
1867 if (str->direction == CODING_DECODE)
|
|
1868 {
|
|
1869 unsigned char counter = data->counter;
|
|
1870
|
|
1871 while (n--)
|
|
1872 {
|
|
1873 UExtbyte c = *src++;
|
|
1874
|
|
1875 switch (type)
|
|
1876 {
|
|
1877 case UNICODE_UTF_8:
|
|
1878 switch (counter)
|
|
1879 {
|
|
1880 case 0:
|
|
1881 if (c >= 0xfc)
|
|
1882 {
|
|
1883 ch = c & 0x01;
|
|
1884 counter = 5;
|
|
1885 }
|
|
1886 else if (c >= 0xf8)
|
|
1887 {
|
|
1888 ch = c & 0x03;
|
|
1889 counter = 4;
|
|
1890 }
|
|
1891 else if (c >= 0xf0)
|
|
1892 {
|
|
1893 ch = c & 0x07;
|
|
1894 counter = 3;
|
|
1895 }
|
|
1896 else if (c >= 0xe0)
|
|
1897 {
|
|
1898 ch = c & 0x0f;
|
|
1899 counter = 2;
|
|
1900 }
|
|
1901 else if (c >= 0xc0)
|
|
1902 {
|
|
1903 ch = c & 0x1f;
|
|
1904 counter = 1;
|
|
1905 }
|
|
1906 else
|
|
1907 decode_unicode_char (c, dst, data, ignore_bom);
|
|
1908 break;
|
|
1909 case 1:
|
|
1910 ch = (ch << 6) | (c & 0x3f);
|
|
1911 decode_unicode_char (ch, dst, data, ignore_bom);
|
|
1912 ch = 0;
|
|
1913 counter = 0;
|
|
1914 break;
|
|
1915 default:
|
|
1916 ch = (ch << 6) | (c & 0x3f);
|
|
1917 counter--;
|
|
1918 }
|
|
1919 break;
|
|
1920
|
|
1921 case UNICODE_UTF_16:
|
|
1922 if (little_endian)
|
|
1923 ch = (c << counter) | ch;
|
|
1924 else
|
|
1925 ch = (ch << 8) | c;
|
|
1926 counter += 8;
|
|
1927 if (counter == 16)
|
|
1928 {
|
|
1929 int tempch = ch;
|
|
1930 ch = 0;
|
|
1931 counter = 0;
|
|
1932 decode_unicode_char (tempch, dst, data, ignore_bom);
|
|
1933 }
|
|
1934 break;
|
|
1935
|
|
1936 case UNICODE_UCS_4:
|
|
1937 if (little_endian)
|
|
1938 ch = (c << counter) | ch;
|
|
1939 else
|
|
1940 ch = (ch << 8) | c;
|
|
1941 counter += 8;
|
|
1942 if (counter == 32)
|
|
1943 {
|
|
1944 int tempch = ch;
|
|
1945 ch = 0;
|
|
1946 counter = 0;
|
|
1947 if (tempch < 0)
|
|
1948 {
|
|
1949 /* !!#### indicate an error */
|
|
1950 tempch = '~';
|
|
1951 }
|
|
1952 decode_unicode_char (tempch, dst, data, ignore_bom);
|
|
1953 }
|
|
1954 break;
|
|
1955
|
|
1956 case UNICODE_UTF_7:
|
2500
|
1957 ABORT ();
|
771
|
1958 break;
|
|
1959
|
2500
|
1960 default: ABORT ();
|
771
|
1961 }
|
|
1962
|
|
1963 }
|
|
1964 if (str->eof)
|
|
1965 DECODE_OUTPUT_PARTIAL_CHAR (ch, dst);
|
|
1966
|
|
1967 data->counter = counter;
|
|
1968 }
|
|
1969 else
|
|
1970 {
|
|
1971 unsigned char char_boundary = data->current_char_boundary;
|
|
1972 Lisp_Object charset = data->current_charset;
|
|
1973
|
|
1974 #ifdef ENABLE_COMPOSITE_CHARS
|
|
1975 /* flags for handling composite chars. We do a little switcheroo
|
|
1976 on the source while we're outputting the composite char. */
|
|
1977 Bytecount saved_n = 0;
|
867
|
1978 const Ibyte *saved_src = NULL;
|
771
|
1979 int in_composite = 0;
|
|
1980
|
|
1981 back_to_square_n:
|
|
1982 #endif /* ENABLE_COMPOSITE_CHARS */
|
|
1983
|
|
1984 if (XCODING_SYSTEM_UNICODE_NEED_BOM (str->codesys) && !data->wrote_bom)
|
|
1985 {
|
|
1986 encode_unicode_char_1 (0xFEFF, dst, type, little_endian);
|
|
1987 data->wrote_bom = 1;
|
|
1988 }
|
|
1989
|
|
1990 while (n--)
|
|
1991 {
|
867
|
1992 Ibyte c = *src++;
|
771
|
1993
|
|
1994 #ifdef MULE
|
826
|
1995 if (byte_ascii_p (c))
|
771
|
1996 #endif /* MULE */
|
|
1997 { /* Processing ASCII character */
|
|
1998 ch = 0;
|
|
1999 encode_unicode_char (Vcharset_ascii, c, 0, dst, type,
|
|
2000 little_endian);
|
|
2001
|
|
2002 char_boundary = 1;
|
|
2003 }
|
|
2004 #ifdef MULE
|
867
|
2005 else if (ibyte_leading_byte_p (c) || ibyte_leading_byte_p (ch))
|
771
|
2006 { /* Processing Leading Byte */
|
|
2007 ch = 0;
|
826
|
2008 charset = charset_by_leading_byte (c);
|
|
2009 if (leading_byte_prefix_p(c))
|
771
|
2010 ch = c;
|
|
2011 char_boundary = 0;
|
|
2012 }
|
|
2013 else
|
|
2014 { /* Processing Non-ASCII character */
|
|
2015 char_boundary = 1;
|
|
2016 if (EQ (charset, Vcharset_control_1))
|
2704
|
2017 /* See:
|
|
2018
|
|
2019 (Info-goto-node "(internals)Internal String Encoding")
|
|
2020
|
|
2021 for the rationale behind subtracting #xa0 from the
|
|
2022 character's code. */
|
|
2023 encode_unicode_char (Vcharset_control_1, c - 0xa0, 0, dst,
|
771
|
2024 type, little_endian);
|
|
2025 else
|
|
2026 {
|
|
2027 switch (XCHARSET_REP_BYTES (charset))
|
|
2028 {
|
|
2029 case 2:
|
|
2030 encode_unicode_char (charset, c, 0, dst, type,
|
|
2031 little_endian);
|
|
2032 break;
|
|
2033 case 3:
|
|
2034 if (XCHARSET_PRIVATE_P (charset))
|
|
2035 {
|
|
2036 encode_unicode_char (charset, c, 0, dst, type,
|
|
2037 little_endian);
|
|
2038 ch = 0;
|
|
2039 }
|
|
2040 else if (ch)
|
|
2041 {
|
|
2042 #ifdef ENABLE_COMPOSITE_CHARS
|
|
2043 if (EQ (charset, Vcharset_composite))
|
|
2044 {
|
|
2045 if (in_composite)
|
|
2046 {
|
|
2047 /* #### Bother! We don't know how to
|
|
2048 handle this yet. */
|
|
2049 encode_unicode_char (Vcharset_ascii, '~', 0,
|
|
2050 dst, type,
|
|
2051 little_endian);
|
|
2052 }
|
|
2053 else
|
|
2054 {
|
867
|
2055 Ichar emch = make_ichar (Vcharset_composite,
|
771
|
2056 ch & 0x7F,
|
|
2057 c & 0x7F);
|
|
2058 Lisp_Object lstr =
|
|
2059 composite_char_string (emch);
|
|
2060 saved_n = n;
|
|
2061 saved_src = src;
|
|
2062 in_composite = 1;
|
|
2063 src = XSTRING_DATA (lstr);
|
|
2064 n = XSTRING_LENGTH (lstr);
|
|
2065 }
|
|
2066 }
|
|
2067 else
|
|
2068 #endif /* ENABLE_COMPOSITE_CHARS */
|
|
2069 encode_unicode_char (charset, ch, c, dst, type,
|
|
2070 little_endian);
|
|
2071 ch = 0;
|
|
2072 }
|
|
2073 else
|
|
2074 {
|
|
2075 ch = c;
|
|
2076 char_boundary = 0;
|
|
2077 }
|
|
2078 break;
|
|
2079 case 4:
|
|
2080 if (ch)
|
|
2081 {
|
|
2082 encode_unicode_char (charset, ch, c, dst, type,
|
|
2083 little_endian);
|
|
2084 ch = 0;
|
|
2085 }
|
|
2086 else
|
|
2087 {
|
|
2088 ch = c;
|
|
2089 char_boundary = 0;
|
|
2090 }
|
|
2091 break;
|
|
2092 default:
|
2500
|
2093 ABORT ();
|
771
|
2094 }
|
|
2095 }
|
|
2096 }
|
|
2097 #endif /* MULE */
|
|
2098 }
|
|
2099
|
|
2100 #ifdef ENABLE_COMPOSITE_CHARS
|
|
2101 if (in_composite)
|
|
2102 {
|
|
2103 n = saved_n;
|
|
2104 src = saved_src;
|
|
2105 in_composite = 0;
|
|
2106 goto back_to_square_n; /* Wheeeeeeeee ..... */
|
|
2107 }
|
|
2108 #endif /* ENABLE_COMPOSITE_CHARS */
|
|
2109
|
|
2110 data->current_char_boundary = char_boundary;
|
|
2111 data->current_charset = charset;
|
|
2112
|
|
2113 /* La palabra se hizo carne! */
|
|
2114 /* A palavra fez-se carne! */
|
|
2115 /* Whatever. */
|
|
2116 }
|
|
2117
|
|
2118 str->ch = ch;
|
|
2119 return orign;
|
|
2120 }
|
|
2121
|
|
2122 /* DEFINE_DETECTOR (utf_7); */
|
|
2123 DEFINE_DETECTOR (utf_8);
|
|
2124 DEFINE_DETECTOR_CATEGORY (utf_8, utf_8);
|
985
|
2125 DEFINE_DETECTOR_CATEGORY (utf_8, utf_8_bom);
|
771
|
2126 DEFINE_DETECTOR (ucs_4);
|
|
2127 DEFINE_DETECTOR_CATEGORY (ucs_4, ucs_4);
|
|
2128 DEFINE_DETECTOR (utf_16);
|
|
2129 DEFINE_DETECTOR_CATEGORY (utf_16, utf_16);
|
|
2130 DEFINE_DETECTOR_CATEGORY (utf_16, utf_16_little_endian);
|
|
2131 DEFINE_DETECTOR_CATEGORY (utf_16, utf_16_bom);
|
|
2132 DEFINE_DETECTOR_CATEGORY (utf_16, utf_16_little_endian_bom);
|
|
2133
|
|
2134 struct ucs_4_detector
|
|
2135 {
|
|
2136 int in_ucs_4_byte;
|
|
2137 };
|
|
2138
|
|
2139 static void
|
|
2140 ucs_4_detect (struct detection_state *st, const UExtbyte *src,
|
|
2141 Bytecount n)
|
|
2142 {
|
|
2143 struct ucs_4_detector *data = DETECTION_STATE_DATA (st, ucs_4);
|
|
2144
|
|
2145 while (n--)
|
|
2146 {
|
|
2147 UExtbyte c = *src++;
|
|
2148 switch (data->in_ucs_4_byte)
|
|
2149 {
|
|
2150 case 0:
|
|
2151 if (c >= 128)
|
|
2152 {
|
|
2153 DET_RESULT (st, ucs_4) = DET_NEARLY_IMPOSSIBLE;
|
|
2154 return;
|
|
2155 }
|
|
2156 else
|
|
2157 data->in_ucs_4_byte++;
|
|
2158 break;
|
|
2159 case 3:
|
|
2160 data->in_ucs_4_byte = 0;
|
|
2161 break;
|
|
2162 default:
|
|
2163 data->in_ucs_4_byte++;
|
|
2164 }
|
|
2165 }
|
|
2166
|
|
2167 /* !!#### write this for real */
|
|
2168 DET_RESULT (st, ucs_4) = DET_AS_LIKELY_AS_UNLIKELY;
|
|
2169 }
|
|
2170
|
|
2171 struct utf_16_detector
|
|
2172 {
|
|
2173 unsigned int seen_ffff:1;
|
|
2174 unsigned int seen_forward_bom:1;
|
|
2175 unsigned int seen_rev_bom:1;
|
|
2176 int byteno;
|
|
2177 int prev_char;
|
|
2178 int text, rev_text;
|
1267
|
2179 int sep, rev_sep;
|
|
2180 int num_ascii;
|
771
|
2181 };
|
|
2182
|
|
2183 static void
|
|
2184 utf_16_detect (struct detection_state *st, const UExtbyte *src,
|
|
2185 Bytecount n)
|
|
2186 {
|
|
2187 struct utf_16_detector *data = DETECTION_STATE_DATA (st, utf_16);
|
|
2188
|
|
2189 while (n--)
|
|
2190 {
|
|
2191 UExtbyte c = *src++;
|
|
2192 int prevc = data->prev_char;
|
|
2193 if (data->byteno == 1 && c == 0xFF && prevc == 0xFE)
|
|
2194 data->seen_forward_bom = 1;
|
|
2195 else if (data->byteno == 1 && c == 0xFE && prevc == 0xFF)
|
|
2196 data->seen_rev_bom = 1;
|
|
2197
|
|
2198 if (data->byteno & 1)
|
|
2199 {
|
|
2200 if (c == 0xFF && prevc == 0xFF)
|
|
2201 data->seen_ffff = 1;
|
|
2202 if (prevc == 0
|
|
2203 && (c == '\r' || c == '\n'
|
|
2204 || (c >= 0x20 && c <= 0x7E)))
|
|
2205 data->text++;
|
|
2206 if (c == 0
|
|
2207 && (prevc == '\r' || prevc == '\n'
|
|
2208 || (prevc >= 0x20 && prevc <= 0x7E)))
|
|
2209 data->rev_text++;
|
1267
|
2210 /* #### 0x2028 is LINE SEPARATOR and 0x2029 is PARAGRAPH SEPARATOR.
|
|
2211 I used to count these in text and rev_text but that is very bad,
|
|
2212 as 0x2028 is also space + left-paren in ASCII, which is extremely
|
|
2213 common. So, what do we do with these? */
|
771
|
2214 if (prevc == 0x20 && (c == 0x28 || c == 0x29))
|
1267
|
2215 data->sep++;
|
771
|
2216 if (c == 0x20 && (prevc == 0x28 || prevc == 0x29))
|
1267
|
2217 data->rev_sep++;
|
771
|
2218 }
|
|
2219
|
1267
|
2220 if ((c >= ' ' && c <= '~') || c == '\n' || c == '\r' || c == '\t' ||
|
|
2221 c == '\f' || c == '\v')
|
|
2222 data->num_ascii++;
|
771
|
2223 data->byteno++;
|
|
2224 data->prev_char = c;
|
|
2225 }
|
|
2226
|
|
2227 {
|
|
2228 int variance_indicates_big_endian =
|
|
2229 (data->text >= 10
|
|
2230 && (data->rev_text == 0
|
|
2231 || data->text / data->rev_text >= 10));
|
|
2232 int variance_indicates_little_endian =
|
|
2233 (data->rev_text >= 10
|
|
2234 && (data->text == 0
|
|
2235 || data->rev_text / data->text >= 10));
|
|
2236
|
|
2237 if (data->seen_ffff)
|
|
2238 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE);
|
|
2239 else if (data->seen_forward_bom)
|
|
2240 {
|
|
2241 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE);
|
|
2242 if (variance_indicates_big_endian)
|
|
2243 DET_RESULT (st, utf_16_bom) = DET_NEAR_CERTAINTY;
|
|
2244 else if (variance_indicates_little_endian)
|
|
2245 DET_RESULT (st, utf_16_bom) = DET_SOMEWHAT_LIKELY;
|
|
2246 else
|
|
2247 DET_RESULT (st, utf_16_bom) = DET_QUITE_PROBABLE;
|
|
2248 }
|
|
2249 else if (data->seen_forward_bom)
|
|
2250 {
|
|
2251 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE);
|
|
2252 if (variance_indicates_big_endian)
|
|
2253 DET_RESULT (st, utf_16_bom) = DET_NEAR_CERTAINTY;
|
|
2254 else if (variance_indicates_little_endian)
|
|
2255 /* #### may need to rethink */
|
|
2256 DET_RESULT (st, utf_16_bom) = DET_SOMEWHAT_LIKELY;
|
|
2257 else
|
|
2258 /* #### may need to rethink */
|
|
2259 DET_RESULT (st, utf_16_bom) = DET_QUITE_PROBABLE;
|
|
2260 }
|
|
2261 else if (data->seen_rev_bom)
|
|
2262 {
|
|
2263 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE);
|
|
2264 if (variance_indicates_little_endian)
|
|
2265 DET_RESULT (st, utf_16_little_endian_bom) = DET_NEAR_CERTAINTY;
|
|
2266 else if (variance_indicates_big_endian)
|
|
2267 /* #### may need to rethink */
|
|
2268 DET_RESULT (st, utf_16_little_endian_bom) = DET_SOMEWHAT_LIKELY;
|
|
2269 else
|
|
2270 /* #### may need to rethink */
|
|
2271 DET_RESULT (st, utf_16_little_endian_bom) = DET_QUITE_PROBABLE;
|
|
2272 }
|
|
2273 else if (variance_indicates_big_endian)
|
|
2274 {
|
|
2275 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE);
|
|
2276 DET_RESULT (st, utf_16) = DET_SOMEWHAT_LIKELY;
|
|
2277 DET_RESULT (st, utf_16_little_endian) = DET_SOMEWHAT_UNLIKELY;
|
|
2278 }
|
|
2279 else if (variance_indicates_little_endian)
|
|
2280 {
|
|
2281 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE);
|
|
2282 DET_RESULT (st, utf_16) = DET_SOMEWHAT_UNLIKELY;
|
|
2283 DET_RESULT (st, utf_16_little_endian) = DET_SOMEWHAT_LIKELY;
|
|
2284 }
|
|
2285 else
|
1267
|
2286 {
|
|
2287 /* #### FUCKME! There should really be an ASCII detector. This
|
|
2288 would rule out the need to have this built-in here as
|
|
2289 well. --ben */
|
1292
|
2290 int pct_ascii = data->byteno ? (100 * data->num_ascii) / data->byteno
|
|
2291 : 100;
|
1267
|
2292
|
|
2293 if (pct_ascii > 90)
|
|
2294 SET_DET_RESULTS (st, utf_16, DET_QUITE_IMPROBABLE);
|
|
2295 else if (pct_ascii > 75)
|
|
2296 SET_DET_RESULTS (st, utf_16, DET_SOMEWHAT_UNLIKELY);
|
|
2297 else
|
|
2298 SET_DET_RESULTS (st, utf_16, DET_AS_LIKELY_AS_UNLIKELY);
|
|
2299 }
|
771
|
2300 }
|
|
2301 }
|
|
2302
|
|
2303 struct utf_8_detector
|
|
2304 {
|
985
|
2305 int byteno;
|
|
2306 int first_byte;
|
|
2307 int second_byte;
|
1267
|
2308 int prev_byte;
|
771
|
2309 int in_utf_8_byte;
|
1267
|
2310 int recent_utf_8_sequence;
|
|
2311 int seen_bogus_utf8;
|
|
2312 int seen_really_bogus_utf8;
|
|
2313 int seen_2byte_sequence;
|
|
2314 int seen_longer_sequence;
|
|
2315 int seen_iso2022_esc;
|
|
2316 int seen_iso_shift;
|
1887
|
2317 unsigned int seen_utf_bom:1;
|
771
|
2318 };
|
|
2319
|
|
2320 static void
|
|
2321 utf_8_detect (struct detection_state *st, const UExtbyte *src,
|
|
2322 Bytecount n)
|
|
2323 {
|
|
2324 struct utf_8_detector *data = DETECTION_STATE_DATA (st, utf_8);
|
|
2325
|
|
2326 while (n--)
|
|
2327 {
|
|
2328 UExtbyte c = *src++;
|
985
|
2329 switch (data->byteno)
|
|
2330 {
|
|
2331 case 0:
|
|
2332 data->first_byte = c;
|
|
2333 break;
|
|
2334 case 1:
|
|
2335 data->second_byte = c;
|
|
2336 break;
|
|
2337 case 2:
|
|
2338 if (data->first_byte == 0xef &&
|
|
2339 data->second_byte == 0xbb &&
|
|
2340 c == 0xbf)
|
1267
|
2341 data->seen_utf_bom = 1;
|
985
|
2342 break;
|
|
2343 }
|
|
2344
|
771
|
2345 switch (data->in_utf_8_byte)
|
|
2346 {
|
|
2347 case 0:
|
1267
|
2348 if (data->prev_byte == ISO_CODE_ESC && c >= 0x28 && c <= 0x2F)
|
|
2349 data->seen_iso2022_esc++;
|
|
2350 else if (c == ISO_CODE_SI || c == ISO_CODE_SO)
|
|
2351 data->seen_iso_shift++;
|
771
|
2352 else if (c >= 0xfc)
|
|
2353 data->in_utf_8_byte = 5;
|
|
2354 else if (c >= 0xf8)
|
|
2355 data->in_utf_8_byte = 4;
|
|
2356 else if (c >= 0xf0)
|
|
2357 data->in_utf_8_byte = 3;
|
|
2358 else if (c >= 0xe0)
|
|
2359 data->in_utf_8_byte = 2;
|
|
2360 else if (c >= 0xc0)
|
|
2361 data->in_utf_8_byte = 1;
|
|
2362 else if (c >= 0x80)
|
1267
|
2363 data->seen_bogus_utf8++;
|
|
2364 if (data->in_utf_8_byte > 0)
|
|
2365 data->recent_utf_8_sequence = data->in_utf_8_byte;
|
771
|
2366 break;
|
|
2367 default:
|
|
2368 if ((c & 0xc0) != 0x80)
|
1267
|
2369 data->seen_really_bogus_utf8++;
|
|
2370 else
|
771
|
2371 {
|
1267
|
2372 data->in_utf_8_byte--;
|
|
2373 if (data->in_utf_8_byte == 0)
|
|
2374 {
|
|
2375 if (data->recent_utf_8_sequence == 1)
|
|
2376 data->seen_2byte_sequence++;
|
|
2377 else
|
|
2378 {
|
|
2379 assert (data->recent_utf_8_sequence >= 2);
|
|
2380 data->seen_longer_sequence++;
|
|
2381 }
|
|
2382 }
|
771
|
2383 }
|
|
2384 }
|
985
|
2385
|
|
2386 data->byteno++;
|
1267
|
2387 data->prev_byte = c;
|
771
|
2388 }
|
1267
|
2389
|
|
2390 /* either BOM or no BOM, but not both */
|
|
2391 SET_DET_RESULTS (st, utf_8, DET_NEARLY_IMPOSSIBLE);
|
|
2392
|
|
2393
|
|
2394 if (data->seen_utf_bom)
|
|
2395 DET_RESULT (st, utf_8_bom) = DET_NEAR_CERTAINTY;
|
|
2396 else
|
|
2397 {
|
|
2398 if (data->seen_really_bogus_utf8 ||
|
|
2399 data->seen_bogus_utf8 >= 2)
|
|
2400 ; /* bogus */
|
|
2401 else if (data->seen_bogus_utf8)
|
|
2402 DET_RESULT (st, utf_8) = DET_SOMEWHAT_UNLIKELY;
|
|
2403 else if ((data->seen_longer_sequence >= 5 ||
|
|
2404 data->seen_2byte_sequence >= 10) &&
|
|
2405 (!(data->seen_iso2022_esc + data->seen_iso_shift) ||
|
|
2406 (data->seen_longer_sequence * 2 + data->seen_2byte_sequence) /
|
|
2407 (data->seen_iso2022_esc + data->seen_iso_shift) >= 10))
|
|
2408 /* heuristics, heuristics, we love heuristics */
|
|
2409 DET_RESULT (st, utf_8) = DET_QUITE_PROBABLE;
|
|
2410 else if (data->seen_iso2022_esc ||
|
|
2411 data->seen_iso_shift >= 3)
|
|
2412 DET_RESULT (st, utf_8) = DET_SOMEWHAT_UNLIKELY;
|
|
2413 else if (data->seen_longer_sequence ||
|
|
2414 data->seen_2byte_sequence)
|
|
2415 DET_RESULT (st, utf_8) = DET_SOMEWHAT_LIKELY;
|
|
2416 else if (data->seen_iso_shift)
|
|
2417 DET_RESULT (st, utf_8) = DET_SOMEWHAT_UNLIKELY;
|
|
2418 else
|
|
2419 DET_RESULT (st, utf_8) = DET_AS_LIKELY_AS_UNLIKELY;
|
|
2420 }
|
771
|
2421 }
|
|
2422
|
|
2423 static void
|
|
2424 unicode_init_coding_stream (struct coding_stream *str)
|
|
2425 {
|
|
2426 struct unicode_coding_stream *data =
|
|
2427 CODING_STREAM_TYPE_DATA (str, unicode);
|
|
2428 xzero (*data);
|
|
2429 data->current_charset = Qnil;
|
|
2430 }
|
|
2431
|
|
2432 static void
|
|
2433 unicode_rewind_coding_stream (struct coding_stream *str)
|
|
2434 {
|
|
2435 unicode_init_coding_stream (str);
|
|
2436 }
|
|
2437
|
|
2438 static int
|
|
2439 unicode_putprop (Lisp_Object codesys, Lisp_Object key, Lisp_Object value)
|
|
2440 {
|
3767
|
2441 if (EQ (key, Qunicode_type))
|
771
|
2442 {
|
|
2443 enum unicode_type type;
|
|
2444
|
|
2445 if (EQ (value, Qutf_8))
|
|
2446 type = UNICODE_UTF_8;
|
|
2447 else if (EQ (value, Qutf_16))
|
|
2448 type = UNICODE_UTF_16;
|
|
2449 else if (EQ (value, Qutf_7))
|
|
2450 type = UNICODE_UTF_7;
|
|
2451 else if (EQ (value, Qucs_4))
|
|
2452 type = UNICODE_UCS_4;
|
|
2453 else
|
|
2454 invalid_constant ("Invalid Unicode type", key);
|
|
2455
|
|
2456 XCODING_SYSTEM_UNICODE_TYPE (codesys) = type;
|
|
2457 }
|
|
2458 else if (EQ (key, Qlittle_endian))
|
|
2459 XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN (codesys) = !NILP (value);
|
|
2460 else if (EQ (key, Qneed_bom))
|
|
2461 XCODING_SYSTEM_UNICODE_NEED_BOM (codesys) = !NILP (value);
|
|
2462 else
|
|
2463 return 0;
|
|
2464 return 1;
|
|
2465 }
|
|
2466
|
|
2467 static Lisp_Object
|
|
2468 unicode_getprop (Lisp_Object coding_system, Lisp_Object prop)
|
|
2469 {
|
3767
|
2470 if (EQ (prop, Qunicode_type))
|
771
|
2471 {
|
|
2472 switch (XCODING_SYSTEM_UNICODE_TYPE (coding_system))
|
|
2473 {
|
|
2474 case UNICODE_UTF_16: return Qutf_16;
|
|
2475 case UNICODE_UTF_8: return Qutf_8;
|
|
2476 case UNICODE_UTF_7: return Qutf_7;
|
|
2477 case UNICODE_UCS_4: return Qucs_4;
|
2500
|
2478 default: ABORT ();
|
771
|
2479 }
|
|
2480 }
|
|
2481 else if (EQ (prop, Qlittle_endian))
|
|
2482 return XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN (coding_system) ? Qt : Qnil;
|
|
2483 else if (EQ (prop, Qneed_bom))
|
|
2484 return XCODING_SYSTEM_UNICODE_NEED_BOM (coding_system) ? Qt : Qnil;
|
|
2485 return Qunbound;
|
|
2486 }
|
|
2487
|
|
2488 static void
|
2286
|
2489 unicode_print (Lisp_Object cs, Lisp_Object printcharfun,
|
|
2490 int UNUSED (escapeflag))
|
771
|
2491 {
|
3767
|
2492 write_fmt_string_lisp (printcharfun, "(%s", 1,
|
|
2493 unicode_getprop (cs, Qunicode_type));
|
771
|
2494 if (XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN (cs))
|
826
|
2495 write_c_string (printcharfun, ", little-endian");
|
771
|
2496 if (XCODING_SYSTEM_UNICODE_NEED_BOM (cs))
|
826
|
2497 write_c_string (printcharfun, ", need-bom");
|
|
2498 write_c_string (printcharfun, ")");
|
771
|
2499 }
|
|
2500
|
|
2501 int
|
2286
|
2502 dfc_coding_system_is_unicode (
|
|
2503 #ifdef WIN32_ANY
|
|
2504 Lisp_Object codesys
|
|
2505 #else
|
|
2506 Lisp_Object UNUSED (codesys)
|
|
2507 #endif
|
|
2508 )
|
771
|
2509 {
|
1315
|
2510 #ifdef WIN32_ANY
|
771
|
2511 codesys = Fget_coding_system (codesys);
|
|
2512 return (EQ (XCODING_SYSTEM_TYPE (codesys), Qunicode) &&
|
|
2513 XCODING_SYSTEM_UNICODE_TYPE (codesys) == UNICODE_UTF_16 &&
|
|
2514 XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN (codesys));
|
|
2515
|
|
2516 #else
|
|
2517 return 0;
|
|
2518 #endif
|
|
2519 }
|
|
2520
|
|
2521
|
|
2522 /************************************************************************/
|
|
2523 /* Initialization */
|
|
2524 /************************************************************************/
|
|
2525
|
|
2526 void
|
|
2527 syms_of_unicode (void)
|
|
2528 {
|
|
2529 #ifdef MULE
|
877
|
2530 DEFSUBR (Funicode_precedence_list);
|
771
|
2531 DEFSUBR (Fset_language_unicode_precedence_list);
|
|
2532 DEFSUBR (Flanguage_unicode_precedence_list);
|
|
2533 DEFSUBR (Fset_default_unicode_precedence_list);
|
|
2534 DEFSUBR (Fdefault_unicode_precedence_list);
|
|
2535 DEFSUBR (Fset_unicode_conversion);
|
|
2536
|
1318
|
2537 DEFSUBR (Fload_unicode_mapping_table);
|
771
|
2538
|
3439
|
2539 DEFSYMBOL (Qccl_encode_to_ucs_2);
|
|
2540 DEFSYMBOL (Qlast_allocated_character);
|
771
|
2541 DEFSYMBOL (Qignore_first_column);
|
3659
|
2542
|
|
2543 DEFSYMBOL (Qunicode_registries);
|
771
|
2544 #endif /* MULE */
|
|
2545
|
800
|
2546 DEFSUBR (Fchar_to_unicode);
|
|
2547 DEFSUBR (Funicode_to_char);
|
771
|
2548
|
|
2549 DEFSYMBOL (Qunicode);
|
|
2550 DEFSYMBOL (Qucs_4);
|
|
2551 DEFSYMBOL (Qutf_16);
|
|
2552 DEFSYMBOL (Qutf_8);
|
|
2553 DEFSYMBOL (Qutf_7);
|
|
2554
|
|
2555 DEFSYMBOL (Qneed_bom);
|
|
2556
|
|
2557 DEFSYMBOL (Qutf_16);
|
|
2558 DEFSYMBOL (Qutf_16_little_endian);
|
|
2559 DEFSYMBOL (Qutf_16_bom);
|
|
2560 DEFSYMBOL (Qutf_16_little_endian_bom);
|
985
|
2561
|
|
2562 DEFSYMBOL (Qutf_8);
|
|
2563 DEFSYMBOL (Qutf_8_bom);
|
771
|
2564 }
|
|
2565
|
|
2566 void
|
|
2567 coding_system_type_create_unicode (void)
|
|
2568 {
|
|
2569 INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA (unicode, "unicode-coding-system-p");
|
|
2570 CODING_SYSTEM_HAS_METHOD (unicode, print);
|
|
2571 CODING_SYSTEM_HAS_METHOD (unicode, convert);
|
|
2572 CODING_SYSTEM_HAS_METHOD (unicode, init_coding_stream);
|
|
2573 CODING_SYSTEM_HAS_METHOD (unicode, rewind_coding_stream);
|
|
2574 CODING_SYSTEM_HAS_METHOD (unicode, putprop);
|
|
2575 CODING_SYSTEM_HAS_METHOD (unicode, getprop);
|
|
2576
|
|
2577 INITIALIZE_DETECTOR (utf_8);
|
|
2578 DETECTOR_HAS_METHOD (utf_8, detect);
|
|
2579 INITIALIZE_DETECTOR_CATEGORY (utf_8, utf_8);
|
985
|
2580 INITIALIZE_DETECTOR_CATEGORY (utf_8, utf_8_bom);
|
771
|
2581
|
|
2582 INITIALIZE_DETECTOR (ucs_4);
|
|
2583 DETECTOR_HAS_METHOD (ucs_4, detect);
|
|
2584 INITIALIZE_DETECTOR_CATEGORY (ucs_4, ucs_4);
|
|
2585
|
|
2586 INITIALIZE_DETECTOR (utf_16);
|
|
2587 DETECTOR_HAS_METHOD (utf_16, detect);
|
|
2588 INITIALIZE_DETECTOR_CATEGORY (utf_16, utf_16);
|
|
2589 INITIALIZE_DETECTOR_CATEGORY (utf_16, utf_16_little_endian);
|
|
2590 INITIALIZE_DETECTOR_CATEGORY (utf_16, utf_16_bom);
|
|
2591 INITIALIZE_DETECTOR_CATEGORY (utf_16, utf_16_little_endian_bom);
|
|
2592 }
|
|
2593
|
|
2594 void
|
|
2595 reinit_coding_system_type_create_unicode (void)
|
|
2596 {
|
|
2597 REINITIALIZE_CODING_SYSTEM_TYPE (unicode);
|
|
2598 }
|
|
2599
|
|
2600 void
|
|
2601 vars_of_unicode (void)
|
|
2602 {
|
|
2603 Fprovide (intern ("unicode"));
|
|
2604
|
|
2605 #ifdef MULE
|
|
2606 staticpro (&Vlanguage_unicode_precedence_list);
|
|
2607 Vlanguage_unicode_precedence_list = Qnil;
|
|
2608
|
|
2609 staticpro (&Vdefault_unicode_precedence_list);
|
|
2610 Vdefault_unicode_precedence_list = Qnil;
|
|
2611
|
|
2612 unicode_precedence_dynarr = Dynarr_new (Lisp_Object);
|
2367
|
2613 dump_add_root_block_ptr (&unicode_precedence_dynarr,
|
771
|
2614 &lisp_object_dynarr_description);
|
2367
|
2615
|
3659
|
2616
|
|
2617
|
2367
|
2618 init_blank_unicode_tables ();
|
|
2619
|
3439
|
2620 staticpro (&Vcurrent_jit_charset);
|
|
2621 Vcurrent_jit_charset = Qnil;
|
|
2622
|
2367
|
2623 /* Note that the "block" we are describing is a single pointer, and hence
|
|
2624 we could potentially use dump_add_root_block_ptr(). However, given
|
|
2625 the way the descriptions are written, we couldn't use them, and would
|
|
2626 have to write new descriptions for each of the pointers below, since
|
|
2627 we would have to make use of a description with an XD_BLOCK_ARRAY
|
|
2628 in it. */
|
|
2629
|
|
2630 dump_add_root_block (&to_unicode_blank_1, sizeof (void *),
|
|
2631 to_unicode_level_1_desc_1);
|
|
2632 dump_add_root_block (&to_unicode_blank_2, sizeof (void *),
|
|
2633 to_unicode_level_2_desc_1);
|
|
2634
|
|
2635 dump_add_root_block (&from_unicode_blank_1, sizeof (void *),
|
|
2636 from_unicode_level_1_desc_1);
|
|
2637 dump_add_root_block (&from_unicode_blank_2, sizeof (void *),
|
|
2638 from_unicode_level_2_desc_1);
|
|
2639 dump_add_root_block (&from_unicode_blank_3, sizeof (void *),
|
|
2640 from_unicode_level_3_desc_1);
|
|
2641 dump_add_root_block (&from_unicode_blank_4, sizeof (void *),
|
|
2642 from_unicode_level_4_desc_1);
|
3659
|
2643
|
|
2644 DEFVAR_LISP ("unicode-registries", &Qunicode_registries /*
|
|
2645 Vector describing the X11 registries searched when using fallback fonts.
|
|
2646
|
|
2647 "Fallback fonts" here includes by default those fonts used by redisplay when
|
|
2648 displaying charsets for which the `encode-as-utf-8' property is true, and
|
|
2649 those used when no font matching the charset's registries property has been
|
|
2650 found (that is, they're probably Mule-specific charsets like Ethiopic or
|
|
2651 IPA.)
|
|
2652 */ );
|
|
2653 Qunicode_registries = vector1(build_string("iso10646-1"));
|
771
|
2654 #endif /* MULE */
|
|
2655 }
|