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