Continue reforming error message support. In this phase, rename
[pspp-builds.git] / src / language / data-io / data-list.c
index 59830347009e5005ffd5264f274b18d69a873f67..6002b1e91857e5e8787a176daadb812977a4d0c3 100644 (file)
    02110-1301, USA. */
 
 #include <config.h>
-#include "data-list.h"
-#include "message.h"
+#include <language/data-io/data-list.h>
+#include <libpspp/message.h>
 #include <ctype.h>
 #include <float.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include "alloc.h"
-#include "case.h"
-#include "command.h"
-#include "data-in.h"
-#include "debug-print.h"
-#include "data-reader.h"
-#include "dictionary.h"
-#include "message.h"
-#include "file-handle.h"
-#include "format.h"
-#include "lexer.h"
-#include "misc.h"
-#include "settings.h"
-#include "str.h"
-#include "table.h"
-#include "variable.h"
-#include "procedure.h"
+#include <libpspp/alloc.h>
+#include <data/case.h>
+#include <language/command.h>
+#include <libpspp/compiler.h>
+#include <data/data-in.h>
+#include <language/data-io/data-reader.h>
+#include <data/dictionary.h>
+#include <libpspp/message.h>
+#include <language/data-io/file-handle.h>
+#include <data/format.h>
+#include <language/lexer/lexer.h>
+#include <libpspp/misc.h>
+#include <data/settings.h>
+#include <libpspp/str.h>
+#include <output/table.h>
+#include <data/variable.h>
+#include <procedure.h>
+
+#include "data-list.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -96,6 +98,7 @@ struct data_list_pgm
 
 static const struct case_source_class data_list_source_class;
 
+static void rpd_msg (enum msg_class, const char *format, ...);
 static int parse_fixed (struct data_list_pgm *);
 static int parse_free (struct dls_var_spec **, struct dls_var_spec **);
 static void dump_fixed_table (const struct dls_var_spec *,
@@ -106,9 +109,6 @@ static void destroy_dls_var_spec (struct dls_var_spec *);
 static trns_free_func data_list_trns_free;
 static trns_proc_func data_list_trns_proc;
 
-/* Message title for REPEATING DATA. */
-#define RPD_ERR "REPEATING DATA: "
-
 int
 cmd_data_list (void)
 {
@@ -791,12 +791,12 @@ dump_fixed_table (const struct dls_var_spec *specs,
       tab_text (t, 1, i, TAT_PRINTF, "%d", spec->rec);
       tab_text (t, 2, i, TAT_PRINTF, "%3d-%3d",
                    spec->fc, spec->lc);
-      tab_text (t, 3, i, TAB_LEFT | TAT_FIX,
+      tab_text (t, 3, i, TAB_LEFT | TAB_FIX,
                    fmt_to_string (&spec->input));
     }
 
-  tab_title (t, 1, ngettext ("Reading %d record from %s.",
-                             "Reading %d records from %s.", rec_cnt),
+  tab_title (t, ngettext ("Reading %d record from %s.",
+                          "Reading %d records from %s.", rec_cnt),
              rec_cnt, fh_get_name (fh));
   tab_submit (t);
 }
@@ -907,11 +907,11 @@ dump_free_table (const struct data_list_pgm *dls,
     for (i = 1, spec = dls->first; spec; spec = spec->next, i++)
       {
        tab_text (t, 0, i, TAB_LEFT, spec->v->name);
-       tab_text (t, 1, i, TAB_LEFT | TAT_FIX, fmt_to_string (&spec->input));
+       tab_text (t, 1, i, TAB_LEFT | TAB_FIX, fmt_to_string (&spec->input));
       }
   }
 
-  tab_title (t, 1, _("Reading free-form data from %s."), fh_get_name (fh));
+  tab_title (t, _("Reading free-form data from %s."), fh_get_name (fh));
   
   tab_submit (t);
 }
@@ -1345,6 +1345,8 @@ static int parse_repeating_data (struct dls_var_spec **,
 static void find_variable_input_spec (struct variable *v,
                                      struct fmt_spec *spec);
 
+int cmd_repeating_data (void);
+
 /* Parses the REPEATING DATA command. */
 int
 cmd_repeating_data (void)
@@ -1810,9 +1812,10 @@ rpd_parse_record (const struct rpd_parse_info *info)
          data_out (actual_str, &t->id_var->print, id_temp);
           actual_str[t->id_var->print.w] = '\0';
            
-         tmsg (SE, RPD_ERR, 
-               _("Encountered mismatched record ID \"%s\" expecting \"%s\"."),
-               actual_str, expected_str);
+         rpd_msg (SE, 
+                   _("Encountered mismatched record ID \"%s\" "
+                     "expecting \"%s\"."),
+                   actual_str, expected_str);
 
          return 0;
        }
@@ -1842,10 +1845,10 @@ rpd_parse_record (const struct rpd_parse_info *info)
                {
                  warned = 1;
 
-                 tmsg (SW, RPD_ERR,
-                       _("Variable %s starting in column %d extends "
-                         "beyond physical record length of %d."),
-                       var_spec->v->name, fc, info->len);
+                 rpd_msg (SW,
+                           _("Variable %s starting in column %d extends "
+                             "beyond physical record length of %d."),
+                           var_spec->v->name, fc, info->len);
                }
              
              {
@@ -1910,46 +1913,45 @@ repeating_data_trns_proc (void *trns_, struct ccase *c, int case_num UNUSED)
   occurs_left = occurs = realize_value (&t->occurs, c);
   if (occurs <= 0)
     {
-      tmsg (SE, RPD_ERR, _("Invalid value %d for OCCURS."), occurs);
+      rpd_msg (SE, _("Invalid value %d for OCCURS."), occurs);
       return TRNS_NEXT_CASE;
     }
   starts_beg = realize_value (&t->starts_beg, c);
   if (starts_beg <= 0)
     {
-      tmsg (SE, RPD_ERR, _("Beginning column for STARTS (%d) must be "
-                           "at least 1."),
-            starts_beg);
+      rpd_msg (SE, _("Beginning column for STARTS (%d) must be at least 1."),
+               starts_beg);
       return TRNS_NEXT_CASE;
     }
   starts_end = realize_value (&t->starts_end, c);
   if (starts_end < starts_beg)
     {
-      tmsg (SE, RPD_ERR, _("Ending column for STARTS (%d) is less than "
-                           "beginning column (%d)."),
-            starts_end, starts_beg);
+      rpd_msg (SE, _("Ending column for STARTS (%d) is less than "
+                     "beginning column (%d)."),
+               starts_end, starts_beg);
       skip_first_record = 1;
     }
   length = realize_value (&t->length, c);
   if (length < 0)
     {
-      tmsg (SE, RPD_ERR, _("Invalid value %d for LENGTH."), length);
+      rpd_msg (SE, _("Invalid value %d for LENGTH."), length);
       length = 1;
       occurs = occurs_left = 1;
     }
   cont_beg = realize_value (&t->cont_beg, c);
   if (cont_beg < 0)
     {
-      tmsg (SE, RPD_ERR, _("Beginning column for CONTINUED (%d) must be "
-                           "at least 1."),
-            cont_beg);
+      rpd_msg (SE, _("Beginning column for CONTINUED (%d) must be "
+                     "at least 1."),
+               cont_beg);
       return TRNS_DROP_CASE;
     }
   cont_end = realize_value (&t->cont_end, c);
   if (cont_end < cont_beg)
     {
-      tmsg (SE, RPD_ERR, _("Ending column for CONTINUED (%d) is less than "
-                           "beginning column (%d)."),
-            cont_end, cont_beg);
+      rpd_msg (SE, _("Ending column for CONTINUED (%d) is less than "
+                     "beginning column (%d)."),
+               cont_end, cont_beg);
       return TRNS_DROP_CASE;
     }
 
@@ -1978,11 +1980,11 @@ repeating_data_trns_proc (void *trns_, struct ccase *c, int case_num UNUSED)
      continuation records. */
   if (occurs_left > 0 && cont_beg == 0)
     {
-      tmsg (SE, RPD_ERR,
-            _("Number of repetitions specified on OCCURS (%d) "
-              "exceed number of repetitions available in "
-              "space on STARTS (%d), and CONTINUED not specified."),
-            occurs, (starts_end - starts_beg + 1) / length);
+      rpd_msg (SE,
+               _("Number of repetitions specified on OCCURS (%d) "
+                 "exceed number of repetitions available in "
+                 "space on STARTS (%d), and CONTINUED not specified."),
+               occurs, (starts_end - starts_beg + 1) / length);
       return TRNS_DROP_CASE;
     }
 
@@ -1996,10 +1998,10 @@ repeating_data_trns_proc (void *trns_, struct ccase *c, int case_num UNUSED)
       /* Read in another record. */
       if (dfm_eof (t->reader))
         {
-          tmsg (SE, RPD_ERR,
-                _("Unexpected end of file with %d repetitions "
-                  "remaining out of %d."),
-                occurs_left, occurs);
+          rpd_msg (SE,
+                   _("Unexpected end of file with %d repetitions "
+                     "remaining out of %d."),
+                   occurs_left, occurs);
           return TRNS_DROP_CASE;
         }
       dfm_expand_tabs (t->reader);
@@ -2056,3 +2058,27 @@ repeating_data_set_write_case (struct transformation *trns_,
   t->write_case = write_case;
   t->wc_data = wc_data;
 }
+
+/* Reports a message in CLASS with the given FORMAT as text,
+   prefixing the message with "REPEATING DATA: " to make the
+   cause clear. */
+static void
+rpd_msg (enum msg_class class, const char *format, ...)
+{
+  struct msg m;
+  va_list args;
+  struct string text;
+
+  ds_create (&text, "REPEATING DATA: ");
+  va_start (args, format);
+  ds_vprintf (&text, format, args);
+  va_end (args);
+
+  m.category = msg_class_to_category (class);
+  m.severity = msg_class_to_severity (class);
+  m.where.file_name = NULL;
+  m.where.line_number = 0;
+  m.text = ds_c_str (&text);
+
+  msg_emit (&m);
+}