1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2010, 2011, 2013 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/>. */
22 #include "data/dataset.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"
30 #include "gl/minmax.h"
31 #include "gl/xalloc.h"
34 #define _(msgid) gettext (msgid)
37 cmd_variable_alignment (struct lexer *lexer, struct dataset *ds)
44 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
47 if (!lex_force_match (lexer, T_LPAREN))
51 if (lex_match_id (lexer, "LEFT"))
53 else if (lex_match_id (lexer, "RIGHT"))
55 else if (lex_match_id (lexer, "CENTER"))
59 lex_error_expecting (lexer, "LEFT", "RIGHT", "CENTER");
63 if (!lex_force_match (lexer, T_RPAREN))
66 for (size_t i = 0; i < nv; ++i)
67 var_set_alignment (v[i], align);
69 while (lex_token (lexer) == T_SLASH)
78 while (lex_token (lexer) != T_ENDCMD);
83 cmd_variable_width (struct lexer *lexer, struct dataset *ds)
89 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
92 if (!lex_force_match (lexer, T_LPAREN)
93 || !lex_force_int_range (lexer, NULL, 1, INT_MAX))
95 long width = lex_integer (lexer);
97 if (!lex_force_match (lexer, T_RPAREN))
100 width = MIN (width, 2 * MAX_STRING);
102 for (size_t i = 0; i < nv; ++i)
103 var_set_display_width (v[i], width);
105 while (lex_token (lexer) == T_SLASH)
114 while (lex_token (lexer) != T_ENDCMD);
118 /* Set variables' measurement level */
120 cmd_variable_level (struct lexer *lexer, struct dataset *ds)
127 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
130 if (!lex_force_match (lexer, T_LPAREN))
134 if (lex_match_id (lexer, "SCALE"))
135 level = MEASURE_SCALE;
136 else if (lex_match_id (lexer, "ORDINAL"))
137 level = MEASURE_ORDINAL;
138 else if (lex_match_id (lexer, "NOMINAL"))
139 level = MEASURE_NOMINAL;
142 lex_error_expecting (lexer, "SCALE", "ORDINAL", "NOMINAL");
146 if (!lex_force_match (lexer, T_RPAREN))
149 for (size_t i = 0; i < nv; ++i)
150 var_set_measure (v[i], level);
152 while (lex_token (lexer) == T_SLASH)
161 while (lex_token (lexer) != T_ENDCMD);
166 cmd_variable_role (struct lexer *lexer, struct dataset *ds)
170 if (!lex_force_match (lexer, T_SLASH))
174 if (lex_match_id (lexer, "INPUT"))
176 else if (lex_match_id (lexer, "TARGET"))
178 else if (lex_match_id (lexer, "BOTH"))
180 else if (lex_match_id (lexer, "NONE"))
182 else if (lex_match_id (lexer, "PARTITION"))
183 role = ROLE_PARTITION;
184 else if (lex_match_id (lexer, "SPLIT"))
188 lex_error_expecting (lexer, "INPUT", "TARGET", "BOTH",
189 "NONE", "PARTITION", "SPLIT");
195 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
198 for (size_t i = 0; i < nv; i++)
199 var_set_role (v[i], role);
203 while (lex_token (lexer) != T_ENDCMD);