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