Greatly simplify PSPP configuration.
[pspp-builds.git] / src / ui / terminal / msg-ui.c
index fb0e7557e2e017da38c9b4c41f8715b3122a0ba2..b5280fe6bba980949083151ddefc99c82b544dab 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2010 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
 #include "msg-ui.h"
 
-#include "linebreak.h"
-#include "localcharset.h"
-
-#include <libpspp/msg-locator.h>
-#include <libpspp/getl.h>
 #include <data/settings.h>
+#include <libpspp/getl.h>
 #include <libpspp/message.h>
+#include <libpspp/msg-locator.h>
 #include <libpspp/str.h>
 #include <output/journal.h>
-#include <output/output.h>
-#include <output/table.h>
+#include <output/driver.h>
+#include <output/tab.h>
+
 #include <errno.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 
+#include "unilbrk.h"
+#include "localcharset.h"
+
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 #define N_(msgid) msgid
@@ -90,14 +92,15 @@ check_msg_count (struct source_stream *ss)
 {
   if (!getl_is_interactive (ss))
     {
-      if (settings_get_errorbreak () && error_count)
-        msg (MN, _("Terminating execution of syntax file due to error."));
-      else if (error_count > settings_get_mxerrs () )
-        msg (MN, _("Errors (%d) exceeds limit (%d)."),
-             error_count, settings_get_mxerrs ());
-      else if (error_count + warning_count > settings_get_mxwarns () )
+      int max_errors = settings_get_max_messages (MSG_S_ERROR);
+      int max_warnings = settings_get_max_messages (MSG_S_WARNING);
+
+      if (error_count > max_errors)
+        msg (MN, _("Errors (%d) exceed limit (%d)."),
+             error_count, max_errors);
+      else if (error_count + warning_count > max_warnings)
         msg (MN, _("Warnings (%d) exceed limit (%d)."),
-             error_count + warning_count, settings_get_mxwarns () );
+             error_count + warning_count, max_warnings);
       else
         return;
 
@@ -141,20 +144,22 @@ handle_msg (const struct msg *m)
 
   struct severity
     {
+      enum settings_output_type type;
       const char *name;         /* How to identify this severity. */
       int *count;               /* Number of msgs with this severity so far. */
     };
 
   static struct severity severities[] =
     {
-      {N_("error"), &error_count},          /* MSG_ERROR. */
-      {N_("warning"), &warning_count},      /* MSG_WARNING. */
-      {NULL, NULL},                         /* MSG_NOTE. */
+      { SETTINGS_OUTPUT_ERROR, N_("error"), &error_count },
+      { SETTINGS_OUTPUT_ERROR, N_("warning"), &warning_count },
+      { SETTINGS_OUTPUT_NOTE, NULL, NULL},
     };
 
   const struct category *category = &categories[m->category];
   const struct severity *severity = &severities[m->severity];
   struct string string = DS_EMPTY_INITIALIZER;
+  enum settings_output_devices routing;
 
   if (category->show_file_location && m->where.file_name)
     {
@@ -175,21 +180,22 @@ handle_msg (const struct msg *m)
 
   ds_put_cstr (&string, m->text);
 
-  if (msg_file != stdout || settings_get_error_routing_to_terminal ())
+  routing = settings_get_output_routing (severity->type);
+  if (msg_file != stdout || routing & SETTINGS_DEVICE_TERMINAL)
     dump_message (ds_cstr (&string),
                   isatty (fileno (msg_file)) ? settings_get_viewwidth () : INT_MAX, 8,
                   write_stream, msg_file);
 
   dump_message (ds_cstr (&string), 78, 0, write_journal, NULL);
 
-  if (settings_get_error_routing_to_listing ())
+  if (routing & SETTINGS_DEVICE_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);
+      /* Disable terminal output devices, because the error should already have
+         been reported to the terminal with the dump_message call above. */
+      settings_set_output_routing (severity->type,
+                                   routing & ~SETTINGS_DEVICE_TERMINAL);
       tab_output_text (TAB_LEFT, ds_cstr (&string));
-      outp_enable_device (true, OUTP_DEV_SCREEN);
+      settings_set_output_routing (severity->type, routing);
     }
 
   ds_destroy (&string);
@@ -224,7 +230,7 @@ dump_message (char *msg, unsigned width, unsigned indent,
   /* Break into lines. */
   if (indent > width / 3)
     indent = width / 3;
-  mbs_width_linebreaks (string, length,
+  ulc_width_linebreaks (string, length,
                         width - indent, -indent, 0,
                         NULL, locale_charset (), breaks);
 
@@ -267,7 +273,7 @@ write_stream (int line_indent, struct substring line, void *stream_)
 
 /* Writes LINE to the journal. */
 static void
-write_journal (int line_indent, struct substring line, void *unused UNUSED)
+write_journal (int line_indent UNUSED, struct substring line, void *unused UNUSED)
 {
   char *s = xstrndup (ss_data (line), ss_length (line));
   journal_write (true, s);