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