Add some missing mappings to CHINA3-JEF code points.
[chise/xemacs-chise.git] / 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    Copyright (C) 1999,2000,2001,2002 MORIOKA Tomohiko
5
6 This file is part of XEmacs.
7
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
11 later version.
12
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
16 for more details.
17
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.  */
22
23 /* Synched up with: Mule 2.3.  Not synched with FSF.
24
25    This file was written independently of the FSF implementation,
26    and is not compatible. */
27
28 #ifndef INCLUDED_chartab_h_
29 #define INCLUDED_chartab_h_
30
31
32 #ifdef UTF2000
33
34 EXFUN (Fmake_char, 3);
35 EXFUN (Fdecode_char, 3);
36
37 EXFUN (Fput_char_attribute, 3);
38
39 EXFUN (Ffind_char, 1);
40
41
42 /************************************************************************/
43 /*                          Char-ID Tables                              */
44 /************************************************************************/
45
46 struct Lisp_Uint8_Byte_Table
47 {
48   struct lcrecord_header header;
49
50   unsigned char property[256];
51 };
52 typedef struct Lisp_Uint8_Byte_Table Lisp_Uint8_Byte_Table;
53
54 DECLARE_LRECORD (uint8_byte_table, Lisp_Uint8_Byte_Table);
55 #define XUINT8_BYTE_TABLE(x) \
56    XRECORD (x, uint8_byte_table, Lisp_Uint8_Byte_Table)
57 #define XSETUINT8_BYTE_TABLE(x, p) XSETRECORD (x, p, uint8_byte_table)
58 #define UINT8_BYTE_TABLE_P(x) RECORDP (x, uint8_byte_table)
59 #define GC_UINT8_BYTE_TABLE_P(x) GC_RECORDP (x, uint8_byte_table)
60 /* #define CHECK_UINT8_BYTE_TABLE(x) CHECK_RECORD (x, uint8_byte_table)
61    char table entries should never escape to Lisp */
62
63
64 struct Lisp_Uint16_Byte_Table
65 {
66   struct lcrecord_header header;
67
68   unsigned short property[256];
69 };
70 typedef struct Lisp_Uint16_Byte_Table Lisp_Uint16_Byte_Table;
71
72 DECLARE_LRECORD (uint16_byte_table, Lisp_Uint16_Byte_Table);
73 #define XUINT16_BYTE_TABLE(x) \
74    XRECORD (x, uint16_byte_table, Lisp_Uint16_Byte_Table)
75 #define XSETUINT16_BYTE_TABLE(x, p) XSETRECORD (x, p, uint16_byte_table)
76 #define UINT16_BYTE_TABLE_P(x) RECORDP (x, uint16_byte_table)
77 #define GC_UINT16_BYTE_TABLE_P(x) GC_RECORDP (x, uint16_byte_table)
78 /* #define CHECK_UINT16_BYTE_TABLE(x) CHECK_RECORD (x, uint16_byte_table)
79    char table entries should never escape to Lisp */
80
81
82 struct Lisp_Byte_Table
83 {
84   struct lcrecord_header header;
85
86   Lisp_Object property[256];
87 };
88 typedef struct Lisp_Byte_Table Lisp_Byte_Table;
89
90 DECLARE_LRECORD (byte_table, Lisp_Byte_Table);
91 #define XBYTE_TABLE(x) XRECORD (x, byte_table, Lisp_Byte_Table)
92 #define XSETBYTE_TABLE(x, p) XSETRECORD (x, p, byte_table)
93 #define BYTE_TABLE_P(x) RECORDP (x, byte_table)
94 #define GC_BYTE_TABLE_P(x) GC_RECORDP (x, byte_table)
95 /* #define CHECK_BYTE_TABLE(x) CHECK_RECORD (x, byte_table)
96    char table entries should never escape to Lisp */
97
98 Lisp_Object get_byte_table (Lisp_Object table, unsigned char idx);
99
100 Lisp_Object put_byte_table (Lisp_Object table, unsigned char idx,
101                             Lisp_Object value);
102
103
104 Lisp_Object make_char_id_table (Lisp_Object initval);
105
106 #endif
107
108
109 /************************************************************************/
110 /*                               Char Tables                            */
111 /************************************************************************/
112
113 /* Under Mule, we use a complex representation (see below).
114    When not under Mule, there are only 256 possible characters
115    so we just represent them directly. */
116
117 #if defined(MULE)&&!defined(UTF2000)
118
119 struct Lisp_Char_Table_Entry
120 {
121   struct lcrecord_header header;
122
123   /* In the interests of simplicity, we just use a fixed 96-entry
124      table.  If we felt like being smarter, we could make this
125      variable-size and add an offset value into this structure. */
126   Lisp_Object level2[96];
127 };
128 typedef struct Lisp_Char_Table_Entry Lisp_Char_Table_Entry;
129
130 DECLARE_LRECORD (char_table_entry, Lisp_Char_Table_Entry);
131 #define XCHAR_TABLE_ENTRY(x) \
132   XRECORD (x, char_table_entry, Lisp_Char_Table_Entry)
133 #define XSETCHAR_TABLE_ENTRY(x, p) XSETRECORD (x, p, char_table_entry)
134 #define CHAR_TABLE_ENTRYP(x) RECORDP (x, char_table_entry)
135 /* #define CHECK_CHAR_TABLE_ENTRY(x) CHECK_RECORD (x, char_table_entry)
136    char table entries should never escape to Lisp */
137
138 #endif /* MULE */
139
140 enum char_table_type
141 {
142   CHAR_TABLE_TYPE_GENERIC,
143 #ifdef MULE
144   CHAR_TABLE_TYPE_CATEGORY,
145 #endif
146   CHAR_TABLE_TYPE_SYNTAX,
147   CHAR_TABLE_TYPE_DISPLAY,
148   CHAR_TABLE_TYPE_CHAR
149 };
150
151 #ifndef UTF2000
152 #ifdef MULE
153 #define NUM_ASCII_CHARS 160
154 #else
155 #define NUM_ASCII_CHARS 256
156 #endif
157 #endif
158
159 struct Lisp_Char_Table
160 {
161   struct lcrecord_header header;
162
163 #ifdef UTF2000
164   Lisp_Object table;
165   Lisp_Object default_value;
166 #else
167   Lisp_Object ascii[NUM_ASCII_CHARS];
168
169 #ifdef MULE
170   /* We basically duplicate the Mule vectors-of-vectors implementation.
171      We can do this because we know a great deal about the sorts of
172      things we are going to be indexing.
173
174      The current implementation is as follows:
175
176      ascii[0-159] is used for ASCII and Control-1 characters.
177
178      level1[0 .. (NUM_LEADING_BYTES-1)] indexes charsets by leading
179      byte (subtract MIN_LEADING_BYTE from the leading byte).  If the
180      value of this is not an opaque, then it specifies a value for all
181      characters in the charset.  Otherwise, it will be a
182      96-Lisp-Object opaque that we created, specifying a value for
183      each row.  If the value of this is not an opaque, then it
184      specifies a value for all characters in the row.  Otherwise, it
185      will be a 96-Lisp-Object opaque that we created, specifying a
186      value for each character.
187
188      NOTE: 1) This will fail if some C routine passes an opaque to
189               Fput_char_table().  Currently this is not a problem
190               since all char tables that are created are Lisp-visible
191               and thus no one should ever be putting an opaque in
192               a char table.  Another possibility is to consider
193               adding a type to */
194
195   Lisp_Object level1[NUM_LEADING_BYTES];
196
197 #endif /* MULE */
198 #endif /* non UTF2000 */
199
200   enum char_table_type type;
201
202 #ifndef UTF2000
203   /* stuff used for syntax tables */
204   Lisp_Object mirror_table;
205 #endif
206   Lisp_Object next_table; /* DO NOT mark through this. */
207 };
208 typedef struct Lisp_Char_Table Lisp_Char_Table;
209
210 DECLARE_LRECORD (char_table, Lisp_Char_Table);
211 #define XCHAR_TABLE(x) XRECORD (x, char_table, Lisp_Char_Table)
212 #define XSETCHAR_TABLE(x, p) XSETRECORD (x, p, char_table)
213 #define CHAR_TABLEP(x) RECORDP (x, char_table)
214 #define CHECK_CHAR_TABLE(x) CHECK_RECORD (x, char_table)
215 #define CONCHECK_CHAR_TABLE(x) CONCHECK_RECORD (x, char_table)
216
217 #define CHAR_TABLE_TYPE(ct) ((ct)->type)
218 #define XCHAR_TABLE_TYPE(ct) CHAR_TABLE_TYPE (XCHAR_TABLE (ct))
219
220 #ifdef UTF2000
221
222 INLINE_HEADER Lisp_Object
223 CHAR_TABLE_VALUE_UNSAFE (Lisp_Char_Table *ct, Emchar ch);
224 INLINE_HEADER Lisp_Object
225 CHAR_TABLE_VALUE_UNSAFE (Lisp_Char_Table *ct, Emchar ch)
226 {
227   Lisp_Object val = get_byte_table (get_byte_table
228                                     (get_byte_table
229                                      (get_byte_table
230                                       (ct->table,
231                                        (unsigned char)(ch >> 24)),
232                                       (unsigned char) (ch >> 16)),
233                                      (unsigned char)  (ch >> 8)),
234                                     (unsigned char)    ch);
235   if (UNBOUNDP (val))
236     return ct->default_value;
237   else
238     return val;
239 }
240
241 #elif defined(MULE)
242
243 Lisp_Object get_non_ascii_char_table_value (Lisp_Char_Table *ct,
244                                             Charset_ID leading_byte,
245                                             Emchar c);
246
247 INLINE_HEADER Lisp_Object
248 CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (Lisp_Char_Table *ct, Emchar ch);
249 INLINE_HEADER Lisp_Object
250 CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (Lisp_Char_Table *ct, Emchar ch)
251 {
252 #ifdef UTF2000
253   Charset_ID lb = CHAR_CHARSET_ID (ch);
254 #else
255   Charset_ID lb = CHAR_LEADING_BYTE (ch);
256 #endif
257   if (!CHAR_TABLE_ENTRYP ((ct)->level1[lb - MIN_LEADING_BYTE]))
258     return (ct)->level1[lb - MIN_LEADING_BYTE];
259   else
260     return get_non_ascii_char_table_value (ct, lb, ch);
261 }
262
263 #define CHAR_TABLE_VALUE_UNSAFE(ct, ch)         \
264   ((ch) < NUM_ASCII_CHARS                       \
265    ? (ct)->ascii[ch]                            \
266    : CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (ct, ch))
267
268 #else /* not MULE */
269
270 #define CHAR_TABLE_VALUE_UNSAFE(ct, ch) ((ct)->ascii[(unsigned char) (ch)])
271
272 #endif /* not MULE */
273
274 #define XCHAR_TABLE_VALUE_UNSAFE(ct, ch) \
275   CHAR_TABLE_VALUE_UNSAFE (XCHAR_TABLE (ct), ch)
276
277 enum chartab_range_type
278 {
279   CHARTAB_RANGE_ALL,
280 #ifdef UTF2000
281   CHARTAB_RANGE_DEFAULT,
282 #endif
283 #ifdef MULE
284   CHARTAB_RANGE_CHARSET,
285   CHARTAB_RANGE_ROW,
286 #endif
287   CHARTAB_RANGE_CHAR
288 };
289
290 struct chartab_range
291 {
292   enum chartab_range_type type;
293   Emchar ch;
294   Lisp_Object charset;
295   int row;
296 };
297
298 void fill_char_table (Lisp_Char_Table *ct, Lisp_Object value);
299 void put_char_table (Lisp_Char_Table *ct, struct chartab_range *range,
300                      Lisp_Object val);
301 Lisp_Object get_char_table (Emchar, Lisp_Char_Table *);
302 int map_char_table (Lisp_Char_Table *ct,
303                     struct chartab_range *range,
304                     int (*fn) (struct chartab_range *range,
305                                Lisp_Object val, void *arg),
306                     void *arg);
307 void prune_syntax_tables (void);
308
309 EXFUN (Fcopy_char_table, 1);
310 EXFUN (Fmake_char_table, 1);
311 EXFUN (Fput_char_table, 3);
312 EXFUN (Fget_char_table, 2);
313
314 extern Lisp_Object Vall_syntax_tables;
315
316 \f
317 #ifdef UTF2000
318
319 INLINE_HEADER Lisp_Object get_char_id_table (Lisp_Char_Table* cit, Emchar ch);
320 INLINE_HEADER Lisp_Object
321 get_char_id_table (Lisp_Char_Table* cit, Emchar ch)
322 {
323   Lisp_Object val = get_byte_table (get_byte_table
324                                     (get_byte_table
325                                      (get_byte_table
326                                       (cit->table,
327                                        (unsigned char)(ch >> 24)),
328                                       (unsigned char) (ch >> 16)),
329                                      (unsigned char)  (ch >> 8)),
330                                     (unsigned char)    ch);
331   if (UNBOUNDP (val))
332     return cit->default_value;
333   else
334     return val;
335 }
336
337 INLINE_HEADER void
338 put_char_id_table_0 (Lisp_Char_Table* cit, Emchar code, Lisp_Object value);
339 INLINE_HEADER void
340 put_char_id_table_0 (Lisp_Char_Table* cit, Emchar code, Lisp_Object value)
341 {
342   Lisp_Object table1, table2, table3, table4;
343         
344   table1 = cit->table;
345   table2 = get_byte_table (table1, (unsigned char)(code >> 24));
346   table3 = get_byte_table (table2, (unsigned char)(code >> 16));
347   table4 = get_byte_table (table3, (unsigned char)(code >>  8));
348
349   table4     = put_byte_table (table4, (unsigned char) code, value);
350   table3     = put_byte_table (table3, (unsigned char)(code >>  8), table4);
351   table2     = put_byte_table (table2, (unsigned char)(code >> 16), table3);
352   cit->table = put_byte_table (table1, (unsigned char)(code >> 24), table2);
353 }
354
355 void
356 decode_char_table_range (Lisp_Object range, struct chartab_range *outrange);
357
358 INLINE_HEADER void
359 put_char_id_table (Lisp_Char_Table* table,
360                    Lisp_Object character, Lisp_Object value);
361 INLINE_HEADER void
362 put_char_id_table (Lisp_Char_Table* table,
363                    Lisp_Object character, Lisp_Object value)
364 {
365   struct chartab_range range;
366
367   decode_char_table_range (character, &range);
368   put_char_table (table, &range, value);
369 }
370
371
372 EXFUN (Fget_char_attribute, 3);
373
374 #endif
375 \f
376
377 #ifdef MULE
378 int check_category_char(Emchar ch, Lisp_Object ctbl,
379                         unsigned int designator, unsigned int not_p);
380
381 extern Lisp_Object Vstandard_category_table;
382
383 #define CATEGORY_DESIGNATORP(x) \
384  (CHARP (x) && XCHAR (x) >= 32 && XCHAR (x) <= 126)
385
386 #define CHECK_CATEGORY_DESIGNATOR(x) do {                       \
387   if (!CATEGORY_DESIGNATORP (x))                                \
388     dead_wrong_type_argument (Qcategory_designator_p, x);       \
389 } while (0)
390
391 #define CONCHECK_CATEGORY_DESIGNATOR(x) do {                    \
392   if (!CATEGORY_DESIGNATORP (x))                                \
393     x = wrong_type_argument (Qcategory_designator_p, x);        \
394 } while (0)
395
396 #define CATEGORY_TABLE_VALUEP(x) \
397  (NILP (x) || (BIT_VECTORP (x) && (bit_vector_length (XBIT_VECTOR (x)) == 95)))
398
399 #define CHECK_CATEGORY_TABLE_VALUE(x) do {                      \
400   if (!CATEGORY_TABLE_VALUEP (x))                               \
401     dead_wrong_type_argument (Qcategory_table_value_p, x);      \
402 } while (0)
403
404 #define CONCHECK_CATEGORY_TABLE_VALUE(x) do {                   \
405   if (!CATEGORY_TABLE_VALUEP (x))                               \
406     x = wrong_type_argument (Qcategory_table_value_p, x);       \
407 } while (0)
408
409 #endif /* MULE */
410
411 #endif /* INCLUDED_chartab_h_ */