428
|
1 /* Functions to handle multilingual characters.
|
|
2 Copyright (C) 1992, 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
771
|
4 Copyright (C) 2001, 2002 Ben Wing.
|
428
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: FSF 20.3. Not in FSF. */
|
|
24
|
|
25 /* Rewritten by Ben Wing <ben@xemacs.org>. */
|
|
26
|
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29
|
|
30 #include "buffer.h"
|
|
31 #include "chartab.h"
|
|
32 #include "elhash.h"
|
|
33 #include "device.h"
|
|
34 #include "faces.h"
|
771
|
35 #include "lstream.h"
|
428
|
36 #include "mule-ccl.h"
|
872
|
37 #include "objects.h"
|
428
|
38
|
|
39 /* The various pre-defined charsets. */
|
|
40
|
|
41 Lisp_Object Vcharset_ascii;
|
|
42 Lisp_Object Vcharset_control_1;
|
|
43 Lisp_Object Vcharset_latin_iso8859_1;
|
|
44 Lisp_Object Vcharset_latin_iso8859_2;
|
|
45 Lisp_Object Vcharset_latin_iso8859_3;
|
|
46 Lisp_Object Vcharset_latin_iso8859_4;
|
|
47 Lisp_Object Vcharset_thai_tis620;
|
|
48 Lisp_Object Vcharset_greek_iso8859_7;
|
|
49 Lisp_Object Vcharset_arabic_iso8859_6;
|
|
50 Lisp_Object Vcharset_hebrew_iso8859_8;
|
|
51 Lisp_Object Vcharset_katakana_jisx0201;
|
|
52 Lisp_Object Vcharset_latin_jisx0201;
|
|
53 Lisp_Object Vcharset_cyrillic_iso8859_5;
|
|
54 Lisp_Object Vcharset_latin_iso8859_9;
|
728
|
55 Lisp_Object Vcharset_latin_iso8859_15;
|
428
|
56 Lisp_Object Vcharset_japanese_jisx0208_1978;
|
|
57 Lisp_Object Vcharset_chinese_gb2312;
|
|
58 Lisp_Object Vcharset_japanese_jisx0208;
|
|
59 Lisp_Object Vcharset_korean_ksc5601;
|
|
60 Lisp_Object Vcharset_japanese_jisx0212;
|
|
61 Lisp_Object Vcharset_chinese_cns11643_1;
|
|
62 Lisp_Object Vcharset_chinese_cns11643_2;
|
|
63 Lisp_Object Vcharset_chinese_big5_1;
|
|
64 Lisp_Object Vcharset_chinese_big5_2;
|
|
65 Lisp_Object Vcharset_composite;
|
|
66
|
|
67 struct charset_lookup *chlook;
|
|
68
|
1204
|
69 static const struct memory_description charset_lookup_description_1[] = {
|
771
|
70 { XD_LISP_OBJECT_ARRAY, offsetof (struct charset_lookup, charset_by_leading_byte), NUM_LEADING_BYTES+4*128*2 },
|
428
|
71 { XD_END }
|
|
72 };
|
|
73
|
1204
|
74 static const struct sized_memory_description charset_lookup_description = {
|
440
|
75 sizeof (struct charset_lookup),
|
428
|
76 charset_lookup_description_1
|
|
77 };
|
|
78
|
|
79 Lisp_Object Qcharsetp;
|
|
80
|
|
81 /* Qdoc_string, Qdimension, Qchars defined in general.c */
|
|
82 Lisp_Object Qregistry, Qfinal, Qgraphic;
|
|
83 Lisp_Object Qdirection;
|
|
84 Lisp_Object Qreverse_direction_charset;
|
|
85 Lisp_Object Qshort_name, Qlong_name;
|
|
86
|
771
|
87 Lisp_Object Qfrom_unicode, Qto_unicode;
|
|
88
|
|
89 Lisp_Object
|
428
|
90 Qlatin_iso8859_1,
|
|
91 Qlatin_iso8859_2,
|
|
92 Qlatin_iso8859_3,
|
|
93 Qlatin_iso8859_4,
|
|
94 Qthai_tis620,
|
|
95 Qgreek_iso8859_7,
|
|
96 Qarabic_iso8859_6,
|
|
97 Qhebrew_iso8859_8,
|
|
98 Qkatakana_jisx0201,
|
|
99 Qlatin_jisx0201,
|
|
100 Qcyrillic_iso8859_5,
|
|
101 Qlatin_iso8859_9,
|
728
|
102 Qlatin_iso8859_15,
|
428
|
103 Qjapanese_jisx0208_1978,
|
|
104 Qchinese_gb2312,
|
|
105 Qjapanese_jisx0208,
|
|
106 Qkorean_ksc5601,
|
|
107 Qjapanese_jisx0212,
|
|
108 Qchinese_cns11643_1,
|
|
109 Qchinese_cns11643_2,
|
|
110 Qchinese_big5_1,
|
|
111 Qchinese_big5_2,
|
|
112 Qcomposite;
|
|
113
|
|
114 Lisp_Object Ql2r, Qr2l;
|
|
115
|
|
116 Lisp_Object Vcharset_hash_table;
|
|
117
|
|
118
|
|
119 /************************************************************************/
|
|
120 /* charset object */
|
|
121 /************************************************************************/
|
|
122
|
|
123 static Lisp_Object
|
|
124 mark_charset (Lisp_Object obj)
|
|
125 {
|
440
|
126 Lisp_Charset *cs = XCHARSET (obj);
|
428
|
127
|
|
128 mark_object (cs->short_name);
|
|
129 mark_object (cs->long_name);
|
|
130 mark_object (cs->doc_string);
|
|
131 mark_object (cs->registry);
|
|
132 mark_object (cs->ccl_program);
|
|
133 return cs->name;
|
|
134 }
|
|
135
|
|
136 static void
|
2286
|
137 print_charset (Lisp_Object obj, Lisp_Object printcharfun,
|
|
138 int UNUSED (escapeflag))
|
428
|
139 {
|
440
|
140 Lisp_Charset *cs = XCHARSET (obj);
|
428
|
141
|
|
142 if (print_readably)
|
563
|
143 printing_unreadable_object ("#<charset %s 0x%x>",
|
793
|
144 XSTRING_DATA (XSYMBOL (CHARSET_NAME (cs))->
|
563
|
145 name),
|
|
146 cs->header.uid);
|
428
|
147
|
771
|
148 write_fmt_string_lisp (printcharfun, "#<charset %s %S %S %S", 4,
|
|
149 CHARSET_NAME (cs), CHARSET_SHORT_NAME (cs),
|
|
150 CHARSET_LONG_NAME (cs), CHARSET_DOC_STRING (cs));
|
|
151 write_fmt_string (printcharfun, " %s %s cols=%d g%d final='%c' reg=",
|
|
152 CHARSET_TYPE (cs) == CHARSET_TYPE_94 ? "94" :
|
|
153 CHARSET_TYPE (cs) == CHARSET_TYPE_96 ? "96" :
|
|
154 CHARSET_TYPE (cs) == CHARSET_TYPE_94X94 ? "94x94" :
|
|
155 "96x96",
|
|
156 CHARSET_DIRECTION (cs) == CHARSET_LEFT_TO_RIGHT ? "l2r" :
|
|
157 "r2l",
|
|
158 CHARSET_COLUMNS (cs),
|
|
159 CHARSET_GRAPHIC (cs),
|
|
160 CHARSET_FINAL (cs));
|
428
|
161 print_internal (CHARSET_REGISTRY (cs), printcharfun, 0);
|
771
|
162 write_fmt_string (printcharfun, " 0x%x>", cs->header.uid);
|
|
163 }
|
|
164
|
|
165 static void
|
|
166 finalize_charset (void *header, int for_disksave)
|
|
167 {
|
|
168 /* See mule-charset.h, definition of Lisp_Charset. */
|
|
169 Lisp_Object charset = wrap_charset ((Lisp_Charset *) header);
|
|
170 if (for_disksave && XCHARSET_TO_UNICODE_TABLE (charset))
|
|
171 {
|
|
172 /* Control-1, ASCII, Composite don't have tables */
|
|
173 free_charset_unicode_tables (charset);
|
|
174 XCHARSET_TO_UNICODE_TABLE (charset) = 0;
|
|
175 XCHARSET_FROM_UNICODE_TABLE (charset) = 0;
|
|
176 }
|
428
|
177 }
|
|
178
|
1204
|
179 static const struct memory_description charset_description[] = {
|
|
180 { XD_INT, offsetof (Lisp_Charset, dimension) },
|
|
181 { XD_INT, offsetof (Lisp_Charset, from_unicode_levels) },
|
440
|
182 { XD_LISP_OBJECT, offsetof (Lisp_Charset, name) },
|
|
183 { XD_LISP_OBJECT, offsetof (Lisp_Charset, doc_string) },
|
|
184 { XD_LISP_OBJECT, offsetof (Lisp_Charset, registry) },
|
|
185 { XD_LISP_OBJECT, offsetof (Lisp_Charset, short_name) },
|
|
186 { XD_LISP_OBJECT, offsetof (Lisp_Charset, long_name) },
|
|
187 { XD_LISP_OBJECT, offsetof (Lisp_Charset, reverse_direction_charset) },
|
|
188 { XD_LISP_OBJECT, offsetof (Lisp_Charset, ccl_program) },
|
771
|
189 { XD_UNION, offsetof (Lisp_Charset, to_unicode_table),
|
1204
|
190 XD_INDIRECT (0, 0), &to_unicode_description },
|
771
|
191 { XD_UNION, offsetof (Lisp_Charset, from_unicode_table),
|
1204
|
192 XD_INDIRECT (1, 0), &from_unicode_description },
|
428
|
193 { XD_END }
|
|
194 };
|
|
195
|
934
|
196 DEFINE_LRECORD_IMPLEMENTATION ("charset", charset,
|
|
197 1, /* dumpable flag */
|
|
198 mark_charset, print_charset, finalize_charset,
|
|
199 0, 0, charset_description, Lisp_Charset);
|
428
|
200 /* Make a new charset. */
|
446
|
201 /* #### SJT Should generic properties be allowed? */
|
428
|
202 static Lisp_Object
|
771
|
203 make_charset (int id, Lisp_Object name, int rep_bytes,
|
|
204 int type, int columns, int graphic,
|
867
|
205 Ibyte final, int direction, Lisp_Object short_name,
|
428
|
206 Lisp_Object long_name, Lisp_Object doc,
|
771
|
207 Lisp_Object reg, int overwrite)
|
428
|
208 {
|
|
209 Lisp_Object obj;
|
771
|
210 Lisp_Charset *cs;
|
|
211
|
|
212 if (!overwrite)
|
|
213 {
|
|
214 cs = alloc_lcrecord_type (Lisp_Charset, &lrecord_charset);
|
793
|
215 obj = wrap_charset (cs);
|
771
|
216
|
|
217 if (final)
|
|
218 {
|
|
219 /* some charsets do not have final characters. This includes
|
|
220 ASCII, Control-1, Composite, and the two faux private
|
|
221 charsets. */
|
|
222 assert (NILP (chlook->
|
|
223 charset_by_attributes[type][final][direction]));
|
|
224 chlook->charset_by_attributes[type][final][direction] = obj;
|
|
225 }
|
440
|
226
|
771
|
227 assert (NILP (chlook->charset_by_leading_byte[id - MIN_LEADING_BYTE]));
|
|
228 chlook->charset_by_leading_byte[id - MIN_LEADING_BYTE] = obj;
|
|
229 }
|
|
230 else
|
|
231 {
|
|
232 Lisp_Object ret;
|
|
233 /* Actually overwrite the properties of the existing charset.
|
|
234 We do this because until now charsets could never be "deleted",
|
|
235 so parts of the code don't bother to GC charsets. */
|
|
236 obj = chlook->charset_by_leading_byte[id - MIN_LEADING_BYTE];
|
|
237 cs = XCHARSET (obj);
|
|
238 assert (EQ (chlook->charset_by_attributes[type][final][direction],
|
|
239 obj));
|
|
240
|
|
241 ret = Fremhash (XCHARSET_NAME (obj), Vcharset_hash_table);
|
|
242 assert (!NILP (ret));
|
|
243 }
|
428
|
244
|
|
245 CHARSET_ID (cs) = id;
|
|
246 CHARSET_NAME (cs) = name;
|
|
247 CHARSET_SHORT_NAME (cs) = short_name;
|
|
248 CHARSET_LONG_NAME (cs) = long_name;
|
|
249 CHARSET_REP_BYTES (cs) = rep_bytes;
|
|
250 CHARSET_DIRECTION (cs) = direction;
|
|
251 CHARSET_TYPE (cs) = type;
|
|
252 CHARSET_COLUMNS (cs) = columns;
|
|
253 CHARSET_GRAPHIC (cs) = graphic;
|
|
254 CHARSET_FINAL (cs) = final;
|
|
255 CHARSET_DOC_STRING (cs) = doc;
|
|
256 CHARSET_REGISTRY (cs) = reg;
|
|
257 CHARSET_CCL_PROGRAM (cs) = Qnil;
|
|
258 CHARSET_REVERSE_DIRECTION_CHARSET (cs) = Qnil;
|
|
259
|
771
|
260 CHARSET_DIMENSION (cs) = (CHARSET_TYPE (cs) == CHARSET_TYPE_94 ||
|
|
261 CHARSET_TYPE (cs) == CHARSET_TYPE_96) ? 1 : 2;
|
|
262 CHARSET_CHARS (cs) = (CHARSET_TYPE (cs) == CHARSET_TYPE_94 ||
|
|
263 CHARSET_TYPE (cs) == CHARSET_TYPE_94X94) ? 94 : 96;
|
428
|
264
|
771
|
265 if (id == LEADING_BYTE_ASCII || id == LEADING_BYTE_CONTROL_1
|
|
266 #ifdef ENABLE_COMPOSITE_CHARS
|
|
267 || id == LEADING_BYTE_COMPOSITE
|
|
268 #endif
|
|
269 )
|
|
270 assert (!overwrite);
|
|
271 else
|
428
|
272 {
|
771
|
273 if (overwrite)
|
|
274 free_charset_unicode_tables (obj);
|
|
275 init_charset_unicode_tables (obj);
|
428
|
276 }
|
|
277
|
|
278 /* Some charsets are "faux" and don't have names or really exist at
|
|
279 all except in the leading-byte table. */
|
|
280 if (!NILP (name))
|
771
|
281 {
|
|
282 assert (NILP (Fgethash (name, Vcharset_hash_table, Qnil)));
|
|
283 Fputhash (name, obj, Vcharset_hash_table);
|
|
284 }
|
|
285
|
|
286 recalculate_unicode_precedence ();
|
428
|
287 return obj;
|
|
288 }
|
|
289
|
|
290 static int
|
|
291 get_unallocated_leading_byte (int dimension)
|
|
292 {
|
|
293 int lb;
|
|
294
|
|
295 if (dimension == 1)
|
|
296 {
|
771
|
297 if (chlook->next_allocated_1_byte_leading_byte >
|
|
298 MAX_LEADING_BYTE_PRIVATE_1)
|
428
|
299 lb = 0;
|
|
300 else
|
442
|
301 lb = chlook->next_allocated_1_byte_leading_byte++;
|
428
|
302 }
|
|
303 else
|
|
304 {
|
1747
|
305 /* awfully fragile, but correct */
|
|
306 #if MAX_LEADING_BYTE_PRIVATE_2 == 255
|
|
307 if (chlook->next_allocated_2_byte_leading_byte == 0)
|
1749
|
308 #else
|
771
|
309 if (chlook->next_allocated_2_byte_leading_byte >
|
|
310 MAX_LEADING_BYTE_PRIVATE_2)
|
1747
|
311 #endif
|
428
|
312 lb = 0;
|
|
313 else
|
442
|
314 lb = chlook->next_allocated_2_byte_leading_byte++;
|
428
|
315 }
|
|
316
|
|
317 if (!lb)
|
563
|
318 invalid_operation
|
771
|
319 ("No more character sets free for this dimension", make_int (dimension));
|
428
|
320
|
|
321 return lb;
|
|
322 }
|
|
323
|
|
324
|
|
325 /************************************************************************/
|
|
326 /* Basic charset Lisp functions */
|
|
327 /************************************************************************/
|
|
328
|
788
|
329 void
|
|
330 get_charset_limits (Lisp_Object charset, int *low, int *high)
|
|
331 {
|
|
332 Lisp_Charset *cs = XCHARSET (charset);
|
|
333
|
|
334 if (EQ (charset, Vcharset_ascii)) *low = 0, *high = 127;
|
|
335 else if (EQ (charset, Vcharset_control_1)) *low = 0, *high = 31;
|
|
336 else if (CHARSET_CHARS (cs) == 94) *low = 33, *high = 126;
|
|
337 else /* CHARSET_CHARS (cs) == 96) */ *low = 32, *high = 127;
|
|
338 }
|
|
339
|
428
|
340 DEFUN ("charsetp", Fcharsetp, 1, 1, 0, /*
|
|
341 Return non-nil if OBJECT is a charset.
|
|
342 */
|
|
343 (object))
|
|
344 {
|
|
345 return CHARSETP (object) ? Qt : Qnil;
|
|
346 }
|
|
347
|
|
348 DEFUN ("find-charset", Ffind_charset, 1, 1, 0, /*
|
|
349 Retrieve the charset of the given name.
|
|
350 If CHARSET-OR-NAME is a charset object, it is simply returned.
|
|
351 Otherwise, CHARSET-OR-NAME should be a symbol. If there is no such charset,
|
|
352 nil is returned. Otherwise the associated charset object is returned.
|
|
353 */
|
|
354 (charset_or_name))
|
|
355 {
|
|
356 if (CHARSETP (charset_or_name))
|
|
357 return charset_or_name;
|
|
358
|
|
359 CHECK_SYMBOL (charset_or_name);
|
|
360 return Fgethash (charset_or_name, Vcharset_hash_table, Qnil);
|
|
361 }
|
|
362
|
|
363 DEFUN ("get-charset", Fget_charset, 1, 1, 0, /*
|
|
364 Retrieve the charset of the given name.
|
|
365 Same as `find-charset' except an error is signalled if there is no such
|
|
366 charset instead of returning nil.
|
|
367 */
|
|
368 (name))
|
|
369 {
|
|
370 Lisp_Object charset = Ffind_charset (name);
|
|
371
|
|
372 if (NILP (charset))
|
563
|
373 invalid_argument ("No such charset", name);
|
428
|
374 return charset;
|
|
375 }
|
|
376
|
|
377 /* We store the charsets in hash tables with the names as the key and the
|
|
378 actual charset object as the value. Occasionally we need to use them
|
|
379 in a list format. These routines provide us with that. */
|
|
380 struct charset_list_closure
|
|
381 {
|
|
382 Lisp_Object *charset_list;
|
|
383 };
|
|
384
|
|
385 static int
|
2286
|
386 add_charset_to_list_mapper (Lisp_Object UNUSED (key), Lisp_Object value,
|
428
|
387 void *charset_list_closure)
|
|
388 {
|
|
389 /* This function can GC */
|
|
390 struct charset_list_closure *chcl =
|
|
391 (struct charset_list_closure*) charset_list_closure;
|
|
392 Lisp_Object *charset_list = chcl->charset_list;
|
|
393
|
|
394 *charset_list = Fcons (XCHARSET_NAME (value), *charset_list);
|
|
395 return 0;
|
|
396 }
|
|
397
|
|
398 DEFUN ("charset-list", Fcharset_list, 0, 0, 0, /*
|
|
399 Return a list of the names of all defined charsets.
|
|
400 */
|
|
401 ())
|
|
402 {
|
|
403 Lisp_Object charset_list = Qnil;
|
|
404 struct gcpro gcpro1;
|
|
405 struct charset_list_closure charset_list_closure;
|
|
406
|
|
407 GCPRO1 (charset_list);
|
|
408 charset_list_closure.charset_list = &charset_list;
|
|
409 elisp_maphash (add_charset_to_list_mapper, Vcharset_hash_table,
|
|
410 &charset_list_closure);
|
|
411 UNGCPRO;
|
|
412
|
|
413 return charset_list;
|
|
414 }
|
|
415
|
|
416 DEFUN ("charset-name", Fcharset_name, 1, 1, 0, /*
|
444
|
417 Return the name of charset CHARSET.
|
428
|
418 */
|
|
419 (charset))
|
|
420 {
|
|
421 return XCHARSET_NAME (Fget_charset (charset));
|
|
422 }
|
|
423
|
446
|
424 /* #### SJT Should generic properties be allowed? */
|
428
|
425 DEFUN ("make-charset", Fmake_charset, 3, 3, 0, /*
|
|
426 Define a new character set.
|
|
427 This function is for use with Mule support.
|
|
428 NAME is a symbol, the name by which the character set is normally referred.
|
|
429 DOC-STRING is a string describing the character set.
|
|
430 PROPS is a property list, describing the specific nature of the
|
|
431 character set. Recognized properties are:
|
|
432
|
|
433 'short-name Short version of the charset name (ex: Latin-1)
|
|
434 'long-name Long version of the charset name (ex: ISO8859-1 (Latin-1))
|
|
435 'registry A regular expression matching the font registry field for
|
|
436 this character set.
|
|
437 'dimension Number of octets used to index a character in this charset.
|
|
438 Either 1 or 2. Defaults to 1.
|
|
439 'columns Number of columns used to display a character in this charset.
|
|
440 Only used in TTY mode. (Under X, the actual width of a
|
|
441 character can be derived from the font used to display the
|
|
442 characters.) If unspecified, defaults to the dimension
|
|
443 (this is almost always the correct value).
|
|
444 'chars Number of characters in each dimension (94 or 96).
|
|
445 Defaults to 94. Note that if the dimension is 2, the
|
|
446 character set thus described is 94x94 or 96x96.
|
|
447 'final Final byte of ISO 2022 escape sequence. Must be
|
|
448 supplied. Each combination of (DIMENSION, CHARS) defines a
|
|
449 separate namespace for final bytes. Note that ISO
|
|
450 2022 restricts the final byte to the range
|
|
451 0x30 - 0x7E if dimension == 1, and 0x30 - 0x5F if
|
|
452 dimension == 2. Note also that final bytes in the range
|
|
453 0x30 - 0x3F are reserved for user-defined (not official)
|
|
454 character sets.
|
|
455 'graphic 0 (use left half of font on output) or 1 (use right half
|
|
456 of font on output). Defaults to 0. For example, for
|
|
457 a font whose registry is ISO8859-1, the left half
|
|
458 (octets 0x20 - 0x7F) is the `ascii' character set, while
|
|
459 the right half (octets 0xA0 - 0xFF) is the `latin-1'
|
|
460 character set. With 'graphic set to 0, the octets
|
|
461 will have their high bit cleared; with it set to 1,
|
|
462 the octets will have their high bit set.
|
|
463 'direction 'l2r (left-to-right) or 'r2l (right-to-left).
|
|
464 Defaults to 'l2r.
|
|
465 'ccl-program A compiled CCL program used to convert a character in
|
|
466 this charset into an index into the font. This is in
|
|
467 addition to the 'graphic property. The CCL program
|
|
468 is passed the octets of the character, with the high
|
|
469 bit cleared and set depending upon whether the value
|
|
470 of the 'graphic property is 0 or 1.
|
|
471 */
|
|
472 (name, doc_string, props))
|
|
473 {
|
771
|
474 int id, dimension = 1, chars = 94, graphic = 0, columns = -1;
|
867
|
475 Ibyte final = 0;
|
428
|
476 int direction = CHARSET_LEFT_TO_RIGHT;
|
|
477 int type;
|
|
478 Lisp_Object registry = Qnil;
|
771
|
479 Lisp_Object charset = Qnil;
|
428
|
480 Lisp_Object ccl_program = Qnil;
|
|
481 Lisp_Object short_name = Qnil, long_name = Qnil;
|
771
|
482 Lisp_Object existing_charset;
|
|
483 int temporary = UNBOUNDP (name);
|
428
|
484
|
771
|
485 /* NOTE: name == Qunbound is a directive from the iso2022 code to
|
|
486 create a temporary charset for an unknown final. We allow the final
|
|
487 to be overwritten with a real charset later on. */
|
|
488
|
428
|
489 if (!NILP (doc_string))
|
|
490 CHECK_STRING (doc_string);
|
771
|
491 if (!UNBOUNDP (name))
|
|
492 {
|
|
493 CHECK_SYMBOL (name);
|
428
|
494
|
771
|
495 charset = Ffind_charset (name);
|
|
496 if (!NILP (charset))
|
|
497 invalid_operation ("Cannot redefine existing charset", name);
|
|
498 }
|
428
|
499
|
442
|
500 {
|
|
501 EXTERNAL_PROPERTY_LIST_LOOP_3 (keyword, value, props)
|
|
502 {
|
|
503 if (EQ (keyword, Qshort_name))
|
|
504 {
|
|
505 CHECK_STRING (value);
|
|
506 short_name = value;
|
|
507 }
|
428
|
508
|
519
|
509 else if (EQ (keyword, Qlong_name))
|
442
|
510 {
|
|
511 CHECK_STRING (value);
|
|
512 long_name = value;
|
|
513 }
|
428
|
514
|
442
|
515 else if (EQ (keyword, Qdimension))
|
|
516 {
|
|
517 CHECK_INT (value);
|
|
518 dimension = XINT (value);
|
|
519 if (dimension < 1 || dimension > 2)
|
563
|
520 invalid_constant ("Invalid value for 'dimension", value);
|
442
|
521 }
|
428
|
522
|
442
|
523 else if (EQ (keyword, Qchars))
|
|
524 {
|
|
525 CHECK_INT (value);
|
|
526 chars = XINT (value);
|
|
527 if (chars != 94 && chars != 96)
|
563
|
528 invalid_constant ("Invalid value for 'chars", value);
|
442
|
529 }
|
428
|
530
|
442
|
531 else if (EQ (keyword, Qcolumns))
|
|
532 {
|
|
533 CHECK_INT (value);
|
|
534 columns = XINT (value);
|
|
535 if (columns != 1 && columns != 2)
|
563
|
536 invalid_constant ("Invalid value for 'columns", value);
|
442
|
537 }
|
428
|
538
|
442
|
539 else if (EQ (keyword, Qgraphic))
|
|
540 {
|
|
541 CHECK_INT (value);
|
|
542 graphic = XINT (value);
|
|
543 if (graphic < 0 || graphic > 1)
|
563
|
544 invalid_constant ("Invalid value for 'graphic", value);
|
442
|
545 }
|
428
|
546
|
442
|
547 else if (EQ (keyword, Qregistry))
|
|
548 {
|
|
549 CHECK_STRING (value);
|
|
550 registry = value;
|
|
551 }
|
428
|
552
|
442
|
553 else if (EQ (keyword, Qdirection))
|
|
554 {
|
|
555 if (EQ (value, Ql2r))
|
|
556 direction = CHARSET_LEFT_TO_RIGHT;
|
|
557 else if (EQ (value, Qr2l))
|
|
558 direction = CHARSET_RIGHT_TO_LEFT;
|
|
559 else
|
563
|
560 invalid_constant ("Invalid value for 'direction", value);
|
442
|
561 }
|
428
|
562
|
442
|
563 else if (EQ (keyword, Qfinal))
|
|
564 {
|
|
565 CHECK_CHAR_COERCE_INT (value);
|
|
566 final = XCHAR (value);
|
|
567 if (final < '0' || final > '~')
|
563
|
568 invalid_constant ("Invalid value for 'final", value);
|
442
|
569 }
|
428
|
570
|
442
|
571 else if (EQ (keyword, Qccl_program))
|
|
572 {
|
444
|
573 struct ccl_program test_ccl;
|
|
574
|
|
575 if (setup_ccl_program (&test_ccl, value) < 0)
|
563
|
576 invalid_argument ("Invalid value for 'ccl-program", value);
|
442
|
577 ccl_program = value;
|
|
578 }
|
|
579 else
|
563
|
580 invalid_constant ("Unrecognized property", keyword);
|
442
|
581 }
|
|
582 }
|
428
|
583
|
|
584 if (!final)
|
563
|
585 invalid_argument ("'final must be specified", Qunbound);
|
428
|
586 if (dimension == 2 && final > 0x5F)
|
563
|
587 invalid_constant
|
428
|
588 ("Final must be in the range 0x30 - 0x5F for dimension == 2",
|
|
589 make_char (final));
|
|
590
|
|
591 if (dimension == 1)
|
|
592 type = (chars == 94) ? CHARSET_TYPE_94 : CHARSET_TYPE_96;
|
|
593 else
|
|
594 type = (chars == 94) ? CHARSET_TYPE_94X94 : CHARSET_TYPE_96X96;
|
|
595
|
826
|
596 existing_charset = charset_by_attributes (type, final, direction);
|
771
|
597
|
|
598 if (!NILP (existing_charset) && !XCHARSET (existing_charset)->temporary)
|
578
|
599 invalid_argument
|
793
|
600 ("Character set already defined for this DIMENSION/CHARS/FINAL/DIRECTION combo",
|
771
|
601 existing_charset);
|
|
602
|
|
603 if (!NILP (existing_charset))
|
|
604 /* Reuse same leading byte */
|
|
605 id = XCHARSET_ID (existing_charset);
|
|
606 else
|
|
607 id = get_unallocated_leading_byte (dimension);
|
428
|
608
|
771
|
609 if (temporary)
|
|
610 {
|
867
|
611 Ibyte tempname[80];
|
428
|
612
|
771
|
613 qxesprintf (tempname, "___temporary___%d__", id);
|
|
614 name = intern_int (tempname);
|
|
615 }
|
428
|
616 if (NILP (doc_string))
|
|
617 doc_string = build_string ("");
|
|
618 if (NILP (registry))
|
|
619 registry = build_string ("");
|
|
620 if (NILP (short_name))
|
793
|
621 short_name = XSYMBOL (name)->name;
|
428
|
622 if (NILP (long_name))
|
|
623 long_name = doc_string;
|
|
624 if (columns == -1)
|
|
625 columns = dimension;
|
771
|
626
|
428
|
627 charset = make_charset (id, name, dimension + 2, type, columns, graphic,
|
771
|
628 final, direction, short_name, long_name,
|
|
629 doc_string, registry, !NILP (existing_charset));
|
|
630
|
|
631 XCHARSET (charset)->temporary = temporary;
|
428
|
632 if (!NILP (ccl_program))
|
|
633 XCHARSET_CCL_PROGRAM (charset) = ccl_program;
|
771
|
634
|
793
|
635 {
|
|
636 Lisp_Object revdircs =
|
826
|
637 charset_by_attributes (type, final,
|
793
|
638 direction == CHARSET_LEFT_TO_RIGHT ?
|
|
639 CHARSET_RIGHT_TO_LEFT : CHARSET_LEFT_TO_RIGHT);
|
|
640 if (!NILP (revdircs))
|
|
641 {
|
|
642 XCHARSET_REVERSE_DIRECTION_CHARSET (revdircs) = charset;
|
|
643 XCHARSET_REVERSE_DIRECTION_CHARSET (charset) = revdircs;
|
|
644 }
|
|
645 }
|
|
646
|
428
|
647 return charset;
|
|
648 }
|
|
649
|
|
650 DEFUN ("make-reverse-direction-charset", Fmake_reverse_direction_charset,
|
|
651 2, 2, 0, /*
|
|
652 Make a charset equivalent to CHARSET but which goes in the opposite direction.
|
|
653 NEW-NAME is the name of the new charset. Return the new charset.
|
|
654 */
|
|
655 (charset, new_name))
|
|
656 {
|
|
657 Lisp_Object new_charset = Qnil;
|
771
|
658 int id, dimension, columns, graphic;
|
867
|
659 Ibyte final;
|
428
|
660 int direction, type;
|
|
661 Lisp_Object registry, doc_string, short_name, long_name;
|
440
|
662 Lisp_Charset *cs;
|
428
|
663
|
|
664 charset = Fget_charset (charset);
|
|
665 if (!NILP (XCHARSET_REVERSE_DIRECTION_CHARSET (charset)))
|
563
|
666 invalid_operation ("Charset already has reverse-direction charset",
|
793
|
667 charset);
|
428
|
668
|
|
669 CHECK_SYMBOL (new_name);
|
|
670 if (!NILP (Ffind_charset (new_name)))
|
563
|
671 invalid_operation ("Cannot redefine existing charset", new_name);
|
428
|
672
|
|
673 cs = XCHARSET (charset);
|
|
674
|
|
675 type = CHARSET_TYPE (cs);
|
|
676 columns = CHARSET_COLUMNS (cs);
|
|
677 dimension = CHARSET_DIMENSION (cs);
|
|
678 id = get_unallocated_leading_byte (dimension);
|
|
679
|
|
680 graphic = CHARSET_GRAPHIC (cs);
|
|
681 final = CHARSET_FINAL (cs);
|
|
682 direction = CHARSET_RIGHT_TO_LEFT;
|
|
683 if (CHARSET_DIRECTION (cs) == CHARSET_RIGHT_TO_LEFT)
|
|
684 direction = CHARSET_LEFT_TO_RIGHT;
|
|
685 doc_string = CHARSET_DOC_STRING (cs);
|
|
686 short_name = CHARSET_SHORT_NAME (cs);
|
|
687 long_name = CHARSET_LONG_NAME (cs);
|
|
688 registry = CHARSET_REGISTRY (cs);
|
|
689
|
|
690 new_charset = make_charset (id, new_name, dimension + 2, type, columns,
|
|
691 graphic, final, direction, short_name, long_name,
|
771
|
692 doc_string, registry, 0);
|
428
|
693
|
|
694 CHARSET_REVERSE_DIRECTION_CHARSET (cs) = new_charset;
|
|
695 XCHARSET_REVERSE_DIRECTION_CHARSET (new_charset) = charset;
|
|
696
|
|
697 return new_charset;
|
|
698 }
|
|
699
|
|
700 DEFUN ("charset-reverse-direction-charset", Fcharset_reverse_direction_charset,
|
|
701 1, 1, 0, /*
|
|
702 Return the reverse-direction charset parallel to CHARSET, if any.
|
|
703 This is the charset with the same properties (in particular, the same
|
|
704 dimension, number of characters per dimension, and final byte) as
|
|
705 CHARSET but whose characters are displayed in the opposite direction.
|
|
706 */
|
|
707 (charset))
|
|
708 {
|
|
709 charset = Fget_charset (charset);
|
|
710 return XCHARSET_REVERSE_DIRECTION_CHARSET (charset);
|
|
711 }
|
|
712
|
|
713 DEFUN ("charset-from-attributes", Fcharset_from_attributes, 3, 4, 0, /*
|
|
714 Return a charset with the given DIMENSION, CHARS, FINAL, and DIRECTION.
|
|
715 If DIRECTION is omitted, both directions will be checked (left-to-right
|
|
716 will be returned if character sets exist for both directions).
|
|
717 */
|
|
718 (dimension, chars, final, direction))
|
|
719 {
|
|
720 int dm, ch, fi, di = -1;
|
|
721 int type;
|
|
722 Lisp_Object obj = Qnil;
|
|
723
|
|
724 CHECK_INT (dimension);
|
|
725 dm = XINT (dimension);
|
|
726 if (dm < 1 || dm > 2)
|
563
|
727 invalid_constant ("Invalid value for DIMENSION", dimension);
|
428
|
728
|
|
729 CHECK_INT (chars);
|
|
730 ch = XINT (chars);
|
|
731 if (ch != 94 && ch != 96)
|
563
|
732 invalid_constant ("Invalid value for CHARS", chars);
|
428
|
733
|
|
734 CHECK_CHAR_COERCE_INT (final);
|
|
735 fi = XCHAR (final);
|
|
736 if (fi < '0' || fi > '~')
|
563
|
737 invalid_constant ("Invalid value for FINAL", final);
|
428
|
738
|
|
739 if (EQ (direction, Ql2r))
|
|
740 di = CHARSET_LEFT_TO_RIGHT;
|
|
741 else if (EQ (direction, Qr2l))
|
|
742 di = CHARSET_RIGHT_TO_LEFT;
|
|
743 else if (!NILP (direction))
|
563
|
744 invalid_constant ("Invalid value for DIRECTION", direction);
|
428
|
745
|
|
746 if (dm == 2 && fi > 0x5F)
|
563
|
747 invalid_constant
|
428
|
748 ("Final must be in the range 0x30 - 0x5F for dimension == 2", final);
|
|
749
|
|
750 if (dm == 1)
|
|
751 type = (ch == 94) ? CHARSET_TYPE_94 : CHARSET_TYPE_96;
|
|
752 else
|
|
753 type = (ch == 94) ? CHARSET_TYPE_94X94 : CHARSET_TYPE_96X96;
|
|
754
|
|
755 if (di == -1)
|
|
756 {
|
826
|
757 obj = charset_by_attributes (type, fi, CHARSET_LEFT_TO_RIGHT);
|
428
|
758 if (NILP (obj))
|
826
|
759 obj = charset_by_attributes (type, fi, CHARSET_RIGHT_TO_LEFT);
|
428
|
760 }
|
|
761 else
|
826
|
762 obj = charset_by_attributes (type, fi, di);
|
428
|
763
|
|
764 if (CHARSETP (obj))
|
|
765 return XCHARSET_NAME (obj);
|
|
766 return obj;
|
|
767 }
|
|
768
|
|
769 DEFUN ("charset-short-name", Fcharset_short_name, 1, 1, 0, /*
|
|
770 Return short name of CHARSET.
|
|
771 */
|
|
772 (charset))
|
|
773 {
|
|
774 return XCHARSET_SHORT_NAME (Fget_charset (charset));
|
|
775 }
|
|
776
|
|
777 DEFUN ("charset-long-name", Fcharset_long_name, 1, 1, 0, /*
|
|
778 Return long name of CHARSET.
|
|
779 */
|
|
780 (charset))
|
|
781 {
|
|
782 return XCHARSET_LONG_NAME (Fget_charset (charset));
|
|
783 }
|
|
784
|
|
785 DEFUN ("charset-description", Fcharset_description, 1, 1, 0, /*
|
|
786 Return description of CHARSET.
|
|
787 */
|
|
788 (charset))
|
|
789 {
|
|
790 return XCHARSET_DOC_STRING (Fget_charset (charset));
|
|
791 }
|
|
792
|
|
793 DEFUN ("charset-dimension", Fcharset_dimension, 1, 1, 0, /*
|
|
794 Return dimension of CHARSET.
|
|
795 */
|
|
796 (charset))
|
|
797 {
|
|
798 return make_int (XCHARSET_DIMENSION (Fget_charset (charset)));
|
|
799 }
|
|
800
|
|
801 DEFUN ("charset-property", Fcharset_property, 2, 2, 0, /*
|
446
|
802 Return property PROP of CHARSET, a charset object or symbol naming a charset.
|
428
|
803 Recognized properties are those listed in `make-charset', as well as
|
|
804 'name and 'doc-string.
|
|
805 */
|
|
806 (charset, prop))
|
|
807 {
|
440
|
808 Lisp_Charset *cs;
|
428
|
809
|
|
810 charset = Fget_charset (charset);
|
|
811 cs = XCHARSET (charset);
|
|
812
|
|
813 CHECK_SYMBOL (prop);
|
|
814 if (EQ (prop, Qname)) return CHARSET_NAME (cs);
|
|
815 if (EQ (prop, Qshort_name)) return CHARSET_SHORT_NAME (cs);
|
|
816 if (EQ (prop, Qlong_name)) return CHARSET_LONG_NAME (cs);
|
|
817 if (EQ (prop, Qdoc_string)) return CHARSET_DOC_STRING (cs);
|
|
818 if (EQ (prop, Qdimension)) return make_int (CHARSET_DIMENSION (cs));
|
|
819 if (EQ (prop, Qcolumns)) return make_int (CHARSET_COLUMNS (cs));
|
|
820 if (EQ (prop, Qgraphic)) return make_int (CHARSET_GRAPHIC (cs));
|
|
821 if (EQ (prop, Qfinal)) return make_char (CHARSET_FINAL (cs));
|
|
822 if (EQ (prop, Qchars)) return make_int (CHARSET_CHARS (cs));
|
|
823 if (EQ (prop, Qregistry)) return CHARSET_REGISTRY (cs);
|
|
824 if (EQ (prop, Qccl_program)) return CHARSET_CCL_PROGRAM (cs);
|
|
825 if (EQ (prop, Qdirection))
|
|
826 return CHARSET_DIRECTION (cs) == CHARSET_LEFT_TO_RIGHT ? Ql2r : Qr2l;
|
|
827 if (EQ (prop, Qreverse_direction_charset))
|
|
828 {
|
|
829 Lisp_Object obj = CHARSET_REVERSE_DIRECTION_CHARSET (cs);
|
446
|
830 /* #### Is this translation OK? If so, error checking sufficient? */
|
|
831 return CHARSETP (obj) ? XCHARSET_NAME (obj) : obj;
|
428
|
832 }
|
563
|
833 invalid_constant ("Unrecognized charset property name", prop);
|
1204
|
834 RETURN_NOT_REACHED (Qnil);
|
428
|
835 }
|
|
836
|
|
837 DEFUN ("charset-id", Fcharset_id, 1, 1, 0, /*
|
|
838 Return charset identification number of CHARSET.
|
|
839 */
|
|
840 (charset))
|
|
841 {
|
793
|
842 return make_int (XCHARSET_LEADING_BYTE (Fget_charset (charset)));
|
428
|
843 }
|
|
844
|
|
845 /* #### We need to figure out which properties we really want to
|
|
846 allow to be set. */
|
|
847
|
|
848 DEFUN ("set-charset-ccl-program", Fset_charset_ccl_program, 2, 2, 0, /*
|
|
849 Set the 'ccl-program property of CHARSET to CCL-PROGRAM.
|
|
850 */
|
|
851 (charset, ccl_program))
|
|
852 {
|
444
|
853 struct ccl_program test_ccl;
|
|
854
|
428
|
855 charset = Fget_charset (charset);
|
444
|
856 if (setup_ccl_program (&test_ccl, ccl_program) < 0)
|
563
|
857 invalid_argument ("Invalid ccl-program", ccl_program);
|
428
|
858 XCHARSET_CCL_PROGRAM (charset) = ccl_program;
|
510
|
859 face_property_was_changed (Vdefault_face, Qfont, Qglobal);
|
428
|
860 return Qnil;
|
|
861 }
|
|
862
|
|
863 /* Japanese folks may want to (set-charset-registry 'ascii "jisx0201") */
|
|
864 DEFUN ("set-charset-registry", Fset_charset_registry, 2, 2, 0, /*
|
|
865 Set the 'registry property of CHARSET to REGISTRY.
|
|
866 */
|
|
867 (charset, registry))
|
|
868 {
|
|
869 charset = Fget_charset (charset);
|
|
870 CHECK_STRING (registry);
|
|
871 XCHARSET_REGISTRY (charset) = registry;
|
|
872 invalidate_charset_font_caches (charset);
|
|
873 face_property_was_changed (Vdefault_face, Qfont, Qglobal);
|
|
874 return Qnil;
|
|
875 }
|
|
876
|
|
877
|
|
878 /************************************************************************/
|
771
|
879 /* memory usage */
|
428
|
880 /************************************************************************/
|
|
881
|
771
|
882 #ifdef MEMORY_USAGE_STATS
|
428
|
883
|
771
|
884 struct charset_stats
|
|
885 {
|
|
886 int from_unicode;
|
|
887 int to_unicode;
|
|
888 int other;
|
|
889 };
|
428
|
890
|
771
|
891 static void
|
|
892 compute_charset_usage (Lisp_Object charset, struct charset_stats *stats,
|
|
893 struct overhead_stats *ovstats)
|
428
|
894 {
|
771
|
895 struct Lisp_Charset *c = XCHARSET (charset);
|
|
896 xzero (*stats);
|
|
897 stats->other += malloced_storage_size (c, sizeof (*c), ovstats);
|
|
898 stats->from_unicode += compute_from_unicode_table_size (charset, ovstats);
|
|
899 stats->to_unicode += compute_to_unicode_table_size (charset, ovstats);
|
438
|
900 }
|
|
901
|
771
|
902 DEFUN ("charset-memory-usage", Fcharset_memory_usage, 1, 1, 0, /*
|
|
903 Return stats about the memory usage of charset CHARSET.
|
|
904 The values returned are in the form of an alist of usage types and
|
|
905 byte counts. The byte counts attempt to encompass all the memory used
|
|
906 by the charset (separate from the memory logically associated with a
|
|
907 charset or frame), including internal structures and any malloc()
|
|
908 overhead associated with them. In practice, the byte counts are
|
|
909 underestimated for various reasons, e.g. because certain memory usage
|
|
910 is very hard to determine \(e.g. the amount of memory used inside the
|
|
911 Xt library or inside the X server).
|
428
|
912
|
771
|
913 Multiple slices of the total memory usage may be returned, separated
|
|
914 by a nil. Each slice represents a particular view of the memory, a
|
|
915 particular way of partitioning it into groups. Within a slice, there
|
|
916 is no overlap between the groups of memory, and each slice collectively
|
|
917 represents all the memory concerned.
|
|
918 */
|
|
919 (charset))
|
|
920 {
|
|
921 struct charset_stats stats;
|
|
922 struct overhead_stats ovstats;
|
|
923 Lisp_Object val = Qnil;
|
428
|
924
|
771
|
925 charset = Fget_charset (charset);
|
|
926 xzero (ovstats);
|
|
927 compute_charset_usage (charset, &stats, &ovstats);
|
428
|
928
|
771
|
929 val = acons (Qfrom_unicode, make_int (stats.from_unicode), val);
|
|
930 val = acons (Qto_unicode, make_int (stats.to_unicode), val);
|
|
931 val = Fcons (Qnil, val);
|
|
932 val = acons (Qactually_requested, make_int (ovstats.was_requested), val);
|
|
933 val = acons (Qmalloc_overhead, make_int (ovstats.malloc_overhead), val);
|
|
934 val = acons (Qgap_overhead, make_int (ovstats.gap_overhead), val);
|
|
935 val = acons (Qdynarr_overhead, make_int (ovstats.dynarr_overhead), val);
|
|
936
|
|
937 return Fnreverse (val);
|
428
|
938 }
|
|
939
|
771
|
940 #endif /* MEMORY_USAGE_STATS */
|
428
|
941
|
|
942
|
|
943 /************************************************************************/
|
|
944 /* initialization */
|
|
945 /************************************************************************/
|
|
946
|
|
947 void
|
|
948 syms_of_mule_charset (void)
|
|
949 {
|
442
|
950 INIT_LRECORD_IMPLEMENTATION (charset);
|
|
951
|
428
|
952 DEFSUBR (Fcharsetp);
|
|
953 DEFSUBR (Ffind_charset);
|
|
954 DEFSUBR (Fget_charset);
|
|
955 DEFSUBR (Fcharset_list);
|
|
956 DEFSUBR (Fcharset_name);
|
|
957 DEFSUBR (Fmake_charset);
|
|
958 DEFSUBR (Fmake_reverse_direction_charset);
|
793
|
959 DEFSUBR (Fcharset_reverse_direction_charset);
|
428
|
960 DEFSUBR (Fcharset_from_attributes);
|
|
961 DEFSUBR (Fcharset_short_name);
|
|
962 DEFSUBR (Fcharset_long_name);
|
|
963 DEFSUBR (Fcharset_description);
|
|
964 DEFSUBR (Fcharset_dimension);
|
|
965 DEFSUBR (Fcharset_property);
|
|
966 DEFSUBR (Fcharset_id);
|
|
967 DEFSUBR (Fset_charset_ccl_program);
|
|
968 DEFSUBR (Fset_charset_registry);
|
|
969
|
771
|
970 #ifdef MEMORY_USAGE_STATS
|
|
971 DEFSUBR (Fcharset_memory_usage);
|
428
|
972 #endif
|
|
973
|
563
|
974 DEFSYMBOL (Qcharsetp);
|
|
975 DEFSYMBOL (Qregistry);
|
|
976 DEFSYMBOL (Qfinal);
|
|
977 DEFSYMBOL (Qgraphic);
|
|
978 DEFSYMBOL (Qdirection);
|
|
979 DEFSYMBOL (Qreverse_direction_charset);
|
|
980 DEFSYMBOL (Qshort_name);
|
|
981 DEFSYMBOL (Qlong_name);
|
428
|
982
|
771
|
983 DEFSYMBOL (Qfrom_unicode);
|
|
984 DEFSYMBOL (Qto_unicode);
|
|
985
|
563
|
986 DEFSYMBOL (Ql2r);
|
|
987 DEFSYMBOL (Qr2l);
|
428
|
988
|
|
989 /* Charsets, compatible with FSF 20.3
|
|
990 Naming convention is Script-Charset[-Edition] */
|
563
|
991 DEFSYMBOL (Qlatin_iso8859_1);
|
|
992 DEFSYMBOL (Qlatin_iso8859_2);
|
|
993 DEFSYMBOL (Qlatin_iso8859_3);
|
|
994 DEFSYMBOL (Qlatin_iso8859_4);
|
|
995 DEFSYMBOL (Qthai_tis620);
|
|
996 DEFSYMBOL (Qgreek_iso8859_7);
|
|
997 DEFSYMBOL (Qarabic_iso8859_6);
|
|
998 DEFSYMBOL (Qhebrew_iso8859_8);
|
|
999 DEFSYMBOL (Qkatakana_jisx0201);
|
|
1000 DEFSYMBOL (Qlatin_jisx0201);
|
|
1001 DEFSYMBOL (Qcyrillic_iso8859_5);
|
|
1002 DEFSYMBOL (Qlatin_iso8859_9);
|
728
|
1003 DEFSYMBOL (Qlatin_iso8859_15);
|
563
|
1004 DEFSYMBOL (Qjapanese_jisx0208_1978);
|
|
1005 DEFSYMBOL (Qchinese_gb2312);
|
|
1006 DEFSYMBOL (Qjapanese_jisx0208);
|
|
1007 DEFSYMBOL (Qkorean_ksc5601);
|
|
1008 DEFSYMBOL (Qjapanese_jisx0212);
|
|
1009 DEFSYMBOL (Qchinese_cns11643_1);
|
|
1010 DEFSYMBOL (Qchinese_cns11643_2);
|
|
1011 DEFSYMBOL (Qchinese_big5_1);
|
|
1012 DEFSYMBOL (Qchinese_big5_2);
|
428
|
1013
|
563
|
1014 DEFSYMBOL (Qcomposite);
|
428
|
1015 }
|
|
1016
|
771
|
1017 static int
|
2286
|
1018 init_charset_unicode_tables_mapper (Lisp_Object UNUSED (key),
|
|
1019 Lisp_Object value, void *UNUSED (closure))
|
771
|
1020 {
|
|
1021 init_charset_unicode_tables (value);
|
|
1022 return 0;
|
|
1023 }
|
|
1024
|
|
1025 void
|
|
1026 init_mule_charset (void)
|
|
1027 {
|
|
1028 /* See mule-charset.h, definition of Lisp_Charset. */
|
|
1029 if (initialized)
|
|
1030 elisp_maphash (init_charset_unicode_tables_mapper, Vcharset_hash_table,
|
|
1031 0);
|
|
1032 }
|
|
1033
|
428
|
1034 void
|
|
1035 vars_of_mule_charset (void)
|
|
1036 {
|
|
1037 int i, j, k;
|
|
1038
|
452
|
1039 chlook = xnew_and_zero (struct charset_lookup); /* zero for Purify. */
|
|
1040 dump_add_root_struct_ptr (&chlook, &charset_lookup_description);
|
428
|
1041
|
|
1042 /* Table of charsets indexed by leading byte. */
|
|
1043 for (i = 0; i < countof (chlook->charset_by_leading_byte); i++)
|
|
1044 chlook->charset_by_leading_byte[i] = Qnil;
|
|
1045
|
|
1046 /* Table of charsets indexed by type/final-byte/direction. */
|
|
1047 for (i = 0; i < countof (chlook->charset_by_attributes); i++)
|
|
1048 for (j = 0; j < countof (chlook->charset_by_attributes[0]); j++)
|
|
1049 for (k = 0; k < countof (chlook->charset_by_attributes[0][0]); k++)
|
|
1050 chlook->charset_by_attributes[i][j][k] = Qnil;
|
|
1051
|
442
|
1052 chlook->next_allocated_1_byte_leading_byte = MIN_LEADING_BYTE_PRIVATE_1;
|
|
1053 chlook->next_allocated_2_byte_leading_byte = MIN_LEADING_BYTE_PRIVATE_2;
|
771
|
1054
|
|
1055 staticpro (&Vcharset_hash_table);
|
|
1056 Vcharset_hash_table =
|
|
1057 make_lisp_hash_table (50, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
|
428
|
1058 }
|
|
1059
|
|
1060 void
|
|
1061 complex_vars_of_mule_charset (void)
|
|
1062 {
|
|
1063 /* Predefined character sets. We store them into variables for
|
|
1064 ease of access. */
|
|
1065
|
|
1066 staticpro (&Vcharset_ascii);
|
|
1067 Vcharset_ascii =
|
|
1068 make_charset (LEADING_BYTE_ASCII, Qascii, 1,
|
|
1069 CHARSET_TYPE_94, 1, 0, 'B',
|
|
1070 CHARSET_LEFT_TO_RIGHT,
|
|
1071 build_string ("ASCII"),
|
771
|
1072 build_msg_string ("ASCII"),
|
|
1073 build_msg_string ("ASCII (ISO646 IRV)"),
|
|
1074 build_string ("\\(iso8859-[0-9]*\\|-ascii\\)"), 0);
|
428
|
1075 staticpro (&Vcharset_control_1);
|
|
1076 Vcharset_control_1 =
|
|
1077 make_charset (LEADING_BYTE_CONTROL_1, Qcontrol_1, 2,
|
|
1078 CHARSET_TYPE_94, 1, 1, 0,
|
|
1079 CHARSET_LEFT_TO_RIGHT,
|
|
1080 build_string ("C1"),
|
771
|
1081 build_msg_string ("Control characters"),
|
|
1082 build_msg_string ("Control characters 128-191"),
|
|
1083 build_string (""), 0);
|
428
|
1084 staticpro (&Vcharset_latin_iso8859_1);
|
|
1085 Vcharset_latin_iso8859_1 =
|
|
1086 make_charset (LEADING_BYTE_LATIN_ISO8859_1, Qlatin_iso8859_1, 2,
|
|
1087 CHARSET_TYPE_96, 1, 1, 'A',
|
|
1088 CHARSET_LEFT_TO_RIGHT,
|
|
1089 build_string ("Latin-1"),
|
771
|
1090 build_msg_string ("ISO8859-1 (Latin-1)"),
|
|
1091 build_msg_string ("ISO8859-1 (Latin-1)"),
|
|
1092 build_string ("iso8859-1"), 0);
|
428
|
1093 staticpro (&Vcharset_latin_iso8859_2);
|
|
1094 Vcharset_latin_iso8859_2 =
|
|
1095 make_charset (LEADING_BYTE_LATIN_ISO8859_2, Qlatin_iso8859_2, 2,
|
|
1096 CHARSET_TYPE_96, 1, 1, 'B',
|
|
1097 CHARSET_LEFT_TO_RIGHT,
|
|
1098 build_string ("Latin-2"),
|
771
|
1099 build_msg_string ("ISO8859-2 (Latin-2)"),
|
|
1100 build_msg_string ("ISO8859-2 (Latin-2)"),
|
|
1101 build_string ("iso8859-2"), 0);
|
428
|
1102 staticpro (&Vcharset_latin_iso8859_3);
|
|
1103 Vcharset_latin_iso8859_3 =
|
|
1104 make_charset (LEADING_BYTE_LATIN_ISO8859_3, Qlatin_iso8859_3, 2,
|
|
1105 CHARSET_TYPE_96, 1, 1, 'C',
|
|
1106 CHARSET_LEFT_TO_RIGHT,
|
|
1107 build_string ("Latin-3"),
|
771
|
1108 build_msg_string ("ISO8859-3 (Latin-3)"),
|
|
1109 build_msg_string ("ISO8859-3 (Latin-3)"),
|
|
1110 build_string ("iso8859-3"), 0);
|
428
|
1111 staticpro (&Vcharset_latin_iso8859_4);
|
|
1112 Vcharset_latin_iso8859_4 =
|
|
1113 make_charset (LEADING_BYTE_LATIN_ISO8859_4, Qlatin_iso8859_4, 2,
|
|
1114 CHARSET_TYPE_96, 1, 1, 'D',
|
|
1115 CHARSET_LEFT_TO_RIGHT,
|
|
1116 build_string ("Latin-4"),
|
771
|
1117 build_msg_string ("ISO8859-4 (Latin-4)"),
|
|
1118 build_msg_string ("ISO8859-4 (Latin-4)"),
|
|
1119 build_string ("iso8859-4"), 0);
|
428
|
1120 staticpro (&Vcharset_thai_tis620);
|
|
1121 Vcharset_thai_tis620 =
|
|
1122 make_charset (LEADING_BYTE_THAI_TIS620, Qthai_tis620, 2,
|
|
1123 CHARSET_TYPE_96, 1, 1, 'T',
|
|
1124 CHARSET_LEFT_TO_RIGHT,
|
|
1125 build_string ("TIS620"),
|
771
|
1126 build_msg_string ("TIS620 (Thai)"),
|
|
1127 build_msg_string ("TIS620.2529 (Thai)"),
|
|
1128 build_string ("tis620"),0);
|
428
|
1129 staticpro (&Vcharset_greek_iso8859_7);
|
|
1130 Vcharset_greek_iso8859_7 =
|
|
1131 make_charset (LEADING_BYTE_GREEK_ISO8859_7, Qgreek_iso8859_7, 2,
|
|
1132 CHARSET_TYPE_96, 1, 1, 'F',
|
|
1133 CHARSET_LEFT_TO_RIGHT,
|
|
1134 build_string ("ISO8859-7"),
|
771
|
1135 build_msg_string ("ISO8859-7 (Greek)"),
|
|
1136 build_msg_string ("ISO8859-7 (Greek)"),
|
|
1137 build_string ("iso8859-7"), 0);
|
428
|
1138 staticpro (&Vcharset_arabic_iso8859_6);
|
|
1139 Vcharset_arabic_iso8859_6 =
|
|
1140 make_charset (LEADING_BYTE_ARABIC_ISO8859_6, Qarabic_iso8859_6, 2,
|
|
1141 CHARSET_TYPE_96, 1, 1, 'G',
|
|
1142 CHARSET_RIGHT_TO_LEFT,
|
|
1143 build_string ("ISO8859-6"),
|
771
|
1144 build_msg_string ("ISO8859-6 (Arabic)"),
|
|
1145 build_msg_string ("ISO8859-6 (Arabic)"),
|
|
1146 build_string ("iso8859-6"), 0);
|
428
|
1147 staticpro (&Vcharset_hebrew_iso8859_8);
|
|
1148 Vcharset_hebrew_iso8859_8 =
|
|
1149 make_charset (LEADING_BYTE_HEBREW_ISO8859_8, Qhebrew_iso8859_8, 2,
|
|
1150 CHARSET_TYPE_96, 1, 1, 'H',
|
|
1151 CHARSET_RIGHT_TO_LEFT,
|
|
1152 build_string ("ISO8859-8"),
|
771
|
1153 build_msg_string ("ISO8859-8 (Hebrew)"),
|
|
1154 build_msg_string ("ISO8859-8 (Hebrew)"),
|
|
1155 build_string ("iso8859-8"), 0);
|
428
|
1156 staticpro (&Vcharset_katakana_jisx0201);
|
|
1157 Vcharset_katakana_jisx0201 =
|
|
1158 make_charset (LEADING_BYTE_KATAKANA_JISX0201, Qkatakana_jisx0201, 2,
|
|
1159 CHARSET_TYPE_94, 1, 1, 'I',
|
|
1160 CHARSET_LEFT_TO_RIGHT,
|
|
1161 build_string ("JISX0201 Kana"),
|
771
|
1162 build_msg_string ("JISX0201.1976 (Japanese Kana)"),
|
|
1163 build_msg_string ("JISX0201.1976 Japanese Kana"),
|
|
1164 build_string ("jisx0201.1976"), 0);
|
428
|
1165 staticpro (&Vcharset_latin_jisx0201);
|
|
1166 Vcharset_latin_jisx0201 =
|
|
1167 make_charset (LEADING_BYTE_LATIN_JISX0201, Qlatin_jisx0201, 2,
|
|
1168 CHARSET_TYPE_94, 1, 0, 'J',
|
|
1169 CHARSET_LEFT_TO_RIGHT,
|
|
1170 build_string ("JISX0201 Roman"),
|
771
|
1171 build_msg_string ("JISX0201.1976 (Japanese Roman)"),
|
|
1172 build_msg_string ("JISX0201.1976 Japanese Roman"),
|
|
1173 build_string ("jisx0201.1976"), 0);
|
428
|
1174 staticpro (&Vcharset_cyrillic_iso8859_5);
|
|
1175 Vcharset_cyrillic_iso8859_5 =
|
|
1176 make_charset (LEADING_BYTE_CYRILLIC_ISO8859_5, Qcyrillic_iso8859_5, 2,
|
|
1177 CHARSET_TYPE_96, 1, 1, 'L',
|
|
1178 CHARSET_LEFT_TO_RIGHT,
|
|
1179 build_string ("ISO8859-5"),
|
771
|
1180 build_msg_string ("ISO8859-5 (Cyrillic)"),
|
|
1181 build_msg_string ("ISO8859-5 (Cyrillic)"),
|
|
1182 build_string ("iso8859-5"), 0);
|
428
|
1183 staticpro (&Vcharset_latin_iso8859_9);
|
|
1184 Vcharset_latin_iso8859_9 =
|
|
1185 make_charset (LEADING_BYTE_LATIN_ISO8859_9, Qlatin_iso8859_9, 2,
|
|
1186 CHARSET_TYPE_96, 1, 1, 'M',
|
|
1187 CHARSET_LEFT_TO_RIGHT,
|
|
1188 build_string ("Latin-5"),
|
771
|
1189 build_msg_string ("ISO8859-9 (Latin-5)"),
|
|
1190 build_msg_string ("ISO8859-9 (Latin-5)"),
|
|
1191 build_string ("iso8859-9"), 0);
|
728
|
1192 staticpro (&Vcharset_latin_iso8859_15);
|
|
1193 Vcharset_latin_iso8859_15 =
|
|
1194 make_charset (LEADING_BYTE_LATIN_ISO8859_15, Qlatin_iso8859_15, 2,
|
|
1195 CHARSET_TYPE_96, 1, 1, 'b',
|
|
1196 CHARSET_LEFT_TO_RIGHT,
|
|
1197 build_string ("Latin-9"),
|
771
|
1198 build_msg_string ("ISO8859-15 (Latin-9)"),
|
|
1199 build_msg_string ("ISO8859-15 (Latin-9)"),
|
|
1200 build_string ("iso8859-15"), 0);
|
428
|
1201 staticpro (&Vcharset_japanese_jisx0208_1978);
|
|
1202 Vcharset_japanese_jisx0208_1978 =
|
|
1203 make_charset (LEADING_BYTE_JAPANESE_JISX0208_1978, Qjapanese_jisx0208_1978, 3,
|
|
1204 CHARSET_TYPE_94X94, 2, 0, '@',
|
|
1205 CHARSET_LEFT_TO_RIGHT,
|
|
1206 build_string ("JISX0208.1978"),
|
771
|
1207 build_msg_string ("JISX0208.1978 (Japanese)"),
|
|
1208 build_msg_string
|
428
|
1209 ("JISX0208.1978 Japanese Kanji (so called \"old JIS\")"),
|
771
|
1210 build_string ("\\(jisx0208\\|jisc6226\\)\\.1978"), 0);
|
428
|
1211 staticpro (&Vcharset_chinese_gb2312);
|
|
1212 Vcharset_chinese_gb2312 =
|
|
1213 make_charset (LEADING_BYTE_CHINESE_GB2312, Qchinese_gb2312, 3,
|
|
1214 CHARSET_TYPE_94X94, 2, 0, 'A',
|
|
1215 CHARSET_LEFT_TO_RIGHT,
|
|
1216 build_string ("GB2312"),
|
771
|
1217 build_msg_string ("GB2312)"),
|
|
1218 build_msg_string ("GB2312 Chinese simplified"),
|
|
1219 build_string ("gb2312"), 0);
|
428
|
1220 staticpro (&Vcharset_japanese_jisx0208);
|
|
1221 Vcharset_japanese_jisx0208 =
|
|
1222 make_charset (LEADING_BYTE_JAPANESE_JISX0208, Qjapanese_jisx0208, 3,
|
|
1223 CHARSET_TYPE_94X94, 2, 0, 'B',
|
|
1224 CHARSET_LEFT_TO_RIGHT,
|
|
1225 build_string ("JISX0208"),
|
771
|
1226 build_msg_string ("JISX0208.1983/1990 (Japanese)"),
|
|
1227 build_msg_string ("JISX0208.1983/1990 Japanese Kanji"),
|
|
1228 build_string ("jisx0208.19\\(83\\|90\\)"), 0);
|
428
|
1229 staticpro (&Vcharset_korean_ksc5601);
|
|
1230 Vcharset_korean_ksc5601 =
|
|
1231 make_charset (LEADING_BYTE_KOREAN_KSC5601, Qkorean_ksc5601, 3,
|
|
1232 CHARSET_TYPE_94X94, 2, 0, 'C',
|
|
1233 CHARSET_LEFT_TO_RIGHT,
|
|
1234 build_string ("KSC5601"),
|
771
|
1235 build_msg_string ("KSC5601 (Korean"),
|
|
1236 build_msg_string ("KSC5601 Korean Hangul and Hanja"),
|
|
1237 build_string ("ksc5601"), 0);
|
428
|
1238 staticpro (&Vcharset_japanese_jisx0212);
|
|
1239 Vcharset_japanese_jisx0212 =
|
|
1240 make_charset (LEADING_BYTE_JAPANESE_JISX0212, Qjapanese_jisx0212, 3,
|
|
1241 CHARSET_TYPE_94X94, 2, 0, 'D',
|
|
1242 CHARSET_LEFT_TO_RIGHT,
|
|
1243 build_string ("JISX0212"),
|
771
|
1244 build_msg_string ("JISX0212 (Japanese)"),
|
|
1245 build_msg_string ("JISX0212 Japanese Supplement"),
|
|
1246 build_string ("jisx0212"), 0);
|
428
|
1247
|
|
1248 #define CHINESE_CNS_PLANE_RE(n) "cns11643[.-]\\(.*[.-]\\)?" n "$"
|
|
1249 staticpro (&Vcharset_chinese_cns11643_1);
|
|
1250 Vcharset_chinese_cns11643_1 =
|
|
1251 make_charset (LEADING_BYTE_CHINESE_CNS11643_1, Qchinese_cns11643_1, 3,
|
|
1252 CHARSET_TYPE_94X94, 2, 0, 'G',
|
|
1253 CHARSET_LEFT_TO_RIGHT,
|
|
1254 build_string ("CNS11643-1"),
|
771
|
1255 build_msg_string ("CNS11643-1 (Chinese traditional)"),
|
|
1256 build_msg_string
|
428
|
1257 ("CNS 11643 Plane 1 Chinese traditional"),
|
771
|
1258 build_string (CHINESE_CNS_PLANE_RE("1")), 0);
|
428
|
1259 staticpro (&Vcharset_chinese_cns11643_2);
|
|
1260 Vcharset_chinese_cns11643_2 =
|
|
1261 make_charset (LEADING_BYTE_CHINESE_CNS11643_2, Qchinese_cns11643_2, 3,
|
|
1262 CHARSET_TYPE_94X94, 2, 0, 'H',
|
|
1263 CHARSET_LEFT_TO_RIGHT,
|
|
1264 build_string ("CNS11643-2"),
|
771
|
1265 build_msg_string ("CNS11643-2 (Chinese traditional)"),
|
|
1266 build_msg_string
|
428
|
1267 ("CNS 11643 Plane 2 Chinese traditional"),
|
771
|
1268 build_string (CHINESE_CNS_PLANE_RE("2")), 0);
|
428
|
1269 staticpro (&Vcharset_chinese_big5_1);
|
|
1270 Vcharset_chinese_big5_1 =
|
|
1271 make_charset (LEADING_BYTE_CHINESE_BIG5_1, Qchinese_big5_1, 3,
|
|
1272 CHARSET_TYPE_94X94, 2, 0, '0',
|
|
1273 CHARSET_LEFT_TO_RIGHT,
|
|
1274 build_string ("Big5"),
|
771
|
1275 build_msg_string ("Big5 (Level-1)"),
|
|
1276 build_msg_string
|
428
|
1277 ("Big5 Level-1 Chinese traditional"),
|
771
|
1278 build_string ("big5"), 0);
|
428
|
1279 staticpro (&Vcharset_chinese_big5_2);
|
|
1280 Vcharset_chinese_big5_2 =
|
|
1281 make_charset (LEADING_BYTE_CHINESE_BIG5_2, Qchinese_big5_2, 3,
|
|
1282 CHARSET_TYPE_94X94, 2, 0, '1',
|
|
1283 CHARSET_LEFT_TO_RIGHT,
|
|
1284 build_string ("Big5"),
|
771
|
1285 build_msg_string ("Big5 (Level-2)"),
|
|
1286 build_msg_string
|
428
|
1287 ("Big5 Level-2 Chinese traditional"),
|
771
|
1288 build_string ("big5"), 0);
|
428
|
1289
|
|
1290
|
|
1291 #ifdef ENABLE_COMPOSITE_CHARS
|
|
1292 /* #### For simplicity, we put composite chars into a 96x96 charset.
|
|
1293 This is going to lead to problems because you can run out of
|
|
1294 room, esp. as we don't yet recycle numbers. */
|
|
1295 staticpro (&Vcharset_composite);
|
|
1296 Vcharset_composite =
|
|
1297 make_charset (LEADING_BYTE_COMPOSITE, Qcomposite, 3,
|
|
1298 CHARSET_TYPE_96X96, 2, 0, 0,
|
|
1299 CHARSET_LEFT_TO_RIGHT,
|
|
1300 build_string ("Composite"),
|
771
|
1301 build_msg_string ("Composite characters"),
|
|
1302 build_msg_string ("Composite characters"),
|
|
1303 build_string (""), 0);
|
|
1304 #else
|
|
1305 /* We create a hack so that we have a way of storing ESC 0 and ESC 1
|
|
1306 sequences as "characters", so that they will be output correctly. */
|
|
1307 staticpro (&Vcharset_composite);
|
|
1308 Vcharset_composite =
|
|
1309 make_charset (LEADING_BYTE_COMPOSITE_REPLACEMENT, Qcomposite, 2,
|
|
1310 CHARSET_TYPE_96, 1, 1, '|',
|
|
1311 CHARSET_LEFT_TO_RIGHT,
|
|
1312 build_string ("Composite hack"),
|
|
1313 build_msg_string ("Composite characters hack"),
|
|
1314 build_msg_string ("Composite characters hack"),
|
|
1315 build_string (""), 0);
|
428
|
1316 #endif /* ENABLE_COMPOSITE_CHARS */
|
|
1317 }
|