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