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