comparison src/casetab.c @ 826:6728e641994e

[xemacs-hg @ 2002-05-05 11:30:15 by ben] syntax cache, 8-bit-format, lots of code cleanup README.packages: Update info about --package-path. i.c: Create an inheritable event and pass it on to XEmacs, so that ^C can be handled properly. Intercept ^C and signal the event. "Stop Build" in VC++ now works. bytecomp-runtime.el: Doc string changes. compat.el: Some attempts to redo this to make it truly useful and fix the "multiple versions interacting with each other" problem. Not yet done. Currently doesn't work. files.el: Use with-obsolete-variable to avoid warnings in new revert-buffer code. xemacs.mak: Split up CFLAGS into a version without flags specifying the C library. The problem seems to be that minitar depends on zlib, which depends specifically on libc.lib, not on any of the other C libraries. Unless you compile with libc.lib, you get errors -- specifically, no _errno in the other libraries, which must make it something other than an int. (#### But this doesn't seem to obtain in XEmacs, which also uses zlib, and can be linked with any of the C libraries. Maybe zlib is used differently and doesn't need errno, or maybe XEmacs provides an int errno; ... I don't understand. Makefile.in.in: Fix so that packages are around when testing. abbrev.c, alloc.c, buffer.c, buffer.h, bytecode.c, callint.c, casefiddle.c, casetab.c, casetab.h, charset.h, chartab.c, chartab.h, cmds.c, console-msw.h, console-stream.c, console-x.c, console.c, console.h, data.c, device-msw.c, device.c, device.h, dialog-msw.c, dialog-x.c, dired-msw.c, dired.c, doc.c, doprnt.c, dumper.c, editfns.c, elhash.c, emacs.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, events.h, extents.c, extents.h, faces.c, file-coding.c, file-coding.h, fileio.c, fns.c, font-lock.c, frame-gtk.c, frame-msw.c, frame-x.c, frame.c, frame.h, glade.c, glyphs-gtk.c, glyphs-msw.c, glyphs-msw.h, glyphs-x.c, glyphs.c, glyphs.h, gui-msw.c, gui-x.c, gui.h, gutter.h, hash.h, indent.c, insdel.c, intl-win32.c, intl.c, keymap.c, lisp-disunion.h, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, marker.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, mule-ccl.c, mule-charset.c, mule-coding.c, mule-wnnfns.c, nas.c, objects-msw.c, objects-x.c, opaque.c, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, process.h, profile.c, rangetab.c, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-x.c, redisplay.c, redisplay.h, regex.c, regex.h, scrollbar-msw.c, search.c, select-x.c, specifier.c, specifier.h, symbols.c, symsinit.h, syntax.c, syntax.h, syswindows.h, tests.c, text.c, text.h, tooltalk.c, ui-byhand.c, ui-gtk.c, unicode.c, win32.c, window.c: Another big Ben patch. -- FUNCTIONALITY CHANGES: add partial support for 8-bit-fixed, 16-bit-fixed, and 32-bit-fixed formats. not quite done yet. (in particular, needs functions to actually convert the buffer.) NOTE: lots of changes to regex.c here. also, many new *_fmt() inline funs that take an Internal_Format argument. redo syntax cache code. make the cache per-buffer; keep the cache valid across calls to functions that use it. also keep it valid across insertions/deletions and extent changes, as much as is possible. eliminate the junky regex-reentrancy code by passing in the relevant lisp info to the regex routines as local vars. add general mechanism in extents code for signalling extent changes. fix numerous problems with the case-table implementation; yoshiki never properly transferred many algorithms from old-style to new-style case tables. redo char tables to support a default argument, so that mapping only occurs over changed args. change many chartab functions to accept Lisp_Object instead of Lisp_Char_Table *. comment out the code in font-lock.c by default, because font-lock.el no longer uses it. we should consider eliminating it entirely. Don't output bell as ^G in console-stream when not a TTY. add -mswindows-termination-handle to interface with i.c, so we can properly kill a build. add more error-checking to buffer/string macros. add some additional buffer_or_string_() funs. -- INTERFACE CHANGES AFFECTING MORE CODE: switch the arguments of write_c_string and friends to be consistent with write_fmt_string, which must have printcharfun first. change BI_* macros to BYTE_* for increased clarity; similarly for bi_* local vars. change VOID_TO_LISP to be a one-argument function. eliminate no-longer-needed CVOID_TO_LISP. -- char/string macro changes: rename MAKE_CHAR() to make_emchar() for slightly less confusion with make_char(). (The former generates an Emchar, the latter a Lisp object. Conceivably we should rename make_char() -> wrap_char() and similarly for make_int(), make_float().) Similar changes for other *CHAR* macros -- we now consistently use names with `emchar' whenever we are working with Emchars. Any remaining name with just `char' always refers to a Lisp object. rename macros with XSTRING_* to string_* except for those that reference actual fields in the Lisp_String object, following conventions used elsewhere. rename set_string_{data,length} macros (the only ones to work with a Lisp_String_* instead of a Lisp_Object) to set_lispstringp_* to make the difference clear. try to be consistent about caps vs. lowercase in macro/inline-fun names for chars and such, which wasn't the case before. we now reserve caps either for XFOO_ macros that reference object fields (e.g. XSTRING_DATA) or for things that have non-function semantics, e.g. directly modifying an arg (BREAKUP_EMCHAR) or evaluating an arg (any arg) more than once. otherwise, use lowercase. here is a summary of most of the macros/inline funs changed by all of the above changes: BYTE_*_P -> byte_*_p XSTRING_BYTE -> string_byte set_string_data/length -> set_lispstringp_data/length XSTRING_CHAR_LENGTH -> string_char_length XSTRING_CHAR -> string_emchar INTBYTE_FIRST_BYTE_P -> intbyte_first_byte_p INTBYTE_LEADING_BYTE_P -> intbyte_leading_byte_p charptr_copy_char -> charptr_copy_emchar LEADING_BYTE_* -> leading_byte_* CHAR_* -> EMCHAR_* *_CHAR_* -> *_EMCHAR_* *_CHAR -> *_EMCHAR CHARSET_BY_ -> charset_by_* BYTE_SHIFT_JIS* -> byte_shift_jis* BYTE_BIG5* -> byte_big5* REP_BYTES_BY_FIRST_BYTE -> rep_bytes_by_first_byte char_to_unicode -> emchar_to_unicode valid_char_p -> valid_emchar_p Change intbyte_strcmp -> qxestrcmp_c (duplicated functionality). -- INTERFACE CHANGES AFFECTING LESS CODE: use DECLARE_INLINE_HEADER in various places. remove '#ifdef emacs' from XEmacs-only files. eliminate CHAR_TABLE_VALUE(), which duplicated the functionality of get_char_table(). add BUFFER_TEXT_LOOP to simplify iterations over buffer text. define typedefs for signed and unsigned types of fixed sizes (INT_32_BIT, UINT_32_BIT, etc.). create ALIGN_FOR_TYPE as a higher-level interface onto ALIGN_SIZE; fix code to use it. add charptr_emchar_len to return the text length of the character pointed to by a ptr; use it in place of charcount_to_bytecount(..., 1). add emchar_len to return the text length of a given character. add types Bytexpos and Charxpos to generalize Bytebpos/Bytecount and Charbpos/Charcount, in code (particularly, the extents code and redisplay code) that works with either kind of index. rename redisplay struct params with names such as `charbpos' to e.g. `charpos' when they are e.g. a Charxpos, not a Charbpos. eliminate xxDEFUN in place of DEFUN; no longer necessary with changes awhile back to doc.c. split up big ugly combined list of EXFUNs in lisp.h on a file-by-file basis, since other prototypes are similarly split. rewrite some "*_UNSAFE" macros as inline funs and eliminate the _UNSAFE suffix. move most string code from lisp.h to text.h; the string code and text.h code is now intertwined in such a fashion that they need to be in the same place and partially interleaved. (you can't create forward references for inline funs) automated/lisp-tests.el, automated/symbol-tests.el, automated/test-harness.el: Fix test harness to output FAIL messages to stderr when in batch mode. Fix up some problems in lisp-tests/symbol-tests that were causing spurious failures.
author ben
date Sun, 05 May 2002 11:33:57 +0000
parents a5954632b187
children 804517e16990
comparison
equal deleted inserted replaced
825:eb3bc15a6e0f 826:6728e641994e
22 22
23 /* Synched up with: FSF 19.28. Between FSF 19.28 and 19.30, casetab.c 23 /* Synched up with: FSF 19.28. Between FSF 19.28 and 19.30, casetab.c
24 was rewritten to use junky FSF char tables. Meanwhile I rewrote it 24 was rewritten to use junky FSF char tables. Meanwhile I rewrote it
25 to use more logical char tables. --ben */ 25 to use more logical char tables. --ben */
26 26
27 /* Written by Howard Gayle. See some mythical and not-in-the-Emacs- 27 /* Written by Howard Gayle. */
28 distribution file chartab.c for details. */
29 28
30 /* Modified for Mule by Ben Wing. */ 29 /* Modified for Mule by Ben Wing. */
31 30
32 /* #### Someone (Yoshiki?) wrote the following comment, which I don't 31 /* The four tables in a case table are downcase, upcase, canon, and eqv.
33 understand. 32 Each is a char-table. Their workings are rather non-obvious.
34 33
35 Case tables consist of four char-tables. These are for downcase, 34 (1) `downcase' is the only obvious table: Map a character to its
36 upcase, canonical and equivalent respectively. 35 lowercase equivalent.
37 36
38 The entries are like this: 37 (2) `upcase' does *NOT* map a character to its uppercase equivalent,
39 38 despite its name. Rather, it maps lowercase characters to their
40 downcase: a -> a, A -> a. 39 uppercase equivalent, and uppercase characters to *ANYTHING BUT* their
41 upcase: a -> A, A -> a. (The latter is for NOCASEP.) 40 uppercase equivalent (currently, their lowercase equivalent), and
42 canon: a -> a, A -> a. 41 characters without case to themselves. It is used to determine if a
43 eqv: a -> A, A -> a. 42 character "has no case" (no uppercase or lowercase mapping). #### This
44 */ 43 is way bogus. Just use the obvious implementation of uppercase mapping
44 and of NOCASE_P.
45
46 (3) `canon' maps each character to a "canonical" lowercase, such that if
47 two different uppercase characters map to the same lowercase character,
48 or vice versa, both characters will have the same entry in the canon
49 table.
50
51 (4) `equiv' lists the "equivalence classes" defined by `canon'. Imagine
52 that all characters are divided into groups having the same `canon'
53 entry; these groups are called "equivalence classes" and `equiv' lists
54 them by linking the characters in each equivalence class together in a
55 circular list.
56
57 `canon' is used when doing case-insensitive comparisons. `equiv' is
58 used in the Boyer-Moore search code.
59 */
45 60
46 #include <config.h> 61 #include <config.h>
47 #include "lisp.h" 62 #include "lisp.h"
48 #include "buffer.h" 63 #include "buffer.h"
49 #include "opaque.h" 64 #include "opaque.h"
51 #include "casetab.h" 66 #include "casetab.h"
52 67
53 Lisp_Object Qcase_tablep, Qdowncase, Qupcase; 68 Lisp_Object Qcase_tablep, Qdowncase, Qupcase;
54 Lisp_Object Vstandard_case_table; 69 Lisp_Object Vstandard_case_table;
55 70
56 static void compute_trt_inverse (Lisp_Object trt, Lisp_Object inverse);
57 Lisp_Object case_table_char (Lisp_Object ch, Lisp_Object table); 71 Lisp_Object case_table_char (Lisp_Object ch, Lisp_Object table);
58 72
59 #define STRING256_P(obj) ((STRINGP (obj) && XSTRING_CHAR_LENGTH (obj) == 256)) 73 #define STRING256_P(obj) ((STRINGP (obj) && string_char_length (obj) == 256))
60 74
61 static Lisp_Object 75 static Lisp_Object
62 mark_case_table (Lisp_Object obj) 76 mark_case_table (Lisp_Object obj)
63 { 77 {
64 Lisp_Case_Table *ct = XCASE_TABLE (obj); 78 Lisp_Case_Table *ct = XCASE_TABLE (obj);
73 static void 87 static void
74 print_case_table (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) 88 print_case_table (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
75 { 89 {
76 Lisp_Case_Table *ct = XCASE_TABLE (obj); 90 Lisp_Case_Table *ct = XCASE_TABLE (obj);
77 if (print_readably) 91 if (print_readably)
78 printing_unreadable_object ("#<case-table 0x%x", ct->header.uid); 92 printing_unreadable_object ("#<case-table 0x%x>", ct->header.uid);
79 write_fmt_string (printcharfun, "#<case-table 0x%x>", ct->header.uid); 93 write_fmt_string_lisp
94 (printcharfun, "#<case-table downcase=%s upcase=%s canon=%s eqv=%s ", 4,
95 CASE_TABLE_DOWNCASE (ct), CASE_TABLE_UPCASE (ct),
96 CASE_TABLE_CANON (ct), CASE_TABLE_EQV (ct));
97 write_fmt_string (printcharfun, "0x%x>", ct->header.uid);
80 } 98 }
81 99
82 static const struct lrecord_description case_table_description [] = { 100 static const struct lrecord_description case_table_description [] = {
83 { XD_LISP_OBJECT, offsetof (Lisp_Case_Table, downcase_table) }, 101 { XD_LISP_OBJECT, offsetof (Lisp_Case_Table, downcase_table) },
84 { XD_LISP_OBJECT, offsetof (Lisp_Case_Table, upcase_table) }, 102 { XD_LISP_OBJECT, offsetof (Lisp_Case_Table, upcase_table) },
90 DEFINE_LRECORD_IMPLEMENTATION ("case-table", case_table, 108 DEFINE_LRECORD_IMPLEMENTATION ("case-table", case_table,
91 mark_case_table, print_case_table, 0, 109 mark_case_table, print_case_table, 0,
92 0, 0, case_table_description, Lisp_Case_Table); 110 0, 0, case_table_description, Lisp_Case_Table);
93 111
94 static Lisp_Object 112 static Lisp_Object
95 allocate_case_table (void) 113 allocate_case_table (int init_tables)
96 { 114 {
97 Lisp_Case_Table *ct = 115 Lisp_Case_Table *ct =
98 alloc_lcrecord_type (Lisp_Case_Table, &lrecord_case_table); 116 alloc_lcrecord_type (Lisp_Case_Table, &lrecord_case_table);
99 117
100 SET_CASE_TABLE_DOWNCASE (ct, Qnil); 118 if (init_tables)
101 SET_CASE_TABLE_UPCASE (ct, Qnil); 119 {
102 SET_CASE_TABLE_CANON (ct, Qnil); 120 SET_CASE_TABLE_DOWNCASE (ct, MAKE_TRT_TABLE ());
103 SET_CASE_TABLE_EQV (ct, Qnil); 121 SET_CASE_TABLE_UPCASE (ct, MAKE_TRT_TABLE ());
104 122 SET_CASE_TABLE_CANON (ct, MAKE_TRT_TABLE ());
123 SET_CASE_TABLE_EQV (ct, MAKE_TRT_TABLE ());
124 }
125 else
126 {
127 SET_CASE_TABLE_DOWNCASE (ct, Qnil);
128 SET_CASE_TABLE_UPCASE (ct, Qnil);
129 SET_CASE_TABLE_CANON (ct, Qnil);
130 SET_CASE_TABLE_EQV (ct, Qnil);
131 }
105 return wrap_case_table (ct); 132 return wrap_case_table (ct);
133 }
134
135 DEFUN ("make-case-table", Fmake_case_table, 0, 0, 0, /*
136 Create a new, empty case table.
137 */
138 ())
139 {
140 return allocate_case_table (1);
106 } 141 }
107 142
108 DEFUN ("case-table-p", Fcase_table_p, 1, 1, 0, /* 143 DEFUN ("case-table-p", Fcase_table_p, 1, 1, 0, /*
109 Return t if OBJECT is a case table. 144 Return t if OBJECT is a case table.
110 See `set-case-table' for more information on these data structures. 145 See `set-case-table' for more information on these data structures.
150 185
151 Lisp_Object 186 Lisp_Object
152 case_table_char (Lisp_Object ch, Lisp_Object table) 187 case_table_char (Lisp_Object ch, Lisp_Object table)
153 { 188 {
154 Lisp_Object ct_char; 189 Lisp_Object ct_char;
155 ct_char = get_char_table (XCHAR (ch), XCHAR_TABLE (table)); 190 ct_char = get_char_table (XCHAR (ch), table);
156 if (NILP (ct_char)) 191 if (NILP (ct_char))
157 return ch; 192 return ch;
158 else 193 else
159 return ct_char; 194 return ct_char;
160 } 195 }
161 196
162 DEFUN ("get-case-table", Fget_case_table, 3, 3, 0, /* 197 DEFUN ("get-case-table", Fget_case_table, 3, 3, 0, /*
163 Return CHAR-CASE version of CHARACTER in CASE-TABLE. 198 Return CHAR-CASE version of CHARACTER in CASE-TABLE.
164 199
165 CHAR-CASE is either downcase or upcase. 200 CHAR-CASE is either `downcase' or `upcase'.
166 */ 201 */
167 (char_case, character, case_table)) 202 (char_case, character, case_table))
168 { 203 {
169 CHECK_CHAR (character); 204 CHECK_CHAR (character);
170 CHECK_CASE_TABLE (case_table); 205 CHECK_CASE_TABLE (case_table);
179 } 214 }
180 215
181 DEFUN ("put-case-table", Fput_case_table, 4, 4, 0, /* 216 DEFUN ("put-case-table", Fput_case_table, 4, 4, 0, /*
182 Set CHAR-CASE version of CHARACTER to be VALUE in CASE-TABLE. 217 Set CHAR-CASE version of CHARACTER to be VALUE in CASE-TABLE.
183 218
184 CHAR-CASE is either downcase or upcase. 219 CHAR-CASE is either `downcase' or `upcase'.
185 See also `put-case-table-pair'. 220 See also `put-case-table-pair'.
186 */ 221 */
187 (char_case, character, value, case_table)) 222 (char_case, character, value, case_table))
188 { 223 {
189 CHECK_CHAR (character); 224 CHECK_CHAR (character);
190 CHECK_CHAR (value); 225 CHECK_CHAR (value);
191 226
192 if (EQ (char_case, Qdowncase)) 227 if (EQ (char_case, Qdowncase))
193 { 228 {
194 Fput_char_table (character, value, XCASE_TABLE_DOWNCASE (case_table)); 229 Fput_char_table (character, value, XCASE_TABLE_DOWNCASE (case_table));
195 /* This one is not at all intuitive. */ 230 /* This one is not at all intuitive. See comment at top of file. */
196 Fput_char_table (character, value, XCASE_TABLE_UPCASE (case_table)); 231 Fput_char_table (character, value, XCASE_TABLE_UPCASE (case_table));
197 Fput_char_table (character, value, XCASE_TABLE_CANON (case_table));
198 Fput_char_table (value, value, XCASE_TABLE_CANON (case_table));
199 Fput_char_table (value, character, XCASE_TABLE_EQV (case_table));
200 Fput_char_table (character, value, XCASE_TABLE_EQV (case_table));
201 } 232 }
202 else if (EQ (char_case, Qupcase)) 233 else if (EQ (char_case, Qupcase))
203 { 234 {
204 Fput_char_table (character, value, XCASE_TABLE_UPCASE (case_table)); 235 Fput_char_table (character, value, XCASE_TABLE_UPCASE (case_table));
205 Fput_char_table (character, character, XCASE_TABLE_DOWNCASE (case_table)); 236 Fput_char_table (character, character,
206 Fput_char_table (character, character, XCASE_TABLE_CANON (case_table)); 237 XCASE_TABLE_DOWNCASE (case_table));
207 Fput_char_table (value, character, XCASE_TABLE_CANON (case_table));
208 Fput_char_table (value, character, XCASE_TABLE_EQV (case_table));
209 Fput_char_table (character, value, XCASE_TABLE_EQV (case_table));
210 } 238 }
211 else 239 else
212 invalid_constant ("Char case must be downcase or upcase", char_case); 240 invalid_constant ("CHAR-CASE must be downcase or upcase", char_case);
213 241
242 XCASE_TABLE (case_table)->dirty = 1;
214 return Qnil; 243 return Qnil;
215 } 244 }
216 245
217 DEFUN ("put-case-table-pair", Fput_case_table_pair, 3, 3, 0, /* 246 DEFUN ("put-case-table-pair", Fput_case_table_pair, 3, 3, 0, /*
218 Make UC and LC a pair of inter-case-converting letters in CASE-TABLE. 247 Make UC and LC a pair of inter-case-converting letters in CASE-TABLE.
227 Fput_char_table (lc, lc, XCASE_TABLE_DOWNCASE (case_table)); 256 Fput_char_table (lc, lc, XCASE_TABLE_DOWNCASE (case_table));
228 Fput_char_table (uc, lc, XCASE_TABLE_UPCASE (case_table)); 257 Fput_char_table (uc, lc, XCASE_TABLE_UPCASE (case_table));
229 Fput_char_table (uc, lc, XCASE_TABLE_DOWNCASE (case_table)); 258 Fput_char_table (uc, lc, XCASE_TABLE_DOWNCASE (case_table));
230 Fput_char_table (lc, uc, XCASE_TABLE_UPCASE (case_table)); 259 Fput_char_table (lc, uc, XCASE_TABLE_UPCASE (case_table));
231 260
232 Fput_char_table (lc, lc, XCASE_TABLE_CANON (case_table)); 261 XCASE_TABLE (case_table)->dirty = 1;
233 Fput_char_table (uc, lc, XCASE_TABLE_CANON (case_table));
234 Fput_char_table (uc, lc, XCASE_TABLE_EQV (case_table));
235 Fput_char_table (lc, uc, XCASE_TABLE_EQV (case_table));
236 return Qnil; 262 return Qnil;
237 } 263 }
238 264
239 DEFUN ("copy-case-table", Fcopy_case_table, 1, 1, 0, /* 265 DEFUN ("copy-case-table", Fcopy_case_table, 1, 1, 0, /*
240 Return a new case table which is a copy of CASE-TABLE 266 Return a new case table which is a copy of CASE-TABLE
242 (case_table)) 268 (case_table))
243 { 269 {
244 Lisp_Object new_obj; 270 Lisp_Object new_obj;
245 CHECK_CASE_TABLE (case_table); 271 CHECK_CASE_TABLE (case_table);
246 272
247 new_obj = allocate_case_table (); 273 new_obj = allocate_case_table (0);
248 XSET_CASE_TABLE_DOWNCASE 274 XSET_CASE_TABLE_DOWNCASE
249 (new_obj, Fcopy_char_table (XCASE_TABLE_DOWNCASE (case_table))); 275 (new_obj, Fcopy_char_table (XCASE_TABLE_DOWNCASE (case_table)));
250 XSET_CASE_TABLE_UPCASE 276 XSET_CASE_TABLE_UPCASE
251 (new_obj, Fcopy_char_table (XCASE_TABLE_UPCASE (case_table))); 277 (new_obj, Fcopy_char_table (XCASE_TABLE_UPCASE (case_table)));
252 XSET_CASE_TABLE_CANON 278 XSET_CASE_TABLE_CANON
254 XSET_CASE_TABLE_EQV 280 XSET_CASE_TABLE_EQV
255 (new_obj, Fcopy_char_table (XCASE_TABLE_EQV (case_table))); 281 (new_obj, Fcopy_char_table (XCASE_TABLE_EQV (case_table)));
256 return new_obj; 282 return new_obj;
257 } 283 }
258 284
285 static int
286 compute_canon_mapper (struct chartab_range *range,
287 Lisp_Object table, Lisp_Object val, void *arg)
288 {
289 Lisp_Object casetab = VOID_TO_LISP (arg);
290 if (range->type == CHARTAB_RANGE_CHAR)
291 SET_TRT_TABLE_OF (XCASE_TABLE_CANON (casetab), range->ch,
292 TRT_TABLE_OF (XCASE_TABLE_DOWNCASE (casetab),
293 TRT_TABLE_OF (XCASE_TABLE_UPCASE (casetab),
294 XCHAR (val))));
295
296 return 0;
297 }
298
299 static int
300 initialize_identity_mapper (struct chartab_range *range,
301 Lisp_Object table, Lisp_Object val, void *arg)
302 {
303 Lisp_Object trt = VOID_TO_LISP (arg);
304 if (range->type == CHARTAB_RANGE_CHAR)
305 SET_TRT_TABLE_OF (trt, range->ch, range->ch);
306
307 return 0;
308 }
309
310 static int
311 compute_up_or_eqv_mapper (struct chartab_range *range,
312 Lisp_Object table, Lisp_Object val, void *arg)
313 {
314 Lisp_Object inverse = VOID_TO_LISP (arg);
315 Emchar toch = XCHAR (val);
316
317 if (range->type == CHARTAB_RANGE_CHAR && range->ch != toch)
318 {
319 Emchar c = TRT_TABLE_OF (inverse, toch);
320 SET_TRT_TABLE_OF (inverse, toch, range->ch);
321 SET_TRT_TABLE_OF (inverse, range->ch, c);
322 }
323
324 return 0;
325 }
326
327 /* Recomputing the canonical and equivalency tables from scratch is a
328 lengthy process, and doing them incrementally is extremely difficult or
329 perhaps impossible -- and certainly not worth it. To avoid lots of
330 excessive recomputation when lots of stuff is incrementally added, we
331 just store a dirty flag and then recompute when a value from the canon
332 or eqv tables is actually needed. */
333
334 void
335 recompute_case_table (Lisp_Object casetab)
336 {
337 struct chartab_range range;
338
339 range.type = CHARTAB_RANGE_ALL;
340 /* Turn off dirty flag first so we don't get infinite recursion when
341 retrieving the values below! */
342 XCASE_TABLE (casetab)->dirty = 0;
343 map_char_table (XCASE_TABLE_DOWNCASE (casetab), &range,
344 compute_canon_mapper, LISP_TO_VOID (casetab));
345 map_char_table (XCASE_TABLE_CANON (casetab), &range,
346 initialize_identity_mapper,
347 LISP_TO_VOID (XCASE_TABLE_EQV (casetab)));
348 map_char_table (XCASE_TABLE_CANON (casetab), &range,
349 compute_up_or_eqv_mapper,
350 LISP_TO_VOID (XCASE_TABLE_EQV (casetab)));
351 }
352
259 DEFUN ("current-case-table", Fcurrent_case_table, 0, 1, 0, /* 353 DEFUN ("current-case-table", Fcurrent_case_table, 0, 1, 0, /*
260 Return the case table of BUFFER, which defaults to the current buffer. 354 Return the case table of BUFFER, which defaults to the current buffer.
261 */ 355 */
262 (buffer)) 356 (buffer))
263 { 357 {
273 ()) 367 ())
274 { 368 {
275 return Vstandard_case_table; 369 return Vstandard_case_table;
276 } 370 }
277 371
278 static Lisp_Object set_case_table (Lisp_Object table, int standard); 372 static void
373 convert_old_style_syntax_string (Lisp_Object table, Lisp_Object string)
374 {
375 Emchar i;
376
377 for (i = 0; i < 256; i++)
378 SET_TRT_TABLE_OF (table, i, string_emchar (string, i));
379 }
380
381 static Lisp_Object
382 set_case_table (Lisp_Object table, int standard)
383 {
384 /* This function can GC */
385 struct buffer *buf =
386 standard ? XBUFFER (Vbuffer_defaults) : current_buffer;
387
388 check_case_table (table);
389
390 if (CASE_TABLEP (table))
391 {
392 if (standard)
393 Vstandard_case_table = table;
394
395 buf->case_table = table;
396 }
397 else
398 {
399 /* For backward compatibility. */
400 Lisp_Object down, up, canon, eqv, tail = table;
401 Lisp_Object casetab =
402 standard ? Vstandard_case_table : buf->case_table;
403 struct chartab_range range;
404
405 range.type = CHARTAB_RANGE_ALL;
406
407 Freset_char_table (XCASE_TABLE_DOWNCASE (casetab));
408 Freset_char_table (XCASE_TABLE_UPCASE (casetab));
409 Freset_char_table (XCASE_TABLE_CANON (casetab));
410 Freset_char_table (XCASE_TABLE_EQV (casetab));
411
412 down = XCAR (tail); tail = XCDR (tail);
413 up = XCAR (tail); tail = XCDR (tail);
414 canon = XCAR (tail); tail = XCDR (tail);
415 eqv = XCAR (tail);
416
417 convert_old_style_syntax_string (XCASE_TABLE_DOWNCASE (casetab), down);
418
419 if (NILP (up))
420 {
421 map_char_table (XCASE_TABLE_DOWNCASE (casetab), &range,
422 initialize_identity_mapper,
423 LISP_TO_VOID (XCASE_TABLE_UPCASE (casetab)));
424 map_char_table (XCASE_TABLE_DOWNCASE (casetab), &range,
425 compute_up_or_eqv_mapper,
426 LISP_TO_VOID (XCASE_TABLE_UPCASE (casetab)));
427 }
428 else
429 convert_old_style_syntax_string (XCASE_TABLE_UPCASE (casetab), up);
430
431 if (NILP (canon))
432 map_char_table (XCASE_TABLE_DOWNCASE (casetab), &range,
433 compute_canon_mapper, LISP_TO_VOID (casetab));
434 else
435 convert_old_style_syntax_string (XCASE_TABLE_CANON (casetab), canon);
436
437 if (NILP (eqv))
438 {
439 map_char_table (XCASE_TABLE_CANON (casetab), &range,
440 initialize_identity_mapper,
441 LISP_TO_VOID (XCASE_TABLE_EQV (casetab)));
442 map_char_table (XCASE_TABLE_CANON (casetab), &range,
443 compute_up_or_eqv_mapper,
444 LISP_TO_VOID (XCASE_TABLE_EQV (casetab)));
445 }
446 else
447 convert_old_style_syntax_string (XCASE_TABLE_CANON (casetab), eqv);
448 }
449
450 return buf->case_table;
451 }
279 452
280 DEFUN ("set-case-table", Fset_case_table, 1, 1, 0, /* 453 DEFUN ("set-case-table", Fset_case_table, 1, 1, 0, /*
281 Select CASE-TABLE as the new case table for the current buffer. 454 Select CASE-TABLE as the new case table for the current buffer.
282 A case table is a case-table object or list 455 A case table is a case-table object or list
283 (DOWNCASE UPCASE CANONICALIZE EQUIVALENCES) 456 (DOWNCASE UPCASE CANONICALIZE EQUIVALENCES)
311 { 484 {
312 /* This function can GC */ 485 /* This function can GC */
313 return set_case_table (case_table, 1); 486 return set_case_table (case_table, 1);
314 } 487 }
315 488
316 static Lisp_Object
317 set_case_table (Lisp_Object table, int standard)
318 {
319 /* This function can GC */
320 struct buffer *buf =
321 standard ? XBUFFER(Vbuffer_defaults) : current_buffer;
322
323 check_case_table (table);
324
325 if (CASE_TABLEP (table))
326 {
327 if (standard)
328 Vstandard_case_table = table;
329
330 buf->case_table = table;
331 }
332 else
333 {
334 /* For backward compatibility. */
335 Lisp_Object down, up, canon, eqv, tail = table;
336 Lisp_Object temp;
337 int i;
338
339 down = XCAR (tail); tail = XCDR (tail);
340 up = XCAR (tail); tail = XCDR (tail);
341 canon = XCAR (tail); tail = XCDR (tail);
342 eqv = XCAR (tail);
343
344 temp = down;
345 down = MAKE_TRT_TABLE ();
346 for (i = 0; i < 256; i++)
347 SET_TRT_TABLE_CHAR_1 (down, i, XSTRING_CHAR (temp, i));
348
349 if (NILP (up))
350 {
351 up = MAKE_TRT_TABLE ();
352 compute_trt_inverse (down, up);
353 }
354 else
355 {
356 temp = up;
357 up = MAKE_TRT_TABLE ();
358 for (i = 0; i < 256; i++)
359 SET_TRT_TABLE_CHAR_1 (up, i, XSTRING_CHAR (temp, i));
360 }
361 if (NILP (canon))
362 {
363 canon = MAKE_TRT_TABLE ();
364
365 /* Set up the CANON table; for each character,
366 this sequence of upcasing and downcasing ought to
367 get the "preferred" lowercase equivalent. */
368 for (i = 0; i < 256; i++)
369 SET_TRT_TABLE_CHAR_1 (canon, i,
370 TRT_TABLE_CHAR_1
371 (down,
372 TRT_TABLE_CHAR_1
373 (up,
374 TRT_TABLE_CHAR_1 (down, i))));
375 }
376 else
377 {
378 temp = canon;
379 canon = MAKE_TRT_TABLE ();
380 for (i = 0; i < 256; i++)
381 SET_TRT_TABLE_CHAR_1 (canon, i, XSTRING_CHAR (temp, i));
382 }
383
384 if (NILP (eqv))
385 {
386 eqv = MAKE_TRT_TABLE ();
387 compute_trt_inverse (canon, eqv);
388 }
389 else
390 {
391 temp = eqv;
392 eqv = MAKE_TRT_TABLE ();
393 for (i = 0; i < 256; i++)
394 SET_TRT_TABLE_CHAR_1 (eqv, i, XSTRING_CHAR (temp, i));
395 }
396
397 if (standard)
398 {
399 XSET_CASE_TABLE_DOWNCASE (Vstandard_case_table, down);
400 XSET_CASE_TABLE_UPCASE (Vstandard_case_table, up);
401 XSET_CASE_TABLE_CANON (Vstandard_case_table, canon);
402 XSET_CASE_TABLE_EQV (Vstandard_case_table, eqv);
403 }
404
405 buf->case_table = allocate_case_table ();
406 XSET_CASE_TABLE_DOWNCASE (buf->case_table, down);
407 XSET_CASE_TABLE_UPCASE (buf->case_table, up);
408 XSET_CASE_TABLE_CANON (buf->case_table, canon);
409 XSET_CASE_TABLE_EQV (buf->case_table, eqv);
410 }
411
412 return buf->case_table;
413 }
414
415 /* Given a translate table TRT, store the inverse mapping into INVERSE.
416 Since TRT is not one-to-one, INVERSE is not a simple mapping.
417 Instead, it divides the space of characters into equivalence classes.
418 All characters in a given class form one circular list, chained through
419 the elements of INVERSE. */
420
421 static void
422 compute_trt_inverse (Lisp_Object trt, Lisp_Object inverse)
423 {
424 Charcount i = 0400;
425 Emchar c, q;
426
427 while (--i)
428 SET_TRT_TABLE_CHAR_1 (inverse, i, (Emchar) i);
429 i = 0400;
430 while (--i)
431 {
432 if ((q = TRT_TABLE_CHAR_1 (trt, i)) != (Emchar) i)
433 {
434 c = TRT_TABLE_CHAR_1 (inverse, q);
435 SET_TRT_TABLE_CHAR_1 (inverse, q, (Emchar) i);
436 SET_TRT_TABLE_CHAR_1 (inverse, i, c);
437 }
438 }
439 }
440
441 489
442 void 490 void
443 syms_of_casetab (void) 491 syms_of_casetab (void)
444 { 492 {
445 INIT_LRECORD_IMPLEMENTATION (case_table); 493 INIT_LRECORD_IMPLEMENTATION (case_table);
446 494
447 DEFSYMBOL_MULTIWORD_PREDICATE (Qcase_tablep); 495 DEFSYMBOL_MULTIWORD_PREDICATE (Qcase_tablep);
448 DEFSYMBOL (Qdowncase); 496 DEFSYMBOL (Qdowncase);
449 DEFSYMBOL (Qupcase); 497 DEFSYMBOL (Qupcase);
450 498
499 DEFSUBR (Fmake_case_table);
451 DEFSUBR (Fcase_table_p); 500 DEFSUBR (Fcase_table_p);
452 DEFSUBR (Fget_case_table); 501 DEFSUBR (Fget_case_table);
453 DEFSUBR (Fput_case_table); 502 DEFSUBR (Fput_case_table);
454 DEFSUBR (Fput_case_table_pair); 503 DEFSUBR (Fput_case_table_pair);
455 DEFSUBR (Fcurrent_case_table); 504 DEFSUBR (Fcurrent_case_table);
461 510
462 void 511 void
463 complex_vars_of_casetab (void) 512 complex_vars_of_casetab (void)
464 { 513 {
465 REGISTER Emchar i; 514 REGISTER Emchar i;
466 Lisp_Object tem;
467 515
468 staticpro (&Vstandard_case_table); 516 staticpro (&Vstandard_case_table);
469 517
470 Vstandard_case_table = allocate_case_table (); 518 Vstandard_case_table = allocate_case_table (1);
471 519
472 tem = MAKE_TRT_TABLE ();
473 XSET_CASE_TABLE_DOWNCASE (Vstandard_case_table, tem);
474 XSET_CASE_TABLE_CANON (Vstandard_case_table, tem);
475
476 /* Under Mule, can't do set_string_char() until Vcharset_control_1
477 and Vcharset_ascii are initialized. */
478 for (i = 0; i < 256; i++) 520 for (i = 0; i < 256; i++)
479 { 521 {
480 unsigned char lowered = tolower (i); 522 unsigned char lowered = tolower (i);
481 523
482 SET_TRT_TABLE_CHAR_1 (tem, i, lowered); 524 SET_TRT_TABLE_OF (XCASE_TABLE_DOWNCASE (Vstandard_case_table), i,
483 } 525 lowered);
484 526 }
485 tem = MAKE_TRT_TABLE ();
486 XSET_CASE_TABLE_UPCASE (Vstandard_case_table, tem);
487 XSET_CASE_TABLE_EQV (Vstandard_case_table, tem);
488 527
489 for (i = 0; i < 256; i++) 528 for (i = 0; i < 256; i++)
490 { 529 {
491 unsigned char flipped = (isupper (i) ? tolower (i) 530 unsigned char flipped = (isupper (i) ? tolower (i)
492 : (islower (i) ? toupper (i) : i)); 531 : (islower (i) ? toupper (i) : i));
493 532
494 SET_TRT_TABLE_CHAR_1 (tem, i, flipped); 533 SET_TRT_TABLE_OF (XCASE_TABLE_UPCASE (Vstandard_case_table), i,
495 } 534 flipped);
496 } 535 }
536
537 recompute_case_table (Vstandard_case_table);
538 }