(put_char_ccs_code_point): Modify for interface change of
[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
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 INCLUDED_chartab_h_
28 #define INCLUDED_chartab_h_
29
30
31 #ifdef UTF2000
32
33 #include "char-ucs.h"
34
35 Lisp_Object make_char_id_table (Lisp_Object initval);
36
37 void put_char_id_table (Lisp_Char_ID_Table* table,
38                         Lisp_Object character, Lisp_Object value);
39
40 EXFUN (Fget_char_attribute, 3);
41
42 #endif
43
44
45 /************************************************************************/
46 /*                               Char Tables                            */
47 /************************************************************************/
48
49 /* Under Mule, we use a complex representation (see below).
50    When not under Mule, there are only 256 possible characters
51    so we just represent them directly. */
52
53 #ifdef MULE
54
55 struct Lisp_Char_Table_Entry
56 {
57   struct lcrecord_header header;
58
59   /* In the interests of simplicity, we just use a fixed 96-entry
60      table.  If we felt like being smarter, we could make this
61      variable-size and add an offset value into this structure. */
62   Lisp_Object level2[96];
63 };
64 typedef struct Lisp_Char_Table_Entry Lisp_Char_Table_Entry;
65
66 DECLARE_LRECORD (char_table_entry, Lisp_Char_Table_Entry);
67 #define XCHAR_TABLE_ENTRY(x) \
68   XRECORD (x, char_table_entry, Lisp_Char_Table_Entry)
69 #define XSETCHAR_TABLE_ENTRY(x, p) XSETRECORD (x, p, char_table_entry)
70 #define CHAR_TABLE_ENTRYP(x) RECORDP (x, char_table_entry)
71 /* #define CHECK_CHAR_TABLE_ENTRY(x) CHECK_RECORD (x, char_table_entry)
72    char table entries should never escape to Lisp */
73
74 #endif /* MULE */
75
76 enum char_table_type
77 {
78   CHAR_TABLE_TYPE_GENERIC,
79 #ifdef MULE
80   CHAR_TABLE_TYPE_CATEGORY,
81 #endif
82   CHAR_TABLE_TYPE_SYNTAX,
83   CHAR_TABLE_TYPE_DISPLAY,
84   CHAR_TABLE_TYPE_CHAR
85 };
86
87 #ifdef MULE
88 #define NUM_ASCII_CHARS 160
89 #else
90 #define NUM_ASCII_CHARS 256
91 #endif
92
93 struct Lisp_Char_Table
94 {
95   struct lcrecord_header header;
96
97   Lisp_Object ascii[NUM_ASCII_CHARS];
98
99 #ifdef MULE
100   /* We basically duplicate the Mule vectors-of-vectors implementation.
101      We can do this because we know a great deal about the sorts of
102      things we are going to be indexing.
103
104      The current implementation is as follows:
105
106      ascii[0-159] is used for ASCII and Control-1 characters.
107
108      level1[0 .. (NUM_LEADING_BYTES-1)] indexes charsets by leading
109      byte (subtract MIN_LEADING_BYTE from the leading byte).  If the
110      value of this is not an opaque, then it specifies a value for all
111      characters in the charset.  Otherwise, it will be a
112      96-Lisp-Object opaque that we created, specifying a value for
113      each row.  If the value of this is not an opaque, then it
114      specifies a value for all characters in the row.  Otherwise, it
115      will be a 96-Lisp-Object opaque that we created, specifying a
116      value for each character.
117
118      NOTE: 1) This will fail if some C routine passes an opaque to
119               Fput_char_table().  Currently this is not a problem
120               since all char tables that are created are Lisp-visible
121               and thus no one should ever be putting an opaque in
122               a char table.  Another possibility is to consider
123               adding a type to */
124
125   Lisp_Object level1[NUM_LEADING_BYTES];
126
127 #endif /* MULE */
128
129   enum char_table_type type;
130
131   /* stuff used for syntax tables */
132   Lisp_Object mirror_table;
133   Lisp_Object next_table; /* DO NOT mark through this. */
134 };
135 typedef struct Lisp_Char_Table Lisp_Char_Table;
136
137 DECLARE_LRECORD (char_table, Lisp_Char_Table);
138 #define XCHAR_TABLE(x) XRECORD (x, char_table, Lisp_Char_Table)
139 #define XSETCHAR_TABLE(x, p) XSETRECORD (x, p, char_table)
140 #define CHAR_TABLEP(x) RECORDP (x, char_table)
141 #define CHECK_CHAR_TABLE(x) CHECK_RECORD (x, char_table)
142 #define CONCHECK_CHAR_TABLE(x) CONCHECK_RECORD (x, char_table)
143
144 #define CHAR_TABLE_TYPE(ct) ((ct)->type)
145 #define XCHAR_TABLE_TYPE(ct) CHAR_TABLE_TYPE (XCHAR_TABLE (ct))
146
147 #ifdef MULE
148
149 Lisp_Object get_non_ascii_char_table_value (Lisp_Char_Table *ct,
150                                             Charset_ID leading_byte,
151                                             Emchar c);
152
153 INLINE_HEADER Lisp_Object
154 CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (Lisp_Char_Table *ct, Emchar ch);
155 INLINE_HEADER Lisp_Object
156 CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (Lisp_Char_Table *ct, Emchar ch)
157 {
158 #ifdef UTF2000
159   Charset_ID lb = CHAR_CHARSET_ID (ch);
160 #else
161   Charset_ID lb = CHAR_LEADING_BYTE (ch);
162 #endif
163   if (!CHAR_TABLE_ENTRYP ((ct)->level1[lb - MIN_LEADING_BYTE]))
164     return (ct)->level1[lb - MIN_LEADING_BYTE];
165   else
166     return get_non_ascii_char_table_value (ct, lb, ch);
167 }
168
169 #define CHAR_TABLE_VALUE_UNSAFE(ct, ch)         \
170   ((ch) < NUM_ASCII_CHARS                       \
171    ? (ct)->ascii[ch]                            \
172    : CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (ct, ch))
173
174 #else /* not MULE */
175
176 #define CHAR_TABLE_VALUE_UNSAFE(ct, ch) ((ct)->ascii[(unsigned char) (ch)])
177
178 #endif /* not MULE */
179
180 #define XCHAR_TABLE_VALUE_UNSAFE(ct, ch) \
181   CHAR_TABLE_VALUE_UNSAFE (XCHAR_TABLE (ct), ch)
182
183 enum chartab_range_type
184 {
185   CHARTAB_RANGE_ALL,
186 #ifdef MULE
187   CHARTAB_RANGE_CHARSET,
188   CHARTAB_RANGE_ROW,
189 #endif
190   CHARTAB_RANGE_CHAR
191 };
192
193 struct chartab_range
194 {
195   enum chartab_range_type type;
196   Emchar ch;
197   Lisp_Object charset;
198   int row;
199 };
200
201 void fill_char_table (Lisp_Char_Table *ct, Lisp_Object value);
202 void put_char_table (Lisp_Char_Table *ct, struct chartab_range *range,
203                      Lisp_Object val);
204 Lisp_Object get_char_table (Emchar, Lisp_Char_Table *);
205 int map_char_table (Lisp_Char_Table *ct,
206                     struct chartab_range *range,
207                     int (*fn) (struct chartab_range *range,
208                                Lisp_Object val, void *arg),
209                     void *arg);
210 void prune_syntax_tables (void);
211
212 EXFUN (Fcopy_char_table, 1);
213 EXFUN (Fmake_char_table, 1);
214 EXFUN (Fput_char_table, 3);
215 EXFUN (Fget_char_table, 2);
216
217 extern Lisp_Object Vall_syntax_tables;
218
219 \f
220
221 #ifdef MULE
222 int check_category_char(Emchar ch, Lisp_Object ctbl,
223                         unsigned int designator, unsigned int not);
224
225 extern Lisp_Object Vstandard_category_table;
226
227 #define CATEGORY_DESIGNATORP(x) \
228  (CHARP (x) && XCHAR (x) >= 32 && XCHAR (x) <= 126)
229
230 #define CHECK_CATEGORY_DESIGNATOR(x) do {                       \
231   if (!CATEGORY_DESIGNATORP (x))                                \
232     dead_wrong_type_argument (Qcategory_designator_p, x);       \
233 } while (0)
234
235 #define CONCHECK_CATEGORY_DESIGNATOR(x) do {                    \
236   if (!CATEGORY_DESIGNATORP (x))                                \
237     x = wrong_type_argument (Qcategory_designator_p, x);        \
238 } while (0)
239
240 #define CATEGORY_TABLE_VALUEP(x) \
241  (NILP (x) || (BIT_VECTORP (x) && (bit_vector_length (XBIT_VECTOR (x)) == 95)))
242
243 #define CHECK_CATEGORY_TABLE_VALUE(x) do {                      \
244   if (!CATEGORY_TABLE_VALUEP (x))                               \
245     dead_wrong_type_argument (Qcategory_table_value_p, x);      \
246 } while (0)
247
248 #define CONCHECK_CATEGORY_TABLE_VALUE(x) do {                   \
249   if (!CATEGORY_TABLE_VALUEP (x))                               \
250     x = wrong_type_argument (Qcategory_table_value_p, x);       \
251 } while (0)
252
253 #endif /* MULE */
254
255 #endif /* INCLUDED_chartab_h_ */