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) || !lex_force_int (lexer))
111 width = lex_integer (lexer);
113 if (!lex_force_match (lexer, T_RPAREN))
121 msg (SE, _("Variable display width must be a positive integer."));
125 width = MIN (width, 2 * MAX_STRING);
127 for( i = 0 ; i < nv ; ++i )
128 var_set_display_width (v[i], width);
130 while (lex_token (lexer) == T_SLASH)
135 while (lex_token (lexer) != T_ENDCMD);
139 /* Set variables' measurement level */
141 cmd_variable_level (struct lexer *lexer, struct dataset *ds)
150 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
153 if ( lex_force_match (lexer, T_LPAREN) )
155 if ( lex_match_id (lexer, "SCALE"))
156 level = MEASURE_SCALE;
157 else if ( lex_match_id (lexer, "ORDINAL"))
158 level = MEASURE_ORDINAL;
159 else if ( lex_match_id (lexer, "NOMINAL"))
160 level = MEASURE_NOMINAL;
167 if (!lex_force_match (lexer, T_RPAREN))
176 for( i = 0 ; i < nv ; ++i )
177 var_set_measure (v[i], level);
180 while (lex_token (lexer) == T_SLASH)
185 while (lex_token (lexer) != T_ENDCMD);
189 /* Set variables' role */
191 cmd_variable_role (struct lexer *lexer, struct dataset *ds)
193 while (lex_match (lexer, T_SLASH))
200 if ( lex_match_id (lexer, "INPUT"))
202 else if ( lex_match_id (lexer, "TARGET"))
204 else if ( lex_match_id (lexer, "BOTH"))
206 else if ( lex_match_id (lexer, "NONE"))
208 else if ( lex_match_id (lexer, "PARTITION"))
209 role = ROLE_PARTITION;
210 else if ( lex_match_id (lexer, "SPLIT"))
214 lex_error (lexer, NULL);
218 if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
221 for (i = 0; i < nv; i++)
222 var_set_role (v[i], role);