Fix error messages and comment.
[pspp-builds.git] / src / data / data-in.c
index aa8041d8a814b58c9dd11f94f509885a56c0585e..c5556a3c78694d0b939547d82ba0c812231be661 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <config.h>
 #include "data-in.h"
-#include "message.h"
+#include <libpspp/message.h>
 #include <math.h>
 #include <ctype.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdbool.h>
-#include "message.h"
+#include <libpspp/message.h>
 #include "calendar.h"
-#include "compiler.h"
+#include <libpspp/compiler.h>
 #include "identifier.h"
-#include "magic.h"
-#include "misc.h"
+#include <libpspp/magic.h>
+#include <libpspp/misc.h>
 #include "settings.h"
-#include "str.h"
+#include <libpspp/str.h>
 #include "variable.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
-
-#include "debug-print.h"
 \f
 /* Specialized error routine. */
 
@@ -50,26 +48,25 @@ static void dls_error (const struct data_in *, const char *format, ...)
 static void
 vdls_error (const struct data_in *i, const char *format, va_list args)
 {
-  struct error e;
-  struct string title;
+  struct msg m;
+  struct string text;
 
   if (i->flags & DI_IGNORE_ERROR)
     return;
 
-  ds_init (&title, 64);
+  ds_init_empty (&text);
   if (i->f1 == i->f2)
-    ds_printf (&title, _("(column %d"), i->f1);
+    ds_put_format (&text, _("(column %d"), i->f1);
   else
-    ds_printf (&title, _("(columns %d-%d"), i->f1, i->f2);
-  ds_printf (&title, _(", field type %s) "), fmt_to_string (&i->format));
-    
-  e.class = DE;
-  err_location (&e.where);
-  e.title = ds_c_str (&title);
+    ds_put_format (&text, _("(columns %d-%d"), i->f1, i->f2);
+  ds_put_format (&text, _(", field type %s) "), fmt_to_string (&i->format));
+  ds_put_vformat (&text, format, args);
 
-  err_vmsg (&e, format, args);
+  m.category = MSG_DATA;
+  m.severity = MSG_ERROR;
+  m.text = ds_cstr (&text);
 
-  ds_destroy (&title);
+  msg_emit (&m);
 }
 
 static void
@@ -96,7 +93,7 @@ trim_whitespace (struct data_in *i)
     i->e--;
 }
 
-/* Returns nonzero if we're not at the end of the string being
+/* Returns true if we're not at the end of the string being
    parsed. */
 static inline bool
 have_char (struct data_in *i)
@@ -570,10 +567,12 @@ parse_RB (struct data_in *i)
   return true;
 }
 
+
 static inline bool
 parse_A (struct data_in *i)
 {
   buf_copy_rpad (i->v->s, i->format.w, i->s, i->e - i->s);
+  
   return true;
 }
 
@@ -836,7 +835,8 @@ parse_trailer (struct data_in *i)
   if (!have_char (i))
     return true;
   
-  dls_error (i, _("Trailing garbage \"%s\" following date."), i->s);
+  dls_error (i, _("Trailing garbage \"%.*s\" following date."),
+             (int) (i->e - i->s), i->s);
   return false;
 }
 
@@ -1395,7 +1395,8 @@ data_in (struct data_in *i)
     }
   
   {
-    static bool (*const handlers[FMT_NUMBER_OF_FORMATS])(struct data_in *) = 
+    typedef bool (*handler_t) (struct data_in *);
+    static const handler_t handlers[FMT_NUMBER_OF_FORMATS] = 
       {
        parse_numeric, parse_N, parse_numeric, parse_numeric,
        parse_numeric, parse_numeric, parse_numeric,
@@ -1408,7 +1409,7 @@ data_in (struct data_in *i)
        parse_WKDAY, parse_MONTH,
       };
 
-    bool (*handler)(struct data_in *);
+    handler_t handler;
     bool success;
 
     handler = handlers[i->format.type];