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