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