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 Copyright (C) 1999,2000,2001,2002 MORIOKA Tomohiko
6 This file is part of XEmacs.
8 XEmacs is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with XEmacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* Synched up with: Mule 2.3. Not synched with FSF.
25 This file was written independently of the FSF implementation,
26 and is not compatible. */
28 #ifndef INCLUDED_chartab_h_
29 #define INCLUDED_chartab_h_
38 EXFUN (Fmake_char, 3);
39 EXFUN (Fdecode_char, 3);
41 EXFUN (Fput_char_attribute, 3);
44 /************************************************************************/
46 /************************************************************************/
48 struct Lisp_Uint8_Byte_Table
50 struct lcrecord_header header;
52 unsigned char property[256];
54 typedef struct Lisp_Uint8_Byte_Table Lisp_Uint8_Byte_Table;
56 DECLARE_LRECORD (uint8_byte_table, Lisp_Uint8_Byte_Table);
57 #define XUINT8_BYTE_TABLE(x) \
58 XRECORD (x, uint8_byte_table, Lisp_Uint8_Byte_Table)
59 #define XSETUINT8_BYTE_TABLE(x, p) XSETRECORD (x, p, uint8_byte_table)
60 #define UINT8_BYTE_TABLE_P(x) RECORDP (x, uint8_byte_table)
61 #define GC_UINT8_BYTE_TABLE_P(x) GC_RECORDP (x, uint8_byte_table)
62 /* #define CHECK_UINT8_BYTE_TABLE(x) CHECK_RECORD (x, uint8_byte_table)
63 char table entries should never escape to Lisp */
66 struct Lisp_Uint16_Byte_Table
68 struct lcrecord_header header;
70 unsigned short property[256];
72 typedef struct Lisp_Uint16_Byte_Table Lisp_Uint16_Byte_Table;
74 DECLARE_LRECORD (uint16_byte_table, Lisp_Uint16_Byte_Table);
75 #define XUINT16_BYTE_TABLE(x) \
76 XRECORD (x, uint16_byte_table, Lisp_Uint16_Byte_Table)
77 #define XSETUINT16_BYTE_TABLE(x, p) XSETRECORD (x, p, uint16_byte_table)
78 #define UINT16_BYTE_TABLE_P(x) RECORDP (x, uint16_byte_table)
79 #define GC_UINT16_BYTE_TABLE_P(x) GC_RECORDP (x, uint16_byte_table)
80 /* #define CHECK_UINT16_BYTE_TABLE(x) CHECK_RECORD (x, uint16_byte_table)
81 char table entries should never escape to Lisp */
84 struct Lisp_Byte_Table
86 struct lcrecord_header header;
88 Lisp_Object property[256];
90 typedef struct Lisp_Byte_Table Lisp_Byte_Table;
92 DECLARE_LRECORD (byte_table, Lisp_Byte_Table);
93 #define XBYTE_TABLE(x) XRECORD (x, byte_table, Lisp_Byte_Table)
94 #define XSETBYTE_TABLE(x, p) XSETRECORD (x, p, byte_table)
95 #define BYTE_TABLE_P(x) RECORDP (x, byte_table)
96 #define GC_BYTE_TABLE_P(x) GC_RECORDP (x, byte_table)
97 /* #define CHECK_BYTE_TABLE(x) CHECK_RECORD (x, byte_table)
98 char table entries should never escape to Lisp */
100 Lisp_Object get_byte_table (Lisp_Object table, unsigned char idx);
102 Lisp_Object put_byte_table (Lisp_Object table, unsigned char idx,
106 Lisp_Object make_char_id_table (Lisp_Object initval);
111 /************************************************************************/
113 /************************************************************************/
115 /* Under Mule, we use a complex representation (see below).
116 When not under Mule, there are only 256 possible characters
117 so we just represent them directly. */
119 #if defined(MULE)&&!defined(UTF2000)
121 struct Lisp_Char_Table_Entry
123 struct lcrecord_header header;
125 /* In the interests of simplicity, we just use a fixed 96-entry
126 table. If we felt like being smarter, we could make this
127 variable-size and add an offset value into this structure. */
128 Lisp_Object level2[96];
130 typedef struct Lisp_Char_Table_Entry Lisp_Char_Table_Entry;
132 DECLARE_LRECORD (char_table_entry, Lisp_Char_Table_Entry);
133 #define XCHAR_TABLE_ENTRY(x) \
134 XRECORD (x, char_table_entry, Lisp_Char_Table_Entry)
135 #define XSETCHAR_TABLE_ENTRY(x, p) XSETRECORD (x, p, char_table_entry)
136 #define CHAR_TABLE_ENTRYP(x) RECORDP (x, char_table_entry)
137 /* #define CHECK_CHAR_TABLE_ENTRY(x) CHECK_RECORD (x, char_table_entry)
138 char table entries should never escape to Lisp */
144 CHAR_TABLE_TYPE_GENERIC,
146 CHAR_TABLE_TYPE_CATEGORY,
148 CHAR_TABLE_TYPE_SYNTAX,
149 CHAR_TABLE_TYPE_DISPLAY,
155 #define NUM_ASCII_CHARS 160
157 #define NUM_ASCII_CHARS 256
161 struct Lisp_Char_Table
163 struct lcrecord_header header;
167 Lisp_Object default_value;
170 unsigned char unloaded;
172 Lisp_Object ascii[NUM_ASCII_CHARS];
175 /* We basically duplicate the Mule vectors-of-vectors implementation.
176 We can do this because we know a great deal about the sorts of
177 things we are going to be indexing.
179 The current implementation is as follows:
181 ascii[0-159] is used for ASCII and Control-1 characters.
183 level1[0 .. (NUM_LEADING_BYTES-1)] indexes charsets by leading
184 byte (subtract MIN_LEADING_BYTE from the leading byte). If the
185 value of this is not an opaque, then it specifies a value for all
186 characters in the charset. Otherwise, it will be a
187 96-Lisp-Object opaque that we created, specifying a value for
188 each row. If the value of this is not an opaque, then it
189 specifies a value for all characters in the row. Otherwise, it
190 will be a 96-Lisp-Object opaque that we created, specifying a
191 value for each character.
193 NOTE: 1) This will fail if some C routine passes an opaque to
194 Fput_char_table(). Currently this is not a problem
195 since all char tables that are created are Lisp-visible
196 and thus no one should ever be putting an opaque in
197 a char table. Another possibility is to consider
200 Lisp_Object level1[NUM_LEADING_BYTES];
203 #endif /* non UTF2000 */
205 enum char_table_type type;
208 /* stuff used for syntax tables */
209 Lisp_Object mirror_table;
211 Lisp_Object next_table; /* DO NOT mark through this. */
213 typedef struct Lisp_Char_Table Lisp_Char_Table;
215 DECLARE_LRECORD (char_table, Lisp_Char_Table);
216 #define XCHAR_TABLE(x) XRECORD (x, char_table, Lisp_Char_Table)
217 #define XSETCHAR_TABLE(x, p) XSETRECORD (x, p, char_table)
218 #define CHAR_TABLEP(x) RECORDP (x, char_table)
219 #define CHECK_CHAR_TABLE(x) CHECK_RECORD (x, char_table)
220 #define CONCHECK_CHAR_TABLE(x) CONCHECK_RECORD (x, char_table)
222 #define CHAR_TABLE_TYPE(ct) ((ct)->type)
223 #define XCHAR_TABLE_TYPE(ct) CHAR_TABLE_TYPE (XCHAR_TABLE (ct))
227 #define CHAR_TABLE_NAME(ct) ((ct)->name)
228 #define XCHAR_TABLE_NAME(ct) CHAR_TABLE_NAME (XCHAR_TABLE (ct))
230 #define CHAR_TABLE_UNLOADED(ct) ((ct)->unloaded)
231 #define XCHAR_TABLE_UNLOADED(ct) CHAR_TABLE_UNLOADED (XCHAR_TABLE (ct))
233 INLINE_HEADER Lisp_Object
234 CHAR_TABLE_VALUE_UNSAFE (Lisp_Char_Table *ct, Emchar ch);
235 INLINE_HEADER Lisp_Object
236 CHAR_TABLE_VALUE_UNSAFE (Lisp_Char_Table *ct, Emchar ch)
238 Lisp_Object val = get_byte_table (get_byte_table
242 (unsigned char)(ch >> 24)),
243 (unsigned char) (ch >> 16)),
244 (unsigned char) (ch >> 8)),
247 return ct->default_value;
254 Lisp_Object get_non_ascii_char_table_value (Lisp_Char_Table *ct,
255 Charset_ID leading_byte,
258 INLINE_HEADER Lisp_Object
259 CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (Lisp_Char_Table *ct, Emchar ch);
260 INLINE_HEADER Lisp_Object
261 CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (Lisp_Char_Table *ct, Emchar ch)
264 Charset_ID lb = CHAR_CHARSET_ID (ch);
266 Charset_ID lb = CHAR_LEADING_BYTE (ch);
268 if (!CHAR_TABLE_ENTRYP ((ct)->level1[lb - MIN_LEADING_BYTE]))
269 return (ct)->level1[lb - MIN_LEADING_BYTE];
271 return get_non_ascii_char_table_value (ct, lb, ch);
274 #define CHAR_TABLE_VALUE_UNSAFE(ct, ch) \
275 ((ch) < NUM_ASCII_CHARS \
277 : CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (ct, ch))
281 #define CHAR_TABLE_VALUE_UNSAFE(ct, ch) ((ct)->ascii[(unsigned char) (ch)])
283 #endif /* not MULE */
285 #define XCHAR_TABLE_VALUE_UNSAFE(ct, ch) \
286 CHAR_TABLE_VALUE_UNSAFE (XCHAR_TABLE (ct), ch)
288 enum chartab_range_type
292 CHARTAB_RANGE_DEFAULT,
295 CHARTAB_RANGE_CHARSET,
303 enum chartab_range_type type;
309 void fill_char_table (Lisp_Char_Table *ct, Lisp_Object value);
310 void put_char_table (Lisp_Char_Table *ct, struct chartab_range *range,
312 Lisp_Object get_char_table (Emchar, Lisp_Char_Table *);
313 int map_char_table (Lisp_Char_Table *ct,
314 struct chartab_range *range,
315 int (*fn) (struct chartab_range *range,
316 Lisp_Object val, void *arg),
318 void prune_syntax_tables (void);
320 EXFUN (Fcopy_char_table, 1);
321 EXFUN (Fmake_char_table, 1);
322 EXFUN (Fput_char_table, 3);
323 EXFUN (Fget_char_table, 2);
325 extern Lisp_Object Vall_syntax_tables;
331 put_char_id_table_0 (Lisp_Char_Table* cit, Emchar code, Lisp_Object value);
333 put_char_id_table_0 (Lisp_Char_Table* cit, Emchar code, Lisp_Object value)
335 Lisp_Object table1, table2, table3, table4;
338 table2 = get_byte_table (table1, (unsigned char)(code >> 24));
339 table3 = get_byte_table (table2, (unsigned char)(code >> 16));
340 table4 = get_byte_table (table3, (unsigned char)(code >> 8));
342 table4 = put_byte_table (table4, (unsigned char) code, value);
343 table3 = put_byte_table (table3, (unsigned char)(code >> 8), table4);
344 table2 = put_byte_table (table2, (unsigned char)(code >> 16), table3);
345 cit->table = put_byte_table (table1, (unsigned char)(code >> 24), table2);
349 extern Lisp_Object Qsystem_char_id;
352 char_attribute_system_db_file (Lisp_Object key_type, Lisp_Object attribute,
355 Lisp_Object load_char_attribute_maybe (Lisp_Char_Table* cit, Emchar ch);
358 INLINE_HEADER Lisp_Object get_char_id_table (Lisp_Char_Table* cit, Emchar ch);
359 INLINE_HEADER Lisp_Object
360 get_char_id_table (Lisp_Char_Table* cit, Emchar ch)
362 Lisp_Object val = get_byte_table (get_byte_table
366 (unsigned char)(ch >> 24)),
367 (unsigned char) (ch >> 16)),
368 (unsigned char) (ch >> 8)),
371 if (EQ (val, Qunloaded))
373 val = load_char_attribute_maybe (cit, ch);
374 put_char_id_table_0 (cit, ch, val);
378 return cit->default_value;
384 decode_char_table_range (Lisp_Object range, struct chartab_range *outrange);
387 put_char_id_table (Lisp_Char_Table* table,
388 Lisp_Object character, Lisp_Object value);
390 put_char_id_table (Lisp_Char_Table* table,
391 Lisp_Object character, Lisp_Object value)
393 struct chartab_range range;
395 decode_char_table_range (character, &range);
396 put_char_table (table, &range, value);
400 EXFUN (Fget_char_attribute, 3);
406 int check_category_char(Emchar ch, Lisp_Object ctbl,
407 unsigned int designator, unsigned int not_p);
409 extern Lisp_Object Vstandard_category_table;
411 #define CATEGORY_DESIGNATORP(x) \
412 (CHARP (x) && XCHAR (x) >= 32 && XCHAR (x) <= 126)
414 #define CHECK_CATEGORY_DESIGNATOR(x) do { \
415 if (!CATEGORY_DESIGNATORP (x)) \
416 dead_wrong_type_argument (Qcategory_designator_p, x); \
419 #define CONCHECK_CATEGORY_DESIGNATOR(x) do { \
420 if (!CATEGORY_DESIGNATORP (x)) \
421 x = wrong_type_argument (Qcategory_designator_p, x); \
424 #define CATEGORY_TABLE_VALUEP(x) \
425 (NILP (x) || (BIT_VECTORP (x) && (bit_vector_length (XBIT_VECTOR (x)) == 95)))
427 #define CHECK_CATEGORY_TABLE_VALUE(x) do { \
428 if (!CATEGORY_TABLE_VALUEP (x)) \
429 dead_wrong_type_argument (Qcategory_table_value_p, x); \
432 #define CONCHECK_CATEGORY_TABLE_VALUE(x) do { \
433 if (!CATEGORY_TABLE_VALUEP (x)) \
434 x = wrong_type_argument (Qcategory_table_value_p, x); \
439 #endif /* INCLUDED_chartab_h_ */