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)
36 /* Set variables' alignment
37 This is the alignment for GUI display only.
38 It affects nothing but GUIs
41 cmd_variable_alignment (struct lexer *lexer, struct dataset *ds)
51 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
54 if (lex_force_match (lexer, T_LPAREN))
56 if (lex_match_id (lexer, "LEFT"))
58 else if (lex_match_id (lexer, "RIGHT"))
60 else if (lex_match_id (lexer, "CENTER"))
68 if (!lex_force_match (lexer, T_RPAREN))
77 for(i = 0 ; i < nv ; ++i)
78 var_set_alignment (v[i], align);
80 while (lex_token (lexer) == T_SLASH)
85 while (lex_token (lexer) != T_ENDCMD);
89 /* Set variables' display width.
90 This is the width for GUI display only.
91 It affects nothing but GUIs
94 cmd_variable_width (struct lexer *lexer, struct dataset *ds)
103 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
106 if (!lex_force_match (lexer, T_LPAREN)
107 || !lex_force_int_range (lexer, NULL, 1, INT_MAX))
112 width = lex_integer (lexer);
114 if (!lex_force_match (lexer, T_RPAREN))
120 width = MIN (width, 2 * MAX_STRING);
122 for(i = 0 ; i < nv ; ++i)
123 var_set_display_width (v[i], width);
125 while (lex_token (lexer) == T_SLASH)
130 while (lex_token (lexer) != T_ENDCMD);
134 /* Set variables' measurement level */
136 cmd_variable_level (struct lexer *lexer, struct dataset *ds)
145 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
148 if (lex_force_match (lexer, T_LPAREN))
150 if (lex_match_id (lexer, "SCALE"))
151 level = MEASURE_SCALE;
152 else if (lex_match_id (lexer, "ORDINAL"))
153 level = MEASURE_ORDINAL;
154 else if (lex_match_id (lexer, "NOMINAL"))
155 level = MEASURE_NOMINAL;
162 if (!lex_force_match (lexer, T_RPAREN))
171 for(i = 0 ; i < nv ; ++i)
172 var_set_measure (v[i], level);
175 while (lex_token (lexer) == T_SLASH)
180 while (lex_token (lexer) != T_ENDCMD);
184 /* Set variables' role */
186 cmd_variable_role (struct lexer *lexer, struct dataset *ds)
188 while (lex_match (lexer, T_SLASH))
195 if (lex_match_id (lexer, "INPUT"))
197 else if (lex_match_id (lexer, "TARGET"))
199 else if (lex_match_id (lexer, "BOTH"))
201 else if (lex_match_id (lexer, "NONE"))
203 else if (lex_match_id (lexer, "PARTITION"))
204 role = ROLE_PARTITION;
205 else if (lex_match_id (lexer, "SPLIT"))
209 lex_error (lexer, NULL);
213 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
216 for (i = 0; i < nv; i++)
217 var_set_role (v[i], role);