import -ko -b 1.1.3 XEmacs XEmacs-21_2 r21-2-35
[chise/xemacs-chise.git-] / src / print.c
index dfe2e1c..f98c244 100644 (file)
@@ -38,11 +38,10 @@ Boston, MA 02111-1307, USA.  */
 #include "insdel.h"
 #include "lstream.h"
 #include "sysfile.h"
-#ifdef WINDOWSNT
+#ifdef WIN32_NATIVE
 #include "console-msw.h"
 #endif
 
-#include <limits.h>
 #include <float.h>
 /* Define if not in float.h */
 #ifndef DBL_DIG
@@ -106,6 +105,10 @@ FILE *termscript;  /* Stdio stream being used for copy of all output.  */
 
 int stdout_needs_newline;
 
+#ifdef WIN32_NATIVE
+static int no_useful_stderr;
+#endif
+
 static void
 std_handle_out_external (FILE *stream, Lisp_Object lstream,
                         const Extbyte *extptr, Extcount extlen,
@@ -116,16 +119,19 @@ std_handle_out_external (FILE *stream, Lisp_Object lstream,
 {
   if (stream)
     {
-#ifdef WINDOWSNT
+#ifdef WIN32_NATIVE
+      if (!no_useful_stderr)
+       no_useful_stderr = GetStdHandle (STD_ERROR_HANDLE) == 0 ? 1 : -1;
+
       /* we typically have no useful stdout/stderr under windows if we're
         being invoked graphically. */
-      if (!noninteractive)
-       msw_output_console_string (extptr, extlen);
+      if (!noninteractive || no_useful_stderr > 0)
+       mswindows_output_console_string (extptr, extlen);
       else
 #endif
        {
          fwrite (extptr, 1, extlen, stream);
-#ifdef WINDOWSNT
+#ifdef WIN32_NATIVE
          /* Q122442 says that pipes are "treated as files, not as
             devices", and that this is a feature. Before I found that
             article, I thought it was a bug. Thanks MS, I feel much
@@ -163,7 +169,7 @@ std_handle_out_external (FILE *stream, Lisp_Object lstream,
    called from fatal_error_signal().
 
    2) (to be really correct) make a new lstream that outputs using
-   msw_output_console_string().  */
+   mswindows_output_console_string().  */
 
 static int
 std_handle_out_va (FILE *stream, const char *fmt, va_list args)
@@ -174,9 +180,16 @@ std_handle_out_va (FILE *stream, const char *fmt, va_list args)
   int retval;
 
   retval = vsprintf ((char *) kludge, fmt, args);
-  TO_EXTERNAL_FORMAT (DATA, (kludge, strlen ((char *) kludge)),
-                     ALLOCA, (extptr, extlen),
-                     Qnative);
+  if (initialized && !fatal_error_in_progress)
+    TO_EXTERNAL_FORMAT (DATA, (kludge, strlen ((char *) kludge)),
+                       ALLOCA, (extptr, extlen),
+                       Qnative);
+  else
+    {
+      extptr = (Extbyte *) kludge;
+      extlen = (Extcount) strlen ((char *) kludge);
+    }
+  
   std_handle_out_external (stream, Qnil, extptr, extlen, 1, 1);
   return retval;
 }
@@ -190,7 +203,10 @@ stderr_out (const char *fmt, ...)
   int retval;
   va_list args;
   va_start (args, fmt);
-  retval = std_handle_out_va (stderr, GETTEXT (fmt), args);
+  retval =
+    std_handle_out_va
+    (stderr, initialized && !fatal_error_in_progress ? GETTEXT (fmt) : fmt,
+     args);
   va_end (args);
   return retval;
 }
@@ -204,7 +220,10 @@ stdout_out (const char *fmt, ...)
   int retval;
   va_list args;
   va_start (args, fmt);
-  retval = std_handle_out_va (stdout, GETTEXT (fmt), args);
+  retval =
+    std_handle_out_va
+    (stdout, initialized && !fatal_error_in_progress ? GETTEXT (fmt) : fmt,
+     args);
   va_end (args);
   return retval;
 }
@@ -914,10 +933,8 @@ float_to_string (char *buf, double data)
 }
 #endif /* LISP_FLOAT_TYPE */
 
-/* Print NUMBER to BUFFER.  The digits are first written in reverse
-   order (the least significant digit first), and are then reversed.
-   This is equivalent to sprintf(buffer, "%ld", number), only much
-   faster.
+/* Print NUMBER to BUFFER.  This is equivalent to sprintf(buffer,
+   "%ld", number), only much faster.
 
    BUFFER should accept 24 bytes.  This should suffice for the longest
    numbers on 64-bit machines, including the `-' sign and the trailing
@@ -1539,7 +1556,7 @@ This function can be used as the STREAM argument of Fprint() or the like.
 
 Under MS Windows, this writes output to the console window (which is
 created, if necessary), unless XEmacs is being run noninteractively
-(i.e. using the `-batch' argument).
+\(i.e. using the `-batch' argument).
 
 If you have opened a termscript file (using `open-termscript'), then
 the output also will be logged to this file.