2002-05-07  Nix  <nix@esperi.demon.co.uk>

	* process.h (PROCESS_LIVE_P): Use the process status as
	evidence of health, not the state of the input stream.
	(PROCESS_READABLE_P): Say if the process is readable
	from. (It may be dead nonetheless.)
	(CHECK_READABLE_PROCESS): Test for that condition.

	* process.c (create_process): Use PROCESS_READABLE_P.
	(read_process_output, set_process_filter): Likewise.

	* process.c (Fprocess_input_coding_system): Use CHECK_READABLE_PROCESS.
	(Fset_process_input_coding_system, Fprocess_coding_system): Likewise.

	* process.c (Fprocess_readable_p): Report readability status.
	* process.c (Qprocess_readable_p): New, associated symbol...
	* process.c (syms_of_process): ... initialize it.

diff -durN xemacs-orig/src/process.c xemacs/src/process.c
--- xemacs-orig/src/process.c	Tue May  7 22:28:32 2002
+++ xemacs/src/process.c	Tue May  7 23:12:05 2002
@@ -58,7 +58,7 @@
 #include "systty.h"
 #include "syswait.h"
 
-Lisp_Object Qprocessp, Qprocess_live_p;
+Lisp_Object Qprocessp, Qprocess_live_p, Qprocess_readable_p;
 
 /* Process methods */
 struct process_methods the_process_methods;
@@ -266,6 +266,15 @@
     ? Qt : Qnil;
 }
 
+DEFUN ("process-readable-p", Fprocess_readable_p, 1, 1, 0, /*
+Return t if OBJECT is a process from which input may be available.
+*/
+       (object))
+{
+  return PROCESSP (object) && PROCESS_READABLE_P (XPROCESS (object))
+    ? Qt : Qnil;
+}
+
 DEFUN ("process-list", Fprocess_list, 0, 0, 0, /*
 Return a list of all processes.
 */
@@ -512,7 +521,7 @@
   pid = PROCMETH (create_process, (p, argv, nargv, program, cur_dir));
 
   p->pid = make_int (pid);
-  if (PROCESS_LIVE_P (p))
+  if (PROCESS_READABLE_P (p))
     event_stream_select_process (p);
 }
 
@@ -842,7 +851,7 @@
      Really, the loop in execute_internal_event() should check itself
      for a process-filter change, like in status_notify(); but the
      struct Lisp_Process is not exported outside of this file. */
-  if (!PROCESS_LIVE_P (p))
+  if (!PROCESS_READABLE_P (p))
     return -1; /* already closed */
 
   if (!NILP (p->filter) && (p->filter_does_read))
@@ -1051,7 +1060,7 @@
 set_process_filter (Lisp_Object process, Lisp_Object filter, int filter_does_read)
 {
   CHECK_PROCESS (process);
-  if (PROCESS_LIVE_P (XPROCESS (process))) {
+  if (PROCESS_READABLE_P (XPROCESS (process))) {
     if (EQ (filter, Qt))
       event_stream_unselect_process (XPROCESS (process));
     else
@@ -1142,7 +1151,7 @@
        (process))
 {
   process = get_process (process);
-  CHECK_LIVE_PROCESS (process);
+  CHECK_READABLE_PROCESS (process);
   return decoding_stream_coding_system (XLSTREAM (XPROCESS (process)->coding_instream) );
 }
 
@@ -1162,7 +1171,7 @@
        (process))
 {
   process = get_process (process);
-  CHECK_LIVE_PROCESS (process);
+  CHECK_READABLE_PROCESS (process);
   return Fcons (decoding_stream_coding_system
 		(XLSTREAM (XPROCESS (process)->coding_instream)),
 		encoding_stream_coding_system
@@ -1177,7 +1186,7 @@
 {
   codesys = Fget_coding_system (codesys);
   process = get_process (process);
-  CHECK_LIVE_PROCESS (process);
+  CHECK_READABLE_PROCESS (process);
 
   set_decoding_stream_coding_system
     (XLSTREAM (XPROCESS (process)->coding_instream), codesys);
@@ -2023,6 +2032,7 @@
 
   defsymbol (&Qprocessp, "processp");
   defsymbol (&Qprocess_live_p, "process-live-p");
+  defsymbol (&Qprocess_readable_p, "process-readable-p");
   defsymbol (&Qrun, "run");
   defsymbol (&Qstop, "stop");
   defsymbol (&Qopen, "open");
@@ -2037,6 +2047,7 @@
 
   DEFSUBR (Fprocessp);
   DEFSUBR (Fprocess_live_p);
+  DEFSUBR (Fprocess_readable_p);
   DEFSUBR (Fget_process);
   DEFSUBR (Fget_buffer_process);
   DEFSUBR (Fdelete_process);
diff -durN xemacs-orig/src/process.h xemacs/src/process.h
--- xemacs-orig/src/process.h	Tue May  7 22:18:17 2002
+++ xemacs/src/process.h	Tue May  7 23:04:40 2002
@@ -45,7 +45,8 @@
 #define XSETPROCESS(x, p) XSETRECORD (x, p, process)
 #define PROCESSP(x) RECORDP (x, process)
 #define CHECK_PROCESS(x) CHECK_RECORD (x, process)
-#define PROCESS_LIVE_P(x) (!NILP ((x)->pipe_instream))
+#define PROCESS_LIVE_P(x) (EQ ((x)->status_symbol, Qrun))
+#define PROCESS_READABLE_P(x) (!NILP ((x)->pipe_instream))
 
 #define CHECK_LIVE_PROCESS(x) do {			\
   CHECK_PROCESS (x);					\
@@ -53,6 +54,12 @@
     dead_wrong_type_argument (Qprocess_live_p, (x));	\
 } while (0)
 
+#define CHECK_READABLE_PROCESS(x) do {			\
+  CHECK_PROCESS (x);					\
+  if (! PROCESS_READABLE_P (XPROCESS (x)))		\
+    dead_wrong_type_argument (Qprocess_readable_p, (x));	\
+} while (0)
+
 #ifdef emacs
 
 EXFUN (Fprocess_kill_without_query, 2);