diff lisp/modes/cmacexp.el @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children 131b0175ea99
line wrap: on
line diff
--- a/lisp/modes/cmacexp.el	Mon Aug 13 08:45:53 2007 +0200
+++ b/lisp/modes/cmacexp.el	Mon Aug 13 08:46:35 2007 +0200
@@ -1,9 +1,9 @@
 ;;; cmacexp.el --- expand C macros in a region
 
-;; Copyright (C) 1992, 1994 Free Software Foundation, Inc.
+;; Copyright (C) 1992, 1994, 1996 Free Software Foundation, Inc.
 
 ;; Author: Francesco Potorti` <pot@cnuce.cnr.it>
-;; Version: cmacexp.el,v 1.20 1995/10/26 03:14:40 rms Exp
+;; Version: $Id: cmacexp.el,v 1.1.1.2 1996/12/18 03:44:32 steve Exp $
 ;; Adapted-By: ESR
 ;; Keywords: c
 
@@ -21,9 +21,10 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
-;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+;; 02111-1307, USA.
 
-;;; Synched up with: FSF 19.30.
+;;; Synched up with: FSF 19.34.
 
 ;; USAGE =============================================================
 
@@ -97,7 +98,15 @@
 (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.
+  (cond ((eq system-type 'ms-dos) "cpp -C")
+	;; Solaris has it in an unusual place.
+	((and (string-match "^[^-]*-[^-]*-\\(solaris\\|sunos5\\)"
+			    system-configuration)
+	      (file-exists-p "/opt/SUNWspro/SC3.0.1/bin/acomp"))
+	 "/opt/SUNWspro/SC3.0.1/bin/acomp -C -E")
+	(t "/lib/cpp -C"))
   "The preprocessor used by the cmacexp package.
 
 If you change this, be sure to preserve the `-C' (don't strip comments)
@@ -108,6 +117,7 @@
 
 (defconst c-macro-buffer-name "*Macroexpansion*")
 
+;; Autoload for XEmacs
 ;;;###autoload
 (defun c-macro-expand (start end subst)
   "Expand C macros in the region, using the C preprocessor.
@@ -202,6 +212,7 @@
 	    (setq minheight (if alreadythere
 				(window-height)
 			      window-min-height))
+	    ;; XEmacs change
 	    (setq maxheight (/ (screen-height) 2))
 	    (enlarge-window (- (min maxheight
 				    (max minheight
@@ -240,27 +251,31 @@
 		       c-macro-preprocessor
 		       (if (string= "" c-macro-cppflags) "" " ")
 		       c-macro-cppflags))
-	(uniquestring "???!!!???!!! start of c-macro expansion ???!!!???!!!")
+	(uniquestring "??? !!! ??? start of c-macro expansion ??? !!! ???")
 	(startlinenum 0)
 	(linenum 0)
 	(startstat ())
 	(startmarker "")
 	(exit-status 0)
-	(tempname (make-temp-name "/tmp/")))
+	(tempname (make-temp-name (concat
+				   (or (getenv "TMPDIR") (getenv "TEMP")
+				       (getenv "TMP") "/tmp")
+				   "/"))))
     (unwind-protect
 	(save-excursion
 	  (save-restriction
 	    (widen)
-	    (set-buffer outbuf)
-	    (setq buffer-read-only nil)
-	    (erase-buffer)
-	    (set-syntax-table c-mode-syntax-table)
+            (let ((in-syntax-table (syntax-table)))
+              (set-buffer outbuf)
+              (setq buffer-read-only nil)
+              (erase-buffer)
+              (set-syntax-table in-syntax-table))
 	    (insert-buffer-substring inbuf 1 end))
 
 	  ;; We have copied inbuf to outbuf.  Point is at end of
-	  ;; outbuf.  Insert a space at the end, so cpp can correctly
-	  ;; parse a token ending at END. 
-	  (insert " ")
+	  ;; outbuf.  Inset a newline at the end, so cpp can correctly
+	  ;; parse a token ending at END.
+          (insert "\n")
 
 	  ;; Save sexp status and line number at START.
 	  (setq startstat (parse-partial-sexp 1 start))
@@ -308,8 +323,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.
@@ -328,13 +345,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