1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU 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, see <http://www.gnu.org/licenses/>. */
21 #include "data/procedure.h"
22 #include "data/dictionary.h"
23 #include "data/variable.h"
24 #include "language/command.h"
25 #include "language/lexer/lexer.h"
26 #include "language/lexer/variable-parser.h"
27 #include "libpspp/message.h"
28 #include "libpspp/str.h"
31 #define _(msgid) gettext (msgid)
34 cmd_weight (struct lexer *lexer, struct dataset *ds)
36 struct dictionary *dict = dataset_dict (ds);
37 if (lex_match_id (lexer, "OFF"))
38 dict_set_weight (dataset_dict (ds), NULL);
43 lex_match (lexer, T_BY);
44 v = parse_variable (lexer, dict);
46 return CMD_CASCADING_FAILURE;
49 msg (SE, _("The weighting variable must be numeric."));
50 return CMD_CASCADING_FAILURE;
52 if (dict_class_from_id (var_get_name (v)) == DC_SCRATCH)
54 msg (SE, _("The weighting variable may not be scratch."));
55 return CMD_CASCADING_FAILURE;
58 dict_set_weight (dict, v);
61 return lex_end_of_command (lexer);