Initial git import
[sxemacs] / 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 SXEmacs
6
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.
11
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.
16
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/>. */
19
20
21 /* Synched up with: Mule 2.3.  Not synched with FSF.
22
23    This file was written independently of the FSF implementation,
24    and is not compatible. */
25
26 #ifndef INCLUDED_chartab_h_
27 #define INCLUDED_chartab_h_
28
29 /************************************************************************/
30 /*                               Char Tables                            */
31 /************************************************************************/
32
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. */
36
37 #ifdef MULE
38
39 struct Lisp_Char_Table_Entry {
40         struct lcrecord_header header;
41
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];
46 };
47 typedef struct Lisp_Char_Table_Entry Lisp_Char_Table_Entry;
48
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 */
56
57 #endif                          /* MULE */
58
59 enum char_table_type {
60         CHAR_TABLE_TYPE_GENERIC,
61 #ifdef MULE
62         CHAR_TABLE_TYPE_CATEGORY,
63 #endif
64         CHAR_TABLE_TYPE_SYNTAX,
65         CHAR_TABLE_TYPE_DISPLAY,
66         CHAR_TABLE_TYPE_CHAR
67 };
68
69 #ifdef MULE
70 #define NUM_ASCII_CHARS 160
71 #else
72 #define NUM_ASCII_CHARS 256
73 #endif
74
75 struct Lisp_Char_Table {
76         struct lcrecord_header header;
77
78         Lisp_Object ascii[NUM_ASCII_CHARS];
79
80 #ifdef MULE
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.
84
85            The current implementation is as follows:
86
87            ascii[0-159] is used for ASCII and Control-1 characters.
88
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.
98
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
104            adding a type to */
105
106         Lisp_Object level1[NUM_LEADING_BYTES];
107
108 #endif                          /* MULE */
109
110         enum char_table_type type;
111
112         /* stuff used for syntax tables */
113         Lisp_Object mirror_table;
114         Lisp_Object next_table; /* DO NOT mark through this. */
115 };
116 typedef struct Lisp_Char_Table Lisp_Char_Table;
117
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)
124
125 #define CHAR_TABLE_TYPE(ct) ((ct)->type)
126 #define XCHAR_TABLE_TYPE(ct) CHAR_TABLE_TYPE (XCHAR_TABLE (ct))
127
128 #ifdef MULE
129
130 Lisp_Object get_non_ascii_char_table_value(Lisp_Char_Table * ct,
131                                            int leading_byte, Emchar c);
132
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)
137 {
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];
141         else
142                 return get_non_ascii_char_table_value(ct, lb, ch);
143 }
144
145 #define CHAR_TABLE_VALUE_UNSAFE(ct, ch)         \
146   ((ch) < NUM_ASCII_CHARS                       \
147    ? (ct)->ascii[ch]                            \
148    : CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (ct, ch))
149
150 #else                           /* not MULE */
151
152 #define CHAR_TABLE_VALUE_UNSAFE(ct, ch) ((ct)->ascii[(unsigned char) (ch)])
153
154 #endif                          /* not MULE */
155
156 #define XCHAR_TABLE_VALUE_UNSAFE(ct, ch) \
157   CHAR_TABLE_VALUE_UNSAFE (XCHAR_TABLE (ct), ch)
158
159 enum chartab_range_type {
160         CHARTAB_RANGE_ALL,
161 #ifdef MULE
162         CHARTAB_RANGE_CHARSET,
163         CHARTAB_RANGE_ROW,
164 #endif
165         CHARTAB_RANGE_CHAR
166 };
167
168 struct chartab_range {
169         enum chartab_range_type type;
170         Emchar ch;
171         Lisp_Object charset;
172         int row;
173 };
174
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,
177                     Lisp_Object val);
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);
184
185 EXFUN(Fcopy_char_table, 1);
186 EXFUN(Fmake_char_table, 1);
187 EXFUN(Fput_char_table, 3);
188 EXFUN(Fget_char_table, 2);
189
190 extern Lisp_Object Vall_syntax_tables;
191 \f
192 #ifdef MULE
193 int check_category_char(Emchar ch, Lisp_Object ctbl,
194                         unsigned int designator, unsigned int not_p);
195
196 extern Lisp_Object Vstandard_category_table;
197
198 #define CATEGORY_DESIGNATORP(x) \
199  (CHARP (x) && XCHAR (x) >= 32 && XCHAR (x) <= 126)
200
201 #define CHECK_CATEGORY_DESIGNATOR(x) do {                       \
202   if (!CATEGORY_DESIGNATORP (x))                                \
203     dead_wrong_type_argument (Qcategory_designator_p, x);       \
204 } while (0)
205
206 #define CONCHECK_CATEGORY_DESIGNATOR(x) do {                    \
207   if (!CATEGORY_DESIGNATORP (x))                                \
208     x = wrong_type_argument (Qcategory_designator_p, x);        \
209 } while (0)
210
211 #define CATEGORY_TABLE_VALUEP(x) \
212  (NILP (x) || (BIT_VECTORP (x) && (bit_vector_length (XBIT_VECTOR (x)) == 95)))
213
214 #define CHECK_CATEGORY_TABLE_VALUE(x) do {                      \
215   if (!CATEGORY_TABLE_VALUEP (x))                               \
216     dead_wrong_type_argument (Qcategory_table_value_p, x);      \
217 } while (0)
218
219 #define CONCHECK_CATEGORY_TABLE_VALUE(x) do {                   \
220   if (!CATEGORY_TABLE_VALUEP (x))                               \
221     x = wrong_type_argument (Qcategory_table_value_p, x);       \
222 } while (0)
223
224 #endif                          /* MULE */
225
226 #endif                          /* INCLUDED_chartab_h_ */