annotate src/casetab.c @ 54:05472e90ae02 r19-16-pre2

Import from CVS: tag r19-16-pre2
author cvs
date Mon, 13 Aug 2007 08:57:55 +0200
parents 859a2309aef8
children 131b0175ea99
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 was rewritten to use junky RMS char tables. Meanwhile I rewrote it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 to use more logical char tables. RMS also discards the "list of four
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;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 Lisp_Object Qtranslate_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 static void compute_trt_inverse (Lisp_Object trt, Lisp_Object inverse);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 #define STRING256_P(obj) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (STRINGP (obj) && string_char_length (XSTRING (obj)) == 256)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
55 DEFUN ("case-table-p", Fcase_table_p, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 Return t iff ARG is a case table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 See `set-case-table' for more information on these data structures.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
58 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
59 (table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 Lisp_Object down, up, canon, eqv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 down = Fcar_safe (table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 up = Fcar_safe (Fcdr_safe (table));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 canon = Fcar_safe (Fcdr_safe (Fcdr_safe (table)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 eqv = Fcar_safe (Fcdr_safe (Fcdr_safe (Fcdr_safe (table))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 return (STRING256_P (down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 && (NILP (up) || STRING256_P (up))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 && ((NILP (canon) && NILP (eqv))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 || (STRING256_P (canon)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 && (NILP (eqv) || STRING256_P (eqv))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ? Qt : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 check_case_table (Lisp_Object obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 REGISTER Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 while (tem = Fcase_table_p (obj), NILP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 obj = wrong_type_argument (Qcase_table_p, obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 return (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
85 DEFUN ("current-case-table", Fcurrent_case_table, 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 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
87 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
88 (buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 Lisp_Object down, up, canon, eqv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 struct buffer *buf = decode_buffer (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 down = buf->downcase_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 up = buf->upcase_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 canon = buf->case_canon_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 eqv = buf->case_eqv_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 return Fcons (down, Fcons (up, Fcons (canon, Fcons (eqv, Qnil))));
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 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 return Fcons (Vascii_downcase_table,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 Fcons (Vascii_upcase_table,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 Fcons (Vascii_canon_table,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 Fcons (Vascii_eqv_table,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 Qnil))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 static Lisp_Object set_case_table (Lisp_Object table, int standard);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
117 DEFUN ("set-case-table", Fset_case_table, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 Select a new case table for the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 A case table is a list (DOWNCASE UPCASE CANONICALIZE EQUIVALENCES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 where each element is either nil or a string of length 256.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 DOWNCASE maps each character to its lower-case equivalent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 UPCASE maps each character to its upper-case equivalent;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 if lower and upper case characters are in 1-1 correspondence,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 you may use nil and the upcase table will be deduced from DOWNCASE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 CANONICALIZE maps each character to a canonical equivalent;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 any two characters that are related by case-conversion have the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 canonical equivalent character; it may be nil, in which case it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 deduced from DOWNCASE and UPCASE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 EQUIVALENCES is a map that cyclicly permutes each equivalence class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (of characters with the same canonical equivalent); it may be nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 in which case it is deduced from CANONICALIZE.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
132 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
133 (table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 return set_case_table (table, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
138 DEFUN ("set-standard-case-table", Fset_standard_case_table, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 Select a new standard case table for new buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 See `set-case-table' for more info on case tables.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
141 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
142 (table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 return set_case_table (table, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 set_case_table (Lisp_Object table, int standard)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 Lisp_Object down, up, canon, eqv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 struct buffer *buf = current_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 check_case_table (table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 down = Fcar_safe (table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 up = Fcar_safe (Fcdr_safe (table));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 canon = Fcar_safe (Fcdr_safe (Fcdr_safe (table)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 eqv = Fcar_safe (Fcdr_safe (Fcdr_safe (Fcdr_safe (table))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 if (NILP (up))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 up = MAKE_TRT_TABLE ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 compute_trt_inverse (down, up);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 if (NILP (canon))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 REGISTER Charcount i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 canon = MAKE_TRT_TABLE ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 /* Set up the CANON vector; for each character,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 this sequence of upcasing and downcasing ought to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 get the "preferred" lowercase equivalent. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 for (i = 0; i < 256; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 SET_TRT_TABLE_CHAR_1 (canon, i,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 TRT_TABLE_CHAR_1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (down,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 TRT_TABLE_CHAR_1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (up,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 TRT_TABLE_CHAR_1 (down, i))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 if (NILP (eqv))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 eqv = MAKE_TRT_TABLE ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 compute_trt_inverse (canon, eqv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 if (standard)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 Vascii_downcase_table = down;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 Vascii_upcase_table = up;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 Vascii_canon_table = canon;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 Vascii_eqv_table = eqv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 buf->downcase_table = down;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 buf->upcase_table = up;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 buf->case_canon_table = canon;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 buf->case_eqv_table = eqv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 return table;
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 /* Given a translate table TRT, store the inverse mapping into INVERSE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 Since TRT is not one-to-one, INVERSE is not a simple mapping.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 Instead, it divides the space of characters into equivalence classes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 All characters in a given class form one circular list, chained through
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 the elements of INVERSE. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 compute_trt_inverse (Lisp_Object trt, Lisp_Object inverse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 Charcount i = 0400;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 Emchar c, q;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 while (--i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 SET_TRT_TABLE_CHAR_1 (inverse, i, (Emchar) i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 i = 0400;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 while (--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 if ((q = TRT_TABLE_CHAR_1 (trt, i)) != (Emchar) i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 c = TRT_TABLE_CHAR_1 (inverse, q);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 SET_TRT_TABLE_CHAR_1 (inverse, q, (Emchar) i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 SET_TRT_TABLE_CHAR_1 (inverse, i, c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 }
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 syms_of_casetab (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 defsymbol (&Qcase_table_p, "case-table-p");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 defsymbol (&Qtranslate_table, "translate-table");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
241 DEFSUBR (Fcase_table_p);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
242 DEFSUBR (Fcurrent_case_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
243 DEFSUBR (Fstandard_case_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
244 DEFSUBR (Fset_case_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
245 DEFSUBR (Fset_standard_case_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 complex_vars_of_casetab (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 REGISTER Emchar i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 staticpro (&Vascii_downcase_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 staticpro (&Vascii_upcase_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 staticpro (&Vascii_canon_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 staticpro (&Vascii_eqv_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 tem = MAKE_TRT_TABLE ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 Vascii_downcase_table = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 Vascii_canon_table = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 /* Under Mule, can't do set_string_char() until Vcharset_control_1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 and Vcharset_ascii are initialized. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 for (i = 0; i < 256; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 unsigned char lowered = tolower (i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 SET_TRT_TABLE_CHAR_1 (tem, i, lowered);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 tem = MAKE_TRT_TABLE ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 Vascii_upcase_table = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 Vascii_eqv_table = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 for (i = 0; i < 256; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 unsigned char flipped = (isupper (i) ? tolower (i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 : (islower (i) ? toupper (i) : 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 SET_TRT_TABLE_CHAR_1 (tem, i, flipped);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 }