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