Mercurial > emacs
comparison src/casetab.c @ 88357:1cf6a8acec39
Include "character.h" instead of "charset.h".
(set_canon, set_identity, shuffle): Adjusted for the new
map_char_table spec.
(init_casetab_once): Call CHAR_TABLE_SET instead of directly
accessing the char table structure.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 01 Mar 2002 01:11:39 +0000 |
parents | 6b389fb978bc |
children | 5a64797b3ca1 |
comparison
equal
deleted
inserted
replaced
88356:5ace79aaf5ad | 88357:1cf6a8acec39 |
---|---|
21 /* Written by Howard Gayle. See chartab.c for details. */ | 21 /* Written by Howard Gayle. See chartab.c for details. */ |
22 | 22 |
23 #include <config.h> | 23 #include <config.h> |
24 #include "lisp.h" | 24 #include "lisp.h" |
25 #include "buffer.h" | 25 #include "buffer.h" |
26 #include "charset.h" | 26 #include "character.h" |
27 | 27 |
28 Lisp_Object Qcase_table_p, Qcase_table; | 28 Lisp_Object Qcase_table_p, Qcase_table; |
29 Lisp_Object Vascii_downcase_table, Vascii_upcase_table; | 29 Lisp_Object Vascii_downcase_table, Vascii_upcase_table; |
30 Lisp_Object Vascii_canon_table, Vascii_eqv_table; | 30 Lisp_Object Vascii_canon_table, Vascii_eqv_table; |
31 | 31 |
176 /* Set CANON char-table element for C to a translated ELT by UP and | 176 /* Set CANON char-table element for C to a translated ELT by UP and |
177 DOWN char-tables. This is done only when ELT is a character. The | 177 DOWN char-tables. This is done only when ELT is a character. The |
178 char-tables CANON, UP, and DOWN are in CASE_TABLE. */ | 178 char-tables CANON, UP, and DOWN are in CASE_TABLE. */ |
179 | 179 |
180 static void | 180 static void |
181 set_canon (case_table, c, elt) | 181 set_canon (case_table, range, elt) |
182 Lisp_Object case_table, c, elt; | 182 Lisp_Object case_table, range, elt; |
183 { | 183 { |
184 Lisp_Object up = XCHAR_TABLE (case_table)->extras[0]; | 184 Lisp_Object up = XCHAR_TABLE (case_table)->extras[0]; |
185 Lisp_Object canon = XCHAR_TABLE (case_table)->extras[1]; | 185 Lisp_Object canon = XCHAR_TABLE (case_table)->extras[1]; |
186 int from, to; | |
186 | 187 |
187 if (NATNUMP (elt)) | 188 if (NATNUMP (elt)) |
188 Faset (canon, c, Faref (case_table, Faref (up, elt))); | 189 { |
189 } | 190 if (CONSP (range)) |
190 | 191 { |
191 /* Set elements of char-table TABLE for C to C itself. This is done | 192 from = XINT (XCAR (range)); |
192 only when ELT is a character. This is called in map_char_table. */ | 193 to = XINT (XCDR (range)); |
194 } | |
195 else | |
196 from = to = XINT (range); | |
197 | |
198 for (; from <= to; from++) | |
199 { | |
200 Lisp_Object val1, val2; | |
201 | |
202 val1 = Faref (up, elt); | |
203 if (EQ (val1, Qt)) | |
204 val1 = elt; | |
205 else if (! NATNUMP (val1)) | |
206 continue; | |
207 val2 = Faref (case_table, val1); | |
208 if (EQ (val2, Qt)) | |
209 val2 = val1; | |
210 else if (! NATNUMP (val2)) | |
211 continue; | |
212 Faset (canon, make_number (from), val2); | |
213 } | |
214 } | |
215 } | |
216 | |
217 /* Set elements of char-table TABLE for characters in RANGE to | |
218 themselves. This is done only when ELT is a character. This is | |
219 called in map_char_table. */ | |
193 | 220 |
194 static void | 221 static void |
195 set_identity (table, c, elt) | 222 set_identity (table, range, elt) |
196 Lisp_Object table, c, elt; | 223 Lisp_Object table, range, elt; |
197 { | 224 { |
198 if (NATNUMP (elt)) | 225 if (EQ (elt, Qt) || NATNUMP (elt)) |
199 Faset (table, c, c); | 226 Fset_char_table_range (table, range, Qt); |
200 } | 227 } |
201 | 228 |
202 /* Permute the elements of TABLE (which is initially an identity | 229 /* Permute the elements of TABLE (which is initially an identity |
203 mapping) so that it has one cycle for each equivalence class | 230 mapping) so that it has one cycle for each equivalence class |
204 induced by the translation table on which map_char_table is | 231 induced by the translation table on which map_char_table is |
205 operated. */ | 232 operated. */ |
206 | 233 |
207 static void | 234 static void |
208 shuffle (table, c, elt) | 235 shuffle (table, range, elt) |
209 Lisp_Object table, c, elt; | 236 Lisp_Object table, range, elt; |
210 { | 237 { |
211 if (NATNUMP (elt) && !EQ (c, elt)) | 238 int from, to; |
212 { | 239 |
213 Lisp_Object tem = Faref (table, elt); | 240 if (NATNUMP (elt)) |
214 Faset (table, elt, c); | 241 { |
215 Faset (table, c, tem); | 242 Lisp_Object tem; |
243 | |
244 if (CONSP (range)) | |
245 { | |
246 from = XINT (XCAR (range)); | |
247 to = XINT (XCDR (range)); | |
248 } | |
249 else | |
250 from = to = XINT (range); | |
251 | |
252 for (; from <= to; from++) | |
253 if (from != XINT (elt)) | |
254 { | |
255 tem = Faref (table, elt); | |
256 if (EQ (tem, Qt)) | |
257 tem = elt; | |
258 Faset (table, elt, make_number (from)); | |
259 Faset (table, make_number (from), tem); | |
260 } | |
216 } | 261 } |
217 } | 262 } |
218 | 263 |
219 void | 264 void |
220 init_casetab_once () | 265 init_casetab_once () |
235 | 280 |
236 down = Fmake_char_table (Qcase_table, Qnil); | 281 down = Fmake_char_table (Qcase_table, Qnil); |
237 Vascii_downcase_table = down; | 282 Vascii_downcase_table = down; |
238 XCHAR_TABLE (down)->purpose = Qcase_table; | 283 XCHAR_TABLE (down)->purpose = Qcase_table; |
239 | 284 |
240 for (i = 0; i < CHAR_TABLE_SINGLE_BYTE_SLOTS; i++) | 285 for (i = 0; i < 128; i++) |
241 XSETFASTINT (XCHAR_TABLE (down)->contents[i], | 286 CHAR_TABLE_SET (down, i, (i >= 'A' && i <= 'Z') ? i + ('a' - 'A') : i); |
242 (i >= 'A' && i <= 'Z') ? i + ('a' - 'A') : i); | |
243 | 287 |
244 XCHAR_TABLE (down)->extras[1] = Fcopy_sequence (down); | 288 XCHAR_TABLE (down)->extras[1] = Fcopy_sequence (down); |
245 | 289 |
246 up = Fmake_char_table (Qcase_table, Qnil); | 290 up = Fmake_char_table (Qcase_table, Qnil); |
247 XCHAR_TABLE (down)->extras[0] = up; | 291 XCHAR_TABLE (down)->extras[0] = up; |
248 | 292 |
249 for (i = 0; i < CHAR_TABLE_SINGLE_BYTE_SLOTS; i++) | 293 for (i = 0; i < 128; i++) |
250 XSETFASTINT (XCHAR_TABLE (up)->contents[i], | 294 CHAR_TABLE_SET (up, i, ((i >= 'A' && i <= 'Z') |
251 ((i >= 'A' && i <= 'Z') | 295 ? i + ('a' - 'A') |
252 ? i + ('a' - 'A') | 296 : ((i >= 'a' && i <= 'z') |
253 : ((i >= 'a' && i <= 'z') | 297 ? i + ('A' - 'a') |
254 ? i + ('A' - 'a') | 298 : i))); |
255 : i))); | |
256 | 299 |
257 XCHAR_TABLE (down)->extras[2] = Fcopy_sequence (up); | 300 XCHAR_TABLE (down)->extras[2] = Fcopy_sequence (up); |
258 } | 301 } |
259 | 302 |
260 void | 303 void |