changeset 14408:9defc34879ad

(c-macro-preprocessor): Define a preprocessor name which is valid on MS-DOS. (c-macro-expansion): Do not rely on ``/tmp/'' being present; use environment variables as alternatives (MSDOS). Use `shell-file-name' rather than ``sh''. Redirect `stderr' with `call-process-region' option, not from the shell. Handle shells which don't return exit code from `cpp' (MSDOS). Put messages from `cpp' inside a comment, to avoid messing up syntax highlighting.
author Richard M. Stallman <rms@gnu.org>
date Mon, 29 Jan 1996 05:26:21 +0000
parents 78c37f6d697b
children 11a297676bda
files lisp/progmodes/cmacexp.el
diffstat 1 files changed, 27 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/progmodes/cmacexp.el	Mon Jan 29 04:53:39 1996 +0000
+++ b/lisp/progmodes/cmacexp.el	Mon Jan 29 05:26:21 1996 +0000
@@ -3,7 +3,7 @@
 ;; Copyright (C) 1992, 1994 Free Software Foundation, Inc.
 
 ;; Author: Francesco Potorti` <pot@cnuce.cnr.it>
-;; Version: $Id: cmacexp.el,v 1.20 1995/10/26 03:14:40 rms Exp erik $
+;; Version: $Id: cmacexp.el,v 1.21 1996/01/14 07:34:30 erik Exp rms $
 ;; Adapted-By: ESR
 ;; Keywords: c
 
@@ -96,7 +96,9 @@
 (defvar c-macro-prompt-flag nil
   "*Non-nil makes `c-macro-expand' prompt for preprocessor arguments.")
 
-(defvar c-macro-preprocessor "/lib/cpp -C"
+(defvar c-macro-preprocessor
+  ;; Cannot rely on standard directory on MS-DOS to find CPP.
+  (if (eq system-type 'ms-dos) "cpp -C" "/lib/cpp -C")
   "The preprocessor used by the cmacexp package.
 
 If you change this, be sure to preserve the `-C' (don't strip comments)
@@ -244,7 +246,8 @@
 	(startstat ())
 	(startmarker "")
 	(exit-status 0)
-	(tempname (make-temp-name "/tmp/")))
+	(tempname (make-temp-name (or (getenv "TMPDIR") (getenv "TEMP")
+				      (getenv "TMP") "/tmp/"))))
     (unwind-protect
 	(save-excursion
 	  (save-restriction
@@ -306,8 +309,10 @@
 	  ;; Call the preprocessor.
 	  (if display (message mymsg))
 	  (setq exit-status
-		(call-process-region 1 (point-max) "sh" t t nil "-c"
-				     (concat cppcommand " 2>" tempname)))
+		(call-process-region 1 (point-max)
+				     shell-file-name
+				     t (list t tempname) nil "-c"
+				     cppcommand))
 	  (if display (message (concat mymsg "done")))
 	  (if (= (buffer-size) 0)
 	      ;; Empty output is normal after a fatal error.
@@ -326,13 +331,25 @@
 	      (delete-region beg (point))))
 
 	  ;; If CPP got errors, show them at the beginning.
-	  (or (eq exit-status 0)
+	  ;; MS-DOS shells don't return the exit code of their children.
+	  ;; Look at the size of the error message file instead, but
+	  ;; don't punish those MS-DOS users who have a shell that does
+	  ;; return an error code.
+	  (or (and (or (not (boundp 'msdos-shells))
+		       (not (member (file-name-nondirectory shell-file-name)
+				    msdos-shells)))
+		   (eq exit-status 0))
+	      (zerop (nth 7 (file-attributes (expand-file-name tempname))))
 	      (progn
 		(goto-char (point-min))
-		(insert (format "Preprocessor terminated with status %s\n"
-				exit-status))
-		(insert-file-contents tempname)
-		(insert "\n")))
+		;; Put the messages inside a comment, so they won't get in
+		;; the way of font-lock, highlighting etc.
+		(insert
+		 (format "/* Preprocessor terminated with status %s\n\n   Messages from `%s\':\n\n"
+			 exit-status cppcommand))
+		(goto-char (+ (point)
+			      (nth 1 (insert-file-contents tempname))))
+		(insert "\n\n*/\n")))
 	  (delete-file tempname)
 
 	  ;; Compute the return value, keeping in account the space