changeset 110831:74ecb389545a

Complement a coding system for encoding arguments and input to a process.
author Kenichi Handa <handa@m17n.org>
date Thu, 30 Sep 2010 21:48:25 +0900
parents 2ceb09ee5949 (current diff) 4665df4accaa (diff)
children 0eedefa853ee
files
diffstat 5 files changed, 108 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Sep 29 21:41:13 2010 -0400
+++ b/src/ChangeLog	Thu Sep 30 21:48:25 2010 +0900
@@ -1,3 +1,19 @@
+2010-09-30  Kenichi Handa  <handa@m17n.org>
+
+	* coding.c (complement_process_encoding_system): New function.
+
+	* coding.h (complement_process_encoding_system): Extern it.
+
+	* callproc.c (Fcall_process): Complement the coding system for
+	encoding arguments.
+	(Fcall_process_region): Complement the coding system for encoding
+	the input to the process.
+
+	* process.c (Fstart_process): Complement the coding system for
+	encoding arguments.
+	(send_process): Complement the coding system for encoding what
+	sent to the process.
+
 2010-09-29  Kenichi Handa  <handa@m17n.org>
 
 	* xfont.c (xfont_open): Fix setting of font->average_width from
--- a/src/callproc.c	Wed Sep 29 21:41:13 2010 -0400
+++ b/src/callproc.c	Thu Sep 30 21:48:25 2010 +0900
@@ -287,21 +287,16 @@
 	if (!NILP (Vcoding_system_for_write))
 	  val = Vcoding_system_for_write;
 	else if (! must_encode)
-	  val = Qnil;
+	  val = Qraw_text;
 	else
 	  {
 	    args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
 	    args2[0] = Qcall_process;
 	    for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
 	    coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
-	    if (CONSP (coding_systems))
-	      val = XCDR (coding_systems);
-	    else if (CONSP (Vdefault_process_coding_system))
-	      val = XCDR (Vdefault_process_coding_system);
-	    else
-	      val = Qnil;
+	    val = CONSP (coding_systems) ? XCDR (coding_systems) : Qnil;
 	  }
-	val = coding_inherit_eol_type (val, Qnil);
+	val = complement_process_encoding_system (val);
 	setup_coding_system (Fcheck_coding_system (val), &argument_coding);
 	coding_attrs = CODING_ID_ATTRS (argument_coding.id);
 	if (NILP (CODING_ATTR_ASCII_COMPAT (coding_attrs)))
@@ -954,20 +949,16 @@
   if (!NILP (Vcoding_system_for_write))
     val = Vcoding_system_for_write;
   else if (NILP (current_buffer->enable_multibyte_characters))
-    val = Qnil;
+    val = Qraw_text;
   else
     {
       args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
       args2[0] = Qcall_process_region;
       for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
       coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
-      if (CONSP (coding_systems))
-	val = XCDR (coding_systems);
-      else if (CONSP (Vdefault_process_coding_system))
-	val = XCDR (Vdefault_process_coding_system);
-      else
-	val = Qnil;
+      val = CONSP (coding_systems) ? XCDR (coding_systems) : Qnil;
     }
+  val = complement_process_encoding_system (val);
 
   {
     int count1 = SPECPDL_INDEX ();
--- a/src/coding.c	Wed Sep 29 21:41:13 2010 -0400
+++ b/src/coding.c	Thu Sep 30 21:48:25 2010 +0900
@@ -6112,6 +6112,63 @@
   return coding_system;
 }
 
+
+/* Check if text-conversion and eol-conversion of CODING_SYSTEM are
+   decided for writing to a process.  If not, complement them, and
+   return a new coding system.  */
+
+Lisp_Object
+complement_process_encoding_system (coding_system)
+     Lisp_Object coding_system;
+{
+  Lisp_Object spec, attrs, coding_type, eol_type;
+
+  if (NILP (coding_system))
+    coding_system = Qundecided;
+  spec = CODING_SYSTEM_SPEC (coding_system);
+  attrs = AREF (spec, 0);
+  coding_type = CODING_ATTR_TYPE (attrs);
+  eol_type = AREF (spec, 2);
+
+  if (EQ (coding_type, Qundecided))
+    {
+      /* We must decide the text-conversion part.  */
+      if (CONSP (Vdefault_process_coding_system))
+	{
+	  coding_system = XCDR (Vdefault_process_coding_system);
+	  if (! NILP (coding_system))
+	    {
+	      spec = CODING_SYSTEM_SPEC (coding_system);
+	      attrs = AREF (spec, 0);
+	      coding_type = CODING_ATTR_TYPE (attrs);
+	      eol_type = AREF (spec, 2);
+	    }
+	}
+      if (EQ (coding_type, Qundecided))
+	{
+	  coding_system = preferred_coding_system ();
+	  spec = CODING_SYSTEM_SPEC (coding_system);
+	  attrs = AREF (spec, 0);
+	  coding_type = CODING_ATTR_TYPE (attrs);
+	  eol_type = AREF (spec, 2);
+	}
+      if (EQ (coding_type, Qundecided))
+	{
+	  coding_system = Qraw_text;
+	  coding_type = Qraw_text;
+	  eol_type = Qnil;
+	}
+    }
+  if (NILP (eol_type) || VECTORP (eol_type))
+    {
+      /* We must decide the eol-conversion part.  */      
+      coding_system = coding_inherit_eol_type (coding_system, Qnil);
+    }
+
+  return coding_system;
+}
+
+
 /* Emacs has a mechanism to automatically detect a coding system if it
    is one of Emacs' internal format, ISO2022, SJIS, and BIG5.  But,
    it's impossible to distinguish some coding systems accurately
--- a/src/coding.h	Wed Sep 29 21:41:13 2010 -0400
+++ b/src/coding.h	Thu Sep 30 21:48:25 2010 +0900
@@ -707,6 +707,7 @@
 						     int));
 extern Lisp_Object raw_text_coding_system P_ ((Lisp_Object));
 extern Lisp_Object coding_inherit_eol_type P_ ((Lisp_Object, Lisp_Object));
+extern Lisp_Object complement_process_encoding_system P_ ((Lisp_Object));
 
 extern int decode_coding_gap P_ ((struct coding_system *,
 				  EMACS_INT, EMACS_INT));
--- a/src/process.c	Wed Sep 29 21:41:13 2010 -0400
+++ b/src/process.c	Thu Sep 30 21:48:25 2010 +0900
@@ -1727,6 +1727,11 @@
 	  val = XCDR (Vdefault_process_coding_system);
       }
     XPROCESS (proc)->encode_coding_system = val;
+    /* Note: At this momemnt, the above coding system may leave
+       text-conversion or eol-conversion unspecified.  They will be
+       decided after we read output from the process and decode it by
+       some coding system, or just before we actually send a text to
+       the process.  */
   }
 
 
@@ -1769,6 +1774,7 @@
 	tem = Fsubstring (tem, make_number (2), Qnil);
 
       {
+	Lisp_Object arg_encoding = Qnil;
 	struct gcpro gcpro1;
 	GCPRO1 (tem);
 
@@ -1786,9 +1792,14 @@
 	    tem = Fcons (args[i], tem);
 	    CHECK_STRING (XCAR (tem));
 	    if (STRING_MULTIBYTE (XCAR (tem)))
-	      XSETCAR (tem,
-		       code_convert_string_norecord
-		       (XCAR (tem), XPROCESS (proc)->encode_coding_system, 1));
+	      {
+		if (NILP (arg_encoding))
+		  arg_encoding = (complement_process_encoding_system
+				  (XPROCESS (proc)->encode_coding_system));
+		XSETCAR (tem,
+			 code_convert_string_norecord
+			 (XCAR (tem), arg_encoding, 1));
+	      }
 	  }
 
 	UNGCPRO;
@@ -5690,12 +5701,21 @@
 	  && !NILP (XBUFFER (object)->enable_multibyte_characters))
       || EQ (object, Qt))
     {
+      p->encode_coding_system
+	= complement_process_encoding_system (p->encode_coding_system);
       if (!EQ (Vlast_coding_system_used, p->encode_coding_system))
-	/* The coding system for encoding was changed to raw-text
-	   because we sent a unibyte text previously.  Now we are
-	   sending a multibyte text, thus we must encode it by the
-	   original coding system specified for the current process.  */
-	setup_coding_system (p->encode_coding_system, coding);
+	{
+	  /* The coding system for encoding was changed to raw-text
+	     because we sent a unibyte text previously.  Now we are
+	     sending a multibyte text, thus we must encode it by the
+	     original coding system specified for the current process.
+
+	     Another reason we comming here is that the coding system
+	     was just complemented and new one was returned by
+	     complement_process_encoding_system.  */
+	  setup_coding_system (p->encode_coding_system, coding);
+	  Vlast_coding_system_used = p->encode_coding_system;
+	}
       coding->src_multibyte = 1;
     }
   else