Changed a lot of ints to bools.
[pspp-builds.git] / src / language / stats / crosstabs.q
index 8f1e42b430e37f38b8977f1b18bc7a09260562f3..4dca0b9b580993c0a9b82176a742c2ba3dcc5777 100644 (file)
 */
 
 #include <config.h>
-#include <libpspp/message.h>
+
 #include <ctype.h>
+#include <gsl/gsl_cdf.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <gsl/gsl_cdf.h>
-#include <libpspp/array.h>
-#include <libpspp/alloc.h>
+
 #include <data/case.h>
 #include <data/dictionary.h>
-#include <libpspp/hash.h>
-#include <libpspp/pool.h>
+#include <data/procedure.h>
+#include <data/value-labels.h>
+#include <data/variable.h>
 #include <language/command.h>
-#include <libpspp/compiler.h>
+#include <language/dictionary/split-file.h>
 #include <language/lexer/lexer.h>
-#include <libpspp/message.h>
+#include <language/lexer/variable-parser.h>
+#include <libpspp/alloc.h>
+#include <libpspp/array.h>
+#include <libpspp/assertion.h>
+#include <libpspp/compiler.h>
+#include <libpspp/hash.h>
 #include <libpspp/magic.h>
+#include <libpspp/message.h>
+#include <libpspp/message.h>
 #include <libpspp/misc.h>
-#include <output/output.h>
+#include <libpspp/pool.h>
 #include <libpspp/str.h>
+#include <output/output.h>
 #include <output/table.h>
-#include <data/value-labels.h>
-#include <data/variable.h>
-#include <procedure.h>
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -64,7 +69,7 @@
    crosstabs (crs_):
      *^tables=custom;
      +variables=custom;
-     +missing=miss:!table/include/report;
+     missing=miss:!table/include/report;
      +write[wr_]=none,cells,all;
      +format=fmt:!labels/nolabels/novallabs,
             val:!avalue/dvalue,
@@ -171,9 +176,9 @@ static struct pool *pl_tc;  /* For table cells. */
 static struct pool *pl_col;    /* For column data. */
 
 static int internal_cmd_crosstabs (void);
-static void precalc (void *);
-static bool calc_general (struct ccase *, void *);
-static bool calc_integer (struct ccase *, void *);
+static void precalc (const struct ccase *, void *);
+static bool calc_general (const struct ccase *, void *);
+static bool calc_integer (const struct ccase *, void *);
 static void postcalc (void *);
 static void submit (struct tab_table *);
 
@@ -207,7 +212,7 @@ internal_cmd_crosstabs (void)
   pl_tc = pool_create ();
   pl_col = pool_create ();
 
-  if (!parse_crosstabs (&cmd))
+  if (!parse_crosstabs (&cmd, NULL))
     return CMD_FAILURE;
 
   mode = variables ? INTEGER : GENERAL;
@@ -297,7 +302,7 @@ internal_cmd_crosstabs (void)
 
 /* Parses the TABLES subcommand. */
 static int
-crs_custom_tables (struct cmd_crosstabs *cmd UNUSED)
+crs_custom_tables (struct cmd_crosstabs *cmd UNUSED, void *aux UNUSED)
 {
   struct var_set *var_set;
   int n_by;
@@ -401,7 +406,7 @@ crs_custom_tables (struct cmd_crosstabs *cmd UNUSED)
 
 /* Parses the VARIABLES subcommand. */
 static int
-crs_custom_variables (struct cmd_crosstabs *cmd UNUSED)
+crs_custom_variables (struct cmd_crosstabs *cmd UNUSED, void *aux UNUSED)
 {
   if (nxtab)
     {
@@ -483,8 +488,9 @@ static unsigned hash_table_entry (const void *, void *);
 
 /* Set up the crosstabulation tables for processing. */
 static void
-precalc (void *aux UNUSED)
+precalc (const struct ccase *first, void *aux UNUSED)
 {
+  output_split_file_values (first);
   if (mode == GENERAL)
     {
       gen_tab = hsh_create (512, compare_table_entry, hash_table_entry,
@@ -556,9 +562,9 @@ precalc (void *aux UNUSED)
 
 /* Form crosstabulations for general mode. */
 static bool
-calc_general (struct ccase *c, void *aux UNUSED)
+calc_general (const struct ccase *c, void *aux UNUSED)
 {
-  int bad_warn = 1;
+  bool bad_warn = true;
 
   /* Case weight. */
   double weight = dict_get_case_weight (default_dict, c, &bad_warn);
@@ -630,9 +636,9 @@ calc_general (struct ccase *c, void *aux UNUSED)
 }
 
 static bool
-calc_integer (struct ccase *c, void *aux UNUSED)
+calc_integer (const struct ccase *c, void *aux UNUSED)
 {
-  int bad_warn = 1;
+  bool bad_warn = true;
 
   /* Case weight. */
   double weight = dict_get_case_weight (default_dict, c, &bad_warn);
@@ -1657,7 +1663,7 @@ static void
 table_value_missing (struct tab_table *table, int c, int r, unsigned char opt,
                     const union value *v, const struct variable *var)
 {
-  struct fixed_string s;
+  struct substring s;
 
   const char *label = val_labs_find (var->val_labs, *v);
   if (label) 
@@ -1696,15 +1702,15 @@ display_dimensions (struct tab_table *table, int first_difference, struct table_
 }
 
 /* Put VALUE into cell (C,R) of TABLE, suffixed with character
-   SUFFIX if nonzero.  If MARK_MISSING is nonzero the entry is
+   SUFFIX if nonzero.  If MARK_MISSING is true the entry is
    additionally suffixed with a letter `M'. */
 static void
 format_cell_entry (struct tab_table *table, int c, int r, double value,
-                   char suffix, int mark_missing)
+                   char suffix, bool mark_missing)
 {
   const struct fmt_spec f = {FMT_F, 10, 1};
   union value v;
-  struct fixed_string s;
+  struct substring s;
   
   s.length = 10;
   s.string = tab_alloc (table, 16);
@@ -1749,13 +1755,13 @@ display_crosstabulation (void)
          tab_hline (table, TAL_1, -1, n_cols, 0);
        for (c = 0; c < n_cols; c++)
          {
-            int mark_missing = 0;
+            bool mark_missing = false;
             double expected_value = row_tot[r] * col_tot[c] / W;
             if (cmd.miss == CRS_REPORT
                 && (mv_is_num_user_missing (&x->vars[COL_VAR]->miss, cols[c].f)
                     || mv_is_num_user_missing (&x->vars[ROW_VAR]->miss,
                                                rows[r].f)))
-              mark_missing = 1;
+              mark_missing = true;
            for (i = 0; i < num_cells; i++)
              {
                double v;
@@ -1794,8 +1800,7 @@ display_crosstabulation (void)
                                 * (1. - col_tot[c] / W)));
                    break;
                  default:
-                   assert (0);
-                    abort ();
+                    NOT_REACHED ();
                  }
 
                 format_cell_entry (table, c, i, v, suffix, mark_missing);
@@ -1816,11 +1821,11 @@ display_crosstabulation (void)
     for (r = 0; r < n_rows; r++) 
       {
         char suffix = 0;
-        int mark_missing = 0;
+        bool mark_missing = false;
 
         if (cmd.miss == CRS_REPORT
             && mv_is_num_user_missing (&x->vars[ROW_VAR]->miss, rows[r].f))
-          mark_missing = 1;
+          mark_missing = true;
 
         for (i = 0; i < num_cells; i++)
           {
@@ -1850,8 +1855,7 @@ display_crosstabulation (void)
                 v = 0.;
                 break;
               default:
-                assert (0);
-                abort ();
+                NOT_REACHED ();
               }
 
             format_cell_entry (table, n_cols, 0, v, suffix, mark_missing);
@@ -1870,13 +1874,13 @@ display_crosstabulation (void)
     for (c = 0; c <= n_cols; c++)
       {
        double ct = c < n_cols ? col_tot[c] : W;
-        int mark_missing = 0;
+        bool mark_missing = false;
         char suffix = 0;
         int i;
            
         if (cmd.miss == CRS_REPORT && c < n_cols 
             && mv_is_num_user_missing (&x->vars[COL_VAR]->miss, cols[c].f))
-          mark_missing = 1;
+          mark_missing = true;
 
         for (i = 0; i < num_cells; i++)
          {
@@ -1906,8 +1910,7 @@ display_crosstabulation (void)
              case CRS_CL_ASRESIDUAL:
                continue;
              default:
-               assert (0);
-                abort ();
+                NOT_REACHED ();
              }
 
             format_cell_entry (table, c, i, v, suffix, mark_missing);