GNU standards require "file name" instead of "filename" in
[pspp-builds.git] / src / message.c
index b77e7b627fe1e9eacb5eae6b3a110f1ebcee72f9..e6a8f76b11f346e96355053d8a0dc6b9bfea8e4d 100644 (file)
    02110-1301, USA. */
 
 #include <config.h>
-#include "message.h"
+#include <libpspp/message.h>
 #include <ctype.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include "alloc.h"
-#include "filename.h"
-#include "line-buffer.h"
-#include "lexer.h"
-#include "settings.h"
-#include "read-line.h"
-#include "version.h"
+#include <libpspp/alloc.h>
+#include <data/file-name.h>
+#include <language/line-buffer.h>
+#include <language/lexer/lexer.h>
+#include <data/settings.h>
+#include <ui/terminal/read-line.h>
+#include <libpspp/version.h>
+#include "progname.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -80,6 +81,23 @@ msg (int class, const char *format, ...)
   va_end (args);
 }
 
+/* Writes MESSAGE formatted with printf, to stderr, if the
+   verbosity level is at least LEVEL. */
+void
+verbose_msg (int level, const char *format, ...)
+{
+  if (err_verbosity >= level)
+    {
+      va_list args;
+  
+      va_start (args, format);
+      fprintf (stderr, "%s: ", program_name);
+      vfprintf (stderr, format, args);
+      putc ('\n', stderr);
+      va_end (args);
+    }
+}
+
 /* Checks whether we've had so many errors that it's time to quit
    processing this syntax file. */
 void
@@ -127,7 +145,7 @@ err_vmsg (const struct error *e, const char *format, va_list args)
   enum
     {
       ERR_IN_PROCEDURE = 01,   /* 1=Display name of current procedure. */
-      ERR_WITH_FILE = 02,      /* 1=Display filename and line number. */
+      ERR_WITH_FILE = 02,      /* 1=Display file name and line number. */
     };
 
   /* Describes one class of error. */
@@ -138,15 +156,12 @@ err_vmsg (const struct error *e, const char *format, va_list args)
       const char *banner;      /* Banner. */
     };
 
-  static const struct error_class error_classes[ERR_CLASS_COUNT] =
+  static const struct error_class error_classes[MSG_CLASS_CNT] =
     {
       {3, &err_error_count, N_("error")},      /* SE */
       {3, &err_warning_count, N_("warning")},  /* SW */
       {3, NULL, N_("note")},                   /* SM */
 
-      {0, NULL, N_("installation error")},     /* IE */
-      {2, NULL, N_("installation error")},     /* IS */
-
       {2, &err_error_count, N_("error")},      /* DE */
       {2, &err_warning_count, N_("warning")},  /* DW */
 
@@ -156,35 +171,29 @@ err_vmsg (const struct error *e, const char *format, va_list args)
     };
 
   struct string msg;
-  int class;
 
-  /* Check verbosity level. */
-  class = e->class;
-  if (((class >> ERR_VERBOSITY_SHIFT) & ERR_VERBOSITY_MASK) > err_verbosity)
-    return;
-  class &= ERR_CLASS_MASK;
-  
-  assert (class >= 0 && class < ERR_CLASS_COUNT);
+  assert (e->class >= 0 && e->class < MSG_CLASS_CNT);
   assert (format != NULL);
   
   ds_init (&msg, 64);
-  if (e->where.filename && (error_classes[class].flags & ERR_WITH_FILE))
+  if (e->where.file_name && (error_classes[e->class].flags & ERR_WITH_FILE))
     {
-      ds_printf (&msg, "%s:", e->where.filename);
+      ds_printf (&msg, "%s:", e->where.file_name);
       if (e->where.line_number != -1)
        ds_printf (&msg, "%d:", e->where.line_number);
       ds_putc (&msg, ' ');
     }
 
-  ds_printf (&msg, "%s: ", gettext (error_classes[class].banner));
+  ds_printf (&msg, "%s: ", gettext (error_classes[e->class].banner));
   
   {
-    int *count = error_classes[class].count;
+    int *count = error_classes[e->class].count;
     if (count)
       (*count)++;
   }
   
-  if (command_name != NULL && (error_classes[class].flags & ERR_IN_PROCEDURE))
+  if (command_name != NULL
+      && (error_classes[e->class].flags & ERR_IN_PROCEDURE))
     ds_printf (&msg, "%s: ", command_name);
 
   if (e->title)
@@ -234,8 +243,8 @@ compulsory_break(int c)
 static inline int
 char_is_break (int quote, int c)
 {
-  return ((quote && c == DIR_SEPARATOR)
-         || (!quote && (isspace (c) || c == '-' || c == '/'))); 
+  return ((quote && c == '/')
+          || (!quote && (isspace (c) || c == '-' || c == '/'))); 
 }
 
 /* Returns 1 if C is a break character where the break should be made