- Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
-#include <libpspp/hash.h>
-#include <libpspp/pool.h>
+#include <data/procedure.h>
+#include <data/value-labels.h>
+#include <data/variable.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>
+write[wr_]=none,cells,all;
+format=fmt:!labels/nolabels/novallabs,
val:!avalue/dvalue,
+write[wr_]=none,cells,all;
+format=fmt:!labels/nolabels/novallabs,
val:!avalue/dvalue,
-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 postcalc (void *);
+static int internal_cmd_crosstabs (struct lexer *lexer, struct dataset *ds);
+static void precalc (const struct ccase *, void *, const struct dataset *);
+static bool calc_general (const struct ccase *, void *, const struct dataset *);
+static bool calc_integer (const struct ccase *, void *, const struct dataset *);
+static bool postcalc (void *, const struct dataset *);
static void submit (struct tab_table *);
static void format_short (char *s, const struct fmt_spec *fp,
static void submit (struct tab_table *);
static void format_short (char *s, const struct fmt_spec *fp,
- if (!lex_match_id ("TABLES")
- && (token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
- && token != T_ALL)
+ if (!lex_match_id (lexer, "TABLES")
+ && (lex_token (lexer) != T_ID || dict_lookup_var (dataset_dict (ds), lex_tokid (lexer)) == NULL)
+ && lex_token (lexer) != T_ALL)
assert (var_set != NULL);
for (n_by = 0; ;)
{
by = xnrealloc (by, n_by + 1, sizeof *by);
by_nvar = xnrealloc (by_nvar, n_by + 1, sizeof *by_nvar);
assert (var_set != NULL);
for (n_by = 0; ;)
{
by = xnrealloc (by, n_by + 1, sizeof *by);
by_nvar = xnrealloc (by_nvar, n_by + 1, sizeof *by_nvar);
- if (!parse_var_set_vars (var_set, &by[n_by], &by_nvar[n_by],
+ if (!parse_var_set_vars (lexer, var_set, &by[n_by], &by_nvar[n_by],
PV_NO_DUPLICATE | PV_NO_SCRATCH))
goto done;
if (xalloc_oversized (nx, by_nvar[n_by]))
PV_NO_DUPLICATE | PV_NO_SCRATCH))
goto done;
if (xalloc_oversized (nx, by_nvar[n_by]))
- if (!parse_variables (default_dict, &variables, &variables_cnt,
+ if (!parse_variables (lexer, dataset_dict (ds),
+ &variables, &variables_cnt,
-static int compare_table_entry (const void *, const void *, void *);
-static unsigned hash_table_entry (const void *, void *);
+static int compare_table_entry (const void *, const void *, const void *);
+static unsigned hash_table_entry (const void *, const void *);
if (mode == GENERAL)
{
gen_tab = hsh_create (512, compare_table_entry, hash_table_entry,
if (mode == GENERAL)
{
gen_tab = hsh_create (512, compare_table_entry, hash_table_entry,
n_sorted_tab + 1, sizeof *sorted_tab);
sorted_tab[n_sorted_tab] = NULL;
}
n_sorted_tab + 1, sizeof *sorted_tab);
sorted_tab[n_sorted_tab] = NULL;
}
for (j = 0; j < x->nvar; j++)
{
const union value *v = case_data (c, x->vars[j]->fv);
for (j = 0; j < x->nvar; j++)
{
const union value *v = case_data (c, x->vars[j]->fv);
te->values[j].f = case_num (c, x->vars[j]->fv);
else
{
memcpy (te->values[j].s, case_str (c, x->vars[j]->fv),
te->values[j].f = case_num (c, x->vars[j]->fv);
else
{
memcpy (te->values[j].s, case_str (c, x->vars[j]->fv),
- memset (&te->values[j].s[x->vars[j]->width], 0,
- sizeof (union value) - x->vars[j]->width);
+ memset (&te->values[j].s[var_get_width (x->vars[j])], 0,
+ sizeof (union value) - var_get_width (x->vars[j]));
- {
- assert (x->vars[i]->type == ALPHA);
- {
- const int diffstr = strncmp (a->values[i].s, b->values[i].s,
- x->vars[i]->width);
- if (diffstr)
- return diffstr;
- }
- }
+ {
+ const int diffstr = strncmp (a->values[i].s, b->values[i].s,
+ var_get_width (x->vars[i]));
+ if (diffstr)
+ return diffstr;
+ }
tab_headers (summary, 1, 0, 3, 0);
tab_joint_text (summary, 1, 0, 6, 0, TAB_CENTER, _("Cases"));
tab_joint_text (summary, 1, 1, 2, 1, TAB_CENTER, _("Valid"));
tab_headers (summary, 1, 0, 3, 0);
tab_joint_text (summary, 1, 0, 6, 0, TAB_CENTER, _("Cases"));
tab_joint_text (summary, 1, 1, 2, 1, TAB_CENTER, _("Valid"));
}
tab_text (t, 0, 0, TAB_LEFT, buf);
}
tab_text (t, 0, 0, TAB_LEFT, buf);
/* Number of variables from the crosstabulation to consider. This is
either x->nvar, if pivoting is on, or 2, if pivoting is off. */
/* Number of variables from the crosstabulation to consider. This is
either x->nvar, if pivoting is on, or 2, if pivoting is off. */
/* First header line. */
tab_joint_text (table, nvar - 1, 0, (nvar - 1) + (n_cols - 1), 0,
/* First header line. */
tab_joint_text (table, nvar - 1, 0, (nvar - 1) + (n_cols - 1), 0,
tab_hline (table, TAL_1, nvar - 1, nvar + n_cols - 2, 1);
tab_hline (table, TAL_1, nvar - 1, nvar + n_cols - 2, 1);
for (i = 2; i < nvar; i++)
tab_joint_text (table, nvar - i - 1, 0, nvar - i - 1, 1,
for (i = 2; i < nvar; i++)
tab_joint_text (table, nvar - i - 1, 0, nvar - i - 1, 1,
tab_text (table, nvar - 2, 1, TAB_RIGHT | TAT_TITLE,
tab_text (table, nvar - 2, 1, TAB_RIGHT | TAT_TITLE,
for (i = 0; i < n_cols; i++)
table_value_missing (table, nvar + i - 1, 1, TAB_RIGHT, &cols[i],
x->vars[COL_VAR]);
for (i = 0; i < n_cols; i++)
table_value_missing (table, nvar + i - 1, 1, TAB_RIGHT, &cols[i],
x->vars[COL_VAR]);
(pe - pb) / n_cols * 3 / 2 * N_CHISQ + 10, 1);
tab_headers (chisq, 1 + (nvar - 2), 0, 1, 0);
(pe - pb) / n_cols * 3 / 2 * N_CHISQ + 10, 1);
tab_headers (chisq, 1 + (nvar - 2), 0, 1, 0);
tab_offset (chisq, nvar - 2, 0);
tab_text (chisq, 0, 0, TAB_LEFT | TAT_TITLE, _("Statistic"));
tab_offset (chisq, nvar - 2, 0);
tab_text (chisq, 0, 0, TAB_LEFT | TAT_TITLE, _("Statistic"));
{
sym = tab_create (6 + (nvar - 2), (pe - pb) / n_cols * 7 + 10, 1);
tab_headers (sym, 2 + (nvar - 2), 0, 1, 0);
{
sym = tab_create (6 + (nvar - 2), (pe - pb) / n_cols * 7 + 10, 1);
tab_headers (sym, 2 + (nvar - 2), 0, 1, 0);
tab_offset (sym, nvar - 2, 0);
tab_text (sym, 0, 0, TAB_LEFT | TAT_TITLE, _("Category"));
tab_offset (sym, nvar - 2, 0);
tab_text (sym, 0, 0, TAB_LEFT | TAT_TITLE, _("Category"));
{
risk = tab_create (4 + (nvar - 2), (pe - pb) / n_cols * 4 + 10, 1);
tab_headers (risk, 1 + nvar - 2, 0, 2, 0);
{
risk = tab_create (4 + (nvar - 2), (pe - pb) / n_cols * 4 + 10, 1);
tab_headers (risk, 1 + nvar - 2, 0, 2, 0);
tab_offset (risk, nvar - 2, 0);
tab_joint_text (risk, 2, 0, 3, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF,
tab_offset (risk, nvar - 2, 0);
tab_joint_text (risk, 2, 0, 3, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF,
tab_text (risk, 0, 1, TAB_LEFT | TAT_TITLE, _("Statistic"));
tab_text (risk, 1, 1, TAB_RIGHT | TAT_TITLE, _("Value"));
tab_text (risk, 2, 1, TAB_RIGHT | TAT_TITLE, _("Lower"));
tab_text (risk, 0, 1, TAB_LEFT | TAT_TITLE, _("Statistic"));
tab_text (risk, 1, 1, TAB_RIGHT | TAT_TITLE, _("Value"));
tab_text (risk, 2, 1, TAB_RIGHT | TAT_TITLE, _("Lower"));
{
direct = tab_create (7 + (nvar - 2), (pe - pb) / n_cols * 7 + 10, 1);
tab_headers (direct, 3 + (nvar - 2), 0, 1, 0);
{
direct = tab_create (7 + (nvar - 2), (pe - pb) / n_cols * 7 + 10, 1);
tab_headers (direct, 3 + (nvar - 2), 0, 1, 0);
tab_offset (direct, nvar - 2, 0);
tab_text (direct, 0, 0, TAB_LEFT | TAT_TITLE, _("Category"));
tab_offset (direct, nvar - 2, 0);
tab_text (direct, 0, 0, TAB_LEFT | TAT_TITLE, _("Category"));
/* Allocate table space for the matrix. */
if (table && tab_row (table) + (n_rows + 1) * num_cells > tab_nr (table))
tab_realloc (table, -1,
/* Allocate table space for the matrix. */
if (table && tab_row (table) + (n_rows + 1) * num_cells > tab_nr (table))
tab_realloc (table, -1,
if (t != table)
for (i = 2; i < nvar; i++)
tab_text (t, nvar - i - 1, 0, TAB_RIGHT | TAT_TITLE,
if (t != table)
for (i = 2; i < nvar; i++)
tab_text (t, nvar - i - 1, 0, TAB_RIGHT | TAT_TITLE,
tab_box (t, TAL_2, TAL_2, -1, -1, 0, 0, tab_nc (t) - 1, tab_nr (t) - 1);
tab_box (t, -1, -1, -1, TAL_1, tab_l (t), tab_t (t) - 1, tab_nc (t) - 1,
tab_nr (t) - 1);
tab_box (t, TAL_2, TAL_2, -1, -1, 0, 0, tab_nc (t) - 1, tab_nr (t) - 1);
tab_box (t, -1, -1, -1, TAL_1, tab_l (t), tab_t (t) - 1, tab_nc (t) - 1,
tab_nr (t) - 1);
- tab_box (t, -1, -1, -1, TAL_1 | TAL_SPACING, 0, tab_t (t), tab_l (t) - 1,
+ tab_box (t, -1, -1, -1, TAL_GAP, 0, tab_t (t), tab_l (t) - 1,
tab_nr (t) - 1);
tab_vline (t, TAL_2, tab_l (t), 0, tab_nr (t) - 1);
tab_dim (t, crosstabs_dim);
tab_nr (t) - 1);
tab_vline (t, TAL_2, tab_l (t), 0, tab_nr (t) - 1);
tab_dim (t, crosstabs_dim);
result. WIDTH_ points to an int which is either 0 for a
numeric value or a string width for a string value. */
static int
result. WIDTH_ points to an int which is either 0 for a
numeric value or a string width for a string value. */
static int
table_value_missing (struct tab_table *table, int c, int r, unsigned char opt,
const union value *v, const struct variable *var)
{
table_value_missing (struct tab_table *table, int c, int r, unsigned char opt,
const union value *v, const struct variable *var)
{
- s.string = tab_alloc (table, var->print.w);
- format_short (s.string, &var->print, v);
+ s.string = tab_alloc (table, print->w);
+ format_short (s.string, print, v);
additionally suffixed with a letter `M'. */
static void
format_cell_entry (struct tab_table *table, int c, int r, double value,
additionally suffixed with a letter `M'. */
static void
format_cell_entry (struct tab_table *table, int c, int r, double value,
tab_hline (table, TAL_1, -1, n_cols, 0);
for (c = 0; c < n_cols; c++)
{
tab_hline (table, TAL_1, -1, n_cols, 0);
for (c = 0; c < n_cols; c++)
{
- && (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;
+ && (var_is_num_user_missing (x->vars[COL_VAR], cols[c].f)
+ || var_is_num_user_missing (x->vars[ROW_VAR], rows[r].f)))
+ mark_missing = true;
}
format_cell_entry (table, c, i, v, suffix, mark_missing);
}
format_cell_entry (table, c, i, v, suffix, mark_missing);
}
format_cell_entry (table, n_cols, 0, v, suffix, mark_missing);
}
format_cell_entry (table, n_cols, 0, v, suffix, mark_missing);
}
format_cell_entry (table, c, i, v, suffix, mark_missing);
}
format_cell_entry (table, c, i, v, suffix, mark_missing);
- x->vars[COL_VAR]->name,
- x->vars[COL_VAR]->width, c[0].s,
- x->vars[COL_VAR]->width, c[1].s);
+ var_get_name (x->vars[COL_VAR]),
+ var_get_width (x->vars[COL_VAR]), c[0].s,
+ var_get_width (x->vars[COL_VAR]), c[1].s);
- x->vars[ROW_VAR]->name,
- x->vars[ROW_VAR]->width, rows[i - 1].s);
+ var_get_name (x->vars[ROW_VAR]),
+ var_get_width (x->vars[ROW_VAR]), rows[i - 1].s);
tab_text (direct, j, 0, TAB_LEFT | TAT_PRINTF,
gettext (stats_names[j][k]), string);
tab_text (direct, j, 0, TAB_LEFT | TAT_PRINTF,
gettext (stats_names[j][k]), string);
swap (&a, &c), swap (&b, &d);
swap (&a, &c), swap (&b, &d);
swap (&a, &b), swap (&c, &d);
if (b * c < a * d)
{
swap (&a, &b), swap (&c, &d);
if (b * c < a * d)
{
{
double r, ase_0, ase_1;
calc_r ((double *) rows, (double *) cols, &r, &ase_0, &ase_1);
{
double r, ase_0, ase_1;
calc_r ((double *) rows, (double *) cols, &r, &ase_0, &ase_1);