32 |
#include "casefile.h" |
#include "casefile.h" |
33 |
#include "command.h" |
#include "command.h" |
34 |
#include "dictionary.h" |
#include "dictionary.h" |
35 |
#include "do-ifP.h" |
#include "ctl-stack.h" |
36 |
#include "error.h" |
#include "error.h" |
37 |
#include "expressions/public.h" |
#include "expressions/public.h" |
38 |
#include "misc.h" |
#include "misc.h" |
94 |
static void open_active_file (void); |
static void open_active_file (void); |
95 |
static int write_case (struct write_case_data *wc_data); |
static int write_case (struct write_case_data *wc_data); |
96 |
static int execute_transformations (struct ccase *c, |
static int execute_transformations (struct ccase *c, |
97 |
struct trns_header **trns, |
struct transformation *trns, |
98 |
int first_idx, int last_idx, |
int first_idx, int last_idx, |
99 |
int case_num); |
int case_num); |
100 |
static int filter_case (const struct ccase *c, int case_num); |
static int filter_case (const struct ccase *c, int case_num); |
233 |
} |
} |
234 |
|
|
235 |
/* Close any unclosed DO IF or LOOP constructs. */ |
/* Close any unclosed DO IF or LOOP constructs. */ |
236 |
discard_ctl_stack (); |
ctl_stack_clear (); |
237 |
} |
} |
238 |
|
|
239 |
/* Transforms trns_case and writes it to the replacement active |
/* Transforms trns_case and writes it to the replacement active |
299 |
transformations, nonzero otherwise. */ |
transformations, nonzero otherwise. */ |
300 |
static int |
static int |
301 |
execute_transformations (struct ccase *c, |
execute_transformations (struct ccase *c, |
302 |
struct trns_header **trns, |
struct transformation *trns, |
303 |
int first_idx, int last_idx, |
int first_idx, int last_idx, |
304 |
int case_num) |
int case_num) |
305 |
{ |
{ |
307 |
|
|
308 |
for (idx = first_idx; idx != last_idx; ) |
for (idx = first_idx; idx != last_idx; ) |
309 |
{ |
{ |
310 |
int retval = trns[idx]->proc (trns[idx], c, case_num); |
struct transformation *t = &trns[idx]; |
311 |
|
int retval = t->proc (t->private, c, case_num); |
312 |
switch (retval) |
switch (retval) |
313 |
{ |
{ |
314 |
case -1: |
case -1: |
604 |
/* Appends TRNS to t_trns[], the list of all transformations to be |
/* Appends TRNS to t_trns[], the list of all transformations to be |
605 |
performed on data as it is read from the active file. */ |
performed on data as it is read from the active file. */ |
606 |
void |
void |
607 |
add_transformation (struct trns_header * trns) |
add_transformation (trns_proc_func *proc, trns_free_func *free, void *private) |
608 |
{ |
{ |
609 |
|
struct transformation *trns; |
610 |
if (n_trns >= m_trns) |
if (n_trns >= m_trns) |
611 |
{ |
t_trns = x2nrealloc (t_trns, &m_trns, sizeof *t_trns); |
612 |
m_trns += 16; |
trns = &t_trns[n_trns++]; |
613 |
t_trns = xnrealloc (t_trns, m_trns, sizeof *t_trns); |
trns->proc = proc; |
614 |
} |
trns->free = free; |
615 |
t_trns[n_trns] = trns; |
trns->private = private; |
616 |
trns->index = n_trns++; |
} |
617 |
|
|
618 |
|
/* Returns the index number that the next transformation added by |
619 |
|
add_transformation() will receive. A trns_proc_func that |
620 |
|
returns this index causes control flow to jump to it. */ |
621 |
|
size_t |
622 |
|
next_transformation (void) |
623 |
|
{ |
624 |
|
return n_trns; |
625 |
} |
} |
626 |
|
|
627 |
/* Cancels all active transformations, including any transformations |
/* Cancels all active transformations, including any transformations |
629 |
void |
void |
630 |
cancel_transformations (void) |
cancel_transformations (void) |
631 |
{ |
{ |
632 |
int i; |
size_t i; |
633 |
for (i = 0; i < n_trns; i++) |
for (i = 0; i < n_trns; i++) |
634 |
{ |
{ |
635 |
if (t_trns[i]->free) |
struct transformation *t = &t_trns[i]; |
636 |
t_trns[i]->free (t_trns[i]); |
if (t->free != NULL) |
637 |
free (t_trns[i]); |
t->free (t->private); |
638 |
} |
} |
639 |
n_trns = f_trns = 0; |
n_trns = f_trns = 0; |
640 |
free (t_trns); |
free (t_trns); |
938 |
|
|
939 |
cancel_transformations (); |
cancel_transformations (); |
940 |
|
|
941 |
ctl_stack = NULL; |
ctl_stack_clear (); |
942 |
|
|
943 |
expr_free (process_if_expr); |
expr_free (process_if_expr); |
944 |
process_if_expr = NULL; |
process_if_expr = NULL; |