1 /* Declarations having to do with Mule char tables.
2 Copyright (C) 1992 Free Software Foundation, Inc.
3 Copyright (C) 1995 Sun Microsystems, Inc.
5 This file is part of SXEmacs
7 SXEmacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 SXEmacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* Synched up with: Mule 2.3. Not synched with FSF.
23 This file was written independently of the FSF implementation,
24 and is not compatible. */
26 #ifndef INCLUDED_chartab_h_
27 #define INCLUDED_chartab_h_
29 /************************************************************************/
31 /************************************************************************/
33 /* Under Mule, we use a complex representation (see below).
34 When not under Mule, there are only 256 possible characters
35 so we just represent them directly. */
39 struct Lisp_Char_Table_Entry {
40 struct lcrecord_header header;
42 /* In the interests of simplicity, we just use a fixed 96-entry
43 table. If we felt like being smarter, we could make this
44 variable-size and add an offset value into this structure. */
45 Lisp_Object level2[96];
47 typedef struct Lisp_Char_Table_Entry Lisp_Char_Table_Entry;
49 DECLARE_LRECORD(char_table_entry, Lisp_Char_Table_Entry);
50 #define XCHAR_TABLE_ENTRY(x) \
51 XRECORD (x, char_table_entry, Lisp_Char_Table_Entry)
52 #define XSETCHAR_TABLE_ENTRY(x, p) XSETRECORD (x, p, char_table_entry)
53 #define CHAR_TABLE_ENTRYP(x) RECORDP (x, char_table_entry)
54 /* #define CHECK_CHAR_TABLE_ENTRY(x) CHECK_RECORD (x, char_table_entry)
55 char table entries should never escape to Lisp */
59 enum char_table_type {
60 CHAR_TABLE_TYPE_GENERIC,
62 CHAR_TABLE_TYPE_CATEGORY,
64 CHAR_TABLE_TYPE_SYNTAX,
65 CHAR_TABLE_TYPE_DISPLAY,
70 #define NUM_ASCII_CHARS 160
72 #define NUM_ASCII_CHARS 256
75 struct Lisp_Char_Table {
76 struct lcrecord_header header;
78 Lisp_Object ascii[NUM_ASCII_CHARS];
81 /* We basically duplicate the Mule vectors-of-vectors implementation.
82 We can do this because we know a great deal about the sorts of
83 things we are going to be indexing.
85 The current implementation is as follows:
87 ascii[0-159] is used for ASCII and Control-1 characters.
89 level1[0 .. (NUM_LEADING_BYTES-1)] indexes charsets by leading
90 byte (subtract MIN_LEADING_BYTE from the leading byte). If the
91 value of this is not an opaque, then it specifies a value for all
92 characters in the charset. Otherwise, it will be a
93 96-Lisp-Object opaque that we created, specifying a value for
94 each row. If the value of this is not an opaque, then it
95 specifies a value for all characters in the row. Otherwise, it
96 will be a 96-Lisp-Object opaque that we created, specifying a
97 value for each character.
99 NOTE: 1) This will fail if some C routine passes an opaque to
100 Fput_char_table(). Currently this is not a problem
101 since all char tables that are created are Lisp-visible
102 and thus no one should ever be putting an opaque in
103 a char table. Another possibility is to consider
106 Lisp_Object level1[NUM_LEADING_BYTES];
110 enum char_table_type type;
112 /* stuff used for syntax tables */
113 Lisp_Object mirror_table;
114 Lisp_Object next_table; /* DO NOT mark through this. */
116 typedef struct Lisp_Char_Table Lisp_Char_Table;
118 DECLARE_LRECORD(char_table, Lisp_Char_Table);
119 #define XCHAR_TABLE(x) XRECORD (x, char_table, Lisp_Char_Table)
120 #define XSETCHAR_TABLE(x, p) XSETRECORD (x, p, char_table)
121 #define CHAR_TABLEP(x) RECORDP (x, char_table)
122 #define CHECK_CHAR_TABLE(x) CHECK_RECORD (x, char_table)
123 #define CONCHECK_CHAR_TABLE(x) CONCHECK_RECORD (x, char_table)
125 #define CHAR_TABLE_TYPE(ct) ((ct)->type)
126 #define XCHAR_TABLE_TYPE(ct) CHAR_TABLE_TYPE (XCHAR_TABLE (ct))
130 Lisp_Object get_non_ascii_char_table_value(Lisp_Char_Table * ct,
131 int leading_byte, Emchar c);
133 extern_inline Lisp_Object
134 CHAR_TABLE_NON_ASCII_VALUE_UNSAFE(Lisp_Char_Table * ct, Emchar ch);
135 extern_inline Lisp_Object
136 CHAR_TABLE_NON_ASCII_VALUE_UNSAFE(Lisp_Char_Table * ct, Emchar ch)
138 unsigned char lb = CHAR_LEADING_BYTE(ch);
139 if (!CHAR_TABLE_ENTRYP((ct)->level1[lb - MIN_LEADING_BYTE]))
140 return (ct)->level1[lb - MIN_LEADING_BYTE];
142 return get_non_ascii_char_table_value(ct, lb, ch);
145 #define CHAR_TABLE_VALUE_UNSAFE(ct, ch) \
146 ((ch) < NUM_ASCII_CHARS \
148 : CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (ct, ch))
152 #define CHAR_TABLE_VALUE_UNSAFE(ct, ch) ((ct)->ascii[(unsigned char) (ch)])
154 #endif /* not MULE */
156 #define XCHAR_TABLE_VALUE_UNSAFE(ct, ch) \
157 CHAR_TABLE_VALUE_UNSAFE (XCHAR_TABLE (ct), ch)
159 enum chartab_range_type {
162 CHARTAB_RANGE_CHARSET,
168 struct chartab_range {
169 enum chartab_range_type type;
175 void fill_char_table(Lisp_Char_Table * ct, Lisp_Object value);
176 void put_char_table(Lisp_Char_Table * ct, struct chartab_range *range,
178 Lisp_Object get_char_table(Emchar, Lisp_Char_Table *);
179 int map_char_table(Lisp_Char_Table * ct,
180 struct chartab_range *range,
181 int (*fn) (struct chartab_range * range,
182 Lisp_Object val, void *arg), void *arg);
183 void prune_syntax_tables(void);
185 EXFUN(Fcopy_char_table, 1);
186 EXFUN(Fmake_char_table, 1);
187 EXFUN(Fput_char_table, 3);
188 EXFUN(Fget_char_table, 2);
190 extern Lisp_Object Vall_syntax_tables;
193 int check_category_char(Emchar ch, Lisp_Object ctbl,
194 unsigned int designator, unsigned int not_p);
196 extern Lisp_Object Vstandard_category_table;
198 #define CATEGORY_DESIGNATORP(x) \
199 (CHARP (x) && XCHAR (x) >= 32 && XCHAR (x) <= 126)
201 #define CHECK_CATEGORY_DESIGNATOR(x) do { \
202 if (!CATEGORY_DESIGNATORP (x)) \
203 dead_wrong_type_argument (Qcategory_designator_p, x); \
206 #define CONCHECK_CATEGORY_DESIGNATOR(x) do { \
207 if (!CATEGORY_DESIGNATORP (x)) \
208 x = wrong_type_argument (Qcategory_designator_p, x); \
211 #define CATEGORY_TABLE_VALUEP(x) \
212 (NILP (x) || (BIT_VECTORP (x) && (bit_vector_length (XBIT_VECTOR (x)) == 95)))
214 #define CHECK_CATEGORY_TABLE_VALUE(x) do { \
215 if (!CATEGORY_TABLE_VALUEP (x)) \
216 dead_wrong_type_argument (Qcategory_table_value_p, x); \
219 #define CONCHECK_CATEGORY_TABLE_VALUE(x) do { \
220 if (!CATEGORY_TABLE_VALUEP (x)) \
221 x = wrong_type_argument (Qcategory_table_value_p, x); \
226 #endif /* INCLUDED_chartab_h_ */