Closing bug #21760
[pspp] / src / ui / terminal / msg-ui.c
index b51a3e557021fe26f042ed3e610a4981a315fb3f..98f99c1c71cd8dae6002cef7eb7624403e24fc5d 100644 (file)
@@ -19,6 +19,7 @@
 #include "msg-ui.h"
 
 #include "linebreak.h"
+#include "localcharset.h"
 
 #include <libpspp/msg-locator.h>
 #include <libpspp/getl.h>
 #include <libpspp/message.h>
 #include <libpspp/str.h>
 #include <output/journal.h>
+#include <output/output.h>
+#include <output/table.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -172,11 +176,22 @@ handle_msg (const struct msg *m)
   ds_put_cstr (&string, m->text);
 
   if (msg_file != stdout || get_error_routing_to_terminal ())
-    dump_message (ds_cstr (&string), get_viewwidth (), 8,
+    dump_message (ds_cstr (&string),
+                  isatty (fileno (msg_file)) ? get_viewwidth () : INT_MAX, 8,
                   write_stream, msg_file);
 
   dump_message (ds_cstr (&string), 78, 0, write_journal, NULL);
 
+  if (get_error_routing_to_listing ())
+    {
+      /* Disable screen output devices, because the error should
+         already have been reported to the screen with the
+         dump_message call above. */
+      outp_enable_device (false, OUTP_DEV_SCREEN);
+      tab_output_text (TAB_LEFT, ds_cstr (&string));
+      outp_enable_device (true, OUTP_DEV_SCREEN);
+    }
+
   ds_destroy (&string);
 }