aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c148
1 files changed, 67 insertions, 81 deletions
diff --git a/src/coding.c b/src/coding.c
index e22581b2c03..12891aec6e9 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -69,9 +69,8 @@ Boston, MA 02111-1307, USA. */
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
@@ -272,7 +271,9 @@ int system_eol_type;
272 271
273#ifdef emacs 272#ifdef emacs
274 273
275Lisp_Object Qcoding_system_spec, Qcoding_system_p, Qcoding_system_error; 274Lisp_Object Vcoding_system_list, Vcoding_system_alist;
275
276Lisp_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. */
278Lisp_Object Qemacs_mule; 279Lisp_Object Qemacs_mule;
@@ -2299,7 +2300,8 @@ 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;
@@ -2314,55 +2316,34 @@ setup_coding_system (coding_system, coding)
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)
@@ -2372,7 +2353,7 @@ setup_coding_system (coding_system, coding)
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:
@@ -2390,7 +2371,7 @@ setup_coding_system (coding_system, coding)
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;
@@ -2536,7 +2517,7 @@ setup_coding_system (coding_system, coding)
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;
@@ -2544,7 +2525,7 @@ setup_coding_system (coding_system, coding)
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))
@@ -2833,7 +2814,7 @@ detect_eol (coding, src, src_bytes)
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)
@@ -2858,10 +2839,7 @@ detect_eol (coding, src, src_bytes)
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}
@@ -3075,26 +3053,20 @@ get_conversion_buffer (size)
3075#ifdef emacs 3053#ifdef emacs
3076/*** 7. Emacs Lisp library functions ***/ 3054/*** 7. Emacs Lisp library functions ***/
3077 3055
3078DEFUN ("coding-system-spec", Fcoding_system_spec, Scoding_system_spec,
3079 1, 1, 0,
3080 "Return coding-spec of CODING-SYSTEM.\n\
3081If 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
3091DEFUN ("coding-system-p", Fcoding_system_p, Scoding_system_p, 1, 1, 0, 3056DEFUN ("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\
3093See document of make-coding-system for coding-system object.") 3058See 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
3100DEFUN ("read-non-nil-coding-system", Fread_non_nil_coding_system, 3072DEFUN ("read-non-nil-coding-system", Fread_non_nil_coding_system,
@@ -3106,8 +3078,8 @@ DEFUN ("read-non-nil-coding-system", Fread_non_nil_coding_system,
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));
@@ -3122,7 +3094,7 @@ If the user enters null input, return second argument DEFAULT-CODING-SYSTEM.")
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));
@@ -3927,9 +3899,6 @@ syms_of_coding ()
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
@@ -3971,7 +3940,6 @@ syms_of_coding ()
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);
@@ -3992,6 +3960,24 @@ syms_of_coding ()
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\
3966Do not alter the value of this variable manually. This variable should be\n\
3967updated 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\
3973Each element is one element list of coding system name.\n\
3974This variable is given to `completing-read' as TABLE argument.\n\
3975\n\
3976Do not alter the value of this variable manually. This variable should be\n\
3977updated 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 {