Mercurial > emacs
comparison src/charset.c @ 88874:82c5e4f67e4a
(charset_ordered_list_tick): New variable.
(Fdefine_charset_internal): Increment charset_ordered_list_tick.
(Funify_charset): New optional arg DEUNIFY. If it is non-nil,
deunify intead of unify a charset.
(string_xstring_p): Add `const' to local variables.
(find_charsets_in_text): Add `const' to arguemnts and local
variables.
(encode_char): Adjusted for the change of Funify_charset. Fix
detecting of invalid code.
(Fset_charset_priority): Increment charset_ordered_list_tick.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 22 Jul 2002 06:35:00 +0000 |
parents | 23c58f02c558 |
children | 7702a9d9edff |
comparison
equal
deleted
inserted
replaced
88873:7d441bc35e9b | 88874:82c5e4f67e4a |
---|---|
104 /* The primary charset. It is a charset of unibyte characters. */ | 104 /* The primary charset. It is a charset of unibyte characters. */ |
105 int charset_primary; | 105 int charset_primary; |
106 | 106 |
107 /* List of charsets ordered by the priority. */ | 107 /* List of charsets ordered by the priority. */ |
108 Lisp_Object Vcharset_ordered_list; | 108 Lisp_Object Vcharset_ordered_list; |
109 | |
110 /* Incremented everytime we change Vcharset_ordered_list. This is | |
111 unsigned short so that it fits in Lisp_Int and never match with | |
112 -1. */ | |
113 unsigned short charset_ordered_list_tick; | |
109 | 114 |
110 /* List of iso-2022 charsets. */ | 115 /* List of iso-2022 charsets. */ |
111 Lisp_Object Viso_2022_charset_list; | 116 Lisp_Object Viso_2022_charset_list; |
112 | 117 |
113 /* List of emacs-mule charsets. */ | 118 /* List of emacs-mule charsets. */ |
1053 if (new_definition_p) | 1058 if (new_definition_p) |
1054 { | 1059 { |
1055 Vcharset_list = Fcons (args[charset_arg_name], Vcharset_list); | 1060 Vcharset_list = Fcons (args[charset_arg_name], Vcharset_list); |
1056 Vcharset_ordered_list = nconc2 (Vcharset_ordered_list, | 1061 Vcharset_ordered_list = nconc2 (Vcharset_ordered_list, |
1057 Fcons (make_number (id), Qnil)); | 1062 Fcons (make_number (id), Qnil)); |
1063 charset_ordered_list_tick++; | |
1058 } | 1064 } |
1059 | 1065 |
1060 return Qnil; | 1066 return Qnil; |
1061 } | 1067 } |
1062 | 1068 |
1122 CHARSET_ATTR_PLIST (attrs) = plist; | 1128 CHARSET_ATTR_PLIST (attrs) = plist; |
1123 return plist; | 1129 return plist; |
1124 } | 1130 } |
1125 | 1131 |
1126 | 1132 |
1127 DEFUN ("unify-charset", Funify_charset, Sunify_charset, 1, 2, 0, | 1133 DEFUN ("unify-charset", Funify_charset, Sunify_charset, 1, 3, 0, |
1128 doc: /* Unify characters of CHARSET with Unicode. | 1134 doc: /* Unify characters of CHARSET with Unicode. |
1129 This means reading the relevant file and installing the table defined | 1135 This means reading the relevant file and installing the table defined |
1130 by CHARSET's `:unify-map' property. */) | 1136 by CHARSET's `:unify-map' property. |
1131 (charset, unify_map) | 1137 |
1132 Lisp_Object charset, unify_map; | 1138 Optional second arg UNIFY-MAP a file name string or vector that has |
1139 the same meaning of the `:unify-map' attribute of the function | |
1140 `define-charset' (which see). | |
1141 | |
1142 Optional third argument DEUNIFY, if non-nil, means to de-unify CHARSET. */) | |
1143 (charset, unify_map, deunify) | |
1144 Lisp_Object charset, unify_map, deunify; | |
1133 { | 1145 { |
1134 int id; | 1146 int id; |
1135 struct charset *cs; | 1147 struct charset *cs; |
1136 | 1148 |
1137 CHECK_CHARSET_GET_ID (charset, id); | 1149 CHECK_CHARSET_GET_ID (charset, id); |
1138 cs = CHARSET_FROM_ID (id); | 1150 cs = CHARSET_FROM_ID (id); |
1139 if (CHARSET_METHOD (cs) == CHARSET_METHOD_MAP_DEFERRED) | 1151 if (CHARSET_METHOD (cs) == CHARSET_METHOD_MAP_DEFERRED) |
1140 load_charset (cs); | 1152 load_charset (cs); |
1141 if (CHARSET_UNIFIED_P (cs) | 1153 if (NILP (deunify) |
1142 && CHAR_TABLE_P (CHARSET_DEUNIFIER (cs))) | 1154 ? CHARSET_UNIFIED_P (cs) && ! NILP (CHARSET_DEUNIFIER (cs)) |
1155 : ! CHARSET_UNIFIED_P (cs)) | |
1143 return Qnil; | 1156 return Qnil; |
1157 | |
1144 CHARSET_UNIFIED_P (cs) = 0; | 1158 CHARSET_UNIFIED_P (cs) = 0; |
1145 if (NILP (unify_map)) | 1159 if (NILP (deunify)) |
1146 unify_map = CHARSET_UNIFY_MAP (cs); | 1160 { |
1147 if (STRINGP (unify_map)) | 1161 if (CHARSET_METHOD (cs) != CHARSET_METHOD_OFFSET) |
1148 load_charset_map_from_file (cs, unify_map, 2); | 1162 error ("Can't unify charset: %s", XSYMBOL (charset)->name->data); |
1149 else if (VECTORP (unify_map)) | 1163 if (NILP (unify_map)) |
1150 load_charset_map_from_vector (cs, unify_map, 2); | 1164 unify_map = CHARSET_UNIFY_MAP (cs); |
1151 else if (NILP (unify_map)) | 1165 if (STRINGP (unify_map)) |
1152 error ("No unify-map for charset"); | 1166 load_charset_map_from_file (cs, unify_map, 2); |
1153 else | 1167 else if (VECTORP (unify_map)) |
1154 error ("Bad unify-map arg"); | 1168 load_charset_map_from_vector (cs, unify_map, 2); |
1155 CHARSET_UNIFIED_P (cs) = 1; | 1169 else if (NILP (unify_map)) |
1170 error ("No unify-map for charset"); | |
1171 else | |
1172 error ("Bad unify-map arg"); | |
1173 CHARSET_UNIFIED_P (cs) = 1; | |
1174 } | |
1175 else if (CHAR_TABLE_P (Vchar_unify_table)) | |
1176 { | |
1177 int min_code = CHARSET_MIN_CODE (cs); | |
1178 int max_code = CHARSET_MAX_CODE (cs); | |
1179 int min_char = DECODE_CHAR (cs, min_code); | |
1180 int max_char = DECODE_CHAR (cs, max_code); | |
1181 | |
1182 char_table_set_range (Vchar_unify_table, min_char, max_char, Qnil); | |
1183 } | |
1184 | |
1156 return Qnil; | 1185 return Qnil; |
1157 } | 1186 } |
1158 | 1187 |
1159 DEFUN ("get-unused-iso-final-char", Fget_unused_iso_final_char, | 1188 DEFUN ("get-unused-iso-final-char", Fget_unused_iso_final_char, |
1160 Sget_unused_iso_final_char, 2, 2, 0, | 1189 Sget_unused_iso_final_char, 2, 2, 0, |
1233 | 1262 |
1234 int | 1263 int |
1235 string_xstring_p (string) | 1264 string_xstring_p (string) |
1236 Lisp_Object string; | 1265 Lisp_Object string; |
1237 { | 1266 { |
1238 unsigned char *p = XSTRING (string)->data; | 1267 const unsigned char *p = XSTRING (string)->data; |
1239 unsigned char *endp = p + STRING_BYTES (XSTRING (string)); | 1268 const unsigned char *endp = p + STRING_BYTES (XSTRING (string)); |
1240 struct charset *charset; | 1269 struct charset *charset; |
1241 | 1270 |
1242 if (XSTRING (string)->size == STRING_BYTES (XSTRING (string))) | 1271 if (XSTRING (string)->size == STRING_BYTES (XSTRING (string))) |
1243 return 0; | 1272 return 0; |
1244 | 1273 |
1263 | 1292 |
1264 It may lookup a translation table TABLE if supplied. */ | 1293 It may lookup a translation table TABLE if supplied. */ |
1265 | 1294 |
1266 static void | 1295 static void |
1267 find_charsets_in_text (ptr, nchars, nbytes, charsets, table) | 1296 find_charsets_in_text (ptr, nchars, nbytes, charsets, table) |
1268 unsigned char *ptr; | 1297 const unsigned char *ptr; |
1269 int nchars, nbytes; | 1298 int nchars, nbytes; |
1270 Lisp_Object charsets, table; | 1299 Lisp_Object charsets, table; |
1271 { | 1300 { |
1272 unsigned char *pend = ptr + nbytes; | 1301 const unsigned char *pend = ptr + nbytes; |
1273 int ncharsets = ASIZE (charsets); | 1302 int ncharsets = ASIZE (charsets); |
1274 | 1303 |
1275 if (nchars == nbytes) | 1304 if (nchars == nbytes) |
1276 return; | 1305 return; |
1277 | 1306 |
1488 Lisp_Object deunifier, deunified; | 1517 Lisp_Object deunifier, deunified; |
1489 | 1518 |
1490 deunifier = CHARSET_DEUNIFIER (charset); | 1519 deunifier = CHARSET_DEUNIFIER (charset); |
1491 if (! CHAR_TABLE_P (deunifier)) | 1520 if (! CHAR_TABLE_P (deunifier)) |
1492 { | 1521 { |
1493 Funify_charset (CHARSET_NAME (charset), Qnil); | 1522 Funify_charset (CHARSET_NAME (charset), Qnil, Qnil); |
1494 deunifier = CHARSET_DEUNIFIER (charset); | 1523 deunifier = CHARSET_DEUNIFIER (charset); |
1495 } | 1524 } |
1496 deunified = CHAR_TABLE_REF (deunifier, c); | 1525 deunified = CHAR_TABLE_REF (deunifier, c); |
1497 if (! NILP (deunified)) | 1526 if (! NILP (deunified)) |
1498 c = XINT (deunified); | 1527 c = XINT (deunified); |
1528 int id = XINT (XCAR (XCAR (parents))); | 1557 int id = XINT (XCAR (XCAR (parents))); |
1529 int code_offset = XINT (XCDR (XCAR (parents))); | 1558 int code_offset = XINT (XCDR (XCAR (parents))); |
1530 struct charset *this_charset = CHARSET_FROM_ID (id); | 1559 struct charset *this_charset = CHARSET_FROM_ID (id); |
1531 | 1560 |
1532 code = ENCODE_CHAR (this_charset, c); | 1561 code = ENCODE_CHAR (this_charset, c); |
1533 if (code != CHARSET_INVALID_CODE (this_charset) | 1562 if (code != CHARSET_INVALID_CODE (this_charset)) |
1534 && (code_offset < 0 || code >= code_offset)) | 1563 return code + code_offset; |
1535 { | |
1536 code += code_offset; | |
1537 if (code >= charset->min_code && code <= charset->max_code | |
1538 && CODE_POINT_TO_INDEX (charset, code) >= 0) | |
1539 return code; | |
1540 } | |
1541 } | 1564 } |
1542 return CHARSET_INVALID_CODE (charset); | 1565 return CHARSET_INVALID_CODE (charset); |
1543 } | 1566 } |
1544 | 1567 |
1545 if (method == CHARSET_METHOD_MAP_DEFERRED) | 1568 if (method == CHARSET_METHOD_MAP_DEFERRED) |
1902 new_head = Fcons (make_number (id), new_head); | 1925 new_head = Fcons (make_number (id), new_head); |
1903 } | 1926 } |
1904 arglist[0] = Fnreverse (new_head); | 1927 arglist[0] = Fnreverse (new_head); |
1905 arglist[1] = old_list; | 1928 arglist[1] = old_list; |
1906 Vcharset_ordered_list = Fnconc (2, arglist); | 1929 Vcharset_ordered_list = Fnconc (2, arglist); |
1930 charset_ordered_list_tick++; | |
1907 return Qnil; | 1931 return Qnil; |
1908 } | 1932 } |
1909 | 1933 |
1910 void | 1934 void |
1911 init_charset () | 1935 init_charset () |