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 lex_force_match (lexer, T_RPAREN);
76 for( i = 0 ; i < nv ; ++i )
77 var_set_alignment (v[i], align);
79 while (lex_token (lexer) == T_SLASH)
84 while (lex_token (lexer) != T_ENDCMD);
88 /* Set variables' display width.
89 This is the width for GUI display only.
90 It affects nothing but GUIs
93 cmd_variable_width (struct lexer *lexer, struct dataset *ds)
102 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
105 if (!lex_force_match (lexer, T_LPAREN) || !lex_force_int (lexer))
110 width = lex_integer (lexer);
112 if (!lex_force_match (lexer, T_RPAREN))
120 msg (SE, _("Variable display width must be a positive integer."));
124 width = MIN (width, 2 * MAX_STRING);
126 for( i = 0 ; i < nv ; ++i )
127 var_set_display_width (v[i], width);
129 while (lex_token (lexer) == T_SLASH)
134 while (lex_token (lexer) != T_ENDCMD);
138 /* Set variables' measurement level */
140 cmd_variable_level (struct lexer *lexer, struct dataset *ds)
149 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
152 if ( lex_force_match (lexer, T_LPAREN) )
154 if ( lex_match_id (lexer, "SCALE"))
155 level = MEASURE_SCALE;
156 else if ( lex_match_id (lexer, "ORDINAL"))
157 level = MEASURE_ORDINAL;
158 else if ( lex_match_id (lexer, "NOMINAL"))
159 level = MEASURE_NOMINAL;
166 lex_force_match (lexer, T_RPAREN);
174 for( i = 0 ; i < nv ; ++i )
175 var_set_measure (v[i], level);
178 while (lex_token (lexer) == T_SLASH)
183 while (lex_token (lexer) != T_ENDCMD);
187 /* Set variables' role */
189 cmd_variable_role (struct lexer *lexer, struct dataset *ds)
191 while (lex_match (lexer, T_SLASH))
198 if ( lex_match_id (lexer, "INPUT"))
200 else if ( lex_match_id (lexer, "TARGET"))
202 else if ( lex_match_id (lexer, "BOTH"))
204 else if ( lex_match_id (lexer, "NONE"))
206 else if ( lex_match_id (lexer, "PARTITION"))
207 role = ROLE_PARTITION;
208 else if ( lex_match_id (lexer, "SPLIT"))
212 lex_error (lexer, NULL);
216 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
219 for (i = 0; i < nv; i++)
220 var_set_role (v[i], role);