XEmacs 21.2.4
[chise/xemacs-chise.git.1] / src / chartab.h
1 /* Declarations having to do with Mule char tables.
2    Copyright (C) 1992 Free Software Foundation, Inc.
3    Copyright (C) 1995 Sun Microsystems, Inc.
4
5 This file is part of XEmacs.
6
7 XEmacs is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
11
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with XEmacs; see the file COPYING.  If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 /* Synched up with: Mule 2.3.  Not synched with FSF.
23
24    This file was written independently of the FSF implementation,
25    and is not compatible. */
26
27 #ifndef _MULE_CHARTAB_H
28 #define _MULE_CHARTAB_H
29
30 /************************************************************************/
31 /*                               Char Tables                            */
32 /************************************************************************/
33
34 /* Under Mule, we use a complex representation (see below).
35    When not under Mule, there are only 256 possible characters
36    so we just represent them directly. */
37
38 #ifdef MULE
39
40 DECLARE_LRECORD (char_table_entry, struct Lisp_Char_Table_Entry);
41 #define XCHAR_TABLE_ENTRY(x) \
42   XRECORD (x, char_table_entry, struct Lisp_Char_Table_Entry)
43 #define XSETCHAR_TABLE_ENTRY(x, p) XSETRECORD (x, p, char_table_entry)
44 #define CHAR_TABLE_ENTRYP(x) RECORDP (x, char_table_entry)
45 #define GC_CHAR_TABLE_ENTRYP(x) GC_RECORDP (x, char_table_entry)
46 /* #define CHECK_CHAR_TABLE_ENTRY(x) CHECK_RECORD (x, char_table_entry)
47    char table entries should never escape to Lisp */
48
49 struct Lisp_Char_Table_Entry
50 {
51   struct lcrecord_header header;
52
53   /* In the interests of simplicity, we just use a fixed 96-entry
54      table.  If we felt like being smarter, we could make this
55      variable-size and add an offset value into this structure. */
56   Lisp_Object level2[96];
57 };
58
59 #endif /* MULE */
60
61 DECLARE_LRECORD (char_table, struct Lisp_Char_Table);
62 #define XCHAR_TABLE(x) \
63   XRECORD (x, char_table, struct Lisp_Char_Table)
64 #define XSETCHAR_TABLE(x, p) XSETRECORD (x, p, char_table)
65 #define CHAR_TABLEP(x) RECORDP (x, char_table)
66 #define GC_CHAR_TABLEP(x) GC_RECORDP (x, char_table)
67 #define CHECK_CHAR_TABLE(x) CHECK_RECORD (x, char_table)
68 #define CONCHECK_CHAR_TABLE(x) CONCHECK_RECORD (x, char_table)
69
70 #define CHAR_TABLE_TYPE(ct) ((ct)->type)
71 #define XCHAR_TABLE_TYPE(ct) CHAR_TABLE_TYPE (XCHAR_TABLE (ct))
72
73 enum char_table_type
74 {
75   CHAR_TABLE_TYPE_GENERIC,
76 #ifdef MULE
77   CHAR_TABLE_TYPE_CATEGORY,
78 #endif
79   CHAR_TABLE_TYPE_SYNTAX,
80   CHAR_TABLE_TYPE_DISPLAY,
81   CHAR_TABLE_TYPE_CHAR
82 };
83
84 #ifdef MULE
85 #define NUM_ASCII_CHARS 160
86 #else
87 #define NUM_ASCII_CHARS 256
88 #endif
89
90 struct Lisp_Char_Table
91 {
92   struct lcrecord_header header;
93
94   Lisp_Object ascii[NUM_ASCII_CHARS];
95
96 #ifdef MULE
97   /* We basically duplicate the Mule vectors-of-vectors implementation.
98      We can do this because we know a great deal about the sorts of
99      things we are going to be indexing.
100
101      The current implementation is as follows:
102
103      ascii[0-159] is used for ASCII and Control-1 characters.
104
105      level1[0 .. (NUM_LEADING_BYTES-1)] indexes charsets by leading
106      byte (subtract MIN_LEADING_BYTE from the leading byte).  If the
107      value of this is not an opaque, then it specifies a value for all
108      characters in the charset.  Otherwise, it will be a
109      96-Lisp-Object opaque that we created, specifying a value for
110      each row.  If the value of this is not an opaque, then it
111      specifies a value for all characters in the row.  Otherwise, it
112      will be a 96-Lisp-Object opaque that we created, specifying a
113      value for each character.
114
115      NOTE: 1) This will fail if some C routine passes an opaque to
116               Fput_char_table().  Currently this is not a problem
117               since all char tables that are created are Lisp-visible
118               and thus no one should ever be putting an opaque in
119               a char table.  Another possibility is to consider
120               adding a type to */
121
122   Lisp_Object level1[NUM_LEADING_BYTES];
123
124 #endif /* MULE */
125
126   enum char_table_type type;
127
128   /* stuff used for syntax tables */
129   Lisp_Object mirror_table;
130   Lisp_Object next_table; /* DO NOT mark through this. */
131 };
132
133 #ifdef MULE
134
135 Lisp_Object get_non_ascii_char_table_value (struct Lisp_Char_Table *ct,
136                                            int leading_byte,
137                                            Emchar c);
138
139 INLINE Lisp_Object
140 CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (struct Lisp_Char_Table *ct, Emchar ch);
141 INLINE Lisp_Object
142 CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (struct Lisp_Char_Table *ct, Emchar ch)
143 {
144   unsigned char lb = CHAR_LEADING_BYTE (ch);
145   if (!CHAR_TABLE_ENTRYP ((ct)->level1[lb - MIN_LEADING_BYTE]))
146     return (ct)->level1[lb - MIN_LEADING_BYTE];
147   else
148     return get_non_ascii_char_table_value (ct, lb, ch);
149 }
150
151 #define CHAR_TABLE_VALUE_UNSAFE(ct, ch)         \
152   ((ch) < NUM_ASCII_CHARS                       \
153    ? (ct)->ascii[ch]                            \
154    : CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (ct, ch))
155
156 #else /* not MULE */
157
158 #define CHAR_TABLE_VALUE_UNSAFE(ct, ch) ((ct)->ascii[(unsigned char) (ch)])
159
160 #endif /* not MULE */
161
162 enum chartab_range_type
163 {
164   CHARTAB_RANGE_ALL,
165 #ifdef MULE
166   CHARTAB_RANGE_CHARSET,
167   CHARTAB_RANGE_ROW,
168 #endif
169   CHARTAB_RANGE_CHAR
170 };
171
172 struct chartab_range
173 {
174   enum chartab_range_type type;
175   Emchar ch;
176   Lisp_Object charset;
177   int row;
178 };
179
180 void fill_char_table (struct Lisp_Char_Table *ct, Lisp_Object value);
181 void put_char_table (struct Lisp_Char_Table *ct, struct chartab_range *range,
182                      Lisp_Object val);
183 Lisp_Object get_char_table (Emchar, struct Lisp_Char_Table *);
184 int map_char_table (struct Lisp_Char_Table *ct,
185                     struct chartab_range *range,
186                     int (*fn) (struct chartab_range *range,
187                                Lisp_Object val, void *arg),
188                     void *arg);
189 void prune_syntax_tables (int (*obj_marked_p) (Lisp_Object));
190
191 EXFUN (Fcopy_char_table, 1);
192 EXFUN (Fmake_char_table, 1);
193 EXFUN (Fput_char_table, 3);
194
195 extern Lisp_Object Vall_syntax_tables;
196
197 \f
198
199 #ifdef MULE
200 int check_category_char(Emchar ch, Lisp_Object ctbl,
201                         unsigned int designator, unsigned int not);
202
203 extern Lisp_Object Vstandard_category_table;
204
205 #define CATEGORY_DESIGNATORP(x) \
206  (CHARP (x) && XCHAR (x) >= 32 && XCHAR (x) <= 126)
207
208 #define CHECK_CATEGORY_DESIGNATOR(x) do {                       \
209   if (!CATEGORY_DESIGNATORP (x))                                \
210     dead_wrong_type_argument (Qcategory_designator_p, x);       \
211 } while (0)
212
213 #define CONCHECK_CATEGORY_DESIGNATOR(x) do {                    \
214   if (!CATEGORY_DESIGNATORP (x))                                \
215     x = wrong_type_argument (Qcategory_designator_p, x);        \
216 } while (0)
217
218 #define CATEGORY_TABLE_VALUEP(x) \
219  (NILP (x) || (BIT_VECTORP (x) && (bit_vector_length (XBIT_VECTOR (x)) == 95)))
220
221 #define CHECK_CATEGORY_TABLE_VALUE(x) do {                      \
222   if (!CATEGORY_TABLE_VALUEP (x))                               \
223     dead_wrong_type_argument (Qcategory_table_value_p, x);      \
224 } while (0)
225
226 #define CONCHECK_CATEGORY_TABLE_VALUE(x) do {                   \
227   if (!CATEGORY_TABLE_VALUEP (x))                               \
228     x = wrong_type_argument (Qcategory_table_value_p, x);       \
229 } while (0)
230
231 #endif /* MULE */
232
233 #endif /* _MULE_CHARTAB_H */