1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include "dictionary.h"
26 #include "expressions/public.h"
32 #define _(msgid) gettext (msgid)
34 /* SELECT IF transformation. */
37 struct expression *e; /* Test expression. */
40 static trns_proc_func select_if_proc;
41 static trns_free_func select_if_free;
43 /* Parses the SELECT IF transformation. */
48 struct select_if_trns *t;
50 e = expr_parse (default_dict, EXPR_BOOLEAN);
52 return CMD_CASCADING_FAILURE;
57 lex_error (_("expecting end of command"));
58 return CMD_CASCADING_FAILURE;
61 t = xmalloc (sizeof *t);
63 add_transformation (select_if_proc, select_if_free, t);
68 /* Performs the SELECT IF transformation T on case C. */
70 select_if_proc (void *t_, struct ccase *c,
73 struct select_if_trns *t = t_;
74 return (expr_evaluate_num (t->e, c, case_num) == 1.0
75 ? TRNS_CONTINUE : TRNS_DROP_CASE);
78 /* Frees SELECT IF transformation T. */
80 select_if_free (void *t_)
82 struct select_if_trns *t = t_;
88 /* Parses the FILTER command. */
92 if (lex_match_id ("OFF"))
93 dict_set_filter (default_dict, NULL);
99 v = parse_variable ();
101 return CMD_CASCADING_FAILURE;
103 if (v->type == ALPHA)
105 msg (SE, _("The filter variable must be numeric."));
106 return CMD_CASCADING_FAILURE;
109 if (dict_class_from_id (v->name) == DC_SCRATCH)
111 msg (SE, _("The filter variable may not be scratch."));
112 return CMD_CASCADING_FAILURE;
115 dict_set_filter (default_dict, v);
121 /* Expression on PROCESS IF. */
122 struct expression *process_if_expr;
124 /* Parses the PROCESS IF command. */
126 cmd_process_if (void)
128 struct expression *e;
130 e = expr_parse (default_dict, EXPR_BOOLEAN);
137 lex_error (_("expecting end of command"));
143 msg (MW, _("Only last instance of this command is in effect."));
144 expr_free (process_if_expr);