428
|
1 /* XEmacs routines to deal with char tables.
|
|
2 Copyright (C) 1992, 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
788
|
4 Copyright (C) 1995, 1996, 2002 Ben Wing.
|
428
|
5 Copyright (C) 1995, 1997, 1999 Electrotechnical Laboratory, JAPAN.
|
|
6 Licensed to the Free Software Foundation.
|
|
7
|
|
8 This file is part of XEmacs.
|
|
9
|
|
10 XEmacs is free software; you can redistribute it and/or modify it
|
|
11 under the terms of the GNU General Public License as published by the
|
|
12 Free Software Foundation; either version 2, or (at your option) any
|
|
13 later version.
|
|
14
|
|
15 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
18 for more details.
|
|
19
|
|
20 You should have received a copy of the GNU General Public License
|
|
21 along with XEmacs; see the file COPYING. If not, write to
|
|
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 Boston, MA 02111-1307, USA. */
|
|
24
|
|
25 /* Synched up with: Mule 2.3. Not synched with FSF.
|
|
26
|
|
27 This file was written independently of the FSF implementation,
|
|
28 and is not compatible. */
|
|
29
|
|
30 /* Authorship:
|
|
31
|
|
32 Ben Wing: wrote, for 19.13 (Mule). Some category table stuff
|
|
33 loosely based on the original Mule.
|
|
34 Jareth Hein: fixed a couple of bugs in the implementation, and
|
|
35 added regex support for categories with check_category_at
|
|
36 */
|
|
37
|
|
38 #include <config.h>
|
|
39 #include "lisp.h"
|
|
40
|
|
41 #include "buffer.h"
|
|
42 #include "chartab.h"
|
|
43 #include "syntax.h"
|
|
44
|
|
45 Lisp_Object Qchar_tablep, Qchar_table;
|
|
46
|
|
47 Lisp_Object Vall_syntax_tables;
|
|
48
|
|
49 #ifdef MULE
|
|
50 Lisp_Object Qcategory_table_p;
|
|
51 Lisp_Object Qcategory_designator_p;
|
|
52 Lisp_Object Qcategory_table_value_p;
|
|
53
|
|
54 Lisp_Object Vstandard_category_table;
|
|
55
|
|
56 /* Variables to determine word boundary. */
|
|
57 Lisp_Object Vword_combining_categories, Vword_separating_categories;
|
|
58 #endif /* MULE */
|
|
59
|
|
60
|
|
61 /* A char table maps from ranges of characters to values.
|
|
62
|
|
63 Implementing a general data structure that maps from arbitrary
|
|
64 ranges of numbers to values is tricky to do efficiently. As it
|
|
65 happens, it should suffice (and is usually more convenient, anyway)
|
|
66 when dealing with characters to restrict the sorts of ranges that
|
|
67 can be assigned values, as follows:
|
|
68
|
|
69 1) All characters.
|
|
70 2) All characters in a charset.
|
|
71 3) All characters in a particular row of a charset, where a "row"
|
|
72 means all characters with the same first byte.
|
|
73 4) A particular character in a charset.
|
|
74
|
|
75 We use char tables to generalize the 256-element vectors now
|
|
76 littering the Emacs code.
|
|
77
|
|
78 Possible uses (all should be converted at some point):
|
|
79
|
|
80 1) category tables
|
|
81 2) syntax tables
|
|
82 3) display tables
|
|
83 4) case tables
|
|
84 5) keyboard-translate-table?
|
|
85
|
|
86 We provide an
|
|
87 abstract type to generalize the Emacs vectors and Mule
|
|
88 vectors-of-vectors goo.
|
|
89 */
|
|
90
|
|
91 /************************************************************************/
|
|
92 /* Char Table object */
|
|
93 /************************************************************************/
|
|
94
|
|
95 #ifdef MULE
|
|
96
|
|
97 static Lisp_Object
|
|
98 mark_char_table_entry (Lisp_Object obj)
|
|
99 {
|
440
|
100 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (obj);
|
428
|
101 int i;
|
|
102
|
|
103 for (i = 0; i < 96; i++)
|
|
104 {
|
|
105 mark_object (cte->level2[i]);
|
|
106 }
|
|
107 return Qnil;
|
|
108 }
|
|
109
|
|
110 static int
|
|
111 char_table_entry_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
112 {
|
440
|
113 Lisp_Char_Table_Entry *cte1 = XCHAR_TABLE_ENTRY (obj1);
|
|
114 Lisp_Char_Table_Entry *cte2 = XCHAR_TABLE_ENTRY (obj2);
|
428
|
115 int i;
|
|
116
|
|
117 for (i = 0; i < 96; i++)
|
|
118 if (!internal_equal (cte1->level2[i], cte2->level2[i], depth + 1))
|
|
119 return 0;
|
|
120
|
|
121 return 1;
|
|
122 }
|
|
123
|
665
|
124 static Hashcode
|
428
|
125 char_table_entry_hash (Lisp_Object obj, int depth)
|
|
126 {
|
440
|
127 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (obj);
|
428
|
128
|
|
129 return internal_array_hash (cte->level2, 96, depth);
|
|
130 }
|
|
131
|
|
132 static const struct lrecord_description char_table_entry_description[] = {
|
440
|
133 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Char_Table_Entry, level2), 96 },
|
428
|
134 { XD_END }
|
|
135 };
|
|
136
|
|
137 DEFINE_LRECORD_IMPLEMENTATION ("char-table-entry", char_table_entry,
|
|
138 mark_char_table_entry, internal_object_printer,
|
|
139 0, char_table_entry_equal,
|
|
140 char_table_entry_hash,
|
|
141 char_table_entry_description,
|
440
|
142 Lisp_Char_Table_Entry);
|
428
|
143 #endif /* MULE */
|
|
144
|
|
145 static Lisp_Object
|
|
146 mark_char_table (Lisp_Object obj)
|
|
147 {
|
440
|
148 Lisp_Char_Table *ct = XCHAR_TABLE (obj);
|
428
|
149 int i;
|
|
150
|
|
151 for (i = 0; i < NUM_ASCII_CHARS; i++)
|
|
152 mark_object (ct->ascii[i]);
|
|
153 #ifdef MULE
|
|
154 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
155 mark_object (ct->level1[i]);
|
|
156 #endif
|
793
|
157 mark_object (ct->parent);
|
|
158 mark_object (ct->default_);
|
428
|
159 return ct->mirror_table;
|
|
160 }
|
|
161
|
|
162 /* WARNING: All functions of this nature need to be written extremely
|
|
163 carefully to avoid crashes during GC. Cf. prune_specifiers()
|
|
164 and prune_weak_hash_tables(). */
|
|
165
|
|
166 void
|
|
167 prune_syntax_tables (void)
|
|
168 {
|
|
169 Lisp_Object rest, prev = Qnil;
|
|
170
|
|
171 for (rest = Vall_syntax_tables;
|
|
172 !NILP (rest);
|
|
173 rest = XCHAR_TABLE (rest)->next_table)
|
|
174 {
|
|
175 if (! marked_p (rest))
|
|
176 {
|
|
177 /* This table is garbage. Remove it from the list. */
|
|
178 if (NILP (prev))
|
|
179 Vall_syntax_tables = XCHAR_TABLE (rest)->next_table;
|
|
180 else
|
|
181 XCHAR_TABLE (prev)->next_table =
|
|
182 XCHAR_TABLE (rest)->next_table;
|
|
183 }
|
|
184 }
|
|
185 }
|
|
186
|
|
187 static Lisp_Object
|
|
188 char_table_type_to_symbol (enum char_table_type type)
|
|
189 {
|
|
190 switch (type)
|
|
191 {
|
|
192 default: abort();
|
|
193 case CHAR_TABLE_TYPE_GENERIC: return Qgeneric;
|
|
194 case CHAR_TABLE_TYPE_SYNTAX: return Qsyntax;
|
|
195 case CHAR_TABLE_TYPE_DISPLAY: return Qdisplay;
|
|
196 case CHAR_TABLE_TYPE_CHAR: return Qchar;
|
|
197 #ifdef MULE
|
|
198 case CHAR_TABLE_TYPE_CATEGORY: return Qcategory;
|
|
199 #endif
|
|
200 }
|
|
201 }
|
|
202
|
|
203 static enum char_table_type
|
|
204 symbol_to_char_table_type (Lisp_Object symbol)
|
|
205 {
|
|
206 CHECK_SYMBOL (symbol);
|
|
207
|
|
208 if (EQ (symbol, Qgeneric)) return CHAR_TABLE_TYPE_GENERIC;
|
|
209 if (EQ (symbol, Qsyntax)) return CHAR_TABLE_TYPE_SYNTAX;
|
|
210 if (EQ (symbol, Qdisplay)) return CHAR_TABLE_TYPE_DISPLAY;
|
|
211 if (EQ (symbol, Qchar)) return CHAR_TABLE_TYPE_CHAR;
|
|
212 #ifdef MULE
|
|
213 if (EQ (symbol, Qcategory)) return CHAR_TABLE_TYPE_CATEGORY;
|
|
214 #endif
|
|
215
|
563
|
216 invalid_constant ("Unrecognized char table type", symbol);
|
428
|
217 return CHAR_TABLE_TYPE_GENERIC; /* not reached */
|
|
218 }
|
|
219
|
|
220 static void
|
|
221 print_chartab_range (Emchar first, Emchar last, Lisp_Object val,
|
|
222 Lisp_Object printcharfun)
|
|
223 {
|
|
224 if (first != last)
|
|
225 {
|
|
226 write_c_string (" (", printcharfun);
|
|
227 print_internal (make_char (first), printcharfun, 0);
|
|
228 write_c_string (" ", printcharfun);
|
|
229 print_internal (make_char (last), printcharfun, 0);
|
|
230 write_c_string (") ", printcharfun);
|
|
231 }
|
|
232 else
|
|
233 {
|
|
234 write_c_string (" ", printcharfun);
|
|
235 print_internal (make_char (first), printcharfun, 0);
|
|
236 write_c_string (" ", printcharfun);
|
|
237 }
|
|
238 print_internal (val, printcharfun, 1);
|
|
239 }
|
|
240
|
|
241 #ifdef MULE
|
|
242
|
|
243 static void
|
|
244 print_chartab_charset_row (Lisp_Object charset,
|
|
245 int row,
|
440
|
246 Lisp_Char_Table_Entry *cte,
|
428
|
247 Lisp_Object printcharfun)
|
|
248 {
|
|
249 int i;
|
|
250 Lisp_Object cat = Qunbound;
|
|
251 int first = -1;
|
|
252
|
|
253 for (i = 32; i < 128; i++)
|
|
254 {
|
|
255 Lisp_Object pam = cte->level2[i - 32];
|
|
256
|
|
257 if (first == -1)
|
|
258 {
|
|
259 first = i;
|
|
260 cat = pam;
|
|
261 continue;
|
|
262 }
|
|
263
|
|
264 if (!EQ (cat, pam))
|
|
265 {
|
|
266 if (row == -1)
|
|
267 print_chartab_range (MAKE_CHAR (charset, first, 0),
|
|
268 MAKE_CHAR (charset, i - 1, 0),
|
|
269 cat, printcharfun);
|
|
270 else
|
|
271 print_chartab_range (MAKE_CHAR (charset, row, first),
|
|
272 MAKE_CHAR (charset, row, i - 1),
|
|
273 cat, printcharfun);
|
|
274 first = -1;
|
|
275 i--;
|
|
276 }
|
|
277 }
|
|
278
|
|
279 if (first != -1)
|
|
280 {
|
|
281 if (row == -1)
|
|
282 print_chartab_range (MAKE_CHAR (charset, first, 0),
|
|
283 MAKE_CHAR (charset, i - 1, 0),
|
|
284 cat, printcharfun);
|
|
285 else
|
|
286 print_chartab_range (MAKE_CHAR (charset, row, first),
|
|
287 MAKE_CHAR (charset, row, i - 1),
|
|
288 cat, printcharfun);
|
|
289 }
|
|
290 }
|
|
291
|
|
292 static void
|
|
293 print_chartab_two_byte_charset (Lisp_Object charset,
|
440
|
294 Lisp_Char_Table_Entry *cte,
|
428
|
295 Lisp_Object printcharfun)
|
|
296 {
|
|
297 int i;
|
|
298
|
|
299 for (i = 32; i < 128; i++)
|
|
300 {
|
|
301 Lisp_Object jen = cte->level2[i - 32];
|
|
302
|
|
303 if (!CHAR_TABLE_ENTRYP (jen))
|
|
304 {
|
|
305 char buf[100];
|
|
306
|
|
307 write_c_string (" [", printcharfun);
|
|
308 print_internal (XCHARSET_NAME (charset), printcharfun, 0);
|
|
309 sprintf (buf, " %d] ", i);
|
|
310 write_c_string (buf, printcharfun);
|
|
311 print_internal (jen, printcharfun, 0);
|
|
312 }
|
|
313 else
|
|
314 print_chartab_charset_row (charset, i, XCHAR_TABLE_ENTRY (jen),
|
|
315 printcharfun);
|
|
316 }
|
|
317 }
|
|
318
|
|
319 #endif /* MULE */
|
|
320
|
|
321 static void
|
|
322 print_char_table (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
323 {
|
440
|
324 Lisp_Char_Table *ct = XCHAR_TABLE (obj);
|
428
|
325
|
793
|
326 write_fmt_string_lisp (printcharfun, "#s(char-table type %s data (",
|
|
327 1, char_table_type_to_symbol (ct->type));
|
428
|
328
|
|
329 /* Now write out the ASCII/Control-1 stuff. */
|
|
330 {
|
|
331 int i;
|
|
332 int first = -1;
|
|
333 Lisp_Object val = Qunbound;
|
|
334
|
|
335 for (i = 0; i < NUM_ASCII_CHARS; i++)
|
|
336 {
|
|
337 if (first == -1)
|
|
338 {
|
|
339 first = i;
|
|
340 val = ct->ascii[i];
|
|
341 continue;
|
|
342 }
|
|
343
|
|
344 if (!EQ (ct->ascii[i], val))
|
|
345 {
|
|
346 print_chartab_range (first, i - 1, val, printcharfun);
|
|
347 first = -1;
|
|
348 i--;
|
|
349 }
|
|
350 }
|
|
351
|
|
352 if (first != -1)
|
|
353 print_chartab_range (first, i - 1, val, printcharfun);
|
|
354 }
|
|
355
|
|
356 #ifdef MULE
|
|
357 {
|
|
358 int i;
|
|
359
|
|
360 for (i = MIN_LEADING_BYTE; i < MIN_LEADING_BYTE + NUM_LEADING_BYTES;
|
|
361 i++)
|
|
362 {
|
|
363 Lisp_Object ann = ct->level1[i - MIN_LEADING_BYTE];
|
|
364 Lisp_Object charset = CHARSET_BY_LEADING_BYTE (i);
|
|
365
|
|
366 if (!CHARSETP (charset) || i == LEADING_BYTE_ASCII
|
|
367 || i == LEADING_BYTE_CONTROL_1)
|
|
368 continue;
|
|
369 if (!CHAR_TABLE_ENTRYP (ann))
|
|
370 {
|
|
371 write_c_string (" ", printcharfun);
|
|
372 print_internal (XCHARSET_NAME (charset),
|
|
373 printcharfun, 0);
|
|
374 write_c_string (" ", printcharfun);
|
|
375 print_internal (ann, printcharfun, 0);
|
|
376 }
|
|
377 else
|
|
378 {
|
440
|
379 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (ann);
|
428
|
380 if (XCHARSET_DIMENSION (charset) == 1)
|
|
381 print_chartab_charset_row (charset, -1, cte, printcharfun);
|
|
382 else
|
|
383 print_chartab_two_byte_charset (charset, cte, printcharfun);
|
|
384 }
|
|
385 }
|
|
386 }
|
|
387 #endif /* MULE */
|
|
388
|
|
389 write_c_string ("))", printcharfun);
|
|
390 }
|
|
391
|
|
392 static int
|
|
393 char_table_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
394 {
|
440
|
395 Lisp_Char_Table *ct1 = XCHAR_TABLE (obj1);
|
|
396 Lisp_Char_Table *ct2 = XCHAR_TABLE (obj2);
|
428
|
397 int i;
|
|
398
|
|
399 if (CHAR_TABLE_TYPE (ct1) != CHAR_TABLE_TYPE (ct2))
|
|
400 return 0;
|
|
401
|
|
402 for (i = 0; i < NUM_ASCII_CHARS; i++)
|
|
403 if (!internal_equal (ct1->ascii[i], ct2->ascii[i], depth + 1))
|
|
404 return 0;
|
|
405
|
|
406 #ifdef MULE
|
|
407 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
408 if (!internal_equal (ct1->level1[i], ct2->level1[i], depth + 1))
|
|
409 return 0;
|
|
410 #endif /* MULE */
|
|
411
|
|
412 return 1;
|
|
413 }
|
|
414
|
665
|
415 static Hashcode
|
428
|
416 char_table_hash (Lisp_Object obj, int depth)
|
|
417 {
|
440
|
418 Lisp_Char_Table *ct = XCHAR_TABLE (obj);
|
665
|
419 Hashcode hashval = internal_array_hash (ct->ascii, NUM_ASCII_CHARS,
|
647
|
420 depth);
|
428
|
421 #ifdef MULE
|
|
422 hashval = HASH2 (hashval,
|
|
423 internal_array_hash (ct->level1, NUM_LEADING_BYTES, depth));
|
|
424 #endif /* MULE */
|
|
425 return hashval;
|
|
426 }
|
|
427
|
|
428 static const struct lrecord_description char_table_description[] = {
|
440
|
429 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Char_Table, ascii), NUM_ASCII_CHARS },
|
428
|
430 #ifdef MULE
|
440
|
431 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Char_Table, level1), NUM_LEADING_BYTES },
|
428
|
432 #endif
|
793
|
433 { XD_LISP_OBJECT, offsetof (Lisp_Char_Table, parent) },
|
|
434 { XD_LISP_OBJECT, offsetof (Lisp_Char_Table, default_) },
|
440
|
435 { XD_LISP_OBJECT, offsetof (Lisp_Char_Table, mirror_table) },
|
|
436 { XD_LO_LINK, offsetof (Lisp_Char_Table, next_table) },
|
428
|
437 { XD_END }
|
|
438 };
|
|
439
|
|
440 DEFINE_LRECORD_IMPLEMENTATION ("char-table", char_table,
|
|
441 mark_char_table, print_char_table, 0,
|
|
442 char_table_equal, char_table_hash,
|
|
443 char_table_description,
|
440
|
444 Lisp_Char_Table);
|
428
|
445
|
|
446 DEFUN ("char-table-p", Fchar_table_p, 1, 1, 0, /*
|
|
447 Return non-nil if OBJECT is a char table.
|
|
448
|
|
449 A char table is a table that maps characters (or ranges of characters)
|
|
450 to values. Char tables are specialized for characters, only allowing
|
|
451 particular sorts of ranges to be assigned values. Although this
|
|
452 loses in generality, it makes for extremely fast (constant-time)
|
|
453 lookups, and thus is feasible for applications that do an extremely
|
|
454 large number of lookups (e.g. scanning a buffer for a character in
|
|
455 a particular syntax, where a lookup in the syntax table must occur
|
|
456 once per character).
|
|
457
|
|
458 When Mule support exists, the types of ranges that can be assigned
|
|
459 values are
|
|
460
|
|
461 -- all characters
|
|
462 -- an entire charset
|
|
463 -- a single row in a two-octet charset
|
|
464 -- a single character
|
|
465
|
|
466 When Mule support is not present, the types of ranges that can be
|
|
467 assigned values are
|
|
468
|
|
469 -- all characters
|
|
470 -- a single character
|
|
471
|
444
|
472 To create a char table, use `make-char-table'.
|
|
473 To modify a char table, use `put-char-table' or `remove-char-table'.
|
|
474 To retrieve the value for a particular character, use `get-char-table'.
|
|
475 See also `map-char-table', `clear-char-table', `copy-char-table',
|
|
476 `valid-char-table-type-p', `char-table-type-list',
|
|
477 `valid-char-table-value-p', and `check-char-table-value'.
|
428
|
478 */
|
|
479 (object))
|
|
480 {
|
|
481 return CHAR_TABLEP (object) ? Qt : Qnil;
|
|
482 }
|
|
483
|
|
484 DEFUN ("char-table-type-list", Fchar_table_type_list, 0, 0, 0, /*
|
|
485 Return a list of the recognized char table types.
|
|
486 See `valid-char-table-type-p'.
|
|
487 */
|
|
488 ())
|
|
489 {
|
|
490 #ifdef MULE
|
|
491 return list5 (Qchar, Qcategory, Qdisplay, Qgeneric, Qsyntax);
|
|
492 #else
|
|
493 return list4 (Qchar, Qdisplay, Qgeneric, Qsyntax);
|
|
494 #endif
|
|
495 }
|
|
496
|
|
497 DEFUN ("valid-char-table-type-p", Fvalid_char_table_type_p, 1, 1, 0, /*
|
|
498 Return t if TYPE if a recognized char table type.
|
|
499
|
|
500 Each char table type is used for a different purpose and allows different
|
|
501 sorts of values. The different char table types are
|
|
502
|
|
503 `category'
|
|
504 Used for category tables, which specify the regexp categories
|
|
505 that a character is in. The valid values are nil or a
|
|
506 bit vector of 95 elements. Higher-level Lisp functions are
|
|
507 provided for working with category tables. Currently categories
|
|
508 and category tables only exist when Mule support is present.
|
|
509 `char'
|
|
510 A generalized char table, for mapping from one character to
|
|
511 another. Used for case tables, syntax matching tables,
|
|
512 `keyboard-translate-table', etc. The valid values are characters.
|
|
513 `generic'
|
|
514 An even more generalized char table, for mapping from a
|
|
515 character to anything.
|
|
516 `display'
|
|
517 Used for display tables, which specify how a particular character
|
|
518 is to appear when displayed. #### Not yet implemented.
|
|
519 `syntax'
|
|
520 Used for syntax tables, which specify the syntax of a particular
|
|
521 character. Higher-level Lisp functions are provided for
|
|
522 working with syntax tables. The valid values are integers.
|
|
523
|
|
524 */
|
|
525 (type))
|
|
526 {
|
|
527 return (EQ (type, Qchar) ||
|
|
528 #ifdef MULE
|
|
529 EQ (type, Qcategory) ||
|
|
530 #endif
|
|
531 EQ (type, Qdisplay) ||
|
|
532 EQ (type, Qgeneric) ||
|
|
533 EQ (type, Qsyntax)) ? Qt : Qnil;
|
|
534 }
|
|
535
|
|
536 DEFUN ("char-table-type", Fchar_table_type, 1, 1, 0, /*
|
444
|
537 Return the type of CHAR-TABLE.
|
428
|
538 See `valid-char-table-type-p'.
|
|
539 */
|
444
|
540 (char_table))
|
428
|
541 {
|
444
|
542 CHECK_CHAR_TABLE (char_table);
|
|
543 return char_table_type_to_symbol (XCHAR_TABLE (char_table)->type);
|
428
|
544 }
|
|
545
|
|
546 void
|
440
|
547 fill_char_table (Lisp_Char_Table *ct, Lisp_Object value)
|
428
|
548 {
|
|
549 int i;
|
|
550
|
|
551 for (i = 0; i < NUM_ASCII_CHARS; i++)
|
|
552 ct->ascii[i] = value;
|
|
553 #ifdef MULE
|
|
554 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
555 ct->level1[i] = value;
|
|
556 #endif /* MULE */
|
|
557
|
|
558 if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
|
|
559 update_syntax_table (ct);
|
|
560 }
|
|
561
|
|
562 DEFUN ("reset-char-table", Freset_char_table, 1, 1, 0, /*
|
444
|
563 Reset CHAR-TABLE to its default state.
|
428
|
564 */
|
444
|
565 (char_table))
|
428
|
566 {
|
440
|
567 Lisp_Char_Table *ct;
|
428
|
568
|
444
|
569 CHECK_CHAR_TABLE (char_table);
|
|
570 ct = XCHAR_TABLE (char_table);
|
428
|
571
|
|
572 switch (ct->type)
|
|
573 {
|
|
574 case CHAR_TABLE_TYPE_CHAR:
|
|
575 fill_char_table (ct, make_char (0));
|
|
576 break;
|
|
577 case CHAR_TABLE_TYPE_DISPLAY:
|
|
578 case CHAR_TABLE_TYPE_GENERIC:
|
|
579 #ifdef MULE
|
|
580 case CHAR_TABLE_TYPE_CATEGORY:
|
|
581 #endif /* MULE */
|
|
582 fill_char_table (ct, Qnil);
|
|
583 break;
|
|
584
|
|
585 case CHAR_TABLE_TYPE_SYNTAX:
|
|
586 fill_char_table (ct, make_int (Sinherit));
|
|
587 break;
|
|
588
|
|
589 default:
|
|
590 abort ();
|
|
591 }
|
|
592
|
|
593 return Qnil;
|
|
594 }
|
|
595
|
|
596 DEFUN ("make-char-table", Fmake_char_table, 1, 1, 0, /*
|
|
597 Return a new, empty char table of type TYPE.
|
|
598 Currently recognized types are 'char, 'category, 'display, 'generic,
|
|
599 and 'syntax. See `valid-char-table-type-p'.
|
|
600 */
|
|
601 (type))
|
|
602 {
|
440
|
603 Lisp_Char_Table *ct;
|
428
|
604 Lisp_Object obj;
|
|
605 enum char_table_type ty = symbol_to_char_table_type (type);
|
|
606
|
440
|
607 ct = alloc_lcrecord_type (Lisp_Char_Table, &lrecord_char_table);
|
428
|
608 ct->type = ty;
|
|
609 if (ty == CHAR_TABLE_TYPE_SYNTAX)
|
|
610 {
|
|
611 ct->mirror_table = Fmake_char_table (Qgeneric);
|
|
612 fill_char_table (XCHAR_TABLE (ct->mirror_table),
|
|
613 make_int (Spunct));
|
|
614 }
|
|
615 else
|
|
616 ct->mirror_table = Qnil;
|
|
617 ct->next_table = Qnil;
|
793
|
618 ct->parent = Qnil;
|
|
619 ct->default_ = Qnil;
|
|
620 obj = wrap_char_table (ct);
|
428
|
621 if (ty == CHAR_TABLE_TYPE_SYNTAX)
|
|
622 {
|
|
623 ct->next_table = Vall_syntax_tables;
|
|
624 Vall_syntax_tables = obj;
|
|
625 }
|
|
626 Freset_char_table (obj);
|
|
627 return obj;
|
|
628 }
|
|
629
|
|
630 #ifdef MULE
|
|
631
|
|
632 static Lisp_Object
|
|
633 make_char_table_entry (Lisp_Object initval)
|
|
634 {
|
|
635 int i;
|
440
|
636 Lisp_Char_Table_Entry *cte =
|
|
637 alloc_lcrecord_type (Lisp_Char_Table_Entry, &lrecord_char_table_entry);
|
428
|
638
|
|
639 for (i = 0; i < 96; i++)
|
|
640 cte->level2[i] = initval;
|
|
641
|
793
|
642 return wrap_char_table_entry (cte);
|
428
|
643 }
|
|
644
|
|
645 static Lisp_Object
|
|
646 copy_char_table_entry (Lisp_Object entry)
|
|
647 {
|
440
|
648 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (entry);
|
428
|
649 int i;
|
440
|
650 Lisp_Char_Table_Entry *ctenew =
|
|
651 alloc_lcrecord_type (Lisp_Char_Table_Entry, &lrecord_char_table_entry);
|
428
|
652
|
|
653 for (i = 0; i < 96; i++)
|
|
654 {
|
|
655 Lisp_Object new = cte->level2[i];
|
|
656 if (CHAR_TABLE_ENTRYP (new))
|
|
657 ctenew->level2[i] = copy_char_table_entry (new);
|
|
658 else
|
|
659 ctenew->level2[i] = new;
|
|
660 }
|
|
661
|
793
|
662 return wrap_char_table_entry (ctenew);
|
428
|
663 }
|
|
664
|
|
665 #endif /* MULE */
|
|
666
|
|
667 DEFUN ("copy-char-table", Fcopy_char_table, 1, 1, 0, /*
|
444
|
668 Return a new char table which is a copy of CHAR-TABLE.
|
428
|
669 It will contain the same values for the same characters and ranges
|
444
|
670 as CHAR-TABLE. The values will not themselves be copied.
|
428
|
671 */
|
444
|
672 (char_table))
|
428
|
673 {
|
440
|
674 Lisp_Char_Table *ct, *ctnew;
|
428
|
675 Lisp_Object obj;
|
|
676 int i;
|
|
677
|
444
|
678 CHECK_CHAR_TABLE (char_table);
|
|
679 ct = XCHAR_TABLE (char_table);
|
440
|
680 ctnew = alloc_lcrecord_type (Lisp_Char_Table, &lrecord_char_table);
|
428
|
681 ctnew->type = ct->type;
|
793
|
682 ctnew->parent = ct->parent;
|
|
683 ctnew->default_ = ct->default_;
|
428
|
684
|
|
685 for (i = 0; i < NUM_ASCII_CHARS; i++)
|
|
686 {
|
|
687 Lisp_Object new = ct->ascii[i];
|
|
688 #ifdef MULE
|
|
689 assert (! (CHAR_TABLE_ENTRYP (new)));
|
|
690 #endif /* MULE */
|
|
691 ctnew->ascii[i] = new;
|
|
692 }
|
|
693
|
|
694 #ifdef MULE
|
|
695
|
|
696 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
697 {
|
|
698 Lisp_Object new = ct->level1[i];
|
|
699 if (CHAR_TABLE_ENTRYP (new))
|
|
700 ctnew->level1[i] = copy_char_table_entry (new);
|
|
701 else
|
|
702 ctnew->level1[i] = new;
|
|
703 }
|
|
704
|
|
705 #endif /* MULE */
|
|
706
|
|
707 if (CHAR_TABLEP (ct->mirror_table))
|
|
708 ctnew->mirror_table = Fcopy_char_table (ct->mirror_table);
|
|
709 else
|
|
710 ctnew->mirror_table = ct->mirror_table;
|
|
711 ctnew->next_table = Qnil;
|
793
|
712 obj = wrap_char_table (ctnew);
|
428
|
713 if (ctnew->type == CHAR_TABLE_TYPE_SYNTAX)
|
|
714 {
|
|
715 ctnew->next_table = Vall_syntax_tables;
|
|
716 Vall_syntax_tables = obj;
|
|
717 }
|
|
718 return obj;
|
|
719 }
|
|
720
|
|
721 static void
|
|
722 decode_char_table_range (Lisp_Object range, struct chartab_range *outrange)
|
|
723 {
|
|
724 if (EQ (range, Qt))
|
|
725 outrange->type = CHARTAB_RANGE_ALL;
|
|
726 else if (CHAR_OR_CHAR_INTP (range))
|
|
727 {
|
|
728 outrange->type = CHARTAB_RANGE_CHAR;
|
|
729 outrange->ch = XCHAR_OR_CHAR_INT (range);
|
|
730 }
|
|
731 #ifndef MULE
|
|
732 else
|
563
|
733 sferror ("Range must be t or a character", range);
|
428
|
734 #else /* MULE */
|
|
735 else if (VECTORP (range))
|
|
736 {
|
440
|
737 Lisp_Vector *vec = XVECTOR (range);
|
428
|
738 Lisp_Object *elts = vector_data (vec);
|
|
739 if (vector_length (vec) != 2)
|
563
|
740 sferror ("Length of charset row vector must be 2",
|
428
|
741 range);
|
|
742 outrange->type = CHARTAB_RANGE_ROW;
|
|
743 outrange->charset = Fget_charset (elts[0]);
|
|
744 CHECK_INT (elts[1]);
|
|
745 outrange->row = XINT (elts[1]);
|
|
746 switch (XCHARSET_TYPE (outrange->charset))
|
|
747 {
|
|
748 case CHARSET_TYPE_94:
|
|
749 case CHARSET_TYPE_96:
|
563
|
750 sferror ("Charset in row vector must be multi-byte",
|
428
|
751 outrange->charset);
|
|
752 case CHARSET_TYPE_94X94:
|
|
753 check_int_range (outrange->row, 33, 126);
|
|
754 break;
|
|
755 case CHARSET_TYPE_96X96:
|
|
756 check_int_range (outrange->row, 32, 127);
|
|
757 break;
|
|
758 default:
|
|
759 abort ();
|
|
760 }
|
|
761 }
|
|
762 else
|
|
763 {
|
|
764 if (!CHARSETP (range) && !SYMBOLP (range))
|
563
|
765 sferror
|
428
|
766 ("Char table range must be t, charset, char, or vector", range);
|
|
767 outrange->type = CHARTAB_RANGE_CHARSET;
|
|
768 outrange->charset = Fget_charset (range);
|
|
769 }
|
|
770 #endif /* MULE */
|
|
771 }
|
|
772
|
|
773 #ifdef MULE
|
|
774
|
|
775 /* called from CHAR_TABLE_VALUE(). */
|
|
776 Lisp_Object
|
440
|
777 get_non_ascii_char_table_value (Lisp_Char_Table *ct, int leading_byte,
|
428
|
778 Emchar c)
|
|
779 {
|
|
780 Lisp_Object val;
|
|
781 Lisp_Object charset = CHARSET_BY_LEADING_BYTE (leading_byte);
|
|
782 int byte1, byte2;
|
|
783
|
|
784 BREAKUP_CHAR_1_UNSAFE (c, charset, byte1, byte2);
|
|
785 val = ct->level1[leading_byte - MIN_LEADING_BYTE];
|
|
786 if (CHAR_TABLE_ENTRYP (val))
|
|
787 {
|
440
|
788 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
|
428
|
789 val = cte->level2[byte1 - 32];
|
|
790 if (CHAR_TABLE_ENTRYP (val))
|
|
791 {
|
|
792 cte = XCHAR_TABLE_ENTRY (val);
|
|
793 assert (byte2 >= 32);
|
|
794 val = cte->level2[byte2 - 32];
|
|
795 assert (!CHAR_TABLE_ENTRYP (val));
|
|
796 }
|
|
797 }
|
|
798
|
|
799 return val;
|
|
800 }
|
|
801
|
|
802 #endif /* MULE */
|
|
803
|
|
804 Lisp_Object
|
440
|
805 get_char_table (Emchar ch, Lisp_Char_Table *ct)
|
428
|
806 {
|
|
807 #ifdef MULE
|
|
808 {
|
|
809 Lisp_Object charset;
|
|
810 int byte1, byte2;
|
|
811 Lisp_Object val;
|
|
812
|
|
813 BREAKUP_CHAR (ch, charset, byte1, byte2);
|
|
814
|
|
815 if (EQ (charset, Vcharset_ascii))
|
|
816 val = ct->ascii[byte1];
|
|
817 else if (EQ (charset, Vcharset_control_1))
|
|
818 val = ct->ascii[byte1 + 128];
|
|
819 else
|
|
820 {
|
|
821 int lb = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
|
|
822 val = ct->level1[lb];
|
|
823 if (CHAR_TABLE_ENTRYP (val))
|
|
824 {
|
440
|
825 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
|
428
|
826 val = cte->level2[byte1 - 32];
|
|
827 if (CHAR_TABLE_ENTRYP (val))
|
|
828 {
|
|
829 cte = XCHAR_TABLE_ENTRY (val);
|
|
830 assert (byte2 >= 32);
|
|
831 val = cte->level2[byte2 - 32];
|
|
832 assert (!CHAR_TABLE_ENTRYP (val));
|
|
833 }
|
|
834 }
|
|
835 }
|
|
836
|
|
837 return val;
|
|
838 }
|
|
839 #else /* not MULE */
|
|
840 return ct->ascii[(unsigned char)ch];
|
|
841 #endif /* not MULE */
|
|
842 }
|
|
843
|
|
844
|
|
845 DEFUN ("get-char-table", Fget_char_table, 2, 2, 0, /*
|
444
|
846 Find value for CHARACTER in CHAR-TABLE.
|
428
|
847 */
|
444
|
848 (character, char_table))
|
428
|
849 {
|
444
|
850 CHECK_CHAR_TABLE (char_table);
|
|
851 CHECK_CHAR_COERCE_INT (character);
|
428
|
852
|
444
|
853 return get_char_table (XCHAR (character), XCHAR_TABLE (char_table));
|
428
|
854 }
|
|
855
|
|
856 DEFUN ("get-range-char-table", Fget_range_char_table, 2, 3, 0, /*
|
444
|
857 Find value for a range in CHAR-TABLE.
|
428
|
858 If there is more than one value, return MULTI (defaults to nil).
|
|
859 */
|
444
|
860 (range, char_table, multi))
|
428
|
861 {
|
440
|
862 Lisp_Char_Table *ct;
|
428
|
863 struct chartab_range rainj;
|
|
864
|
|
865 if (CHAR_OR_CHAR_INTP (range))
|
444
|
866 return Fget_char_table (range, char_table);
|
|
867 CHECK_CHAR_TABLE (char_table);
|
|
868 ct = XCHAR_TABLE (char_table);
|
428
|
869
|
|
870 decode_char_table_range (range, &rainj);
|
|
871 switch (rainj.type)
|
|
872 {
|
|
873 case CHARTAB_RANGE_ALL:
|
|
874 {
|
|
875 int i;
|
|
876 Lisp_Object first = ct->ascii[0];
|
|
877
|
|
878 for (i = 1; i < NUM_ASCII_CHARS; i++)
|
|
879 if (!EQ (first, ct->ascii[i]))
|
|
880 return multi;
|
|
881
|
|
882 #ifdef MULE
|
|
883 for (i = MIN_LEADING_BYTE; i < MIN_LEADING_BYTE + NUM_LEADING_BYTES;
|
|
884 i++)
|
|
885 {
|
|
886 if (!CHARSETP (CHARSET_BY_LEADING_BYTE (i))
|
|
887 || i == LEADING_BYTE_ASCII
|
|
888 || i == LEADING_BYTE_CONTROL_1)
|
|
889 continue;
|
|
890 if (!EQ (first, ct->level1[i - MIN_LEADING_BYTE]))
|
|
891 return multi;
|
|
892 }
|
|
893 #endif /* MULE */
|
|
894
|
|
895 return first;
|
|
896 }
|
|
897
|
|
898 #ifdef MULE
|
|
899 case CHARTAB_RANGE_CHARSET:
|
|
900 if (EQ (rainj.charset, Vcharset_ascii))
|
|
901 {
|
|
902 int i;
|
|
903 Lisp_Object first = ct->ascii[0];
|
|
904
|
|
905 for (i = 1; i < 128; i++)
|
|
906 if (!EQ (first, ct->ascii[i]))
|
|
907 return multi;
|
|
908 return first;
|
|
909 }
|
|
910
|
|
911 if (EQ (rainj.charset, Vcharset_control_1))
|
|
912 {
|
|
913 int i;
|
|
914 Lisp_Object first = ct->ascii[128];
|
|
915
|
|
916 for (i = 129; i < 160; i++)
|
|
917 if (!EQ (first, ct->ascii[i]))
|
|
918 return multi;
|
|
919 return first;
|
|
920 }
|
|
921
|
|
922 {
|
|
923 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (rainj.charset) -
|
|
924 MIN_LEADING_BYTE];
|
|
925 if (CHAR_TABLE_ENTRYP (val))
|
|
926 return multi;
|
|
927 return val;
|
|
928 }
|
|
929
|
|
930 case CHARTAB_RANGE_ROW:
|
|
931 {
|
|
932 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (rainj.charset) -
|
|
933 MIN_LEADING_BYTE];
|
|
934 if (!CHAR_TABLE_ENTRYP (val))
|
|
935 return val;
|
|
936 val = XCHAR_TABLE_ENTRY (val)->level2[rainj.row - 32];
|
|
937 if (CHAR_TABLE_ENTRYP (val))
|
|
938 return multi;
|
|
939 return val;
|
|
940 }
|
|
941 #endif /* not MULE */
|
|
942
|
|
943 default:
|
|
944 abort ();
|
|
945 }
|
|
946
|
|
947 return Qnil; /* not reached */
|
|
948 }
|
|
949
|
|
950 static int
|
|
951 check_valid_char_table_value (Lisp_Object value, enum char_table_type type,
|
578
|
952 Error_Behavior errb)
|
428
|
953 {
|
|
954 switch (type)
|
|
955 {
|
|
956 case CHAR_TABLE_TYPE_SYNTAX:
|
|
957 if (!ERRB_EQ (errb, ERROR_ME))
|
|
958 return INTP (value) || (CONSP (value) && INTP (XCAR (value))
|
|
959 && CHAR_OR_CHAR_INTP (XCDR (value)));
|
|
960 if (CONSP (value))
|
|
961 {
|
|
962 Lisp_Object cdr = XCDR (value);
|
|
963 CHECK_INT (XCAR (value));
|
|
964 CHECK_CHAR_COERCE_INT (cdr);
|
|
965 }
|
|
966 else
|
|
967 CHECK_INT (value);
|
|
968 break;
|
|
969
|
|
970 #ifdef MULE
|
|
971 case CHAR_TABLE_TYPE_CATEGORY:
|
|
972 if (!ERRB_EQ (errb, ERROR_ME))
|
|
973 return CATEGORY_TABLE_VALUEP (value);
|
|
974 CHECK_CATEGORY_TABLE_VALUE (value);
|
|
975 break;
|
|
976 #endif /* MULE */
|
|
977
|
|
978 case CHAR_TABLE_TYPE_GENERIC:
|
|
979 return 1;
|
|
980
|
|
981 case CHAR_TABLE_TYPE_DISPLAY:
|
|
982 /* #### fix this */
|
563
|
983 maybe_signal_error (Qunimplemented,
|
|
984 "Display char tables not yet implemented",
|
|
985 value, Qchar_table, errb);
|
428
|
986 return 0;
|
|
987
|
|
988 case CHAR_TABLE_TYPE_CHAR:
|
|
989 if (!ERRB_EQ (errb, ERROR_ME))
|
|
990 return CHAR_OR_CHAR_INTP (value);
|
|
991 CHECK_CHAR_COERCE_INT (value);
|
|
992 break;
|
|
993
|
|
994 default:
|
|
995 abort ();
|
|
996 }
|
|
997
|
|
998 return 0; /* not reached */
|
|
999 }
|
|
1000
|
|
1001 static Lisp_Object
|
|
1002 canonicalize_char_table_value (Lisp_Object value, enum char_table_type type)
|
|
1003 {
|
|
1004 switch (type)
|
|
1005 {
|
|
1006 case CHAR_TABLE_TYPE_SYNTAX:
|
|
1007 if (CONSP (value))
|
|
1008 {
|
|
1009 Lisp_Object car = XCAR (value);
|
|
1010 Lisp_Object cdr = XCDR (value);
|
|
1011 CHECK_CHAR_COERCE_INT (cdr);
|
|
1012 return Fcons (car, cdr);
|
|
1013 }
|
|
1014 break;
|
|
1015 case CHAR_TABLE_TYPE_CHAR:
|
|
1016 CHECK_CHAR_COERCE_INT (value);
|
|
1017 break;
|
|
1018 default:
|
|
1019 break;
|
|
1020 }
|
|
1021 return value;
|
|
1022 }
|
|
1023
|
|
1024 DEFUN ("valid-char-table-value-p", Fvalid_char_table_value_p, 2, 2, 0, /*
|
|
1025 Return non-nil if VALUE is a valid value for CHAR-TABLE-TYPE.
|
|
1026 */
|
|
1027 (value, char_table_type))
|
|
1028 {
|
|
1029 enum char_table_type type = symbol_to_char_table_type (char_table_type);
|
|
1030
|
|
1031 return check_valid_char_table_value (value, type, ERROR_ME_NOT) ? Qt : Qnil;
|
|
1032 }
|
|
1033
|
|
1034 DEFUN ("check-valid-char-table-value", Fcheck_valid_char_table_value, 2, 2, 0, /*
|
|
1035 Signal an error if VALUE is not a valid value for CHAR-TABLE-TYPE.
|
|
1036 */
|
|
1037 (value, char_table_type))
|
|
1038 {
|
|
1039 enum char_table_type type = symbol_to_char_table_type (char_table_type);
|
|
1040
|
|
1041 check_valid_char_table_value (value, type, ERROR_ME);
|
|
1042 return Qnil;
|
|
1043 }
|
|
1044
|
|
1045 /* Assign VAL to all characters in RANGE in char table CT. */
|
|
1046
|
|
1047 void
|
440
|
1048 put_char_table (Lisp_Char_Table *ct, struct chartab_range *range,
|
428
|
1049 Lisp_Object val)
|
|
1050 {
|
|
1051 switch (range->type)
|
|
1052 {
|
|
1053 case CHARTAB_RANGE_ALL:
|
|
1054 fill_char_table (ct, val);
|
|
1055 return; /* avoid the duplicate call to update_syntax_table() below,
|
|
1056 since fill_char_table() also did that. */
|
|
1057
|
|
1058 #ifdef MULE
|
|
1059 case CHARTAB_RANGE_CHARSET:
|
|
1060 if (EQ (range->charset, Vcharset_ascii))
|
|
1061 {
|
|
1062 int i;
|
|
1063 for (i = 0; i < 128; i++)
|
|
1064 ct->ascii[i] = val;
|
|
1065 }
|
|
1066 else if (EQ (range->charset, Vcharset_control_1))
|
|
1067 {
|
|
1068 int i;
|
|
1069 for (i = 128; i < 160; i++)
|
|
1070 ct->ascii[i] = val;
|
|
1071 }
|
|
1072 else
|
|
1073 {
|
|
1074 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
|
|
1075 ct->level1[lb] = val;
|
|
1076 }
|
|
1077 break;
|
|
1078
|
|
1079 case CHARTAB_RANGE_ROW:
|
|
1080 {
|
440
|
1081 Lisp_Char_Table_Entry *cte;
|
428
|
1082 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
|
|
1083 /* make sure that there is a separate entry for the row. */
|
|
1084 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
|
|
1085 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
|
|
1086 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
|
|
1087 cte->level2[range->row - 32] = val;
|
|
1088 }
|
|
1089 break;
|
|
1090 #endif /* MULE */
|
|
1091
|
|
1092 case CHARTAB_RANGE_CHAR:
|
|
1093 #ifdef MULE
|
|
1094 {
|
|
1095 Lisp_Object charset;
|
|
1096 int byte1, byte2;
|
|
1097
|
|
1098 BREAKUP_CHAR (range->ch, charset, byte1, byte2);
|
|
1099 if (EQ (charset, Vcharset_ascii))
|
|
1100 ct->ascii[byte1] = val;
|
|
1101 else if (EQ (charset, Vcharset_control_1))
|
|
1102 ct->ascii[byte1 + 128] = val;
|
|
1103 else
|
|
1104 {
|
440
|
1105 Lisp_Char_Table_Entry *cte;
|
428
|
1106 int lb = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
|
|
1107 /* make sure that there is a separate entry for the row. */
|
|
1108 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
|
|
1109 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
|
|
1110 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
|
|
1111 /* now CTE is a char table entry for the charset;
|
|
1112 each entry is for a single row (or character of
|
|
1113 a one-octet charset). */
|
|
1114 if (XCHARSET_DIMENSION (charset) == 1)
|
|
1115 cte->level2[byte1 - 32] = val;
|
|
1116 else
|
|
1117 {
|
|
1118 /* assigning to one character in a two-octet charset. */
|
|
1119 /* make sure that the charset row contains a separate
|
|
1120 entry for each character. */
|
|
1121 if (!CHAR_TABLE_ENTRYP (cte->level2[byte1 - 32]))
|
|
1122 cte->level2[byte1 - 32] =
|
|
1123 make_char_table_entry (cte->level2[byte1 - 32]);
|
|
1124 cte = XCHAR_TABLE_ENTRY (cte->level2[byte1 - 32]);
|
|
1125 cte->level2[byte2 - 32] = val;
|
|
1126 }
|
|
1127 }
|
|
1128 }
|
|
1129 #else /* not MULE */
|
|
1130 ct->ascii[(unsigned char) (range->ch)] = val;
|
|
1131 break;
|
|
1132 #endif /* not MULE */
|
|
1133 }
|
|
1134
|
|
1135 if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
|
|
1136 update_syntax_table (ct);
|
|
1137 }
|
|
1138
|
|
1139 DEFUN ("put-char-table", Fput_char_table, 3, 3, 0, /*
|
444
|
1140 Set the value for chars in RANGE to be VALUE in CHAR-TABLE.
|
428
|
1141
|
|
1142 RANGE specifies one or more characters to be affected and should be
|
|
1143 one of the following:
|
|
1144
|
|
1145 -- t (all characters are affected)
|
|
1146 -- A charset (only allowed when Mule support is present)
|
|
1147 -- A vector of two elements: a two-octet charset and a row number
|
|
1148 (only allowed when Mule support is present)
|
|
1149 -- A single character
|
|
1150
|
444
|
1151 VALUE must be a value appropriate for the type of CHAR-TABLE.
|
428
|
1152 See `valid-char-table-type-p'.
|
|
1153 */
|
444
|
1154 (range, value, char_table))
|
428
|
1155 {
|
440
|
1156 Lisp_Char_Table *ct;
|
428
|
1157 struct chartab_range rainj;
|
|
1158
|
444
|
1159 CHECK_CHAR_TABLE (char_table);
|
|
1160 ct = XCHAR_TABLE (char_table);
|
|
1161 check_valid_char_table_value (value, ct->type, ERROR_ME);
|
428
|
1162 decode_char_table_range (range, &rainj);
|
444
|
1163 value = canonicalize_char_table_value (value, ct->type);
|
|
1164 put_char_table (ct, &rainj, value);
|
428
|
1165 return Qnil;
|
|
1166 }
|
|
1167
|
|
1168 /* Map FN over the ASCII chars in CT. */
|
|
1169
|
|
1170 static int
|
440
|
1171 map_over_charset_ascii (Lisp_Char_Table *ct,
|
428
|
1172 int (*fn) (struct chartab_range *range,
|
|
1173 Lisp_Object val, void *arg),
|
|
1174 void *arg)
|
|
1175 {
|
|
1176 struct chartab_range rainj;
|
|
1177 int i, retval;
|
|
1178 int start = 0;
|
|
1179 #ifdef MULE
|
|
1180 int stop = 128;
|
|
1181 #else
|
|
1182 int stop = 256;
|
|
1183 #endif
|
|
1184
|
|
1185 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1186
|
|
1187 for (i = start, retval = 0; i < stop && retval == 0; i++)
|
|
1188 {
|
|
1189 rainj.ch = (Emchar) i;
|
|
1190 retval = (fn) (&rainj, ct->ascii[i], arg);
|
|
1191 }
|
|
1192
|
|
1193 return retval;
|
|
1194 }
|
|
1195
|
|
1196 #ifdef MULE
|
|
1197
|
|
1198 /* Map FN over the Control-1 chars in CT. */
|
|
1199
|
|
1200 static int
|
440
|
1201 map_over_charset_control_1 (Lisp_Char_Table *ct,
|
428
|
1202 int (*fn) (struct chartab_range *range,
|
|
1203 Lisp_Object val, void *arg),
|
|
1204 void *arg)
|
|
1205 {
|
|
1206 struct chartab_range rainj;
|
|
1207 int i, retval;
|
|
1208 int start = 128;
|
|
1209 int stop = start + 32;
|
|
1210
|
|
1211 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1212
|
|
1213 for (i = start, retval = 0; i < stop && retval == 0; i++)
|
|
1214 {
|
|
1215 rainj.ch = (Emchar) (i);
|
|
1216 retval = (fn) (&rainj, ct->ascii[i], arg);
|
|
1217 }
|
|
1218
|
|
1219 return retval;
|
|
1220 }
|
|
1221
|
|
1222 /* Map FN over the row ROW of two-byte charset CHARSET.
|
|
1223 There must be a separate value for that row in the char table.
|
|
1224 CTE specifies the char table entry for CHARSET. */
|
|
1225
|
|
1226 static int
|
440
|
1227 map_over_charset_row (Lisp_Char_Table_Entry *cte,
|
428
|
1228 Lisp_Object charset, int row,
|
|
1229 int (*fn) (struct chartab_range *range,
|
|
1230 Lisp_Object val, void *arg),
|
|
1231 void *arg)
|
|
1232 {
|
|
1233 Lisp_Object val = cte->level2[row - 32];
|
|
1234
|
|
1235 if (!CHAR_TABLE_ENTRYP (val))
|
|
1236 {
|
|
1237 struct chartab_range rainj;
|
|
1238
|
|
1239 rainj.type = CHARTAB_RANGE_ROW;
|
|
1240 rainj.charset = charset;
|
|
1241 rainj.row = row;
|
|
1242 return (fn) (&rainj, val, arg);
|
|
1243 }
|
|
1244 else
|
|
1245 {
|
|
1246 struct chartab_range rainj;
|
|
1247 int i, retval;
|
|
1248 int charset94_p = (XCHARSET_CHARS (charset) == 94);
|
|
1249 int start = charset94_p ? 33 : 32;
|
|
1250 int stop = charset94_p ? 127 : 128;
|
|
1251
|
|
1252 cte = XCHAR_TABLE_ENTRY (val);
|
|
1253
|
|
1254 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1255
|
|
1256 for (i = start, retval = 0; i < stop && retval == 0; i++)
|
|
1257 {
|
|
1258 rainj.ch = MAKE_CHAR (charset, row, i);
|
|
1259 retval = (fn) (&rainj, cte->level2[i - 32], arg);
|
|
1260 }
|
|
1261 return retval;
|
|
1262 }
|
|
1263 }
|
|
1264
|
|
1265
|
|
1266 static int
|
440
|
1267 map_over_other_charset (Lisp_Char_Table *ct, int lb,
|
428
|
1268 int (*fn) (struct chartab_range *range,
|
|
1269 Lisp_Object val, void *arg),
|
|
1270 void *arg)
|
|
1271 {
|
|
1272 Lisp_Object val = ct->level1[lb - MIN_LEADING_BYTE];
|
|
1273 Lisp_Object charset = CHARSET_BY_LEADING_BYTE (lb);
|
|
1274
|
|
1275 if (!CHARSETP (charset)
|
|
1276 || lb == LEADING_BYTE_ASCII
|
|
1277 || lb == LEADING_BYTE_CONTROL_1)
|
|
1278 return 0;
|
|
1279
|
|
1280 if (!CHAR_TABLE_ENTRYP (val))
|
|
1281 {
|
|
1282 struct chartab_range rainj;
|
|
1283
|
|
1284 rainj.type = CHARTAB_RANGE_CHARSET;
|
|
1285 rainj.charset = charset;
|
|
1286 return (fn) (&rainj, val, arg);
|
|
1287 }
|
|
1288
|
|
1289 {
|
440
|
1290 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
|
428
|
1291 int charset94_p = (XCHARSET_CHARS (charset) == 94);
|
|
1292 int start = charset94_p ? 33 : 32;
|
|
1293 int stop = charset94_p ? 127 : 128;
|
|
1294 int i, retval;
|
|
1295
|
|
1296 if (XCHARSET_DIMENSION (charset) == 1)
|
|
1297 {
|
|
1298 struct chartab_range rainj;
|
|
1299 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1300
|
|
1301 for (i = start, retval = 0; i < stop && retval == 0; i++)
|
|
1302 {
|
|
1303 rainj.ch = MAKE_CHAR (charset, i, 0);
|
|
1304 retval = (fn) (&rainj, cte->level2[i - 32], arg);
|
|
1305 }
|
|
1306 }
|
|
1307 else
|
|
1308 {
|
|
1309 for (i = start, retval = 0; i < stop && retval == 0; i++)
|
|
1310 retval = map_over_charset_row (cte, charset, i, fn, arg);
|
|
1311 }
|
|
1312
|
|
1313 return retval;
|
|
1314 }
|
|
1315 }
|
|
1316
|
|
1317 #endif /* MULE */
|
|
1318
|
|
1319 /* Map FN (with client data ARG) over range RANGE in char table CT.
|
|
1320 Mapping stops the first time FN returns non-zero, and that value
|
|
1321 becomes the return value of map_char_table(). */
|
|
1322
|
|
1323 int
|
440
|
1324 map_char_table (Lisp_Char_Table *ct,
|
428
|
1325 struct chartab_range *range,
|
|
1326 int (*fn) (struct chartab_range *range,
|
|
1327 Lisp_Object val, void *arg),
|
|
1328 void *arg)
|
|
1329 {
|
|
1330 switch (range->type)
|
|
1331 {
|
|
1332 case CHARTAB_RANGE_ALL:
|
|
1333 {
|
|
1334 int retval;
|
|
1335
|
|
1336 retval = map_over_charset_ascii (ct, fn, arg);
|
|
1337 if (retval)
|
|
1338 return retval;
|
|
1339 #ifdef MULE
|
|
1340 retval = map_over_charset_control_1 (ct, fn, arg);
|
|
1341 if (retval)
|
|
1342 return retval;
|
|
1343 {
|
|
1344 int i;
|
|
1345 int start = MIN_LEADING_BYTE;
|
|
1346 int stop = start + NUM_LEADING_BYTES;
|
|
1347
|
|
1348 for (i = start, retval = 0; i < stop && retval == 0; i++)
|
|
1349 {
|
771
|
1350 if (i != LEADING_BYTE_ASCII && i != LEADING_BYTE_CONTROL_1)
|
|
1351 retval = map_over_other_charset (ct, i, fn, arg);
|
428
|
1352 }
|
|
1353 }
|
|
1354 #endif /* MULE */
|
|
1355 return retval;
|
|
1356 }
|
|
1357
|
|
1358 #ifdef MULE
|
|
1359 case CHARTAB_RANGE_CHARSET:
|
|
1360 return map_over_other_charset (ct,
|
|
1361 XCHARSET_LEADING_BYTE (range->charset),
|
|
1362 fn, arg);
|
|
1363
|
|
1364 case CHARTAB_RANGE_ROW:
|
|
1365 {
|
771
|
1366 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (range->charset) -
|
|
1367 MIN_LEADING_BYTE];
|
428
|
1368 if (!CHAR_TABLE_ENTRYP (val))
|
|
1369 {
|
|
1370 struct chartab_range rainj;
|
|
1371
|
|
1372 rainj.type = CHARTAB_RANGE_ROW;
|
|
1373 rainj.charset = range->charset;
|
|
1374 rainj.row = range->row;
|
|
1375 return (fn) (&rainj, val, arg);
|
|
1376 }
|
|
1377 else
|
|
1378 return map_over_charset_row (XCHAR_TABLE_ENTRY (val),
|
|
1379 range->charset, range->row,
|
|
1380 fn, arg);
|
|
1381 }
|
|
1382 #endif /* MULE */
|
|
1383
|
|
1384 case CHARTAB_RANGE_CHAR:
|
|
1385 {
|
|
1386 Emchar ch = range->ch;
|
|
1387 Lisp_Object val = CHAR_TABLE_VALUE_UNSAFE (ct, ch);
|
|
1388 struct chartab_range rainj;
|
|
1389
|
|
1390 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1391 rainj.ch = ch;
|
|
1392 return (fn) (&rainj, val, arg);
|
|
1393 }
|
|
1394
|
|
1395 default:
|
|
1396 abort ();
|
|
1397 }
|
|
1398
|
|
1399 return 0;
|
|
1400 }
|
|
1401
|
|
1402 struct slow_map_char_table_arg
|
|
1403 {
|
|
1404 Lisp_Object function;
|
|
1405 Lisp_Object retval;
|
|
1406 };
|
|
1407
|
|
1408 static int
|
|
1409 slow_map_char_table_fun (struct chartab_range *range,
|
|
1410 Lisp_Object val, void *arg)
|
|
1411 {
|
|
1412 Lisp_Object ranjarg = Qnil;
|
|
1413 struct slow_map_char_table_arg *closure =
|
|
1414 (struct slow_map_char_table_arg *) arg;
|
|
1415
|
|
1416 switch (range->type)
|
|
1417 {
|
|
1418 case CHARTAB_RANGE_ALL:
|
|
1419 ranjarg = Qt;
|
|
1420 break;
|
|
1421
|
|
1422 #ifdef MULE
|
|
1423 case CHARTAB_RANGE_CHARSET:
|
|
1424 ranjarg = XCHARSET_NAME (range->charset);
|
|
1425 break;
|
|
1426
|
|
1427 case CHARTAB_RANGE_ROW:
|
|
1428 ranjarg = vector2 (XCHARSET_NAME (range->charset),
|
|
1429 make_int (range->row));
|
|
1430 break;
|
|
1431 #endif /* MULE */
|
|
1432 case CHARTAB_RANGE_CHAR:
|
|
1433 ranjarg = make_char (range->ch);
|
|
1434 break;
|
|
1435 default:
|
|
1436 abort ();
|
|
1437 }
|
|
1438
|
|
1439 closure->retval = call2 (closure->function, ranjarg, val);
|
|
1440 return !NILP (closure->retval);
|
|
1441 }
|
|
1442
|
|
1443 DEFUN ("map-char-table", Fmap_char_table, 2, 3, 0, /*
|
444
|
1444 Map FUNCTION over entries in CHAR-TABLE, calling it with two args,
|
428
|
1445 each key and value in the table.
|
|
1446
|
|
1447 RANGE specifies a subrange to map over and is in the same format as
|
|
1448 the RANGE argument to `put-range-table'. If omitted or t, it defaults to
|
|
1449 the entire table.
|
|
1450 */
|
444
|
1451 (function, char_table, range))
|
428
|
1452 {
|
440
|
1453 Lisp_Char_Table *ct;
|
428
|
1454 struct slow_map_char_table_arg slarg;
|
|
1455 struct gcpro gcpro1, gcpro2;
|
|
1456 struct chartab_range rainj;
|
|
1457
|
444
|
1458 CHECK_CHAR_TABLE (char_table);
|
|
1459 ct = XCHAR_TABLE (char_table);
|
428
|
1460 if (NILP (range))
|
|
1461 range = Qt;
|
|
1462 decode_char_table_range (range, &rainj);
|
|
1463 slarg.function = function;
|
|
1464 slarg.retval = Qnil;
|
|
1465 GCPRO2 (slarg.function, slarg.retval);
|
|
1466 map_char_table (ct, &rainj, slow_map_char_table_fun, &slarg);
|
|
1467 UNGCPRO;
|
|
1468
|
|
1469 return slarg.retval;
|
|
1470 }
|
|
1471
|
|
1472
|
|
1473
|
|
1474 /************************************************************************/
|
|
1475 /* Char table read syntax */
|
|
1476 /************************************************************************/
|
|
1477
|
|
1478 static int
|
|
1479 chartab_type_validate (Lisp_Object keyword, Lisp_Object value,
|
578
|
1480 Error_Behavior errb)
|
428
|
1481 {
|
|
1482 /* #### should deal with ERRB */
|
|
1483 symbol_to_char_table_type (value);
|
|
1484 return 1;
|
|
1485 }
|
|
1486
|
|
1487 static int
|
|
1488 chartab_data_validate (Lisp_Object keyword, Lisp_Object value,
|
578
|
1489 Error_Behavior errb)
|
428
|
1490 {
|
|
1491 Lisp_Object rest;
|
|
1492
|
|
1493 /* #### should deal with ERRB */
|
|
1494 EXTERNAL_LIST_LOOP (rest, value)
|
|
1495 {
|
|
1496 Lisp_Object range = XCAR (rest);
|
|
1497 struct chartab_range dummy;
|
|
1498
|
|
1499 rest = XCDR (rest);
|
|
1500 if (!CONSP (rest))
|
563
|
1501 signal_error (Qlist_formation_error, "Invalid list format", value);
|
428
|
1502 if (CONSP (range))
|
|
1503 {
|
|
1504 if (!CONSP (XCDR (range))
|
|
1505 || !NILP (XCDR (XCDR (range))))
|
563
|
1506 sferror ("Invalid range format", range);
|
428
|
1507 decode_char_table_range (XCAR (range), &dummy);
|
|
1508 decode_char_table_range (XCAR (XCDR (range)), &dummy);
|
|
1509 }
|
|
1510 else
|
|
1511 decode_char_table_range (range, &dummy);
|
|
1512 }
|
|
1513
|
|
1514 return 1;
|
|
1515 }
|
|
1516
|
|
1517 static Lisp_Object
|
|
1518 chartab_instantiate (Lisp_Object data)
|
|
1519 {
|
|
1520 Lisp_Object chartab;
|
|
1521 Lisp_Object type = Qgeneric;
|
|
1522 Lisp_Object dataval = Qnil;
|
|
1523
|
|
1524 while (!NILP (data))
|
|
1525 {
|
|
1526 Lisp_Object keyw = Fcar (data);
|
|
1527 Lisp_Object valw;
|
|
1528
|
|
1529 data = Fcdr (data);
|
|
1530 valw = Fcar (data);
|
|
1531 data = Fcdr (data);
|
|
1532 if (EQ (keyw, Qtype))
|
|
1533 type = valw;
|
|
1534 else if (EQ (keyw, Qdata))
|
|
1535 dataval = valw;
|
|
1536 }
|
|
1537
|
|
1538 chartab = Fmake_char_table (type);
|
|
1539
|
|
1540 data = dataval;
|
|
1541 while (!NILP (data))
|
|
1542 {
|
|
1543 Lisp_Object range = Fcar (data);
|
|
1544 Lisp_Object val = Fcar (Fcdr (data));
|
|
1545
|
|
1546 data = Fcdr (Fcdr (data));
|
|
1547 if (CONSP (range))
|
|
1548 {
|
|
1549 if (CHAR_OR_CHAR_INTP (XCAR (range)))
|
|
1550 {
|
|
1551 Emchar first = XCHAR_OR_CHAR_INT (Fcar (range));
|
|
1552 Emchar last = XCHAR_OR_CHAR_INT (Fcar (Fcdr (range)));
|
|
1553 Emchar i;
|
|
1554
|
|
1555 for (i = first; i <= last; i++)
|
|
1556 Fput_char_table (make_char (i), val, chartab);
|
|
1557 }
|
|
1558 else
|
|
1559 abort ();
|
|
1560 }
|
|
1561 else
|
|
1562 Fput_char_table (range, val, chartab);
|
|
1563 }
|
|
1564
|
|
1565 return chartab;
|
|
1566 }
|
|
1567
|
|
1568 #ifdef MULE
|
|
1569
|
|
1570
|
|
1571 /************************************************************************/
|
|
1572 /* Category Tables, specifically */
|
|
1573 /************************************************************************/
|
|
1574
|
|
1575 DEFUN ("category-table-p", Fcategory_table_p, 1, 1, 0, /*
|
444
|
1576 Return t if OBJECT is a category table.
|
428
|
1577 A category table is a type of char table used for keeping track of
|
|
1578 categories. Categories are used for classifying characters for use
|
|
1579 in regexps -- you can refer to a category rather than having to use
|
|
1580 a complicated [] expression (and category lookups are significantly
|
|
1581 faster).
|
|
1582
|
|
1583 There are 95 different categories available, one for each printable
|
|
1584 character (including space) in the ASCII charset. Each category
|
|
1585 is designated by one such character, called a "category designator".
|
|
1586 They are specified in a regexp using the syntax "\\cX", where X is
|
|
1587 a category designator.
|
|
1588
|
|
1589 A category table specifies, for each character, the categories that
|
|
1590 the character is in. Note that a character can be in more than one
|
|
1591 category. More specifically, a category table maps from a character
|
|
1592 to either the value nil (meaning the character is in no categories)
|
|
1593 or a 95-element bit vector, specifying for each of the 95 categories
|
|
1594 whether the character is in that category.
|
|
1595
|
|
1596 Special Lisp functions are provided that abstract this, so you do not
|
|
1597 have to directly manipulate bit vectors.
|
|
1598 */
|
444
|
1599 (object))
|
428
|
1600 {
|
444
|
1601 return (CHAR_TABLEP (object) &&
|
|
1602 XCHAR_TABLE_TYPE (object) == CHAR_TABLE_TYPE_CATEGORY) ?
|
428
|
1603 Qt : Qnil;
|
|
1604 }
|
|
1605
|
|
1606 static Lisp_Object
|
444
|
1607 check_category_table (Lisp_Object object, Lisp_Object default_)
|
428
|
1608 {
|
444
|
1609 if (NILP (object))
|
|
1610 object = default_;
|
|
1611 while (NILP (Fcategory_table_p (object)))
|
|
1612 object = wrong_type_argument (Qcategory_table_p, object);
|
|
1613 return object;
|
428
|
1614 }
|
|
1615
|
|
1616 int
|
|
1617 check_category_char (Emchar ch, Lisp_Object table,
|
647
|
1618 int designator, int not_p)
|
428
|
1619 {
|
|
1620 REGISTER Lisp_Object temp;
|
440
|
1621 Lisp_Char_Table *ctbl;
|
428
|
1622 #ifdef ERROR_CHECK_TYPECHECK
|
|
1623 if (NILP (Fcategory_table_p (table)))
|
563
|
1624 wtaerror ("Expected category table", table);
|
428
|
1625 #endif
|
|
1626 ctbl = XCHAR_TABLE (table);
|
|
1627 temp = get_char_table (ch, ctbl);
|
|
1628 if (NILP (temp))
|
458
|
1629 return not_p;
|
428
|
1630
|
|
1631 designator -= ' ';
|
458
|
1632 return bit_vector_bit (XBIT_VECTOR (temp), designator) ? !not_p : not_p;
|
428
|
1633 }
|
|
1634
|
|
1635 DEFUN ("check-category-at", Fcheck_category_at, 2, 4, 0, /*
|
444
|
1636 Return t if category of the character at POSITION includes DESIGNATOR.
|
|
1637 Optional third arg BUFFER specifies which buffer to use, and defaults
|
|
1638 to the current buffer.
|
|
1639 Optional fourth arg CATEGORY-TABLE specifies the category table to
|
|
1640 use, and defaults to BUFFER's category table.
|
428
|
1641 */
|
444
|
1642 (position, designator, buffer, category_table))
|
428
|
1643 {
|
|
1644 Lisp_Object ctbl;
|
|
1645 Emchar ch;
|
647
|
1646 int des;
|
428
|
1647 struct buffer *buf = decode_buffer (buffer, 0);
|
|
1648
|
444
|
1649 CHECK_INT (position);
|
428
|
1650 CHECK_CATEGORY_DESIGNATOR (designator);
|
|
1651 des = XCHAR (designator);
|
788
|
1652 ctbl = check_category_table (category_table, buf->category_table);
|
444
|
1653 ch = BUF_FETCH_CHAR (buf, XINT (position));
|
428
|
1654 return check_category_char (ch, ctbl, des, 0) ? Qt : Qnil;
|
|
1655 }
|
|
1656
|
|
1657 DEFUN ("char-in-category-p", Fchar_in_category_p, 2, 3, 0, /*
|
788
|
1658 Return non-nil if category of CHARACTER includes DESIGNATOR.
|
444
|
1659 Optional third arg CATEGORY-TABLE specifies the category table to use,
|
788
|
1660 and defaults to the current buffer's category table.
|
428
|
1661 */
|
444
|
1662 (character, designator, category_table))
|
428
|
1663 {
|
|
1664 Lisp_Object ctbl;
|
|
1665 Emchar ch;
|
647
|
1666 int des;
|
428
|
1667
|
|
1668 CHECK_CATEGORY_DESIGNATOR (designator);
|
|
1669 des = XCHAR (designator);
|
444
|
1670 CHECK_CHAR (character);
|
|
1671 ch = XCHAR (character);
|
788
|
1672 ctbl = check_category_table (category_table, current_buffer->category_table);
|
428
|
1673 return check_category_char (ch, ctbl, des, 0) ? Qt : Qnil;
|
|
1674 }
|
|
1675
|
|
1676 DEFUN ("category-table", Fcategory_table, 0, 1, 0, /*
|
444
|
1677 Return BUFFER's current category table.
|
|
1678 BUFFER defaults to the current buffer.
|
428
|
1679 */
|
|
1680 (buffer))
|
|
1681 {
|
|
1682 return decode_buffer (buffer, 0)->category_table;
|
|
1683 }
|
|
1684
|
|
1685 DEFUN ("standard-category-table", Fstandard_category_table, 0, 0, 0, /*
|
|
1686 Return the standard category table.
|
|
1687 This is the one used for new buffers.
|
|
1688 */
|
|
1689 ())
|
|
1690 {
|
|
1691 return Vstandard_category_table;
|
|
1692 }
|
|
1693
|
|
1694 DEFUN ("copy-category-table", Fcopy_category_table, 0, 1, 0, /*
|
444
|
1695 Return a new category table which is a copy of CATEGORY-TABLE.
|
|
1696 CATEGORY-TABLE defaults to the standard category table.
|
428
|
1697 */
|
444
|
1698 (category_table))
|
428
|
1699 {
|
|
1700 if (NILP (Vstandard_category_table))
|
|
1701 return Fmake_char_table (Qcategory);
|
|
1702
|
444
|
1703 category_table =
|
|
1704 check_category_table (category_table, Vstandard_category_table);
|
|
1705 return Fcopy_char_table (category_table);
|
428
|
1706 }
|
|
1707
|
|
1708 DEFUN ("set-category-table", Fset_category_table, 1, 2, 0, /*
|
444
|
1709 Select CATEGORY-TABLE as the new category table for BUFFER.
|
428
|
1710 BUFFER defaults to the current buffer if omitted.
|
|
1711 */
|
444
|
1712 (category_table, buffer))
|
428
|
1713 {
|
|
1714 struct buffer *buf = decode_buffer (buffer, 0);
|
444
|
1715 category_table = check_category_table (category_table, Qnil);
|
|
1716 buf->category_table = category_table;
|
428
|
1717 /* Indicate that this buffer now has a specified category table. */
|
|
1718 buf->local_var_flags |= XINT (buffer_local_flags.category_table);
|
444
|
1719 return category_table;
|
428
|
1720 }
|
|
1721
|
|
1722 DEFUN ("category-designator-p", Fcategory_designator_p, 1, 1, 0, /*
|
444
|
1723 Return t if OBJECT is a category designator (a char in the range ' ' to '~').
|
428
|
1724 */
|
444
|
1725 (object))
|
428
|
1726 {
|
444
|
1727 return CATEGORY_DESIGNATORP (object) ? Qt : Qnil;
|
428
|
1728 }
|
|
1729
|
|
1730 DEFUN ("category-table-value-p", Fcategory_table_value_p, 1, 1, 0, /*
|
444
|
1731 Return t if OBJECT is a category table value.
|
428
|
1732 Valid values are nil or a bit vector of size 95.
|
|
1733 */
|
444
|
1734 (object))
|
428
|
1735 {
|
444
|
1736 return CATEGORY_TABLE_VALUEP (object) ? Qt : Qnil;
|
428
|
1737 }
|
|
1738
|
|
1739
|
|
1740 #define CATEGORYP(x) \
|
|
1741 (CHARP (x) && XCHAR (x) >= 0x20 && XCHAR (x) <= 0x7E)
|
|
1742
|
|
1743 #define CATEGORY_SET(c) \
|
|
1744 (get_char_table(c, XCHAR_TABLE(current_buffer->category_table)))
|
|
1745
|
|
1746 /* Return 1 if CATEGORY_SET contains CATEGORY, else return 0.
|
|
1747 The faster version of `!NILP (Faref (category_set, category))'. */
|
|
1748 #define CATEGORY_MEMBER(category, category_set) \
|
|
1749 (bit_vector_bit(XBIT_VECTOR (category_set), category - 32))
|
|
1750
|
|
1751 /* Return 1 if there is a word boundary between two word-constituent
|
|
1752 characters C1 and C2 if they appear in this order, else return 0.
|
|
1753 Use the macro WORD_BOUNDARY_P instead of calling this function
|
|
1754 directly. */
|
|
1755
|
|
1756 int word_boundary_p (Emchar c1, Emchar c2);
|
|
1757 int
|
|
1758 word_boundary_p (Emchar c1, Emchar c2)
|
|
1759 {
|
|
1760 Lisp_Object category_set1, category_set2;
|
|
1761 Lisp_Object tail;
|
|
1762 int default_result;
|
|
1763
|
|
1764 #if 0
|
|
1765 if (COMPOSITE_CHAR_P (c1))
|
|
1766 c1 = cmpchar_component (c1, 0, 1);
|
|
1767 if (COMPOSITE_CHAR_P (c2))
|
|
1768 c2 = cmpchar_component (c2, 0, 1);
|
|
1769 #endif
|
|
1770
|
|
1771 if (EQ (CHAR_CHARSET (c1), CHAR_CHARSET (c2)))
|
|
1772 {
|
|
1773 tail = Vword_separating_categories;
|
|
1774 default_result = 0;
|
|
1775 }
|
|
1776 else
|
|
1777 {
|
|
1778 tail = Vword_combining_categories;
|
|
1779 default_result = 1;
|
|
1780 }
|
|
1781
|
|
1782 category_set1 = CATEGORY_SET (c1);
|
|
1783 if (NILP (category_set1))
|
|
1784 return default_result;
|
|
1785 category_set2 = CATEGORY_SET (c2);
|
|
1786 if (NILP (category_set2))
|
|
1787 return default_result;
|
|
1788
|
|
1789 for (; CONSP (tail); tail = XCONS (tail)->cdr)
|
|
1790 {
|
|
1791 Lisp_Object elt = XCONS(tail)->car;
|
|
1792
|
|
1793 if (CONSP (elt)
|
|
1794 && CATEGORYP (XCONS (elt)->car)
|
|
1795 && CATEGORYP (XCONS (elt)->cdr)
|
|
1796 && CATEGORY_MEMBER (XCHAR (XCONS (elt)->car), category_set1)
|
|
1797 && CATEGORY_MEMBER (XCHAR (XCONS (elt)->cdr), category_set2))
|
|
1798 return !default_result;
|
|
1799 }
|
|
1800 return default_result;
|
|
1801 }
|
|
1802 #endif /* MULE */
|
|
1803
|
|
1804
|
|
1805 void
|
|
1806 syms_of_chartab (void)
|
|
1807 {
|
442
|
1808 INIT_LRECORD_IMPLEMENTATION (char_table);
|
|
1809
|
428
|
1810 #ifdef MULE
|
442
|
1811 INIT_LRECORD_IMPLEMENTATION (char_table_entry);
|
|
1812
|
563
|
1813 DEFSYMBOL (Qcategory_table_p);
|
|
1814 DEFSYMBOL (Qcategory_designator_p);
|
|
1815 DEFSYMBOL (Qcategory_table_value_p);
|
428
|
1816 #endif /* MULE */
|
|
1817
|
563
|
1818 DEFSYMBOL (Qchar_table);
|
|
1819 DEFSYMBOL_MULTIWORD_PREDICATE (Qchar_tablep);
|
428
|
1820
|
|
1821 DEFSUBR (Fchar_table_p);
|
|
1822 DEFSUBR (Fchar_table_type_list);
|
|
1823 DEFSUBR (Fvalid_char_table_type_p);
|
|
1824 DEFSUBR (Fchar_table_type);
|
|
1825 DEFSUBR (Freset_char_table);
|
|
1826 DEFSUBR (Fmake_char_table);
|
|
1827 DEFSUBR (Fcopy_char_table);
|
|
1828 DEFSUBR (Fget_char_table);
|
|
1829 DEFSUBR (Fget_range_char_table);
|
|
1830 DEFSUBR (Fvalid_char_table_value_p);
|
|
1831 DEFSUBR (Fcheck_valid_char_table_value);
|
|
1832 DEFSUBR (Fput_char_table);
|
|
1833 DEFSUBR (Fmap_char_table);
|
|
1834
|
|
1835 #ifdef MULE
|
|
1836 DEFSUBR (Fcategory_table_p);
|
|
1837 DEFSUBR (Fcategory_table);
|
|
1838 DEFSUBR (Fstandard_category_table);
|
|
1839 DEFSUBR (Fcopy_category_table);
|
|
1840 DEFSUBR (Fset_category_table);
|
|
1841 DEFSUBR (Fcheck_category_at);
|
|
1842 DEFSUBR (Fchar_in_category_p);
|
|
1843 DEFSUBR (Fcategory_designator_p);
|
|
1844 DEFSUBR (Fcategory_table_value_p);
|
|
1845 #endif /* MULE */
|
|
1846
|
|
1847 }
|
|
1848
|
|
1849 void
|
|
1850 vars_of_chartab (void)
|
|
1851 {
|
|
1852 /* DO NOT staticpro this. It works just like Vweak_hash_tables. */
|
|
1853 Vall_syntax_tables = Qnil;
|
452
|
1854 dump_add_weak_object_chain (&Vall_syntax_tables);
|
428
|
1855 }
|
|
1856
|
|
1857 void
|
|
1858 structure_type_create_chartab (void)
|
|
1859 {
|
|
1860 struct structure_type *st;
|
|
1861
|
|
1862 st = define_structure_type (Qchar_table, 0, chartab_instantiate);
|
|
1863
|
|
1864 define_structure_type_keyword (st, Qtype, chartab_type_validate);
|
|
1865 define_structure_type_keyword (st, Qdata, chartab_data_validate);
|
|
1866 }
|
|
1867
|
|
1868 void
|
|
1869 complex_vars_of_chartab (void)
|
|
1870 {
|
|
1871 #ifdef MULE
|
|
1872 /* Set this now, so first buffer creation can refer to it. */
|
|
1873 /* Make it nil before calling copy-category-table
|
|
1874 so that copy-category-table will know not to try to copy from garbage */
|
|
1875 Vstandard_category_table = Qnil;
|
|
1876 Vstandard_category_table = Fcopy_category_table (Qnil);
|
|
1877 staticpro (&Vstandard_category_table);
|
|
1878
|
|
1879 DEFVAR_LISP ("word-combining-categories", &Vword_combining_categories /*
|
|
1880 List of pair (cons) of categories to determine word boundary.
|
|
1881
|
|
1882 Emacs treats a sequence of word constituent characters as a single
|
|
1883 word (i.e. finds no word boundary between them) iff they belongs to
|
|
1884 the same charset. But, exceptions are allowed in the following cases.
|
|
1885
|
444
|
1886 \(1) The case that characters are in different charsets is controlled
|
428
|
1887 by the variable `word-combining-categories'.
|
|
1888
|
|
1889 Emacs finds no word boundary between characters of different charsets
|
|
1890 if they have categories matching some element of this list.
|
|
1891
|
|
1892 More precisely, if an element of this list is a cons of category CAT1
|
|
1893 and CAT2, and a multibyte character C1 which has CAT1 is followed by
|
|
1894 C2 which has CAT2, there's no word boundary between C1 and C2.
|
|
1895
|
|
1896 For instance, to tell that ASCII characters and Latin-1 characters can
|
|
1897 form a single word, the element `(?l . ?l)' should be in this list
|
|
1898 because both characters have the category `l' (Latin characters).
|
|
1899
|
444
|
1900 \(2) The case that character are in the same charset is controlled by
|
428
|
1901 the variable `word-separating-categories'.
|
|
1902
|
|
1903 Emacs find a word boundary between characters of the same charset
|
|
1904 if they have categories matching some element of this list.
|
|
1905
|
|
1906 More precisely, if an element of this list is a cons of category CAT1
|
|
1907 and CAT2, and a multibyte character C1 which has CAT1 is followed by
|
|
1908 C2 which has CAT2, there's a word boundary between C1 and C2.
|
|
1909
|
|
1910 For instance, to tell that there's a word boundary between Japanese
|
|
1911 Hiragana and Japanese Kanji (both are in the same charset), the
|
|
1912 element `(?H . ?C) should be in this list.
|
|
1913 */ );
|
|
1914
|
|
1915 Vword_combining_categories = Qnil;
|
|
1916
|
|
1917 DEFVAR_LISP ("word-separating-categories", &Vword_separating_categories /*
|
|
1918 List of pair (cons) of categories to determine word boundary.
|
|
1919 See the documentation of the variable `word-combining-categories'.
|
|
1920 */ );
|
|
1921
|
|
1922 Vword_separating_categories = Qnil;
|
|
1923 #endif /* MULE */
|
|
1924 }
|