Mercurial > emacs
comparison src/coding.c @ 20105:c017642863c2
(Qcoding_system_spec): Deleted.
(Vcoding_system_list, Vcoding_system_alist): New variables.
(setup_coding_system): Adjusted for the change in mule.el.
(detect_eol): Likewise.
(Fcoding_system_spec): Changed to Lisp function in mule.el.
(Fcoding_system_p): Do not call Fcoding_system_spec.
(Fread_coding_system): Give Vcoding_system_alist to
Fcompleting_read as the arg TABLE.
(Fread_non_nil_coding_system): Likewise. Give
Vcoding_system_history to Fcompleting_read as the arg HIST.
(syms_of_coding): Deleted codes for Qcoding_system and
Fcoding_system_spec. Set up new Lisp variables.
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Tue, 21 Oct 1997 10:43:40 +0000 |
| parents | ea89a2408bfa |
| children | 402b6e5f4b58 |
comparison
equal
deleted
inserted
replaced
| 20104:6128508b0c31 | 20105:c017642863c2 |
|---|---|
| 67 (all uppercase), we mean the coding system, and when we write | 67 (all uppercase), we mean the coding system, and when we write |
| 68 "Big5" (capitalized), we mean the character set. | 68 "Big5" (capitalized), we mean the character set. |
| 69 | 69 |
| 70 4. Raw text | 70 4. Raw text |
| 71 | 71 |
| 72 A coding system to for a text containing random 8-bit code. Emacs | 72 A coding system for a text containing random 8-bit code. Emacs does |
| 73 does no code conversion on such a text except for end-of-line | 73 no code conversion on such a text except for end-of-line format. |
| 74 format. | |
| 75 | 74 |
| 76 5. Other | 75 5. Other |
| 77 | 76 |
| 78 If a user wants to read/write a text encoded in a coding system not | 77 If a user wants to read/write a text encoded in a coding system not |
| 79 listed above, he can supply a decoder and an encoder for it in CCL | 78 listed above, he can supply a decoder and an encoder for it in CCL |
| 270 Unix, CODING_EOL_CRLF on DOS/Windows, and CODING_EOL_CR on Mac. */ | 269 Unix, CODING_EOL_CRLF on DOS/Windows, and CODING_EOL_CR on Mac. */ |
| 271 int system_eol_type; | 270 int system_eol_type; |
| 272 | 271 |
| 273 #ifdef emacs | 272 #ifdef emacs |
| 274 | 273 |
| 275 Lisp_Object Qcoding_system_spec, Qcoding_system_p, Qcoding_system_error; | 274 Lisp_Object Vcoding_system_list, Vcoding_system_alist; |
| 275 | |
| 276 Lisp_Object Qcoding_system_p, Qcoding_system_error; | |
| 276 | 277 |
| 277 /* Coding system emacs-mule is for converting only end-of-line format. */ | 278 /* Coding system emacs-mule is for converting only end-of-line format. */ |
| 278 Lisp_Object Qemacs_mule; | 279 Lisp_Object Qemacs_mule; |
| 279 | 280 |
| 280 /* Coding-systems are handed between Emacs Lisp programs and C internal | 281 /* Coding-systems are handed between Emacs Lisp programs and C internal |
| 2297 int | 2298 int |
| 2298 setup_coding_system (coding_system, coding) | 2299 setup_coding_system (coding_system, coding) |
| 2299 Lisp_Object coding_system; | 2300 Lisp_Object coding_system; |
| 2300 struct coding_system *coding; | 2301 struct coding_system *coding; |
| 2301 { | 2302 { |
| 2302 Lisp_Object type, eol_type; | 2303 Lisp_Object coding_spec, plist, type, eol_type; |
| 2304 Lisp_Object val; | |
| 2303 | 2305 |
| 2304 /* At first, set several fields to default values. */ | 2306 /* At first, set several fields to default values. */ |
| 2305 coding->require_flushing = 0; | 2307 coding->require_flushing = 0; |
| 2306 coding->last_block = 0; | 2308 coding->last_block = 0; |
| 2307 coding->selective = 0; | 2309 coding->selective = 0; |
| 2312 coding->character_unification_table_for_decode = Qnil; | 2314 coding->character_unification_table_for_decode = Qnil; |
| 2313 coding->character_unification_table_for_encode = Qnil; | 2315 coding->character_unification_table_for_encode = Qnil; |
| 2314 | 2316 |
| 2315 Vlast_coding_system_used = coding->symbol = coding_system; | 2317 Vlast_coding_system_used = coding->symbol = coding_system; |
| 2316 eol_type = Qnil; | 2318 eol_type = Qnil; |
| 2317 /* Get value of property `coding-system' until we get a vector. | 2319 |
| 2318 While doing that, also get values of properties | 2320 /* Get values of property `coding-system' and `eol-type'. |
| 2321 Also get values of coding system properties: | |
| 2319 `post-read-conversion', `pre-write-conversion', | 2322 `post-read-conversion', `pre-write-conversion', |
| 2320 `character-unification-table-for-decode', | 2323 `character-unification-table-for-decode', |
| 2321 `character-unification-table-for-encode' and `eol-type'. */ | 2324 `character-unification-table-for-encode'. */ |
| 2322 while (!NILP (coding_system) && SYMBOLP (coding_system)) | 2325 coding_spec = Fget (coding_system, Qcoding_system); |
| 2323 { | 2326 if (!VECTORP (coding_spec) |
| 2324 if (NILP (coding->post_read_conversion)) | 2327 || XVECTOR (coding_spec)->size != 5 |
| 2325 coding->post_read_conversion = Fget (coding_system, | 2328 || !CONSP (XVECTOR (coding_spec)->contents[3])) |
| 2326 Qpost_read_conversion); | |
| 2327 if (NILP (coding->pre_write_conversion)) | |
| 2328 coding->pre_write_conversion = Fget (coding_system, | |
| 2329 Qpre_write_conversion); | |
| 2330 if (!inhibit_eol_conversion && NILP (eol_type)) | |
| 2331 eol_type = Fget (coding_system, Qeol_type); | |
| 2332 | |
| 2333 if (NILP (coding->character_unification_table_for_decode)) | |
| 2334 coding->character_unification_table_for_decode | |
| 2335 = Fget (coding_system, Qcharacter_unification_table_for_decode); | |
| 2336 | |
| 2337 if (NILP (coding->character_unification_table_for_encode)) | |
| 2338 coding->character_unification_table_for_encode | |
| 2339 = Fget (coding_system, Qcharacter_unification_table_for_encode); | |
| 2340 | |
| 2341 coding_system = Fget (coding_system, Qcoding_system); | |
| 2342 } | |
| 2343 | |
| 2344 while (!NILP (coding->character_unification_table_for_decode) | |
| 2345 && SYMBOLP (coding->character_unification_table_for_decode)) | |
| 2346 coding->character_unification_table_for_decode | |
| 2347 = Fget (coding->character_unification_table_for_decode, | |
| 2348 Qcharacter_unification_table_for_decode); | |
| 2349 if (!NILP (coding->character_unification_table_for_decode) | |
| 2350 && !CHAR_TABLE_P (coding->character_unification_table_for_decode)) | |
| 2351 coding->character_unification_table_for_decode = Qnil; | |
| 2352 | |
| 2353 while (!NILP (coding->character_unification_table_for_encode) | |
| 2354 && SYMBOLP (coding->character_unification_table_for_encode)) | |
| 2355 coding->character_unification_table_for_encode | |
| 2356 = Fget (coding->character_unification_table_for_encode, | |
| 2357 Qcharacter_unification_table_for_encode); | |
| 2358 if (!NILP (coding->character_unification_table_for_encode) | |
| 2359 && !CHAR_TABLE_P (coding->character_unification_table_for_encode)) | |
| 2360 coding->character_unification_table_for_encode = Qnil; | |
| 2361 | |
| 2362 if (!VECTORP (coding_system) | |
| 2363 || XVECTOR (coding_system)->size != 5) | |
| 2364 goto label_invalid_coding_system; | 2329 goto label_invalid_coding_system; |
| 2365 | 2330 if (!inhibit_eol_conversion) |
| 2331 eol_type = Fget (coding_system, Qeol_type); | |
| 2332 | |
| 2333 plist = XVECTOR (coding_spec)->contents[3]; | |
| 2334 coding->post_read_conversion = Fplist_get (plist, Qpost_read_conversion); | |
| 2335 coding->pre_write_conversion = Fplist_get (plist, Qpre_write_conversion); | |
| 2336 val = Fplist_get (plist, Qcharacter_unification_table_for_decode); | |
| 2337 if (SYMBOLP (val)) | |
| 2338 val = Fget (val, Qcharacter_unification_table_for_decode); | |
| 2339 coding->character_unification_table_for_decode | |
| 2340 = CHAR_TABLE_P (val) ? val : Qnil; | |
| 2341 val = Fplist_get (plist, Qcharacter_unification_table_for_encode); | |
| 2342 if (SYMBOLP (val)) | |
| 2343 val = Fget (val, Qcharacter_unification_table_for_encode); | |
| 2344 coding->character_unification_table_for_encode | |
| 2345 = CHAR_TABLE_P (val) ? val : Qnil; | |
| 2346 | |
| 2366 if (VECTORP (eol_type)) | 2347 if (VECTORP (eol_type)) |
| 2367 coding->eol_type = CODING_EOL_UNDECIDED; | 2348 coding->eol_type = CODING_EOL_UNDECIDED; |
| 2368 else if (XFASTINT (eol_type) == 1) | 2349 else if (XFASTINT (eol_type) == 1) |
| 2369 coding->eol_type = CODING_EOL_CRLF; | 2350 coding->eol_type = CODING_EOL_CRLF; |
| 2370 else if (XFASTINT (eol_type) == 2) | 2351 else if (XFASTINT (eol_type) == 2) |
| 2371 coding->eol_type = CODING_EOL_CR; | 2352 coding->eol_type = CODING_EOL_CR; |
| 2372 else | 2353 else |
| 2373 coding->eol_type = CODING_EOL_LF; | 2354 coding->eol_type = CODING_EOL_LF; |
| 2374 | 2355 |
| 2375 type = XVECTOR (coding_system)->contents[0]; | 2356 type = XVECTOR (coding_spec)->contents[0]; |
| 2376 switch (XFASTINT (type)) | 2357 switch (XFASTINT (type)) |
| 2377 { | 2358 { |
| 2378 case 0: | 2359 case 0: |
| 2379 coding->type = coding_type_emacs_mule; | 2360 coding->type = coding_type_emacs_mule; |
| 2380 break; | 2361 break; |
| 2388 { | 2369 { |
| 2389 Lisp_Object val; | 2370 Lisp_Object val; |
| 2390 Lisp_Object *flags; | 2371 Lisp_Object *flags; |
| 2391 int i, charset, default_reg_bits = 0; | 2372 int i, charset, default_reg_bits = 0; |
| 2392 | 2373 |
| 2393 val = XVECTOR (coding_system)->contents[4]; | 2374 val = XVECTOR (coding_spec)->contents[4]; |
| 2394 | 2375 |
| 2395 if (!VECTORP (val) || XVECTOR (val)->size != 32) | 2376 if (!VECTORP (val) || XVECTOR (val)->size != 32) |
| 2396 goto label_invalid_coding_system; | 2377 goto label_invalid_coding_system; |
| 2397 | 2378 |
| 2398 flags = XVECTOR (val)->contents; | 2379 flags = XVECTOR (val)->contents; |
| 2534 break; | 2515 break; |
| 2535 | 2516 |
| 2536 case 3: | 2517 case 3: |
| 2537 coding->type = coding_type_big5; | 2518 coding->type = coding_type_big5; |
| 2538 coding->flags | 2519 coding->flags |
| 2539 = (NILP (XVECTOR (coding_system)->contents[4]) | 2520 = (NILP (XVECTOR (coding_spec)->contents[4]) |
| 2540 ? CODING_FLAG_BIG5_HKU | 2521 ? CODING_FLAG_BIG5_HKU |
| 2541 : CODING_FLAG_BIG5_ETEN); | 2522 : CODING_FLAG_BIG5_ETEN); |
| 2542 break; | 2523 break; |
| 2543 | 2524 |
| 2544 case 4: | 2525 case 4: |
| 2545 coding->type = coding_type_ccl; | 2526 coding->type = coding_type_ccl; |
| 2546 { | 2527 { |
| 2547 Lisp_Object val = XVECTOR (coding_system)->contents[4]; | 2528 Lisp_Object val = XVECTOR (coding_spec)->contents[4]; |
| 2548 if (CONSP (val) | 2529 if (CONSP (val) |
| 2549 && VECTORP (XCONS (val)->car) | 2530 && VECTORP (XCONS (val)->car) |
| 2550 && VECTORP (XCONS (val)->cdr)) | 2531 && VECTORP (XCONS (val)->cdr)) |
| 2551 { | 2532 { |
| 2552 setup_ccl_program (&(coding->spec.ccl.decoder), XCONS (val)->car); | 2533 setup_ccl_program (&(coding->spec.ccl.decoder), XCONS (val)->car); |
| 2831 detect_eol (coding, src, src_bytes) | 2812 detect_eol (coding, src, src_bytes) |
| 2832 struct coding_system *coding; | 2813 struct coding_system *coding; |
| 2833 unsigned char *src; | 2814 unsigned char *src; |
| 2834 int src_bytes; | 2815 int src_bytes; |
| 2835 { | 2816 { |
| 2836 Lisp_Object val, coding_system; | 2817 Lisp_Object val; |
| 2837 int eol_type = detect_eol_type (src, src_bytes); | 2818 int eol_type = detect_eol_type (src, src_bytes); |
| 2838 | 2819 |
| 2839 if (eol_type == CODING_EOL_UNDECIDED) | 2820 if (eol_type == CODING_EOL_UNDECIDED) |
| 2840 /* We found no end-of-line in the source text. */ | 2821 /* We found no end-of-line in the source text. */ |
| 2841 return; | 2822 return; |
| 2856 /* Else, let's decode only text code anyway. */ | 2837 /* Else, let's decode only text code anyway. */ |
| 2857 #endif /* 0 */ | 2838 #endif /* 0 */ |
| 2858 eol_type = CODING_EOL_LF; | 2839 eol_type = CODING_EOL_LF; |
| 2859 } | 2840 } |
| 2860 | 2841 |
| 2861 coding_system = coding->symbol; | 2842 val = Fget (coding->symbol, Qeol_type); |
| 2862 while (!NILP (coding_system) | |
| 2863 && NILP (val = Fget (coding_system, Qeol_type))) | |
| 2864 coding_system = Fget (coding_system, Qcoding_system); | |
| 2865 if (VECTORP (val) && XVECTOR (val)->size == 3) | 2843 if (VECTORP (val) && XVECTOR (val)->size == 3) |
| 2866 setup_coding_system (XVECTOR (val)->contents[eol_type], coding); | 2844 setup_coding_system (XVECTOR (val)->contents[eol_type], coding); |
| 2867 } | 2845 } |
| 2868 | 2846 |
| 2869 /* See "GENERAL NOTES about `decode_coding_XXX ()' functions". Before | 2847 /* See "GENERAL NOTES about `decode_coding_XXX ()' functions". Before |
| 3073 | 3051 |
| 3074 | 3052 |
| 3075 #ifdef emacs | 3053 #ifdef emacs |
| 3076 /*** 7. Emacs Lisp library functions ***/ | 3054 /*** 7. Emacs Lisp library functions ***/ |
| 3077 | 3055 |
| 3078 DEFUN ("coding-system-spec", Fcoding_system_spec, Scoding_system_spec, | |
| 3079 1, 1, 0, | |
| 3080 "Return coding-spec of CODING-SYSTEM.\n\ | |
| 3081 If CODING-SYSTEM is not a valid coding-system, return nil.") | |
| 3082 (obj) | |
| 3083 Lisp_Object obj; | |
| 3084 { | |
| 3085 while (SYMBOLP (obj) && !NILP (obj)) | |
| 3086 obj = Fget (obj, Qcoding_system); | |
| 3087 return ((NILP (obj) || !VECTORP (obj) || XVECTOR (obj)->size != 5) | |
| 3088 ? Qnil : obj); | |
| 3089 } | |
| 3090 | |
| 3091 DEFUN ("coding-system-p", Fcoding_system_p, Scoding_system_p, 1, 1, 0, | 3056 DEFUN ("coding-system-p", Fcoding_system_p, Scoding_system_p, 1, 1, 0, |
| 3092 "Return t if OBJECT is nil or a coding-system.\n\ | 3057 "Return t if OBJECT is nil or a coding-system.\n\ |
| 3093 See document of make-coding-system for coding-system object.") | 3058 See document of make-coding-system for coding-system object.") |
| 3094 (obj) | 3059 (obj) |
| 3095 Lisp_Object obj; | 3060 Lisp_Object obj; |
| 3096 { | 3061 { |
| 3097 return ((NILP (obj) || !NILP (Fcoding_system_spec (obj))) ? Qt : Qnil); | 3062 if (NILP (obj)) |
| 3063 return Qt; | |
| 3064 if (!SYMBOLP (obj)) | |
| 3065 return Qnil; | |
| 3066 /* Get coding-spec vector for OBJ. */ | |
| 3067 obj = Fget (obj, Qcoding_system); | |
| 3068 return ((VECTORP (obj) && XVECTOR (obj)->size == 5) | |
| 3069 ? Qt : Qnil); | |
| 3098 } | 3070 } |
| 3099 | 3071 |
| 3100 DEFUN ("read-non-nil-coding-system", Fread_non_nil_coding_system, | 3072 DEFUN ("read-non-nil-coding-system", Fread_non_nil_coding_system, |
| 3101 Sread_non_nil_coding_system, 1, 1, 0, | 3073 Sread_non_nil_coding_system, 1, 1, 0, |
| 3102 "Read a coding system from the minibuffer, prompting with string PROMPT.") | 3074 "Read a coding system from the minibuffer, prompting with string PROMPT.") |
| 3104 Lisp_Object prompt; | 3076 Lisp_Object prompt; |
| 3105 { | 3077 { |
| 3106 Lisp_Object val; | 3078 Lisp_Object val; |
| 3107 do | 3079 do |
| 3108 { | 3080 { |
| 3109 val = Fcompleting_read (prompt, Vobarray, Qcoding_system_spec, | 3081 val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil, |
| 3110 Qt, Qnil, Qnil, Qnil, Qnil); | 3082 Qt, Qnil, Qcoding_system_history, Qnil, Qnil); |
| 3111 } | 3083 } |
| 3112 while (XSTRING (val)->size == 0); | 3084 while (XSTRING (val)->size == 0); |
| 3113 return (Fintern (val, Qnil)); | 3085 return (Fintern (val, Qnil)); |
| 3114 } | 3086 } |
| 3115 | 3087 |
| 3120 Lisp_Object prompt, default_coding_system; | 3092 Lisp_Object prompt, default_coding_system; |
| 3121 { | 3093 { |
| 3122 Lisp_Object val; | 3094 Lisp_Object val; |
| 3123 if (SYMBOLP (default_coding_system)) | 3095 if (SYMBOLP (default_coding_system)) |
| 3124 XSETSTRING (default_coding_system, XSYMBOL (default_coding_system)->name); | 3096 XSETSTRING (default_coding_system, XSYMBOL (default_coding_system)->name); |
| 3125 val = Fcompleting_read (prompt, Vobarray, Qcoding_system_p, | 3097 val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil, |
| 3126 Qt, Qnil, Qcoding_system_history, | 3098 Qt, Qnil, Qcoding_system_history, |
| 3127 default_coding_system, Qnil); | 3099 default_coding_system, Qnil); |
| 3128 return (XSTRING (val)->size == 0 ? Qnil : Fintern (val, Qnil)); | 3100 return (XSTRING (val)->size == 0 ? Qnil : Fintern (val, Qnil)); |
| 3129 } | 3101 } |
| 3130 | 3102 |
| 3925 staticpro (&Qno_conversion); | 3897 staticpro (&Qno_conversion); |
| 3926 | 3898 |
| 3927 Qundecided = intern ("undecided"); | 3899 Qundecided = intern ("undecided"); |
| 3928 staticpro (&Qundecided); | 3900 staticpro (&Qundecided); |
| 3929 | 3901 |
| 3930 Qcoding_system_spec = intern ("coding-system-spec"); | |
| 3931 staticpro (&Qcoding_system_spec); | |
| 3932 | |
| 3933 Qcoding_system_p = intern ("coding-system-p"); | 3902 Qcoding_system_p = intern ("coding-system-p"); |
| 3934 staticpro (&Qcoding_system_p); | 3903 staticpro (&Qcoding_system_p); |
| 3935 | 3904 |
| 3936 Qcoding_system_error = intern ("coding-system-error"); | 3905 Qcoding_system_error = intern ("coding-system-error"); |
| 3937 staticpro (&Qcoding_system_error); | 3906 staticpro (&Qcoding_system_error); |
| 3969 staticpro (&Qcharacter_unification_table_for_encode); | 3938 staticpro (&Qcharacter_unification_table_for_encode); |
| 3970 | 3939 |
| 3971 Qemacs_mule = intern ("emacs-mule"); | 3940 Qemacs_mule = intern ("emacs-mule"); |
| 3972 staticpro (&Qemacs_mule); | 3941 staticpro (&Qemacs_mule); |
| 3973 | 3942 |
| 3974 defsubr (&Scoding_system_spec); | |
| 3975 defsubr (&Scoding_system_p); | 3943 defsubr (&Scoding_system_p); |
| 3976 defsubr (&Sread_coding_system); | 3944 defsubr (&Sread_coding_system); |
| 3977 defsubr (&Sread_non_nil_coding_system); | 3945 defsubr (&Sread_non_nil_coding_system); |
| 3978 defsubr (&Scheck_coding_system); | 3946 defsubr (&Scheck_coding_system); |
| 3979 defsubr (&Sdetect_coding_region); | 3947 defsubr (&Sdetect_coding_region); |
| 3990 defsubr (&Sterminal_coding_system); | 3958 defsubr (&Sterminal_coding_system); |
| 3991 defsubr (&Sset_keyboard_coding_system_internal); | 3959 defsubr (&Sset_keyboard_coding_system_internal); |
| 3992 defsubr (&Skeyboard_coding_system); | 3960 defsubr (&Skeyboard_coding_system); |
| 3993 defsubr (&Sfind_operation_coding_system); | 3961 defsubr (&Sfind_operation_coding_system); |
| 3994 | 3962 |
| 3963 DEFVAR_LISP ("coding-system-list", &Vcoding_system_list, | |
| 3964 "List of coding systems.\n\ | |
| 3965 \n\ | |
| 3966 Do not alter the value of this variable manually. This variable should be\n\ | |
| 3967 updated by the functions `make-coding-system' and\n\ | |
| 3968 `define-coding-system-alias'."); | |
| 3969 Vcoding_system_list = Qnil; | |
| 3970 | |
| 3971 DEFVAR_LISP ("coding-system-alist", &Vcoding_system_alist, | |
| 3972 "Alist of coding system names.\n\ | |
| 3973 Each element is one element list of coding system name.\n\ | |
| 3974 This variable is given to `completing-read' as TABLE argument.\n\ | |
| 3975 \n\ | |
| 3976 Do not alter the value of this variable manually. This variable should be\n\ | |
| 3977 updated by the functions `make-coding-system' and\n\ | |
| 3978 `define-coding-system-alias'."); | |
| 3979 Vcoding_system_alist = Qnil; | |
| 3980 | |
| 3995 DEFVAR_LISP ("coding-category-list", &Vcoding_category_list, | 3981 DEFVAR_LISP ("coding-category-list", &Vcoding_category_list, |
| 3996 "List of coding-categories (symbols) ordered by priority."); | 3982 "List of coding-categories (symbols) ordered by priority."); |
| 3997 { | 3983 { |
| 3998 int i; | 3984 int i; |
| 3999 | 3985 |
