X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvfm.c;h=344f94b9a80224625fdfed08e9ed84fcb7dc9645;hb=304c185799902df1dd96a8ff2d13d279005a82e5;hp=1d3d2a5ca627a2d98db8f65b124c46e3eeaea1af;hpb=06f9ee45954e5e71fa7f6262dbf37defa1dbf996;p=pspp-builds.git diff --git a/src/vfm.c b/src/vfm.c index 1d3d2a5c..344f94b9 100644 --- a/src/vfm.c +++ b/src/vfm.c @@ -30,11 +30,11 @@ #include "alloc.h" #include "case.h" #include "casefile.h" +#include "dictionary.h" #include "do-ifP.h" #include "error.h" -#include "expr.h" +#include "expressions/public.h" #include "misc.h" -#include "random.h" #include "settings.h" #include "som.h" #include "str.h" @@ -95,7 +95,6 @@ static int execute_transformations (struct ccase *c, int case_num); static int filter_case (const struct ccase *c, int case_num); static void lag_case (const struct ccase *c); -static void compact_case (struct ccase *dest, const struct ccase *src); static void clear_case (struct ccase *c); static void close_active_file (void); @@ -260,7 +259,7 @@ write_case (struct write_case_data *wc_data) { if (compaction_necessary) { - compact_case (&wc_data->sink_case, &wc_data->trns_case); + dict_compact_case (temp_dict, &wc_data->sink_case, &wc_data->trns_case); vfm_sink->class->write (vfm_sink, &wc_data->sink_case); } else @@ -339,7 +338,7 @@ filter_case (const struct ccase *c, int case_idx) /* PROCESS IF. */ if (process_if_expr != NULL - && expr_evaluate (process_if_expr, c, case_idx, NULL) != 1.0) + && expr_evaluate_num (process_if_expr, c, case_idx) != 1.0) return 1; return 0; @@ -357,43 +356,6 @@ lag_case (const struct ccase *c) lag_head = 0; } -/* Copies case SRC to case DEST, compacting it in the process. */ -static void -compact_case (struct ccase *dest, const struct ccase *src) -{ - int i; - int nval = 0; - size_t var_cnt; - - assert (compaction_necessary); - - /* Copy all the variables except scratch variables from SRC to - DEST. */ - /* FIXME: this should be temp_dict not default_dict I guess. */ - var_cnt = dict_get_var_cnt (default_dict); - for (i = 0; i < var_cnt; i++) - { - struct variable *v = dict_get_var (default_dict, i); - - if (dict_class_from_id (v->name) == DC_SCRATCH) - continue; - - if (v->type == NUMERIC) - { - case_data_rw (dest, nval)->f = case_num (src, v->fv); - nval++; - } - else - { - int w = DIV_RND_UP (v->width, sizeof (union value)); - - memcpy (case_data_rw (dest, nval), case_str (src, v->fv), - w * sizeof (union value)); - nval += w; - } - } -} - /* Clears the variables in C that need to be cleared between processing cases. */ static void @@ -518,7 +480,7 @@ static struct case_source * storage_sink_make_source (struct case_sink *sink) { struct case_source *source - = create_case_source (&storage_source_class, sink->dict, sink->aux); + = create_case_source (&storage_source_class, sink->aux); sink->aux = NULL; return source; } @@ -594,14 +556,14 @@ storage_source_get_casefile (struct case_source *source) } struct case_source * -storage_source_create (struct casefile *cf, const struct dictionary *dict) +storage_source_create (struct casefile *cf) { struct storage_stream_info *info; info = xmalloc (sizeof *info); info->casefile = cf; - return create_case_source (&storage_source_class, dict, info); + return create_case_source (&storage_source_class, info); } /* Null sink. Used by a few procedures that keep track of output @@ -622,7 +584,7 @@ const struct case_sink_class null_sink_class = struct ccase * lagged_case (int n_before) { - assert (n_before <= n_lag); + assert (n_before >= 1 && n_before <= n_lag); if (n_before <= lag_count) { int index = lag_head - n_before; @@ -661,24 +623,19 @@ cancel_transformations (void) free (t_trns[i]); } n_trns = f_trns = 0; - if (m_trns > 32) - { - free (t_trns); - t_trns=NULL; - m_trns = 0; - } + free (t_trns); + t_trns=NULL; + m_trns = 0; } /* Creates a case source with class CLASS and auxiliary data AUX and based on dictionary DICT. */ struct case_source * create_case_source (const struct case_source_class *class, - const struct dictionary *dict, void *aux) { struct case_source *source = xmalloc (sizeof *source); source->class = class; - source->value_cnt = dict_get_next_value_idx (dict); source->aux = aux; return source; } @@ -712,8 +669,8 @@ case_source_is_class (const struct case_source *source, return source != NULL && source->class == class; } -/* Creates a case sink with class CLASS and auxiliary data - AUX. */ +/* Creates a case sink to accept cases from the given DICT with + class CLASS and auxiliary data AUX. */ struct case_sink * create_case_sink (const struct case_sink_class *class, const struct dictionary *dict, @@ -721,8 +678,6 @@ create_case_sink (const struct case_sink_class *class, { struct case_sink *sink = xmalloc (sizeof *sink); sink->class = class; - sink->dict = dict; - sink->idx_to_fv = dict_get_compacted_idx_to_fv (dict); sink->value_cnt = dict_get_compacted_value_cnt (dict); sink->aux = aux; return sink; @@ -736,7 +691,6 @@ free_case_sink (struct case_sink *sink) { if (sink->class->destroy != NULL) sink->class->destroy (sink); - free (sink->idx_to_fv); free (sink); } } @@ -786,10 +740,12 @@ procedure_with_splits (void (*begin_func) (void *aux), split_aux.end_func = end_func; split_aux.func_aux = func_aux; - procedure (procedure_with_splits_callback, &split_aux); - + open_active_file (); + internal_procedure (procedure_with_splits_callback, &split_aux); if (split_aux.case_count > 0 && end_func != NULL) end_func (func_aux); + close_active_file (); + case_destroy (&split_aux.prev_case); }