(msb--choose-menu): Fix error format string.
[bpt/emacs.git] / src / callproc.c
index ea995b6..9151f0d 100644 (file)
@@ -15,7 +15,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 
 #include <signal.h>
@@ -324,12 +325,6 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
   }
 
 #ifdef MSDOS /* MW, July 1993 */
-  /* These vars record information from process termination.
-     Clear them now before process can possibly terminate,
-     to avoid timing error if process terminates soon.  */
-  synch_process_death = 0;
-  synch_process_retcode = 0;
-
   if ((outf = egetenv ("TMP")) || (outf = egetenv ("TEMP")))
     strcpy (tempfile = alloca (strlen (outf) + 20), outf);
   else
@@ -349,6 +344,7 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
       close (filefd);
       report_file_error ("Opening process output file", Fcons (tempfile, Qnil));
     }
+  fd[1] = outfilefd;
 #endif
 
   if (INTEGERP (buffer))
@@ -388,21 +384,6 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
     synch_process_death = 0;
     synch_process_retcode = 0;
 
-#ifdef MSDOS /* MW, July 1993 */
-    /* ??? Someone who knows MSDOG needs to check whether this properly
-       closes all descriptors that it opens.  */
-    pid = run_msdos_command (new_argv, current_dir, filefd, outfilefd);
-    close (outfilefd);
-    fd1 = -1; /* No harm in closing that one!  */
-    fd[0] = open (tempfile, NILP (Vbinary_process_output) ? O_TEXT : O_BINARY);
-    if (fd[0] < 0)
-      {
-       unlink (tempfile);
-       close (filefd);
-       report_file_error ("Cannot re-open temporary file", Qnil);
-      }
-#else /* not MSDOS */
-
     if (NILP (error_file))
       fd_error = open (NULL_DEVICE, O_WRONLY);
     else if (STRINGP (error_file))
@@ -424,7 +405,35 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
          close (fd1);
        report_file_error ("Cannot open", error_file);
       }
+#ifdef MSDOS /* MW, July 1993 */
+    /* ??? Someone who knows MSDOG needs to check whether this properly
+       closes all descriptors that it opens.
 
+       Note that run_msdos_command() actually returns the child process
+       exit status, not its PID, so we assign it to `synch_process_retcode'
+       below.  */
+    pid = run_msdos_command (new_argv, current_dir,
+                            filefd, outfilefd, fd_error);
+
+    /* Record that the synchronous process exited and note its
+       termination status.  */
+    synch_process_alive = 0;
+    synch_process_retcode = pid;
+    if (synch_process_retcode < 0)  /* means it couldn't be exec'ed */
+      synch_process_death = strerror(errno);
+
+    close (outfilefd);
+    if (fd_error != outfilefd)
+      close (fd_error);
+    fd1 = -1; /* No harm in closing that one!  */
+    fd[0] = open (tempfile, NILP (Vbinary_process_output) ? O_TEXT : O_BINARY);
+    if (fd[0] < 0)
+      {
+       unlink (tempfile);
+       close (filefd);
+       report_file_error ("Cannot re-open temporary file", Qnil);
+      }
+#else /* not MSDOS */
 #ifdef WINDOWSNT
     pid = child_setup (filefd, fd1, fd_error, new_argv, 0, current_dir);
 #else  /* not WINDOWSNT */
@@ -441,8 +450,8 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
 #endif /* USG */
        child_setup (filefd, fd1, fd_error, new_argv, 0, current_dir);
       }
-#endif /* not MSDOS */
 #endif /* not WINDOWSNT */
+#endif /* not MSDOS */
 
     environ = save_environ;
 
@@ -501,7 +510,7 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
       {
        /* Repeatedly read until we've filled as much as possible
           of the buffer size we have.  But don't read
-          less than 1024--save that for the next bufferfull.  */
+          less than 1024--save that for the next bufferful.  */
 
        nread = 0;
        while (nread < bufsize - 1024)
@@ -647,10 +656,10 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
   end = args[1];
 #ifdef DOS_NT
   specbind (Qbuffer_file_type, Vbinary_process_input);
-  Fwrite_region (start, end, filename_string, Qnil, Qlambda);
+  Fwrite_region (start, end, filename_string, Qnil, Qlambda, Qnil);
   unbind_to (count, Qnil);
 #else  /* not DOS_NT */
-  Fwrite_region (start, end, filename_string, Qnil, Qlambda);
+  Fwrite_region (start, end, filename_string, Qnil, Qlambda, Qnil);
 #endif /* not DOS_NT */
 
   record_unwind_protect (delete_temp_file, filename_string);
@@ -995,7 +1004,7 @@ init_callproc_1 ()
   Vexec_path = nconc2 (decode_env_path ("PATH", ""), Vexec_path);
 }
 
-/* This is run after init_cmdargs, so that Vinvocation_directory is valid.  */
+/* This is run after init_cmdargs, when Vinstallation_directory is valid.  */
 
 init_callproc ()
 {
@@ -1017,21 +1026,20 @@ init_callproc ()
          Vexec_path = nconc2 (Vexec_path, Fcons (tem, Qnil));
          Vexec_directory = Ffile_name_as_directory (tem);
 #endif /* not DOS_NT */
+       }
 
-         /* If we use ../lib-src, maybe use ../etc as well.
-            Do so if ../etc exists and has our DOC-... file in it.  */
-         if (data_dir == 0)
-           {
-             tem = Fexpand_file_name (build_string ("etc"),
-                                      Vinstallation_directory);
-             Vdoc_directory = Ffile_name_as_directory (tem);
-           }
+      /* Maybe use ../etc as well as ../lib-src.  */
+      if (data_dir == 0)
+       {
+         tem = Fexpand_file_name (build_string ("etc"),
+                                  Vinstallation_directory);
+         Vdoc_directory = Ffile_name_as_directory (tem);
        }
     }
 
   /* Look for the files that should be in etc.  We don't use
      Vinstallation_directory, because these files are never installed
-     in /bin near the executable, and they are never in the build
+     near the executable, and they are never in the build
      directory when that's different from the source directory.
 
      Instead, if these files are not in the nominal place, we try the