(g2-UU+5B73): Add `=decomposition@hanyo-denshi'.
[chise/xemacs-chise.git.1] / src / callproc.c
index b908a3a..8272ca9 100644 (file)
@@ -1,4 +1,4 @@
-/* Synchronous subprocess invocation for XEmacs.
+/* Old synchronous subprocess invocation for XEmacs.
    Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
 
 This file is part of XEmacs.
@@ -21,6 +21,16 @@ Boston, MA 02111-1307, USA.  */
 /* Synched up with: Mule 2.0, FSF 19.30. */
 /* Partly sync'ed with 19.36.4 */
 
+
+/* #### This ENTIRE file is only used in batch mode.
+
+   We only need two things to get rid of both this and ntproc.c:
+
+   -- my `stderr-proc' ws, which adds support for a separate stderr
+      in asynch. subprocesses. (it's a feature in `old-call-process-internal'.)
+   -- a noninteractive event loop that supports processes.
+*/
+
 #include <config.h>
 #include "lisp.h"
 
@@ -37,7 +47,9 @@ Boston, MA 02111-1307, USA.  */
 
 #include "systime.h"
 #include "sysproc.h"
+#include "sysdir.h"
 #include "sysfile.h" /* Always include after sysproc.h */
+#include "sysdir.h"
 #include "syssignal.h" /* Always include before systty.h */
 #include "systty.h"
 
@@ -159,6 +171,8 @@ Arguments are
 The program's input comes from file INFILE (nil means `/dev/null').
 Insert output in BUFFER before point; t means current buffer;
  nil for BUFFER means discard it; 0 means discard and don't wait.
+If BUFFER is a string, then find or create a buffer with that name,
+then insert the output in that buffer, before point.
 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
 REAL-BUFFER says what to do with standard output, as above,
 while STDERR-FILE says what to do with standard error in the child.
@@ -221,8 +235,8 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you
        buffer's current directory.  We can't just have the child check
        for an error when it does the chdir, since it's in a vfork.  */
 
-    NGCPRO2 (current_dir, path);   /* Caller gcprotects args[] */
     current_dir = current_buffer->directory;
+    NGCPRO2 (current_dir, path);   /* Caller gcprotects args[] */
     current_dir = Funhandled_file_name_directory (current_dir);
     current_dir = expand_and_dir_to_file (current_dir, Qnil);
 #if 0
@@ -278,7 +292,7 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you
            || ZEROP (buffer)))
        {
          Lisp_Object spec_buffer = buffer;
-         buffer = Fget_buffer (buffer);
+         buffer = Fget_buffer_create (buffer);
          /* Mention the buffer name for a better error message.  */
          if (NILP (buffer))
            CHECK_BUFFER (spec_buffer);
@@ -331,9 +345,6 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you
     REGISTER char **save_environ = environ;
     REGISTER int fd1 = fd[1];
     int fd_error = fd1;
-    char **env;
-
-    env = environ;
 
     /* Record that we're about to create a synchronous process.  */
     synch_process_alive = 1;
@@ -388,9 +399,6 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you
          }
 #endif
       }
-    /* Close STDERR into the parent process.  We no longer need it. */
-    if (fd_error >= 0)
-      close (fd_error);
 #else  /* not WIN32_NATIVE */
     pid = fork ();
 
@@ -409,17 +417,18 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you
        child_setup (filefd, fd1, fd_error, new_argv,
                     (char *) XSTRING_DATA (current_dir));
       }
-    if (fd_error >= 0)
-      close (fd_error);
-
 #endif /* not WIN32_NATIVE */
 
     environ = save_environ;
 
+    /* Close STDERR into the parent process.  We no longer need it. */
+    if (fd_error >= 0)
+      close (fd_error);
+
     /* Close most of our fd's, but not fd[0]
        since we will use that to read input from.  */
     close (filefd);
-    if (fd1 >= 0)
+    if ((fd1 >= 0) && (fd1 != fd_error))
       close (fd1);
   }
 
@@ -452,7 +461,6 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you
 
   {
     int nread;
-    int first = 1;
     int total_read = 0;
     Lisp_Object instream;
     struct gcpro ngcpro1;
@@ -486,7 +494,7 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you
        nread = 0;
        while (nread < bufsize - 1024)
          {
-           ssize_t this_read
+           Lstream_data_count this_read
              = Lstream_read (XLSTREAM (instream), bufptr + nread,
                              bufsize - nread);
 
@@ -536,7 +544,6 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you
 
        if (!NILP (display) && INTERACTIVE)
          {
-           first = 0;
            redisplay ();
          }
       }
@@ -767,13 +774,14 @@ child_setup (int in, int out, int err, char **new_argv,
   close (out);
   close (err);
 
-  /* I can't think of any reason why child processes need any more
-     than the standard 3 file descriptors.  It would be cleaner to
+  /* Close non-process-related file descriptors. It would be cleaner to
      close just the ones that need to be, but the following brute
      force approach is certainly effective, and not too slow. */
+
   {
     int fd;
-    for (fd=3; fd<=64; fd++)
+
+    for (fd = 3; fd < MAXDESC; fd++)
       close (fd);
   }
 #endif /* not WIN32_NATIVE */
@@ -898,13 +906,40 @@ init_callproc (void)
   {
     /* Initialize shell-file-name from environment variables or best guess. */
 #ifdef WIN32_NATIVE
-    const char *shell = egetenv ("COMSPEC");
-    if (!shell) shell = "\\WINNT\\system32\\cmd.exe";
+    const char *shell = egetenv ("SHELL");
+    if (!shell) shell = egetenv ("COMSPEC");
+    /* Should never happen! */
+    if (!shell) shell = (GetVersion () & 0x80000000 ? "command" : "cmd");
 #else /* not WIN32_NATIVE */
     const char *shell = egetenv ("SHELL");
     if (!shell) shell = "/bin/sh";
 #endif
 
+#if 0 /* defined (WIN32_NATIVE) */
+    /* BAD BAD BAD.  We do not wanting to be passing an XEmacs-created
+       SHELL var down to some inferior Cygwin process, which might get
+       screwed up.
+        
+       There are a few broken apps (eterm/term.el, eterm/tshell.el,
+       os-utils/terminal.el, texinfo/tex-mode.el) where this will
+       cause problems.  Those broken apps don't look at
+       shell-file-name, instead just at explicit-shell-file-name,
+       ESHELL and SHELL.  They are apparently attempting to borrow
+       what `M-x shell' uses, but that latter also looks at
+       shell-file-name.  What we want is for all of these apps to look
+       at shell-file-name, so that the user can change the value of
+       shell-file-name and everything will work out hunky-dorey.
+       */
+    
+    if (!egetenv ("SHELL"))
+      {
+       CBufbyte *faux_var = alloca_array (CBufbyte, 7 + strlen (shell));
+       sprintf (faux_var, "SHELL=%s", shell);
+       Vprocess_environment = Fcons (build_string (faux_var),
+                                     Vprocess_environment);
+      }
+#endif /* 0 */
+
     Vshell_file_name = build_string (shell);
   }
 }