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