CORRELATIONS: Improve error messages and coding style.
[pspp] / src / language / stats / matrix.c
index 01d448078752753109b18cdb32907dc14fe8f709..69c6323ef48152076b9c953bf2b4aaea13f2dc27 100644 (file)
@@ -6265,6 +6265,8 @@ matrix_save_parse (struct matrix_state *s)
   if (!save->expression)
     goto error;
 
+  int names_start = 0;
+  int names_end = 0;
   while (lex_match (s->lexer, T_SLASH))
     {
       if (lex_match_id (s->lexer, "OUTFILE"))
@@ -6302,7 +6304,9 @@ matrix_save_parse (struct matrix_state *s)
         {
           lex_match (s->lexer, T_EQUALS);
           matrix_expr_destroy (names);
+          names_start = lex_ofs (s->lexer);
           names = matrix_parse_exp (s);
+          names_end = lex_ofs (s->lexer) - 1;
           if (!names)
             goto error;
         }
@@ -6340,7 +6344,8 @@ matrix_save_parse (struct matrix_state *s)
 
   if (variables.n && names)
     {
-      msg (SW, _("VARIABLES and NAMES both specified; ignoring NAMES."));
+      lex_ofs_msg (s->lexer, SW, names_start, names_end,
+                   _("Ignoring NAMES because VARIABLES was also specified."));
       matrix_expr_destroy (names);
       names = NULL;
     }
@@ -7249,9 +7254,38 @@ matrix_write_parse (struct matrix_state *s)
       write->format = xmalloc (sizeof *write->format);
       *write->format = (struct fmt_spec) { .type = format, .w = w };
 
-      if (!fmt_check_output (write->format))
-        goto error;
-    };
+      char *error = fmt_check_output__ (write->format);
+      if (error)
+        {
+          msg (SE, "%s", error);
+          free (error);
+
+          if (has_format)
+            lex_ofs_msg (s->lexer, SN, format_ofs, format_ofs,
+                         _("This syntax specifies format %s."),
+                         fmt_name (format));
+
+          if (repetitions)
+            {
+              lex_ofs_msg (s->lexer, SN, format_ofs, format_ofs,
+                           ngettext ("This syntax specifies %d repetition.",
+                                     "This syntax specifies %d repetitions.",
+                                     repetitions),
+                           repetitions);
+              lex_ofs_msg (s->lexer, SN, record_width_start, record_width_end,
+                           _("This syntax designates record width %d, "
+                             "which divided by %d repetitions implies "
+                             "field width %d."),
+                           record_width, repetitions, w);
+            }
+
+          if (by)
+            lex_ofs_msg (s->lexer, SN, by_ofs, by_ofs,
+                         _("This syntax specifies field width %d."), by);
+
+          goto error;
+        }
+    }
 
   if (write->format && fmt_var_width (write->format) > sizeof (double))
     {