Get rid of most global variables in outputting tables.
[pspp] / src / language / stats / crosstabs.q
index c18c3a960ec3c223c31292c642df72a102d0f4e4..29ed67e4f18673bcd525f904aa446cfaaa81eaa3 100644 (file)
@@ -161,41 +161,6 @@ struct pivot_table
     double total;              /* Grand total. */
   };
 
-/* A crosstabulation of exactly 2 variables, conditional on zero
-   or more other variables having given values. */
-struct crosstab
-  {
-    /* Case counts. */
-    double missing;
-
-    /* Variables. */
-    int n_vars;                        /* Number of variables (at least 2). */
-    const struct variable **vars;
-    union value *values;       /* Values of variables beyond 2. */
-
-    /* Data. */
-    struct table_entry **entries;
-    size_t n_entries;
-
-    /* Column values, number of columns. */
-    union value *cols;
-    int n_cols;
-
-    /* Row values, number of rows. */
-    union value *rows;
-    int n_rows;
-
-    /* Number of statistically interesting columns/rows
-       (columns/rows with data in them). */
-    int ns_cols, ns_rows;
-
-    /* Matrix contents. */
-    double *mat;               /* Matrix proper. */
-    double *row_tot;           /* Row totals. */
-    double *col_tot;           /* Column totals. */
-    double total;              /* Grand total. */
-  };
-
 /* Integer mode variable info. */
 struct var_range
   {
@@ -947,8 +912,7 @@ static void display_symmetric (struct crosstabs_proc *, struct pivot_table *,
 static void display_risk (struct pivot_table *, struct tab_table *);
 static void display_directional (struct crosstabs_proc *, struct pivot_table *,
                                  struct tab_table *);
-static void crosstabs_dim (struct tab_table *, struct outp_driver *,
-                           void *proc);
+static void crosstabs_dim (struct tab_rendering *, void *proc);
 static void table_value_missing (struct crosstabs_proc *proc,
                                  struct tab_table *table, int c, int r,
                                 unsigned char opt, const union value *v,
@@ -1028,22 +992,22 @@ output_pivot_table (struct crosstabs_proc *proc, struct pivot_table *pt)
       if (chisq)
         {
           display_dimensions (proc, &x, chisq, first_difference);
-          display_chisq (pt, chisq, &showed_fisher);
+          display_chisq (&x, chisq, &showed_fisher);
         }
       if (sym)
         {
           display_dimensions (proc, &x, sym, first_difference);
-          display_symmetric (proc, pt, sym);
+          display_symmetric (proc, &x, sym);
         }
       if (risk)
         {
           display_dimensions (proc, &x, risk, first_difference);
-          display_risk (pt, risk);
+          display_risk (&x, risk);
         }
       if (direct)
         {
           display_dimensions (proc, &x, direct, first_difference);
-          display_directional (proc, pt, direct);
+          display_directional (proc, &x, direct);
         }
 
       /* Free the parts of x that are not owned by pt.  In
@@ -1408,8 +1372,10 @@ submit (struct crosstabs_proc *proc, struct pivot_table *pt,
 /* Sets the widths of all the columns and heights of all the rows in
    table T for driver D. */
 static void
-crosstabs_dim (struct tab_table *t, struct outp_driver *d, void *proc_)
+crosstabs_dim (struct tab_rendering *r, void *proc_)
 {
+  const struct tab_table *t = r->table;
+  struct outp_driver *d = r->driver;
   struct crosstabs_proc *proc = proc_;
   int i;
 
@@ -1426,7 +1392,7 @@ crosstabs_dim (struct tab_table *t, struct outp_driver *d, void *proc_)
 
       w = d->width - c * (t->nc - t->l);
       for (i = 0; i <= t->nc; i++)
-        w -= t->wrv[i];
+        w -= r->wrv[i];
       w /= t->l;
 
       if (w < d->prop_em_width * 8)
@@ -1436,14 +1402,14 @@ crosstabs_dim (struct tab_table *t, struct outp_driver *d, void *proc_)
        w = d->prop_em_width * 15;
 
       for (i = 0; i < t->l; i++)
-       t->w[i] = w;
+       r->w[i] = w;
     }
 
   for (i = t->l; i < t->nc; i++)
-    t->w[i] = c;
+    r->w[i] = c;
 
   for (i = 0; i < t->nr; i++)
-    t->h[i] = tab_natural_height (t, d, i);
+    r->h[i] = tab_natural_height (r, i);
 }
 
 static bool