X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmatrix-data.c;h=ee43d82f2ba2df94bc8cc94b9cd4119e5d8213ad;hb=5ff91bd55867848d448c2f09bc7057cc1fb77b18;hp=e90aef0955ed5872509a27a4a7726912320346df;hpb=06f9ee45954e5e71fa7f6262dbf37defa1dbf996;p=pspp diff --git a/src/matrix-data.c b/src/matrix-data.c index e90aef0955..ee43d82f2b 100644 --- a/src/matrix-data.c +++ b/src/matrix-data.c @@ -14,8 +14,8 @@ 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., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ #include #include "error.h" @@ -27,7 +27,8 @@ #include "case.h" #include "command.h" #include "data-in.h" -#include "dfm.h" +#include "dfm-read.h" +#include "dictionary.h" #include "error.h" #include "file-handle.h" #include "lexer.h" @@ -37,11 +38,27 @@ #include "var.h" #include "vfm.h" +#include "gettext.h" +#define _(msgid) gettext (msgid) + #include "debug-print.h" /* FIXME: /N subcommand not implemented. It should be pretty simple, too. */ +/* Different types of variables for MATRIX DATA procedure. Order is + important: these are used for sort keys. */ +enum + { + MXD_SPLIT, /* SPLIT FILE variables. */ + MXD_ROWTYPE, /* ROWTYPE_. */ + MXD_FACTOR, /* Factor variables. */ + MXD_VARNAME, /* VARNAME_. */ + MXD_CONTINUOUS, /* Continuous variables. */ + + MXD_COUNT + }; + /* Format type enums. */ enum format_type { @@ -102,7 +119,7 @@ static const char *content_names[PROX + 1] = struct matrix_data_pgm { struct pool *container; /* Arena used for all allocations. */ - struct file_handle *data_file; /* The data file to be read. */ + struct dfm_reader *reader; /* Data file to read. */ /* Format. */ enum format_type fmt; /* LIST or FREE. */ @@ -115,7 +132,7 @@ struct matrix_data_pgm struct variable *single_split; /* Single SPLIT FILE variable. */ /* Factor variables. */ - int n_factors; /* Number of factor variables. */ + size_t n_factors; /* Number of factor variables. */ struct variable **factors; /* Factor variables. */ int is_per_factor[PROX + 1]; /* Is there per-factor data? */ @@ -133,21 +150,30 @@ struct matrix_data_pgm first continuous variable. */ }; +/* Auxiliary data attached to MATRIX DATA variables. */ +struct mxd_var + { + int var_type; /* Variable type. */ + int sub_type; /* Subtype. */ + }; + static const struct case_source_class matrix_data_with_rowtype_source_class; static const struct case_source_class matrix_data_without_rowtype_source_class; -static int compare_variables_by_mxd_vartype (const void *pa, +static int compare_variables_by_mxd_var_type (const void *pa, const void *pb); static void read_matrices_without_rowtype (struct matrix_data_pgm *); static void read_matrices_with_rowtype (struct matrix_data_pgm *); static int string_to_content_type (char *, int *); +static void attach_mxd_aux (struct variable *, int var_type, int sub_type); int cmd_matrix_data (void) { struct pool *pool; struct matrix_data_pgm *mx; - + struct file_handle *fh = NULL; + unsigned seen = 0; discard_variables (); @@ -155,7 +181,7 @@ cmd_matrix_data (void) pool = pool_create (); mx = pool_alloc (pool, sizeof *mx); mx->container = pool; - mx->data_file = inline_file; + mx->reader = NULL; mx->fmt = LIST; mx->section = LOWER; mx->diag = DIAGONAL; @@ -178,7 +204,7 @@ cmd_matrix_data (void) if (lex_match_id ("VARIABLES")) { char **v; - int nv; + size_t nv; if (seen & 1) { @@ -192,10 +218,10 @@ cmd_matrix_data (void) goto lossage; { - int i; + size_t i; for (i = 0; i < nv; i++) - if (!strcmp (v[i], "VARNAME_")) + if (!strcasecmp (v[i], "VARNAME_")) { msg (SE, _("VARNAME_ cannot be explicitly specified on " "VARIABLES.")); @@ -207,18 +233,17 @@ cmd_matrix_data (void) } { - int i; + size_t i; for (i = 0; i < nv; i++) { struct variable *new_var; - if (strcmp (v[i], "ROWTYPE_")) + if (strcasecmp (v[i], "ROWTYPE_")) { new_var = dict_create_var_assert (default_dict, v[i], 0); - new_var->p.mxd.vartype = MXD_CONTINUOUS; - new_var->p.mxd.subtype = i; - } + attach_mxd_aux (new_var, MXD_CONTINUOUS, i); + } else mx->explicit_rowtype = 1; free (v[i]); @@ -226,18 +251,15 @@ cmd_matrix_data (void) free (v); } - { - mx->rowtype_ = dict_create_var_assert (default_dict, - "ROWTYPE_", 8); - mx->rowtype_->p.mxd.vartype = MXD_ROWTYPE; - mx->rowtype_->p.mxd.subtype = 0; - } + mx->rowtype_ = dict_create_var_assert (default_dict, + "ROWTYPE_", 8); + attach_mxd_aux (mx->rowtype_, MXD_ROWTYPE, 0); } else if (lex_match_id ("FILE")) { lex_match ('='); - mx->data_file = fh_parse_file_handle (); - if (mx->data_file == NULL) + fh = fh_parse (); + if (fh == NULL) goto lossage; } else if (lex_match_id ("FORMAT")) @@ -287,7 +309,8 @@ cmd_matrix_data (void) if (dict_lookup_var (default_dict, tokid) == NULL && (lex_look_ahead () == '.' || lex_look_ahead () == '/')) { - if (!strcmp (tokid, "ROWTYPE_") || !strcmp (tokid, "VARNAME_")) + if (!strcasecmp (tokid, "ROWTYPE_") + || !strcasecmp (tokid, "VARNAME_")) { msg (SE, _("Split variable may not be named ROWTYPE_ " "or VARNAME_.")); @@ -296,16 +319,15 @@ cmd_matrix_data (void) mx->single_split = dict_create_var_assert (default_dict, tokid, 0); + attach_mxd_aux (mx->single_split, MXD_CONTINUOUS, 0); lex_get (); - mx->single_split->p.mxd.vartype = MXD_CONTINUOUS; - dict_set_split_vars (default_dict, &mx->single_split, 1); } else { struct variable **split; - int n; + size_t n; if (!parse_variables (default_dict, &split, &n, PV_NO_DUPLICATE)) goto lossage; @@ -320,14 +342,16 @@ cmd_matrix_data (void) for (i = 0; i < split_cnt; i++) { - if (split[i]->p.mxd.vartype != MXD_CONTINUOUS) + struct mxd_var *mv = split[i]->aux; + assert (mv != NULL); + if (mv->var_type != MXD_CONTINUOUS) { msg (SE, _("Split variable %s is already another type."), tokid); goto lossage; } - split[i]->p.mxd.vartype = MXD_SPLIT; - split[i]->p.mxd.subtype = i; + var_clear_aux (split[i]); + attach_mxd_aux (split[i], MXD_SPLIT, i); } } } @@ -342,22 +366,26 @@ cmd_matrix_data (void) } seen |= 4; - if (!parse_variables (default_dict, &mx->factors, &mx->n_factors, PV_NONE)) + if (!parse_variables (default_dict, &mx->factors, &mx->n_factors, + PV_NONE)) goto lossage; { - int i; + size_t i; for (i = 0; i < mx->n_factors; i++) { - if (mx->factors[i]->p.mxd.vartype != MXD_CONTINUOUS) + struct variable *v = mx->factors[i]; + struct mxd_var *mv = v->aux; + assert (mv != NULL); + if (mv->var_type != MXD_CONTINUOUS) { msg (SE, _("Factor variable %s is already another type."), tokid); goto lossage; } - mx->factors[i]->p.mxd.vartype = MXD_FACTOR; - mx->factors[i]->p.mxd.subtype = i; + var_clear_aux (v); + attach_mxd_aux (v, MXD_FACTOR, i); } } } @@ -371,7 +399,7 @@ cmd_matrix_data (void) goto lossage; } - if (!lex_integer_p () || lex_integer () < 1) + if (!lex_is_integer () || lex_integer () < 1) { lex_error (_("expecting positive integer")); goto lossage; @@ -390,7 +418,7 @@ cmd_matrix_data (void) goto lossage; } - if (!lex_integer_p () || lex_integer () < 1) + if (!lex_is_integer () || lex_integer () < 1) { lex_error (_("expecting positive integer")); goto lossage; @@ -537,11 +565,8 @@ cmd_matrix_data (void) } /* Create VARNAME_. */ - { - mx->varname_ = dict_create_var_assert (default_dict, "VARNAME_", 8); - mx->varname_->p.mxd.vartype = MXD_VARNAME; - mx->varname_->p.mxd.subtype = 0; - } + mx->varname_ = dict_create_var_assert (default_dict, "VARNAME_", 8); + attach_mxd_aux (mx->varname_, MXD_VARNAME, 0); /* Sort the dictionary variables into the desired order for the system file output. */ @@ -550,7 +575,7 @@ cmd_matrix_data (void) size_t nv; dict_get_vars (default_dict, &v, &nv, 0); - qsort (v, nv, sizeof *v, compare_variables_by_mxd_vartype); + qsort (v, nv, sizeof *v, compare_variables_by_mxd_var_type); dict_reorder_vars (default_dict, v, nv); free (v); } @@ -572,7 +597,8 @@ cmd_matrix_data (void) for (i = 0; i < dict_get_var_cnt (default_dict); i++) { struct variable *v = dict_get_var (default_dict, i); - int type = v->p.mxd.vartype; + struct mxd_var *mv = v->aux; + int type = mv->var_type; assert (type >= 0 && type < MXD_COUNT); v->print = v->write = fmt_tab[type]; @@ -590,7 +616,8 @@ cmd_matrix_data (void) goto lossage; } - if (!dfm_open_for_reading (mx->data_file)) + mx->reader = dfm_open_reader (fh); + if (mx->reader == NULL) goto lossage; if (mx->explicit_rowtype) @@ -598,6 +625,8 @@ cmd_matrix_data (void) else read_matrices_without_rowtype (mx); + dfm_close_reader (mx->reader); + pool_destroy (mx->container); return CMD_SUCCESS; @@ -644,7 +673,7 @@ string_to_content_type (char *s, int *collide) }; for (tp = tab; tp->value != -1; tp++) - if (!strcmp (s, tp->string)) + if (!strcasecmp (s, tp->string)) { if (collide) *collide = tp->collide; @@ -654,20 +683,34 @@ string_to_content_type (char *s, int *collide) return -1; } -/* Compare two variables using p.mxd.vartype and p.mxd.subtype +/* Compare two variables using p.mxd.var_type and p.mxd.sub_type fields. */ static int -compare_variables_by_mxd_vartype (const void *a_, const void *b_) +compare_variables_by_mxd_var_type (const void *a_, const void *b_) { struct variable *const *pa = a_; struct variable *const *pb = b_; - const struct matrix_data_proc *a = &(*pa)->p.mxd; - const struct matrix_data_proc *b = &(*pb)->p.mxd; - - if (a->vartype != b->vartype) - return a->vartype > b->vartype ? 1 : -1; + const struct mxd_var *a = (*pa)->aux; + const struct mxd_var *b = (*pb)->aux; + + if (a->var_type != b->var_type) + return a->var_type > b->var_type ? 1 : -1; else - return a->subtype < b->subtype ? -1 : a->subtype > b->subtype; + return a->sub_type < b->sub_type ? -1 : a->sub_type > b->sub_type; +} + +/* Attaches a struct mxd_var with the specific member values to + V. */ +static void +attach_mxd_aux (struct variable *v, int var_type, int sub_type) +{ + struct mxd_var *mv; + + assert (v->aux == NULL); + mv = xmalloc (sizeof *mv); + mv->var_type = var_type; + mv->sub_type = sub_type; + var_attach_aux (v, mv, var_dtor_free); } /* Matrix tokenizer. */ @@ -688,10 +731,10 @@ struct matrix_token int length; /* MSTR: tokstr length. */ }; -static int mget_token (struct matrix_token *, struct file_handle *); +static int mget_token (struct matrix_token *, struct dfm_reader *); #if DEBUGGING -#define mget_token(TOKEN, HANDLE) mget_token_dump(TOKEN, HANDLE) +#define mget_token(TOKEN, READER) mget_token_dump(TOKEN, READER) static void mdump_token (const struct matrix_token *token) @@ -711,28 +754,28 @@ mdump_token (const struct matrix_token *token) } static int -mget_token_dump (struct matrix_token *token, struct file_handle *data_file) +mget_token_dump (struct matrix_token *token, struct dfm_reader *reader) { - int result = (mget_token) (token, data_file); + int result = (mget_token) (token, reader); mdump_token (token); return result; } #endif -/* Return the current position in DATA_FILE. */ +/* Return the current position in READER. */ static const char * -context (struct file_handle *data_file) +context (struct dfm_reader *reader) { static char buf[32]; - if (dfm_eof (data_file)) + if (dfm_eof (reader)) strcpy (buf, "at end of file"); else { - struct len_string line; + struct fixed_string line; const char *sp; - dfm_get_record (data_file, &line); + dfm_get_record (reader, &line); sp = ls_c_str (&line); while (sp < ls_end (&line) && isspace ((unsigned char) *sp)) sp++; @@ -759,16 +802,16 @@ context (struct file_handle *data_file) /* Is there at least one token left in the data file? */ static int -another_token (struct file_handle *data_file) +another_token (struct dfm_reader *reader) { for (;;) { - struct len_string line; + struct fixed_string line; const char *cp; - if (dfm_eof (data_file)) + if (dfm_eof (reader)) return 0; - dfm_get_record (data_file, &line); + dfm_get_record (reader, &line); cp = ls_c_str (&line); while (isspace ((unsigned char) *cp) && cp < ls_end (&line)) @@ -776,27 +819,27 @@ another_token (struct file_handle *data_file) if (cp < ls_end (&line)) { - dfm_forward_columns (data_file, cp - ls_c_str (&line)); + dfm_forward_columns (reader, cp - ls_c_str (&line)); return 1; } - dfm_forward_record (data_file); + dfm_forward_record (reader); } } -/* Parse a MATRIX DATA token from mx->data_file into TOKEN. */ +/* Parse a MATRIX DATA token from READER into TOKEN. */ static int -(mget_token) (struct matrix_token *token, struct file_handle *data_file) +(mget_token) (struct matrix_token *token, struct dfm_reader *reader) { - struct len_string line; + struct fixed_string line; int first_column; char *cp; - if (!another_token (data_file)) + if (!another_token (reader)) return 0; - dfm_get_record (data_file, &line); - first_column = dfm_column_start (data_file); + dfm_get_record (reader, &line); + first_column = dfm_column_start (reader); /* Three types of fields: quoted with ', quoted with ", unquoted. */ cp = ls_c_str (&line); @@ -845,9 +888,7 @@ static int di.e = token->string + token->length; di.v = (union value *) &token->number; di.f1 = first_column; - di.format.type = FMT_F; - di.format.w = token->length; - di.format.d = 0; + di.format = make_output_format (FMT_F, token->length, 0); if (!data_in (&di)) return 0; @@ -856,22 +897,22 @@ static int token->type = MSTR; } - dfm_forward_columns (data_file, cp - ls_c_str (&line)); + dfm_forward_columns (reader, cp - ls_c_str (&line)); return 1; } /* Forcibly skip the end of a line for content type CONTENT in - DATA_FILE. */ + READER. */ static int -force_eol (struct file_handle *data_file, const char *content) +force_eol (struct dfm_reader *reader, const char *content) { - struct len_string line; + struct fixed_string line; const char *cp; - if (dfm_eof (data_file)) + if (dfm_eof (reader)) return 0; - dfm_get_record (data_file, &line); + dfm_get_record (reader, &line); cp = ls_c_str (&line); while (isspace ((unsigned char) *cp) && cp < ls_end (&line)) @@ -880,11 +921,11 @@ force_eol (struct file_handle *data_file, const char *content) if (cp < ls_end (&line)) { msg (SE, _("End of line expected %s while reading %s."), - context (data_file), content); + context (reader), content); return 0; } - dfm_forward_record (data_file); + dfm_forward_record (reader); return 1; } @@ -920,20 +961,18 @@ read_matrices_without_rowtype (struct matrix_data_pgm *mx) nr.mx = mx; nr.data = NULL; - nr.factor_values = xmalloc (sizeof *nr.factor_values * mx->n_factors * mx->cells); + nr.factor_values = xnmalloc (mx->n_factors * mx->cells, + sizeof *nr.factor_values); nr.max_cell_idx = 0; - nr.split_values = xmalloc (sizeof *nr.split_values - * dict_get_split_cnt (default_dict)); + nr.split_values = xnmalloc (dict_get_split_cnt (default_dict), + sizeof *nr.split_values); - vfm_source = create_case_source (&matrix_data_without_rowtype_source_class, - default_dict, &nr); + vfm_source = create_case_source (&matrix_data_without_rowtype_source_class, &nr); procedure (NULL, NULL); free (nr.split_values); free (nr.factor_values); - - fh_close_handle (mx->data_file); } /* Mirror data across the diagonal of matrix CP which contains @@ -1063,20 +1102,20 @@ nr_read_data_lines (struct nr_aux_data *nr, for (j = 0; j < n_cols; j++) { struct matrix_token token; - if (!mget_token (&token, mx->data_file)) + if (!mget_token (&token, mx->reader)) return 0; if (token.type != MNUM) { msg (SE, _("expecting value for %s %s"), dict_get_var (default_dict, j)->name, - context (mx->data_file)); + context (mx->reader)); return 0; } *cp++ = token.number; } if (mx->fmt != FREE - && !force_eol (mx->data_file, content_names[content])) + && !force_eol (mx->reader, content_names[content])) return 0; debug_printf (("\n")); } @@ -1104,7 +1143,7 @@ matrix_data_read_without_rowtype (struct case_source *source, { int *cp; - nr->data = pool_alloc (mx->container, (PROX + 1) * sizeof *nr->data); + nr->data = pool_nalloc (mx->container, PROX + 1, sizeof *nr->data); { int i; @@ -1127,12 +1166,12 @@ matrix_data_read_without_rowtype (struct case_source *source, int n_vectors = per_factor ? mx->cells : 1; int i; - nr->data[*cp] = pool_alloc (mx->container, - n_vectors * sizeof **nr->data); + nr->data[*cp] = pool_nalloc (mx->container, + n_vectors, sizeof **nr->data); for (i = 0; i < n_vectors; i++) - nr->data[*cp][i] = pool_alloc (mx->container, - n_entries * sizeof ***nr->data); + nr->data[*cp][i] = pool_nalloc (mx->container, + n_entries, sizeof ***nr->data); } } } @@ -1185,7 +1224,7 @@ matrix_data_read_without_rowtype (struct case_source *source, nr_output_data (nr, c, write_case, wc_data); if (dict_get_split_cnt (default_dict) == 0 - || !another_token (mx->data_file)) + || !another_token (mx->reader)) return; } } @@ -1212,9 +1251,11 @@ nr_read_splits (struct nr_aux_data *nr, int compare) if (mx->single_split) { - if (!compare) - nr->split_values[0] - = ++dict_get_split_vars (default_dict)[0]->p.mxd.subtype; + if (!compare) + { + struct mxd_var *mv = dict_get_split_vars (default_dict)[0]->aux; + nr->split_values[0] = ++mv->sub_type; + } return 1; } @@ -1225,12 +1266,12 @@ nr_read_splits (struct nr_aux_data *nr, int compare) for (i = 0; i < split_cnt; i++) { struct matrix_token token; - if (!mget_token (&token, mx->data_file)) + if (!mget_token (&token, mx->reader)) return 0; if (token.type != MNUM) { msg (SE, _("Syntax error expecting SPLIT FILE value %s."), - context (mx->data_file)); + context (mx->reader)); return 0; } @@ -1270,17 +1311,17 @@ nr_read_factors (struct nr_aux_data *nr, int cell) } { - int i; + size_t i; for (i = 0; i < mx->n_factors; i++) { struct matrix_token token; - if (!mget_token (&token, mx->data_file)) + if (!mget_token (&token, mx->reader)) return 0; if (token.type != MNUM) { msg (SE, _("Syntax error expecting factor value %s."), - context (mx->data_file)); + context (mx->reader)); return 0; } @@ -1290,7 +1331,7 @@ nr_read_factors (struct nr_aux_data *nr, int cell) { msg (SE, _("Syntax error expecting value %g for %s %s."), nr->factor_values[i + mx->n_factors * cell], - mx->factors[i]->name, context (mx->data_file)); + mx->factors[i]->name, context (mx->reader)); return 0; } } @@ -1309,8 +1350,8 @@ dump_cell_content (struct matrix_data_pgm *mx, int content, double *cp, int type = content_type[content]; { - st_bare_pad_copy (case_data_rw (c, mx->rowtype_->fv)->s, - content_names[content], 8); + buf_copy_str_rpad (case_data_rw (c, mx->rowtype_->fv)->s, 8, + content_names[content]); if (type != 1) memset (case_data_rw (c, mx->varname_->fv)->s, ' ', 8); @@ -1331,10 +1372,9 @@ dump_cell_content (struct matrix_data_pgm *mx, int content, double *cp, cp++; } if (type == 1) - st_bare_pad_copy (case_data_rw (c, mx->varname_->fv)->s, - dict_get_var (default_dict, - mx->first_continuous + i)->name, - 8); + buf_copy_str_rpad (case_data_rw (c, mx->varname_->fv)->s, 8, + dict_get_var (default_dict, + mx->first_continuous + i)->name); write_case (wc_data); } } @@ -1365,7 +1405,7 @@ nr_output_data (struct nr_aux_data *nr, struct ccase *c, for (cell = 0; cell < mx->cells; cell++) { { - int factor; + size_t factor; for (factor = 0; factor < mx->n_factors; factor++) { @@ -1395,7 +1435,7 @@ nr_output_data (struct nr_aux_data *nr, struct ccase *c, int content; { - int factor; + size_t factor; for (factor = 0; factor < mx->n_factors; factor++) case_data_rw (c, mx->factors[factor]->fv)->f = SYSMIS; @@ -1434,7 +1474,7 @@ static int wr_read_splits (struct wr_aux_data *, struct ccase *, static int wr_output_data (struct wr_aux_data *, struct ccase *, write_case_func *, write_case_data); static int wr_read_rowtype (struct wr_aux_data *, - const struct matrix_token *, struct file_handle *); + const struct matrix_token *, struct dfm_reader *); static int wr_read_factors (struct wr_aux_data *); static int wr_read_indeps (struct wr_aux_data *); static void matrix_data_read_with_rowtype (struct case_source *, @@ -1457,11 +1497,10 @@ read_matrices_with_rowtype (struct matrix_data_pgm *mx) mx->cells = 0; vfm_source = create_case_source (&matrix_data_with_rowtype_source_class, - default_dict, &wr); + &wr); procedure (NULL, NULL); free (wr.split_values); - fh_close_handle (mx->data_file); } /* Read from the data file and write it to the active file. */ @@ -1485,7 +1524,7 @@ matrix_data_read_with_rowtype (struct case_source *source, if (!wr_read_indeps (wr)) return; } - while (another_token (mx->data_file)); + while (another_token (mx->reader)); wr_output_data (wr, c, write_case, wc_data); } @@ -1510,7 +1549,7 @@ wr_read_splits (struct wr_aux_data *wr, else { compare = 0; - wr->split_values = xmalloc (split_cnt * sizeof *wr->split_values); + wr->split_values = xnmalloc (split_cnt, sizeof *wr->split_values); } { @@ -1520,12 +1559,12 @@ wr_read_splits (struct wr_aux_data *wr, for (i = 0; i < split_cnt; i++) { struct matrix_token token; - if (!mget_token (&token, mx->data_file)) + if (!mget_token (&token, mx->reader)) return 0; if (token.type != MNUM) { msg (SE, _("Syntax error %s expecting SPLIT FILE value."), - context (mx->data_file)); + context (mx->reader)); return 0; } @@ -1605,7 +1644,7 @@ wr_output_data (struct wr_aux_data *wr, struct factor_data *iter; int i; - factors = xmalloc (sizeof *factors * mx->cells); + factors = xnmalloc (mx->cells, sizeof *factors); for (i = 0, iter = wr->data; iter; iter = iter->next, i++) factors[i] = iter; @@ -1627,14 +1666,11 @@ wr_output_data (struct wr_aux_data *wr, for (iter = wr->data; iter; iter = iter->next) { { - int factor; + size_t factor; for (factor = 0; factor < mx->n_factors; factor++) - { - case_data_rw (c, mx->factors[factor]->fv)->f - = iter->factors[factor]; - debug_printf (("f:%s ", factors[factor]->name)); - } + case_data_rw (c, mx->factors[factor]->fv)->f + = iter->factors[factor]; } { @@ -1680,22 +1716,22 @@ wr_output_data (struct wr_aux_data *wr, return 1; } -/* Sets ROWTYPE_ based on the given TOKEN read from DATA_FILE. +/* Sets ROWTYPE_ based on the given TOKEN read from READER. Return success. */ static int wr_read_rowtype (struct wr_aux_data *wr, const struct matrix_token *token, - struct file_handle *data_file) + struct dfm_reader *reader) { if (wr->content != -1) { - msg (SE, _("Multiply specified ROWTYPE_ %s."), context (data_file)); + msg (SE, _("Multiply specified ROWTYPE_ %s."), context (reader)); return 0; } if (token->type != MSTR) { msg (SE, _("Syntax error %s expecting ROWTYPE_ string."), - context (data_file)); + context (reader)); return 0; } @@ -1714,7 +1750,7 @@ wr_read_rowtype (struct wr_aux_data *wr, if (wr->content == -1) { - msg (SE, _("Syntax error %s."), context (data_file)); + msg (SE, _("Syntax error %s."), context (reader)); return 0; } @@ -1731,24 +1767,24 @@ wr_read_factors (struct wr_aux_data *wr) wr->content = -1; { - int i; + size_t i; for (i = 0; i < mx->n_factors; i++) { struct matrix_token token; - if (!mget_token (&token, mx->data_file)) + if (!mget_token (&token, mx->reader)) goto lossage; if (token.type == MSTR) { - if (!wr_read_rowtype (wr, &token, mx->data_file)) + if (!wr_read_rowtype (wr, &token, mx->reader)) goto lossage; - if (!mget_token (&token, mx->data_file)) + if (!mget_token (&token, mx->reader)) goto lossage; } if (token.type != MNUM) { msg (SE, _("Syntax error expecting factor value %s."), - context (mx->data_file)); + context (mx->reader)); goto lossage; } @@ -1758,9 +1794,9 @@ wr_read_factors (struct wr_aux_data *wr) if (wr->content == -1) { struct matrix_token token; - if (!mget_token (&token, mx->data_file)) + if (!mget_token (&token, mx->reader)) goto lossage; - if (!wr_read_rowtype (wr, &token, mx->data_file)) + if (!wr_read_rowtype (wr, &token, mx->reader)) goto lossage; } @@ -1768,7 +1804,7 @@ wr_read_factors (struct wr_aux_data *wr) mechanism. */ if (wr->current) { - int i; + size_t i; for (i = 0; i < mx->n_factors; i++) if (factor_values[i] != wr->current->factors[i]) @@ -1783,7 +1819,7 @@ cache_miss: for (iter = wr->data; iter; iter = iter->next) { - int i; + size_t i; for (i = 0; i < mx->n_factors; i++) if (factor_values[i] != iter->factors[i]) @@ -1800,10 +1836,11 @@ cache_miss: { struct factor_data *new = pool_alloc (mx->container, sizeof *new); - new->factors = pool_alloc (mx->container, sizeof *new->factors * mx->n_factors); + new->factors = pool_nalloc (mx->container, + mx->n_factors, sizeof *new->factors); { - int i; + size_t i; for (i = 0; i < mx->n_factors; i++) new->factors[i] = factor_values[i]; @@ -1851,8 +1888,8 @@ wr_read_indeps (struct wr_aux_data *wr) if (type == 1) n_items *= mx->n_continuous; - c->data[wr->content] = pool_alloc (mx->container, - sizeof **c->data * n_items); + c->data[wr->content] = pool_nalloc (mx->container, + n_items, sizeof **c->data); } cp = &c->data[wr->content][n_rows * mx->n_continuous]; @@ -1920,20 +1957,20 @@ wr_read_indeps (struct wr_aux_data *wr) for (j = 0; j < n_cols; j++) { struct matrix_token token; - if (!mget_token (&token, mx->data_file)) + if (!mget_token (&token, mx->reader)) return 0; if (token.type != MNUM) { msg (SE, _("Syntax error expecting value for %s %s."), dict_get_var (default_dict, mx->first_continuous + j)->name, - context (mx->data_file)); + context (mx->reader)); return 0; } *cp++ = token.number; } if (mx->fmt != FREE - && !force_eol (mx->data_file, content_names[wr->content])) + && !force_eol (mx->reader, content_names[wr->content])) return 0; debug_printf (("\n")); } @@ -1959,3 +1996,4 @@ matrix_data_without_rowtype_source_class = matrix_data_read_without_rowtype, NULL, }; +