emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/emacs-23 r100073: Complement a coding syste


From: Kenichi Handa
Subject: [Emacs-diffs] /srv/bzr/emacs/emacs-23 r100073: Complement a coding system for encoding arguments and input to a process.
Date: Thu, 30 Sep 2010 21:48:25 +0900
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 100073 [merge]
committer: Kenichi Handa <address@hidden>
branch nick: emacs-23
timestamp: Thu 2010-09-30 21:48:25 +0900
message:
  Complement a coding system for encoding arguments and input to a process.
modified:
  src/ChangeLog
  src/callproc.c
  src/coding.c
  src/coding.h
  src/process.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2010-09-29 00:55:58 +0000
+++ b/src/ChangeLog     2010-09-30 04:28:34 +0000
@@ -1,3 +1,19 @@
+2010-09-30  Kenichi Handa  <address@hidden>
+
+       * 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  <address@hidden>
 
        * xfont.c (xfont_open): Fix setting of font->average_width from

=== modified file 'src/callproc.c'
--- a/src/callproc.c    2010-01-13 08:35:10 +0000
+++ b/src/callproc.c    2010-09-30 04:28:34 +0000
@@ -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 ();

=== modified file 'src/coding.c'
--- a/src/coding.c      2010-09-08 02:21:03 +0000
+++ b/src/coding.c      2010-09-30 04:28:34 +0000
@@ -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

=== modified file 'src/coding.h'
--- a/src/coding.h      2010-01-13 08:35:10 +0000
+++ b/src/coding.h      2010-09-30 04:28:34 +0000
@@ -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));

=== modified file 'src/process.c'
--- a/src/process.c     2010-06-03 22:47:35 +0000
+++ b/src/process.c     2010-09-30 04:28:34 +0000
@@ -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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]