aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa2010-09-30 13:28:34 +0900
committerKenichi Handa2010-09-30 13:28:34 +0900
commitfcaf88782ba68e7c0618a663db51cf4a26cb3926 (patch)
tree589ae64ef6f2e2acc260726235d0c98b29150c0a /src
parent9fb7a510c91c6aad04d2d6ba8e8c0889d19e1d79 (diff)
downloademacs-fcaf88782ba68e7c0618a663db51cf4a26cb3926.tar.gz
emacs-fcaf88782ba68e7c0618a663db51cf4a26cb3926.zip
Complement a coding system for encoding arguments and input to a process.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog16
-rw-r--r--src/callproc.c21
-rw-r--r--src/coding.c57
-rw-r--r--src/coding.h1
-rw-r--r--src/process.c36
5 files changed, 108 insertions, 23 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index b756aebe8a5..773715ed1f2 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,19 @@
12010-09-30 Kenichi Handa <handa@m17n.org>
2
3 * coding.c (complement_process_encoding_system): New function.
4
5 * coding.h (complement_process_encoding_system): Extern it.
6
7 * callproc.c (Fcall_process): Complement the coding system for
8 encoding arguments.
9 (Fcall_process_region): Complement the coding system for encoding
10 the input to the process.
11
12 * process.c (Fstart_process): Complement the coding system for
13 encoding arguments.
14 (send_process): Complement the coding system for encoding what
15 sent to the process.
16
12010-09-29 Kenichi Handa <handa@m17n.org> 172010-09-29 Kenichi Handa <handa@m17n.org>
2 18
3 * xfont.c (xfont_open): Fix setting of font->average_width from 19 * xfont.c (xfont_open): Fix setting of font->average_width from
diff --git a/src/callproc.c b/src/callproc.c
index bed3302e508..863d4e41dbd 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -287,21 +287,16 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
287 if (!NILP (Vcoding_system_for_write)) 287 if (!NILP (Vcoding_system_for_write))
288 val = Vcoding_system_for_write; 288 val = Vcoding_system_for_write;
289 else if (! must_encode) 289 else if (! must_encode)
290 val = Qnil; 290 val = Qraw_text;
291 else 291 else
292 { 292 {
293 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2); 293 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
294 args2[0] = Qcall_process; 294 args2[0] = Qcall_process;
295 for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; 295 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
296 coding_systems = Ffind_operation_coding_system (nargs + 1, args2); 296 coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
297 if (CONSP (coding_systems)) 297 val = CONSP (coding_systems) ? XCDR (coding_systems) : Qnil;
298 val = XCDR (coding_systems);
299 else if (CONSP (Vdefault_process_coding_system))
300 val = XCDR (Vdefault_process_coding_system);
301 else
302 val = Qnil;
303 } 298 }
304 val = coding_inherit_eol_type (val, Qnil); 299 val = complement_process_encoding_system (val);
305 setup_coding_system (Fcheck_coding_system (val), &argument_coding); 300 setup_coding_system (Fcheck_coding_system (val), &argument_coding);
306 coding_attrs = CODING_ID_ATTRS (argument_coding.id); 301 coding_attrs = CODING_ID_ATTRS (argument_coding.id);
307 if (NILP (CODING_ATTR_ASCII_COMPAT (coding_attrs))) 302 if (NILP (CODING_ATTR_ASCII_COMPAT (coding_attrs)))
@@ -954,20 +949,16 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
954 if (!NILP (Vcoding_system_for_write)) 949 if (!NILP (Vcoding_system_for_write))
955 val = Vcoding_system_for_write; 950 val = Vcoding_system_for_write;
956 else if (NILP (current_buffer->enable_multibyte_characters)) 951 else if (NILP (current_buffer->enable_multibyte_characters))
957 val = Qnil; 952 val = Qraw_text;
958 else 953 else
959 { 954 {
960 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2); 955 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
961 args2[0] = Qcall_process_region; 956 args2[0] = Qcall_process_region;
962 for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; 957 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
963 coding_systems = Ffind_operation_coding_system (nargs + 1, args2); 958 coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
964 if (CONSP (coding_systems)) 959 val = CONSP (coding_systems) ? XCDR (coding_systems) : Qnil;
965 val = XCDR (coding_systems);
966 else if (CONSP (Vdefault_process_coding_system))
967 val = XCDR (Vdefault_process_coding_system);
968 else
969 val = Qnil;
970 } 960 }
961 val = complement_process_encoding_system (val);
971 962
972 { 963 {
973 int count1 = SPECPDL_INDEX (); 964 int count1 = SPECPDL_INDEX ();
diff --git a/src/coding.c b/src/coding.c
index 92b328091ff..cbebeff6310 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -6112,6 +6112,63 @@ coding_inherit_eol_type (coding_system, parent)
6112 return coding_system; 6112 return coding_system;
6113} 6113}
6114 6114
6115
6116/* Check if text-conversion and eol-conversion of CODING_SYSTEM are
6117 decided for writing to a process. If not, complement them, and
6118 return a new coding system. */
6119
6120Lisp_Object
6121complement_process_encoding_system (coding_system)
6122 Lisp_Object coding_system;
6123{
6124 Lisp_Object spec, attrs, coding_type, eol_type;
6125
6126 if (NILP (coding_system))
6127 coding_system = Qundecided;
6128 spec = CODING_SYSTEM_SPEC (coding_system);
6129 attrs = AREF (spec, 0);
6130 coding_type = CODING_ATTR_TYPE (attrs);
6131 eol_type = AREF (spec, 2);
6132
6133 if (EQ (coding_type, Qundecided))
6134 {
6135 /* We must decide the text-conversion part. */
6136 if (CONSP (Vdefault_process_coding_system))
6137 {
6138 coding_system = XCDR (Vdefault_process_coding_system);
6139 if (! NILP (coding_system))
6140 {
6141 spec = CODING_SYSTEM_SPEC (coding_system);
6142 attrs = AREF (spec, 0);
6143 coding_type = CODING_ATTR_TYPE (attrs);
6144 eol_type = AREF (spec, 2);
6145 }
6146 }
6147 if (EQ (coding_type, Qundecided))
6148 {
6149 coding_system = preferred_coding_system ();
6150 spec = CODING_SYSTEM_SPEC (coding_system);
6151 attrs = AREF (spec, 0);
6152 coding_type = CODING_ATTR_TYPE (attrs);
6153 eol_type = AREF (spec, 2);
6154 }
6155 if (EQ (coding_type, Qundecided))
6156 {
6157 coding_system = Qraw_text;
6158 coding_type = Qraw_text;
6159 eol_type = Qnil;
6160 }
6161 }
6162 if (NILP (eol_type) || VECTORP (eol_type))
6163 {
6164 /* We must decide the eol-conversion part. */
6165 coding_system = coding_inherit_eol_type (coding_system, Qnil);
6166 }
6167
6168 return coding_system;
6169}
6170
6171
6115/* Emacs has a mechanism to automatically detect a coding system if it 6172/* Emacs has a mechanism to automatically detect a coding system if it
6116 is one of Emacs' internal format, ISO2022, SJIS, and BIG5. But, 6173 is one of Emacs' internal format, ISO2022, SJIS, and BIG5. But,
6117 it's impossible to distinguish some coding systems accurately 6174 it's impossible to distinguish some coding systems accurately
diff --git a/src/coding.h b/src/coding.h
index f47c33847f9..58d70644124 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -707,6 +707,7 @@ extern Lisp_Object code_convert_string_norecord P_ ((Lisp_Object, Lisp_Object,
707 int)); 707 int));
708extern Lisp_Object raw_text_coding_system P_ ((Lisp_Object)); 708extern Lisp_Object raw_text_coding_system P_ ((Lisp_Object));
709extern Lisp_Object coding_inherit_eol_type P_ ((Lisp_Object, Lisp_Object)); 709extern Lisp_Object coding_inherit_eol_type P_ ((Lisp_Object, Lisp_Object));
710extern Lisp_Object complement_process_encoding_system P_ ((Lisp_Object));
710 711
711extern int decode_coding_gap P_ ((struct coding_system *, 712extern int decode_coding_gap P_ ((struct coding_system *,
712 EMACS_INT, EMACS_INT)); 713 EMACS_INT, EMACS_INT));
diff --git a/src/process.c b/src/process.c
index 7adc114075e..3e2aa61ffe6 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1727,6 +1727,11 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1727 val = XCDR (Vdefault_process_coding_system); 1727 val = XCDR (Vdefault_process_coding_system);
1728 } 1728 }
1729 XPROCESS (proc)->encode_coding_system = val; 1729 XPROCESS (proc)->encode_coding_system = val;
1730 /* Note: At this momemnt, the above coding system may leave
1731 text-conversion or eol-conversion unspecified. They will be
1732 decided after we read output from the process and decode it by
1733 some coding system, or just before we actually send a text to
1734 the process. */
1730 } 1735 }
1731 1736
1732 1737
@@ -1769,6 +1774,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1769 tem = Fsubstring (tem, make_number (2), Qnil); 1774 tem = Fsubstring (tem, make_number (2), Qnil);
1770 1775
1771 { 1776 {
1777 Lisp_Object arg_encoding = Qnil;
1772 struct gcpro gcpro1; 1778 struct gcpro gcpro1;
1773 GCPRO1 (tem); 1779 GCPRO1 (tem);
1774 1780
@@ -1786,9 +1792,14 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1786 tem = Fcons (args[i], tem); 1792 tem = Fcons (args[i], tem);
1787 CHECK_STRING (XCAR (tem)); 1793 CHECK_STRING (XCAR (tem));
1788 if (STRING_MULTIBYTE (XCAR (tem))) 1794 if (STRING_MULTIBYTE (XCAR (tem)))
1789 XSETCAR (tem, 1795 {
1790 code_convert_string_norecord 1796 if (NILP (arg_encoding))
1791 (XCAR (tem), XPROCESS (proc)->encode_coding_system, 1)); 1797 arg_encoding = (complement_process_encoding_system
1798 (XPROCESS (proc)->encode_coding_system));
1799 XSETCAR (tem,
1800 code_convert_string_norecord
1801 (XCAR (tem), arg_encoding, 1));
1802 }
1792 } 1803 }
1793 1804
1794 UNGCPRO; 1805 UNGCPRO;
@@ -5690,12 +5701,21 @@ send_process (proc, buf, len, object)
5690 && !NILP (XBUFFER (object)->enable_multibyte_characters)) 5701 && !NILP (XBUFFER (object)->enable_multibyte_characters))
5691 || EQ (object, Qt)) 5702 || EQ (object, Qt))
5692 { 5703 {
5704 p->encode_coding_system
5705 = complement_process_encoding_system (p->encode_coding_system);
5693 if (!EQ (Vlast_coding_system_used, p->encode_coding_system)) 5706 if (!EQ (Vlast_coding_system_used, p->encode_coding_system))
5694 /* The coding system for encoding was changed to raw-text 5707 {
5695 because we sent a unibyte text previously. Now we are 5708 /* The coding system for encoding was changed to raw-text
5696 sending a multibyte text, thus we must encode it by the 5709 because we sent a unibyte text previously. Now we are
5697 original coding system specified for the current process. */ 5710 sending a multibyte text, thus we must encode it by the
5698 setup_coding_system (p->encode_coding_system, coding); 5711 original coding system specified for the current process.
5712
5713 Another reason we comming here is that the coding system
5714 was just complemented and new one was returned by
5715 complement_process_encoding_system. */
5716 setup_coding_system (p->encode_coding_system, coding);
5717 Vlast_coding_system_used = p->encode_coding_system;
5718 }
5699 coding->src_multibyte = 1; 5719 coding->src_multibyte = 1;
5700 } 5720 }
5701 else 5721 else