(x_set_alpha): Set alpha to -1 if nil given.
[bpt/emacs.git] / src / charset.c
CommitLineData
3263d5a2 1/* Basic character set support.
c8f94403
GM
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008 Free Software Foundation, Inc.
7976eda0 4 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
8cabe764 5 2005, 2006, 2007, 2008
ce03bf76
KH
6 National Institute of Advanced Industrial Science and Technology (AIST)
7 Registration Number H14PRO021
4ed46869 8
327719ee 9 Copyright (C) 2003, 2004
3263d5a2
KH
10 National Institute of Advanced Industrial Science and Technology (AIST)
11 Registration Number H13PRO009
4ed46869 12
369314dc
KH
13This file is part of GNU Emacs.
14
9ec0b715 15GNU Emacs is free software: you can redistribute it and/or modify
369314dc 16it under the terms of the GNU General Public License as published by
9ec0b715
GM
17the Free Software Foundation, either version 3 of the License, or
18(at your option) any later version.
4ed46869 19
369314dc
KH
20GNU Emacs is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23GNU General Public License for more details.
4ed46869 24
369314dc 25You should have received a copy of the GNU General Public License
9ec0b715 26along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
4ed46869 27
68c45bf0 28#include <config.h>
68c45bf0 29
4ed46869 30#include <stdio.h>
3263d5a2
KH
31#include <unistd.h>
32#include <ctype.h>
4ed46869 33#include <sys/types.h>
4ed46869 34#include "lisp.h"
3263d5a2 35#include "character.h"
4ed46869
KH
36#include "charset.h"
37#include "coding.h"
fc6b09bf 38#include "disptab.h"
3263d5a2 39#include "buffer.h"
4ed46869 40
04c2f2c5 41/*** GENERAL NOTES on CODED CHARACTER SETS (CHARSETS) ***
4ed46869 42
3263d5a2 43 A coded character set ("charset" hereafter) is a meaningful
04c2f2c5 44 collection (i.e. language, culture, functionality, etc.) of
3263d5a2 45 characters. Emacs handles multiple charsets at once. In Emacs Lisp
04c2f2c5
DL
46 code, a charset is represented by a symbol. In C code, a charset is
47 represented by its ID number or by a pointer to a struct charset.
4ed46869 48
3263d5a2
KH
49 The actual information about each charset is stored in two places.
50 Lispy information is stored in the hash table Vcharset_hash_table as
51 a vector (charset attributes). The other information is stored in
04c2f2c5 52 charset_table as a struct charset.
4ed46869 53
3263d5a2 54*/
4ed46869 55
3263d5a2
KH
56/* List of all charsets. This variable is used only from Emacs
57 Lisp. */
4ed46869 58Lisp_Object Vcharset_list;
4ed46869 59
3263d5a2
KH
60/* Hash table that contains attributes of each charset. Keys are
61 charset symbols, and values are vectors of charset attributes. */
62Lisp_Object Vcharset_hash_table;
4ed46869 63
3263d5a2
KH
64/* Table of struct charset. */
65struct charset *charset_table;
4ed46869 66
3263d5a2 67static int charset_table_size;
5af5dd92 68static int charset_table_used;
4ed46869 69
3263d5a2 70Lisp_Object Qcharsetp;
4ed46869 71
3263d5a2
KH
72/* Special charset symbols. */
73Lisp_Object Qascii;
2fe1edd1 74Lisp_Object Qeight_bit;
3263d5a2
KH
75Lisp_Object Qiso_8859_1;
76Lisp_Object Qunicode;
6c652beb 77Lisp_Object Qemacs;
4ed46869 78
3263d5a2
KH
79/* The corresponding charsets. */
80int charset_ascii;
2fe1edd1 81int charset_eight_bit;
3263d5a2
KH
82int charset_iso_8859_1;
83int charset_unicode;
6c652beb 84int charset_emacs;
b0e3cf2b 85
7c7dceee
KH
86/* The other special charsets. */
87int charset_jisx0201_roman;
88int charset_jisx0208_1978;
89int charset_jisx0208;
c1a08b4c 90
3263d5a2
KH
91/* Value of charset attribute `charset-iso-plane'. */
92Lisp_Object Qgl, Qgr;
c1a08b4c 93
d1a04588
KH
94/* Charset of unibyte characters. */
95int charset_unibyte;
4ed46869 96
3263d5a2
KH
97/* List of charsets ordered by the priority. */
98Lisp_Object Vcharset_ordered_list;
4ed46869 99
6a9c90ec
KH
100/* Sub-list of Vcharset_ordered_list that contains all non-preferred
101 charsets. */
102Lisp_Object Vcharset_non_preferred_head;
103
dbbb237d 104/* Incremented everytime we change Vcharset_ordered_list. This is
64165ae2 105 unsigned short so that it fits in Lisp_Int and never matches
dbbb237d
KH
106 -1. */
107unsigned short charset_ordered_list_tick;
4ed46869 108
3263d5a2
KH
109/* List of iso-2022 charsets. */
110Lisp_Object Viso_2022_charset_list;
35e623fb 111
3263d5a2
KH
112/* List of emacs-mule charsets. */
113Lisp_Object Vemacs_mule_charset_list;
114
115struct charset *emacs_mule_charset[256];
4ed46869
KH
116
117/* Mapping table from ISO2022's charset (specified by DIMENSION,
118 CHARS, and FINAL-CHAR) to Emacs' charset. */
3263d5a2
KH
119int iso_charset_table[ISO_MAX_DIMENSION][ISO_MAX_CHARS][ISO_MAX_FINAL];
120
4beef065 121Lisp_Object Vcharset_map_path;
3263d5a2
KH
122
123Lisp_Object Vchar_unified_charset_table;
124
6a9c90ec
KH
125Lisp_Object Vcurrent_iso639_language;
126
64165ae2
DL
127/* Defined in chartab.c */
128extern void
129map_char_table_for_charset P_ ((void (*c_function) (Lisp_Object, Lisp_Object),
130 Lisp_Object function, Lisp_Object table,
131 Lisp_Object arg, struct charset *charset,
132 unsigned from, unsigned to));
133
69f8de5b
KH
134#define CODE_POINT_TO_INDEX(charset, code) \
135 ((charset)->code_linear_p \
136 ? (code) - (charset)->min_code \
137 : (((charset)->code_space_mask[(code) >> 24] & 0x8) \
138 && ((charset)->code_space_mask[((code) >> 16) & 0xFF] & 0x4) \
139 && ((charset)->code_space_mask[((code) >> 8) & 0xFF] & 0x2) \
140 && ((charset)->code_space_mask[(code) & 0xFF] & 0x1)) \
141 ? (((((code) >> 24) - (charset)->code_space[12]) \
142 * (charset)->code_space[11]) \
143 + (((((code) >> 16) & 0xFF) - (charset)->code_space[8]) \
144 * (charset)->code_space[7]) \
145 + (((((code) >> 8) & 0xFF) - (charset)->code_space[4]) \
146 * (charset)->code_space[3]) \
820ee249
KH
147 + (((code) & 0xFF) - (charset)->code_space[0]) \
148 - ((charset)->char_index_offset)) \
3263d5a2
KH
149 : -1)
150
151
152/* Convert the character index IDX to code-point CODE for CHARSET.
153 It is assumed that IDX is in a valid range. */
154
820ee249
KH
155#define INDEX_TO_CODE_POINT(charset, idx) \
156 ((charset)->code_linear_p \
157 ? (idx) + (charset)->min_code \
158 : (idx += (charset)->char_index_offset, \
159 (((charset)->code_space[0] + (idx) % (charset)->code_space[2]) \
160 | (((charset)->code_space[4] \
161 + ((idx) / (charset)->code_space[3] % (charset)->code_space[6])) \
162 << 8) \
163 | (((charset)->code_space[8] \
164 + ((idx) / (charset)->code_space[7] % (charset)->code_space[10])) \
165 << 16) \
166 | (((charset)->code_space[12] + ((idx) / (charset)->code_space[11])) \
167 << 24))))
4cf9710d 168
8a73a704 169
046b1f03 170\f
93bcb785 171
e9ce014c
KH
172/* Set to 1 to warn that a charset map is loaded and thus a buffer
173 text and a string data may be relocated. */
3263d5a2 174int charset_map_loaded;
4ed46869 175
e9ce014c 176struct charset_map_entries
4ed46869 177{
e9ce014c
KH
178 struct {
179 unsigned from, to;
180 int c;
181 } entry[0x10000];
182 struct charset_map_entries *next;
183};
184
185/* Load the mapping information for CHARSET from ENTRIES.
4cf9710d 186
3263d5a2 187 If CONTROL_FLAG is 0, setup CHARSET->min_char and CHARSET->max_char.
8a73a704 188
3263d5a2
KH
189 If CONTROL_FLAG is 1, setup CHARSET->min_char, CHARSET->max_char,
190 CHARSET->decoder, and CHARSET->encoder.
93bcb785 191
3263d5a2
KH
192 If CONTROL_FLAG is 2, setup CHARSET->deunifier and
193 Vchar_unify_table. If Vchar_unified_charset_table is non-nil,
194 setup it too. */
4ed46869 195
3263d5a2 196static void
e9ce014c 197load_charset_map (charset, entries, n_entries, control_flag)
3263d5a2 198 struct charset *charset;
e9ce014c
KH
199 struct charset_map_entries *entries;
200 int n_entries;
3263d5a2 201 int control_flag;
4ed46869 202{
3263d5a2 203 Lisp_Object vec, table;
3263d5a2
KH
204 unsigned max_code = CHARSET_MAX_CODE (charset);
205 int ascii_compatible_p = charset->ascii_compatible_p;
206 int min_char, max_char, nonascii_min_char;
3263d5a2 207 int i;
3263d5a2 208 unsigned char *fast_map = charset->fast_map;
99529c2c 209
e9ce014c
KH
210 if (n_entries <= 0)
211 return;
212
213 if (control_flag > 0)
8ac5a9cc 214 {
3263d5a2 215 int n = CODE_POINT_TO_INDEX (charset, max_code) + 1;
6662e69b 216
374c5cfd 217 table = Fmake_char_table (Qnil, Qnil);
3263d5a2
KH
218 if (control_flag == 1)
219 vec = Fmake_vector (make_number (n), make_number (-1));
220 else if (! CHAR_TABLE_P (Vchar_unify_table))
374c5cfd 221 Vchar_unify_table = Fmake_char_table (Qnil, Qnil);
6662e69b 222
3263d5a2 223 charset_map_loaded = 1;
2e344af3 224 }
6662e69b 225
e9ce014c 226 min_char = max_char = entries->entry[0].c;
3263d5a2 227 nonascii_min_char = MAX_CHAR;
e9ce014c 228 for (i = 0; i < n_entries; i++)
2e344af3 229 {
e9ce014c 230 unsigned from, to;
3b4f4446
KH
231 int from_index, to_index;
232 int from_c, to_c;
e9ce014c 233 int idx = i % 0x10000;
3263d5a2 234
e9ce014c
KH
235 if (i > 0 && idx == 0)
236 entries = entries->next;
237 from = entries->entry[idx].from;
238 to = entries->entry[idx].to;
3b4f4446
KH
239 from_c = entries->entry[idx].c;
240 from_index = CODE_POINT_TO_INDEX (charset, from);
241 if (from == to)
6662e69b 242 {
3b4f4446
KH
243 to_index = from_index;
244 to_c = from_c;
6662e69b 245 }
3b4f4446 246 else
6662e69b 247 {
3b4f4446
KH
248 to_index = CODE_POINT_TO_INDEX (charset, to);
249 to_c = from_c + (to_index - from_index);
6662e69b 250 }
3b4f4446
KH
251 if (from_index < 0 || to_index < 0)
252 continue;
3263d5a2 253
3263d5a2 254 if (control_flag < 2)
6662e69b 255 {
3b4f4446 256 int c;
6662e69b 257
3b4f4446
KH
258 if (to_c > max_char)
259 max_char = to_c;
260 else if (from_c < min_char)
261 min_char = from_c;
262 if (ascii_compatible_p)
263 {
264 if (! ASCII_BYTE_P (from_c))
265 {
266 if (from_c < nonascii_min_char)
267 nonascii_min_char = from_c;
268 }
269 else if (! ASCII_BYTE_P (to_c))
270 {
271 nonascii_min_char = 0x80;
272 }
273 }
177c0ea7 274
3b4f4446
KH
275 for (c = from_c; c <= to_c; c++)
276 CHARSET_FAST_MAP_SET (c, fast_map);
277
e9ce014c 278 if (control_flag == 1)
3263d5a2 279 {
e9ce014c 280 unsigned code = from;
e9ce014c 281
e9ce014c
KH
282 if (CHARSET_COMPACT_CODES_P (charset))
283 while (1)
284 {
3b4f4446 285 ASET (vec, from_index, make_number (from_c));
8f924df7
KH
286 if (NILP (CHAR_TABLE_REF (table, from_c)))
287 CHAR_TABLE_SET (table, from_c, make_number (code));
e9ce014c
KH
288 if (from_index == to_index)
289 break;
3b4f4446 290 from_index++, from_c++;
e9ce014c
KH
291 code = INDEX_TO_CODE_POINT (charset, from_index);
292 }
293 else
3b4f4446 294 for (; from_index <= to_index; from_index++, from_c++)
e9ce014c 295 {
3b4f4446 296 ASET (vec, from_index, make_number (from_c));
8f924df7
KH
297 if (NILP (CHAR_TABLE_REF (table, from_c)))
298 CHAR_TABLE_SET (table, from_c, make_number (from_index));
e9ce014c 299 }
3263d5a2 300 }
3263d5a2 301 }
2e344af3
KH
302 else
303 {
69f8de5b 304 unsigned code = from;
3b4f4446 305
69f8de5b
KH
306 while (1)
307 {
308 int c1 = DECODE_CHAR (charset, code);
8f924df7 309
3263d5a2
KH
310 if (c1 >= 0)
311 {
3b4f4446 312 CHAR_TABLE_SET (table, from_c, make_number (c1));
16fed1fc 313 CHAR_TABLE_SET (Vchar_unify_table, c1, make_number (from_c));
3263d5a2
KH
314 if (CHAR_TABLE_P (Vchar_unified_charset_table))
315 CHAR_TABLE_SET (Vchar_unified_charset_table, c1,
316 CHARSET_NAME (charset));
317 }
69f8de5b
KH
318 if (from_index == to_index)
319 break;
3b4f4446 320 from_index++, from_c++;
69f8de5b 321 code = INDEX_TO_CODE_POINT (charset, from_index);
3263d5a2 322 }
2e344af3 323 }
8ac5a9cc 324 }
3263d5a2
KH
325
326 if (control_flag < 2)
4ed46869 327 {
3263d5a2
KH
328 CHARSET_MIN_CHAR (charset) = (ascii_compatible_p
329 ? nonascii_min_char : min_char);
330 CHARSET_MAX_CHAR (charset) = max_char;
e9ce014c 331 if (control_flag == 1)
4ed46869 332 {
3263d5a2
KH
333 CHARSET_DECODER (charset) = vec;
334 CHARSET_ENCODER (charset) = table;
4ed46869
KH
335 }
336 }
2e344af3 337 else
8f924df7 338 CHARSET_DEUNIFIER (charset) = table;
4ed46869
KH
339}
340
12bcae05 341
3263d5a2
KH
342/* Read a hexadecimal number (preceded by "0x") from the file FP while
343 paying attention to comment charcter '#'. */
12bcae05 344
3263d5a2
KH
345static INLINE unsigned
346read_hex (fp, eof)
347 FILE *fp;
348 int *eof;
12bcae05 349{
3263d5a2
KH
350 int c;
351 unsigned n;
12bcae05 352
3263d5a2
KH
353 while ((c = getc (fp)) != EOF)
354 {
69f8de5b 355 if (c == '#')
3263d5a2
KH
356 {
357 while ((c = getc (fp)) != EOF && c != '\n');
358 }
359 else if (c == '0')
360 {
361 if ((c = getc (fp)) == EOF || c == 'x')
362 break;
363 }
8f924df7 364 }
3263d5a2
KH
365 if (c == EOF)
366 {
367 *eof = 1;
368 return 0;
369 }
370 *eof = 0;
371 n = 0;
372 if (c == 'x')
373 while ((c = getc (fp)) != EOF && isxdigit (c))
374 n = ((n << 4)
375 | (c <= '9' ? c - '0' : c <= 'F' ? c - 'A' + 10 : c - 'a' + 10));
376 else
377 while ((c = getc (fp)) != EOF && isdigit (c))
378 n = (n * 10) + c - '0';
e9ce014c
KH
379 if (c != EOF)
380 ungetc (c, fp);
3263d5a2
KH
381 return n;
382}
12bcae05 383
537efd8d 384
3263d5a2 385/* Return a mapping vector for CHARSET loaded from MAPFILE.
e9ce014c
KH
386 Each line of MAPFILE has this form
387 0xAAAA 0xCCCC
388 where 0xAAAA is a code-point and 0xCCCC is the corresponding
389 character code, or this form
390 0xAAAA-0xBBBB 0xCCCC
391 where 0xAAAA and 0xBBBB are code-points specifying a range, and
392 0xCCCC is the first character code of the range.
4ed46869 393
3263d5a2
KH
394 The returned vector has this form:
395 [ CODE1 CHAR1 CODE2 CHAR2 .... ]
e9ce014c
KH
396 where CODE1 is a code-point or a cons of code-points specifying a
397 range. */
4ed46869 398
c449997d 399extern void add_to_log P_ ((char *, Lisp_Object, Lisp_Object));
4ed46869 400
e9ce014c
KH
401static void
402load_charset_map_from_file (charset, mapfile, control_flag)
3263d5a2
KH
403 struct charset *charset;
404 Lisp_Object mapfile;
e9ce014c 405 int control_flag;
4ed46869 406{
e9ce014c
KH
407 unsigned min_code = CHARSET_MIN_CODE (charset);
408 unsigned max_code = CHARSET_MAX_CODE (charset);
3263d5a2
KH
409 int fd;
410 FILE *fp;
3263d5a2
KH
411 int eof;
412 Lisp_Object suffixes;
e9ce014c
KH
413 struct charset_map_entries *head, *entries;
414 int n_entries;
4ed46869 415
3263d5a2
KH
416 suffixes = Fcons (build_string (".map"),
417 Fcons (build_string (".TXT"), Qnil));
4ed46869 418
4beef065 419 fd = openp (Vcharset_map_path, mapfile, suffixes, NULL, Qnil);
3263d5a2
KH
420 if (fd < 0
421 || ! (fp = fdopen (fd, "r")))
422 {
423 add_to_log ("Failure in loading charset map: %S", mapfile, Qnil);
e9ce014c 424 return;
3263d5a2 425 }
4ed46869 426
e9ce014c
KH
427 head = entries = ((struct charset_map_entries *)
428 alloca (sizeof (struct charset_map_entries)));
429 n_entries = 0;
3263d5a2
KH
430 eof = 0;
431 while (1)
432 {
e9ce014c
KH
433 unsigned from, to;
434 int c;
435 int idx;
4ed46869 436
e9ce014c 437 from = read_hex (fp, &eof);
3263d5a2
KH
438 if (eof)
439 break;
e9ce014c
KH
440 if (getc (fp) == '-')
441 to = read_hex (fp, &eof);
442 else
443 to = from;
444 c = (int) read_hex (fp, &eof);
ac4137cc 445
e9ce014c
KH
446 if (from < min_code || to > max_code || from > to || c > MAX_CHAR)
447 continue;
ac4137cc 448
e9ce014c 449 if (n_entries > 0 && (n_entries % 0x10000) == 0)
3263d5a2 450 {
e9ce014c
KH
451 entries->next = ((struct charset_map_entries *)
452 alloca (sizeof (struct charset_map_entries)));
453 entries = entries->next;
3263d5a2 454 }
e9ce014c
KH
455 idx = n_entries % 0x10000;
456 entries->entry[idx].from = from;
457 entries->entry[idx].to = to;
458 entries->entry[idx].c = c;
459 n_entries++;
3263d5a2
KH
460 }
461 fclose (fp);
462 close (fd);
177c0ea7 463
e9ce014c 464 load_charset_map (charset, head, n_entries, control_flag);
4ed46869
KH
465}
466
e9ce014c
KH
467static void
468load_charset_map_from_vector (charset, vec, control_flag)
469 struct charset *charset;
470 Lisp_Object vec;
471 int control_flag;
23d2a7f1 472{
e9ce014c
KH
473 unsigned min_code = CHARSET_MIN_CODE (charset);
474 unsigned max_code = CHARSET_MAX_CODE (charset);
475 struct charset_map_entries *head, *entries;
476 int n_entries;
477 int len = ASIZE (vec);
478 int i;
23d2a7f1 479
e9ce014c 480 if (len % 2 == 1)
3263d5a2 481 {
e9ce014c
KH
482 add_to_log ("Failure in loading charset map: %V", vec, Qnil);
483 return;
3263d5a2 484 }
35e623fb 485
e9ce014c
KH
486 head = entries = ((struct charset_map_entries *)
487 alloca (sizeof (struct charset_map_entries)));
488 n_entries = 0;
489 for (i = 0; i < len; i += 2)
35e623fb 490 {
e9ce014c
KH
491 Lisp_Object val, val2;
492 unsigned from, to;
493 int c;
494 int idx;
d2665018 495
e9ce014c
KH
496 val = AREF (vec, i);
497 if (CONSP (val))
bbf12bb3 498 {
e9ce014c
KH
499 val2 = XCDR (val);
500 val = XCAR (val);
501 CHECK_NATNUM (val);
502 CHECK_NATNUM (val2);
503 from = XFASTINT (val);
504 to = XFASTINT (val2);
bbf12bb3 505 }
e9ce014c 506 else
bbf12bb3 507 {
e9ce014c
KH
508 CHECK_NATNUM (val);
509 from = to = XFASTINT (val);
bbf12bb3 510 }
e9ce014c
KH
511 val = AREF (vec, i + 1);
512 CHECK_NATNUM (val);
513 c = XFASTINT (val);
76d7b829 514
e9ce014c
KH
515 if (from < min_code || to > max_code || from > to || c > MAX_CHAR)
516 continue;
76d7b829 517
dcc694d7 518 if (n_entries > 0 && (n_entries % 0x10000) == 0)
e9ce014c
KH
519 {
520 entries->next = ((struct charset_map_entries *)
521 alloca (sizeof (struct charset_map_entries)));
522 entries = entries->next;
523 }
524 idx = n_entries % 0x10000;
525 entries->entry[idx].from = from;
526 entries->entry[idx].to = to;
527 entries->entry[idx].c = c;
528 n_entries++;
529 }
76d7b829 530
e9ce014c 531 load_charset_map (charset, head, n_entries, control_flag);
ac4137cc
KH
532}
533
3263d5a2
KH
534static void
535load_charset (charset)
536 struct charset *charset;
76d7b829 537{
3263d5a2 538 if (CHARSET_METHOD (charset) == CHARSET_METHOD_MAP_DEFERRED)
76d7b829 539 {
3263d5a2 540 Lisp_Object map;
76d7b829 541
3263d5a2
KH
542 map = CHARSET_MAP (charset);
543 if (STRINGP (map))
e9ce014c 544 load_charset_map_from_file (charset, map, 1);
bbf12bb3 545 else
e9ce014c 546 load_charset_map_from_vector (charset, map, 1);
3263d5a2 547 CHARSET_METHOD (charset) = CHARSET_METHOD_MAP;
76d7b829 548 }
4ed46869 549}
76d7b829 550
3263d5a2
KH
551
552DEFUN ("charsetp", Fcharsetp, Scharsetp, 1, 1, 0,
553 doc: /* Return non-nil if and only if OBJECT is a charset.*/)
554 (object)
555 Lisp_Object object;
23d2a7f1 556{
3263d5a2 557 return (CHARSETP (object) ? Qt : Qnil);
76d7b829
KH
558}
559
4ed46869
KH
560
561void
374c5cfd
KH
562map_charset_chars (c_function, function, arg,
563 charset, from, to)
564 void (*c_function) P_ ((Lisp_Object, Lisp_Object));
565 Lisp_Object function, arg;
566 struct charset *charset;
567 unsigned from, to;
4ed46869 568{
3263d5a2 569 Lisp_Object range;
374c5cfd 570 int partial;
3263d5a2 571
8f924df7 572 if (CHARSET_METHOD (charset) == CHARSET_METHOD_MAP_DEFERRED)
3263d5a2
KH
573 load_charset (charset);
574
374c5cfd
KH
575 partial = (from > CHARSET_MIN_CODE (charset)
576 || to < CHARSET_MAX_CODE (charset));
577
578 if (CHARSET_UNIFIED_P (charset)
579 && CHAR_TABLE_P (CHARSET_DEUNIFIER (charset)))
4ed46869 580 {
374c5cfd
KH
581 map_char_table_for_charset (c_function, function,
582 CHARSET_DEUNIFIER (charset), arg,
583 partial ? charset : NULL, from, to);
4ed46869 584 }
374c5cfd 585
3263d5a2 586 if (CHARSET_METHOD (charset) == CHARSET_METHOD_OFFSET)
4ed46869 587 {
374c5cfd
KH
588 int from_idx = CODE_POINT_TO_INDEX (charset, from);
589 int to_idx = CODE_POINT_TO_INDEX (charset, to);
590 int from_c = from_idx + CHARSET_CODE_OFFSET (charset);
591 int to_c = to_idx + CHARSET_CODE_OFFSET (charset);
592
593 range = Fcons (make_number (from_c), make_number (to_c));
3263d5a2 594 if (NILP (function))
5af5dd92 595 (*c_function) (arg, range);
3263d5a2
KH
596 else
597 call2 (function, range, arg);
c83ef371 598 }
3263d5a2
KH
599 else if (CHARSET_METHOD (charset) == CHARSET_METHOD_MAP)
600 {
601 if (! CHAR_TABLE_P (CHARSET_ENCODER (charset)))
602 return;
374c5cfd
KH
603 map_char_table_for_charset (c_function, function,
604 CHARSET_ENCODER (charset), arg,
605 partial ? charset : NULL, from, to);
3263d5a2 606 }
374c5cfd 607 else if (CHARSET_METHOD (charset) == CHARSET_METHOD_SUBSET)
4ed46869 608 {
374c5cfd
KH
609 Lisp_Object subset_info;
610 int offset;
611
612 subset_info = CHARSET_SUBSET (charset);
613 charset = CHARSET_FROM_ID (XFASTINT (AREF (subset_info, 0)));
614 offset = XINT (AREF (subset_info, 3));
615 from -= offset;
616 if (from < XFASTINT (AREF (subset_info, 1)))
617 from = XFASTINT (AREF (subset_info, 1));
618 to -= offset;
619 if (to > XFASTINT (AREF (subset_info, 2)))
620 to = XFASTINT (AREF (subset_info, 2));
621 map_charset_chars (c_function, function, arg, charset, from, to);
4ed46869 622 }
374c5cfd
KH
623 else /* i.e. CHARSET_METHOD_SUPERSET */
624 {
625 Lisp_Object parents;
4ed46869 626
374c5cfd
KH
627 for (parents = CHARSET_SUPERSET (charset); CONSP (parents);
628 parents = XCDR (parents))
bbf12bb3 629 {
374c5cfd
KH
630 int offset;
631 unsigned this_from, this_to;
632
633 charset = CHARSET_FROM_ID (XFASTINT (XCAR (XCAR (parents))));
634 offset = XINT (XCDR (XCAR (parents)));
635 this_from = from - offset;
636 this_to = to - offset;
637 if (this_from < CHARSET_MIN_CODE (charset))
638 this_from = CHARSET_MIN_CODE (charset);
639 if (this_to > CHARSET_MAX_CODE (charset))
640 this_to = CHARSET_MAX_CODE (charset);
111daccf
KH
641 map_charset_chars (c_function, function, arg, charset,
642 this_from, this_to);
bbf12bb3 643 }
35e623fb 644 }
4ed46869
KH
645}
646
374c5cfd 647DEFUN ("map-charset-chars", Fmap_charset_chars, Smap_charset_chars, 2, 5, 0,
04c2f2c5 648 doc: /* Call FUNCTION for all characters in CHARSET.
374c5cfd 649FUNCTION is called with an argument RANGE and the optional 3rd
3263d5a2 650argument ARG.
4ed46869 651
374c5cfd
KH
652RANGE is a cons (FROM . TO), where FROM and TO indicate a range of
653characters contained in CHARSET.
4ed46869 654
374c5cfd 655The optional 4th and 5th arguments FROM-CODE and TO-CODE specify the
8f924df7 656range of code points of target characters. */)
374c5cfd
KH
657 (function, charset, arg, from_code, to_code)
658 Lisp_Object function, charset, arg, from_code, to_code;
4ed46869 659{
374c5cfd 660 struct charset *cs;
16fed1fc 661 unsigned from, to;
4ed46869 662
374c5cfd
KH
663 CHECK_CHARSET_GET_CHARSET (charset, cs);
664 if (NILP (from_code))
16fed1fc 665 from = CHARSET_MIN_CODE (cs);
970b7474 666 else
4ed46869 667 {
970b7474
KH
668 CHECK_NATNUM (from_code);
669 from = XINT (from_code);
670 if (from < CHARSET_MIN_CODE (cs))
671 from = CHARSET_MIN_CODE (cs);
4ed46869 672 }
374c5cfd 673 if (NILP (to_code))
970b7474 674 to = CHARSET_MAX_CODE (cs);
4ed46869
KH
675 else
676 {
970b7474
KH
677 CHECK_NATNUM (to_code);
678 to = XINT (to_code);
679 if (to > CHARSET_MAX_CODE (cs))
680 to = CHARSET_MAX_CODE (cs);
4ed46869 681 }
16fed1fc 682 map_charset_chars (NULL, function, arg, cs, from, to);
3263d5a2 683 return Qnil;
35e623fb 684}
4ed46869 685
4ed46869 686
3263d5a2
KH
687/* Define a charset according to the arguments. The Nth argument is
688 the Nth attribute of the charset (the last attribute `charset-id'
689 is not included). See the docstring of `define-charset' for the
690 detail. */
4ed46869 691
3263d5a2
KH
692DEFUN ("define-charset-internal", Fdefine_charset_internal,
693 Sdefine_charset_internal, charset_arg_max, MANY, 0,
04c2f2c5
DL
694 doc: /* For internal use only.
695usage: (define-charset-internal ...) */)
3263d5a2
KH
696 (nargs, args)
697 int nargs;
698 Lisp_Object *args;
4ed46869 699{
3263d5a2
KH
700 /* Charset attr vector. */
701 Lisp_Object attrs;
702 Lisp_Object val;
703 unsigned hash_code;
704 struct Lisp_Hash_Table *hash_table = XHASH_TABLE (Vcharset_hash_table);
69f8de5b 705 int i, j;
3263d5a2
KH
706 struct charset charset;
707 int id;
708 int dimension;
709 int new_definition_p;
710 int nchars;
711
712 if (nargs != charset_arg_max)
713 return Fsignal (Qwrong_number_of_arguments,
714 Fcons (intern ("define-charset-internal"),
715 make_number (nargs)));
716
717 attrs = Fmake_vector (make_number (charset_attr_max), Qnil);
718
719 CHECK_SYMBOL (args[charset_arg_name]);
720 ASET (attrs, charset_name, args[charset_arg_name]);
721
722 val = args[charset_arg_code_space];
723 for (i = 0, dimension = 0, nchars = 1; i < 4; i++)
76d7b829 724 {
3263d5a2
KH
725 int min_byte, max_byte;
726
727 min_byte = XINT (Faref (val, make_number (i * 2)));
728 max_byte = XINT (Faref (val, make_number (i * 2 + 1)));
729 if (min_byte < 0 || min_byte > max_byte || max_byte >= 256)
730 error ("Invalid :code-space value");
731 charset.code_space[i * 4] = min_byte;
732 charset.code_space[i * 4 + 1] = max_byte;
733 charset.code_space[i * 4 + 2] = max_byte - min_byte + 1;
734 nchars *= charset.code_space[i * 4 + 2];
735 charset.code_space[i * 4 + 3] = nchars;
736 if (max_byte > 0)
737 dimension = i + 1;
738 }
4ed46869 739
3263d5a2
KH
740 val = args[charset_arg_dimension];
741 if (NILP (val))
742 charset.dimension = dimension;
743 else
4ed46869 744 {
3263d5a2
KH
745 CHECK_NATNUM (val);
746 charset.dimension = XINT (val);
747 if (charset.dimension < 1 || charset.dimension > 4)
748 args_out_of_range_3 (val, make_number (1), make_number (4));
4ed46869
KH
749 }
750
3263d5a2
KH
751 charset.code_linear_p
752 = (charset.dimension == 1
753 || (charset.code_space[2] == 256
754 && (charset.dimension == 2
755 || (charset.code_space[6] == 256
756 && (charset.dimension == 3
757 || charset.code_space[10] == 256)))));
758
69f8de5b 759 if (! charset.code_linear_p)
4ed46869 760 {
69f8de5b 761 charset.code_space_mask = (unsigned char *) xmalloc (256);
33df3183 762 bzero (charset.code_space_mask, 256);
69f8de5b
KH
763 for (i = 0; i < 4; i++)
764 for (j = charset.code_space[i * 4]; j <= charset.code_space[i * 4 + 1];
765 j++)
766 charset.code_space_mask[j] |= (1 << i);
4ed46869
KH
767 }
768
3263d5a2 769 charset.iso_chars_96 = charset.code_space[2] == 96;
4ed46869 770
3263d5a2
KH
771 charset.min_code = (charset.code_space[0]
772 | (charset.code_space[4] << 8)
773 | (charset.code_space[8] << 16)
774 | (charset.code_space[12] << 24));
775 charset.max_code = (charset.code_space[1]
776 | (charset.code_space[5] << 8)
777 | (charset.code_space[9] << 16)
778 | (charset.code_space[13] << 24));
820ee249 779 charset.char_index_offset = 0;
8a73a704 780
820ee249
KH
781 val = args[charset_arg_min_code];
782 if (! NILP (val))
783 {
784 unsigned code;
fdb82f93 785
820ee249
KH
786 if (INTEGERP (val))
787 code = XINT (val);
788 else
789 {
790 CHECK_CONS (val);
8f924df7
KH
791 CHECK_NUMBER_CAR (val);
792 CHECK_NUMBER_CDR (val);
820ee249
KH
793 code = (XINT (XCAR (val)) << 16) | (XINT (XCDR (val)));
794 }
795 if (code < charset.min_code
796 || code > charset.max_code)
797 args_out_of_range_3 (make_number (charset.min_code),
798 make_number (charset.max_code), val);
799 charset.char_index_offset = CODE_POINT_TO_INDEX (&charset, code);
800 charset.min_code = code;
801 }
3fac5a51 802
820ee249
KH
803 val = args[charset_arg_max_code];
804 if (! NILP (val))
3fac5a51 805 {
820ee249
KH
806 unsigned code;
807
808 if (INTEGERP (val))
809 code = XINT (val);
810 else
811 {
812 CHECK_CONS (val);
8f924df7
KH
813 CHECK_NUMBER_CAR (val);
814 CHECK_NUMBER_CDR (val);
820ee249
KH
815 code = (XINT (XCAR (val)) << 16) | (XINT (XCDR (val)));
816 }
817 if (code < charset.min_code
818 || code > charset.max_code)
819 args_out_of_range_3 (make_number (charset.min_code),
820 make_number (charset.max_code), val);
821 charset.max_code = code;
3fac5a51 822 }
3fac5a51 823
e9ce014c 824 charset.compact_codes_p = charset.max_code < 0x1000000;
4ed46869 825
3263d5a2
KH
826 val = args[charset_arg_invalid_code];
827 if (NILP (val))
828 {
829 if (charset.min_code > 0)
830 charset.invalid_code = 0;
bbf12bb3
KH
831 else
832 {
3263d5a2
KH
833 XSETINT (val, charset.max_code + 1);
834 if (XINT (val) == charset.max_code + 1)
835 charset.invalid_code = charset.max_code + 1;
836 else
837 error ("Attribute :invalid-code must be specified");
76d7b829 838 }
76d7b829 839 }
3263d5a2
KH
840 else
841 {
842 CHECK_NATNUM (val);
843 charset.invalid_code = XFASTINT (val);
844 }
4ed46869 845
3263d5a2
KH
846 val = args[charset_arg_iso_final];
847 if (NILP (val))
848 charset.iso_final = -1;
849 else
850 {
851 CHECK_NUMBER (val);
852 if (XINT (val) < '0' || XINT (val) > 127)
853 error ("Invalid iso-final-char: %d", XINT (val));
854 charset.iso_final = XINT (val);
855 }
4ed46869 856
3263d5a2
KH
857 val = args[charset_arg_iso_revision];
858 if (NILP (val))
859 charset.iso_revision = -1;
860 else
4ed46869 861 {
3263d5a2
KH
862 CHECK_NUMBER (val);
863 if (XINT (val) > 63)
864 args_out_of_range (make_number (63), val);
865 charset.iso_revision = XINT (val);
4ed46869 866 }
4ed46869 867
3263d5a2
KH
868 val = args[charset_arg_emacs_mule_id];
869 if (NILP (val))
870 charset.emacs_mule_id = -1;
4ed46869
KH
871 else
872 {
3263d5a2
KH
873 CHECK_NATNUM (val);
874 if ((XINT (val) > 0 && XINT (val) <= 128) || XINT (val) >= 256)
875 error ("Invalid emacs-mule-id: %d", XINT (val));
876 charset.emacs_mule_id = XINT (val);
c83ef371 877 }
f6302ac9 878
3263d5a2 879 charset.ascii_compatible_p = ! NILP (args[charset_arg_ascii_compatible_p]);
1d67c29b 880
3263d5a2 881 charset.supplementary_p = ! NILP (args[charset_arg_supplementary_p]);
4ed46869 882
3263d5a2
KH
883 charset.unified_p = 0;
884
885 bzero (charset.fast_map, sizeof (charset.fast_map));
886
887 if (! NILP (args[charset_arg_code_offset]))
888 {
889 val = args[charset_arg_code_offset];
890 CHECK_NUMBER (val);
891
892 charset.method = CHARSET_METHOD_OFFSET;
893 charset.code_offset = XINT (val);
894
895 i = CODE_POINT_TO_INDEX (&charset, charset.min_code);
896 charset.min_char = i + charset.code_offset;
897 i = CODE_POINT_TO_INDEX (&charset, charset.max_code);
898 charset.max_char = i + charset.code_offset;
899 if (charset.max_char > MAX_CHAR)
900 error ("Unsupported max char: %d", charset.max_char);
901
f148205f
KH
902 i = (charset.min_char >> 7) << 7;
903 for (; i < 0x10000 && i <= charset.max_char; i += 128)
3263d5a2 904 CHARSET_FAST_MAP_SET (i, charset.fast_map);
f148205f 905 i = (i >> 12) << 12;
3263d5a2
KH
906 for (; i <= charset.max_char; i += 0x1000)
907 CHARSET_FAST_MAP_SET (i, charset.fast_map);
908 }
909 else if (! NILP (args[charset_arg_map]))
910 {
911 val = args[charset_arg_map];
912 ASET (attrs, charset_map, val);
913 if (STRINGP (val))
e9ce014c
KH
914 load_charset_map_from_file (&charset, val, 0);
915 else
916 load_charset_map_from_vector (&charset, val, 0);
3263d5a2
KH
917 charset.method = CHARSET_METHOD_MAP_DEFERRED;
918 }
374c5cfd 919 else if (! NILP (args[charset_arg_subset]))
3263d5a2 920 {
374c5cfd
KH
921 Lisp_Object parent;
922 Lisp_Object parent_min_code, parent_max_code, parent_code_offset;
923 struct charset *parent_charset;
924
925 val = args[charset_arg_subset];
926 parent = Fcar (val);
927 CHECK_CHARSET_GET_CHARSET (parent, parent_charset);
928 parent_min_code = Fnth (make_number (1), val);
929 CHECK_NATNUM (parent_min_code);
930 parent_max_code = Fnth (make_number (2), val);
931 CHECK_NATNUM (parent_max_code);
932 parent_code_offset = Fnth (make_number (3), val);
933 CHECK_NUMBER (parent_code_offset);
934 val = Fmake_vector (make_number (4), Qnil);
935 ASET (val, 0, make_number (parent_charset->id));
936 ASET (val, 1, parent_min_code);
937 ASET (val, 2, parent_max_code);
938 ASET (val, 3, parent_code_offset);
939 ASET (attrs, charset_subset, val);
940
941 charset.method = CHARSET_METHOD_SUBSET;
942 /* Here, we just copy the parent's fast_map. It's not accurate,
943 but at least it works for quickly detecting which character
944 DOESN'T belong to this charset. */
945 for (i = 0; i < 190; i++)
946 charset.fast_map[i] = parent_charset->fast_map[i];
947
948 /* We also copy these for parents. */
949 charset.min_char = parent_charset->min_char;
950 charset.max_char = parent_charset->max_char;
951 }
952 else if (! NILP (args[charset_arg_superset]))
0282eb69 953 {
374c5cfd
KH
954 val = args[charset_arg_superset];
955 charset.method = CHARSET_METHOD_SUPERSET;
3263d5a2 956 val = Fcopy_sequence (val);
374c5cfd 957 ASET (attrs, charset_superset, val);
3263d5a2
KH
958
959 charset.min_char = MAX_CHAR;
960 charset.max_char = 0;
961 for (; ! NILP (val); val = Fcdr (val))
0282eb69 962 {
3263d5a2
KH
963 Lisp_Object elt, car_part, cdr_part;
964 int this_id, offset;
965 struct charset *this_charset;
2e344af3 966
3263d5a2
KH
967 elt = Fcar (val);
968 if (CONSP (elt))
2e344af3 969 {
3263d5a2
KH
970 car_part = XCAR (elt);
971 cdr_part = XCDR (elt);
972 CHECK_CHARSET_GET_ID (car_part, this_id);
973 CHECK_NUMBER (cdr_part);
974 offset = XINT (cdr_part);
177c0ea7 975 }
3263d5a2 976 else
4ed46869 977 {
3263d5a2
KH
978 CHECK_CHARSET_GET_ID (elt, this_id);
979 offset = 0;
4ed46869 980 }
3263d5a2
KH
981 XSETCAR (val, Fcons (make_number (this_id), make_number (offset)));
982
983 this_charset = CHARSET_FROM_ID (this_id);
984 if (charset.min_char > this_charset->min_char)
985 charset.min_char = this_charset->min_char;
986 if (charset.max_char < this_charset->max_char)
987 charset.max_char = this_charset->max_char;
988 for (i = 0; i < 190; i++)
989 charset.fast_map[i] |= this_charset->fast_map[i];
0282eb69 990 }
0282eb69 991 }
2e344af3 992 else
3263d5a2 993 error ("None of :code-offset, :map, :parents are specified");
05505664 994
3263d5a2
KH
995 val = args[charset_arg_unify_map];
996 if (! NILP (val) && !STRINGP (val))
997 CHECK_VECTOR (val);
998 ASET (attrs, charset_unify_map, val);
05505664 999
3263d5a2
KH
1000 CHECK_LIST (args[charset_arg_plist]);
1001 ASET (attrs, charset_plist, args[charset_arg_plist]);
4ed46869 1002
3263d5a2
KH
1003 charset.hash_index = hash_lookup (hash_table, args[charset_arg_name],
1004 &hash_code);
1005 if (charset.hash_index >= 0)
1006 {
1007 new_definition_p = 0;
4f65af01 1008 id = XFASTINT (CHARSET_SYMBOL_ID (args[charset_arg_name]));
3263d5a2
KH
1009 HASH_VALUE (hash_table, charset.hash_index) = attrs;
1010 }
1a45ff10 1011 else
3263d5a2
KH
1012 {
1013 charset.hash_index = hash_put (hash_table, args[charset_arg_name], attrs,
1014 hash_code);
1015 if (charset_table_used == charset_table_size)
1016 {
2fe1edd1
KH
1017 struct charset *new_table
1018 = (struct charset *) xmalloc (sizeof (struct charset)
1019 * (charset_table_size + 16));
1020 bcopy (charset_table, new_table,
1021 sizeof (struct charset) * charset_table_size);
1022 charset_table_size += 16;
1023 charset_table = new_table;
3263d5a2
KH
1024 }
1025 id = charset_table_used++;
3263d5a2
KH
1026 new_definition_p = 1;
1027 }
2e344af3 1028
4f65af01 1029 ASET (attrs, charset_id, make_number (id));
3263d5a2
KH
1030 charset.id = id;
1031 charset_table[id] = charset;
2e344af3 1032
3263d5a2 1033 if (charset.iso_final >= 0)
4ed46869 1034 {
3263d5a2
KH
1035 ISO_CHARSET_TABLE (charset.dimension, charset.iso_chars_96,
1036 charset.iso_final) = id;
1037 if (new_definition_p)
1038 Viso_2022_charset_list = nconc2 (Viso_2022_charset_list,
1039 Fcons (make_number (id), Qnil));
7c7dceee
KH
1040 if (ISO_CHARSET_TABLE (1, 0, 'J') == id)
1041 charset_jisx0201_roman = id;
1042 else if (ISO_CHARSET_TABLE (2, 0, '@') == id)
1043 charset_jisx0208_1978 = id;
1044 else if (ISO_CHARSET_TABLE (2, 0, 'B') == id)
1045 charset_jisx0208 = id;
4ed46869 1046 }
d0cf2d48 1047
3263d5a2 1048 if (charset.emacs_mule_id >= 0)
4ed46869 1049 {
3263d5a2 1050 emacs_mule_charset[charset.emacs_mule_id] = CHARSET_FROM_ID (id);
4f65af01
KH
1051 if (charset.emacs_mule_id < 0xA0)
1052 emacs_mule_bytes[charset.emacs_mule_id] = charset.dimension + 1;
3b1ae89b
KH
1053 else
1054 emacs_mule_bytes[charset.emacs_mule_id] = charset.dimension + 2;
3263d5a2
KH
1055 if (new_definition_p)
1056 Vemacs_mule_charset_list = nconc2 (Vemacs_mule_charset_list,
1057 Fcons (make_number (id), Qnil));
4ed46869
KH
1058 }
1059
3263d5a2
KH
1060 if (new_definition_p)
1061 {
1062 Vcharset_list = Fcons (args[charset_arg_name], Vcharset_list);
8055c66a
KH
1063 if (charset.supplementary_p)
1064 Vcharset_ordered_list = nconc2 (Vcharset_ordered_list,
1065 Fcons (make_number (id), Qnil));
1066 else
880820fe
KH
1067 {
1068 Lisp_Object tail;
1069
1070 for (tail = Vcharset_ordered_list; CONSP (tail); tail = XCDR (tail))
1071 {
1072 struct charset *cs = CHARSET_FROM_ID (XINT (XCAR (tail)));
1073
1074 if (cs->supplementary_p)
1075 break;
1076 }
1077 if (EQ (tail, Vcharset_ordered_list))
1078 Vcharset_ordered_list = Fcons (make_number (id),
1079 Vcharset_ordered_list);
1080 else if (NILP (tail))
1081 Vcharset_ordered_list = nconc2 (Vcharset_ordered_list,
1082 Fcons (make_number (id), Qnil));
1083 else
1084 {
1085 val = Fcons (XCAR (tail), XCDR (tail));
1086 XSETCDR (tail, val);
1087 XSETCAR (tail, make_number (id));
1088 }
1089 }
dbbb237d 1090 charset_ordered_list_tick++;
3263d5a2 1091 }
4ed46869 1092
3263d5a2 1093 return Qnil;
4ed46869
KH
1094}
1095
2fe1edd1
KH
1096
1097/* Same as Fdefine_charset_internal but arguments are more convenient
1098 to call from C (typically in syms_of_charset). This can define a
1099 charset of `offset' method only. Return the ID of the new
1100 charset. */
1101
1102static int
1103define_charset_internal (name, dimension, code_space, min_code, max_code,
1104 iso_final, iso_revision, emacs_mule_id,
7acf89e6 1105 ascii_compatible, supplementary,
2fe1edd1
KH
1106 code_offset)
1107 Lisp_Object name;
1108 int dimension;
1109 unsigned char *code_space;
1110 unsigned min_code, max_code;
1111 int iso_final, iso_revision, emacs_mule_id;
7acf89e6 1112 int ascii_compatible, supplementary;
2fe1edd1
KH
1113 int code_offset;
1114{
1115 Lisp_Object args[charset_arg_max];
1116 Lisp_Object plist[14];
1117 Lisp_Object val;
1118 int i;
1119
1120 args[charset_arg_name] = name;
1121 args[charset_arg_dimension] = make_number (dimension);
1122 val = Fmake_vector (make_number (8), make_number (0));
1123 for (i = 0; i < 8; i++)
1124 ASET (val, i, make_number (code_space[i]));
1125 args[charset_arg_code_space] = val;
1126 args[charset_arg_min_code] = make_number (min_code);
1127 args[charset_arg_max_code] = make_number (max_code);
1128 args[charset_arg_iso_final]
1129 = (iso_final < 0 ? Qnil : make_number (iso_final));
1130 args[charset_arg_iso_revision] = make_number (iso_revision);
1131 args[charset_arg_emacs_mule_id]
1132 = (emacs_mule_id < 0 ? Qnil : make_number (emacs_mule_id));
1133 args[charset_arg_ascii_compatible_p] = ascii_compatible ? Qt : Qnil;
7acf89e6 1134 args[charset_arg_supplementary_p] = supplementary ? Qt : Qnil;
2fe1edd1
KH
1135 args[charset_arg_invalid_code] = Qnil;
1136 args[charset_arg_code_offset] = make_number (code_offset);
1137 args[charset_arg_map] = Qnil;
1138 args[charset_arg_subset] = Qnil;
1139 args[charset_arg_superset] = Qnil;
1140 args[charset_arg_unify_map] = Qnil;
1141
1142 plist[0] = intern (":name");
1143 plist[1] = args[charset_arg_name];
1144 plist[2] = intern (":dimension");
1145 plist[3] = args[charset_arg_dimension];
1146 plist[4] = intern (":code-space");
1147 plist[5] = args[charset_arg_code_space];
1148 plist[6] = intern (":iso-final-char");
1149 plist[7] = args[charset_arg_iso_final];
1150 plist[8] = intern (":emacs-mule-id");
1151 plist[9] = args[charset_arg_emacs_mule_id];
1152 plist[10] = intern (":ascii-compatible-p");
1153 plist[11] = args[charset_arg_ascii_compatible_p];
1154 plist[12] = intern (":code-offset");
1155 plist[13] = args[charset_arg_code_offset];
1156
1157 args[charset_arg_plist] = Flist (14, plist);
1158 Fdefine_charset_internal (charset_arg_max, args);
1159
1160 return XINT (CHARSET_SYMBOL_ID (name));
1161}
1162
1163
3263d5a2
KH
1164DEFUN ("define-charset-alias", Fdefine_charset_alias,
1165 Sdefine_charset_alias, 2, 2, 0,
1166 doc: /* Define ALIAS as an alias for charset CHARSET. */)
1167 (alias, charset)
1168 Lisp_Object alias, charset;
4ed46869 1169{
3263d5a2
KH
1170 Lisp_Object attr;
1171
1172 CHECK_CHARSET_GET_ATTR (charset, attr);
1173 Fputhash (alias, attr, Vcharset_hash_table);
528623a0 1174 Vcharset_list = Fcons (alias, Vcharset_list);
3263d5a2
KH
1175 return Qnil;
1176}
4ed46869 1177
4ed46869 1178
3263d5a2 1179DEFUN ("charset-plist", Fcharset_plist, Scharset_plist, 1, 1, 0,
56a46d1d 1180 doc: /* Return the property list of CHARSET. */)
3263d5a2
KH
1181 (charset)
1182 Lisp_Object charset;
1183{
1184 Lisp_Object attrs;
1185
1186 CHECK_CHARSET_GET_ATTR (charset, attrs);
1187 return CHARSET_ATTR_PLIST (attrs);
1188}
1189
1190
1191DEFUN ("set-charset-plist", Fset_charset_plist, Sset_charset_plist, 2, 2, 0,
1192 doc: /* Set CHARSET's property list to PLIST. */)
1193 (charset, plist)
1194 Lisp_Object charset, plist;
1195{
1196 Lisp_Object attrs;
1197
1198 CHECK_CHARSET_GET_ATTR (charset, attrs);
1199 CHARSET_ATTR_PLIST (attrs) = plist;
1200 return plist;
1201}
1202
1203
dbbb237d 1204DEFUN ("unify-charset", Funify_charset, Sunify_charset, 1, 3, 0,
56a46d1d
DL
1205 doc: /* Unify characters of CHARSET with Unicode.
1206This means reading the relevant file and installing the table defined
dbbb237d
KH
1207by CHARSET's `:unify-map' property.
1208
64165ae2
DL
1209Optional second arg UNIFY-MAP is a file name string or a vector. It has
1210the same meaning as the `:unify-map' attribute in the function
dbbb237d
KH
1211`define-charset' (which see).
1212
1213Optional third argument DEUNIFY, if non-nil, means to de-unify CHARSET. */)
1214 (charset, unify_map, deunify)
1215 Lisp_Object charset, unify_map, deunify;
8a73a704 1216{
3263d5a2
KH
1217 int id;
1218 struct charset *cs;
8f924df7 1219
3263d5a2
KH
1220 CHECK_CHARSET_GET_ID (charset, id);
1221 cs = CHARSET_FROM_ID (id);
1222 if (CHARSET_METHOD (cs) == CHARSET_METHOD_MAP_DEFERRED)
1223 load_charset (cs);
dbbb237d
KH
1224 if (NILP (deunify)
1225 ? CHARSET_UNIFIED_P (cs) && ! NILP (CHARSET_DEUNIFIER (cs))
1226 : ! CHARSET_UNIFIED_P (cs))
3263d5a2 1227 return Qnil;
dbbb237d 1228
3263d5a2 1229 CHARSET_UNIFIED_P (cs) = 0;
dbbb237d
KH
1230 if (NILP (deunify))
1231 {
1232 if (CHARSET_METHOD (cs) != CHARSET_METHOD_OFFSET)
8f924df7 1233 error ("Can't unify charset: %s", SDATA (SYMBOL_NAME (charset)));
dbbb237d
KH
1234 if (NILP (unify_map))
1235 unify_map = CHARSET_UNIFY_MAP (cs);
1236 if (STRINGP (unify_map))
1237 load_charset_map_from_file (cs, unify_map, 2);
1238 else if (VECTORP (unify_map))
1239 load_charset_map_from_vector (cs, unify_map, 2);
1240 else if (NILP (unify_map))
1241 error ("No unify-map for charset");
1242 else
1243 error ("Bad unify-map arg");
1244 CHARSET_UNIFIED_P (cs) = 1;
1245 }
1246 else if (CHAR_TABLE_P (Vchar_unify_table))
1247 {
1248 int min_code = CHARSET_MIN_CODE (cs);
1249 int max_code = CHARSET_MAX_CODE (cs);
1250 int min_char = DECODE_CHAR (cs, min_code);
1251 int max_char = DECODE_CHAR (cs, max_code);
8f924df7 1252
dbbb237d
KH
1253 char_table_set_range (Vchar_unify_table, min_char, max_char, Qnil);
1254 }
8f924df7 1255
3263d5a2 1256 return Qnil;
8a73a704
KH
1257}
1258
3fac5a51
KH
1259DEFUN ("get-unused-iso-final-char", Fget_unused_iso_final_char,
1260 Sget_unused_iso_final_char, 2, 2, 0,
3263d5a2 1261 doc: /*
d0cf2d48 1262Return an unused ISO final char for a charset of DIMENSION and CHARS.
fdb82f93
PJ
1263DIMENSION is the number of bytes to represent a character: 1 or 2.
1264CHARS is the number of characters in a dimension: 94 or 96.
1265
1266This final char is for private use, thus the range is `0' (48) .. `?' (63).
1721b6af 1267If there's no unused final char for the specified kind of charset,
fdb82f93
PJ
1268return nil. */)
1269 (dimension, chars)
3fac5a51
KH
1270 Lisp_Object dimension, chars;
1271{
1272 int final_char;
1273
b7826503
PJ
1274 CHECK_NUMBER (dimension);
1275 CHECK_NUMBER (chars);
3263d5a2
KH
1276 if (XINT (dimension) != 1 && XINT (dimension) != 2 && XINT (dimension) != 3)
1277 args_out_of_range_3 (dimension, make_number (1), make_number (3));
3fac5a51 1278 if (XINT (chars) != 94 && XINT (chars) != 96)
3263d5a2 1279 args_out_of_range_3 (chars, make_number (94), make_number (96));
3fac5a51 1280 for (final_char = '0'; final_char <= '?'; final_char++)
3263d5a2
KH
1281 if (ISO_CHARSET_TABLE (XINT (dimension), XINT (chars), final_char) < 0)
1282 break;
3fac5a51
KH
1283 return (final_char <= '?' ? make_number (final_char) : Qnil);
1284}
1285
3263d5a2
KH
1286static void
1287check_iso_charset_parameter (dimension, chars, final_char)
1288 Lisp_Object dimension, chars, final_char;
4ed46869 1289{
3263d5a2
KH
1290 CHECK_NATNUM (dimension);
1291 CHECK_NATNUM (chars);
1292 CHECK_NATNUM (final_char);
4ed46869 1293
3263d5a2
KH
1294 if (XINT (dimension) > 3)
1295 error ("Invalid DIMENSION %d, it should be 1, 2, or 3", XINT (dimension));
4ed46869
KH
1296 if (XINT (chars) != 94 && XINT (chars) != 96)
1297 error ("Invalid CHARS %d, it should be 94 or 96", XINT (chars));
3263d5a2 1298 if (XINT (final_char) < '0' || XINT (final_char) > '~')
4ed46869 1299 error ("Invalid FINAL-CHAR %c, it should be `0'..`~'", XINT (chars));
3263d5a2
KH
1300}
1301
1302
1303DEFUN ("declare-equiv-charset", Fdeclare_equiv_charset, Sdeclare_equiv_charset,
1304 4, 4, 0,
cefd8c4f
KH
1305 doc: /* Declare an equivalent charset for ISO-2022 decoding.
1306
1307On decoding by an ISO-2022 base coding system, when a charset
1308specified by DIMENSION, CHARS, and FINAL-CHAR is designated, behave as
1309if CHARSET is designated instead. */)
3263d5a2
KH
1310 (dimension, chars, final_char, charset)
1311 Lisp_Object dimension, chars, final_char, charset;
1312{
1313 int id;
82215ce9 1314 int chars_flag;
4ed46869 1315
3263d5a2
KH
1316 CHECK_CHARSET_GET_ID (charset, id);
1317 check_iso_charset_parameter (dimension, chars, final_char);
82215ce9
KH
1318 chars_flag = XINT (chars) == 96;
1319 ISO_CHARSET_TABLE (XINT (dimension), chars_flag, XINT (final_char)) = id;
4ed46869
KH
1320 return Qnil;
1321}
1322
3263d5a2 1323
2e344af3
KH
1324/* Return information about charsets in the text at PTR of NBYTES
1325 bytes, which are NCHARS characters. The value is:
f6302ac9 1326
cfe34140 1327 0: Each character is represented by one byte. This is always
3263d5a2
KH
1328 true for a unibyte string. For a multibyte string, true if
1329 it contains only ASCII characters.
1330
28c026cd
DL
1331 1: No charsets other than ascii, control-1, and latin-1 are
1332 found.
1d67c29b 1333
3263d5a2
KH
1334 2: Otherwise.
1335*/
4ed46869
KH
1336
1337int
3263d5a2
KH
1338string_xstring_p (string)
1339 Lisp_Object string;
4ed46869 1340{
8f924df7
KH
1341 const unsigned char *p = SDATA (string);
1342 const unsigned char *endp = p + SBYTES (string);
3263d5a2 1343
8f924df7 1344 if (SCHARS (string) == SBYTES (string))
3263d5a2
KH
1345 return 0;
1346
3263d5a2 1347 while (p < endp)
0282eb69 1348 {
3263d5a2 1349 int c = STRING_CHAR_ADVANCE (p);
2e344af3 1350
3cc67a4d 1351 if (c >= 0x100)
3263d5a2 1352 return 2;
0282eb69 1353 }
3263d5a2
KH
1354 return 1;
1355}
05505664 1356
05505664 1357
3263d5a2 1358/* Find charsets in the string at PTR of NCHARS and NBYTES.
4ed46869 1359
3cc67a4d
KH
1360 CHARSETS is a vector. If Nth element is non-nil, it means the
1361 charset whose id is N is already found.
2e344af3 1362
3263d5a2 1363 It may lookup a translation table TABLE if supplied. */
2e344af3 1364
3263d5a2 1365static void
3cc67a4d 1366find_charsets_in_text (ptr, nchars, nbytes, charsets, table, multibyte)
dbbb237d 1367 const unsigned char *ptr;
42ca828e 1368 EMACS_INT nchars, nbytes;
3263d5a2 1369 Lisp_Object charsets, table;
3cc67a4d 1370 int multibyte;
3263d5a2 1371{
dbbb237d 1372 const unsigned char *pend = ptr + nbytes;
3263d5a2
KH
1373
1374 if (nchars == nbytes)
3263d5a2 1375 {
3cc67a4d
KH
1376 if (multibyte)
1377 ASET (charsets, charset_ascii, Qt);
1378 else
1379 while (ptr < pend)
1380 {
1381 int c = *ptr++;
1382
1383 if (!NILP (table))
1384 c = translate_char (table, c);
1385 if (ASCII_BYTE_P (c))
1386 ASET (charsets, charset_ascii, Qt);
1387 else
1388 ASET (charsets, charset_eight_bit, Qt);
1389 }
1390 }
1391 else
1392 {
1393 while (ptr < pend)
3263d5a2 1394 {
3cc67a4d
KH
1395 int c = STRING_CHAR_ADVANCE (ptr);
1396 struct charset *charset;
3263d5a2 1397
3cc67a4d
KH
1398 if (!NILP (table))
1399 c = translate_char (table, c);
1400 charset = CHAR_CHARSET (c);
1401 ASET (charsets, CHARSET_ID (charset), Qt);
4ed46869 1402 }
4ed46869 1403 }
4ed46869
KH
1404}
1405
1406DEFUN ("find-charset-region", Ffind_charset_region, Sfind_charset_region,
23d2a7f1 1407 2, 3, 0,
fdb82f93
PJ
1408 doc: /* Return a list of charsets in the region between BEG and END.
1409BEG and END are buffer positions.
1410Optional arg TABLE if non-nil is a translation table to look up.
1411
fdb82f93
PJ
1412If the current buffer is unibyte, the returned list may contain
1413only `ascii', `eight-bit-control', and `eight-bit-graphic'. */)
1414 (beg, end, table)
23d2a7f1 1415 Lisp_Object beg, end, table;
4ed46869 1416{
3263d5a2 1417 Lisp_Object charsets;
42ca828e
DL
1418 EMACS_INT from, from_byte, to, stop, stop_byte;
1419 int i;
4ed46869 1420 Lisp_Object val;
3cc67a4d 1421 int multibyte = ! NILP (current_buffer->enable_multibyte_characters);
4ed46869
KH
1422
1423 validate_region (&beg, &end);
1424 from = XFASTINT (beg);
1425 stop = to = XFASTINT (end);
6ae1f27e 1426
4ed46869 1427 if (from < GPT && GPT < to)
6ae1f27e
RS
1428 {
1429 stop = GPT;
1430 stop_byte = GPT_BYTE;
1431 }
1432 else
1433 stop_byte = CHAR_TO_BYTE (stop);
1434
1435 from_byte = CHAR_TO_BYTE (from);
1436
3263d5a2 1437 charsets = Fmake_vector (make_number (charset_table_used), Qnil);
4ed46869
KH
1438 while (1)
1439 {
3263d5a2 1440 find_charsets_in_text (BYTE_POS_ADDR (from_byte), stop - from,
3cc67a4d
KH
1441 stop_byte - from_byte, charsets, table,
1442 multibyte);
4ed46869 1443 if (stop < to)
6ae1f27e
RS
1444 {
1445 from = stop, from_byte = stop_byte;
1446 stop = to, stop_byte = CHAR_TO_BYTE (stop);
1447 }
4ed46869
KH
1448 else
1449 break;
1450 }
6ae1f27e 1451
4ed46869 1452 val = Qnil;
3263d5a2 1453 for (i = charset_table_used - 1; i >= 0; i--)
3cc67a4d 1454 if (!NILP (AREF (charsets, i)))
3263d5a2 1455 val = Fcons (CHARSET_NAME (charset_table + i), val);
4ed46869
KH
1456 return val;
1457}
1458
1459DEFUN ("find-charset-string", Ffind_charset_string, Sfind_charset_string,
23d2a7f1 1460 1, 2, 0,
fdb82f93
PJ
1461 doc: /* Return a list of charsets in STR.
1462Optional arg TABLE if non-nil is a translation table to look up.
1463
fdb82f93 1464If STR is unibyte, the returned list may contain
3263d5a2 1465only `ascii', `eight-bit-control', and `eight-bit-graphic'. */)
fdb82f93 1466 (str, table)
23d2a7f1 1467 Lisp_Object str, table;
4ed46869 1468{
3263d5a2 1469 Lisp_Object charsets;
4ed46869
KH
1470 int i;
1471 Lisp_Object val;
1472
b7826503 1473 CHECK_STRING (str);
87b089ad 1474
3263d5a2 1475 charsets = Fmake_vector (make_number (charset_table_used), Qnil);
8f924df7 1476 find_charsets_in_text (SDATA (str), SCHARS (str), SBYTES (str),
3cc67a4d
KH
1477 charsets, table,
1478 STRING_MULTIBYTE (str));
4ed46869 1479 val = Qnil;
3263d5a2 1480 for (i = charset_table_used - 1; i >= 0; i--)
3cc67a4d 1481 if (!NILP (AREF (charsets, i)))
3263d5a2 1482 val = Fcons (CHARSET_NAME (charset_table + i), val);
4ed46869
KH
1483 return val;
1484}
2e344af3 1485
4ed46869 1486\f
3263d5a2
KH
1487
1488/* Return a character correponding to the code-point CODE of
1489 CHARSET. */
1490
1491int
1492decode_char (charset, code)
1493 struct charset *charset;
1494 unsigned code;
4ed46869 1495{
3263d5a2
KH
1496 int c, char_index;
1497 enum charset_method method = CHARSET_METHOD (charset);
ac4137cc 1498
3263d5a2
KH
1499 if (code < CHARSET_MIN_CODE (charset) || code > CHARSET_MAX_CODE (charset))
1500 return -1;
4ed46869 1501
3263d5a2 1502 if (method == CHARSET_METHOD_MAP_DEFERRED)
ac4137cc 1503 {
3263d5a2
KH
1504 load_charset (charset);
1505 method = CHARSET_METHOD (charset);
ac4137cc 1506 }
4ed46869 1507
374c5cfd 1508 if (method == CHARSET_METHOD_SUBSET)
2e344af3 1509 {
374c5cfd
KH
1510 Lisp_Object subset_info;
1511
1512 subset_info = CHARSET_SUBSET (charset);
1513 charset = CHARSET_FROM_ID (XFASTINT (AREF (subset_info, 0)));
1514 code -= XINT (AREF (subset_info, 3));
1515 if (code < XFASTINT (AREF (subset_info, 1))
1516 || code > XFASTINT (AREF (subset_info, 2)))
1517 c = -1;
1518 else
1519 c = DECODE_CHAR (charset, code);
2e344af3 1520 }
374c5cfd 1521 else if (method == CHARSET_METHOD_SUPERSET)
2e344af3 1522 {
3263d5a2 1523 Lisp_Object parents;
4ed46869 1524
374c5cfd 1525 parents = CHARSET_SUPERSET (charset);
3263d5a2
KH
1526 c = -1;
1527 for (; CONSP (parents); parents = XCDR (parents))
1528 {
1529 int id = XINT (XCAR (XCAR (parents)));
1530 int code_offset = XINT (XCDR (XCAR (parents)));
374c5cfd 1531 unsigned this_code = code - code_offset;
4ed46869 1532
3263d5a2
KH
1533 charset = CHARSET_FROM_ID (id);
1534 if ((c = DECODE_CHAR (charset, this_code)) >= 0)
1535 break;
1536 }
1537 }
1538 else
ac4137cc 1539 {
3263d5a2 1540 char_index = CODE_POINT_TO_INDEX (charset, code);
69f8de5b
KH
1541 if (char_index < 0)
1542 return -1;
4ed46869 1543
3263d5a2 1544 if (method == CHARSET_METHOD_MAP)
ac4137cc 1545 {
3263d5a2 1546 Lisp_Object decoder;
4ed46869 1547
3263d5a2
KH
1548 decoder = CHARSET_DECODER (charset);
1549 if (! VECTORP (decoder))
1550 return -1;
1551 c = XINT (AREF (decoder, char_index));
ac4137cc
KH
1552 }
1553 else
1554 {
3263d5a2 1555 c = char_index + CHARSET_CODE_OFFSET (charset);
ac4137cc
KH
1556 }
1557 }
4ed46869 1558
3263d5a2
KH
1559 if (CHARSET_UNIFIED_P (charset)
1560 && c >= 0)
c449997d
KH
1561 {
1562 MAYBE_UNIFY_CHAR (c);
1563 }
ac4137cc 1564
3263d5a2 1565 return c;
90d7b74e
KH
1566}
1567
374c5cfd
KH
1568/* Variable used temporarily by the macro ENCODE_CHAR. */
1569Lisp_Object charset_work;
4ed46869 1570
3263d5a2 1571/* Return a code-point of CHAR in CHARSET. If CHAR doesn't belong to
28c026cd
DL
1572 CHARSET, return CHARSET_INVALID_CODE (CHARSET). If STRICT is true,
1573 use CHARSET's strict_max_char instead of max_char. */
4ed46869 1574
3263d5a2
KH
1575unsigned
1576encode_char (charset, c)
1577 struct charset *charset;
9b6a601f 1578 int c;
9d3d8cba 1579{
3263d5a2
KH
1580 unsigned code;
1581 enum charset_method method = CHARSET_METHOD (charset);
9d3d8cba 1582
3263d5a2 1583 if (CHARSET_UNIFIED_P (charset))
ac4137cc 1584 {
374c5cfd 1585 Lisp_Object deunifier, deunified;
4ed46869 1586
3263d5a2
KH
1587 deunifier = CHARSET_DEUNIFIER (charset);
1588 if (! CHAR_TABLE_P (deunifier))
ac4137cc 1589 {
dbbb237d 1590 Funify_charset (CHARSET_NAME (charset), Qnil, Qnil);
3263d5a2 1591 deunifier = CHARSET_DEUNIFIER (charset);
ac4137cc 1592 }
374c5cfd
KH
1593 deunified = CHAR_TABLE_REF (deunifier, c);
1594 if (! NILP (deunified))
1595 c = XINT (deunified);
ac4137cc 1596 }
9d3d8cba 1597
374c5cfd
KH
1598 if (method == CHARSET_METHOD_SUBSET)
1599 {
1600 Lisp_Object subset_info;
1601 struct charset *this_charset;
1602
1603 subset_info = CHARSET_SUBSET (charset);
1604 this_charset = CHARSET_FROM_ID (XFASTINT (AREF (subset_info, 0)));
1605 code = ENCODE_CHAR (this_charset, c);
1606 if (code == CHARSET_INVALID_CODE (this_charset)
1607 || code < XFASTINT (AREF (subset_info, 1))
1608 || code > XFASTINT (AREF (subset_info, 2)))
1609 return CHARSET_INVALID_CODE (charset);
1610 code += XINT (AREF (subset_info, 3));
1611 return code;
1612 }
9d3d8cba 1613
374c5cfd 1614 if (method == CHARSET_METHOD_SUPERSET)
859f2b3c 1615 {
3263d5a2 1616 Lisp_Object parents;
d2665018 1617
374c5cfd 1618 parents = CHARSET_SUPERSET (charset);
3263d5a2 1619 for (; CONSP (parents); parents = XCDR (parents))
beeedaad 1620 {
3263d5a2
KH
1621 int id = XINT (XCAR (XCAR (parents)));
1622 int code_offset = XINT (XCDR (XCAR (parents)));
1623 struct charset *this_charset = CHARSET_FROM_ID (id);
d2665018 1624
3263d5a2 1625 code = ENCODE_CHAR (this_charset, c);
dbbb237d
KH
1626 if (code != CHARSET_INVALID_CODE (this_charset))
1627 return code + code_offset;
beeedaad 1628 }
3263d5a2
KH
1629 return CHARSET_INVALID_CODE (charset);
1630 }
1bcc1567 1631
15c85a88
KH
1632 if (! CHARSET_FAST_MAP_REF ((c), charset->fast_map)
1633 || c < CHARSET_MIN_CHAR (charset) || c > CHARSET_MAX_CHAR (charset))
1634 return CHARSET_INVALID_CODE (charset);
1bcc1567 1635
3263d5a2 1636 if (method == CHARSET_METHOD_MAP_DEFERRED)
beeedaad 1637 {
3263d5a2
KH
1638 load_charset (charset);
1639 method = CHARSET_METHOD (charset);
859f2b3c 1640 }
9b6a601f 1641
3263d5a2 1642 if (method == CHARSET_METHOD_MAP)
3f62427c 1643 {
3263d5a2 1644 Lisp_Object encoder;
beeedaad 1645 Lisp_Object val;
9b6a601f 1646
3263d5a2
KH
1647 encoder = CHARSET_ENCODER (charset);
1648 if (! CHAR_TABLE_P (CHARSET_ENCODER (charset)))
1649 return CHARSET_INVALID_CODE (charset);
1650 val = CHAR_TABLE_REF (encoder, c);
374c5cfd
KH
1651 if (NILP (val))
1652 return CHARSET_INVALID_CODE (charset);
e9ce014c
KH
1653 code = XINT (val);
1654 if (! CHARSET_COMPACT_CODES_P (charset))
1655 code = INDEX_TO_CODE_POINT (charset, code);
3263d5a2 1656 }
820ee249 1657 else /* method == CHARSET_METHOD_OFFSET */
beeedaad 1658 {
3263d5a2
KH
1659 code = c - CHARSET_CODE_OFFSET (charset);
1660 code = INDEX_TO_CODE_POINT (charset, code);
3f62427c 1661 }
8ac5a9cc 1662
3263d5a2 1663 return code;
4ed46869
KH
1664}
1665
4ed46869 1666
3263d5a2
KH
1667DEFUN ("decode-char", Fdecode_char, Sdecode_char, 2, 3, 0,
1668 doc: /* Decode the pair of CHARSET and CODE-POINT into a character.
1669Return nil if CODE-POINT is not valid in CHARSET.
4ed46869 1670
3263d5a2 1671CODE-POINT may be a cons (HIGHER-16-BIT-VALUE . LOWER-16-BIT-VALUE).
859f2b3c 1672
3263d5a2 1673Optional argument RESTRICTION specifies a way to map the pair of CCS
d0cf2d48 1674and CODE-POINT to a character. Currently not supported and just ignored. */)
3263d5a2
KH
1675 (charset, code_point, restriction)
1676 Lisp_Object charset, code_point, restriction;
4ed46869 1677{
3263d5a2
KH
1678 int c, id;
1679 unsigned code;
1680 struct charset *charsetp;
859f2b3c 1681
3263d5a2
KH
1682 CHECK_CHARSET_GET_ID (charset, id);
1683 if (CONSP (code_point))
1684 {
8f924df7
KH
1685 CHECK_NATNUM_CAR (code_point);
1686 CHECK_NATNUM_CDR (code_point);
69f8de5b 1687 code = (XINT (XCAR (code_point)) << 16) | (XINT (XCDR (code_point)));
3263d5a2 1688 }
4ed46869
KH
1689 else
1690 {
3263d5a2
KH
1691 CHECK_NATNUM (code_point);
1692 code = XINT (code_point);
4ed46869 1693 }
3263d5a2
KH
1694 charsetp = CHARSET_FROM_ID (id);
1695 c = DECODE_CHAR (charsetp, code);
1696 return (c >= 0 ? make_number (c) : Qnil);
4ed46869
KH
1697}
1698
859f2b3c 1699
3263d5a2
KH
1700DEFUN ("encode-char", Fencode_char, Sencode_char, 2, 3, 0,
1701 doc: /* Encode the character CH into a code-point of CHARSET.
1702Return nil if CHARSET doesn't include CH.
17e7ef1b 1703
d0cf2d48 1704Optional argument RESTRICTION specifies a way to map CH to a
3263d5a2
KH
1705code-point in CCS. Currently not supported and just ignored. */)
1706 (ch, charset, restriction)
1707 Lisp_Object ch, charset, restriction;
4ed46869 1708{
16fed1fc 1709 int id;
3263d5a2
KH
1710 unsigned code;
1711 struct charset *charsetp;
046b1f03 1712
3263d5a2
KH
1713 CHECK_CHARSET_GET_ID (charset, id);
1714 CHECK_NATNUM (ch);
3263d5a2 1715 charsetp = CHARSET_FROM_ID (id);
16fed1fc 1716 code = ENCODE_CHAR (charsetp, XINT (ch));
3263d5a2
KH
1717 if (code == CHARSET_INVALID_CODE (charsetp))
1718 return Qnil;
1719 if (code > 0x7FFFFFF)
1720 return Fcons (make_number (code >> 16), make_number (code & 0xFFFF));
1721 return make_number (code);
beeedaad
KH
1722}
1723
beeedaad 1724
b121a744
KH
1725DEFUN ("make-char", Fmake_char, Smake_char, 1, 5, 0,
1726 doc:
1727 /* Return a character of CHARSET whose position codes are CODEn.
1728
1729CODE1 through CODE4 are optional, but if you don't supply sufficient
1730position codes, it is assumed that the minimum code in each dimension
04c2f2c5 1731is specified. */)
b121a744
KH
1732 (charset, code1, code2, code3, code4)
1733 Lisp_Object charset, code1, code2, code3, code4;
beeedaad 1734{
3263d5a2
KH
1735 int id, dimension;
1736 struct charset *charsetp;
b121a744
KH
1737 unsigned code;
1738 int c;
87b089ad 1739
3263d5a2
KH
1740 CHECK_CHARSET_GET_ID (charset, id);
1741 charsetp = CHARSET_FROM_ID (id);
4ed46869 1742
b121a744
KH
1743 dimension = CHARSET_DIMENSION (charsetp);
1744 if (NILP (code1))
d47073ca
KH
1745 code = (CHARSET_ASCII_COMPATIBLE_P (charsetp)
1746 ? 0 : CHARSET_MIN_CODE (charsetp));
3263d5a2 1747 else
859f2b3c 1748 {
b121a744
KH
1749 CHECK_NATNUM (code1);
1750 if (XFASTINT (code1) >= 0x100)
1751 args_out_of_range (make_number (0xFF), code1);
1752 code = XFASTINT (code1);
859f2b3c 1753
b0a1e45e 1754 if (dimension > 1)
beeedaad 1755 {
b121a744 1756 code <<= 8;
b0a1e45e
KH
1757 if (NILP (code2))
1758 code |= charsetp->code_space[(dimension - 2) * 4];
beeedaad 1759 else
b121a744 1760 {
b0a1e45e
KH
1761 CHECK_NATNUM (code2);
1762 if (XFASTINT (code2) >= 0x100)
1763 args_out_of_range (make_number (0xFF), code2);
1764 code |= XFASTINT (code2);
b121a744 1765 }
99529c2c 1766
b0a1e45e 1767 if (dimension > 2)
b121a744
KH
1768 {
1769 code <<= 8;
b0a1e45e
KH
1770 if (NILP (code3))
1771 code |= charsetp->code_space[(dimension - 3) * 4];
b121a744
KH
1772 else
1773 {
b0a1e45e
KH
1774 CHECK_NATNUM (code3);
1775 if (XFASTINT (code3) >= 0x100)
1776 args_out_of_range (make_number (0xFF), code3);
1777 code |= XFASTINT (code3);
1778 }
1779
1780 if (dimension > 3)
1781 {
1782 code <<= 8;
1783 if (NILP (code4))
1784 code |= charsetp->code_space[0];
1785 else
1786 {
1787 CHECK_NATNUM (code4);
1788 if (XFASTINT (code4) >= 0x100)
1789 args_out_of_range (make_number (0xFF), code4);
1790 code |= XFASTINT (code4);
1791 }
b121a744
KH
1792 }
1793 }
beeedaad 1794 }
859f2b3c 1795 }
beeedaad 1796
b121a744
KH
1797 if (CHARSET_ISO_FINAL (charsetp) >= 0)
1798 code &= 0x7F7F7F7F;
1799 c = DECODE_CHAR (charsetp, code);
1800 if (c < 0)
1801 error ("Invalid code(s)");
3263d5a2 1802 return make_number (c);
4ed46869
KH
1803}
1804
beeedaad 1805
3263d5a2
KH
1806/* Return the first charset in CHARSET_LIST that contains C.
1807 CHARSET_LIST is a list of charset IDs. If it is nil, use
1808 Vcharset_ordered_list. */
beeedaad 1809
3263d5a2
KH
1810struct charset *
1811char_charset (c, charset_list, code_return)
1812 int c;
1813 Lisp_Object charset_list;
1814 unsigned *code_return;
2e344af3 1815{
8a1816bb
KH
1816 int maybe_null = 0;
1817
3263d5a2
KH
1818 if (NILP (charset_list))
1819 charset_list = Vcharset_ordered_list;
8a1816bb
KH
1820 else
1821 maybe_null = 1;
beeedaad 1822
6c652beb 1823 while (CONSP (charset_list))
2e344af3 1824 {
3263d5a2
KH
1825 struct charset *charset = CHARSET_FROM_ID (XINT (XCAR (charset_list)));
1826 unsigned code = ENCODE_CHAR (charset, c);
beeedaad 1827
3263d5a2 1828 if (code != CHARSET_INVALID_CODE (charset))
beeedaad 1829 {
3263d5a2
KH
1830 if (code_return)
1831 *code_return = code;
1832 return charset;
3f62427c 1833 }
3263d5a2 1834 charset_list = XCDR (charset_list);
6c652beb
KH
1835 if (c <= MAX_UNICODE_CHAR
1836 && EQ (charset_list, Vcharset_non_preferred_head))
1837 return CHARSET_FROM_ID (charset_unicode);
3f62427c 1838 }
8a1816bb
KH
1839 return (maybe_null ? NULL
1840 : c <= MAX_5_BYTE_CHAR ? CHARSET_FROM_ID (charset_emacs)
6a9c90ec 1841 : CHARSET_FROM_ID (charset_eight_bit));
3f62427c
KH
1842}
1843
2e344af3 1844
3263d5a2 1845DEFUN ("split-char", Fsplit_char, Ssplit_char, 1, 1, 0,
3cc67a4d 1846 doc:
d0cf2d48 1847 /*Return list of charset and one to four position-codes of CH.
3cc67a4d
KH
1848The charset is decided by the current priority order of charsets.
1849A position-code is a byte value of each dimension of the code-point of
d0cf2d48 1850CH in the charset. */)
3263d5a2
KH
1851 (ch)
1852 Lisp_Object ch;
4ed46869 1853{
3263d5a2
KH
1854 struct charset *charset;
1855 int c, dimension;
1856 unsigned code;
4ed46869
KH
1857 Lisp_Object val;
1858
3263d5a2
KH
1859 CHECK_CHARACTER (ch);
1860 c = XFASTINT (ch);
1861 charset = CHAR_CHARSET (c);
1862 if (! charset)
3cc67a4d 1863 abort ();
3263d5a2
KH
1864 code = ENCODE_CHAR (charset, c);
1865 if (code == CHARSET_INVALID_CODE (charset))
1866 abort ();
1867 dimension = CHARSET_DIMENSION (charset);
3cc67a4d
KH
1868 for (val = Qnil; dimension > 0; dimension--)
1869 {
1870 val = Fcons (make_number (code & 0xFF), val);
1871 code >>= 8;
1872 }
3263d5a2 1873 return Fcons (CHARSET_NAME (charset), val);
4ed46869
KH
1874}
1875
740f080d 1876
3263d5a2 1877DEFUN ("char-charset", Fchar_charset, Schar_charset, 1, 1, 0,
327719ee 1878 doc: /* Return the charset of highest priority that contains CH. */)
fdb82f93 1879 (ch)
4ed46869
KH
1880 Lisp_Object ch;
1881{
3263d5a2 1882 struct charset *charset;
4ed46869 1883
3263d5a2
KH
1884 CHECK_CHARACTER (ch);
1885 charset = CHAR_CHARSET (XINT (ch));
1886 return (CHARSET_NAME (charset));
4ed46869
KH
1887}
1888
17e7ef1b 1889
3263d5a2
KH
1890DEFUN ("charset-after", Fcharset_after, Scharset_after, 0, 1, 0,
1891 doc: /*
1892Return charset of a character in the current buffer at position POS.
1893If POS is nil, it defauls to the current point.
1894If POS is out of range, the value is nil. */)
1895 (pos)
1896 Lisp_Object pos;
2e344af3 1897{
3263d5a2
KH
1898 Lisp_Object ch;
1899 struct charset *charset;
046b1f03 1900
3263d5a2
KH
1901 ch = Fchar_after (pos);
1902 if (! INTEGERP (ch))
1903 return ch;
1904 charset = CHAR_CHARSET (XINT (ch));
1905 return (CHARSET_NAME (charset));
6ae1f27e 1906}
9036eb45 1907
87b089ad 1908
3263d5a2
KH
1909DEFUN ("iso-charset", Fiso_charset, Siso_charset, 3, 3, 0,
1910 doc: /*
1911Return charset of ISO's specification DIMENSION, CHARS, and FINAL-CHAR.
1912
1913ISO 2022's designation sequence (escape sequence) distinguishes charsets
1914by their DIMENSION, CHARS, and FINAL-CHAR,
d0cf2d48 1915whereas Emacs distinguishes them by charset symbol.
3263d5a2
KH
1916See the documentation of the function `charset-info' for the meanings of
1917DIMENSION, CHARS, and FINAL-CHAR. */)
1918 (dimension, chars, final_char)
1919 Lisp_Object dimension, chars, final_char;
6ae1f27e 1920{
3263d5a2 1921 int id;
82215ce9 1922 int chars_flag;
a8a35e61 1923
3263d5a2 1924 check_iso_charset_parameter (dimension, chars, final_char);
82215ce9
KH
1925 chars_flag = XFASTINT (chars) == 96;
1926 id = ISO_CHARSET_TABLE (XFASTINT (dimension), chars_flag,
3263d5a2
KH
1927 XFASTINT (final_char));
1928 return (id >= 0 ? CHARSET_NAME (CHARSET_FROM_ID (id)) : Qnil);
046b1f03
RS
1929}
1930
87b089ad 1931
3263d5a2
KH
1932DEFUN ("clear-charset-maps", Fclear_charset_maps, Sclear_charset_maps,
1933 0, 0, 0,
1934 doc: /*
1935Clear encoder and decoder of charsets that are loaded from mapfiles. */)
1936 ()
87b089ad 1937{
53316e55 1938 int i;
3263d5a2
KH
1939 struct charset *charset;
1940 Lisp_Object attrs;
87b089ad 1941
3263d5a2 1942 for (i = 0; i < charset_table_used; i++)
87b089ad 1943 {
3263d5a2
KH
1944 charset = CHARSET_FROM_ID (i);
1945 attrs = CHARSET_ATTRIBUTES (charset);
2e344af3 1946
3263d5a2
KH
1947 if (CHARSET_METHOD (charset) == CHARSET_METHOD_MAP)
1948 {
1949 CHARSET_ATTR_DECODER (attrs) = Qnil;
1950 CHARSET_ATTR_ENCODER (attrs) = Qnil;
1951 CHARSET_METHOD (charset) = CHARSET_METHOD_MAP_DEFERRED;
1952 }
2e344af3 1953
3263d5a2
KH
1954 if (CHARSET_UNIFIED_P (charset))
1955 CHARSET_ATTR_DEUNIFIER (attrs) = Qnil;
2e344af3 1956 }
2e344af3 1957
3263d5a2 1958 if (CHAR_TABLE_P (Vchar_unified_charset_table))
2e344af3 1959 {
d0827857 1960 Foptimize_char_table (Vchar_unified_charset_table, Qnil);
3263d5a2
KH
1961 Vchar_unify_table = Vchar_unified_charset_table;
1962 Vchar_unified_charset_table = Qnil;
87b089ad 1963 }
740f080d 1964
3263d5a2 1965 return Qnil;
740f080d
KH
1966}
1967
8ddf5e57
DL
1968DEFUN ("charset-priority-list", Fcharset_priority_list,
1969 Scharset_priority_list, 0, 1, 0,
1970 doc: /* Return the list of charsets ordered by priority.
1971HIGHESTP non-nil means just return the highest priority one. */)
1972 (highestp)
1973 Lisp_Object highestp;
2e344af3 1974{
8ddf5e57 1975 Lisp_Object val = Qnil, list = Vcharset_ordered_list;
2e344af3 1976
8ddf5e57 1977 if (!NILP (highestp))
16fed1fc 1978 return CHARSET_NAME (CHARSET_FROM_ID (XINT (Fcar (list))));
2e344af3 1979
8ddf5e57 1980 while (!NILP (list))
2e344af3 1981 {
16fed1fc 1982 val = Fcons (CHARSET_NAME (CHARSET_FROM_ID (XINT (XCAR (list)))), val);
8ddf5e57 1983 list = XCDR (list);
2e344af3 1984 }
8ddf5e57 1985 return Fnreverse (val);
2e344af3
KH
1986}
1987
8ddf5e57
DL
1988DEFUN ("set-charset-priority", Fset_charset_priority, Sset_charset_priority,
1989 1, MANY, 0,
1990 doc: /* Assign higher priority to the charsets given as arguments.
1991usage: (set-charset-priority &rest charsets) */)
1992 (nargs, args)
1993 int nargs;
4ed46869
KH
1994 Lisp_Object *args;
1995{
af7c60ca 1996 Lisp_Object new_head, old_list, arglist[2];
321c819c 1997 Lisp_Object list_2022, list_emacs_mule;
16fed1fc 1998 int i, id;
4ed46869 1999
8ddf5e57 2000 old_list = Fcopy_sequence (Vcharset_ordered_list);
af7c60ca 2001 new_head = Qnil;
8ddf5e57 2002 for (i = 0; i < nargs; i++)
4ed46869 2003 {
8ddf5e57 2004 CHECK_CHARSET_GET_ID (args[i], id);
af7c60ca
KH
2005 if (! NILP (Fmemq (make_number (id), old_list)))
2006 {
2007 old_list = Fdelq (make_number (id), old_list);
2008 new_head = Fcons (make_number (id), new_head);
2009 }
5729c92f 2010 }
8ddf5e57 2011 arglist[0] = Fnreverse (new_head);
6a9c90ec 2012 arglist[1] = Vcharset_non_preferred_head = old_list;
8ddf5e57 2013 Vcharset_ordered_list = Fnconc (2, arglist);
dbbb237d 2014 charset_ordered_list_tick++;
5729c92f 2015
321c819c 2016 for (old_list = Vcharset_ordered_list, list_2022 = list_emacs_mule = Qnil;
d017b41e 2017 CONSP (old_list); old_list = XCDR (old_list))
5729c92f 2018 {
e77415b0 2019 if (! NILP (Fmemq (XCAR (old_list), Viso_2022_charset_list)))
321c819c
KH
2020 list_2022 = Fcons (XCAR (old_list), list_2022);
2021 if (! NILP (Fmemq (XCAR (old_list), Vemacs_mule_charset_list)))
2022 list_emacs_mule = Fcons (XCAR (old_list), list_emacs_mule);
4ed46869 2023 }
321c819c
KH
2024 Viso_2022_charset_list = Fnreverse (list_2022);
2025 Vemacs_mule_charset_list = Fnreverse (list_emacs_mule);
4ed46869 2026
8ddf5e57 2027 return Qnil;
4ed46869
KH
2028}
2029
d5b33309
KH
2030DEFUN ("charset-id-internal", Fcharset_id_internal, Scharset_id_internal,
2031 0, 1, 0,
2032 doc: /* Internal use only.
2033Return charset identification number of CHARSET. */)
2034 (charset)
2035 Lisp_Object charset;
4ed46869 2036{
d5b33309 2037 int id;
4ed46869 2038
d5b33309
KH
2039 CHECK_CHARSET_GET_ID (charset, id);
2040 return make_number (id);
4ed46869
KH
2041}
2042
4ed46869 2043\f
3263d5a2
KH
2044void
2045init_charset ()
4ed46869 2046{
c8f94403
GM
2047 Lisp_Object tempdir;
2048 tempdir = Fexpand_file_name (build_string ("charsets"), Vdata_directory);
2049 if (access (SDATA (tempdir), 0) < 0)
2050 {
2051 dir_warning ("Error: charsets directory (%s) does not exist.\n\
2052Emacs will not function correctly without the character map files.\n\
2053Please check your installation!\n",
2054 tempdir);
2055 /* TODO should this be a fatal error? (Bug#909) */
2056 }
2057
2058 Vcharset_map_path = Fcons (tempdir, Qnil);
4ed46869
KH
2059}
2060
4ed46869 2061
dfcf069d 2062void
4ed46869
KH
2063init_charset_once ()
2064{
2065 int i, j, k;
2066
3263d5a2
KH
2067 for (i = 0; i < ISO_MAX_DIMENSION; i++)
2068 for (j = 0; j < ISO_MAX_CHARS; j++)
2069 for (k = 0; k < ISO_MAX_FINAL; k++)
2070 iso_charset_table[i][j][k] = -1;
4ed46869 2071
60383934 2072 for (i = 0; i < 256; i++)
3263d5a2 2073 emacs_mule_charset[i] = NULL;
4ed46869 2074
7c7dceee
KH
2075 charset_jisx0201_roman = -1;
2076 charset_jisx0208_1978 = -1;
2077 charset_jisx0208 = -1;
4ed46869
KH
2078
2079 for (i = 0; i < 128; i++)
14e3d523 2080 unibyte_to_multibyte_table[i] = i;
4ed46869 2081 for (; i < 256; i++)
170e4589 2082 unibyte_to_multibyte_table[i] = BYTE8_TO_CHAR (i);
4ed46869
KH
2083}
2084
2085#ifdef emacs
2086
dfcf069d 2087void
4ed46869
KH
2088syms_of_charset ()
2089{
3263d5a2
KH
2090 DEFSYM (Qcharsetp, "charsetp");
2091
2092 DEFSYM (Qascii, "ascii");
2093 DEFSYM (Qunicode, "unicode");
6c652beb 2094 DEFSYM (Qemacs, "emacs");
2fe1edd1 2095 DEFSYM (Qeight_bit, "eight-bit");
3263d5a2
KH
2096 DEFSYM (Qiso_8859_1, "iso-8859-1");
2097
2098 DEFSYM (Qgl, "gl");
2099 DEFSYM (Qgr, "gr");
2100
3263d5a2
KH
2101 staticpro (&Vcharset_ordered_list);
2102 Vcharset_ordered_list = Qnil;
2103
2104 staticpro (&Viso_2022_charset_list);
2105 Viso_2022_charset_list = Qnil;
2106
2107 staticpro (&Vemacs_mule_charset_list);
2108 Vemacs_mule_charset_list = Qnil;
2109
3943ed76
KH
2110 /* Don't staticpro them here. It's done in syms_of_fns. */
2111 QCtest = intern (":test");
2112 Qeq = intern ("eq");
2113
3263d5a2 2114 staticpro (&Vcharset_hash_table);
8f924df7
KH
2115 {
2116 Lisp_Object args[2];
2117 args[0] = QCtest;
2118 args[1] = Qeq;
2119 Vcharset_hash_table = Fmake_hash_table (2, args);
2120 }
3263d5a2
KH
2121
2122 charset_table_size = 128;
2123 charset_table = ((struct charset *)
2124 xmalloc (sizeof (struct charset) * charset_table_size));
2125 charset_table_used = 0;
2126
2127 staticpro (&Vchar_unified_charset_table);
2128 Vchar_unified_charset_table = Fmake_char_table (Qnil, make_number (-1));
2129
2130 defsubr (&Scharsetp);
2131 defsubr (&Smap_charset_chars);
2132 defsubr (&Sdefine_charset_internal);
2133 defsubr (&Sdefine_charset_alias);
3263d5a2
KH
2134 defsubr (&Scharset_plist);
2135 defsubr (&Sset_charset_plist);
2136 defsubr (&Sunify_charset);
3fac5a51 2137 defsubr (&Sget_unused_iso_final_char);
4ed46869
KH
2138 defsubr (&Sdeclare_equiv_charset);
2139 defsubr (&Sfind_charset_region);
2140 defsubr (&Sfind_charset_string);
3263d5a2
KH
2141 defsubr (&Sdecode_char);
2142 defsubr (&Sencode_char);
4ed46869 2143 defsubr (&Ssplit_char);
3263d5a2 2144 defsubr (&Smake_char);
4ed46869 2145 defsubr (&Schar_charset);
90d7b74e 2146 defsubr (&Scharset_after);
4ed46869 2147 defsubr (&Siso_charset);
3263d5a2 2148 defsubr (&Sclear_charset_maps);
8ddf5e57
DL
2149 defsubr (&Scharset_priority_list);
2150 defsubr (&Sset_charset_priority);
d5b33309 2151 defsubr (&Scharset_id_internal);
3263d5a2 2152
4beef065 2153 DEFVAR_LISP ("charset-map-path", &Vcharset_map_path,
6f3122a7 2154 doc: /* *List of directories to search for charset map files. */);
4beef065 2155 Vcharset_map_path = Qnil;
4ed46869
KH
2156
2157 DEFVAR_LISP ("charset-list", &Vcharset_list,
528623a0 2158 doc: /* List of all charsets ever defined. */);
3263d5a2
KH
2159 Vcharset_list = Qnil;
2160
6a9c90ec
KH
2161 DEFVAR_LISP ("current-iso639-language", &Vcurrent_iso639_language,
2162 doc: /* ISO639 language mnemonic symbol for the current language environment.
2163If the current language environment is for multiple languages (e.g. "Latin-1"),
2164the value may be a list of mnemonics. */);
2165 Vcurrent_iso639_language = Qnil;
2166
2fe1edd1
KH
2167 charset_ascii
2168 = define_charset_internal (Qascii, 1, "\x00\x7F\x00\x00\x00\x00",
2169 0, 127, 'B', -1, 0, 1, 0, 0);
14e3d523
KH
2170 charset_iso_8859_1
2171 = define_charset_internal (Qiso_8859_1, 1, "\x00\xFF\x00\x00\x00\x00",
2172 0, 255, -1, -1, -1, 1, 0, 0);
2fe1edd1 2173 charset_unicode
73fbf2d9 2174 = define_charset_internal (Qunicode, 3, "\x00\xFF\x00\xFF\x00\x10",
2fe1edd1 2175 0, MAX_UNICODE_CHAR, -1, 0, -1, 1, 0, 0);
6c652beb
KH
2176 charset_emacs
2177 = define_charset_internal (Qemacs, 3, "\x00\xFF\x00\xFF\x00\x3F",
2178 0, MAX_5_BYTE_CHAR, -1, 0, -1, 1, 1, 0);
2fe1edd1
KH
2179 charset_eight_bit
2180 = define_charset_internal (Qeight_bit, 1, "\x80\xFF\x00\x00\x00\x00",
880820fe 2181 128, 255, -1, 0, -1, 0, 1,
2fe1edd1 2182 MAX_5_BYTE_CHAR + 1);
4ed46869
KH
2183}
2184
2185#endif /* emacs */
cefd8c4f
KH
2186
2187/* arch-tag: 66a89b8d-4c28-47d3-9ca1-56f78440d69f
2188 (do not change this comment) */