(wait_reading_process_input): Don't signal SIGIO in batch mode.
[bpt/emacs.git] / src / process.c
index 5a27114..8fac995 100644 (file)
@@ -1,6 +1,6 @@
 /* Asynchronous subprocess control for GNU Emacs.
    Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 96, 98, 1999,
-      2001, 2002 Free Software Foundation, Inc.
+      2001, 2002, 2003 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -20,7 +20,6 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
 
-#define _GNU_SOURCE            /* to get strsignal declared with glibc 2 */
 #include <config.h>
 #include <signal.h>
 
@@ -102,7 +101,7 @@ Boston, MA 02111-1307, USA.  */
 #ifdef IRIS
 #include <sys/sysmacros.h>     /* for "minor" */
 #endif /* not IRIS */
-  
+
 #ifdef HAVE_SYS_WAIT
 #include <sys/wait.h>
 #endif
@@ -133,7 +132,8 @@ Lisp_Object Qlocal, Qdatagram;
 Lisp_Object QCname, QCbuffer, QChost, QCservice, QCtype;
 Lisp_Object QClocal, QCremote, QCcoding;
 Lisp_Object QCserver, QCnowait, QCnoquery, QCstop;
-Lisp_Object QCsentinel, QClog, QCoptions;
+Lisp_Object QCsentinel, QClog, QCoptions, QCplist;
+Lisp_Object QCfilter_multibyte;
 Lisp_Object Qlast_nonmenu_event;
 /* QCfamily is declared and initialized in xfaces.c,
    QCfilter in keyboard.c.  */
@@ -147,7 +147,7 @@ extern Lisp_Object QCfamily;
 extern Lisp_Object QCfilter;
 
 /* a process object is a network connection when its childp field is neither
-   Qt nor Qnil but is instead a cons cell (HOSTNAME PORTNUM).  */
+   Qt nor Qnil but is instead a property list (KEY VAL ...).  */
 
 #ifdef HAVE_SOCKETS
 #define NETCONN_P(p) (GC_CONSP (XPROCESS (p)->childp))
@@ -358,7 +358,7 @@ update_status (p)
   p->raw_status_high = Qnil;
 }
 
-/*  Convert a process status word in Unix format to 
+/*  Convert a process status word in Unix format to
     the list that we use internally.  */
 
 Lisp_Object
@@ -407,7 +407,7 @@ decode_status (l, symbol, code, coredump)
 
 /* Return a string describing a process status list.  */
 
-Lisp_Object 
+Lisp_Object
 status_message (status)
      Lisp_Object status;
 {
@@ -459,17 +459,9 @@ status_message (status)
 int
 allocate_pty ()
 {
-  struct stat stb;
   register int c, i;
   int fd;
 
-  /* Some systems name their pseudoterminals so that there are gaps in
-     the usual sequence - for example, on HP9000/S700 systems, there
-     are no pseudoterminals with names ending in 'f'.  So we wait for
-     three failures in a row before deciding that we've reached the
-     end of the ptys.  */
-  int failed_count = 0;
-
 #ifdef PTY_ITERATION
   PTY_ITERATION
 #else
@@ -477,6 +469,7 @@ allocate_pty ()
     for (i = 0; i < 16; i++)
 #endif
       {
+       struct stat stb;        /* Used in some PTY_OPEN.  */
 #ifdef PTY_NAME_SPRINTF
        PTY_NAME_SPRINTF
 #else
@@ -486,28 +479,38 @@ allocate_pty ()
 #ifdef PTY_OPEN
        PTY_OPEN;
 #else /* no PTY_OPEN */
-#ifdef IRIS
-       /* Unusual IRIS code */
-       *ptyv = emacs_open ("/dev/ptc", O_RDWR | O_NDELAY, 0);
-       if (fd < 0)
-         return -1;
-       if (fstat (fd, &stb) < 0)
-         return -1;
-#else /* not IRIS */
-       if (stat (pty_name, &stb) < 0)
-         {
-           failed_count++;
-           if (failed_count >= 3)
-             return -1;
+       {
+# ifdef IRIS
+         /* Unusual IRIS code */
+         *ptyv = emacs_open ("/dev/ptc", O_RDWR | O_NDELAY, 0);
+         if (fd < 0)
+           return -1;
+         if (fstat (fd, &stb) < 0)
+           return -1;
+# else /* not IRIS */
+         { /* Some systems name their pseudoterminals so that there are gaps in
+              the usual sequence - for example, on HP9000/S700 systems, there
+              are no pseudoterminals with names ending in 'f'.  So we wait for
+              three failures in a row before deciding that we've reached the
+              end of the ptys.  */
+           int failed_count = 0;
+           
+           if (stat (pty_name, &stb) < 0)
+             {
+               failed_count++;
+               if (failed_count >= 3)
+                 return -1;
+             }
+           else
+             failed_count = 0;
          }
-       else
-         failed_count = 0;
-#ifdef O_NONBLOCK
-       fd = emacs_open (pty_name, O_RDWR | O_NONBLOCK, 0);
-#else
-       fd = emacs_open (pty_name, O_RDWR | O_NDELAY, 0);
-#endif
-#endif /* not IRIS */
+#  ifdef O_NONBLOCK
+         fd = emacs_open (pty_name, O_RDWR | O_NONBLOCK, 0);
+#  else
+         fd = emacs_open (pty_name, O_RDWR | O_NDELAY, 0);
+#  endif
+# endif /* not IRIS */
+       }
 #endif /* no PTY_OPEN */
 
        if (fd >= 0)
@@ -523,11 +526,11 @@ allocate_pty ()
            if (access (pty_name, 6) != 0)
              {
                emacs_close (fd);
-#if !defined(IRIS) && !defined(__sgi)
+# if !defined(IRIS) && !defined(__sgi)
                continue;
-#else
+# else
                return -1;
-#endif /* IRIS */
+# endif /* IRIS */
              }
 #endif /* not UNIPLUS */
            setup_pty (fd);
@@ -587,6 +590,42 @@ remove_process (proc)
 
   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 (inch < 0 || outch < 0)
+    return;
+
+  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]);
+}
 \f
 DEFUN ("processp", Fprocessp, Sprocessp, 1, 1, 0,
        doc: /* Return t if OBJECT is a process.  */)
@@ -686,7 +725,7 @@ nil, indicating the current buffer's process.  */)
     {
       Fkill_process (process, Qnil);
       /* Do this now, since remove_process will make sigchld_handler do nothing.  */
-      XPROCESS (process)->status 
+      XPROCESS (process)->status
        = Fcons (Qsignal, Fcons (make_number (SIGKILL), Qnil));
       XSETINT (XPROCESS (process)->tick, ++process_tick);
       status_notify ();
@@ -817,6 +856,7 @@ DEFUN ("set-process-buffer", Fset_process_buffer, Sset_process_buffer,
   p->buffer = buffer;
   if (NETCONN1_P (p))
     p->childp = Fplist_put (p->childp, QCbuffer, buffer);
+  setup_process_coding_systems (process);
   return buffer;
 }
 
@@ -845,15 +885,23 @@ DEFUN ("set-process-filter", Fset_process_filter, Sset_process_filter,
        2, 2, 0,
        doc: /* Give PROCESS the filter function FILTER; nil means no filter.
 t means stop accepting output from the process.
-When a process has a filter, each time it does output
-the entire string of output is passed to the filter.
+
+When a process has a filter, its buffer is not used for output.
+Instead, each time it does output, the entire string of output is
+passed to the filter.
+
 The filter gets two arguments: the process and the string of output.
-If the process has a filter, its buffer is not used for output.  */)
+The string argument is normally a multibyte string, except:
+- if the process' input coding system is no-conversion or raw-text,
+  it is a unibyte string (the non-converted input), or else
+- if `default-enable-multibyte-characters' is nil, it is a unibyte
+  string (the result of converting the decoded input multibyte
+  string to unibyte with `string-make-unibyte').  */)
      (process, filter)
      register Lisp_Object process, filter;
 {
   struct Lisp_Process *p;
-  
+
   CHECK_PROCESS (process);
   p = XPROCESS (process);
 
@@ -864,7 +912,7 @@ If the process has a filter, its buffer is not used for output.  */)
      (setq process (start-process ...))
      (debug)
      (set-process-filter process ...)  */
-  
+
   if (XINT (p->infd) >= 0)
     {
       if (EQ (filter, Qt) && !EQ (p->status, Qlisten))
@@ -879,10 +927,11 @@ If the process has a filter, its buffer is not used for output.  */)
          FD_SET (XINT (p->infd), &non_keyboard_wait_mask);
        }
     }
-  
+
   p->filter = filter;
   if (NETCONN1_P (p))
     p->childp = Fplist_put (p->childp, QCfilter, filter);
+  setup_process_coding_systems (process);
   return filter;
 }
 
@@ -930,7 +979,7 @@ DEFUN ("set-process-window-size", Fset_process_window_size,
   CHECK_PROCESS (process);
   CHECK_NATNUM (height);
   CHECK_NATNUM (width);
-  
+
   if (XINT (XPROCESS (process)->infd) < 0
       || set_window_size (XINT (XPROCESS (process)->infd),
                          XINT (height), XINT (width)) <= 0)
@@ -1026,7 +1075,7 @@ See `make-network-process' for a list of keywords.  */)
 #ifdef DATAGRAM_SOCKETS
   if (DATAGRAM_CONN_P (process)
       && (EQ (key, Qt) || EQ (key, QCremote)))
-    contact = Fplist_put (contact, QCremote, 
+    contact = Fplist_put (contact, QCremote,
                          Fprocess_datagram_address (process));
 #endif
 
@@ -1038,6 +1087,29 @@ See `make-network-process' for a list of keywords.  */)
   return Fplist_get (contact, key);
 }
 
+DEFUN ("process-plist", Fprocess_plist, Sprocess_plist,
+       1, 1, 0,
+       doc: /* Return the plist of PROCESS.  */)
+     (process)
+     register Lisp_Object process;
+{
+  CHECK_PROCESS (process);
+  return XPROCESS (process)->plist;
+}
+
+DEFUN ("set-process-plist", Fset_process_plist, Sset_process_plist,
+       2, 2, 0,
+       doc: /* Replace the plist of PROCESS with PLIST.  Returns PLIST.  */)
+     (process, plist)
+     register Lisp_Object process, plist;
+{
+  CHECK_PROCESS (process);
+  CHECK_LIST (plist);
+
+  XPROCESS (process)->plist = plist;
+  return plist;
+}
+
 #if 0 /* Turned off because we don't currently record this info
         in the process.  Perhaps add it.  */
 DEFUN ("process-connection", Fprocess_connection, Sprocess_connection, 1, 1, 0,
@@ -1053,16 +1125,14 @@ a socket connection.  */)
 
 #ifdef HAVE_SOCKETS
 DEFUN ("format-network-address", Fformat_network_address, Sformat_network_address,
-       1, 1, 0,
+       1, 2, 0,
        doc: /* Convert network ADDRESS from internal format to a string.
-Returns nil if format of ADDRESS is invalid.  */)
-     (address)
-     Lisp_Object address;
+If optional second argument OMIT-PORT is non-nil, don't include a port
+number in the string; in this case, interpret a 4 element vector as an
+IP address.  Returns nil if format of ADDRESS is invalid.  */)
+     (address, omit_port)
+     Lisp_Object address, omit_port;
 {
-  register struct Lisp_Vector *p;
-  register unsigned char *cp;
-  register int i;
-
   if (NILP (address))
     return Qnil;
 
@@ -1073,26 +1143,33 @@ Returns nil if format of ADDRESS is invalid.  */)
     {
       register struct Lisp_Vector *p = XVECTOR (address);
       Lisp_Object args[6];
+      int nargs, i;
 
-      if (p->size != 5)
+      if (!NILP (omit_port) && (p->size == 4 || p->size == 5))
+       {
+         args[0] = build_string ("%d.%d.%d.%d");
+         nargs = 4;
+       }
+      else if (p->size == 5)
+       {
+         args[0] = build_string ("%d.%d.%d.%d:%d");
+         nargs = 5;
+       }
+      else
        return Qnil;
 
-      args[0] = build_string ("%d.%d.%d.%d:%d");
-      args[1] = XINT (p->contents[0]);
-      args[2] = XINT (p->contents[1]);
-      args[3] = XINT (p->contents[2]);
-      args[4] = XINT (p->contents[3]);
-      args[5] = XINT (p->contents[4]);
-      return Fformat (6, args);
+      for (i = 0; i < nargs; i++)
+       args[i+1] = p->contents[i];
+      return Fformat (nargs+1, args);
     }
 
   if (CONSP (address))
     {
       Lisp_Object args[2];
       args[0] = build_string ("<Family %d>");
-      args[1] = XINT (Fcar (address));
+      args[1] = Fcar (address);
       return Fformat (2, args);
-      
+
     }
 
   return Qnil;
@@ -1197,7 +1274,7 @@ list_processes_1 (query_only)
       if (CONSP (p->status))
        symbol = XCAR (p->status);
 
-      
+
       if (EQ (symbol, Qsignal))
        {
          Lisp_Object tem;
@@ -1260,7 +1337,7 @@ list_processes_1 (query_only)
          if (INTEGERP (port))
            port = Fnumber_to_string (port);
          if (NILP (port))
-           port = Fformat_network_address (Fplist_get (p->childp, QClocal));
+           port = Fformat_network_address (Fplist_get (p->childp, QClocal), Qnil);
          sprintf (tembuf, "(network %s server on %s)\n",
                   (DATAGRAM_CHAN_P (XINT (p->infd)) ? "datagram" : "stream"),
                   (STRINGP (port) ? (char *)SDATA (port) : "?"));
@@ -1278,13 +1355,13 @@ list_processes_1 (query_only)
                host = Fnumber_to_string (host);
            }
          if (NILP (host))
-           host = Fformat_network_address (Fplist_get (p->childp, QCremote));
+           host = Fformat_network_address (Fplist_get (p->childp, QCremote), Qnil);
          sprintf (tembuf, "(network %s connection to %s)\n",
                   (DATAGRAM_CHAN_P (XINT (p->infd)) ? "datagram" : "stream"),
                   (STRINGP (host) ? (char *)SDATA (host) : "?"));
          insert_string (tembuf);
         }
-      else 
+      else
        {
          tem = p->command;
          while (1)
@@ -1373,7 +1450,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS)  */)
 
     GCPRO2 (buffer, current_dir);
 
-    current_dir 
+    current_dir
       = expand_and_dir_to_file (Funhandled_file_name_directory (current_dir),
                                Qnil);
     if (NILP (Ffile_accessible_directory_p (current_dir)))
@@ -1398,10 +1475,13 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS)  */)
   record_unwind_protect (start_process_unwind, proc);
 
   XPROCESS (proc)->childp = Qt;
+  XPROCESS (proc)->plist = Qnil;
   XPROCESS (proc)->command_channel_p = Qnil;
   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).  */
@@ -1476,7 +1556,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS)  */)
       strcat (new_argv, SDATA (tem));
     }
   /* Need to add code here to check for program existence on VMS */
-  
+
 #else /* not VMS */
   new_argv = (unsigned char **) alloca ((nargs - 1) * sizeof (char *));
 
@@ -1705,23 +1785,15 @@ create_process (process, new_argv, current_dir)
   chan_process[inchannel] = process;
   XSETINT (XPROCESS (process)->infd, inchannel);
   XSETINT (XPROCESS (process)->outfd, outchannel);
-  /* Record the tty descriptor used in the subprocess.  */
-  if (forkin < 0)
-    XPROCESS (process)->subtty = Qnil;
-  else
-    XSETFASTINT (XPROCESS (process)->subtty, forkin);
+
+  /* Previously we recorded the tty descriptor used in the subprocess.
+     It was only used for getting the foreground tty process, so now
+     we just reopen the device (see emacs_get_tty_pgrp) as this is
+     more portable (see USG_SUBTTY_WORKS above).  */
+
   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 */
@@ -1773,7 +1845,7 @@ create_process (process, new_argv, current_dir)
   XSETINT (XPROCESS (process)->pid, -1);
 
   BLOCK_INPUT;
-  
+
   {
     /* child_setup must clobber environ on systems with true vfork.
        Protect it from permanent change.  */
@@ -1838,12 +1910,12 @@ create_process (process, new_argv, current_dir)
          }
 #endif
 #endif
-#ifdef TIOCNOTTY 
+#ifdef TIOCNOTTY
        /* In 4.3BSD, the TIOCSPGRP bug has been fixed, and now you
           can do TIOCSPGRP only to the process's controlling tty.  */
        if (pty_flag)
          {
-           /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here? 
+           /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here?
               I can't test it since I don't have 4.3.  */
            int j = emacs_open ("/dev/tty", O_RDWR, 0);
            ioctl (j, TIOCNOTTY, 0);
@@ -1938,7 +2010,7 @@ create_process (process, new_argv, current_dir)
 #ifdef WINDOWSNT
        pid = child_setup (xforkin, xforkout, xforkout,
                           new_argv, 1, current_dir);
-#else  /* not WINDOWSNT */     
+#else  /* not WINDOWSNT */
        child_setup (xforkin, xforkout, xforkout,
                     new_argv, 1, current_dir);
 #endif /* not WINDOWSNT */
@@ -1971,19 +2043,18 @@ create_process (process, new_argv, current_dir)
       {
        struct atimer *timer;
        EMACS_TIME offset;
-       
+
        stop_polling ();
        EMACS_SET_SECS_USECS (offset, 1, 0);
        timer = start_atimer (ATIMER_RELATIVE, offset, create_process_1, 0);
-       
-       XPROCESS (process)->subtty = Qnil;
+
        if (forkin >= 0)
          emacs_close (forkin);
 
        cancel_atimer (timer);
        start_polling ();
       }
-      
+
       if (forkin != forkout && forkout >= 0)
        emacs_close (forkout);
 
@@ -2135,7 +2206,7 @@ conv_lisp_to_sockaddr (family, address, sa, len)
      int len;
 {
   register struct Lisp_Vector *p;
-  register unsigned char *cp;
+  register unsigned char *cp = NULL;
   register int i;
 
   bzero (sa, len);
@@ -2224,7 +2295,7 @@ Returns nil upon error setting address, ADDRESS otherwise.  */)
 
 static struct socket_options {
   /* The name of this option.  Should be lowercase version of option
-     name without SO_ prefix. */ 
+     name without SO_ prefix. */
   char *name;
   /* Length of name.  */
   int nlen;
@@ -2370,14 +2441,14 @@ set_socket_options (s, opts, no_error)
                  arg = (char *) SDATA (val);
                else if (XSYMBOL (val))
                  arg = (char *) SDATA (SYMBOL_NAME (val));
-               else 
+               else
                  error ("Invalid argument to %s option", name);
              }
            ret = setsockopt (s, sopt->optlevel, sopt->optnum,
                              arg, strlen (arg));
          }
 
-#ifdef SO_LINGER           
+#ifdef SO_LINGER
        case SOPT_LINGER:
          {
            struct linger linger;
@@ -2419,7 +2490,7 @@ set_socket_options (s, opts, no_error)
 
 DEFUN ("set-network-process-options",
        Fset_network_process_options, Sset_network_process_options,
-       1, MANY, 0, 
+       1, MANY, 0,
        doc: /* Set one or more options for network process PROCESS.
 Each option is either a string "OPT=VALUE" or a cons (OPT . VALUE).
 A boolean value is false if it either zero or nil, true otherwise.
@@ -2430,9 +2501,9 @@ pages for more information.
 bindtodevice=NAME -- bind to interface NAME, or remove binding if nil.
 broadcast=BOOL -- Allow send and receive of datagram broadcasts.
 dontroute=BOOL -- Only send to directly connected hosts.
-keepalive=BOOL -- Send keep-alive messages on network stream. 
+keepalive=BOOL -- Send keep-alive messages on network stream.
 linger=BOOL or TIMEOUT -- Send queued messages before closing.
-oobinline=BOOL -- Place out-of-band data in receive data stream. 
+oobinline=BOOL -- Place out-of-band data in receive data stream.
 priority=INT -- Set protocol defined priority for sent packets.
 reuseaddr=BOOL -- Allow reusing a recently used address.
 
@@ -2471,8 +2542,8 @@ unwind_request_sigio (dummy)
    connection has no PID; you cannot signal it.  All you can do is
    stop/continue it and deactivate/close it via delete-process */
 
-DEFUN ("make-network-process", Fmake_network_process, Smake_network_process, 
-       0, MANY, 0, 
+DEFUN ("make-network-process", Fmake_network_process, Smake_network_process,
+       0, MANY, 0,
        doc: /* Create and return a network server or client process.
 
 In Emacs, network connections are represented by process objects, so
@@ -2554,6 +2625,11 @@ The stopped state is cleared by `continue-process' and set by
 
 :filter FILTER -- Install FILTER as the process filter.
 
+:filter-multibyte BOOL -- If BOOL is non-nil, strings given to the
+process filter are multibyte, otherwise they are unibyte.
+If this keyword is not specified, the strings are 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
@@ -2562,29 +2638,35 @@ client.  The arguments are SERVER, CLIENT, and MESSAGE, where SERVER
 is the server process, CLIENT is the new process for the connection,
 and MESSAGE is a string.
 
+:plist PLIST -- Install PLIST as the new process' initial plist.
+
 :server BOOL -- if BOOL is non-nil, create a server process for the
 specified FAMILY, SERVICE, and connection type (stream or datagram).
 Default is a client process.
 
 A server process will listen for and accept connections from
 clients.  When a client connection is accepted, a new network process
-is created for the connection with the following parameters: 
+is created for the connection with the following parameters:
 - The client's process name is constructed by concatenating the server
 process' NAME and a client identification string.
 - If the FILTER argument is non-nil, the client process will not get a
 separate process buffer; otherwise, the client's process buffer is a newly
 created buffer named after the server process' BUFFER name or process
-NAME concatenated with the client identification string.  
+NAME concatenated with the client identification string.
 - The connection type and the process filter and sentinel parameters are
 inherited from the server process' TYPE, FILTER and SENTINEL.
 - The client process' contact info is set according to the client's
 addressing information (typically an IP address and a port number).
+- The client process' plist is initialized from the server's plist.
 
 Notice that the FILTER and SENTINEL args are never used directly by
 the server process.  Also, the BUFFER argument is not used directly by
 the server process, but via the optional :log function, accepted (and
 failed) connections may be logged in the server process' buffer.
 
+The original argument list, modified with the actual connection
+information, is available via the `process-contact' function.
+
 usage: (make-network-process &rest ARGS)  */)
      (nargs, args)
      int nargs;
@@ -2690,7 +2772,7 @@ usage: (make-network-process &rest ARGS)  */)
   /* Let's handle TERM before things get complicated ...   */
   host = Fplist_get (contact, QChost);
   CHECK_STRING (host);
-  
+
   service = Fplist_get (contact, QCservice);
   if (INTEGERP (service))
     port = htons ((unsigned short) XINT (service));
@@ -2839,7 +2921,7 @@ usage: (make-network-process &rest ARGS)  */)
     {
       struct servent *svc_info;
       CHECK_STRING (service);
-      svc_info = getservbyname (SDATA (service), 
+      svc_info = getservbyname (SDATA (service),
                                (socktype == SOCK_DGRAM ? "udp" : "tcp"));
       if (svc_info == 0)
        error ("Unknown service: %s", SDATA (service));
@@ -2862,7 +2944,7 @@ usage: (make-network-process &rest ARGS)  */)
       QUIT;
       host_info_ptr = gethostbyname (SDATA (host));
       immediate_quit = 0;
-  
+
       if (host_info_ptr)
        {
          bcopy (host_info_ptr->h_addr, (char *) &address_in.sin_addr,
@@ -2943,7 +3025,7 @@ usage: (make-network-process &rest ARGS)  */)
            }
        }
 #endif
-      
+
       /* Make us close S if quit.  */
       record_unwind_protect (close_file_unwind, make_number (s));
 
@@ -2958,7 +3040,7 @@ usage: (make-network-process &rest ARGS)  */)
              if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval))
                report_file_error ("Cannot set reuse option on server socket.", Qnil);
            }
-      
+
          if (bind (s, lres->ai_addr, lres->ai_addrlen))
            report_file_error ("Cannot bind server socket", Qnil);
 
@@ -2970,7 +3052,7 @@ usage: (make-network-process &rest ARGS)  */)
              if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
                {
                  ((struct sockaddr_in *)(lres->ai_addr))->sin_port = sa1.sin_port;
-                 service = make_number (sa1.sin_port);
+                 service = make_number (ntohs (sa1.sin_port));
                  contact = Fplist_put (contact, QCservice, service);
                }
            }
@@ -2993,7 +3075,7 @@ usage: (make-network-process &rest ARGS)  */)
         set.
 
         It'd be nice to be able to control the connect timeout
-        though.  Would non-blocking connect calls be portable? 
+        though.  Would non-blocking connect calls be portable?
 
         This used to be conditioned by HAVE_GETADDRINFO.  Why?  */
 
@@ -3069,8 +3151,18 @@ usage: (make-network-process &rest ARGS)  */)
            bcopy (lres->ai_addr, datagram_address[s].sa, lres->ai_addrlen);
        }
 #endif
-      contact = Fplist_put (contact, QCaddress, 
+      contact = Fplist_put (contact, QCaddress,
                            conv_sockaddr_to_lisp (lres->ai_addr, lres->ai_addrlen));
+#ifdef HAVE_GETSOCKNAME
+      if (!is_server)
+       {
+         struct sockaddr_in sa1;
+         int len1 = sizeof (sa1);
+         if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
+           contact = Fplist_put (contact, QClocal,
+                                 conv_sockaddr_to_lisp (&sa1, len1));
+       }
+#endif
     }
 
 #ifdef HAVE_GETADDRINFO
@@ -3128,9 +3220,15 @@ usage: (make-network-process &rest ARGS)  */)
   p = XPROCESS (proc);
 
   p->childp = contact;
+  p->plist = Fcopy_sequence (Fplist_get (contact, QCplist));
+
   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;
@@ -3242,17 +3340,7 @@ usage: (make-network-process &rest ARGS)  */)
       }
     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);
@@ -3407,12 +3495,7 @@ Return non-nil iff we received any output before the timeout expired.  */)
        seconds = -1;
     }
   else
-    {
-      if (NILP (process))
-       seconds = -1;
-      else
-       seconds = 0;
-    }
+    seconds = NILP (process) ? -1 : 0;
 
   if (NILP (process))
     XSETFASTINT (process, 0);
@@ -3549,16 +3632,18 @@ server_accept_connection (server, channel)
   contact = Fplist_put (contact, QChost, host);
   if (!NILP (service))
     contact = Fplist_put (contact, QCservice, service);
-  contact = Fplist_put (contact, QCremote, 
+  contact = Fplist_put (contact, QCremote,
                        conv_sockaddr_to_lisp (&saddr.sa, len));
 #ifdef HAVE_GETSOCKNAME
   len = sizeof saddr;
-  if (getsockname (channel, &saddr.sa, &len) == 0)
-    contact = Fplist_put (contact, QClocal, 
+  if (getsockname (s, &saddr.sa, &len) == 0)
+    contact = Fplist_put (contact, QClocal,
                          conv_sockaddr_to_lisp (&saddr.sa, len));
 #endif
 
   p->childp = contact;
+  p->plist = Fcopy_sequence (ps->plist);
+
   p->buffer = buffer;
   p->sentinel = ps->sentinel;
   p->filter = ps->filter;
@@ -3578,24 +3663,14 @@ server_accept_connection (server, channel)
   if (s > max_process_desc)
     max_process_desc = s;
 
-  /* Setup coding system for new process based on server process.  
+  /* Setup coding system for new process based on server process.
      This seems to be the proper thing to do, as the coding system
      of the new process should reflect the settings at the time the
      server socket was opened; not the current settings. */
 
   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);
@@ -3612,7 +3687,7 @@ server_accept_connection (server, channel)
                      build_string ("\n")));
 
   if (!NILP (p->sentinel))
-    exec_sentinel (proc, 
+    exec_sentinel (proc,
                   concat3 (build_string ("open from "),
                            (STRINGP (host) ? host : build_string ("-")),
                            build_string ("\n")));
@@ -3716,7 +3791,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
       EMACS_SET_SECS_USECS (timeout, time_limit, microsecs);
       EMACS_ADD_TIME (end_time, end_time, timeout);
     }
-#ifdef hpux
+#ifdef POLL_INTERRUPTED_SYS_CALL
   /* AlainF 5-Jul-1996
      HP-UX 10.10 seem to have problems with signals coming in
      Causes "poll: interrupted system call" messages when Emacs is run
@@ -3725,7 +3800,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
      and then turn off any other atimers.  */
   stop_polling ();
   turn_on_atimers (0);
-#endif
+#endif /* POLL_INTERRUPTED_SYS_CALL */
 
   while (1)
     {
@@ -3775,7 +3850,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
            {
              int old_timers_run = timers_run;
              struct buffer *old_buffer = current_buffer;
-             
+
              timer_delay = timer_check (1);
 
              /* If a timer has run, this might have changed buffers
@@ -3784,7 +3859,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
                  && old_buffer != current_buffer
                  && waiting_for_user_input_p == -1)
                record_asynch_buffer_change ();
-             
+
              if (timers_run != old_timers_run && do_display)
                /* We must retry, since a timer may have requeued itself
                   and that could alter the time_delay.  */
@@ -3846,7 +3921,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
          Ctemp = connect_wait_mask;
          EMACS_SET_SECS_USECS (timeout, 0, 0);
          if ((select (max (max_process_desc, max_keyboard_desc) + 1,
-                      &Atemp, 
+                      &Atemp,
                       (num_pending_connects > 0 ? &Ctemp : (SELECT_TYPE *)0),
                       (SELECT_TYPE *)0, &timeout)
               <= 0))
@@ -3879,7 +3954,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
              if (nread == 0)
                break;
 
-              if (0 < nread) 
+              if (0 < nread)
                 total_nread += nread;
 #ifdef EIO
              else if (nread == -1 && EIO == errno)
@@ -3940,7 +4015,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
          if (check_connect)
            Connecting = connect_wait_mask;
          nfds = select (max (max_process_desc, max_keyboard_desc) + 1,
-                        &Available, 
+                        &Available,
                         (check_connect ? &Connecting : (SELECT_TYPE *)0),
                         (SELECT_TYPE *)0, &timeout);
        }
@@ -4037,7 +4112,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
          int old_timers_run = timers_run;
          struct buffer *old_buffer = current_buffer;
          int leave = 0;
-       
+
          if (detect_input_pending_run_timers (do_display))
            {
              swallow_events (do_display);
@@ -4054,8 +4129,8 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
 
          if (leave)
            break;
-       }    
-      
+       }
+
       /* If there is unread keyboard input, also return.  */
       if (XINT (read_kbd) != 0
          && requeued_events_pending_p ())
@@ -4088,7 +4163,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
         but select says there is input.  */
 
       if (XINT (read_kbd) && interrupt_input
-         && keyboard_bit_set (&Available))
+         && keyboard_bit_set (&Available) && ! noninteractive)
        kill (getpid (), SIGIO);
 #endif
 
@@ -4202,7 +4277,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
                      = Fcons (Qexit, Fcons (make_number (256), Qnil));
                }
            }
-#ifdef NON_BLOCKING_CONNECT      
+#ifdef NON_BLOCKING_CONNECT
          if (check_connect && FD_ISSET (channel, &Connecting))
            {
              struct Lisp_Process *p;
@@ -4277,14 +4352,14 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
       clear_input_pending ();
       QUIT;
     }
-#ifdef hpux
+#ifdef POLL_INTERRUPTED_SYS_CALL
   /* AlainF 5-Jul-1996
      HP-UX 10.10 seems to have problems with signals coming in
      Causes "poll: interrupted system call" messages when Emacs is run
      in an X window
      Turn periodic alarms back on */
   start_polling ();
-#endif
+#endif /* POLL_INTERRUPTED_SYS_CALL */
 
   return got_some_input;
 }
@@ -4423,7 +4498,7 @@ read_process_output (proc, channel)
   outstream = p->filter;
   if (!NILP (outstream))
     {
-      /* We inhibit quit here instead of just catching it so that 
+      /* We inhibit quit here instead of just catching it so that
         hitting ^G when a filter happens to be running won't screw
         it up.  */
       int count = SPECPDL_INDEX ();
@@ -4461,10 +4536,6 @@ read_process_output (proc, channel)
 
       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))
@@ -4495,6 +4566,11 @@ read_process_output (proc, channel)
       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)
@@ -4601,7 +4677,7 @@ read_process_output (proc, channel)
          != ! 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
@@ -4889,7 +4965,7 @@ send_process (proc, buf, len, object)
                      || errno == EAGAIN
 #endif
                      )
-                   /* Buffer is full.  Wait, accepting input; 
+                   /* Buffer is full.  Wait, accepting input;
                       that may allow the program
                       to finish doing output and read more.  */
                    {
@@ -4913,7 +4989,7 @@ send_process (proc, buf, len, object)
                         the terminal is set up that way which it is
                         here).  The same bytes will be seen again in a
                         later read(2), without the CRs.  */
-                   
+
                      if (errno == EAGAIN)
                        {
                          int flags = FWRITE;
@@ -4921,7 +4997,7 @@ send_process (proc, buf, len, object)
                                 &flags);
                        }
 #endif /* BROKEN_PTY_READ_AFTER_EAGAIN */
-                   
+
                      /* Running filters might relocate buffers or strings.
                         Arrange to relocate BUF.  */
                      if (BUFFERP (object))
@@ -4970,7 +5046,7 @@ send_process (proc, buf, len, object)
       XSETINT (XPROCESS (proc)->tick, ++process_tick);
       deactivate_process (proc);
 #ifdef VMS
-      error ("Error writing to process %s; closed it", 
+      error ("Error writing to process %s; closed it",
             SDATA (XPROCESS (proc)->name));
 #else
       error ("SIGPIPE raised on process %s; closed it",
@@ -5029,6 +5105,33 @@ Output from processes can arrive in between bunches.  */)
   return Qnil;
 }
 \f
+/* Return the foreground process group for the tty/pty that
+   the process P uses.  */
+static int
+emacs_get_tty_pgrp (p)
+     struct Lisp_Process *p;
+{
+  int gid = -1;
+
+#ifdef TIOCGPGRP 
+  if (ioctl (XINT (p->infd), TIOCGPGRP, &gid) == -1 && ! NILP (p->tty_name))
+    {
+      int fd;
+      /* Some OS:es (Solaris 8/9) does not allow TIOCGPGRP from the
+        master side.  Try the slave side.  */
+      fd = emacs_open (XSTRING (p->tty_name)->data, O_RDONLY, 0);
+
+      if (fd != -1)
+       {
+         ioctl (fd, TIOCGPGRP, &gid);
+         emacs_close (fd);
+       }
+    }
+#endif /* defined (TIOCGPGRP ) */
+
+  return gid;
+}
+
 DEFUN ("process-running-child-p", Fprocess_running_child_p,
        Sprocess_running_child_p, 0, 1, 0,
        doc: /* Return t if PROCESS has given the terminal to a child.
@@ -5039,7 +5142,7 @@ return t unconditionally.  */)
 {
   /* Initialize in case ioctl doesn't exist or gives an error,
      in a way that will cause returning t.  */
-  int gid = 0;
+  int gid;
   Lisp_Object proc;
   struct Lisp_Process *p;
 
@@ -5053,12 +5156,7 @@ return t unconditionally.  */)
     error ("Process %s is not active",
           SDATA (p->name));
 
-#ifdef TIOCGPGRP 
-  if (!NILP (p->subtty))
-    ioctl (XFASTINT (p->subtty), TIOCGPGRP, &gid);
-  else
-    ioctl (XINT (p->infd), TIOCGPGRP, &gid);
-#endif /* defined (TIOCGPGRP ) */
+  gid = emacs_get_tty_pgrp (p);
 
   if (gid == XFASTINT (p->pid))
     return Qnil;
@@ -5202,7 +5300,7 @@ process_send_signal (process, signo, current_group, nomsg)
       /* The code above always returns from the function.  */
 #endif /* defined (SIGNALS_VIA_CHARACTERS) */
 
-#ifdef TIOCGPGRP 
+#ifdef TIOCGPGRP
       /* Get the current pgrp using the tty itself, if we have that.
         Otherwise, use the pty to get the pgrp.
         On pfa systems, saka@pfu.fujitsu.co.JP writes:
@@ -5210,19 +5308,13 @@ process_send_signal (process, signo, current_group, nomsg)
         But, TIOCGPGRP does not work on E50 ;-P works fine on E60"
         His patch indicates that if TIOCGPGRP returns an error, then
         we should just assume that p->pid is also the process group id.  */
-      {
-       int err;
-
-       if (!NILP (p->subtty))
-         err = ioctl (XFASTINT (p->subtty), TIOCGPGRP, &gid);
-       else
-         err = ioctl (XINT (p->infd), TIOCGPGRP, &gid);
 
-       if (err == -1)
-         /* If we can't get the information, assume
-            the shell owns the tty.  */
-         gid = XFASTINT (p->pid);
-      }
+      gid = emacs_get_tty_pgrp (p);
+       
+      if (gid == -1)
+       /* If we can't get the information, assume
+          the shell owns the tty.  */
+       gid = XFASTINT (p->pid);
 
       /* It is not clear whether anything really can set GID to -1.
         Perhaps on some system one of those ioctls can or could do so.
@@ -5284,7 +5376,10 @@ process_send_signal (process, signo, current_group, nomsg)
   /* gid may be a pid, or minus a pgrp's number */
 #ifdef TIOCSIGSEND
   if (!NILP (current_group))
-    ioctl (XINT (p->infd), TIOCSIGSEND, signo);
+    {
+      if (ioctl (XINT (p->infd), TIOCSIGSEND, signo) == -1)
+       EMACS_KILLPG (gid, signo);
+    }
   else
     {
       gid = - XFASTINT (p->pid);
@@ -5336,7 +5431,7 @@ See function `interrupt-process' for more details on usage.  */)
 
 DEFUN ("stop-process", Fstop_process, Sstop_process, 0, 2, 0,
        doc: /* Stop process PROCESS.  May be process or name of one.
-See function `interrupt-process' for more details on usage.  
+See function `interrupt-process' for more details on usage.
 If PROCESS is a network process, inhibit handling of incoming traffic.  */)
      (process, current_group)
      Lisp_Object process, current_group;
@@ -5345,7 +5440,7 @@ If PROCESS is a network process, inhibit handling of incoming traffic.  */)
   if (PROCESSP (process) && NETCONN_P (process))
     {
       struct Lisp_Process *p;
-  
+
       p = XPROCESS (process);
       if (NILP (p->command)
          && XINT (p->infd) >= 0)
@@ -5367,7 +5462,7 @@ If PROCESS is a network process, inhibit handling of incoming traffic.  */)
 
 DEFUN ("continue-process", Fcontinue_process, Scontinue_process, 0, 2, 0,
        doc: /* Continue process PROCESS.  May be process or name of one.
-See function `interrupt-process' for more details on usage.  
+See function `interrupt-process' for more details on usage.
 If PROCESS is a network process, resume handling of incoming traffic.  */)
      (process, current_group)
      Lisp_Object process, current_group;
@@ -5428,7 +5523,7 @@ SIGCODE may be an integer, or a symbol whose name is a signal name.  */)
     }
   else
     process = get_process (process);
-      
+
   if (NILP (process))
     return process;
 
@@ -5652,7 +5747,7 @@ kill_buffer_processes (buffer)
 /* On receipt of a signal that a child status has changed, loop asking
    about children with changed statuses until the system says there
    are no more.
-   
+
    All we do is change the status; we do not run sentinels or print
    notifications.  That is saved for the next time keyboard input is
    done, in order to avoid timing errors.
@@ -5696,7 +5791,7 @@ sigchld_handler (signo)
 #define WUNTRACED 0
 #endif /* no WUNTRACED */
       /* Keep trying to get a status until we get a definitive result.  */
-      do 
+      do
        {
          errno = 0;
          pid = wait3 (&w, WNOHANG | WUNTRACED, 0);
@@ -5747,18 +5842,18 @@ sigchld_handler (signo)
              break;
            p = 0;
          }
-      
+
       /* Change the status of the process that was found.  */
       if (p != 0)
        {
          union { int i; WAITTYPE wt; } u;
          int clear_desc_flag = 0;
-         
+
          XSETINT (p->tick, ++process_tick);
          u.wt = w;
          XSETINT (p->raw_status_low, u.i & 0xffff);
          XSETINT (p->raw_status_high, u.i >> 16);
-         
+
          /* If process has terminated, stop waiting for its output.  */
          if ((WIFSIGNALED (w) || WIFEXITED (w))
              && XINT (p->infd) >= 0)
@@ -6062,13 +6157,12 @@ encode subprocess input.  */)
     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));
+  Fcheck_coding_system (decoding);
+  Fcheck_coding_system (encoding);
 
-  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)]);
+  p->decode_coding_system = decoding;
+  p->encode_coding_system = encoding;
+  setup_process_coding_systems (proc);
 
   return Qnil;
 }
@@ -6083,6 +6177,42 @@ DEFUN ("process-coding-system",
   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 the strings given to PROCESS's filter.
+If FLAG is non-nil, the filter is given multibyte strings.
+If FLAG is nil, the filter is given unibyte strings.  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);
+}
+
+
 \f
 /* The first time this is called, assume keyboard input comes from DESC
    instead of from where we used to expect it.
@@ -6284,7 +6414,11 @@ syms_of_process ()
   staticpro (&QCstop);
   QCoptions = intern (":options");
   staticpro (&QCoptions);
-    
+  QCplist = intern (":plist");
+  staticpro (&QCplist);
+  QCfilter_multibyte = intern (":filter-multibyte");
+  staticpro (&QCfilter_multibyte);
+
   Qlast_nonmenu_event = intern ("last-nonmenu-event");
   staticpro (&Qlast_nonmenu_event);
 
@@ -6327,6 +6461,8 @@ The value takes effect when `start-process' is called.  */);
   defsubr (&Sset_process_query_on_exit_flag);
   defsubr (&Sprocess_query_on_exit_flag);
   defsubr (&Sprocess_contact);
+  defsubr (&Sprocess_plist);
+  defsubr (&Sset_process_plist);
   defsubr (&Slist_processes);
   defsubr (&Sprocess_list);
   defsubr (&Sstart_process);
@@ -6354,6 +6490,8 @@ The value takes effect when `start-process' is called.  */);
 /*  defsubr (&Sprocess_connection); */
   defsubr (&Sset_process_coding_system);
   defsubr (&Sprocess_coding_system);
+  defsubr (&Sset_process_filter_multibyte);
+  defsubr (&Sprocess_filter_multibyte_p);
 }
 
 \f
@@ -6412,7 +6550,9 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
   int xerrno;
   /* Either nil or a cons cell, the car of which is of interest and
      may be changed outside of this routine.  */
-  Lisp_Object wait_for_cell = Qnil;
+  Lisp_Object wait_for_cell;
+
+  wait_for_cell = Qnil;
 
   /* If waiting for non-nil in a cell, record where.  */
   if (CONSP (read_kbd))