Mercurial > emacs
annotate src/charset.c @ 20705:a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
(syms_of_charset): Initialize variable.
(unibyte_char_to_multibyte): New function.
(DEFAULT_NONASCII_INSERT_OFFSET): New macro definition.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 21 Jan 1998 22:06:06 +0000 |
parents | 5ab6701a2b4b |
children | f084bb8d535f |
rev | line source |
---|---|
18341
33e78cc7f058
Change copyright notices.
Richard M. Stallman <rms@gnu.org>
parents:
18003
diff
changeset
|
1 /* Basic multilingual character support. |
20705
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
2 Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN. |
18341
33e78cc7f058
Change copyright notices.
Richard M. Stallman <rms@gnu.org>
parents:
18003
diff
changeset
|
3 Licensed to the Free Software Foundation. |
17052 | 4 |
17071 | 5 This file is part of GNU Emacs. |
6 | |
7 GNU Emacs 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 2, or (at your option) | |
10 any later version. | |
17052 | 11 |
17071 | 12 GNU Emacs 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. | |
17052 | 16 |
17071 | 17 You should have received a copy of the GNU General Public License |
18 along with GNU Emacs; 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. */ | |
17052 | 21 |
22 /* At first, see the document in `charset.h' to understand the code in | |
23 this file. */ | |
24 | |
25 #include <stdio.h> | |
26 | |
27 #ifdef emacs | |
28 | |
29 #include <sys/types.h> | |
30 #include <config.h> | |
31 #include "lisp.h" | |
32 #include "buffer.h" | |
33 #include "charset.h" | |
34 #include "coding.h" | |
17843 | 35 #include "disptab.h" |
17052 | 36 |
37 #else /* not emacs */ | |
38 | |
39 #include "mulelib.h" | |
40 | |
41 #endif /* emacs */ | |
42 | |
43 Lisp_Object Qcharset, Qascii, Qcomposition; | |
44 | |
45 /* Declaration of special leading-codes. */ | |
46 int leading_code_composition; /* for composite characters */ | |
47 int leading_code_private_11; /* for private DIMENSION1 of 1-column */ | |
48 int leading_code_private_12; /* for private DIMENSION1 of 2-column */ | |
49 int leading_code_private_21; /* for private DIMENSION2 of 1-column */ | |
50 int leading_code_private_22; /* for private DIMENSION2 of 2-column */ | |
51 | |
52 /* Declaration of special charsets. */ | |
53 int charset_ascii; /* ASCII */ | |
54 int charset_composition; /* for a composite character */ | |
55 int charset_latin_iso8859_1; /* ISO8859-1 (Latin-1) */ | |
56 int charset_jisx0208_1978; /* JISX0208.1978 (Japanese Kanji old set) */ | |
57 int charset_jisx0208; /* JISX0208.1983 (Japanese Kanji) */ | |
58 int charset_katakana_jisx0201; /* JISX0201.Kana (Japanese Katakana) */ | |
59 int charset_latin_jisx0201; /* JISX0201.Roman (Japanese Roman) */ | |
60 int charset_big5_1; /* Big5 Level 1 (Chinese Traditional) */ | |
61 int charset_big5_2; /* Big5 Level 2 (Chinese Traditional) */ | |
62 | |
63 Lisp_Object Qcharset_table; | |
64 | |
65 /* A char-table containing information of each character set. */ | |
66 Lisp_Object Vcharset_table; | |
67 | |
68 /* A vector of charset symbol indexed by charset-id. This is used | |
69 only for returning charset symbol from C functions. */ | |
70 Lisp_Object Vcharset_symbol_table; | |
71 | |
72 /* A list of charset symbols ever defined. */ | |
73 Lisp_Object Vcharset_list; | |
74 | |
75 /* Tables used by macros BYTES_BY_CHAR_HEAD and WIDTH_BY_CHAR_HEAD. */ | |
76 int bytes_by_char_head[256]; | |
77 int width_by_char_head[256]; | |
78 | |
79 /* Mapping table from ISO2022's charset (specified by DIMENSION, | |
80 CHARS, and FINAL-CHAR) to Emacs' charset. */ | |
81 int iso_charset_table[2][2][128]; | |
82 | |
17186
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
83 /* Table of pointers to the structure `cmpchar_info' indexed by |
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
84 CMPCHAR-ID. */ |
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
85 struct cmpchar_info **cmpchar_table; |
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
86 /* The current size of `cmpchar_table'. */ |
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
87 static int cmpchar_table_size; |
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
88 /* Number of the current composite characters. */ |
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
89 int n_cmpchars; |
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
90 |
17052 | 91 /* Variables used locally in the macro FETCH_MULTIBYTE_CHAR. */ |
92 unsigned char *_fetch_multibyte_char_p; | |
93 int _fetch_multibyte_char_len; | |
94 | |
20705
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
95 /* Offset to add to a non-ASCII value when inserting it. */ |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
96 int nonascii_insert_offset; |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
97 |
19384 | 98 #define min(X, Y) ((X) < (Y) ? (X) : (Y)) |
99 #define max(X, Y) ((X) > (Y) ? (X) : (Y)) | |
100 | |
17052 | 101 /* Set STR a pointer to the multi-byte form of the character C. If C |
102 is not a composite character, the multi-byte form is set in WORKBUF | |
103 and STR points WORKBUF. The caller should allocate at least 4-byte | |
104 area at WORKBUF in advance. Returns the length of the multi-byte | |
17834
e154b943bbba
(non_ascii_char_to_string): Signal error if the
Kenichi Handa <handa@m17n.org>
parents:
17818
diff
changeset
|
105 form. If C is an invalid character to have a multi-byte form, |
e154b943bbba
(non_ascii_char_to_string): Signal error if the
Kenichi Handa <handa@m17n.org>
parents:
17818
diff
changeset
|
106 signal an error. |
17052 | 107 |
108 Use macro `CHAR_STRING (C, WORKBUF, STR)' instead of calling this | |
109 function directly if C can be an ASCII character. */ | |
110 | |
111 int | |
112 non_ascii_char_to_string (c, workbuf, str) | |
113 int c; | |
114 unsigned char *workbuf, **str; | |
115 { | |
17322
a7d9b8e167ca
(non_ascii_char_to_string, update_charset_table,
Kenichi Handa <handa@m17n.org>
parents:
17186
diff
changeset
|
116 int charset, c1, c2; |
17052 | 117 |
118 if (COMPOSITE_CHAR_P (c)) | |
119 { | |
120 int cmpchar_id = COMPOSITE_CHAR_ID (c); | |
121 | |
122 if (cmpchar_id < n_cmpchars) | |
123 { | |
124 *str = cmpchar_table[cmpchar_id]->data; | |
125 return cmpchar_table[cmpchar_id]->len; | |
126 } | |
127 else | |
128 { | |
19025
8d7c6644d2f9
(non_ascii_char_to_string): Fix typos.
Richard M. Stallman <rms@gnu.org>
parents:
18537
diff
changeset
|
129 error ("Invalid character: %d", c); |
17052 | 130 } |
131 } | |
132 | |
133 SPLIT_NON_ASCII_CHAR (c, charset, c1, c2); | |
17834
e154b943bbba
(non_ascii_char_to_string): Signal error if the
Kenichi Handa <handa@m17n.org>
parents:
17818
diff
changeset
|
134 if (!charset |
e154b943bbba
(non_ascii_char_to_string): Signal error if the
Kenichi Handa <handa@m17n.org>
parents:
17818
diff
changeset
|
135 || ! CHARSET_DEFINED_P (charset) |
e154b943bbba
(non_ascii_char_to_string): Signal error if the
Kenichi Handa <handa@m17n.org>
parents:
17818
diff
changeset
|
136 || c1 >= 0 && c1 < 32 |
e154b943bbba
(non_ascii_char_to_string): Signal error if the
Kenichi Handa <handa@m17n.org>
parents:
17818
diff
changeset
|
137 || c2 >= 0 && c2 < 32) |
19025
8d7c6644d2f9
(non_ascii_char_to_string): Fix typos.
Richard M. Stallman <rms@gnu.org>
parents:
18537
diff
changeset
|
138 error ("Invalid character: %d", c); |
17052 | 139 |
140 *str = workbuf; | |
141 *workbuf++ = CHARSET_LEADING_CODE_BASE (charset); | |
142 if (*workbuf = CHARSET_LEADING_CODE_EXT (charset)) | |
143 workbuf++; | |
144 *workbuf++ = c1 | 0x80; | |
17322
a7d9b8e167ca
(non_ascii_char_to_string, update_charset_table,
Kenichi Handa <handa@m17n.org>
parents:
17186
diff
changeset
|
145 if (c2 >= 0) |
17052 | 146 *workbuf++ = c2 | 0x80; |
147 | |
148 return (workbuf - *str); | |
149 } | |
150 | |
151 /* Return a non-ASCII character of which multi-byte form is at STR of | |
152 length LEN. If ACTUAL_LEN is not NULL, the actual length of the | |
153 character is set to the address ACTUAL_LEN. | |
154 | |
155 Use macro `STRING_CHAR (STR, LEN)' instead of calling this function | |
156 directly if STR can hold an ASCII character. */ | |
157 | |
158 string_to_non_ascii_char (str, len, actual_len) | |
159 unsigned char *str; | |
160 int len, *actual_len; | |
161 { | |
162 int charset; | |
163 unsigned char c1, c2; | |
164 register int c; | |
165 | |
166 if (SPLIT_STRING (str, len, charset, c1, c2) == CHARSET_ASCII) | |
167 { | |
168 if (actual_len) | |
169 *actual_len = 1; | |
170 return (int) *str; | |
171 } | |
172 | |
173 c = MAKE_NON_ASCII_CHAR (charset, c1, c2); | |
174 | |
175 if (actual_len) | |
176 *actual_len = (charset == CHARSET_COMPOSITION | |
177 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->len | |
178 : BYTES_BY_CHAR_HEAD (*str)); | |
179 return c; | |
180 } | |
181 | |
182 /* Return the length of the multi-byte form at string STR of length LEN. */ | |
183 int | |
184 multibyte_form_length (str, len) | |
185 unsigned char *str; | |
186 int len; | |
187 { | |
188 int charset; | |
189 unsigned char c1, c2; | |
190 register int c; | |
191 | |
192 if (SPLIT_STRING (str, len, charset, c1, c2) == CHARSET_ASCII) | |
193 return 1; | |
194 | |
195 return (charset == CHARSET_COMPOSITION | |
196 ? cmpchar_table[(c1 << 7) | c2]->len | |
197 : BYTES_BY_CHAR_HEAD (*str)); | |
198 } | |
199 | |
200 /* Check if string STR of length LEN contains valid multi-byte form of | |
201 a character. If valid, charset and position codes of the character | |
202 is set at *CHARSET, *C1, and *C2, and return 0. If not valid, | |
203 return -1. This should be used only in the macro SPLIT_STRING | |
204 which checks range of STR in advance. */ | |
205 | |
206 split_non_ascii_string (str, len, charset, c1, c2) | |
207 register unsigned char *str, *c1, *c2; | |
208 register int len, *charset; | |
209 { | |
210 register unsigned int cs = *str++; | |
211 | |
212 if (cs == LEADING_CODE_COMPOSITION) | |
213 { | |
214 int cmpchar_id = str_cmpchar_id (str - 1, len); | |
215 | |
216 if (cmpchar_id < 0) | |
217 return -1; | |
218 *charset = cs, *c1 = cmpchar_id >> 7, *c2 = cmpchar_id & 0x7F; | |
219 } | |
220 else if ((cs < LEADING_CODE_PRIVATE_11 || (cs = *str++) >= 0xA0) | |
221 && CHARSET_DEFINED_P (cs)) | |
222 { | |
223 *charset = cs; | |
224 if (*str < 0xA0) | |
225 return -1; | |
226 *c1 = (*str++) & 0x7F; | |
227 if (CHARSET_DIMENSION (cs) == 2) | |
228 { | |
229 if (*str < 0xA0) | |
230 return -1; | |
231 *c2 = (*str++) & 0x7F; | |
232 } | |
233 } | |
234 else | |
235 return -1; | |
236 return 0; | |
237 } | |
238 | |
17727
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
239 /* Return a character unified with C (or a character made of CHARSET, |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
240 C1, and C2) in unification table TABLE. If no unification is found |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
241 in TABLE, return C. */ |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
242 unify_char (table, c, charset, c1, c2) |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
243 Lisp_Object table; |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
244 int c, charset, c1, c2; |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
245 { |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
246 Lisp_Object ch; |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
247 int alt_charset, alt_c1, alt_c2, dimension; |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
248 |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
249 if (c < 0) c = MAKE_CHAR (charset, c1, c2); |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
250 if (!CHAR_TABLE_P (table) |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
251 || (ch = Faref (table, make_number (c)), !INTEGERP (ch)) |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
252 || XINT (ch) < 0) |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
253 return c; |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
254 |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
255 SPLIT_CHAR (XFASTINT (ch), alt_charset, alt_c1, alt_c2); |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
256 dimension = CHARSET_DIMENSION (alt_charset); |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
257 if (dimension == 1 && alt_c1 > 0 || dimension == 2 && alt_c2 > 0) |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
258 /* CH is not a generic character, just return it. */ |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
259 return XFASTINT (ch); |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
260 |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
261 /* Since CH is a generic character, we must return a specific |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
262 charater which has the same position codes as C from CH. */ |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
263 if (charset < 0) |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
264 SPLIT_CHAR (c, charset, c1, c2); |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
265 if (dimension != CHARSET_DIMENSION (charset)) |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
266 /* We can't make such a character because of dimension mismatch. */ |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
267 return c; |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
268 if (!alt_c1) alt_c1 = c1; |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
269 if (!alt_c2) alt_c2 = c2; |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
270 return MAKE_CHAR (alt_charset, c1, c2); |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
271 } |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
272 |
20705
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
273 #define DEFAULT_NONASCII_INSERT_OFFSET 0x800 |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
274 |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
275 /* Convert the unibyte character C to multibyte |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
276 based on nonascii_insert_offset. Note that copy_text in insdel.c |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
277 has similar code. */ |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
278 |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
279 int |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
280 unibyte_char_to_multibyte (c) |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
281 int c; |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
282 { |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
283 if (c >= 0200 && c < 0400) |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
284 { |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
285 if (nonascii_insert_offset > 0) |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
286 c += nonascii_insert_offset; |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
287 else |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
288 c += DEFAULT_NONASCII_INSERT_OFFSET; |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
289 } |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
290 return c; |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
291 } |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
292 |
17052 | 293 /* Update the table Vcharset_table with the given arguments (see the |
294 document of `define-charset' for the meaning of each argument). | |
295 Several other table contents are also updated. The caller should | |
296 check the validity of CHARSET-ID and the remaining arguments in | |
297 advance. */ | |
298 | |
299 void | |
300 update_charset_table (charset_id, dimension, chars, width, direction, | |
301 iso_final_char, iso_graphic_plane, | |
302 short_name, long_name, description) | |
303 Lisp_Object charset_id, dimension, chars, width, direction; | |
304 Lisp_Object iso_final_char, iso_graphic_plane; | |
305 Lisp_Object short_name, long_name, description; | |
306 { | |
307 int charset = XINT (charset_id); | |
308 int bytes; | |
309 unsigned char leading_code_base, leading_code_ext; | |
310 | |
17322
a7d9b8e167ca
(non_ascii_char_to_string, update_charset_table,
Kenichi Handa <handa@m17n.org>
parents:
17186
diff
changeset
|
311 if (NILP (CHARSET_TABLE_ENTRY (charset))) |
a7d9b8e167ca
(non_ascii_char_to_string, update_charset_table,
Kenichi Handa <handa@m17n.org>
parents:
17186
diff
changeset
|
312 CHARSET_TABLE_ENTRY (charset) |
a7d9b8e167ca
(non_ascii_char_to_string, update_charset_table,
Kenichi Handa <handa@m17n.org>
parents:
17186
diff
changeset
|
313 = Fmake_vector (make_number (CHARSET_MAX_IDX), Qnil); |
17052 | 314 |
315 /* Get byte length of multibyte form, base leading-code, and | |
316 extended leading-code of the charset. See the comment under the | |
317 title "GENERAL NOTE on CHARACTER SET (CHARSET)" in charset.h. */ | |
318 bytes = XINT (dimension); | |
319 if (charset < MIN_CHARSET_PRIVATE_DIMENSION1) | |
320 { | |
321 /* Official charset, it doesn't have an extended leading-code. */ | |
322 if (charset != CHARSET_ASCII) | |
323 bytes += 1; /* For a base leading-code. */ | |
324 leading_code_base = charset; | |
325 leading_code_ext = 0; | |
326 } | |
327 else | |
328 { | |
329 /* Private charset. */ | |
330 bytes += 2; /* For base and extended leading-codes. */ | |
331 leading_code_base | |
332 = (charset < LEADING_CODE_EXT_12 | |
333 ? LEADING_CODE_PRIVATE_11 | |
334 : (charset < LEADING_CODE_EXT_21 | |
335 ? LEADING_CODE_PRIVATE_12 | |
336 : (charset < LEADING_CODE_EXT_22 | |
337 ? LEADING_CODE_PRIVATE_21 | |
338 : LEADING_CODE_PRIVATE_22))); | |
339 leading_code_ext = charset; | |
340 } | |
341 | |
342 CHARSET_TABLE_INFO (charset, CHARSET_ID_IDX) = charset_id; | |
343 CHARSET_TABLE_INFO (charset, CHARSET_BYTES_IDX) = make_number (bytes); | |
344 CHARSET_TABLE_INFO (charset, CHARSET_DIMENSION_IDX) = dimension; | |
345 CHARSET_TABLE_INFO (charset, CHARSET_CHARS_IDX) = chars; | |
346 CHARSET_TABLE_INFO (charset, CHARSET_WIDTH_IDX) = width; | |
347 CHARSET_TABLE_INFO (charset, CHARSET_DIRECTION_IDX) = direction; | |
348 CHARSET_TABLE_INFO (charset, CHARSET_LEADING_CODE_BASE_IDX) | |
349 = make_number (leading_code_base); | |
350 CHARSET_TABLE_INFO (charset, CHARSET_LEADING_CODE_EXT_IDX) | |
351 = make_number (leading_code_ext); | |
352 CHARSET_TABLE_INFO (charset, CHARSET_ISO_FINAL_CHAR_IDX) = iso_final_char; | |
353 CHARSET_TABLE_INFO (charset, CHARSET_ISO_GRAPHIC_PLANE_IDX) | |
354 = iso_graphic_plane; | |
355 CHARSET_TABLE_INFO (charset, CHARSET_SHORT_NAME_IDX) = short_name; | |
356 CHARSET_TABLE_INFO (charset, CHARSET_LONG_NAME_IDX) = long_name; | |
357 CHARSET_TABLE_INFO (charset, CHARSET_DESCRIPTION_IDX) = description; | |
358 CHARSET_TABLE_INFO (charset, CHARSET_PLIST_IDX) = Qnil; | |
359 | |
360 { | |
361 /* If we have already defined a charset which has the same | |
362 DIMENSION, CHARS and ISO-FINAL-CHAR but the different | |
363 DIRECTION, we must update the entry REVERSE-CHARSET of both | |
364 charsets. If there's no such charset, the value of the entry | |
365 is set to nil. */ | |
366 int i; | |
367 | |
17186
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
368 for (i = 0; i <= MAX_CHARSET; i++) |
17052 | 369 if (!NILP (CHARSET_TABLE_ENTRY (i))) |
370 { | |
371 if (CHARSET_DIMENSION (i) == XINT (dimension) | |
372 && CHARSET_CHARS (i) == XINT (chars) | |
373 && CHARSET_ISO_FINAL_CHAR (i) == XINT (iso_final_char) | |
374 && CHARSET_DIRECTION (i) != XINT (direction)) | |
375 { | |
376 CHARSET_TABLE_INFO (charset, CHARSET_REVERSE_CHARSET_IDX) | |
377 = make_number (i); | |
378 CHARSET_TABLE_INFO (i, CHARSET_REVERSE_CHARSET_IDX) = charset_id; | |
379 break; | |
380 } | |
381 } | |
17186
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
382 if (i > MAX_CHARSET) |
17052 | 383 /* No such a charset. */ |
384 CHARSET_TABLE_INFO (charset, CHARSET_REVERSE_CHARSET_IDX) | |
385 = make_number (-1); | |
386 } | |
387 | |
388 if (charset != CHARSET_ASCII | |
389 && charset < MIN_CHARSET_PRIVATE_DIMENSION1) | |
390 { | |
391 /* Update tables bytes_by_char_head and width_by_char_head. */ | |
392 bytes_by_char_head[leading_code_base] = bytes; | |
393 width_by_char_head[leading_code_base] = XINT (width); | |
394 | |
395 /* Update table emacs_code_class. */ | |
396 emacs_code_class[charset] = (bytes == 2 | |
397 ? EMACS_leading_code_2 | |
398 : (bytes == 3 | |
399 ? EMACS_leading_code_3 | |
400 : EMACS_leading_code_4)); | |
401 } | |
402 | |
403 /* Update table iso_charset_table. */ | |
404 if (ISO_CHARSET_TABLE (dimension, chars, iso_final_char) < 0) | |
405 ISO_CHARSET_TABLE (dimension, chars, iso_final_char) = charset; | |
406 } | |
407 | |
408 #ifdef emacs | |
409 | |
410 /* Return charset id of CHARSET_SYMBOL, or return -1 if CHARSET_SYMBOL | |
411 is invalid. */ | |
412 int | |
413 get_charset_id (charset_symbol) | |
414 Lisp_Object charset_symbol; | |
415 { | |
416 Lisp_Object val; | |
417 int charset; | |
418 | |
419 return ((SYMBOLP (charset_symbol) | |
420 && (val = Fget (charset_symbol, Qcharset), VECTORP (val)) | |
421 && (charset = XINT (XVECTOR (val)->contents[CHARSET_ID_IDX]), | |
422 CHARSET_VALID_P (charset))) | |
423 ? charset : -1); | |
424 } | |
425 | |
426 /* Return an identification number for a new private charset of | |
427 DIMENSION and WIDTH. If there's no more room for the new charset, | |
428 return 0. */ | |
429 Lisp_Object | |
430 get_new_private_charset_id (dimension, width) | |
431 int dimension, width; | |
432 { | |
433 int charset, from, to; | |
434 | |
435 if (dimension == 1) | |
436 { | |
437 if (width == 1) | |
438 from = LEADING_CODE_EXT_11, to = LEADING_CODE_EXT_12; | |
439 else | |
440 from = LEADING_CODE_EXT_12, to = LEADING_CODE_EXT_21; | |
441 } | |
442 else | |
443 { | |
444 if (width == 1) | |
445 from = LEADING_CODE_EXT_21, to = LEADING_CODE_EXT_22; | |
446 else | |
447 from = LEADING_CODE_EXT_22, to = LEADING_CODE_EXT_MAX - 1; | |
448 } | |
449 | |
450 for (charset = from; charset < to; charset++) | |
451 if (!CHARSET_DEFINED_P (charset)) break; | |
452 | |
453 return make_number (charset < to ? charset : 0); | |
454 } | |
455 | |
456 DEFUN ("define-charset", Fdefine_charset, Sdefine_charset, 3, 3, 0, | |
457 "Define CHARSET-ID as the identification number of CHARSET with INFO-VECTOR.\n\ | |
17727
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
458 If CHARSET-ID is nil, it is decided automatically, which means CHARSET is\n\ |
17052 | 459 treated as a private charset.\n\ |
460 INFO-VECTOR is a vector of the format:\n\ | |
461 [DIMENSION CHARS WIDTH DIRECTION ISO-FINAL-CHAR ISO-GRAPHIC-PLANE\n\ | |
462 SHORT-NAME LONG-NAME DESCRIPTION]\n\ | |
463 The meanings of each elements is as follows:\n\ | |
464 DIMENSION (integer) is the number of bytes to represent a character: 1 or 2.\n\ | |
465 CHARS (integer) is the number of characters in a dimension: 94 or 96.\n\ | |
466 WIDTH (integer) is the number of columns a character in the charset\n\ | |
467 occupies on the screen: one of 0, 1, and 2.\n\ | |
468 \n\ | |
469 DIRECTION (integer) is the rendering direction of characters in the\n\ | |
470 charset when rendering. If 0, render from right to left, else\n\ | |
471 render from left to right.\n\ | |
472 \n\ | |
473 ISO-FINAL-CHAR (character) is the final character of the\n\ | |
474 corresponding ISO 2022 charset.\n\ | |
475 \n\ | |
476 ISO-GRAPHIC-PLANE (integer) is the graphic plane to be invoked\n\ | |
477 while encoding to variants of ISO 2022 coding system, one of the\n\ | |
478 following: 0/graphic-plane-left(GL), 1/graphic-plane-right(GR).\n\ | |
479 \n\ | |
480 SHORT-NAME (string) is the short name to refer to the charset.\n\ | |
481 \n\ | |
482 LONG-NAME (string) is the long name to refer to the charset.\n\ | |
483 \n\ | |
484 DESCRIPTION (string) is the description string of the charset.") | |
485 (charset_id, charset_symbol, info_vector) | |
486 Lisp_Object charset_id, charset_symbol, info_vector; | |
487 { | |
488 Lisp_Object *vec; | |
489 | |
490 if (!NILP (charset_id)) | |
491 CHECK_NUMBER (charset_id, 0); | |
492 CHECK_SYMBOL (charset_symbol, 1); | |
493 CHECK_VECTOR (info_vector, 2); | |
494 | |
495 if (! NILP (charset_id)) | |
496 { | |
497 if (! CHARSET_VALID_P (XINT (charset_id))) | |
498 error ("Invalid CHARSET: %d", XINT (charset_id)); | |
499 else if (CHARSET_DEFINED_P (XINT (charset_id))) | |
500 error ("Already defined charset: %d", XINT (charset_id)); | |
501 } | |
502 | |
503 vec = XVECTOR (info_vector)->contents; | |
504 if (XVECTOR (info_vector)->size != 9 | |
505 || !INTEGERP (vec[0]) || !(XINT (vec[0]) == 1 || XINT (vec[0]) == 2) | |
506 || !INTEGERP (vec[1]) || !(XINT (vec[1]) == 94 || XINT (vec[1]) == 96) | |
507 || !INTEGERP (vec[2]) || !(XINT (vec[2]) == 1 || XINT (vec[2]) == 2) | |
508 || !INTEGERP (vec[3]) || !(XINT (vec[3]) == 0 || XINT (vec[3]) == 1) | |
509 || !INTEGERP (vec[4]) || !(XINT (vec[4]) >= '0' && XINT (vec[4]) <= '~') | |
510 || !INTEGERP (vec[5]) || !(XINT (vec[5]) == 0 || XINT (vec[5]) == 1) | |
511 || !STRINGP (vec[6]) | |
512 || !STRINGP (vec[7]) | |
513 || !STRINGP (vec[8])) | |
514 error ("Invalid info-vector argument for defining charset %s", | |
515 XSYMBOL (charset_symbol)->name->data); | |
516 | |
517 if (NILP (charset_id)) | |
518 { | |
519 charset_id = get_new_private_charset_id (XINT (vec[0]), XINT (vec[2])); | |
520 if (XINT (charset_id) == 0) | |
521 error ("There's no room for a new private charset %s", | |
522 XSYMBOL (charset_symbol)->name->data); | |
523 } | |
524 | |
525 update_charset_table (charset_id, vec[0], vec[1], vec[2], vec[3], | |
526 vec[4], vec[5], vec[6], vec[7], vec[8]); | |
17322
a7d9b8e167ca
(non_ascii_char_to_string, update_charset_table,
Kenichi Handa <handa@m17n.org>
parents:
17186
diff
changeset
|
527 Fput (charset_symbol, Qcharset, CHARSET_TABLE_ENTRY (XINT (charset_id))); |
17052 | 528 CHARSET_SYMBOL (XINT (charset_id)) = charset_symbol; |
529 Vcharset_list = Fcons (charset_symbol, Vcharset_list); | |
530 return Qnil; | |
531 } | |
532 | |
20435
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
533 DEFUN ("get-unused-iso-final-char", Fget_unused_iso_final_char, |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
534 Sget_unused_iso_final_char, 2, 2, 0, |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
535 "Return an unsed ISO's final char for a charset of DIMENISION and CHARS.\n\ |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
536 DIMENSION is the number of bytes to represent a character: 1 or 2.\n\ |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
537 CHARS is the number of characters in a dimension: 94 or 96.\n\ |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
538 \n\ |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
539 This final char is for private use, thus the range is `0' (48) .. `?' (63).\n\ |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
540 If there's no unused final char for the specified kind of charset,\n\ |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
541 return nil.") |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
542 (dimension, chars) |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
543 Lisp_Object dimension, chars; |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
544 { |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
545 int final_char; |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
546 |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
547 CHECK_NUMBER (dimension, 0); |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
548 CHECK_NUMBER (chars, 1); |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
549 if (XINT (dimension) != 1 && XINT (dimension) != 2) |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
550 error ("Invalid charset dimension %d, it should be 1 or 2", |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
551 XINT (dimension)); |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
552 if (XINT (chars) != 94 && XINT (chars) != 96) |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
553 error ("Invalid charset chars %d, it should be 94 or 96", |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
554 XINT (chars)); |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
555 for (final_char = '0'; final_char <= '?'; final_char++) |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
556 { |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
557 if (ISO_CHARSET_TABLE (dimension, chars, make_number (final_char)) < 0) |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
558 break; |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
559 } |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
560 return (final_char <= '?' ? make_number (final_char) : Qnil); |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
561 } |
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
562 |
17052 | 563 DEFUN ("declare-equiv-charset", Fdeclare_equiv_charset, Sdeclare_equiv_charset, |
564 4, 4, 0, | |
565 "Declare a charset of DIMENSION, CHARS, FINAL-CHAR is the same as CHARSET.\n\ | |
566 CHARSET should be defined by `defined-charset' in advance.") | |
567 (dimension, chars, final_char, charset_symbol) | |
568 Lisp_Object dimension, chars, final_char, charset_symbol; | |
569 { | |
570 int charset; | |
571 | |
572 CHECK_NUMBER (dimension, 0); | |
573 CHECK_NUMBER (chars, 1); | |
574 CHECK_NUMBER (final_char, 2); | |
575 CHECK_SYMBOL (charset_symbol, 3); | |
576 | |
577 if (XINT (dimension) != 1 && XINT (dimension) != 2) | |
578 error ("Invalid DIMENSION %d, it should be 1 or 2", XINT (dimension)); | |
579 if (XINT (chars) != 94 && XINT (chars) != 96) | |
580 error ("Invalid CHARS %d, it should be 94 or 96", XINT (chars)); | |
581 if (XINT (final_char) < '0' || XFASTINT (final_char) > '~') | |
582 error ("Invalid FINAL-CHAR %c, it should be `0'..`~'", XINT (chars)); | |
583 if ((charset = get_charset_id (charset_symbol)) < 0) | |
584 error ("Invalid charset %s", XSYMBOL (charset_symbol)->name->data); | |
585 | |
586 ISO_CHARSET_TABLE (dimension, chars, final_char) = charset; | |
587 return Qnil; | |
588 } | |
589 | |
590 /* Return number of different charsets in STR of length LEN. In | |
591 addition, for each found charset N, CHARSETS[N] is set 1. The | |
18003
ac148c939dec
(Ffind_charset_string): The variable CHARSETS is
Kenichi Handa <handa@m17n.org>
parents:
17880
diff
changeset
|
592 caller should allocate CHARSETS (MAX_CHARSET + 1 elements) in advance. |
17727
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
593 It may lookup a unification table TABLE if supplied. */ |
17052 | 594 |
595 int | |
17727
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
596 find_charset_in_str (str, len, charsets, table) |
17880
06f58d8a59ba
(Ffind_charset_region): Change the declaration of
Kenichi Handa <handa@m17n.org>
parents:
17863
diff
changeset
|
597 unsigned char *str; |
06f58d8a59ba
(Ffind_charset_region): Change the declaration of
Kenichi Handa <handa@m17n.org>
parents:
17863
diff
changeset
|
598 int len, *charsets; |
17727
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
599 Lisp_Object table; |
17052 | 600 { |
20228
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
601 register int num = 0, c; |
17052 | 602 |
17727
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
603 if (! CHAR_TABLE_P (table)) |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
604 table = Qnil; |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
605 |
17052 | 606 while (len > 0) |
607 { | |
19983
a62008636710
(find_charset_in_str): Return also charsets in
Kenichi Handa <handa@m17n.org>
parents:
19444
diff
changeset
|
608 int bytes, charset; |
20228
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
609 c = *str; |
17727
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
610 |
20228
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
611 if (c == LEADING_CODE_COMPOSITION) |
19983
a62008636710
(find_charset_in_str): Return also charsets in
Kenichi Handa <handa@m17n.org>
parents:
19444
diff
changeset
|
612 { |
20228
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
613 int cmpchar_id = str_cmpchar_id (str, len); |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
614 GLYPH *glyph; |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
615 |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
616 if (cmpchar_id > 0) |
19983
a62008636710
(find_charset_in_str): Return also charsets in
Kenichi Handa <handa@m17n.org>
parents:
19444
diff
changeset
|
617 { |
20228
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
618 struct cmpchar_info *cmpcharp = cmpchar_table[cmpchar_id]; |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
619 int i; |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
620 |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
621 for (i = 0; i < cmpcharp->glyph_len; i++) |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
622 { |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
623 c = cmpcharp->glyph[i]; |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
624 if (!NILP (table)) |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
625 { |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
626 if ((c = unify_char (table, c, 0, 0, 0)) < 0) |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
627 c = cmpcharp->glyph[i]; |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
628 } |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
629 if ((charset = CHAR_CHARSET (c)) < 0) |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
630 charset = CHARSET_ASCII; |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
631 if (!charsets[charset]) |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
632 { |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
633 charsets[charset] = 1; |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
634 num += 1; |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
635 } |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
636 } |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
637 str += cmpcharp->len; |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
638 len -= cmpcharp->len; |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
639 continue; |
19983
a62008636710
(find_charset_in_str): Return also charsets in
Kenichi Handa <handa@m17n.org>
parents:
19444
diff
changeset
|
640 } |
20228
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
641 |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
642 charset = CHARSET_ASCII; |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
643 bytes = 1; |
19983
a62008636710
(find_charset_in_str): Return also charsets in
Kenichi Handa <handa@m17n.org>
parents:
19444
diff
changeset
|
644 } |
a62008636710
(find_charset_in_str): Return also charsets in
Kenichi Handa <handa@m17n.org>
parents:
19444
diff
changeset
|
645 else |
17727
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
646 { |
20228
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
647 c = STRING_CHAR_AND_LENGTH (str, len, bytes); |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
648 if (! NILP (table)) |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
649 { |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
650 int c1 = unify_char (table, c, 0, 0, 0); |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
651 if (c1 >= 0) |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
652 c = c1; |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
653 } |
acb7aa0aa71f
(find_charset_in_str): Handle the case that STR
Kenichi Handa <handa@m17n.org>
parents:
20188
diff
changeset
|
654 charset = CHAR_CHARSET (c); |
17727
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
655 } |
17052 | 656 |
657 if (!charsets[charset]) | |
658 { | |
659 charsets[charset] = 1; | |
660 num += 1; | |
661 } | |
662 str += bytes; | |
663 len -= bytes; | |
664 } | |
665 return num; | |
666 } | |
667 | |
668 DEFUN ("find-charset-region", Ffind_charset_region, Sfind_charset_region, | |
17727
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
669 2, 3, 0, |
17052 | 670 "Return a list of charsets in the region between BEG and END.\n\ |
17727
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
671 BEG and END are buffer positions.\n\ |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
672 Optional arg TABLE if non-nil is a unification table to look up.") |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
673 (beg, end, table) |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
674 Lisp_Object beg, end, table; |
17052 | 675 { |
17880
06f58d8a59ba
(Ffind_charset_region): Change the declaration of
Kenichi Handa <handa@m17n.org>
parents:
17863
diff
changeset
|
676 int charsets[MAX_CHARSET + 1]; |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
677 int from, from_byte, to, stop, stop_byte, i; |
17052 | 678 Lisp_Object val; |
679 | |
680 validate_region (&beg, &end); | |
681 from = XFASTINT (beg); | |
682 stop = to = XFASTINT (end); | |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
683 |
17052 | 684 if (from < GPT && GPT < to) |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
685 { |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
686 stop = GPT; |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
687 stop_byte = GPT_BYTE; |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
688 } |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
689 else |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
690 stop_byte = CHAR_TO_BYTE (stop); |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
691 |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
692 from_byte = CHAR_TO_BYTE (from); |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
693 |
17880
06f58d8a59ba
(Ffind_charset_region): Change the declaration of
Kenichi Handa <handa@m17n.org>
parents:
17863
diff
changeset
|
694 bzero (charsets, (MAX_CHARSET + 1) * sizeof (int)); |
17052 | 695 while (1) |
696 { | |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
697 find_charset_in_str (BYTE_POS_ADDR (from_byte), stop_byte - from_byte, |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
698 charsets, table); |
17052 | 699 if (stop < to) |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
700 { |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
701 from = stop, from_byte = stop_byte; |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
702 stop = to, stop_byte = CHAR_TO_BYTE (stop); |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
703 } |
17052 | 704 else |
705 break; | |
706 } | |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
707 |
17052 | 708 val = Qnil; |
17186
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
709 for (i = MAX_CHARSET; i >= 0; i--) |
17052 | 710 if (charsets[i]) |
711 val = Fcons (CHARSET_SYMBOL (i), val); | |
712 return val; | |
713 } | |
714 | |
715 DEFUN ("find-charset-string", Ffind_charset_string, Sfind_charset_string, | |
17727
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
716 1, 2, 0, |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
717 "Return a list of charsets in STR.\n\ |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
718 Optional arg TABLE if non-nil is a unification table to look up.") |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
719 (str, table) |
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
720 Lisp_Object str, table; |
17052 | 721 { |
18003
ac148c939dec
(Ffind_charset_string): The variable CHARSETS is
Kenichi Handa <handa@m17n.org>
parents:
17880
diff
changeset
|
722 int charsets[MAX_CHARSET + 1]; |
17052 | 723 int i; |
724 Lisp_Object val; | |
725 | |
726 CHECK_STRING (str, 0); | |
20614
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
727 |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
728 if (! STRING_MULTIBYTE (str)) |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
729 return Qnil; |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
730 |
18003
ac148c939dec
(Ffind_charset_string): The variable CHARSETS is
Kenichi Handa <handa@m17n.org>
parents:
17880
diff
changeset
|
731 bzero (charsets, (MAX_CHARSET + 1) * sizeof (int)); |
20614
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
732 find_charset_in_str (XSTRING (str)->data, XSTRING (str)->size_byte, |
17727
9d39361ce928
(unify_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
17366
diff
changeset
|
733 charsets, table); |
17052 | 734 val = Qnil; |
17186
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
735 for (i = MAX_CHARSET; i >= 0; i--) |
17052 | 736 if (charsets[i]) |
737 val = Fcons (CHARSET_SYMBOL (i), val); | |
738 return val; | |
739 } | |
740 | |
741 DEFUN ("make-char-internal", Fmake_char_internal, Smake_char_internal, 1, 3, 0, | |
17186
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
742 "") |
17052 | 743 (charset, code1, code2) |
744 Lisp_Object charset, code1, code2; | |
745 { | |
746 CHECK_NUMBER (charset, 0); | |
747 | |
748 if (NILP (code1)) | |
749 XSETFASTINT (code1, 0); | |
750 else | |
751 CHECK_NUMBER (code1, 1); | |
752 if (NILP (code2)) | |
753 XSETFASTINT (code2, 0); | |
754 else | |
755 CHECK_NUMBER (code2, 2); | |
756 | |
757 if (!CHARSET_DEFINED_P (XINT (charset))) | |
758 error ("Invalid charset: %d", XINT (charset)); | |
759 | |
760 return make_number (MAKE_CHAR (XINT (charset), XINT (code1), XINT (code2))); | |
761 } | |
762 | |
763 DEFUN ("split-char", Fsplit_char, Ssplit_char, 1, 1, 0, | |
764 "Return list of charset and one or two position-codes of CHAR.") | |
765 (ch) | |
766 Lisp_Object ch; | |
767 { | |
768 Lisp_Object val; | |
17322
a7d9b8e167ca
(non_ascii_char_to_string, update_charset_table,
Kenichi Handa <handa@m17n.org>
parents:
17186
diff
changeset
|
769 int charset, c1, c2; |
17052 | 770 |
771 CHECK_NUMBER (ch, 0); | |
772 SPLIT_CHAR (XFASTINT (ch), charset, c1, c2); | |
17322
a7d9b8e167ca
(non_ascii_char_to_string, update_charset_table,
Kenichi Handa <handa@m17n.org>
parents:
17186
diff
changeset
|
773 return (c2 >= 0 |
17052 | 774 ? Fcons (CHARSET_SYMBOL (charset), |
775 Fcons (make_number (c1), Fcons (make_number (c2), Qnil))) | |
776 : Fcons (CHARSET_SYMBOL (charset), Fcons (make_number (c1), Qnil))); | |
777 } | |
778 | |
779 DEFUN ("char-charset", Fchar_charset, Schar_charset, 1, 1, 0, | |
780 "Return charset of CHAR.") | |
781 (ch) | |
782 Lisp_Object ch; | |
783 { | |
784 CHECK_NUMBER (ch, 0); | |
785 | |
786 return CHARSET_SYMBOL (CHAR_CHARSET (XINT (ch))); | |
787 } | |
788 | |
789 DEFUN ("iso-charset", Fiso_charset, Siso_charset, 3, 3, 0, | |
790 "Return charset of ISO's specification DIMENSION, CHARS, and FINAL-CHAR.") | |
791 (dimension, chars, final_char) | |
792 Lisp_Object dimension, chars, final_char; | |
793 { | |
794 int charset; | |
795 | |
796 CHECK_NUMBER (dimension, 0); | |
797 CHECK_NUMBER (chars, 1); | |
798 CHECK_NUMBER (final_char, 2); | |
799 | |
800 if ((charset = ISO_CHARSET_TABLE (dimension, chars, final_char)) < 0) | |
801 return Qnil; | |
802 return CHARSET_SYMBOL (charset); | |
803 } | |
804 | |
20152
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
805 /* If GENERICP is nonzero, return nonzero iff C is a valid normal or |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
806 generic character. If GENERICP is zero, return nonzero iff C is a |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
807 valid normal character. Do not call this function directly, |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
808 instead use macro CHAR_VALID_P. */ |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
809 int |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
810 char_valid_p (c, genericp) |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
811 int c, genericp; |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
812 { |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
813 int charset, c1, c2; |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
814 |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
815 if (c < 0) |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
816 return 0; |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
817 if (SINGLE_BYTE_CHAR_P (c)) |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
818 return 1; |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
819 SPLIT_NON_ASCII_CHAR (c, charset, c1, c2); |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
820 if (!CHARSET_VALID_P (charset)) |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
821 return 0; |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
822 return (c < MIN_CHAR_COMPOSITION |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
823 ? ((c & CHAR_FIELD1_MASK) /* i.e. dimension of C is two. */ |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
824 ? (genericp && c1 == 0 && c2 == 0 |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
825 || c1 >= 32 && c2 >= 32) |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
826 : (genericp && c1 == 0 |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
827 || c1 >= 32)) |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
828 : c < MIN_CHAR_COMPOSITION + n_cmpchars); |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
829 } |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
830 |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
831 DEFUN ("char-valid-p", Fchar_valid_p, Schar_valid_p, 1, 2, 0, |
20636
5ab6701a2b4b
(Fchar_valid_p): Fix bare newlines in doc string.
Dave Love <fx@gnu.org>
parents:
20614
diff
changeset
|
832 "Return t if OBJECT is a valid normal character.\n\ |
5ab6701a2b4b
(Fchar_valid_p): Fix bare newlines in doc string.
Dave Love <fx@gnu.org>
parents:
20614
diff
changeset
|
833 If optional arg GENERICP is non-nil, also return t if OBJECT is\n\ |
20152
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
834 a valid generic character.") |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
835 (object, genericp) |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
836 Lisp_Object object, genericp; |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
837 { |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
838 if (! NATNUMP (object)) |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
839 return Qnil; |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
840 return (CHAR_VALID_P (XFASTINT (object), !NILP (genericp)) ? Qt : Qnil); |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
841 } |
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
842 |
17052 | 843 DEFUN ("char-bytes", Fchar_bytes, Schar_bytes, 1, 1, 0, |
844 "Return byte length of multi-byte form of CHAR.") | |
845 (ch) | |
846 Lisp_Object ch; | |
847 { | |
848 Lisp_Object val; | |
849 int bytes; | |
850 | |
851 CHECK_NUMBER (ch, 0); | |
852 if (COMPOSITE_CHAR_P (XFASTINT (ch))) | |
853 { | |
854 unsigned int id = COMPOSITE_CHAR_ID (XFASTINT (ch)); | |
855 | |
856 bytes = (id < n_cmpchars ? cmpchar_table[id]->len : 1); | |
857 } | |
858 else | |
859 { | |
860 int charset = CHAR_CHARSET (XFASTINT (ch)); | |
861 | |
862 bytes = CHARSET_DEFINED_P (charset) ? CHARSET_BYTES (charset) : 1; | |
863 } | |
864 | |
865 XSETFASTINT (val, bytes); | |
866 return val; | |
867 } | |
868 | |
869 /* Return the width of character of which multi-byte form starts with | |
870 C. The width is measured by how many columns occupied on the | |
871 screen when displayed in the current buffer. */ | |
872 | |
873 #define ONE_BYTE_CHAR_WIDTH(c) \ | |
874 (c < 0x20 \ | |
875 ? (c == '\t' \ | |
17366
f7809ff2c65f
(ONE_BYTE_CHAR_WIDTH, Fconcat_chars): Don't use Lisp_Object as integer.
Karl Heuer <kwzh@gnu.org>
parents:
17322
diff
changeset
|
876 ? XFASTINT (current_buffer->tab_width) \ |
17052 | 877 : (c == '\n' ? 0 : (NILP (current_buffer->ctl_arrow) ? 4 : 2))) \ |
878 : (c < 0x7f \ | |
879 ? 1 \ | |
880 : (c == 0x7F \ | |
881 ? (NILP (current_buffer->ctl_arrow) ? 4 : 2) \ | |
882 : ((! NILP (current_buffer->enable_multibyte_characters) \ | |
883 && BASE_LEADING_CODE_P (c)) \ | |
884 ? WIDTH_BY_CHAR_HEAD (c) \ | |
885 : 4)))) \ | |
886 | |
887 | |
888 DEFUN ("char-width", Fchar_width, Schar_width, 1, 1, 0, | |
889 "Return width of CHAR when displayed in the current buffer.\n\ | |
890 The width is measured by how many columns it occupies on the screen.") | |
891 (ch) | |
892 Lisp_Object ch; | |
893 { | |
17818
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
894 Lisp_Object val, disp; |
17052 | 895 int c; |
18537
6a726658dfa9
(Fchar_width): Check if the current buffer has display
Kenichi Handa <handa@m17n.org>
parents:
18341
diff
changeset
|
896 struct Lisp_Char_Table *dp = buffer_display_table (); |
17052 | 897 |
898 CHECK_NUMBER (ch, 0); | |
899 | |
17818
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
900 c = XINT (ch); |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
901 |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
902 /* Get the way the display table would display it. */ |
18537
6a726658dfa9
(Fchar_width): Check if the current buffer has display
Kenichi Handa <handa@m17n.org>
parents:
18341
diff
changeset
|
903 disp = dp ? DISP_CHAR_VECTOR (dp, c) : Qnil; |
17818
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
904 |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
905 if (VECTORP (disp)) |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
906 XSETINT (val, XVECTOR (disp)->size); |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
907 else if (SINGLE_BYTE_CHAR_P (c)) |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
908 XSETINT (val, ONE_BYTE_CHAR_WIDTH (c)); |
17052 | 909 else if (COMPOSITE_CHAR_P (c)) |
910 { | |
911 int id = COMPOSITE_CHAR_ID (XFASTINT (ch)); | |
912 XSETFASTINT (val, (id < n_cmpchars ? cmpchar_table[id]->width : 0)); | |
913 } | |
914 else | |
915 { | |
916 int charset = CHAR_CHARSET (c); | |
917 | |
918 XSETFASTINT (val, CHARSET_WIDTH (charset)); | |
919 } | |
920 return val; | |
921 } | |
922 | |
923 /* Return width of string STR of length LEN when displayed in the | |
924 current buffer. The width is measured by how many columns it | |
925 occupies on the screen. */ | |
17818
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
926 |
17052 | 927 int |
928 strwidth (str, len) | |
929 unsigned char *str; | |
930 int len; | |
931 { | |
932 unsigned char *endp = str + len; | |
933 int width = 0; | |
20362
67bcb068070c
(strwidth): Remove extra argument to buffer_display_table.
Kenichi Handa <handa@m17n.org>
parents:
20228
diff
changeset
|
934 struct Lisp_Char_Table *dp = buffer_display_table (); |
17052 | 935 |
17818
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
936 while (str < endp) |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
937 { |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
938 if (*str == LEADING_CODE_COMPOSITION) |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
939 { |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
940 int id = str_cmpchar_id (str, endp - str); |
17052 | 941 |
17818
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
942 if (id < 0) |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
943 { |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
944 width += 4; |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
945 str++; |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
946 } |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
947 else |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
948 { |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
949 width += cmpchar_table[id]->width; |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
950 str += cmpchar_table[id]->len; |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
951 } |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
952 } |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
953 else |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
954 { |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
955 Lisp_Object disp; |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
956 int thiswidth; |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
957 int c = STRING_CHAR (str, endp - str); |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
958 |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
959 /* Get the way the display table would display it. */ |
17863
bc8774c7999b
(strwidth): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17843
diff
changeset
|
960 if (dp) |
bc8774c7999b
(strwidth): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17843
diff
changeset
|
961 disp = DISP_CHAR_VECTOR (dp, c); |
bc8774c7999b
(strwidth): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17843
diff
changeset
|
962 else |
bc8774c7999b
(strwidth): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
17843
diff
changeset
|
963 disp = Qnil; |
17818
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
964 |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
965 if (VECTORP (disp)) |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
966 thiswidth = XVECTOR (disp)->size; |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
967 else |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
968 thiswidth = ONE_BYTE_CHAR_WIDTH (*str); |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
969 |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
970 width += thiswidth; |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
971 str += BYTES_BY_CHAR_HEAD (*str); |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
972 } |
76c6740bd736
(strwidth, Fchar_width): Handle display table.
Richard M. Stallman <rms@gnu.org>
parents:
17727
diff
changeset
|
973 } |
17052 | 974 return width; |
975 } | |
976 | |
977 DEFUN ("string-width", Fstring_width, Sstring_width, 1, 1, 0, | |
978 "Return width of STRING when displayed in the current buffer.\n\ | |
979 Width is measured by how many columns it occupies on the screen.\n\ | |
19384 | 980 When calculating width of a multibyte character in STRING,\n\ |
981 only the base leading-code is considered; the validity of\n\ | |
982 the following bytes is not checked.") | |
17052 | 983 (str) |
984 Lisp_Object str; | |
985 { | |
986 Lisp_Object val; | |
987 | |
988 CHECK_STRING (str, 0); | |
989 XSETFASTINT (val, strwidth (XSTRING (str)->data, XSTRING (str)->size)); | |
990 return val; | |
991 } | |
992 | |
993 DEFUN ("char-direction", Fchar_direction, Schar_direction, 1, 1, 0, | |
994 "Return the direction of CHAR.\n\ | |
995 The returned value is 0 for left-to-right and 1 for right-to-left.") | |
996 (ch) | |
997 Lisp_Object ch; | |
998 { | |
999 int charset; | |
1000 | |
1001 CHECK_NUMBER (ch, 0); | |
1002 charset = CHAR_CHARSET (XFASTINT (ch)); | |
1003 if (!CHARSET_DEFINED_P (charset)) | |
1004 error ("Invalid character: %d", XINT (ch)); | |
1005 return CHARSET_TABLE_INFO (charset, CHARSET_DIRECTION_IDX); | |
1006 } | |
1007 | |
19415
309b9a0d8a45
(Fchars_in_region): Renamed form Fcount_chars_region.
Kenichi Handa <handa@m17n.org>
parents:
19384
diff
changeset
|
1008 DEFUN ("chars-in-region", Fchars_in_region, Schars_in_region, 2, 2, 0, |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1009 "Return number of characters between BEG and END.") |
19384 | 1010 (beg, end) |
1011 Lisp_Object beg, end; | |
1012 { | |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1013 int from, to; |
19384 | 1014 |
1015 from = min (XFASTINT (beg), XFASTINT (end)); | |
19444
752afe97eaa4
(Fchars_in_region): Fix gap handling.
Richard M. Stallman <rms@gnu.org>
parents:
19415
diff
changeset
|
1016 to = max (XFASTINT (beg), XFASTINT (end)); |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1017 |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1018 return to - from; |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1019 } |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1020 |
20614
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1021 /* Return the number of characters in the NBYTES bytes at PTR. |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1022 This works by looking at the contents and checking for multibyte sequences. |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1023 However, if the current buffer has enable-multibyte-characters = nil, |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1024 we treat each byte as a character. */ |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1025 |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1026 int |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1027 chars_in_text (ptr, nbytes) |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1028 unsigned char *ptr; |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1029 int nbytes; |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1030 { |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1031 unsigned char *endp; |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1032 int chars; |
19384 | 1033 |
20614
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1034 /* current_buffer is null at early stages of Emacs initialization. */ |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1035 if (current_buffer == 0 |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1036 || NILP (current_buffer->enable_multibyte_characters)) |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1037 return nbytes; |
20188
d4ad4463384d
(Fchars_in_string): Pay attention to
Kenichi Handa <handa@m17n.org>
parents:
20152
diff
changeset
|
1038 |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1039 endp = ptr + nbytes; |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1040 chars = 0; |
19384 | 1041 |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1042 while (ptr < endp) |
19384 | 1043 { |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1044 if (*ptr == LEADING_CODE_COMPOSITION) |
19384 | 1045 { |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1046 ptr++; |
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1047 while (ptr < endp && ! CHAR_HEAD_P (*ptr)) ptr++; |
19384 | 1048 } |
1049 else | |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1050 ptr += BYTES_BY_CHAR_HEAD (*ptr); |
19384 | 1051 chars++; |
1052 } | |
1053 | |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1054 return chars; |
19384 | 1055 } |
1056 | |
20614
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1057 /* Return the number of characters in the NBYTES bytes at PTR. |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1058 This works by looking at the contents and checking for multibyte sequences. |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1059 It ignores enable-multibyte-characters. */ |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1060 |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1061 int |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1062 multibyte_chars_in_text (ptr, nbytes) |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1063 unsigned char *ptr; |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1064 int nbytes; |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1065 { |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1066 unsigned char *endp; |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1067 int chars; |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1068 |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1069 endp = ptr + nbytes; |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1070 chars = 0; |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1071 |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1072 while (ptr < endp) |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1073 { |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1074 if (*ptr == LEADING_CODE_COMPOSITION) |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1075 { |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1076 ptr++; |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1077 while (ptr < endp && ! CHAR_HEAD_P (*ptr)) ptr++; |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1078 } |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1079 else |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1080 ptr += BYTES_BY_CHAR_HEAD (*ptr); |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1081 chars++; |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1082 } |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1083 |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1084 return chars; |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1085 } |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1086 |
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1087 DEFUN ("string", Fstring, Sstring, 1, MANY, 0, |
17052 | 1088 "Concatenate all the argument characters and make the result a string.") |
17366
f7809ff2c65f
(ONE_BYTE_CHAR_WIDTH, Fconcat_chars): Don't use Lisp_Object as integer.
Karl Heuer <kwzh@gnu.org>
parents:
17322
diff
changeset
|
1089 (n, args) |
f7809ff2c65f
(ONE_BYTE_CHAR_WIDTH, Fconcat_chars): Don't use Lisp_Object as integer.
Karl Heuer <kwzh@gnu.org>
parents:
17322
diff
changeset
|
1090 int n; |
17052 | 1091 Lisp_Object *args; |
1092 { | |
17366
f7809ff2c65f
(ONE_BYTE_CHAR_WIDTH, Fconcat_chars): Don't use Lisp_Object as integer.
Karl Heuer <kwzh@gnu.org>
parents:
17322
diff
changeset
|
1093 int i; |
17052 | 1094 unsigned char *buf |
17834
e154b943bbba
(non_ascii_char_to_string): Signal error if the
Kenichi Handa <handa@m17n.org>
parents:
17818
diff
changeset
|
1095 = (unsigned char *) alloca (MAX_LENGTH_OF_MULTI_BYTE_FORM * n); |
17052 | 1096 unsigned char *p = buf; |
1097 Lisp_Object val; | |
1098 | |
1099 for (i = 0; i < n; i++) | |
1100 { | |
1101 int c, len; | |
1102 unsigned char *str; | |
1103 | |
1104 if (!INTEGERP (args[i])) | |
1105 { | |
1106 free (buf); | |
1107 CHECK_NUMBER (args[i], 0); | |
1108 } | |
1109 c = XINT (args[i]); | |
1110 len = CHAR_STRING (c, p, str); | |
1111 if (p != str) | |
1112 /* C is a composite character. */ | |
1113 bcopy (str, p, len); | |
1114 p += len; | |
1115 } | |
1116 | |
20614
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1117 val = make_multibyte_string (buf, n, p - buf); |
17052 | 1118 return val; |
1119 } | |
1120 | |
1121 #endif /* emacs */ | |
1122 | |
1123 /*** Composite characters staffs ***/ | |
1124 | |
1125 /* Each composite character is identified by CMPCHAR-ID which is | |
1126 assigned when Emacs needs the character code of the composite | |
1127 character (e.g. when displaying it on the screen). See the | |
1128 document "GENERAL NOTE on COMPOSITE CHARACTER" in `charset.h' how a | |
1129 composite character is represented in Emacs. */ | |
1130 | |
1131 /* If `static' is defined, it means that it is defined to null string. */ | |
1132 #ifndef static | |
1133 /* The following function is copied from lread.c. */ | |
1134 static int | |
1135 hash_string (ptr, len) | |
1136 unsigned char *ptr; | |
1137 int len; | |
1138 { | |
1139 register unsigned char *p = ptr; | |
1140 register unsigned char *end = p + len; | |
1141 register unsigned char c; | |
1142 register int hash = 0; | |
1143 | |
1144 while (p != end) | |
1145 { | |
1146 c = *p++; | |
1147 if (c >= 0140) c -= 40; | |
1148 hash = ((hash<<3) + (hash>>28) + c); | |
1149 } | |
1150 return hash & 07777777777; | |
1151 } | |
1152 #endif | |
1153 | |
1154 #define CMPCHAR_HASH_TABLE_SIZE 0xFFF | |
1155 | |
1156 static int *cmpchar_hash_table[CMPCHAR_HASH_TABLE_SIZE]; | |
1157 | |
1158 /* Each element of `cmpchar_hash_table' is a pointer to an array of | |
1159 integer, where the 1st element is the size of the array, the 2nd | |
1160 element is how many elements are actually used in the array, and | |
1161 the remaining elements are CMPCHAR-IDs of composite characters of | |
1162 the same hash value. */ | |
1163 #define CMPCHAR_HASH_SIZE(table) table[0] | |
1164 #define CMPCHAR_HASH_USED(table) table[1] | |
1165 #define CMPCHAR_HASH_CMPCHAR_ID(table, i) table[i] | |
1166 | |
1167 /* Return CMPCHAR-ID of the composite character in STR of the length | |
1168 LEN. If the composite character has not yet been registered, | |
1169 register it in `cmpchar_table' and assign new CMPCHAR-ID. This | |
1170 is the sole function for assigning CMPCHAR-ID. */ | |
1171 int | |
1172 str_cmpchar_id (str, len) | |
1173 unsigned char *str; | |
1174 int len; | |
1175 { | |
1176 int hash_idx, *hashp; | |
1177 unsigned char *buf; | |
1178 int embedded_rule; /* 1 if composition rule is embedded. */ | |
1179 int chars; /* number of components. */ | |
1180 int i; | |
1181 struct cmpchar_info *cmpcharp; | |
1182 | |
1183 if (len < 5) | |
1184 /* Any composite char have at least 3-byte length. */ | |
1185 return -1; | |
1186 | |
1187 /* The second byte 0xFF means compostion rule is embedded. */ | |
1188 embedded_rule = (str[1] == 0xFF); | |
1189 | |
1190 /* At first, get the actual length of the composite character. */ | |
1191 { | |
1192 unsigned char *p, *endp = str + 1, *lastp = str + len; | |
1193 int bytes; | |
1194 | |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1195 while (endp < lastp && ! CHAR_HEAD_P (*endp)) endp++; |
17052 | 1196 chars = 0; |
1197 p = str + 1 + embedded_rule; | |
1198 while (p < endp) | |
1199 { | |
1200 /* No need of checking if *P is 0xA0 because | |
1201 BYTES_BY_CHAR_HEAD (0x80) surely returns 2. */ | |
1202 p += (bytes = BYTES_BY_CHAR_HEAD (*p - 0x20) + embedded_rule); | |
1203 chars++; | |
1204 } | |
1205 len = (p -= embedded_rule) - str; | |
1206 if (p > endp) | |
1207 len -= - bytes, chars--; | |
1208 | |
1209 if (chars < 2 || chars > MAX_COMPONENT_COUNT) | |
1210 /* Invalid number of components. */ | |
1211 return -1; | |
1212 } | |
1213 hash_idx = hash_string (str, len) % CMPCHAR_HASH_TABLE_SIZE; | |
1214 hashp = cmpchar_hash_table[hash_idx]; | |
1215 | |
1216 /* Then, look into the hash table. */ | |
1217 if (hashp != NULL) | |
1218 /* Find the correct one among composite characters of the same | |
1219 hash value. */ | |
1220 for (i = 2; i < CMPCHAR_HASH_USED (hashp); i++) | |
1221 { | |
1222 cmpcharp = cmpchar_table[CMPCHAR_HASH_CMPCHAR_ID (hashp, i)]; | |
1223 if (len == cmpcharp->len | |
1224 && ! bcmp (str, cmpcharp->data, len)) | |
1225 return CMPCHAR_HASH_CMPCHAR_ID (hashp, i); | |
1226 } | |
1227 | |
1228 /* We have to register the composite character in cmpchar_table. */ | |
17186
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
1229 if (n_cmpchars > (CHAR_FIELD2_MASK | CHAR_FIELD3_MASK)) |
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
1230 /* No, we have no more room for a new composite character. */ |
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
1231 return -1; |
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
1232 |
17052 | 1233 /* Make the entry in hash table. */ |
1234 if (hashp == NULL) | |
1235 { | |
1236 /* Make a table for 8 composite characters initially. */ | |
1237 hashp = (cmpchar_hash_table[hash_idx] | |
1238 = (int *) xmalloc (sizeof (int) * (2 + 8))); | |
1239 CMPCHAR_HASH_SIZE (hashp) = 10; | |
1240 CMPCHAR_HASH_USED (hashp) = 2; | |
1241 } | |
1242 else if (CMPCHAR_HASH_USED (hashp) >= CMPCHAR_HASH_SIZE (hashp)) | |
1243 { | |
1244 CMPCHAR_HASH_SIZE (hashp) += 8; | |
1245 hashp = (cmpchar_hash_table[hash_idx] | |
1246 = (int *) xrealloc (hashp, | |
1247 sizeof (int) * CMPCHAR_HASH_SIZE (hashp))); | |
1248 } | |
1249 CMPCHAR_HASH_CMPCHAR_ID (hashp, CMPCHAR_HASH_USED (hashp)) = n_cmpchars; | |
1250 CMPCHAR_HASH_USED (hashp)++; | |
1251 | |
1252 /* Set information of the composite character in cmpchar_table. */ | |
1253 if (cmpchar_table_size == 0) | |
1254 { | |
1255 /* This is the first composite character to be registered. */ | |
1256 cmpchar_table_size = 256; | |
1257 cmpchar_table | |
1258 = (struct cmpchar_info **) xmalloc (sizeof (cmpchar_table[0]) | |
1259 * cmpchar_table_size); | |
1260 } | |
1261 else if (cmpchar_table_size <= n_cmpchars) | |
1262 { | |
1263 cmpchar_table_size += 256; | |
1264 cmpchar_table | |
1265 = (struct cmpchar_info **) xrealloc (cmpchar_table, | |
1266 sizeof (cmpchar_table[0]) | |
1267 * cmpchar_table_size); | |
1268 } | |
1269 | |
1270 cmpcharp = (struct cmpchar_info *) xmalloc (sizeof (struct cmpchar_info)); | |
1271 | |
1272 cmpcharp->len = len; | |
1273 cmpcharp->data = (unsigned char *) xmalloc (len + 1); | |
1274 bcopy (str, cmpcharp->data, len); | |
1275 cmpcharp->data[len] = 0; | |
1276 cmpcharp->glyph_len = chars; | |
1277 cmpcharp->glyph = (GLYPH *) xmalloc (sizeof (GLYPH) * chars); | |
1278 if (embedded_rule) | |
1279 { | |
1280 cmpcharp->cmp_rule = (unsigned char *) xmalloc (chars); | |
1281 cmpcharp->col_offset = (float *) xmalloc (sizeof (float) * chars); | |
1282 } | |
1283 else | |
1284 { | |
1285 cmpcharp->cmp_rule = NULL; | |
1286 cmpcharp->col_offset = NULL; | |
1287 } | |
1288 | |
1289 /* Setup GLYPH data and composition rules (if any) so as not to make | |
1290 them every time on displaying. */ | |
1291 { | |
1292 unsigned char *bufp; | |
1293 int width; | |
1294 float leftmost = 0.0, rightmost = 1.0; | |
1295 | |
1296 if (embedded_rule) | |
1297 /* At first, col_offset[N] is set to relative to col_offset[0]. */ | |
1298 cmpcharp->col_offset[0] = 0; | |
1299 | |
1300 for (i = 0, bufp = cmpcharp->data + 1; i < chars; i++) | |
1301 { | |
1302 if (embedded_rule) | |
1303 cmpcharp->cmp_rule[i] = *bufp++; | |
1304 | |
1305 if (*bufp == 0xA0) /* This is an ASCII character. */ | |
1306 { | |
1307 cmpcharp->glyph[i] = FAST_MAKE_GLYPH ((*++bufp & 0x7F), 0); | |
1308 width = 1; | |
1309 bufp++; | |
1310 } | |
1311 else /* Multibyte character. */ | |
1312 { | |
1313 /* Make `bufp' point normal multi-byte form temporally. */ | |
1314 *bufp -= 0x20; | |
1315 cmpcharp->glyph[i] | |
1316 = FAST_MAKE_GLYPH (string_to_non_ascii_char (bufp, 4, 0), 0); | |
1317 width = WIDTH_BY_CHAR_HEAD (*bufp); | |
1318 *bufp += 0x20; | |
1319 bufp += BYTES_BY_CHAR_HEAD (*bufp - 0x20); | |
1320 } | |
1321 | |
1322 if (embedded_rule && i > 0) | |
1323 { | |
1324 /* Reference points (global_ref and new_ref) are | |
1325 encoded as below: | |
1326 | |
1327 0--1--2 -- ascent | |
1328 | | | |
1329 | | | |
1330 | 4 -+--- center | |
1331 -- 3 5 -- baseline | |
1332 | | | |
1333 6--7--8 -- descent | |
1334 | |
1335 Now, we calculate the column offset of the new glyph | |
1336 from the left edge of the first glyph. This can avoid | |
1337 the same calculation everytime displaying this | |
1338 composite character. */ | |
1339 | |
1340 /* Reference points of global glyph and new glyph. */ | |
1341 int global_ref = (cmpcharp->cmp_rule[i] - 0xA0) / 9; | |
1342 int new_ref = (cmpcharp->cmp_rule[i] - 0xA0) % 9; | |
1343 /* Column offset relative to the first glyph. */ | |
1344 float left = (leftmost | |
1345 + (global_ref % 3) * (rightmost - leftmost) / 2.0 | |
1346 - (new_ref % 3) * width / 2.0); | |
1347 | |
1348 cmpcharp->col_offset[i] = left; | |
1349 if (left < leftmost) | |
1350 leftmost = left; | |
1351 if (left + width > rightmost) | |
1352 rightmost = left + width; | |
1353 } | |
1354 else | |
1355 { | |
1356 if (width > rightmost) | |
1357 rightmost = width; | |
1358 } | |
1359 } | |
1360 if (embedded_rule) | |
1361 { | |
1362 /* Now col_offset[N] are relative to the left edge of the | |
1363 first component. Make them relative to the left edge of | |
1364 overall glyph. */ | |
1365 for (i = 0; i < chars; i++) | |
1366 cmpcharp->col_offset[i] -= leftmost; | |
1367 /* Make rightmost holds width of overall glyph. */ | |
1368 rightmost -= leftmost; | |
1369 } | |
1370 | |
1371 cmpcharp->width = rightmost; | |
1372 if (cmpcharp->width < rightmost) | |
1373 /* To get a ceiling integer value. */ | |
1374 cmpcharp->width++; | |
1375 } | |
1376 | |
1377 cmpchar_table[n_cmpchars] = cmpcharp; | |
1378 | |
1379 return n_cmpchars++; | |
1380 } | |
1381 | |
1382 /* Return the Nth element of the composite character C. */ | |
1383 int | |
1384 cmpchar_component (c, n) | |
1385 unsigned int c, n; | |
1386 { | |
1387 int id = COMPOSITE_CHAR_ID (c); | |
1388 | |
1389 if (id >= n_cmpchars /* C is not a valid composite character. */ | |
1390 || n >= cmpchar_table[id]->glyph_len) /* No such component. */ | |
1391 return -1; | |
1392 /* No face data is stored in glyph code. */ | |
1393 return ((int) (cmpchar_table[id]->glyph[n])); | |
1394 } | |
1395 | |
1396 DEFUN ("cmpcharp", Fcmpcharp, Scmpcharp, 1, 1, 0, | |
1397 "T if CHAR is a composite character.") | |
1398 (ch) | |
1399 Lisp_Object ch; | |
1400 { | |
1401 CHECK_NUMBER (ch, 0); | |
1402 return (COMPOSITE_CHAR_P (XINT (ch)) ? Qt : Qnil); | |
1403 } | |
1404 | |
1405 DEFUN ("composite-char-component", Fcmpchar_component, Scmpchar_component, | |
1406 2, 2, 0, | |
1407 "Return the IDXth component character of composite character CHARACTER.") | |
1408 (character, idx) | |
1409 Lisp_Object character, idx; | |
1410 { | |
1411 int c; | |
1412 | |
1413 CHECK_NUMBER (character, 0); | |
1414 CHECK_NUMBER (idx, 1); | |
1415 | |
1416 if ((c = cmpchar_component (XINT (character), XINT (idx))) < 0) | |
1417 args_out_of_range (character, idx); | |
1418 | |
1419 return make_number (c); | |
1420 } | |
1421 | |
1422 DEFUN ("composite-char-composition-rule", Fcmpchar_cmp_rule, Scmpchar_cmp_rule, | |
1423 2, 2, 0, | |
17121
f8e2cd94c274
(Fcmpchar_cmp_rule): Escape newlines in docstring.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1424 "Return the Nth composition rule embedded in composite character CHARACTER.\n\ |
f8e2cd94c274
(Fcmpchar_cmp_rule): Escape newlines in docstring.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1425 The returned rule is for composing the Nth component\n\ |
f8e2cd94c274
(Fcmpchar_cmp_rule): Escape newlines in docstring.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1426 on the (N-1)th component. If N is 0, the returned value is always 255.") |
f8e2cd94c274
(Fcmpchar_cmp_rule): Escape newlines in docstring.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1427 (character, n) |
f8e2cd94c274
(Fcmpchar_cmp_rule): Escape newlines in docstring.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1428 Lisp_Object character, n; |
17052 | 1429 { |
1430 int id, i; | |
1431 | |
1432 CHECK_NUMBER (character, 0); | |
17121
f8e2cd94c274
(Fcmpchar_cmp_rule): Escape newlines in docstring.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1433 CHECK_NUMBER (n, 1); |
17052 | 1434 |
1435 id = COMPOSITE_CHAR_ID (XINT (character)); | |
1436 if (id < 0 || id >= n_cmpchars) | |
1437 error ("Invalid composite character: %d", XINT (character)); | |
17121
f8e2cd94c274
(Fcmpchar_cmp_rule): Escape newlines in docstring.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1438 i = XINT (n); |
17052 | 1439 if (i > cmpchar_table[id]->glyph_len) |
17121
f8e2cd94c274
(Fcmpchar_cmp_rule): Escape newlines in docstring.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1440 args_out_of_range (character, n); |
17052 | 1441 |
1442 return make_number (cmpchar_table[id]->cmp_rule[i]); | |
1443 } | |
1444 | |
1445 DEFUN ("composite-char-composition-rule-p", Fcmpchar_cmp_rule_p, | |
1446 Scmpchar_cmp_rule_p, 1, 1, 0, | |
1447 "Return non-nil if composite character CHARACTER contains a embedded rule.") | |
1448 (character) | |
1449 Lisp_Object character; | |
1450 { | |
1451 int id; | |
1452 | |
1453 CHECK_NUMBER (character, 0); | |
1454 id = COMPOSITE_CHAR_ID (XINT (character)); | |
1455 if (id < 0 || id >= n_cmpchars) | |
1456 error ("Invalid composite character: %d", XINT (character)); | |
1457 | |
1458 return (cmpchar_table[id]->cmp_rule ? Qt : Qnil); | |
1459 } | |
1460 | |
1461 DEFUN ("composite-char-component-count", Fcmpchar_cmp_count, | |
1462 Scmpchar_cmp_count, 1, 1, 0, | |
1463 "Return number of compoents of composite character CHARACTER.") | |
1464 (character) | |
1465 Lisp_Object character; | |
1466 { | |
1467 int id; | |
1468 | |
1469 CHECK_NUMBER (character, 0); | |
1470 id = COMPOSITE_CHAR_ID (XINT (character)); | |
1471 if (id < 0 || id >= n_cmpchars) | |
1472 error ("Invalid composite character: %d", XINT (character)); | |
1473 | |
1474 return (make_number (cmpchar_table[id]->glyph_len)); | |
1475 } | |
1476 | |
1477 DEFUN ("compose-string", Fcompose_string, Scompose_string, | |
1478 1, 1, 0, | |
1479 "Return one char string composed from all characters in STRING.") | |
1480 (str) | |
1481 Lisp_Object str; | |
1482 { | |
1483 unsigned char buf[MAX_LENGTH_OF_MULTI_BYTE_FORM], *p, *pend, *ptemp; | |
1484 int len, i; | |
1485 | |
1486 CHECK_STRING (str, 0); | |
1487 | |
1488 buf[0] = LEADING_CODE_COMPOSITION; | |
1489 p = XSTRING (str)->data; | |
20614
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1490 pend = p + XSTRING (str)->size_byte; |
17052 | 1491 i = 1; |
1492 while (p < pend) | |
1493 { | |
1494 if (*p < 0x20 || *p == 127) /* control code */ | |
1495 error ("Invalid component character: %d", *p); | |
1496 else if (*p < 0x80) /* ASCII */ | |
1497 { | |
1498 if (i + 2 >= MAX_LENGTH_OF_MULTI_BYTE_FORM) | |
1499 error ("Too long string to be composed: %s", XSTRING (str)->data); | |
1500 /* Prepend an ASCII charset indicator 0xA0, set MSB of the | |
1501 code itself. */ | |
1502 buf[i++] = 0xA0; | |
1503 buf[i++] = *p++ + 0x80; | |
1504 } | |
1505 else if (*p == LEADING_CODE_COMPOSITION) /* composite char */ | |
1506 { | |
1507 /* Already composed. Eliminate the heading | |
1508 LEADING_CODE_COMPOSITION, keep the remaining bytes | |
1509 unchanged. */ | |
1510 p++; | |
1511 ptemp = p; | |
20534
066251bcf9f7
(Fchars_in_string): Update call to CHAR_HEAD_P.
Richard M. Stallman <rms@gnu.org>
parents:
20435
diff
changeset
|
1512 while (! CHAR_HEAD_P (*p)) p++; |
17052 | 1513 if (i + (p - ptemp) >= MAX_LENGTH_OF_MULTI_BYTE_FORM) |
1514 error ("Too long string to be composed: %s", XSTRING (str)->data); | |
1515 bcopy (ptemp, buf + i, p - ptemp); | |
1516 i += p - ptemp; | |
1517 } | |
1518 else /* multibyte char */ | |
1519 { | |
1520 /* Add 0x20 to the base leading-code, keep the remaining | |
1521 bytes unchanged. */ | |
1522 len = BYTES_BY_CHAR_HEAD (*p); | |
1523 if (i + len >= MAX_LENGTH_OF_MULTI_BYTE_FORM) | |
1524 error ("Too long string to be composed: %s", XSTRING (str)->data); | |
1525 bcopy (p, buf + i, len); | |
1526 buf[i] += 0x20; | |
1527 p += len, i += len; | |
1528 } | |
1529 } | |
1530 | |
1531 if (i < 5) | |
1532 /* STR contains only one character, which can't be composed. */ | |
1533 error ("Too short string to be composed: %s", XSTRING (str)->data); | |
1534 | |
20614
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1535 return make_multibyte_string (buf, 1, i); |
17052 | 1536 } |
1537 | |
1538 | |
1539 charset_id_internal (charset_name) | |
1540 char *charset_name; | |
1541 { | |
1542 Lisp_Object val = Fget (intern (charset_name), Qcharset); | |
1543 | |
1544 if (!VECTORP (val)) | |
1545 error ("Charset %s is not defined", charset_name); | |
1546 | |
1547 return (XINT (XVECTOR (val)->contents[0])); | |
1548 } | |
1549 | |
1550 DEFUN ("setup-special-charsets", Fsetup_special_charsets, | |
1551 Ssetup_special_charsets, 0, 0, 0, "Internal use only.") | |
1552 () | |
1553 { | |
1554 charset_latin_iso8859_1 = charset_id_internal ("latin-iso8859-1"); | |
1555 charset_jisx0208_1978 = charset_id_internal ("japanese-jisx0208-1978"); | |
1556 charset_jisx0208 = charset_id_internal ("japanese-jisx0208"); | |
1557 charset_katakana_jisx0201 = charset_id_internal ("katakana-jisx0201"); | |
1558 charset_latin_jisx0201 = charset_id_internal ("latin-jisx0201"); | |
1559 charset_big5_1 = charset_id_internal ("chinese-big5-1"); | |
1560 charset_big5_2 = charset_id_internal ("chinese-big5-2"); | |
1561 return Qnil; | |
1562 } | |
1563 | |
1564 init_charset_once () | |
1565 { | |
1566 int i, j, k; | |
1567 | |
1568 staticpro (&Vcharset_table); | |
1569 staticpro (&Vcharset_symbol_table); | |
1570 | |
1571 /* This has to be done here, before we call Fmake_char_table. */ | |
1572 Qcharset_table = intern ("charset-table"); | |
1573 staticpro (&Qcharset_table); | |
1574 | |
1575 /* Intern this now in case it isn't already done. | |
1576 Setting this variable twice is harmless. | |
1577 But don't staticpro it here--that is done in alloc.c. */ | |
1578 Qchar_table_extra_slots = intern ("char-table-extra-slots"); | |
1579 | |
1580 /* Now we are ready to set up this property, so we can | |
1581 create the charset table. */ | |
1582 Fput (Qcharset_table, Qchar_table_extra_slots, make_number (0)); | |
1583 Vcharset_table = Fmake_char_table (Qcharset_table, Qnil); | |
1584 | |
17186
65bc06706714
Adjusted for the change of MAX_CHARSET.
Kenichi Handa <handa@m17n.org>
parents:
17121
diff
changeset
|
1585 Vcharset_symbol_table = Fmake_vector (make_number (MAX_CHARSET + 1), Qnil); |
17052 | 1586 |
1587 /* Setup tables. */ | |
1588 for (i = 0; i < 2; i++) | |
1589 for (j = 0; j < 2; j++) | |
1590 for (k = 0; k < 128; k++) | |
1591 iso_charset_table [i][j][k] = -1; | |
1592 | |
1593 bzero (cmpchar_hash_table, sizeof cmpchar_hash_table); | |
1594 cmpchar_table_size = n_cmpchars = 0; | |
1595 | |
1596 for (i = 0; i < 256; i++) | |
1597 BYTES_BY_CHAR_HEAD (i) = 1; | |
1598 BYTES_BY_CHAR_HEAD (LEADING_CODE_PRIVATE_11) = 3; | |
1599 BYTES_BY_CHAR_HEAD (LEADING_CODE_PRIVATE_12) = 3; | |
1600 BYTES_BY_CHAR_HEAD (LEADING_CODE_PRIVATE_21) = 4; | |
1601 BYTES_BY_CHAR_HEAD (LEADING_CODE_PRIVATE_22) = 4; | |
1602 /* The following doesn't reflect the actual bytes, but just to tell | |
1603 that it is a start of a multibyte character. */ | |
1604 BYTES_BY_CHAR_HEAD (LEADING_CODE_COMPOSITION) = 2; | |
1605 | |
1606 for (i = 0; i < 128; i++) | |
1607 WIDTH_BY_CHAR_HEAD (i) = 1; | |
1608 for (; i < 256; i++) | |
1609 WIDTH_BY_CHAR_HEAD (i) = 4; | |
1610 WIDTH_BY_CHAR_HEAD (LEADING_CODE_PRIVATE_11) = 1; | |
1611 WIDTH_BY_CHAR_HEAD (LEADING_CODE_PRIVATE_12) = 2; | |
1612 WIDTH_BY_CHAR_HEAD (LEADING_CODE_PRIVATE_21) = 1; | |
1613 WIDTH_BY_CHAR_HEAD (LEADING_CODE_PRIVATE_22) = 2; | |
1614 } | |
1615 | |
1616 #ifdef emacs | |
1617 | |
1618 syms_of_charset () | |
1619 { | |
1620 Qascii = intern ("ascii"); | |
1621 staticpro (&Qascii); | |
1622 | |
1623 Qcharset = intern ("charset"); | |
1624 staticpro (&Qcharset); | |
1625 | |
1626 /* Define ASCII charset now. */ | |
1627 update_charset_table (make_number (CHARSET_ASCII), | |
1628 make_number (1), make_number (94), | |
1629 make_number (1), | |
1630 make_number (0), | |
1631 make_number ('B'), | |
1632 make_number (0), | |
1633 build_string ("ASCII"), | |
1634 build_string ("ASCII"), | |
1635 build_string ("ASCII (ISO646 IRV)")); | |
1636 CHARSET_SYMBOL (CHARSET_ASCII) = Qascii; | |
1637 Fput (Qascii, Qcharset, CHARSET_TABLE_ENTRY (CHARSET_ASCII)); | |
1638 | |
1639 Qcomposition = intern ("composition"); | |
1640 staticpro (&Qcomposition); | |
1641 CHARSET_SYMBOL (CHARSET_COMPOSITION) = Qcomposition; | |
1642 | |
1643 defsubr (&Sdefine_charset); | |
20435
099812ea310f
(Fget_unused_iso_final_char): New function.
Kenichi Handa <handa@m17n.org>
parents:
20362
diff
changeset
|
1644 defsubr (&Sget_unused_iso_final_char); |
17052 | 1645 defsubr (&Sdeclare_equiv_charset); |
1646 defsubr (&Sfind_charset_region); | |
1647 defsubr (&Sfind_charset_string); | |
1648 defsubr (&Smake_char_internal); | |
1649 defsubr (&Ssplit_char); | |
1650 defsubr (&Schar_charset); | |
1651 defsubr (&Siso_charset); | |
20152
9a3343c36e83
(char_valid_p): New function
Kenichi Handa <handa@m17n.org>
parents:
19983
diff
changeset
|
1652 defsubr (&Schar_valid_p); |
17052 | 1653 defsubr (&Schar_bytes); |
1654 defsubr (&Schar_width); | |
1655 defsubr (&Sstring_width); | |
1656 defsubr (&Schar_direction); | |
19415
309b9a0d8a45
(Fchars_in_region): Renamed form Fcount_chars_region.
Kenichi Handa <handa@m17n.org>
parents:
19384
diff
changeset
|
1657 defsubr (&Schars_in_region); |
20614
a4800f9842e4
(multibyte_chars_in_text): New function.
Richard M. Stallman <rms@gnu.org>
parents:
20575
diff
changeset
|
1658 defsubr (&Sstring); |
17052 | 1659 defsubr (&Scmpcharp); |
1660 defsubr (&Scmpchar_component); | |
1661 defsubr (&Scmpchar_cmp_rule); | |
1662 defsubr (&Scmpchar_cmp_rule_p); | |
1663 defsubr (&Scmpchar_cmp_count); | |
1664 defsubr (&Scompose_string); | |
1665 defsubr (&Ssetup_special_charsets); | |
1666 | |
1667 DEFVAR_LISP ("charset-list", &Vcharset_list, | |
1668 "List of charsets ever defined."); | |
1669 Vcharset_list = Fcons (Qascii, Qnil); | |
1670 | |
1671 DEFVAR_INT ("leading-code-composition", &leading_code_composition, | |
1672 "Leading-code of composite characters."); | |
1673 leading_code_composition = LEADING_CODE_COMPOSITION; | |
1674 | |
1675 DEFVAR_INT ("leading-code-private-11", &leading_code_private_11, | |
1676 "Leading-code of private TYPE9N charset of column-width 1."); | |
1677 leading_code_private_11 = LEADING_CODE_PRIVATE_11; | |
1678 | |
1679 DEFVAR_INT ("leading-code-private-12", &leading_code_private_12, | |
1680 "Leading-code of private TYPE9N charset of column-width 2."); | |
1681 leading_code_private_12 = LEADING_CODE_PRIVATE_12; | |
1682 | |
1683 DEFVAR_INT ("leading-code-private-21", &leading_code_private_21, | |
1684 "Leading-code of private TYPE9Nx9N charset of column-width 1."); | |
1685 leading_code_private_21 = LEADING_CODE_PRIVATE_21; | |
1686 | |
1687 DEFVAR_INT ("leading-code-private-22", &leading_code_private_22, | |
1688 "Leading-code of private TYPE9Nx9N charset of column-width 2."); | |
1689 leading_code_private_22 = LEADING_CODE_PRIVATE_22; | |
20705
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
1690 |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
1691 DEFVAR_INT ("nonascii-insert-offset", &nonascii_insert_offset, |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
1692 "Offset to add to a non-ascii code 0200...0377 when inserting it.\n\ |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
1693 This applies only when multibyte characters are enabled, and it serves\n\ |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
1694 to convert a Latin-1 or similar 8-bit character code to the corresponding\n\ |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
1695 Emacs character code."); |
a949dc65fbea
(nonascii_insert_offset): Variable moved from cmds.c.
Richard M. Stallman <rms@gnu.org>
parents:
20636
diff
changeset
|
1696 nonascii_insert_offset = 0; |
17052 | 1697 } |
1698 | |
1699 #endif /* emacs */ |