annotate src/casetab.c @ 771:943eaba38521

[xemacs-hg @ 2002-03-13 08:51:24 by ben] The big ben-mule-21-5 check-in! Various files were added and deleted. See CHANGES-ben-mule. There are still some test suite failures. No crashes, though. Many of the failures have to do with problems in the test suite itself rather than in the actual code. I'll be addressing these in the next day or so -- none of the test suite failures are at all critical. Meanwhile I'll be trying to address the biggest issues -- i.e. build or run failures, which will almost certainly happen on various platforms. All comments should be sent to ben@xemacs.org -- use a Cc: if necessary when sending to mailing lists. There will be pre- and post- tags, something like pre-ben-mule-21-5-merge-in, and post-ben-mule-21-5-merge-in.
author ben
date Wed, 13 Mar 2002 08:54:06 +0000
parents 183866b06e0b
children e38acbeb1cae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* XEmacs routines to deal with case tables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1987, 1992, 1993, 1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
22 /* Synched up with: FSF 19.28. Between FSF 19.28 and 19.30, casetab.c
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 was rewritten to use junky FSF char tables. Meanwhile I rewrote it
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
24 to use more logical char tables. --ben */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 /* Written by Howard Gayle. See some mythical and not-in-the-Emacs-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 distribution file chartab.c for details. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 /* Modified for Mule by Ben Wing. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
31 /* #### Someone (Yoshiki?) wrote the following comment, which I don't
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
32 understand.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
33
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
34 Case tables consist of four char-tables. These are for downcase,
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
35 upcase, canonical and equivalent respectively.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
36
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
37 The entries are like this:
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
38
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
39 downcase: a -> a, A -> a.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
40 upcase: a -> A, A -> a. (The latter is for NOCASEP.)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
41 canon: a -> a, A -> a.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
42 eqv: a -> A, A -> a.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
43 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 #include "opaque.h"
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
49 #include "chartab.h"
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
50 #include "casetab.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
52 Lisp_Object Qcase_tablep, Qdowncase, Qupcase;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
53 Lisp_Object Vstandard_case_table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 static void compute_trt_inverse (Lisp_Object trt, Lisp_Object inverse);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
56 Lisp_Object case_table_char (Lisp_Object ch, Lisp_Object table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
58 #define STRING256_P(obj) ((STRINGP (obj) && XSTRING_CHAR_LENGTH (obj) == 256))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
59
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
60 static Lisp_Object
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
61 mark_case_table (Lisp_Object obj)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
62 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
63 Lisp_Case_Table *ct = XCASE_TABLE (obj);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
64
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
65 mark_object (CASE_TABLE_DOWNCASE (ct));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
66 mark_object (CASE_TABLE_UPCASE (ct));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
67 mark_object (CASE_TABLE_CANON (ct));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
68 mark_object (CASE_TABLE_EQV (ct));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
69 return Qnil;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
70 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
71
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
72 static void
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
73 print_case_table (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
74 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
75 Lisp_Case_Table *ct = XCASE_TABLE (obj);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
76 char buf[200];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
77 if (print_readably)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
78 printing_unreadable_object ("#<case-table 0x%x", ct->header.uid);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
79 write_c_string ("#<case-table ", printcharfun);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
80 sprintf (buf, "0x%x>", ct->header.uid);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
81 write_c_string (buf, printcharfun);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
82 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
83
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
84 static const struct lrecord_description case_table_description [] = {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
85 { XD_LISP_OBJECT, offsetof (Lisp_Case_Table, downcase_table) },
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
86 { XD_LISP_OBJECT, offsetof (Lisp_Case_Table, upcase_table) },
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
87 { XD_LISP_OBJECT, offsetof (Lisp_Case_Table, case_canon_table) },
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
88 { XD_LISP_OBJECT, offsetof (Lisp_Case_Table, case_eqv_table) },
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
89 { XD_END }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
90 };
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
91
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
92 DEFINE_LRECORD_IMPLEMENTATION ("case-table", case_table,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
93 mark_case_table, print_case_table, 0,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
94 0, 0, case_table_description, Lisp_Case_Table);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
95
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
96 static Lisp_Object
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
97 allocate_case_table (void)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
98 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
99 Lisp_Object val;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
100 Lisp_Case_Table *ct =
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
101 alloc_lcrecord_type (Lisp_Case_Table, &lrecord_case_table);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
102
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
103 SET_CASE_TABLE_DOWNCASE (ct, Qnil);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
104 SET_CASE_TABLE_UPCASE (ct, Qnil);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
105 SET_CASE_TABLE_CANON (ct, Qnil);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
106 SET_CASE_TABLE_EQV (ct, Qnil);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
107
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
108 XSETCASE_TABLE (val, ct);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
109 return val;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
110 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 DEFUN ("case-table-p", Fcase_table_p, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
113 Return t if OBJECT is a case table.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 See `set-case-table' for more information on these data structures.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
116 (object))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
118 if (CASE_TABLEP (object))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
119 return Qt;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
120 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
121 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
122 Lisp_Object down, up, canon, eqv;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
123 if (!CONSP (object))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
124 return Qnil;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
125 down = XCAR (object); object = XCDR (object);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
126 if (!CONSP (object))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
127 return Qnil;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
128 up = XCAR (object); object = XCDR (object);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
129 if (!CONSP (object))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
130 return Qnil;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
131 canon = XCAR (object); object = XCDR (object);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
132 if (!CONSP (object))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
133 return Qnil;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
134 eqv = XCAR (object);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
136 return ((STRING256_P (down)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
137 && (NILP (up) || STRING256_P (up))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
138 && ((NILP (canon) && NILP (eqv))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
139 || STRING256_P (canon))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
140 && (NILP (eqv) || STRING256_P (eqv)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
141 ? Qt : Qnil);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
142
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
143 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 static Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
147 check_case_table (Lisp_Object object)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
149 /* This function can GC */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
150 while (NILP (Fcase_table_p (object)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
151 object = wrong_type_argument (Qcase_tablep, object);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
152 return object;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
155 Lisp_Object
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
156 case_table_char (Lisp_Object ch, Lisp_Object table)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
157 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
158 Lisp_Object ct_char;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
159 ct_char = get_char_table (XCHAR (ch), XCHAR_TABLE (table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
160 if (NILP (ct_char))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
161 return ch;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
162 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
163 return ct_char;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
164 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
165
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
166 DEFUN ("get-case-table", Fget_case_table, 3, 3, 0, /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
167 Return CHAR-CASE version of CHARACTER in CASE-TABLE.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
168
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
169 CHAR-CASE is either downcase or upcase.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
170 */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
171 (char_case, character, case_table))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
172 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
173 CHECK_CHAR (character);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
174 CHECK_CASE_TABLE (case_table);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
175 if (EQ (char_case, Qdowncase))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
176 return case_table_char (character, XCASE_TABLE_DOWNCASE (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
177 else if (EQ (char_case, Qupcase))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
178 return case_table_char (character, XCASE_TABLE_UPCASE (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
179 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
180 invalid_constant ("Char case must be downcase or upcase", char_case);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
181
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
182 return Qnil; /* Not reached. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
183 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
184
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
185 DEFUN ("put-case-table", Fput_case_table, 4, 4, 0, /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
186 Set CHAR-CASE version of CHARACTER to be VALUE in CASE-TABLE.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
187
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
188 CHAR-CASE is either downcase or upcase.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
189 See also `put-case-table-pair'.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
190 */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
191 (char_case, character, value, case_table))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
192 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
193 CHECK_CHAR (character);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
194 CHECK_CHAR (value);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
195
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
196 if (EQ (char_case, Qdowncase))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
197 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
198 Fput_char_table (character, value, XCASE_TABLE_DOWNCASE (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
199 /* This one is not at all intuitive. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
200 Fput_char_table (character, value, XCASE_TABLE_UPCASE (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
201 Fput_char_table (character, value, XCASE_TABLE_CANON (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
202 Fput_char_table (value, value, XCASE_TABLE_CANON (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
203 Fput_char_table (value, character, XCASE_TABLE_EQV (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
204 Fput_char_table (character, value, XCASE_TABLE_EQV (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
205 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
206 else if (EQ (char_case, Qupcase))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
207 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
208 Fput_char_table (character, value, XCASE_TABLE_UPCASE (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
209 Fput_char_table (character, character, XCASE_TABLE_DOWNCASE (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
210 Fput_char_table (character, character, XCASE_TABLE_CANON (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
211 Fput_char_table (value, character, XCASE_TABLE_CANON (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
212 Fput_char_table (value, character, XCASE_TABLE_EQV (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
213 Fput_char_table (character, value, XCASE_TABLE_EQV (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
214 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
215 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
216 invalid_constant ("Char case must be downcase or upcase", char_case);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
217
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
218 return Qnil;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
219 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
220
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
221 DEFUN ("put-case-table-pair", Fput_case_table_pair, 3, 3, 0, /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
222 Make UC and LC a pair of inter-case-converting letters in CASE-TABLE.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
223 UC is an uppercase character and LC is a downcase character.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
224 */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
225 (uc, lc, case_table))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
226 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
227 CHECK_CHAR (uc);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
228 CHECK_CHAR (lc);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
229 CHECK_CASE_TABLE (case_table);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
230
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
231 Fput_char_table (lc, lc, XCASE_TABLE_DOWNCASE (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
232 Fput_char_table (uc, lc, XCASE_TABLE_UPCASE (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
233 Fput_char_table (uc, lc, XCASE_TABLE_DOWNCASE (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
234 Fput_char_table (lc, uc, XCASE_TABLE_UPCASE (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
235
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
236 Fput_char_table (lc, lc, XCASE_TABLE_CANON (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
237 Fput_char_table (uc, lc, XCASE_TABLE_CANON (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
238 Fput_char_table (uc, lc, XCASE_TABLE_EQV (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
239 Fput_char_table (lc, uc, XCASE_TABLE_EQV (case_table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
240 return Qnil;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
241 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
242
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
243 DEFUN ("copy-case-table", Fcopy_case_table, 1, 1, 0, /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
244 Return a new case table which is a copy of CASE-TABLE
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
245 */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
246 (case_table))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
247 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
248 Lisp_Object new_obj;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
249 CHECK_CASE_TABLE (case_table);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
250
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
251 new_obj = allocate_case_table ();
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
252 XSET_CASE_TABLE_DOWNCASE
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
253 (new_obj, Fcopy_char_table (XCASE_TABLE_DOWNCASE (case_table)));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
254 XSET_CASE_TABLE_UPCASE
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
255 (new_obj, Fcopy_char_table (XCASE_TABLE_UPCASE (case_table)));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
256 XSET_CASE_TABLE_CANON
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
257 (new_obj, Fcopy_char_table (XCASE_TABLE_CANON (case_table)));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
258 XSET_CASE_TABLE_EQV
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
259 (new_obj, Fcopy_char_table (XCASE_TABLE_EQV (case_table)));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
260 return new_obj;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
261 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
262
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 DEFUN ("current-case-table", Fcurrent_case_table, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 Return the case table of BUFFER, which defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
270 return buf->case_table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 DEFUN ("standard-case-table", Fstandard_case_table, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 Return the standard case table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 This is the one used for new buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
279 return Vstandard_case_table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 static Lisp_Object set_case_table (Lisp_Object table, int standard);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 DEFUN ("set-case-table", Fset_case_table, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
285 Select CASE-TABLE as the new case table for the current buffer.
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
286 A case table is a case-table object or list
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
287 (DOWNCASE UPCASE CANONICALIZE EQUIVALENCES)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 where each element is either nil or a string of length 256.
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
289 The latter is provided for backward-compatibility.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 DOWNCASE maps each character to its lower-case equivalent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 UPCASE maps each character to its upper-case equivalent;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 if lower and upper case characters are in 1-1 correspondence,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 you may use nil and the upcase table will be deduced from DOWNCASE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 CANONICALIZE maps each character to a canonical equivalent;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 any two characters that are related by case-conversion have the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 canonical equivalent character; it may be nil, in which case it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 deduced from DOWNCASE and UPCASE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 EQUIVALENCES is a map that cyclicly permutes each equivalence class
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (of characters with the same canonical equivalent); it may be nil,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 in which case it is deduced from CANONICALIZE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
302 See also `get-case-table', `put-case-table' and `put-case-table-pair'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
304 (case_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
306 /* This function can GC */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
307 return set_case_table (case_table, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 DEFUN ("set-standard-case-table", Fset_standard_case_table, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
311 Select CASE-TABLE as the new standard case table for new buffers.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 See `set-case-table' for more info on case tables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
314 (case_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
316 /* This function can GC */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
317 return set_case_table (case_table, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 set_case_table (Lisp_Object table, int standard)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
323 /* This function can GC */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
324 struct buffer *buf =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
325 standard ? XBUFFER(Vbuffer_defaults) : current_buffer;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 check_case_table (table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
329 if (CASE_TABLEP (table))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
330 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
331 if (standard)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
332 Vstandard_case_table = table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
334 buf->case_table = table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
336 else
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
338 /* For backward compatibility. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
339 Lisp_Object down, up, canon, eqv, tail = table;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
340 Lisp_Object temp;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
341 int i;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
342
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
343 down = XCAR (tail); tail = XCDR (tail);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
344 up = XCAR (tail); tail = XCDR (tail);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
345 canon = XCAR (tail); tail = XCDR (tail);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
346 eqv = XCAR (tail);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
347
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
348 temp = down;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
349 down = MAKE_TRT_TABLE ();
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
350 for (i = 0; i < 256; i++)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
351 SET_TRT_TABLE_CHAR_1 (down, i, string_char (XSTRING (temp), i));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
353 if (NILP (up))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
354 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
355 up = MAKE_TRT_TABLE ();
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
356 compute_trt_inverse (down, up);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
357 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
358 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
359 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
360 temp = up;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
361 up = MAKE_TRT_TABLE ();
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
362 for (i = 0; i < 256; i++)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
363 SET_TRT_TABLE_CHAR_1 (up, i, string_char (XSTRING (temp), i));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
364 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
365 if (NILP (canon))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
366 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
367 canon = MAKE_TRT_TABLE ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
369 /* Set up the CANON table; for each character,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
370 this sequence of upcasing and downcasing ought to
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
371 get the "preferred" lowercase equivalent. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
372 for (i = 0; i < 256; i++)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
373 SET_TRT_TABLE_CHAR_1 (canon, i,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
374 TRT_TABLE_CHAR_1
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
375 (down,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
376 TRT_TABLE_CHAR_1
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
377 (up,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
378 TRT_TABLE_CHAR_1 (down, i))));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
379 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
380 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
381 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
382 temp = canon;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
383 canon = MAKE_TRT_TABLE ();
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
384 for (i = 0; i < 256; i++)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
385 SET_TRT_TABLE_CHAR_1 (canon, i, string_char (XSTRING (temp), i));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
386 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
387
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
388 if (NILP (eqv))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
389 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
390 eqv = MAKE_TRT_TABLE ();
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
391 compute_trt_inverse (canon, eqv);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
392 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
393 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
394 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
395 temp = eqv;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
396 eqv = MAKE_TRT_TABLE ();
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
397 for (i = 0; i < 256; i++)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
398 SET_TRT_TABLE_CHAR_1 (eqv, i, string_char (XSTRING (temp), i));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
399 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
400
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
401 if (standard)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
402 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
403 XSET_CASE_TABLE_DOWNCASE (Vstandard_case_table, down);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
404 XSET_CASE_TABLE_UPCASE (Vstandard_case_table, up);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
405 XSET_CASE_TABLE_CANON (Vstandard_case_table, canon);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
406 XSET_CASE_TABLE_EQV (Vstandard_case_table, eqv);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
407 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
408
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
409 buf->case_table = allocate_case_table ();
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
410 XSET_CASE_TABLE_DOWNCASE (buf->case_table, down);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
411 XSET_CASE_TABLE_UPCASE (buf->case_table, up);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
412 XSET_CASE_TABLE_CANON (buf->case_table, canon);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
413 XSET_CASE_TABLE_EQV (buf->case_table, eqv);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
416 return buf->case_table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 /* Given a translate table TRT, store the inverse mapping into INVERSE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 Since TRT is not one-to-one, INVERSE is not a simple mapping.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 Instead, it divides the space of characters into equivalence classes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 All characters in a given class form one circular list, chained through
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 the elements of INVERSE. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 compute_trt_inverse (Lisp_Object trt, Lisp_Object inverse)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 Charcount i = 0400;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 Emchar c, q;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 while (--i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 SET_TRT_TABLE_CHAR_1 (inverse, i, (Emchar) i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 i = 0400;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 while (--i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 if ((q = TRT_TABLE_CHAR_1 (trt, i)) != (Emchar) i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 c = TRT_TABLE_CHAR_1 (inverse, q);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 SET_TRT_TABLE_CHAR_1 (inverse, q, (Emchar) i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 SET_TRT_TABLE_CHAR_1 (inverse, i, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 syms_of_casetab (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
449 INIT_LRECORD_IMPLEMENTATION (case_table);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
450
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
451 DEFSYMBOL_MULTIWORD_PREDICATE (Qcase_tablep);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
452 DEFSYMBOL (Qdowncase);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
453 DEFSYMBOL (Qupcase);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 DEFSUBR (Fcase_table_p);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
456 DEFSUBR (Fget_case_table);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
457 DEFSUBR (Fput_case_table);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
458 DEFSUBR (Fput_case_table_pair);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 DEFSUBR (Fcurrent_case_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 DEFSUBR (Fstandard_case_table);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
461 DEFSUBR (Fcopy_case_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 DEFSUBR (Fset_case_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 DEFSUBR (Fset_standard_case_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 complex_vars_of_casetab (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 REGISTER Emchar i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 Lisp_Object tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
472 staticpro (&Vstandard_case_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
474 Vstandard_case_table = allocate_case_table ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 tem = MAKE_TRT_TABLE ();
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
477 XSET_CASE_TABLE_DOWNCASE (Vstandard_case_table, tem);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
478 XSET_CASE_TABLE_CANON (Vstandard_case_table, tem);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 /* Under Mule, can't do set_string_char() until Vcharset_control_1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 and Vcharset_ascii are initialized. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 for (i = 0; i < 256; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 unsigned char lowered = tolower (i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 SET_TRT_TABLE_CHAR_1 (tem, i, lowered);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 tem = MAKE_TRT_TABLE ();
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
490 XSET_CASE_TABLE_UPCASE (Vstandard_case_table, tem);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
491 XSET_CASE_TABLE_EQV (Vstandard_case_table, tem);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 for (i = 0; i < 256; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 unsigned char flipped = (isupper (i) ? tolower (i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 : (islower (i) ? toupper (i) : i));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 SET_TRT_TABLE_CHAR_1 (tem, i, flipped);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 }