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
23 #include "dictionary.h"
25 #include "expressions/public.h"
31 #define _(msgid) gettext (msgid)
33 /* 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);
57 lex_error (_("expecting end of command"));
61 t = xmalloc (sizeof *t);
62 t->h.proc = select_if_proc;
63 t->h.free = select_if_free;
65 add_transformation ((struct trns_header *) t);
70 /* Performs the SELECT IF transformation T on case C. */
72 select_if_proc (struct trns_header *t_, struct ccase *c,
75 struct select_if_trns *t = (struct select_if_trns *) t_;
76 return expr_evaluate_num (t->e, c, case_num) == 1.0 ? -1 : -2;
79 /* Frees SELECT IF transformation T. */
81 select_if_free (struct trns_header * t)
83 expr_free (((struct select_if_trns *) t)->e);
86 /* Parses the FILTER command. */
90 if (lex_match_id ("OFF"))
91 dict_set_filter (default_dict, NULL);
97 v = parse_variable ();
101 if (v->type == ALPHA)
103 msg (SE, _("The filter variable must be numeric."));
107 if (dict_class_from_id (v->name) == DC_SCRATCH)
109 msg (SE, _("The filter variable may not be scratch."));
113 dict_set_filter (default_dict, v);
115 FILTER_before_TEMPORARY = !temporary;
121 /* Parses the PROCESS IF command. */
123 cmd_process_if (void)
125 struct expression *e;
127 e = expr_parse (default_dict, EXPR_BOOLEAN);
134 lex_error (_("expecting end of command"));
140 msg (MW, _("Only last instance of this command is in effect."));
141 expr_free (process_if_expr);