-/* Transforms temp_case and writes it to the replacement active file
- if advisable. Returns nonzero if more cases can be accepted, zero
- otherwise. Do not call this function again after it has returned
- zero once. */
-int
-procedure_write_case (write_case_data wc_data)
-{
- /* Index of current transformation. */
- int cur_trns;
-
- /* Return value: whether it's reasonable to write any more cases. */
- int more_cases = 1;
-
- debug_printf ((_("transform: ")));
-
- cur_trns = f_trns;
- for (;;)
- {
- /* Output the case if this is temp_trns. */
- if (cur_trns == temp_trns)
- {
- debug_printf (("REC"));
-
- if (n_lag)
- lag_case ();
-
- vfm_sink_info.ncases++;
- vfm_sink->class->write (vfm_sink, temp_case);
-
- if (dict_get_case_limit (default_dict))
- more_cases = (vfm_sink_info.ncases
- < dict_get_case_limit (default_dict));
- }
-
- /* Are we done? */
- if (cur_trns >= n_trns)
- break;
-
- debug_printf (("$%d", cur_trns));
-
- /* Decide which transformation should come next. */
- {
- int code;
-
- code = t_trns[cur_trns]->proc (t_trns[cur_trns], temp_case);
- switch (code)
- {
- case -1:
- /* Next transformation. */
- cur_trns++;
- break;
- case -2:
- /* Delete this case. */
- goto done;
- default:
- /* Go to that transformation. */
- cur_trns = code;
- break;
- }
- }
- }
-
- /* Call the beginning of group function. */
- if (!case_count && wc_data->beginfunc != NULL)
- wc_data->beginfunc (wc_data->aux);
-
- /* Call the procedure if there is one and FILTER and PROCESS IF
- don't prohibit it. */
- if (wc_data->procfunc != NULL && !exclude_this_case ())
- wc_data->procfunc (temp_case, wc_data->aux);
-
- case_count++;
-
-done:
- debug_putc ('\n', stdout);
-
- 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);
- }
- }
-}
-
-/* Returns nonzero if this case should be exclude as specified on
- FILTER or PROCESS IF, otherwise zero. */
-static int
-exclude_this_case (void)
-{
- /* FILTER. */
- struct variable *filter_var = dict_get_filter (default_dict);
- if (filter_var != NULL)
- {
- double f = temp_case->data[filter_var->fv].f;
- if (f == 0.0 || f == SYSMIS || is_num_user_missing (f, filter_var))
- return 1;
- }
-
- /* PROCESS IF. */
- if (process_if_expr != NULL
- && expr_evaluate (process_if_expr, temp_case, NULL) != 1.0)
- return 1;
-
- return 0;
-}
-