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