1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include <data/dictionary.h>
24 #include <data/transformations.h>
25 #include <data/procedure.h>
26 #include <data/variable.h>
27 #include <language/command.h>
28 #include <language/expressions/public.h>
29 #include <language/lexer/lexer.h>
30 #include <language/lexer/variable-parser.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. */
49 cmd_select_if (struct lexer *lexer, struct dataset *ds)
52 struct select_if_trns *t;
54 e = expr_parse (lexer, ds, EXPR_BOOLEAN);
56 return CMD_CASCADING_FAILURE;
58 if (lex_token (lexer) != '.')
61 lex_error (lexer, _("expecting end of command"));
62 return CMD_CASCADING_FAILURE;
65 t = xmalloc (sizeof *t);
67 add_transformation (ds, 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. */
94 cmd_filter (struct lexer *lexer, struct dataset *ds)
96 struct dictionary *dict = dataset_dict (ds);
97 if (lex_match_id (lexer, "OFF"))
98 dict_set_filter (dataset_dict (ds), NULL);
99 else if (lex_token (lexer) == '.')
101 msg (SW, _("Syntax error expecting OFF or BY. "
102 "Turning off case filtering."));
103 dict_set_filter (dataset_dict (ds), NULL);
109 lex_match (lexer, T_BY);
110 v = parse_variable (lexer, dict);
114 if (var_is_alpha (v))
116 msg (SE, _("The filter variable must be numeric."));
120 if (dict_class_from_id (var_get_name (v)) == DC_SCRATCH)
122 msg (SE, _("The filter variable may not be scratch."));
126 dict_set_filter (dict, v);
129 return lex_end_of_command (lexer);