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 {
|
|
470 return (CHAR_TABLEP (object) ? Qt : Qnil);
|
|
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 {
|
|
516 if (EQ (type, Qchar)
|
|
517 #ifdef MULE
|
|
518 || EQ (type, Qcategory)
|
|
519 #endif
|
|
520 || EQ (type, Qdisplay)
|
|
521 || EQ (type, Qgeneric)
|
|
522 || EQ (type, Qsyntax))
|
|
523 return Qt;
|
|
524
|
|
525 return Qnil;
|
|
526 }
|
|
527
|
|
528 DEFUN ("char-table-type", Fchar_table_type, 1, 1, 0, /*
|
|
529 Return the type of char table TABLE.
|
|
530 See `valid-char-table-type-p'.
|
|
531 */
|
|
532 (table))
|
|
533 {
|
|
534 CHECK_CHAR_TABLE (table);
|
|
535 return char_table_type_to_symbol (XCHAR_TABLE (table)->type);
|
|
536 }
|
|
537
|
|
538 void
|
|
539 fill_char_table (struct Lisp_Char_Table *ct, Lisp_Object value)
|
|
540 {
|
|
541 int i;
|
|
542
|
|
543 for (i = 0; i < NUM_ASCII_CHARS; i++)
|
|
544 ct->ascii[i] = value;
|
|
545 #ifdef MULE
|
|
546 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
547 ct->level1[i] = value;
|
|
548 #endif /* MULE */
|
|
549
|
|
550 if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
|
|
551 update_syntax_table (ct);
|
|
552 }
|
|
553
|
|
554 DEFUN ("reset-char-table", Freset_char_table, 1, 1, 0, /*
|
|
555 Reset a char table to its default state.
|
|
556 */
|
|
557 (table))
|
|
558 {
|
|
559 struct Lisp_Char_Table *ct;
|
|
560
|
|
561 CHECK_CHAR_TABLE (table);
|
|
562 ct = XCHAR_TABLE (table);
|
|
563
|
|
564 switch (ct->type)
|
|
565 {
|
|
566 case CHAR_TABLE_TYPE_CHAR:
|
|
567 case CHAR_TABLE_TYPE_DISPLAY:
|
|
568 case CHAR_TABLE_TYPE_GENERIC:
|
|
569 #ifdef MULE
|
|
570 case CHAR_TABLE_TYPE_CATEGORY:
|
|
571 fill_char_table (ct, Qnil);
|
|
572 break;
|
|
573 #endif
|
|
574
|
|
575 case CHAR_TABLE_TYPE_SYNTAX:
|
|
576 fill_char_table (ct, make_int (Sinherit));
|
|
577 break;
|
|
578
|
|
579 default:
|
|
580 abort ();
|
|
581 }
|
|
582
|
|
583 return Qnil;
|
|
584 }
|
|
585
|
|
586 DEFUN ("make-char-table", Fmake_char_table, 1, 1, 0, /*
|
|
587 Make a new, empty char table of type TYPE.
|
|
588 Currently recognized types are 'char, 'category, 'display, 'generic,
|
|
589 and 'syntax. See `valid-char-table-type-p'.
|
|
590 */
|
|
591 (type))
|
|
592 {
|
|
593 struct Lisp_Char_Table *ct;
|
|
594 Lisp_Object obj = Qnil;
|
|
595 enum char_table_type ty = symbol_to_char_table_type (type);
|
|
596
|
|
597 ct = (struct Lisp_Char_Table *)
|
|
598 alloc_lcrecord (sizeof (struct Lisp_Char_Table), lrecord_char_table);
|
|
599 ct->type = ty;
|
|
600 if (ty == CHAR_TABLE_TYPE_SYNTAX)
|
|
601 {
|
|
602 ct->mirror_table = Fmake_char_table (Qgeneric);
|
|
603 }
|
|
604 else
|
|
605 ct->mirror_table = Qnil;
|
|
606 ct->next_table = Qnil;
|
|
607 XSETCHAR_TABLE (obj, ct);
|
|
608 if (ty == CHAR_TABLE_TYPE_SYNTAX)
|
|
609 {
|
|
610 ct->next_table = Vall_syntax_tables;
|
|
611 Vall_syntax_tables = obj;
|
|
612 }
|
|
613 Freset_char_table (obj);
|
|
614 return obj;
|
|
615 }
|
|
616
|
|
617 #ifdef MULE
|
|
618
|
|
619 static Lisp_Object
|
|
620 make_char_table_entry (Lisp_Object initval)
|
|
621 {
|
|
622 struct Lisp_Char_Table_Entry *cte;
|
|
623 Lisp_Object obj = Qnil;
|
|
624 int i;
|
|
625
|
|
626 cte = (struct Lisp_Char_Table_Entry *)
|
|
627 alloc_lcrecord (sizeof (struct Lisp_Char_Table_Entry),
|
|
628 lrecord_char_table_entry);
|
|
629 for (i = 0; i < 96; i++)
|
|
630 cte->level2[i] = initval;
|
|
631 XSETCHAR_TABLE_ENTRY (obj, cte);
|
|
632 return obj;
|
|
633 }
|
|
634
|
|
635 static Lisp_Object
|
|
636 copy_char_table_entry (Lisp_Object entry)
|
|
637 {
|
|
638 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (entry);
|
|
639 struct Lisp_Char_Table_Entry *ctenew;
|
|
640 Lisp_Object obj = Qnil;
|
|
641 int i;
|
|
642
|
|
643 ctenew = (struct Lisp_Char_Table_Entry *)
|
|
644 alloc_lcrecord (sizeof (struct Lisp_Char_Table_Entry),
|
|
645 lrecord_char_table_entry);
|
|
646 for (i = 0; i < 96; i++)
|
|
647 {
|
|
648 Lisp_Object new = cte->level2[i];
|
|
649 if (CHAR_TABLE_ENTRYP (new))
|
|
650 ctenew->level2[i] = copy_char_table_entry (new);
|
|
651 else
|
|
652 ctenew->level2[i] = new;
|
|
653 }
|
|
654
|
|
655 XSETCHAR_TABLE_ENTRY (obj, cte);
|
|
656 return obj;
|
|
657 }
|
|
658
|
|
659 #endif /* MULE */
|
|
660
|
|
661 DEFUN ("copy-char-table", Fcopy_char_table, 1, 1, 0, /*
|
|
662 Make a new char table which is a copy of OLD-TABLE.
|
|
663 It will contain the same values for the same characters and ranges
|
|
664 as OLD-TABLE. The values will not themselves be copied.
|
|
665 */
|
|
666 (old_table))
|
|
667 {
|
|
668 struct Lisp_Char_Table *ct, *ctnew;
|
|
669 Lisp_Object obj = Qnil;
|
|
670 int i;
|
|
671
|
|
672 CHECK_CHAR_TABLE (old_table);
|
|
673 ct = XCHAR_TABLE (old_table);
|
|
674 ctnew = (struct Lisp_Char_Table *)
|
|
675 alloc_lcrecord (sizeof (struct Lisp_Char_Table), lrecord_char_table);
|
|
676 ctnew->type = ct->type;
|
|
677
|
|
678 for (i = 0; i < NUM_ASCII_CHARS; i++)
|
|
679 {
|
|
680 Lisp_Object new = ct->ascii[i];
|
|
681 #ifdef MULE
|
|
682 assert (! (CHAR_TABLE_ENTRYP (new)));
|
|
683 #endif /* MULE */
|
|
684 ctnew->ascii[i] = new;
|
|
685 }
|
|
686
|
|
687 #ifdef MULE
|
|
688
|
|
689 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
690 {
|
|
691 Lisp_Object new = ct->level1[i];
|
|
692 if (CHAR_TABLE_ENTRYP (new))
|
|
693 ctnew->level1[i] = copy_char_table_entry (new);
|
|
694 else
|
|
695 ctnew->level1[i] = new;
|
|
696 }
|
|
697
|
|
698 #endif /* MULE */
|
|
699
|
|
700 if (CHAR_TABLEP (ct->mirror_table))
|
|
701 ctnew->mirror_table = Fcopy_char_table (ct->mirror_table);
|
|
702 else
|
|
703 ctnew->mirror_table = ct->mirror_table;
|
|
704 XSETCHAR_TABLE (obj, ctnew);
|
|
705 return obj;
|
|
706 }
|
|
707
|
|
708 static void
|
|
709 decode_char_table_range (Lisp_Object range, struct chartab_range *outrange)
|
|
710 {
|
|
711 if (EQ (range, Qt))
|
|
712 outrange->type = CHARTAB_RANGE_ALL;
|
|
713 else if (CHAR_OR_CHAR_INTP (range))
|
|
714 {
|
|
715 outrange->type = CHARTAB_RANGE_CHAR;
|
|
716 outrange->ch = XCHAR_OR_CHAR_INT (range);
|
|
717 }
|
|
718 #ifndef MULE
|
|
719 else
|
|
720 signal_simple_error ("Range must be t or a character", range);
|
|
721 #else /* MULE */
|
|
722 else if (VECTORP (range))
|
|
723 {
|
|
724 struct Lisp_Vector *vec = XVECTOR (range);
|
|
725 Lisp_Object *elts = vector_data (vec);
|
|
726 if (vector_length (vec) != 2)
|
|
727 signal_simple_error ("Length of charset row vector must be 2",
|
|
728 range);
|
|
729 outrange->type = CHARTAB_RANGE_ROW;
|
|
730 outrange->charset = Fget_charset (elts[0]);
|
|
731 CHECK_INT (elts[1]);
|
|
732 outrange->row = XINT (elts[1]);
|
|
733 switch (XCHARSET_TYPE (outrange->charset))
|
|
734 {
|
|
735 case CHARSET_TYPE_94:
|
|
736 case CHARSET_TYPE_96:
|
|
737 signal_simple_error ("Charset in row vector must be multi-byte",
|
|
738 outrange->charset);
|
|
739 case CHARSET_TYPE_94X94:
|
|
740 check_int_range (outrange->row, 33, 126);
|
|
741 break;
|
|
742 case CHARSET_TYPE_96X96:
|
|
743 check_int_range (outrange->row, 32, 127);
|
|
744 break;
|
|
745 default:
|
|
746 abort ();
|
|
747 }
|
|
748 }
|
|
749 else
|
|
750 {
|
|
751 if (!CHARSETP (range) && !SYMBOLP (range))
|
|
752 signal_simple_error
|
|
753 ("Char table range must be t, charset, char, or vector", range);
|
|
754 outrange->type = CHARTAB_RANGE_CHARSET;
|
|
755 outrange->charset = Fget_charset (range);
|
|
756 }
|
|
757 #endif /* MULE */
|
|
758 }
|
|
759
|
|
760 #ifdef MULE
|
|
761
|
|
762 /* called from CHAR_TABLE_VALUE(). */
|
|
763 Lisp_Object
|
|
764 get_non_ascii_char_table_value (struct Lisp_Char_Table *ct, int leading_byte,
|
|
765 Emchar c)
|
|
766 {
|
|
767 Lisp_Object val;
|
|
768 Lisp_Object charset = CHARSET_BY_LEADING_BYTE (leading_byte);
|
|
769 int byte1, byte2;
|
|
770
|
|
771 BREAKUP_CHAR_1_UNSAFE (c, charset, byte1, byte2);
|
|
772 val = ct->level1[leading_byte - MIN_LEADING_BYTE];
|
|
773 if (CHAR_TABLE_ENTRYP (val))
|
|
774 {
|
|
775 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
|
|
776 val = cte->level2[byte1 - 32];
|
|
777 if (CHAR_TABLE_ENTRYP (val))
|
|
778 {
|
|
779 cte = XCHAR_TABLE_ENTRY (val);
|
|
780 assert (byte2 >= 32);
|
|
781 val = cte->level2[byte2 - 32];
|
|
782 assert (!CHAR_TABLE_ENTRYP (val));
|
|
783 }
|
|
784 }
|
|
785
|
|
786 return val;
|
|
787 }
|
|
788
|
|
789 #endif /* MULE */
|
|
790
|
104
|
791 static Lisp_Object
|
|
792 get_char_table (Emchar ch, struct Lisp_Char_Table *ct)
|
70
|
793 {
|
|
794 #ifdef MULE
|
|
795 {
|
|
796 Lisp_Object charset;
|
|
797 int byte1, byte2;
|
|
798 Lisp_Object val;
|
|
799
|
104
|
800 BREAKUP_CHAR (ch, charset, byte1, byte2);
|
70
|
801
|
|
802 if (EQ (charset, Vcharset_ascii))
|
|
803 val = ct->ascii[byte1];
|
|
804 else if (EQ (charset, Vcharset_control_1))
|
|
805 val = ct->ascii[byte1 + 128];
|
|
806 else
|
|
807 {
|
|
808 int lb = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
|
|
809 val = ct->level1[lb];
|
|
810 if (CHAR_TABLE_ENTRYP (val))
|
|
811 {
|
|
812 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
|
|
813 val = cte->level2[byte1 - 32];
|
|
814 if (CHAR_TABLE_ENTRYP (val))
|
|
815 {
|
|
816 cte = XCHAR_TABLE_ENTRY (val);
|
|
817 assert (byte2 >= 32);
|
|
818 val = cte->level2[byte2 - 32];
|
|
819 assert (!CHAR_TABLE_ENTRYP (val));
|
|
820 }
|
|
821 }
|
|
822 }
|
|
823
|
|
824 return val;
|
|
825 }
|
|
826 #else /* not MULE */
|
104
|
827 return ct->ascii[(unsigned char)ch];
|
70
|
828 #endif /* not MULE */
|
|
829 }
|
|
830
|
104
|
831
|
|
832 DEFUN ("get-char-table", Fget_char_table, 2, 2, 0, /*
|
|
833 Find value for char CH in TABLE.
|
|
834 */
|
|
835 (ch, table))
|
|
836 {
|
|
837 struct Lisp_Char_Table *ct;
|
|
838 Emchar chr;
|
|
839
|
|
840 CHECK_CHAR_TABLE (table);
|
|
841 ct = XCHAR_TABLE (table);
|
|
842 CHECK_CHAR_COERCE_INT (ch);
|
|
843 chr = XCHAR(ch);
|
|
844
|
|
845 return (get_char_table (chr, ct));
|
|
846 }
|
|
847
|
70
|
848 DEFUN ("get-range-char-table", Fget_range_char_table, 2, 3, 0, /*
|
|
849 Find value for a range in TABLE.
|
|
850 If there is more than one value, return MULTI (defaults to nil).
|
|
851 */
|
|
852 (range, table, multi))
|
|
853 {
|
|
854 struct Lisp_Char_Table *ct;
|
|
855 struct chartab_range rainj;
|
|
856
|
|
857 if (CHAR_OR_CHAR_INTP (range))
|
|
858 return Fget_char_table (range, table);
|
|
859 CHECK_CHAR_TABLE (table);
|
|
860 ct = XCHAR_TABLE (table);
|
|
861
|
|
862 decode_char_table_range (range, &rainj);
|
|
863 switch (rainj.type)
|
|
864 {
|
|
865 case CHARTAB_RANGE_ALL:
|
|
866 {
|
|
867 int i;
|
|
868 Lisp_Object first = ct->ascii[0];
|
|
869
|
|
870 for (i = 1; i < NUM_ASCII_CHARS; i++)
|
|
871 if (!EQ (first, ct->ascii[i]))
|
|
872 return multi;
|
|
873
|
|
874 #ifdef MULE
|
|
875 for (i = MIN_LEADING_BYTE; i < MIN_LEADING_BYTE + NUM_LEADING_BYTES;
|
|
876 i++)
|
|
877 {
|
|
878 if (!CHARSETP (CHARSET_BY_LEADING_BYTE (i))
|
|
879 || i == LEADING_BYTE_ASCII
|
|
880 || i == LEADING_BYTE_CONTROL_1)
|
|
881 continue;
|
|
882 if (!EQ (first, ct->level1[i - MIN_LEADING_BYTE]))
|
|
883 return multi;
|
|
884 }
|
|
885 #endif /* MULE */
|
|
886
|
|
887 return first;
|
|
888 }
|
|
889
|
|
890 #ifdef MULE
|
|
891 case CHARTAB_RANGE_CHARSET:
|
|
892 if (EQ (rainj.charset, Vcharset_ascii))
|
|
893 {
|
|
894 int i;
|
|
895 Lisp_Object first = ct->ascii[0];
|
|
896
|
|
897 for (i = 1; i < 128; i++)
|
|
898 if (!EQ (first, ct->ascii[i]))
|
|
899 return multi;
|
|
900 return first;
|
|
901 }
|
|
902
|
|
903 if (EQ (rainj.charset, Vcharset_control_1))
|
|
904 {
|
|
905 int i;
|
|
906 Lisp_Object first = ct->ascii[128];
|
|
907
|
|
908 for (i = 129; i < 160; i++)
|
|
909 if (!EQ (first, ct->ascii[i]))
|
|
910 return multi;
|
|
911 return first;
|
|
912 }
|
|
913
|
|
914 {
|
|
915 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (rainj.charset) -
|
|
916 MIN_LEADING_BYTE];
|
|
917 if (CHAR_TABLE_ENTRYP (val))
|
|
918 return multi;
|
|
919 return val;
|
|
920 }
|
|
921
|
|
922 case CHARTAB_RANGE_ROW:
|
|
923 {
|
|
924 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (rainj.charset) -
|
|
925 MIN_LEADING_BYTE];
|
|
926 if (!CHAR_TABLE_ENTRYP (val))
|
|
927 return val;
|
|
928 val = XCHAR_TABLE_ENTRY (val)->level2[rainj.row - 32];
|
|
929 if (CHAR_TABLE_ENTRYP (val))
|
|
930 return multi;
|
|
931 return val;
|
|
932 }
|
|
933 #endif /* not MULE */
|
|
934
|
|
935 default:
|
|
936 abort ();
|
|
937 }
|
|
938
|
|
939 return Qnil; /* not reached */
|
|
940 }
|
|
941
|
|
942 static int
|
|
943 check_valid_char_table_value (Lisp_Object value, enum char_table_type type,
|
|
944 Error_behavior errb)
|
|
945 {
|
|
946 switch (type)
|
|
947 {
|
|
948 case CHAR_TABLE_TYPE_SYNTAX:
|
|
949 if (!ERRB_EQ (errb, ERROR_ME))
|
|
950 return INTP (value) || (CONSP (value) && INTP (XCAR (value))
|
|
951 && CHAR_OR_CHAR_INTP (XCDR (value)));
|
|
952 if (CONSP (value))
|
|
953 {
|
|
954 Lisp_Object cdr = XCDR (value);
|
|
955 CHECK_INT (XCAR (value));
|
|
956 CHECK_CHAR_COERCE_INT (cdr);
|
|
957 }
|
|
958 else
|
|
959 CHECK_INT (value);
|
|
960 break;
|
|
961
|
|
962 #ifdef MULE
|
|
963 case CHAR_TABLE_TYPE_CATEGORY:
|
|
964 if (!ERRB_EQ (errb, ERROR_ME))
|
|
965 return CATEGORY_TABLE_VALUEP (value);
|
|
966 CHECK_CATEGORY_TABLE_VALUE (value);
|
|
967 break;
|
|
968 #endif
|
|
969
|
|
970 case CHAR_TABLE_TYPE_GENERIC:
|
|
971 return 1;
|
|
972
|
|
973 case CHAR_TABLE_TYPE_DISPLAY:
|
|
974 /* #### fix this */
|
|
975 maybe_signal_simple_error ("Display char tables not yet implemented",
|
|
976 value, Qchar_table, errb);
|
|
977 return 0;
|
|
978
|
|
979 case CHAR_TABLE_TYPE_CHAR:
|
|
980 if (!ERRB_EQ (errb, ERROR_ME))
|
|
981 return CHAR_OR_CHAR_INTP (value);
|
|
982 CHECK_CHAR_COERCE_INT (value);
|
|
983 break;
|
|
984
|
|
985 default:
|
|
986 abort ();
|
|
987 }
|
|
988
|
|
989 return 0; /* not reached */
|
|
990 }
|
|
991
|
|
992 static Lisp_Object
|
|
993 canonicalize_char_table_value (Lisp_Object value, enum char_table_type type)
|
|
994 {
|
|
995 switch (type)
|
|
996 {
|
|
997 case CHAR_TABLE_TYPE_SYNTAX:
|
|
998 if (CONSP (value))
|
|
999 {
|
|
1000 Lisp_Object car = XCAR (value);
|
|
1001 Lisp_Object cdr = XCDR (value);
|
|
1002 CHECK_CHAR_COERCE_INT (cdr);
|
|
1003 return Fcons (car, cdr);
|
|
1004 }
|
|
1005 default:
|
|
1006 break;
|
|
1007 }
|
|
1008 return value;
|
|
1009 }
|
|
1010
|
|
1011 DEFUN ("valid-char-table-value-p", Fvalid_char_table_value_p, 2, 2, 0, /*
|
|
1012 Return non-nil if VALUE is a valid value for CHAR-TABLE-TYPE.
|
|
1013 */
|
|
1014 (value, char_table_type))
|
|
1015 {
|
|
1016 enum char_table_type type = symbol_to_char_table_type (char_table_type);
|
|
1017
|
|
1018 return check_valid_char_table_value (value, type, ERROR_ME_NOT) ? Qt : Qnil;
|
|
1019 }
|
|
1020
|
|
1021 DEFUN ("check-valid-char-table-value", Fcheck_valid_char_table_value, 2, 2, 0, /*
|
|
1022 Signal an error if VALUE is not a valid value for CHAR-TABLE-TYPE.
|
|
1023 */
|
|
1024 (value, char_table_type))
|
|
1025 {
|
|
1026 enum char_table_type type = symbol_to_char_table_type (char_table_type);
|
|
1027
|
|
1028 check_valid_char_table_value (value, type, ERROR_ME);
|
|
1029 return Qnil;
|
|
1030 }
|
|
1031
|
|
1032 /* Assign VAL to all characters in RANGE in char table CT. */
|
|
1033
|
|
1034 void
|
|
1035 put_char_table (struct Lisp_Char_Table *ct, struct chartab_range *range,
|
|
1036 Lisp_Object val)
|
|
1037 {
|
|
1038 switch (range->type)
|
|
1039 {
|
|
1040 case CHARTAB_RANGE_ALL:
|
|
1041 fill_char_table (ct, val);
|
|
1042 return; /* avoid the duplicate call to update_syntax_table() below,
|
|
1043 since fill_char_table() also did that. */
|
|
1044
|
|
1045 #ifdef MULE
|
|
1046 case CHARTAB_RANGE_CHARSET:
|
|
1047 if (EQ (range->charset, Vcharset_ascii))
|
|
1048 {
|
|
1049 int i;
|
|
1050 for (i = 0; i < 128; i++)
|
|
1051 ct->ascii[i] = val;
|
|
1052 }
|
|
1053 else if (EQ (range->charset, Vcharset_control_1))
|
|
1054 {
|
|
1055 int i;
|
|
1056 for (i = 128; i < 160; i++)
|
|
1057 ct->ascii[i] = val;
|
|
1058 }
|
|
1059 else
|
|
1060 {
|
|
1061 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
|
|
1062 ct->level1[lb] = val;
|
|
1063 }
|
|
1064 break;
|
|
1065
|
|
1066 case CHARTAB_RANGE_ROW:
|
|
1067 {
|
|
1068 struct Lisp_Char_Table_Entry *cte;
|
|
1069 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
|
|
1070 /* make sure that there is a separate entry for the row. */
|
|
1071 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
|
|
1072 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
|
|
1073 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
|
|
1074 cte->level2[range->row - 32] = val;
|
|
1075 }
|
|
1076 break;
|
|
1077 #endif /* MULE */
|
|
1078
|
|
1079 case CHARTAB_RANGE_CHAR:
|
|
1080 #ifdef MULE
|
|
1081 {
|
|
1082 Lisp_Object charset;
|
|
1083 int byte1, byte2;
|
|
1084
|
|
1085 BREAKUP_CHAR (range->ch, charset, byte1, byte2);
|
|
1086 if (EQ (charset, Vcharset_ascii))
|
|
1087 ct->ascii[byte1] = val;
|
|
1088 else if (EQ (charset, Vcharset_control_1))
|
|
1089 ct->ascii[byte1 + 128] = val;
|
|
1090 else
|
|
1091 {
|
|
1092 struct Lisp_Char_Table_Entry *cte;
|
|
1093 int lb = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
|
|
1094 /* make sure that there is a separate entry for the row. */
|
|
1095 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
|
|
1096 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
|
|
1097 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
|
|
1098 /* now CTE is a char table entry for the charset;
|
|
1099 each entry is for a single row (or character of
|
|
1100 a one-octet charset). */
|
|
1101 if (XCHARSET_DIMENSION (charset) == 1)
|
|
1102 cte->level2[byte1 - 32] = val;
|
|
1103 else
|
|
1104 {
|
|
1105 /* assigning to one character in a two-octet charset. */
|
|
1106 /* make sure that the charset row contains a separate
|
|
1107 entry for each character. */
|
|
1108 if (!CHAR_TABLE_ENTRYP (cte->level2[byte1 - 32]))
|
|
1109 cte->level2[byte1 - 32] =
|
|
1110 make_char_table_entry (cte->level2[byte1 - 32]);
|
|
1111 cte = XCHAR_TABLE_ENTRY (cte->level2[byte1 - 32]);
|
|
1112 cte->level2[byte2 - 32] = val;
|
|
1113 }
|
|
1114 }
|
|
1115 }
|
|
1116 #else /* not MULE */
|
|
1117 ct->ascii[(unsigned char) (range->ch)] = val;
|
|
1118 break;
|
|
1119 #endif /* not MULE */
|
|
1120 }
|
|
1121
|
|
1122 if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
|
|
1123 update_syntax_table (ct);
|
|
1124 }
|
|
1125
|
|
1126 DEFUN ("put-char-table", Fput_char_table, 3, 3, 0, /*
|
|
1127 Set the value for chars in RANGE to be VAL in TABLE.
|
|
1128
|
|
1129 RANGE specifies one or more characters to be affected and should be
|
|
1130 one of the following:
|
|
1131
|
|
1132 -- t (all characters are affected)
|
|
1133 -- A charset (only allowed when Mule support is present)
|
|
1134 -- A vector of two elements: a two-octet charset and a row number
|
|
1135 (only allowed when Mule support is present)
|
|
1136 -- A single character
|
|
1137
|
|
1138 VAL must be a value appropriate for the type of TABLE.
|
|
1139 See `valid-char-table-type-p'.
|
|
1140 */
|
|
1141 (range, val, table))
|
|
1142 {
|
|
1143 struct Lisp_Char_Table *ct;
|
|
1144 struct chartab_range rainj;
|
|
1145
|
|
1146 CHECK_CHAR_TABLE (table);
|
|
1147 ct = XCHAR_TABLE (table);
|
|
1148 check_valid_char_table_value (val, ct->type, ERROR_ME);
|
|
1149 decode_char_table_range (range, &rainj);
|
|
1150 val = canonicalize_char_table_value (val, ct->type);
|
|
1151 put_char_table (ct, &rainj, val);
|
|
1152 return Qnil;
|
|
1153 }
|
|
1154
|
|
1155 /* Map FN over the ASCII chars in CT. */
|
|
1156
|
|
1157 static int
|
|
1158 map_over_charset_ascii (struct Lisp_Char_Table *ct,
|
|
1159 int (*fn) (struct chartab_range *range,
|
|
1160 Lisp_Object val, void *arg),
|
|
1161 void *arg)
|
|
1162 {
|
|
1163 int i;
|
|
1164
|
|
1165 #ifdef MULE
|
|
1166 for (i = 0; i < 128; i++)
|
|
1167 #else
|
|
1168 for (i = 0; i < 256; i++)
|
|
1169 #endif
|
|
1170 {
|
|
1171 Lisp_Object val = ct->ascii[i];
|
|
1172 struct chartab_range rainj;
|
|
1173 int retval;
|
|
1174
|
|
1175 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1176 rainj.ch = (Emchar) i;
|
|
1177 retval = (fn) (&rainj, val, arg);
|
|
1178 if (retval)
|
|
1179 return retval;
|
|
1180 }
|
|
1181
|
|
1182 return 0;
|
|
1183 }
|
|
1184
|
|
1185 #ifdef MULE
|
|
1186
|
|
1187 /* Map FN over the Control-1 chars in CT. */
|
|
1188
|
|
1189 static int
|
|
1190 map_over_charset_control_1 (struct Lisp_Char_Table *ct,
|
|
1191 int (*fn) (struct chartab_range *range,
|
|
1192 Lisp_Object val, void *arg),
|
|
1193 void *arg)
|
|
1194 {
|
|
1195 int i;
|
|
1196
|
|
1197 for (i = 0; i < 32; i++)
|
|
1198 {
|
|
1199 Lisp_Object val = ct->ascii[i + 128];
|
|
1200 struct chartab_range rainj;
|
|
1201 int retval;
|
|
1202
|
|
1203 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1204 rainj.ch = (Emchar) (i + 128);
|
|
1205 retval = (fn) (&rainj, val, arg);
|
|
1206 if (retval)
|
|
1207 return retval;
|
|
1208 }
|
|
1209
|
|
1210 return 0;
|
|
1211 }
|
|
1212
|
|
1213 /* Map FN over the row ROW of two-byte charset CHARSET.
|
|
1214 There must be a separate value for that row in the char table.
|
|
1215 CTE specifies the char table entry for CHARSET. */
|
|
1216
|
|
1217 static int
|
|
1218 map_over_charset_row (struct Lisp_Char_Table_Entry *cte,
|
|
1219 Lisp_Object charset, int row,
|
|
1220 int (*fn) (struct chartab_range *range,
|
|
1221 Lisp_Object val, void *arg),
|
|
1222 void *arg)
|
|
1223 {
|
|
1224 Lisp_Object val;
|
|
1225
|
|
1226 val = cte->level2[row - 32];
|
|
1227 if (!CHAR_TABLE_ENTRYP (val))
|
|
1228 {
|
|
1229 struct chartab_range rainj;
|
|
1230
|
|
1231 rainj.type = CHARTAB_RANGE_ROW;
|
|
1232 rainj.charset = charset;
|
|
1233 rainj.row = row;
|
|
1234 return (fn) (&rainj, val, arg);
|
|
1235 }
|
|
1236 else
|
|
1237 {
|
|
1238 int i;
|
|
1239 int start, stop;
|
|
1240
|
|
1241 cte = XCHAR_TABLE_ENTRY (val);
|
|
1242 if (XCHARSET_CHARS (charset) == 94)
|
|
1243 {
|
|
1244 start = 33;
|
|
1245 stop = 127;
|
|
1246 }
|
|
1247 else
|
|
1248 {
|
|
1249 start = 32;
|
|
1250 stop = 128;
|
|
1251 }
|
|
1252
|
|
1253 for (i = start; i < stop; i++)
|
|
1254 {
|
|
1255 int retval;
|
|
1256 struct chartab_range rainj;
|
|
1257
|
|
1258 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1259 rainj.ch = MAKE_CHAR (charset, row, i);
|
|
1260
|
|
1261 val = cte->level2[i - 32];
|
|
1262 retval = (fn) (&rainj, val, arg);
|
|
1263 if (retval)
|
|
1264 return retval;
|
|
1265 }
|
|
1266 }
|
|
1267
|
|
1268 return 0;
|
|
1269 }
|
|
1270
|
|
1271 static int
|
|
1272 map_over_other_charset (struct Lisp_Char_Table *ct, int lb,
|
|
1273 int (*fn) (struct chartab_range *range,
|
|
1274 Lisp_Object val, void *arg),
|
|
1275 void *arg)
|
|
1276 {
|
|
1277 Lisp_Object charset;
|
|
1278 Lisp_Object val;
|
|
1279
|
|
1280 val = ct->level1[lb - MIN_LEADING_BYTE];
|
|
1281
|
|
1282 charset = CHARSET_BY_LEADING_BYTE (lb);
|
|
1283 if (!CHARSETP (charset) || lb == LEADING_BYTE_ASCII
|
|
1284 || lb == LEADING_BYTE_CONTROL_1)
|
|
1285 return 0;
|
|
1286 if (!CHAR_TABLE_ENTRYP (val))
|
|
1287 {
|
|
1288 struct chartab_range rainj;
|
|
1289
|
|
1290 rainj.type = CHARTAB_RANGE_CHARSET;
|
|
1291 rainj.charset = charset;
|
|
1292 return (fn) (&rainj, val, arg);
|
|
1293 }
|
|
1294 else if (XCHARSET_DIMENSION (charset) == 1)
|
|
1295 {
|
|
1296 int i;
|
|
1297 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
|
|
1298 int start, stop;
|
|
1299
|
|
1300 if (XCHARSET_CHARS (charset) == 94)
|
|
1301 {
|
|
1302 start = 33;
|
|
1303 stop = 127;
|
|
1304 }
|
|
1305 else
|
|
1306 {
|
|
1307 start = 32;
|
|
1308 stop = 128;
|
|
1309 }
|
|
1310
|
|
1311 for (i = start; i < stop; i++)
|
|
1312 {
|
|
1313 int retval;
|
|
1314 struct chartab_range rainj;
|
|
1315
|
|
1316 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1317 rainj.ch = MAKE_CHAR (charset, i, 0);
|
|
1318 retval = (fn) (&rainj, cte->level2[i - 32], arg);
|
|
1319 if (retval)
|
|
1320 return retval;
|
|
1321 }
|
|
1322 }
|
|
1323 else
|
|
1324 {
|
|
1325 int i;
|
|
1326 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
|
|
1327 int start, stop;
|
|
1328
|
|
1329 if (XCHARSET_CHARS (charset) == 94)
|
|
1330 {
|
|
1331 start = 33;
|
|
1332 stop = 127;
|
|
1333 }
|
|
1334 else
|
|
1335 {
|
|
1336 start = 32;
|
|
1337 stop = 128;
|
|
1338 }
|
|
1339
|
|
1340 for (i = start; i < stop; i++)
|
|
1341 {
|
|
1342 int retval =
|
|
1343 map_over_charset_row (cte, charset, i, fn, arg);
|
|
1344 if (retval)
|
|
1345 return retval;
|
|
1346 }
|
|
1347 }
|
|
1348
|
|
1349 return 0;
|
|
1350 }
|
|
1351
|
|
1352 #endif /* MULE */
|
|
1353
|
|
1354 /* Map FN (with client data ARG) over range RANGE in char table CT.
|
|
1355 Mapping stops the first time FN returns non-zero, and that value
|
|
1356 becomes the return value of map_char_table(). */
|
|
1357
|
|
1358 int
|
|
1359 map_char_table (struct Lisp_Char_Table *ct,
|
|
1360 struct chartab_range *range,
|
|
1361 int (*fn) (struct chartab_range *range,
|
|
1362 Lisp_Object val, void *arg),
|
|
1363 void *arg)
|
|
1364 {
|
|
1365 switch (range->type)
|
|
1366 {
|
|
1367 case CHARTAB_RANGE_ALL:
|
|
1368 {
|
|
1369 int retval;
|
|
1370
|
|
1371 retval = map_over_charset_ascii (ct, fn, arg);
|
|
1372 if (retval)
|
|
1373 return retval;
|
|
1374 #ifdef MULE
|
|
1375 retval = map_over_charset_control_1 (ct, fn, arg);
|
|
1376 if (retval)
|
|
1377 return retval;
|
|
1378 {
|
|
1379 int i;
|
|
1380 for (i = MIN_LEADING_BYTE; i < MIN_LEADING_BYTE + NUM_LEADING_BYTES;
|
|
1381 i++)
|
|
1382 {
|
|
1383 retval = map_over_other_charset (ct, i, fn, arg);
|
|
1384 if (retval)
|
|
1385 return retval;
|
|
1386 }
|
|
1387 }
|
|
1388 #endif
|
|
1389 }
|
|
1390 break;
|
|
1391
|
|
1392 #ifdef MULE
|
|
1393 case CHARTAB_RANGE_CHARSET:
|
|
1394 return map_over_other_charset (ct,
|
|
1395 XCHARSET_LEADING_BYTE (range->charset),
|
|
1396 fn, arg);
|
|
1397
|
|
1398 case CHARTAB_RANGE_ROW:
|
|
1399 {
|
104
|
1400 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE];
|
70
|
1401 if (!CHAR_TABLE_ENTRYP (val))
|
|
1402 {
|
|
1403 struct chartab_range rainj;
|
|
1404
|
|
1405 rainj.type = CHARTAB_RANGE_ROW;
|
|
1406 rainj.charset = range->charset;
|
|
1407 rainj.row = range->row;
|
|
1408 return (fn) (&rainj, val, arg);
|
|
1409 }
|
|
1410 else
|
|
1411 return map_over_charset_row (XCHAR_TABLE_ENTRY (val),
|
|
1412 range->charset, range->row,
|
|
1413 fn, arg);
|
|
1414 }
|
|
1415 #endif /* MULE */
|
|
1416
|
|
1417 case CHARTAB_RANGE_CHAR:
|
|
1418 {
|
|
1419 Emchar ch = range->ch;
|
|
1420 Lisp_Object val = CHAR_TABLE_VALUE_UNSAFE (ct, ch);
|
|
1421 struct chartab_range rainj;
|
|
1422
|
|
1423 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1424 rainj.ch = ch;
|
|
1425 return (fn) (&rainj, val, arg);
|
|
1426 }
|
|
1427
|
|
1428 default:
|
|
1429 abort ();
|
|
1430 }
|
|
1431
|
|
1432 return 0;
|
|
1433 }
|
|
1434
|
|
1435 struct slow_map_char_table_arg
|
|
1436 {
|
|
1437 Lisp_Object function;
|
|
1438 Lisp_Object retval;
|
|
1439 };
|
|
1440
|
|
1441 static int
|
|
1442 slow_map_char_table_fun (struct chartab_range *range,
|
|
1443 Lisp_Object val, void *arg)
|
|
1444 {
|
|
1445 Lisp_Object ranjarg = Qnil;
|
|
1446 struct slow_map_char_table_arg *closure =
|
|
1447 (struct slow_map_char_table_arg *) arg;
|
|
1448
|
|
1449 switch (range->type)
|
|
1450 {
|
|
1451 case CHARTAB_RANGE_ALL:
|
|
1452 ranjarg = Qt;
|
|
1453 break;
|
|
1454
|
|
1455 #ifdef MULE
|
|
1456 case CHARTAB_RANGE_CHARSET:
|
|
1457 ranjarg = XCHARSET_NAME (range->charset);
|
|
1458 break;
|
|
1459
|
|
1460 case CHARTAB_RANGE_ROW:
|
|
1461 ranjarg = vector2 (XCHARSET_NAME (range->charset),
|
|
1462 make_int (range->row));
|
|
1463 break;
|
|
1464 #endif
|
|
1465 case CHARTAB_RANGE_CHAR:
|
|
1466 ranjarg = make_char (range->ch);
|
|
1467 break;
|
|
1468 default:
|
|
1469 abort ();
|
|
1470 }
|
|
1471
|
|
1472 closure->retval = call2 (closure->function, ranjarg, val);
|
|
1473 return (!NILP (closure->retval));
|
|
1474 }
|
|
1475
|
|
1476 DEFUN ("map-char-table", Fmap_char_table, 2, 3, 0, /*
|
|
1477 Map FUNCTION over entries in TABLE, calling it with two args,
|
|
1478 each key and value in the table.
|
|
1479
|
|
1480 RANGE specifies a subrange to map over and is in the same format as
|
|
1481 the RANGE argument to `put-range-table'. If omitted or t, it defaults to
|
|
1482 the entire table.
|
|
1483 */
|
|
1484 (function, table, range))
|
|
1485 {
|
|
1486 struct Lisp_Char_Table *ct;
|
|
1487 struct slow_map_char_table_arg slarg;
|
|
1488 struct gcpro gcpro1, gcpro2;
|
|
1489 struct chartab_range rainj;
|
|
1490
|
|
1491 CHECK_CHAR_TABLE (table);
|
|
1492 ct = XCHAR_TABLE (table);
|
|
1493 if (NILP (range))
|
|
1494 range = Qt;
|
|
1495 decode_char_table_range (range, &rainj);
|
|
1496 slarg.function = function;
|
|
1497 slarg.retval = Qnil;
|
|
1498 GCPRO2 (slarg.function, slarg.retval);
|
|
1499 map_char_table (ct, &rainj, slow_map_char_table_fun, &slarg);
|
|
1500 UNGCPRO;
|
|
1501
|
|
1502 return slarg.retval;
|
|
1503 }
|
|
1504
|
104
|
1505
|
70
|
1506
|
|
1507 /************************************************************************/
|
|
1508 /* Char table read syntax */
|
|
1509 /************************************************************************/
|
|
1510
|
|
1511 static int
|
|
1512 chartab_type_validate (Lisp_Object keyword, Lisp_Object value,
|
|
1513 Error_behavior errb)
|
|
1514 {
|
|
1515 /* #### should deal with ERRB */
|
|
1516 (void) symbol_to_char_table_type (value);
|
|
1517 return 1;
|
|
1518 }
|
|
1519
|
|
1520 static int
|
|
1521 chartab_data_validate (Lisp_Object keyword, Lisp_Object value,
|
|
1522 Error_behavior errb)
|
|
1523 {
|
|
1524 Lisp_Object rest;
|
|
1525
|
|
1526 /* #### should deal with ERRB */
|
|
1527 EXTERNAL_LIST_LOOP (rest, value)
|
|
1528 {
|
|
1529 Lisp_Object range = XCAR (rest);
|
|
1530 struct chartab_range dummy;
|
|
1531
|
|
1532 rest = XCDR (rest);
|
|
1533 if (!CONSP (rest))
|
|
1534 signal_simple_error ("Invalid list format", value);
|
|
1535 if (CONSP (range))
|
|
1536 {
|
|
1537 if (!CONSP (XCDR (range))
|
|
1538 || !NILP (XCDR (XCDR (range))))
|
|
1539 signal_simple_error ("Invalid range format", range);
|
|
1540 decode_char_table_range (XCAR (range), &dummy);
|
|
1541 decode_char_table_range (XCAR (XCDR (range)), &dummy);
|
|
1542 }
|
|
1543 else
|
|
1544 decode_char_table_range (range, &dummy);
|
|
1545 }
|
|
1546
|
|
1547 return 1;
|
|
1548 }
|
|
1549
|
|
1550 static Lisp_Object
|
|
1551 chartab_instantiate (Lisp_Object data)
|
|
1552 {
|
|
1553 Lisp_Object chartab;
|
|
1554 Lisp_Object type = Qgeneric;
|
|
1555 Lisp_Object dataval = Qnil;
|
|
1556
|
|
1557 while (!NILP (data))
|
|
1558 {
|
|
1559 Lisp_Object keyw = Fcar (data);
|
|
1560 Lisp_Object valw;
|
|
1561
|
|
1562 data = Fcdr (data);
|
|
1563 valw = Fcar (data);
|
|
1564 data = Fcdr (data);
|
|
1565 if (EQ (keyw, Qtype))
|
|
1566 type = valw;
|
|
1567 else if (EQ (keyw, Qdata))
|
|
1568 dataval = valw;
|
|
1569 }
|
|
1570
|
|
1571 chartab = Fmake_char_table (type);
|
|
1572
|
|
1573 data = dataval;
|
|
1574 while (!NILP (data))
|
|
1575 {
|
|
1576 Lisp_Object range = Fcar (data);
|
|
1577 Lisp_Object val = Fcar (Fcdr (data));
|
|
1578
|
|
1579 data = Fcdr (Fcdr (data));
|
|
1580 if (CONSP (range))
|
|
1581 {
|
|
1582 if (CHAR_OR_CHAR_INTP (XCAR (range)))
|
|
1583 {
|
|
1584 Emchar first = XCHAR_OR_CHAR_INT (Fcar (range));
|
|
1585 Emchar last = XCHAR_OR_CHAR_INT (Fcar (Fcdr (range)));
|
|
1586 Emchar i;
|
|
1587
|
|
1588 for (i = first; i <= last; i++)
|
|
1589 Fput_char_table (make_char (i), val, chartab);
|
|
1590 }
|
|
1591 else
|
|
1592 abort ();
|
|
1593 }
|
|
1594 else
|
|
1595 Fput_char_table (range, val, chartab);
|
|
1596 }
|
|
1597
|
|
1598 return chartab;
|
|
1599 }
|
|
1600
|
|
1601 #ifdef MULE
|
|
1602
|
|
1603
|
|
1604 /************************************************************************/
|
|
1605 /* Category Tables, specifically */
|
|
1606 /************************************************************************/
|
|
1607
|
|
1608 DEFUN ("category-table-p", Fcategory_table_p, 1, 1, 0, /*
|
|
1609 Return t if ARG is a category table.
|
|
1610 A category table is a type of char table used for keeping track of
|
|
1611 categories. Categories are used for classifying characters for use
|
|
1612 in regexps -- you can refer to a category rather than having to use
|
|
1613 a complicated [] expression (and category lookups are significantly
|
|
1614 faster).
|
|
1615
|
|
1616 There are 95 different categories available, one for each printable
|
|
1617 character (including space) in the ASCII charset. Each category
|
|
1618 is designated by one such character, called a \"category designator\".
|
|
1619 They are specified in a regexp using the syntax \"\\cX\", where X is
|
104
|
1620 a category designator.
|
70
|
1621
|
|
1622 A category table specifies, for each character, the categories that
|
|
1623 the character is in. Note that a character can be in more than one
|
|
1624 category. More specifically, a category table maps from a character
|
|
1625 to either the value nil (meaning the character is in no categories)
|
|
1626 or a 95-element bit vector, specifying for each of the 95 categories
|
|
1627 whether the character is in that category.
|
|
1628
|
|
1629 Special Lisp functions are provided that abstract this, so you do not
|
|
1630 have to directly manipulate bit vectors.
|
|
1631 */
|
|
1632 (obj))
|
|
1633 {
|
|
1634 if (CHAR_TABLEP (obj) && XCHAR_TABLE_TYPE (obj) == CHAR_TABLE_TYPE_CATEGORY)
|
|
1635 return Qt;
|
|
1636 return Qnil;
|
|
1637 }
|
|
1638
|
|
1639 static Lisp_Object
|
|
1640 check_category_table (Lisp_Object obj, Lisp_Object def)
|
|
1641 {
|
|
1642 if (NILP (obj))
|
|
1643 obj = def;
|
|
1644 while (NILP (Fcategory_table_p (obj)))
|
|
1645 obj = wrong_type_argument (Qcategory_table_p, obj);
|
|
1646 return (obj);
|
|
1647 }
|
|
1648
|
104
|
1649 int
|
110
|
1650 check_category_char(Emchar ch, Lisp_Object table,
|
|
1651 unsigned int designator, unsigned int not)
|
104
|
1652 {
|
|
1653 register Lisp_Object temp;
|
|
1654 struct Lisp_Char_Table *ctbl;
|
110
|
1655 #ifdef ERROR_CHECK_TYPECHECK
|
104
|
1656 if (NILP (Fcategory_table_p (table)))
|
|
1657 signal_simple_error("Expected category table", table);
|
|
1658 #endif
|
|
1659 ctbl = XCHAR_TABLE(table);
|
|
1660 temp = get_char_table(ch, ctbl);
|
|
1661 if (EQ (temp, Qnil)) return not;
|
|
1662
|
|
1663 designator -= ' ';
|
|
1664 return (bit_vector_bit(XBIT_VECTOR (temp), designator) ? !not : not);
|
|
1665 }
|
|
1666
|
|
1667 DEFUN ("check-category-at", Fcheck_category_at, 2, 4, 0, /*
|
110
|
1668 Return t if category of a character at POS includes DESIGNATOR,
|
104
|
1669 else return nil. Optional third arg specifies which buffer
|
|
1670 (defaulting to current), and fourth specifies the CATEGORY-TABLE,
|
|
1671 (defaulting to the buffer's category table).
|
|
1672 */
|
|
1673 (pos, designator, buffer, category_table))
|
|
1674 {
|
|
1675 Lisp_Object ctbl;
|
|
1676 Emchar ch;
|
|
1677 unsigned int des;
|
|
1678 struct buffer *buf = decode_buffer(buffer, 0);
|
|
1679
|
|
1680 CHECK_INT (pos);
|
|
1681 CHECK_CATEGORY_DESIGNATOR (designator);
|
|
1682 des = XREALINT(designator);
|
|
1683 ctbl = check_category_table (category_table, Vstandard_category_table);
|
|
1684 ch = BUF_FETCH_CHAR (buf, XINT(pos));
|
110
|
1685 return (check_category_char(ch, ctbl, des, 0)
|
|
1686 ? Qt : Qnil);
|
|
1687 }
|
|
1688
|
|
1689 DEFUN ("char-in-category-p", Fchar_in_category_p, 2, 3, 0, /*
|
|
1690 Return t if category of character CHR includes DESIGNATOR, else
|
|
1691 return nil. Optional third arg specifies the CATEGORY-TABLE to use,
|
|
1692
|
|
1693 which defaults to the system default table.
|
|
1694 */
|
|
1695 (chr, designator, category_table))
|
|
1696 {
|
|
1697 Lisp_Object ctbl;
|
|
1698 Emchar ch;
|
|
1699 unsigned int des;
|
|
1700
|
|
1701 CHECK_CATEGORY_DESIGNATOR (designator);
|
|
1702 des = XREALINT(designator);
|
|
1703 CHECK_CHAR(chr);
|
|
1704 ch = XCHAR(chr);
|
|
1705 ctbl = check_category_table (category_table, Vstandard_category_table);
|
|
1706 return (check_category_char(ch, ctbl, des, 0)
|
104
|
1707 ? Qt : Qnil);
|
|
1708 }
|
|
1709
|
70
|
1710 DEFUN ("category-table", Fcategory_table, 0, 1, 0, /*
|
|
1711 Return the current category table.
|
|
1712 This is the one specified by the current buffer, or by BUFFER if it
|
|
1713 is non-nil.
|
|
1714 */
|
|
1715 (buffer))
|
|
1716 {
|
|
1717 return decode_buffer (buffer, 0)->category_table;
|
|
1718 }
|
|
1719
|
|
1720 DEFUN ("standard-category-table", Fstandard_category_table, 0, 0, 0, /*
|
|
1721 Return the standard category table.
|
|
1722 This is the one used for new buffers.
|
|
1723 */
|
|
1724 ())
|
|
1725 {
|
|
1726 return Vstandard_category_table;
|
|
1727 }
|
|
1728
|
|
1729 DEFUN ("copy-category-table", Fcopy_category_table, 0, 1, 0, /*
|
|
1730 Construct a new category table and return it.
|
|
1731 It is a copy of the TABLE, which defaults to the standard category table.
|
|
1732 */
|
|
1733 (table))
|
|
1734 {
|
|
1735 if (NILP (Vstandard_category_table))
|
|
1736 return Fmake_char_table (Qcategory);
|
|
1737
|
|
1738 table = check_category_table (table, Vstandard_category_table);
|
|
1739 return Fcopy_char_table (table);
|
|
1740 }
|
|
1741
|
|
1742 DEFUN ("set-category-table", Fset_category_table, 1, 2, 0, /*
|
|
1743 Select a new category table for BUFFER.
|
|
1744 One argument, a category table.
|
|
1745 BUFFER defaults to the current buffer if omitted.
|
|
1746 */
|
|
1747 (table, buffer))
|
|
1748 {
|
|
1749 struct buffer *buf = decode_buffer (buffer, 0);
|
|
1750 table = check_category_table (table, Qnil);
|
|
1751 buf->category_table = table;
|
|
1752 /* Indicate that this buffer now has a specified category table. */
|
|
1753 buf->local_var_flags |= XINT (buffer_local_flags.category_table);
|
|
1754 return table;
|
|
1755 }
|
|
1756
|
|
1757 DEFUN ("category-designator-p", Fcategory_designator_p, 1, 1, 0, /*
|
|
1758 Return t if ARG is a category designator (a char in the range ' ' to '~').
|
|
1759 */
|
|
1760 (obj))
|
|
1761 {
|
|
1762 if (CATEGORY_DESIGNATORP (obj))
|
|
1763 return Qt;
|
|
1764 return Qnil;
|
|
1765 }
|
|
1766
|
|
1767 DEFUN ("category-table-value-p", Fcategory_table_value_p, 1, 1, 0, /*
|
|
1768 Return t if ARG is a category table value.
|
|
1769 Valid values are nil or a bit vector of size 95.
|
|
1770 */
|
|
1771 (obj))
|
|
1772 {
|
|
1773 if (CATEGORY_TABLE_VALUEP (obj))
|
|
1774 return Qt;
|
|
1775 return Qnil;
|
|
1776 }
|
|
1777
|
|
1778 #endif /* MULE */
|
|
1779
|
|
1780
|
|
1781 void
|
|
1782 syms_of_chartab (void)
|
|
1783 {
|
|
1784 #ifdef MULE
|
|
1785 defsymbol (&Qcategory_table_p, "category-table-p");
|
|
1786 defsymbol (&Qcategory_designator_p, "category-designator-p");
|
|
1787 defsymbol (&Qcategory_table_value_p, "category-table-value-p");
|
|
1788 #endif /* MULE */
|
|
1789
|
|
1790 defsymbol (&Qchar_table, "char-table");
|
|
1791 defsymbol (&Qchar_tablep, "char-table-p");
|
|
1792
|
|
1793 DEFSUBR (Fchar_table_p);
|
|
1794 DEFSUBR (Fchar_table_type_list);
|
|
1795 DEFSUBR (Fvalid_char_table_type_p);
|
|
1796 DEFSUBR (Fchar_table_type);
|
|
1797 DEFSUBR (Freset_char_table);
|
|
1798 DEFSUBR (Fmake_char_table);
|
|
1799 DEFSUBR (Fcopy_char_table);
|
|
1800 DEFSUBR (Fget_char_table);
|
|
1801 DEFSUBR (Fget_range_char_table);
|
|
1802 DEFSUBR (Fvalid_char_table_value_p);
|
|
1803 DEFSUBR (Fcheck_valid_char_table_value);
|
|
1804 DEFSUBR (Fput_char_table);
|
|
1805 DEFSUBR (Fmap_char_table);
|
|
1806
|
|
1807 #ifdef MULE
|
|
1808 DEFSUBR (Fcategory_table_p);
|
|
1809 DEFSUBR (Fcategory_table);
|
|
1810 DEFSUBR (Fstandard_category_table);
|
|
1811 DEFSUBR (Fcopy_category_table);
|
|
1812 DEFSUBR (Fset_category_table);
|
104
|
1813 DEFSUBR (Fcheck_category_at);
|
110
|
1814 DEFSUBR (Fchar_in_category_p);
|
70
|
1815 DEFSUBR (Fcategory_designator_p);
|
|
1816 DEFSUBR (Fcategory_table_value_p);
|
|
1817 #endif /* MULE */
|
|
1818
|
|
1819 /* DO NOT staticpro this. It works just like Vweak_hash_tables. */
|
|
1820 Vall_syntax_tables = Qnil;
|
|
1821 }
|
|
1822
|
|
1823 void
|
|
1824 structure_type_create_chartab (void)
|
|
1825 {
|
|
1826 struct structure_type *st;
|
|
1827
|
|
1828 st = define_structure_type (Qchar_table, 0, chartab_instantiate);
|
|
1829
|
|
1830 define_structure_type_keyword (st, Qtype, chartab_type_validate);
|
|
1831 define_structure_type_keyword (st, Qdata, chartab_data_validate);
|
|
1832 }
|
|
1833
|
|
1834 void
|
|
1835 complex_vars_of_chartab (void)
|
|
1836 {
|
|
1837 #ifdef MULE
|
|
1838 /* Set this now, so first buffer creation can refer to it. */
|
|
1839 /* Make it nil before calling copy-category-table
|
|
1840 so that copy-category-table will know not to try to copy from garbage */
|
|
1841 Vstandard_category_table = Qnil;
|
|
1842 Vstandard_category_table = Fcopy_category_table (Qnil);
|
|
1843 staticpro (&Vstandard_category_table);
|
|
1844 #endif /* MULE */
|
|
1845 }
|