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