comparison src/mule-charset.c @ 380:8626e4521993 r21-2-5

Import from CVS: tag r21-2-5
author cvs
date Mon, 13 Aug 2007 11:07:10 +0200
parents d883f39b8495
children 1f50e6fe4f3f
comparison
equal deleted inserted replaced
379:76b7d63099ad 380:8626e4521993
58 Lisp_Object Vcharset_chinese_cns11643_1; 58 Lisp_Object Vcharset_chinese_cns11643_1;
59 Lisp_Object Vcharset_chinese_cns11643_2; 59 Lisp_Object Vcharset_chinese_cns11643_2;
60 Lisp_Object Vcharset_korean_ksc5601; 60 Lisp_Object Vcharset_korean_ksc5601;
61 Lisp_Object Vcharset_composite; 61 Lisp_Object Vcharset_composite;
62 62
63 /* Hashtables for composite chars. One maps string representing 63 /* Hash tables for composite chars. One maps string representing
64 composed chars to their equivalent chars; one goes the 64 composed chars to their equivalent chars; one goes the
65 other way. */ 65 other way. */
66 Lisp_Object Vcomposite_char_char2string_hashtable; 66 Lisp_Object Vcomposite_char_char2string_hash_table;
67 Lisp_Object Vcomposite_char_string2char_hashtable; 67 Lisp_Object Vcomposite_char_string2char_hash_table;
68 68
69 /* Table of charsets indexed by leading byte. */ 69 /* Table of charsets indexed by leading byte. */
70 Lisp_Object charset_by_leading_byte[128]; 70 Lisp_Object charset_by_leading_byte[128];
71 71
72 /* Table of charsets indexed by type/final-byte/direction. */ 72 /* Table of charsets indexed by type/final-byte/direction. */
134 134
135 Qkorean_ksc5601, Qcomposite; 135 Qkorean_ksc5601, Qcomposite;
136 136
137 Lisp_Object Ql2r, Qr2l; 137 Lisp_Object Ql2r, Qr2l;
138 138
139 Lisp_Object Vcharset_hashtable; 139 Lisp_Object Vcharset_hash_table;
140 140
141 static Bufbyte next_allocated_1_byte_leading_byte; 141 static Bufbyte next_allocated_1_byte_leading_byte;
142 static Bufbyte next_allocated_2_byte_leading_byte; 142 static Bufbyte next_allocated_2_byte_leading_byte;
143 143
144 /* Composite characters are characters constructed by overstriking two 144 /* Composite characters are characters constructed by overstriking two
278 return 0; 278 return 0;
279 279
280 if (f1 + FIELD1_TO_OFFICIAL_LEADING_BYTE == LEADING_BYTE_COMPOSITE) 280 if (f1 + FIELD1_TO_OFFICIAL_LEADING_BYTE == LEADING_BYTE_COMPOSITE)
281 { 281 {
282 if (UNBOUNDP (Fgethash (make_int (ch), 282 if (UNBOUNDP (Fgethash (make_int (ch),
283 Vcomposite_char_char2string_hashtable, 283 Vcomposite_char_char2string_hash_table,
284 Qunbound))) 284 Qunbound)))
285 return 0; 285 return 0;
286 return 1; 286 return 1;
287 } 287 }
288 288
389 static Lisp_Object 389 static Lisp_Object
390 mark_charset (Lisp_Object obj, void (*markobj) (Lisp_Object)) 390 mark_charset (Lisp_Object obj, void (*markobj) (Lisp_Object))
391 { 391 {
392 struct Lisp_Charset *cs = XCHARSET (obj); 392 struct Lisp_Charset *cs = XCHARSET (obj);
393 393
394 (markobj) (cs->doc_string); 394 markobj (cs->doc_string);
395 (markobj) (cs->registry); 395 markobj (cs->registry);
396 (markobj) (cs->ccl_program); 396 markobj (cs->ccl_program);
397 return cs->name; 397 return cs->name;
398 } 398 }
399 399
400 static void 400 static void
401 print_charset (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) 401 print_charset (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
459 459
460 CHARSET_DIMENSION (cs) = (CHARSET_TYPE (cs) == CHARSET_TYPE_94 || 460 CHARSET_DIMENSION (cs) = (CHARSET_TYPE (cs) == CHARSET_TYPE_94 ||
461 CHARSET_TYPE (cs) == CHARSET_TYPE_96) ? 1 : 2; 461 CHARSET_TYPE (cs) == CHARSET_TYPE_96) ? 1 : 2;
462 CHARSET_CHARS (cs) = (CHARSET_TYPE (cs) == CHARSET_TYPE_94 || 462 CHARSET_CHARS (cs) = (CHARSET_TYPE (cs) == CHARSET_TYPE_94 ||
463 CHARSET_TYPE (cs) == CHARSET_TYPE_94X94) ? 94 : 96; 463 CHARSET_TYPE (cs) == CHARSET_TYPE_94X94) ? 94 : 96;
464 464
465 if (final) 465 if (final)
466 { 466 {
467 /* some charsets do not have final characters. This includes 467 /* some charsets do not have final characters. This includes
468 ASCII, Control-1, Composite, and the two faux private 468 ASCII, Control-1, Composite, and the two faux private
469 charsets. */ 469 charsets. */
478 rep_bytes_by_first_byte[leading_byte] = rep_bytes; 478 rep_bytes_by_first_byte[leading_byte] = rep_bytes;
479 479
480 /* Some charsets are "faux" and don't have names or really exist at 480 /* Some charsets are "faux" and don't have names or really exist at
481 all except in the leading-byte table. */ 481 all except in the leading-byte table. */
482 if (!NILP (name)) 482 if (!NILP (name))
483 Fputhash (name, obj, Vcharset_hashtable); 483 Fputhash (name, obj, Vcharset_hash_table);
484 return obj; 484 return obj;
485 } 485 }
486 486
487 static int 487 static int
488 get_unallocated_leading_byte (int dimension) 488 get_unallocated_leading_byte (int dimension)
535 { 535 {
536 if (CHARSETP (charset_or_name)) 536 if (CHARSETP (charset_or_name))
537 return charset_or_name; 537 return charset_or_name;
538 538
539 CHECK_SYMBOL (charset_or_name); 539 CHECK_SYMBOL (charset_or_name);
540 return Fgethash (charset_or_name, Vcharset_hashtable, Qnil); 540 return Fgethash (charset_or_name, Vcharset_hash_table, Qnil);
541 } 541 }
542 542
543 DEFUN ("get-charset", Fget_charset, 1, 1, 0, /* 543 DEFUN ("get-charset", Fget_charset, 1, 1, 0, /*
544 Retrieve the charset of the given name. 544 Retrieve the charset of the given name.
545 Same as `find-charset' except an error is signalled if there is no such 545 Same as `find-charset' except an error is signalled if there is no such
561 { 561 {
562 Lisp_Object *charset_list; 562 Lisp_Object *charset_list;
563 }; 563 };
564 564
565 static int 565 static int
566 add_charset_to_list_mapper (CONST void *hash_key, void *hash_contents, 566 add_charset_to_list_mapper (Lisp_Object key, Lisp_Object value,
567 void *charset_list_closure) 567 void *charset_list_closure)
568 { 568 {
569 /* This function can GC */ 569 /* This function can GC */
570 Lisp_Object key, contents;
571 Lisp_Object *charset_list;
572 struct charset_list_closure *chcl = 570 struct charset_list_closure *chcl =
573 (struct charset_list_closure*) charset_list_closure; 571 (struct charset_list_closure*) charset_list_closure;
574 CVOID_TO_LISP (key, hash_key); 572 Lisp_Object *charset_list = chcl->charset_list;
575 VOID_TO_LISP (contents, hash_contents); 573
576 charset_list = chcl->charset_list; 574 *charset_list = Fcons (XCHARSET_NAME (value), *charset_list);
577
578 *charset_list = Fcons (XCHARSET_NAME (contents), *charset_list);
579 return 0; 575 return 0;
580 } 576 }
581 577
582 DEFUN ("charset-list", Fcharset_list, 0, 0, 0, /* 578 DEFUN ("charset-list", Fcharset_list, 0, 0, 0, /*
583 Return a list of the names of all defined charsets. 579 Return a list of the names of all defined charsets.
588 struct gcpro gcpro1; 584 struct gcpro gcpro1;
589 struct charset_list_closure charset_list_closure; 585 struct charset_list_closure charset_list_closure;
590 586
591 GCPRO1 (charset_list); 587 GCPRO1 (charset_list);
592 charset_list_closure.charset_list = &charset_list; 588 charset_list_closure.charset_list = &charset_list;
593 elisp_maphash (add_charset_to_list_mapper, Vcharset_hashtable, 589 elisp_maphash (add_charset_to_list_mapper, Vcharset_hash_table,
594 &charset_list_closure); 590 &charset_list_closure);
595 UNGCPRO; 591 UNGCPRO;
596 592
597 return charset_list; 593 return charset_list;
598 } 594 }
964 960
965 static void 961 static void
966 invalidate_charset_font_caches (Lisp_Object charset) 962 invalidate_charset_font_caches (Lisp_Object charset)
967 { 963 {
968 /* Invalidate font cache entries for charset on all devices. */ 964 /* Invalidate font cache entries for charset on all devices. */
969 Lisp_Object devcons, concons, hashtab; 965 Lisp_Object devcons, concons, hash_table;
970 DEVICE_LOOP_NO_BREAK (devcons, concons) 966 DEVICE_LOOP_NO_BREAK (devcons, concons)
971 { 967 {
972 struct device *d = XDEVICE (XCAR (devcons)); 968 struct device *d = XDEVICE (XCAR (devcons));
973 hashtab = Fgethash (charset, d->charset_font_cache, Qunbound); 969 hash_table = Fgethash (charset, d->charset_font_cache, Qunbound);
974 if (!UNBOUNDP (hashtab)) 970 if (!UNBOUNDP (hash_table))
975 Fclrhash (hashtab); 971 Fclrhash (hash_table);
976 } 972 }
977 } 973 }
978 974
979 /* Japanese folks may want to (set-charset-registry 'ascii "jisx0201") */ 975 /* Japanese folks may want to (set-charset-registry 'ascii "jisx0201") */
980 DEFUN ("set-charset-registry", Fset_charset_registry, 2, 2, 0, /* 976 DEFUN ("set-charset-registry", Fset_charset_registry, 2, 2, 0, /*
1075 Emchar 1071 Emchar
1076 lookup_composite_char (Bufbyte *str, int len) 1072 lookup_composite_char (Bufbyte *str, int len)
1077 { 1073 {
1078 Lisp_Object lispstr = make_string (str, len); 1074 Lisp_Object lispstr = make_string (str, len);
1079 Lisp_Object ch = Fgethash (lispstr, 1075 Lisp_Object ch = Fgethash (lispstr,
1080 Vcomposite_char_string2char_hashtable, 1076 Vcomposite_char_string2char_hash_table,
1081 Qunbound); 1077 Qunbound);
1082 Emchar emch; 1078 Emchar emch;
1083 1079
1084 if (UNBOUNDP (ch)) 1080 if (UNBOUNDP (ch))
1085 { 1081 {
1086 if (composite_char_row_next >= 128) 1082 if (composite_char_row_next >= 128)
1087 signal_simple_error ("No more composite chars available", lispstr); 1083 signal_simple_error ("No more composite chars available", lispstr);
1088 emch = MAKE_CHAR (Vcharset_composite, composite_char_row_next, 1084 emch = MAKE_CHAR (Vcharset_composite, composite_char_row_next,
1089 composite_char_col_next); 1085 composite_char_col_next);
1090 Fputhash (make_char (emch), lispstr, 1086 Fputhash (make_char (emch), lispstr,
1091 Vcomposite_char_char2string_hashtable); 1087 Vcomposite_char_char2string_hash_table);
1092 Fputhash (lispstr, make_char (emch), 1088 Fputhash (lispstr, make_char (emch),
1093 Vcomposite_char_string2char_hashtable); 1089 Vcomposite_char_string2char_hash_table);
1094 composite_char_col_next++; 1090 composite_char_col_next++;
1095 if (composite_char_col_next >= 128) 1091 if (composite_char_col_next >= 128)
1096 { 1092 {
1097 composite_char_col_next = 32; 1093 composite_char_col_next = 32;
1098 composite_char_row_next++; 1094 composite_char_row_next++;
1105 1101
1106 Lisp_Object 1102 Lisp_Object
1107 composite_char_string (Emchar ch) 1103 composite_char_string (Emchar ch)
1108 { 1104 {
1109 Lisp_Object str = Fgethash (make_char (ch), 1105 Lisp_Object str = Fgethash (make_char (ch),
1110 Vcomposite_char_char2string_hashtable, 1106 Vcomposite_char_char2string_hash_table,
1111 Qunbound); 1107 Qunbound);
1112 assert (!UNBOUNDP (str)); 1108 assert (!UNBOUNDP (str));
1113 return str; 1109 return str;
1114 } 1110 }
1115 1111
1232 } 1228 }
1233 1229
1234 void 1230 void
1235 complex_vars_of_mule_charset (void) 1231 complex_vars_of_mule_charset (void)
1236 { 1232 {
1237 staticpro (&Vcharset_hashtable); 1233 staticpro (&Vcharset_hash_table);
1238 Vcharset_hashtable = make_lisp_hashtable (50, HASHTABLE_NONWEAK, 1234 Vcharset_hash_table =
1239 HASHTABLE_EQ); 1235 make_lisp_hash_table (50, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
1240 1236
1241 /* Predefined character sets. We store them into variables for 1237 /* Predefined character sets. We store them into variables for
1242 ease of access. */ 1238 ease of access. */
1243 1239
1244 Vcharset_ascii = 1240 Vcharset_ascii =
1408 build_string ("")); 1404 build_string (""));
1409 1405
1410 composite_char_row_next = 32; 1406 composite_char_row_next = 32;
1411 composite_char_col_next = 32; 1407 composite_char_col_next = 32;
1412 1408
1413 Vcomposite_char_string2char_hashtable = 1409 Vcomposite_char_string2char_hash_table =
1414 make_lisp_hashtable (500, HASHTABLE_NONWEAK, HASHTABLE_EQUAL); 1410 make_lisp_hash_table (500, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL);
1415 Vcomposite_char_char2string_hashtable = 1411 Vcomposite_char_char2string_hash_table =
1416 make_lisp_hashtable (500, HASHTABLE_NONWEAK, HASHTABLE_EQ); 1412 make_lisp_hash_table (500, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
1417 staticpro (&Vcomposite_char_string2char_hashtable); 1413 staticpro (&Vcomposite_char_string2char_hash_table);
1418 staticpro (&Vcomposite_char_char2string_hashtable); 1414 staticpro (&Vcomposite_char_char2string_hash_table);
1419 1415
1420 } 1416 }