From 18febf84744dc7ab4248542c2f88d91c01ef3fa1 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 16 Feb 2004 07:39:57 +0000 Subject: [PATCH] Got rid of "struct long_vec", envector(), devector(), etc. New functions dict_create_var_assert(), dict_lookup_var_assert(). --- src/ChangeLog | 68 ++++++++++++++++++++++++++++ src/Makefile.am | 2 +- src/aggregate.c | 1 + src/autorecode.c | 4 +- src/cases.c | 110 --------------------------------------------- src/cases.h | 42 ------------------ src/compute.c | 16 ++----- src/count.c | 7 +-- src/data-list.c | 19 +++++--- src/descript.q | 6 +-- src/dictionary.c | 37 ++++++++++------ src/flip.c | 6 +-- src/glob.c | 5 --- src/inpt-pgm.c | 2 +- src/loop.c | 7 +-- src/matrix-data.c | 12 ++--- src/numeric.c | 14 ++---- src/recode.c | 11 ++--- src/repeat.c | 10 +---- src/var.h | 25 ++++------- src/vector.c | 5 +-- src/vfm.c | 111 ++++++++++++++++++---------------------------- src/vfm.h | 1 - 23 files changed, 187 insertions(+), 334 deletions(-) delete mode 100644 src/cases.c delete mode 100644 src/cases.h diff --git a/src/ChangeLog b/src/ChangeLog index 64185402ca..819ed0e570 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,71 @@ +Sun Feb 15 23:14:59 2004 Ben Pfaff + + New functions dict_create_var_assert(), dict_lookup_var_assert(). + Converted several dict_*_var()/assert pairs into a single + dict_*_var_assert(). + + * dictionary.c: (dict_create_var_assert) New function. + (dict_lookup_var_assert) New function. + +Sun Feb 15 23:06:08 2004 Ben Pfaff + + Got rid of "struct long_vec", envector(), devector(), etc. Added + two members `init', `reinit' to struct variable as a substitute. + + * Makefile.am: (pspp_SOURCES) Removed cases.c, cases.h. + + * cases.c: Removed. + + * cases.h: Removed. + + * aggregate.c: (parse_aggregate_functions) destvar doesn't need + init. + + * autorecode.c: (cmd_autorecode) destvars don't need init. + + * compute.c: (lvalue_finalize) Set reinit. + + * data-list.c: (fixed_parse_compatible) Don't need init usually. + (dump_fmt_list) Ditto. + (parse_free) Ditto. + + * descript.q: (run_z_pass) Don't need init for z-scores. + + * dictionary.c: (dict_create_var) Initialize `init', `reinit' + members. + (dict_clone_var) Copy `reinit' member, initialize `init' member. + + * glob.c: (init_glob) Remove vec_init() calls. + + * inpt-pgm.c: (cmd_end_input_program) Use `reinit', not `left'. + + * loop.c: (internal_cmd_loop) Don't need to call envector(). + + * numeric.c: (cmd_numeric) Ditto. + (cmd_string) Ditto. + (cmd_leave) Ditto. Set `init', `reinit' members. + + * recode.c: (cmd_recode) Don't need to call envector(). + + * repeat.c: (internal_cmd_do_repeat) Ditto. + + * var.h: (struct variable) Remove `left'. Add `init', `reinit'. + (force_create_variable) Removed prototype. + (force_dup_variable) Ditto. + + * vector.c: (cmd_vector) Don't need to call envector(). + + * vfm.c: (reinit_sysmis) Removed. + (reinit_blanks) Removed. + (init_zero) Removed. + (init_blanks) Removed. + (process_active_file_write_case) No need to deal with vectors. + Call clear_temp_case(). + (vector_initialization) Rewrite to use `init', `reinit'. + (close_active_file) No need to call vec_clear(). + (procedure_write_case) Call clear_temp_case(). + (clear_temp_case) New function. + Sun Feb 15 20:50:36 2004 Ben Pfaff * pfm-write.c: (bufwrite) Get rid of nasty cast that also invoked diff --git a/src/Makefile.am b/src/Makefile.am index 144bc09ff2..1305ca7e5c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -35,7 +35,7 @@ frequencies.q list.q means.q set.q t-test.q pspp_SOURCES = $(q_sources_c) \ aggregate.c algorithm.c algorithm.h alloc.c alloc.h \ -apply-dict.c approx.h ascii.c autorecode.c bitvector.h cases.c cases.h \ +apply-dict.c approx.h ascii.c autorecode.c bitvector.h \ cmdline.c cmdline.h command.c command.def command.h compute.c \ count.c data-in.c data-in.h data-list.c \ data-out.c debug-print.h devind.c devind.h dfm.c dfm.h \ diff --git a/src/aggregate.c b/src/aggregate.c index 2a564167fe..657db1b8e8 100644 --- a/src/aggregate.c +++ b/src/aggregate.c @@ -664,6 +664,7 @@ parse_aggregate_functions (void) } free (dest[i]); + destvar->init = 0; if (dest_label[i]) { destvar->label = dest_label[i]; diff --git a/src/autorecode.c b/src/autorecode.c index edc07701b2..8d15ce63ba 100644 --- a/src/autorecode.c +++ b/src/autorecode.c @@ -157,8 +157,8 @@ cmd_autorecode (void) for (i = 0; i < nv_dest; i++) { - v_dest[i] = dict_create_var (default_dict, n_dest[i], 0); - assert (v_dest[i] != NULL); + v_dest[i] = dict_create_var_assert (default_dict, n_dest[i], 0); + v_dest[i]->init = 0; free (n_dest[i]); } free (n_dest); diff --git a/src/cases.c b/src/cases.c deleted file mode 100644 index 6ca177c2c2..0000000000 --- a/src/cases.c +++ /dev/null @@ -1,110 +0,0 @@ -/* PSPP - computes sample statistics. - Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. - Written by Ben Pfaff . - - 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 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., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ - -#include -#include -#include -#include -#include "alloc.h" -#include "cases.h" -#include "var.h" -#include "vfm.h" - -#include "debug-print.h" - -/* Initializes V. */ -void -vec_init (struct long_vec * v) -{ - v->vec = NULL; - v->n = v->m = 0; -} - -/* Deletes the contents of V. */ -void -vec_clear (struct long_vec * v) -{ - free (v->vec); - v->vec = NULL; - v->n = v->m = 0; -} - -/* Inserts ELEM into V. */ -void -vec_insert (struct long_vec * v, long elem) -{ - if (v->n >= v->m) - { - v->m = (v->m == 0 ? 16 : 2 * v->m); - v->vec = xrealloc (v->vec, v->m * sizeof *v->vec); - } - v->vec[v->n++] = elem; -} - -/* Deletes all occurrences of values A through B exclusive from V. */ -void -vec_delete (struct long_vec * v, long a, long b) -{ - int i; - - for (i = v->n - 1; i >= 0; i--) - if (v->vec[i] >= a && v->vec[i] < b) - v->vec[i] = v->vec[--v->n]; -} - -/* Sticks V->FV in the proper vector. */ -void -envector (const struct variable *v) -{ - if (v->type == NUMERIC) - { - if (v->left) - vec_insert (&init_zero, v->fv); - else - vec_insert (&reinit_sysmis, v->fv); - } - else - { - int i; - - if (v->left) - for (i = v->fv; i < v->fv + v->nv; i++) - vec_insert (&init_blanks, i); - else - for (i = v->fv; i < v->fv + v->nv; i++) - vec_insert (&reinit_blanks, i); - } -} - -/* Removes V->FV from the proper vector. */ -void -devector (const struct variable *v) -{ - if (v->type == NUMERIC) - { - if (v->left) - vec_delete (&init_zero, v->fv, v->fv + 1); - else - vec_delete (&reinit_sysmis, v->fv, v->fv + 1); - } - else if (v->left) - vec_delete (&init_blanks, v->fv, v->fv + v->nv); - else - vec_delete (&reinit_blanks, v->fv, v->fv + v->nv); -} diff --git a/src/cases.h b/src/cases.h deleted file mode 100644 index b78672325f..0000000000 --- a/src/cases.h +++ /dev/null @@ -1,42 +0,0 @@ -/* PSPP - computes sample statistics. - Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. - Written by Ben Pfaff . - - 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 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., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ - -#if !cases_h -#define cases_h 1 - -/* Vectors. */ - -/* A vector of longs. */ -struct long_vec - { - long *vec; /* Contents. */ - int n; /* Number of elements. */ - int m; /* Number of elements room is allocated for. */ - }; - -struct variable; - -void vec_init (struct long_vec *); -void vec_clear (struct long_vec *); -void vec_insert (struct long_vec *, long); -void vec_delete (struct long_vec *, long a, long b); -void devector (const struct variable *); -void envector (const struct variable *); - -#endif /* !cases_h */ diff --git a/src/compute.c b/src/compute.c index e299bd67f5..ff127e359f 100644 --- a/src/compute.c +++ b/src/compute.c @@ -22,7 +22,6 @@ #include #include "alloc.h" #include "approx.h" -#include "cases.h" #include "command.h" #include "error.h" #include "expr.h" @@ -398,21 +397,14 @@ lvalue_finalize (struct lvalue *lvalue, { compute->variable = dict_lookup_var (default_dict, lvalue->var_name); if (compute->variable == NULL) - compute->variable = dict_create_var (default_dict, lvalue->var_name, - 0); - assert (compute->variable != NULL); - + compute->variable = dict_create_var_assert (default_dict, + lvalue->var_name, 0); compute->fv = compute->variable->fv; compute->width = compute->variable->width; /* Goofy behavior, but compatible: Turn off LEAVE. */ - if (compute->variable->left - && dict_class_from_id (compute->variable->name) != DC_SCRATCH) - { - devector (compute->variable); - compute->variable->left = 0; - envector (compute->variable); - } + if (dict_class_from_id (compute->variable->name) != DC_SCRATCH) + compute->variable->reinit = 1; } else { diff --git a/src/count.c b/src/count.c index 02cb783889..cf8d067673 100644 --- a/src/count.c +++ b/src/count.c @@ -220,11 +220,8 @@ cmd_count (void) the same dest var more than once. */ cnt->d = dict_lookup_var (default_dict, cnt->n); - if (!cnt->d) - { - cnt->d = dict_create_var (default_dict, cnt->n, 0); - assert (cnt->d != NULL); - } + if (cnt->d == NULL) + cnt->d = dict_create_var_assert (default_dict, cnt->n, 0); } #if DEBUGGING diff --git a/src/data-list.c b/src/data-list.c index 7512a8e18f..f4ed8d874d 100644 --- a/src/data-list.c +++ b/src/data-list.c @@ -163,10 +163,7 @@ cmd_data_list (void) return CMD_FAILURE; dls.end = dict_lookup_var (default_dict, tokid); if (!dls.end) - { - dls.end = dict_create_var (default_dict, tokid, 0); - assert (dls.end != NULL); - } + dls.end = dict_create_var_assert (default_dict, tokid, 0); lex_get (); } else if (token == T_ID) @@ -519,11 +516,13 @@ fixed_parse_compatible (void) { convert_fmt_ItoO (&fx.spec.input, &v->print); v->write = v->print; + if (vfm_source != &input_program_source + && vfm_source != &file_type_source) + v->init = 0; } else { - v = dict_lookup_var (default_dict, fx.name[i]); - assert (v != NULL); + v = dict_lookup_var_assert (default_dict, fx.name[i]); if (!vfm_source) { msg (SE, _("%s is a duplicate variable name."), fx.name[i]); @@ -627,6 +626,10 @@ dump_fmt_list (struct fmt_list *f) return 0; } + if (vfm_source != &input_program_source + && vfm_source != &file_type_source) + v->init = 0; + fx.spec.input = f->f; convert_fmt_ItoO (&fx.spec.input, &v->print); v->write = v->print; @@ -829,6 +832,10 @@ parse_free (void) v->print = v->write = out; + if (vfm_source != &input_program_source + && vfm_source != &file_type_source) + v->init = 0; + strcpy (spec.name, name[i]); spec.fv = v->fv; spec.width = width; diff --git a/src/descript.q b/src/descript.q index 84bc16c5fa..cf33db6927 100644 --- a/src/descript.q +++ b/src/descript.q @@ -539,9 +539,9 @@ run_z_pass (void) struct variable *d; t->z[count].s = v; - t->z[count].d = d = dict_create_var (default_dict, - v->p.dsc.zname, 0); - assert (d != NULL); + t->z[count].d = d = dict_create_var_assert (default_dict, + v->p.dsc.zname, 0); + d->init = 0; if (v->label) { d->label = xmalloc (strlen (v->label) + 12); diff --git a/src/dictionary.c b/src/dictionary.c index e03c429eab..03670fe42f 100644 --- a/src/dictionary.c +++ b/src/dictionary.c @@ -86,23 +86,14 @@ dict_clone (const struct dictionary *s) { d->split = xmalloc (d->split_cnt * sizeof *d->split); for (i = 0; i < d->split_cnt; i++) - { - d->split[i] = dict_lookup_var (d, s->split[i]->name); - assert (d->split[i] != NULL); - } + d->split[i] = dict_lookup_var_assert (d, s->split[i]->name); } if (s->weight != NULL) - { - d->weight = dict_lookup_var (d, s->weight->name); - assert (d->weight != NULL); - } + d->weight = dict_lookup_var_assert (d, s->weight->name); if (s->filter != NULL) - { - d->filter = dict_lookup_var (d, s->filter->name); - assert (d->filter != NULL); - } + d->filter = dict_lookup_var_assert (d, s->filter->name); d->case_limit = s->case_limit; dict_set_label (d, dict_get_label (s)); @@ -227,7 +218,8 @@ dict_create_var (struct dictionary *d, const char *name, int width) v->width = width; v->fv = d->value_cnt; v->nv = width == 0 ? 1 : DIV_RND_UP (width, 8); - v->left = name[0] == '#'; + v->init = 1; + v->reinit = name[0] != '#'; v->miss_type = MISSING_NONE; if (v->type == NUMERIC) { @@ -258,6 +250,14 @@ dict_create_var (struct dictionary *d, const char *name, int width) return v; } +struct variable * +dict_create_var_assert (struct dictionary *d, const char *name, int width) +{ + struct variable *v = dict_create_var (d, name, width); + assert (v != NULL); + return v; +} + struct variable * dict_clone_var (struct dictionary *d, const struct variable *ov, const char *name) @@ -273,7 +273,8 @@ dict_clone_var (struct dictionary *d, const struct variable *ov, if (nv == NULL) return NULL; - nv->left = ov->left; + nv->init = 1; + nv->reinit = ov->reinit; nv->miss_type = ov->miss_type; memcpy (nv->missing, ov->missing, sizeof nv->missing); nv->print = ov->print; @@ -321,6 +322,14 @@ dict_lookup_var (const struct dictionary *d, const char *name) return hsh_find (d->name_tab, &v); } +struct variable * +dict_lookup_var_assert (const struct dictionary *d, const char *name) +{ + struct variable *v = dict_lookup_var (d, name); + assert (v != NULL); + return v; +} + int dict_contains_var (const struct dictionary *d, const struct variable *v) { diff --git a/src/flip.c b/src/flip.c index c4bb5fdc9b..f599fd78f0 100644 --- a/src/flip.c +++ b/src/flip.c @@ -167,8 +167,7 @@ make_new_var (char name[]) static int build_dictionary (void) { - if (!dict_create_var (default_dict, "CASE_LBL", 8)) - assert (0); + dict_create_var_assert (default_dict, "CASE_LBL", 8); if (!new_names_tail) { @@ -186,8 +185,7 @@ build_dictionary (void) char s[9]; sprintf (s, "VAR%03d", i); - v = dict_create_var (default_dict, s, 0); - assert (v != NULL); + v = dict_create_var_assert (default_dict, s, 0); } } else diff --git a/src/glob.c b/src/glob.c index db3bda94ac..cc76e340ab 100644 --- a/src/glob.c +++ b/src/glob.c @@ -169,11 +169,6 @@ init_glob (int argc UNUSED, char **argv) /* var.h */ default_dict = dict_create (); - vec_init (&reinit_sysmis); - vec_init (&reinit_blanks); - vec_init (&init_zero); - vec_init (&init_blanks); - last_vfm_invocation = time (NULL); /* lexer.h */ diff --git a/src/inpt-pgm.c b/src/inpt-pgm.c index 144aceb51c..cfc6428840 100644 --- a/src/inpt-pgm.c +++ b/src/inpt-pgm.c @@ -105,7 +105,7 @@ cmd_end_input_program (void) size_t j; value_init = var->type == NUMERIC ? INP_NUMERIC : INP_STRING; - value_init |= var->left ? INP_INIT_ONCE : INP_REINIT; + value_init |= var->reinit ? INP_REINIT : INP_INIT_ONCE; for (j = 0; j < var->nv; j++) inp_init[j + var->fv] = value_init; diff --git a/src/loop.c b/src/loop.c index 5d9266b0e4..424e5aabaf 100644 --- a/src/loop.c +++ b/src/loop.c @@ -254,12 +254,7 @@ internal_cmd_loop (void) { two->index = dict_lookup_var (default_dict, name); if (!two->index) - { - two->index = dict_create_var (default_dict, name, 0); -#if DEBUGGING - envector (two->index); -#endif - } + two->index = dict_create_var (default_dict, name, 0); } /* Push on control stack. */ diff --git a/src/matrix-data.c b/src/matrix-data.c index fd3d380767..9502c57555 100644 --- a/src/matrix-data.c +++ b/src/matrix-data.c @@ -216,8 +216,7 @@ cmd_matrix_data (void) if (strcmp (v[i], "ROWTYPE_")) { - new_var = dict_create_var (default_dict, v[i], 0); - assert (new_var != NULL); + new_var = dict_create_var_assert (default_dict, v[i], 0); new_var->p.mxd.vartype = MXD_CONTINUOUS; new_var->p.mxd.subtype = i; } @@ -229,8 +228,7 @@ cmd_matrix_data (void) } { - rowtype_ = dict_create_var (default_dict, "ROWTYPE_", 8); - assert (rowtype_ != NULL); + rowtype_ = dict_create_var_assert (default_dict, "ROWTYPE_", 8); rowtype_->p.mxd.vartype = MXD_ROWTYPE; rowtype_->p.mxd.subtype = 0; } @@ -296,8 +294,7 @@ cmd_matrix_data (void) goto lossage; } - single_split = dict_create_var (default_dict, tokid, 0); - assert (single_split != NULL); + single_split = dict_create_var_assert (default_dict, tokid, 0); lex_get (); single_split->p.mxd.vartype = MXD_CONTINUOUS; @@ -540,8 +537,7 @@ cmd_matrix_data (void) /* Create VARNAME_. */ { - varname_ = dict_create_var (default_dict, "VARNAME_", 8); - assert (varname_ != NULL); + varname_ = dict_create_var_assert (default_dict, "VARNAME_", 8); varname_->p.mxd.vartype = MXD_VARNAME; varname_->p.mxd.subtype = 0; } diff --git a/src/numeric.c b/src/numeric.c index 1619a99af3..b97410a51b 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -20,7 +20,6 @@ #include #include #include -#include "cases.h" #include "command.h" #include "error.h" #include "lexer.h" @@ -80,7 +79,6 @@ cmd_numeric (void) { if (f.type != -1) new_var->print = new_var->write = f; - envector (new_var); } } @@ -160,10 +158,7 @@ cmd_string (void) if (!new_var) msg (SE, _("There is already a variable named %s."), v[i]); else - { - new_var->print = new_var->write = f; - envector (new_var); - } + new_var->print = new_var->write = f; } /* Clean up. */ @@ -198,11 +193,10 @@ cmd_leave (void) return CMD_FAILURE; for (i = 0; i < nv; i++) { - if (v[i]->left) + if (!v[i]->reinit) continue; - devector (v[i]); - v[i]->left = 1; - envector (v[i]); + v[i]->reinit = 0; + v[i]->init = 1; } free (v); diff --git a/src/recode.c b/src/recode.c index 2485b3d1ee..185067bae8 100644 --- a/src/recode.c +++ b/src/recode.c @@ -23,7 +23,6 @@ #include #include "alloc.h" #include "approx.h" -#include "cases.h" #include "command.h" #include "error.h" #include "lexer.h" @@ -416,13 +415,11 @@ cmd_recode (void) rcd->dest = dict_create_var (default_dict, rcd->dest_name, 0); if (!rcd->dest) { - /* This can occur if a destname is duplicated. We could - give an error at parse time but I don't care enough. */ - rcd->dest = dict_lookup_var (default_dict, rcd->dest_name); - assert (rcd->dest != NULL); + /* FIXME: This can occur if a destname is duplicated. + We could give an error at parse time but I don't + care enough. */ + rcd->dest = dict_lookup_var_assert (default_dict, rcd->dest_name); } - else - envector (rcd->dest); } trns = xmalloc (sizeof *trns); diff --git a/src/repeat.c b/src/repeat.c index 09809fde1e..bf89fedecd 100644 --- a/src/repeat.c +++ b/src/repeat.c @@ -24,7 +24,6 @@ #include #include #include "alloc.h" -#include "cases.h" #include "command.h" #include "error.h" #include "getline.h" @@ -329,14 +328,7 @@ internal_cmd_do_repeat (void) { /* Note that if the variable already exists there is no harm done. */ - struct variable *v = dict_create_var (default_dict, - iter->replacement[i], - 0); - - /* If we created the variable then we need to initialize - its observations to SYSMIS. */ - if (v) - envector (v); + dict_create_var (default_dict, iter->replacement[i], 0); } } } diff --git a/src/var.h b/src/var.h index f67ef84d6f..c587f7a23d 100644 --- a/src/var.h +++ b/src/var.h @@ -275,19 +275,20 @@ enum /* A variable's dictionary entry. Note: don't reorder name[] from the first element; a pointer to `variable' should be a pointer to - member `name'.*/ + member `name'. FIXME: is this comment still accurate? */ struct variable { /* Required by parse_variables() to be in this order. */ char name[9]; /* As a string. */ int index; /* Index into its dictionary's var[]. */ - int type; /* NUMERIC or ALPHA. */ + int type; /* NUMERIC or ALPHA. */ /* Also important but parse_variables() doesn't need it. Still, check before reordering. */ int width; /* Size of string variables in chars. */ int fv, nv; /* Index into `value's, number of values. */ - int left; /* 0=reinitialize each case, 1=don't. */ + unsigned init : 1; /* 1=VFM must init and possibly reinit. */ + unsigned reinit : 1; /* Cases are: 1=reinitialized; 0=left. */ /* Missing values. */ int miss_type; /* One of the MISSING_* constants. */ @@ -369,11 +370,15 @@ void dict_get_vars (const struct dictionary *, struct variable *dict_create_var (struct dictionary *, const char *, int width); +struct variable *dict_create_var_assert (struct dictionary *, const char *, + int width); struct variable *dict_clone_var (struct dictionary *, const struct variable *, const char *); void dict_rename_var (struct dictionary *, struct variable *, const char *); struct variable *dict_lookup_var (const struct dictionary *, const char *); +struct variable *dict_lookup_var_assert (const struct dictionary *, + const char *); int dict_contains_var (const struct dictionary *, const struct variable *); void dict_delete_var (struct dictionary *, struct variable *); void dict_delete_vars (struct dictionary *, @@ -462,20 +467,6 @@ int is_missing (const union value *, const struct variable *); int is_system_missing (const union value *, const struct variable *); int is_user_missing (const union value *, const struct variable *); void copy_missing_values (struct variable *dest, const struct variable *src); - -#if GLOBAL_DEBUGGING -struct variable *force_create_variable (struct dictionary *, const char *name, - int type, int width); -struct variable *force_dup_variable (struct dictionary *, - const struct variable *src, - const char *name); -#else -#define force_create_variable(A, B, C, D) \ - create_variable (A, B, C, D) -#define force_dup_variable(A, B, C) \ - dup_variable (A, B, C) -#endif - /* Transformations. */ diff --git a/src/vector.c b/src/vector.c index e63ac2153f..2296672dc2 100644 --- a/src/vector.c +++ b/src/vector.c @@ -21,7 +21,6 @@ #include #include #include "alloc.h" -#include "cases.h" #include "command.h" #include "error.h" #include "lexer.h" @@ -169,9 +168,7 @@ cmd_vector (void) for (i = 0; i < nv; i++) { sprintf (name, "%s%d", cp, i + 1); - v[i] = dict_create_var (default_dict, name, 0); - assert (v[i] != NULL); - envector (v[i]); + v[i] = dict_create_var_assert (default_dict, name, 0); } if (!dict_create_vector (default_dict, cp, v, nv)) assert (0); diff --git a/src/vfm.c b/src/vfm.c index 173bbb0f4a..45d9c28e8b 100644 --- a/src/vfm.c +++ b/src/vfm.c @@ -62,12 +62,6 @@ struct write_case_data /* This is used to read from the active file. */ struct case_stream *vfm_source; -/* `value' indexes to initialize to particular values for certain cases. */ -struct long_vec reinit_sysmis; /* SYSMIS for every case. */ -struct long_vec reinit_blanks; /* Blanks for every case. */ -struct long_vec init_zero; /* Zero for first case only. */ -struct long_vec init_blanks; /* Blanks for first case only. */ - /* This is used to write to the replacement active file. */ struct case_stream *vfm_sink; @@ -122,6 +116,7 @@ static int SPLIT_FILE_procfunc (struct ccase *, void *); static void finish_compaction (void); static void lag_case (void); static int procedure_write_case (struct write_case_data *); +static void clear_temp_case (void); /* Public functions. */ @@ -256,16 +251,8 @@ process_active_file_write_case (struct write_case_data *data) case_count++; done: - { - long *lp; + clear_temp_case (); - /* This case is finished. Initialize the variables for the next case. */ - for (lp = reinit_sysmis.vec; *lp != -1;) - temp_case->data[*lp++].f = SYSMIS; - for (lp = reinit_blanks.vec; *lp != -1;) - memset (temp_case->data[*lp++].s, ' ', MAX_SHORT_STRING); - } - return 1; } @@ -387,48 +374,29 @@ index_to_varname (int ccase_index) } #endif -/* Initializes temp_case from the vectors that say which `value's need - to be initialized just once, and which ones need to be +/* Initializes temp_case from the vectors that say which `value's + need to be initialized just once, and which ones need to be re-initialized before every case. */ static void vector_initialization (void) { - int i; - long *lp; - - /* Just once. */ - for (i = 0; i < init_zero.n; i++) - temp_case->data[init_zero.vec[i]].f = 0.0; - for (i = 0; i < init_blanks.n; i++) - memset (temp_case->data[init_blanks.vec[i]].s, ' ', MAX_SHORT_STRING); - - /* These vectors need to be repeatedly accessed, so we add a - sentinel to (hopefully) improve speed. */ - vec_insert (&reinit_sysmis, -1); - vec_insert (&reinit_blanks, -1); - - for (lp = reinit_sysmis.vec; *lp != -1;) - temp_case->data[*lp++].f = SYSMIS; - for (lp = reinit_blanks.vec; *lp != -1;) - memset (temp_case->data[*lp++].s, ' ', MAX_SHORT_STRING); + size_t var_cnt = dict_get_var_cnt (default_dict); + size_t i; -#if DEBUGGING - printf ("vfm: init_zero="); - for (i = 0; i < init_zero.n; i++) - printf ("%s%s", i ? "," : "", index_to_varname (init_zero.vec[i])); - printf (" init_blanks="); - for (i = 0; i < init_blanks.n; i++) - printf ("%s%s", i ? "," : "", index_to_varname (init_blanks.vec[i])); - printf (" reinit_sysmis="); - for (lp = reinit_sysmis.vec; *lp != -1; lp++) - printf ("%s%s", lp != reinit_sysmis.vec ? "," : "", - index_to_varname (*lp)); - printf (" reinit_blanks="); - for (lp = reinit_blanks.vec; *lp != -1; lp++) - printf ("%s%s", lp != reinit_blanks.vec ? "," : "", - index_to_varname (*lp)); - printf ("\n"); -#endif + for (i = 0; i < var_cnt; i++) + { + struct variable *v = dict_get_var (default_dict, i); + + if (v->type == NUMERIC) + { + if (v->reinit) + temp_case->data[v->fv].f = 0.0; + else + temp_case->data[v->fv].f = SYSMIS; + } + else + memset (temp_case->data[v->fv].s, ' ', v->width); + } } /* Sets filter_index to an appropriate value. */ @@ -602,12 +570,6 @@ close_active_file (struct write_case_data *data) /* Cancel transformations. */ cancel_transformations (); - /* Clear value-initialization vectors. */ - vec_clear (&init_zero); - vec_clear (&init_blanks); - vec_clear (&reinit_sysmis); - vec_clear (&reinit_blanks); - /* Turn off case limiter. */ dict_set_case_limit (default_dict, 0); @@ -1048,21 +1010,36 @@ procedure_write_case (write_case_data wc_data) done: debug_putc ('\n', stdout); - - { - long *lp; - /* This case is finished. Initialize the variables for the next case. */ - for (lp = reinit_sysmis.vec; *lp != -1;) - temp_case->data[*lp++].f = SYSMIS; - for (lp = reinit_blanks.vec; *lp != -1;) - memset (temp_case->data[*lp++].s, ' ', MAX_SHORT_STRING); - } + clear_temp_case (); /* Return previously determined value. */ return more_cases; } +/* Clears the variables in the temporary case that need to be + cleared between processing cases. */ +static void +clear_temp_case (void) +{ + /* FIXME? This is linear in the number of variables, but + doesn't need to be, so it's an easy optimization target. */ + size_t var_cnt = dict_get_var_cnt (default_dict); + size_t i; + + for (i = 0; i < var_cnt; i++) + { + struct variable *v = dict_get_var (default_dict, i); + if (v->init && v->reinit) + { + if (v->type == NUMERIC) + temp_case->data[v->fv].f = SYSMIS; + else + memset (temp_case->data[v->fv].s, ' ', v->width); + } + } +} + /* Appends TRNS to t_trns[], the list of all transformations to be performed on data as it is read from the active file. */ void diff --git a/src/vfm.h b/src/vfm.h index 27cac23549..a9355636ac 100644 --- a/src/vfm.h +++ b/src/vfm.h @@ -20,7 +20,6 @@ #if !vfm_h #define vfm_h 1 -#include "cases.h" #include /* This is the time at which vfm was last invoked. */ -- 2.30.2