X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Fcrosstabs.q;h=fcfccc39a251c2fbbfffbda7a6913207a70d1757;hb=e051d2cccc85e4ae2c46bddc7c674676ba7a5515;hp=3f140059fede345280ed5402e8bbcc01c5ac330f;hpb=f5c108becd49d78f4898cab11352291f5689d24e;p=pspp-builds.git diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index 3f140059..fcfccc39 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -1,20 +1,18 @@ -/* PSPP - computes sample statistics. +/* PSPP - a program for statistical analysis. Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ + along with this program. If not, see . */ /* FIXME: @@ -48,13 +46,10 @@ #include #include #include -#include #include #include #include #include -#include -#include #include #include #include @@ -63,6 +58,8 @@ #include #include "minmax.h" +#include "xalloc.h" +#include "xmalloca.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -193,11 +190,16 @@ int cmd_crosstabs (struct lexer *lexer, struct dataset *ds) { int result = internal_cmd_crosstabs (lexer, ds); + int i; free (variables); pool_destroy (pl_tc); pool_destroy (pl_col); + for (i = 0; i < nxtab; i++) + free (xtab[i]); + free (xtab); + return result; } @@ -358,7 +360,7 @@ crs_custom_tables (struct lexer *lexer, struct dataset *ds, struct cmd_crosstabs goto done; if (xalloc_oversized (nx, by_nvar[n_by])) { - msg (SE, _("Too many crosstabulation variables or dimensions.")); + msg (SE, _("Too many cross-tabulation variables or dimensions.")); goto done; } nx *= by_nvar[n_by]; @@ -518,10 +520,11 @@ precalc (struct casereader *input, const struct dataset *ds) { struct ccase c; - if (!casereader_peek (input, 0, &c)) - return; - output_split_file_values (ds, &c); - case_destroy (&c); + if (casereader_peek (input, 0, &c)) + { + output_split_file_values (ds, &c); + case_destroy (&c); + } if (mode == GENERAL) { @@ -549,7 +552,7 @@ precalc (struct casereader *input, const struct dataset *ds) sorted_tab = xnrealloc (sorted_tab, n_sorted_tab + count, sizeof *sorted_tab); - v = local_alloc (sizeof *v * x->nvar); + v = xmalloca (sizeof *v * x->nvar); for (j = 2; j < x->nvar; j++) v[j] = get_var_range (x->vars[j])->min; for (j = 0; j < count; j++) @@ -583,7 +586,7 @@ precalc (struct casereader *input, const struct dataset *ds) break; } } - local_free (v); + freea (v); } sorted_tab = xnrealloc (sorted_tab, @@ -613,7 +616,7 @@ calc_general (struct ccase *c, const struct dataset *ds) struct crosstab *x = xtab[t]; const size_t entry_size = (sizeof (struct table_entry) + sizeof (union value) * (x->nvar - 1)); - struct table_entry *te = local_alloc (entry_size); + struct table_entry *te = xmalloca (entry_size); /* Construct table entry for the current record and table. */ te->table = t; @@ -634,12 +637,14 @@ calc_general (struct ccase *c, const struct dataset *ds) te->values[j].f = case_num (c, x->vars[j]); else { - memcpy (te->values[j].s, case_str (c, x->vars[j]), - var_get_width (x->vars[j])); + size_t n = var_get_width (x->vars[j]); + if (n > MAX_SHORT_STRING) + n = MAX_SHORT_STRING; + memcpy (te->values[j].s, case_str (c, x->vars[j]), n); /* Necessary in order to simplify comparisons. */ memset (&te->values[j].s[var_get_width (x->vars[j])], 0, - sizeof (union value) - var_get_width (x->vars[j])); + sizeof (union value) - n); } } } @@ -662,7 +667,7 @@ calc_general (struct ccase *c, const struct dataset *ds) } next_crosstab: - local_free (te); + freea (te); } } @@ -824,6 +829,16 @@ postcalc (void) } hsh_destroy (gen_tab); + if (mode == INTEGER) + { + int i; + for (i = 0; i < n_sorted_tab; i++) + { + free (sorted_tab[i]->u.data); + free (sorted_tab[i]); + } + free (sorted_tab); + } } static void insert_summary (struct tab_table *, int tab_index, double valid); @@ -912,7 +927,7 @@ insert_summary (struct tab_table *t, int tab_index, double valid) /* Crosstabulation name. */ { - char *buf = local_alloc (128 * x->nvar); + char *buf = xmalloca (128 * x->nvar); char *cp = buf; int i; @@ -925,7 +940,7 @@ insert_summary (struct tab_table *t, int tab_index, double valid) } tab_text (t, 0, 0, TAB_LEFT, buf); - local_free (buf); + freea (buf); } /* Counts and percentages. */ @@ -1052,7 +1067,7 @@ output_pivot_table (struct table_entry **pb, struct table_entry **pe, /* Title. */ { - char *title = local_alloc (x->nvar * 64 + 128); + char *title = xmalloca (x->nvar * 64 + 128); char *cp = title; int i; @@ -1118,7 +1133,7 @@ output_pivot_table (struct table_entry **pb, struct table_entry **pe, strcpy (cp, "]."); tab_title (table, "%s", title); - local_free (title); + freea (title); } tab_offset (table, 0, 2); @@ -2722,8 +2737,8 @@ calc_symmetric (double v[N_SYMMETRIC], double ase[N_SYMMETRIC], /* Spearman correlation, Pearson's r. */ if (cmd.a_statistics[CRS_ST_CORR]) { - double *R = local_alloc (sizeof *R * n_rows); - double *C = local_alloc (sizeof *C * n_cols); + double *R = xmalloca (sizeof *R * n_rows); + double *C = xmalloca (sizeof *C * n_cols); { double y, t, c = 0., s = 0.; @@ -2762,8 +2777,8 @@ calc_symmetric (double v[N_SYMMETRIC], double ase[N_SYMMETRIC], calc_r (R, C, &v[6], &t[6], &ase[6]); t[6] = v[6] / t[6]; - local_free (R); - local_free (C); + freea (R); + freea (C); calc_r ((double *) rows, (double *) cols, &v[7], &t[7], &ase[7]); t[7] = v[7] / t[7];