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