comparison src/charset.c @ 89483:2f877ed80fa6

*** empty log message ***
author Kenichi Handa <handa@m17n.org>
date Mon, 08 Sep 2003 12:53:41 +0000
parents 375f2633d815 31ac7465ef51
children 36913565de8a
comparison
equal deleted inserted replaced
88123:375f2633d815 89483:2f877ed80fa6
1 /* Basic multilingual character support. 1 /* Basic character set support.
2 Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN. 2 Copyright (C) 1995, 97, 98, 2000, 2001 Electrotechnical Laboratory, JAPAN.
3 Licensed to the Free Software Foundation. 3 Licensed to the Free Software Foundation.
4 Copyright (C) 2001 Free Software Foundation, Inc. 4 Copyright (C) 2001 Free Software Foundation, Inc.
5 Copyright (C) 2003
6 National Institute of Advanced Industrial Science and Technology (AIST)
7 Registration Number H13PRO009
5 8
6 This file is part of GNU Emacs. 9 This file is part of GNU Emacs.
7 10
8 GNU Emacs is free software; you can redistribute it and/or modify 11 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 12 it under the terms of the GNU General Public License as published by
18 You should have received a copy of the GNU General Public License 21 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to 22 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */ 24 Boston, MA 02111-1307, USA. */
22 25
23 /* At first, see the document in `charset.h' to understand the code in
24 this file. */
25
26 #ifdef emacs
27 #include <config.h> 26 #include <config.h>
28 #endif
29 27
30 #include <stdio.h> 28 #include <stdio.h>
31 29 #include <unistd.h>
32 #ifdef emacs 30 #include <ctype.h>
33
34 #include <sys/types.h> 31 #include <sys/types.h>
35 #include "lisp.h" 32 #include "lisp.h"
36 #include "buffer.h" 33 #include "character.h"
37 #include "charset.h" 34 #include "charset.h"
38 #include "composite.h"
39 #include "coding.h" 35 #include "coding.h"
40 #include "disptab.h" 36 #include "disptab.h"
41 37 #include "buffer.h"
42 #else /* not emacs */ 38
43 39 /*** GENERAL NOTES on CODED CHARACTER SETS (CHARSETS) ***
44 #include "mulelib.h" 40
45 41 A coded character set ("charset" hereafter) is a meaningful
46 #endif /* emacs */ 42 collection (i.e. language, culture, functionality, etc.) of
47 43 characters. Emacs handles multiple charsets at once. In Emacs Lisp
48 Lisp_Object Qcharset, Qascii, Qeight_bit_control, Qeight_bit_graphic; 44 code, a charset is represented by a symbol. In C code, a charset is
49 Lisp_Object Qunknown; 45 represented by its ID number or by a pointer to a struct charset.
50 46
51 /* Declaration of special leading-codes. */ 47 The actual information about each charset is stored in two places.
52 EMACS_INT leading_code_private_11; /* for private DIMENSION1 of 1-column */ 48 Lispy information is stored in the hash table Vcharset_hash_table as
53 EMACS_INT leading_code_private_12; /* for private DIMENSION1 of 2-column */ 49 a vector (charset attributes). The other information is stored in
54 EMACS_INT leading_code_private_21; /* for private DIMENSION2 of 1-column */ 50 charset_table as a struct charset.
55 EMACS_INT leading_code_private_22; /* for private DIMENSION2 of 2-column */ 51
56 52 */
57 /* Declaration of special charsets. The values are set by 53
58 Fsetup_special_charsets. */ 54 /* List of all charsets. This variable is used only from Emacs
59 int charset_latin_iso8859_1; /* ISO8859-1 (Latin-1) */ 55 Lisp. */
60 int charset_jisx0208_1978; /* JISX0208.1978 (Japanese Kanji old set) */
61 int charset_jisx0208; /* JISX0208.1983 (Japanese Kanji) */
62 int charset_katakana_jisx0201; /* JISX0201.Kana (Japanese Katakana) */
63 int charset_latin_jisx0201; /* JISX0201.Roman (Japanese Roman) */
64 int charset_big5_1; /* Big5 Level 1 (Chinese Traditional) */
65 int charset_big5_2; /* Big5 Level 2 (Chinese Traditional) */
66
67 Lisp_Object Qcharset_table;
68
69 /* A char-table containing information of each character set. */
70 Lisp_Object Vcharset_table;
71
72 /* A vector of charset symbol indexed by charset-id. This is used
73 only for returning charset symbol from C functions. */
74 Lisp_Object Vcharset_symbol_table;
75
76 /* A list of charset symbols ever defined. */
77 Lisp_Object Vcharset_list; 56 Lisp_Object Vcharset_list;
78 57
79 /* Vector of translation table ever defined. 58 /* Hash table that contains attributes of each charset. Keys are
80 ID of a translation table is used to index this vector. */ 59 charset symbols, and values are vectors of charset attributes. */
81 Lisp_Object Vtranslation_table_vector; 60 Lisp_Object Vcharset_hash_table;
82 61
83 /* A char-table for characters which may invoke auto-filling. */ 62 /* Table of struct charset. */
84 Lisp_Object Vauto_fill_chars; 63 struct charset *charset_table;
85 64
86 Lisp_Object Qauto_fill_chars; 65 static int charset_table_size;
87 66 int charset_table_used;
88 /* Tables used by macros BYTES_BY_CHAR_HEAD and WIDTH_BY_CHAR_HEAD. */ 67
89 int bytes_by_char_head[256]; 68 Lisp_Object Qcharsetp;
90 int width_by_char_head[256]; 69
70 /* Special charset symbols. */
71 Lisp_Object Qascii;
72 Lisp_Object Qeight_bit;
73 Lisp_Object Qiso_8859_1;
74 Lisp_Object Qunicode;
75
76 /* The corresponding charsets. */
77 int charset_ascii;
78 int charset_eight_bit;
79 int charset_iso_8859_1;
80 int charset_unicode;
81
82 /* The other special charsets. */
83 int charset_jisx0201_roman;
84 int charset_jisx0208_1978;
85 int charset_jisx0208;
86
87 /* Value of charset attribute `charset-iso-plane'. */
88 Lisp_Object Qgl, Qgr;
89
90 /* Charset of unibyte characters. */
91 int charset_unibyte;
92
93 /* List of charsets ordered by the priority. */
94 Lisp_Object Vcharset_ordered_list;
95
96 /* Incremented everytime we change Vcharset_ordered_list. This is
97 unsigned short so that it fits in Lisp_Int and never matches
98 -1. */
99 unsigned short charset_ordered_list_tick;
100
101 /* List of iso-2022 charsets. */
102 Lisp_Object Viso_2022_charset_list;
103
104 /* List of emacs-mule charsets. */
105 Lisp_Object Vemacs_mule_charset_list;
106
107 struct charset *emacs_mule_charset[256];
91 108
92 /* Mapping table from ISO2022's charset (specified by DIMENSION, 109 /* Mapping table from ISO2022's charset (specified by DIMENSION,
93 CHARS, and FINAL-CHAR) to Emacs' charset. */ 110 CHARS, and FINAL-CHAR) to Emacs' charset. */
94 int iso_charset_table[2][2][128]; 111 int iso_charset_table[ISO_MAX_DIMENSION][ISO_MAX_CHARS][ISO_MAX_FINAL];
95 112
96 /* Variables used locally in the macro FETCH_MULTIBYTE_CHAR. */ 113 Lisp_Object Vcharset_map_directory;
97 unsigned char *_fetch_multibyte_char_p; 114
98 int _fetch_multibyte_char_len; 115 Lisp_Object Vchar_unified_charset_table;
99 116
100 /* Offset to add to a non-ASCII value when inserting it. */ 117 /* Defined in chartab.c */
101 EMACS_INT nonascii_insert_offset; 118 extern void
102 119 map_char_table_for_charset P_ ((void (*c_function) (Lisp_Object, Lisp_Object),
103 /* Translation table for converting non-ASCII unibyte characters 120 Lisp_Object function, Lisp_Object table,
104 to multibyte codes, or nil. */ 121 Lisp_Object arg, struct charset *charset,
105 Lisp_Object Vnonascii_translation_table; 122 unsigned from, unsigned to));
106 123
107 /* List of all possible generic characters. */ 124 #define CODE_POINT_TO_INDEX(charset, code) \
108 Lisp_Object Vgeneric_character_list; 125 ((charset)->code_linear_p \
126 ? (code) - (charset)->min_code \
127 : (((charset)->code_space_mask[(code) >> 24] & 0x8) \
128 && ((charset)->code_space_mask[((code) >> 16) & 0xFF] & 0x4) \
129 && ((charset)->code_space_mask[((code) >> 8) & 0xFF] & 0x2) \
130 && ((charset)->code_space_mask[(code) & 0xFF] & 0x1)) \
131 ? (((((code) >> 24) - (charset)->code_space[12]) \
132 * (charset)->code_space[11]) \
133 + (((((code) >> 16) & 0xFF) - (charset)->code_space[8]) \
134 * (charset)->code_space[7]) \
135 + (((((code) >> 8) & 0xFF) - (charset)->code_space[4]) \
136 * (charset)->code_space[3]) \
137 + (((code) & 0xFF) - (charset)->code_space[0]) \
138 - ((charset)->char_index_offset)) \
139 : -1)
140
141
142 /* Convert the character index IDX to code-point CODE for CHARSET.
143 It is assumed that IDX is in a valid range. */
144
145 #define INDEX_TO_CODE_POINT(charset, idx) \
146 ((charset)->code_linear_p \
147 ? (idx) + (charset)->min_code \
148 : (idx += (charset)->char_index_offset, \
149 (((charset)->code_space[0] + (idx) % (charset)->code_space[2]) \
150 | (((charset)->code_space[4] \
151 + ((idx) / (charset)->code_space[3] % (charset)->code_space[6])) \
152 << 8) \
153 | (((charset)->code_space[8] \
154 + ((idx) / (charset)->code_space[7] % (charset)->code_space[10])) \
155 << 16) \
156 | (((charset)->code_space[12] + ((idx) / (charset)->code_space[11])) \
157 << 24))))
158
109 159
110 160
161
162 /* Set to 1 to warn that a charset map is loaded and thus a buffer
163 text and a string data may be relocated. */
164 int charset_map_loaded;
165
166 struct charset_map_entries
167 {
168 struct {
169 unsigned from, to;
170 int c;
171 } entry[0x10000];
172 struct charset_map_entries *next;
173 };
174
175 /* Load the mapping information for CHARSET from ENTRIES.
176
177 If CONTROL_FLAG is 0, setup CHARSET->min_char and CHARSET->max_char.
178
179 If CONTROL_FLAG is 1, setup CHARSET->min_char, CHARSET->max_char,
180 CHARSET->decoder, and CHARSET->encoder.
181
182 If CONTROL_FLAG is 2, setup CHARSET->deunifier and
183 Vchar_unify_table. If Vchar_unified_charset_table is non-nil,
184 setup it too. */
185
186 static void
187 load_charset_map (charset, entries, n_entries, control_flag)
188 struct charset *charset;
189 struct charset_map_entries *entries;
190 int n_entries;
191 int control_flag;
192 {
193 Lisp_Object vec, table;
194 unsigned max_code = CHARSET_MAX_CODE (charset);
195 int ascii_compatible_p = charset->ascii_compatible_p;
196 int min_char, max_char, nonascii_min_char;
197 int i;
198 unsigned char *fast_map = charset->fast_map;
199
200 if (n_entries <= 0)
201 return;
202
203 if (control_flag > 0)
204 {
205 int n = CODE_POINT_TO_INDEX (charset, max_code) + 1;
206
207 table = Fmake_char_table (Qnil, Qnil);
208 if (control_flag == 1)
209 vec = Fmake_vector (make_number (n), make_number (-1));
210 else if (! CHAR_TABLE_P (Vchar_unify_table))
211 Vchar_unify_table = Fmake_char_table (Qnil, Qnil);
212
213 charset_map_loaded = 1;
214 }
215
216 min_char = max_char = entries->entry[0].c;
217 nonascii_min_char = MAX_CHAR;
218 for (i = 0; i < n_entries; i++)
219 {
220 unsigned from, to;
221 int from_index, to_index;
222 int from_c, to_c;
223 int idx = i % 0x10000;
224
225 if (i > 0 && idx == 0)
226 entries = entries->next;
227 from = entries->entry[idx].from;
228 to = entries->entry[idx].to;
229 from_c = entries->entry[idx].c;
230 from_index = CODE_POINT_TO_INDEX (charset, from);
231 if (from == to)
232 {
233 to_index = from_index;
234 to_c = from_c;
235 }
236 else
237 {
238 to_index = CODE_POINT_TO_INDEX (charset, to);
239 to_c = from_c + (to_index - from_index);
240 }
241 if (from_index < 0 || to_index < 0)
242 continue;
243
244 if (control_flag < 2)
245 {
246 int c;
247
248 if (to_c > max_char)
249 max_char = to_c;
250 else if (from_c < min_char)
251 min_char = from_c;
252 if (ascii_compatible_p)
253 {
254 if (! ASCII_BYTE_P (from_c))
255 {
256 if (from_c < nonascii_min_char)
257 nonascii_min_char = from_c;
258 }
259 else if (! ASCII_BYTE_P (to_c))
260 {
261 nonascii_min_char = 0x80;
262 }
263 }
264
265 for (c = from_c; c <= to_c; c++)
266 CHARSET_FAST_MAP_SET (c, fast_map);
267
268 if (control_flag == 1)
269 {
270 unsigned code = from;
271
272 if (CHARSET_COMPACT_CODES_P (charset))
273 while (1)
274 {
275 ASET (vec, from_index, make_number (from_c));
276 if (NILP (CHAR_TABLE_REF (table, from_c)))
277 CHAR_TABLE_SET (table, from_c, make_number (code));
278 if (from_index == to_index)
279 break;
280 from_index++, from_c++;
281 code = INDEX_TO_CODE_POINT (charset, from_index);
282 }
283 else
284 for (; from_index <= to_index; from_index++, from_c++)
285 {
286 ASET (vec, from_index, make_number (from_c));
287 if (NILP (CHAR_TABLE_REF (table, from_c)))
288 CHAR_TABLE_SET (table, from_c, make_number (from_index));
289 }
290 }
291 }
292 else
293 {
294 unsigned code = from;
295
296 while (1)
297 {
298 int c1 = DECODE_CHAR (charset, code);
299
300 if (c1 >= 0)
301 {
302 CHAR_TABLE_SET (table, from_c, make_number (c1));
303 CHAR_TABLE_SET (Vchar_unify_table, c1, make_number (from_c));
304 if (CHAR_TABLE_P (Vchar_unified_charset_table))
305 CHAR_TABLE_SET (Vchar_unified_charset_table, c1,
306 CHARSET_NAME (charset));
307 }
308 if (from_index == to_index)
309 break;
310 from_index++, from_c++;
311 code = INDEX_TO_CODE_POINT (charset, from_index);
312 }
313 }
314 }
315
316 if (control_flag < 2)
317 {
318 CHARSET_MIN_CHAR (charset) = (ascii_compatible_p
319 ? nonascii_min_char : min_char);
320 CHARSET_MAX_CHAR (charset) = max_char;
321 if (control_flag == 1)
322 {
323 CHARSET_DECODER (charset) = vec;
324 CHARSET_ENCODER (charset) = table;
325 }
326 }
327 else
328 CHARSET_DEUNIFIER (charset) = table;
329 }
330
331
332 /* Read a hexadecimal number (preceded by "0x") from the file FP while
333 paying attention to comment charcter '#'. */
334
335 static INLINE unsigned
336 read_hex (fp, eof)
337 FILE *fp;
338 int *eof;
339 {
340 int c;
341 unsigned n;
342
343 while ((c = getc (fp)) != EOF)
344 {
345 if (c == '#')
346 {
347 while ((c = getc (fp)) != EOF && c != '\n');
348 }
349 else if (c == '0')
350 {
351 if ((c = getc (fp)) == EOF || c == 'x')
352 break;
353 }
354 }
355 if (c == EOF)
356 {
357 *eof = 1;
358 return 0;
359 }
360 *eof = 0;
361 n = 0;
362 if (c == 'x')
363 while ((c = getc (fp)) != EOF && isxdigit (c))
364 n = ((n << 4)
365 | (c <= '9' ? c - '0' : c <= 'F' ? c - 'A' + 10 : c - 'a' + 10));
366 else
367 while ((c = getc (fp)) != EOF && isdigit (c))
368 n = (n * 10) + c - '0';
369 if (c != EOF)
370 ungetc (c, fp);
371 return n;
372 }
373
374
375 /* Return a mapping vector for CHARSET loaded from MAPFILE.
376 Each line of MAPFILE has this form
377 0xAAAA 0xCCCC
378 where 0xAAAA is a code-point and 0xCCCC is the corresponding
379 character code, or this form
380 0xAAAA-0xBBBB 0xCCCC
381 where 0xAAAA and 0xBBBB are code-points specifying a range, and
382 0xCCCC is the first character code of the range.
383
384 The returned vector has this form:
385 [ CODE1 CHAR1 CODE2 CHAR2 .... ]
386 where CODE1 is a code-point or a cons of code-points specifying a
387 range. */
388
389 extern void add_to_log P_ ((char *, Lisp_Object, Lisp_Object));
390
391 static void
392 load_charset_map_from_file (charset, mapfile, control_flag)
393 struct charset *charset;
394 Lisp_Object mapfile;
395 int control_flag;
396 {
397 unsigned min_code = CHARSET_MIN_CODE (charset);
398 unsigned max_code = CHARSET_MAX_CODE (charset);
399 int fd;
400 FILE *fp;
401 int eof;
402 Lisp_Object suffixes;
403 struct charset_map_entries *head, *entries;
404 int n_entries;
405
406 suffixes = Fcons (build_string (".map"),
407 Fcons (build_string (".TXT"), Qnil));
408
409 fd = openp (Fcons (Vcharset_map_directory, Qnil), mapfile, suffixes,
410 NULL, Qnil);
411 if (fd < 0
412 || ! (fp = fdopen (fd, "r")))
413 {
414 add_to_log ("Failure in loading charset map: %S", mapfile, Qnil);
415 return;
416 }
417
418 head = entries = ((struct charset_map_entries *)
419 alloca (sizeof (struct charset_map_entries)));
420 n_entries = 0;
421 eof = 0;
422 while (1)
423 {
424 unsigned from, to;
425 int c;
426 int idx;
427
428 from = read_hex (fp, &eof);
429 if (eof)
430 break;
431 if (getc (fp) == '-')
432 to = read_hex (fp, &eof);
433 else
434 to = from;
435 c = (int) read_hex (fp, &eof);
436
437 if (from < min_code || to > max_code || from > to || c > MAX_CHAR)
438 continue;
439
440 if (n_entries > 0 && (n_entries % 0x10000) == 0)
441 {
442 entries->next = ((struct charset_map_entries *)
443 alloca (sizeof (struct charset_map_entries)));
444 entries = entries->next;
445 }
446 idx = n_entries % 0x10000;
447 entries->entry[idx].from = from;
448 entries->entry[idx].to = to;
449 entries->entry[idx].c = c;
450 n_entries++;
451 }
452 fclose (fp);
453 close (fd);
454
455 load_charset_map (charset, head, n_entries, control_flag);
456 }
457
458 static void
459 load_charset_map_from_vector (charset, vec, control_flag)
460 struct charset *charset;
461 Lisp_Object vec;
462 int control_flag;
463 {
464 unsigned min_code = CHARSET_MIN_CODE (charset);
465 unsigned max_code = CHARSET_MAX_CODE (charset);
466 struct charset_map_entries *head, *entries;
467 int n_entries;
468 int len = ASIZE (vec);
469 int i;
470
471 if (len % 2 == 1)
472 {
473 add_to_log ("Failure in loading charset map: %V", vec, Qnil);
474 return;
475 }
476
477 head = entries = ((struct charset_map_entries *)
478 alloca (sizeof (struct charset_map_entries)));
479 n_entries = 0;
480 for (i = 0; i < len; i += 2)
481 {
482 Lisp_Object val, val2;
483 unsigned from, to;
484 int c;
485 int idx;
486
487 val = AREF (vec, i);
488 if (CONSP (val))
489 {
490 val2 = XCDR (val);
491 val = XCAR (val);
492 CHECK_NATNUM (val);
493 CHECK_NATNUM (val2);
494 from = XFASTINT (val);
495 to = XFASTINT (val2);
496 }
497 else
498 {
499 CHECK_NATNUM (val);
500 from = to = XFASTINT (val);
501 }
502 val = AREF (vec, i + 1);
503 CHECK_NATNUM (val);
504 c = XFASTINT (val);
505
506 if (from < min_code || to > max_code || from > to || c > MAX_CHAR)
507 continue;
508
509 if ((n_entries % 0x10000) == 0)
510 {
511 entries->next = ((struct charset_map_entries *)
512 alloca (sizeof (struct charset_map_entries)));
513 entries = entries->next;
514 }
515 idx = n_entries % 0x10000;
516 entries->entry[idx].from = from;
517 entries->entry[idx].to = to;
518 entries->entry[idx].c = c;
519 n_entries++;
520 }
521
522 load_charset_map (charset, head, n_entries, control_flag);
523 }
524
525 static void
526 load_charset (charset)
527 struct charset *charset;
528 {
529 if (CHARSET_METHOD (charset) == CHARSET_METHOD_MAP_DEFERRED)
530 {
531 Lisp_Object map;
532
533 map = CHARSET_MAP (charset);
534 if (STRINGP (map))
535 load_charset_map_from_file (charset, map, 1);
536 else
537 load_charset_map_from_vector (charset, map, 1);
538 CHARSET_METHOD (charset) = CHARSET_METHOD_MAP;
539 }
540 }
541
542
543 DEFUN ("charsetp", Fcharsetp, Scharsetp, 1, 1, 0,
544 doc: /* Return non-nil if and only if OBJECT is a charset.*/)
545 (object)
546 Lisp_Object object;
547 {
548 return (CHARSETP (object) ? Qt : Qnil);
549 }
550
551
111 void 552 void
112 invalid_character (c) 553 map_charset_chars (c_function, function, arg,
113 int c; 554 charset, from, to)
114 { 555 void (*c_function) P_ ((Lisp_Object, Lisp_Object));
115 error ("Invalid character: 0%o, %d, 0x%x", c, c, c); 556 Lisp_Object function, arg;
116 } 557 struct charset *charset;
117 558 unsigned from, to;
118 /* Parse string STR of length LENGTH and fetch information of a 559 {
119 character at STR. Set BYTES to the byte length the character 560 Lisp_Object range;
120 occupies, CHARSET, C1, C2 to proper values of the character. */ 561 int partial;
121 562
122 #define SPLIT_MULTIBYTE_SEQ(str, length, bytes, charset, c1, c2) \ 563 if (CHARSET_METHOD (charset) == CHARSET_METHOD_MAP_DEFERRED)
123 do { \ 564 load_charset (charset);
124 (c1) = *(str); \ 565
125 (bytes) = BYTES_BY_CHAR_HEAD (c1); \ 566 partial = (from > CHARSET_MIN_CODE (charset)
126 if ((bytes) == 1) \ 567 || to < CHARSET_MAX_CODE (charset));
127 (charset) = ASCII_BYTE_P (c1) ? CHARSET_ASCII : CHARSET_8_BIT_GRAPHIC; \ 568
128 else if ((bytes) == 2) \ 569 if (CHARSET_UNIFIED_P (charset)
129 { \ 570 && CHAR_TABLE_P (CHARSET_DEUNIFIER (charset)))
130 if ((c1) == LEADING_CODE_8_BIT_CONTROL) \ 571 {
131 (charset) = CHARSET_8_BIT_CONTROL, (c1) = (str)[1] - 0x20; \ 572 map_char_table_for_charset (c_function, function,
132 else \ 573 CHARSET_DEUNIFIER (charset), arg,
133 (charset) = (c1), (c1) = (str)[1] & 0x7F; \ 574 partial ? charset : NULL, from, to);
134 } \ 575 }
135 else if ((bytes) == 3) \ 576
136 { \ 577 if (CHARSET_METHOD (charset) == CHARSET_METHOD_OFFSET)
137 if ((c1) < LEADING_CODE_PRIVATE_11) \ 578 {
138 (charset) = (c1), (c1) = (str)[1] & 0x7F, (c2) = (str)[2] & 0x7F; \ 579 int from_idx = CODE_POINT_TO_INDEX (charset, from);
139 else \ 580 int to_idx = CODE_POINT_TO_INDEX (charset, to);
140 (charset) = (str)[1], (c1) = (str)[2] & 0x7F; \ 581 int from_c = from_idx + CHARSET_CODE_OFFSET (charset);
141 } \ 582 int to_c = to_idx + CHARSET_CODE_OFFSET (charset);
142 else \ 583
143 (charset) = (str)[1], (c1) = (str)[2] & 0x7F, (c2) = (str)[3] & 0x7F; \ 584 range = Fcons (make_number (from_c), make_number (to_c));
144 } while (0) 585 if (NILP (function))
145 586 (*c_function) (range, arg);
146 /* 1 if CHARSET, C1, and C2 compose a valid character, else 0.
147 Note that this intentionally allows invalid components, such
148 as 0xA0 0xA0, because there exist many files that contain
149 such invalid byte sequences, especially in EUC-GB. */
150 #define CHAR_COMPONENTS_VALID_P(charset, c1, c2) \
151 ((charset) == CHARSET_ASCII \
152 ? ((c1) >= 0 && (c1) <= 0x7F) \
153 : ((charset) == CHARSET_8_BIT_CONTROL \
154 ? ((c1) >= 0x80 && (c1) <= 0x9F) \
155 : ((charset) == CHARSET_8_BIT_GRAPHIC \
156 ? ((c1) >= 0x80 && (c1) <= 0xFF) \
157 : (CHARSET_DIMENSION (charset) == 1 \
158 ? ((c1) >= 0x20 && (c1) <= 0x7F) \
159 : ((c1) >= 0x20 && (c1) <= 0x7F \
160 && (c2) >= 0x20 && (c2) <= 0x7F)))))
161
162 /* Store multi-byte form of the character C in STR. The caller should
163 allocate at least 4-byte area at STR in advance. Returns the
164 length of the multi-byte form. If C is an invalid character code,
165 return -1. */
166
167 int
168 char_to_string_1 (c, str)
169 int c;
170 unsigned char *str;
171 {
172 unsigned char *p = str;
173
174 if (c & CHAR_MODIFIER_MASK) /* This includes the case C is negative. */
175 {
176 /* Multibyte character can't have a modifier bit. */
177 if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
178 return -1;
179
180 /* For Meta, Shift, and Control modifiers, we need special care. */
181 if (c & CHAR_META)
182 {
183 /* Move the meta bit to the right place for a string. */
184 c = (c & ~CHAR_META) | 0x80;
185 }
186 if (c & CHAR_SHIFT)
187 {
188 /* Shift modifier is valid only with [A-Za-z]. */
189 if ((c & 0377) >= 'A' && (c & 0377) <= 'Z')
190 c &= ~CHAR_SHIFT;
191 else if ((c & 0377) >= 'a' && (c & 0377) <= 'z')
192 c = (c & ~CHAR_SHIFT) - ('a' - 'A');
193 }
194 if (c & CHAR_CTL)
195 {
196 /* Simulate the code in lread.c. */
197 /* Allow `\C- ' and `\C-?'. */
198 if (c == (CHAR_CTL | ' '))
199 c = 0;
200 else if (c == (CHAR_CTL | '?'))
201 c = 127;
202 /* ASCII control chars are made from letters (both cases),
203 as well as the non-letters within 0100...0137. */
204 else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
205 c &= (037 | (~0177 & ~CHAR_CTL));
206 else if ((c & 0177) >= 0100 && (c & 0177) <= 0137)
207 c &= (037 | (~0177 & ~CHAR_CTL));
208 }
209
210 /* If C still has any modifier bits, just ignore it. */
211 c &= ~CHAR_MODIFIER_MASK;
212 }
213
214 if (SINGLE_BYTE_CHAR_P (c))
215 {
216 if (ASCII_BYTE_P (c) || c >= 0xA0)
217 *p++ = c;
218 else 587 else
219 { 588 call2 (function, range, arg);
220 *p++ = LEADING_CODE_8_BIT_CONTROL; 589 }
221 *p++ = c + 0x20; 590 else if (CHARSET_METHOD (charset) == CHARSET_METHOD_MAP)
222 } 591 {
223 } 592 if (! CHAR_TABLE_P (CHARSET_ENCODER (charset)))
224 else if (CHAR_VALID_P (c, 0)) 593 return;
225 { 594 if (CHARSET_ASCII_COMPATIBLE_P (charset) && from <= 127)
226 int charset, c1, c2; 595 {
227 596 range = Fcons (make_number (from), make_number (to));
228 SPLIT_CHAR (c, charset, c1, c2); 597 if (to >= 128)
229 598 XSETCAR (range, make_number (127));
230 if (charset >= LEADING_CODE_EXT_11) 599
231 *p++ = (charset < LEADING_CODE_EXT_12 600 if (NILP (function))
232 ? LEADING_CODE_PRIVATE_11 601 (*c_function) (range, arg);
233 : (charset < LEADING_CODE_EXT_21 602 else
234 ? LEADING_CODE_PRIVATE_12 603 call2 (function, range, arg);
235 : (charset < LEADING_CODE_EXT_22 604 }
236 ? LEADING_CODE_PRIVATE_21 605 map_char_table_for_charset (c_function, function,
237 : LEADING_CODE_PRIVATE_22))); 606 CHARSET_ENCODER (charset), arg,
238 *p++ = charset; 607 partial ? charset : NULL, from, to);
239 if ((c1 > 0 && c1 < 32) || (c2 > 0 && c2 < 32)) 608 }
240 return -1; 609 else if (CHARSET_METHOD (charset) == CHARSET_METHOD_SUBSET)
241 if (c1) 610 {
242 { 611 Lisp_Object subset_info;
243 *p++ = c1 | 0x80; 612 int offset;
244 if (c2 > 0) 613
245 *p++ = c2 | 0x80; 614 subset_info = CHARSET_SUBSET (charset);
246 } 615 charset = CHARSET_FROM_ID (XFASTINT (AREF (subset_info, 0)));
247 } 616 offset = XINT (AREF (subset_info, 3));
617 from -= offset;
618 if (from < XFASTINT (AREF (subset_info, 1)))
619 from = XFASTINT (AREF (subset_info, 1));
620 to -= offset;
621 if (to > XFASTINT (AREF (subset_info, 2)))
622 to = XFASTINT (AREF (subset_info, 2));
623 map_charset_chars (c_function, function, arg, charset, from, to);
624 }
625 else /* i.e. CHARSET_METHOD_SUPERSET */
626 {
627 Lisp_Object parents;
628
629 for (parents = CHARSET_SUPERSET (charset); CONSP (parents);
630 parents = XCDR (parents))
631 {
632 int offset;
633 unsigned this_from, this_to;
634
635 charset = CHARSET_FROM_ID (XFASTINT (XCAR (XCAR (parents))));
636 offset = XINT (XCDR (XCAR (parents)));
637 this_from = from - offset;
638 this_to = to - offset;
639 if (this_from < CHARSET_MIN_CODE (charset))
640 this_from = CHARSET_MIN_CODE (charset);
641 if (this_to > CHARSET_MAX_CODE (charset))
642 this_to = CHARSET_MAX_CODE (charset);
643 map_charset_chars (c_function, function, arg, charset, from, to);
644 }
645 }
646 }
647
648 DEFUN ("map-charset-chars", Fmap_charset_chars, Smap_charset_chars, 2, 5, 0,
649 doc: /* Call FUNCTION for all characters in CHARSET.
650 FUNCTION is called with an argument RANGE and the optional 3rd
651 argument ARG.
652
653 RANGE is a cons (FROM . TO), where FROM and TO indicate a range of
654 characters contained in CHARSET.
655
656 The optional 4th and 5th arguments FROM-CODE and TO-CODE specify the
657 range of code points of target characters. */)
658 (function, charset, arg, from_code, to_code)
659 Lisp_Object function, charset, arg, from_code, to_code;
660 {
661 struct charset *cs;
662 unsigned from, to;
663
664 CHECK_CHARSET_GET_CHARSET (charset, cs);
665 if (NILP (from_code))
666 from = CHARSET_MIN_CODE (cs);
248 else 667 else
249 return -1; 668 {
250 669 CHECK_NATNUM (from_code);
251 return (p - str); 670 from = XINT (from_code);
252 } 671 if (from < CHARSET_MIN_CODE (cs))
253 672 from = CHARSET_MIN_CODE (cs);
254 673 }
255 /* Store multi-byte form of the character C in STR. The caller should 674 if (NILP (to_code))
256 allocate at least 4-byte area at STR in advance. Returns the 675 to = CHARSET_MAX_CODE (cs);
257 length of the multi-byte form. If C is an invalid character code, 676 else
258 signal an error. 677 {
259 678 CHECK_NATNUM (to_code);
260 Use macro `CHAR_STRING (C, STR)' instead of calling this function 679 to = XINT (to_code);
261 directly if C can be an ASCII character. */ 680 if (to > CHARSET_MAX_CODE (cs))
262 681 to = CHARSET_MAX_CODE (cs);
263 int 682 }
264 char_to_string (c, str) 683 map_charset_chars (NULL, function, arg, cs, from, to);
265 int c; 684 return Qnil;
266 unsigned char *str; 685 }
267 { 686
268 int len; 687
269 len = char_to_string_1 (c, str); 688 /* Define a charset according to the arguments. The Nth argument is
270 if (len == -1) 689 the Nth attribute of the charset (the last attribute `charset-id'
271 invalid_character (c); 690 is not included). See the docstring of `define-charset' for the
272 return len; 691 detail. */
273 } 692
274 693 DEFUN ("define-charset-internal", Fdefine_charset_internal,
275 694 Sdefine_charset_internal, charset_arg_max, MANY, 0,
276 /* Return the non-ASCII character corresponding to multi-byte form at 695 doc: /* For internal use only.
277 STR of length LEN. If ACTUAL_LEN is not NULL, store the byte 696 usage: (define-charset-internal ...) */)
278 length of the multibyte form in *ACTUAL_LEN. 697 (nargs, args)
279 698 int nargs;
280 Use macros STRING_CHAR or STRING_CHAR_AND_LENGTH instead of calling 699 Lisp_Object *args;
281 this function directly if you want ot handle ASCII characters as 700 {
282 well. */ 701 /* Charset attr vector. */
283 702 Lisp_Object attrs;
284 int 703 Lisp_Object val;
285 string_to_char (str, len, actual_len) 704 unsigned hash_code;
286 const unsigned char *str; 705 struct Lisp_Hash_Table *hash_table = XHASH_TABLE (Vcharset_hash_table);
287 int len, *actual_len; 706 int i, j;
288 { 707 struct charset charset;
289 int c, bytes, charset, c1, c2; 708 int id;
290 709 int dimension;
291 SPLIT_MULTIBYTE_SEQ (str, len, bytes, charset, c1, c2); 710 int new_definition_p;
292 c = MAKE_CHAR (charset, c1, c2); 711 int nchars;
293 if (actual_len) 712
294 *actual_len = bytes; 713 if (nargs != charset_arg_max)
295 return c; 714 return Fsignal (Qwrong_number_of_arguments,
296 } 715 Fcons (intern ("define-charset-internal"),
297 716 make_number (nargs)));
298 /* Return the length of the multi-byte form at string STR of length LEN. 717
299 Use the macro MULTIBYTE_FORM_LENGTH instead. */ 718 attrs = Fmake_vector (make_number (charset_attr_max), Qnil);
300 int 719
301 multibyte_form_length (str, len) 720 CHECK_SYMBOL (args[charset_arg_name]);
302 const unsigned char *str; 721 ASET (attrs, charset_name, args[charset_arg_name]);
303 int len; 722
304 { 723 val = args[charset_arg_code_space];
305 int bytes; 724 for (i = 0, dimension = 0, nchars = 1; i < 4; i++)
306 725 {
307 PARSE_MULTIBYTE_SEQ (str, len, bytes); 726 int min_byte, max_byte;
308 return bytes; 727
309 } 728 min_byte = XINT (Faref (val, make_number (i * 2)));
310 729 max_byte = XINT (Faref (val, make_number (i * 2 + 1)));
311 /* Check multibyte form at string STR of length LEN and set variables 730 if (min_byte < 0 || min_byte > max_byte || max_byte >= 256)
312 pointed by CHARSET, C1, and C2 to charset and position codes of the 731 error ("Invalid :code-space value");
313 character at STR, and return 0. If there's no multibyte character, 732 charset.code_space[i * 4] = min_byte;
314 return -1. This should be used only in the macro SPLIT_STRING 733 charset.code_space[i * 4 + 1] = max_byte;
315 which checks range of STR in advance. */ 734 charset.code_space[i * 4 + 2] = max_byte - min_byte + 1;
316 735 nchars *= charset.code_space[i * 4 + 2];
317 int 736 charset.code_space[i * 4 + 3] = nchars;
318 split_string (str, len, charset, c1, c2) 737 if (max_byte > 0)
319 const unsigned char *str; 738 dimension = i + 1;
320 unsigned char *c1, *c2; 739 }
321 int len, *charset; 740
322 { 741 val = args[charset_arg_dimension];
323 register int bytes, cs, code1, code2 = -1; 742 if (NILP (val))
324 743 charset.dimension = dimension;
325 SPLIT_MULTIBYTE_SEQ (str, len, bytes, cs, code1, code2); 744 else
326 if (cs == CHARSET_ASCII) 745 {
327 return -1; 746 CHECK_NATNUM (val);
328 *charset = cs; 747 charset.dimension = XINT (val);
329 *c1 = code1; 748 if (charset.dimension < 1 || charset.dimension > 4)
330 *c2 = code2; 749 args_out_of_range_3 (val, make_number (1), make_number (4));
331 return 0; 750 }
332 } 751
333 752 charset.code_linear_p
334 /* Return 1 iff character C has valid printable glyph. 753 = (charset.dimension == 1
335 Use the macro CHAR_PRINTABLE_P instead. */ 754 || (charset.code_space[2] == 256
336 int 755 && (charset.dimension == 2
337 char_printable_p (c) 756 || (charset.code_space[6] == 256
338 int c; 757 && (charset.dimension == 3
339 { 758 || charset.code_space[10] == 256)))));
340 int charset, c1, c2; 759
341 760 if (! charset.code_linear_p)
342 if (ASCII_BYTE_P (c)) 761 {
343 return 1; 762 charset.code_space_mask = (unsigned char *) xmalloc (256);
344 else if (SINGLE_BYTE_CHAR_P (c)) 763 bzero (charset.code_space_mask, 256);
345 return 0; 764 for (i = 0; i < 4; i++)
346 else if (c >= MAX_CHAR) 765 for (j = charset.code_space[i * 4]; j <= charset.code_space[i * 4 + 1];
347 return 0; 766 j++)
348 767 charset.code_space_mask[j] |= (1 << i);
349 SPLIT_CHAR (c, charset, c1, c2); 768 }
350 if (! CHARSET_DEFINED_P (charset)) 769
351 return 0; 770 charset.iso_chars_96 = charset.code_space[2] == 96;
352 if (CHARSET_CHARS (charset) == 94 771
353 ? c1 <= 32 || c1 >= 127 772 charset.min_code = (charset.code_space[0]
354 : c1 < 32) 773 | (charset.code_space[4] << 8)
355 return 0; 774 | (charset.code_space[8] << 16)
356 if (CHARSET_DIMENSION (charset) == 2 775 | (charset.code_space[12] << 24));
357 && (CHARSET_CHARS (charset) == 94 776 charset.max_code = (charset.code_space[1]
358 ? c2 <= 32 || c2 >= 127 777 | (charset.code_space[5] << 8)
359 : c2 < 32)) 778 | (charset.code_space[9] << 16)
360 return 0; 779 | (charset.code_space[13] << 24));
361 return 1; 780 charset.char_index_offset = 0;
362 } 781
363 782 val = args[charset_arg_min_code];
364 /* Translate character C by translation table TABLE. If C 783 if (! NILP (val))
365 is negative, translate a character specified by CHARSET, C1, and C2 784 {
366 (C1 and C2 are code points of the character). If no translation is 785 unsigned code;
367 found in TABLE, return C. */ 786
368 int 787 if (INTEGERP (val))
369 translate_char (table, c, charset, c1, c2) 788 code = XINT (val);
370 Lisp_Object table;
371 int c, charset, c1, c2;
372 {
373 Lisp_Object ch;
374 int alt_charset, alt_c1, alt_c2, dimension;
375
376 if (c < 0) c = MAKE_CHAR (charset, (c1 & 0x7F) , (c2 & 0x7F));
377 if (!CHAR_TABLE_P (table)
378 || (ch = Faref (table, make_number (c)), !NATNUMP (ch)))
379 return c;
380
381 SPLIT_CHAR (XFASTINT (ch), alt_charset, alt_c1, alt_c2);
382 dimension = CHARSET_DIMENSION (alt_charset);
383 if ((dimension == 1 && alt_c1 > 0) || (dimension == 2 && alt_c2 > 0))
384 /* CH is not a generic character, just return it. */
385 return XFASTINT (ch);
386
387 /* Since CH is a generic character, we must return a specific
388 charater which has the same position codes as C from CH. */
389 if (charset < 0)
390 SPLIT_CHAR (c, charset, c1, c2);
391 if (dimension != CHARSET_DIMENSION (charset))
392 /* We can't make such a character because of dimension mismatch. */
393 return c;
394 return MAKE_CHAR (alt_charset, c1, c2);
395 }
396
397 /* Convert the unibyte character C to multibyte based on
398 Vnonascii_translation_table or nonascii_insert_offset. If they can't
399 convert C to a valid multibyte character, convert it based on
400 DEFAULT_NONASCII_INSERT_OFFSET which makes C a Latin-1 character. */
401
402 int
403 unibyte_char_to_multibyte (c)
404 int c;
405 {
406 if (c < 0400 && c >= 0200)
407 {
408 int c_save = c;
409
410 if (! NILP (Vnonascii_translation_table))
411 {
412 c = XINT (Faref (Vnonascii_translation_table, make_number (c)));
413 if (c >= 0400 && ! char_valid_p (c, 0))
414 c = c_save + DEFAULT_NONASCII_INSERT_OFFSET;
415 }
416 else if (c >= 0240 && nonascii_insert_offset > 0)
417 {
418 c += nonascii_insert_offset;
419 if (c < 0400 || ! char_valid_p (c, 0))
420 c = c_save + DEFAULT_NONASCII_INSERT_OFFSET;
421 }
422 else if (c >= 0240)
423 c = c_save + DEFAULT_NONASCII_INSERT_OFFSET;
424 }
425 return c;
426 }
427
428
429 /* Convert the multibyte character C to unibyte 8-bit character based
430 on Vnonascii_translation_table or nonascii_insert_offset. If
431 REV_TBL is non-nil, it should be a reverse table of
432 Vnonascii_translation_table, i.e. what given by:
433 Fchar_table_extra_slot (Vnonascii_translation_table, make_number (0)) */
434
435 int
436 multibyte_char_to_unibyte (c, rev_tbl)
437 int c;
438 Lisp_Object rev_tbl;
439 {
440 if (!SINGLE_BYTE_CHAR_P (c))
441 {
442 int c_save = c;
443
444 if (! CHAR_TABLE_P (rev_tbl)
445 && CHAR_TABLE_P (Vnonascii_translation_table))
446 rev_tbl = Fchar_table_extra_slot (Vnonascii_translation_table,
447 make_number (0));
448 if (CHAR_TABLE_P (rev_tbl))
449 {
450 Lisp_Object temp;
451 temp = Faref (rev_tbl, make_number (c));
452 if (INTEGERP (temp))
453 c = XINT (temp);
454 if (c >= 256)
455 c = (c_save & 0177) + 0200;
456 }
457 else 789 else
458 { 790 {
459 if (nonascii_insert_offset > 0) 791 CHECK_CONS (val);
460 c -= nonascii_insert_offset; 792 CHECK_NUMBER_CAR (val);
461 if (c < 128 || c >= 256) 793 CHECK_NUMBER_CDR (val);
462 c = (c_save & 0177) + 0200; 794 code = (XINT (XCAR (val)) << 16) | (XINT (XCDR (val)));
463 } 795 }
464 } 796 if (code < charset.min_code
465 797 || code > charset.max_code)
466 return c; 798 args_out_of_range_3 (make_number (charset.min_code),
467 } 799 make_number (charset.max_code), val);
468 800 charset.char_index_offset = CODE_POINT_TO_INDEX (&charset, code);
469 801 charset.min_code = code;
470 /* Update the table Vcharset_table with the given arguments (see the 802 }
471 document of `define-charset' for the meaning of each argument). 803
472 Several other table contents are also updated. The caller should 804 val = args[charset_arg_max_code];
473 check the validity of CHARSET-ID and the remaining arguments in 805 if (! NILP (val))
474 advance. */ 806 {
475 807 unsigned code;
476 void 808
477 update_charset_table (charset_id, dimension, chars, width, direction, 809 if (INTEGERP (val))
478 iso_final_char, iso_graphic_plane, 810 code = XINT (val);
479 short_name, long_name, description) 811 else
480 Lisp_Object charset_id, dimension, chars, width, direction; 812 {
481 Lisp_Object iso_final_char, iso_graphic_plane; 813 CHECK_CONS (val);
482 Lisp_Object short_name, long_name, description; 814 CHECK_NUMBER_CAR (val);
483 { 815 CHECK_NUMBER_CDR (val);
484 int charset = XINT (charset_id); 816 code = (XINT (XCAR (val)) << 16) | (XINT (XCDR (val)));
485 int bytes; 817 }
486 unsigned char leading_code_base, leading_code_ext; 818 if (code < charset.min_code
487 819 || code > charset.max_code)
488 if (NILP (CHARSET_TABLE_ENTRY (charset))) 820 args_out_of_range_3 (make_number (charset.min_code),
489 CHARSET_TABLE_ENTRY (charset) 821 make_number (charset.max_code), val);
490 = Fmake_vector (make_number (CHARSET_MAX_IDX), Qnil); 822 charset.max_code = code;
491 823 }
492 if (NILP (long_name)) 824
493 long_name = short_name; 825 charset.compact_codes_p = charset.max_code < 0x1000000;
494 if (NILP (description)) 826
495 description = long_name; 827 val = args[charset_arg_invalid_code];
496 828 if (NILP (val))
497 /* Get byte length of multibyte form, base leading-code, and 829 {
498 extended leading-code of the charset. See the comment under the 830 if (charset.min_code > 0)
499 title "GENERAL NOTE on CHARACTER SET (CHARSET)" in charset.h. */ 831 charset.invalid_code = 0;
500 bytes = XINT (dimension); 832 else
501 if (charset < MIN_CHARSET_PRIVATE_DIMENSION1) 833 {
502 { 834 XSETINT (val, charset.max_code + 1);
503 /* Official charset, it doesn't have an extended leading-code. */ 835 if (XINT (val) == charset.max_code + 1)
504 if (charset != CHARSET_ASCII && charset != CHARSET_8_BIT_GRAPHIC) 836 charset.invalid_code = charset.max_code + 1;
505 bytes += 1; /* For a base leading-code. */ 837 else
506 leading_code_base = charset; 838 error ("Attribute :invalid-code must be specified");
507 leading_code_ext = 0; 839 }
508 } 840 }
509 else 841 else
510 { 842 {
511 /* Private charset. */ 843 CHECK_NATNUM (val);
512 bytes += 2; /* For base and extended leading-codes. */ 844 charset.invalid_code = XFASTINT (val);
513 leading_code_base 845 }
514 = (charset < LEADING_CODE_EXT_12 846
515 ? LEADING_CODE_PRIVATE_11 847 val = args[charset_arg_iso_final];
516 : (charset < LEADING_CODE_EXT_21 848 if (NILP (val))
517 ? LEADING_CODE_PRIVATE_12 849 charset.iso_final = -1;
518 : (charset < LEADING_CODE_EXT_22 850 else
519 ? LEADING_CODE_PRIVATE_21 851 {
520 : LEADING_CODE_PRIVATE_22))); 852 CHECK_NUMBER (val);
521 leading_code_ext = charset; 853 if (XINT (val) < '0' || XINT (val) > 127)
522 if (BYTES_BY_CHAR_HEAD (leading_code_base) != bytes) 854 error ("Invalid iso-final-char: %d", XINT (val));
523 error ("Invalid dimension for the charset-ID %d", charset); 855 charset.iso_final = XINT (val);
524 } 856 }
525 857
526 CHARSET_TABLE_INFO (charset, CHARSET_ID_IDX) = charset_id; 858 val = args[charset_arg_iso_revision];
527 CHARSET_TABLE_INFO (charset, CHARSET_BYTES_IDX) = make_number (bytes); 859 if (NILP (val))
528 CHARSET_TABLE_INFO (charset, CHARSET_DIMENSION_IDX) = dimension; 860 charset.iso_revision = -1;
529 CHARSET_TABLE_INFO (charset, CHARSET_CHARS_IDX) = chars; 861 else
530 CHARSET_TABLE_INFO (charset, CHARSET_WIDTH_IDX) = width; 862 {
531 CHARSET_TABLE_INFO (charset, CHARSET_DIRECTION_IDX) = direction; 863 CHECK_NUMBER (val);
532 CHARSET_TABLE_INFO (charset, CHARSET_LEADING_CODE_BASE_IDX) 864 if (XINT (val) > 63)
533 = make_number (leading_code_base); 865 args_out_of_range (make_number (63), val);
534 CHARSET_TABLE_INFO (charset, CHARSET_LEADING_CODE_EXT_IDX) 866 charset.iso_revision = XINT (val);
535 = make_number (leading_code_ext); 867 }
536 CHARSET_TABLE_INFO (charset, CHARSET_ISO_FINAL_CHAR_IDX) = iso_final_char; 868
537 CHARSET_TABLE_INFO (charset, CHARSET_ISO_GRAPHIC_PLANE_IDX) 869 val = args[charset_arg_emacs_mule_id];
538 = iso_graphic_plane; 870 if (NILP (val))
539 CHARSET_TABLE_INFO (charset, CHARSET_SHORT_NAME_IDX) = short_name; 871 charset.emacs_mule_id = -1;
540 CHARSET_TABLE_INFO (charset, CHARSET_LONG_NAME_IDX) = long_name; 872 else
541 CHARSET_TABLE_INFO (charset, CHARSET_DESCRIPTION_IDX) = description; 873 {
542 CHARSET_TABLE_INFO (charset, CHARSET_PLIST_IDX) = Qnil; 874 CHECK_NATNUM (val);
543 875 if ((XINT (val) > 0 && XINT (val) <= 128) || XINT (val) >= 256)
544 { 876 error ("Invalid emacs-mule-id: %d", XINT (val));
545 /* If we have already defined a charset which has the same 877 charset.emacs_mule_id = XINT (val);
546 DIMENSION, CHARS and ISO-FINAL-CHAR but the different 878 }
547 DIRECTION, we must update the entry REVERSE-CHARSET of both 879
548 charsets. If there's no such charset, the value of the entry 880 charset.ascii_compatible_p = ! NILP (args[charset_arg_ascii_compatible_p]);
549 is set to nil. */ 881
550 int i; 882 charset.supplementary_p = ! NILP (args[charset_arg_supplementary_p]);
551 883
552 for (i = 0; i <= MAX_CHARSET; i++) 884 charset.unified_p = 0;
553 if (!NILP (CHARSET_TABLE_ENTRY (i))) 885
554 { 886 bzero (charset.fast_map, sizeof (charset.fast_map));
555 if (CHARSET_DIMENSION (i) == XINT (dimension) 887
556 && CHARSET_CHARS (i) == XINT (chars) 888 if (! NILP (args[charset_arg_code_offset]))
557 && CHARSET_ISO_FINAL_CHAR (i) == XINT (iso_final_char) 889 {
558 && CHARSET_DIRECTION (i) != XINT (direction)) 890 val = args[charset_arg_code_offset];
891 CHECK_NUMBER (val);
892
893 charset.method = CHARSET_METHOD_OFFSET;
894 charset.code_offset = XINT (val);
895
896 i = CODE_POINT_TO_INDEX (&charset, charset.min_code);
897 charset.min_char = i + charset.code_offset;
898 i = CODE_POINT_TO_INDEX (&charset, charset.max_code);
899 charset.max_char = i + charset.code_offset;
900 if (charset.max_char > MAX_CHAR)
901 error ("Unsupported max char: %d", charset.max_char);
902
903 i = (charset.min_char >> 7) << 7;
904 for (; i < 0x10000 && i <= charset.max_char; i += 128)
905 CHARSET_FAST_MAP_SET (i, charset.fast_map);
906 i = (i >> 12) << 12;
907 for (; i <= charset.max_char; i += 0x1000)
908 CHARSET_FAST_MAP_SET (i, charset.fast_map);
909 }
910 else if (! NILP (args[charset_arg_map]))
911 {
912 val = args[charset_arg_map];
913 ASET (attrs, charset_map, val);
914 if (STRINGP (val))
915 load_charset_map_from_file (&charset, val, 0);
916 else
917 load_charset_map_from_vector (&charset, val, 0);
918 charset.method = CHARSET_METHOD_MAP_DEFERRED;
919 }
920 else if (! NILP (args[charset_arg_subset]))
921 {
922 Lisp_Object parent;
923 Lisp_Object parent_min_code, parent_max_code, parent_code_offset;
924 struct charset *parent_charset;
925
926 val = args[charset_arg_subset];
927 parent = Fcar (val);
928 CHECK_CHARSET_GET_CHARSET (parent, parent_charset);
929 parent_min_code = Fnth (make_number (1), val);
930 CHECK_NATNUM (parent_min_code);
931 parent_max_code = Fnth (make_number (2), val);
932 CHECK_NATNUM (parent_max_code);
933 parent_code_offset = Fnth (make_number (3), val);
934 CHECK_NUMBER (parent_code_offset);
935 val = Fmake_vector (make_number (4), Qnil);
936 ASET (val, 0, make_number (parent_charset->id));
937 ASET (val, 1, parent_min_code);
938 ASET (val, 2, parent_max_code);
939 ASET (val, 3, parent_code_offset);
940 ASET (attrs, charset_subset, val);
941
942 charset.method = CHARSET_METHOD_SUBSET;
943 /* Here, we just copy the parent's fast_map. It's not accurate,
944 but at least it works for quickly detecting which character
945 DOESN'T belong to this charset. */
946 for (i = 0; i < 190; i++)
947 charset.fast_map[i] = parent_charset->fast_map[i];
948
949 /* We also copy these for parents. */
950 charset.min_char = parent_charset->min_char;
951 charset.max_char = parent_charset->max_char;
952 }
953 else if (! NILP (args[charset_arg_superset]))
954 {
955 val = args[charset_arg_superset];
956 charset.method = CHARSET_METHOD_SUPERSET;
957 val = Fcopy_sequence (val);
958 ASET (attrs, charset_superset, val);
959
960 charset.min_char = MAX_CHAR;
961 charset.max_char = 0;
962 for (; ! NILP (val); val = Fcdr (val))
963 {
964 Lisp_Object elt, car_part, cdr_part;
965 int this_id, offset;
966 struct charset *this_charset;
967
968 elt = Fcar (val);
969 if (CONSP (elt))
559 { 970 {
560 CHARSET_TABLE_INFO (charset, CHARSET_REVERSE_CHARSET_IDX) 971 car_part = XCAR (elt);
561 = make_number (i); 972 cdr_part = XCDR (elt);
562 CHARSET_TABLE_INFO (i, CHARSET_REVERSE_CHARSET_IDX) = charset_id; 973 CHECK_CHARSET_GET_ID (car_part, this_id);
563 break; 974 CHECK_NUMBER (cdr_part);
975 offset = XINT (cdr_part);
564 } 976 }
565 } 977 else
566 if (i > MAX_CHARSET) 978 {
567 /* No such a charset. */ 979 CHECK_CHARSET_GET_ID (elt, this_id);
568 CHARSET_TABLE_INFO (charset, CHARSET_REVERSE_CHARSET_IDX) 980 offset = 0;
569 = make_number (-1); 981 }
570 } 982 XSETCAR (val, Fcons (make_number (this_id), make_number (offset)));
571 983
572 if (charset != CHARSET_ASCII && charset != CHARSET_8_BIT_GRAPHIC 984 this_charset = CHARSET_FROM_ID (this_id);
573 && charset < MIN_CHARSET_PRIVATE_DIMENSION1) 985 if (charset.min_char > this_charset->min_char)
574 { 986 charset.min_char = this_charset->min_char;
575 bytes_by_char_head[leading_code_base] = bytes; 987 if (charset.max_char < this_charset->max_char)
576 width_by_char_head[leading_code_base] = XINT (width); 988 charset.max_char = this_charset->max_char;
577 989 for (i = 0; i < 190; i++)
578 /* Update table emacs_code_class. */ 990 charset.fast_map[i] |= this_charset->fast_map[i];
579 emacs_code_class[charset] = (bytes == 2 991 }
580 ? EMACS_leading_code_2 992 }
581 : (bytes == 3 993 else
582 ? EMACS_leading_code_3 994 error ("None of :code-offset, :map, :parents are specified");
583 : EMACS_leading_code_4)); 995
584 } 996 val = args[charset_arg_unify_map];
585 997 if (! NILP (val) && !STRINGP (val))
586 /* Update table iso_charset_table. */ 998 CHECK_VECTOR (val);
587 if (XINT (iso_final_char) >= 0 999 ASET (attrs, charset_unify_map, val);
588 && ISO_CHARSET_TABLE (dimension, chars, iso_final_char) < 0) 1000
589 ISO_CHARSET_TABLE (dimension, chars, iso_final_char) = charset; 1001 CHECK_LIST (args[charset_arg_plist]);
590 } 1002 ASET (attrs, charset_plist, args[charset_arg_plist]);
591 1003
592 #ifdef emacs 1004 charset.hash_index = hash_lookup (hash_table, args[charset_arg_name],
593 1005 &hash_code);
594 /* Return charset id of CHARSET_SYMBOL, or return -1 if CHARSET_SYMBOL 1006 if (charset.hash_index >= 0)
595 is invalid. */ 1007 {
596 int 1008 new_definition_p = 0;
597 get_charset_id (charset_symbol) 1009 id = XFASTINT (CHARSET_SYMBOL_ID (args[charset_arg_name]));
598 Lisp_Object charset_symbol; 1010 HASH_VALUE (hash_table, charset.hash_index) = attrs;
599 { 1011 }
1012 else
1013 {
1014 charset.hash_index = hash_put (hash_table, args[charset_arg_name], attrs,
1015 hash_code);
1016 if (charset_table_used == charset_table_size)
1017 {
1018 struct charset *new_table
1019 = (struct charset *) xmalloc (sizeof (struct charset)
1020 * (charset_table_size + 16));
1021 bcopy (charset_table, new_table,
1022 sizeof (struct charset) * charset_table_size);
1023 charset_table_size += 16;
1024 charset_table = new_table;
1025 }
1026 id = charset_table_used++;
1027 new_definition_p = 1;
1028 }
1029
1030 ASET (attrs, charset_id, make_number (id));
1031 charset.id = id;
1032 charset_table[id] = charset;
1033
1034 if (charset.iso_final >= 0)
1035 {
1036 ISO_CHARSET_TABLE (charset.dimension, charset.iso_chars_96,
1037 charset.iso_final) = id;
1038 if (new_definition_p)
1039 Viso_2022_charset_list = nconc2 (Viso_2022_charset_list,
1040 Fcons (make_number (id), Qnil));
1041 if (ISO_CHARSET_TABLE (1, 0, 'J') == id)
1042 charset_jisx0201_roman = id;
1043 else if (ISO_CHARSET_TABLE (2, 0, '@') == id)
1044 charset_jisx0208_1978 = id;
1045 else if (ISO_CHARSET_TABLE (2, 0, 'B') == id)
1046 charset_jisx0208 = id;
1047 }
1048
1049 if (charset.emacs_mule_id >= 0)
1050 {
1051 emacs_mule_charset[charset.emacs_mule_id] = CHARSET_FROM_ID (id);
1052 if (charset.emacs_mule_id < 0xA0)
1053 emacs_mule_bytes[charset.emacs_mule_id] = charset.dimension + 1;
1054 if (new_definition_p)
1055 Vemacs_mule_charset_list = nconc2 (Vemacs_mule_charset_list,
1056 Fcons (make_number (id), Qnil));
1057 }
1058
1059 if (new_definition_p)
1060 {
1061 Vcharset_list = Fcons (args[charset_arg_name], Vcharset_list);
1062 Vcharset_ordered_list = nconc2 (Vcharset_ordered_list,
1063 Fcons (make_number (id), Qnil));
1064 charset_ordered_list_tick++;
1065 }
1066
1067 return Qnil;
1068 }
1069
1070
1071 /* Same as Fdefine_charset_internal but arguments are more convenient
1072 to call from C (typically in syms_of_charset). This can define a
1073 charset of `offset' method only. Return the ID of the new
1074 charset. */
1075
1076 static int
1077 define_charset_internal (name, dimension, code_space, min_code, max_code,
1078 iso_final, iso_revision, emacs_mule_id,
1079 ascii_compatible, supplementary,
1080 code_offset)
1081 Lisp_Object name;
1082 int dimension;
1083 unsigned char *code_space;
1084 unsigned min_code, max_code;
1085 int iso_final, iso_revision, emacs_mule_id;
1086 int ascii_compatible, supplementary;
1087 int code_offset;
1088 {
1089 Lisp_Object args[charset_arg_max];
1090 Lisp_Object plist[14];
600 Lisp_Object val; 1091 Lisp_Object val;
601 int charset; 1092 int i;
602 1093
603 /* This originally used a ?: operator, but reportedly the HP-UX 1094 args[charset_arg_name] = name;
604 compiler version HP92453-01 A.10.32.22 miscompiles that. */ 1095 args[charset_arg_dimension] = make_number (dimension);
605 if (SYMBOLP (charset_symbol) 1096 val = Fmake_vector (make_number (8), make_number (0));
606 && VECTORP (val = Fget (charset_symbol, Qcharset)) 1097 for (i = 0; i < 8; i++)
607 && CHARSET_VALID_P (charset = 1098 ASET (val, i, make_number (code_space[i]));
608 XINT (XVECTOR (val)->contents[CHARSET_ID_IDX]))) 1099 args[charset_arg_code_space] = val;
609 return charset; 1100 args[charset_arg_min_code] = make_number (min_code);
610 else 1101 args[charset_arg_max_code] = make_number (max_code);
611 return -1; 1102 args[charset_arg_iso_final]
612 } 1103 = (iso_final < 0 ? Qnil : make_number (iso_final));
613 1104 args[charset_arg_iso_revision] = make_number (iso_revision);
614 /* Return an identification number for a new private charset of 1105 args[charset_arg_emacs_mule_id]
615 DIMENSION and WIDTH. If there's no more room for the new charset, 1106 = (emacs_mule_id < 0 ? Qnil : make_number (emacs_mule_id));
616 return 0. */ 1107 args[charset_arg_ascii_compatible_p] = ascii_compatible ? Qt : Qnil;
617 Lisp_Object 1108 args[charset_arg_supplementary_p] = supplementary ? Qt : Qnil;
618 get_new_private_charset_id (dimension, width) 1109 args[charset_arg_invalid_code] = Qnil;
619 int dimension, width; 1110 args[charset_arg_code_offset] = make_number (code_offset);
620 { 1111 args[charset_arg_map] = Qnil;
621 int charset, from, to; 1112 args[charset_arg_subset] = Qnil;
622 1113 args[charset_arg_superset] = Qnil;
623 if (dimension == 1) 1114 args[charset_arg_unify_map] = Qnil;
624 { 1115
625 from = LEADING_CODE_EXT_11; 1116 plist[0] = intern (":name");
626 to = LEADING_CODE_EXT_21; 1117 plist[1] = args[charset_arg_name];
627 } 1118 plist[2] = intern (":dimension");
628 else 1119 plist[3] = args[charset_arg_dimension];
629 { 1120 plist[4] = intern (":code-space");
630 from = LEADING_CODE_EXT_21; 1121 plist[5] = args[charset_arg_code_space];
631 to = LEADING_CODE_EXT_MAX + 1; 1122 plist[6] = intern (":iso-final-char");
632 } 1123 plist[7] = args[charset_arg_iso_final];
633 1124 plist[8] = intern (":emacs-mule-id");
634 for (charset = from; charset < to; charset++) 1125 plist[9] = args[charset_arg_emacs_mule_id];
635 if (!CHARSET_DEFINED_P (charset)) break; 1126 plist[10] = intern (":ascii-compatible-p");
636 1127 plist[11] = args[charset_arg_ascii_compatible_p];
637 return make_number (charset < to ? charset : 0); 1128 plist[12] = intern (":code-offset");
638 } 1129 plist[13] = args[charset_arg_code_offset];
639 1130
640 DEFUN ("define-charset", Fdefine_charset, Sdefine_charset, 3, 3, 0, 1131 args[charset_arg_plist] = Flist (14, plist);
641 doc: /* Define CHARSET-ID as the identification number of CHARSET with INFO-VECTOR. 1132 Fdefine_charset_internal (charset_arg_max, args);
642 If CHARSET-ID is nil, it is decided automatically, which means CHARSET is 1133
643 treated as a private charset. 1134 return XINT (CHARSET_SYMBOL_ID (name));
644 INFO-VECTOR is a vector of the format: 1135 }
645 [DIMENSION CHARS WIDTH DIRECTION ISO-FINAL-CHAR ISO-GRAPHIC-PLANE 1136
646 SHORT-NAME LONG-NAME DESCRIPTION] 1137
647 The meanings of each elements is as follows: 1138 DEFUN ("define-charset-alias", Fdefine_charset_alias,
648 DIMENSION (integer) is the number of bytes to represent a character: 1 or 2. 1139 Sdefine_charset_alias, 2, 2, 0,
649 CHARS (integer) is the number of characters in a dimension: 94 or 96. 1140 doc: /* Define ALIAS as an alias for charset CHARSET. */)
650 WIDTH (integer) is the number of columns a character in the charset 1141 (alias, charset)
651 occupies on the screen: one of 0, 1, and 2. 1142 Lisp_Object alias, charset;
652 1143 {
653 DIRECTION (integer) is the rendering direction of characters in the 1144 Lisp_Object attr;
654 charset when rendering. If 0, render from left to right, else 1145
655 render from right to left. 1146 CHECK_CHARSET_GET_ATTR (charset, attr);
656 1147 Fputhash (alias, attr, Vcharset_hash_table);
657 ISO-FINAL-CHAR (character) is the final character of the 1148 Vcharset_list = Fcons (alias, Vcharset_list);
658 corresponding ISO 2022 charset.
659 It may be -1 if the charset is internal use only.
660
661 ISO-GRAPHIC-PLANE (integer) is the graphic plane to be invoked
662 while encoding to variants of ISO 2022 coding system, one of the
663 following: 0/graphic-plane-left(GL), 1/graphic-plane-right(GR).
664 It may be -1 if the charset is internal use only.
665
666 SHORT-NAME (string) is the short name to refer to the charset.
667
668 LONG-NAME (string) is the long name to refer to the charset.
669
670 DESCRIPTION (string) is the description string of the charset. */)
671 (charset_id, charset_symbol, info_vector)
672 Lisp_Object charset_id, charset_symbol, info_vector;
673 {
674 Lisp_Object *vec;
675
676 if (!NILP (charset_id))
677 CHECK_NUMBER (charset_id);
678 CHECK_SYMBOL (charset_symbol);
679 CHECK_VECTOR (info_vector);
680
681 if (! NILP (charset_id))
682 {
683 if (! CHARSET_VALID_P (XINT (charset_id)))
684 error ("Invalid CHARSET: %d", XINT (charset_id));
685 else if (CHARSET_DEFINED_P (XINT (charset_id)))
686 error ("Already defined charset: %d", XINT (charset_id));
687 }
688
689 vec = XVECTOR (info_vector)->contents;
690 if (XVECTOR (info_vector)->size != 9
691 || !INTEGERP (vec[0]) || !(XINT (vec[0]) == 1 || XINT (vec[0]) == 2)
692 || !INTEGERP (vec[1]) || !(XINT (vec[1]) == 94 || XINT (vec[1]) == 96)
693 || !INTEGERP (vec[2]) || !(XINT (vec[2]) == 1 || XINT (vec[2]) == 2)
694 || !INTEGERP (vec[3]) || !(XINT (vec[3]) == 0 || XINT (vec[3]) == 1)
695 || !INTEGERP (vec[4])
696 || !(XINT (vec[4]) == -1 || (XINT (vec[4]) >= '0' && XINT (vec[4]) <= '~'))
697 || !INTEGERP (vec[5])
698 || !(XINT (vec[5]) == -1 || XINT (vec[5]) == 0 || XINT (vec[5]) == 1)
699 || !STRINGP (vec[6])
700 || !STRINGP (vec[7])
701 || !STRINGP (vec[8]))
702 error ("Invalid info-vector argument for defining charset %s",
703 SDATA (SYMBOL_NAME (charset_symbol)));
704
705 if (NILP (charset_id))
706 {
707 charset_id = get_new_private_charset_id (XINT (vec[0]), XINT (vec[2]));
708 if (XINT (charset_id) == 0)
709 error ("There's no room for a new private charset %s",
710 SDATA (SYMBOL_NAME (charset_symbol)));
711 }
712
713 update_charset_table (charset_id, vec[0], vec[1], vec[2], vec[3],
714 vec[4], vec[5], vec[6], vec[7], vec[8]);
715 Fput (charset_symbol, Qcharset, CHARSET_TABLE_ENTRY (XINT (charset_id)));
716 CHARSET_SYMBOL (XINT (charset_id)) = charset_symbol;
717 Vcharset_list = Fcons (charset_symbol, Vcharset_list);
718 Fupdate_coding_systems_internal ();
719 return Qnil; 1149 return Qnil;
720 } 1150 }
721 1151
722 DEFUN ("generic-character-list", Fgeneric_character_list, 1152
723 Sgeneric_character_list, 0, 0, 0, 1153 DEFUN ("unibyte-charset", Funibyte_charset, Sunibyte_charset, 0, 0, 0,
724 doc: /* Return a list of all possible generic characters. 1154 doc: /* Return the unibyte charset (set by `set-unibyte-charset'). */)
725 It includes a generic character for a charset not yet defined. */)
726 () 1155 ()
727 { 1156 {
728 return Vgeneric_character_list; 1157 return CHARSET_NAME (CHARSET_FROM_ID (charset_unibyte));
1158 }
1159
1160
1161 DEFUN ("set-unibyte-charset", Fset_unibyte_charset, Sset_unibyte_charset,
1162 1, 1, 0,
1163 doc: /* Set the unibyte charset to CHARSET.
1164 This determines how unibyte/multibyte conversion is done. See also
1165 function `unibyte-charset'. */)
1166 (charset)
1167 Lisp_Object charset;
1168 {
1169 struct charset *cs;
1170 int i, c;
1171
1172 CHECK_CHARSET_GET_CHARSET (charset, cs);
1173 if (! cs->ascii_compatible_p
1174 || cs->dimension != 1)
1175 error ("Inappropriate unibyte charset: %s", SDATA (SYMBOL_NAME (charset)));
1176 charset_unibyte = cs->id;
1177 for (i = 128; i < 256; i++)
1178 {
1179 c = DECODE_CHAR (cs, i);
1180 unibyte_to_multibyte_table[i] = (c < 0 ? BYTE8_TO_CHAR (i) : c);
1181 }
1182
1183 return Qnil;
1184 }
1185
1186
1187 DEFUN ("charset-plist", Fcharset_plist, Scharset_plist, 1, 1, 0,
1188 doc: /* Return the property list of CHARSET. */)
1189 (charset)
1190 Lisp_Object charset;
1191 {
1192 Lisp_Object attrs;
1193
1194 CHECK_CHARSET_GET_ATTR (charset, attrs);
1195 return CHARSET_ATTR_PLIST (attrs);
1196 }
1197
1198
1199 DEFUN ("set-charset-plist", Fset_charset_plist, Sset_charset_plist, 2, 2, 0,
1200 doc: /* Set CHARSET's property list to PLIST. */)
1201 (charset, plist)
1202 Lisp_Object charset, plist;
1203 {
1204 Lisp_Object attrs;
1205
1206 CHECK_CHARSET_GET_ATTR (charset, attrs);
1207 CHARSET_ATTR_PLIST (attrs) = plist;
1208 return plist;
1209 }
1210
1211
1212 DEFUN ("unify-charset", Funify_charset, Sunify_charset, 1, 3, 0,
1213 doc: /* Unify characters of CHARSET with Unicode.
1214 This means reading the relevant file and installing the table defined
1215 by CHARSET's `:unify-map' property.
1216
1217 Optional second arg UNIFY-MAP is a file name string or a vector. It has
1218 the same meaning as the `:unify-map' attribute in the function
1219 `define-charset' (which see).
1220
1221 Optional third argument DEUNIFY, if non-nil, means to de-unify CHARSET. */)
1222 (charset, unify_map, deunify)
1223 Lisp_Object charset, unify_map, deunify;
1224 {
1225 int id;
1226 struct charset *cs;
1227
1228 CHECK_CHARSET_GET_ID (charset, id);
1229 cs = CHARSET_FROM_ID (id);
1230 if (CHARSET_METHOD (cs) == CHARSET_METHOD_MAP_DEFERRED)
1231 load_charset (cs);
1232 if (NILP (deunify)
1233 ? CHARSET_UNIFIED_P (cs) && ! NILP (CHARSET_DEUNIFIER (cs))
1234 : ! CHARSET_UNIFIED_P (cs))
1235 return Qnil;
1236
1237 CHARSET_UNIFIED_P (cs) = 0;
1238 if (NILP (deunify))
1239 {
1240 if (CHARSET_METHOD (cs) != CHARSET_METHOD_OFFSET)
1241 error ("Can't unify charset: %s", SDATA (SYMBOL_NAME (charset)));
1242 if (NILP (unify_map))
1243 unify_map = CHARSET_UNIFY_MAP (cs);
1244 if (STRINGP (unify_map))
1245 load_charset_map_from_file (cs, unify_map, 2);
1246 else if (VECTORP (unify_map))
1247 load_charset_map_from_vector (cs, unify_map, 2);
1248 else if (NILP (unify_map))
1249 error ("No unify-map for charset");
1250 else
1251 error ("Bad unify-map arg");
1252 CHARSET_UNIFIED_P (cs) = 1;
1253 }
1254 else if (CHAR_TABLE_P (Vchar_unify_table))
1255 {
1256 int min_code = CHARSET_MIN_CODE (cs);
1257 int max_code = CHARSET_MAX_CODE (cs);
1258 int min_char = DECODE_CHAR (cs, min_code);
1259 int max_char = DECODE_CHAR (cs, max_code);
1260
1261 char_table_set_range (Vchar_unify_table, min_char, max_char, Qnil);
1262 }
1263
1264 return Qnil;
729 } 1265 }
730 1266
731 DEFUN ("get-unused-iso-final-char", Fget_unused_iso_final_char, 1267 DEFUN ("get-unused-iso-final-char", Fget_unused_iso_final_char,
732 Sget_unused_iso_final_char, 2, 2, 0, 1268 Sget_unused_iso_final_char, 2, 2, 0,
733 doc: /* Return an unsed ISO's final char for a charset of DIMENISION and CHARS. 1269 doc: /*
1270 Return an unsed ISO final char for a charset of DIMENISION and CHARS.
734 DIMENSION is the number of bytes to represent a character: 1 or 2. 1271 DIMENSION is the number of bytes to represent a character: 1 or 2.
735 CHARS is the number of characters in a dimension: 94 or 96. 1272 CHARS is the number of characters in a dimension: 94 or 96.
736 1273
737 This final char is for private use, thus the range is `0' (48) .. `?' (63). 1274 This final char is for private use, thus the range is `0' (48) .. `?' (63).
738 If there's no unused final char for the specified kind of charset, 1275 If there's no unused final char for the specified kind of charset,
742 { 1279 {
743 int final_char; 1280 int final_char;
744 1281
745 CHECK_NUMBER (dimension); 1282 CHECK_NUMBER (dimension);
746 CHECK_NUMBER (chars); 1283 CHECK_NUMBER (chars);
747 if (XINT (dimension) != 1 && XINT (dimension) != 2) 1284 if (XINT (dimension) != 1 && XINT (dimension) != 2 && XINT (dimension) != 3)
748 error ("Invalid charset dimension %d, it should be 1 or 2", 1285 args_out_of_range_3 (dimension, make_number (1), make_number (3));
749 XINT (dimension));
750 if (XINT (chars) != 94 && XINT (chars) != 96) 1286 if (XINT (chars) != 94 && XINT (chars) != 96)
751 error ("Invalid charset chars %d, it should be 94 or 96", 1287 args_out_of_range_3 (chars, make_number (94), make_number (96));
752 XINT (chars));
753 for (final_char = '0'; final_char <= '?'; final_char++) 1288 for (final_char = '0'; final_char <= '?'; final_char++)
754 { 1289 if (ISO_CHARSET_TABLE (XINT (dimension), XINT (chars), final_char) < 0)
755 if (ISO_CHARSET_TABLE (dimension, chars, make_number (final_char)) < 0) 1290 break;
756 break;
757 }
758 return (final_char <= '?' ? make_number (final_char) : Qnil); 1291 return (final_char <= '?' ? make_number (final_char) : Qnil);
759 } 1292 }
1293
1294 static void
1295 check_iso_charset_parameter (dimension, chars, final_char)
1296 Lisp_Object dimension, chars, final_char;
1297 {
1298 CHECK_NATNUM (dimension);
1299 CHECK_NATNUM (chars);
1300 CHECK_NATNUM (final_char);
1301
1302 if (XINT (dimension) > 3)
1303 error ("Invalid DIMENSION %d, it should be 1, 2, or 3", XINT (dimension));
1304 if (XINT (chars) != 94 && XINT (chars) != 96)
1305 error ("Invalid CHARS %d, it should be 94 or 96", XINT (chars));
1306 if (XINT (final_char) < '0' || XINT (final_char) > '~')
1307 error ("Invalid FINAL-CHAR %c, it should be `0'..`~'", XINT (chars));
1308 }
1309
760 1310
761 DEFUN ("declare-equiv-charset", Fdeclare_equiv_charset, Sdeclare_equiv_charset, 1311 DEFUN ("declare-equiv-charset", Fdeclare_equiv_charset, Sdeclare_equiv_charset,
762 4, 4, 0, 1312 4, 4, 0,
763 doc: /* Declare a charset of DIMENSION, CHARS, FINAL-CHAR is the same as CHARSET. 1313 doc: /*
764 CHARSET should be defined by `defined-charset' in advance. */) 1314 Declare a charset of DIMENSION, CHARS, FINAL-CHAR is the same as CHARSET.
765 (dimension, chars, final_char, charset_symbol) 1315 CHARSET should be defined by `define-charset' in advance. */)
766 Lisp_Object dimension, chars, final_char, charset_symbol; 1316 (dimension, chars, final_char, charset)
767 { 1317 Lisp_Object dimension, chars, final_char, charset;
768 int charset; 1318 {
769 1319 int id;
770 CHECK_NUMBER (dimension); 1320
771 CHECK_NUMBER (chars); 1321 CHECK_CHARSET_GET_ID (charset, id);
772 CHECK_NUMBER (final_char); 1322 check_iso_charset_parameter (dimension, chars, final_char);
773 CHECK_SYMBOL (charset_symbol); 1323
774 1324 ISO_CHARSET_TABLE (XINT (dimension), XINT (chars), XINT (final_char)) = id;
775 if (XINT (dimension) != 1 && XINT (dimension) != 2)
776 error ("Invalid DIMENSION %d, it should be 1 or 2", XINT (dimension));
777 if (XINT (chars) != 94 && XINT (chars) != 96)
778 error ("Invalid CHARS %d, it should be 94 or 96", XINT (chars));
779 if (XINT (final_char) < '0' || XFASTINT (final_char) > '~')
780 error ("Invalid FINAL-CHAR %c, it should be `0'..`~'", XINT (chars));
781 if ((charset = get_charset_id (charset_symbol)) < 0)
782 error ("Invalid charset %s", SDATA (SYMBOL_NAME (charset_symbol)));
783
784 ISO_CHARSET_TABLE (dimension, chars, final_char) = charset;
785 return Qnil; 1325 return Qnil;
786 } 1326 }
1327
787 1328
788 /* Return information about charsets in the text at PTR of NBYTES 1329 /* Return information about charsets in the text at PTR of NBYTES
789 bytes, which are NCHARS characters. The value is: 1330 bytes, which are NCHARS characters. The value is:
790 1331
791 0: Each character is represented by one byte. This is always 1332 0: Each character is represented by one byte. This is always
792 true for unibyte text. 1333 true for a unibyte string. For a multibyte string, true if
793 1: No charsets other than ascii eight-bit-control, 1334 it contains only ASCII characters.
794 eight-bit-graphic, and latin-1 are found. 1335
1336 1: No charsets other than ascii, control-1, and latin-1 are
1337 found.
1338
795 2: Otherwise. 1339 2: Otherwise.
796 1340 */
797 In addition, if CHARSETS is nonzero, for each found charset N, set
798 CHARSETS[N] to 1. For that, callers should allocate CHARSETS
799 (MAX_CHARSET + 1 elements) in advance. It may lookup a translation
800 table TABLE if supplied. For invalid charsets, set CHARSETS[1] to
801 1 (note that there's no charset whose ID is 1). */
802 1341
803 int 1342 int
804 find_charset_in_text (ptr, nchars, nbytes, charsets, table) 1343 string_xstring_p (string)
1344 Lisp_Object string;
1345 {
1346 const unsigned char *p = SDATA (string);
1347 const unsigned char *endp = p + SBYTES (string);
1348 struct charset *charset;
1349
1350 if (SCHARS (string) == SBYTES (string))
1351 return 0;
1352
1353 charset = CHARSET_FROM_ID (charset_iso_8859_1);
1354 while (p < endp)
1355 {
1356 int c = STRING_CHAR_ADVANCE (p);
1357
1358 /* Fixme: comparison of unsigned expression < 0 is always false */
1359 if (ENCODE_CHAR (charset, c) < 0)
1360 return 2;
1361 }
1362 return 1;
1363 }
1364
1365
1366 /* Find charsets in the string at PTR of NCHARS and NBYTES.
1367
1368 CHARSETS is a vector. Each element is a cons of CHARSET and
1369 FOUND-FLAG. CHARSET is a charset id, and FOUND-FLAG is nil or t.
1370 FOUND-FLAG t (or nil) means that the corresponding charset is
1371 already found (or not yet found).
1372
1373 It may lookup a translation table TABLE if supplied. */
1374
1375 static void
1376 find_charsets_in_text (ptr, nchars, nbytes, charsets, table)
805 const unsigned char *ptr; 1377 const unsigned char *ptr;
806 int nchars, nbytes, *charsets; 1378 int nchars, nbytes;
807 Lisp_Object table; 1379 Lisp_Object charsets, table;
808 { 1380 {
1381 const unsigned char *pend = ptr + nbytes;
1382 int ncharsets = ASIZE (charsets);
1383
809 if (nchars == nbytes) 1384 if (nchars == nbytes)
810 { 1385 return;
811 if (charsets && nbytes > 0) 1386
812 { 1387 while (ptr < pend)
813 const unsigned char *endp = ptr + nbytes; 1388 {
814 int maskbits = 0; 1389 int c = STRING_CHAR_ADVANCE (ptr);
815 1390 int i;
816 while (ptr < endp && maskbits != 7) 1391 int all_found = 1;
1392 Lisp_Object elt;
1393
1394 if (!NILP (table))
1395 c = translate_char (table, c);
1396 for (i = 0; i < ncharsets; i++)
1397 {
1398 elt = AREF (charsets, i);
1399 if (NILP (XCDR (elt)))
817 { 1400 {
818 maskbits |= (*ptr < 0x80 ? 1 : *ptr < 0xA0 ? 2 : 4); 1401 struct charset *charset = CHARSET_FROM_ID (XINT (XCAR (elt)));
819 ptr++; 1402
1403 if (ENCODE_CHAR (charset, c) != CHARSET_INVALID_CODE (charset))
1404 XSETCDR (elt, Qt);
1405 else
1406 all_found = 0;
820 } 1407 }
821 1408 }
822 if (maskbits & 1) 1409 if (all_found)
823 charsets[CHARSET_ASCII] = 1; 1410 break;
824 if (maskbits & 2) 1411 }
825 charsets[CHARSET_8_BIT_CONTROL] = 1; 1412 }
826 if (maskbits & 4) 1413
827 charsets[CHARSET_8_BIT_GRAPHIC] = 1; 1414 /* Fixme: returns nil for unibyte. */
828 }
829 return 0;
830 }
831 else
832 {
833 int return_val = 1;
834 int bytes, charset, c1, c2;
835
836 if (! CHAR_TABLE_P (table))
837 table = Qnil;
838
839 while (nchars-- > 0)
840 {
841 SPLIT_MULTIBYTE_SEQ (ptr, len, bytes, charset, c1, c2);
842 ptr += bytes;
843
844 if (!CHARSET_DEFINED_P (charset))
845 charset = 1;
846 else if (! NILP (table))
847 {
848 int c = translate_char (table, -1, charset, c1, c2);
849 if (c >= 0)
850 charset = CHAR_CHARSET (c);
851 }
852
853 if (return_val == 1
854 && charset != CHARSET_ASCII
855 && charset != CHARSET_8_BIT_CONTROL
856 && charset != CHARSET_8_BIT_GRAPHIC
857 && charset != charset_latin_iso8859_1)
858 return_val = 2;
859
860 if (charsets)
861 charsets[charset] = 1;
862 else if (return_val == 2)
863 break;
864 }
865 return return_val;
866 }
867 }
868
869 DEFUN ("find-charset-region", Ffind_charset_region, Sfind_charset_region, 1415 DEFUN ("find-charset-region", Ffind_charset_region, Sfind_charset_region,
870 2, 3, 0, 1416 2, 3, 0,
871 doc: /* Return a list of charsets in the region between BEG and END. 1417 doc: /* Return a list of charsets in the region between BEG and END.
872 BEG and END are buffer positions. 1418 BEG and END are buffer positions.
873 Optional arg TABLE if non-nil is a translation table to look up. 1419 Optional arg TABLE if non-nil is a translation table to look up.
874 1420
875 If the region contains invalid multibyte characters,
876 `unknown' is included in the returned list.
877
878 If the current buffer is unibyte, the returned list may contain 1421 If the current buffer is unibyte, the returned list may contain
879 only `ascii', `eight-bit-control', and `eight-bit-graphic'. */) 1422 only `ascii', `eight-bit-control', and `eight-bit-graphic'. */)
880 (beg, end, table) 1423 (beg, end, table)
881 Lisp_Object beg, end, table; 1424 Lisp_Object beg, end, table;
882 { 1425 {
883 int charsets[MAX_CHARSET + 1]; 1426 Lisp_Object charsets;
884 int from, from_byte, to, stop, stop_byte, i; 1427 int from, from_byte, to, stop, stop_byte, i;
885 Lisp_Object val; 1428 Lisp_Object val;
886 1429
887 validate_region (&beg, &end); 1430 validate_region (&beg, &end);
888 from = XFASTINT (beg); 1431 from = XFASTINT (beg);
896 else 1439 else
897 stop_byte = CHAR_TO_BYTE (stop); 1440 stop_byte = CHAR_TO_BYTE (stop);
898 1441
899 from_byte = CHAR_TO_BYTE (from); 1442 from_byte = CHAR_TO_BYTE (from);
900 1443
901 bzero (charsets, (MAX_CHARSET + 1) * sizeof (int)); 1444 charsets = Fmake_vector (make_number (charset_table_used), Qnil);
1445 for (i = 0; i < charset_table_used; i++)
1446 ASET (charsets, i, Fcons (make_number (i), Qnil));
1447
902 while (1) 1448 while (1)
903 { 1449 {
904 find_charset_in_text (BYTE_POS_ADDR (from_byte), stop - from, 1450 find_charsets_in_text (BYTE_POS_ADDR (from_byte), stop - from,
905 stop_byte - from_byte, charsets, table); 1451 stop_byte - from_byte, charsets, table);
906 if (stop < to) 1452 if (stop < to)
907 { 1453 {
908 from = stop, from_byte = stop_byte; 1454 from = stop, from_byte = stop_byte;
909 stop = to, stop_byte = CHAR_TO_BYTE (stop); 1455 stop = to, stop_byte = CHAR_TO_BYTE (stop);
910 } 1456 }
911 else 1457 else
912 break; 1458 break;
913 } 1459 }
914 1460
915 val = Qnil; 1461 val = Qnil;
916 if (charsets[1]) 1462 for (i = charset_table_used - 1; i >= 0; i--)
917 val = Fcons (Qunknown, val); 1463 if (!NILP (XCDR (AREF (charsets, i))))
918 for (i = MAX_CHARSET; i >= MIN_CHARSET_OFFICIAL_DIMENSION1; i--) 1464 val = Fcons (CHARSET_NAME (charset_table + i), val);
919 if (charsets[i])
920 val = Fcons (CHARSET_SYMBOL (i), val);
921 if (charsets[0])
922 val = Fcons (Qascii, val);
923 return val; 1465 return val;
924 } 1466 }
925 1467
1468 /* Fixme: returns nil for unibyte. */
926 DEFUN ("find-charset-string", Ffind_charset_string, Sfind_charset_string, 1469 DEFUN ("find-charset-string", Ffind_charset_string, Sfind_charset_string,
927 1, 2, 0, 1470 1, 2, 0,
928 doc: /* Return a list of charsets in STR. 1471 doc: /* Return a list of charsets in STR.
929 Optional arg TABLE if non-nil is a translation table to look up. 1472 Optional arg TABLE if non-nil is a translation table to look up.
930 1473
931 If the string contains invalid multibyte characters,
932 `unknown' is included in the returned list.
933
934 If STR is unibyte, the returned list may contain 1474 If STR is unibyte, the returned list may contain
935 only `ascii', `eight-bit-control', and `eight-bit-graphic'. */) 1475 only `ascii', `eight-bit-control', and `eight-bit-graphic'. */)
936 (str, table) 1476 (str, table)
937 Lisp_Object str, table; 1477 Lisp_Object str, table;
938 { 1478 {
939 int charsets[MAX_CHARSET + 1]; 1479 Lisp_Object charsets;
940 int i; 1480 int i;
941 Lisp_Object val; 1481 Lisp_Object val;
942 1482
943 CHECK_STRING (str); 1483 CHECK_STRING (str);
944 1484
945 bzero (charsets, (MAX_CHARSET + 1) * sizeof (int)); 1485 charsets = Fmake_vector (make_number (charset_table_used), Qnil);
946 find_charset_in_text (SDATA (str), SCHARS (str), 1486 for (i = 0; i < charset_table_used; i++)
947 SBYTES (str), charsets, table); 1487 ASET (charsets, i, Fcons (make_number (i), Qnil));
1488 find_charsets_in_text (SDATA (str), SCHARS (str), SBYTES (str),
1489 charsets, table);
948 1490
949 val = Qnil; 1491 val = Qnil;
950 if (charsets[1]) 1492 for (i = charset_table_used - 1; i >= 0; i--)
951 val = Fcons (Qunknown, val); 1493 if (!NILP (XCDR (AREF (charsets, i))))
952 for (i = MAX_CHARSET; i >= MIN_CHARSET_OFFICIAL_DIMENSION1; i--) 1494 val = Fcons (CHARSET_NAME (charset_table + i), val);
953 if (charsets[i])
954 val = Fcons (CHARSET_SYMBOL (i), val);
955 if (charsets[0])
956 val = Fcons (Qascii, val);
957 return val; 1495 return val;
958 } 1496 }
959 1497
960 1498
961 DEFUN ("make-char-internal", Fmake_char_internal, Smake_char_internal, 1, 3, 0, 1499
962 doc: /* Return a character made from arguments. 1500 /* Return a character correponding to the code-point CODE of
963 Internal use only. */) 1501 CHARSET. */
964 (charset, code1, code2) 1502
965 Lisp_Object charset, code1, code2; 1503 int
966 { 1504 decode_char (charset, code)
967 int charset_id, c1, c2; 1505 struct charset *charset;
968 1506 unsigned code;
969 CHECK_NUMBER (charset); 1507 {
970 charset_id = XINT (charset); 1508 int c, char_index;
971 if (!CHARSET_DEFINED_P (charset_id)) 1509 enum charset_method method = CHARSET_METHOD (charset);
972 error ("Invalid charset ID: %d", XINT (charset)); 1510
973 1511 if (code < CHARSET_MIN_CODE (charset) || code > CHARSET_MAX_CODE (charset))
1512 return -1;
1513
1514 if (method == CHARSET_METHOD_MAP_DEFERRED)
1515 {
1516 load_charset (charset);
1517 method = CHARSET_METHOD (charset);
1518 }
1519
1520 if (method == CHARSET_METHOD_SUBSET)
1521 {
1522 Lisp_Object subset_info;
1523
1524 subset_info = CHARSET_SUBSET (charset);
1525 charset = CHARSET_FROM_ID (XFASTINT (AREF (subset_info, 0)));
1526 code -= XINT (AREF (subset_info, 3));
1527 if (code < XFASTINT (AREF (subset_info, 1))
1528 || code > XFASTINT (AREF (subset_info, 2)))
1529 c = -1;
1530 else
1531 c = DECODE_CHAR (charset, code);
1532 }
1533 else if (method == CHARSET_METHOD_SUPERSET)
1534 {
1535 Lisp_Object parents;
1536
1537 parents = CHARSET_SUPERSET (charset);
1538 c = -1;
1539 for (; CONSP (parents); parents = XCDR (parents))
1540 {
1541 int id = XINT (XCAR (XCAR (parents)));
1542 int code_offset = XINT (XCDR (XCAR (parents)));
1543 unsigned this_code = code - code_offset;
1544
1545 charset = CHARSET_FROM_ID (id);
1546 if ((c = DECODE_CHAR (charset, this_code)) >= 0)
1547 break;
1548 }
1549 }
1550 else
1551 {
1552 char_index = CODE_POINT_TO_INDEX (charset, code);
1553 if (char_index < 0)
1554 return -1;
1555
1556 if (method == CHARSET_METHOD_MAP)
1557 {
1558 Lisp_Object decoder;
1559
1560 decoder = CHARSET_DECODER (charset);
1561 if (! VECTORP (decoder))
1562 return -1;
1563 c = XINT (AREF (decoder, char_index));
1564 }
1565 else
1566 {
1567 c = char_index + CHARSET_CODE_OFFSET (charset);
1568 }
1569 }
1570
1571 if (CHARSET_UNIFIED_P (charset)
1572 && c >= 0)
1573 {
1574 MAYBE_UNIFY_CHAR (c);
1575 }
1576
1577 return c;
1578 }
1579
1580 /* Variable used temporarily by the macro ENCODE_CHAR. */
1581 Lisp_Object charset_work;
1582
1583 /* Return a code-point of CHAR in CHARSET. If CHAR doesn't belong to
1584 CHARSET, return CHARSET_INVALID_CODE (CHARSET). If STRICT is true,
1585 use CHARSET's strict_max_char instead of max_char. */
1586
1587 unsigned
1588 encode_char (charset, c)
1589 struct charset *charset;
1590 int c;
1591 {
1592 unsigned code;
1593 enum charset_method method = CHARSET_METHOD (charset);
1594
1595 if (CHARSET_UNIFIED_P (charset))
1596 {
1597 Lisp_Object deunifier, deunified;
1598
1599 deunifier = CHARSET_DEUNIFIER (charset);
1600 if (! CHAR_TABLE_P (deunifier))
1601 {
1602 Funify_charset (CHARSET_NAME (charset), Qnil, Qnil);
1603 deunifier = CHARSET_DEUNIFIER (charset);
1604 }
1605 deunified = CHAR_TABLE_REF (deunifier, c);
1606 if (! NILP (deunified))
1607 c = XINT (deunified);
1608 }
1609
1610 if (method == CHARSET_METHOD_SUBSET)
1611 {
1612 Lisp_Object subset_info;
1613 struct charset *this_charset;
1614
1615 subset_info = CHARSET_SUBSET (charset);
1616 this_charset = CHARSET_FROM_ID (XFASTINT (AREF (subset_info, 0)));
1617 code = ENCODE_CHAR (this_charset, c);
1618 if (code == CHARSET_INVALID_CODE (this_charset)
1619 || code < XFASTINT (AREF (subset_info, 1))
1620 || code > XFASTINT (AREF (subset_info, 2)))
1621 return CHARSET_INVALID_CODE (charset);
1622 code += XINT (AREF (subset_info, 3));
1623 return code;
1624 }
1625
1626 if (method == CHARSET_METHOD_SUPERSET)
1627 {
1628 Lisp_Object parents;
1629
1630 parents = CHARSET_SUPERSET (charset);
1631 for (; CONSP (parents); parents = XCDR (parents))
1632 {
1633 int id = XINT (XCAR (XCAR (parents)));
1634 int code_offset = XINT (XCDR (XCAR (parents)));
1635 struct charset *this_charset = CHARSET_FROM_ID (id);
1636
1637 code = ENCODE_CHAR (this_charset, c);
1638 if (code != CHARSET_INVALID_CODE (this_charset))
1639 return code + code_offset;
1640 }
1641 return CHARSET_INVALID_CODE (charset);
1642 }
1643
1644 if (! CHARSET_FAST_MAP_REF ((c), charset->fast_map)
1645 || c < CHARSET_MIN_CHAR (charset) || c > CHARSET_MAX_CHAR (charset))
1646 return CHARSET_INVALID_CODE (charset);
1647
1648 if (method == CHARSET_METHOD_MAP_DEFERRED)
1649 {
1650 load_charset (charset);
1651 method = CHARSET_METHOD (charset);
1652 }
1653
1654 if (method == CHARSET_METHOD_MAP)
1655 {
1656 Lisp_Object encoder;
1657 Lisp_Object val;
1658
1659 encoder = CHARSET_ENCODER (charset);
1660 if (! CHAR_TABLE_P (CHARSET_ENCODER (charset)))
1661 return CHARSET_INVALID_CODE (charset);
1662 val = CHAR_TABLE_REF (encoder, c);
1663 if (NILP (val))
1664 return CHARSET_INVALID_CODE (charset);
1665 code = XINT (val);
1666 if (! CHARSET_COMPACT_CODES_P (charset))
1667 code = INDEX_TO_CODE_POINT (charset, code);
1668 }
1669 else /* method == CHARSET_METHOD_OFFSET */
1670 {
1671 code = c - CHARSET_CODE_OFFSET (charset);
1672 code = INDEX_TO_CODE_POINT (charset, code);
1673 }
1674
1675 return code;
1676 }
1677
1678
1679 DEFUN ("decode-char", Fdecode_char, Sdecode_char, 2, 3, 0,
1680 doc: /* Decode the pair of CHARSET and CODE-POINT into a character.
1681 Return nil if CODE-POINT is not valid in CHARSET.
1682
1683 CODE-POINT may be a cons (HIGHER-16-BIT-VALUE . LOWER-16-BIT-VALUE).
1684
1685 Optional argument RESTRICTION specifies a way to map the pair of CCS
1686 and CODE-POINT to a chracter. Currently not supported and just ignored. */)
1687 (charset, code_point, restriction)
1688 Lisp_Object charset, code_point, restriction;
1689 {
1690 int c, id;
1691 unsigned code;
1692 struct charset *charsetp;
1693
1694 CHECK_CHARSET_GET_ID (charset, id);
1695 if (CONSP (code_point))
1696 {
1697 CHECK_NATNUM_CAR (code_point);
1698 CHECK_NATNUM_CDR (code_point);
1699 code = (XINT (XCAR (code_point)) << 16) | (XINT (XCDR (code_point)));
1700 }
1701 else
1702 {
1703 CHECK_NATNUM (code_point);
1704 code = XINT (code_point);
1705 }
1706 charsetp = CHARSET_FROM_ID (id);
1707 c = DECODE_CHAR (charsetp, code);
1708 return (c >= 0 ? make_number (c) : Qnil);
1709 }
1710
1711
1712 DEFUN ("encode-char", Fencode_char, Sencode_char, 2, 3, 0,
1713 doc: /* Encode the character CH into a code-point of CHARSET.
1714 Return nil if CHARSET doesn't include CH.
1715
1716 Optional argument RESTRICTION specifies a way to map CHAR to a
1717 code-point in CCS. Currently not supported and just ignored. */)
1718 (ch, charset, restriction)
1719 Lisp_Object ch, charset, restriction;
1720 {
1721 int id;
1722 unsigned code;
1723 struct charset *charsetp;
1724
1725 CHECK_CHARSET_GET_ID (charset, id);
1726 CHECK_NATNUM (ch);
1727 charsetp = CHARSET_FROM_ID (id);
1728 code = ENCODE_CHAR (charsetp, XINT (ch));
1729 if (code == CHARSET_INVALID_CODE (charsetp))
1730 return Qnil;
1731 if (code > 0x7FFFFFF)
1732 return Fcons (make_number (code >> 16), make_number (code & 0xFFFF));
1733 return make_number (code);
1734 }
1735
1736
1737 DEFUN ("make-char", Fmake_char, Smake_char, 1, 5, 0,
1738 doc:
1739 /* Return a character of CHARSET whose position codes are CODEn.
1740
1741 CODE1 through CODE4 are optional, but if you don't supply sufficient
1742 position codes, it is assumed that the minimum code in each dimension
1743 is specified. */)
1744 (charset, code1, code2, code3, code4)
1745 Lisp_Object charset, code1, code2, code3, code4;
1746 {
1747 int id, dimension;
1748 struct charset *charsetp;
1749 unsigned code;
1750 int c;
1751
1752 CHECK_CHARSET_GET_ID (charset, id);
1753 charsetp = CHARSET_FROM_ID (id);
1754
1755 dimension = CHARSET_DIMENSION (charsetp);
974 if (NILP (code1)) 1756 if (NILP (code1))
975 c1 = 0; 1757 code = (CHARSET_ASCII_COMPATIBLE_P (charsetp)
1758 ? 0 : CHARSET_MIN_CODE (charsetp));
976 else 1759 else
977 { 1760 {
978 CHECK_NUMBER (code1); 1761 CHECK_NATNUM (code1);
979 c1 = XINT (code1); 1762 if (XFASTINT (code1) >= 0x100)
980 } 1763 args_out_of_range (make_number (0xFF), code1);
981 if (NILP (code2)) 1764 code = XFASTINT (code1);
982 c2 = 0; 1765
983 else 1766 if (dimension > 1)
984 { 1767 {
985 CHECK_NUMBER (code2); 1768 code <<= 8;
986 c2 = XINT (code2); 1769 if (NILP (code2))
987 } 1770 code |= charsetp->code_space[(dimension - 2) * 4];
988 1771 else
989 if (charset_id == CHARSET_ASCII) 1772 {
990 { 1773 CHECK_NATNUM (code2);
991 if (c1 < 0 || c1 > 0x7F) 1774 if (XFASTINT (code2) >= 0x100)
992 goto invalid_code_posints; 1775 args_out_of_range (make_number (0xFF), code2);
993 return make_number (c1); 1776 code |= XFASTINT (code2);
994 } 1777 }
995 else if (charset_id == CHARSET_8_BIT_CONTROL) 1778
996 { 1779 if (dimension > 2)
997 if (NILP (code1)) 1780 {
998 c1 = 0x80; 1781 code <<= 8;
999 else if (c1 < 0x80 || c1 > 0x9F) 1782 if (NILP (code3))
1000 goto invalid_code_posints; 1783 code |= charsetp->code_space[(dimension - 3) * 4];
1001 return make_number (c1); 1784 else
1002 } 1785 {
1003 else if (charset_id == CHARSET_8_BIT_GRAPHIC) 1786 CHECK_NATNUM (code3);
1004 { 1787 if (XFASTINT (code3) >= 0x100)
1005 if (NILP (code1)) 1788 args_out_of_range (make_number (0xFF), code3);
1006 c1 = 0xA0; 1789 code |= XFASTINT (code3);
1007 else if (c1 < 0xA0 || c1 > 0xFF) 1790 }
1008 goto invalid_code_posints; 1791
1009 return make_number (c1); 1792 if (dimension > 3)
1010 } 1793 {
1011 else if (c1 < 0 || c1 > 0xFF || c2 < 0 || c2 > 0xFF) 1794 code <<= 8;
1012 goto invalid_code_posints; 1795 if (NILP (code4))
1013 c1 &= 0x7F; 1796 code |= charsetp->code_space[0];
1014 c2 &= 0x7F; 1797 else
1015 if (c1 == 0 1798 {
1016 ? c2 != 0 1799 CHECK_NATNUM (code4);
1017 : (c2 == 0 1800 if (XFASTINT (code4) >= 0x100)
1018 ? !CHAR_COMPONENTS_VALID_P (charset_id, c1, 0x20) 1801 args_out_of_range (make_number (0xFF), code4);
1019 : !CHAR_COMPONENTS_VALID_P (charset_id, c1, c2))) 1802 code |= XFASTINT (code4);
1020 goto invalid_code_posints; 1803 }
1021 return make_number (MAKE_CHAR (charset_id, c1, c2)); 1804 }
1022 1805 }
1023 invalid_code_posints: 1806 }
1024 error ("Invalid code points for charset ID %d: %d %d", charset_id, c1, c2); 1807 }
1025 } 1808
1026 1809 if (CHARSET_ISO_FINAL (charsetp) >= 0)
1810 code &= 0x7F7F7F7F;
1811 c = DECODE_CHAR (charsetp, code);
1812 if (c < 0)
1813 error ("Invalid code(s)");
1814 return make_number (c);
1815 }
1816
1817
1818 /* Return the first charset in CHARSET_LIST that contains C.
1819 CHARSET_LIST is a list of charset IDs. If it is nil, use
1820 Vcharset_ordered_list. */
1821
1822 struct charset *
1823 char_charset (c, charset_list, code_return)
1824 int c;
1825 Lisp_Object charset_list;
1826 unsigned *code_return;
1827 {
1828 if (NILP (charset_list))
1829 charset_list = Vcharset_ordered_list;
1830
1831 while (CONSP (charset_list))
1832 {
1833 struct charset *charset = CHARSET_FROM_ID (XINT (XCAR (charset_list)));
1834 unsigned code = ENCODE_CHAR (charset, c);
1835
1836 if (code != CHARSET_INVALID_CODE (charset))
1837 {
1838 if (code_return)
1839 *code_return = code;
1840 return charset;
1841 }
1842 charset_list = XCDR (charset_list);
1843 }
1844 return NULL;
1845 }
1846
1847
1848 /* Fixme: `unknown' can't happen now? */
1027 DEFUN ("split-char", Fsplit_char, Ssplit_char, 1, 1, 0, 1849 DEFUN ("split-char", Fsplit_char, Ssplit_char, 1, 1, 0,
1028 doc: /* Return list of charset and one or two position-codes of CHAR. 1850 doc: /*Return list of charset and one to three position-codes of CHAR.
1029 If CHAR is invalid as a character code, 1851 If CHAR is invalid as a character code, return a list `(unknown CHAR)'. */)
1030 return a list of symbol `unknown' and CHAR. */)
1031 (ch) 1852 (ch)
1032 Lisp_Object ch; 1853 Lisp_Object ch;
1033 { 1854 {
1034 int c, charset, c1, c2; 1855 struct charset *charset;
1035 1856 int c, dimension;
1036 CHECK_NUMBER (ch); 1857 unsigned code;
1858 Lisp_Object val;
1859
1860 CHECK_CHARACTER (ch);
1037 c = XFASTINT (ch); 1861 c = XFASTINT (ch);
1038 if (!CHAR_VALID_P (c, 1)) 1862 charset = CHAR_CHARSET (c);
1039 return Fcons (Qunknown, Fcons (ch, Qnil)); 1863 if (! charset)
1040 SPLIT_CHAR (XFASTINT (ch), charset, c1, c2); 1864 return Fcons (intern ("unknown"), Fcons (ch, Qnil));
1041 return (c2 >= 0 1865
1042 ? Fcons (CHARSET_SYMBOL (charset), 1866 code = ENCODE_CHAR (charset, c);
1043 Fcons (make_number (c1), Fcons (make_number (c2), Qnil))) 1867 if (code == CHARSET_INVALID_CODE (charset))
1044 : Fcons (CHARSET_SYMBOL (charset), Fcons (make_number (c1), Qnil))); 1868 abort ();
1045 } 1869 dimension = CHARSET_DIMENSION (charset);
1870 val = (dimension == 1 ? Fcons (make_number (code), Qnil)
1871 : dimension == 2 ? Fcons (make_number (code >> 8),
1872 Fcons (make_number (code & 0xFF), Qnil))
1873 : Fcons (make_number (code >> 16),
1874 Fcons (make_number ((code >> 8) & 0xFF),
1875 Fcons (make_number (code & 0xFF), Qnil))));
1876 return Fcons (CHARSET_NAME (charset), val);
1877 }
1878
1046 1879
1047 DEFUN ("char-charset", Fchar_charset, Schar_charset, 1, 1, 0, 1880 DEFUN ("char-charset", Fchar_charset, Schar_charset, 1, 1, 0,
1048 doc: /* Return charset of CHAR. */) 1881 doc: /* Return the charset of highest priority that contains CHAR. */)
1049 (ch) 1882 (ch)
1050 Lisp_Object ch; 1883 Lisp_Object ch;
1051 { 1884 {
1052 CHECK_NUMBER (ch); 1885 struct charset *charset;
1053 1886
1054 return CHARSET_SYMBOL (CHAR_CHARSET (XINT (ch))); 1887 CHECK_CHARACTER (ch);
1055 } 1888 charset = CHAR_CHARSET (XINT (ch));
1889 return (CHARSET_NAME (charset));
1890 }
1891
1056 1892
1057 DEFUN ("charset-after", Fcharset_after, Scharset_after, 0, 1, 0, 1893 DEFUN ("charset-after", Fcharset_after, Scharset_after, 0, 1, 0,
1058 doc: /* Return charset of a character in the current buffer at position POS. 1894 doc: /*
1895 Return charset of a character in the current buffer at position POS.
1059 If POS is nil, it defauls to the current point. 1896 If POS is nil, it defauls to the current point.
1060 If POS is out of range, the value is nil. */) 1897 If POS is out of range, the value is nil. */)
1061 (pos) 1898 (pos)
1062 Lisp_Object pos; 1899 Lisp_Object pos;
1063 { 1900 {
1064 Lisp_Object ch; 1901 Lisp_Object ch;
1065 int charset; 1902 struct charset *charset;
1066 1903
1067 ch = Fchar_after (pos); 1904 ch = Fchar_after (pos);
1068 if (! INTEGERP (ch)) 1905 if (! INTEGERP (ch))
1069 return ch; 1906 return ch;
1070 charset = CHAR_CHARSET (XINT (ch)); 1907 charset = CHAR_CHARSET (XINT (ch));
1071 return CHARSET_SYMBOL (charset); 1908 return (CHARSET_NAME (charset));
1072 } 1909 }
1910
1073 1911
1074 DEFUN ("iso-charset", Fiso_charset, Siso_charset, 3, 3, 0, 1912 DEFUN ("iso-charset", Fiso_charset, Siso_charset, 3, 3, 0,
1075 doc: /* Return charset of ISO's specification DIMENSION, CHARS, and FINAL-CHAR. 1913 doc: /*
1914 Return charset of ISO's specification DIMENSION, CHARS, and FINAL-CHAR.
1076 1915
1077 ISO 2022's designation sequence (escape sequence) distinguishes charsets 1916 ISO 2022's designation sequence (escape sequence) distinguishes charsets
1078 by their DIMENSION, CHARS, and FINAL-CHAR, 1917 by their DIMENSION, CHARS, and FINAL-CHAR,
1079 where as Emacs distinguishes them by charset symbol. 1918 where as Emacs distinguishes them by charset symbol.
1080 See the documentation of the function `charset-info' for the meanings of 1919 See the documentation of the function `charset-info' for the meanings of
1081 DIMENSION, CHARS, and FINAL-CHAR. */) 1920 DIMENSION, CHARS, and FINAL-CHAR. */)
1082 (dimension, chars, final_char) 1921 (dimension, chars, final_char)
1083 Lisp_Object dimension, chars, final_char; 1922 Lisp_Object dimension, chars, final_char;
1084 { 1923 {
1085 int charset; 1924 int id;
1086 1925
1087 CHECK_NUMBER (dimension); 1926 check_iso_charset_parameter (dimension, chars, final_char);
1088 CHECK_NUMBER (chars); 1927 id = ISO_CHARSET_TABLE (XFASTINT (dimension), XFASTINT (chars),
1089 CHECK_NUMBER (final_char); 1928 XFASTINT (final_char));
1090 1929 return (id >= 0 ? CHARSET_NAME (CHARSET_FROM_ID (id)) : Qnil);
1091 if ((charset = ISO_CHARSET_TABLE (dimension, chars, final_char)) < 0) 1930 }
1092 return Qnil; 1931
1093 return CHARSET_SYMBOL (charset); 1932
1094 } 1933 DEFUN ("clear-charset-maps", Fclear_charset_maps, Sclear_charset_maps,
1095 1934 0, 0, 0,
1096 /* If GENERICP is nonzero, return nonzero iff C is a valid normal or 1935 doc: /*
1097 generic character. If GENERICP is zero, return nonzero iff C is a 1936 Clear encoder and decoder of charsets that are loaded from mapfiles. */)
1098 valid normal character. Do not call this function directly, 1937 ()
1099 instead use macro CHAR_VALID_P. */ 1938 {
1100 int 1939 int i;
1101 char_valid_p (c, genericp) 1940 struct charset *charset;
1102 int c, genericp; 1941 Lisp_Object attrs;
1103 { 1942
1104 int charset, c1, c2; 1943 for (i = 0; i < charset_table_used; i++)
1105 1944 {
1106 if (c < 0 || c >= MAX_CHAR) 1945 charset = CHARSET_FROM_ID (i);
1107 return 0; 1946 attrs = CHARSET_ATTRIBUTES (charset);
1108 if (SINGLE_BYTE_CHAR_P (c)) 1947
1109 return 1; 1948 if (CHARSET_METHOD (charset) == CHARSET_METHOD_MAP)
1110 SPLIT_CHAR (c, charset, c1, c2); 1949 {
1111 if (genericp) 1950 CHARSET_ATTR_DECODER (attrs) = Qnil;
1112 { 1951 CHARSET_ATTR_ENCODER (attrs) = Qnil;
1113 if (c1) 1952 CHARSET_METHOD (charset) = CHARSET_METHOD_MAP_DEFERRED;
1114 { 1953 }
1115 if (c2 <= 0) c2 = 0x20; 1954
1116 } 1955 if (CHARSET_UNIFIED_P (charset))
1117 else 1956 CHARSET_ATTR_DEUNIFIER (attrs) = Qnil;
1118 { 1957 }
1119 if (c2 <= 0) c1 = c2 = 0x20; 1958
1120 } 1959 if (CHAR_TABLE_P (Vchar_unified_charset_table))
1121 } 1960 {
1122 return (CHARSET_DEFINED_P (charset) 1961 Foptimize_char_table (Vchar_unified_charset_table);
1123 && CHAR_COMPONENTS_VALID_P (charset, c1, c2)); 1962 Vchar_unify_table = Vchar_unified_charset_table;
1124 } 1963 Vchar_unified_charset_table = Qnil;
1125 1964 }
1126 DEFUN ("char-valid-p", Fchar_valid_p, Schar_valid_p, 1, 2, 0, 1965
1127 doc: /* Return t if OBJECT is a valid normal character. 1966 return Qnil;
1128 If optional arg GENERICP is non-nil, also return t if OBJECT is 1967 }
1129 a valid generic character. */) 1968
1130 (object, genericp) 1969 DEFUN ("charset-priority-list", Fcharset_priority_list,
1131 Lisp_Object object, genericp; 1970 Scharset_priority_list, 0, 1, 0,
1132 { 1971 doc: /* Return the list of charsets ordered by priority.
1133 if (! NATNUMP (object)) 1972 HIGHESTP non-nil means just return the highest priority one. */)
1134 return Qnil; 1973 (highestp)
1135 return (CHAR_VALID_P (XFASTINT (object), !NILP (genericp)) ? Qt : Qnil); 1974 Lisp_Object highestp;
1136 } 1975 {
1137 1976 Lisp_Object val = Qnil, list = Vcharset_ordered_list;
1138 DEFUN ("unibyte-char-to-multibyte", Funibyte_char_to_multibyte, 1977
1139 Sunibyte_char_to_multibyte, 1, 1, 0, 1978 if (!NILP (highestp))
1140 doc: /* Convert the unibyte character CH to multibyte character. 1979 return CHARSET_NAME (CHARSET_FROM_ID (XINT (Fcar (list))));
1141 The conversion is done based on `nonascii-translation-table' (which see) 1980
1142 or `nonascii-insert-offset' (which see). */) 1981 while (!NILP (list))
1143 (ch) 1982 {
1144 Lisp_Object ch; 1983 val = Fcons (CHARSET_NAME (CHARSET_FROM_ID (XINT (XCAR (list)))), val);
1145 { 1984 list = XCDR (list);
1146 int c; 1985 }
1147 1986 return Fnreverse (val);
1148 CHECK_NUMBER (ch); 1987 }
1149 c = XINT (ch); 1988
1150 if (c < 0 || c >= 0400) 1989 DEFUN ("set-charset-priority", Fset_charset_priority, Sset_charset_priority,
1151 error ("Invalid unibyte character: %d", c); 1990 1, MANY, 0,
1152 c = unibyte_char_to_multibyte (c); 1991 doc: /* Assign higher priority to the charsets given as arguments.
1153 if (c < 0) 1992 usage: (set-charset-priority &rest charsets) */)
1154 error ("Can't convert to multibyte character: %d", XINT (ch)); 1993 (nargs, args)
1155 return make_number (c); 1994 int nargs;
1156 } 1995 Lisp_Object *args;
1157 1996 {
1158 DEFUN ("multibyte-char-to-unibyte", Fmultibyte_char_to_unibyte, 1997 Lisp_Object new_head, old_list, arglist[2];
1159 Smultibyte_char_to_unibyte, 1, 1, 0, 1998 int i, id;
1160 doc: /* Convert the multibyte character CH to unibyte character. 1999
1161 The conversion is done based on `nonascii-translation-table' (which see) 2000 old_list = Fcopy_sequence (Vcharset_ordered_list);
1162 or `nonascii-insert-offset' (which see). */) 2001 new_head = Qnil;
1163 (ch) 2002 for (i = 0; i < nargs; i++)
1164 Lisp_Object ch; 2003 {
1165 { 2004 CHECK_CHARSET_GET_ID (args[i], id);
1166 int c; 2005 if (! NILP (Fmemq (make_number (id), old_list)))
1167 2006 {
1168 CHECK_NUMBER (ch); 2007 old_list = Fdelq (make_number (id), old_list);
1169 c = XINT (ch); 2008 new_head = Fcons (make_number (id), new_head);
1170 if (! CHAR_VALID_P (c, 0)) 2009 }
1171 error ("Invalid multibyte character: %d", c); 2010 }
1172 c = multibyte_char_to_unibyte (c, Qnil); 2011 arglist[0] = Fnreverse (new_head);
1173 if (c < 0) 2012 arglist[1] = old_list;
1174 error ("Can't convert to unibyte character: %d", XINT (ch)); 2013 Vcharset_ordered_list = Fnconc (2, arglist);
1175 return make_number (c); 2014 charset_ordered_list_tick++;
1176 } 2015
1177 2016 for (old_list = Vcharset_ordered_list, new_head = Qnil;
1178 DEFUN ("char-bytes", Fchar_bytes, Schar_bytes, 1, 1, 0, 2017 CONSP (old_list); old_list = XCDR (old_list))
1179 doc: /* Return 1 regardless of the argument CHAR. */) 2018 {
1180 (ch) 2019 if (! NILP (Fmemq (XCAR (old_list), Viso_2022_charset_list)))
1181 Lisp_Object ch; 2020 new_head = Fcons (XCAR (old_list), new_head);
1182 { 2021 }
1183 CHECK_NUMBER (ch); 2022 Viso_2022_charset_list = Fnreverse (new_head);
1184 return make_number (1); 2023
1185 } 2024 return Qnil;
1186 2025 }
1187 /* Return how many bytes C will occupy in a multibyte buffer. 2026
1188 Don't call this function directly, instead use macro CHAR_BYTES. */ 2027 DEFUN ("charset-id-internal", Fcharset_id_internal, Scharset_id_internal,
1189 int 2028 0, 1, 0,
1190 char_bytes (c) 2029 doc: /* Internal use only.
1191 int c; 2030 Return charset identification number of CHARSET. */)
1192 { 2031 (charset)
1193 int charset; 2032 Lisp_Object charset;
1194 2033 {
1195 if (ASCII_BYTE_P (c) || (c & ~((1 << CHARACTERBITS) -1))) 2034 int id;
1196 return 1; 2035
1197 if (SINGLE_BYTE_CHAR_P (c) && c >= 0xA0) 2036 CHECK_CHARSET_GET_ID (charset, id);
1198 return 1; 2037 return make_number (id);
1199 2038 }
1200 charset = CHAR_CHARSET (c); 2039
1201 return (CHARSET_DEFINED_P (charset) ? CHARSET_BYTES (charset) : 1); 2040
1202 }
1203
1204 /* Return the width of character of which multi-byte form starts with
1205 C. The width is measured by how many columns occupied on the
1206 screen when displayed in the current buffer. */
1207
1208 #define ONE_BYTE_CHAR_WIDTH(c) \
1209 (c < 0x20 \
1210 ? (c == '\t' \
1211 ? XFASTINT (current_buffer->tab_width) \
1212 : (c == '\n' ? 0 : (NILP (current_buffer->ctl_arrow) ? 4 : 2))) \
1213 : (c < 0x7f \
1214 ? 1 \
1215 : (c == 0x7F \
1216 ? (NILP (current_buffer->ctl_arrow) ? 4 : 2) \
1217 : ((! NILP (current_buffer->enable_multibyte_characters) \
1218 && BASE_LEADING_CODE_P (c)) \
1219 ? WIDTH_BY_CHAR_HEAD (c) \
1220 : 4))))
1221
1222 DEFUN ("char-width", Fchar_width, Schar_width, 1, 1, 0,
1223 doc: /* Return width of CHAR when displayed in the current buffer.
1224 The width is measured by how many columns it occupies on the screen.
1225 Tab is taken to occupy `tab-width' columns. */)
1226 (ch)
1227 Lisp_Object ch;
1228 {
1229 Lisp_Object val, disp;
1230 int c;
1231 struct Lisp_Char_Table *dp = buffer_display_table ();
1232
1233 CHECK_NUMBER (ch);
1234
1235 c = XINT (ch);
1236
1237 /* Get the way the display table would display it. */
1238 disp = dp ? DISP_CHAR_VECTOR (dp, c) : Qnil;
1239
1240 if (VECTORP (disp))
1241 XSETINT (val, XVECTOR (disp)->size);
1242 else if (SINGLE_BYTE_CHAR_P (c))
1243 XSETINT (val, ONE_BYTE_CHAR_WIDTH (c));
1244 else
1245 {
1246 int charset = CHAR_CHARSET (c);
1247
1248 XSETFASTINT (val, CHARSET_WIDTH (charset));
1249 }
1250 return val;
1251 }
1252
1253 /* Return width of string STR of length LEN when displayed in the
1254 current buffer. The width is measured by how many columns it
1255 occupies on the screen. */
1256
1257 int
1258 strwidth (str, len)
1259 unsigned char *str;
1260 int len;
1261 {
1262 return c_string_width (str, len, -1, NULL, NULL);
1263 }
1264
1265 /* Return width of string STR of length LEN when displayed in the
1266 current buffer. The width is measured by how many columns it
1267 occupies on the screen. If PRECISION > 0, return the width of
1268 longest substring that doesn't exceed PRECISION, and set number of
1269 characters and bytes of the substring in *NCHARS and *NBYTES
1270 respectively. */
1271
1272 int
1273 c_string_width (str, len, precision, nchars, nbytes)
1274 const unsigned char *str;
1275 int len, precision, *nchars, *nbytes;
1276 {
1277 int i = 0, i_byte = 0;
1278 int width = 0;
1279 int chars;
1280 struct Lisp_Char_Table *dp = buffer_display_table ();
1281
1282 while (i_byte < len)
1283 {
1284 int bytes, thiswidth;
1285 Lisp_Object val;
1286
1287 if (dp)
1288 {
1289 int c = STRING_CHAR_AND_LENGTH (str + i_byte, len - i_byte, bytes);
1290
1291 chars = 1;
1292 val = DISP_CHAR_VECTOR (dp, c);
1293 if (VECTORP (val))
1294 thiswidth = XVECTOR (val)->size;
1295 else
1296 thiswidth = ONE_BYTE_CHAR_WIDTH (str[i_byte]);
1297 }
1298 else
1299 {
1300 chars = 1;
1301 PARSE_MULTIBYTE_SEQ (str + i_byte, len - i_byte, bytes);
1302 thiswidth = ONE_BYTE_CHAR_WIDTH (str[i_byte]);
1303 }
1304
1305 if (precision > 0
1306 && (width + thiswidth > precision))
1307 {
1308 *nchars = i;
1309 *nbytes = i_byte;
1310 return width;
1311 }
1312 i++;
1313 i_byte += bytes;
1314 width += thiswidth;
1315 }
1316
1317 if (precision > 0)
1318 {
1319 *nchars = i;
1320 *nbytes = i_byte;
1321 }
1322
1323 return width;
1324 }
1325
1326 /* Return width of Lisp string STRING when displayed in the current
1327 buffer. The width is measured by how many columns it occupies on
1328 the screen while paying attention to compositions. If PRECISION >
1329 0, return the width of longest substring that doesn't exceed
1330 PRECISION, and set number of characters and bytes of the substring
1331 in *NCHARS and *NBYTES respectively. */
1332
1333 int
1334 lisp_string_width (string, precision, nchars, nbytes)
1335 Lisp_Object string;
1336 int precision, *nchars, *nbytes;
1337 {
1338 int len = SCHARS (string);
1339 int len_byte = SBYTES (string);
1340 const unsigned char *str = SDATA (string);
1341 int i = 0, i_byte = 0;
1342 int width = 0;
1343 struct Lisp_Char_Table *dp = buffer_display_table ();
1344
1345 while (i < len)
1346 {
1347 int chars, bytes, thiswidth;
1348 Lisp_Object val;
1349 int cmp_id;
1350 int ignore, end;
1351
1352 if (find_composition (i, -1, &ignore, &end, &val, string)
1353 && ((cmp_id = get_composition_id (i, i_byte, end - i, val, string))
1354 >= 0))
1355 {
1356 thiswidth = composition_table[cmp_id]->width;
1357 chars = end - i;
1358 bytes = string_char_to_byte (string, end) - i_byte;
1359 }
1360 else if (dp)
1361 {
1362 int c = STRING_CHAR_AND_LENGTH (str + i_byte, len - i_byte, bytes);
1363
1364 chars = 1;
1365 val = DISP_CHAR_VECTOR (dp, c);
1366 if (VECTORP (val))
1367 thiswidth = XVECTOR (val)->size;
1368 else
1369 thiswidth = ONE_BYTE_CHAR_WIDTH (str[i_byte]);
1370 }
1371 else
1372 {
1373 chars = 1;
1374 PARSE_MULTIBYTE_SEQ (str + i_byte, len_byte - i_byte, bytes);
1375 thiswidth = ONE_BYTE_CHAR_WIDTH (str[i_byte]);
1376 }
1377
1378 if (precision > 0
1379 && (width + thiswidth > precision))
1380 {
1381 *nchars = i;
1382 *nbytes = i_byte;
1383 return width;
1384 }
1385 i += chars;
1386 i_byte += bytes;
1387 width += thiswidth;
1388 }
1389
1390 if (precision > 0)
1391 {
1392 *nchars = i;
1393 *nbytes = i_byte;
1394 }
1395
1396 return width;
1397 }
1398
1399 DEFUN ("string-width", Fstring_width, Sstring_width, 1, 1, 0,
1400 doc: /* Return width of STRING when displayed in the current buffer.
1401 Width is measured by how many columns it occupies on the screen.
1402 When calculating width of a multibyte character in STRING,
1403 only the base leading-code is considered; the validity of
1404 the following bytes is not checked. Tabs in STRING are always
1405 taken to occupy `tab-width' columns. */)
1406 (str)
1407 Lisp_Object str;
1408 {
1409 Lisp_Object val;
1410
1411 CHECK_STRING (str);
1412 XSETFASTINT (val, lisp_string_width (str, -1, NULL, NULL));
1413 return val;
1414 }
1415
1416 DEFUN ("char-direction", Fchar_direction, Schar_direction, 1, 1, 0,
1417 doc: /* Return the direction of CHAR.
1418 The returned value is 0 for left-to-right and 1 for right-to-left. */)
1419 (ch)
1420 Lisp_Object ch;
1421 {
1422 int charset;
1423
1424 CHECK_NUMBER (ch);
1425 charset = CHAR_CHARSET (XFASTINT (ch));
1426 if (!CHARSET_DEFINED_P (charset))
1427 invalid_character (XINT (ch));
1428 return CHARSET_TABLE_INFO (charset, CHARSET_DIRECTION_IDX);
1429 }
1430
1431 DEFUN ("chars-in-region", Fchars_in_region, Schars_in_region, 2, 2, 0,
1432 doc: /* Return number of characters between BEG and END. */)
1433 (beg, end)
1434 Lisp_Object beg, end;
1435 {
1436 int from, to;
1437
1438 CHECK_NUMBER_COERCE_MARKER (beg);
1439 CHECK_NUMBER_COERCE_MARKER (end);
1440
1441 from = min (XFASTINT (beg), XFASTINT (end));
1442 to = max (XFASTINT (beg), XFASTINT (end));
1443
1444 return make_number (to - from);
1445 }
1446
1447 /* Return the number of characters in the NBYTES bytes at PTR.
1448 This works by looking at the contents and checking for multibyte sequences.
1449 However, if the current buffer has enable-multibyte-characters = nil,
1450 we treat each byte as a character. */
1451
1452 int
1453 chars_in_text (ptr, nbytes)
1454 const unsigned char *ptr;
1455 int nbytes;
1456 {
1457 /* current_buffer is null at early stages of Emacs initialization. */
1458 if (current_buffer == 0
1459 || NILP (current_buffer->enable_multibyte_characters))
1460 return nbytes;
1461
1462 return multibyte_chars_in_text (ptr, nbytes);
1463 }
1464
1465 /* Return the number of characters in the NBYTES bytes at PTR.
1466 This works by looking at the contents and checking for multibyte sequences.
1467 It ignores enable-multibyte-characters. */
1468
1469 int
1470 multibyte_chars_in_text (ptr, nbytes)
1471 const unsigned char *ptr;
1472 int nbytes;
1473 {
1474 const unsigned char *endp;
1475 int chars, bytes;
1476
1477 endp = ptr + nbytes;
1478 chars = 0;
1479
1480 while (ptr < endp)
1481 {
1482 PARSE_MULTIBYTE_SEQ (ptr, endp - ptr, bytes);
1483 ptr += bytes;
1484 chars++;
1485 }
1486
1487 return chars;
1488 }
1489
1490 /* Parse unibyte text at STR of LEN bytes as multibyte text, and
1491 count the numbers of characters and bytes in it. On counting
1492 bytes, pay attention to the fact that 8-bit characters in the range
1493 0x80..0x9F are represented by 2 bytes in multibyte text. */
1494 void 2041 void
1495 parse_str_as_multibyte (str, len, nchars, nbytes) 2042 init_charset ()
1496 const unsigned char *str; 2043 {
1497 int len, *nchars, *nbytes; 2044
1498 { 2045 }
1499 const unsigned char *endp = str + len; 2046
1500 int n, chars = 0, bytes = 0;
1501
1502 while (str < endp)
1503 {
1504 if (UNIBYTE_STR_AS_MULTIBYTE_P (str, endp - str, n))
1505 str += n, bytes += n;
1506 else
1507 str++, bytes += 2;
1508 chars++;
1509 }
1510 *nchars = chars;
1511 *nbytes = bytes;
1512 return;
1513 }
1514
1515 /* Arrange unibyte text at STR of NBYTES bytes as multibyte text.
1516 It actually converts only 8-bit characters in the range 0x80..0x9F
1517 that don't contruct multibyte characters to multibyte forms. If
1518 NCHARS is nonzero, set *NCHARS to the number of characters in the
1519 text. It is assured that we can use LEN bytes at STR as a work
1520 area and that is enough. Return the number of bytes of the
1521 resulting text. */
1522
1523 int
1524 str_as_multibyte (str, len, nbytes, nchars)
1525 unsigned char *str;
1526 int len, nbytes, *nchars;
1527 {
1528 unsigned char *p = str, *endp = str + nbytes;
1529 unsigned char *to;
1530 int chars = 0;
1531 int n;
1532
1533 while (p < endp && UNIBYTE_STR_AS_MULTIBYTE_P (p, endp - p, n))
1534 p += n, chars++;
1535 if (nchars)
1536 *nchars = chars;
1537 if (p == endp)
1538 return nbytes;
1539
1540 to = p;
1541 nbytes = endp - p;
1542 endp = str + len;
1543 safe_bcopy (p, endp - nbytes, nbytes);
1544 p = endp - nbytes;
1545 while (p < endp)
1546 {
1547 if (UNIBYTE_STR_AS_MULTIBYTE_P (p, endp - p, n))
1548 {
1549 while (n--)
1550 *to++ = *p++;
1551 }
1552 else
1553 {
1554 *to++ = LEADING_CODE_8_BIT_CONTROL;
1555 *to++ = *p++ + 0x20;
1556 }
1557 chars++;
1558 }
1559 if (nchars)
1560 *nchars = chars;
1561 return (to - str);
1562 }
1563
1564 /* Parse unibyte string at STR of LEN bytes, and return the number of
1565 bytes it may ocupy when converted to multibyte string by
1566 `str_to_multibyte'. */
1567
1568 int
1569 parse_str_to_multibyte (str, len)
1570 unsigned char *str;
1571 int len;
1572 {
1573 unsigned char *endp = str + len;
1574 int bytes;
1575
1576 for (bytes = 0; str < endp; str++)
1577 bytes += (*str < 0x80 || *str >= 0xA0) ? 1 : 2;
1578 return bytes;
1579 }
1580
1581 /* Convert unibyte text at STR of NBYTES bytes to multibyte text
1582 that contains the same single-byte characters. It actually
1583 converts all 8-bit characters to multibyte forms. It is assured
1584 that we can use LEN bytes at STR as a work area and that is
1585 enough. */
1586
1587 int
1588 str_to_multibyte (str, len, bytes)
1589 unsigned char *str;
1590 int len, bytes;
1591 {
1592 unsigned char *p = str, *endp = str + bytes;
1593 unsigned char *to;
1594
1595 while (p < endp && (*p < 0x80 || *p >= 0xA0)) p++;
1596 if (p == endp)
1597 return bytes;
1598 to = p;
1599 bytes = endp - p;
1600 endp = str + len;
1601 safe_bcopy (p, endp - bytes, bytes);
1602 p = endp - bytes;
1603 while (p < endp)
1604 {
1605 if (*p < 0x80 || *p >= 0xA0)
1606 *to++ = *p++;
1607 else
1608 *to++ = LEADING_CODE_8_BIT_CONTROL, *to++ = *p++ + 0x20;
1609 }
1610 return (to - str);
1611 }
1612
1613 /* Arrange multibyte text at STR of LEN bytes as a unibyte text. It
1614 actually converts only 8-bit characters in the range 0x80..0x9F to
1615 unibyte forms. */
1616
1617 int
1618 str_as_unibyte (str, bytes)
1619 unsigned char *str;
1620 int bytes;
1621 {
1622 unsigned char *p = str, *endp = str + bytes;
1623 unsigned char *to = str;
1624
1625 while (p < endp && *p != LEADING_CODE_8_BIT_CONTROL) p++;
1626 to = p;
1627 while (p < endp)
1628 {
1629 if (*p == LEADING_CODE_8_BIT_CONTROL)
1630 *to++ = *(p + 1) - 0x20, p += 2;
1631 else
1632 *to++ = *p++;
1633 }
1634 return (to - str);
1635 }
1636
1637
1638 DEFUN ("string", Fstring, Sstring, 0, MANY, 0,
1639 doc: /* Concatenate all the argument characters and make the result a string.
1640 usage: (string &rest CHARACTERS) */)
1641 (n, args)
1642 int n;
1643 Lisp_Object *args;
1644 {
1645 int i;
1646 unsigned char *buf = (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH * n);
1647 unsigned char *p = buf;
1648 int c;
1649 int multibyte = 0;
1650
1651 for (i = 0; i < n; i++)
1652 {
1653 CHECK_NUMBER (args[i]);
1654 if (!multibyte && !SINGLE_BYTE_CHAR_P (XFASTINT (args[i])))
1655 multibyte = 1;
1656 }
1657
1658 for (i = 0; i < n; i++)
1659 {
1660 c = XINT (args[i]);
1661 if (multibyte)
1662 p += CHAR_STRING (c, p);
1663 else
1664 *p++ = c;
1665 }
1666
1667 return make_string_from_bytes (buf, n, p - buf);
1668 }
1669
1670 #endif /* emacs */
1671
1672 int
1673 charset_id_internal (charset_name)
1674 char *charset_name;
1675 {
1676 Lisp_Object val;
1677
1678 val= Fget (intern (charset_name), Qcharset);
1679 if (!VECTORP (val))
1680 error ("Charset %s is not defined", charset_name);
1681
1682 return (XINT (XVECTOR (val)->contents[0]));
1683 }
1684
1685 DEFUN ("setup-special-charsets", Fsetup_special_charsets,
1686 Ssetup_special_charsets, 0, 0, 0, doc: /* Internal use only. */)
1687 ()
1688 {
1689 charset_latin_iso8859_1 = charset_id_internal ("latin-iso8859-1");
1690 charset_jisx0208_1978 = charset_id_internal ("japanese-jisx0208-1978");
1691 charset_jisx0208 = charset_id_internal ("japanese-jisx0208");
1692 charset_katakana_jisx0201 = charset_id_internal ("katakana-jisx0201");
1693 charset_latin_jisx0201 = charset_id_internal ("latin-jisx0201");
1694 charset_big5_1 = charset_id_internal ("chinese-big5-1");
1695 charset_big5_2 = charset_id_internal ("chinese-big5-2");
1696 return Qnil;
1697 }
1698 2047
1699 void 2048 void
1700 init_charset_once () 2049 init_charset_once ()
1701 { 2050 {
1702 int i, j, k; 2051 int i, j, k;
1703 2052
1704 staticpro (&Vcharset_table); 2053 for (i = 0; i < ISO_MAX_DIMENSION; i++)
1705 staticpro (&Vcharset_symbol_table); 2054 for (j = 0; j < ISO_MAX_CHARS; j++)
1706 staticpro (&Vgeneric_character_list); 2055 for (k = 0; k < ISO_MAX_FINAL; k++)
1707 2056 iso_charset_table[i][j][k] = -1;
1708 /* This has to be done here, before we call Fmake_char_table. */
1709 Qcharset_table = intern ("charset-table");
1710 staticpro (&Qcharset_table);
1711
1712 /* Intern this now in case it isn't already done.
1713 Setting this variable twice is harmless.
1714 But don't staticpro it here--that is done in alloc.c. */
1715 Qchar_table_extra_slots = intern ("char-table-extra-slots");
1716
1717 /* Now we are ready to set up this property, so we can
1718 create the charset table. */
1719 Fput (Qcharset_table, Qchar_table_extra_slots, make_number (0));
1720 Vcharset_table = Fmake_char_table (Qcharset_table, Qnil);
1721
1722 Qunknown = intern ("unknown");
1723 staticpro (&Qunknown);
1724 Vcharset_symbol_table = Fmake_vector (make_number (MAX_CHARSET + 1),
1725 Qunknown);
1726
1727 /* Setup tables. */
1728 for (i = 0; i < 2; i++)
1729 for (j = 0; j < 2; j++)
1730 for (k = 0; k < 128; k++)
1731 iso_charset_table [i][j][k] = -1;
1732 2057
1733 for (i = 0; i < 256; i++) 2058 for (i = 0; i < 256; i++)
1734 bytes_by_char_head[i] = 1; 2059 emacs_mule_charset[i] = NULL;
1735 bytes_by_char_head[LEADING_CODE_PRIVATE_11] = 3; 2060
1736 bytes_by_char_head[LEADING_CODE_PRIVATE_12] = 3; 2061 charset_jisx0201_roman = -1;
1737 bytes_by_char_head[LEADING_CODE_PRIVATE_21] = 4; 2062 charset_jisx0208_1978 = -1;
1738 bytes_by_char_head[LEADING_CODE_PRIVATE_22] = 4; 2063 charset_jisx0208 = -1;
1739 2064
1740 for (i = 0; i < 128; i++) 2065 for (i = 0; i < 128; i++)
1741 width_by_char_head[i] = 1; 2066 unibyte_to_multibyte_table[i] = i;
1742 for (; i < 256; i++) 2067 for (; i < 256; i++)
1743 width_by_char_head[i] = 4; 2068 unibyte_to_multibyte_table[i] = BYTE8_TO_CHAR (i);
1744 width_by_char_head[LEADING_CODE_PRIVATE_11] = 1;
1745 width_by_char_head[LEADING_CODE_PRIVATE_12] = 2;
1746 width_by_char_head[LEADING_CODE_PRIVATE_21] = 1;
1747 width_by_char_head[LEADING_CODE_PRIVATE_22] = 2;
1748
1749 {
1750 Lisp_Object val;
1751
1752 val = Qnil;
1753 for (i = 0x81; i < 0x90; i++)
1754 val = Fcons (make_number ((i - 0x70) << 7), val);
1755 for (; i < 0x9A; i++)
1756 val = Fcons (make_number ((i - 0x8F) << 14), val);
1757 for (i = 0xA0; i < 0xF0; i++)
1758 val = Fcons (make_number ((i - 0x70) << 7), val);
1759 for (; i < 0xFF; i++)
1760 val = Fcons (make_number ((i - 0xE0) << 14), val);
1761 Vgeneric_character_list = Fnreverse (val);
1762 }
1763
1764 nonascii_insert_offset = 0;
1765 Vnonascii_translation_table = Qnil;
1766 } 2069 }
1767 2070
1768 #ifdef emacs 2071 #ifdef emacs
1769 2072
1770 void 2073 void
1771 syms_of_charset () 2074 syms_of_charset ()
1772 { 2075 {
1773 Qcharset = intern ("charset"); 2076 char *p;
1774 staticpro (&Qcharset); 2077
1775 2078 DEFSYM (Qcharsetp, "charsetp");
1776 Qascii = intern ("ascii"); 2079
1777 staticpro (&Qascii); 2080 DEFSYM (Qascii, "ascii");
1778 2081 DEFSYM (Qunicode, "unicode");
1779 Qeight_bit_control = intern ("eight-bit-control"); 2082 DEFSYM (Qeight_bit, "eight-bit");
1780 staticpro (&Qeight_bit_control); 2083 DEFSYM (Qiso_8859_1, "iso-8859-1");
1781 2084
1782 Qeight_bit_graphic = intern ("eight-bit-graphic"); 2085 DEFSYM (Qgl, "gl");
1783 staticpro (&Qeight_bit_graphic); 2086 DEFSYM (Qgr, "gr");
1784 2087
1785 /* Define special charsets ascii, eight-bit-control, and 2088 p = (char *) xmalloc (30000);
1786 eight-bit-graphic. */ 2089
1787 update_charset_table (make_number (CHARSET_ASCII), 2090 staticpro (&Vcharset_ordered_list);
1788 make_number (1), make_number (94), 2091 Vcharset_ordered_list = Qnil;
1789 make_number (1), 2092
1790 make_number (0), 2093 staticpro (&Viso_2022_charset_list);
1791 make_number ('B'), 2094 Viso_2022_charset_list = Qnil;
1792 make_number (0), 2095
1793 build_string ("ASCII"), 2096 staticpro (&Vemacs_mule_charset_list);
1794 Qnil, /* same as above */ 2097 Vemacs_mule_charset_list = Qnil;
1795 build_string ("ASCII (ISO646 IRV)")); 2098
1796 CHARSET_SYMBOL (CHARSET_ASCII) = Qascii; 2099 staticpro (&Vcharset_hash_table);
1797 Fput (Qascii, Qcharset, CHARSET_TABLE_ENTRY (CHARSET_ASCII)); 2100 {
1798 2101 Lisp_Object args[2];
1799 update_charset_table (make_number (CHARSET_8_BIT_CONTROL), 2102 args[0] = QCtest;
1800 make_number (1), make_number (96), 2103 args[1] = Qeq;
1801 make_number (4), 2104 Vcharset_hash_table = Fmake_hash_table (2, args);
1802 make_number (0), 2105 }
1803 make_number (-1), 2106
1804 make_number (-1), 2107 charset_table_size = 128;
1805 build_string ("8-bit control code (0x80..0x9F)"), 2108 charset_table = ((struct charset *)
1806 Qnil, /* same as above */ 2109 xmalloc (sizeof (struct charset) * charset_table_size));
1807 Qnil); /* same as above */ 2110 charset_table_used = 0;
1808 CHARSET_SYMBOL (CHARSET_8_BIT_CONTROL) = Qeight_bit_control; 2111
1809 Fput (Qeight_bit_control, Qcharset, 2112 staticpro (&Vchar_unified_charset_table);
1810 CHARSET_TABLE_ENTRY (CHARSET_8_BIT_CONTROL)); 2113 Vchar_unified_charset_table = Fmake_char_table (Qnil, make_number (-1));
1811 2114
1812 update_charset_table (make_number (CHARSET_8_BIT_GRAPHIC), 2115 defsubr (&Scharsetp);
1813 make_number (1), make_number (96), 2116 defsubr (&Smap_charset_chars);
1814 make_number (4), 2117 defsubr (&Sdefine_charset_internal);
1815 make_number (0), 2118 defsubr (&Sdefine_charset_alias);
1816 make_number (-1), 2119 defsubr (&Sunibyte_charset);
1817 make_number (-1), 2120 defsubr (&Sset_unibyte_charset);
1818 build_string ("8-bit graphic char (0xA0..0xFF)"), 2121 defsubr (&Scharset_plist);
1819 Qnil, /* same as above */ 2122 defsubr (&Sset_charset_plist);
1820 Qnil); /* same as above */ 2123 defsubr (&Sunify_charset);
1821 CHARSET_SYMBOL (CHARSET_8_BIT_GRAPHIC) = Qeight_bit_graphic;
1822 Fput (Qeight_bit_graphic, Qcharset,
1823 CHARSET_TABLE_ENTRY (CHARSET_8_BIT_GRAPHIC));
1824
1825 Qauto_fill_chars = intern ("auto-fill-chars");
1826 staticpro (&Qauto_fill_chars);
1827 Fput (Qauto_fill_chars, Qchar_table_extra_slots, make_number (0));
1828
1829 defsubr (&Sdefine_charset);
1830 defsubr (&Sgeneric_character_list);
1831 defsubr (&Sget_unused_iso_final_char); 2124 defsubr (&Sget_unused_iso_final_char);
1832 defsubr (&Sdeclare_equiv_charset); 2125 defsubr (&Sdeclare_equiv_charset);
1833 defsubr (&Sfind_charset_region); 2126 defsubr (&Sfind_charset_region);
1834 defsubr (&Sfind_charset_string); 2127 defsubr (&Sfind_charset_string);
1835 defsubr (&Smake_char_internal); 2128 defsubr (&Sdecode_char);
2129 defsubr (&Sencode_char);
1836 defsubr (&Ssplit_char); 2130 defsubr (&Ssplit_char);
2131 defsubr (&Smake_char);
1837 defsubr (&Schar_charset); 2132 defsubr (&Schar_charset);
1838 defsubr (&Scharset_after); 2133 defsubr (&Scharset_after);
1839 defsubr (&Siso_charset); 2134 defsubr (&Siso_charset);
1840 defsubr (&Schar_valid_p); 2135 defsubr (&Sclear_charset_maps);
1841 defsubr (&Sunibyte_char_to_multibyte); 2136 defsubr (&Scharset_priority_list);
1842 defsubr (&Smultibyte_char_to_unibyte); 2137 defsubr (&Sset_charset_priority);
1843 defsubr (&Schar_bytes); 2138 defsubr (&Scharset_id_internal);
1844 defsubr (&Schar_width); 2139
1845 defsubr (&Sstring_width); 2140 DEFVAR_LISP ("charset-map-directory", &Vcharset_map_directory,
1846 defsubr (&Schar_direction); 2141 doc: /* Directory of charset map files that come with GNU Emacs.
1847 defsubr (&Schars_in_region); 2142 The default value is sub-directory "charsets" of `data-directory'. */);
1848 defsubr (&Sstring); 2143 Vcharset_map_directory = Fexpand_file_name (build_string ("charsets"),
1849 defsubr (&Ssetup_special_charsets); 2144 Vdata_directory);
1850 2145
1851 DEFVAR_LISP ("charset-list", &Vcharset_list, 2146 DEFVAR_LISP ("charset-list", &Vcharset_list,
1852 doc: /* List of charsets ever defined. */); 2147 doc: /* List of all charsets ever defined. */);
1853 Vcharset_list = Fcons (Qascii, Fcons (Qeight_bit_control, 2148 Vcharset_list = Qnil;
1854 Fcons (Qeight_bit_graphic, Qnil))); 2149
1855 2150 charset_ascii
1856 DEFVAR_LISP ("translation-table-vector", &Vtranslation_table_vector, 2151 = define_charset_internal (Qascii, 1, "\x00\x7F\x00\x00\x00\x00",
1857 doc: /* Vector of cons cell of a symbol and translation table ever defined. 2152 0, 127, 'B', -1, 0, 1, 0, 0);
1858 An ID of a translation table is an index of this vector. */); 2153 charset_iso_8859_1
1859 Vtranslation_table_vector = Fmake_vector (make_number (16), Qnil); 2154 = define_charset_internal (Qiso_8859_1, 1, "\x00\xFF\x00\x00\x00\x00",
1860 2155 0, 255, -1, -1, -1, 1, 0, 0);
1861 DEFVAR_INT ("leading-code-private-11", &leading_code_private_11, 2156 charset_unicode
1862 doc: /* Leading-code of private TYPE9N charset of column-width 1. */); 2157 = define_charset_internal (Qunicode, 3, "\x00\xFF\x00\xFF\x00\x10",
1863 leading_code_private_11 = LEADING_CODE_PRIVATE_11; 2158 0, MAX_UNICODE_CHAR, -1, 0, -1, 1, 0, 0);
1864 2159 charset_eight_bit
1865 DEFVAR_INT ("leading-code-private-12", &leading_code_private_12, 2160 = define_charset_internal (Qeight_bit, 1, "\x80\xFF\x00\x00\x00\x00",
1866 doc: /* Leading-code of private TYPE9N charset of column-width 2. */); 2161 128, 255, -1, 0, -1, 0, 0,
1867 leading_code_private_12 = LEADING_CODE_PRIVATE_12; 2162 MAX_5_BYTE_CHAR + 1);
1868
1869 DEFVAR_INT ("leading-code-private-21", &leading_code_private_21,
1870 doc: /* Leading-code of private TYPE9Nx9N charset of column-width 1. */);
1871 leading_code_private_21 = LEADING_CODE_PRIVATE_21;
1872
1873 DEFVAR_INT ("leading-code-private-22", &leading_code_private_22,
1874 doc: /* Leading-code of private TYPE9Nx9N charset of column-width 2. */);
1875 leading_code_private_22 = LEADING_CODE_PRIVATE_22;
1876
1877 DEFVAR_INT ("nonascii-insert-offset", &nonascii_insert_offset,
1878 doc: /* Offset for converting non-ASCII unibyte codes 0240...0377 to multibyte.
1879 This is used for converting unibyte text to multibyte,
1880 and for inserting character codes specified by number.
1881
1882 This serves to convert a Latin-1 or similar 8-bit character code
1883 to the corresponding Emacs multibyte character code.
1884 Typically the value should be (- (make-char CHARSET 0) 128),
1885 for your choice of character set.
1886 If `nonascii-translation-table' is non-nil, it overrides this variable. */);
1887 nonascii_insert_offset = 0;
1888
1889 DEFVAR_LISP ("nonascii-translation-table", &Vnonascii_translation_table,
1890 doc: /* Translation table to convert non-ASCII unibyte codes to multibyte.
1891 This is used for converting unibyte text to multibyte,
1892 and for inserting character codes specified by number.
1893
1894 Conversion is performed only when multibyte characters are enabled,
1895 and it serves to convert a Latin-1 or similar 8-bit character code
1896 to the corresponding Emacs character code.
1897
1898 If this is nil, `nonascii-insert-offset' is used instead.
1899 See also the docstring of `make-translation-table'. */);
1900 Vnonascii_translation_table = Qnil;
1901
1902 DEFVAR_LISP ("auto-fill-chars", &Vauto_fill_chars,
1903 doc: /* A char-table for characters which invoke auto-filling.
1904 Such characters have value t in this table. */);
1905 Vauto_fill_chars = Fmake_char_table (Qauto_fill_chars, Qnil);
1906 CHAR_TABLE_SET (Vauto_fill_chars, make_number (' '), Qt);
1907 CHAR_TABLE_SET (Vauto_fill_chars, make_number ('\n'), Qt);
1908 } 2163 }
1909 2164
1910 #endif /* emacs */ 2165 #endif /* emacs */