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);
|
3879
|
671 assert(!ct->mirror_table_p);
|
3017
|
672 ctnew = ALLOC_LCRECORD_TYPE (Lisp_Char_Table, &lrecord_char_table);
|
428
|
673 ctnew->type = ct->type;
|
793
|
674 ctnew->parent = ct->parent;
|
|
675 ctnew->default_ = ct->default_;
|
3879
|
676 ctnew->mirror_table_p = 0;
|
1296
|
677 obj = wrap_char_table (ctnew);
|
428
|
678
|
|
679 for (i = 0; i < NUM_ASCII_CHARS; i++)
|
|
680 {
|
3025
|
681 Lisp_Object new_ = ct->ascii[i];
|
428
|
682 #ifdef MULE
|
3025
|
683 assert (! (CHAR_TABLE_ENTRYP (new_)));
|
428
|
684 #endif /* MULE */
|
3025
|
685 ctnew->ascii[i] = new_;
|
428
|
686 }
|
|
687
|
|
688 #ifdef MULE
|
|
689
|
|
690 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
691 {
|
3025
|
692 Lisp_Object new_ = ct->level1[i];
|
|
693 if (CHAR_TABLE_ENTRYP (new_))
|
|
694 ctnew->level1[i] = copy_char_table_entry (new_);
|
428
|
695 else
|
3025
|
696 ctnew->level1[i] = new_;
|
428
|
697 }
|
|
698
|
|
699 #endif /* MULE */
|
|
700
|
3881
|
701 if (!EQ (ct->mirror_table, Qnil))
|
1296
|
702 {
|
3879
|
703 ctnew->mirror_table = Fmake_char_table (Qgeneric);
|
|
704 set_char_table_default (ctnew->mirror_table, make_int (Sword));
|
1296
|
705 XCHAR_TABLE (ctnew->mirror_table)->mirror_table = obj;
|
3879
|
706 XCHAR_TABLE (ctnew->mirror_table)->mirror_table_p = 1;
|
|
707 XCHAR_TABLE (ctnew->mirror_table)->dirty = 1;
|
1296
|
708 }
|
428
|
709 else
|
3879
|
710 ctnew->mirror_table = Qnil;
|
|
711
|
428
|
712 ctnew->next_table = Qnil;
|
|
713 if (ctnew->type == CHAR_TABLE_TYPE_SYNTAX)
|
|
714 {
|
|
715 ctnew->next_table = Vall_syntax_tables;
|
|
716 Vall_syntax_tables = obj;
|
|
717 }
|
|
718 return obj;
|
|
719 }
|
|
720
|
|
721 #ifdef MULE
|
|
722
|
826
|
723 /* called from get_char_table(). */
|
428
|
724 Lisp_Object
|
440
|
725 get_non_ascii_char_table_value (Lisp_Char_Table *ct, int leading_byte,
|
867
|
726 Ichar c)
|
428
|
727 {
|
|
728 Lisp_Object val;
|
826
|
729 Lisp_Object charset = charset_by_leading_byte (leading_byte);
|
428
|
730 int byte1, byte2;
|
|
731
|
867
|
732 BREAKUP_ICHAR_1_UNSAFE (c, charset, byte1, byte2);
|
428
|
733 val = ct->level1[leading_byte - MIN_LEADING_BYTE];
|
|
734 if (CHAR_TABLE_ENTRYP (val))
|
|
735 {
|
440
|
736 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
|
428
|
737 val = cte->level2[byte1 - 32];
|
|
738 if (CHAR_TABLE_ENTRYP (val))
|
|
739 {
|
|
740 cte = XCHAR_TABLE_ENTRY (val);
|
|
741 assert (byte2 >= 32);
|
|
742 val = cte->level2[byte2 - 32];
|
|
743 assert (!CHAR_TABLE_ENTRYP (val));
|
|
744 }
|
|
745 }
|
|
746
|
|
747 return val;
|
|
748 }
|
|
749
|
|
750 #endif /* MULE */
|
|
751
|
826
|
752 DEFUN ("char-table-default", Fchar_table_default, 1, 1, 0, /*
|
|
753 Return the default value for CHAR-TABLE. When an entry for a character
|
|
754 does not exist, the default is returned.
|
|
755 */
|
|
756 (char_table))
|
428
|
757 {
|
826
|
758 CHECK_CHAR_TABLE (char_table);
|
|
759 return XCHAR_TABLE (char_table)->default_;
|
428
|
760 }
|
|
761
|
826
|
762 DEFUN ("set-char-table-default", Fset_char_table_default, 2, 2, 0, /*
|
|
763 Set the default value for CHAR-TABLE to DEFAULT.
|
|
764 Currently, the default value for syntax tables cannot be changed.
|
|
765 (This policy might change in the future.)
|
|
766 */
|
|
767 (char_table, default_))
|
|
768 {
|
|
769 CHECK_CHAR_TABLE (char_table);
|
|
770 if (XCHAR_TABLE_TYPE (char_table) == CHAR_TABLE_TYPE_SYNTAX)
|
|
771 invalid_change ("Can't change default for syntax tables", char_table);
|
|
772 check_valid_char_table_value (default_, XCHAR_TABLE_TYPE (char_table),
|
|
773 ERROR_ME);
|
|
774 set_char_table_default (char_table, default_);
|
|
775 return Qnil;
|
|
776 }
|
428
|
777
|
|
778 DEFUN ("get-char-table", Fget_char_table, 2, 2, 0, /*
|
444
|
779 Find value for CHARACTER in CHAR-TABLE.
|
428
|
780 */
|
444
|
781 (character, char_table))
|
428
|
782 {
|
444
|
783 CHECK_CHAR_TABLE (char_table);
|
|
784 CHECK_CHAR_COERCE_INT (character);
|
428
|
785
|
826
|
786 return get_char_table (XCHAR (character), char_table);
|
|
787 }
|
|
788
|
|
789 static int
|
2286
|
790 copy_mapper (struct chartab_range *range, Lisp_Object UNUSED (table),
|
826
|
791 Lisp_Object val, void *arg)
|
|
792 {
|
|
793 put_char_table (VOID_TO_LISP (arg), range, val);
|
|
794 return 0;
|
|
795 }
|
|
796
|
|
797 void
|
|
798 copy_char_table_range (Lisp_Object from, Lisp_Object to,
|
|
799 struct chartab_range *range)
|
|
800 {
|
|
801 map_char_table (from, range, copy_mapper, LISP_TO_VOID (to));
|
|
802 }
|
|
803
|
1296
|
804 static Lisp_Object
|
|
805 get_range_char_table_1 (struct chartab_range *range, Lisp_Object table,
|
|
806 Lisp_Object multi)
|
826
|
807 {
|
|
808 Lisp_Char_Table *ct = XCHAR_TABLE (table);
|
|
809 Lisp_Object retval = Qnil;
|
|
810
|
|
811 switch (range->type)
|
|
812 {
|
|
813 case CHARTAB_RANGE_CHAR:
|
|
814 return get_char_table (range->ch, table);
|
|
815
|
|
816 case CHARTAB_RANGE_ALL:
|
|
817 {
|
|
818 int i;
|
|
819 retval = ct->ascii[0];
|
|
820
|
|
821 for (i = 1; i < NUM_ASCII_CHARS; i++)
|
|
822 if (!EQ (retval, ct->ascii[i]))
|
|
823 return multi;
|
|
824
|
|
825 #ifdef MULE
|
|
826 for (i = MIN_LEADING_BYTE; i < MIN_LEADING_BYTE + NUM_LEADING_BYTES;
|
|
827 i++)
|
|
828 {
|
|
829 if (!CHARSETP (charset_by_leading_byte (i))
|
|
830 || i == LEADING_BYTE_ASCII
|
|
831 || i == LEADING_BYTE_CONTROL_1)
|
|
832 continue;
|
|
833 if (!EQ (retval, ct->level1[i - MIN_LEADING_BYTE]))
|
|
834 return multi;
|
|
835 }
|
|
836 #endif /* MULE */
|
|
837
|
|
838 break;
|
|
839 }
|
|
840
|
|
841 #ifdef MULE
|
|
842 case CHARTAB_RANGE_CHARSET:
|
|
843 if (EQ (range->charset, Vcharset_ascii))
|
|
844 {
|
|
845 int i;
|
|
846 retval = ct->ascii[0];
|
|
847
|
|
848 for (i = 1; i < 128; i++)
|
|
849 if (!EQ (retval, ct->ascii[i]))
|
|
850 return multi;
|
|
851 break;
|
|
852 }
|
|
853
|
|
854 if (EQ (range->charset, Vcharset_control_1))
|
|
855 {
|
|
856 int i;
|
|
857 retval = ct->ascii[128];
|
|
858
|
|
859 for (i = 129; i < 160; i++)
|
|
860 if (!EQ (retval, ct->ascii[i]))
|
|
861 return multi;
|
|
862 break;
|
|
863 }
|
|
864
|
|
865 {
|
|
866 retval = ct->level1[XCHARSET_LEADING_BYTE (range->charset) -
|
|
867 MIN_LEADING_BYTE];
|
|
868 if (CHAR_TABLE_ENTRYP (retval))
|
|
869 return multi;
|
|
870 break;
|
|
871 }
|
|
872
|
|
873 case CHARTAB_RANGE_ROW:
|
|
874 {
|
|
875 retval = ct->level1[XCHARSET_LEADING_BYTE (range->charset) -
|
|
876 MIN_LEADING_BYTE];
|
|
877 if (!CHAR_TABLE_ENTRYP (retval))
|
|
878 break;
|
|
879 retval = XCHAR_TABLE_ENTRY (retval)->level2[range->row - 32];
|
|
880 if (CHAR_TABLE_ENTRYP (retval))
|
|
881 return multi;
|
|
882 break;
|
|
883 }
|
|
884 #endif /* not MULE */
|
|
885
|
|
886 default:
|
2500
|
887 ABORT ();
|
826
|
888 }
|
|
889
|
|
890 if (UNBOUNDP (retval))
|
|
891 return ct->default_;
|
|
892 return retval;
|
428
|
893 }
|
|
894
|
1296
|
895 Lisp_Object
|
|
896 get_range_char_table (struct chartab_range *range, Lisp_Object table,
|
|
897 Lisp_Object multi)
|
|
898 {
|
|
899 if (range->type == CHARTAB_RANGE_CHAR)
|
|
900 return get_char_table (range->ch, table);
|
|
901 else
|
|
902 return get_range_char_table_1 (range, table, multi);
|
|
903 }
|
|
904
|
|
905 #ifdef ERROR_CHECK_TYPES
|
|
906
|
|
907 /* Only exists so as not to trip an assert in get_char_table(). */
|
|
908 Lisp_Object
|
|
909 updating_mirror_get_range_char_table (struct chartab_range *range,
|
|
910 Lisp_Object table,
|
|
911 Lisp_Object multi)
|
|
912 {
|
|
913 if (range->type == CHARTAB_RANGE_CHAR)
|
|
914 return get_char_table_1 (range->ch, table);
|
|
915 else
|
|
916 return get_range_char_table_1 (range, table, multi);
|
|
917 }
|
|
918
|
|
919 #endif /* ERROR_CHECK_TYPES */
|
|
920
|
428
|
921 DEFUN ("get-range-char-table", Fget_range_char_table, 2, 3, 0, /*
|
2714
|
922 Find value for RANGE in CHAR-TABLE.
|
428
|
923 If there is more than one value, return MULTI (defaults to nil).
|
2714
|
924
|
|
925 Valid values for RANGE are single characters, charsets, a row in a
|
|
926 two-octet charset, and all characters. See `put-char-table'.
|
428
|
927 */
|
444
|
928 (range, char_table, multi))
|
428
|
929 {
|
|
930 struct chartab_range rainj;
|
|
931
|
|
932 if (CHAR_OR_CHAR_INTP (range))
|
444
|
933 return Fget_char_table (range, char_table);
|
|
934 CHECK_CHAR_TABLE (char_table);
|
428
|
935
|
|
936 decode_char_table_range (range, &rainj);
|
826
|
937 return get_range_char_table (&rainj, char_table, multi);
|
428
|
938 }
|
826
|
939
|
428
|
940 static int
|
|
941 check_valid_char_table_value (Lisp_Object value, enum char_table_type type,
|
578
|
942 Error_Behavior errb)
|
428
|
943 {
|
|
944 switch (type)
|
|
945 {
|
|
946 case CHAR_TABLE_TYPE_SYNTAX:
|
|
947 if (!ERRB_EQ (errb, ERROR_ME))
|
|
948 return INTP (value) || (CONSP (value) && INTP (XCAR (value))
|
|
949 && CHAR_OR_CHAR_INTP (XCDR (value)));
|
|
950 if (CONSP (value))
|
|
951 {
|
|
952 Lisp_Object cdr = XCDR (value);
|
|
953 CHECK_INT (XCAR (value));
|
|
954 CHECK_CHAR_COERCE_INT (cdr);
|
|
955 }
|
|
956 else
|
|
957 CHECK_INT (value);
|
|
958 break;
|
|
959
|
|
960 #ifdef MULE
|
|
961 case CHAR_TABLE_TYPE_CATEGORY:
|
|
962 if (!ERRB_EQ (errb, ERROR_ME))
|
|
963 return CATEGORY_TABLE_VALUEP (value);
|
|
964 CHECK_CATEGORY_TABLE_VALUE (value);
|
|
965 break;
|
|
966 #endif /* MULE */
|
|
967
|
|
968 case CHAR_TABLE_TYPE_GENERIC:
|
|
969 return 1;
|
|
970
|
|
971 case CHAR_TABLE_TYPE_DISPLAY:
|
|
972 /* #### fix this */
|
563
|
973 maybe_signal_error (Qunimplemented,
|
|
974 "Display char tables not yet implemented",
|
|
975 value, Qchar_table, errb);
|
428
|
976 return 0;
|
|
977
|
|
978 case CHAR_TABLE_TYPE_CHAR:
|
|
979 if (!ERRB_EQ (errb, ERROR_ME))
|
|
980 return CHAR_OR_CHAR_INTP (value);
|
|
981 CHECK_CHAR_COERCE_INT (value);
|
|
982 break;
|
|
983
|
|
984 default:
|
2500
|
985 ABORT ();
|
428
|
986 }
|
|
987
|
801
|
988 return 0; /* not (usually) reached */
|
428
|
989 }
|
|
990
|
|
991 static Lisp_Object
|
|
992 canonicalize_char_table_value (Lisp_Object value, enum char_table_type type)
|
|
993 {
|
|
994 switch (type)
|
|
995 {
|
|
996 case CHAR_TABLE_TYPE_SYNTAX:
|
|
997 if (CONSP (value))
|
|
998 {
|
|
999 Lisp_Object car = XCAR (value);
|
|
1000 Lisp_Object cdr = XCDR (value);
|
|
1001 CHECK_CHAR_COERCE_INT (cdr);
|
|
1002 return Fcons (car, cdr);
|
|
1003 }
|
|
1004 break;
|
|
1005 case CHAR_TABLE_TYPE_CHAR:
|
|
1006 CHECK_CHAR_COERCE_INT (value);
|
|
1007 break;
|
|
1008 default:
|
|
1009 break;
|
|
1010 }
|
|
1011 return value;
|
|
1012 }
|
|
1013
|
|
1014 DEFUN ("valid-char-table-value-p", Fvalid_char_table_value_p, 2, 2, 0, /*
|
|
1015 Return non-nil if VALUE is a valid value for CHAR-TABLE-TYPE.
|
|
1016 */
|
|
1017 (value, char_table_type))
|
|
1018 {
|
|
1019 enum char_table_type type = symbol_to_char_table_type (char_table_type);
|
|
1020
|
|
1021 return check_valid_char_table_value (value, type, ERROR_ME_NOT) ? Qt : Qnil;
|
|
1022 }
|
|
1023
|
|
1024 DEFUN ("check-valid-char-table-value", Fcheck_valid_char_table_value, 2, 2, 0, /*
|
|
1025 Signal an error if VALUE is not a valid value for CHAR-TABLE-TYPE.
|
|
1026 */
|
|
1027 (value, char_table_type))
|
|
1028 {
|
|
1029 enum char_table_type type = symbol_to_char_table_type (char_table_type);
|
|
1030
|
|
1031 check_valid_char_table_value (value, type, ERROR_ME);
|
|
1032 return Qnil;
|
|
1033 }
|
|
1034
|
826
|
1035 /* Assign VAL to all characters in RANGE in char table TABLE. */
|
428
|
1036
|
|
1037 void
|
826
|
1038 put_char_table (Lisp_Object table, struct chartab_range *range,
|
428
|
1039 Lisp_Object val)
|
|
1040 {
|
826
|
1041 Lisp_Char_Table *ct = XCHAR_TABLE (table);
|
|
1042
|
428
|
1043 switch (range->type)
|
|
1044 {
|
|
1045 case CHARTAB_RANGE_ALL:
|
|
1046 fill_char_table (ct, val);
|
1296
|
1047 return; /* fill_char_table() recorded the table as dirty. */
|
428
|
1048
|
|
1049 #ifdef MULE
|
|
1050 case CHARTAB_RANGE_CHARSET:
|
|
1051 if (EQ (range->charset, Vcharset_ascii))
|
|
1052 {
|
|
1053 int i;
|
|
1054 for (i = 0; i < 128; i++)
|
|
1055 ct->ascii[i] = val;
|
|
1056 }
|
|
1057 else if (EQ (range->charset, Vcharset_control_1))
|
|
1058 {
|
|
1059 int i;
|
|
1060 for (i = 128; i < 160; i++)
|
|
1061 ct->ascii[i] = val;
|
|
1062 }
|
|
1063 else
|
|
1064 {
|
|
1065 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
|
1330
|
1066 if (CHAR_TABLE_ENTRYP (ct->level1[lb]) &&
|
|
1067 !OBJECT_DUMPED_P (ct->level1[lb]))
|
3017
|
1068 FREE_LCRECORD (ct->level1[lb]);
|
428
|
1069 ct->level1[lb] = val;
|
|
1070 }
|
|
1071 break;
|
|
1072
|
|
1073 case CHARTAB_RANGE_ROW:
|
|
1074 {
|
440
|
1075 Lisp_Char_Table_Entry *cte;
|
428
|
1076 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
|
|
1077 /* make sure that there is a separate entry for the row. */
|
|
1078 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
|
|
1079 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
|
|
1080 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
|
|
1081 cte->level2[range->row - 32] = val;
|
|
1082 }
|
|
1083 break;
|
|
1084 #endif /* MULE */
|
|
1085
|
|
1086 case CHARTAB_RANGE_CHAR:
|
|
1087 #ifdef MULE
|
|
1088 {
|
|
1089 Lisp_Object charset;
|
|
1090 int byte1, byte2;
|
|
1091
|
867
|
1092 BREAKUP_ICHAR (range->ch, charset, byte1, byte2);
|
428
|
1093 if (EQ (charset, Vcharset_ascii))
|
|
1094 ct->ascii[byte1] = val;
|
|
1095 else if (EQ (charset, Vcharset_control_1))
|
|
1096 ct->ascii[byte1 + 128] = val;
|
|
1097 else
|
|
1098 {
|
440
|
1099 Lisp_Char_Table_Entry *cte;
|
428
|
1100 int lb = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
|
|
1101 /* make sure that there is a separate entry for the row. */
|
|
1102 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
|
|
1103 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
|
|
1104 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
|
|
1105 /* now CTE is a char table entry for the charset;
|
|
1106 each entry is for a single row (or character of
|
|
1107 a one-octet charset). */
|
|
1108 if (XCHARSET_DIMENSION (charset) == 1)
|
|
1109 cte->level2[byte1 - 32] = val;
|
|
1110 else
|
|
1111 {
|
|
1112 /* assigning to one character in a two-octet charset. */
|
|
1113 /* make sure that the charset row contains a separate
|
|
1114 entry for each character. */
|
|
1115 if (!CHAR_TABLE_ENTRYP (cte->level2[byte1 - 32]))
|
|
1116 cte->level2[byte1 - 32] =
|
|
1117 make_char_table_entry (cte->level2[byte1 - 32]);
|
|
1118 cte = XCHAR_TABLE_ENTRY (cte->level2[byte1 - 32]);
|
|
1119 cte->level2[byte2 - 32] = val;
|
|
1120 }
|
|
1121 }
|
|
1122 }
|
|
1123 #else /* not MULE */
|
|
1124 ct->ascii[(unsigned char) (range->ch)] = val;
|
|
1125 break;
|
|
1126 #endif /* not MULE */
|
|
1127 }
|
|
1128
|
|
1129 if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
|
1296
|
1130 set_char_table_dirty (wrap_char_table (ct));
|
428
|
1131 }
|
|
1132
|
|
1133 DEFUN ("put-char-table", Fput_char_table, 3, 3, 0, /*
|
444
|
1134 Set the value for chars in RANGE to be VALUE in CHAR-TABLE.
|
428
|
1135
|
|
1136 RANGE specifies one or more characters to be affected and should be
|
|
1137 one of the following:
|
|
1138
|
|
1139 -- t (all characters are affected)
|
|
1140 -- A charset (only allowed when Mule support is present)
|
2714
|
1141 -- A vector of two elements: a two-octet charset and a row number; the row
|
|
1142 must be an integer, not a character (only allowed when Mule support is
|
|
1143 present)
|
428
|
1144 -- A single character
|
|
1145
|
444
|
1146 VALUE must be a value appropriate for the type of CHAR-TABLE.
|
800
|
1147 See `make-char-table'.
|
428
|
1148 */
|
444
|
1149 (range, value, char_table))
|
428
|
1150 {
|
440
|
1151 Lisp_Char_Table *ct;
|
428
|
1152 struct chartab_range rainj;
|
|
1153
|
444
|
1154 CHECK_CHAR_TABLE (char_table);
|
|
1155 ct = XCHAR_TABLE (char_table);
|
|
1156 check_valid_char_table_value (value, ct->type, ERROR_ME);
|
428
|
1157 decode_char_table_range (range, &rainj);
|
444
|
1158 value = canonicalize_char_table_value (value, ct->type);
|
826
|
1159 put_char_table (char_table, &rainj, value);
|
|
1160 return Qnil;
|
|
1161 }
|
|
1162
|
|
1163 DEFUN ("remove-char-table", Fremove_char_table, 2, 2, 0, /*
|
|
1164 Remove any value from chars in RANGE in CHAR-TABLE.
|
|
1165
|
|
1166 RANGE specifies one or more characters to be affected and should be
|
|
1167 one of the following:
|
|
1168
|
|
1169 -- t (all characters are affected)
|
|
1170 -- A charset (only allowed when Mule support is present)
|
|
1171 -- A vector of two elements: a two-octet charset and a row number
|
|
1172 (only allowed when Mule support is present)
|
|
1173 -- A single character
|
|
1174
|
2726
|
1175 With all values removed, the default value will be returned by
|
|
1176 `get-char-table' and `get-range-char-table'.
|
826
|
1177 */
|
|
1178 (range, char_table))
|
|
1179 {
|
|
1180 struct chartab_range rainj;
|
|
1181
|
|
1182 CHECK_CHAR_TABLE (char_table);
|
|
1183 decode_char_table_range (range, &rainj);
|
|
1184 put_char_table (char_table, &rainj, Qunbound);
|
428
|
1185 return Qnil;
|
|
1186 }
|
|
1187
|
|
1188 /* Map FN over the ASCII chars in CT. */
|
|
1189
|
|
1190 static int
|
826
|
1191 map_over_charset_ascii_1 (Lisp_Char_Table *ct,
|
|
1192 int start, int stop,
|
|
1193 int (*fn) (struct chartab_range *range,
|
|
1194 Lisp_Object table, Lisp_Object val,
|
|
1195 void *arg),
|
|
1196 void *arg)
|
|
1197 {
|
|
1198 struct chartab_range rainj;
|
|
1199 int i, retval;
|
|
1200
|
|
1201 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1202
|
|
1203 for (i = start, retval = 0; i <= stop && retval == 0; i++)
|
|
1204 {
|
867
|
1205 rainj.ch = (Ichar) i;
|
826
|
1206 if (!UNBOUNDP (ct->ascii[i]))
|
|
1207 retval = (fn) (&rainj, wrap_char_table (ct), ct->ascii[i], arg);
|
|
1208 }
|
|
1209
|
|
1210 return retval;
|
|
1211 }
|
|
1212
|
|
1213
|
|
1214 /* Map FN over the ASCII chars in CT. */
|
|
1215
|
|
1216 static int
|
440
|
1217 map_over_charset_ascii (Lisp_Char_Table *ct,
|
428
|
1218 int (*fn) (struct chartab_range *range,
|
826
|
1219 Lisp_Object table, Lisp_Object val,
|
|
1220 void *arg),
|
428
|
1221 void *arg)
|
|
1222 {
|
826
|
1223 return map_over_charset_ascii_1 (ct, 0,
|
428
|
1224 #ifdef MULE
|
826
|
1225 127,
|
428
|
1226 #else
|
826
|
1227 255,
|
428
|
1228 #endif
|
826
|
1229 fn, arg);
|
428
|
1230 }
|
|
1231
|
|
1232 #ifdef MULE
|
|
1233
|
|
1234 /* Map FN over the Control-1 chars in CT. */
|
|
1235
|
|
1236 static int
|
440
|
1237 map_over_charset_control_1 (Lisp_Char_Table *ct,
|
428
|
1238 int (*fn) (struct chartab_range *range,
|
826
|
1239 Lisp_Object table, Lisp_Object val,
|
|
1240 void *arg),
|
428
|
1241 void *arg)
|
|
1242 {
|
826
|
1243 return map_over_charset_ascii_1 (ct, 128, 159, fn, arg);
|
428
|
1244 }
|
|
1245
|
|
1246 /* Map FN over the row ROW of two-byte charset CHARSET.
|
|
1247 There must be a separate value for that row in the char table.
|
|
1248 CTE specifies the char table entry for CHARSET. */
|
|
1249
|
|
1250 static int
|
826
|
1251 map_over_charset_row (Lisp_Char_Table *ct,
|
|
1252 Lisp_Char_Table_Entry *cte,
|
428
|
1253 Lisp_Object charset, int row,
|
|
1254 int (*fn) (struct chartab_range *range,
|
826
|
1255 Lisp_Object table, Lisp_Object val,
|
|
1256 void *arg),
|
428
|
1257 void *arg)
|
|
1258 {
|
|
1259 Lisp_Object val = cte->level2[row - 32];
|
|
1260
|
826
|
1261 if (UNBOUNDP (val))
|
|
1262 return 0;
|
|
1263 else if (!CHAR_TABLE_ENTRYP (val))
|
428
|
1264 {
|
|
1265 struct chartab_range rainj;
|
826
|
1266
|
428
|
1267 rainj.type = CHARTAB_RANGE_ROW;
|
|
1268 rainj.charset = charset;
|
|
1269 rainj.row = row;
|
826
|
1270 return (fn) (&rainj, wrap_char_table (ct), val, arg);
|
428
|
1271 }
|
|
1272 else
|
|
1273 {
|
|
1274 struct chartab_range rainj;
|
|
1275 int i, retval;
|
826
|
1276 int start, stop;
|
|
1277
|
|
1278 get_charset_limits (charset, &start, &stop);
|
428
|
1279
|
|
1280 cte = XCHAR_TABLE_ENTRY (val);
|
|
1281
|
|
1282 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1283
|
826
|
1284 for (i = start, retval = 0; i <= stop && retval == 0; i++)
|
428
|
1285 {
|
867
|
1286 rainj.ch = make_ichar (charset, row, i);
|
826
|
1287 if (!UNBOUNDP (cte->level2[i - 32]))
|
|
1288 retval = (fn) (&rainj, wrap_char_table (ct), cte->level2[i - 32],
|
|
1289 arg);
|
428
|
1290 }
|
|
1291 return retval;
|
|
1292 }
|
|
1293 }
|
|
1294
|
|
1295
|
|
1296 static int
|
440
|
1297 map_over_other_charset (Lisp_Char_Table *ct, int lb,
|
428
|
1298 int (*fn) (struct chartab_range *range,
|
826
|
1299 Lisp_Object table, Lisp_Object val,
|
|
1300 void *arg),
|
428
|
1301 void *arg)
|
|
1302 {
|
|
1303 Lisp_Object val = ct->level1[lb - MIN_LEADING_BYTE];
|
826
|
1304 Lisp_Object charset = charset_by_leading_byte (lb);
|
428
|
1305
|
|
1306 if (!CHARSETP (charset)
|
|
1307 || lb == LEADING_BYTE_ASCII
|
|
1308 || lb == LEADING_BYTE_CONTROL_1)
|
|
1309 return 0;
|
|
1310
|
826
|
1311 if (UNBOUNDP (val))
|
|
1312 return 0;
|
428
|
1313 if (!CHAR_TABLE_ENTRYP (val))
|
|
1314 {
|
|
1315 struct chartab_range rainj;
|
|
1316
|
|
1317 rainj.type = CHARTAB_RANGE_CHARSET;
|
|
1318 rainj.charset = charset;
|
826
|
1319 return (fn) (&rainj, wrap_char_table (ct), val, arg);
|
428
|
1320 }
|
|
1321 {
|
440
|
1322 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
|
826
|
1323 int start, stop;
|
428
|
1324 int i, retval;
|
|
1325
|
826
|
1326 get_charset_limits (charset, &start, &stop);
|
428
|
1327 if (XCHARSET_DIMENSION (charset) == 1)
|
|
1328 {
|
|
1329 struct chartab_range rainj;
|
|
1330 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1331
|
826
|
1332 for (i = start, retval = 0; i <= stop && retval == 0; i++)
|
428
|
1333 {
|
867
|
1334 rainj.ch = make_ichar (charset, i, 0);
|
826
|
1335 if (!UNBOUNDP (cte->level2[i - 32]))
|
|
1336 retval = (fn) (&rainj, wrap_char_table (ct), cte->level2[i - 32],
|
|
1337 arg);
|
428
|
1338 }
|
|
1339 }
|
|
1340 else
|
|
1341 {
|
826
|
1342 for (i = start, retval = 0; i <= stop && retval == 0; i++)
|
|
1343 retval = map_over_charset_row (ct, cte, charset, i, fn, arg);
|
428
|
1344 }
|
|
1345
|
|
1346 return retval;
|
|
1347 }
|
|
1348 }
|
|
1349
|
|
1350 #endif /* MULE */
|
|
1351
|
|
1352 /* Map FN (with client data ARG) over range RANGE in char table CT.
|
|
1353 Mapping stops the first time FN returns non-zero, and that value
|
826
|
1354 becomes the return value of map_char_table().
|
|
1355
|
|
1356 #### This mapping code is way ugly. The FSF version, in contrast,
|
|
1357 is short and sweet, and much more recursive. There should be some way
|
|
1358 of cleaning this up. */
|
428
|
1359
|
|
1360 int
|
826
|
1361 map_char_table (Lisp_Object table,
|
428
|
1362 struct chartab_range *range,
|
|
1363 int (*fn) (struct chartab_range *range,
|
826
|
1364 Lisp_Object table, Lisp_Object val, void *arg),
|
428
|
1365 void *arg)
|
|
1366 {
|
826
|
1367 Lisp_Char_Table *ct = XCHAR_TABLE (table);
|
428
|
1368 switch (range->type)
|
|
1369 {
|
|
1370 case CHARTAB_RANGE_ALL:
|
|
1371 {
|
|
1372 int retval;
|
|
1373
|
|
1374 retval = map_over_charset_ascii (ct, fn, arg);
|
|
1375 if (retval)
|
|
1376 return retval;
|
|
1377 #ifdef MULE
|
|
1378 retval = map_over_charset_control_1 (ct, fn, arg);
|
|
1379 if (retval)
|
|
1380 return retval;
|
|
1381 {
|
|
1382 int i;
|
|
1383 int start = MIN_LEADING_BYTE;
|
|
1384 int stop = start + NUM_LEADING_BYTES;
|
|
1385
|
|
1386 for (i = start, retval = 0; i < stop && retval == 0; i++)
|
|
1387 {
|
771
|
1388 if (i != LEADING_BYTE_ASCII && i != LEADING_BYTE_CONTROL_1)
|
|
1389 retval = map_over_other_charset (ct, i, fn, arg);
|
428
|
1390 }
|
|
1391 }
|
|
1392 #endif /* MULE */
|
|
1393 return retval;
|
|
1394 }
|
|
1395
|
|
1396 #ifdef MULE
|
|
1397 case CHARTAB_RANGE_CHARSET:
|
|
1398 return map_over_other_charset (ct,
|
|
1399 XCHARSET_LEADING_BYTE (range->charset),
|
|
1400 fn, arg);
|
|
1401
|
|
1402 case CHARTAB_RANGE_ROW:
|
|
1403 {
|
771
|
1404 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (range->charset) -
|
|
1405 MIN_LEADING_BYTE];
|
826
|
1406
|
|
1407 if (CHAR_TABLE_ENTRYP (val))
|
|
1408 return map_over_charset_row (ct, XCHAR_TABLE_ENTRY (val),
|
|
1409 range->charset, range->row, fn, arg);
|
|
1410 else if (!UNBOUNDP (val))
|
428
|
1411 {
|
|
1412 struct chartab_range rainj;
|
|
1413
|
|
1414 rainj.type = CHARTAB_RANGE_ROW;
|
|
1415 rainj.charset = range->charset;
|
|
1416 rainj.row = range->row;
|
826
|
1417 return (fn) (&rainj, table, val, arg);
|
428
|
1418 }
|
|
1419 else
|
826
|
1420 return 0;
|
428
|
1421 }
|
|
1422 #endif /* MULE */
|
|
1423
|
|
1424 case CHARTAB_RANGE_CHAR:
|
|
1425 {
|
867
|
1426 Ichar ch = range->ch;
|
826
|
1427 Lisp_Object val = get_char_table (ch, table);
|
428
|
1428 struct chartab_range rainj;
|
|
1429
|
826
|
1430 if (!UNBOUNDP (val))
|
|
1431 {
|
|
1432 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1433 rainj.ch = ch;
|
|
1434 return (fn) (&rainj, table, val, arg);
|
|
1435 }
|
|
1436 else
|
|
1437 return 0;
|
428
|
1438 }
|
|
1439
|
|
1440 default:
|
2500
|
1441 ABORT ();
|
428
|
1442 }
|
|
1443
|
|
1444 return 0;
|
|
1445 }
|
|
1446
|
|
1447 struct slow_map_char_table_arg
|
|
1448 {
|
|
1449 Lisp_Object function;
|
|
1450 Lisp_Object retval;
|
|
1451 };
|
|
1452
|
|
1453 static int
|
|
1454 slow_map_char_table_fun (struct chartab_range *range,
|
2286
|
1455 Lisp_Object UNUSED (table), Lisp_Object val,
|
|
1456 void *arg)
|
428
|
1457 {
|
|
1458 struct slow_map_char_table_arg *closure =
|
|
1459 (struct slow_map_char_table_arg *) arg;
|
|
1460
|
826
|
1461 closure->retval = call2 (closure->function, encode_char_table_range (range),
|
|
1462 val);
|
428
|
1463 return !NILP (closure->retval);
|
|
1464 }
|
|
1465
|
|
1466 DEFUN ("map-char-table", Fmap_char_table, 2, 3, 0, /*
|
2726
|
1467 Map FUNCTION over CHAR-TABLE until it returns non-nil; return that value.
|
|
1468 FUNCTION is called with two arguments, each key and entry in the table.
|
|
1469
|
|
1470 RANGE specifies a subrange to map over. If omitted or t, it defaults to
|
|
1471 the entire table.
|
428
|
1472
|
2726
|
1473 Both RANGE and the keys passed to FUNCTION are in the same format as the
|
|
1474 RANGE argument to `put-char-table'. N.B. This function does NOT map over
|
|
1475 all characters in RANGE, but over the subranges that have been assigned to.
|
|
1476 Thus this function is most suitable for searching a char-table, or for
|
|
1477 populating one char-table based on the contents of another. The current
|
|
1478 implementation does not coalesce ranges all of whose values are the same.
|
428
|
1479 */
|
444
|
1480 (function, char_table, range))
|
428
|
1481 {
|
|
1482 struct slow_map_char_table_arg slarg;
|
|
1483 struct gcpro gcpro1, gcpro2;
|
|
1484 struct chartab_range rainj;
|
|
1485
|
444
|
1486 CHECK_CHAR_TABLE (char_table);
|
428
|
1487 if (NILP (range))
|
|
1488 range = Qt;
|
|
1489 decode_char_table_range (range, &rainj);
|
|
1490 slarg.function = function;
|
|
1491 slarg.retval = Qnil;
|
|
1492 GCPRO2 (slarg.function, slarg.retval);
|
826
|
1493 map_char_table (char_table, &rainj, slow_map_char_table_fun, &slarg);
|
428
|
1494 UNGCPRO;
|
|
1495
|
|
1496 return slarg.retval;
|
|
1497 }
|
|
1498
|
|
1499
|
|
1500
|
|
1501 /************************************************************************/
|
|
1502 /* Char table read syntax */
|
|
1503 /************************************************************************/
|
|
1504
|
|
1505 static int
|
2286
|
1506 chartab_type_validate (Lisp_Object UNUSED (keyword), Lisp_Object value,
|
|
1507 Error_Behavior UNUSED (errb))
|
428
|
1508 {
|
|
1509 /* #### should deal with ERRB */
|
|
1510 symbol_to_char_table_type (value);
|
|
1511 return 1;
|
|
1512 }
|
|
1513
|
826
|
1514 /* #### Document the print/read format; esp. what's this cons element? */
|
|
1515
|
428
|
1516 static int
|
2286
|
1517 chartab_data_validate (Lisp_Object UNUSED (keyword), Lisp_Object value,
|
|
1518 Error_Behavior UNUSED (errb))
|
428
|
1519 {
|
|
1520 /* #### should deal with ERRB */
|
2367
|
1521 EXTERNAL_PROPERTY_LIST_LOOP_3 (range, data, value)
|
428
|
1522 {
|
|
1523 struct chartab_range dummy;
|
|
1524
|
|
1525 if (CONSP (range))
|
|
1526 {
|
|
1527 if (!CONSP (XCDR (range))
|
|
1528 || !NILP (XCDR (XCDR (range))))
|
563
|
1529 sferror ("Invalid range format", range);
|
428
|
1530 decode_char_table_range (XCAR (range), &dummy);
|
|
1531 decode_char_table_range (XCAR (XCDR (range)), &dummy);
|
|
1532 }
|
|
1533 else
|
|
1534 decode_char_table_range (range, &dummy);
|
|
1535 }
|
|
1536
|
|
1537 return 1;
|
|
1538 }
|
|
1539
|
|
1540 static Lisp_Object
|
|
1541 chartab_instantiate (Lisp_Object data)
|
|
1542 {
|
|
1543 Lisp_Object chartab;
|
|
1544 Lisp_Object type = Qgeneric;
|
|
1545 Lisp_Object dataval = Qnil;
|
|
1546
|
|
1547 while (!NILP (data))
|
|
1548 {
|
|
1549 Lisp_Object keyw = Fcar (data);
|
|
1550 Lisp_Object valw;
|
|
1551
|
|
1552 data = Fcdr (data);
|
|
1553 valw = Fcar (data);
|
|
1554 data = Fcdr (data);
|
|
1555 if (EQ (keyw, Qtype))
|
|
1556 type = valw;
|
|
1557 else if (EQ (keyw, Qdata))
|
|
1558 dataval = valw;
|
|
1559 }
|
|
1560
|
|
1561 chartab = Fmake_char_table (type);
|
|
1562
|
|
1563 data = dataval;
|
|
1564 while (!NILP (data))
|
|
1565 {
|
|
1566 Lisp_Object range = Fcar (data);
|
|
1567 Lisp_Object val = Fcar (Fcdr (data));
|
|
1568
|
|
1569 data = Fcdr (Fcdr (data));
|
|
1570 if (CONSP (range))
|
|
1571 {
|
|
1572 if (CHAR_OR_CHAR_INTP (XCAR (range)))
|
|
1573 {
|
867
|
1574 Ichar first = XCHAR_OR_CHAR_INT (Fcar (range));
|
|
1575 Ichar last = XCHAR_OR_CHAR_INT (Fcar (Fcdr (range)));
|
|
1576 Ichar i;
|
428
|
1577
|
|
1578 for (i = first; i <= last; i++)
|
|
1579 Fput_char_table (make_char (i), val, chartab);
|
|
1580 }
|
|
1581 else
|
2500
|
1582 ABORT ();
|
428
|
1583 }
|
|
1584 else
|
|
1585 Fput_char_table (range, val, chartab);
|
|
1586 }
|
|
1587
|
|
1588 return chartab;
|
|
1589 }
|
|
1590
|
|
1591 #ifdef MULE
|
|
1592
|
|
1593
|
|
1594 /************************************************************************/
|
|
1595 /* Category Tables, specifically */
|
|
1596 /************************************************************************/
|
|
1597
|
|
1598 DEFUN ("category-table-p", Fcategory_table_p, 1, 1, 0, /*
|
444
|
1599 Return t if OBJECT is a category table.
|
428
|
1600 A category table is a type of char table used for keeping track of
|
|
1601 categories. Categories are used for classifying characters for use
|
|
1602 in regexps -- you can refer to a category rather than having to use
|
|
1603 a complicated [] expression (and category lookups are significantly
|
|
1604 faster).
|
|
1605
|
|
1606 There are 95 different categories available, one for each printable
|
|
1607 character (including space) in the ASCII charset. Each category
|
|
1608 is designated by one such character, called a "category designator".
|
|
1609 They are specified in a regexp using the syntax "\\cX", where X is
|
|
1610 a category designator.
|
|
1611
|
|
1612 A category table specifies, for each character, the categories that
|
|
1613 the character is in. Note that a character can be in more than one
|
|
1614 category. More specifically, a category table maps from a character
|
|
1615 to either the value nil (meaning the character is in no categories)
|
|
1616 or a 95-element bit vector, specifying for each of the 95 categories
|
|
1617 whether the character is in that category.
|
|
1618
|
|
1619 Special Lisp functions are provided that abstract this, so you do not
|
|
1620 have to directly manipulate bit vectors.
|
|
1621 */
|
444
|
1622 (object))
|
428
|
1623 {
|
444
|
1624 return (CHAR_TABLEP (object) &&
|
|
1625 XCHAR_TABLE_TYPE (object) == CHAR_TABLE_TYPE_CATEGORY) ?
|
428
|
1626 Qt : Qnil;
|
|
1627 }
|
|
1628
|
|
1629 static Lisp_Object
|
444
|
1630 check_category_table (Lisp_Object object, Lisp_Object default_)
|
428
|
1631 {
|
444
|
1632 if (NILP (object))
|
|
1633 object = default_;
|
|
1634 while (NILP (Fcategory_table_p (object)))
|
|
1635 object = wrong_type_argument (Qcategory_table_p, object);
|
|
1636 return object;
|
428
|
1637 }
|
|
1638
|
|
1639 int
|
867
|
1640 check_category_char (Ichar ch, Lisp_Object table,
|
647
|
1641 int designator, int not_p)
|
428
|
1642 {
|
|
1643 REGISTER Lisp_Object temp;
|
|
1644 if (NILP (Fcategory_table_p (table)))
|
563
|
1645 wtaerror ("Expected category table", table);
|
826
|
1646 temp = get_char_table (ch, table);
|
428
|
1647 if (NILP (temp))
|
458
|
1648 return not_p;
|
428
|
1649
|
|
1650 designator -= ' ';
|
458
|
1651 return bit_vector_bit (XBIT_VECTOR (temp), designator) ? !not_p : not_p;
|
428
|
1652 }
|
|
1653
|
|
1654 DEFUN ("check-category-at", Fcheck_category_at, 2, 4, 0, /*
|
444
|
1655 Return t if category of the character at POSITION includes DESIGNATOR.
|
|
1656 Optional third arg BUFFER specifies which buffer to use, and defaults
|
|
1657 to the current buffer.
|
|
1658 Optional fourth arg CATEGORY-TABLE specifies the category table to
|
|
1659 use, and defaults to BUFFER's category table.
|
428
|
1660 */
|
444
|
1661 (position, designator, buffer, category_table))
|
428
|
1662 {
|
|
1663 Lisp_Object ctbl;
|
867
|
1664 Ichar ch;
|
647
|
1665 int des;
|
428
|
1666 struct buffer *buf = decode_buffer (buffer, 0);
|
|
1667
|
444
|
1668 CHECK_INT (position);
|
428
|
1669 CHECK_CATEGORY_DESIGNATOR (designator);
|
|
1670 des = XCHAR (designator);
|
788
|
1671 ctbl = check_category_table (category_table, buf->category_table);
|
444
|
1672 ch = BUF_FETCH_CHAR (buf, XINT (position));
|
428
|
1673 return check_category_char (ch, ctbl, des, 0) ? Qt : Qnil;
|
|
1674 }
|
|
1675
|
|
1676 DEFUN ("char-in-category-p", Fchar_in_category_p, 2, 3, 0, /*
|
788
|
1677 Return non-nil if category of CHARACTER includes DESIGNATOR.
|
444
|
1678 Optional third arg CATEGORY-TABLE specifies the category table to use,
|
788
|
1679 and defaults to the current buffer's category table.
|
428
|
1680 */
|
444
|
1681 (character, designator, category_table))
|
428
|
1682 {
|
|
1683 Lisp_Object ctbl;
|
867
|
1684 Ichar ch;
|
647
|
1685 int des;
|
428
|
1686
|
|
1687 CHECK_CATEGORY_DESIGNATOR (designator);
|
|
1688 des = XCHAR (designator);
|
444
|
1689 CHECK_CHAR (character);
|
|
1690 ch = XCHAR (character);
|
788
|
1691 ctbl = check_category_table (category_table, current_buffer->category_table);
|
428
|
1692 return check_category_char (ch, ctbl, des, 0) ? Qt : Qnil;
|
|
1693 }
|
|
1694
|
|
1695 DEFUN ("category-table", Fcategory_table, 0, 1, 0, /*
|
444
|
1696 Return BUFFER's current category table.
|
|
1697 BUFFER defaults to the current buffer.
|
428
|
1698 */
|
|
1699 (buffer))
|
|
1700 {
|
|
1701 return decode_buffer (buffer, 0)->category_table;
|
|
1702 }
|
|
1703
|
|
1704 DEFUN ("standard-category-table", Fstandard_category_table, 0, 0, 0, /*
|
|
1705 Return the standard category table.
|
|
1706 This is the one used for new buffers.
|
|
1707 */
|
|
1708 ())
|
|
1709 {
|
|
1710 return Vstandard_category_table;
|
|
1711 }
|
|
1712
|
|
1713 DEFUN ("copy-category-table", Fcopy_category_table, 0, 1, 0, /*
|
444
|
1714 Return a new category table which is a copy of CATEGORY-TABLE.
|
|
1715 CATEGORY-TABLE defaults to the standard category table.
|
428
|
1716 */
|
444
|
1717 (category_table))
|
428
|
1718 {
|
|
1719 if (NILP (Vstandard_category_table))
|
|
1720 return Fmake_char_table (Qcategory);
|
|
1721
|
444
|
1722 category_table =
|
|
1723 check_category_table (category_table, Vstandard_category_table);
|
|
1724 return Fcopy_char_table (category_table);
|
428
|
1725 }
|
|
1726
|
|
1727 DEFUN ("set-category-table", Fset_category_table, 1, 2, 0, /*
|
444
|
1728 Select CATEGORY-TABLE as the new category table for BUFFER.
|
428
|
1729 BUFFER defaults to the current buffer if omitted.
|
|
1730 */
|
444
|
1731 (category_table, buffer))
|
428
|
1732 {
|
|
1733 struct buffer *buf = decode_buffer (buffer, 0);
|
444
|
1734 category_table = check_category_table (category_table, Qnil);
|
|
1735 buf->category_table = category_table;
|
428
|
1736 /* Indicate that this buffer now has a specified category table. */
|
|
1737 buf->local_var_flags |= XINT (buffer_local_flags.category_table);
|
444
|
1738 return category_table;
|
428
|
1739 }
|
|
1740
|
|
1741 DEFUN ("category-designator-p", Fcategory_designator_p, 1, 1, 0, /*
|
444
|
1742 Return t if OBJECT is a category designator (a char in the range ' ' to '~').
|
428
|
1743 */
|
444
|
1744 (object))
|
428
|
1745 {
|
444
|
1746 return CATEGORY_DESIGNATORP (object) ? Qt : Qnil;
|
428
|
1747 }
|
|
1748
|
|
1749 DEFUN ("category-table-value-p", Fcategory_table_value_p, 1, 1, 0, /*
|
444
|
1750 Return t if OBJECT is a category table value.
|
428
|
1751 Valid values are nil or a bit vector of size 95.
|
|
1752 */
|
444
|
1753 (object))
|
428
|
1754 {
|
444
|
1755 return CATEGORY_TABLE_VALUEP (object) ? Qt : Qnil;
|
428
|
1756 }
|
|
1757
|
|
1758
|
|
1759 #define CATEGORYP(x) \
|
|
1760 (CHARP (x) && XCHAR (x) >= 0x20 && XCHAR (x) <= 0x7E)
|
|
1761
|
826
|
1762 #define CATEGORY_SET(c) get_char_table (c, current_buffer->category_table)
|
428
|
1763
|
|
1764 /* Return 1 if CATEGORY_SET contains CATEGORY, else return 0.
|
|
1765 The faster version of `!NILP (Faref (category_set, category))'. */
|
|
1766 #define CATEGORY_MEMBER(category, category_set) \
|
|
1767 (bit_vector_bit(XBIT_VECTOR (category_set), category - 32))
|
|
1768
|
|
1769 /* Return 1 if there is a word boundary between two word-constituent
|
|
1770 characters C1 and C2 if they appear in this order, else return 0.
|
|
1771 Use the macro WORD_BOUNDARY_P instead of calling this function
|
|
1772 directly. */
|
|
1773
|
|
1774 int
|
867
|
1775 word_boundary_p (Ichar c1, Ichar c2)
|
428
|
1776 {
|
|
1777 Lisp_Object category_set1, category_set2;
|
|
1778 Lisp_Object tail;
|
|
1779 int default_result;
|
|
1780
|
|
1781 #if 0
|
|
1782 if (COMPOSITE_CHAR_P (c1))
|
|
1783 c1 = cmpchar_component (c1, 0, 1);
|
|
1784 if (COMPOSITE_CHAR_P (c2))
|
|
1785 c2 = cmpchar_component (c2, 0, 1);
|
|
1786 #endif
|
|
1787
|
867
|
1788 if (EQ (ichar_charset (c1), ichar_charset (c2)))
|
428
|
1789 {
|
|
1790 tail = Vword_separating_categories;
|
|
1791 default_result = 0;
|
|
1792 }
|
|
1793 else
|
|
1794 {
|
|
1795 tail = Vword_combining_categories;
|
|
1796 default_result = 1;
|
|
1797 }
|
|
1798
|
|
1799 category_set1 = CATEGORY_SET (c1);
|
|
1800 if (NILP (category_set1))
|
|
1801 return default_result;
|
|
1802 category_set2 = CATEGORY_SET (c2);
|
|
1803 if (NILP (category_set2))
|
|
1804 return default_result;
|
|
1805
|
853
|
1806 for (; CONSP (tail); tail = XCDR (tail))
|
428
|
1807 {
|
853
|
1808 Lisp_Object elt = XCAR (tail);
|
428
|
1809
|
|
1810 if (CONSP (elt)
|
853
|
1811 && CATEGORYP (XCAR (elt))
|
|
1812 && CATEGORYP (XCDR (elt))
|
|
1813 && CATEGORY_MEMBER (XCHAR (XCAR (elt)), category_set1)
|
|
1814 && CATEGORY_MEMBER (XCHAR (XCDR (elt)), category_set2))
|
428
|
1815 return !default_result;
|
|
1816 }
|
|
1817 return default_result;
|
|
1818 }
|
|
1819 #endif /* MULE */
|
|
1820
|
|
1821
|
|
1822 void
|
|
1823 syms_of_chartab (void)
|
|
1824 {
|
442
|
1825 INIT_LRECORD_IMPLEMENTATION (char_table);
|
|
1826
|
428
|
1827 #ifdef MULE
|
442
|
1828 INIT_LRECORD_IMPLEMENTATION (char_table_entry);
|
|
1829
|
563
|
1830 DEFSYMBOL (Qcategory_table_p);
|
|
1831 DEFSYMBOL (Qcategory_designator_p);
|
|
1832 DEFSYMBOL (Qcategory_table_value_p);
|
428
|
1833 #endif /* MULE */
|
|
1834
|
563
|
1835 DEFSYMBOL (Qchar_table);
|
|
1836 DEFSYMBOL_MULTIWORD_PREDICATE (Qchar_tablep);
|
428
|
1837
|
|
1838 DEFSUBR (Fchar_table_p);
|
|
1839 DEFSUBR (Fchar_table_type_list);
|
|
1840 DEFSUBR (Fvalid_char_table_type_p);
|
|
1841 DEFSUBR (Fchar_table_type);
|
826
|
1842 DEFSUBR (Fchar_table_default);
|
|
1843 DEFSUBR (Fset_char_table_default);
|
428
|
1844 DEFSUBR (Freset_char_table);
|
|
1845 DEFSUBR (Fmake_char_table);
|
|
1846 DEFSUBR (Fcopy_char_table);
|
|
1847 DEFSUBR (Fget_char_table);
|
|
1848 DEFSUBR (Fget_range_char_table);
|
|
1849 DEFSUBR (Fvalid_char_table_value_p);
|
|
1850 DEFSUBR (Fcheck_valid_char_table_value);
|
|
1851 DEFSUBR (Fput_char_table);
|
826
|
1852 DEFSUBR (Fremove_char_table);
|
428
|
1853 DEFSUBR (Fmap_char_table);
|
|
1854
|
|
1855 #ifdef MULE
|
|
1856 DEFSUBR (Fcategory_table_p);
|
|
1857 DEFSUBR (Fcategory_table);
|
|
1858 DEFSUBR (Fstandard_category_table);
|
|
1859 DEFSUBR (Fcopy_category_table);
|
|
1860 DEFSUBR (Fset_category_table);
|
|
1861 DEFSUBR (Fcheck_category_at);
|
|
1862 DEFSUBR (Fchar_in_category_p);
|
|
1863 DEFSUBR (Fcategory_designator_p);
|
|
1864 DEFSUBR (Fcategory_table_value_p);
|
|
1865 #endif /* MULE */
|
|
1866
|
|
1867 }
|
|
1868
|
|
1869 void
|
|
1870 vars_of_chartab (void)
|
|
1871 {
|
|
1872 /* DO NOT staticpro this. It works just like Vweak_hash_tables. */
|
|
1873 Vall_syntax_tables = Qnil;
|
452
|
1874 dump_add_weak_object_chain (&Vall_syntax_tables);
|
428
|
1875 }
|
|
1876
|
|
1877 void
|
|
1878 structure_type_create_chartab (void)
|
|
1879 {
|
|
1880 struct structure_type *st;
|
|
1881
|
|
1882 st = define_structure_type (Qchar_table, 0, chartab_instantiate);
|
|
1883
|
|
1884 define_structure_type_keyword (st, Qtype, chartab_type_validate);
|
|
1885 define_structure_type_keyword (st, Qdata, chartab_data_validate);
|
|
1886 }
|
|
1887
|
|
1888 void
|
|
1889 complex_vars_of_chartab (void)
|
|
1890 {
|
|
1891 #ifdef MULE
|
|
1892 /* Set this now, so first buffer creation can refer to it. */
|
|
1893 /* Make it nil before calling copy-category-table
|
|
1894 so that copy-category-table will know not to try to copy from garbage */
|
|
1895 Vstandard_category_table = Qnil;
|
|
1896 Vstandard_category_table = Fcopy_category_table (Qnil);
|
|
1897 staticpro (&Vstandard_category_table);
|
|
1898
|
|
1899 DEFVAR_LISP ("word-combining-categories", &Vword_combining_categories /*
|
|
1900 List of pair (cons) of categories to determine word boundary.
|
|
1901
|
|
1902 Emacs treats a sequence of word constituent characters as a single
|
|
1903 word (i.e. finds no word boundary between them) iff they belongs to
|
|
1904 the same charset. But, exceptions are allowed in the following cases.
|
|
1905
|
444
|
1906 \(1) The case that characters are in different charsets is controlled
|
428
|
1907 by the variable `word-combining-categories'.
|
|
1908
|
|
1909 Emacs finds no word boundary between characters of different charsets
|
|
1910 if they have categories matching some element of this list.
|
|
1911
|
|
1912 More precisely, if an element of this list is a cons of category CAT1
|
|
1913 and CAT2, and a multibyte character C1 which has CAT1 is followed by
|
|
1914 C2 which has CAT2, there's no word boundary between C1 and C2.
|
|
1915
|
|
1916 For instance, to tell that ASCII characters and Latin-1 characters can
|
|
1917 form a single word, the element `(?l . ?l)' should be in this list
|
|
1918 because both characters have the category `l' (Latin characters).
|
|
1919
|
444
|
1920 \(2) The case that character are in the same charset is controlled by
|
428
|
1921 the variable `word-separating-categories'.
|
|
1922
|
|
1923 Emacs find a word boundary between characters of the same charset
|
|
1924 if they have categories matching some element of this list.
|
|
1925
|
|
1926 More precisely, if an element of this list is a cons of category CAT1
|
|
1927 and CAT2, and a multibyte character C1 which has CAT1 is followed by
|
|
1928 C2 which has CAT2, there's a word boundary between C1 and C2.
|
|
1929
|
|
1930 For instance, to tell that there's a word boundary between Japanese
|
|
1931 Hiragana and Japanese Kanji (both are in the same charset), the
|
|
1932 element `(?H . ?C) should be in this list.
|
|
1933 */ );
|
|
1934
|
|
1935 Vword_combining_categories = Qnil;
|
|
1936
|
|
1937 DEFVAR_LISP ("word-separating-categories", &Vword_separating_categories /*
|
|
1938 List of pair (cons) of categories to determine word boundary.
|
|
1939 See the documentation of the variable `word-combining-categories'.
|
|
1940 */ );
|
|
1941
|
|
1942 Vword_separating_categories = Qnil;
|
|
1943 #endif /* MULE */
|
|
1944 }
|