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