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