annotate src/casetab.c @ 272:c5d627a313b1 r21-0b34

Import from CVS: tag r21-0b34
author cvs
date Mon, 13 Aug 2007 10:28:48 +0200
parents 677f6a0ee643
children 6330739388db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* XEmacs routines to deal with case tables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1987, 1992, 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: FSF 19.28. Between FSF 19.28 and 19.30, casetab.c
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 185
diff changeset
23 was rewritten to use junky char tables. Meanwhile I rewrote it
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 185
diff changeset
24 to use more logical char tables. Emacs also discards the "list of four
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 tables" format and instead stuffs the other tables as "extra slots"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 in the downcase table. I've kept the four-lists format for now. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 /* Written by Howard Gayle. See some mythical and not-in-the-Emacs-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 distribution file chartab.c for details. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 /* Modified for Mule by Ben Wing. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 /* #### We do not currently deal properly with translating non-ASCII
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (including Latin-1!) characters under Mule. Getting this right is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 *hard*, way fucking hard. So we at least preserve consistency by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 sanitizing all the case tables to remove translations that would
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 get us into trouble and possibly result in inconsistent internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 text, which would likely lead to crashes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #include "opaque.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 Lisp_Object Qcase_table_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 Lisp_Object Vascii_downcase_table, Vascii_upcase_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 Lisp_Object Vascii_canon_table, Vascii_eqv_table;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
48 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
49 Lisp_Object Vmirror_ascii_downcase_table, Vmirror_ascii_upcase_table;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
50 Lisp_Object Vmirror_ascii_canon_table, Vmirror_ascii_eqv_table;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
51 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 Lisp_Object Qtranslate_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 static void compute_trt_inverse (Lisp_Object trt, Lisp_Object inverse);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
56 #define STRING256_P(obj) (STRINGP (obj) && XSTRING_CHAR_LENGTH (obj) == 256)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
58 DEFUN ("case-table-p", Fcase_table_p, 1, 1, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
59 Return t if ARG is a case table.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 See `set-case-table' for more information on these data structures.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
61 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
62 (table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 Lisp_Object down, up, canon, eqv;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
65 if (!CONSP (table)) return Qnil; down = XCAR (table); table = XCDR (table);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
66 if (!CONSP (table)) return Qnil; up = XCAR (table); table = XCDR (table);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
67 if (!CONSP (table)) return Qnil; canon = XCAR (table); table = XCDR (table);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
68 if (!CONSP (table)) return Qnil; eqv = XCAR (table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 return (STRING256_P (down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 && (NILP (up) || STRING256_P (up))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 && ((NILP (canon) && NILP (eqv))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 || (STRING256_P (canon)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 && (NILP (eqv) || STRING256_P (eqv))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ? Qt : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 check_case_table (Lisp_Object obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 REGISTER Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 while (tem = Fcase_table_p (obj), NILP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 obj = wrong_type_argument (Qcase_table_p, obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 return (obj);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
86 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
88 DEFUN ("current-case-table", Fcurrent_case_table, 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 Return the case table of BUFFER, which defaults to the current buffer.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
90 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
91 (buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 struct buffer *buf = decode_buffer (buffer, 0);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
94
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
95 return list4 (buf->downcase_table,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
96 buf->upcase_table,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
97 buf->case_canon_table,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
98 buf->case_eqv_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
101 DEFUN ("standard-case-table", Fstandard_case_table, 0, 0, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 Return the standard case table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 This is the one used for new buffers.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
104 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
105 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
107 return list4 (Vascii_downcase_table,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
108 Vascii_upcase_table,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
109 Vascii_canon_table,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
110 Vascii_eqv_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 static Lisp_Object set_case_table (Lisp_Object table, int standard);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
116 DEFUN ("set-case-table", Fset_case_table, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 Select a new case table for the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 A case table is a list (DOWNCASE UPCASE CANONICALIZE EQUIVALENCES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 where each element is either nil or a string of length 256.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 DOWNCASE maps each character to its lower-case equivalent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 UPCASE maps each character to its upper-case equivalent;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 if lower and upper case characters are in 1-1 correspondence,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 you may use nil and the upcase table will be deduced from DOWNCASE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 CANONICALIZE maps each character to a canonical equivalent;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 any two characters that are related by case-conversion have the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 canonical equivalent character; it may be nil, in which case it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 deduced from DOWNCASE and UPCASE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 EQUIVALENCES is a map that cyclicly permutes each equivalence class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (of characters with the same canonical equivalent); it may be nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 in which case it is deduced from CANONICALIZE.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
131
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
132 BUG: Under XEmacs/Mule, translations to or from non-ASCII characters
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
133 (this includes chars in the range 128 - 255) are ignored by
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
134 the string/buffer-searching routines. Thus, `case-fold-search'
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
135 will not correctly conflate a-umlaut and A-umlaut even if the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
136 case tables call for this.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
137 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
138 (table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 return set_case_table (table, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
143 DEFUN ("set-standard-case-table", Fset_standard_case_table, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 Select a new standard case table for new buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 See `set-case-table' for more info on case tables.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
146 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
147 (table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 return set_case_table (table, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
152 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
153
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
154 static Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
155 make_mirror_trt_table (Lisp_Object table)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
156 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
157 Lisp_Object new_table;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
158
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
159 if (!STRING256_P (table))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
160 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
161 #ifdef DEBUG_XEMACS
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
162 /* This should be caught farther up. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
163 abort ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
164 #else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
165 signal_simple_error ("Invalid translate table", table);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
166 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
167 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
168
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
169 new_table = MAKE_MIRROR_TRT_TABLE ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
170 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
171 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
172
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
173 for (i = 0; i < 256; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
174 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
175 Emchar newval = string_char (XSTRING (table), i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
176 if ((i >= 128 && newval != i)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
177 || (i < 128 && newval >= 128))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
178 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
179 newval = (Emchar) i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
180 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
181 SET_MIRROR_TRT_TABLE_CHAR_1 (new_table, i, newval);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
182 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
183 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
184 return new_table;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
185 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
186
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
187 #endif /* MULE */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
188
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 set_case_table (Lisp_Object table, int standard)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
192 Lisp_Object down, up, canon, eqv, tail = table;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 struct buffer *buf = current_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 check_case_table (table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
197 down = XCAR (tail); tail = XCDR (tail);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
198 up = XCAR (tail); tail = XCDR (tail);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
199 canon = XCAR (tail); tail = XCDR (tail);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
200 eqv = XCAR (tail);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 if (NILP (up))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 up = MAKE_TRT_TABLE ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 compute_trt_inverse (down, up);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 if (NILP (canon))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 REGISTER Charcount i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 canon = MAKE_TRT_TABLE ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 /* Set up the CANON vector; for each character,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 this sequence of upcasing and downcasing ought to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 get the "preferred" lowercase equivalent. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 for (i = 0; i < 256; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 SET_TRT_TABLE_CHAR_1 (canon, i,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 TRT_TABLE_CHAR_1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (down,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 TRT_TABLE_CHAR_1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (up,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 TRT_TABLE_CHAR_1 (down, i))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 if (NILP (eqv))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 eqv = MAKE_TRT_TABLE ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 compute_trt_inverse (canon, eqv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 if (standard)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 Vascii_downcase_table = down;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 Vascii_upcase_table = up;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 Vascii_canon_table = canon;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 Vascii_eqv_table = eqv;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
239 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
240 Vmirror_ascii_downcase_table = make_mirror_trt_table (down);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
241 Vmirror_ascii_upcase_table = make_mirror_trt_table (up);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
242 Vmirror_ascii_canon_table = make_mirror_trt_table (canon);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
243 Vmirror_ascii_eqv_table = make_mirror_trt_table (eqv);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
244 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 buf->downcase_table = down;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 buf->upcase_table = up;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 buf->case_canon_table = canon;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 buf->case_eqv_table = eqv;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
252 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
253 buf->mirror_downcase_table = make_mirror_trt_table (down);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
254 buf->mirror_upcase_table = make_mirror_trt_table (up);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
255 buf->mirror_case_canon_table = make_mirror_trt_table (canon);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
256 buf->mirror_case_eqv_table = make_mirror_trt_table (eqv);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
257 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 return table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 /* Given a translate table TRT, store the inverse mapping into INVERSE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 Since TRT is not one-to-one, INVERSE is not a simple mapping.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 Instead, it divides the space of characters into equivalence classes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 All characters in a given class form one circular list, chained through
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 the elements of INVERSE. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 compute_trt_inverse (Lisp_Object trt, Lisp_Object inverse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 Charcount i = 0400;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 Emchar c, q;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 while (--i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 SET_TRT_TABLE_CHAR_1 (inverse, i, (Emchar) i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 i = 0400;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 while (--i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 if ((q = TRT_TABLE_CHAR_1 (trt, i)) != (Emchar) i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 c = TRT_TABLE_CHAR_1 (inverse, q);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 SET_TRT_TABLE_CHAR_1 (inverse, q, (Emchar) i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 SET_TRT_TABLE_CHAR_1 (inverse, i, c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 syms_of_casetab (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 defsymbol (&Qcase_table_p, "case-table-p");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 defsymbol (&Qtranslate_table, "translate-table");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
295 DEFSUBR (Fcase_table_p);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
296 DEFSUBR (Fcurrent_case_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
297 DEFSUBR (Fstandard_case_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
298 DEFSUBR (Fset_case_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
299 DEFSUBR (Fset_standard_case_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 complex_vars_of_casetab (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 REGISTER Emchar i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 staticpro (&Vascii_downcase_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 staticpro (&Vascii_upcase_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 staticpro (&Vascii_canon_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 staticpro (&Vascii_eqv_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 tem = MAKE_TRT_TABLE ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 Vascii_downcase_table = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 Vascii_canon_table = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 /* Under Mule, can't do set_string_char() until Vcharset_control_1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 and Vcharset_ascii are initialized. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 for (i = 0; i < 256; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 unsigned char lowered = tolower (i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 SET_TRT_TABLE_CHAR_1 (tem, i, lowered);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
325
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
326 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
327 tem = make_mirror_trt_table (tem);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
328 Vmirror_ascii_downcase_table = tem;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
329 Vmirror_ascii_canon_table = tem;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
330 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 tem = MAKE_TRT_TABLE ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 Vascii_upcase_table = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 Vascii_eqv_table = tem;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
335
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 for (i = 0; i < 256; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 unsigned char flipped = (isupper (i) ? tolower (i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 : (islower (i) ? toupper (i) : i));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 SET_TRT_TABLE_CHAR_1 (tem, i, flipped);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
344 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
345 tem = make_mirror_trt_table (tem);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
346 Vmirror_ascii_upcase_table = tem;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
347 Vmirror_ascii_eqv_table = tem;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
348 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 }