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 <data/dictionary.h>
25 #include <data/transformations.h>
26 #include <data/procedure.h>
27 #include <data/variable.h>
28 #include <language/command.h>
29 #include <language/expressions/public.h>
30 #include <language/lexer/lexer.h>
31 #include <language/lexer/variable-parser.h>
32 #include <libpspp/alloc.h>
33 #include <libpspp/message.h>
34 #include <libpspp/str.h>
37 #define _(msgid) gettext (msgid)
39 /* SELECT IF transformation. */
42 struct expression *e; /* Test expression. */
45 static trns_proc_func select_if_proc;
46 static trns_free_func select_if_free;
48 /* Parses the SELECT IF transformation. */
50 cmd_select_if (struct dataset *ds)
53 struct select_if_trns *t;
55 e = expr_parse (ds, EXPR_BOOLEAN);
57 return CMD_CASCADING_FAILURE;
62 lex_error (_("expecting end of command"));
63 return CMD_CASCADING_FAILURE;
66 t = xmalloc (sizeof *t);
68 add_transformation (ds, select_if_proc, select_if_free, t);
73 /* Performs the SELECT IF transformation T on case C. */
75 select_if_proc (void *t_, struct ccase *c,
78 struct select_if_trns *t = t_;
79 return (expr_evaluate_num (t->e, c, case_num) == 1.0
80 ? TRNS_CONTINUE : TRNS_DROP_CASE);
83 /* Frees SELECT IF transformation T. */
85 select_if_free (void *t_)
87 struct select_if_trns *t = t_;
93 /* Parses the FILTER command. */
95 cmd_filter (struct dataset *ds)
97 struct dictionary *dict = dataset_dict (ds);
98 if (lex_match_id ("OFF"))
99 dict_set_filter (dataset_dict (ds), NULL);
100 else if (token == '.')
102 msg (SW, _("Syntax error expecting OFF or BY. "
103 "Turning off case filtering."));
104 dict_set_filter (dataset_dict (ds), NULL);
111 v = parse_variable (dict);
115 if (v->type == ALPHA)
117 msg (SE, _("The filter variable must be numeric."));
121 if (dict_class_from_id (v->name) == DC_SCRATCH)
123 msg (SE, _("The filter variable may not be scratch."));
127 dict_set_filter (dict, v);
130 return lex_end_of_command ();