Improve error messages by citing syntax in more of them.
[pspp] / src / language / stats / crosstabs.c
index 0b9d1519517b100f6e0376110ab3a91813a44a9d..1b203083e0768b6f738c7c7e67e8d2b5c1a277c3 100644 (file)
@@ -59,6 +59,7 @@
 #include "output/charts/barchart.h"
 
 #include "gl/minmax.h"
+#include "gl/xalloc-oversized.h"
 #include "gl/xalloc.h"
 #include "gl/xsize.h"
 
@@ -304,6 +305,7 @@ cmd_crosstabs (struct lexer *lexer, struct dataset *ds)
     .descending = false,
   };
   bool show_tables = true;
+  int exclude_ofs = 0;
   lex_match (lexer, T_SLASH);
   for (;;)
     {
@@ -315,12 +317,13 @@ cmd_crosstabs (struct lexer *lexer, struct dataset *ds)
       else if (lex_match_id (lexer, "MISSING"))
         {
           lex_match (lexer, T_EQUALS);
+          exclude_ofs = lex_ofs (lexer);
           if (lex_match_id (lexer, "TABLE"))
             proc.exclude = MV_ANY;
           else if (lex_match_id (lexer, "INCLUDE"))
             proc.exclude = MV_SYSTEM;
           else if (lex_match_id (lexer, "REPORT"))
-            proc.exclude = MV_NEVER;
+            proc.exclude = 0;
           else
             {
               lex_error (lexer, NULL);
@@ -469,10 +472,11 @@ cmd_crosstabs (struct lexer *lexer, struct dataset *ds)
   assert (proc.n_cells < CRS_N_CELLS);
 
   /* Missing values. */
-  if (proc.mode == GENERAL && proc.exclude == MV_NEVER)
+  if (proc.mode == GENERAL && !proc.exclude)
     {
-      msg (SE, _("Missing mode %s not allowed in general mode.  "
-                "Assuming %s."), "REPORT", "MISSING=TABLE");
+      lex_ofs_error (lexer, exclude_ofs, exclude_ofs,
+                     _("Missing mode %s not allowed in general mode.  "
+                       "Assuming %s."), "REPORT", "MISSING=TABLE");
       proc.exclude = MV_ANY;
     }
 
@@ -605,7 +609,7 @@ parse_crosstabs_tables (struct lexer *lexer, struct dataset *ds,
        }
     }
 
-  int *by_iter = xcalloc (n_by, sizeof *by_iter);
+  int *by_iter = XCALLOC (n_by, int);
   proc->pivots = xnrealloc (proc->pivots,
                             proc->n_pivots + nx, sizeof *proc->pivots);
   for (int i = 0; i < nx; i++)
@@ -655,7 +659,8 @@ parse_crosstabs_variables (struct lexer *lexer, struct dataset *ds,
 {
   if (proc->n_pivots)
     {
-      msg (SE, _("%s must be specified before %s."), "VARIABLES", "TABLES");
+      lex_next_error (lexer, -1, -1, _("%s must be specified before %s."),
+                      "VARIABLES", "TABLES");
       return false;
     }
 
@@ -744,7 +749,7 @@ should_tabulate_case (const struct crosstabulation *xt, const struct ccase *c,
       const struct variable *var = xt->vars[j].var;
       const struct var_range *range = get_var_range (xt->proc, var);
 
-      if (var_is_value_missing (var, case_data (c, var), exclude))
+      if (var_is_value_missing (var, case_data (c, var)) & exclude)
         return false;
 
       if (range != NULL)
@@ -911,7 +916,7 @@ postcalc (struct crosstabs_proc *proc)
       if (proc->barchart)
         {
           int n_vars = (xt->n_vars > 2 ? 2 : xt->n_vars);
-          const struct variable **vars = xcalloc (n_vars, sizeof *vars);
+          const struct variable **vars = XCALLOC (n_vars, const struct variable*);
           for (size_t i = 0; i < n_vars; i++)
             vars[i] = xt->vars[i].var;
           chart_submit (barchart_create (vars, n_vars, _("Count"),
@@ -1190,7 +1195,7 @@ output_crosstabulation (struct crosstabs_proc *proc, struct crosstabulation *xt)
       if (table)
         display_crosstabulation (proc, &x, table, crs_leaves);
 
-      if (proc->exclude == MV_NEVER)
+      if (proc->exclude == 0)
        delete_missing (&x);
 
       if (chisq)
@@ -1334,7 +1339,7 @@ add_var_dimension (struct pivot_table *table, const struct xtab_var *var,
     {
       struct pivot_value *value = pivot_value_new_var_value (
         var->var, &var->values[j]);
-      if (var_is_value_missing (var->var, &var->values[j], MV_ANY))
+      if (var_is_value_missing (var->var, &var->values[j]))
         pivot_value_add_footnote (value, missing_footnote);
       pivot_category_create_leaf (group, value);
     }
@@ -1561,7 +1566,7 @@ delete_missing (struct crosstabulation *xt)
 
   for (r = 0; r < n_rows; r++)
     if (var_is_num_missing (xt->vars[ROW_VAR].var,
-                            xt->vars[ROW_VAR].values[r].f, MV_USER))
+                            xt->vars[ROW_VAR].values[r].f) == MV_USER)
       {
         for (c = 0; c < n_cols; c++)
           xt->mat[c + r * n_cols] = 0.;
@@ -1571,7 +1576,7 @@ delete_missing (struct crosstabulation *xt)
 
   for (c = 0; c < n_cols; c++)
     if (var_is_num_missing (xt->vars[COL_VAR].var,
-                            xt->vars[COL_VAR].values[c].f, MV_USER))
+                            xt->vars[COL_VAR].values[c].f) == MV_USER)
       {
         for (r = 0; r < n_rows; r++)
           xt->mat[c + r * n_cols] = 0.;
@@ -1716,7 +1721,8 @@ display_crosstabulation (struct crosstabs_proc *proc,
           double expected_value = xt->row_tot[r] * xt->col_tot[c] / xt->total;
           double residual = *mp - expected_value;
           double sresidual = residual / sqrt (expected_value);
-          double asresidual = (sresidual
+          double asresidual
+            = residual / sqrt (expected_value
                                * (1. - xt->row_tot[r] / xt->total)
                                * (1. - xt->col_tot[c] / xt->total));
           double entries[CRS_N_CELLS] = {
@@ -1921,6 +1927,7 @@ display_risk (struct crosstabulation *xt, struct pivot_table *risk,
   union value c[2];
   if (!calc_risk (xt, risk_v, upper, lower, c, &n_valid))
     return;
+  assert (risk_statistics);
 
   size_t *indexes = xnmalloc (risk->n_dimensions, sizeof *indexes);
   assert (xt->n_vars == 2);
@@ -2955,9 +2962,3 @@ calc_directional (struct crosstabs_proc *proc, struct crosstabulation *xt,
 
   return 1;
 }
-
-/*
-   Local Variables:
-   mode: c
-   End:
-*/