changeset 49667:cbec1327e2f1

(QCfilter_multibyte): New variable. (setup_process_coding_systems): New function. (Fset_process_buffer, Fset_process_filter): Call setup_process_coding_systems. (Fstart_process): Initialize the member `filter_multibyte' of struct Lisp_Process. (create_process): Call setup_process_coding_systems. (Fmake_network_process): New keyward `:filter-multibyte'. Initialize the member `filter_multibyte' of struct Lisp_Process. Call setup_process_coding_systems. (server_accept_connection): Call setup_process_coding_systems. (read_process_output): If the process has a filter, decide the multibyteness of a string to given to the filter by `filter_multibyte' member of the process. If the process doesn't have a filter and the result of conversion is unibyte, use Fstring_to_multibyte (not Fstring_make_multibyte) to get the multibyte form. (Fset_process_coding_system): Call setup_process_coding_systems. (Fset_process_filter_multibyte): New function. (Fprocess_filter_multibyte_p): New function. (syms_of_process): Intern and staticpro QCfilter_multibyte. Defsubr Sset_process_filter_multibyte and Sprocess_filter_multibyte_p.
author Kenichi Handa <handa@m17n.org>
date Mon, 10 Feb 2003 07:58:29 +0000
parents 9f435c19ea6f
children f118fc83f5a5
files src/process.c
diffstat 1 files changed, 102 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/src/process.c	Mon Feb 10 07:45:13 2003 +0000
+++ b/src/process.c	Mon Feb 10 07:58:29 2003 +0000
@@ -137,6 +137,7 @@
 /* QCfamily is declared and initialized in xfaces.c,
    QCfilter in keyboard.c.  */
 extern Lisp_Object QCfamily, QCfilter;
+Lisp_Object QCfilter_multibyte;
 
 /* Qexit is declared and initialized in eval.c.  */
 
@@ -586,6 +587,39 @@
 
   deactivate_process (proc);
 }
+
+/* Setup coding systems of PROCESS.  */
+
+void
+setup_process_coding_systems (process)
+     Lisp_Object process;
+{
+  struct Lisp_Process *p = XPROCESS (process);
+  int inch = XINT (p->infd);
+  int outch = XINT (p->outfd);
+
+  if (!proc_decode_coding_system[inch])
+    proc_decode_coding_system[inch]
+      = (struct coding_system *) xmalloc (sizeof (struct coding_system));
+  setup_coding_system (p->decode_coding_system,
+		       proc_decode_coding_system[inch]);
+  if (! NILP (p->filter))
+    {
+      if (NILP (p->filter_multibyte))
+	setup_raw_text_coding_system (proc_decode_coding_system[inch]);
+    }
+  else if (BUFFERP (p->buffer))
+    {
+      if (NILP (XBUFFER (p->buffer)->enable_multibyte_characters))
+	setup_raw_text_coding_system (proc_decode_coding_system[inch]);
+    }
+
+  if (!proc_encode_coding_system[outch])
+    proc_encode_coding_system[outch]
+      = (struct coding_system *) xmalloc (sizeof (struct coding_system));
+  setup_coding_system (p->encode_coding_system,
+		       proc_encode_coding_system[outch]);
+}
 
 DEFUN ("processp", Fprocessp, Sprocessp, 1, 1, 0,
        doc: /* Return t if OBJECT is a process.  */)
@@ -816,6 +850,7 @@
   p->buffer = buffer;
   if (NETCONN1_P (p))
     p->childp = Fplist_put (p->childp, QCbuffer, buffer);
+  setup_process_coding_systems (process);
   return buffer;
 }
 
@@ -890,6 +925,7 @@
   p->filter = filter;
   if (NETCONN1_P (p))
     p->childp = Fplist_put (p->childp, QCfilter, filter);
+  setup_process_coding_systems (process);
   return filter;
 }
 
@@ -1438,6 +1474,8 @@
   XPROCESS (proc)->buffer = buffer;
   XPROCESS (proc)->sentinel = Qnil;
   XPROCESS (proc)->filter = Qnil;
+  XPROCESS (proc)->filter_multibyte
+    = buffer_defaults.enable_multibyte_characters;
   XPROCESS (proc)->command = Flist (nargs - 2, args + 2);
 
   /* Make the process marker point into the process buffer (if any).  */
@@ -1748,16 +1786,7 @@
     XSETFASTINT (XPROCESS (process)->subtty, forkin);
   XPROCESS (process)->pty_flag = (pty_flag ? Qt : Qnil);
   XPROCESS (process)->status = Qrun;
-  if (!proc_decode_coding_system[inchannel])
-    proc_decode_coding_system[inchannel]
-      = (struct coding_system *) xmalloc (sizeof (struct coding_system));
-  setup_coding_system (XPROCESS (process)->decode_coding_system,
-		       proc_decode_coding_system[inchannel]);
-  if (!proc_encode_coding_system[outchannel])
-    proc_encode_coding_system[outchannel]
-      = (struct coding_system *) xmalloc (sizeof (struct coding_system));
-  setup_coding_system (XPROCESS (process)->encode_coding_system,
-		       proc_encode_coding_system[outchannel]);
+  setup_process_coding_systems (process);
 
   /* Delay interrupts until we have a chance to store
      the new fork's pid in its process structure */
@@ -2590,6 +2619,11 @@
 
 :filter FILTER -- Install FILTER as the process filter.
 
+:filter-multibyte BOOL -- If BOOL is non-nil, a string given to the
+process filter is multibyte, otherwise it is unibyte.  If this keyword
+is not specified, the string is multibyte iff
+`default-enable-multibyte-characters' is non-nil.
+
 :sentinel SENTINEL -- Install SENTINEL as the process sentinel.
 
 :log LOG -- Install LOG as the server process log function.  This
@@ -3185,6 +3219,10 @@
   p->buffer = buffer;
   p->sentinel = sentinel;
   p->filter = filter;
+  p->filter_multibyte = buffer_defaults.enable_multibyte_characters;
+  /* Override the above only if :filter-multibyte is specified.  */
+  if (! NILP (Fplist_member (contact, QCfilter_multibyte)))
+    p->filter_multibyte = Fplist_get (contact, QCfilter_multibyte);
   p->log = Fplist_get (contact, QClog);
   if (tem = Fplist_get (contact, QCnoquery), !NILP (tem))
     p->kill_without_query = Qt;
@@ -3296,17 +3334,7 @@
       }
     p->encode_coding_system = val;
   }
-
-  if (!proc_decode_coding_system[inch])
-    proc_decode_coding_system[inch]
-      = (struct coding_system *) xmalloc (sizeof (struct coding_system));
-  setup_coding_system (p->decode_coding_system,
-		       proc_decode_coding_system[inch]);
-  if (!proc_encode_coding_system[outch])
-    proc_encode_coding_system[outch]
-      = (struct coding_system *) xmalloc (sizeof (struct coding_system));
-  setup_coding_system (p->encode_coding_system,
-		       proc_encode_coding_system[outch]);
+  setup_process_coding_systems (proc);
 
   p->decoding_buf = make_uninit_string (0);
   p->decoding_carryover = make_number (0);
@@ -3641,17 +3669,7 @@
 
   p->decode_coding_system = ps->decode_coding_system;
   p->encode_coding_system = ps->encode_coding_system;
-
-  if (!proc_decode_coding_system[s])
-    proc_decode_coding_system[s]
-      = (struct coding_system *) xmalloc (sizeof (struct coding_system));
-  setup_coding_system (p->decode_coding_system,
-		       proc_decode_coding_system[s]);
-  if (!proc_encode_coding_system[s])
-    proc_encode_coding_system[s]
-      = (struct coding_system *) xmalloc (sizeof (struct coding_system));
-  setup_coding_system (p->encode_coding_system,
-		       proc_encode_coding_system[s]);
+  setup_process_coding_systems (proc);
 
   p->decoding_buf = make_uninit_string (0);
   p->decoding_carryover = make_number (0);
@@ -4517,10 +4535,6 @@
 
       text = decode_coding_string (make_unibyte_string (chars, nbytes),
 				   coding, 0);
-      if (NILP (buffer_defaults.enable_multibyte_characters))
-	/* We had better return unibyte string.  */
-	text = string_make_unibyte (text);
-
       Vlast_coding_system_used = coding->symbol;
       /* A new coding system might be found.  */
       if (!EQ (p->decode_coding_system, coding->symbol))
@@ -4551,6 +4565,11 @@
       bcopy (chars + coding->consumed, SDATA (p->decoding_buf),
 	     carryover);
       XSETINT (p->decoding_carryover, carryover);
+      /* Adjust the multibyteness of TEXT to that of the filter.  */
+      if (NILP (p->filter_multibyte) != ! STRING_MULTIBYTE (text))
+	text = (STRING_MULTIBYTE (text)
+		? Fstring_as_unibyte (text)
+		: Fstring_to_multibyte (text));
       nbytes = SBYTES (text);
       nchars = SCHARS (text);
       if (nbytes > 0)
@@ -4657,7 +4676,7 @@
 	  != ! STRING_MULTIBYTE (text))
 	text = (STRING_MULTIBYTE (text)
 		? Fstring_as_unibyte (text)
-		: Fstring_as_multibyte (text));
+		: Fstring_to_multibyte (text));
       nbytes = SBYTES (text);
       nchars = SCHARS (text);
       /* Insert before markers in case we are inserting where
@@ -6118,13 +6137,12 @@
     error ("Input file descriptor of %s closed", SDATA (p->name));
   if (XINT (p->outfd) < 0)
     error ("Output file descriptor of %s closed", SDATA (p->name));
-
-  p->decode_coding_system = Fcheck_coding_system (decoding);
-  p->encode_coding_system = Fcheck_coding_system (encoding);
-  setup_coding_system (decoding,
-		       proc_decode_coding_system[XINT (p->infd)]);
-  setup_coding_system (encoding,
-		       proc_encode_coding_system[XINT (p->outfd)]);
+  Fcheck_coding_system (decoding);
+  Fcheck_coding_system (encoding);
+
+  p->decode_coding_system = decoding;
+  p->encode_coding_system = encoding;
+  setup_process_coding_systems (proc);
 
   return Qnil;
 }
@@ -6139,6 +6157,42 @@
   return Fcons (XPROCESS (proc)->decode_coding_system,
 		XPROCESS (proc)->encode_coding_system);
 }
+
+DEFUN ("set-process-filter-multibyte", Fset_process_filter_multibyte,
+       Sset_process_filter_multibyte, 2, 2, 0,
+       doc: /* Set multibyteness of a string given to PROCESS's filter.
+If FLAG is non-nil, the filter is given a multibyte string.
+If FLAG is nil, the filter is give a unibyte string.  In this case,
+all character code conversion except for end-of-line conversion is
+suppressed.  */)
+     (proc, flag)
+     Lisp_Object proc, flag;
+{
+  register struct Lisp_Process *p;
+
+  CHECK_PROCESS (proc);
+  p = XPROCESS (proc);
+  p->filter_multibyte = flag;
+  setup_process_coding_systems (proc);
+
+  return Qnil;
+}
+
+DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p,
+       Sprocess_filter_multibyte_p, 1, 1, 0,
+       doc: /* Return t if a multibyte string is given to PROCESS's filter.*/)
+     (proc)
+     Lisp_Object proc;
+{
+  register struct Lisp_Process *p;
+
+  CHECK_PROCESS (proc);
+  p = XPROCESS (proc);
+
+  return (NILP (p->filter_multibyte) ? Qnil : Qt);
+}
+
+
 
 /* The first time this is called, assume keyboard input comes from DESC
    instead of from where we used to expect it.
@@ -6345,6 +6399,8 @@
 
   Qlast_nonmenu_event = intern ("last-nonmenu-event");
   staticpro (&Qlast_nonmenu_event);
+  QCfilter_multibyte = intern ("filter-multibyte");
+  staticpro (&QCfilter_multibyte);
 
   staticpro (&Vprocess_alist);
 
@@ -6414,6 +6470,8 @@
 /*  defsubr (&Sprocess_connection); */
   defsubr (&Sset_process_coding_system);
   defsubr (&Sprocess_coding_system);
+  defsubr (&Sset_process_filter_multibyte);
+  defsubr (&Sprocess_filter_multibyte_p);
 }