Mercurial > hg > xemacs-beta
comparison src/mule-coding.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 | cc15677e0335 |
children |
comparison
equal
deleted
inserted
replaced
379:76b7d63099ad | 380:8626e4521993 |
---|---|
73 | 73 |
74 Lisp_Object Qencode, Qdecode; | 74 Lisp_Object Qencode, Qdecode; |
75 | 75 |
76 Lisp_Object Qctext; | 76 Lisp_Object Qctext; |
77 | 77 |
78 Lisp_Object Vcoding_system_hashtable; | 78 Lisp_Object Vcoding_system_hash_table; |
79 | 79 |
80 int enable_multibyte_characters; | 80 int enable_multibyte_characters; |
81 | 81 |
82 /* Additional information used by the ISO2022 decoder and detector. */ | 82 /* Additional information used by the ISO2022 decoder and detector. */ |
83 struct iso2022_decoder | 83 struct iso2022_decoder |
218 static Lisp_Object | 218 static Lisp_Object |
219 mark_coding_system (Lisp_Object obj, void (*markobj) (Lisp_Object)) | 219 mark_coding_system (Lisp_Object obj, void (*markobj) (Lisp_Object)) |
220 { | 220 { |
221 struct Lisp_Coding_System *codesys = XCODING_SYSTEM (obj); | 221 struct Lisp_Coding_System *codesys = XCODING_SYSTEM (obj); |
222 | 222 |
223 (markobj) (CODING_SYSTEM_NAME (codesys)); | 223 markobj (CODING_SYSTEM_NAME (codesys)); |
224 (markobj) (CODING_SYSTEM_DOC_STRING (codesys)); | 224 markobj (CODING_SYSTEM_DOC_STRING (codesys)); |
225 (markobj) (CODING_SYSTEM_MNEMONIC (codesys)); | 225 markobj (CODING_SYSTEM_MNEMONIC (codesys)); |
226 (markobj) (CODING_SYSTEM_EOL_LF (codesys)); | 226 markobj (CODING_SYSTEM_EOL_LF (codesys)); |
227 (markobj) (CODING_SYSTEM_EOL_CRLF (codesys)); | 227 markobj (CODING_SYSTEM_EOL_CRLF (codesys)); |
228 (markobj) (CODING_SYSTEM_EOL_CR (codesys)); | 228 markobj (CODING_SYSTEM_EOL_CR (codesys)); |
229 | 229 |
230 switch (CODING_SYSTEM_TYPE (codesys)) | 230 switch (CODING_SYSTEM_TYPE (codesys)) |
231 { | 231 { |
232 int i; | 232 int i; |
233 case CODESYS_ISO2022: | 233 case CODESYS_ISO2022: |
234 for (i = 0; i < 4; i++) | 234 for (i = 0; i < 4; i++) |
235 (markobj) (CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i)); | 235 markobj (CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i)); |
236 if (codesys->iso2022.input_conv) | 236 if (codesys->iso2022.input_conv) |
237 { | 237 { |
238 for (i = 0; i < Dynarr_length (codesys->iso2022.input_conv); i++) | 238 for (i = 0; i < Dynarr_length (codesys->iso2022.input_conv); i++) |
239 { | 239 { |
240 struct charset_conversion_spec *ccs = | 240 struct charset_conversion_spec *ccs = |
241 Dynarr_atp (codesys->iso2022.input_conv, i); | 241 Dynarr_atp (codesys->iso2022.input_conv, i); |
242 (markobj) (ccs->from_charset); | 242 markobj (ccs->from_charset); |
243 (markobj) (ccs->to_charset); | 243 markobj (ccs->to_charset); |
244 } | 244 } |
245 } | 245 } |
246 if (codesys->iso2022.output_conv) | 246 if (codesys->iso2022.output_conv) |
247 { | 247 { |
248 for (i = 0; i < Dynarr_length (codesys->iso2022.output_conv); i++) | 248 for (i = 0; i < Dynarr_length (codesys->iso2022.output_conv); i++) |
249 { | 249 { |
250 struct charset_conversion_spec *ccs = | 250 struct charset_conversion_spec *ccs = |
251 Dynarr_atp (codesys->iso2022.output_conv, i); | 251 Dynarr_atp (codesys->iso2022.output_conv, i); |
252 (markobj) (ccs->from_charset); | 252 markobj (ccs->from_charset); |
253 (markobj) (ccs->to_charset); | 253 markobj (ccs->to_charset); |
254 } | 254 } |
255 } | 255 } |
256 break; | 256 break; |
257 | 257 |
258 case CODESYS_CCL: | 258 case CODESYS_CCL: |
259 (markobj) (CODING_SYSTEM_CCL_DECODE (codesys)); | 259 markobj (CODING_SYSTEM_CCL_DECODE (codesys)); |
260 (markobj) (CODING_SYSTEM_CCL_ENCODE (codesys)); | 260 markobj (CODING_SYSTEM_CCL_ENCODE (codesys)); |
261 break; | 261 break; |
262 default: | 262 default: |
263 break; | 263 break; |
264 } | 264 } |
265 | 265 |
266 (markobj) (CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys)); | 266 markobj (CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys)); |
267 return CODING_SYSTEM_POST_READ_CONVERSION (codesys); | 267 return CODING_SYSTEM_POST_READ_CONVERSION (codesys); |
268 } | 268 } |
269 | 269 |
270 static void | 270 static void |
271 print_coding_system (Lisp_Object obj, Lisp_Object printcharfun, | 271 print_coding_system (Lisp_Object obj, Lisp_Object printcharfun, |
332 static Lisp_Object | 332 static Lisp_Object |
333 eol_type_to_symbol (enum eol_type type) | 333 eol_type_to_symbol (enum eol_type type) |
334 { | 334 { |
335 switch (type) | 335 switch (type) |
336 { | 336 { |
337 default: abort (); | |
337 case EOL_LF: return Qlf; | 338 case EOL_LF: return Qlf; |
338 case EOL_CRLF: return Qcrlf; | 339 case EOL_CRLF: return Qcrlf; |
339 case EOL_CR: return Qcr; | 340 case EOL_CR: return Qcr; |
340 case EOL_AUTODETECT: return Qnil; | 341 case EOL_AUTODETECT: return Qnil; |
341 default: abort (); return Qnil; /* not reached */ | |
342 } | 342 } |
343 } | 343 } |
344 | 344 |
345 static void | 345 static void |
346 setup_eol_coding_systems (struct Lisp_Coding_System *codesys) | 346 setup_eol_coding_systems (struct Lisp_Coding_System *codesys) |
409 coding_system_or_name = Qbinary; | 409 coding_system_or_name = Qbinary; |
410 if (CODING_SYSTEMP (coding_system_or_name)) | 410 if (CODING_SYSTEMP (coding_system_or_name)) |
411 return coding_system_or_name; | 411 return coding_system_or_name; |
412 CHECK_SYMBOL (coding_system_or_name); | 412 CHECK_SYMBOL (coding_system_or_name); |
413 | 413 |
414 return Fgethash (coding_system_or_name, Vcoding_system_hashtable, Qnil); | 414 return Fgethash (coding_system_or_name, Vcoding_system_hash_table, Qnil); |
415 } | 415 } |
416 | 416 |
417 DEFUN ("get-coding-system", Fget_coding_system, 1, 1, 0, /* | 417 DEFUN ("get-coding-system", Fget_coding_system, 1, 1, 0, /* |
418 Retrieve the coding system of the given name. | 418 Retrieve the coding system of the given name. |
419 Same as `find-coding-system' except that if there is no such | 419 Same as `find-coding-system' except that if there is no such |
463 struct gcpro gcpro1; | 463 struct gcpro gcpro1; |
464 struct coding_system_list_closure coding_system_list_closure; | 464 struct coding_system_list_closure coding_system_list_closure; |
465 | 465 |
466 GCPRO1 (coding_system_list); | 466 GCPRO1 (coding_system_list); |
467 coding_system_list_closure.coding_system_list = &coding_system_list; | 467 coding_system_list_closure.coding_system_list = &coding_system_list; |
468 elisp_maphash (add_coding_system_to_list_mapper, Vcoding_system_hashtable, | 468 elisp_maphash (add_coding_system_to_list_mapper, Vcoding_system_hash_table, |
469 &coding_system_list_closure); | 469 &coding_system_list_closure); |
470 UNGCPRO; | 470 UNGCPRO; |
471 | 471 |
472 return coding_system_list; | 472 return coding_system_list; |
473 } | 473 } |
853 setup_eol_coding_systems (codesys); | 853 setup_eol_coding_systems (codesys); |
854 | 854 |
855 { | 855 { |
856 Lisp_Object codesys_obj; | 856 Lisp_Object codesys_obj; |
857 XSETCODING_SYSTEM (codesys_obj, codesys); | 857 XSETCODING_SYSTEM (codesys_obj, codesys); |
858 Fputhash (name, codesys_obj, Vcoding_system_hashtable); | 858 Fputhash (name, codesys_obj, Vcoding_system_hash_table); |
859 return codesys_obj; | 859 return codesys_obj; |
860 } | 860 } |
861 } | 861 } |
862 | 862 |
863 DEFUN ("copy-coding-system", Fcopy_coding_system, 2, 2, 0, /* | 863 DEFUN ("copy-coding-system", Fcopy_coding_system, 2, 2, 0, /* |
874 { | 874 { |
875 XSETCODING_SYSTEM (new_coding_system, | 875 XSETCODING_SYSTEM (new_coding_system, |
876 allocate_coding_system | 876 allocate_coding_system |
877 (XCODING_SYSTEM_TYPE (old_coding_system), | 877 (XCODING_SYSTEM_TYPE (old_coding_system), |
878 new_name)); | 878 new_name)); |
879 Fputhash (new_name, new_coding_system, Vcoding_system_hashtable); | 879 Fputhash (new_name, new_coding_system, Vcoding_system_hash_table); |
880 } | 880 } |
881 | 881 |
882 { | 882 { |
883 struct Lisp_Coding_System *to = XCODING_SYSTEM (new_coding_system); | 883 struct Lisp_Coding_System *to = XCODING_SYSTEM (new_coding_system); |
884 struct Lisp_Coding_System *from = XCODING_SYSTEM (old_coding_system); | 884 struct Lisp_Coding_System *from = XCODING_SYSTEM (old_coding_system); |
1700 /* We do not need to mark the coding systems or charsets stored | 1700 /* We do not need to mark the coding systems or charsets stored |
1701 within the stream because they are stored in a global list | 1701 within the stream because they are stored in a global list |
1702 and automatically marked. */ | 1702 and automatically marked. */ |
1703 | 1703 |
1704 XSETLSTREAM (str_obj, str); | 1704 XSETLSTREAM (str_obj, str); |
1705 (markobj) (str_obj); | 1705 markobj (str_obj); |
1706 if (str->imp->marker) | 1706 if (str->imp->marker) |
1707 return (str->imp->marker) (str_obj, markobj); | 1707 return (str->imp->marker) (str_obj, markobj); |
1708 else | 1708 else |
1709 return Qnil; | 1709 return Qnil; |
1710 } | 1710 } |
2139 /* We do not need to mark the coding systems or charsets stored | 2139 /* We do not need to mark the coding systems or charsets stored |
2140 within the stream because they are stored in a global list | 2140 within the stream because they are stored in a global list |
2141 and automatically marked. */ | 2141 and automatically marked. */ |
2142 | 2142 |
2143 XSETLSTREAM (str_obj, str); | 2143 XSETLSTREAM (str_obj, str); |
2144 (markobj) (str_obj); | 2144 markobj (str_obj); |
2145 if (str->imp->marker) | 2145 if (str->imp->marker) |
2146 return (str->imp->marker) (str_obj, markobj); | 2146 return (str->imp->marker) (str_obj, markobj); |
2147 else | 2147 else |
2148 return Qnil; | 2148 return Qnil; |
2149 } | 2149 } |
2690 (2nd byte) 0x40 .. 0x7E and 0xA1 .. 0xFE | 2690 (2nd byte) 0x40 .. 0x7E and 0xA1 .. 0xFE |
2691 -------------------------- | 2691 -------------------------- |
2692 | 2692 |
2693 Since the number of characters in Big5 is larger than maximum | 2693 Since the number of characters in Big5 is larger than maximum |
2694 characters in Emacs' charset (96x96), it can't be handled as one | 2694 characters in Emacs' charset (96x96), it can't be handled as one |
2695 charset. So, in Emacs, Big5 is devided into two: `charset-big5-1' | 2695 charset. So, in Emacs, Big5 is divided into two: `charset-big5-1' |
2696 and `charset-big5-2'. Both <type>s are TYPE94x94. The former | 2696 and `charset-big5-2'. Both <type>s are TYPE94x94. The former |
2697 contains frequently used characters and the latter contains less | 2697 contains frequently used characters and the latter contains less |
2698 frequently used characters. */ | 2698 frequently used characters. */ |
2699 | 2699 |
2700 #define BYTE_BIG5_TWO_BYTE_1_P(c) \ | 2700 #define BYTE_BIG5_TWO_BYTE_1_P(c) \ |
4426 static Extbyte_dynarr *conversion_out_dynarr; | 4426 static Extbyte_dynarr *conversion_out_dynarr; |
4427 static Bufbyte_dynarr *conversion_in_dynarr; | 4427 static Bufbyte_dynarr *conversion_in_dynarr; |
4428 | 4428 |
4429 /* Determine coding system from coding format */ | 4429 /* Determine coding system from coding format */ |
4430 | 4430 |
4431 #define FILE_NAME_CODING_SYSTEM \ | |
4432 ((NILP (Vfile_name_coding_system) || \ | |
4433 (EQ ((Vfile_name_coding_system), Qbinary))) ? \ | |
4434 Qnil : Fget_coding_system (Vfile_name_coding_system)) | |
4435 | |
4436 /* #### not correct for all values of `fmt'! */ | 4431 /* #### not correct for all values of `fmt'! */ |
4437 #define FMT_CODING_SYSTEM(fmt) \ | 4432 static Lisp_Object |
4438 (((fmt) == FORMAT_FILENAME) ? FILE_NAME_CODING_SYSTEM : \ | 4433 external_data_format_to_coding_system (enum external_data_format fmt) |
4439 ((fmt) == FORMAT_CTEXT ) ? Fget_coding_system (Qctext) : \ | 4434 { |
4440 ((fmt) == FORMAT_TERMINAL) ? FILE_NAME_CODING_SYSTEM : \ | 4435 switch (fmt) |
4441 Qnil) | 4436 { |
4437 case FORMAT_FILENAME: | |
4438 case FORMAT_TERMINAL: | |
4439 if (EQ (Vfile_name_coding_system, Qnil) || | |
4440 EQ (Vfile_name_coding_system, Qbinary)) | |
4441 return Qnil; | |
4442 else | |
4443 return Fget_coding_system (Vfile_name_coding_system); | |
4444 case FORMAT_CTEXT: | |
4445 return Fget_coding_system (Qctext); | |
4446 default: | |
4447 return Qnil; | |
4448 } | |
4449 } | |
4442 | 4450 |
4443 CONST Extbyte * | 4451 CONST Extbyte * |
4444 convert_to_external_format (CONST Bufbyte *ptr, | 4452 convert_to_external_format (CONST Bufbyte *ptr, |
4445 Bytecount len, | 4453 Bytecount len, |
4446 Extcount *len_out, | 4454 Extcount *len_out, |
4447 enum external_data_format fmt) | 4455 enum external_data_format fmt) |
4448 { | 4456 { |
4449 Lisp_Object coding_system = FMT_CODING_SYSTEM (fmt); | 4457 Lisp_Object coding_system = external_data_format_to_coding_system (fmt); |
4450 | 4458 |
4451 if (!conversion_out_dynarr) | 4459 if (!conversion_out_dynarr) |
4452 conversion_out_dynarr = Dynarr_new (Extbyte); | 4460 conversion_out_dynarr = Dynarr_new (Extbyte); |
4453 else | 4461 else |
4454 Dynarr_reset (conversion_out_dynarr); | 4462 Dynarr_reset (conversion_out_dynarr); |
4512 convert_from_external_format (CONST Extbyte *ptr, | 4520 convert_from_external_format (CONST Extbyte *ptr, |
4513 Extcount len, | 4521 Extcount len, |
4514 Bytecount *len_out, | 4522 Bytecount *len_out, |
4515 enum external_data_format fmt) | 4523 enum external_data_format fmt) |
4516 { | 4524 { |
4517 Lisp_Object coding_system = FMT_CODING_SYSTEM (fmt); | 4525 Lisp_Object coding_system = external_data_format_to_coding_system (fmt); |
4518 | 4526 |
4519 if (!conversion_in_dynarr) | 4527 if (!conversion_in_dynarr) |
4520 conversion_in_dynarr = Dynarr_new (Bufbyte); | 4528 conversion_in_dynarr = Dynarr_new (Bufbyte); |
4521 else | 4529 else |
4522 Dynarr_reset (conversion_in_dynarr); | 4530 Dynarr_reset (conversion_in_dynarr); |
4747 } | 4755 } |
4748 | 4756 |
4749 void | 4757 void |
4750 complex_vars_of_mule_coding (void) | 4758 complex_vars_of_mule_coding (void) |
4751 { | 4759 { |
4752 staticpro (&Vcoding_system_hashtable); | 4760 staticpro (&Vcoding_system_hash_table); |
4753 Vcoding_system_hashtable = make_lisp_hashtable (50, HASHTABLE_NONWEAK, | 4761 Vcoding_system_hash_table = |
4754 HASHTABLE_EQ); | 4762 make_lisp_hash_table (50, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ); |
4755 | 4763 |
4756 the_codesys_prop_dynarr = Dynarr_new (codesys_prop); | 4764 the_codesys_prop_dynarr = Dynarr_new (codesys_prop); |
4757 | 4765 |
4758 #define DEFINE_CODESYS_PROP(Prop_Type, Sym) do \ | 4766 #define DEFINE_CODESYS_PROP(Prop_Type, Sym) do \ |
4759 { \ | 4767 { \ |