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 <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 <libpspp/alloc.h>
32 #include <libpspp/message.h>
33 #include <libpspp/str.h>
36 #define _(msgid) gettext (msgid)
38 /* SELECT IF transformation. */
41 struct expression *e; /* Test expression. */
44 static trns_proc_func select_if_proc;
45 static trns_free_func select_if_free;
47 /* Parses the SELECT IF transformation. */
52 struct select_if_trns *t;
54 e = expr_parse (default_dict, EXPR_BOOLEAN);
56 return CMD_CASCADING_FAILURE;
61 lex_error (_("expecting end of command"));
62 return CMD_CASCADING_FAILURE;
65 t = xmalloc (sizeof *t);
67 add_transformation (select_if_proc, select_if_free, t);
72 /* Performs the SELECT IF transformation T on case C. */
74 select_if_proc (void *t_, struct ccase *c,
77 struct select_if_trns *t = t_;
78 return (expr_evaluate_num (t->e, c, case_num) == 1.0
79 ? TRNS_CONTINUE : TRNS_DROP_CASE);
82 /* Frees SELECT IF transformation T. */
84 select_if_free (void *t_)
86 struct select_if_trns *t = t_;
92 /* Parses the FILTER command. */
96 if (lex_match_id ("OFF"))
97 dict_set_filter (default_dict, NULL);
103 v = parse_variable ();
105 return CMD_CASCADING_FAILURE;
107 if (v->type == ALPHA)
109 msg (SE, _("The filter variable must be numeric."));
110 return CMD_CASCADING_FAILURE;
113 if (dict_class_from_id (v->name) == DC_SCRATCH)
115 msg (SE, _("The filter variable may not be scratch."));
116 return CMD_CASCADING_FAILURE;
119 dict_set_filter (default_dict, v);
125 /* Expression on PROCESS IF. */
126 struct expression *process_if_expr;
128 /* Parses the PROCESS IF command. */
130 cmd_process_if (void)
132 struct expression *e;
134 e = expr_parse (default_dict, EXPR_BOOLEAN);
141 lex_error (_("expecting end of command"));
147 msg (SW, _("Only last instance of this command is in effect."));
148 expr_free (process_if_expr);