X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvfm.c;h=84efc3e0004ea4062735ba13dd24f123abed3e0e;hb=d69833d7d425cd98c3793a89945153306dfa7ab3;hp=333851d61176071a6e7b90ad9d62f7d9e9adf354;hpb=4944c86a9318bc5b5578ab145a95c116ffd2c9fd;p=pspp-builds.git diff --git a/src/vfm.c b/src/vfm.c index 333851d6..84efc3e0 100644 --- a/src/vfm.c +++ b/src/vfm.c @@ -17,24 +17,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* AIX requires this to be the first thing in the file. */ #include -#if __GNUC__ -#define alloca __builtin_alloca -#else -#if HAVE_ALLOCA_H -#include -#else -#ifdef _AIX -#pragma alloca -#else -#ifndef alloca /* predefined by HP cc +Olibcalls */ -char *alloca (); -#endif -#endif -#endif -#endif - +#include "vfm.h" +#include "vfmP.h" #include #include #include @@ -53,9 +38,7 @@ char *alloca (); #include "str.h" #include "tab.h" #include "var.h" -#include "vector.h" -#include "vfm.h" -#include "vfmP.h" +#include "value-labels.h" /* Virtual File Manager (vfm): @@ -65,8 +48,6 @@ char *alloca (); (the data sink). The data source is then deleted and the data sink becomes the data source for the next procedure. */ -#undef DEBUGGING -/*#define DEBUGGING 1 */ #include "debug-print.h" /* This is used to read from the active file. */ @@ -159,7 +140,7 @@ procedure (void (*beginfunc) (void), end_func = endfunc; write_case = procedure_write_case; - if (default_dict.n_splits && procfunc != NULL) + if (dict_get_split_cnt (default_dict) != 0 && procfunc != NULL) { virt_proc_func = procfunc; proc_func = SPLIT_FILE_procfunc; @@ -299,9 +280,10 @@ prepare_for_writing (void) file--it's just a waste of time and space. */ vfm_sink_info.ncases = 0; - vfm_sink_info.nval = default_dict.nval; + vfm_sink_info.nval = dict_get_value_cnt (default_dict); vfm_sink_info.case_size = (sizeof (struct ccase) - + (default_dict.nval - 1) * sizeof (union value)); + + ((dict_get_value_cnt (default_dict) - 1) + * sizeof (union value))); if (vfm_sink == NULL) { @@ -331,19 +313,24 @@ arrange_compaction (void) int i; /* Count up the number of `value's that will be output. */ - for (i = 0; i < temp_dict->nvar; i++) - if (temp_dict->var[i]->name[0] != '#') - { - assert (temp_dict->var[i]->nv > 0); - count_values += temp_dict->var[i]->nv; - } - assert (temporary == 2 || count_values <= temp_dict->nval); + for (i = 0; i < dict_get_var_cnt (temp_dict); i++) + { + struct variable *v = dict_get_var (temp_dict, i); + + if (v->name[0] != '#') + { + assert (v->nv > 0); + count_values += v->nv; + } + } + assert (temporary == 2 || count_values <= dict_get_value_cnt (temp_dict)); } /* Compaction is only necessary if the number of `value's to output differs from the number already present. */ compaction_nval = count_values; - compaction_necessary = temporary == 2 || count_values != temp_dict->nval; + compaction_necessary = (temporary == 2 + || count_values != dict_get_value_cnt (temp_dict)); if (vfm_sink->init) vfm_sink->init (); @@ -358,23 +345,6 @@ make_temp_case (void) if (compaction_necessary) compaction_case = xmalloc (sizeof (struct ccase) + sizeof (union value) * (compaction_nval - 1)); - -#if __CHECKER__ - /* Initialize the unused trailing parts of string variables to avoid - spurious warnings from Checker. */ - { - int i; - - for (i = 0; i < default_dict.nvar; i++) - { - struct variable *v = default_dict.var[i]; - - if (v->type == ALPHA && v->width % 8 != 0) - memcpy (&temp_case->data[v->fv + v->nv - 1] - .s[v->width % 8], _("!ERROR!"), 8 - v->width % 8); - } - } -#endif } #if DEBUGGING @@ -387,7 +357,7 @@ index_to_varname (int ccase_index) for (i = 0; i < default_dict.nvar; i++) { - variable *v = default_dict.var[i]; + struct variable *v = default_dict.var[i]; if (ccase_index >= v->fv && ccase_index < v->fv + v->nv) return default_dict.var[i]->name; @@ -444,19 +414,14 @@ vector_initialization (void) static void setup_filter (void) { - filter_index = -1; + filter_var = dict_get_filter (default_dict); - if (default_dict.filter_var[0]) + if (filter_var != NULL) { - struct variable *fv = find_variable (default_dict.filter_var); - - if (fv == NULL || fv->type == ALPHA) - default_dict.filter_var[0] = 0; - else - { - filter_index = fv->index; - filter_var = fv; - } + assert (filter_var->type == NUMERIC); + filter_index = filter_var->index; + } else { + filter_index = -1; } } @@ -473,7 +438,8 @@ setup_lag (void) lag_head = 0; lag_queue = xmalloc (n_lag * sizeof *lag_queue); for (i = 0; i < n_lag; i++) - lag_queue[i] = xmalloc (temp_dict->nval * sizeof **lag_queue); + lag_queue[i] = xmalloc (dict_get_value_cnt (temp_dict) + * sizeof **lag_queue); } /* There is a lot of potential confusion in the vfm and related @@ -522,7 +488,7 @@ open_active_file (void) if (!temporary) { temp_trns = n_trns; - temp_dict = &default_dict; + temp_dict = default_dict; } /* No cases passed to the procedure yet. */ @@ -533,7 +499,6 @@ open_active_file (void) arrange_compaction (); make_temp_case (); vector_initialization (); - setup_randomize (); discard_ctl_stack (); setup_filter (); setup_lag (); @@ -571,12 +536,14 @@ close_active_file (void) off TEMPORARY. */ if (temporary) { - restore_dictionary (temp_dict); + dict_destroy (default_dict); + default_dict = temp_dict; temp_dict = NULL; } - /* The default dictionary assumes the compacted data size. */ - default_dict.nval = compaction_nval; + /* Finish compaction. */ + if (compaction_necessary) + finish_compaction (); /* Old data sink --> New data source. */ if (vfm_source && vfm_source->destroy_source) @@ -593,9 +560,7 @@ close_active_file (void) /* Old data sink is gone now. */ vfm_sink = NULL; - /* Finish compaction. */ - if (compaction_necessary) - finish_compaction (); + /* Cancel TEMPORARY. */ cancel_temporary (); /* Free temporary cases. */ @@ -610,8 +575,8 @@ close_active_file (void) process_if_expr = NULL; /* Cancel FILTER if temporary. */ - if (filter_index != -1 && !FILTER_before_TEMPORARY) - default_dict.filter_var[0] = 0; + if (filter_var != NULL && !FILTER_before_TEMPORARY) + dict_set_filter (default_dict, NULL); /* Cancel transformations. */ cancel_transformations (); @@ -623,18 +588,10 @@ close_active_file (void) vec_clear (&reinit_blanks); /* Turn off case limiter. */ - default_dict.N = 0; + dict_set_case_limit (default_dict, 0); /* Clear VECTOR vectors. */ - { - int i; - - for (i = 0; i < nvec; i++) - free (vec[i].v); - free (vec); - vec = NULL; - nvec = 0; - } + dict_clear_vectors (default_dict); debug_printf (("vfm: procedure complete\n\n")); } @@ -961,7 +918,6 @@ struct case_stream vfm_memory_stream = "memory", }; -#undef DEBUGGING #include "debug-print.h" /* Add temp_case to the lag queue. */ @@ -970,7 +926,8 @@ lag_case (void) { if (lag_count < n_lag) lag_count++; - memcpy (lag_queue[lag_head], temp_case, sizeof (union value) * temp_dict->nval); + memcpy (lag_queue[lag_head], temp_case, + sizeof (union value) * dict_get_value_cnt (temp_dict)); if (++lag_head >= n_lag) lag_head = 0; } @@ -1021,8 +978,9 @@ procedure_write_case (void) vfm_sink_info.ncases++; vfm_sink->write (); - if (default_dict.N) - more_cases = vfm_sink_info.ncases < default_dict.N; + if (dict_get_case_limit (default_dict)) + more_cases = (vfm_sink_info.ncases + < dict_get_case_limit (default_dict)); } /* Are we done? */ @@ -1122,22 +1080,25 @@ cancel_transformations (void) static void dump_splits (struct ccase *c) { - struct variable **iter; + struct variable *const *split; struct tab_table *t; + size_t split_cnt; int i; - t = tab_create (3, default_dict.n_splits + 1, 0); + split_cnt = dict_get_split_cnt (default_dict); + t = tab_create (3, split_cnt + 1, 0); tab_dim (t, tab_natural_dimensions); - tab_vline (t, TAL_1 | TAL_SPACING, 1, 0, default_dict.n_splits); - tab_vline (t, TAL_1 | TAL_SPACING, 2, 0, default_dict.n_splits); + tab_vline (t, TAL_1 | TAL_SPACING, 1, 0, split_cnt); + tab_vline (t, TAL_1 | TAL_SPACING, 2, 0, split_cnt); tab_text (t, 0, 0, TAB_NONE, _("Variable")); tab_text (t, 1, 0, TAB_LEFT, _("Value")); tab_text (t, 2, 0, TAB_LEFT, _("Label")); - for (iter = default_dict.splits, i = 0; *iter; iter++, i++) + split = dict_get_split_vars (default_dict); + for (i = 0; i < split_cnt; i++) { - struct variable *v = *iter; + struct variable *v = split[i]; char temp_buf[80]; - char *val_lab; + const char *val_lab; assert (v->type == NUMERIC || v->type == ALPHA); tab_text (t, 0, i + 1, TAB_LEFT | TAT_PRINTF, "%s", v->name); @@ -1152,7 +1113,7 @@ dump_splits (struct ccase *c) temp_buf[v->print.w] = 0; tab_text (t, 1, i + 1, TAT_PRINTF, "%.*s", v->print.w, temp_buf); - val_lab = get_val_lab (v, c->data[v->fv], 0); + val_lab = val_labs_find (v->val_labs, c->data[v->fv]); if (val_lab) tab_text (t, 2, i + 1, TAB_LEFT, val_lab); } @@ -1167,7 +1128,9 @@ static int SPLIT_FILE_procfunc (struct ccase *c) { static struct ccase *prev_case; - struct variable **iter; + struct variable *const *split; + size_t split_cnt; + size_t i; /* The first case always begins a new series. We also need to preserve the values of the case for later comparison. */ @@ -1187,9 +1150,11 @@ SPLIT_FILE_procfunc (struct ccase *c) /* Compare the value of each SPLIT FILE variable to the values on the previous case. */ - for (iter = default_dict.splits; *iter; iter++) + split = dict_get_split_vars (default_dict); + split_cnt = dict_get_split_cnt (default_dict); + for (i = 0; i < split_cnt; i++) { - struct variable *v = *iter; + struct variable *v = split[i]; switch (v->type) { @@ -1228,6 +1193,7 @@ compact_case (struct ccase *dest, const struct ccase *src) { int i; int nval = 0; + size_t var_cnt; assert (compaction_necessary); @@ -1240,9 +1206,10 @@ compact_case (struct ccase *dest, const struct ccase *src) /* Copy all the variables except the scratch variables from SRC to DEST. */ - for (i = 0; i < default_dict.nvar; i++) + var_cnt = dict_get_var_cnt (default_dict); + for (i = 0; i < var_cnt; i++) { - struct variable *v = default_dict.var[i]; + struct variable *v = dict_get_var (default_dict, i); if (v->name[0] == '#') continue; @@ -1263,35 +1230,18 @@ compact_case (struct ccase *dest, const struct ccase *src) static void finish_compaction (void) { - int copy_index = 0; - int nval = 0; int i; - for (i = 0; i < default_dict.nvar; i++) + for (i = 0; i < dict_get_var_cnt (default_dict); ) { - struct variable *v = default_dict.var[i]; + struct variable *v = dict_get_var (default_dict, i); - if (v->name[0] == '#') - { - clear_variable (&default_dict, v); - free (v); - continue; - } - - v->fv = nval; - if (v->type == NUMERIC) - nval++; + if (v->name[0] == '#') + dict_delete_var (default_dict, v); else - nval += DIV_RND_UP (v->width, sizeof (union value)); - - default_dict.var[copy_index++] = v; - } - if (copy_index != default_dict.nvar) - { - default_dict.var = xrealloc (default_dict.var, - sizeof *default_dict.var * copy_index); - default_dict.nvar = copy_index; + i++; } + dict_compact_values (default_dict); }