annotate src/casetab.c @ 0:376386a54a3c r19-14

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