18 |
02110-1301, USA. */ |
02110-1301, USA. */ |
19 |
|
|
20 |
#include <config.h> |
#include <config.h> |
21 |
|
#include <stdlib.h> |
22 |
#include "alloc.h" |
#include "alloc.h" |
23 |
#include "command.h" |
#include "command.h" |
24 |
#include "dictionary.h" |
#include "dictionary.h" |
34 |
/* SELECT IF transformation. */ |
/* SELECT IF transformation. */ |
35 |
struct select_if_trns |
struct select_if_trns |
36 |
{ |
{ |
|
struct trns_header h; |
|
37 |
struct expression *e; /* Test expression. */ |
struct expression *e; /* Test expression. */ |
38 |
}; |
}; |
39 |
|
|
59 |
} |
} |
60 |
|
|
61 |
t = xmalloc (sizeof *t); |
t = xmalloc (sizeof *t); |
|
t->h.proc = select_if_proc; |
|
|
t->h.free = select_if_free; |
|
62 |
t->e = e; |
t->e = e; |
63 |
add_transformation ((struct trns_header *) t); |
add_transformation (select_if_proc, select_if_free, t); |
64 |
|
|
65 |
return CMD_SUCCESS; |
return CMD_SUCCESS; |
66 |
} |
} |
67 |
|
|
68 |
/* Performs the SELECT IF transformation T on case C. */ |
/* Performs the SELECT IF transformation T on case C. */ |
69 |
static int |
static int |
70 |
select_if_proc (struct trns_header *t_, struct ccase *c, |
select_if_proc (void *t_, struct ccase *c, |
71 |
int case_num) |
int case_num) |
72 |
{ |
{ |
73 |
struct select_if_trns *t = (struct select_if_trns *) t_; |
struct select_if_trns *t = t_; |
74 |
return expr_evaluate_num (t->e, c, case_num) == 1.0 ? -1 : -2; |
return expr_evaluate_num (t->e, c, case_num) == 1.0 ? -1 : -2; |
75 |
} |
} |
76 |
|
|
77 |
/* Frees SELECT IF transformation T. */ |
/* Frees SELECT IF transformation T. */ |
78 |
static void |
static void |
79 |
select_if_free (struct trns_header * t) |
select_if_free (void *t_) |
80 |
{ |
{ |
81 |
expr_free (((struct select_if_trns *) t)->e); |
struct select_if_trns *t = t_; |
82 |
|
expr_free (t->e); |
83 |
|
free (t); |
84 |
} |
} |
85 |
|
|
86 |
/* Parses the FILTER command. */ |
/* Parses the FILTER command. */ |